@getflip/swirl-components 0.340.1 → 0.341.1

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 (35) hide show
  1. package/components.json +1 -1
  2. package/dist/cjs/{maska-BX2QG_K8.js → index-BOqO2Grl.js} +3593 -17
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/swirl-components.cjs.js +1 -1
  5. package/dist/cjs/swirl-date-input.cjs.entry.js +92 -37
  6. package/dist/cjs/swirl-file-viewer_8.cjs.entry.js +10 -3
  7. package/dist/cjs/swirl-time-input.cjs.entry.js +78 -49
  8. package/dist/collection/components/swirl-date-input/swirl-date-input.js +88 -33
  9. package/dist/collection/components/swirl-date-input/swirl-date-input.stories.js +1 -1
  10. package/dist/collection/components/swirl-file-viewer/viewers/swirl-file-viewer-pdf/swirl-file-viewer-pdf.js +10 -3
  11. package/dist/collection/components/swirl-time-input/swirl-time-input.js +77 -46
  12. package/dist/collection/components/swirl-time-input/swirl-time-input.stories.js +1 -1
  13. package/dist/components/assets/pdfjs/pdf.worker.min.mjs +4 -1
  14. package/dist/components/{maska.js → index3.js} +3593 -17
  15. package/dist/components/swirl-date-input.js +88 -33
  16. package/dist/components/swirl-file-viewer-pdf2.js +10 -3
  17. package/dist/components/swirl-time-input.js +78 -48
  18. package/dist/esm/{maska-CSSJQ9ZE.js → index-D3UoejeY.js} +3593 -17
  19. package/dist/esm/loader.js +1 -1
  20. package/dist/esm/swirl-components.js +1 -1
  21. package/dist/esm/swirl-date-input.entry.js +88 -33
  22. package/dist/esm/swirl-file-viewer_8.entry.js +10 -3
  23. package/dist/esm/swirl-time-input.entry.js +76 -47
  24. package/dist/swirl-components/{p-ca695458.entry.js → p-01748667.entry.js} +1 -1
  25. package/dist/swirl-components/p-1bbb3a4b.entry.js +1 -0
  26. package/dist/swirl-components/p-96441b7e.entry.js +1 -0
  27. package/dist/swirl-components/p-D3UoejeY.js +1 -0
  28. package/dist/swirl-components/swirl-components.esm.js +1 -1
  29. package/dist/types/components/swirl-date-input/swirl-date-input.d.ts +2 -2
  30. package/dist/types/components/swirl-file-viewer/viewers/swirl-file-viewer-pdf/swirl-file-viewer-pdf.d.ts +1 -0
  31. package/dist/types/components/swirl-time-input/swirl-time-input.d.ts +1 -2
  32. package/package.json +2 -2
  33. package/dist/swirl-components/p-1217fdca.entry.js +0 -1
  34. package/dist/swirl-components/p-CSSJQ9ZE.js +0 -6
  35. package/dist/swirl-components/p-b96b8029.entry.js +0 -1
@@ -6238,26 +6238,3602 @@ function cleanEscapedString(input) {
6238
6238
  return input.match(escapedStringRegExp)[1].replace(doubleQuoteRegExp, "'");
6239
6239
  }
6240
6240
 
