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