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