1(function (global, factory) { 2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : 3 typeof define === 'function' && define.amd ? define(['exports'], factory) : 4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.IMask = {})); 5})(this, (function (exports) { 'use strict'; 6 7 var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; 8 9 var check = function (it) { 10 return it && it.Math == Math && it; 11 }; // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 12 13 14 var global$p = // eslint-disable-next-line es/no-global-this -- safe 15 check(typeof globalThis == 'object' && globalThis) || check(typeof window == 'object' && window) || // eslint-disable-next-line no-restricted-globals -- safe 16 check(typeof self == 'object' && self) || check(typeof commonjsGlobal == 'object' && commonjsGlobal) || // eslint-disable-next-line no-new-func -- fallback 17 function () { 18 return this; 19 }() || Function('return this')(); 20 21 var objectGetOwnPropertyDescriptor = {}; 22 23 var fails$8 = function (exec) { 24 try { 25 return !!exec(); 26 } catch (error) { 27 return true; 28 } 29 }; 30 31 var fails$7 = fails$8; // Detect IE8's incomplete defineProperty implementation 32 33 34 var descriptors = !fails$7(function () { 35 // eslint-disable-next-line es/no-object-defineproperty -- required for testing 36 return Object.defineProperty({}, 1, { 37 get: function () { 38 return 7; 39 } 40 })[1] != 7; 41 }); 42 43 var fails$6 = fails$8; 44 45 var functionBindNative = !fails$6(function () { 46 var test = function () { 47 /* empty */ 48 }.bind(); // eslint-disable-next-line no-prototype-builtins -- safe 49 50 51 return typeof test != 'function' || test.hasOwnProperty('prototype'); 52 }); 53 54 var NATIVE_BIND$1 = functionBindNative; 55 56 var call$5 = Function.prototype.call; 57 var functionCall = NATIVE_BIND$1 ? call$5.bind(call$5) : function () { 58 return call$5.apply(call$5, arguments); 59 }; 60 61 var objectPropertyIsEnumerable = {}; 62 63 var $propertyIsEnumerable = {}.propertyIsEnumerable; // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe 64 65 var getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor; // Nashorn ~ JDK8 bug 66 67 var NASHORN_BUG = getOwnPropertyDescriptor$1 && !$propertyIsEnumerable.call({ 68 1: 2 69 }, 1); // `Object.prototype.propertyIsEnumerable` method implementation 70 // https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable 71 72 objectPropertyIsEnumerable.f = NASHORN_BUG ? function propertyIsEnumerable(V) { 73 var descriptor = getOwnPropertyDescriptor$1(this, V); 74 return !!descriptor && descriptor.enumerable; 75 } : $propertyIsEnumerable; 76 77 var createPropertyDescriptor$2 = function (bitmap, value) { 78 return { 79 enumerable: !(bitmap & 1), 80 configurable: !(bitmap & 2), 81 writable: !(bitmap & 4), 82 value: value 83 }; 84 }; 85 86 var NATIVE_BIND = functionBindNative; 87 88 var FunctionPrototype$1 = Function.prototype; 89 var bind = FunctionPrototype$1.bind; 90 var call$4 = FunctionPrototype$1.call; 91 var uncurryThis$b = NATIVE_BIND && bind.bind(call$4, call$4); 92 var functionUncurryThis = NATIVE_BIND ? function (fn) { 93 return fn && uncurryThis$b(fn); 94 } : function (fn) { 95 return fn && function () { 96 return call$4.apply(fn, arguments); 97 }; 98 }; 99 100 var uncurryThis$a = functionUncurryThis; 101 102 var toString$4 = uncurryThis$a({}.toString); 103 var stringSlice$1 = uncurryThis$a(''.slice); 104 105 var classofRaw$1 = function (it) { 106 return stringSlice$1(toString$4(it), 8, -1); 107 }; 108 109 var global$o = global$p; 110 111 var uncurryThis$9 = functionUncurryThis; 112 113 var fails$5 = fails$8; 114 115 var classof$2 = classofRaw$1; 116 117 var Object$4 = global$o.Object; 118 var split = uncurryThis$9(''.split); // fallback for non-array-like ES3 and non-enumerable old V8 strings 119 120 var indexedObject = fails$5(function () { 121 // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346 122 // eslint-disable-next-line no-prototype-builtins -- safe 123 return !Object$4('z').propertyIsEnumerable(0); 124 }) ? function (it) { 125 return classof$2(it) == 'String' ? split(it, '') : Object$4(it); 126 } : Object$4;
vendor: 12,307 bytes, lines 127-557
127 128 var global$n = global$p; 129 130 var TypeError$7 = global$n.TypeError; // `RequireObjectCoercible` abstract operation 131 // https://tc39.es/ecma262/#sec-requireobjectcoercible 132 133 var requireObjectCoercible$4 = function (it) { 134 if (it == undefined) throw TypeError$7("Can't call method on " + it); 135 return it; 136 }; 137 138 // toObject with fallback for non-array-like ES3 strings 139 var IndexedObject$1 = indexedObject; 140 141 var requireObjectCoercible$3 = requireObjectCoercible$4; 142 143 var toIndexedObject$3 = function (it) { 144 return IndexedObject$1(requireObjectCoercible$3(it)); 145 }; 146 147 // `IsCallable` abstract operation 148 // https://tc39.es/ecma262/#sec-iscallable 149 var isCallable$a = function (argument) { 150 return typeof argument == 'function'; 151 }; 152 153 var isCallable$9 = isCallable$a; 154 155 var isObject$5 = function (it) { 156 return typeof it == 'object' ? it !== null : isCallable$9(it); 157 }; 158 159 var global$m = global$p; 160 161 var isCallable$8 = isCallable$a; 162 163 var aFunction = function (argument) { 164 return isCallable$8(argument) ? argument : undefined; 165 }; 166 167 var getBuiltIn$3 = function (namespace, method) { 168 return arguments.length < 2 ? aFunction(global$m[namespace]) : global$m[namespace] && global$m[namespace][method]; 169 }; 170 171 var uncurryThis$8 = functionUncurryThis; 172 173 var objectIsPrototypeOf = uncurryThis$8({}.isPrototypeOf); 174 175 var getBuiltIn$2 = getBuiltIn$3; 176 177 var engineUserAgent = getBuiltIn$2('navigator', 'userAgent') || ''; 178 179 var global$l = global$p; 180 181 var userAgent$1 = engineUserAgent; 182 183 var process = global$l.process; 184 var Deno = global$l.Deno; 185 var versions = process && process.versions || Deno && Deno.version; 186 var v8 = versions && versions.v8; 187 var match, version; 188 189 if (v8) { 190 match = v8.split('.'); // in old Chrome, versions of V8 isn't V8 = Chrome / 10 191 // but their correct versions are not interesting for us 192 193 version = match[0] > 0 && match[0] < 4 ? 1 : +(match[0] + match[1]); 194 } // BrowserFS NodeJS `process` polyfill incorrectly set `.v8` to `0.0` 195 // so check `userAgent` even if `.v8` exists, but 0 196 197 198 if (!version && userAgent$1) { 199 match = userAgent$1.match(/Edge\/(\d+)/); 200 201 if (!match || match[1] >= 74) { 202 match = userAgent$1.match(/Chrome\/(\d+)/); 203 if (match) version = +match[1]; 204 } 205 } 206 207 var engineV8Version = version; 208 209 /* eslint-disable es/no-symbol -- required for testing */ 210 211 var V8_VERSION = engineV8Version; 212 213 var fails$4 = fails$8; // eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing 214 215 216 var nativeSymbol = !!Object.getOwnPropertySymbols && !fails$4(function () { 217 var symbol = Symbol(); // Chrome 38 Symbol has incorrect toString conversion 218 // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances 219 220 return !String(symbol) || !(Object(symbol) instanceof Symbol) || // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances 221 !Symbol.sham && V8_VERSION && V8_VERSION < 41; 222 }); 223 224 /* eslint-disable es/no-symbol -- required for testing */ 225 226 var NATIVE_SYMBOL$1 = nativeSymbol; 227 228 var useSymbolAsUid = NATIVE_SYMBOL$1 && !Symbol.sham && typeof Symbol.iterator == 'symbol'; 229 230 var global$k = global$p; 231 232 var getBuiltIn$1 = getBuiltIn$3; 233 234 var isCallable$7 = isCallable$a; 235 236 var isPrototypeOf = objectIsPrototypeOf; 237 238 var USE_SYMBOL_AS_UID$1 = useSymbolAsUid; 239 240 var Object$3 = global$k.Object; 241 var isSymbol$2 = USE_SYMBOL_AS_UID$1 ? function (it) { 242 return typeof it == 'symbol'; 243 } : function (it) { 244 var $Symbol = getBuiltIn$1('Symbol'); 245 return isCallable$7($Symbol) && isPrototypeOf($Symbol.prototype, Object$3(it)); 246 }; 247 248 var global$j = global$p; 249 250 var String$3 = global$j.String; 251 252 var tryToString$1 = function (argument) { 253 try { 254 return String$3(argument); 255 } catch (error) { 256 return 'Object'; 257 } 258 }; 259 260 var global$i = global$p; 261 262 var isCallable$6 = isCallable$a; 263 264 var tryToString = tryToString$1; 265 266 var TypeError$6 = global$i.TypeError; // `Assert: IsCallable(argument) is true` 267 268 var aCallable$1 = function (argument) { 269 if (isCallable$6(argument)) return argument; 270 throw TypeError$6(tryToString(argument) + ' is not a function'); 271 }; 272 273 var aCallable = aCallable$1; // `GetMethod` abstract operation 274 // https://tc39.es/ecma262/#sec-getmethod 275 276 277 var getMethod$1 = function (V, P) { 278 var func = V[P]; 279 return func == null ? undefined : aCallable(func); 280 }; 281 282 var global$h = global$p; 283 284 var call$3 = functionCall; 285 286 var isCallable$5 = isCallable$a; 287 288 var isObject$4 = isObject$5; 289 290 var TypeError$5 = global$h.TypeError; // `OrdinaryToPrimitive` abstract operation 291 // https://tc39.es/ecma262/#sec-ordinarytoprimitive 292 293 var ordinaryToPrimitive$1 = function (input, pref) { 294 var fn, val; 295 if (pref === 'string' && isCallable$5(fn = input.toString) && !isObject$4(val = call$3(fn, input))) return val; 296 if (isCallable$5(fn = input.valueOf) && !isObject$4(val = call$3(fn, input))) return val; 297 if (pref !== 'string' && isCallable$5(fn = input.toString) && !isObject$4(val = call$3(fn, input))) return val; 298 throw TypeError$5("Can't convert object to primitive value"); 299 }; 300 301 var shared$3 = {exports: {}}; 302 303 var global$g = global$p; // eslint-disable-next-line es/no-object-defineproperty -- safe 304 305 306 var defineProperty$1 = Object.defineProperty; 307 308 var setGlobal$3 = function (key, value) { 309 try { 310 defineProperty$1(global$g, key, { 311 value: value, 312 configurable: true, 313 writable: true 314 }); 315 } catch (error) { 316 global$g[key] = value; 317 } 318 319 return value; 320 }; 321 322 var global$f = global$p; 323 324 var setGlobal$2 = setGlobal$3; 325 326 var SHARED = '__core-js_shared__'; 327 var store$3 = global$f[SHARED] || setGlobal$2(SHARED, {}); 328 var sharedStore = store$3; 329 330 var store$2 = sharedStore; 331 332 (shared$3.exports = function (key, value) { 333 return store$2[key] || (store$2[key] = value !== undefined ? value : {}); 334 })('versions', []).push({ 335 version: '3.21.0', 336 mode: 'global', 337 copyright: '© 2014-2022 Denis Pushkarev (zloirock.ru)', 338 license: 'https://github.com/zloirock/core-js/blob/v3.21.0/LICENSE', 339 source: 'https://github.com/zloirock/core-js' 340 }); 341 342 var global$e = global$p; 343 344 var requireObjectCoercible$2 = requireObjectCoercible$4; 345 346 var Object$2 = global$e.Object; // `ToObject` abstract operation 347 // https://tc39.es/ecma262/#sec-toobject 348 349 var toObject$2 = function (argument) { 350 return Object$2(requireObjectCoercible$2(argument)); 351 }; 352 353 var uncurryThis$7 = functionUncurryThis; 354 355 var toObject$1 = toObject$2; 356 357 var hasOwnProperty = uncurryThis$7({}.hasOwnProperty); // `HasOwnProperty` abstract operation 358 // https://tc39.es/ecma262/#sec-hasownproperty 359 360 var hasOwnProperty_1 = Object.hasOwn || function hasOwn(it, key) { 361 return hasOwnProperty(toObject$1(it), key); 362 }; 363 364 var uncurryThis$6 = functionUncurryThis; 365 366 var id = 0; 367 var postfix = Math.random(); 368 var toString$3 = uncurryThis$6(1.0.toString); 369 370 var uid$2 = function (key) { 371 return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString$3(++id + postfix, 36); 372 }; 373 374 var global$d = global$p; 375 376 var shared$2 = shared$3.exports; 377 378 var hasOwn$6 = hasOwnProperty_1; 379 380 var uid$1 = uid$2; 381 382 var NATIVE_SYMBOL = nativeSymbol; 383 384 var USE_SYMBOL_AS_UID = useSymbolAsUid; 385 386 var WellKnownSymbolsStore = shared$2('wks'); 387 var Symbol$1 = global$d.Symbol; 388 var symbolFor = Symbol$1 && Symbol$1['for']; 389 var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid$1; 390 391 var wellKnownSymbol$3 = function (name) { 392 if (!hasOwn$6(WellKnownSymbolsStore, name) || !(NATIVE_SYMBOL || typeof WellKnownSymbolsStore[name] == 'string')) { 393 var description = 'Symbol.' + name; 394 395 if (NATIVE_SYMBOL && hasOwn$6(Symbol$1, name)) { 396 WellKnownSymbolsStore[name] = Symbol$1[name]; 397 } else if (USE_SYMBOL_AS_UID && symbolFor) { 398 WellKnownSymbolsStore[name] = symbolFor(description); 399 } else { 400 WellKnownSymbolsStore[name] = createWellKnownSymbol(description); 401 } 402 } 403 404 return WellKnownSymbolsStore[name]; 405 }; 406 407 var global$c = global$p; 408 409 var call$2 = functionCall; 410 411 var isObject$3 = isObject$5; 412 413 var isSymbol$1 = isSymbol$2; 414 415 var getMethod = getMethod$1; 416 417 var ordinaryToPrimitive = ordinaryToPrimitive$1; 418 419 var wellKnownSymbol$2 = wellKnownSymbol$3; 420 421 var TypeError$4 = global$c.TypeError; 422 var TO_PRIMITIVE = wellKnownSymbol$2('toPrimitive'); // `ToPrimitive` abstract operation 423 // https://tc39.es/ecma262/#sec-toprimitive 424 425 var toPrimitive$1 = function (input, pref) { 426 if (!isObject$3(input) || isSymbol$1(input)) return input; 427 var exoticToPrim = getMethod(input, TO_PRIMITIVE); 428 var result; 429 430 if (exoticToPrim) { 431 if (pref === undefined) pref = 'default'; 432 result = call$2(exoticToPrim, input, pref); 433 if (!isObject$3(result) || isSymbol$1(result)) return result; 434 throw TypeError$4("Can't convert object to primitive value"); 435 } 436 437 if (pref === undefined) pref = 'number'; 438 return ordinaryToPrimitive(input, pref); 439 }; 440 441 var toPrimitive = toPrimitive$1; 442 443 var isSymbol = isSymbol$2; // `ToPropertyKey` abstract operation 444 // https://tc39.es/ecma262/#sec-topropertykey 445 446 447 var toPropertyKey$2 = function (argument) { 448 var key = toPrimitive(argument, 'string'); 449 return isSymbol(key) ? key : key + ''; 450 }; 451 452 var global$b = global$p; 453 454 var isObject$2 = isObject$5; 455 456 var document$1 = global$b.document; // typeof document.createElement is 'object' in old IE 457 458 var EXISTS$1 = isObject$2(document$1) && isObject$2(document$1.createElement); 459 460 var documentCreateElement = function (it) { 461 return EXISTS$1 ? document$1.createElement(it) : {}; 462 }; 463 464 var DESCRIPTORS$6 = descriptors; 465 466 var fails$3 = fails$8; 467 468 var createElement = documentCreateElement; // Thanks to IE8 for its funny defineProperty 469 470 471 var ie8DomDefine = !DESCRIPTORS$6 && !fails$3(function () { 472 // eslint-disable-next-line es/no-object-defineproperty -- required for testing 473 return Object.defineProperty(createElement('div'), 'a', { 474 get: function () { 475 return 7; 476 } 477 }).a != 7; 478 }); 479 480 var DESCRIPTORS$5 = descriptors; 481 482 var call$1 = functionCall; 483 484 var propertyIsEnumerableModule$1 = objectPropertyIsEnumerable; 485 486 var createPropertyDescriptor$1 = createPropertyDescriptor$2; 487 488 var toIndexedObject$2 = toIndexedObject$3; 489 490 var toPropertyKey$1 = toPropertyKey$2; 491 492 var hasOwn$5 = hasOwnProperty_1; 493 494 var IE8_DOM_DEFINE$1 = ie8DomDefine; // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe 495 496 497 var $getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor; // `Object.getOwnPropertyDescriptor` method 498 // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor 499 500 objectGetOwnPropertyDescriptor.f = DESCRIPTORS$5 ? $getOwnPropertyDescriptor$1 : function getOwnPropertyDescriptor(O, P) { 501 O = toIndexedObject$2(O); 502 P = toPropertyKey$1(P); 503 if (IE8_DOM_DEFINE$1) try { 504 return $getOwnPropertyDescriptor$1(O, P); 505 } catch (error) { 506 /* empty */ 507 } 508 if (hasOwn$5(O, P)) return createPropertyDescriptor$1(!call$1(propertyIsEnumerableModule$1.f, O, P), O[P]); 509 }; 510 511 var objectDefineProperty = {}; 512 513 var DESCRIPTORS$4 = descriptors; 514 515 var fails$2 = fails$8; // V8 ~ Chrome 36- 516 // https://bugs.chromium.org/p/v8/issues/detail?id=3334 517 518 519 var v8PrototypeDefineBug = DESCRIPTORS$4 && fails$2(function () { 520 // eslint-disable-next-line es/no-object-defineproperty -- required for testing 521 return Object.defineProperty(function () { 522 /* empty */ 523 }, 'prototype', { 524 value: 42, 525 writable: false 526 }).prototype != 42; 527 }); 528 529 var global$a = global$p; 530 531 var isObject$1 = isObject$5; 532 533 var String$2 = global$a.String; 534 var TypeError$3 = global$a.TypeError; // `Assert: Type(argument) is Object` 535 536 var anObject$2 = function (argument) { 537 if (isObject$1(argument)) return argument; 538 throw TypeError$3(String$2(argument) + ' is not an object'); 539 }; 540 541 var global$9 = global$p; 542 543 var DESCRIPTORS$3 = descriptors; 544 545 var IE8_DOM_DEFINE = ie8DomDefine; 546 547 var V8_PROTOTYPE_DEFINE_BUG = v8PrototypeDefineBug; 548 549 var anObject$1 = anObject$2; 550 551 var toPropertyKey = toPropertyKey$2; 552 553 var TypeError$2 = global$9.TypeError; // eslint-disable-next-line es/no-object-defineproperty -- safe 554 555 var $defineProperty = Object.defineProperty; // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe 556 557 var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
558 var ENUMERABLE = 'enumerable'; 559 var CONFIGURABLE$1 = 'configurable'; 560 var WRITABLE = 'writable'; // `Object.defineProperty` method 561 // https://tc39.es/ecma262/#sec-object.defineproperty 562 563 objectDefineProperty.f = DESCRIPTORS$3 ? V8_PROTOTYPE_DEFINE_BUG ? function defineProperty(O, P, Attributes) { 564 anObject$1(O); 565 P = toPropertyKey(P); 566 anObject$1(Attributes); 567 568 if (typeof O === 'function' && P === 'prototype' && 'value' in Attributes && WRITABLE in Attributes && !Attributes[WRITABLE]) { 569 var current = $getOwnPropertyDescriptor(O, P); 570 571 if (current && current[WRITABLE]) { 572 O[P] = Attributes.value; 573 Attributes = { 574 configurable: CONFIGURABLE$1 in Attributes ? Attributes[CONFIGURABLE$1] : current[CONFIGURABLE$1], 575 enumerable: ENUMERABLE in Attributes ? Attributes[ENUMERABLE] : current[ENUMERABLE], 576 writable: false 577 }; 578 } 579 } 580 581 return $defineProperty(O, P, Attributes); 582 } : $defineProperty : function defineProperty(O, P, Attributes) { 583 anObject$1(O); 584 P = toPropertyKey(P); 585 anObject$1(Attributes); 586 if (IE8_DOM_DEFINE) try { 587 return $defineProperty(O, P, Attributes); 588 } catch (error) { 589 /* empty */ 590 } 591 if ('get' in Attributes || 'set' in Attributes) throw TypeError$2('Accessors not supported'); 592 if ('value' in Attributes) O[P] = Attributes.value; 593 return O; 594 }; 595 596 var DESCRIPTORS$2 = descriptors; 597 598 var definePropertyModule$1 = objectDefineProperty; 599 600 var createPropertyDescriptor = createPropertyDescriptor$2; 601 602 var createNonEnumerableProperty$3 = DESCRIPTORS$2 ? function (object, key, value) { 603 return definePropertyModule$1.f(object, key, createPropertyDescriptor(1, value)); 604 } : function (object, key, value) { 605 object[key] = value; 606 return object; 607 }; 608 609 var redefine$1 = {exports: {}}; 610 611 var uncurryThis$5 = functionUncurryThis; 612 613 var isCallable$4 = isCallable$a; 614 615 var store$1 = sharedStore; 616 617 var functionToString = uncurryThis$5(Function.toString); // this helper broken in `[email protected]`, so we can't use `shared` helper 618 619 if (!isCallable$4(store$1.inspectSource)) { 620 store$1.inspectSource = function (it) { 621 return functionToString(it); 622 }; 623 } 624 625 var inspectSource$2 = store$1.inspectSource; 626 627 var global$8 = global$p; 628 629 var isCallable$3 = isCallable$a; 630 631 var inspectSource$1 = inspectSource$2; 632 633 var WeakMap$1 = global$8.WeakMap; 634 var nativeWeakMap = isCallable$3(WeakMap$1) && /native code/.test(inspectSource$1(WeakMap$1)); 635 636 var shared$1 = shared$3.exports; 637 638 var uid = uid$2; 639 640 var keys = shared$1('keys'); 641 642 var sharedKey$1 = function (key) { 643 return keys[key] || (keys[key] = uid(key)); 644 }; 645 646 var hiddenKeys$3 = {}; 647 648 var NATIVE_WEAK_MAP = nativeWeakMap; 649 650 var global$7 = global$p; 651 652 var uncurryThis$4 = functionUncurryThis; 653 654 var isObject = isObject$5; 655 656 var createNonEnumerableProperty$2 = createNonEnumerableProperty$3; 657 658 var hasOwn$4 = hasOwnProperty_1; 659 660 var shared = sharedStore; 661 662 var sharedKey = sharedKey$1; 663 664 var hiddenKeys$2 = hiddenKeys$3; 665 666 var OBJECT_ALREADY_INITIALIZED = 'Object already initialized'; 667 var TypeError$1 = global$7.TypeError; 668 var WeakMap = global$7.WeakMap; 669 var set$1, get, has; 670 671 var enforce = function (it) { 672 return has(it) ? get(it) : set$1(it, {}); 673 }; 674 675 var getterFor = function (TYPE) { 676 return function (it) { 677 var state; 678 679 if (!isObject(it) || (state = get(it)).type !== TYPE) { 680 throw TypeError$1('Incompatible receiver, ' + TYPE + ' required'); 681 } 682 683 return state; 684 }; 685 }; 686 687 if (NATIVE_WEAK_MAP || shared.state) { 688 var store = shared.state || (shared.state = new WeakMap()); 689 var wmget = uncurryThis$4(store.get); 690 var wmhas = uncurryThis$4(store.has); 691 var wmset = uncurryThis$4(store.set); 692 693 set$1 = function (it, metadata) { 694 if (wmhas(store, it)) throw new TypeError$1(OBJECT_ALREADY_INITIALIZED); 695 metadata.facade = it; 696 wmset(store, it, metadata); 697 return metadata; 698 }; 699 700 get = function (it) { 701 return wmget(store, it) || {}; 702 }; 703 704 has = function (it) { 705 return wmhas(store, it); 706 }; 707 } else { 708 var STATE = sharedKey('state'); 709 hiddenKeys$2[STATE] = true; 710 711 set$1 = function (it, metadata) { 712 if (hasOwn$4(it, STATE)) throw new TypeError$1(OBJECT_ALREADY_INITIALIZED); 713 metadata.facade = it; 714 createNonEnumerableProperty$2(it, STATE, metadata); 715 return metadata; 716 }; 717 718 get = function (it) { 719 return hasOwn$4(it, STATE) ? it[STATE] : {}; 720 }; 721 722 has = function (it) { 723 return hasOwn$4(it, STATE); 724 }; 725 } 726 727 var internalState = { 728 set: set$1, 729 get: get, 730 has: has, 731 enforce: enforce, 732 getterFor: getterFor 733 }; 734 735 var DESCRIPTORS$1 = descriptors; 736 737 var hasOwn$3 = hasOwnProperty_1; 738 739 var FunctionPrototype = Function.prototype; // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe 740 741 var getDescriptor = DESCRIPTORS$1 && Object.getOwnPropertyDescriptor; 742 var EXISTS = hasOwn$3(FunctionPrototype, 'name'); // additional protection from minified / mangled / dropped function names 743 744 var PROPER = EXISTS && function something() { 745 /* empty */ 746 }.name === 'something'; 747 748 var CONFIGURABLE = EXISTS && (!DESCRIPTORS$1 || DESCRIPTORS$1 && getDescriptor(FunctionPrototype, 'name').configurable); 749 var functionName = { 750 EXISTS: EXISTS, 751 PROPER: PROPER, 752 CONFIGURABLE: CONFIGURABLE 753 }; 754 755 var global$6 = global$p; 756 757 var isCallable$2 = isCallable$a; 758 759 var hasOwn$2 = hasOwnProperty_1; 760 761 var createNonEnumerableProperty$1 = createNonEnumerableProperty$3; 762 763 var setGlobal$1 = setGlobal$3; 764 765 var inspectSource = inspectSource$2; 766 767 var InternalStateModule = internalState; 768 769 var CONFIGURABLE_FUNCTION_NAME = functionName.CONFIGURABLE; 770 771 var getInternalState = InternalStateModule.get; 772 var enforceInternalState = InternalStateModule.enforce;
vendor: 4,855 bytes, lines 773-916
773 var TEMPLATE = String(String).split('String'); 774 (redefine$1.exports = function (O, key, value, options) { 775 var unsafe = options ? !!options.unsafe : false; 776 var simple = options ? !!options.enumerable : false; 777 var noTargetGet = options ? !!options.noTargetGet : false; 778 var name = options && options.name !== undefined ? options.name : key; 779 var state; 780 781 if (isCallable$2(value)) { 782 if (String(name).slice(0, 7) === 'Symbol(') { 783 name = '[' + String(name).replace(/^Symbol\(([^)]*)\)/, '$1') + ']'; 784 } 785 786 if (!hasOwn$2(value, 'name') || CONFIGURABLE_FUNCTION_NAME && value.name !== name) { 787 createNonEnumerableProperty$1(value, 'name', name); 788 } 789 790 state = enforceInternalState(value); 791 792 if (!state.source) { 793 state.source = TEMPLATE.join(typeof name == 'string' ? name : ''); 794 } 795 } 796 797 if (O === global$6) { 798 if (simple) O[key] = value;else setGlobal$1(key, value); 799 return; 800 } else if (!unsafe) { 801 delete O[key]; 802 } else if (!noTargetGet && O[key]) { 803 simple = true; 804 } 805 806 if (simple) O[key] = value;else createNonEnumerableProperty$1(O, key, value); // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative 807 })(Function.prototype, 'toString', function toString() { 808 return isCallable$2(this) && getInternalState(this).source || inspectSource(this); 809 }); 810 811 var objectGetOwnPropertyNames = {}; 812 813 var ceil$1 = Math.ceil; 814 var floor = Math.floor; // `ToIntegerOrInfinity` abstract operation 815 // https://tc39.es/ecma262/#sec-tointegerorinfinity 816 817 var toIntegerOrInfinity$3 = function (argument) { 818 var number = +argument; // eslint-disable-next-line no-self-compare -- safe 819 820 return number !== number || number === 0 ? 0 : (number > 0 ? floor : ceil$1)(number); 821 }; 822 823 var toIntegerOrInfinity$2 = toIntegerOrInfinity$3; 824 825 var max = Math.max; 826 var min$1 = Math.min; // Helper for a popular repeating case of the spec: 827 // Let integer be ? ToInteger(index). 828 // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length). 829 830 var toAbsoluteIndex$1 = function (index, length) { 831 var integer = toIntegerOrInfinity$2(index); 832 return integer < 0 ? max(integer + length, 0) : min$1(integer, length); 833 }; 834 835 var toIntegerOrInfinity$1 = toIntegerOrInfinity$3; 836 837 var min = Math.min; // `ToLength` abstract operation 838 // https://tc39.es/ecma262/#sec-tolength 839 840 var toLength$2 = function (argument) { 841 return argument > 0 ? min(toIntegerOrInfinity$1(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991 842 }; 843 844 var toLength$1 = toLength$2; // `LengthOfArrayLike` abstract operation 845 // https://tc39.es/ecma262/#sec-lengthofarraylike 846 847 848 var lengthOfArrayLike$1 = function (obj) { 849 return toLength$1(obj.length); 850 }; 851 852 var toIndexedObject$1 = toIndexedObject$3; 853 854 var toAbsoluteIndex = toAbsoluteIndex$1; 855 856 var lengthOfArrayLike = lengthOfArrayLike$1; // `Array.prototype.{ indexOf, includes }` methods implementation 857 858 859 var createMethod$1 = function (IS_INCLUDES) { 860 return function ($this, el, fromIndex) { 861 var O = toIndexedObject$1($this); 862 var length = lengthOfArrayLike(O); 863 var index = toAbsoluteIndex(fromIndex, length); 864 var value; // Array#includes uses SameValueZero equality algorithm 865 // eslint-disable-next-line no-self-compare -- NaN check 866 867 if (IS_INCLUDES && el != el) while (length > index) { 868 value = O[index++]; // eslint-disable-next-line no-self-compare -- NaN check 869 870 if (value != value) return true; // Array#indexOf ignores holes, Array#includes - not 871 } else for (; length > index; index++) { 872 if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0; 873 } 874 return !IS_INCLUDES && -1; 875 }; 876 }; 877 878 var arrayIncludes = { 879 // `Array.prototype.includes` method 880 // https://tc39.es/ecma262/#sec-array.prototype.includes 881 includes: createMethod$1(true), 882 // `Array.prototype.indexOf` method 883 // https://tc39.es/ecma262/#sec-array.prototype.indexof 884 indexOf: createMethod$1(false) 885 }; 886 887 var uncurryThis$3 = functionUncurryThis; 888 889 var hasOwn$1 = hasOwnProperty_1; 890 891 var toIndexedObject = toIndexedObject$3; 892 893 var indexOf = arrayIncludes.indexOf; 894 895 var hiddenKeys$1 = hiddenKeys$3; 896 897 var push = uncurryThis$3([].push); 898 899 var objectKeysInternal = function (object, names) { 900 var O = toIndexedObject(object); 901 var i = 0; 902 var result = []; 903 var key; 904 905 for (key in O) !hasOwn$1(hiddenKeys$1, key) && hasOwn$1(O, key) && push(result, key); // Don't enum bug & hidden keys 906 907 908 while (names.length > i) if (hasOwn$1(O, key = names[i++])) { 909 ~indexOf(result, key) || push(result, key); 910 } 911 912 return result; 913 }; 914 915 // IE8- don't enum bug keys 916 var enumBugKeys$2 = ['constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleStr
vendor: 4,755 bytes, lines 916-1052
916ing', 'toString', 'valueOf']; 917 918 var internalObjectKeys$1 = objectKeysInternal; 919 920 var enumBugKeys$1 = enumBugKeys$2; 921 922 var hiddenKeys = enumBugKeys$1.concat('length', 'prototype'); // `Object.getOwnPropertyNames` method 923 // https://tc39.es/ecma262/#sec-object.getownpropertynames 924 // eslint-disable-next-line es/no-object-getownpropertynames -- safe 925 926 objectGetOwnPropertyNames.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) { 927 return internalObjectKeys$1(O, hiddenKeys); 928 }; 929 930 var objectGetOwnPropertySymbols = {}; 931 932 // eslint-disable-next-line es/no-object-getownpropertysymbols -- safe 933 objectGetOwnPropertySymbols.f = Object.getOwnPropertySymbols; 934 935 var getBuiltIn = getBuiltIn$3; 936 937 var uncurryThis$2 = functionUncurryThis; 938 939 var getOwnPropertyNamesModule = objectGetOwnPropertyNames; 940 941 var getOwnPropertySymbolsModule$1 = objectGetOwnPropertySymbols; 942 943 var anObject = anObject$2; 944 945 var concat$1 = uncurryThis$2([].concat); // all object keys, includes non-enumerable and symbols 946 947 var ownKeys$1 = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) { 948 var keys = getOwnPropertyNamesModule.f(anObject(it)); 949 var getOwnPropertySymbols = getOwnPropertySymbolsModule$1.f; 950 return getOwnPropertySymbols ? concat$1(keys, getOwnPropertySymbols(it)) : keys; 951 }; 952 953 var hasOwn = hasOwnProperty_1; 954 955 var ownKeys = ownKeys$1; 956 957 var getOwnPropertyDescriptorModule = objectGetOwnPropertyDescriptor; 958 959 var definePropertyModule = objectDefineProperty; 960 961 var copyConstructorProperties$1 = function (target, source, exceptions) { 962 var keys = ownKeys(source); 963 var defineProperty = definePropertyModule.f; 964 var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f; 965 966 for (var i = 0; i < keys.length; i++) { 967 var key = keys[i]; 968 969 if (!hasOwn(target, key) && !(exceptions && hasOwn(exceptions, key))) { 970 defineProperty(target, key, getOwnPropertyDescriptor(source, key)); 971 } 972 } 973 }; 974 975 var fails$1 = fails$8; 976 977 var isCallable$1 = isCallable$a; 978 979 var replacement = /#|\.prototype\./; 980 981 var isForced$1 = function (feature, detection) { 982 var value = data[normalize(feature)]; 983 return value == POLYFILL ? true : value == NATIVE ? false : isCallable$1(detection) ? fails$1(detection) : !!detection; 984 }; 985 986 var normalize = isForced$1.normalize = function (string) { 987 return String(string).replace(replacement, '.').toLowerCase(); 988 }; 989 990 var data = isForced$1.data = {}; 991 var NATIVE = isForced$1.NATIVE = 'N'; 992 var POLYFILL = isForced$1.POLYFILL = 'P'; 993 var isForced_1 = isForced$1; 994 995 var global$5 = global$p; 996 997 var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f; 998 999 var createNonEnumerableProperty = createNonEnumerableProperty$3; 1000 1001 var redefine = redefine$1.exports; 1002 1003 var setGlobal = setGlobal$3; 1004 1005 var copyConstructorProperties = copyConstructorProperties$1; 1006 1007 var isForced = isForced_1; 1008 /* 1009 options.target - name of the target object 1010 options.global - target is the global object 1011 options.stat - export as static methods of target 1012 options.proto - export as prototype methods of target 1013 options.real - real prototype method for the `pure` version 1014 options.forced - export even if the native feature is available 1015 options.bind - bind methods to the target, required for the `pure` version 1016 options.wrap - wrap constructors to preventing global pollution, required for the `pure` version 1017 options.unsafe - use the simple assignment of property instead of delete + defineProperty 1018 options.sham - add a flag to not completely full polyfills 1019 options.enumerable - export as enumerable property 1020 options.noTargetGet - prevent calling a getter on target 1021 options.name - the .name of the function if it does not match the key 1022 */ 1023 1024 1025 var _export = function (options, source) { 1026 var TARGET = options.target; 1027 var GLOBAL = options.global; 1028 var STATIC = options.stat; 1029 var FORCED, target, key, targetProperty, sourceProperty, descriptor; 1030 1031 if (GLOBAL) { 1032 target = global$5; 1033 } else if (STATIC) { 1034 target = global$5[TARGET] || setGlobal(TARGET, {}); 1035 } else { 1036 target = (global$5[TARGET] || {}).prototype; 1037 } 1038 1039 if (target) for (key in source) { 1040 sourceProperty = source[key]; 1041 1042 if (options.noTargetGet) { 1043 descriptor = getOwnPropertyDescriptor(target, key); 1044 targetProperty = descriptor && descriptor.value; 1045 } else targetProperty = target[key]; 1046 1047 FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced); // contained in target 1048 1049 if (!FORCED && targetProperty !== undefined) { 1050 if (typeof sourceProperty == typeof targetProperty) continue; 1051 copyConstructorProperties(sourceProperty, targetProperty); 1052 }
1052 // add a flag to not completely full polyfills 1053 1054 1055 if (options.sham || targetProperty && targetProperty.sham) { 1056 createNonEnumerableProperty(sourceProperty, 'sham', true); 1057 } // extend global 1058 1059 1060 redefine(target, key, sourceProperty, options); 1061 } 1062 }; 1063 1064 var internalObjectKeys = objectKeysInternal; 1065 1066 var enumBugKeys = enumBugKeys$2; // `Object.keys` method 1067 // https://tc39.es/ecma262/#sec-object.keys 1068 // eslint-disable-next-line es/no-object-keys -- safe 1069 1070 1071 var objectKeys$1 = Object.keys || function keys(O) { 1072 return internalObjectKeys(O, enumBugKeys); 1073 }; 1074 1075 var DESCRIPTORS = descriptors; 1076 1077 var uncurryThis$1 = functionUncurryThis; 1078 1079 var call = functionCall; 1080 1081 var fails = fails$8; 1082 1083 var objectKeys = objectKeys$1; 1084 1085 var getOwnPropertySymbolsModule = objectGetOwnPropertySymbols; 1086 1087 var propertyIsEnumerableModule = objectPropertyIsEnumerable; 1088 1089 var toObject = toObject$2; 1090 1091 var IndexedObject = indexedObject; // eslint-disable-next-line es/no-object-assign -- safe 1092 1093 1094 var $assign = Object.assign; // eslint-disable-next-line es/no-object-defineproperty -- required for testing 1095 1096 var defineProperty = Object.defineProperty; 1097 var concat = uncurryThis$1([].concat); // `Object.assign` method 1098 // https://tc39.es/ecma262/#sec-object.assign 1099 1100 var objectAssign = !$assign || fails(function () { 1101 // should have correct order of operations (Edge bug) 1102 if (DESCRIPTORS && $assign({ 1103 b: 1 1104 }, $assign(defineProperty({}, 'a', { 1105 enumerable: true, 1106 get: function () { 1107 defineProperty(this, 'b', { 1108 value: 3, 1109 enumerable: false 1110 }); 1111 } 1112 }), { 1113 b: 2 1114 })).b !== 1) return true; // should work with symbols and should have deterministic property order (V8 bug) 1115 1116 var A = {}; 1117 var B = {}; // eslint-disable-next-line es/no-symbol -- safe 1118 1119 var symbol = Symbol(); 1120 var alphabet = 'abcdefghijklmnopqrst'; 1121 A[symbol] = 7; 1122 alphabet.split('').forEach(function (chr) { 1123 B[chr] = chr; 1124 }); 1125 return $assign({}, A)[symbol] != 7 || objectKeys($assign({}, B)).join('') != alphabet; 1126 }) ? function assign(target, source) { 1127 // eslint-disable-line no-unused-vars -- required for `.length` 1128 var T = toObject(target); 1129 var argumentsLength = arguments.length; 1130 var index = 1; 1131 var getOwnPropertySymbols = getOwnPropertySymbolsModule.f; 1132 var propertyIsEnumerable = propertyIsEnumerableModule.f; 1133 1134 while (argumentsLength > index) { 1135 var S = IndexedObject(arguments[index++]); 1136 var keys = getOwnPropertySymbols ? concat(objectKeys(S), getOwnPropertySymbols(S)) : objectKeys(S); 1137 var length = keys.length; 1138 var j = 0; 1139 var key; 1140 1141 while (length > j) { 1142 key = keys[j++]; 1143 if (!DESCRIPTORS || call(propertyIsEnumerable, S, key)) T[key] = S[key]; 1144 } 1145 } 1146 1147 return T; 1148 } : $assign; 1149 1150 var $$4 = _export; 1151 1152 var assign = objectAssign; // `Object.assign` method 1153 // https://tc39.es/ecma262/#sec-object.assign 1154 // eslint-disable-next-line es/no-object-assign -- required for testing 1155 1156 1157 $$4({ 1158 target: 'Object', 1159 stat: true, 1160 forced: Object.assign !== assign 1161 }, { 1162 assign: assign 1163 }); 1164 1165 var wellKnownSymbol$1 = wellKnownSymbol$3; 1166 1167 var TO_STRING_TAG$1 = wellKnownSymbol$1('toStringTag'); 1168 var test = {}; 1169 test[TO_STRING_TAG$1] = 'z'; 1170 var toStringTagSupport = String(test) === '[object z]'; 1171 1172 var global$4 = global$p; 1173 1174 var TO_STRING_TAG_SUPPORT = toStringTagSupport; 1175 1176 var isCallable = isCallable$a; 1177 1178 var classofRaw = classofRaw$1; 1179 1180 var wellKnownSymbol = wellKnownSymbol$3; 1181 1182 var TO_STRING_TAG = wellKnownSymbol('toStringTag'); 1183 var Object$1 = global$4.Object; // ES3 wrong here 1184 1185 var CORRECT_ARGUMENTS = classofRaw(function () { 1186 return arguments; 1187 }()) == 'Arguments'; // fallback for IE11 Script Access Denied error 1188 1189 var tryGet = function (it, key) { 1190 try { 1191 return it[key]; 1192 } catch (error) { 1193 /* empty */ 1194 } 1195 }; // getting tag from ES6+ `Object.prototype.toString` 1196 1197 1198 var classof$1 = TO_STRING_TAG_SUPPORT ? classofRaw : function (it) { 1199 var O, tag, result; 1200 return it === undefined ? 'Undefined' : it === null ? 'Null' // @@toStringTag case 1201 : typeof (tag = tryGet(O = Object$1(it), TO_STRING_TAG)) == 'string' ? tag // builtinTag case 1202 : CORRECT_ARGUMENTS ? classofRaw(O) // ES3 arguments fallback 1203 : (result = classofRaw(O)) == 'Object' && isCallable(O.callee) ? 'Arguments' : result; 1204 }; 1205 1206 var global$3 = global$p; 1207 1208 var classof = classof$1; 1209 1210 var String$1 = global$3.String; 1211 1212 var toString$2 = function (argument) { 1213 if (classof(argument) === 'Symbol') throw TypeError('Cannot convert a Symbol value to a string'); 1214 return String$1(argument); 1215 }; 1216 1217 var global$2 = global$p; 1218 1219 var toIntegerOrInfinity = toIntegerOrInfinity$3; 1220 1221 var toString$1 = toString$2; 1222 1223 var requireObjectCoercible$1 = requireObjectCoercible$4; 1224 1225 var RangeError = global$2.RangeError; // `String.prototype.repeat` method implementation 1226 // https://tc39.es/ecma262/#sec-string.prototype.repeat 1227 1228 var stringRepeat = function repeat(count) { 1229 var str = toString$1(requireObjectCoercible$1(this)); 1230 var result = ''; 1231 var n = toIntegerOrInfinity(count); 1232 if (n < 0 || n == Infinity) throw RangeError('Wrong number of repetitions'); 1233 1234 for (; n > 0; (n >>>= 1) && (str += str)) if (n & 1) result += str; 1235 1236 return result; 1237 }; 1238 1239 var $$3 = _export; 1240 1241 var repeat$1 = stringRepeat; // `String.prototype.repeat` method 1242 // https://tc39.es/ecma262/#sec-string.prototype.repeat 1243 1244 1245 $$3({ 1246 target: 'String', 1247 proto: true 1248 }, { 1249 repeat: repeat$1 1250 }); 1251 1252 // https://github.com/tc39/proposal-string-pad-start-end 1253 var uncurryThis = functionUncurryThis; 1254 1255 var toLength = toLength$2; 1256 1257 var toString = toString$2; 1258 1259 var $repeat = stringRepeat; 1260 1261 var requireObjectCoercible = requireObjectCoercible$4; 1262 1263 var repeat = uncurryThis($repeat); 1264 var stringSlice = uncurryThis(''.slice);
1265 var ceil = Math.ceil; // `String.prototype.{ padStart, padEnd }` methods implementation 1266 1267 var createMethod = function (IS_END) { 1268 return function ($this, maxLength, fillString) { 1269 var S = toString(requireObjectCoercible($this)); 1270 var intMaxLength = toLength(maxLength); 1271 var stringLength = S.length; 1272 var fillStr = fillString === undefined ? ' ' : toString(fillString); 1273 var fillLen, stringFiller; 1274 if (intMaxLength <= stringLength || fillStr == '') return S; 1275 fillLen = intMaxLength - stringLength; 1276 stringFiller = repeat(fillStr, ceil(fillLen / fillStr.length)); 1277 if (stringFiller.length > fillLen) stringFiller = stringSlice(stringFiller, 0, fillLen); 1278 return IS_END ? S + stringFiller : stringFiller + S; 1279 }; 1280 }; 1281 1282 var stringPad = { 1283 // `String.prototype.padStart` method 1284 // https://tc39.es/ecma262/#sec-string.prototype.padstart 1285 start: createMethod(false), 1286 // `String.prototype.padEnd` method 1287 // https://tc39.es/ecma262/#sec-string.prototype.padend 1288 end: createMethod(true) 1289 }; 1290 1291 // https://github.com/zloirock/core-js/issues/280 1292 var userAgent = engineUserAgent; 1293 1294 var stringPadWebkitBug = /Version\/10(?:\.\d+){1,2}(?: [\w./]+)?(?: Mobile\/\w+)? Safari\//.test(userAgent); 1295 1296 var $$2 = _export; 1297 1298 var $padStart = stringPad.start; 1299 1300 var WEBKIT_BUG$1 = stringPadWebkitBug; // `String.prototype.padStart` method 1301 // https://tc39.es/ecma262/#sec-string.prototype.padstart 1302 1303 1304 $$2({ 1305 target: 'String', 1306 proto: true, 1307 forced: WEBKIT_BUG$1 1308 }, { 1309 padStart: function padStart(maxLength 1310 /* , fillString = ' ' */ 1311 ) { 1312 return $padStart(this, maxLength, arguments.length > 1 ? arguments[1] : undefined); 1313 } 1314 }); 1315 1316 var $$1 = _export; 1317 1318 var $padEnd = stringPad.end; 1319 1320 var WEBKIT_BUG = stringPadWebkitBug; // `String.prototype.padEnd` method 1321 // https://tc39.es/ecma262/#sec-string.prototype.padend 1322 1323 1324 $$1({ 1325 target: 'String', 1326 proto: true, 1327 forced: WEBKIT_BUG 1328 }, { 1329 padEnd: function padEnd(maxLength 1330 /* , fillString = ' ' */ 1331 ) { 1332 return $padEnd(this, maxLength, arguments.length > 1 ? arguments[1] : undefined); 1333 } 1334 }); 1335 1336 var $ = _export; 1337 1338 var global$1 = global$p; // `globalThis` object 1339 // https://tc39.es/ecma262/#sec-globalthis 1340 1341 1342 $({ 1343 global: true 1344 }, { 1345 globalThis: global$1 1346 }); 1347 1348 function _typeof(obj) { 1349 "@babel/helpers - typeof"; 1350 1351 return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { 1352 return typeof obj; 1353 } : function (obj) { 1354 return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; 1355 }, _typeof(obj); 1356 } 1357 1358 function _classCallCheck(instance, Constructor) { 1359 if (!(instance instanceof Constructor)) { 1360 throw new TypeError("Cannot call a class as a function"); 1361 } 1362 } 1363 1364 function _defineProperties(target, props) { 1365 for (var i = 0; i < props.length; i++) { 1366 var descriptor = props[i]; 1367 descriptor.enumerable = descriptor.enumerable || false; 1368 descriptor.configurable = true; 1369 if ("value" in descriptor) descriptor.writable = true; 1370 Object.defineProperty(target, descriptor.key, descriptor); 1371 } 1372 } 1373 1374 function _createClass(Constructor, protoProps, staticProps) { 1375 if (protoProps) _defineProperties(Constructor.prototype, protoProps); 1376 if (staticProps) _defineProperties(Constructor, staticProps); 1377 Object.defineProperty(Constructor, "prototype", { 1378 writable: false 1379 }); 1380 return Constructor; 1381 } 1382 1383 function _defineProperty(obj, key, value) { 1384 if (key in obj) { 1385 Object.defineProperty(obj, key, { 1386 value: value, 1387 enumerable: true, 1388 configurable: true, 1389 writable: true 1390 }); 1391 } else { 1392 obj[key] = value; 1393 } 1394 1395 return obj; 1396 } 1397 1398 function _inherits(subClass, superClass) { 1399 if (typeof superClass !== "function" && superClass !== null) { 1400 throw new TypeError("Super expression must either be null or a function"); 1401 } 1402 1403 subClass.prototype = Object.create(superClass && superClass.prototype, { 1404 constructor: { 1405 value: subClass, 1406 writable: true, 1407 configurable: true 1408 } 1409 }); 1410 Object.defineProperty(subClass, "prototype", { 1411 writable: false 1412 }); 1413 if (superClass) _setPrototypeOf(subClass, superClass); 1414 } 1415
1416 function _getPrototypeOf(o) { 1417 _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { 1418 return o.__proto__ || Object.getPrototypeOf(o); 1419 }; 1420 return _getPrototypeOf(o); 1421 } 1422 1423 function _setPrototypeOf(o, p) { 1424 _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { 1425 o.__proto__ = p; 1426 return o; 1427 }; 1428 1429 return _setPrototypeOf(o, p); 1430 } 1431 1432 function _isNativeReflectConstruct() { 1433 if (typeof Reflect === "undefined" || !Reflect.construct) return false; 1434 if (Reflect.construct.sham) return false; 1435 if (typeof Proxy === "function") return true; 1436 1437 try { 1438 Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); 1439 return true; 1440 } catch (e) { 1441 return false; 1442 } 1443 } 1444 1445 function _objectWithoutPropertiesLoose(source, excluded) { 1446 if (source == null) return {}; 1447 var target = {}; 1448 var sourceKeys = Object.keys(source); 1449 var key, i; 1450 1451 for (i = 0; i < sourceKeys.length; i++) { 1452 key = sourceKeys[i]; 1453 if (excluded.indexOf(key) >= 0) continue; 1454 target[key] = source[key]; 1455 } 1456 1457 return target; 1458 } 1459 1460 function _objectWithoutProperties(source, excluded) { 1461 if (source == null) return {}; 1462 1463 var target = _objectWithoutPropertiesLoose(source, excluded); 1464 1465 var key, i; 1466 1467 if (Object.getOwnPropertySymbols) { 1468 var sourceSymbolKeys = Object.getOwnPropertySymbols(source); 1469 1470 for (i = 0; i < sourceSymbolKeys.length; i++) { 1471 key = sourceSymbolKeys[i]; 1472 if (excluded.indexOf(key) >= 0) continue; 1473 if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; 1474 target[key] = source[key]; 1475 } 1476 } 1477 1478 return target; 1479 } 1480 1481 function _assertThisInitialized(self) { 1482 if (self === void 0) { 1483 throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); 1484 } 1485 1486 return self; 1487 } 1488 1489 function _possibleConstructorReturn(self, call) { 1490 if (call && (typeof call === "object" || typeof call === "function")) { 1491 return call; 1492 } else if (call !== void 0) { 1493 throw new TypeError("Derived constructors may only return object or undefined"); 1494 } 1495 1496 return _assertThisInitialized(self); 1497 } 1498 1499 function _createSuper(Derived) { 1500 var hasNativeReflectConstruct = _isNativeReflectConstruct(); 1501 1502 return function _createSuperInternal() { 1503 var Super = _getPrototypeOf(Derived), 1504 result; 1505 1506 if (hasNativeReflectConstruct) { 1507 var NewTarget = _getPrototypeOf(this).constructor; 1508 1509 result = Reflect.construct(Super, arguments, NewTarget); 1510 } else { 1511 result = Super.apply(this, arguments); 1512 } 1513 1514 return _possibleConstructorReturn(this, result); 1515 }; 1516 } 1517 1518 function _superPropBase(object, property) { 1519 while (!Object.prototype.hasOwnProperty.call(object, property)) { 1520 object = _getPrototypeOf(object); 1521 if (object === null) break; 1522 } 1523 1524 return object; 1525 } 1526 1527 function _get() { 1528 if (typeof Reflect !== "undefined" && Reflect.get) { 1529 _get = Reflect.get; 1530 } else { 1531 _get = function _get(target, property, receiver) { 1532 var base = _superPropBase(target, property); 1533 1534 if (!base) return; 1535 var desc = Object.getOwnPropertyDescriptor(base, property); 1536 1537 if (desc.get) { 1538 return desc.get.call(arguments.length < 3 ? target : receiver); 1539 } 1540 1541 return desc.value; 1542 }; 1543 } 1544 1545 return _get.apply(this, arguments); 1546 } 1547 1548 function set(target, property, value, receiver) { 1549 if (typeof Reflect !== "undefined" && Reflect.set) { 1550 set = Reflect.set; 1551 } else { 1552 set = function set(target, property, value, receiver) { 1553 var base = _superPropBase(target, property); 1554 1555 var desc; 1556 1557 if (base) { 1558 desc = Object.getOwnPropertyDescriptor(base, property); 1559 1560 if (desc.set) { 1561 desc.set.call(receiver, value); 1562 return true; 1563 } else if (!desc.writable) { 1564 return false; 1565 } 1566 } 1567 1568 desc = Object.getOwnPropertyDescriptor(receiver, property); 1569 1570 if (desc) { 1571 if (!desc.writable) { 1572 return false; 1573 } 1574 1575 desc.value = value; 1576 Object.defineProperty(receiver, property, desc); 1577 } else { 1578 _defineProperty(receiver, property, value); 1579 } 1580 1581 return true; 1582 }; 1583 } 1584 1585 return set(target, property, value, receiver); 1586 } 1587 1588 function _set(target, property, value, receiver, isStrict) { 1589 var s = set(target, property, value, receiver || target); 1590 1591 if (!s && isStrict) { 1592 throw new Error('failed to set property'); 1593 } 1594 1595 return value; 1596 } 1597 1598 function _slicedToArray(arr, i) { 1599 return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); 1600 } 1601 1602 function _arrayWithHoles(arr) { 1603 if (Array.isArray(arr)) return arr; 1604 } 1605 1606 function _iterableToArrayLimit(arr, i) { 1607 var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; 1608 1609 if (_i == null) return; 1610 var _arr = []; 1611 var _n = true; 1612 var _d = false;
1613 1614 var _s, _e; 1615 1616 try { 1617 for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { 1618 _arr.push(_s.value); 1619 1620 if (i && _arr.length === i) break; 1621 } 1622 } catch (err) { 1623 _d = true; 1624 _e = err; 1625 } finally { 1626 try { 1627 if (!_n && _i["return"] != null) _i["return"](); 1628 } finally { 1629 if (_d) throw _e; 1630 } 1631 } 1632 1633 return _arr; 1634 } 1635 1636 function _unsupportedIterableToArray(o, minLen) { 1637 if (!o) return; 1638 if (typeof o === "string") return _arrayLikeToArray(o, minLen); 1639 var n = Object.prototype.toString.call(o).slice(8, -1); 1640 if (n === "Object" && o.constructor) n = o.constructor.name; 1641 if (n === "Map" || n === "Set") return Array.from(o); 1642 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); 1643 } 1644 1645 function _arrayLikeToArray(arr, len) { 1646 if (len == null || len > arr.length) len = arr.length; 1647 1648 for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; 1649 1650 return arr2; 1651 } 1652 1653 function _nonIterableRest() { 1654 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); 1655 } 1656 1657 /** 1658 Provides details of changing model value 1659 @param {Object} [details] 1660 @param {string} [details.inserted] - Inserted symbols 1661 @param {boolean} [details.skip] - Can skip chars 1662 @param {number} [details.removeCount] - Removed symbols count 1663 @param {number} [details.tailShift] - Additional offset if any changes occurred before tail 1664 */ 1665 var ChangeDetails = /*#__PURE__*/function () { 1666 /** Inserted symbols */ 1667 1668 /** Can skip chars */ 1669 1670 /** Additional offset if any changes occurred before tail */ 1671 1672 /** Raw inserted is used by dynamic mask */ 1673 function ChangeDetails(details) { 1674 _classCallCheck(this, ChangeDetails); 1675 1676 Object.assign(this, { 1677 inserted: '', 1678 rawInserted: '', 1679 skip: false, 1680 tailShift: 0 1681 }, details); 1682 } 1683 /** 1684 Aggregate changes 1685 @returns {ChangeDetails} `this` 1686 */ 1687 1688 1689 _createClass(ChangeDetails, [{ 1690 key: "aggregate", 1691 value: function aggregate(details) { 1692 this.rawInserted += details.rawInserted; 1693 this.skip = this.skip || details.skip; 1694 this.inserted += details.inserted; 1695 this.tailShift += details.tailShift; 1696 return this; 1697 } 1698 /** Total offset considering all changes */ 1699 1700 }, { 1701 key: "offset", 1702 get: function get() { 1703 return this.tailShift + this.inserted.length; 1704 } 1705 }]); 1706 1707 return ChangeDetails; 1708 }(); 1709 1710 /** Checks if value is string */ 1711 1712 function isString(str) { 1713 return typeof str === 'string' || str instanceof String; 1714 } 1715 /** 1716 Direction 1717 @prop {string} NONE 1718 @prop {string} LEFT 1719 @prop {string} FORCE_LEFT 1720 @prop {string} RIGHT 1721 @prop {string} FORCE_RIGHT 1722 */ 1723 1724 var DIRECTION = { 1725 NONE: 'NONE', 1726 LEFT: 'LEFT', 1727 FORCE_LEFT: 'FORCE_LEFT', 1728 RIGHT: 'RIGHT', 1729 FORCE_RIGHT: 'FORCE_RIGHT' 1730 }; 1731 /** */ 1732 1733 function forceDirection(direction) { 1734 switch (direction) { 1735 case DIRECTION.LEFT: 1736 return DIRECTION.FORCE_LEFT; 1737 1738 case DIRECTION.RIGHT: 1739 return DIRECTION.FORCE_RIGHT; 1740 1741 default: 1742 return direction; 1743 } 1744 } 1745 /** Escapes regular expression control chars */ 1746 1747 function escapeRegExp(str) { 1748 return str.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1'); 1749 } 1750 function normalizePrepare(prep) { 1751 return Array.isArray(prep) ? prep : [prep, new ChangeDetails()]; 1752 } // cloned from https://github.com/epoberezkin/fast-deep-equal with small changes 1753 1754 function objectIncludes(b, a) { 1755 if (a === b) return true; 1756 var arrA = Array.isArray(a), 1757 arrB = Array.isArray(b), 1758 i; 1759 1760 if (arrA && arrB) { 1761 if (a.length != b.length) return false; 1762 1763 for (i = 0; i < a.length; i++) { 1764 if (!objectIncludes(a[i], b[i])) return false; 1765 } 1766 1767 return true; 1768 } 1769 1770 if (arrA != arrB) return false; 1771 1772 if (a && b && _typeof(a) === 'object' && _typeof(b) === 'object') { 1773 var dateA = a instanceof Date, 1774 dateB = b instanceof Date; 1775 if (dateA && dateB) return a.getTime() == b.getTime(); 1776 if (dateA != dateB) return false;
1777 var regexpA = a instanceof RegExp, 1778 regexpB = b instanceof RegExp; 1779 if (regexpA && regexpB) return a.toString() == b.toString(); 1780 if (regexpA != regexpB) return false; 1781 var keys = Object.keys(a); // if (keys.length !== Object.keys(b).length) return false; 1782 1783 for (i = 0; i < keys.length; i++) { 1784 // $FlowFixMe ... ??? 1785 if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false; 1786 } 1787 1788 for (i = 0; i < keys.length; i++) { 1789 if (!objectIncludes(b[keys[i]], a[keys[i]])) return false; 1790 } 1791 1792 return true; 1793 } else if (a && b && typeof a === 'function' && typeof b === 'function') { 1794 return a.toString() === b.toString(); 1795 } 1796 1797 return false; 1798 } 1799 /** Selection range */ 1800 1801 /** Provides details of changing input */ 1802 1803 var ActionDetails = /*#__PURE__*/function () { 1804 /** Current input value */ 1805 1806 /** Current cursor position */ 1807 1808 /** Old input value */ 1809 1810 /** Old selection */ 1811 function ActionDetails(value, cursorPos, oldValue, oldSelection) { 1812 _classCallCheck(this, ActionDetails); 1813 1814 this.value = value;
1815 this.cursorPos = cursorPos; 1816 this.oldValue = oldValue; 1817 this.oldSelection = oldSelection; // double check if left part was changed (autofilling, other non-standard input triggers) 1818 1819 while (this.value.slice(0, this.startChangePos) !== this.oldValue.slice(0, this.startChangePos)) { 1820 --this.oldSelection.start; 1821 } 1822 } 1823 /** 1824 Start changing position 1825 @readonly 1826 */ 1827 1828 1829 _createClass(ActionDetails, [{ 1830 key: "startChangePos", 1831 get: function get() { 1832 return Math.min(this.cursorPos, this.oldSelection.start); 1833 } 1834 /** 1835 Inserted symbols count 1836 @readonly 1837 */ 1838 1839 }, { 1840 key: "insertedCount", 1841 get: function get() { 1842 return this.cursorPos - this.startChangePos; 1843 } 1844 /** 1845 Inserted symbols 1846 @readonly 1847 */ 1848 1849 }, { 1850 key: "inserted", 1851 get: function get() { 1852 return this.value.substr(this.startChangePos, this.insertedCount); 1853 } 1854 /** 1855 Removed symbols count 1856 @readonly 1857 */ 1858 1859 }, { 1860 key: "removedCount", 1861 get: function get() { 1862 // Math.max for opposite operation 1863 return Math.max(this.oldSelection.end - this.startChangePos || // for Delete 1864 this.oldValue.length - this.value.length, 0); 1865 } 1866 /** 1867 Removed symbols 1868 @readonly 1869 */ 1870 1871 }, { 1872 key: "removed", 1873 get: function get() { 1874 return this.oldValue.substr(this.startChangePos, this.removedCount); 1875 } 1876 /** 1877 Unchanged head symbols 1878 @readonly 1879 */ 1880 1881 }, { 1882 key: "head", 1883 get: function get() { 1884 return this.value.substring(0, this.startChangePos); 1885 } 1886 /** 1887 Unchanged tail symbols 1888 @readonly 1889 */ 1890 1891 }, { 1892 key: "tail", 1893 get: function get() { 1894 return this.value.substring(this.startChangePos + this.insertedCount); 1895 } 1896 /** 1897 Remove direction 1898 @readonly 1899 */ 1900 1901 }, { 1902 key: "removeDirection", 1903 get: function get() { 1904 if (!this.removedCount || this.insertedCount) return DIRECTION.NONE; // align right if delete at right 1905 1906 return (this.oldSelection.end === this.cursorPos || this.oldSelection.start === this.cursorPos) && // if not range removed (event with backspace) 1907 this.oldSelection.end === this.oldSelection.start ? DIRECTION.RIGHT : DIRECTION.LEFT; 1908 } 1909 }]); 1910 1911 return ActionDetails; 1912 }(); 1913 1914 /** Provides details of continuous extracted tail */ 1915 var ContinuousTailDetails = /*#__PURE__*/function () { 1916 /** Tail value as string */ 1917 1918 /** Tail start position */ 1919 1920 /** Start position */ 1921 function ContinuousTailDetails() { 1922 var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; 1923 var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; 1924 var stop = arguments.length > 2 ? arguments[2] : undefined; 1925 1926 _classCallCheck(this, ContinuousTailDetails); 1927 1928 this.value = value; 1929 this.from = from; 1930 this.stop = stop; 1931 } 1932 1933 _createClass(ContinuousTailDetails, [{ 1934 key: "toString", 1935 value: function toString() { 1936 return this.value; 1937 } 1938 }, { 1939 key: "extend", 1940 value: function extend(tail) { 1941 this.value += String(tail); 1942 } 1943 }, { 1944 key: "appendTo", 1945 value: function appendTo(masked) { 1946 return masked.append(this.toString(), { 1947 tail: true 1948 }).aggregate(masked._appendPlaceholder()); 1949 } 1950 }, { 1951 key: "state", 1952 get: function get() { 1953 return { 1954 value: this.value, 1955 from: this.from, 1956 stop: this.stop 1957 }; 1958 }, 1959 set: function set(state) { 1960 Object.assign(this, state); 1961 } 1962 }, { 1963 key: "unshift", 1964 value: function unshift(beforePos) { 1965 if (!this.value.length || beforePos != null && this.from >= beforePos) return ''; 1966 var shiftChar = this.value[0]; 1967 this.value = this.value.slice(1); 1968 return shiftChar; 1969 } 1970 }, { 1971 key: "shift", 1972 value: function shift() { 1973 if (!this.value.length) return ''; 1974 var shiftChar = this.value[this.value.length - 1]; 1975 this.value = this.value.slice(0, -1); 1976 return shiftChar; 1977 } 1978 }]); 1979 1980 return ContinuousTailDetails; 1981 }(); 1982 1983 /** 1984 * Applies mask on element. 1985 * @constructor 1986 * @param {HTMLInputElement|HTMLTextAreaElement|MaskElement} el - Element to apply mask 1987 * @param {Object} opts - Custom mask options 1988 * @return {InputMask} 1989 */ 1990 function IMask(el) { 1991 var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 1992 // currently available only for input-like elements 1993 return new IMask.InputMask(el, opts); 1994 } 1995 1996 /** Supported mask type */ 1997 1998 /** Provides common masking stuff */ 1999 var Masked = /*#__PURE__*/function () { 2000 // $Shape<MaskedOptions>; TODO after fix https://github.com/facebook/flow/issues/4773 2001 2002 /** @type {Mask} */ 2003 2004 /** */ 2005 // $FlowFixMe no ideas 2006 2007 /** Transforms value before mask processing */ 2008 2009 /** Validates if value is acceptable */ 2010 2011 /** Does additional processing in the end of editing */ 2012 2013 /** Format typed value to string */ 2014 2015 /** Parse strgin to get typed value */ 2016 2017 /** Enable characters overwriting */ 2018 2019 /** */ 2020 2021 /** */ 2022 function Masked(opts) { 2023 _classCallCheck(this, Masked); 2024 2025 this._value = ''; 2026 2027 this._update(Object.assign({}, Masked.DEFAULTS, opts)); 2028 2029 this.isInitialized = true; 2030 } 2031 /** Sets and applies new options */ 2032 2033 2034 _createClass(Masked, [{ 2035 key: "updateOptions", 2036 value: function updateOptions(opts) { 2037 if (!Object.keys(opts).length) return; // $FlowFixMe 2038 2039 this.withValueRefresh(this._update.bind(this, opts)); 2040 } 2041 /** 2042 Sets new options 2043 @protected 2044 */ 2045 2046 }, { 2047 key: "_update", 2048 value: function _update(opts) { 2049 Object.assign(this, opts); 2050 } 2051 /** Mask state */ 2052 2053 }, { 2054 key: "state", 2055 get: function get() { 2056 return { 2057 _value: this.value 2058 }; 2059 }, 2060 set: function set(state) { 2061 this._value = state._value; 2062 } 2063 /** Resets value */ 2064 2065 }, { 2066 key: "reset", 2067 value: function reset() { 2068 this._value = ''; 2069 } 2070 /** */ 2071 2072 }, { 2073 key: "value", 2074 get: function get() { 2075 return this._value; 2076 }, 2077 set: function set(value) { 2078 this.resolve(value); 2079 } 2080 /** Resolve new value */ 2081 2082 }, { 2083 key: "resolve", 2084 value: function resolve(value) { 2085 this.reset(); 2086 this.append(value, { 2087 input: true 2088 }, ''); 2089 this.doCommit(); 2090 return this.value; 2091 } 2092 /** */ 2093 2094 }, { 2095 key: "unmaskedValue", 2096 get: function get() { 2097 return this.value; 2098 }, 2099 set: function set(value) { 2100 this.reset(); 2101 this.append(value, {}, ''); 2102 this.doCommit(); 2103 } 2104 /** */ 2105 2106 }, { 2107 key: "typedValue", 2108 get: function get() { 2109 return this.doParse(this.value); 2110 }, 2111 set: function set(value) { 2112 this.value = this.doFormat(value); 2113 } 2114 /** Value that includes raw user input */ 2115 2116 }, { 2117 key: "rawInputValue", 2118 get: function get() { 2119 return this.extractInput(0, this.value.length, { 2120 raw: true 2121 }); 2122 }, 2123 set: function set(value) { 2124 this.reset(); 2125 this.append(value, { 2126 raw: true 2127 }, ''); 2128 this.doCommit(); 2129 } 2130 /** */ 2131 2132 }, { 2133 key: "isComplete", 2134 get: function get() { 2135 return true; 2136 } 2137 /** */ 2138 2139 }, { 2140 key: "isFilled", 2141 get: function get() { 2142 return this.isComplete; 2143 } 2144 /** Finds nearest input position in direction */ 2145 2146 }, { 2147 key: "nearestInputPos", 2148 value: function nearestInputPos(cursorPos, direction) { 2149 return cursorPos; 2150 } 2151 /** Extracts value in range considering flags */ 2152 2153 }, { 2154 key: "extractInput", 2155 value: function extractInput() { 2156 var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; 2157 var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length; 2158 return this.value.slice(fromPos, toPos); 2159 } 2160 /** Extracts tail in range */ 2161 2162 }, { 2163 key: "extractTail", 2164 value: function extractTail() { 2165 var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; 2166 var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length; 2167 return new ContinuousTailDetails(this.extractInput(fromPos, toPos), fromPos); 2168 } 2169 /** Appends tail */ 2170 // $FlowFixMe no ideas 2171 2172 }, { 2173 key: "appendTail", 2174 value: function appendTail(tail) { 2175 if (isString(tail)) tail = new ContinuousTailDetails(String(tail)); 2176 return tail.appendTo(this); 2177 } 2178 /** Appends char */ 2179 2180 }, { 2181 key: "_appendCharRaw", 2182 value: function _appendCharRaw(ch) { 2183 if (!ch) return new ChangeDetails(); 2184 this._value += ch; 2185 return new ChangeDetails({ 2186 inserted: ch, 2187 rawInserted: ch 2188 }); 2189 } 2190 /** Appends char */ 2191 2192 }, { 2193 key: "_appendChar", 2194 value: function _appendChar(ch) { 2195 var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 2196 var checkTail = arguments.length > 2 ? arguments[2] : undefined; 2197 var consistentState = this.state; 2198 var details; 2199 2200 var _normalizePrepare = normalizePrepare(this.doPrepare(ch, flags)); 2201 2202 var _normalizePrepare2 = _slicedToArray(_normalizePrepare, 2); 2203 2204 ch = _normalizePrepare2[0]; 2205 details = _normalizePrepare2[1]; 2206 details = details.aggregate(this._appendCharRaw(ch, flags)); 2207 2208 if (details.inserted) { 2209 var consistentTail; 2210 var appended = this.doValidate(flags) !== false; 2211 2212 if (appended && checkTail != null) { 2213 // validation ok, check tail 2214 var beforeTailState = this.state; 2215 2216 if (this.overwrite === true) { 2217 consistentTail = checkTail.state; 2218 checkTail.unshift(this.value.length); 2219 } 2220 2221 var tailDetails = this.appendTail(checkTail); 2222 appended = tailDetails.rawInserted === checkTail.toString(); // not ok, try shift 2223 2224 if (!(appended && tailDetails.inserted) && this.overwrite === 'shift') { 2225 this.state = beforeTailState; 2226 consistentTail = checkTail.state; 2227 checkTail.shift(); 2228 tailDetails = this.appendTail(checkTail); 2229 appended = tailDetails.rawInserted === checkTail.toString(); 2230 } // if ok, rollback state after tail 2231 2232 2233 if (appended && tailDetails.inserted) this.state = beforeTailState; 2234 } // revert all if something went wrong 2235 2236 2237 if (!appended) { 2238 details = new ChangeDetails(); 2239 this.state = consistentState; 2240 if (checkTail && consistentTail) checkTail.state = consistentTail; 2241 } 2242 } 2243 2244 return details; 2245 } 2246 /** Appends optional placeholder at end */ 2247 2248 }, { 2249 key: "_appendPlaceholder", 2250 value: function _appendPlaceholder() { 2251 return new ChangeDetails(); 2252 } 2253 /** Appends optional eager placeholder at end */ 2254 2255 }, { 2256 key: "_appendEager", 2257 value: function _appendEager() { 2258 return new ChangeDetails(); 2259 } 2260 /** Appends symbols considering flags */ 2261 // $FlowFixMe no ideas 2262 2263 }, { 2264 key: "append", 2265 value: function append(str, flags, tail) { 2266 if (!isString(str)) throw new Error('value should be string'); 2267 var details = new ChangeDetails(); 2268 var checkTail = isString(tail) ? new ContinuousTailDetails(String(tail)) : tail; 2269 if (flags && flags.tail) flags._beforeTailState = this.state; 2270 2271 for (var ci = 0; ci < str.length; ++ci) { 2272 details.aggregate(this._appendChar(str[ci], flags, checkTail)); 2273 } // append tail but aggregate only tailShift 2274 2275 2276 if (checkTail != null) { 2277 details.tailShift += this.appendTail(checkTail).tailShift; // TODO it's a good idea to clear state after appending ends 2278 // but it causes bugs when one append calls another (when dynamic dispatch set rawInputValue) 2279 // this._resetBeforeTailState(); 2280 } 2281 2282 if (this.eager && flags !== null && flags !== void 0 && flags.input && str) { 2283 details.aggregate(this._appendEager()); 2284 } 2285 2286 return details; 2287 } 2288 /** */ 2289 2290 }, { 2291 key: "remove", 2292 value: function remove() { 2293 var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; 2294 var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length; 2295 this._value = this.value.slice(0, fromPos) + this.value.slice(toPos); 2296 return new ChangeDetails(); 2297 } 2298 /** Calls function and reapplies current value */ 2299 2300 }, { 2301 key: "withValueRefresh", 2302 value: function withValueRefresh(fn) { 2303 if (this._refreshing || !this.isInitialized) return fn(); 2304 this._refreshing = true; 2305 var rawInput = this.rawInputValue; 2306 var value = this.value; 2307 var ret = fn(); 2308 this.rawInputValue = rawInput; // append lost trailing chars at end 2309 2310 if (this.value && this.value !== value && value.indexOf(this.value) === 0) { 2311 this.append(value.slice(this.value.length), {}, ''); 2312 } 2313 2314 delete this._refreshing; 2315 return ret; 2316 } 2317 /** */ 2318 2319 }, { 2320 key: "runIsolated", 2321 value: function runIsolated(fn) { 2322 if (this._isolated || !this.isInitialized) return fn(this); 2323 this._isolated = true; 2324 var state = this.state; 2325 var ret = fn(this); 2326 this.state = state; 2327 delete this._isolated; 2328 return ret; 2329 } 2330 /** 2331 Prepares string before mask processing 2332 @protected 2333 */ 2334 2335 }, { 2336 key: "doPrepare", 2337 value: function doPrepare(str) { 2338 var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 2339 return this.prepare ? this.prepare(str, this, flags) : str; 2340 } 2341 /** 2342 Validates if value is acceptable 2343 @protected 2344 */ 2345 2346 }, { 2347 key: "doValidate", 2348 value: function doValidate(flags) { 2349 return (!this.validate || this.validate(this.value, this, flags)) && (!this.parent || this.parent.doValidate(flags)); 2350 } 2351 /** 2352 Does additional processing in the end of editing 2353 @protected 2354 */ 2355 2356 }, { 2357 key: "doCommit", 2358 value: function doCommit() { 2359 if (this.commit) this.commit(this.value, this); 2360 } 2361 /** */ 2362 2363 }, { 2364 key: "doFormat", 2365 value: function doFormat(value) { 2366 return this.format ? this.format(value, this) : value; 2367 } 2368 /** */ 2369 2370 }, { 2371 key: "doParse", 2372 value: function doParse(str) { 2373 return this.parse ? this.parse(str, this) : str; 2374 } 2375 /** */ 2376 2377 }, { 2378 key: "splice", 2379 value: function splice(start, deleteCount, inserted, removeDirection) { 2380 var tailPos = start + deleteCount; 2381 var tail = this.extractTail(tailPos); 2382 var oldRawValue; 2383 2384 if (this.eager) { 2385 removeDirection = forceDirection(removeDirection); 2386 oldRawValue = this.extractInput(0, tailPos, { 2387 raw: true 2388 }); 2389 } 2390 2391 var startChangePos = this.nearestInputPos(start, deleteCount > 1 && start !== 0 && !this.eager ? DIRECTION.NONE : removeDirection); 2392 var details = new ChangeDetails({ 2393 tailShift: startChangePos - start // adjust tailShift if start was aligned 2394 2395 }).aggregate(this.remove(startChangePos)); 2396 2397 if (this.eager && removeDirection !== DIRECTION.NONE && oldRawValue === this.rawInputValue) { 2398 if (removeDirection === DIRECTION.FORCE_LEFT) { 2399 var valLength; 2400 2401 while (oldRawValue === this.rawInputValue && (valLength = this.value.length)) { 2402 details.aggregate(new ChangeDetails({ 2403 tailShift: -1 2404 })).aggregate(this.remove(valLength - 1)); 2405 } 2406 } else if (removeDirection === DIRECTION.FORCE_RIGHT) { 2407 tail.unshift(); 2408 } 2409 } 2410 2411 return details.aggregate(this.append(inserted, { 2412 input: true 2413 }, tail)); 2414 } 2415 }, { 2416 key: "maskEquals", 2417 value: function maskEquals(mask) { 2418 return this.mask === mask; 2419 } 2420 }]); 2421 2422 return Masked; 2423 }(); 2424 Masked.DEFAULTS = { 2425 format: function format(v) { 2426
2426return v; 2427 }, 2428 parse: function parse(v) { 2429 return v; 2430 } 2431 }; 2432 IMask.Masked = Masked; 2433 2434 /** Get Masked class by mask type */ 2435 2436 function maskedClass(mask) { 2437 if (mask == null) { 2438 throw new Error('mask property should be defined'); 2439 } // $FlowFixMe 2440 2441 2442 if (mask instanceof RegExp) return IMask.MaskedRegExp; // $FlowFixMe 2443 2444 if (isString(mask)) return IMask.MaskedPattern; // $FlowFixMe 2445 2446 if (mask instanceof Date || mask === Date) return IMask.MaskedDate; // $FlowFixMe 2447 2448 if (mask instanceof Number || typeof mask === 'number' || mask === Number) return IMask.MaskedNumber; // $FlowFixMe 2449 2450 if (Array.isArray(mask) || mask === Array) return IMask.MaskedDynamic; // $FlowFixMe 2451 2452 if (IMask.Masked && mask.prototype instanceof IMask.Masked) return mask; // $FlowFixMe 2453 2454 if (mask instanceof IMask.Masked) return mask.constructor; // $FlowFixMe 2455 2456 if (mask instanceof Function) return IMask.MaskedFunction; 2457 console.warn('Mask not found for mask', mask); // eslint-disable-line no-console 2458 // $FlowFixMe 2459 2460 return IMask.Masked; 2461 } 2462 /** Creates new {@link Masked} depending on mask type */ 2463 2464 function createMask(opts) { 2465 // $FlowFixMe 2466 if (IMask.Masked && opts instanceof IMask.Masked) return opts; 2467 opts = Object.assign({}, opts); 2468 var mask = opts.mask; // $FlowFixMe 2469 2470 if (IMask.Masked && mask instanceof IMask.Masked) return mask; 2471 var MaskedClass = maskedClass(mask); 2472 if (!MaskedClass) throw new Error('Masked class is not found for provided mask, appropriate module needs to be import manually before creating mask.'); 2473 return new MaskedClass(opts); 2474 } 2475 IMask.createMask = createMask; 2476 2477 var _excluded$4 = ["mask"]; 2478 var DEFAULT_INPUT_DEFINITIONS = { 2479 '0': /\d/, 2480 '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\uFB
2480D3-\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]/, 2481 // http://stackoverflow.com/a/22075070 2482 '*': /./ 2483 }; 2484 /** */ 2485 2486 var PatternInputDefinition = /*#__PURE__*/function () { 2487 /** */ 2488 2489 /** */ 2490 2491 /** */ 2492 2493 /** */ 2494 2495 /** */ 2496 2497 /** */ 2498 2499 /** */ 2500 function PatternInputDefinition(opts) { 2501 _classCallCheck(this, PatternInputDefinition); 2502 2503 var mask = opts.mask, 2504 blockOpts = _objectWithoutProperties(opts, _excluded$4); 2505 2506 this.masked = createMask({ 2507 mask: mask 2508 }); 2509 Object.assign(this, blockOpts); 2510 } 2511 2512 _createClass(PatternInputDefinition, [{ 2513 key: "reset", 2514 value: function reset() { 2515 this.isFilled = false; 2516 this.masked.reset(); 2517 } 2518 }, { 2519 key: "remove", 2520 value: function remove() { 2521 var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; 2522 var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length; 2523 2524 if (fromPos === 0 && toPos >= 1) { 2525 this.isFilled = false; 2526 return this.masked.remove(fromPos, toPos); 2527 } 2528 2529 return new ChangeDetails(); 2530 } 2531 }, { 2532 key: "value", 2533 get: function get() { 2534 return this.masked.value || (this.isFilled && !this.isOptional ? this.placeholderChar : ''); 2535 } 2536 }, { 2537 key: "unmaskedValue", 2538 get: function get() { 2539 return this.masked.unmaskedValue; 2540 } 2541 }, { 2542 key: "isComplete", 2543 get: function get() { 2544 return Boolean(this.masked.value) || this.isOptional; 2545 } 2546 }, { 2547 key: "_appendChar", 2548 value: function _appendChar(ch) { 2549 var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 2550 if (this.isFilled) return new ChangeDetails(); 2551 var state = this.masked.state; // simulate input 2552 2553 var details = this.masked._appendChar(ch, flags); 2554 2555 if (details.inserted && this.doValidate(flags) === false) { 2556 details.inserted = details.rawInserted = ''; 2557 this.masked.state = state; 2558 } 2559 2560 if (!details.inserted && !this.isOptional && !this.lazy && !flags.input) { 2561 details.inserted = this.placeholderChar; 2562 } 2563 2564 details.skip = !details.inserted && !this.isOptional; 2565 this.isFilled = Boolean(details.inserted); 2566 return details; 2567 } 2568 }, { 2569 key: "append", 2570 value: function append() { 2571 var _this$masked; 2572 2573 // TODO probably should be done via _appendChar 2574 return (_this$masked = this.masked).append.apply(_this$masked, arguments); 2575 } 2576 }, { 2577 key: "_appendPlaceholder", 2578 value: function _appendPlaceholder() { 2579 var details = new ChangeDetails(); 2580 if (this.isFilled || this.isOptional) return details; 2581 this.isFilled = true; 2582 details.inserted = this.placeholderChar; 2583 return details; 2584 } 2585 }, { 2586 key: "_appendEager", 2587 value: function _appendEager() { 2588 return new ChangeDetails(); 2589 } 2590 }, { 2591 key: "extractTail", 2592 value: function extractTail() { 2593 var _this$masked2; 2594 2595 return (_this$masked2 = this.masked).extractTail.apply(_this$masked2, arguments); 2596 } 2597 }, { 2598 key: "appendTail", 2599 value: function appendTail() { 2600 var _this$masked3; 2601 2602 return (_this$masked3 = this.masked).appendTail.apply(_this$masked3, arguments); 2603 } 2604 }, { 2605 key: "extractInput", 2606 value: function extractInput() { 2607 var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; 2608 var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length; 2609 var flags = arguments.length > 2 ? arguments[2] : undefined; 2610 return this.masked.extractInput(fromPos, toPos, flags); 2611 } 2612 }, { 2613 key: "nearestInputPos", 2614 value: function nearestInputPos(cursorPos) { 2615 var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DIRECTION.NONE; 2616 var minPos = 0; 2617 var maxPos = this.value.length; 2618 var boundPos = Math.min(Math.max(cursorPos, minPos), maxPos); 2619 2620 switch (direction) { 2621 case DIRECTION.LEFT: 2622 case DIRECTION.FORCE_LEFT: 2623 return this.isComplete ? boundPos : minPos; 2624 2625 case DIRECTION.RIGHT: 2626 case DIRECTION.FORCE_RIGHT: 2627 return this.isComplete ? boundPos : maxPos; 2628 2629 case DIRECTION.NONE: 2630 default: 2631 return boundPos; 2632 } 2633 } 2634 }, { 2635 key: "doValidate", 2636 value: function doValidate() { 2637 var _this$masked4, _this$parent; 2638 2639 return (_this$masked4 = this.masked).doValidate.apply(_this$masked4, arguments) && (!this.parent || (_this$parent = this.parent).doValidate.apply(_this$parent, arguments)); 2640 } 2641 }, { 2642 key: "doCommit", 2643 value: function doCommit() { 2644 this.masked.doCommit(); 2645 } 2646 }, { 2647 key: "state", 2648 get: function get() { 2649 return { 2650 masked: this.masked.state, 2651 isFilled: this.isFilled 2652 }; 2653 }, 2654 set: function set(state) { 2655 this.masked.state = state.masked; 2656 this.isFilled = state.isFilled; 2657 } 2658 }]); 2659 2660 return PatternInputDefinition; 2661 }(); 2662 2663 var PatternFixedDefinition = /*#__PURE__*/function () { 2664 /** */ 2665 2666 /** */ 2667 2668 /** */ 2669 2670 /** */ 2671 2672 /** */ 2673 2674 /** */ 2675 function PatternFixedDefinition(opts) { 2676 _classCallCheck(this, PatternFixedDefinition); 2677 2678 Object.assign(this, opts); 2679 this._value = ''; 2680 this.isFixed = true; 2681 } 2682 2683 _createClass(PatternFixedDefinition, [{ 2684 key: "value", 2685 get: function get() { 2686 return this._value; 2687 } 2688 }, { 2689 key: "unmaskedValue", 2690 get: function get() { 2691 return this.isUnmasking ? this.value : ''; 2692 } 2693 }, { 2694 key: "reset", 2695 value: function reset() { 2696 this._isRawInput = false;
2697 this._value = ''; 2698 } 2699 }, { 2700 key: "remove", 2701 value: function remove() { 2702 var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; 2703 var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._value.length; 2704 this._value = this._value.slice(0, fromPos) + this._value.slice(toPos); 2705 if (!this._value) this._isRawInput = false; 2706 return new ChangeDetails(); 2707 } 2708 }, { 2709 key: "nearestInputPos", 2710 value: function nearestInputPos(cursorPos) { 2711 var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DIRECTION.NONE; 2712 var minPos = 0; 2713 var maxPos = this._value.length; 2714 2715 switch (direction) { 2716 case DIRECTION.LEFT: 2717 case DIRECTION.FORCE_LEFT: 2718 return minPos; 2719 2720 case DIRECTION.NONE: 2721 case DIRECTION.RIGHT: 2722 case DIRECTION.FORCE_RIGHT: 2723 default: 2724 return maxPos; 2725 } 2726 } 2727 }, { 2728 key: "extractInput", 2729 value: function extractInput() { 2730 var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; 2731 var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._value.length; 2732 var flags = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; 2733 return flags.raw && this._isRawInput && this._value.slice(fromPos, toPos) || ''; 2734 } 2735 }, { 2736 key: "isComplete", 2737 get: function get() { 2738 return true; 2739 } 2740 }, { 2741 key: "isFilled", 2742 get: function get() { 2743 return Boolean(this._value); 2744 } 2745 }, { 2746 key: "_appendChar", 2747 value: function _appendChar(ch) { 2748 var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 2749 var details = new ChangeDetails(); 2750 if (this._value) return details; 2751 var appended = this.char === ch; 2752 var isResolved = appended && (this.isUnmasking || flags.input || flags.raw) && !this.eager && !flags.tail; 2753 if (isResolved) details.rawInserted = this.char; 2754 this._value = details.inserted = this.char; 2755 this._isRawInput = isResolved && (flags.raw || flags.input); 2756 return details; 2757 } 2758 }, { 2759 key: "_appendEager", 2760 value: function _appendEager() { 2761 return this._appendChar(this.char); 2762 } 2763 }, { 2764 key: "_appendPlaceholder", 2765 value: function _appendPlaceholder() { 2766 var details = new ChangeDetails(); 2767 if (this._value) return details; 2768 this._value = details.inserted = this.char; 2769 return details; 2770 } 2771 }, { 2772 key: "extractTail", 2773 value: function extractTail() { 2774 arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length; 2775 return new ContinuousTailDetails(''); 2776 } // $FlowFixMe no ideas 2777 2778 }, { 2779 key: "appendTail", 2780 value: function appendTail(tail) { 2781 if (isString(tail)) tail = new ContinuousTailDetails(String(tail)); 2782 return tail.appendTo(this); 2783 } 2784 }, { 2785 key: "append", 2786 value: function append(str, flags, tail) { 2787 var details = this._appendChar(str[0], flags); 2788 2789 if (tail != null) { 2790 details.tailShift += this.appendTail(tail).tailShift; 2791 } 2792 2793 return details; 2794 } 2795 }, { 2796 key: "doCommit", 2797 value: function doCommit() {} 2798 }, { 2799 key: "state", 2800 get: function get() { 2801 return { 2802 _value: this._value, 2803 _isRawInput: this._isRawInput 2804 }; 2805 }, 2806 set: function set(state) { 2807 Object.assign(this, state); 2808 } 2809 }]); 2810 2811 return PatternFixedDefinition; 2812 }(); 2813 2814 var _excluded$3 = ["chunks"]; 2815 2816 var ChunksTailDetails = /*#__PURE__*/function () { 2817 /** */ 2818 function ChunksTailDetails() { 2819 var chunks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; 2820 var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; 2821 2822 _classCallCheck(this, ChunksTailDetails); 2823 2824 this.chunks = chunks; 2825 this.from = from; 2826 } 2827 2828 _createClass(ChunksTailDetails, [{ 2829 key: "toString", 2830 value: function toString() { 2831 return this.chunks.map(String).join(''); 2832 } // $FlowFixMe no ideas 2833 2834 }, { 2835 key: "extend", 2836 value: function extend(tailChunk) { 2837 if (!String(tailChunk)) return; 2838 if (isString(tailChunk)) tailChunk = new ContinuousTailDetails(String(tailChunk)); 2839 var lastChunk = this.chunks[this.chunks.length - 1];
2840 var extendLast = lastChunk && ( // if stops are same or tail has no stop 2841 lastChunk.stop === tailChunk.stop || tailChunk.stop == null) && // if tail chunk goes just after last chunk 2842 tailChunk.from === lastChunk.from + lastChunk.toString().length; 2843 2844 if (tailChunk instanceof ContinuousTailDetails) { 2845 // check the ability to extend previous chunk 2846 if (extendLast) { 2847 // extend previous chunk 2848 lastChunk.extend(tailChunk.toString()); 2849 } else { 2850 // append new chunk 2851 this.chunks.push(tailChunk); 2852 } 2853 } else if (tailChunk instanceof ChunksTailDetails) { 2854 if (tailChunk.stop == null) { 2855 // unwrap floating chunks to parent, keeping `from` pos 2856 var firstTailChunk; 2857 2858 while (tailChunk.chunks.length && tailChunk.chunks[0].stop == null) { 2859 firstTailChunk = tailChunk.chunks.shift(); 2860 firstTailChunk.from += tailChunk.from; 2861 this.extend(firstTailChunk); 2862 } 2863 } // if tail chunk still has value 2864 2865 2866 if (tailChunk.toString()) { 2867 // if chunks contains stops, then popup stop to container 2868 tailChunk.stop = tailChunk.blockIndex; 2869 this.chunks.push(tailChunk); 2870 } 2871 } 2872 } 2873 }, { 2874 key: "appendTo", 2875 value: function appendTo(masked) { 2876 // $FlowFixMe 2877 if (!(masked instanceof IMask.MaskedPattern)) { 2878 var tail = new ContinuousTailDetails(this.toString()); 2879 return tail.appendTo(masked); 2880 } 2881 2882 var details = new ChangeDetails(); 2883 2884 for (var ci = 0; ci < this.chunks.length && !details.skip; ++ci) { 2885 var chunk = this.chunks[ci]; 2886 2887 var lastBlockIter = masked._mapPosToBlock(masked.value.length); 2888 2889 var stop = chunk.stop; 2890 var chunkBlock = void 0; 2891 2892 if (stop != null && ( // if block not found or stop is behind lastBlock 2893 !lastBlockIter || lastBlockIter.index <= stop)) { 2894 if (chunk instanceof ChunksTailDetails || // for continuous block also check if stop is exist 2895 masked._stops.indexOf(stop) >= 0) { 2896 details.aggregate(masked._appendPlaceholder(stop)); 2897 } 2898 2899 chunkBlock = chunk instanceof ChunksTailDetails && masked._blocks[stop]; 2900 } 2901 2902 if (chunkBlock) { 2903 var tailDetails = chunkBlock.appendTail(chunk); 2904 tailDetails.skip = false; // always ignore skip, it will be set on last 2905 2906 details.aggregate(tailDetails); 2907 masked._value += tailDetails.inserted; // get not inserted chars 2908 2909 var remainChars = chunk.toString().slice(tailDetails.rawInserted.length); 2910 if (remainChars) details.aggregate(masked.append(remainChars, { 2911 tail: true 2912 })); 2913 } else { 2914 details.aggregate(masked.append(chunk.toString(), { 2915 tail: true 2916 })); 2917 } 2918 } 2919 return details; 2920 } 2921 }, { 2922 key: "state", 2923 get: function get() { 2924 return { 2925 chunks: this.chunks.map(function (c) { 2926 return c.state; 2927 }), 2928 from: this.from, 2929 stop: this.stop, 2930 blockIndex: this.blockIndex 2931 }; 2932 }, 2933 set: function set(state) { 2934 var chunks = state.chunks, 2935 props = _objectWithoutProperties(state, _excluded$3); 2936 2937 Object.assign(this, props); 2938 this.chunks = chunks.map(function (cstate) { 2939 var chunk = "chunks" in cstate ? new ChunksTailDetails() : new ContinuousTailDetails(); // $FlowFixMe already checked above 2940 2941 chunk.state = cstate; 2942 return chunk; 2943 }); 2944 } 2945 }, { 2946 key: "unshift", 2947 value: function unshift(beforePos) { 2948 if (!this.chunks.length || beforePos != null && this.from >= beforePos) return ''; 2949 var chunkShiftPos = beforePos != null ? beforePos - this.from : beforePos; 2950 var ci = 0; 2951 2952 while (ci < this.chunks.length) { 2953 var chunk = this.chunks[ci]; 2954 var shiftChar = chunk.unshift(chunkShiftPos); 2955 2956 if (chunk.toString()) { 2957 // chunk still contains value 2958 // but not shifted - means no more available chars to shift 2959 if (!shiftChar) break; 2960 ++ci; 2961 } else { 2962 // clean if chunk has no value 2963 this.chunks.splice(ci, 1); 2964 } 2965 2966 if (shiftChar) return shiftChar; 2967 } 2968 2969 return ''; 2970 } 2971 }, { 2972 key: "shift", 2973 value: function shift() { 2974 if (!this.chunks.length) return ''; 2975 var ci = this.chunks.length - 1; 2976 2977 while (0 <= ci) { 2978 var chunk = this.chunks[ci]; 2979 var shiftChar = chunk.shift(); 2980 2981 if (chunk.toString()) { 2982 // chunk still contains value 2983 // but not shifted - means no more available chars to shift 2984 if (!shiftChar) break; 2985 --ci; 2986 } else { 2987 // clean if chunk has no value 2988 this.chunks.splice(ci, 1); 2989 } 2990 2991 if (shiftChar) return shiftChar; 2992 } 2993 2994 return ''; 2995 } 2996 }]); 2997 2998 return ChunksTailDetails; 2999 }(); 3000 3001 var PatternCursor = /*#__PURE__*/function () { 3002 function PatternCursor(masked, pos) { 3003 _classCallCheck(this, PatternCursor); 3004 3005 this.masked = masked; 3006 this._log = []; 3007 3008 var _ref = masked._mapPosToBlock(pos) || (pos < 0 ? // first 3009 { 3010 index: 0, 3011 offset: 0 3012 } : // last 3013 { 3014 index: this.masked._blocks.length, 3015 offset: 0 3016 }), 3017 offset = _ref.offset, 3018 index = _ref.index; 3019 3020 this.offset = offset; 3021 this.index = index; 3022 this.ok = false;
3023 } 3024 3025 _createClass(PatternCursor, [{ 3026 key: "block", 3027 get: function get() { 3028 return this.masked._blocks[this.index]; 3029 } 3030 }, { 3031 key: "pos", 3032 get: function get() { 3033 return this.masked._blockStartPos(this.index) + this.offset; 3034 } 3035 }, { 3036 key: "state", 3037 get: function get() { 3038 return { 3039 index: this.index, 3040 offset: this.offset, 3041 ok: this.ok 3042 }; 3043 }, 3044 set: function set(s) { 3045 Object.assign(this, s); 3046 } 3047 }, { 3048 key: "pushState", 3049 value: function pushState() { 3050 this._log.push(this.state); 3051 } 3052 }, { 3053 key: "popState", 3054 value: function popState() { 3055 var s = this._log.pop(); 3056 3057 this.state = s; 3058 return s; 3059 } 3060 }, { 3061 key: "bindBlock", 3062 value: function bindBlock() { 3063 if (this.block) return; 3064 3065 if (this.index < 0) { 3066 this.index = 0; 3067 this.offset = 0; 3068 } 3069 3070 if (this.index >= this.masked._blocks.length) { 3071 this.index = this.masked._blocks.length - 1; 3072 this.offset = this.block.value.length; 3073 } 3074 } 3075 }, { 3076 key: "_pushLeft", 3077 value: function _pushLeft(fn) { 3078 this.pushState(); 3079 3080 for (this.bindBlock(); 0 <= this.index; --this.index, this.offset = ((_this$block = this.block) === null || _this$block === void 0 ? void 0 : _this$block.value.length) || 0) { 3081 var _this$block; 3082 3083 if (fn()) return this.ok = true; 3084 } 3085 3086 return this.ok = false; 3087 } 3088 }, { 3089 key: "_pushRight", 3090 value: function _pushRight(fn) { 3091 this.pushState(); 3092 3093 for (this.bindBlock(); this.index < this.masked._blocks.length; ++this.index, this.offset = 0) { 3094 if (fn()) return this.ok = true; 3095 } 3096 3097 return this.ok = false; 3098 } 3099 }, { 3100 key: "pushLeftBeforeFilled", 3101 value: function pushLeftBeforeFilled() { 3102 var _this = this; 3103 3104 return this._pushLeft(function () { 3105 if (_this.block.isFixed || !_this.block.value) return; 3106 _this.offset = _this.block.nearestInputPos(_this.offset, DIRECTION.FORCE_LEFT); 3107 if (_this.offset !== 0) return true; 3108 }); 3109 } 3110 }, { 3111 key: "pushLeftBeforeInput", 3112 value: function pushLeftBeforeInput() { 3113 var _this2 = this; 3114 3115 // cases: 3116 // filled input: 00| 3117 // optional empty input: 00[]| 3118 // nested block: XX<[]>| 3119 return this._pushLeft(function () { 3120 if (_this2.block.isFixed) return; 3121 _this2.offset = _this2.block.nearestInputPos(_this2.offset, DIRECTION.LEFT); 3122 return true; 3123 }); 3124 } 3125 }, { 3126 key: "pushLeftBeforeRequired", 3127 value: function pushLeftBeforeRequired() { 3128 var _this3 = this; 3129 3130 return this._pushLeft(function () { 3131 if (_this3.block.isFixed || _this3.block.isOptional && !_this3.block.value) return; 3132 _this3.offset = _this3.block.nearestInputPos(_this3.offset, DIRECTION.LEFT); 3133 return true; 3134 }); 3135 } 3136 }, { 3137 key: "pushRightBeforeFilled", 3138 value: function pushRightBeforeFilled() { 3139 var _this4 = this; 3140 3141 return this._pushRight(function () { 3142 if (_this4.block.isFixed || !_this4.block.value) return; 3143 _this4.offset = _this4.block.nearestInputPos(_this4.offset, DIRECTION.FORCE_RIGHT); 3144 if (_this4.offset !== _this4.block.value.length) return true; 3145 }); 3146 } 3147 }, { 3148 key: "pushRightBeforeInput", 3149 value: function pushRightBeforeInput() { 3150 var _this5 = this; 3151 3152 return this._pushRight(function () { 3153 if (_this5.block.isFixed) return; // const o = this.offset; 3154 3155 _this5.offset = _this5.block.nearestInputPos(_this5.offset, DIRECTION.NONE); // HACK cases like (STILL DOES NOT WORK FOR NESTED) 3156 // aa|X 3157 // aa<X|[]>X_ - this will not work 3158 // if (o && o === this.offset && this.block instanceof PatternInputDefinition) continue; 3159 3160 return true; 3161 }); 3162 } 3163 }, { 3164 key: "pushRightBeforeRequired", 3165 value: function pushRightBeforeRequired() { 3166 var _this6 = this; 3167 3168 return this._pushRight(function () { 3169 if (_this6.block.isFixed || _this6.block.isOptional && !_this6.block.value) return; // TODO check |[*]XX_ 3170 3171 _this6.offset = _this6.block.nearestInputPos(_this6.offset, DIRECTION.NONE); 3172 return true; 3173 }); 3174 } 3175 }]); 3176 3177 return PatternCursor; 3178 }(); 3179 3180 /** Masking by RegExp */ 3181 3182 var MaskedRegExp = /*#__PURE__*/function (_Masked) { 3183 _inherits(MaskedRegExp, _Masked); 3184 3185 var _super = _createSuper(MaskedRegExp); 3186 3187 function MaskedRegExp() { 3188 _classCallCheck(this, MaskedRegExp); 3189 3190 return _super.apply(this, arguments); 3191 } 3192 3193 _createClass(MaskedRegExp, [{ 3194 key: "_update", 3195 value: 3196 /** 3197 @override 3198 @param {Object} opts 3199 */ 3200 function _update(opts) { 3201 if (opts.mask) opts.validate = function (value) { 3202 return value.search(opts.mask) >= 0; 3203 }; 3204 3205 _get(_getPrototypeOf(MaskedRegExp.prototype), "_update", this).call(this, opts); 3206 } 3207 }]); 3208 3209 return MaskedRegExp; 3210 }(Masked); 3211 IMask.MaskedRegExp = MaskedRegExp; 3212 3213 var _excluded$2 = ["_blocks"]; 3214 3215 /** 3216 Pattern mask 3217 @param {Object} opts 3218 @param {Object} opts.blocks 3219 @param {Object} opts.definitions 3220 @param {string} opts.placeholderChar 3221 @param {boolean} opts.lazy 3222 */ 3223 var MaskedPattern = /*#__PURE__*/function (_Masked) { 3224 _inherits(MaskedPattern, _Masked); 3225 3226 var _super = _createSuper(MaskedPattern); 3227 3228 /** */ 3229 3230 /** */ 3231 3232 /** Single char for empty input */ 3233 3234 /** Show placeholder only when needed */ 3235 function MaskedPattern() { 3236 var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 3237 3238 _classCallCheck(this, MaskedPattern); 3239 3240 // TODO type $Shape<MaskedPatternOptions>={} does not work 3241 opts.definitions = Object.assign({}, DEFAULT_INPUT_DEFINITIONS, opts.definitions); 3242 return _super.call(this, Object.assign({}, MaskedPattern.DEFAULTS, opts)); 3243 } 3244 /** 3245 @override 3246 @param {Object} opts 3247 */ 3248 3249 3250 _createClass(MaskedPattern, [{ 3251 key: "_update", 3252 value: function _update() { 3253 var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 3254 opts.definitions = Object.assign({}, this.definitions, opts.definitions); 3255 3256 _get(_getPrototypeOf(MaskedPattern.prototype), "_update", this).call(this, opts); 3257 3258 this._rebuildMask(); 3259 } 3260 /** */ 3261 3262 }, { 3263 key: "_rebuildMask", 3264 value: function _rebuildMask() { 3265 var _this = this; 3266 3267 var defs = this.definitions; 3268 this._blocks = []; 3269 this._stops = []; 3270 this._maskedBlocks = {}; 3271 var pattern = this.mask; 3272 if (!pattern || !defs) return; 3273 var unmaskingBlock = false;
3274 var optionalBlock = false; 3275 3276 for (var i = 0; i < pattern.length; ++i) { 3277 if (this.blocks) { 3278 var _ret = function () { 3279 var p = pattern.slice(i); 3280 var bNames = Object.keys(_this.blocks).filter(function (bName) { 3281 return p.indexOf(bName) === 0; 3282 }); // order by key length 3283 3284 bNames.sort(function (a, b) { 3285 return b.length - a.length; 3286 }); // use block name with max length 3287 3288 var bName = bNames[0]; 3289 3290 if (bName) { 3291 // $FlowFixMe no ideas 3292 var maskedBlock = createMask(Object.assign({ 3293 parent: _this, 3294 lazy: _this.lazy, 3295 eager: _this.eager, 3296 placeholderChar: _this.placeholderChar, 3297 overwrite: _this.overwrite 3298 }, _this.blocks[bName])); 3299 3300 if (maskedBlock) { 3301 _this._blocks.push(maskedBlock); // store block index 3302 3303 3304 if (!_this._maskedBlocks[bName]) _this._maskedBlocks[bName] = []; 3305 3306 _this._maskedBlocks[bName].push(_this._blocks.length - 1); 3307 } 3308 3309 i += bName.length - 1; 3310 return "continue"; 3311 } 3312 }(); 3313 3314 if (_ret === "continue") continue; 3315 } 3316 3317 var char = pattern[i]; 3318 var isInput = (char in defs); 3319 3320 if (char === MaskedPattern.STOP_CHAR) { 3321 this._stops.push(this._blocks.length); 3322 3323 continue; 3324 } 3325 3326 if (char === '{' || char === '}') { 3327 unmaskingBlock = !unmaskingBlock; 3328 continue; 3329 } 3330 3331 if (char === '[' || char === ']') { 3332 optionalBlock = !optionalBlock; 3333 continue; 3334 } 3335 3336 if (char === MaskedPattern.ESCAPE_CHAR) { 3337 ++i; 3338 char = pattern[i]; 3339 if (!char) break; 3340 isInput = false; 3341 } 3342 3343 var def = isInput ? new PatternInputDefinition({ 3344 parent: this, 3345 lazy: this.lazy, 3346 eager: this.eager, 3347 placeholderChar: this.placeholderChar, 3348 mask: defs[char], 3349 isOptional: optionalBlock 3350 }) : new PatternFixedDefinition({ 3351 char: char, 3352 eager: this.eager, 3353 isUnmasking: unmaskingBlock 3354 }); 3355 3356 this._blocks.push(def); 3357 } 3358 } 3359 /** 3360 @override 3361 */ 3362 3363 }, { 3364 key: "state", 3365 get: function get() { 3366 return Object.assign({}, _get(_getPrototypeOf(MaskedPattern.prototype), "state", this), { 3367 _blocks: this._blocks.map(function (b) { 3368 return b.state; 3369 }) 3370 }); 3371 }, 3372 set: function set(state) { 3373 var _blocks = state._blocks, 3374 maskedState = _objectWithoutProperties(state, _excluded$2); 3375 3376 this._blocks.forEach(function (b, bi) { 3377 return b.state = _blocks[bi]; 3378 }); 3379 3380 _set(_getPrototypeOf(MaskedPattern.prototype), "state", maskedState, this, true); 3381 } 3382 /** 3383 @override 3384 */ 3385 3386 }, { 3387 key: "reset", 3388 value: function reset() { 3389 _get(_getPrototypeOf(MaskedPattern.prototype), "reset", this).call(this); 3390 3391 this._blocks.forEach(function (b) { 3392 return b.reset(); 3393 }); 3394 } 3395 /** 3396 @override 3397 */ 3398 3399 }, { 3400 key: "isComplete", 3401 get: function get() { 3402 return this._blocks.every(function (b) { 3403 return b.isComplete; 3404 }); 3405 } 3406 /** 3407 @override 3408 */ 3409 3410 }, { 3411 key: "isFilled", 3412 get: function get() { 3413 return this._blocks.every(function (b) { 3414 return b.isFilled; 3415 }); 3416 } 3417 }, { 3418 key: "isFixed", 3419 get: function get() { 3420 return this._blocks.every(function (b) { 3421 return b.isFixed; 3422 }); 3423 } 3424 }, { 3425 key: "isOptional", 3426 get: function get() { 3427 return this._blocks.every(function (b) { 3428 return b.isOptional; 3429 }); 3430 } 3431 /** 3432 @override 3433 */ 3434 3435 }, { 3436 key: "doCommit", 3437 value: function doCommit() { 3438 this._blocks.forEach(function (b) { 3439 return b.doCommit(); 3440 }); 3441 3442 _get(_getPrototypeOf(MaskedPattern.prototype), "doCommit", this).call(this); 3443 } 3444 /** 3445 @override 3446 */ 3447 3448 }, { 3449 key: "unmaskedValue", 3450 get: function get() { 3451 return this._blocks.reduce(function (str, b) { 3452 return str += b.unmaskedValue; 3453 }, ''); 3454 }, 3455 set: function set(unmaskedValue) { 3456 _set(_getPrototypeOf(MaskedPattern.prototype), "unmaskedValue", unmaskedValue, this, true); 3457 } 3458 /** 3459 @override 3460 */ 3461 3462 }, { 3463 key: "value", 3464 get: function get() { 3465 // TODO return _value when not in change? 3466 return this._blocks.reduce(function (str, b) { 3467 return str += b.value; 3468 }, ''); 3469 }, 3470 set: function set(value) { 3471 _set(_getPrototypeOf(MaskedPattern.prototype), "value", value, this, true); 3472 } 3473 /** 3474 @override 3475 */ 3476 3477 }, { 3478 key: "appendTail", 3479 value: function appendTail(tail) { 3480 return _get(_getPrototypeOf(MaskedPattern.prototype), "appendTail", this).call(this, tail).aggregate(this._appendPlaceholder()); 3481 } 3482 /** 3483 @override 3484 */ 3485 3486 }, { 3487 key: "_appendEager", 3488 value: function _appendEager() { 3489 var _this$_mapPosToBlock; 3490 3491 var details = new ChangeDetails(); 3492 var startBlockIndex = (_this$_mapPosToBlock = this._mapPosToBlock(this.value.length)) === null || _this$_mapPosToBlock === void 0 ? void 0 : _this$_mapPosToBlock.index; 3493 if (startBlockIndex == null) return details; // TODO test if it works for nested pattern masks 3494 3495 if (this._blocks[startBlockIndex].isFilled) ++startBlockIndex; 3496 3497 for (var bi = startBlockIndex; bi < this._blocks.length; ++bi) { 3498 var d = this._blocks[bi]._appendEager(); 3499 3500 if (!d.inserted) break; 3501 details.aggregate(d); 3502 } 3503 3504 return details; 3505 } 3506 /** 3507 @override 3508 */ 3509 3510 }, { 3511 key: "_appendCharRaw", 3512 value: function _appendCharRaw(ch) { 3513 var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 3514 3515 var blockIter = this._mapPosToBlock(this.value.length); 3516 3517 var details = new ChangeDetails(); 3518 if (!blockIter) return details; 3519 3520 for (var bi = blockIter.index;; ++bi) { 3521 var _flags$_beforeTailSta; 3522 3523 var _block = this._blocks[bi]; 3524 if (!_block) break; 3525
3526 var blockDetails = _block._appendChar(ch, Object.assign({}, flags, { 3527 _beforeTailState: (_flags$_beforeTailSta = flags._beforeTailState) === null || _flags$_beforeTailSta === void 0 ? void 0 : _flags$_beforeTailSta._blocks[bi] 3528 })); 3529 3530 var skip = blockDetails.skip; 3531 details.aggregate(blockDetails); 3532 if (skip || blockDetails.rawInserted) break; // go next char 3533 } 3534 3535 return details; 3536 } 3537 /** 3538 @override 3539 */ 3540 3541 }, { 3542 key: "extractTail", 3543 value: function extractTail() { 3544 var _this2 = this; 3545 3546 var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; 3547 var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length; 3548 var chunkTail = new ChunksTailDetails(); 3549 if (fromPos === toPos) return chunkTail; 3550 3551 this._forEachBlocksInRange(fromPos, toPos, function (b, bi, bFromPos, bToPos) { 3552 var blockChunk = b.extractTail(bFromPos, bToPos); 3553 blockChunk.stop = _this2._findStopBefore(bi); 3554 blockChunk.from = _this2._blockStartPos(bi); 3555 if (blockChunk instanceof ChunksTailDetails) blockChunk.blockIndex = bi; 3556 chunkTail.extend(blockChunk); 3557 }); 3558 3559 return chunkTail; 3560 } 3561 /** 3562 @override 3563 */ 3564 3565 }, { 3566 key: "extractInput", 3567 value: function extractInput() { 3568 var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; 3569 var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length; 3570 var flags = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; 3571 if (fromPos === toPos) return ''; 3572 var input = ''; 3573 3574 this._forEachBlocksInRange(fromPos, toPos, function (b, _, fromPos, toPos) { 3575 input += b.extractInput(fromPos, toPos, flags); 3576 }); 3577 3578 return input; 3579 } 3580 }, { 3581 key: "_findStopBefore", 3582 value: function _findStopBefore(blockIndex) { 3583 var stopBefore; 3584 3585 for (var si = 0; si < this._stops.length; ++si) { 3586 var stop = this._stops[si]; 3587 if (stop <= blockIndex) stopBefore = stop;else break; 3588 } 3589 3590 return stopBefore; 3591 } 3592 /** Appends placeholder depending on laziness */ 3593 3594 }, { 3595 key: "_appendPlaceholder", 3596 value: function _appendPlaceholder(toBlockIndex) { 3597 var _this3 = this; 3598 3599 var details = new ChangeDetails(); 3600 if (this.lazy && toBlockIndex == null) return details; 3601 3602 var startBlockIter = this._mapPosToBlock(this.value.length); 3603 3604 if (!startBlockIter) return details; 3605 var startBlockIndex = startBlockIter.index; 3606 var endBlockIndex = toBlockIndex != null ? toBlockIndex : this._blocks.length; 3607 3608 this._blocks.slice(startBlockIndex, endBlockIndex).forEach(function (b) { 3609 if (!b.lazy || toBlockIndex != null) { 3610 // $FlowFixMe `_blocks` may not be present 3611 var args = b._blocks != null ? [b._blocks.length] : []; 3612 3613 var bDetails = b._appendPlaceholder.apply(b, args); 3614 3615 _this3._value += bDetails.inserted; 3616 details.aggregate(bDetails); 3617 } 3618 }); 3619 3620 return details; 3621 } 3622 /** Finds block in pos */ 3623 3624 }, { 3625 key: "_mapPosToBlock", 3626 value: function _mapPosToBlock(pos) { 3627 var accVal = ''; 3628 3629 for (var bi = 0; bi < this._blocks.length; ++bi) { 3630 var _block2 = this._blocks[bi]; 3631 var blockStartPos = accVal.length; 3632 accVal += _block2.value; 3633 3634 if (pos <= accVal.length) { 3635 return { 3636 index: bi, 3637 offset: pos - blockStartPos 3638 }; 3639 } 3640 } 3641 } 3642 /** */ 3643 3644 }, { 3645 key: "_blockStartPos", 3646 value: function _blockStartPos(blockIndex) { 3647 return this._blocks.slice(0, blockIndex).reduce(function (pos, b) { 3648 return pos += b.value.length; 3649 }, 0); 3650 } 3651 /** */ 3652 3653 }, { 3654 key: "_forEachBlocksInRange", 3655 value: function _forEachBlocksInRange(fromPos) { 3656 var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length; 3657 var fn = arguments.length > 2 ? arguments[2] : undefined; 3658 3659 var fromBlockIter = this._mapPosToBlock(fromPos); 3660 3661 if (fromBlockIter) { 3662 var toBlockIter = this._mapPosToBlock(toPos); // process first block 3663 3664 3665 var isSameBlock = toBlockIter && fromBlockIter.index === toBlockIter.index; 3666 var fromBlockStartPos = fromBlockIter.offset; 3667 var fromBlockEndPos = toBlockIter && isSameBlock ? toBlockIter.offset : this._blocks[fromBlockIter.index].value.length; 3668 fn(this._blocks[fromBlockIter.index], fromBlockIter.index, fromBlockStartPos, fromBlockEndPos); 3669 3670 if (toBlockIter && !isSameBlock) { 3671 // process intermediate blocks 3672 for (var bi = fromBlockIter.index + 1; bi < toBlockIter.index; ++bi) { 3673 fn(this._blocks[bi], bi, 0, this._blocks[bi].value.length); 3674 } // process last block 3675 3676 3677 fn(this._blocks[toBlockIter.index], toBlockIter.index, 0, toBlockIter.offset); 3678 } 3679 } 3680 } 3681 /** 3682 @override 3683 */ 3684 3685 }, { 3686 key: "remove", 3687 value: function remove() { 3688 var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; 3689 var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length; 3690 3691 var removeDetails = _get(_getPrototypeOf(MaskedPattern.prototype), "remove", this).call(this, fromPos, toPos); 3692
3693 this._forEachBlocksInRange(fromPos, toPos, function (b, _, bFromPos, bToPos) { 3694 removeDetails.aggregate(b.remove(bFromPos, bToPos)); 3695 }); 3696 3697 return removeDetails; 3698 } 3699 /** 3700 @override 3701 */ 3702 3703 }, { 3704 key: "nearestInputPos", 3705 value: function nearestInputPos(cursorPos) { 3706 var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DIRECTION.NONE; 3707 if (!this._blocks.length) return 0; 3708 var cursor = new PatternCursor(this, cursorPos); 3709 3710 if (direction === DIRECTION.NONE) { 3711 // ------------------------------------------------- 3712 // NONE should only go out from fixed to the right! 3713 // ------------------------------------------------- 3714 if (cursor.pushRightBeforeInput()) return cursor.pos; 3715 cursor.popState(); 3716 if (cursor.pushLeftBeforeInput()) return cursor.pos; 3717 return this.value.length; 3718 } // FORCE is only about a|* otherwise is 0 3719 3720 3721 if (direction === DIRECTION.LEFT || direction === DIRECTION.FORCE_LEFT) { 3722 // try to break fast when *|a 3723 if (direction === DIRECTION.LEFT) { 3724 cursor.pushRightBeforeFilled(); 3725 if (cursor.ok && cursor.pos === cursorPos) return cursorPos; 3726 cursor.popState(); 3727 } // forward flow 3728 3729 3730 cursor.pushLeftBeforeInput(); 3731 cursor.pushLeftBeforeRequired(); 3732 cursor.pushLeftBeforeFilled(); // backward flow 3733 3734 if (direction === DIRECTION.LEFT) { 3735 cursor.pushRightBeforeInput(); 3736 cursor.pushRightBeforeRequired(); 3737 if (cursor.ok && cursor.pos <= cursorPos) return cursor.pos; 3738 cursor.popState(); 3739 if (cursor.ok && cursor.pos <= cursorPos) return cursor.pos; 3740 cursor.popState(); 3741 } 3742 3743 if (cursor.ok) return cursor.pos; 3744 if (direction === DIRECTION.FORCE_LEFT) return 0; 3745 cursor.popState(); 3746 if (cursor.ok) return cursor.pos; 3747 cursor.popState(); 3748 if (cursor.ok) return cursor.pos; // cursor.popState(); 3749 // if ( 3750 // cursor.pushRightBeforeInput() && 3751 // // TODO HACK for lazy if has aligned left inside fixed and has came to the start - use start position 3752 // (!this.lazy || this.extractInput()) 3753 // ) return cursor.pos; 3754 3755 return 0; 3756 } 3757 3758 if (direction === DIRECTION.RIGHT || direction === DIRECTION.FORCE_RIGHT) { 3759 // forward flow 3760 cursor.pushRightBeforeInput(); 3761 cursor.pushRightBeforeRequired(); 3762 if (cursor.pushRightBeforeFilled()) return cursor.pos; 3763 if (direction === DIRECTION.FORCE_RIGHT) return this.value.length; // backward flow 3764 3765 cursor.popState(); 3766 if (cursor.ok) return cursor.pos; 3767 cursor.popState(); 3768 if (cursor.ok) return cursor.pos; 3769 return this.nearestInputPos(cursorPos, DIRECTION.LEFT); 3770 } 3771 3772 return cursorPos; 3773 } 3774 /** Get block by name */ 3775 3776 }, { 3777 key: "maskedBlock", 3778 value: function maskedBlock(name) { 3779 return this.maskedBlocks(name)[0]; 3780 } 3781 /** Get all blocks by name */ 3782 3783 }, { 3784 key: "maskedBlocks", 3785 value: function maskedBlocks(name) { 3786 var _this4 = this; 3787 3788 var indices = this._maskedBlocks[name]; 3789 if (!indices) return []; 3790 return indices.map(function (gi) { 3791 return _this4._blocks[gi]; 3792 }); 3793 } 3794 }]); 3795 3796 return MaskedPattern; 3797 }(Masked); 3798 MaskedPattern.DEFAULTS = { 3799 lazy: true, 3800 placeholderChar: '_' 3801 }; 3802 MaskedPattern.STOP_CHAR = '`'; 3803 MaskedPattern.ESCAPE_CHAR = '\\'; 3804 MaskedPattern.InputDefinition = PatternInputDefinition; 3805 MaskedPattern.FixedDefinition = PatternFixedDefinition; 3806 IMask.MaskedPattern = MaskedPattern; 3807 3808 /** Pattern which accepts ranges */ 3809 3810 var MaskedRange = /*#__PURE__*/function (_MaskedPattern) { 3811 _inherits(MaskedRange, _MaskedPattern); 3812 3813 var _super = _createSuper(MaskedRange); 3814 3815 function MaskedRange() { 3816 _classCallCheck(this, MaskedRange); 3817 3818 return _super.apply(this, arguments); 3819 } 3820 3821 _createClass(MaskedRange, [{ 3822 key: "_matchFrom", 3823 get: 3824 /** 3825 Optionally sets max length of pattern. 3826 Used when pattern length is longer then `to` param length. Pads zeros at start in this case. 3827 */ 3828 3829 /** Min bound */ 3830 3831 /** Max bound */ 3832 3833 /** */ 3834 function get() { 3835 return this.maxLength - String(this.from).length; 3836 } 3837 /** 3838 @override 3839 */ 3840 3841 }, { 3842 key: "_update", 3843 value: function _update(opts) { 3844 // TODO type 3845 opts = Object.assign({ 3846 to: this.to || 0, 3847 from: this.from || 0, 3848 maxLength: this.maxLength || 0 3849 }, opts); 3850 var maxLength = String(opts.to).length; 3851 if (opts.maxLength != null) maxLength = Math.max(maxLength, opts.maxLength); 3852 opts.maxLength = maxLength; 3853 var fromStr = String(opts.from).padStart(maxLength, '0'); 3854 var toStr = String(opts.to).padStart(maxLength, '0'); 3855 var sameCharsCount = 0; 3856 3857 while (sameCharsCount < toStr.length && toStr[sameCharsCount] === fromStr[sameCharsCount]) { 3858 ++sameCharsCount; 3859 } 3860 3861 opts.mask = toStr.slice(0, sameCharsCount).replace(/0/g, '\\0') + '0'.repeat(maxLength - sameCharsCount); 3862 3863 _get(_getPrototypeOf(MaskedRange.prototype), "_update", this).call(this, opts); 3864 } 3865 /** 3866 @override 3867 */ 3868 3869 }, { 3870 key: "isComplete", 3871 get: function get() { 3872 return _get(_getPrototypeOf(MaskedRange.prototype), "isComplete", this) && Boolean(this.value); 3873 } 3874 }, {
3875 key: "boundaries", 3876 value: function boundaries(str) { 3877 var minstr = ''; 3878 var maxstr = ''; 3879 3880 var _ref = str.match(/^(\D*)(\d*)(\D*)/) || [], 3881 _ref2 = _slicedToArray(_ref, 3), 3882 placeholder = _ref2[1], 3883 num = _ref2[2]; 3884 3885 if (num) { 3886 minstr = '0'.repeat(placeholder.length) + num; 3887 maxstr = '9'.repeat(placeholder.length) + num; 3888 } 3889 3890 minstr = minstr.padEnd(this.maxLength, '0'); 3891 maxstr = maxstr.padEnd(this.maxLength, '9'); 3892 return [minstr, maxstr]; 3893 } // TODO str is a single char everytime 3894 3895 /** 3896 @override 3897 */ 3898 3899 }, { 3900 key: "doPrepare", 3901 value: function doPrepare(ch) { 3902 var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 3903 var details; 3904 3905 var _normalizePrepare = normalizePrepare(_get(_getPrototypeOf(MaskedRange.prototype), "doPrepare", this).call(this, ch.replace(/\D/g, ''), flags)); 3906 3907 var _normalizePrepare2 = _slicedToArray(_normalizePrepare, 2); 3908 3909 ch = _normalizePrepare2[0]; 3910 details = _normalizePrepare2[1]; 3911 if (!this.autofix || !ch) return ch; 3912 var fromStr = String(this.from).padStart(this.maxLength, '0'); 3913 var toStr = String(this.to).padStart(this.maxLength, '0'); 3914 var nextVal = this.value + ch;
3915 if (nextVal.length > this.maxLength) return ''; 3916 3917 var _this$boundaries = this.boundaries(nextVal), 3918 _this$boundaries2 = _slicedToArray(_this$boundaries, 2), 3919 minstr = _this$boundaries2[0], 3920 maxstr = _this$boundaries2[1]; 3921 3922 if (Number(maxstr) < this.from) return fromStr[nextVal.length - 1]; 3923 3924 if (Number(minstr) > this.to) { 3925 if (this.autofix === 'pad' && nextVal.length < this.maxLength) { 3926 return ['', details.aggregate(this.append(fromStr[nextVal.length - 1] + ch, flags))]; 3927 } 3928 3929 return toStr[nextVal.length - 1]; 3930 } 3931 3932 return ch; 3933 } 3934 /** 3935 @override 3936 */ 3937 3938 }, { 3939 key: "doValidate", 3940 value: function doValidate() { 3941 var _get2; 3942 3943 var str = this.value; 3944 var firstNonZero = str.search(/[^0]/); 3945 if (firstNonZero === -1 && str.length <= this._matchFrom) return true; 3946 3947 var _this$boundaries3 = this.boundaries(str), 3948 _this$boundaries4 = _slicedToArray(_this$boundaries3, 2), 3949 minstr = _this$boundaries4[0], 3950 maxstr = _this$boundaries4[1]; 3951 3952 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 3953 args[_key] = arguments[_key]; 3954 } 3955 3956 return this.from <= Number(maxstr) && Number(minstr) <= this.to && (_get2 = _get(_getPrototypeOf(MaskedRange.prototype), "doValidate", this)).call.apply(_get2, [this].concat(args)); 3957 } 3958 }]); 3959 3960 return MaskedRange; 3961 }(MaskedPattern); 3962 IMask.MaskedRange = MaskedRange; 3963 3964 /** Date mask */ 3965 3966 var MaskedDate = /*#__PURE__*/function (_MaskedPattern) { 3967 _inherits(MaskedDate, _MaskedPattern); 3968 3969 var _super = _createSuper(MaskedDate); 3970 3971 /** Pattern mask for date according to {@link MaskedDate#format} */ 3972 3973 /** Start date */ 3974 3975 /** End date */ 3976 3977 /** */ 3978 3979 /** 3980 @param {Object} opts 3981 */ 3982 function MaskedDate(opts) { 3983 _classCallCheck(this, MaskedDate); 3984 3985 return _super.call(this, Object.assign({}, MaskedDate.DEFAULTS, opts)); 3986 } 3987 /** 3988 @override 3989 */ 3990 3991 3992 _createClass(MaskedDate, [{ 3993 key: "_update", 3994 value: function _update(opts) { 3995 if (opts.mask === Date) delete opts.mask; 3996 if (opts.pattern) opts.mask = opts.pattern; 3997 var blocks = opts.blocks; 3998 opts.blocks = Object.assign({}, MaskedDate.GET_DEFAULT_BLOCKS()); // adjust year block 3999 4000 if (opts.min) opts.blocks.Y.from = opts.min.getFullYear(); 4001 if (opts.max) opts.blocks.Y.to = opts.max.getFullYear(); 4002 4003 if (opts.min && opts.max && opts.blocks.Y.from === opts.blocks.Y.to) { 4004 opts.blocks.m.from = opts.min.getMonth() + 1; 4005 opts.blocks.m.to = opts.max.getMonth() + 1; 4006 4007 if (opts.blocks.m.from === opts.blocks.m.to) { 4008 opts.blocks.d.from = opts.min.getDate(); 4009 opts.blocks.d.to = opts.max.getDate(); 4010 } 4011 } 4012 4013 Object.assign(opts.blocks, this.blocks, blocks); // add autofix 4014
4015 Object.keys(opts.blocks).forEach(function (bk) { 4016 var b = opts.blocks[bk]; 4017 if (!('autofix' in b) && 'autofix' in opts) b.autofix = opts.autofix; 4018 }); 4019 4020 _get(_getPrototypeOf(MaskedDate.prototype), "_update", this).call(this, opts); 4021 } 4022 /** 4023 @override 4024 */ 4025 4026 }, { 4027 key: "doValidate", 4028 value: function doValidate() { 4029 var _get2; 4030 4031 var date = this.date; 4032 4033 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 4034 args[_key] = arguments[_key]; 4035 } 4036 4037 return (_get2 = _get(_getPrototypeOf(MaskedDate.prototype), "doValidate", this)).call.apply(_get2, [this].concat(args)) && (!this.isComplete || this.isDateExist(this.value) && date != null && (this.min == null || this.min <= date) && (this.max == null || date <= this.max)); 4038 } 4039 /** Checks if date is exists */ 4040 4041 }, { 4042 key: "isDateExist", 4043 value: function isDateExist(str) { 4044 return this.format(this.parse(str, this), this).indexOf(str) >= 0; 4045 } 4046 /** Parsed Date */ 4047 4048 }, { 4049 key: "date", 4050 get: function get() { 4051 return this.typedValue; 4052 }, 4053 set: function set(date) { 4054 this.typedValue = date; 4055 } 4056 /** 4057 @override 4058 */ 4059 4060 }, { 4061 key: "typedValue", 4062 get: function get() { 4063 return this.isComplete ? _get(_getPrototypeOf(MaskedDate.prototype), "typedValue", this) : null; 4064 }, 4065 set: function set(value) { 4066 _set(_getPrototypeOf(MaskedDate.prototype), "typedValue", value, this, true); 4067 } 4068 /** 4069 @override 4070 */ 4071 4072 }, { 4073 key: "maskEquals", 4074 value: function maskEquals(mask) { 4075 return mask === Date || _get(_getPrototypeOf(MaskedDate.prototype), "maskEquals", this).call(this, mask); 4076 } 4077 }]); 4078 4079 return MaskedDate; 4080 }(MaskedPattern); 4081 MaskedDate.DEFAULTS = { 4082 pattern: 'd{.}`m{.}`Y', 4083 format: function format(date) { 4084 if (!date) return ''; 4085 var day = String(date.getDate()).padStart(2, '0'); 4086 var month = String(date.getMonth() + 1).padStart(2, '0'); 4087 var year = date.getFullYear(); 4088 return [day, month, year].join('.'); 4089 }, 4090 parse: function parse(str) { 4091 var _str$split = str.split('.'), 4092 _str$split2 = _slicedToArray(_str$split, 3), 4093 day = _str$split2[0], 4094 month = _str$split2[1], 4095 year = _str$split2[2]; 4096 4097 return new Date(year, month - 1, day); 4098 } 4099 }; 4100 4101 MaskedDate.GET_DEFAULT_BLOCKS = function () { 4102 return { 4103 d: { 4104 mask: MaskedRange, 4105 from: 1, 4106 to: 31, 4107 maxLength: 2 4108 }, 4109 m: { 4110 mask: MaskedRange, 4111 from: 1, 4112 to: 12, 4113 maxLength: 2 4114 }, 4115 Y: { 4116 mask: MaskedRange, 4117 from: 1900, 4118 to: 9999 4119 } 4120 }; 4121 }; 4122 4123 IMask.MaskedDate = MaskedDate; 4124 4125 /** 4126 Generic element API to use with mask 4127 @interface 4128 */ 4129 var MaskElement = /*#__PURE__*/function () { 4130 function MaskElement() { 4131 _classCallCheck(this, MaskElement); 4132 } 4133 4134 _createClass(MaskElement, [{ 4135 key: "selectionStart", 4136 get: 4137 /** */ 4138 4139 /** */ 4140 4141 /** */ 4142 4143 /** Safely returns selection start */ 4144 function get() { 4145 var start; 4146 4147 try { 4148 start = this._unsafeSelectionStart; 4149 } catch (e) {} 4150 4151 return start != null ? start : this.value.length; 4152 } 4153 /** Safely returns selection end */ 4154 4155 }, { 4156 key: "selectionEnd", 4157 get: function get() { 4158 var end; 4159 4160 try { 4161 end = this._unsafeSelectionEnd; 4162 } catch (e) {} 4163 4164 return end != null ? end : this.value.length; 4165 } 4166 /** Safely sets element selection */ 4167 4168 }, { 4169 key: "select", 4170 value: function select(start, end) { 4171 if (start == null || end == null || start === this.selectionStart && end === this.selectionEnd) return; 4172 4173 try { 4174 this._unsafeSelect(start, end); 4175 } catch (e) {} 4176 } 4177 /** Should be overriden in subclasses */ 4178 4179 }, { 4180 key: "_unsafeSelect", 4181 value: function _unsafeSelect(start, end) {} 4182 /** Should be overriden in subclasses */ 4183 4184 }, { 4185 key: "isActive", 4186 get: function get() { 4187 return false;
4188 } 4189 /** Should be overriden in subclasses */ 4190 4191 }, { 4192 key: "bindEvents", 4193 value: function bindEvents(handlers) {} 4194 /** Should be overriden in subclasses */ 4195 4196 }, { 4197 key: "unbindEvents", 4198 value: function unbindEvents() {} 4199 }]); 4200 4201 return MaskElement; 4202 }(); 4203 IMask.MaskElement = MaskElement; 4204 4205 /** Bridge between HTMLElement and {@link Masked} */ 4206 4207 var HTMLMaskElement = /*#__PURE__*/function (_MaskElement) { 4208 _inherits(HTMLMaskElement, _MaskElement); 4209 4210 var _super = _createSuper(HTMLMaskElement); 4211 4212 /** Mapping between HTMLElement events and mask internal events */ 4213 4214 /** HTMLElement to use mask on */ 4215 4216 /** 4217 @param {HTMLInputElement|HTMLTextAreaElement} input 4218 */ 4219 function HTMLMaskElement(input) { 4220 var _this; 4221 4222 _classCallCheck(this, HTMLMaskElement); 4223 4224 _this = _super.call(this); 4225 _this.input = input; 4226 _this._handlers = {}; 4227 return _this; 4228 } 4229 /** */ 4230 // $FlowFixMe https://github.com/facebook/flow/issues/2839 4231 4232 4233 _createClass(HTMLMaskElement, [{ 4234 key: "rootElement", 4235 get: function get() { 4236 var _this$input$getRootNo, _this$input$getRootNo2, _this$input; 4237 4238 return (_this$input$getRootNo = (_this$input$getRootNo2 = (_this$input = this.input).getRootNode) === null || _this$input$getRootNo2 === void 0 ? void 0 : _this$input$getRootNo2.call(_this$input)) !== null && _this$input$getRootNo !== void 0 ? _this$input$getRootNo : document; 4239 } 4240 /** 4241 Is element in focus 4242 @readonly 4243 */ 4244 4245 }, { 4246 key: "isActive", 4247 get: function get() { 4248 //$FlowFixMe 4249 return this.input === this.rootElement.activeElement; 4250 } 4251 /** 4252 Returns HTMLElement selection start 4253 @override 4254 */ 4255 4256 }, { 4257 key: "_unsafeSelectionStart", 4258 get: function get() { 4259 return this.input.selectionStart; 4260 } 4261 /** 4262 Returns HTMLElement selection end 4263 @override 4264 */ 4265 4266 }, { 4267 key: "_unsafeSelectionEnd", 4268 get: function get() { 4269 return this.input.selectionEnd; 4270 } 4271 /** 4272 Sets HTMLElement selection 4273 @override 4274 */ 4275 4276 }, { 4277 key: "_unsafeSelect", 4278 value: function _unsafeSelect(start, end) { 4279 this.input.setSelectionRange(start, end); 4280 } 4281 /** 4282 HTMLElement value 4283 @override 4284 */ 4285 4286 }, { 4287 key: "value", 4288 get: function get() { 4289 return this.input.value; 4290 }, 4291 set: function set(value) { 4292 this.input.value = value; 4293 } 4294 /** 4295 Binds HTMLElement events to mask internal events 4296 @override 4297 */ 4298 4299 }, { 4300 key: "bindEvents", 4301 value: function bindEvents(handlers) { 4302 var _this2 = this; 4303 4304 Object.keys(handlers).forEach(function (event) { 4305 return _this2._toggleEventHandler(HTMLMaskElement.EVENTS_MAP[event], handlers[event]); 4306 }); 4307 } 4308 /** 4309 Unbinds HTMLElement events to mask internal events 4310 @override 4311 */ 4312 4313 }, { 4314 key: "unbindEvents", 4315 value: function unbindEvents() { 4316 var _this3 = this; 4317 4318 Object.keys(this._handlers).forEach(function (event) { 4319 return _this3._toggleEventHandler(event); 4320 }); 4321 } 4322 /** */ 4323 4324 }, { 4325 key: "_toggleEventHandler", 4326 value: function _toggleEventHandler(event, handler) { 4327 if (this._handlers[event]) { 4328 this.input.removeEventListener(event, this._handlers[event]); 4329 delete this._handlers[event]; 4330 } 4331 4332 if (handler) { 4333 this.input.addEventListener(event, handler); 4334 this._handlers[event] = handler; 4335 } 4336 } 4337 }]); 4338 4339 return HTMLMaskElement; 4340 }(MaskElement); 4341 HTMLMaskElement.EVENTS_MAP = { 4342 selectionChange: 'keydown', 4343 input: 'input', 4344 drop: 'drop', 4345 click: 'click', 4346 focus: 'focus', 4347 commit: 'blur' 4348 }; 4349 IMask.HTMLMaskElement = HTMLMaskElement; 4350 4351 var HTMLContenteditableMaskElement = /*#__PURE__*/function (_HTMLMaskElement) { 4352 _inherits(HTMLContenteditableMaskElement, _HTMLMaskElement); 4353 4354 var _super = _createSuper(HTMLContenteditableMaskElement); 4355 4356 function HTMLContenteditableMaskElement() { 4357 _classCallCheck(this, HTMLContenteditableMaskElement); 4358 4359 return _super.apply(this, arguments); 4360 } 4361 4362 _createClass(HTMLContenteditableMaskElement, [{ 4363 key: "_unsafeSelectionStart", 4364 get: 4365 /** 4366 Returns HTMLElement selection start 4367 @override 4368 */ 4369 function get() { 4370 var root = this.rootElement; 4371 var selection = root.getSelection && root.getSelection(); 4372 var anchorOffset = selection && selection.anchorOffset; 4373 var focusOffset = selection && selection.focusOffset; 4374 4375 if (focusOffset == null || anchorOffset == null || anchorOffset < focusOffset) { 4376 return anchorOffset; 4377 } 4378 4379 return focusOffset; 4380 } 4381 /** 4382 Returns HTMLElement selection end 4383 @override 4384 */ 4385 4386 }, { 4387 key: "_unsafeSelectionEnd", 4388 get: function get() { 4389 var root = this.rootElement; 4390 var selection = root.getSelection && root.getSelection(); 4391 var anchorOffset = selection && selection.anchorOffset; 4392 var focusOffset = selection && selection.focusOffset; 4393 4394 if (focusOffset == null || anchorOffset == null || anchorOffset > focusOffset) { 4395 return anchorOffset; 4396 } 4397 4398 return focusOffset; 4399 } 4400 /** 4401 Sets HTMLElement selection 4402 @override 4403 */ 4404 4405 }, { 4406 key: "_unsafeSelect", 4407 value: function _unsafeSelect(start, end) { 4408 if (!this.rootElement.createRange) return; 4409 var range = this.rootElement.createRange(); 4410 range.setStart(this.input.firstChild || this.input, start);
4411 range.setEnd(this.input.lastChild || this.input, end); 4412 var root = this.rootElement; 4413 var selection = root.getSelection && root.getSelection(); 4414 4415 if (selection) { 4416 selection.removeAllRanges(); 4417 selection.addRange(range); 4418 } 4419 } 4420 /** 4421 HTMLElement value 4422 @override 4423 */ 4424 4425 }, { 4426 key: "value", 4427 get: function get() { 4428 // $FlowFixMe 4429 return this.input.textContent; 4430 }, 4431 set: function set(value) { 4432 this.input.textContent = value; 4433 } 4434 }]); 4435 4436 return HTMLContenteditableMaskElement; 4437 }(HTMLMaskElement); 4438 IMask.HTMLContenteditableMaskElement = HTMLContenteditableMaskElement; 4439 4440 var _excluded$1 = ["mask"]; 4441 /** Listens to element events and controls changes between element and {@link Masked} */ 4442 4443 var InputMask = /*#__PURE__*/function () { 4444 /** 4445 View element 4446 @readonly 4447 */ 4448 4449 /** 4450 Internal {@link Masked} model 4451 @readonly 4452 */ 4453 4454 /** 4455 @param {MaskElement|HTMLInputElement|HTMLTextAreaElement} el 4456 @param {Object} opts 4457 */ 4458 function InputMask(el, opts) { 4459 _classCallCheck(this, InputMask); 4460 4461 this.el = el instanceof MaskElement ? el : el.isContentEditable && el.tagName !== 'INPUT' && el.tagName !== 'TEXTAREA' ? new HTMLContenteditableMaskElement(el) : new HTMLMaskElement(el); 4462 this.masked = createMask(opts); 4463 this._listeners = {}; 4464 this._value = ''; 4465 this._unmaskedValue = ''; 4466 this._saveSelection = this._saveSelection.bind(this); 4467 this._onInput = this._onInput.bind(this); 4468 this._onChange = this._onChange.bind(this); 4469 this._onDrop = this._onDrop.bind(this); 4470 this._onFocus = this._onFocus.bind(this); 4471 this._onClick = this._onClick.bind(this); 4472 this.alignCursor = this.alignCursor.bind(this); 4473 this.alignCursorFriendly = this.alignCursorFriendly.bind(this); 4474 4475 this._bindEvents(); // refresh 4476 4477 4478 this.updateValue(); 4479 4480 this._onChange(); 4481 } 4482 /** Read or update mask */ 4483 4484 4485 _createClass(InputMask, [{ 4486 key: "mask", 4487 get: function get() { 4488 return this.masked.mask; 4489 }, 4490 set: function set(mask) { 4491 if (this.maskEquals(mask)) return; // $FlowFixMe No ideas ... after update 4492 4493 if (!(mask instanceof IMask.Masked) && this.masked.constructor === maskedClass(mask)) { 4494 this.masked.updateOptions({ 4495 mask: mask 4496 }); 4497 return; 4498 } 4499 4500 var masked = createMask({ 4501 mask: mask 4502 }); 4503 masked.unmaskedValue = this.masked.unmaskedValue; 4504 this.masked = masked; 4505 } 4506 /** Raw value */ 4507 4508 }, { 4509 key: "maskEquals", 4510 value: function maskEquals(mask) { 4511 var _this$masked; 4512 4513 return mask == null || ((_this$masked = this.masked) === null || _this$masked === void 0 ? void 0 : _this$masked.maskEquals(mask)); 4514 } 4515 }, { 4516 key: "value", 4517 get: function get() { 4518 return this._value; 4519 }, 4520 set: function set(str) { 4521 this.masked.value = str; 4522 this.updateControl(); 4523 this.alignCursor(); 4524 } 4525 /** Unmasked value */ 4526 4527 }, { 4528 key: "unmaskedValue", 4529 get: function get() { 4530 return this._unmaskedValue; 4531 }, 4532 set: function set(str) { 4533 this.masked.unmaskedValue = str; 4534 this.updateControl(); 4535 this.alignCursor(); 4536 } 4537 /** Typed unmasked value */ 4538 4539 }, { 4540 key: "typedValue", 4541 get: function get() { 4542 return this.masked.typedValue; 4543 }, 4544 set: function set(val) { 4545 this.masked.typedValue = val; 4546 this.updateControl(); 4547 this.alignCursor(); 4548 } 4549 /** 4550 Starts listening to element events 4551 @protected 4552 */ 4553 4554 }, { 4555 key: "_bindEvents", 4556 value: function _bindEvents() { 4557 this.el.bindEvents({ 4558 selectionChange: this._saveSelection, 4559 input: this._onInput, 4560 drop: this._onDrop, 4561 click: this._onClick, 4562 focus: this._onFocus, 4563 commit: this._onChange 4564 }); 4565 } 4566 /** 4567 Stops listening to element events 4568 @protected 4569 */ 4570 4571 }, { 4572 key: "_unbindEvents", 4573 value: function _unbindEvents() { 4574 if (this.el) this.el.unbindEvents(); 4575 } 4576 /** 4577 Fires custom event 4578 @protected 4579 */ 4580 4581 }, { 4582 key: "_fireEvent", 4583 value: function _fireEvent(ev) { 4584 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 4585 args[_key - 1] = arguments[_key]; 4586 } 4587 4588 var listeners = this._listeners[ev]; 4589 if (!listeners) return;
4590 listeners.forEach(function (l) { 4591 return l.apply(void 0, args); 4592 }); 4593 } 4594 /** 4595 Current selection start 4596 @readonly 4597 */ 4598 4599 }, { 4600 key: "selectionStart", 4601 get: function get() { 4602 return this._cursorChanging ? this._changingCursorPos : this.el.selectionStart; 4603 } 4604 /** Current cursor position */ 4605 4606 }, { 4607 key: "cursorPos", 4608 get: function get() { 4609 return this._cursorChanging ? this._changingCursorPos : this.el.selectionEnd; 4610 }, 4611 set: function set(pos) { 4612 if (!this.el || !this.el.isActive) return; 4613 this.el.select(pos, pos); 4614 4615 this._saveSelection(); 4616 } 4617 /** 4618 Stores current selection 4619 @protected 4620 */ 4621 4622 }, { 4623 key: "_saveSelection", 4624 value: function 4625 /* ev */ 4626 _saveSelection() { 4627 if (this.value !== this.el.value) { 4628 console.warn('Element value was changed outside of mask. Syncronize mask using `mask.updateValue()` to work properly.'); // eslint-disable-line no-console 4629 } 4630 4631 this._selection = { 4632 start: this.selectionStart, 4633 end: this.cursorPos 4634 }; 4635 } 4636 /** Syncronizes model value from view */ 4637 4638 }, { 4639 key: "updateValue", 4640 value: function updateValue() { 4641 this.masked.value = this.el.value; 4642 this._value = this.masked.value; 4643 } 4644 /** Syncronizes view from model value, fires change events */ 4645 4646 }, { 4647 key: "updateControl", 4648 value: function updateControl() { 4649 var newUnmaskedValue = this.masked.unmaskedValue; 4650 var newValue = this.masked.value; 4651 var isChanged = this.unmaskedValue !== newUnmaskedValue || this.value !== newValue; 4652 this._unmaskedValue = newUnmaskedValue; 4653 this._value = newValue; 4654 if (this.el.value !== newValue) this.el.value = newValue; 4655 if (isChanged) this._fireChangeEvents(); 4656 } 4657 /** Updates options with deep equal check, recreates @{link Masked} model if mask type changes */ 4658 4659 }, { 4660 key: "updateOptions", 4661 value: function updateOptions(opts) { 4662 var mask = opts.mask, 4663 restOpts = _objectWithoutProperties(opts, _excluded$1); 4664 4665 var updateMask = !this.maskEquals(mask); 4666 var updateOpts = !objectIncludes(this.masked, restOpts); 4667 if (updateMask) this.mask = mask; 4668 if (updateOpts) this.masked.updateOptions(restOpts); 4669 if (updateMask || updateOpts) this.updateControl(); 4670 } 4671 /** Updates cursor */ 4672 4673 }, { 4674 key: "updateCursor", 4675 value: function updateCursor(cursorPos) { 4676 if (cursorPos == null) return;
4677 this.cursorPos = cursorPos; // also queue change cursor for mobile browsers 4678 4679 this._delayUpdateCursor(cursorPos); 4680 } 4681 /** 4682 Delays cursor update to support mobile browsers 4683 @private 4684 */ 4685 4686 }, { 4687 key: "_delayUpdateCursor", 4688 value: function _delayUpdateCursor(cursorPos) { 4689 var _this = this; 4690 4691 this._abortUpdateCursor(); 4692 4693 this._changingCursorPos = cursorPos; 4694 this._cursorChanging = setTimeout(function () { 4695 if (!_this.el) return; // if was destroyed 4696 4697 _this.cursorPos = _this._changingCursorPos; 4698 4699 _this._abortUpdateCursor(); 4700 }, 10); 4701 } 4702 /** 4703 Fires custom events 4704 @protected 4705 */ 4706 4707 }, { 4708 key: "_fireChangeEvents", 4709 value: function _fireChangeEvents() { 4710 this._fireEvent('accept', this._inputEvent); 4711 4712 if (this.masked.isComplete) this._fireEvent('complete', this._inputEvent); 4713 } 4714 /** 4715 Aborts delayed cursor update 4716 @private 4717 */ 4718 4719 }, { 4720 key: "_abortUpdateCursor", 4721 value: function _abortUpdateCursor() { 4722 if (this._cursorChanging) { 4723 clearTimeout(this._cursorChanging); 4724 delete this._cursorChanging; 4725 } 4726 } 4727 /** Aligns cursor to nearest available position */ 4728 4729 }, { 4730 key: "alignCursor", 4731 value: function alignCursor() {
4732 this.cursorPos = this.masked.nearestInputPos(this.masked.nearestInputPos(this.cursorPos, DIRECTION.LEFT)); 4733 } 4734 /** Aligns cursor only if selection is empty */ 4735 4736 }, { 4737 key: "alignCursorFriendly", 4738 value: function alignCursorFriendly() { 4739 if (this.selectionStart !== this.cursorPos) return; // skip if range is selected 4740 4741 this.alignCursor(); 4742 } 4743 /** Adds listener on custom event */ 4744 4745 }, { 4746 key: "on", 4747 value: function on(ev, handler) { 4748 if (!this._listeners[ev]) this._listeners[ev] = []; 4749 4750 this._listeners[ev].push(handler); 4751 4752 return this; 4753 } 4754 /** Removes custom event listener */ 4755 4756 }, { 4757 key: "off", 4758 value: function off(ev, handler) { 4759 if (!this._listeners[ev]) return this; 4760 4761 if (!handler) { 4762 delete this._listeners[ev]; 4763 return this; 4764 } 4765 4766 var hIndex = this._listeners[ev].indexOf(handler); 4767 4768 if (hIndex >= 0) this._listeners[ev].splice(hIndex, 1); 4769 return this; 4770 } 4771 /** Handles view input event */ 4772 4773 }, { 4774 key: "_onInput", 4775 value: function _onInput(e) { 4776 this._inputEvent = e; 4777 4778 this._abortUpdateCursor(); // fix strange IE behavior 4779 4780 4781 if (!this._selection) return this.updateValue(); 4782 var details = new ActionDetails( // new state 4783 this.el.value, this.cursorPos, // old state 4784 this.value, this._selection); 4785 var oldRawValue = this.masked.rawInputValue; 4786 var offset = this.masked.splice(details.startChangePos, details.removed.length, details.inserted, details.removeDirection).offset; // force align in remove direction only if no input chars were removed 4787 // otherwise we still need to align with NONE (to get out from fixed symbols for instance) 4788 4789 var removeDirection = oldRawValue === this.masked.rawInputValue ? details.removeDirection : DIRECTION.NONE; 4790 var cursorPos = this.masked.nearestInputPos(details.startChangePos + offset, removeDirection); 4791 if (removeDirection !== DIRECTION.NONE) cursorPos = this.masked.nearestInputPos(cursorPos, DIRECTION.NONE); 4792 this.updateControl(); 4793 this.updateCursor(cursorPos); 4794 delete this._inputEvent; 4795 } 4796 /** Handles view change event and commits model value */ 4797 4798 }, { 4799 key: "_onChange", 4800 value: function _onChange() { 4801 if (this.value !== this.el.value) { 4802 this.updateValue(); 4803 } 4804 4805 this.masked.doCommit(); 4806 this.updateControl(); 4807 4808 this._saveSelection(); 4809 } 4810 /** Handles view drop event, prevents by default */ 4811 4812 }, { 4813 key: "_onDrop", 4814 value: function _onDrop(ev) { 4815 ev.preventDefault(); 4816 ev.stopPropagation(); 4817 } 4818 /** Restore last selection on focus */ 4819 4820 }, { 4821 key: "_onFocus", 4822 value: function _onFocus(ev) { 4823 this.alignCursorFriendly(); 4824 } 4825 /** Restore last selection on focus */ 4826 4827 }, { 4828 key: "_onClick", 4829 value: function _onClick(ev) { 4830 this.alignCursorFriendly(); 4831 } 4832 /** Unbind view events and removes element reference */ 4833 4834 }, { 4835 key: "destroy", 4836 value: function destroy() { 4837 this._unbindEvents(); // $FlowFixMe why not do so? 4838 4839 4840 this._listeners.length = 0; // $FlowFixMe 4841 4842 delete this.el; 4843 } 4844 }]); 4845 4846 return InputMask; 4847 }(); 4848 IMask.InputMask = InputMask; 4849 4850 /** Pattern which validates enum values */ 4851 4852 var MaskedEnum = /*#__PURE__*/function (_MaskedPattern) { 4853 _inherits(MaskedEnum, _MaskedPattern); 4854 4855 var _super = _createSuper(MaskedEnum); 4856 4857 function MaskedEnum() { 4858 _classCallCheck(this, MaskedEnum); 4859 4860 return _super.apply(this, arguments); 4861 } 4862 4863 _createClass(MaskedEnum, [{ 4864 key: "_update", 4865 value: 4866 /** 4867 @override 4868 @param {Object} opts 4869 */ 4870 function _update(opts) { 4871 // TODO type 4872 if (opts.enum) opts.mask = '*'.repeat(opts.enum[0].length); 4873 4874 _get(_getPrototypeOf(MaskedEnum.prototype), "_update", this).call(this, opts); 4875 } 4876 /** 4877 @override 4878 */ 4879 4880 }, { 4881 key: "doValidate", 4882 value: function doValidate() { 4883 var _this = this, 4884 _get2; 4885 4886 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 4887 args[_key] = arguments[_key]; 4888 } 4889 4890 return this.enum.some(function (e) { 4891 return e.indexOf(_this.unmaskedValue) >= 0; 4892 }) && (_get2 = _get(_getPrototypeOf(MaskedEnum.prototype), "doValidate", this)).call.apply(_get2, [this].concat(args)); 4893 } 4894 }]); 4895 4896 return MaskedEnum; 4897 }(MaskedPattern); 4898 IMask.MaskedEnum = MaskedEnum; 4899 4900 /** 4901 Number mask 4902 @param {Object} opts 4903 @param {string} opts.radix - Single char 4904 @param {string} opts.thousandsSeparator - Single char 4905 @param {Array<string>} opts.mapToRadix - Array of single chars 4906 @param {number} opts.min 4907 @param {number} opts.max 4908 @param {number} opts.scale - Digits after point 4909 @param {boolean} opts.signed - Allow negative 4910 @param {boolean} opts.normalizeZeros - Flag to remove leading and trailing zeros in the end of editing 4911 @param {boolean} opts.padFractionalZeros - Flag to pad trailing zeros after point in the end of editing 4912 */ 4913 var MaskedNumber = /*#__PURE__*/function (_Masked) { 4914 _inherits(MaskedNumber, _Masked); 4915 4916 var _super = _createSuper(MaskedNumber); 4917 4918 /** Single char */ 4919 4920 /** Single char */ 4921 4922 /** Array of single chars */ 4923 4924 /** */ 4925 4926 /** */ 4927 4928 /** Digits after point */ 4929 4930 /** */ 4931 4932 /** Flag to remove leading and trailing zeros in the end of editing */ 4933 4934 /** Flag to pad trailing zeros after point in the end of editing */ 4935 function MaskedNumber(opts) { 4936 _classCallCheck(this, MaskedNumber); 4937 4938 return _super.call(this, Object.assign({}, MaskedNumber.DEFAULTS, opts)); 4939 } 4940 /** 4941 @override 4942 */ 4943 4944 4945 _createClass(MaskedNumber, [{ 4946 key: "_update", 4947 value: function _update(opts) { 4948 _get(_getPrototypeOf(MaskedNumber.prototype), "_update", this).call(this, opts); 4949 4950 this._updateRegExps(); 4951 } 4952 /** */ 4953 4954 }, { 4955 key: "_updateRegExps", 4956 value: function _updateRegExps() { 4957 // use different regexp to process user input (more strict, input suffix
4957) and tail shifting 4958 var start = '^' + (this.allowNegative ? '[+|\\-]?' : ''); 4959 var midInput = '(0|([1-9]+\\d*))?'; 4960 var mid = '\\d*'; 4961 var end = (this.scale ? '(' + escapeRegExp(this.radix) + '\\d{0,' + this.scale + '})?' : '') + '$'; 4962 this._numberRegExpInput = new RegExp(start + midInput + end); 4963 this._numberRegExp = new RegExp(start + mid + end); 4964 this._mapToRadixRegExp = new RegExp('[' + this.mapToRadix.map(escapeRegExp).join('') + ']', 'g'); 4965 this._thousandsSeparatorRegExp = new RegExp(escapeRegExp(this.thousandsSeparator), 'g'); 4966 } 4967 /** */ 4968 4969 }, { 4970 key: "_removeThousandsSeparators", 4971 value: function _removeThousandsSeparators(value) { 4972 return value.replace(this._thousandsSeparatorRegExp, ''); 4973 } 4974 /** */ 4975 4976 }, { 4977 key: "_insertThousandsSeparators", 4978 value: function _insertThousandsSeparators(value) { 4979 // https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript 4980 var parts = value.split(this.radix); 4981 parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, this.thousandsSeparator); 4982 return parts.join(this.radix); 4983 } 4984 /** 4985 @override 4986 */ 4987 4988 }, { 4989 key: "doPrepare", 4990 value: function doPrepare(ch) { 4991 var _get2; 4992 4993 ch = ch.replace(this._mapToRadixRegExp, this.radix); 4994 4995 var noSepCh = this._removeThousandsSeparators(ch); 4996 4997 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 4998 args[_key - 1] = arguments[_key]; 4999 } 5000 5001 var _normalizePrepare = normalizePrepare((_get2 = _get(_getPrototypeOf(MaskedNumber.prototype), "doPrepare", this)).call.apply(_get2, [this, noSepCh].concat(args))), 5002 _normalizePrepare2 = _slicedToArray(_normalizePrepare, 2), 5003 prepCh = _normalizePrepare2[0], 5004 details = _normalizePrepare2[1]; 5005 5006 if (ch && !noSepCh) details.skip = true; 5007 return [prepCh, details]; 5008 } 5009 /** */ 5010 5011 }, { 5012 key: "_separatorsCount", 5013 value: function _separatorsCount(to) { 5014 var extendOnSeparators = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; 5015 var count = 0; 5016 5017 for (var pos = 0; pos < to; ++pos) { 5018 if (this._value.indexOf(this.thousandsSeparator, pos) === pos) { 5019 ++count; 5020 if (extendOnSeparators) to += this.thousandsSeparator.length; 5021 } 5022 } 5023 5024 return count; 5025 } 5026 /** */ 5027 5028 }, { 5029 key: "_separatorsCountFromSlice", 5030 value: function _separatorsCountFromSlice() { 5031 var slice = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._value; 5032 return this._separatorsCount(this._removeThousandsSeparators(slice).length, true); 5033 } 5034 /** 5035 @override 5036 */ 5037 5038 }, { 5039 key: "extractInput", 5040 value: function extractInput() { 5041 var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; 5042 var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length; 5043 var flags = arguments.length > 2 ? arguments[2] : undefined; 5044 5045 var _this$_adjustRangeWit = this._adjustRangeWithSeparators(fromPos, toPos); 5046 5047 var _this$_adjustRangeWit2 = _slicedToArray(_this$_adjustRangeWit, 2); 5048 5049 fromPos = _this$_adjustRangeWit2[0]; 5050 toPos = _this$_adjustRangeWit2[1]; 5051 return this._removeThousandsSeparators(_get(_getPrototypeOf(MaskedNumber.prototype), "extractInput", this).call(this, fromPos, toPos, flags)); 5052 } 5053 /** 5054 @override 5055 */ 5056 5057 }, { 5058 key: "_appendCharRaw", 5059 value: function _appendCharRaw(ch) { 5060 var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 5061 if (!this.thousandsSeparator) return _get(_getPrototypeOf(MaskedNumber.prototype), "_appendCharRaw", this).call(this, ch, flags); 5062 var prevBeforeTailValue = flags.tail && flags._beforeTailState ? flags._beforeTailState._value : this._value; 5063 5064 var prevBeforeTailSeparatorsCount = this._separatorsCountFromSlice(prevBeforeTailValue); 5065 5066 this._value = this._removeThousandsSeparators(this.value); 5067 5068 var appendDetails = _get(_getPrototypeOf(MaskedNumber.prototype), "_appendCharRaw", this).call(this, ch, flags); 5069 5070 this._value = this._insertThousandsSeparators(this._value); 5071 var beforeTailValue = flags.tail && flags._beforeTailState ? flags._beforeTailState._value : this._value; 5072 5073 var beforeTailSeparatorsCount = this._separatorsCountFromSlice(beforeTailValue); 5074 5075 appendDetails.tailShift += (beforeTailSeparatorsCount - prevBeforeTailSeparatorsCount) * this.thousandsSeparator.length; 5076 appendDetails.skip = !appendDetails.rawInserted && ch === this.thousandsSeparator; 5077 return appendDetails; 5078 } 5079 /** */ 5080 5081 }, { 5082 key: "_findSeparatorAround", 5083 value: function _findSeparatorAround(pos) { 5084 if (this.thousandsSeparator) { 5085 var searchFrom = pos - this.thousandsSeparator.length + 1; 5086 var separatorPos = this.value.indexOf(this.thousandsSeparator, searchFrom); 5087 if (separatorPos <= pos) return separatorPos; 5088 } 5089 5090 return -1; 5091 } 5092 }, { 5093 key: "_adjustRangeWithSeparators", 5094 value: function _adjustRangeWithSeparators(from, to) { 5095 var separatorAroundFromPos = this._findSeparatorAround(from); 5096 5097 if (separatorAroundFromPos >= 0) from = separatorAroundFromPos; 5098 5099 var separatorAroundToPos = this._findSeparatorAround(to); 5100 5101 if (separatorAroundToPos >= 0) to = separatorAroundToPos + this.thousandsSeparator.length; 5102 return [from, to]; 5103 } 5104 /** 5105 @override 5106 */ 5107 5108 }, { 5109 key: "remove", 5110 value: function remove() { 5111 var fromPos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; 5112 var toPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.value.length; 5113 5114 var _this$_adjustRangeWit3 = this._adjustRangeWithSeparators(fromPos, toPos); 5115 5116 var _this$_adjustRangeWit4 = _slicedToArray(_this$_adjustRangeWit3, 2); 5117 5118 fromPos = _this$_adjustRangeWit4[0]; 5119 toPos = _this$_adjustRangeWit4[1]; 5120 var valueBeforePos = this.value.slice(0, fromPos); 5121 var valueAfterPos = this.value.slice(toPos); 5122 5123 var prevBeforeTailSeparatorsCount = this._separatorsCount(valueBeforePos.length); 5124 5125 this._value = this._insertThousandsSeparators(this._removeThousandsSeparators(valueBeforePos + valueAfterPos)); 5126 5127 var beforeTailSeparatorsCount = this._separatorsCountFromSlice(valueBeforePos); 5128 5129 return new ChangeDetails({ 5130 tailShift: (beforeTailSeparatorsCount - prevBeforeTailSeparatorsCount) * this.thousandsSeparator.length 5131 }); 5132 } 5133 /** 5134 @override 5135 */ 5136 5137 }, { 5138 key: "nearestInputPos", 5139 value: function nearestInputPos(cursorPos, direction) { 5140 if (!this.thousandsSeparator) return cursorPos; 5141 5142 switch (direction) { 5143 case DIRECTION.NONE: 5144 case DIRECTION.LEFT: 5145 case DIRECTION.FORCE_LEFT: 5146 { 5147 var separatorAtLeftPos = this._findSeparatorAround(cursorPos - 1); 5148 5149 if (separatorAtLeftPos >= 0) { 5150 var separatorAtLeftEndPos = separatorAtLeftPos + this.thousandsSeparator.length; 5151 5152 if (cursorPos < separatorAtLeftEndPos || this.value.length <= separatorAtLeftEndPos || direction === DIRECTION.FORCE_LEFT) { 5153 return separatorAtLeftPos; 5154 } 5155 } 5156 5157 break; 5158 } 5159 5160 case DIRECTION.RIGHT: 5161 case DIRECTION.FORCE_RIGHT: 5162 { 5163 var separatorAtRightPos = this._findSeparatorAround(cursorPos); 5164 5165 if (separatorAtRightPos >= 0) { 5166 return separatorAtRightPos + this.thousandsSeparator.length; 5167 } 5168 } 5169 } 5170 5171 return cursorPos; 5172 } 5173 /** 5174 @override 5175 */ 5176 5177 }, { 5178 key: "doValidate", 5179 value: function doValidate(flags) { 5180 var regexp = flags.input ? this._numberRegExpInput : this._numberRegExp; // validate as string 5181
5182 var valid = regexp.test(this._removeThousandsSeparators(this.value)); 5183 5184 if (valid) { 5185 // validate as number 5186 var number = this.number; 5187 valid = valid && !isNaN(number) && ( // check min bound for negative values 5188 this.min == null || this.min >= 0 || this.min <= this.number) && ( // check max bound for positive values 5189 this.max == null || this.max <= 0 || this.number <= this.max); 5190 } 5191 5192 return valid && _get(_getPrototypeOf(MaskedNumber.prototype), "doValidate", this).call(this, flags); 5193 } 5194 /** 5195 @override 5196 */ 5197 5198 }, { 5199 key: "doCommit", 5200 value: function doCommit() { 5201 if (this.value) { 5202 var number = this.number; 5203 var validnum = number; // check bounds 5204 5205 if (this.min != null) validnum = Math.max(validnum, this.min); 5206 if (this.max != null) validnum = Math.min(validnum, this.max); 5207 if (validnum !== number) this.unmaskedValue = String(validnum); 5208 var formatted = this.value; 5209 if (this.normalizeZeros) formatted = this._normalizeZeros(formatted); 5210 if (this.padFractionalZeros && this.scale > 0) formatted = this._padFractionalZeros(formatted); 5211 this._value = formatted; 5212 } 5213 5214 _get(_getPrototypeOf(MaskedNumber.prototype), "doCommit", this).call(this); 5215 } 5216 /** */ 5217 5218 }, { 5219 key: "_normalizeZeros", 5220 value: function _normalizeZeros(value) { 5221 var parts = this._removeThousandsSeparators(value).split(this.radix); // remove leading zeros 5222 5223 5224 parts[0] = parts[0].replace(/^(\D*)(0*)(\d*)/, function (match, sign, zeros, num) { 5225 return sign + num; 5226 }); // add leading zero 5227 5228 if (value.length && !/\d$/.test(parts[0])) parts[0] = parts[0] + '0'; 5229 5230 if (parts.length > 1) { 5231 parts[1] = parts[1].replace(/0*$/, ''); // remove trailing zeros 5232 5233 if (!parts[1].length) parts.length = 1; // remove fractional 5234 } 5235 5236 return this._insertThousandsSeparators(parts.join(this.radix)); 5237 } 5238 /** */ 5239 5240 }, { 5241 key: "_padFractionalZeros", 5242 value: function _padFractionalZeros(value) { 5243 if (!value) return value; 5244 var parts = value.split(this.radix); 5245 if (parts.length < 2) parts.push(''); 5246 parts[1] = parts[1].padEnd(this.scale, '0'); 5247 return parts.join(this.radix); 5248 } 5249 /** 5250 @override 5251 */ 5252 5253 }, { 5254 key: "unmaskedValue", 5255 get: function get() { 5256 return this._removeThousandsSeparators(this._normalizeZeros(this.value)).replace(this.radix, '.'); 5257 }, 5258 set: function set(unmaskedValue) { 5259 _set(_getPrototypeOf(MaskedNumber.prototype), "unmaskedValue", unmaskedValue.replace('.', this.radix), this, true); 5260 } 5261 /** 5262 @override 5263 */ 5264 5265 }, { 5266 key: "typedValue", 5267 get: function get() { 5268 return Number(this.unmaskedValue); 5269 }, 5270 set: function set(n) { 5271 _set(_getPrototypeOf(MaskedNumber.prototype), "unmaskedValue", String(n), this, true); 5272 } 5273 /** Parsed Number */ 5274 5275 }, { 5276 key: "number", 5277 get: function get() { 5278 return this.typedValue; 5279 }, 5280 set: function set(number) { 5281 this.typedValue = number; 5282 } 5283 /** 5284 Is negative allowed 5285 @readonly 5286 */ 5287 5288 }, { 5289 key: "allowNegative", 5290 get: function get() { 5291 return this.signed || this.min != null && this.min < 0 || this.max != null && this.max < 0; 5292 } 5293 }]); 5294 5295 return MaskedNumber; 5296 }(Masked); 5297 MaskedNumber.DEFAULTS = { 5298 radix: ',', 5299 thousandsSeparator: '', 5300 mapToRadix: ['.'], 5301 scale: 2, 5302 signed: false, 5303 normalizeZeros: true, 5304 padFractionalZeros: false 5305 }; 5306 IMask.MaskedNumber = MaskedNumber; 5307 5308 /** Masking by custom Function */ 5309 5310 var MaskedFunction = /*#__PURE__*/function (_Masked) { 5311 _inherits(MaskedFunction, _Masked); 5312 5313 var _super = _createSuper(MaskedFunction); 5314 5315 function MaskedFunction() { 5316 _classCallCheck(this, MaskedFunction); 5317 5318 return _super.apply(this, arguments); 5319 } 5320 5321 _createClass(MaskedFunction, [{ 5322 key: "_update", 5323 value: 5324 /** 5325 @override 5326 @param {Object} opts 5327 */ 5328 function _update(opts) { 5329 if (opts.mask) opts.validate = opts.mask; 5330 5331 _get(_getPrototypeOf(MaskedFunction.prototype), "_update", this).call(this, opts); 5332 } 5333 }]); 5334 5335 return MaskedFunction; 5336 }(Masked); 5337 IMask.MaskedFunction = MaskedFunction; 5338 5339 var _excluded = ["compiledMasks", "currentMaskRef", "currentMask"]; 5340 5341 /** Dynamic mask for choosing apropriate mask in run-time */ 5342 var MaskedDynamic = /*#__PURE__*/function (_Masked) { 5343 _inherits(MaskedDynamic, _Masked); 5344 5345 var _super = _createSuper(MaskedDynamic); 5346 5347 /** Currently chosen mask */ 5348 5349 /** Compliled {@link Masked} options */ 5350 5351 /** Chooses {@link Masked}
5351 depending on input value */ 5352 5353 /** 5354 @param {Object} opts 5355 */ 5356 function MaskedDynamic(opts) { 5357 var _this; 5358 5359 _classCallCheck(this, MaskedDynamic); 5360 5361 _this = _super.call(this, Object.assign({}, MaskedDynamic.DEFAULTS, opts)); 5362 _this.currentMask = null; 5363 return _this; 5364 } 5365 /** 5366 @override 5367 */ 5368 5369 5370 _createClass(MaskedDynamic, [{ 5371 key: "_update", 5372 value: function _update(opts) { 5373 _get(_getPrototypeOf(MaskedDynamic.prototype), "_update", this).call(this, opts); 5374 5375 if ('mask' in opts) { 5376 // mask could be totally dynamic with only `dispatch` option 5377 this.compiledMasks = Array.isArray(opts.mask) ? opts.mask.map(function (m) { 5378 return createMask(m); 5379 }) : []; 5380 } 5381 } 5382 /** 5383 @override 5384 */ 5385 5386 }, { 5387 key: "_appendCharRaw", 5388 value: function _appendCharRaw(ch) { 5389 var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 5390 5391 var details = this._applyDispatch(ch, flags); 5392 5393 if (this.currentMask) { 5394 details.aggregate(this.currentMask._appendChar(ch, flags)); 5395 } 5396 5397 return details; 5398 } 5399 }, { 5400 key: "_applyDispatch", 5401 value: function _applyDispatch() { 5402 var appended = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; 5403 var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 5404 var prevValueBeforeTail = flags.tail && flags._beforeTailState != null ? flags._beforeTailState._value : this.value; 5405 var inputValue = this.rawInputValue; 5406 var insertValue = flags.tail && flags._beforeTailState != null ? // $FlowFixMe - tired to fight with type system 5407 flags._beforeTailState._rawInputValue : inputValue; 5408 var tailValue = inputValue.slice(insertValue.length); 5409 var prevMask = this.currentMask; 5410 var details = new ChangeDetails(); 5411 var prevMaskState = prevMask && prevMask.state; // clone flags to prevent overwriting `_beforeTailState` 5412 5413 this.currentMask = this.doDispatch(appended, Object.assign({}, flags)); // restore state after dispatch 5414 5415 if (this.currentMask) { 5416 if (this.currentMask !== prevMask) { 5417 // if mask changed reapply input 5418 this.currentMask.reset(); 5419 5420 if (insertValue) { 5421 // $FlowFixMe - it's ok, we don't change current mask above 5422 var d = this.currentMask.append(insertValue, { 5423 raw: true 5424 }); 5425 details.tailShift = d.inserted.length - prevValueBeforeTail.length; 5426 } 5427 5428 if (tailValue) { 5429 // $FlowFixMe - it's ok, we don't change current mask above 5430 details.tailShift += this.currentMask.append(tailValue, { 5431 raw: true, 5432 tail: true 5433 }).tailShift; 5434 } 5435 } else { 5436 // Dispatch can do something bad with state, so 5437 // restore prev mask state 5438 this.currentMask.state = prevMaskState; 5439 } 5440 } 5441 5442 return details; 5443 } 5444 }, { 5445 key: "_appendPlaceholder", 5446 value: function _appendPlaceholder() { 5447 var details = this._applyDispatch.apply(this, arguments); 5448 5449 if (this.currentMask) { 5450 details.aggregate(this.currentMask._appendPlaceholder()); 5451 } 5452 5453 return details; 5454 } 5455 /** 5456 @override 5457 */ 5458 5459 }, { 5460 key: "_appendEager", 5461 value: function _appendEager() { 5462 var details = this._applyDispatch.apply(this, arguments); 5463 5464 if (this.currentMask) { 5465 details.aggregate(this.currentMask._appendEager()); 5466 } 5467 5468 return details; 5469 } 5470 /** 5471 @override 5472 */ 5473 5474 }, { 5475 key: "doDispatch", 5476 value: function doDispatch(appended) { 5477 var flags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 5478 return this.dispatch(appended, this, flags); 5479 } 5480 /** 5481 @override 5482 */ 5483 5484 }, { 5485 key: "doValidate", 5486 value: function doValidate() { 5487 var _get2, _this$currentMask; 5488 5489 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 5490 args[_key] = arguments[_key]; 5491 } 5492 5493 return (_get2 = _get(_getPrototypeOf(MaskedDynamic.prototype), "doValidate", this)).call.apply(_get2, [this].concat(args)) && (!this.currentMask || (_this$currentMask = this.currentMask).doValidate.apply(_this$currentMask, args)); 5494 } 5495 /** 5496 @override 5497 */ 5498 5499 }, { 5500 key: "reset", 5501 value: function reset() { 5502 var _this$currentMask2; 5503 5504 (_this$currentMask2 = this.currentMask) === null || _this$currentMask2 === void 0 ? void 0 : _this$currentMask2.reset(); 5505 this.compiledMasks.forEach(function (m) { 5506 return m.reset(); 5507 }); 5508 } 5509 /** 5510 @override 5511 */ 5512 5513 }, { 5514 key: "value", 5515 get: function get() { 5516 return this.currentMask ? this.currentMask.value : ''; 5517 }, 5518 set: function set(value) { 5519 _set(_getPrototypeOf(MaskedDynamic.prototype), "value", value, this, true); 5520 } 5521 /** 5522 @override 5523 */ 5524 5525 }, { 5526 key: "unmaskedValue", 5527 get: function get() { 5528 return this.currentMask ? this.currentMask.unmaskedValue : ''; 5529 }, 5530 set: function set(unmaskedValue) { 5531 _set(_getPrototypeOf(MaskedDynamic.prototype), "unmaskedValue", unmaskedValue, this, true); 5532 } 5533 /** 5534 @override 5535 */ 5536 5537 }, { 5538 key: "typedValue", 5539 get: function get() { 5540 return this.currentMask ? this.currentMask.typedValue : ''; 5541 } // probably typedValue should not be used with dynamic 5542 , 5543 set: function set(value) { 5544 var unmaskedValue = String(value); // double check it
5545 5546 if (this.currentMask) { 5547 this.currentMask.typedValue = value; 5548 unmaskedValue = this.currentMask.unmaskedValue; 5549 } 5550 5551 this.unmaskedValue = unmaskedValue; 5552 } 5553 /** 5554 @override 5555 */ 5556 5557 }, { 5558 key: "isComplete", 5559 get: function get() { 5560 var _this$currentMask3; 5561 5562 return Boolean((_this$currentMask3 = this.currentMask) === null || _this$currentMask3 === void 0 ? void 0 : _this$currentMask3.isComplete); 5563 } 5564 /** 5565 @override 5566 */ 5567 5568 }, { 5569 key: "isFilled", 5570 get: function get() { 5571 var _this$currentMask4; 5572 5573 return Boolean((_this$currentMask4 = this.currentMask) === null || _this$currentMask4 === void 0 ? void 0 : _this$currentMask4.isFilled); 5574 } 5575 /** 5576 @override 5577 */ 5578 5579 }, { 5580 key: "remove", 5581 value: function remove() { 5582 var details = new ChangeDetails(); 5583 5584 if (this.currentMask) { 5585 var _this$currentMask5; 5586 5587 details.aggregate((_this$currentMask5 = this.currentMask).remove.apply(_this$currentMask5, arguments)) // update with dispatch 5588 .aggregate(this._applyDispatch()); 5589 } 5590 5591 return details; 5592 } 5593 /** 5594 @override 5595 */ 5596 5597 }, { 5598 key: "state", 5599 get: function get() { 5600 return Object.assign({}, _get(_getPrototypeOf(MaskedDynamic.prototype), "state", this), { 5601 _rawInputValue: this.rawInputValue, 5602 compiledMasks: this.compiledMasks.map(function (m) { 5603 return m.state; 5604 }), 5605 currentMaskRef: this.currentMask, 5606 currentMask: this.currentMask && this.currentMask.state 5607 }); 5608 }, 5609 set: function set(state) { 5610 var compiledMasks = state.compiledMasks, 5611 currentMaskRef = state.currentMaskRef, 5612 currentMask = state.currentMask, 5613 maskedState = _objectWithoutProperties(state, _excluded); 5614 5615 this.compiledMasks.forEach(function (m, mi) { 5616 return m.state = compiledMasks[mi]; 5617 }); 5618 5619 if (currentMaskRef != null) { 5620 this.currentMask = currentMaskRef; 5621 this.currentMask.state = currentMask; 5622 } 5623 5624 _set(_getPrototypeOf(MaskedDynamic.prototype), "state", maskedState, this, true); 5625 } 5626 /** 5627 @override 5628 */ 5629 5630 }, { 5631 key: "extractInput", 5632 value: function extractInput() { 5633 var _this$currentMask6; 5634 5635 return this.currentMask ? (_this$currentMask6 = this.currentMask).extractInput.apply(_this$currentMask6, arguments) : ''; 5636 } 5637 /** 5638 @override 5639 */ 5640 5641 }, { 5642 key: "extractTail", 5643 value: function extractTail() { 5644 var _this$currentMask7, _get3; 5645 5646 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 5647 args[_key2] = arguments[_key2]; 5648 } 5649 5650 return this.currentMask ? (_this$currentMask7 = this.currentMask).extractTail.apply(_this$currentMask7, args) : (_get3 = _get(_getPrototypeOf(MaskedDynamic.prototype), "extractTail", this)).call.apply(_get3, [this].concat(args)); 5651 } 5652 /** 5653 @override 5654 */ 5655 5656 }, { 5657 key: "doCommit", 5658 value: function doCommit() { 5659 if (this.currentMask) this.currentMask.doCommit(); 5660 5661 _get(_getPrototypeOf(MaskedDynamic.prototype), "doCommit", this).call(this); 5662 } 5663 /** 5664 @override 5665 */ 5666 5667 }, { 5668 key: "nearestInputPos", 5669 value: function nearestInputPos() { 5670 var _this$currentMask8, _get4; 5671 5672 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { 5673 args[_key3] = arguments[_key3]; 5674 } 5675 5676 return this.currentMask ? (_this$currentMask8 = this.currentMask).nearestInputPos.apply(_this$currentMask8, args) : (_get4 = _get(_getPrototypeOf(MaskedDynamic.prototype), "nearestInputPos", this)).call.apply(_get4, [this].concat(args)); 5677 } 5678 }, { 5679 key: "overwrite", 5680 get: function get() { 5681 return this.currentMask ? this.currentMask.overwrite : _get(_getPrototypeOf(MaskedDynamic.prototype), "overwrite", this); 5682 }, 5683 set: function set(overwrite) { 5684 console.warn('"overwrite" option is not available in dynamic mask, use this option in siblings'); 5685 } 5686 }, { 5687 key: "eager", 5688 get: function get() { 5689 return this.currentMask ? this.currentMask.eager : _get(_getPrototypeOf(MaskedDynamic.prototype), "eager", this); 5690 }, 5691 set: function set(eager) { 5692 console.warn('"eager" option is not available in dynamic mask, use this option in siblings'); 5693 } 5694 /** 5695 @override 5696 */ 5697 5698 }, { 5699 key: "maskEquals", 5700 value: function maskEquals(mask) { 5701 return Array.isArray(mask) && this.compiledMasks.every(function (m, mi) { 5702 var _mask$mi; 5703 5704 return m.maskEquals((_mask$mi = mask[mi]) === null || _mask$mi === void 0 ? void 0 : _mask$mi.mask); 5705 }); 5706 } 5707 }]); 5708 5709 return MaskedDynamic; 5710 }(Masked); 5711 MaskedDynamic.DEFAULTS = { 5712 dispatch: function dispatch(appended, masked, flags) { 5713 if (!masked.compiledMasks.length) return; 5714 var inputValue = masked.rawInputValue; // simulate input 5715 5716 var inputs = masked.compiledMasks.map(function (m, index) { 5717 m.reset(); 5718 m.append(inputValue, { 5719 raw: true 5720 }); 5721 m.append(appended, flags); 5722 var weight = m.rawInputValue.length; 5723 return { 5724 weight: weight, 5725 index: index 5726 }; 5727 }); // pop masks with longer values first 5728 5729 inputs.sort(function (i1, i2) { 5730 return i2.weight - i1.weight; 5731 }); 5732 return masked.compiledMasks[inputs[0].index]; 5733 } 5734 }; 5735 IMask.MaskedDynamic = MaskedDynamic; 5736 5737 /** Mask pipe source and destination types */ 5738 5739 var PIPE_TYPE = { 5740 MASKED: 'value', 5741 UNMASKED: 'unmaskedValue', 5742 TYPED: 'typedValue' 5743 }; 5744 /** Creates new pipe function depending on mask type, source and destination options */ 5745 5746 function createPipe(mask) { 5747 var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : PIPE_TYPE.MASKED; 5748 var to = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : PIPE_TYPE.MASKED; 5749 var masked = createMask(mask); 5750 return function (value) { 5751 return masked.runIsolated(function (m) { 5752 m[from] = value; 5753 return m[to]; 5754 }); 5755 }; 5756 } 5757 /** Pipes value through mask depending on mask type, source and destination options */ 5758 5759 function pipe(value) { 5760 for (var _len = arguments.length, pipeArgs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 5761 pipeArgs[_key - 1] = arguments[_key]; 5762 } 5763 5764 return createPipe.apply(void 0, pipeArgs)(value); 5765 } 5766 IMask.PIPE_TYPE = PIPE_TYPE; 5767 IMask.createPipe = createPipe; 5768 IMask.pipe = pipe; 5769 5770 try { 5771 globalThis.IMask = IMask; 5772 } catch (e) {} 5773 5774 exports.HTMLContenteditableMaskElement = HTMLContenteditableMaskElement; 5775 exports.HTMLMaskElement = HTMLMaskElement; 5776 exports.InputMask = InputMask; 5777 exports.MaskElement = MaskElement; 5778 exports.Masked = Masked; 5779 exports.MaskedDate = MaskedDate; 5780 exports.MaskedDynamic = MaskedDynamic; 5781 exports.MaskedEnum = MaskedEnum; 5782 exports.MaskedFunction = MaskedFunction; 5783 exports.MaskedNumber = MaskedNumber; 5784 exports.MaskedPattern = MaskedPattern; 5785 exports.MaskedRange = MaskedRange; 5786 exports.MaskedRegExp = MaskedRegExp; 5787 exports.PIPE_TYPE = PIPE_TYPE; 5788 exports.createMask = createMask; 5789 exports.createPipe = createPipe;
5790 exports["default"] = IMask; 5791 exports.pipe = pipe; 5792 5793 Object.defineProperty(exports, '__esModule', { value: true }); 5794 5795})); 5796//# sourceMappingURL=imask.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.