6241
- var maska$1 = {exports: {}};
6241
+ /** Checks if value is string */
6242
+ function isString(str) {
6243
+ return typeof str === 'string' || str instanceof String;
6244
+ }
6245
+
6246
+ /** Checks if value is object */
6247
+ function isObject(obj) {
6248
+ var _obj$constructor;
6249
+ return typeof obj === 'object' && obj != null && (obj == null || (_obj$constructor = obj.constructor) == null ? void 0 : _obj$constructor.name) === 'Object';
6250
+ }
6251
+ function pick(obj, keys) {
6252
+ if (Array.isArray(keys)) return pick(obj, (_, k) => keys.includes(k));
6253
+ return Object.entries(obj).reduce((acc, _ref) => {
6254
+ let [k, v] = _ref;
6255
+ if (keys(v, k)) acc[k] = v;
6256
+ return acc;
6257
+ }, {});
6258
+ }
6259
+
6260
+ /** Direction */
6261
+ const DIRECTION = {
6262
+ NONE: 'NONE',
6263
+ LEFT: 'LEFT',
6264
+ FORCE_LEFT: 'FORCE_LEFT',
6265
+ RIGHT: 'RIGHT',
6266
+ FORCE_RIGHT: 'FORCE_RIGHT'
6267
+ };
6268
+
6269
+ /** Direction */
6270
+
6271
+ function forceDirection(direction) {
6272
+ switch (direction) {
6273
+ case DIRECTION.LEFT:
6274
+ return DIRECTION.FORCE_LEFT;
6275
+ case DIRECTION.RIGHT:
6276
+ return DIRECTION.FORCE_RIGHT;
6277
+ default:
6278
+ return direction;
6279
+ }
6280
+ }
6281
+
6282
+ /** Escapes regular expression control chars */
6283
+ function escapeRegExp(str) {
6284
+ return str.replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1');
6285
+ }
6286
+
6287
+ // cloned from https://github.com/epoberezkin/fast-deep-equal with small changes
6288
+ function objectIncludes(b, a) {
6289
+ if (a === b) return true;
6290
+ const arrA = Array.isArray(a),
6291
+ arrB = Array.isArray(b);
6292
+ let i;
6293
+ if (arrA && arrB) {
6294
+ if (a.length != b.length) return false;
6295
+ for (i = 0; i < a.length; i++) if (!objectIncludes(a[i], b[i])) return false;
6296
+ return true;
6297
+ }
6298
+ if (arrA != arrB) return false;
6299
+ if (a && b && typeof a === 'object' && typeof b === 'object') {
6300
+ const dateA = a instanceof Date,
6301
+ dateB = b instanceof Date;
6302
+ if (dateA && dateB) return a.getTime() == b.getTime();
6303
+ if (dateA != dateB) return false;
6304
+ const regexpA = a instanceof RegExp,
6305
+ regexpB = b instanceof RegExp;
6306
+ if (regexpA && regexpB) return a.toString() == b.toString();
6307
+ if (regexpA != regexpB) return false;
6308
+ const keys = Object.keys(a);
6309
+ // if (keys.length !== Object.keys(b).length) return false;
6310
+
6311
+ for (i = 0; i < keys.length; i++) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
6312
+ for (i = 0; i < keys.length; i++) if (!objectIncludes(b[keys[i]], a[keys[i]])) return false;
6313
+ return true;
6314
+ } else if (a && b && typeof a === 'function' && typeof b === 'function') {
6315
+ return a.toString() === b.toString();
6316
+ }
6317
+ return false;
6318
+ }
6319
+
6320
+ /** Provides details of changing input */
6321
+ class ActionDetails {
6322
+ /** Current input value */
6323
+
6324
+ /** Current cursor position */
6325
+
6326
+ /** Old input value */
6327
+
6328
+ /** Old selection */
6329
+
6330
+ constructor(opts) {
6331
+ Object.assign(this, opts);
6332
+
6333
+ // double check if left part was changed (autofilling, other non-standard input triggers)
6334
+ while (this.value.slice(0, this.startChangePos) !== this.oldValue.slice(0, this.startChangePos)) {
6335
+ --this.oldSelection.start;
6336
+ }
6337
+ if (this.insertedCount) {
6338
+ // double check right part
6339
+ while (this.value.slice(this.cursorPos) !== this.oldValue.slice(this.oldSelection.end)) {
6340
+ if (this.value.length - this.cursorPos < this.oldValue.length - this.oldSelection.end) ++this.oldSelection.end;else ++this.cursorPos;
6341
+ }
6342
+ }
6343
+ }
6344
+
6345
+ /** Start changing position */
6346
+ get startChangePos() {
6347
+ return Math.min(this.cursorPos, this.oldSelection.start);
6348
+ }
6349
+
6350
+ /** Inserted symbols count */
6351
+ get insertedCount() {
6352
+ return this.cursorPos - this.startChangePos;
6353
+ }
6354
+
6355
+ /** Inserted symbols */
6356
+ get inserted() {
6357
+ return this.value.substr(this.startChangePos, this.insertedCount);
6358
+ }
6359
+
6360
+ /** Removed symbols count */
6361
+ get removedCount() {
6362
+ // Math.max for opposite operation
6363
+ return Math.max(this.oldSelection.end - this.startChangePos ||
6364
+ // for Delete
6365
+ this.oldValue.length - this.value.length, 0);
6366
+ }
6367
+
6368
+ /** Removed symbols */
6369
+ get removed() {
6370
+ return this.oldValue.substr(this.startChangePos, this.removedCount);
6371
+ }
6372
+
6373
+ /** Unchanged head symbols */
6374
+ get head() {
6375
+ return this.value.substring(0, this.startChangePos);
6376
+ }
6377
+
6378
+ /** Unchanged tail symbols */
6379
+ get tail() {
6380
+ return this.value.substring(this.startChangePos + this.insertedCount);
6381
+ }
6382
+
6383
+ /** Remove direction */
6384
+ get removeDirection() {
6385
+ if (!this.removedCount || this.insertedCount) return DIRECTION.NONE;
6386
+
6387
+ // align right if delete at right
6388
+ return (this.oldSelection.end === this.cursorPos || this.oldSelection.start === this.cursorPos) &&
6389
+ // if not range removed (event with backspace)
6390
+ this.oldSelection.end === this.oldSelection.start ? DIRECTION.RIGHT : DIRECTION.LEFT;
6391
+ }
6392
+ }
6393
+
6394
+ /** Applies mask on element */
6395
+ function IMask(el, opts) {
6396
+ // currently available only for input-like elements
6397
+ return new IMask.InputMask(el, opts);
6398
+ }
6399
+
6400
+ // TODO can't use overloads here because of https://github.com/microsoft/TypeScript/issues/50754
6401
+ // export function maskedClass(mask: string): typeof MaskedPattern;
6402
+ // export function maskedClass(mask: DateConstructor): typeof MaskedDate;
6403
+ // export function maskedClass(mask: NumberConstructor): typeof MaskedNumber;
6404
+ // export function maskedClass(mask: Array<any> | ArrayConstructor): typeof MaskedDynamic;
6405
+ // export function maskedClass(mask: MaskedDate): typeof MaskedDate;
6406
+ // export function maskedClass(mask: MaskedNumber): typeof MaskedNumber;
6407
+ // export function maskedClass(mask: MaskedEnum): typeof MaskedEnum;
6408
+ // export function maskedClass(mask: MaskedRange): typeof MaskedRange;
6409
+ // export function maskedClass(mask: MaskedRegExp): typeof MaskedRegExp;
6410
+ // export function maskedClass(mask: MaskedFunction): typeof MaskedFunction;
6411
+ // export function maskedClass(mask: MaskedPattern): typeof MaskedPattern;
6412
+ // export function maskedClass(mask: MaskedDynamic): typeof MaskedDynamic;
6413
+ // export function maskedClass(mask: Masked): typeof Masked;
6414
+ // export function maskedClass(mask: typeof Masked): typeof Masked;
6415
+ // export function maskedClass(mask: typeof MaskedDate): typeof MaskedDate;
6416
+ // export function maskedClass(mask: typeof MaskedNumber): typeof MaskedNumber;
6417
+ // export function maskedClass(mask: typeof MaskedEnum): typeof MaskedEnum;
6418
+ // export function maskedClass(mask: typeof MaskedRange): typeof MaskedRange;
6419
+ // export function maskedClass(mask: typeof MaskedRegExp): typeof MaskedRegExp;
6420
+ // export function maskedClass(mask: typeof MaskedFunction): typeof MaskedFunction;
6421
+ // export function maskedClass(mask: typeof MaskedPattern): typeof MaskedPattern;
6422
+ // export function maskedClass(mask: typeof MaskedDynamic): typeof MaskedDynamic;
6423
+ // export function maskedClass<Mask extends typeof Masked> (mask: Mask): Mask;
6424
+ // export function maskedClass(mask: RegExp): typeof MaskedRegExp;
6425
+ // export function maskedClass(mask: (value: string, ...args: any[]) => boolean): typeof MaskedFunction;
6426
+
6427
+ /** Get Masked class by mask type */
6428
+ function maskedClass(mask) /* TODO */{
6429
+ if (mask == null) throw new Error('mask property should be defined');
6430
+ if (mask instanceof RegExp) return IMask.MaskedRegExp;
6431
+ if (isString(mask)) return IMask.MaskedPattern;
6432
+ if (mask === Date) return IMask.MaskedDate;
6433
+ if (mask === Number) return IMask.MaskedNumber;
6434
+ if (Array.isArray(mask) || mask === Array) return IMask.MaskedDynamic;
6435
+ if (IMask.Masked && mask.prototype instanceof IMask.Masked) return mask;
6436
+ if (IMask.Masked && mask instanceof IMask.Masked) return mask.constructor;
6437
+ if (mask instanceof Function) return IMask.MaskedFunction;
6438
+ console.warn('Mask not found for mask', mask); // eslint-disable-line no-console
6439
+ return IMask.Masked;
6440
+ }
6441
+ function normalizeOpts(opts) {
6442
+ if (!opts) throw new Error('Options in not defined');
6443
+ if (IMask.Masked) {
6444
+ if (opts.prototype instanceof IMask.Masked) return {
6445
+ mask: opts
6446
+ };
6447
+
6448
+ /*
6449
+ handle cases like:
6450
+ 1) opts = Masked
6451
+ 2) opts = { mask: Masked, ...instanceOpts }
6452
+ */
6453
+ const {
6454
+ mask = undefined,
6455
+ ...instanceOpts
6456
+ } = opts instanceof IMask.Masked ? {
6457
+ mask: opts
6458
+ } : isObject(opts) && opts.mask instanceof IMask.Masked ? opts : {};
6459
+ if (mask) {
6460
+ const _mask = mask.mask;
6461
+ return {
6462
+ ...pick(mask, (_, k) => !k.startsWith('_')),
6463
+ mask: mask.constructor,
6464
+ _mask,
6465
+ ...instanceOpts
6466
+ };
6467
+ }
6468
+ }
6469
+ if (!isObject(opts)) return {
6470
+ mask: opts
6471
+ };
6472
+ return {
6473
+ ...opts
6474
+ };
6475
+ }
6476
+
6477
+ // TODO can't use overloads here because of https://github.com/microsoft/TypeScript/issues/50754
6478
+
6479
+ // From masked
6480
+ // export default function createMask<Opts extends Masked, ReturnMasked=Opts> (opts: Opts): ReturnMasked;
6481
+ // // From masked class
6482
+ // export default function createMask<Opts extends MaskedOptions<typeof Masked>, ReturnMasked extends Masked=InstanceType<Opts['mask']>> (opts: Opts): ReturnMasked;
6483
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedDate>, ReturnMasked extends MaskedDate=MaskedDate<Opts['parent']>> (opts: Opts): ReturnMasked;
6484
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedNumber>, ReturnMasked extends MaskedNumber=MaskedNumber<Opts['parent']>> (opts: Opts): ReturnMasked;
6485
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedEnum>, ReturnMasked extends MaskedEnum=MaskedEnum<Opts['parent']>> (opts: Opts): ReturnMasked;
6486
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedRange>, ReturnMasked extends MaskedRange=MaskedRange<Opts['parent']>> (opts: Opts): ReturnMasked;
6487
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedRegExp>, ReturnMasked extends MaskedRegExp=MaskedRegExp<Opts['parent']>> (opts: Opts): ReturnMasked;
6488
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedFunction>, ReturnMasked extends MaskedFunction=MaskedFunction<Opts['parent']>> (opts: Opts): ReturnMasked;
6489
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedPattern>, ReturnMasked extends MaskedPattern=MaskedPattern<Opts['parent']>> (opts: Opts): ReturnMasked;
6490
+ // export default function createMask<Opts extends MaskedOptions<typeof MaskedDynamic>, ReturnMasked extends MaskedDynamic=MaskedDynamic<Opts['parent']>> (opts: Opts): ReturnMasked;
6491
+ // // From mask opts
6492
+ // export default function createMask<Opts extends MaskedOptions<Masked>, ReturnMasked=Opts extends MaskedOptions<infer M> ? M : never> (opts: Opts): ReturnMasked;
6493
+ // export default function createMask<Opts extends MaskedNumberOptions, ReturnMasked extends MaskedNumber=MaskedNumber<Opts['parent']>> (opts: Opts): ReturnMasked;
6494
+ // export default function createMask<Opts extends MaskedDateFactoryOptions, ReturnMasked extends MaskedDate=MaskedDate<Opts['parent']>> (opts: Opts): ReturnMasked;
6495
+ // export default function createMask<Opts extends MaskedEnumOptions, ReturnMasked extends MaskedEnum=MaskedEnum<Opts['parent']>> (opts: Opts): ReturnMasked;
6496
+ // export default function createMask<Opts extends MaskedRangeOptions, ReturnMasked extends MaskedRange=MaskedRange<Opts['parent']>> (opts: Opts): ReturnMasked;
6497
+ // export default function createMask<Opts extends MaskedPatternOptions, ReturnMasked extends MaskedPattern=MaskedPattern<Opts['parent']>> (opts: Opts): ReturnMasked;
6498
+ // export default function createMask<Opts extends MaskedDynamicOptions, ReturnMasked extends MaskedDynamic=MaskedDynamic<Opts['parent']>> (opts: Opts): ReturnMasked;
6499
+ // export default function createMask<Opts extends MaskedOptions<RegExp>, ReturnMasked extends MaskedRegExp=MaskedRegExp<Opts['parent']>> (opts: Opts): ReturnMasked;
6500
+ // export default function createMask<Opts extends MaskedOptions<Function>, ReturnMasked extends MaskedFunction=MaskedFunction<Opts['parent']>> (opts: Opts): ReturnMasked;
6501
+
6502
+ /** Creates new {@link Masked} depending on mask type */
6503
+ function createMask(opts) {
6504
+ if (IMask.Masked && opts instanceof IMask.Masked) return opts;
6505
+ const nOpts = normalizeOpts(opts);
6506
+ const MaskedClass = maskedClass(nOpts.mask);
6507
+ 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.");
6508
+ if (nOpts.mask === MaskedClass) delete nOpts.mask;
6509
+ if (nOpts._mask) {
6510
+ nOpts.mask = nOpts._mask;
6511
+ delete nOpts._mask;
6512
+ }
6513
+ return new MaskedClass(nOpts);
6514
+ }
6515
+ IMask.createMask = createMask;
6516
+
6517
+ /** Generic element API to use with mask */
6518
+ class MaskElement {
6519
+ /** */
6520
+
6521
+ /** */
6522
+
6523
+ /** */
6524
+
6525
+ /** Safely returns selection start */
6526
+ get selectionStart() {
6527
+ let start;
6528
+ try {
6529
+ start = this._unsafeSelectionStart;
6530
+ } catch {}
6531
+ return start != null ? start : this.value.length;
6532
+ }
6533
+
6534
+ /** Safely returns selection end */
6535
+ get selectionEnd() {
6536
+ let end;
6537
+ try {
6538
+ end = this._unsafeSelectionEnd;
6539
+ } catch {}
6540
+ return end != null ? end : this.value.length;
6541
+ }
6542
+
6543
+ /** Safely sets element selection */
6544
+ select(start, end) {
6545
+ if (start == null || end == null || start === this.selectionStart && end === this.selectionEnd) return;
6546
+ try {
6547
+ this._unsafeSelect(start, end);
6548
+ } catch {}
6549
+ }
6550
+
6551
+ /** */
6552
+ get isActive() {
6553
+ return false;
6554
+ }
6555
+ /** */
6556
+
6557
+ /** */
6558
+
6559
+ /** */
6560
+ }
6561
+ IMask.MaskElement = MaskElement;
6562
+
6563
+ const KEY_Z = 90;
6564
+ const KEY_Y = 89;
6565
+
6566
+ /** Bridge between HTMLElement and {@link Masked} */
6567
+ class HTMLMaskElement extends MaskElement {
6568
+ /** HTMLElement to use mask on */
6569
+
6570
+ constructor(input) {
6571
+ super();
6572
+ this.input = input;
6573
+ this._onKeydown = this._onKeydown.bind(this);
6574
+ this._onInput = this._onInput.bind(this);
6575
+ this._onBeforeinput = this._onBeforeinput.bind(this);
6576
+ this._onCompositionEnd = this._onCompositionEnd.bind(this);
6577
+ }
6578
+ get rootElement() {
6579
+ var _this$input$getRootNo, _this$input$getRootNo2, _this$input;
6580
+ 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;
6581
+ }
6582
+
6583
+ /** Is element in focus */
6584
+ get isActive() {
6585
+ return this.input === this.rootElement.activeElement;
6586
+ }
6587
+
6588
+ /** Binds HTMLElement events to mask internal events */
6589
+ bindEvents(handlers) {
6590
+ this.input.addEventListener('keydown', this._onKeydown);
6591
+ this.input.addEventListener('input', this._onInput);
6592
+ this.input.addEventListener('beforeinput', this._onBeforeinput);
6593
+ this.input.addEventListener('compositionend', this._onCompositionEnd);
6594
+ this.input.addEventListener('drop', handlers.drop);
6595
+ this.input.addEventListener('click', handlers.click);
6596
+ this.input.addEventListener('focus', handlers.focus);
6597
+ this.input.addEventListener('blur', handlers.commit);
6598
+ this._handlers = handlers;
6599
+ }
6600
+ _onKeydown(e) {
6601
+ if (this._handlers.redo && (e.keyCode === KEY_Z && e.shiftKey && (e.metaKey || e.ctrlKey) || e.keyCode === KEY_Y && e.ctrlKey)) {
6602
+ e.preventDefault();
6603
+ return this._handlers.redo(e);
6604
+ }
6605
+ if (this._handlers.undo && e.keyCode === KEY_Z && (e.metaKey || e.ctrlKey)) {
6606
+ e.preventDefault();
6607
+ return this._handlers.undo(e);
6608
+ }
6609
+ if (!e.isComposing) this._handlers.selectionChange(e);
6610
+ }
6611
+ _onBeforeinput(e) {
6612
+ if (e.inputType === 'historyUndo' && this._handlers.undo) {
6613
+ e.preventDefault();
6614
+ return this._handlers.undo(e);
6615
+ }
6616
+ if (e.inputType === 'historyRedo' && this._handlers.redo) {
6617
+ e.preventDefault();
6618
+ return this._handlers.redo(e);
6619
+ }
6620
+ }
6621
+ _onCompositionEnd(e) {
6622
+ this._handlers.input(e);
6623
+ }
6624
+ _onInput(e) {
6625
+ if (!e.isComposing) this._handlers.input(e);
6626
+ }
6627
+
6628
+ /** Unbinds HTMLElement events to mask internal events */
6629
+ unbindEvents() {
6630
+ this.input.removeEventListener('keydown', this._onKeydown);
6631
+ this.input.removeEventListener('input', this._onInput);
6632
+ this.input.removeEventListener('beforeinput', this._onBeforeinput);
6633
+ this.input.removeEventListener('compositionend', this._onCompositionEnd);
6634
+ this.input.removeEventListener('drop', this._handlers.drop);
6635
+ this.input.removeEventListener('click', this._handlers.click);
6636
+ this.input.removeEventListener('focus', this._handlers.focus);
6637
+ this.input.removeEventListener('blur', this._handlers.commit);
6638
+ this._handlers = {};
6639
+ }
6640
+ }
6641
+ IMask.HTMLMaskElement = HTMLMaskElement;
6642
+
6643
+ /** Bridge between InputElement and {@link Masked} */
6644
+ class HTMLInputMaskElement extends HTMLMaskElement {
6645
+ /** InputElement to use mask on */
6646
+
6647
+ constructor(input) {
6648
+ super(input);
6649
+ this.input = input;
6650
+ }
6651
+
6652
+ /** Returns InputElement selection start */
6653
+ get _unsafeSelectionStart() {
6654
+ return this.input.selectionStart != null ? this.input.selectionStart : this.value.length;
6655
+ }
6656
+
6657
+ /** Returns InputElement selection end */
6658
+ get _unsafeSelectionEnd() {
6659
+ return this.input.selectionEnd;
6660
+ }
6661
+
6662
+ /** Sets InputElement selection */
6663
+ _unsafeSelect(start, end) {
6664
+ this.input.setSelectionRange(start, end);
6665
+ }
6666
+ get value() {
6667
+ return this.input.value;
6668
+ }
6669
+ set value(value) {
6670
+ this.input.value = value;
6671
+ }
6672
+ }
6673
+ IMask.HTMLMaskElement = HTMLMaskElement;
6674
+
6675
+ class HTMLContenteditableMaskElement extends HTMLMaskElement {
6676
+ /** Returns HTMLElement selection start */
6677
+ get _unsafeSelectionStart() {
6678
+ const root = this.rootElement;
6679
+ const selection = root.getSelection && root.getSelection();
6680
+ const anchorOffset = selection && selection.anchorOffset;
6681
+ const focusOffset = selection && selection.focusOffset;
6682
+ if (focusOffset == null || anchorOffset == null || anchorOffset < focusOffset) {
6683
+ return anchorOffset;
6684
+ }
6685
+ return focusOffset;
6686
+ }
6687
+
6688
+ /** Returns HTMLElement selection end */
6689
+ get _unsafeSelectionEnd() {
6690
+ const root = this.rootElement;
6691
+ const selection = root.getSelection && root.getSelection();
6692
+ const anchorOffset = selection && selection.anchorOffset;
6693
+ const focusOffset = selection && selection.focusOffset;
6694
+ if (focusOffset == null || anchorOffset == null || anchorOffset > focusOffset) {
6695
+ return anchorOffset;
6696
+ }
6697
+ return focusOffset;
6698
+ }
6699
+
6700
+ /** Sets HTMLElement selection */
6701
+ _unsafeSelect(start, end) {
6702
+ if (!this.rootElement.createRange) return;
6703
+ const range = this.rootElement.createRange();
6704
+ range.setStart(this.input.firstChild || this.input, start);
6705
+ range.setEnd(this.input.lastChild || this.input, end);
6706
+ const root = this.rootElement;
6707
+ const selection = root.getSelection && root.getSelection();
6708
+ if (selection) {
6709
+ selection.removeAllRanges();
6710
+ selection.addRange(range);
6711
+ }
6712
+ }
6713
+
6714
+ /** HTMLElement value */
6715
+ get value() {
6716
+ return this.input.textContent || '';
6717
+ }
6718
+ set value(value) {
6719
+ this.input.textContent = value;
6720
+ }
6721
+ }
6722
+ IMask.HTMLContenteditableMaskElement = HTMLContenteditableMaskElement;
6723
+
6724
+ class InputHistory {
6725
+ constructor() {
6726
+ this.states = [];
6727
+ this.currentIndex = 0;
6728
+ }
6729
+ get currentState() {
6730
+ return this.states[this.currentIndex];
6731
+ }
6732
+ get isEmpty() {
6733
+ return this.states.length === 0;
6734
+ }
6735
+ push(state) {
6736
+ // if current index points before the last element then remove the future
6737
+ if (this.currentIndex < this.states.length - 1) this.states.length = this.currentIndex + 1;
6738
+ this.states.push(state);
6739
+ if (this.states.length > InputHistory.MAX_LENGTH) this.states.shift();
6740
+ this.currentIndex = this.states.length - 1;
6741
+ }
6742
+ go(steps) {
6743
+ this.currentIndex = Math.min(Math.max(this.currentIndex + steps, 0), this.states.length - 1);
6744
+ return this.currentState;
6745
+ }
6746
+ undo() {
6747
+ return this.go(-1);
6748
+ }
6749
+ redo() {
6750
+ return this.go(1);
6751
+ }
6752
+ clear() {
6753
+ this.states.length = 0;
6754
+ this.currentIndex = 0;
6755
+ }
6756
+ }
6757
+ InputHistory.MAX_LENGTH = 100;
6758
+
6759
+ /** Listens to element events and controls changes between element and {@link Masked} */
6760
+ class InputMask {
6761
+ /**
6762
+ View element
6763
+ */
6764
+
6765
+ /** Internal {@link Masked} model */
6766
+
6767
+ constructor(el, opts) {
6768
+ this.el = el instanceof MaskElement ? el : el.isContentEditable && el.tagName !== 'INPUT' && el.tagName !== 'TEXTAREA' ? new HTMLContenteditableMaskElement(el) : new HTMLInputMaskElement(el);
6769
+ this.masked = createMask(opts);
6770
+ this._listeners = {};
6771
+ this._value = '';
6772
+ this._unmaskedValue = '';
6773
+ this._rawInputValue = '';
6774
+ this.history = new InputHistory();
6775
+ this._saveSelection = this._saveSelection.bind(this);
6776
+ this._onInput = this._onInput.bind(this);
6777
+ this._onChange = this._onChange.bind(this);
6778
+ this._onDrop = this._onDrop.bind(this);
6779
+ this._onFocus = this._onFocus.bind(this);
6780
+ this._onClick = this._onClick.bind(this);
6781
+ this._onUndo = this._onUndo.bind(this);
6782
+ this._onRedo = this._onRedo.bind(this);
6783
+ this.alignCursor = this.alignCursor.bind(this);
6784
+ this.alignCursorFriendly = this.alignCursorFriendly.bind(this);
6785
+ this._bindEvents();
6786
+
6787
+ // refresh
6788
+ this.updateValue();
6789
+ this._onChange();
6790
+ }
6791
+ maskEquals(mask) {
6792
+ var _this$masked;
6793
+ return mask == null || ((_this$masked = this.masked) == null ? void 0 : _this$masked.maskEquals(mask));
6794
+ }
6795
+
6796
+ /** Masked */
6797
+ get mask() {
6798
+ return this.masked.mask;
6799
+ }
6800
+ set mask(mask) {
6801
+ if (this.maskEquals(mask)) return;
6802
+ if (!(mask instanceof IMask.Masked) && this.masked.constructor === maskedClass(mask)) {
6803
+ // TODO "any" no idea
6804
+ this.masked.updateOptions({
6805
+ mask
6806
+ });
6807
+ return;
6808
+ }
6809
+ const masked = mask instanceof IMask.Masked ? mask : createMask({
6810
+ mask
6811
+ });
6812
+ masked.unmaskedValue = this.masked.unmaskedValue;
6813
+ this.masked = masked;
6814
+ }
6815
+
6816
+ /** Raw value */
6817
+ get value() {
6818
+ return this._value;
6819
+ }
6820
+ set value(str) {
6821
+ if (this.value === str) return;
6822
+ this.masked.value = str;
6823
+ this.updateControl('auto');
6824
+ }
6825
+
6826
+ /** Unmasked value */
6827
+ get unmaskedValue() {
6828
+ return this._unmaskedValue;
6829
+ }
6830
+ set unmaskedValue(str) {
6831
+ if (this.unmaskedValue === str) return;
6832
+ this.masked.unmaskedValue = str;
6833
+ this.updateControl('auto');
6834
+ }
6835
+
6836
+ /** Raw input value */
6837
+ get rawInputValue() {
6838
+ return this._rawInputValue;
6839
+ }
6840
+ set rawInputValue(str) {
6841
+ if (this.rawInputValue === str) return;
6842
+ this.masked.rawInputValue = str;
6843
+ this.updateControl();
6844
+ this.alignCursor();
6845
+ }
6846
+
6847
+ /** Typed unmasked value */
6848
+ get typedValue() {
6849
+ return this.masked.typedValue;
6850
+ }
6851
+ set typedValue(val) {
6852
+ if (this.masked.typedValueEquals(val)) return;
6853
+ this.masked.typedValue = val;
6854
+ this.updateControl('auto');
6855
+ }
6856
+
6857
+ /** Display value */
6858
+ get displayValue() {
6859
+ return this.masked.displayValue;
6860
+ }
6861
+
6862
+ /** Starts listening to element events */
6863
+ _bindEvents() {
6864
+ this.el.bindEvents({
6865
+ selectionChange: this._saveSelection,
6866
+ input: this._onInput,
6867
+ drop: this._onDrop,
6868
+ click: this._onClick,
6869
+ focus: this._onFocus,
6870
+ commit: this._onChange,
6871
+ undo: this._onUndo,
6872
+ redo: this._onRedo
6873
+ });
6874
+ }
6875
+
6876
+ /** Stops listening to element events */
6877
+ _unbindEvents() {
6878
+ if (this.el) this.el.unbindEvents();
6879
+ }
6880
+
6881
+ /** Fires custom event */
6882
+ _fireEvent(ev, e) {
6883
+ const listeners = this._listeners[ev];
6884
+ if (!listeners) return;
6885
+ listeners.forEach(l => l(e));
6886
+ }
6887
+
6888
+ /** Current selection start */
6889
+ get selectionStart() {
6890
+ return this._cursorChanging ? this._changingCursorPos : this.el.selectionStart;
6891
+ }
6892
+
6893
+ /** Current cursor position */
6894
+ get cursorPos() {
6895
+ return this._cursorChanging ? this._changingCursorPos : this.el.selectionEnd;
6896
+ }
6897
+ set cursorPos(pos) {
6898
+ if (!this.el || !this.el.isActive) return;
6899
+ this.el.select(pos, pos);
6900
+ this._saveSelection();
6901
+ }
6902
+
6903
+ /** Stores current selection */
6904
+ _saveSelection( /* ev */
6905
+ ) {
6906
+ if (this.displayValue !== this.el.value) {
6907
+ console.warn('Element value was changed outside of mask. Syncronize mask using `mask.updateValue()` to work properly.'); // eslint-disable-line no-console
6908
+ }
6909
+ this._selection = {
6910
+ start: this.selectionStart,
6911
+ end: this.cursorPos
6912
+ };
6913
+ }
6914
+
6915
+ /** Syncronizes model value from view */
6916
+ updateValue() {
6917
+ this.masked.value = this.el.value;
6918
+ this._value = this.masked.value;
6919
+ this._unmaskedValue = this.masked.unmaskedValue;
6920
+ this._rawInputValue = this.masked.rawInputValue;
6921
+ }
6922
+
6923
+ /** Syncronizes view from model value, fires change events */
6924
+ updateControl(cursorPos) {
6925
+ const newUnmaskedValue = this.masked.unmaskedValue;
6926
+ const newValue = this.masked.value;
6927
+ const newRawInputValue = this.masked.rawInputValue;
6928
+ const newDisplayValue = this.displayValue;
6929
+ const isChanged = this.unmaskedValue !== newUnmaskedValue || this.value !== newValue || this._rawInputValue !== newRawInputValue;
6930
+ this._unmaskedValue = newUnmaskedValue;
6931
+ this._value = newValue;
6932
+ this._rawInputValue = newRawInputValue;
6933
+ if (this.el.value !== newDisplayValue) this.el.value = newDisplayValue;
6934
+ if (cursorPos === 'auto') this.alignCursor();else if (cursorPos != null) this.cursorPos = cursorPos;
6935
+ if (isChanged) this._fireChangeEvents();
6936
+ if (!this._historyChanging && (isChanged || this.history.isEmpty)) this.history.push({
6937
+ unmaskedValue: newUnmaskedValue,
6938
+ selection: {
6939
+ start: this.selectionStart,
6940
+ end: this.cursorPos
6941
+ }
6942
+ });
6943
+ }
6944
+
6945
+ /** Updates options with deep equal check, recreates {@link Masked} model if mask type changes */
6946
+ updateOptions(opts) {
6947
+ const {
6948
+ mask,
6949
+ ...restOpts
6950
+ } = opts; // TODO types, yes, mask is optional
6951
+
6952
+ const updateMask = !this.maskEquals(mask);
6953
+ const updateOpts = this.masked.optionsIsChanged(restOpts);
6954
+ if (updateMask) this.mask = mask;
6955
+ if (updateOpts) this.masked.updateOptions(restOpts); // TODO
6956
+
6957
+ if (updateMask || updateOpts) this.updateControl();
6958
+ }
6959
+
6960
+ /** Updates cursor */
6961
+ updateCursor(cursorPos) {
6962
+ if (cursorPos == null) return;
6963
+ this.cursorPos = cursorPos;
6964
+
6965
+ // also queue change cursor for mobile browsers
6966
+ this._delayUpdateCursor(cursorPos);
6967
+ }
6968
+
6969
+ /** Delays cursor update to support mobile browsers */
6970
+ _delayUpdateCursor(cursorPos) {
6971
+ this._abortUpdateCursor();
6972
+ this._changingCursorPos = cursorPos;
6973
+ this._cursorChanging = setTimeout(() => {
6974
+ if (!this.el) return; // if was destroyed
6975
+ this.cursorPos = this._changingCursorPos;
6976
+ this._abortUpdateCursor();
6977
+ }, 10);
6978
+ }
6979
+
6980
+ /** Fires custom events */
6981
+ _fireChangeEvents() {
6982
+ this._fireEvent('accept', this._inputEvent);
6983
+ if (this.masked.isComplete) this._fireEvent('complete', this._inputEvent);
6984
+ }
6985
+
6986
+ /** Aborts delayed cursor update */
6987
+ _abortUpdateCursor() {
6988
+ if (this._cursorChanging) {
6989
+ clearTimeout(this._cursorChanging);
6990
+ delete this._cursorChanging;
6991
+ }
6992
+ }
6993
+
6994
+ /** Aligns cursor to nearest available position */
6995
+ alignCursor() {
6996
+ this.cursorPos = this.masked.nearestInputPos(this.masked.nearestInputPos(this.cursorPos, DIRECTION.LEFT));
6997
+ }
6998
+
6999
+ /** Aligns cursor only if selection is empty */
7000
+ alignCursorFriendly() {
7001
+ if (this.selectionStart !== this.cursorPos) return; // skip if range is selected
7002
+ this.alignCursor();
7003
+ }
7004
+
7005
+ /** Adds listener on custom event */
7006
+ on(ev, handler) {
7007
+ if (!this._listeners[ev]) this._listeners[ev] = [];
7008
+ this._listeners[ev].push(handler);
7009
+ return this;
7010
+ }
7011
+
7012
+ /** Removes custom event listener */
7013
+ off(ev, handler) {
7014
+ if (!this._listeners[ev]) return this;
7015
+ if (!handler) {
7016
+ delete this._listeners[ev];
7017
+ return this;
7018
+ }
7019
+ const hIndex = this._listeners[ev].indexOf(handler);
7020
+ if (hIndex >= 0) this._listeners[ev].splice(hIndex, 1);
7021
+ return this;
7022
+ }
7023
+
7024
+ /** Handles view input event */
7025
+ _onInput(e) {
7026
+ this._inputEvent = e;
7027
+ this._abortUpdateCursor();
7028
+ const details = new ActionDetails({
7029
+ // new state
7030
+ value: this.el.value,
7031
+ cursorPos: this.cursorPos,
7032
+ // old state
7033
+ oldValue: this.displayValue,
7034
+ oldSelection: this._selection
7035
+ });
7036
+ const oldRawValue = this.masked.rawInputValue;
7037
+ const offset = this.masked.splice(details.startChangePos, details.removed.length, details.inserted, details.removeDirection, {
7038
+ input: true,
7039
+ raw: true
7040
+ }).offset;
7041
+
7042
+ // force align in remove direction only if no input chars were removed
7043
+ // otherwise we still need to align with NONE (to get out from fixed symbols for instance)
7044
+ const removeDirection = oldRawValue === this.masked.rawInputValue ? details.removeDirection : DIRECTION.NONE;
7045
+ let cursorPos = this.masked.nearestInputPos(details.startChangePos + offset, removeDirection);
7046
+ if (removeDirection !== DIRECTION.NONE) cursorPos = this.masked.nearestInputPos(cursorPos, DIRECTION.NONE);
7047
+ this.updateControl(cursorPos);
7048
+ delete this._inputEvent;
7049
+ }
7050
+
7051
+ /** Handles view change event and commits model value */
7052
+ _onChange() {
7053
+ if (this.displayValue !== this.el.value) this.updateValue();
7054
+ this.masked.doCommit();
7055
+ this.updateControl();
7056
+ this._saveSelection();
7057
+ }
7058
+
7059
+ /** Handles view drop event, prevents by default */
7060
+ _onDrop(ev) {
7061
+ ev.preventDefault();
7062
+ ev.stopPropagation();
7063
+ }
7064
+
7065
+ /** Restore last selection on focus */
7066
+ _onFocus(ev) {
7067
+ this.alignCursorFriendly();
7068
+ }
7069
+
7070
+ /** Restore last selection on focus */
7071
+ _onClick(ev) {
7072
+ this.alignCursorFriendly();
7073
+ }
7074
+ _onUndo() {
7075
+ this._applyHistoryState(this.history.undo());
7076
+ }
7077
+ _onRedo() {
7078
+ this._applyHistoryState(this.history.redo());
7079
+ }
7080
+ _applyHistoryState(state) {
7081
+ if (!state) return;
7082
+ this._historyChanging = true;
7083
+ this.unmaskedValue = state.unmaskedValue;
7084
+ this.el.select(state.selection.start, state.selection.end);
7085
+ this._saveSelection();
7086
+ this._historyChanging = false;
7087
+ }
7088
+
7089
+ /** Unbind view events and removes element reference */
7090
+ destroy() {
7091
+ this._unbindEvents();
7092
+ this._listeners.length = 0;
7093
+ delete this.el;
7094
+ }
7095
+ }
7096
+ IMask.InputMask = InputMask;
7097
+
7098
+ /** Provides details of changing model value */
7099
+ class ChangeDetails {
7100
+ /** Inserted symbols */
7101
+
7102
+ /** Additional offset if any changes occurred before tail */
7103
+
7104
+ /** Raw inserted is used by dynamic mask */
7105
+
7106
+ /** Can skip chars */
7107
+
7108
+ static normalize(prep) {
7109
+ return Array.isArray(prep) ? prep : [prep, new ChangeDetails()];
7110
+ }
7111
+ constructor(details) {
7112
+ Object.assign(this, {
7113
+ inserted: '',
7114
+ rawInserted: '',
7115
+ tailShift: 0,
7116
+ skip: false
7117
+ }, details);
7118
+ }
7119
+
7120
+ /** Aggregate changes */
7121
+ aggregate(details) {
7122
+ this.inserted += details.inserted;
7123
+ this.rawInserted += details.rawInserted;
7124
+ this.tailShift += details.tailShift;
7125
+ this.skip = this.skip || details.skip;
7126
+ return this;
7127
+ }
7128
+
7129
+ /** Total offset considering all changes */
7130
+ get offset() {
7131
+ return this.tailShift + this.inserted.length;
7132
+ }
7133
+ get consumed() {
7134
+ return Boolean(this.rawInserted) || this.skip;
7135
+ }
7136
+ equals(details) {
7137
+ return this.inserted === details.inserted && this.tailShift === details.tailShift && this.rawInserted === details.rawInserted && this.skip === details.skip;
7138
+ }
7139
+ }
7140
+ IMask.ChangeDetails = ChangeDetails;
7141
+
7142
+ /** Provides details of continuous extracted tail */
7143
+ class ContinuousTailDetails {
7144
+ /** Tail value as string */
7145
+
7146
+ /** Tail start position */
7147
+
7148
+ /** Start position */
7149
+
7150
+ constructor(value, from, stop) {
7151
+ if (value === void 0) {
7152
+ value = '';
7153
+ }
7154
+ if (from === void 0) {
7155
+ from = 0;
7156
+ }
7157
+ this.value = value;
7158
+ this.from = from;
7159
+ this.stop = stop;
7160
+ }
7161
+ toString() {
7162
+ return this.value;
7163
+ }
7164
+ extend(tail) {
7165
+ this.value += String(tail);
7166
+ }
7167
+ appendTo(masked) {
7168
+ return masked.append(this.toString(), {
7169
+ tail: true
7170
+ }).aggregate(masked._appendPlaceholder());
7171
+ }
7172
+ get state() {
7173
+ return {
7174
+ value: this.value,
7175
+ from: this.from,
7176
+ stop: this.stop
7177
+ };
7178
+ }
7179
+ set state(state) {
7180
+ Object.assign(this, state);
7181
+ }
7182
+ unshift(beforePos) {
7183
+ if (!this.value.length || beforePos != null && this.from >= beforePos) return '';
7184
+ const shiftChar = this.value[0];
7185
+ this.value = this.value.slice(1);
7186
+ return shiftChar;
7187
+ }
7188
+ shift() {
7189
+ if (!this.value.length) return '';
7190
+ const shiftChar = this.value[this.value.length - 1];
7191
+ this.value = this.value.slice(0, -1);
7192
+ return shiftChar;
7193
+ }
7194
+ }
7195
+
7196
+ /** Append flags */
7197
+
7198
+ /** Extract flags */
7199
+
7200
+ // see https://github.com/microsoft/TypeScript/issues/6223
7201
+
7202
+ /** Provides common masking stuff */
7203
+ class Masked {
7204
+ /** */
7205
+
7206
+ /** */
7207
+
7208
+ /** Transforms value before mask processing */
7209
+
7210
+ /** Transforms each char before mask processing */
7211
+
7212
+ /** Validates if value is acceptable */
7213
+
7214
+ /** Does additional processing at the end of editing */
7215
+
7216
+ /** Format typed value to string */
7217
+
7218
+ /** Parse string to get typed value */
7219
+
7220
+ /** Enable characters overwriting */
7221
+
7222
+ /** */
7223
+
7224
+ /** */
7225
+
7226
+ /** */
7227
+
7228
+ /** */
7229
+
7230
+ constructor(opts) {
7231
+ this._value = '';
7232
+ this._update({
7233
+ ...Masked.DEFAULTS,
7234
+ ...opts
7235
+ });
7236
+ this._initialized = true;
7237
+ }
7238
+
7239
+ /** Sets and applies new options */
7240
+ updateOptions(opts) {
7241
+ if (!this.optionsIsChanged(opts)) return;
7242
+ this.withValueRefresh(this._update.bind(this, opts));
7243
+ }
7244
+
7245
+ /** Sets new options */
7246
+ _update(opts) {
7247
+ Object.assign(this, opts);
7248
+ }
7249
+
7250
+ /** Mask state */
7251
+ get state() {
7252
+ return {
7253
+ _value: this.value,
7254
+ _rawInputValue: this.rawInputValue
7255
+ };
7256
+ }
7257
+ set state(state) {
7258
+ this._value = state._value;
7259
+ }
7260
+
7261
+ /** Resets value */
7262
+ reset() {
7263
+ this._value = '';
7264
+ }
7265
+ get value() {
7266
+ return this._value;
7267
+ }
7268
+ set value(value) {
7269
+ this.resolve(value, {
7270
+ input: true
7271
+ });
7272
+ }
7273
+
7274
+ /** Resolve new value */
7275
+ resolve(value, flags) {
7276
+ if (flags === void 0) {
7277
+ flags = {
7278
+ input: true
7279
+ };
7280
+ }
7281
+ this.reset();
7282
+ this.append(value, flags, '');
7283
+ this.doCommit();
7284
+ }
7285
+ get unmaskedValue() {
7286
+ return this.value;
7287
+ }
7288
+ set unmaskedValue(value) {
7289
+ this.resolve(value, {});
7290
+ }
7291
+ get typedValue() {
7292
+ return this.parse ? this.parse(this.value, this) : this.unmaskedValue;
7293
+ }
7294
+ set typedValue(value) {
7295
+ if (this.format) {
7296
+ this.value = this.format(value, this);
7297
+ } else {
7298
+ this.unmaskedValue = String(value);
7299
+ }
7300
+ }
7301
+
7302
+ /** Value that includes raw user input */
7303
+ get rawInputValue() {
7304
+ return this.extractInput(0, this.displayValue.length, {
7305
+ raw: true
7306
+ });
7307
+ }
7308
+ set rawInputValue(value) {
7309
+ this.resolve(value, {
7310
+ raw: true
7311
+ });
7312
+ }
7313
+ get displayValue() {
7314
+ return this.value;
7315
+ }
7316
+ get isComplete() {
7317
+ return true;
7318
+ }
7319
+ get isFilled() {
7320
+ return this.isComplete;
7321
+ }
7322
+
7323
+ /** Finds nearest input position in direction */
7324
+ nearestInputPos(cursorPos, direction) {
7325
+ return cursorPos;
7326
+ }
7327
+ totalInputPositions(fromPos, toPos) {
7328
+ if (fromPos === void 0) {
7329
+ fromPos = 0;
7330
+ }
7331
+ if (toPos === void 0) {
7332
+ toPos = this.displayValue.length;
7333
+ }
7334
+ return Math.min(this.displayValue.length, toPos - fromPos);
7335
+ }
7336
+
7337
+ /** Extracts value in range considering flags */
7338
+ extractInput(fromPos, toPos, flags) {
7339
+ if (fromPos === void 0) {
7340
+ fromPos = 0;
7341
+ }
7342
+ if (toPos === void 0) {
7343
+ toPos = this.displayValue.length;
7344
+ }
7345
+ return this.displayValue.slice(fromPos, toPos);
7346
+ }
7347
+
7348
+ /** Extracts tail in range */
7349
+ extractTail(fromPos, toPos) {
7350
+ if (fromPos === void 0) {
7351
+ fromPos = 0;
7352
+ }
7353
+ if (toPos === void 0) {
7354
+ toPos = this.displayValue.length;
7355
+ }
7356
+ return new ContinuousTailDetails(this.extractInput(fromPos, toPos), fromPos);
7357
+ }
7358
+
7359
+ /** Appends tail */
7360
+ appendTail(tail) {
7361
+ if (isString(tail)) tail = new ContinuousTailDetails(String(tail));
7362
+ return tail.appendTo(this);
7363
+ }
7364
+
7365
+ /** Appends char */
7366
+ _appendCharRaw(ch, flags) {
7367
+ if (!ch) return new ChangeDetails();
7368
+ this._value += ch;
7369
+ return new ChangeDetails({
7370
+ inserted: ch,
7371
+ rawInserted: ch
7372
+ });
7373
+ }
7374
+
7375
+ /** Appends char */
7376
+ _appendChar(ch, flags, checkTail) {
7377
+ if (flags === void 0) {
7378
+ flags = {};
7379
+ }
7380
+ const consistentState = this.state;
7381
+ let details;
7382
+ [ch, details] = this.doPrepareChar(ch, flags);
7383
+ if (ch) {
7384
+ details = details.aggregate(this._appendCharRaw(ch, flags));
7385
+
7386
+ // TODO handle `skip`?
7387
+
7388
+ // try `autofix` lookahead
7389
+ if (!details.rawInserted && this.autofix === 'pad') {
7390
+ const noFixState = this.state;
7391
+ this.state = consistentState;
7392
+ let fixDetails = this.pad(flags);
7393
+ const chDetails = this._appendCharRaw(ch, flags);
7394
+ fixDetails = fixDetails.aggregate(chDetails);
7395
+
7396
+ // if fix was applied or
7397
+ // if details are equal use skip restoring state optimization
7398
+ if (chDetails.rawInserted || fixDetails.equals(details)) {
7399
+ details = fixDetails;
7400
+ } else {
7401
+ this.state = noFixState;
7402
+ }
7403
+ }
7404
+ }
7405
+ if (details.inserted) {
7406
+ let consistentTail;
7407
+ let appended = this.doValidate(flags) !== false;
7408
+ if (appended && checkTail != null) {
7409
+ // validation ok, check tail
7410
+ const beforeTailState = this.state;
7411
+ if (this.overwrite === true) {
7412
+ consistentTail = checkTail.state;
7413
+ for (let i = 0; i < details.rawInserted.length; ++i) {
7414
+ checkTail.unshift(this.displayValue.length - details.tailShift);
7415
+ }
7416
+ }
7417
+ let tailDetails = this.appendTail(checkTail);
7418
+ appended = tailDetails.rawInserted.length === checkTail.toString().length;
7419
+
7420
+ // not ok, try shift
7421
+ if (!(appended && tailDetails.inserted) && this.overwrite === 'shift') {
7422
+ this.state = beforeTailState;
7423
+ consistentTail = checkTail.state;
7424
+ for (let i = 0; i < details.rawInserted.length; ++i) {
7425
+ checkTail.shift();
7426
+ }
7427
+ tailDetails = this.appendTail(checkTail);
7428
+ appended = tailDetails.rawInserted.length === checkTail.toString().length;
7429
+ }
7430
+
7431
+ // if ok, rollback state after tail
7432
+ if (appended && tailDetails.inserted) this.state = beforeTailState;
7433
+ }
7434
+
7435
+ // revert all if something went wrong
7436
+ if (!appended) {
7437
+ details = new ChangeDetails();
7438
+ this.state = consistentState;
7439
+ if (checkTail && consistentTail) checkTail.state = consistentTail;
7440
+ }
7441
+ }
7442
+ return details;
7443
+ }
7444
+
7445
+ /** Appends optional placeholder at the end */
7446
+ _appendPlaceholder() {
7447
+ return new ChangeDetails();
7448
+ }
7449
+
7450
+ /** Appends optional eager placeholder at the end */
7451
+ _appendEager() {
7452
+ return new ChangeDetails();
7453
+ }
7454
+
7455
+ /** Appends symbols considering flags */
7456
+ append(str, flags, tail) {
7457
+ if (!isString(str)) throw new Error('value should be string');
7458
+ const checkTail = isString(tail) ? new ContinuousTailDetails(String(tail)) : tail;
7459
+ if (flags != null && flags.tail) flags._beforeTailState = this.state;
7460
+ let details;
7461
+ [str, details] = this.doPrepare(str, flags);
7462
+ for (let ci = 0; ci < str.length; ++ci) {
7463
+ const d = this._appendChar(str[ci], flags, checkTail);
7464
+ if (!d.rawInserted && !this.doSkipInvalid(str[ci], flags, checkTail)) break;
7465
+ details.aggregate(d);
7466
+ }
7467
+ if ((this.eager === true || this.eager === 'append') && flags != null && flags.input && str) {
7468
+ details.aggregate(this._appendEager());
7469
+ }
7470
+
7471
+ // append tail but aggregate only tailShift
7472
+ if (checkTail != null) {
7473
+ details.tailShift += this.appendTail(checkTail).tailShift;
7474
+ // TODO it's a good idea to clear state after appending ends
7475
+ // but it causes bugs when one append calls another (when dynamic dispatch set rawInputValue)
7476
+ // this._resetBeforeTailState();
7477
+ }
7478
+ return details;
7479
+ }
7480
+ remove(fromPos, toPos) {
7481
+ if (fromPos === void 0) {
7482
+ fromPos = 0;
7483
+ }
7484
+ if (toPos === void 0) {
7485
+ toPos = this.displayValue.length;
7486
+ }
7487
+ this._value = this.displayValue.slice(0, fromPos) + this.displayValue.slice(toPos);
7488
+ return new ChangeDetails();
7489
+ }
7490
+
7491
+ /** Calls function and reapplies current value */
7492
+ withValueRefresh(fn) {
7493
+ if (this._refreshing || !this._initialized) return fn();
7494
+ this._refreshing = true;
7495
+ const rawInput = this.rawInputValue;
7496
+ const value = this.value;
7497
+ const ret = fn();
7498
+ this.rawInputValue = rawInput;
7499
+ // append lost trailing chars at the end
7500
+ if (this.value && this.value !== value && value.indexOf(this.value) === 0) {
7501
+ this.append(value.slice(this.displayValue.length), {}, '');
7502
+ this.doCommit();
7503
+ }
7504
+ delete this._refreshing;
7505
+ return ret;
7506
+ }
7507
+ runIsolated(fn) {
7508
+ if (this._isolated || !this._initialized) return fn(this);
7509
+ this._isolated = true;
7510
+ const state = this.state;
7511
+ const ret = fn(this);
7512
+ this.state = state;
7513
+ delete this._isolated;
7514
+ return ret;
7515
+ }
7516
+ doSkipInvalid(ch, flags, checkTail) {
7517
+ return Boolean(this.skipInvalid);
7518
+ }
7519
+
7520
+ /** Prepares string before mask processing */
7521
+ doPrepare(str, flags) {
7522
+ if (flags === void 0) {
7523
+ flags = {};
7524
+ }
7525
+ return ChangeDetails.normalize(this.prepare ? this.prepare(str, this, flags) : str);
7526
+ }
7527
+
7528
+ /** Prepares each char before mask processing */
7529
+ doPrepareChar(str, flags) {
7530
+ if (flags === void 0) {
7531
+ flags = {};
7532
+ }
7533
+ return ChangeDetails.normalize(this.prepareChar ? this.prepareChar(str, this, flags) : str);
7534
+ }
7535
+
7536
+ /** Validates if value is acceptable */
7537
+ doValidate(flags) {
7538
+ return (!this.validate || this.validate(this.value, this, flags)) && (!this.parent || this.parent.doValidate(flags));
7539
+ }
7540
+
7541
+ /** Does additional processing at the end of editing */
7542
+ doCommit() {
7543
+ if (this.commit) this.commit(this.value, this);
7544
+ }
7545
+ splice(start, deleteCount, inserted, removeDirection, flags) {
7546
+ if (inserted === void 0) {
7547
+ inserted = '';
7548
+ }
7549
+ if (removeDirection === void 0) {
7550
+ removeDirection = DIRECTION.NONE;
7551
+ }
7552
+ if (flags === void 0) {
7553
+ flags = {
7554
+ input: true
7555
+ };
7556
+ }
7557
+ const tailPos = start + deleteCount;
7558
+ const tail = this.extractTail(tailPos);
7559
+ const eagerRemove = this.eager === true || this.eager === 'remove';
7560
+ let oldRawValue;
7561
+ if (eagerRemove) {
7562
+ removeDirection = forceDirection(removeDirection);
7563
+ oldRawValue = this.extractInput(0, tailPos, {
7564
+ raw: true
7565
+ });
7566
+ }
7567
+ let startChangePos = start;
7568
+ const details = new ChangeDetails();
7569
+
7570
+ // if it is just deletion without insertion
7571
+ if (removeDirection !== DIRECTION.NONE) {
7572
+ startChangePos = this.nearestInputPos(start, deleteCount > 1 && start !== 0 && !eagerRemove ? DIRECTION.NONE : removeDirection);
7573
+
7574
+ // adjust tailShift if start was aligned
7575
+ details.tailShift = startChangePos - start;
7576
+ }
7577
+ details.aggregate(this.remove(startChangePos));
7578
+ if (eagerRemove && removeDirection !== DIRECTION.NONE && oldRawValue === this.rawInputValue) {
7579
+ if (removeDirection === DIRECTION.FORCE_LEFT) {
7580
+ let valLength;
7581
+ while (oldRawValue === this.rawInputValue && (valLength = this.displayValue.length)) {
7582
+ details.aggregate(new ChangeDetails({
7583
+ tailShift: -1
7584
+ })).aggregate(this.remove(valLength - 1));
7585
+ }
7586
+ } else if (removeDirection === DIRECTION.FORCE_RIGHT) {
7587
+ tail.unshift();
7588
+ }
7589
+ }
7590
+ return details.aggregate(this.append(inserted, flags, tail));
7591
+ }
7592
+ maskEquals(mask) {
7593
+ return this.mask === mask;
7594
+ }
7595
+ optionsIsChanged(opts) {
7596
+ return !objectIncludes(this, opts);
7597
+ }
7598
+ typedValueEquals(value) {
7599
+ const tval = this.typedValue;
7600
+ 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);
7601
+ }
7602
+ pad(flags) {
7603
+ return new ChangeDetails();
7604
+ }
7605
+ }
7606
+ Masked.DEFAULTS = {
7607
+ skipInvalid: true
7608
+ };
7609
+ Masked.EMPTY_VALUES = [undefined, null, ''];
7610
+ IMask.Masked = Masked;
7611
+
7612
+ class ChunksTailDetails {
7613
+ /** */
7614
+
7615
+ constructor(chunks, from) {
7616
+ if (chunks === void 0) {
7617
+ chunks = [];
7618
+ }
7619
+ if (from === void 0) {
7620
+ from = 0;
7621
+ }
7622
+ this.chunks = chunks;
7623
+ this.from = from;
7624
+ }
7625
+ toString() {
7626
+ return this.chunks.map(String).join('');
7627
+ }
7628
+ extend(tailChunk) {
7629
+ if (!String(tailChunk)) return;
7630
+ tailChunk = isString(tailChunk) ? new ContinuousTailDetails(String(tailChunk)) : tailChunk;
7631
+ const lastChunk = this.chunks[this.chunks.length - 1];
7632
+ const extendLast = lastChunk && (
7633
+ // if stops are same or tail has no stop
7634
+ lastChunk.stop === tailChunk.stop || tailChunk.stop == null) &&
7635
+ // if tail chunk goes just after last chunk
7636
+ tailChunk.from === lastChunk.from + lastChunk.toString().length;
7637
+ if (tailChunk instanceof ContinuousTailDetails) {
7638
+ // check the ability to extend previous chunk
7639
+ if (extendLast) {
7640
+ // extend previous chunk
7641
+ lastChunk.extend(tailChunk.toString());
7642
+ } else {
7643
+ // append new chunk
7644
+ this.chunks.push(tailChunk);
7645
+ }
7646
+ } else if (tailChunk instanceof ChunksTailDetails) {
7647
+ if (tailChunk.stop == null) {
7648
+ // unwrap floating chunks to parent, keeping `from` pos
7649
+ let firstTailChunk;
7650
+ while (tailChunk.chunks.length && tailChunk.chunks[0].stop == null) {
7651
+ firstTailChunk = tailChunk.chunks.shift(); // not possible to be `undefined` because length was checked above
7652
+ firstTailChunk.from += tailChunk.from;
7653
+ this.extend(firstTailChunk);
7654
+ }
7655
+ }
7656
+
7657
+ // if tail chunk still has value
7658
+ if (tailChunk.toString()) {
7659
+ // if chunks contains stops, then popup stop to container
7660
+ tailChunk.stop = tailChunk.blockIndex;
7661
+ this.chunks.push(tailChunk);
7662
+ }
7663
+ }
7664
+ }
7665
+ appendTo(masked) {
7666
+ if (!(masked instanceof IMask.MaskedPattern)) {
7667
+ const tail = new ContinuousTailDetails(this.toString());
7668
+ return tail.appendTo(masked);
7669
+ }
7670
+ const details = new ChangeDetails();
7671
+ for (let ci = 0; ci < this.chunks.length; ++ci) {
7672
+ const chunk = this.chunks[ci];
7673
+ const lastBlockIter = masked._mapPosToBlock(masked.displayValue.length);
7674
+ const stop = chunk.stop;
7675
+ let chunkBlock;
7676
+ if (stop != null && (
7677
+ // if block not found or stop is behind lastBlock
7678
+ !lastBlockIter || lastBlockIter.index <= stop)) {
7679
+ if (chunk instanceof ChunksTailDetails ||
7680
+ // for continuous block also check if stop is exist
7681
+ masked._stops.indexOf(stop) >= 0) {
7682
+ details.aggregate(masked._appendPlaceholder(stop));
7683
+ }
7684
+ chunkBlock = chunk instanceof ChunksTailDetails && masked._blocks[stop];
7685
+ }
7686
+ if (chunkBlock) {
7687
+ const tailDetails = chunkBlock.appendTail(chunk);
7688
+ details.aggregate(tailDetails);
7689
+
7690
+ // get not inserted chars
7691
+ const remainChars = chunk.toString().slice(tailDetails.rawInserted.length);
7692
+ if (remainChars) details.aggregate(masked.append(remainChars, {
7693
+ tail: true
7694
+ }));
7695
+ } else {
7696
+ details.aggregate(masked.append(chunk.toString(), {
7697
+ tail: true
7698
+ }));
7699
+ }
7700
+ }
7701
+ return details;
7702
+ }
7703
+ get state() {
7704
+ return {
7705
+ chunks: this.chunks.map(c => c.state),
7706
+ from: this.from,
7707
+ stop: this.stop,
7708
+ blockIndex: this.blockIndex
7709
+ };
7710
+ }
7711
+ set state(state) {
7712
+ const {
7713
+ chunks,
7714
+ ...props
7715
+ } = state;
7716
+ Object.assign(this, props);
7717
+ this.chunks = chunks.map(cstate => {
7718
+ const chunk = "chunks" in cstate ? new ChunksTailDetails() : new ContinuousTailDetails();
7719
+ chunk.state = cstate;
7720
+ return chunk;
7721
+ });
7722
+ }
7723
+ unshift(beforePos) {
7724
+ if (!this.chunks.length || beforePos != null && this.from >= beforePos) return '';
7725
+ const chunkShiftPos = beforePos != null ? beforePos - this.from : beforePos;
7726
+ let ci = 0;
7727
+ while (ci < this.chunks.length) {
7728
+ const chunk = this.chunks[ci];
7729
+ const shiftChar = chunk.unshift(chunkShiftPos);
7730
+ if (chunk.toString()) {
7731
+ // chunk still contains value
7732
+ // but not shifted - means no more available chars to shift
7733
+ if (!shiftChar) break;
7734
+ ++ci;
7735
+ } else {
7736
+ // clean if chunk has no value
7737
+ this.chunks.splice(ci, 1);
7738
+ }
7739
+ if (shiftChar) return shiftChar;
7740
+ }
7741
+ return '';
7742
+ }
7743
+ shift() {
7744
+ if (!this.chunks.length) return '';
7745
+ let ci = this.chunks.length - 1;
7746
+ while (0 <= ci) {
7747
+ const chunk = this.chunks[ci];
7748
+ const shiftChar = chunk.shift();
7749
+ if (chunk.toString()) {
7750
+ // chunk still contains value
7751
+ // but not shifted - means no more available chars to shift
7752
+ if (!shiftChar) break;
7753
+ --ci;
7754
+ } else {
7755
+ // clean if chunk has no value
7756
+ this.chunks.splice(ci, 1);
7757
+ }
7758
+ if (shiftChar) return shiftChar;
7759
+ }
7760
+ return '';
7761
+ }
7762
+ }
7763
+
7764
+ class PatternCursor {
7765
+ constructor(masked, pos) {
7766
+ this.masked = masked;
7767
+ this._log = [];
7768
+ const {
7769
+ offset,
7770
+ index
7771
+ } = masked._mapPosToBlock(pos) || (pos < 0 ?
7772
+ // first
7773
+ {
7774
+ index: 0,
7775
+ offset: 0
7776
+ } :
7777
+ // last
7778
+ {
7779
+ index: this.masked._blocks.length,
7780
+ offset: 0
7781
+ });
7782
+ this.offset = offset;
7783
+ this.index = index;
7784
+ this.ok = false;
7785
+ }
7786
+ get block() {
7787
+ return this.masked._blocks[this.index];
7788
+ }
7789
+ get pos() {
7790
+ return this.masked._blockStartPos(this.index) + this.offset;
7791
+ }
7792
+ get state() {
7793
+ return {
7794
+ index: this.index,
7795
+ offset: this.offset,
7796
+ ok: this.ok
7797
+ };
7798
+ }
7799
+ set state(s) {
7800
+ Object.assign(this, s);
7801
+ }
7802
+ pushState() {
7803
+ this._log.push(this.state);
7804
+ }
7805
+ popState() {
7806
+ const s = this._log.pop();
7807
+ if (s) this.state = s;
7808
+ return s;
7809
+ }
7810
+ bindBlock() {
7811
+ if (this.block) return;
7812
+ if (this.index < 0) {
7813
+ this.index = 0;
7814
+ this.offset = 0;
7815
+ }
7816
+ if (this.index >= this.masked._blocks.length) {
7817
+ this.index = this.masked._blocks.length - 1;
7818
+ this.offset = this.block.displayValue.length; // TODO this is stupid type error, `block` depends on index that was changed above
7819
+ }
7820
+ }
7821
+ _pushLeft(fn) {
7822
+ this.pushState();
7823
+ for (this.bindBlock(); 0 <= this.index; --this.index, this.offset = ((_this$block = this.block) == null ? void 0 : _this$block.displayValue.length) || 0) {
7824
+ var _this$block;
7825
+ if (fn()) return this.ok = true;
7826
+ }
7827
+ return this.ok = false;
7828
+ }
7829
+ _pushRight(fn) {
7830
+ this.pushState();
7831
+ for (this.bindBlock(); this.index < this.masked._blocks.length; ++this.index, this.offset = 0) {
7832
+ if (fn()) return this.ok = true;
7833
+ }
7834
+ return this.ok = false;
7835
+ }
7836
+ pushLeftBeforeFilled() {
7837
+ return this._pushLeft(() => {
7838
+ if (this.block.isFixed || !this.block.value) return;
7839
+ this.offset = this.block.nearestInputPos(this.offset, DIRECTION.FORCE_LEFT);
7840
+ if (this.offset !== 0) return true;
7841
+ });
7842
+ }
7843
+ pushLeftBeforeInput() {
7844
+ // cases:
7845
+ // filled input: 00|
7846
+ // optional empty input: 00[]|
7847
+ // nested block: XX<[]>|
7848
+ return this._pushLeft(() => {
7849
+ if (this.block.isFixed) return;
7850
+ this.offset = this.block.nearestInputPos(this.offset, DIRECTION.LEFT);
7851
+ return true;
7852
+ });
7853
+ }
7854
+ pushLeftBeforeRequired() {
7855
+ return this._pushLeft(() => {
7856
+ if (this.block.isFixed || this.block.isOptional && !this.block.value) return;
7857
+ this.offset = this.block.nearestInputPos(this.offset, DIRECTION.LEFT);
7858
+ return true;
7859
+ });
7860
+ }
7861
+ pushRightBeforeFilled() {
7862
+ return this._pushRight(() => {
7863
+ if (this.block.isFixed || !this.block.value) return;
7864
+ this.offset = this.block.nearestInputPos(this.offset, DIRECTION.FORCE_RIGHT);
7865
+ if (this.offset !== this.block.value.length) return true;
7866
+ });
7867
+ }
7868
+ pushRightBeforeInput() {
7869
+ return this._pushRight(() => {
7870
+ if (this.block.isFixed) return;
7871
+
7872
+ // const o = this.offset;
7873
+ this.offset = this.block.nearestInputPos(this.offset, DIRECTION.NONE);
7874
+ // HACK cases like (STILL DOES NOT WORK FOR NESTED)
7875
+ // aa|X
7876
+ // aa<X|[]>X_ - this will not work
7877
+ // if (o && o === this.offset && this.block instanceof PatternInputDefinition) continue;
7878
+ return true;
7879
+ });
7880
+ }
7881
+ pushRightBeforeRequired() {
7882
+ return this._pushRight(() => {
7883
+ if (this.block.isFixed || this.block.isOptional && !this.block.value) return;
7884
+
7885
+ // TODO check |[*]XX_
7886
+ this.offset = this.block.nearestInputPos(this.offset, DIRECTION.NONE);
7887
+ return true;
7888
+ });
7889
+ }
7890
+ }
7891
+
7892
+ class PatternFixedDefinition {
7893
+ /** */
7894
+
7895
+ /** */
7896
+
7897
+ /** */
7898
+
7899
+ /** */
7900
+
7901
+ /** */
7902
+
7903
+ /** */
7904
+
7905
+ constructor(opts) {
7906
+ Object.assign(this, opts);
7907
+ this._value = '';
7908
+ this.isFixed = true;
7909
+ }
7910
+ get value() {
7911
+ return this._value;
7912
+ }
7913
+ get unmaskedValue() {
7914
+ return this.isUnmasking ? this.value : '';
7915
+ }
7916
+ get rawInputValue() {
7917
+ return this._isRawInput ? this.value : '';
7918
+ }
7919
+ get displayValue() {
7920
+ return this.value;
7921
+ }
7922
+ reset() {
7923
+ this._isRawInput = false;
7924
+ this._value = '';
7925
+ }
7926
+ remove(fromPos, toPos) {
7927
+ if (fromPos === void 0) {
7928
+ fromPos = 0;
7929
+ }
7930
+ if (toPos === void 0) {
7931
+ toPos = this._value.length;
7932
+ }
7933
+ this._value = this._value.slice(0, fromPos) + this._value.slice(toPos);
7934
+ if (!this._value) this._isRawInput = false;
7935
+ return new ChangeDetails();
7936
+ }
7937
+ nearestInputPos(cursorPos, direction) {
7938
+ if (direction === void 0) {
7939
+ direction = DIRECTION.NONE;
7940
+ }
7941
+ const minPos = 0;
7942
+ const maxPos = this._value.length;
7943
+ switch (direction) {
7944
+ case DIRECTION.LEFT:
7945
+ case DIRECTION.FORCE_LEFT:
7946
+ return minPos;
7947
+ case DIRECTION.NONE:
7948
+ case DIRECTION.RIGHT:
7949
+ case DIRECTION.FORCE_RIGHT:
7950
+ default:
7951
+ return maxPos;
7952
+ }
7953
+ }
7954
+ totalInputPositions(fromPos, toPos) {
7955
+ if (fromPos === void 0) {
7956
+ fromPos = 0;
7957
+ }
7958
+ if (toPos === void 0) {
7959
+ toPos = this._value.length;
7960
+ }
7961
+ return this._isRawInput ? toPos - fromPos : 0;
7962
+ }
7963
+ extractInput(fromPos, toPos, flags) {
7964
+ if (fromPos === void 0) {
7965
+ fromPos = 0;
7966
+ }
7967
+ if (toPos === void 0) {
7968
+ toPos = this._value.length;
7969
+ }
7970
+ if (flags === void 0) {
7971
+ flags = {};
7972
+ }
7973
+ return flags.raw && this._isRawInput && this._value.slice(fromPos, toPos) || '';
7974
+ }
7975
+ get isComplete() {
7976
+ return true;
7977
+ }
7978
+ get isFilled() {
7979
+ return Boolean(this._value);
7980
+ }
7981
+ _appendChar(ch, flags) {
7982
+ if (flags === void 0) {
7983
+ flags = {};
7984
+ }
7985
+ if (this.isFilled) return new ChangeDetails();
7986
+ const appendEager = this.eager === true || this.eager === 'append';
7987
+ const appended = this.char === ch;
7988
+ const isResolved = appended && (this.isUnmasking || flags.input || flags.raw) && (!flags.raw || !appendEager) && !flags.tail;
7989
+ const details = new ChangeDetails({
7990
+ inserted: this.char,
7991
+ rawInserted: isResolved ? this.char : ''
7992
+ });
7993
+ this._value = this.char;
7994
+ this._isRawInput = isResolved && (flags.raw || flags.input);
7995
+ return details;
7996
+ }
7997
+ _appendEager() {
7998
+ return this._appendChar(this.char, {
7999
+ tail: true
8000
+ });
8001
+ }
8002
+ _appendPlaceholder() {
8003
+ const details = new ChangeDetails();
8004
+ if (this.isFilled) return details;
8005
+ this._value = details.inserted = this.char;
8006
+ return details;
8007
+ }
8008
+ extractTail() {
8009
+ return new ContinuousTailDetails('');
8010
+ }
8011
+ appendTail(tail) {
8012
+ if (isString(tail)) tail = new ContinuousTailDetails(String(tail));
8013
+ return tail.appendTo(this);
8014
+ }
8015
+ append(str, flags, tail) {
8016
+ const details = this._appendChar(str[0], flags);
8017
+ if (tail != null) {
8018
+ details.tailShift += this.appendTail(tail).tailShift;
8019
+ }
8020
+ return details;
8021
+ }
8022
+ doCommit() {}
8023
+ get state() {
8024
+ return {
8025
+ _value: this._value,
8026
+ _rawInputValue: this.rawInputValue
8027
+ };
8028
+ }
8029
+ set state(state) {
8030
+ this._value = state._value;
8031
+ this._isRawInput = Boolean(state._rawInputValue);
8032
+ }
8033
+ pad(flags) {
8034
+ return this._appendPlaceholder();
8035
+ }
8036
+ }
8037
+
8038
+ class PatternInputDefinition {
8039
+ /** */
8040
+
8041
+ /** */
8042
+
8043
+ /** */
8044
+
8045
+ /** */
8046
+
8047
+ /** */
8048
+
8049
+ /** */
8050
+
8051
+ /** */
8052
+
8053
+ /** */
8054
+
8055
+ constructor(opts) {
8056
+ const {
8057
+ parent,
8058
+ isOptional,
8059
+ placeholderChar,
8060
+ displayChar,
8061
+ lazy,
8062
+ eager,
8063
+ ...maskOpts
8064
+ } = opts;
8065
+ this.masked = createMask(maskOpts);
8066
+ Object.assign(this, {
8067
+ parent,
8068
+ isOptional,
8069
+ placeholderChar,
8070
+ displayChar,
8071
+ lazy,
8072
+ eager
8073
+ });
8074
+ }
8075
+ reset() {
8076
+ this.isFilled = false;
8077
+ this.masked.reset();
8078
+ }
8079
+ remove(fromPos, toPos) {
8080
+ if (fromPos === void 0) {
8081
+ fromPos = 0;
8082
+ }
8083
+ if (toPos === void 0) {
8084
+ toPos = this.value.length;
8085
+ }
8086
+ if (fromPos === 0 && toPos >= 1) {
8087
+ this.isFilled = false;
8088
+ return this.masked.remove(fromPos, toPos);
8089
+ }
8090
+ return new ChangeDetails();
8091
+ }
8092
+ get value() {
8093
+ return this.masked.value || (this.isFilled && !this.isOptional ? this.placeholderChar : '');
8094
+ }
8095
+ get unmaskedValue() {
8096
+ return this.masked.unmaskedValue;
8097
+ }
8098
+ get rawInputValue() {
8099
+ return this.masked.rawInputValue;
8100
+ }
8101
+ get displayValue() {
8102
+ return this.masked.value && this.displayChar || this.value;
8103
+ }
8104
+ get isComplete() {
8105
+ return Boolean(this.masked.value) || this.isOptional;
8106
+ }
8107
+ _appendChar(ch, flags) {
8108
+ if (flags === void 0) {
8109
+ flags = {};
8110
+ }
8111
+ if (this.isFilled) return new ChangeDetails();
8112
+ const state = this.masked.state;
8113
+ // simulate input
8114
+ let details = this.masked._appendChar(ch, this.currentMaskFlags(flags));
8115
+ if (details.inserted && this.doValidate(flags) === false) {
8116
+ details = new ChangeDetails();
8117
+ this.masked.state = state;
8118
+ }
8119
+ if (!details.inserted && !this.isOptional && !this.lazy && !flags.input) {
8120
+ details.inserted = this.placeholderChar;
8121
+ }
8122
+ details.skip = !details.inserted && !this.isOptional;
8123
+ this.isFilled = Boolean(details.inserted);
8124
+ return details;
8125
+ }
8126
+ append(str, flags, tail) {
8127
+ // TODO probably should be done via _appendChar
8128
+ return this.masked.append(str, this.currentMaskFlags(flags), tail);
8129
+ }
8130
+ _appendPlaceholder() {
8131
+ if (this.isFilled || this.isOptional) return new ChangeDetails();
8132
+ this.isFilled = true;
8133
+ return new ChangeDetails({
8134
+ inserted: this.placeholderChar
8135
+ });
8136
+ }
8137
+ _appendEager() {
8138
+ return new ChangeDetails();
8139
+ }
8140
+ extractTail(fromPos, toPos) {
8141
+ return this.masked.extractTail(fromPos, toPos);
8142
+ }
8143
+ appendTail(tail) {
8144
+ return this.masked.appendTail(tail);
8145
+ }
8146
+ extractInput(fromPos, toPos, flags) {
8147
+ if (fromPos === void 0) {
8148
+ fromPos = 0;
8149
+ }
8150
+ if (toPos === void 0) {
8151
+ toPos = this.value.length;
8152
+ }
8153
+ return this.masked.extractInput(fromPos, toPos, flags);
8154
+ }
8155
+ nearestInputPos(cursorPos, direction) {
8156
+ if (direction === void 0) {
8157
+ direction = DIRECTION.NONE;
8158
+ }
8159
+ const minPos = 0;
8160
+ const maxPos = this.value.length;
8161
+ const boundPos = Math.min(Math.max(cursorPos, minPos), maxPos);
8162
+ switch (direction) {
8163
+ case DIRECTION.LEFT:
8164
+ case DIRECTION.FORCE_LEFT:
8165
+ return this.isComplete ? boundPos : minPos;
8166
+ case DIRECTION.RIGHT:
8167
+ case DIRECTION.FORCE_RIGHT:
8168
+ return this.isComplete ? boundPos : maxPos;
8169
+ case DIRECTION.NONE:
8170
+ default:
8171
+ return boundPos;
8172
+ }
8173
+ }
8174
+ totalInputPositions(fromPos, toPos) {
8175
+ if (fromPos === void 0) {
8176
+ fromPos = 0;
8177
+ }
8178
+ if (toPos === void 0) {
8179
+ toPos = this.value.length;
8180
+ }
8181
+ return this.value.slice(fromPos, toPos).length;
8182
+ }
8183
+ doValidate(flags) {
8184
+ return this.masked.doValidate(this.currentMaskFlags(flags)) && (!this.parent || this.parent.doValidate(this.currentMaskFlags(flags)));
8185
+ }
8186
+ doCommit() {
8187
+ this.masked.doCommit();
8188
+ }
8189
+ get state() {
8190
+ return {
8191
+ _value: this.value,
8192
+ _rawInputValue: this.rawInputValue,
8193
+ masked: this.masked.state,
8194
+ isFilled: this.isFilled
8195
+ };
8196
+ }
8197
+ set state(state) {
8198
+ this.masked.state = state.masked;
8199
+ this.isFilled = state.isFilled;
8200
+ }
8201
+ currentMaskFlags(flags) {
8202
+ var _flags$_beforeTailSta;
8203
+ return {
8204
+ ...flags,
8205
+ _beforeTailState: (flags == null || (_flags$_beforeTailSta = flags._beforeTailState) == null ? void 0 : _flags$_beforeTailSta.masked) || (flags == null ? void 0 : flags._beforeTailState)
8206
+ };
8207
+ }
8208
+ pad(flags) {
8209
+ return new ChangeDetails();
8210
+ }
8211
+ }
8212
+ PatternInputDefinition.DEFAULT_DEFINITIONS = {
8213
+ '0': /\d/,
8214
+ '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]/,
8215
+ // http://stackoverflow.com/a/22075070
8216
+ '*': /./
8217
+ };
8218
+
8219
+ /** Masking by RegExp */
8220
+ class MaskedRegExp extends Masked {
8221
+ /** */
8222
+
8223
+ /** Enable characters overwriting */
8224
+
8225
+ /** */
8226
+
8227
+ /** */
8228
+
8229
+ /** */
8230
+
8231
+ updateOptions(opts) {
8232
+ super.updateOptions(opts);
8233
+ }
8234
+ _update(opts) {
8235
+ const mask = opts.mask;
8236
+ if (mask) opts.validate = value => value.search(mask) >= 0;
8237
+ super._update(opts);
8238
+ }
8239
+ }
8240
+ IMask.MaskedRegExp = MaskedRegExp;
8241
+
8242
+ /** Pattern mask */
8243
+ class MaskedPattern extends Masked {
8244
+ /** */
8245
+
8246
+ /** */
8247
+
8248
+ /** Single char for empty input */
8249
+
8250
+ /** Single char for filled input */
8251
+
8252
+ /** Show placeholder only when needed */
8253
+
8254
+ /** Enable characters overwriting */
8255
+
8256
+ /** */
8257
+
8258
+ /** */
8259
+
8260
+ /** */
8261
+
8262
+ constructor(opts) {
8263
+ super({
8264
+ ...MaskedPattern.DEFAULTS,
8265
+ ...opts,
8266
+ definitions: Object.assign({}, PatternInputDefinition.DEFAULT_DEFINITIONS, opts == null ? void 0 : opts.definitions)
8267
+ });
8268
+ }
8269
+ updateOptions(opts) {
8270
+ super.updateOptions(opts);
8271
+ }
8272
+ _update(opts) {
8273
+ opts.definitions = Object.assign({}, this.definitions, opts.definitions);
8274
+ super._update(opts);
8275
+ this._rebuildMask();
8276
+ }
8277
+ _rebuildMask() {
8278
+ const defs = this.definitions;
8279
+ this._blocks = [];
8280
+ this.exposeBlock = undefined;
8281
+ this._stops = [];
8282
+ this._maskedBlocks = {};
8283
+ const pattern = this.mask;
8284
+ if (!pattern || !defs) return;
8285
+ let unmaskingBlock = false;
8286
+ let optionalBlock = false;
8287
+ for (let i = 0; i < pattern.length; ++i) {
8288
+ if (this.blocks) {
8289
+ const p = pattern.slice(i);
8290
+ const bNames = Object.keys(this.blocks).filter(bName => p.indexOf(bName) === 0);
8291
+ // order by key length
8292
+ bNames.sort((a, b) => b.length - a.length);
8293
+ // use block name with max length
8294
+ const bName = bNames[0];
8295
+ if (bName) {
8296
+ const {
8297
+ expose,
8298
+ repeat,
8299
+ ...bOpts
8300
+ } = normalizeOpts(this.blocks[bName]); // TODO type Opts<Arg & Extra>
8301
+ const blockOpts = {
8302
+ lazy: this.lazy,
8303
+ eager: this.eager,
8304
+ placeholderChar: this.placeholderChar,
8305
+ displayChar: this.displayChar,
8306
+ overwrite: this.overwrite,
8307
+ autofix: this.autofix,
8308
+ ...bOpts,
8309
+ repeat,
8310
+ parent: this
8311
+ };
8312
+ const maskedBlock = repeat != null ? new IMask.RepeatBlock(blockOpts /* TODO */) : createMask(blockOpts);
8313
+ if (maskedBlock) {
8314
+ this._blocks.push(maskedBlock);
8315
+ if (expose) this.exposeBlock = maskedBlock;
8316
+
8317
+ // store block index
8318
+ if (!this._maskedBlocks[bName]) this._maskedBlocks[bName] = [];
8319
+ this._maskedBlocks[bName].push(this._blocks.length - 1);
8320
+ }
8321
+ i += bName.length - 1;
8322
+ continue;
8323
+ }
8324
+ }
8325
+ let char = pattern[i];
8326
+ let isInput = (char in defs);
8327
+ if (char === MaskedPattern.STOP_CHAR) {
8328
+ this._stops.push(this._blocks.length);
8329
+ continue;
8330
+ }
8331
+ if (char === '{' || char === '}') {
8332
+ unmaskingBlock = !unmaskingBlock;
8333
+ continue;
8334
+ }
8335
+ if (char === '[' || char === ']') {
8336
+ optionalBlock = !optionalBlock;
8337
+ continue;
8338
+ }
8339
+ if (char === MaskedPattern.ESCAPE_CHAR) {
8340
+ ++i;
8341
+ char = pattern[i];
8342
+ if (!char) break;
8343
+ isInput = false;
8344
+ }
8345
+ const def = isInput ? new PatternInputDefinition({
8346
+ isOptional: optionalBlock,
8347
+ lazy: this.lazy,
8348
+ eager: this.eager,
8349
+ placeholderChar: this.placeholderChar,
8350
+ displayChar: this.displayChar,
8351
+ ...normalizeOpts(defs[char]),
8352
+ parent: this
8353
+ }) : new PatternFixedDefinition({
8354
+ char,
8355
+ eager: this.eager,
8356
+ isUnmasking: unmaskingBlock
8357
+ });
8358
+ this._blocks.push(def);
8359
+ }
8360
+ }
8361
+ get state() {
8362
+ return {
8363
+ ...super.state,
8364
+ _blocks: this._blocks.map(b => b.state)
8365
+ };
8366
+ }
8367
+ set state(state) {
8368
+ if (!state) {
8369
+ this.reset();
8370
+ return;
8371
+ }
8372
+ const {
8373
+ _blocks,
8374
+ ...maskedState
8375
+ } = state;
8376
+ this._blocks.forEach((b, bi) => b.state = _blocks[bi]);
8377
+ super.state = maskedState;
8378
+ }
8379
+ reset() {
8380
+ super.reset();
8381
+ this._blocks.forEach(b => b.reset());
8382
+ }
8383
+ get isComplete() {
8384
+ return this.exposeBlock ? this.exposeBlock.isComplete : this._blocks.every(b => b.isComplete);
8385
+ }
8386
+ get isFilled() {
8387
+ return this._blocks.every(b => b.isFilled);
8388
+ }
8389
+ get isFixed() {
8390
+ return this._blocks.every(b => b.isFixed);
8391
+ }
8392
+ get isOptional() {
8393
+ return this._blocks.every(b => b.isOptional);
8394
+ }
8395
+ doCommit() {
8396
+ this._blocks.forEach(b => b.doCommit());
8397
+ super.doCommit();
8398
+ }
8399
+ get unmaskedValue() {
8400
+ return this.exposeBlock ? this.exposeBlock.unmaskedValue : this._blocks.reduce((str, b) => str += b.unmaskedValue, '');
8401
+ }
8402
+ set unmaskedValue(unmaskedValue) {
8403
+ if (this.exposeBlock) {
8404
+ const tail = this.extractTail(this._blockStartPos(this._blocks.indexOf(this.exposeBlock)) + this.exposeBlock.displayValue.length);
8405
+ this.exposeBlock.unmaskedValue = unmaskedValue;
8406
+ this.appendTail(tail);
8407
+ this.doCommit();
8408
+ } else super.unmaskedValue = unmaskedValue;
8409
+ }
8410
+ get value() {
8411
+ return this.exposeBlock ? this.exposeBlock.value :
8412
+ // TODO return _value when not in change?
8413
+ this._blocks.reduce((str, b) => str += b.value, '');
8414
+ }
8415
+ set value(value) {
8416
+ if (this.exposeBlock) {
8417
+ const tail = this.extractTail(this._blockStartPos(this._blocks.indexOf(this.exposeBlock)) + this.exposeBlock.displayValue.length);
8418
+ this.exposeBlock.value = value;
8419
+ this.appendTail(tail);
8420
+ this.doCommit();
8421
+ } else super.value = value;
8422
+ }
8423
+ get typedValue() {
8424
+ return this.exposeBlock ? this.exposeBlock.typedValue : super.typedValue;
8425
+ }
8426
+ set typedValue(value) {
8427
+ if (this.exposeBlock) {
8428
+ const tail = this.extractTail(this._blockStartPos(this._blocks.indexOf(this.exposeBlock)) + this.exposeBlock.displayValue.length);
8429
+ this.exposeBlock.typedValue = value;
8430
+ this.appendTail(tail);
8431
+ this.doCommit();
8432
+ } else super.typedValue = value;
8433
+ }
8434
+ get displayValue() {
8435
+ return this._blocks.reduce((str, b) => str += b.displayValue, '');
8436
+ }
8437
+ appendTail(tail) {
8438
+ return super.appendTail(tail).aggregate(this._appendPlaceholder());
8439
+ }
8440
+ _appendEager() {
8441
+ var _this$_mapPosToBlock;
8442
+ const details = new ChangeDetails();
8443
+ let startBlockIndex = (_this$_mapPosToBlock = this._mapPosToBlock(this.displayValue.length)) == null ? void 0 : _this$_mapPosToBlock.index;
8444
+ if (startBlockIndex == null) return details;
8445
+
8446
+ // TODO test if it works for nested pattern masks
8447
+ if (this._blocks[startBlockIndex].isFilled) ++startBlockIndex;
8448
+ for (let bi = startBlockIndex; bi < this._blocks.length; ++bi) {
8449
+ const d = this._blocks[bi]._appendEager();
8450
+ if (!d.inserted) break;
8451
+ details.aggregate(d);
8452
+ }
8453
+ return details;
8454
+ }
8455
+ _appendCharRaw(ch, flags) {
8456
+ if (flags === void 0) {
8457
+ flags = {};
8458
+ }
8459
+ const blockIter = this._mapPosToBlock(this.displayValue.length);
8460
+ const details = new ChangeDetails();
8461
+ if (!blockIter) return details;
8462
+ for (let bi = blockIter.index, block; block = this._blocks[bi]; ++bi) {
8463
+ var _flags$_beforeTailSta;
8464
+ const blockDetails = block._appendChar(ch, {
8465
+ ...flags,
8466
+ _beforeTailState: (_flags$_beforeTailSta = flags._beforeTailState) == null || (_flags$_beforeTailSta = _flags$_beforeTailSta._blocks) == null ? void 0 : _flags$_beforeTailSta[bi]
8467
+ });
8468
+ details.aggregate(blockDetails);
8469
+ if (blockDetails.consumed) break; // go next char
8470
+ }
8471
+ return details;
8472
+ }
8473
+ extractTail(fromPos, toPos) {
8474
+ if (fromPos === void 0) {
8475
+ fromPos = 0;
8476
+ }
8477
+ if (toPos === void 0) {
8478
+ toPos = this.displayValue.length;
8479
+ }
8480
+ const chunkTail = new ChunksTailDetails();
8481
+ if (fromPos === toPos) return chunkTail;
8482
+ this._forEachBlocksInRange(fromPos, toPos, (b, bi, bFromPos, bToPos) => {
8483
+ const blockChunk = b.extractTail(bFromPos, bToPos);
8484
+ blockChunk.stop = this._findStopBefore(bi);
8485
+ blockChunk.from = this._blockStartPos(bi);
8486
+ if (blockChunk instanceof ChunksTailDetails) blockChunk.blockIndex = bi;
8487
+ chunkTail.extend(blockChunk);
8488
+ });
8489
+ return chunkTail;
8490
+ }
8491
+ extractInput(fromPos, toPos, flags) {
8492
+ if (fromPos === void 0) {
8493
+ fromPos = 0;
8494
+ }
8495
+ if (toPos === void 0) {
8496
+ toPos = this.displayValue.length;
8497
+ }
8498
+ if (flags === void 0) {
8499
+ flags = {};
8500
+ }
8501
+ if (fromPos === toPos) return '';
8502
+ let input = '';
8503
+ this._forEachBlocksInRange(fromPos, toPos, (b, _, fromPos, toPos) => {
8504
+ input += b.extractInput(fromPos, toPos, flags);
8505
+ });
8506
+ return input;
8507
+ }
8508
+ _findStopBefore(blockIndex) {
8509
+ let stopBefore;
8510
+ for (let si = 0; si < this._stops.length; ++si) {
8511
+ const stop = this._stops[si];
8512
+ if (stop <= blockIndex) stopBefore = stop;else break;
8513
+ }
8514
+ return stopBefore;
8515
+ }
8516
+
8517
+ /** Appends placeholder depending on laziness */
8518
+ _appendPlaceholder(toBlockIndex) {
8519
+ const details = new ChangeDetails();
8520
+ if (this.lazy && toBlockIndex == null) return details;
8521
+ const startBlockIter = this._mapPosToBlock(this.displayValue.length);
8522
+ if (!startBlockIter) return details;
8523
+ const startBlockIndex = startBlockIter.index;
8524
+ const endBlockIndex = toBlockIndex != null ? toBlockIndex : this._blocks.length;
8525
+ this._blocks.slice(startBlockIndex, endBlockIndex).forEach(b => {
8526
+ if (!b.lazy || toBlockIndex != null) {
8527
+ var _blocks2;
8528
+ details.aggregate(b._appendPlaceholder((_blocks2 = b._blocks) == null ? void 0 : _blocks2.length));
8529
+ }
8530
+ });
8531
+ return details;
8532
+ }
8533
+
8534
+ /** Finds block in pos */
8535
+ _mapPosToBlock(pos) {
8536
+ let accVal = '';
8537
+ for (let bi = 0; bi < this._blocks.length; ++bi) {
8538
+ const block = this._blocks[bi];
8539
+ const blockStartPos = accVal.length;
8540
+ accVal += block.displayValue;
8541
+ if (pos <= accVal.length) {
8542
+ return {
8543
+ index: bi,
8544
+ offset: pos - blockStartPos
8545
+ };
8546
+ }
8547
+ }
8548
+ }
8549
+ _blockStartPos(blockIndex) {
8550
+ return this._blocks.slice(0, blockIndex).reduce((pos, b) => pos += b.displayValue.length, 0);
8551
+ }
8552
+ _forEachBlocksInRange(fromPos, toPos, fn) {
8553
+ if (toPos === void 0) {
8554
+ toPos = this.displayValue.length;
8555
+ }
8556
+ const fromBlockIter = this._mapPosToBlock(fromPos);
8557
+ if (fromBlockIter) {
8558
+ const toBlockIter = this._mapPosToBlock(toPos);
8559
+ // process first block
8560
+ const isSameBlock = toBlockIter && fromBlockIter.index === toBlockIter.index;
8561
+ const fromBlockStartPos = fromBlockIter.offset;
8562
+ const fromBlockEndPos = toBlockIter && isSameBlock ? toBlockIter.offset : this._blocks[fromBlockIter.index].displayValue.length;
8563
+ fn(this._blocks[fromBlockIter.index], fromBlockIter.index, fromBlockStartPos, fromBlockEndPos);
8564
+ if (toBlockIter && !isSameBlock) {
8565
+ // process intermediate blocks
8566
+ for (let bi = fromBlockIter.index + 1; bi < toBlockIter.index; ++bi) {
8567
+ fn(this._blocks[bi], bi, 0, this._blocks[bi].displayValue.length);
8568
+ }
8569
+
8570
+ // process last block
8571
+ fn(this._blocks[toBlockIter.index], toBlockIter.index, 0, toBlockIter.offset);
8572
+ }
8573
+ }
8574
+ }
8575
+ remove(fromPos, toPos) {
8576
+ if (fromPos === void 0) {
8577
+ fromPos = 0;
8578
+ }
8579
+ if (toPos === void 0) {
8580
+ toPos = this.displayValue.length;
8581
+ }
8582
+ const removeDetails = super.remove(fromPos, toPos);
8583
+ this._forEachBlocksInRange(fromPos, toPos, (b, _, bFromPos, bToPos) => {
8584
+ removeDetails.aggregate(b.remove(bFromPos, bToPos));
8585
+ });
8586
+ return removeDetails;
8587
+ }
8588
+ nearestInputPos(cursorPos, direction) {
8589
+ if (direction === void 0) {
8590
+ direction = DIRECTION.NONE;
8591
+ }
8592
+ if (!this._blocks.length) return 0;
8593
+ const cursor = new PatternCursor(this, cursorPos);
8594
+ if (direction === DIRECTION.NONE) {
8595
+ // -------------------------------------------------
8596
+ // NONE should only go out from fixed to the right!
8597
+ // -------------------------------------------------
8598
+ if (cursor.pushRightBeforeInput()) return cursor.pos;
8599
+ cursor.popState();
8600
+ if (cursor.pushLeftBeforeInput()) return cursor.pos;
8601
+ return this.displayValue.length;
8602
+ }
8603
+
8604
+ // FORCE is only about a|* otherwise is 0
8605
+ if (direction === DIRECTION.LEFT || direction === DIRECTION.FORCE_LEFT) {
8606
+ // try to break fast when *|a
8607
+ if (direction === DIRECTION.LEFT) {
8608
+ cursor.pushRightBeforeFilled();
8609
+ if (cursor.ok && cursor.pos === cursorPos) return cursorPos;
8610
+ cursor.popState();
8611
+ }
8612
+
8613
+ // forward flow
8614
+ cursor.pushLeftBeforeInput();
8615
+ cursor.pushLeftBeforeRequired();
8616
+ cursor.pushLeftBeforeFilled();
8617
+
8618
+ // backward flow
8619
+ if (direction === DIRECTION.LEFT) {
8620
+ cursor.pushRightBeforeInput();
8621
+ cursor.pushRightBeforeRequired();
8622
+ if (cursor.ok && cursor.pos <= cursorPos) return cursor.pos;
8623
+ cursor.popState();
8624
+ if (cursor.ok && cursor.pos <= cursorPos) return cursor.pos;
8625
+ cursor.popState();
8626
+ }
8627
+ if (cursor.ok) return cursor.pos;
8628
+ if (direction === DIRECTION.FORCE_LEFT) return 0;
8629
+ cursor.popState();
8630
+ if (cursor.ok) return cursor.pos;
8631
+ cursor.popState();
8632
+ if (cursor.ok) return cursor.pos;
8633
+ return 0;
8634
+ }
8635
+ if (direction === DIRECTION.RIGHT || direction === DIRECTION.FORCE_RIGHT) {
8636
+ // forward flow
8637
+ cursor.pushRightBeforeInput();
8638
+ cursor.pushRightBeforeRequired();
8639
+ if (cursor.pushRightBeforeFilled()) return cursor.pos;
8640
+ if (direction === DIRECTION.FORCE_RIGHT) return this.displayValue.length;
8641
+
8642
+ // backward flow
8643
+ cursor.popState();
8644
+ if (cursor.ok) return cursor.pos;
8645
+ cursor.popState();
8646
+ if (cursor.ok) return cursor.pos;
8647
+ return this.nearestInputPos(cursorPos, DIRECTION.LEFT);
8648
+ }
8649
+ return cursorPos;
8650
+ }
8651
+ totalInputPositions(fromPos, toPos) {
8652
+ if (fromPos === void 0) {
8653
+ fromPos = 0;
8654
+ }
8655
+ if (toPos === void 0) {
8656
+ toPos = this.displayValue.length;
8657
+ }
8658
+ let total = 0;
8659
+ this._forEachBlocksInRange(fromPos, toPos, (b, _, bFromPos, bToPos) => {
8660
+ total += b.totalInputPositions(bFromPos, bToPos);
8661
+ });
8662
+ return total;
8663
+ }
8664
+
8665
+ /** Get block by name */
8666
+ maskedBlock(name) {
8667
+ return this.maskedBlocks(name)[0];
8668
+ }
8669
+
8670
+ /** Get all blocks by name */
8671
+ maskedBlocks(name) {
8672
+ const indices = this._maskedBlocks[name];
8673
+ if (!indices) return [];
8674
+ return indices.map(gi => this._blocks[gi]);
8675
+ }
8676
+ pad(flags) {
8677
+ const details = new ChangeDetails();
8678
+ this._forEachBlocksInRange(0, this.displayValue.length, b => details.aggregate(b.pad(flags)));
8679
+ return details;
8680
+ }
8681
+ }
8682
+ MaskedPattern.DEFAULTS = {
8683
+ ...Masked.DEFAULTS,
8684
+ lazy: true,
8685
+ placeholderChar: '_'
8686
+ };
8687
+ MaskedPattern.STOP_CHAR = '`';
8688
+ MaskedPattern.ESCAPE_CHAR = '\\';
8689
+ MaskedPattern.InputDefinition = PatternInputDefinition;
8690
+ MaskedPattern.FixedDefinition = PatternFixedDefinition;
8691
+ IMask.MaskedPattern = MaskedPattern;
6242
8692
 
