@verdocs/web-sdk 5.0.46 → 5.0.48

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