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