6243
- /*!
6244
- * maska v1.5.0
6245
- * (c) 2019-2021 Alexander Shabunevich
6246
- * Released under the MIT License.
6247
- */
6248
- var maska = maska$1.exports;
8693
+ /** Pattern which accepts ranges */
8694
+ class MaskedRange extends MaskedPattern {
8695
+ /**
8696
+ Optionally sets max length of pattern.
8697
+ Used when pattern length is longer then `to` param length. Pads zeros at start in this case.
8698
+ */
8699
+
8700
+ /** Min bound */
8701
+
8702
+ /** Max bound */
8703
+
8704
+ get _matchFrom() {
8705
+ return this.maxLength - String(this.from).length;
8706
+ }
8707
+ constructor(opts) {
8708
+ super(opts); // mask will be created in _update
8709
+ }
8710
+ updateOptions(opts) {
8711
+ super.updateOptions(opts);
8712
+ }
8713
+ _update(opts) {
8714
+ const {
8715
+ to = this.to || 0,
8716
+ from = this.from || 0,
8717
+ maxLength = this.maxLength || 0,
8718
+ autofix = this.autofix,
8719
+ ...patternOpts
8720
+ } = opts;
8721
+ this.to = to;
8722
+ this.from = from;
8723
+ this.maxLength = Math.max(String(to).length, maxLength);
8724
+ this.autofix = autofix;
8725
+ const fromStr = String(this.from).padStart(this.maxLength, '0');
8726
+ const toStr = String(this.to).padStart(this.maxLength, '0');
8727
+ let sameCharsCount = 0;
8728
+ while (sameCharsCount < toStr.length && toStr[sameCharsCount] === fromStr[sameCharsCount]) ++sameCharsCount;
8729
+ patternOpts.mask = toStr.slice(0, sameCharsCount).replace(/0/g, '\\0') + '0'.repeat(this.maxLength - sameCharsCount);
8730
+ super._update(patternOpts);
8731
+ }
8732
+ get isComplete() {
8733
+ return super.isComplete && Boolean(this.value);
8734
+ }
8735
+ boundaries(str) {
8736
+ let minstr = '';
8737
+ let maxstr = '';
8738
+ const [, placeholder, num] = str.match(/^(\D*)(\d*)(\D*)/) || [];
8739
+ if (num) {
8740
+ minstr = '0'.repeat(placeholder.length) + num;
8741
+ maxstr = '9'.repeat(placeholder.length) + num;
8742
+ }
8743
+ minstr = minstr.padEnd(this.maxLength, '0');
8744
+ maxstr = maxstr.padEnd(this.maxLength, '9');
8745
+ return [minstr, maxstr];
8746
+ }
8747
+ doPrepareChar(ch, flags) {
8748
+ if (flags === void 0) {
8749
+ flags = {};
8750
+ }
8751
+ let details;
8752
+ [ch, details] = super.doPrepareChar(ch.replace(/\D/g, ''), flags);
8753
+ if (!ch) details.skip = !this.isComplete;
8754
+ return [ch, details];
8755
+ }
8756
+ _appendCharRaw(ch, flags) {
8757
+ if (flags === void 0) {
8758
+ flags = {};
8759
+ }
8760
+ if (!this.autofix || this.value.length + 1 > this.maxLength) return super._appendCharRaw(ch, flags);
8761
+ const fromStr = String(this.from).padStart(this.maxLength, '0');
8762
+ const toStr = String(this.to).padStart(this.maxLength, '0');
8763
+ const [minstr, maxstr] = this.boundaries(this.value + ch);
8764
+ if (Number(maxstr) < this.from) return super._appendCharRaw(fromStr[this.value.length], flags);
8765
+ if (Number(minstr) > this.to) {
8766
+ if (!flags.tail && this.autofix === 'pad' && this.value.length + 1 < this.maxLength) {
8767
+ return super._appendCharRaw(fromStr[this.value.length], flags).aggregate(this._appendCharRaw(ch, flags));
8768
+ }
8769
+ return super._appendCharRaw(toStr[this.value.length], flags);
8770
+ }
8771
+ return super._appendCharRaw(ch, flags);
8772
+ }
8773
+ doValidate(flags) {
8774
+ const str = this.value;
8775
+ const firstNonZero = str.search(/[^0]/);
8776
+ if (firstNonZero === -1 && str.length <= this._matchFrom) return true;
8777
+ const [minstr, maxstr] = this.boundaries(str);
8778
+ return this.from <= Number(maxstr) && Number(minstr) <= this.to && super.doValidate(flags);
8779
+ }
8780
+ pad(flags) {
8781
+ const details = new ChangeDetails();
8782
+ if (this.value.length === this.maxLength) return details;
8783
+ const value = this.value;
8784
+ const padLength = this.maxLength - this.value.length;
8785
+ if (padLength) {
8786
+ this.reset();
8787
+ for (let i = 0; i < padLength; ++i) {
8788
+ details.aggregate(super._appendCharRaw('0', flags));
8789
+ }
8790
+
8791
+ // append tail
8792
+ value.split('').forEach(ch => this._appendCharRaw(ch));
8793
+ }
8794
+ return details;
8795
+ }
8796
+ }
8797
+ IMask.MaskedRange = MaskedRange;
8798
+
8799
+ const DefaultPattern = 'd{.}`m{.}`Y';
8800
+
8801
+ // Make format and parse required when pattern is provided
8802
+
8803
+ /** Date mask */
8804
+ class MaskedDate extends MaskedPattern {
8805
+ static extractPatternOptions(opts) {
8806
+ const {
8807
+ mask,
8808
+ pattern,
8809
+ ...patternOpts
8810
+ } = opts;
8811
+ return {
8812
+ ...patternOpts,
8813
+ mask: isString(mask) ? mask : pattern
8814
+ };
8815
+ }
8816
+
8817
+ /** Pattern mask for date according to {@link MaskedDate#format} */
8818
+
8819
+ /** Start date */
8820
+
8821
+ /** End date */
8822
+
8823
+ /** Format typed value to string */
8824
+
8825
+ /** Parse string to get typed value */
8826
+
8827
+ constructor(opts) {
8828
+ super(MaskedDate.extractPatternOptions({
8829
+ ...MaskedDate.DEFAULTS,
8830
+ ...opts
8831
+ }));
8832
+ }
8833
+ updateOptions(opts) {
8834
+ super.updateOptions(opts);
8835
+ }
8836
+ _update(opts) {
8837
+ const {
8838
+ mask,
8839
+ pattern,
8840
+ blocks,
8841
+ ...patternOpts
8842
+ } = {
8843
+ ...MaskedDate.DEFAULTS,
8844
+ ...opts
8845
+ };
8846
+ const patternBlocks = Object.assign({}, MaskedDate.GET_DEFAULT_BLOCKS());
8847
+ // adjust year block
8848
+ if (opts.min) patternBlocks.Y.from = opts.min.getFullYear();
8849
+ if (opts.max) patternBlocks.Y.to = opts.max.getFullYear();
8850
+ if (opts.min && opts.max && patternBlocks.Y.from === patternBlocks.Y.to) {
8851
+ patternBlocks.m.from = opts.min.getMonth() + 1;
8852
+ patternBlocks.m.to = opts.max.getMonth() + 1;
8853
+ if (patternBlocks.m.from === patternBlocks.m.to) {
8854
+ patternBlocks.d.from = opts.min.getDate();
8855
+ patternBlocks.d.to = opts.max.getDate();
8856
+ }
8857
+ }
8858
+ Object.assign(patternBlocks, this.blocks, blocks);
8859
+ super._update({
8860
+ ...patternOpts,
8861
+ mask: isString(mask) ? mask : pattern,
8862
+ blocks: patternBlocks
8863
+ });
8864
+ }
8865
+ doValidate(flags) {
8866
+ const date = this.date;
8867
+ return super.doValidate(flags) && (!this.isComplete || this.isDateExist(this.value) && date != null && (this.min == null || this.min <= date) && (this.max == null || date <= this.max));
8868
+ }
8869
+
8870
+ /** Checks if date is exists */
8871
+ isDateExist(str) {
8872
+ return this.format(this.parse(str, this), this).indexOf(str) >= 0;
8873
+ }
8874
+
8875
+ /** Parsed Date */
8876
+ get date() {
8877
+ return this.typedValue;
8878
+ }
8879
+ set date(date) {
8880
+ this.typedValue = date;
8881
+ }
8882
+ get typedValue() {
8883
+ return this.isComplete ? super.typedValue : null;
8884
+ }
8885
+ set typedValue(value) {
8886
+ super.typedValue = value;
8887
+ }
8888
+ maskEquals(mask) {
8889
+ return mask === Date || super.maskEquals(mask);
8890
+ }
8891
+ optionsIsChanged(opts) {
8892
+ return super.optionsIsChanged(MaskedDate.extractPatternOptions(opts));
8893
+ }
8894
+ }
8895
+ MaskedDate.GET_DEFAULT_BLOCKS = () => ({
8896
+ d: {
8897
+ mask: MaskedRange,
8898
+ from: 1,
8899
+ to: 31,
8900
+ maxLength: 2
8901
+ },
8902
+ m: {
8903
+ mask: MaskedRange,
8904
+ from: 1,
8905
+ to: 12,
8906
+ maxLength: 2
8907
+ },
8908
+ Y: {
8909
+ mask: MaskedRange,
8910
+ from: 1900,
8911
+ to: 9999
8912
+ }
8913
+ });
8914
+ MaskedDate.DEFAULTS = {
8915
+ ...MaskedPattern.DEFAULTS,
8916
+ mask: Date,
8917
+ pattern: DefaultPattern,
8918
+ format: (date, masked) => {
8919
+ if (!date) return '';
8920
+ const day = String(date.getDate()).padStart(2, '0');
8921
+ const month = String(date.getMonth() + 1).padStart(2, '0');
8922
+ const year = date.getFullYear();
8923
+ return [day, month, year].join('.');
8924
+ },
8925
+ parse: (str, masked) => {
8926
+ const [day, month, year] = str.split('.').map(Number);
8927
+ return new Date(year, month - 1, day);
8928
+ }
8929
+ };
8930
+ IMask.MaskedDate = MaskedDate;
8931
+
8932
+ /** Dynamic mask for choosing appropriate mask in run-time */
8933
+ class MaskedDynamic extends Masked {
8934
+ constructor(opts) {
8935
+ super({
8936
+ ...MaskedDynamic.DEFAULTS,
8937
+ ...opts
8938
+ });
8939
+ this.currentMask = undefined;
8940
+ }
8941
+ updateOptions(opts) {
8942
+ super.updateOptions(opts);
8943
+ }
8944
+ _update(opts) {
8945
+ super._update(opts);
8946
+ if ('mask' in opts) {
8947
+ this.exposeMask = undefined;
8948
+ // mask could be totally dynamic with only `dispatch` option
8949
+ this.compiledMasks = Array.isArray(opts.mask) ? opts.mask.map(m => {
8950
+ const {
8951
+ expose,
8952
+ ...maskOpts
8953
+ } = normalizeOpts(m);
8954
+ const masked = createMask({
8955
+ overwrite: this._overwrite,
8956
+ eager: this._eager,
8957
+ skipInvalid: this._skipInvalid,
8958
+ ...maskOpts
8959
+ });
8960
+ if (expose) this.exposeMask = masked;
8961
+ return masked;
8962
+ }) : [];
8963
+
8964
+ // this.currentMask = this.doDispatch(''); // probably not needed but lets see
8965
+ }
8966
+ }
8967
+ _appendCharRaw(ch, flags) {
8968
+ if (flags === void 0) {
8969
+ flags = {};
8970
+ }
8971
+ const details = this._applyDispatch(ch, flags);
8972
+ if (this.currentMask) {
8973
+ details.aggregate(this.currentMask._appendChar(ch, this.currentMaskFlags(flags)));
8974
+ }
8975
+ return details;
8976
+ }
8977
+ _applyDispatch(appended, flags, tail) {
8978
+ if (appended === void 0) {
8979
+ appended = '';
8980
+ }
8981
+ if (flags === void 0) {
8982
+ flags = {};
8983
+ }
8984
+ if (tail === void 0) {
8985
+ tail = '';
8986
+ }
8987
+ const prevValueBeforeTail = flags.tail && flags._beforeTailState != null ? flags._beforeTailState._value : this.value;
8988
+ const inputValue = this.rawInputValue;
8989
+ const insertValue = flags.tail && flags._beforeTailState != null ? flags._beforeTailState._rawInputValue : inputValue;
8990
+ const tailValue = inputValue.slice(insertValue.length);
8991
+ const prevMask = this.currentMask;
8992
+ const details = new ChangeDetails();
8993
+ const prevMaskState = prevMask == null ? void 0 : prevMask.state;
8994
+
8995
+ // clone flags to prevent overwriting `_beforeTailState`
8996
+ this.currentMask = this.doDispatch(appended, {
8997
+ ...flags
8998
+ }, tail);
8999
+
9000
+ // restore state after dispatch
9001
+ if (this.currentMask) {
9002
+ if (this.currentMask !== prevMask) {
9003
+ // if mask changed reapply input
9004
+ this.currentMask.reset();
9005
+ if (insertValue) {
9006
+ this.currentMask.append(insertValue, {
9007
+ raw: true
9008
+ });
9009
+ details.tailShift = this.currentMask.value.length - prevValueBeforeTail.length;
9010
+ }
9011
+ if (tailValue) {
9012
+ details.tailShift += this.currentMask.append(tailValue, {
9013
+ raw: true,
9014
+ tail: true
9015
+ }).tailShift;
9016
+ }
9017
+ } else if (prevMaskState) {
9018
+ // Dispatch can do something bad with state, so
9019
+ // restore prev mask state
9020
+ this.currentMask.state = prevMaskState;
9021
+ }
9022
+ }
9023
+ return details;
9024
+ }
9025
+ _appendPlaceholder() {
9026
+ const details = this._applyDispatch();
9027
+ if (this.currentMask) {
9028
+ details.aggregate(this.currentMask._appendPlaceholder());
9029
+ }
9030
+ return details;
9031
+ }
9032
+ _appendEager() {
9033
+ const details = this._applyDispatch();
9034
+ if (this.currentMask) {
9035
+ details.aggregate(this.currentMask._appendEager());
9036
+ }
9037
+ return details;
9038
+ }
9039
+ appendTail(tail) {
9040
+ const details = new ChangeDetails();
9041
+ if (tail) details.aggregate(this._applyDispatch('', {}, tail));
9042
+ return details.aggregate(this.currentMask ? this.currentMask.appendTail(tail) : super.appendTail(tail));
9043
+ }
9044
+ currentMaskFlags(flags) {
9045
+ var _flags$_beforeTailSta, _flags$_beforeTailSta2;
9046
+ return {
9047
+ ...flags,
9048
+ _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
9049
+ };
9050
+ }
9051
+ doDispatch(appended, flags, tail) {
9052
+ if (flags === void 0) {
9053
+ flags = {};
9054
+ }
9055
+ if (tail === void 0) {
9056
+ tail = '';
9057
+ }
9058
+ return this.dispatch(appended, this, flags, tail);
9059
+ }
9060
+ doValidate(flags) {
9061
+ return super.doValidate(flags) && (!this.currentMask || this.currentMask.doValidate(this.currentMaskFlags(flags)));
9062
+ }
9063
+ doPrepare(str, flags) {
9064
+ if (flags === void 0) {
9065
+ flags = {};
9066
+ }
9067
+ let [s, details] = super.doPrepare(str, flags);
9068
+ if (this.currentMask) {
9069
+ let currentDetails;
9070
+ [s, currentDetails] = super.doPrepare(s, this.currentMaskFlags(flags));
9071
+ details = details.aggregate(currentDetails);
9072
+ }
9073
+ return [s, details];
9074
+ }
9075
+ doPrepareChar(str, flags) {
9076
+ if (flags === void 0) {
9077
+ flags = {};
9078
+ }
9079
+ let [s, details] = super.doPrepareChar(str, flags);
9080
+ if (this.currentMask) {
9081
+ let currentDetails;
9082
+ [s, currentDetails] = super.doPrepareChar(s, this.currentMaskFlags(flags));
9083
+ details = details.aggregate(currentDetails);
9084
+ }
9085
+ return [s, details];
9086
+ }
9087
+ reset() {
9088
+ var _this$currentMask;
9089
+ (_this$currentMask = this.currentMask) == null || _this$currentMask.reset();
9090
+ this.compiledMasks.forEach(m => m.reset());
9091
+ }
9092
+ get value() {
9093
+ return this.exposeMask ? this.exposeMask.value : this.currentMask ? this.currentMask.value : '';
9094
+ }
9095
+ set value(value) {
9096
+ if (this.exposeMask) {
9097
+ this.exposeMask.value = value;
9098
+ this.currentMask = this.exposeMask;
9099
+ this._applyDispatch();
9100
+ } else super.value = value;
9101
+ }
9102
+ get unmaskedValue() {
9103
+ return this.exposeMask ? this.exposeMask.unmaskedValue : this.currentMask ? this.currentMask.unmaskedValue : '';
9104
+ }
9105
+ set unmaskedValue(unmaskedValue) {
9106
+ if (this.exposeMask) {
9107
+ this.exposeMask.unmaskedValue = unmaskedValue;
9108
+ this.currentMask = this.exposeMask;
9109
+ this._applyDispatch();
9110
+ } else super.unmaskedValue = unmaskedValue;
9111
+ }
9112
+ get typedValue() {
9113
+ return this.exposeMask ? this.exposeMask.typedValue : this.currentMask ? this.currentMask.typedValue : '';
9114
+ }
9115
+ set typedValue(typedValue) {
9116
+ if (this.exposeMask) {
9117
+ this.exposeMask.typedValue = typedValue;
9118
+ this.currentMask = this.exposeMask;
9119
+ this._applyDispatch();
9120
+ return;
9121
+ }
9122
+ let unmaskedValue = String(typedValue);
9123
+
9124
+ // double check it
9125
+ if (this.currentMask) {
9126
+ this.currentMask.typedValue = typedValue;
9127
+ unmaskedValue = this.currentMask.unmaskedValue;
9128
+ }
9129
+ this.unmaskedValue = unmaskedValue;
9130
+ }
9131
+ get displayValue() {
9132
+ return this.currentMask ? this.currentMask.displayValue : '';
9133
+ }
9134
+ get isComplete() {
9135
+ var _this$currentMask2;
9136
+ return Boolean((_this$currentMask2 = this.currentMask) == null ? void 0 : _this$currentMask2.isComplete);
9137
+ }
9138
+ get isFilled() {
9139
+ var _this$currentMask3;
9140
+ return Boolean((_this$currentMask3 = this.currentMask) == null ? void 0 : _this$currentMask3.isFilled);
9141
+ }
9142
+ remove(fromPos, toPos) {
9143
+ const details = new ChangeDetails();
9144
+ if (this.currentMask) {
9145
+ details.aggregate(this.currentMask.remove(fromPos, toPos))
9146
+ // update with dispatch
9147
+ .aggregate(this._applyDispatch());
9148
+ }
9149
+ return details;
9150
+ }
9151
+ get state() {
9152
+ var _this$currentMask4;
9153
+ return {
9154
+ ...super.state,
9155
+ _rawInputValue: this.rawInputValue,
9156
+ compiledMasks: this.compiledMasks.map(m => m.state),
9157
+ currentMaskRef: this.currentMask,
9158
+ currentMask: (_this$currentMask4 = this.currentMask) == null ? void 0 : _this$currentMask4.state
9159
+ };
9160
+ }
9161
+ set state(state) {
9162
+ const {
9163
+ compiledMasks,
9164
+ currentMaskRef,
9165
+ currentMask,
9166
+ ...maskedState
9167
+ } = state;
9168
+ if (compiledMasks) this.compiledMasks.forEach((m, mi) => m.state = compiledMasks[mi]);
9169
+ if (currentMaskRef != null) {
9170
+ this.currentMask = currentMaskRef;
9171
+ this.currentMask.state = currentMask;
9172
+ }
9173
+ super.state = maskedState;
9174
+ }
9175
+ extractInput(fromPos, toPos, flags) {
9176
+ return this.currentMask ? this.currentMask.extractInput(fromPos, toPos, flags) : '';
9177
+ }
9178
+ extractTail(fromPos, toPos) {
9179
+ return this.currentMask ? this.currentMask.extractTail(fromPos, toPos) : super.extractTail(fromPos, toPos);
9180
+ }
9181
+ doCommit() {
9182
+ if (this.currentMask) this.currentMask.doCommit();
9183
+ super.doCommit();
9184
+ }
9185
+ nearestInputPos(cursorPos, direction) {
9186
+ return this.currentMask ? this.currentMask.nearestInputPos(cursorPos, direction) : super.nearestInputPos(cursorPos, direction);
9187
+ }
9188
+ get overwrite() {
9189
+ return this.currentMask ? this.currentMask.overwrite : this._overwrite;
9190
+ }
9191
+ set overwrite(overwrite) {
9192
+ this._overwrite = overwrite;
9193
+ }
9194
+ get eager() {
9195
+ return this.currentMask ? this.currentMask.eager : this._eager;
9196
+ }
9197
+ set eager(eager) {
9198
+ this._eager = eager;
9199
+ }
9200
+ get skipInvalid() {
9201
+ return this.currentMask ? this.currentMask.skipInvalid : this._skipInvalid;
9202
+ }
9203
+ set skipInvalid(skipInvalid) {
9204
+ this._skipInvalid = skipInvalid;
9205
+ }
9206
+ get autofix() {
9207
+ return this.currentMask ? this.currentMask.autofix : this._autofix;
9208
+ }
9209
+ set autofix(autofix) {
9210
+ this._autofix = autofix;
9211
+ }
9212
+ maskEquals(mask) {
9213
+ return Array.isArray(mask) ? this.compiledMasks.every((m, mi) => {
9214
+ if (!mask[mi]) return;
9215
+ const {
9216
+ mask: oldMask,
9217
+ ...restOpts
9218
+ } = mask[mi];
9219
+ return objectIncludes(m, restOpts) && m.maskEquals(oldMask);
9220
+ }) : super.maskEquals(mask);
9221
+ }
9222
+ typedValueEquals(value) {
9223
+ var _this$currentMask5;
9224
+ return Boolean((_this$currentMask5 = this.currentMask) == null ? void 0 : _this$currentMask5.typedValueEquals(value));
9225
+ }
9226
+ }
9227
+ /** Currently chosen mask */
9228
+ /** Currently chosen mask */
9229
+ /** Compliled {@link Masked} options */
9230
+ /** Chooses {@link Masked} depending on input value */
9231
+ MaskedDynamic.DEFAULTS = {
9232
+ ...Masked.DEFAULTS,
9233
+ dispatch: (appended, masked, flags, tail) => {
9234
+ if (!masked.compiledMasks.length) return;
9235
+ const inputValue = masked.rawInputValue;
9236
+
9237
+ // simulate input
9238
+ const inputs = masked.compiledMasks.map((m, index) => {
9239
+ const isCurrent = masked.currentMask === m;
9240
+ const startInputPos = isCurrent ? m.displayValue.length : m.nearestInputPos(m.displayValue.length, DIRECTION.FORCE_LEFT);
9241
+ if (m.rawInputValue !== inputValue) {
9242
+ m.reset();
9243
+ m.append(inputValue, {
9244
+ raw: true
9245
+ });
9246
+ } else if (!isCurrent) {
9247
+ m.remove(startInputPos);
9248
+ }
9249
+ m.append(appended, masked.currentMaskFlags(flags));
9250
+ m.appendTail(tail);
9251
+ return {
9252
+ index,
9253
+ weight: m.rawInputValue.length,
9254
+ totalInputPositions: m.totalInputPositions(0, Math.max(startInputPos, m.nearestInputPos(m.displayValue.length, DIRECTION.FORCE_LEFT)))
9255
+ };
9256
+ });
9257
+
9258
+ // pop masks with longer values first
9259
+ inputs.sort((i1, i2) => i2.weight - i1.weight || i2.totalInputPositions - i1.totalInputPositions);
9260
+ return masked.compiledMasks[inputs[0].index];
9261
+ }
9262
+ };
9263
+ IMask.MaskedDynamic = MaskedDynamic;
9264
+
9265
+ /** Pattern which validates enum values */
9266
+ class MaskedEnum extends MaskedPattern {
9267
+ constructor(opts) {
9268
+ super({
9269
+ ...MaskedEnum.DEFAULTS,
9270
+ ...opts
9271
+ }); // mask will be created in _update
9272
+ }
9273
+ updateOptions(opts) {
9274
+ super.updateOptions(opts);
9275
+ }
9276
+ _update(opts) {
9277
+ const {
9278
+ enum: enum_,
9279
+ ...eopts
9280
+ } = opts;
9281
+ if (enum_) {
9282
+ const lengths = enum_.map(e => e.length);
9283
+ const requiredLength = Math.min(...lengths);
9284
+ const optionalLength = Math.max(...lengths) - requiredLength;
9285
+ eopts.mask = '*'.repeat(requiredLength);
9286
+ if (optionalLength) eopts.mask += '[' + '*'.repeat(optionalLength) + ']';
9287
+ this.enum = enum_;
9288
+ }
9289
+ super._update(eopts);
9290
+ }
9291
+ _appendCharRaw(ch, flags) {
9292
+ if (flags === void 0) {
9293
+ flags = {};
9294
+ }
9295
+ const matchFrom = Math.min(this.nearestInputPos(0, DIRECTION.FORCE_RIGHT), this.value.length);
9296
+ const matches = this.enum.filter(e => this.matchValue(e, this.unmaskedValue + ch, matchFrom));
9297
+ if (matches.length) {
9298
+ if (matches.length === 1) {
9299
+ this._forEachBlocksInRange(0, this.value.length, (b, bi) => {
9300
+ const mch = matches[0][bi];
9301
+ if (bi >= this.value.length || mch === b.value) return;
9302
+ b.reset();
9303
+ b._appendChar(mch, flags);
9304
+ });
9305
+ }
9306
+ const d = super._appendCharRaw(matches[0][this.value.length], flags);
9307
+ if (matches.length === 1) {
9308
+ matches[0].slice(this.unmaskedValue.length).split('').forEach(mch => d.aggregate(super._appendCharRaw(mch)));
9309
+ }
9310
+ return d;
9311
+ }
9312
+ return new ChangeDetails({
9313
+ skip: !this.isComplete
9314
+ });
9315
+ }
9316
+ extractTail(fromPos, toPos) {
9317
+ if (fromPos === void 0) {
9318
+ fromPos = 0;
9319
+ }
9320
+ // just drop tail
9321
+ return new ContinuousTailDetails('', fromPos);
9322
+ }
9323
+ remove(fromPos, toPos) {
9324
+ if (fromPos === void 0) {
9325
+ fromPos = 0;
9326
+ }
9327
+ if (toPos === void 0) {
9328
+ toPos = this.displayValue.length;
9329
+ }
9330
+ if (fromPos === toPos) return new ChangeDetails();
9331
+ const matchFrom = Math.min(super.nearestInputPos(0, DIRECTION.FORCE_RIGHT), this.value.length);
9332
+ let pos;
9333
+ for (pos = fromPos; pos >= 0; --pos) {
9334
+ const matches = this.enum.filter(e => this.matchValue(e, this.value.slice(matchFrom, pos), matchFrom));
9335
+ if (matches.length > 1) break;
9336
+ }
9337
+ const details = super.remove(pos, toPos);
9338
+ details.tailShift += pos - fromPos;
9339
+ return details;
9340
+ }
9341
+ get isComplete() {
9342
+ return this.enum.indexOf(this.value) >= 0;
9343
+ }
9344
+ }
9345
+ /** Match enum value */
9346
+ MaskedEnum.DEFAULTS = {
9347
+ ...MaskedPattern.DEFAULTS,
9348
+ matchValue: (estr, istr, matchFrom) => estr.indexOf(istr, matchFrom) === matchFrom
9349
+ };
9350
+ IMask.MaskedEnum = MaskedEnum;
9351
+
9352
+ /** Masking by custom Function */
9353
+ class MaskedFunction extends Masked {
9354
+ /** */
9355
+
9356
+ /** Enable characters overwriting */
9357
+
9358
+ /** */
9359
+
9360
+ /** */
9361
+
9362
+ /** */
9363
+
9364
+ updateOptions(opts) {
9365
+ super.updateOptions(opts);
9366
+ }
9367
+ _update(opts) {
9368
+ super._update({
9369
+ ...opts,
9370
+ validate: opts.mask
9371
+ });
9372
+ }
9373
+ }
9374
+ IMask.MaskedFunction = MaskedFunction;
9375
+
9376
+ var _MaskedNumber;
9377
+ /** Number mask */
9378
+ class MaskedNumber extends Masked {
9379
+ /** Single char */
9380
+
9381
+ /** Single char */
9382
+
9383
+ /** Array of single chars */
9384
+
9385
+ /** */
9386
+
9387
+ /** */
9388
+
9389
+ /** Digits after point */
9390
+
9391
+ /** Flag to remove leading and trailing zeros in the end of editing */
9392
+
9393
+ /** Flag to pad trailing zeros after point in the end of editing */
9394
+
9395
+ /** Enable characters overwriting */
9396
+
9397
+ /** */
9398
+
9399
+ /** */
9400
+
9401
+ /** */
9402
+
9403
+ /** Format typed value to string */
9404
+
9405
+ /** Parse string to get typed value */
9406
+
9407
+ constructor(opts) {
9408
+ super({
9409
+ ...MaskedNumber.DEFAULTS,
9410
+ ...opts
9411
+ });
9412
+ }
9413
+ updateOptions(opts) {
9414
+ super.updateOptions(opts);
9415
+ }
9416
+ _update(opts) {
9417
+ super._update(opts);
9418
+ this._updateRegExps();
9419
+ }
9420
+ _updateRegExps() {
9421
+ const start = '^' + (this.allowNegative ? '[+|\\-]?' : '');
9422
+ const mid = '\\d*';
9423
+ const end = (this.scale ? "(" + escapeRegExp(this.radix) + "\\d{0," + this.scale + "})?" : '') + '$';
9424
+ this._numberRegExp = new RegExp(start + mid + end);
9425
+ this._mapToRadixRegExp = new RegExp("[" + this.mapToRadix.map(escapeRegExp).join('') + "]", 'g');
9426
+ this._thousandsSeparatorRegExp = new RegExp(escapeRegExp(this.thousandsSeparator), 'g');
9427
+ }
9428
+ _removeThousandsSeparators(value) {
9429
+ return value.replace(this._thousandsSeparatorRegExp, '');
9430
+ }
9431
+ _insertThousandsSeparators(value) {
9432
+ // https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript
9433
+ const parts = value.split(this.radix);
9434
+ parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, this.thousandsSeparator);
9435
+ return parts.join(this.radix);
9436
+ }
9437
+ doPrepareChar(ch, flags) {
9438
+ if (flags === void 0) {
9439
+ flags = {};
9440
+ }
9441
+ const [prepCh, details] = super.doPrepareChar(this._removeThousandsSeparators(this.scale && this.mapToRadix.length && (
9442
+ /*
9443
+ radix should be mapped when
9444
+ 1) input is done from keyboard = flags.input && flags.raw
9445
+ 2) unmasked value is set = !flags.input && !flags.raw
9446
+ and should not be mapped when
9447
+ 1) value is set = flags.input && !flags.raw
9448
+ 2) raw value is set = !flags.input && flags.raw
9449
+ */
9450
+ flags.input && flags.raw || !flags.input && !flags.raw) ? ch.replace(this._mapToRadixRegExp, this.radix) : ch), flags);
9451
+ if (ch && !prepCh) details.skip = true;
9452
+ if (prepCh && !this.allowPositive && !this.value && prepCh !== '-') details.aggregate(this._appendChar('-'));
9453
+ return [prepCh, details];
9454
+ }
9455
+ _separatorsCount(to, extendOnSeparators) {
9456
+ if (extendOnSeparators === void 0) {
9457
+ extendOnSeparators = false;
9458
+ }
9459
+ let count = 0;
9460
+ for (let pos = 0; pos < to; ++pos) {
9461
+ if (this._value.indexOf(this.thousandsSeparator, pos) === pos) {
9462
+ ++count;
9463
+ if (extendOnSeparators) to += this.thousandsSeparator.length;
9464
+ }
9465
+ }
9466
+ return count;
9467
+ }
9468
+ _separatorsCountFromSlice(slice) {
9469
+ if (slice === void 0) {
9470
+ slice = this._value;
9471
+ }
9472
+ return this._separatorsCount(this._removeThousandsSeparators(slice).length, true);
9473
+ }
9474
+ extractInput(fromPos, toPos, flags) {
9475
+ if (fromPos === void 0) {
9476
+ fromPos = 0;
9477
+ }
9478
+ if (toPos === void 0) {
9479
+ toPos = this.displayValue.length;
9480
+ }
9481
+ [fromPos, toPos] = this._adjustRangeWithSeparators(fromPos, toPos);
9482
+ return this._removeThousandsSeparators(super.extractInput(fromPos, toPos, flags));
9483
+ }
9484
+ _appendCharRaw(ch, flags) {
9485
+ if (flags === void 0) {
9486
+ flags = {};
9487
+ }
9488
+ const prevBeforeTailValue = flags.tail && flags._beforeTailState ? flags._beforeTailState._value : this._value;
9489
+ const prevBeforeTailSeparatorsCount = this._separatorsCountFromSlice(prevBeforeTailValue);
9490
+ this._value = this._removeThousandsSeparators(this.value);
9491
+ const oldValue = this._value;
9492
+ this._value += ch;
9493
+ const num = this.number;
9494
+ let accepted = !isNaN(num);
9495
+ let skip = false;
9496
+ if (accepted) {
9497
+ let fixedNum;
9498
+ if (this.min != null && this.min < 0 && this.number < this.min) fixedNum = this.min;
9499
+ if (this.max != null && this.max > 0 && this.number > this.max) fixedNum = this.max;
9500
+ if (fixedNum != null) {
9501
+ if (this.autofix) {
9502
+ this._value = this.format(fixedNum, this).replace(MaskedNumber.UNMASKED_RADIX, this.radix);
9503
+ skip || (skip = oldValue === this._value && !flags.tail); // if not changed on tail it's still ok to proceed
9504
+ } else {
9505
+ accepted = false;
9506
+ }
9507
+ }
9508
+ accepted && (accepted = Boolean(this._value.match(this._numberRegExp)));
9509
+ }
9510
+ let appendDetails;
9511
+ if (!accepted) {
9512
+ this._value = oldValue;
9513
+ appendDetails = new ChangeDetails();
9514
+ } else {
9515
+ appendDetails = new ChangeDetails({
9516
+ inserted: this._value.slice(oldValue.length),
9517
+ rawInserted: skip ? '' : ch,
9518
+ skip
9519
+ });
9520
+ }
9521
+ this._value = this._insertThousandsSeparators(this._value);
9522
+ const beforeTailValue = flags.tail && flags._beforeTailState ? flags._beforeTailState._value : this._value;
9523
+ const beforeTailSeparatorsCount = this._separatorsCountFromSlice(beforeTailValue);
9524
+ appendDetails.tailShift += (beforeTailSeparatorsCount - prevBeforeTailSeparatorsCount) * this.thousandsSeparator.length;
9525
+ return appendDetails;
9526
+ }
9527
+ _findSeparatorAround(pos) {
9528
+ if (this.thousandsSeparator) {
9529
+ const searchFrom = pos - this.thousandsSeparator.length + 1;
9530
+ const separatorPos = this.value.indexOf(this.thousandsSeparator, searchFrom);
9531
+ if (separatorPos <= pos) return separatorPos;
9532
+ }
9533
+ return -1;
9534
+ }
9535
+ _adjustRangeWithSeparators(from, to) {
9536
+ const separatorAroundFromPos = this._findSeparatorAround(from);
9537
+ if (separatorAroundFromPos >= 0) from = separatorAroundFromPos;
9538
+ const separatorAroundToPos = this._findSeparatorAround(to);
9539
+ if (separatorAroundToPos >= 0) to = separatorAroundToPos + this.thousandsSeparator.length;
9540
+ return [from, to];
9541
+ }
9542
+ remove(fromPos, toPos) {
9543
+ if (fromPos === void 0) {
9544
+ fromPos = 0;
9545
+ }
9546
+ if (toPos === void 0) {
9547
+ toPos = this.displayValue.length;
9548
+ }
9549
+ [fromPos, toPos] = this._adjustRangeWithSeparators(fromPos, toPos);
9550
+ const valueBeforePos = this.value.slice(0, fromPos);
9551
+ const valueAfterPos = this.value.slice(toPos);
9552
+ const prevBeforeTailSeparatorsCount = this._separatorsCount(valueBeforePos.length);
9553
+ this._value = this._insertThousandsSeparators(this._removeThousandsSeparators(valueBeforePos + valueAfterPos));
9554
+ const beforeTailSeparatorsCount = this._separatorsCountFromSlice(valueBeforePos);
9555
+ return new ChangeDetails({
9556
+ tailShift: (beforeTailSeparatorsCount - prevBeforeTailSeparatorsCount) * this.thousandsSeparator.length
9557
+ });
9558
+ }
9559
+ nearestInputPos(cursorPos, direction) {
9560
+ if (!this.thousandsSeparator) return cursorPos;
9561
+ switch (direction) {
9562
+ case DIRECTION.NONE:
9563
+ case DIRECTION.LEFT:
9564
+ case DIRECTION.FORCE_LEFT:
9565
+ {
9566
+ const separatorAtLeftPos = this._findSeparatorAround(cursorPos - 1);
9567
+ if (separatorAtLeftPos >= 0) {
9568
+ const separatorAtLeftEndPos = separatorAtLeftPos + this.thousandsSeparator.length;
9569
+ if (cursorPos < separatorAtLeftEndPos || this.value.length <= separatorAtLeftEndPos || direction === DIRECTION.FORCE_LEFT) {
9570
+ return separatorAtLeftPos;
9571
+ }
9572
+ }
9573
+ break;
9574
+ }
9575
+ case DIRECTION.RIGHT:
9576
+ case DIRECTION.FORCE_RIGHT:
9577
+ {
9578
+ const separatorAtRightPos = this._findSeparatorAround(cursorPos);
9579
+ if (separatorAtRightPos >= 0) {
9580
+ return separatorAtRightPos + this.thousandsSeparator.length;
9581
+ }
9582
+ }
9583
+ }
9584
+ return cursorPos;
9585
+ }
9586
+ doCommit() {
9587
+ if (this.value) {
9588
+ const number = this.number;
9589
+ let validnum = number;
9590
+
9591
+ // check bounds
9592
+ if (this.min != null) validnum = Math.max(validnum, this.min);
9593
+ if (this.max != null) validnum = Math.min(validnum, this.max);
9594
+ if (validnum !== number) this.unmaskedValue = this.format(validnum, this);
9595
+ let formatted = this.value;
9596
+ if (this.normalizeZeros) formatted = this._normalizeZeros(formatted);
9597
+ if (this.padFractionalZeros && this.scale > 0) formatted = this._padFractionalZeros(formatted);
9598
+ this._value = formatted;
9599
+ }
9600
+ super.doCommit();
9601
+ }
9602
+ _normalizeZeros(value) {
9603
+ const parts = this._removeThousandsSeparators(value).split(this.radix);
9604
+
9605
+ // remove leading zeros
9606
+ parts[0] = parts[0].replace(/^(\D*)(0*)(\d*)/, (match, sign, zeros, num) => sign + num);
9607
+ // add leading zero
9608
+ if (value.length && !/\d$/.test(parts[0])) parts[0] = parts[0] + '0';
9609
+ if (parts.length > 1) {
9610
+ parts[1] = parts[1].replace(/0*$/, ''); // remove trailing zeros
9611
+ if (!parts[1].length) parts.length = 1; // remove fractional
9612
+ }
9613
+ return this._insertThousandsSeparators(parts.join(this.radix));
9614
+ }
9615
+ _padFractionalZeros(value) {
9616
+ if (!value) return value;
9617
+ const parts = value.split(this.radix);
9618
+ if (parts.length < 2) parts.push('');
9619
+ parts[1] = parts[1].padEnd(this.scale, '0');
9620
+ return parts.join(this.radix);
9621
+ }
9622
+ doSkipInvalid(ch, flags, checkTail) {
9623
+ if (flags === void 0) {
9624
+ flags = {};
9625
+ }
9626
+ const dropFractional = this.scale === 0 && ch !== this.thousandsSeparator && (ch === this.radix || ch === MaskedNumber.UNMASKED_RADIX || this.mapToRadix.includes(ch));
9627
+ return super.doSkipInvalid(ch, flags, checkTail) && !dropFractional;
9628
+ }
9629
+ get unmaskedValue() {
9630
+ return this._removeThousandsSeparators(this._normalizeZeros(this.value)).replace(this.radix, MaskedNumber.UNMASKED_RADIX);
9631
+ }
9632
+ set unmaskedValue(unmaskedValue) {
9633
+ super.unmaskedValue = unmaskedValue;
9634
+ }
9635
+ get typedValue() {
9636
+ return this.parse(this.unmaskedValue, this);
9637
+ }
9638
+ set typedValue(n) {
9639
+ this.rawInputValue = this.format(n, this).replace(MaskedNumber.UNMASKED_RADIX, this.radix);
9640
+ }
9641
+
9642
+ /** Parsed Number */
9643
+ get number() {
9644
+ return this.typedValue;
9645
+ }
9646
+ set number(number) {
9647
+ this.typedValue = number;
9648
+ }
9649
+ get allowNegative() {
9650
+ return this.min != null && this.min < 0 || this.max != null && this.max < 0;
9651
+ }
9652
+ get allowPositive() {
9653
+ return this.min != null && this.min > 0 || this.max != null && this.max > 0;
9654
+ }
9655
+ typedValueEquals(value) {
9656
+ // handle 0 -> '' case (typed = 0 even if value = '')
9657
+ // for details see https://github.com/uNmAnNeR/imaskjs/issues/134
9658
+ return (super.typedValueEquals(value) || MaskedNumber.EMPTY_VALUES.includes(value) && MaskedNumber.EMPTY_VALUES.includes(this.typedValue)) && !(value === 0 && this.value === '');
9659
+ }
9660
+ }
9661
+ _MaskedNumber = MaskedNumber;
9662
+ MaskedNumber.UNMASKED_RADIX = '.';
9663
+ MaskedNumber.EMPTY_VALUES = [...Masked.EMPTY_VALUES, 0];
9664
+ MaskedNumber.DEFAULTS = {
9665
+ ...Masked.DEFAULTS,
9666
+ mask: Number,
9667
+ radix: ',',
9668
+ thousandsSeparator: '',
9669
+ mapToRadix: [_MaskedNumber.UNMASKED_RADIX],
9670
+ min: Number.MIN_SAFE_INTEGER,
9671
+ max: Number.MAX_SAFE_INTEGER,
9672
+ scale: 2,
9673
+ normalizeZeros: true,
9674
+ padFractionalZeros: false,
9675
+ parse: Number,
9676
+ format: n => n.toLocaleString('en-US', {
9677
+ useGrouping: false,
9678
+ maximumFractionDigits: 20
9679
+ })
9680
+ };
9681
+ IMask.MaskedNumber = MaskedNumber;
6249
9682
 
6250
- var hasRequiredMaska;
9683
+ /** Mask pipe source and destination types */
9684
+ const PIPE_TYPE = {
9685
+ MASKED: 'value',
9686
+ UNMASKED: 'unmaskedValue',
9687
+ TYPED: 'typedValue'
9688
+ };
9689
+ /** Creates new pipe function depending on mask type, source and destination options */
9690
+ function createPipe(arg, from, to) {
9691
+ if (from === void 0) {
9692
+ from = PIPE_TYPE.MASKED;
9693
+ }
9694
+ if (to === void 0) {
9695
+ to = PIPE_TYPE.MASKED;
9696
+ }
9697
+ const masked = createMask(arg);
9698
+ return value => masked.runIsolated(m => {
9699
+ m[from] = value;
9700
+ return m[to];
9701
+ });
9702
+ }
6251
9703
 
6252
- function requireMaska () {
6253
- if (hasRequiredMaska) return maska$1.exports;
6254
- hasRequiredMaska = 1;
6255
- (function (module, exports) {
6256
- !function(e,t){t(exports);}(maska,(function(e){var t={"#":{pattern:/[0-9]/},X:{pattern:/[0-9a-zA-Z]/},S:{pattern:/[a-zA-Z]/},A:{pattern:/[a-zA-Z]/,uppercase:true},a:{pattern:/[a-zA-Z]/,lowercase:true},"!":{escape:true},"*":{repeat:true}};function n(e,n,r=t,o=true){return s(n).length>1?function(e){const t=s(e).sort(((e,t)=>e.length-t.length));return function(e,s,r,o=true){const i=t.map((t=>a(e,t,r,false))).pop();for(const s in t)if(n(i,t[s],r))return a(e,t[s],r,o);return ""};function n(e,t,n){for(const e in n)n[e].escape&&(t=t.replace(new RegExp(e+".{1}","g"),""));return t.split("").filter((e=>n[e]&&n[e].pattern)).length>=e.length}}(n)(e,n,r,o):a(e,n,r,o)}function s(e){try{return JSON.parse(e)}catch{return [e]}}function a(e,t,n,s=true){let a=0,o=0,i="",u="";for(;a<t.length&&o<e.length;){let u=t[a];const p=e[o],l=n[u];if(l&&l.pattern)l.pattern.test(p)&&(i+=r(p,l),a++,s&&t[a]&&(n[t[a]]?n[t[a]]&&n[t[a]].escape&&(i+=t[a+1],a+=2):(i+=t[a],a++))),o++;else if(l&&l.repeat){const e=n[t[a-1]];e&&!e.pattern.test(p)?a++:a--;}else l&&l.escape&&(a++,u=t[a]),s&&(i+=u),p===u&&o++,a++;}for(;s&&a<t.length;){const e=t[a];if(n[e]){u="";break}u+=e,a++;}return i+u}function r(e,t){return t.transform&&(e=t.transform(e)),t.uppercase?e.toLocaleUpperCase():t.lowercase?e.toLocaleLowerCase():e}function o(e){return e instanceof HTMLInputElement?e:e.querySelector("input")||e}function i(e){return "[object String]"===Object.prototype.toString.call(e)}class u{constructor(e,n={}){if(!e)throw new Error("Maska: no element for mask");if(null!=n.preprocessor&&"function"!=typeof n.preprocessor)throw new Error("Maska: preprocessor must be a function");if(n.tokens)for(const e in n.tokens)n.tokens[e]={...n.tokens[e]},n.tokens[e].pattern&&i(n.tokens[e].pattern)&&(n.tokens[e].pattern=new RegExp(n.tokens[e].pattern));this._opts={mask:n.mask,tokens:{...t,...n.tokens},preprocessor:n.preprocessor},this._el=i(e)?document.querySelectorAll(e):e.length?e:[e],this.inputEvent=e=>this.updateValue(e.target,e),this.init();}init(){for(let e=0;e<this._el.length;e++){const t=o(this._el[e]);!this._opts.mask||t.dataset.mask&&t.dataset.mask===this._opts.mask||(t.dataset.mask=this._opts.mask),setTimeout((()=>this.updateValue(t)),0),t.dataset.maskInited||(t.dataset.maskInited=true,t.addEventListener("input",this.inputEvent),t.addEventListener("beforeinput",this.beforeInput));}}destroy(){for(let e=0;e<this._el.length;e++){const t=o(this._el[e]);t.removeEventListener("input",this.inputEvent),t.removeEventListener("beforeinput",this.beforeInput),delete t.dataset.mask,delete t.dataset.maskInited;}}updateValue(e,t){if(!e||!e.type)return;const s=e.type.match(/^number$/i)&&e.validity.badInput;if(!e.value&&!s||!e.dataset.mask)return e.dataset.maskRawValue="",void this.dispatch("maska",e,t);let a=e.selectionEnd;const r=e.value,o=r[a-1];e.dataset.maskRawValue=n(e.value,e.dataset.mask,this._opts.tokens,false);let i=e.value;this._opts.preprocessor&&(i=this._opts.preprocessor(i)),e.value=n(i,e.dataset.mask,this._opts.tokens),t&&"insertText"===t.inputType&&a===r.length&&(a=e.value.length),function(e,t,n){for(;t&&t<e.value.length&&e.value.charAt(t-1)!==n;)t++;(e.type?e.type.match(/^(text|search|password|tel|url)$/i):!e.type)&&e===document.activeElement&&(e.setSelectionRange(t,t),setTimeout((function(){e.setSelectionRange(t,t);}),0));}(e,a,o),this.dispatch("maska",e,t),e.value!==r&&this.dispatch("input",e,t);}beforeInput(e){e&&e.target&&e.target.type&&e.target.type.match(/^number$/i)&&e.data&&isNaN(e.target.value+e.data)&&e.preventDefault();}dispatch(e,t,n){t.dispatchEvent(function(e,t=null){const n=document.createEvent("Event");return n.initEvent(e,true,true),t&&(n.inputType=t),n}(e,n&&n.inputType||null));}}var p=(()=>{const e=new WeakMap;return (t,n)=>{n.value&&(e.has(t)&&!function(e){return !(i(e.value)&&e.value===e.oldValue||Array.isArray(e.value)&&JSON.stringify(e.value)===JSON.stringify(e.oldValue)||e.value&&e.value.mask&&e.oldValue&&e.oldValue.mask&&e.value.mask===e.oldValue.mask)}(n)||e.set(t,new u(t,function(e){const t={};return e.mask?(t.mask=Array.isArray(e.mask)?JSON.stringify(e.mask):e.mask,t.tokens=e.tokens?{...e.tokens}:{},t.preprocessor=e.preprocessor):t.mask=Array.isArray(e)?JSON.stringify(e):e,t}(n.value))));}})();function l(e){e.directive("maska",p);}"undefined"!=typeof window&&window.Vue&&window.Vue.use&&window.Vue.use(l),e.create=function(e,t){return new u(e,t)},e.default=l,e.install=l,e.mask=n,e.maska=p,e.tokens=t,Object.defineProperty(e,"__esModule",{value:true});}));
6257
- } (maska$1, maska$1.exports));
6258
- return maska$1.exports;
9704
+ /** Pipes value through mask depending on mask type, source and destination options */
9705
+ function pipe(value, mask, from, to) {
9706
+ return createPipe(mask, from, to)(value);
9707
+ }
9708
+ IMask.PIPE_TYPE = PIPE_TYPE;
9709
+ IMask.createPipe = createPipe;
9710
+ IMask.pipe = pipe;
9711
+
9712
+ /** Pattern mask */
9713
+ class RepeatBlock extends MaskedPattern {
9714
+ get repeatFrom() {
9715
+ var _ref;
9716
+ return (_ref = Array.isArray(this.repeat) ? this.repeat[0] : this.repeat === Infinity ? 0 : this.repeat) != null ? _ref : 0;
9717
+ }
9718
+ get repeatTo() {
9719
+ var _ref2;
9720
+ return (_ref2 = Array.isArray(this.repeat) ? this.repeat[1] : this.repeat) != null ? _ref2 : Infinity;
9721
+ }
9722
+ constructor(opts) {
9723
+ super(opts);
9724
+ }
9725
+ updateOptions(opts) {
9726
+ super.updateOptions(opts);
9727
+ }
9728
+ _update(opts) {
9729
+ var _ref3, _ref4, _this$_blocks;
9730
+ const {
9731
+ repeat,
9732
+ ...blockOpts
9733
+ } = normalizeOpts(opts); // TODO type
9734
+ this._blockOpts = Object.assign({}, this._blockOpts, blockOpts);
9735
+ const block = createMask(this._blockOpts);
9736
+ this.repeat = (_ref3 = (_ref4 = repeat != null ? repeat : block.repeat) != null ? _ref4 : this.repeat) != null ? _ref3 : Infinity; // TODO type
9737
+
9738
+ super._update({
9739
+ mask: 'm'.repeat(Math.max(this.repeatTo === Infinity && ((_this$_blocks = this._blocks) == null ? void 0 : _this$_blocks.length) || 0, this.repeatFrom)),
9740
+ blocks: {
9741
+ m: block
9742
+ },
9743
+ eager: block.eager,
9744
+ overwrite: block.overwrite,
9745
+ skipInvalid: block.skipInvalid,
9746
+ lazy: block.lazy,
9747
+ placeholderChar: block.placeholderChar,
9748
+ displayChar: block.displayChar
9749
+ });
9750
+ }
9751
+ _allocateBlock(bi) {
9752
+ if (bi < this._blocks.length) return this._blocks[bi];
9753
+ if (this.repeatTo === Infinity || this._blocks.length < this.repeatTo) {
9754
+ this._blocks.push(createMask(this._blockOpts));
9755
+ this.mask += 'm';
9756
+ return this._blocks[this._blocks.length - 1];
9757
+ }
9758
+ }
9759
+ _appendCharRaw(ch, flags) {
9760
+ if (flags === void 0) {
9761
+ flags = {};
9762
+ }
9763
+ const details = new ChangeDetails();
9764
+ 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;
9765
+ // try to get a block or
9766
+ // try to allocate a new block if not allocated already
9767
+ block = (_this$_blocks$bi = this._blocks[bi]) != null ? _this$_blocks$bi : allocated = !allocated && this._allocateBlock(bi); ++bi) {
9768
+ var _this$_mapPosToBlock$, _this$_mapPosToBlock, _this$_blocks$bi, _flags$_beforeTailSta;
9769
+ const blockDetails = block._appendChar(ch, {
9770
+ ...flags,
9771
+ _beforeTailState: (_flags$_beforeTailSta = flags._beforeTailState) == null || (_flags$_beforeTailSta = _flags$_beforeTailSta._blocks) == null ? void 0 : _flags$_beforeTailSta[bi]
9772
+ });
9773
+ if (blockDetails.skip && allocated) {
9774
+ // remove the last allocated block and break
9775
+ this._blocks.pop();
9776
+ this.mask = this.mask.slice(1);
9777
+ break;
9778
+ }
9779
+ details.aggregate(blockDetails);
9780
+ if (blockDetails.consumed) break; // go next char
9781
+ }
9782
+ return details;
9783
+ }
9784
+ _trimEmptyTail(fromPos, toPos) {
9785
+ var _this$_mapPosToBlock2, _this$_mapPosToBlock3;
9786
+ if (fromPos === void 0) {
9787
+ fromPos = 0;
9788
+ }
9789
+ const firstBlockIndex = Math.max(((_this$_mapPosToBlock2 = this._mapPosToBlock(fromPos)) == null ? void 0 : _this$_mapPosToBlock2.index) || 0, this.repeatFrom, 0);
9790
+ let lastBlockIndex;
9791
+ if (toPos != null) lastBlockIndex = (_this$_mapPosToBlock3 = this._mapPosToBlock(toPos)) == null ? void 0 : _this$_mapPosToBlock3.index;
9792
+ if (lastBlockIndex == null) lastBlockIndex = this._blocks.length - 1;
9793
+ let removeCount = 0;
9794
+ for (let blockIndex = lastBlockIndex; firstBlockIndex <= blockIndex; --blockIndex, ++removeCount) {
9795
+ if (this._blocks[blockIndex].unmaskedValue) break;
9796
+ }
9797
+ if (removeCount) {
9798
+ this._blocks.splice(lastBlockIndex - removeCount + 1, removeCount);
9799
+ this.mask = this.mask.slice(removeCount);
9800
+ }
9801
+ }
9802
+ reset() {
9803
+ super.reset();
9804
+ this._trimEmptyTail();
9805
+ }
9806
+ remove(fromPos, toPos) {
9807
+ if (fromPos === void 0) {
9808
+ fromPos = 0;
9809
+ }
9810
+ if (toPos === void 0) {
9811
+ toPos = this.displayValue.length;
9812
+ }
9813
+ const removeDetails = super.remove(fromPos, toPos);
9814
+ this._trimEmptyTail(fromPos, toPos);
9815
+ return removeDetails;
9816
+ }
9817
+ totalInputPositions(fromPos, toPos) {
9818
+ if (fromPos === void 0) {
9819
+ fromPos = 0;
9820
+ }
9821
+ if (toPos == null && this.repeatTo === Infinity) return Infinity;
9822
+ return super.totalInputPositions(fromPos, toPos);
9823
+ }
9824
+ get state() {
9825
+ return super.state;
9826
+ }
9827
+ set state(state) {
9828
+ this._blocks.length = state._blocks.length;
9829
+ this.mask = this.mask.slice(0, this._blocks.length);
9830
+ super.state = state;
9831
+ }
6259
9832
  }
9833
+ IMask.RepeatBlock = RepeatBlock;
6260
9834
 
6261
- var maskaExports = requireMaska();
9835
+ try {
9836
+ globalThis.IMask = IMask;
9837
+ } catch {}
6262
9838
 
6263
- export { format as f, isValid as i, maskaExports as m, parse as p };
9839
+ export { IMask as I, format as f, isValid as i, parse as p };