ngx-mask 19.0.4 → 19.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -254,11 +254,48 @@ class NgxMaskApplierService {
254
254
  processedValue = this._stripToDecimal(processedValue);
255
255
  }
256
256
  const precision = this.getPrecision(maskExpression);
257
- const decimalMarker = Array.isArray(this.decimalMarker)
258
- ? this.thousandSeparator === MaskExpression.DOT
259
- ? MaskExpression.COMMA
260
- : MaskExpression.DOT
261
- : this.decimalMarker;
257
+ let decimalMarker = this.decimalMarker;
258
+ if (Array.isArray(this.decimalMarker)) {
259
+ const marker = this.decimalMarker.find((dm) => dm !== this.thousandSeparator);
260
+ decimalMarker = marker
261
+ ? marker
262
+ : this.actualValue.includes(this.decimalMarker[0])
263
+ ? this.decimalMarker[0]
264
+ : this.decimalMarker[1];
265
+ }
266
+ if (backspaced) {
267
+ const { decimalMarkerIndex, nonZeroIndex } = this._findFirstNonZeroAndDecimalIndex(processedValue, decimalMarker);
268
+ const zeroIndexMinus = processedValue[0] === MaskExpression.MINUS;
269
+ const zeroIndexNumberZero = processedValue[0] === MaskExpression.NUMBER_ZERO;
270
+ const zeroIndexDecimalMarker = processedValue[0] === decimalMarker;
271
+ const firstIndexDecimalMarker = processedValue[1] === decimalMarker;
272
+ if ((zeroIndexDecimalMarker && !nonZeroIndex) ||
273
+ (zeroIndexMinus && firstIndexDecimalMarker && !nonZeroIndex) ||
274
+ (zeroIndexNumberZero && !decimalMarkerIndex && !nonZeroIndex)) {
275
+ processedValue = MaskExpression.NUMBER_ZERO;
276
+ }
277
+ if (decimalMarkerIndex &&
278
+ nonZeroIndex &&
279
+ zeroIndexMinus &&
280
+ processedPosition === 1) {
281
+ if (decimalMarkerIndex < nonZeroIndex || decimalMarkerIndex > nonZeroIndex) {
282
+ processedValue = MaskExpression.MINUS + processedValue.slice(nonZeroIndex);
283
+ }
284
+ }
285
+ if (!decimalMarkerIndex && nonZeroIndex && processedValue.length > nonZeroIndex) {
286
+ processedValue = zeroIndexMinus
287
+ ? MaskExpression.MINUS + processedValue.slice(nonZeroIndex)
288
+ : processedValue.slice(nonZeroIndex);
289
+ }
290
+ if (decimalMarkerIndex && nonZeroIndex && processedPosition === 0) {
291
+ if (decimalMarkerIndex < nonZeroIndex) {
292
+ processedValue = processedValue.slice(decimalMarkerIndex - 1);
293
+ }
294
+ if (decimalMarkerIndex > nonZeroIndex) {
295
+ processedValue = processedValue.slice(nonZeroIndex);
296
+ }
297
+ }
298
+ }
262
299
  if (precision === 0) {
263
300
  processedValue = this.allowNegativeNumbers
264
301
  ? processedValue.length > 2 &&
@@ -294,7 +331,8 @@ class NgxMaskApplierService {
294
331
  }
295
332
  if (processedValue[0] === MaskExpression.NUMBER_ZERO &&
296
333
  processedValue[1] !== decimalMarker &&
297
- processedValue[1] !== this.thousandSeparator) {
334
+ processedValue[1] !== this.thousandSeparator &&
335
+ !backspaced) {
298
336
  processedValue =
299
337
  processedValue.length > 1
300
338
  ? processedValue.slice(0, 1) +
@@ -304,6 +342,7 @@ class NgxMaskApplierService {
304
342
  this.plusOnePosition = true;
305
343
  }
306
344
  if (this.allowNegativeNumbers &&
345
+ !backspaced &&
307
346
  processedValue[0] === MaskExpression.MINUS &&
308
347
  (processedValue[1] === decimalMarker ||
309
348
  processedValue[1] === MaskExpression.NUMBER_ZERO)) {
@@ -322,47 +361,6 @@ class NgxMaskApplierService {
322
361
  this.plusOnePosition = true;
323
362
  }
324
363
  }
325
- if (backspaced) {
326
- const inputValueAfterZero = processedValue.slice(this._findFirstNonZeroDigitIndex(processedValue), processedValue.length);
327
- const positionOfZeroOrDecimalMarker = processedValue[processedPosition] === MaskExpression.NUMBER_ZERO ||
328
- processedValue[processedPosition] === decimalMarker;
329
- const zeroIndexNumberZero = processedValue[0] === MaskExpression.NUMBER_ZERO;
330
- const firstIndexNumberZero = processedValue[1] === MaskExpression.NUMBER_ZERO;
331
- const zeroIndexMinus = processedValue[0] === MaskExpression.MINUS;
332
- const zeroIndexThousand = processedValue[0] === this.thousandSeparator;
333
- const firstIndexDecimalMarker = processedValue[1] === decimalMarker;
334
- const zeroIndexDecimalMarker = processedValue[0] === decimalMarker;
335
- const secondIndexDecimalMarker = processedValue[2] === decimalMarker;
336
- if (zeroIndexNumberZero && firstIndexDecimalMarker && processedPosition === 0) {
337
- return processedValue;
338
- }
339
- if (zeroIndexDecimalMarker && processedPosition === 0) {
340
- processedValue = inputValueAfterZero;
341
- }
342
- if (zeroIndexNumberZero &&
343
- firstIndexDecimalMarker &&
344
- positionOfZeroOrDecimalMarker &&
345
- processedPosition < 2) {
346
- processedValue = inputValueAfterZero;
347
- }
348
- if (zeroIndexMinus &&
349
- firstIndexNumberZero &&
350
- secondIndexDecimalMarker &&
351
- positionOfZeroOrDecimalMarker &&
352
- processedPosition < 3) {
353
- processedValue = MaskExpression.MINUS + inputValueAfterZero;
354
- }
355
- if (inputValueAfterZero !== MaskExpression.MINUS &&
356
- ((processedPosition === 0 && (zeroIndexNumberZero || zeroIndexThousand)) ||
357
- (this.allowNegativeNumbers &&
358
- processedPosition === 1 &&
359
- zeroIndexMinus &&
360
- !firstIndexNumberZero))) {
361
- processedValue = zeroIndexMinus
362
- ? MaskExpression.MINUS + inputValueAfterZero
363
- : inputValueAfterZero;
364
- }
365
- }
366
364
  const thousandSeparatorCharEscaped = this._charToRegExpExpression(this.thousandSeparator);
367
365
  let invalidChars = '@#!$%^&*()_+|~=`{}\\[\\]:\\s,\\.";<>?\\/'.replace(thousandSeparatorCharEscaped, '');
368
366
  if (Array.isArray(this.decimalMarker)) {
@@ -856,19 +854,30 @@ class NgxMaskApplierService {
856
854
  : `${emptyOrMinus}${integerString}${decimal}${decimalPart}`;
857
855
  }
858
856
  }
859
- _findFirstNonZeroDigitIndex(inputString) {
857
+ _findFirstNonZeroAndDecimalIndex(inputString, decimalMarker) {
858
+ let decimalMarkerIndex = null;
859
+ let nonZeroIndex = null;
860
860
  for (let i = 0; i < inputString.length; i++) {
861
861
  const char = inputString[i];
862
- if (char && char >= '1' && char <= '9') {
863
- return i;
862
+ if (char === decimalMarker && decimalMarkerIndex === null) {
863
+ decimalMarkerIndex = i;
864
+ }
865
+ if (char && char >= '1' && char <= '9' && nonZeroIndex === null) {
866
+ nonZeroIndex = i;
867
+ }
868
+ if (decimalMarkerIndex !== null && nonZeroIndex !== null) {
869
+ break;
864
870
  }
865
871
  }
866
- return -1;
872
+ return {
873
+ decimalMarkerIndex,
874
+ nonZeroIndex,
875
+ };
867
876
  }
868
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgxMaskApplierService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
869
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgxMaskApplierService });
877
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskApplierService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
878
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskApplierService });
870
879
  }
871
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgxMaskApplierService, decorators: [{
880
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskApplierService, decorators: [{
872
881
  type: Injectable
873
882
  }] });
874
883
 
@@ -1293,6 +1302,7 @@ class NgxMaskService extends NgxMaskApplierService {
1293
1302
  this.triggerOnMaskChange && this.maskChanged
1294
1303
  ? this.onChange(this.outputTransformFn(this._toNumber(this._checkSymbols(this._removeSuffix(this._removePrefix(inputValue))))))
1295
1304
  : '';
1305
+ this.writingValue = false;
1296
1306
  this.maskChanged = false;
1297
1307
  return;
1298
1308
  }
@@ -1458,10 +1468,10 @@ class NgxMaskService extends NgxMaskApplierService {
1458
1468
  currentLocaleDecimalMarker() {
1459
1469
  return (1.1).toLocaleString().substring(1, 2);
1460
1470
  }
1461
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgxMaskService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
1462
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgxMaskService });
1471
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
1472
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskService });
1463
1473
  }
1464
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgxMaskService, decorators: [{
1474
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskService, decorators: [{
1465
1475
  type: Injectable
1466
1476
  }] });
1467
1477
 
@@ -1581,6 +1591,27 @@ class NgxMaskDirective {
1581
1591
  }
1582
1592
  if (thousandSeparator) {
1583
1593
  this._maskService.thousandSeparator = thousandSeparator.currentValue;
1594
+ if (thousandSeparator.previousValue && thousandSeparator.currentValue) {
1595
+ const previousDecimalMarker = this._maskService.decimalMarker;
1596
+ if (thousandSeparator.currentValue === this._maskService.decimalMarker) {
1597
+ this._maskService.decimalMarker =
1598
+ thousandSeparator.currentValue === MaskExpression.COMMA
1599
+ ? MaskExpression.DOT
1600
+ : MaskExpression.COMMA;
1601
+ }
1602
+ if (this._maskService.dropSpecialCharacters === true) {
1603
+ this._maskService.specialCharacters = this._config.specialCharacters;
1604
+ }
1605
+ if (typeof previousDecimalMarker === 'string' &&
1606
+ typeof this._maskService.decimalMarker === 'string') {
1607
+ this._inputValue.set(this._inputValue()
1608
+ .split(thousandSeparator.previousValue)
1609
+ .join('')
1610
+ .replace(previousDecimalMarker, this._maskService.decimalMarker));
1611
+ this._maskService.actualValue = this._inputValue();
1612
+ }
1613
+ this._maskService.writingValue = true;
1614
+ }
1584
1615
  }
1585
1616
  if (decimalMarker) {
1586
1617
  this._maskService.decimalMarker = decimalMarker.currentValue;
@@ -2321,8 +2352,8 @@ class NgxMaskDirective {
2321
2352
  return uniqueCharacters.size === 1;
2322
2353
  });
2323
2354
  }
2324
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgxMaskDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
2325
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.0.3", type: NgxMaskDirective, isStandalone: true, selector: "input[mask], textarea[mask]", inputs: { mask: { classPropertyName: "mask", publicName: "mask", isSignal: true, isRequired: false, transformFunction: null }, specialCharacters: { classPropertyName: "specialCharacters", publicName: "specialCharacters", isSignal: true, isRequired: false, transformFunction: null }, patterns: { classPropertyName: "patterns", publicName: "patterns", isSignal: true, isRequired: false, transformFunction: null }, prefix: { classPropertyName: "prefix", publicName: "prefix", isSignal: true, isRequired: false, transformFunction: null }, suffix: { classPropertyName: "suffix", publicName: "suffix", isSignal: true, isRequired: false, transformFunction: null }, thousandSeparator: { classPropertyName: "thousandSeparator", publicName: "thousandSeparator", isSignal: true, isRequired: false, transformFunction: null }, decimalMarker: { classPropertyName: "decimalMarker", publicName: "decimalMarker", isSignal: true, isRequired: false, transformFunction: null }, dropSpecialCharacters: { classPropertyName: "dropSpecialCharacters", publicName: "dropSpecialCharacters", isSignal: true, isRequired: false, transformFunction: null }, hiddenInput: { classPropertyName: "hiddenInput", publicName: "hiddenInput", isSignal: true, isRequired: false, transformFunction: null }, showMaskTyped: { classPropertyName: "showMaskTyped", publicName: "showMaskTyped", isSignal: true, isRequired: false, transformFunction: null }, placeHolderCharacter: { classPropertyName: "placeHolderCharacter", publicName: "placeHolderCharacter", isSignal: true, isRequired: false, transformFunction: null }, shownMaskExpression: { classPropertyName: "shownMaskExpression", publicName: "shownMaskExpression", isSignal: true, isRequired: false, transformFunction: null }, clearIfNotMatch: { classPropertyName: "clearIfNotMatch", publicName: "clearIfNotMatch", isSignal: true, isRequired: false, transformFunction: null }, validation: { classPropertyName: "validation", publicName: "validation", isSignal: true, isRequired: false, transformFunction: null }, separatorLimit: { classPropertyName: "separatorLimit", publicName: "separatorLimit", isSignal: true, isRequired: false, transformFunction: null }, allowNegativeNumbers: { classPropertyName: "allowNegativeNumbers", publicName: "allowNegativeNumbers", isSignal: true, isRequired: false, transformFunction: null }, leadZeroDateTime: { classPropertyName: "leadZeroDateTime", publicName: "leadZeroDateTime", isSignal: true, isRequired: false, transformFunction: null }, leadZero: { classPropertyName: "leadZero", publicName: "leadZero", isSignal: true, isRequired: false, transformFunction: null }, triggerOnMaskChange: { classPropertyName: "triggerOnMaskChange", publicName: "triggerOnMaskChange", isSignal: true, isRequired: false, transformFunction: null }, apm: { classPropertyName: "apm", publicName: "apm", isSignal: true, isRequired: false, transformFunction: null }, inputTransformFn: { classPropertyName: "inputTransformFn", publicName: "inputTransformFn", isSignal: true, isRequired: false, transformFunction: null }, outputTransformFn: { classPropertyName: "outputTransformFn", publicName: "outputTransformFn", isSignal: true, isRequired: false, transformFunction: null }, keepCharacterPositions: { classPropertyName: "keepCharacterPositions", publicName: "keepCharacterPositions", isSignal: true, isRequired: false, transformFunction: null }, instantPrefix: { classPropertyName: "instantPrefix", publicName: "instantPrefix", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { maskFilled: "maskFilled" }, host: { listeners: { "paste": "onPaste()", "focus": "onFocus($event)", "ngModelChange": "onModelChange($event)", "input": "onInput($event)", "compositionstart": "onCompositionStart($event)", "compositionend": "onCompositionEnd($event)", "blur": "onBlur($event)", "click": "onClick($event)", "keydown": "onKeyDown($event)" } }, providers: [
2355
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
2356
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.0.4", type: NgxMaskDirective, isStandalone: true, selector: "input[mask], textarea[mask]", inputs: { mask: { classPropertyName: "mask", publicName: "mask", isSignal: true, isRequired: false, transformFunction: null }, specialCharacters: { classPropertyName: "specialCharacters", publicName: "specialCharacters", isSignal: true, isRequired: false, transformFunction: null }, patterns: { classPropertyName: "patterns", publicName: "patterns", isSignal: true, isRequired: false, transformFunction: null }, prefix: { classPropertyName: "prefix", publicName: "prefix", isSignal: true, isRequired: false, transformFunction: null }, suffix: { classPropertyName: "suffix", publicName: "suffix", isSignal: true, isRequired: false, transformFunction: null }, thousandSeparator: { classPropertyName: "thousandSeparator", publicName: "thousandSeparator", isSignal: true, isRequired: false, transformFunction: null }, decimalMarker: { classPropertyName: "decimalMarker", publicName: "decimalMarker", isSignal: true, isRequired: false, transformFunction: null }, dropSpecialCharacters: { classPropertyName: "dropSpecialCharacters", publicName: "dropSpecialCharacters", isSignal: true, isRequired: false, transformFunction: null }, hiddenInput: { classPropertyName: "hiddenInput", publicName: "hiddenInput", isSignal: true, isRequired: false, transformFunction: null }, showMaskTyped: { classPropertyName: "showMaskTyped", publicName: "showMaskTyped", isSignal: true, isRequired: false, transformFunction: null }, placeHolderCharacter: { classPropertyName: "placeHolderCharacter", publicName: "placeHolderCharacter", isSignal: true, isRequired: false, transformFunction: null }, shownMaskExpression: { classPropertyName: "shownMaskExpression", publicName: "shownMaskExpression", isSignal: true, isRequired: false, transformFunction: null }, clearIfNotMatch: { classPropertyName: "clearIfNotMatch", publicName: "clearIfNotMatch", isSignal: true, isRequired: false, transformFunction: null }, validation: { classPropertyName: "validation", publicName: "validation", isSignal: true, isRequired: false, transformFunction: null }, separatorLimit: { classPropertyName: "separatorLimit", publicName: "separatorLimit", isSignal: true, isRequired: false, transformFunction: null }, allowNegativeNumbers: { classPropertyName: "allowNegativeNumbers", publicName: "allowNegativeNumbers", isSignal: true, isRequired: false, transformFunction: null }, leadZeroDateTime: { classPropertyName: "leadZeroDateTime", publicName: "leadZeroDateTime", isSignal: true, isRequired: false, transformFunction: null }, leadZero: { classPropertyName: "leadZero", publicName: "leadZero", isSignal: true, isRequired: false, transformFunction: null }, triggerOnMaskChange: { classPropertyName: "triggerOnMaskChange", publicName: "triggerOnMaskChange", isSignal: true, isRequired: false, transformFunction: null }, apm: { classPropertyName: "apm", publicName: "apm", isSignal: true, isRequired: false, transformFunction: null }, inputTransformFn: { classPropertyName: "inputTransformFn", publicName: "inputTransformFn", isSignal: true, isRequired: false, transformFunction: null }, outputTransformFn: { classPropertyName: "outputTransformFn", publicName: "outputTransformFn", isSignal: true, isRequired: false, transformFunction: null }, keepCharacterPositions: { classPropertyName: "keepCharacterPositions", publicName: "keepCharacterPositions", isSignal: true, isRequired: false, transformFunction: null }, instantPrefix: { classPropertyName: "instantPrefix", publicName: "instantPrefix", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { maskFilled: "maskFilled" }, host: { listeners: { "paste": "onPaste()", "focus": "onFocus($event)", "ngModelChange": "onModelChange($event)", "input": "onInput($event)", "compositionstart": "onCompositionStart($event)", "compositionend": "onCompositionEnd($event)", "blur": "onBlur($event)", "click": "onClick($event)", "keydown": "onKeyDown($event)" } }, providers: [
2326
2357
  {
2327
2358
  provide: NG_VALUE_ACCESSOR,
2328
2359
  useExisting: NgxMaskDirective,
@@ -2336,7 +2367,7 @@ class NgxMaskDirective {
2336
2367
  NgxMaskService,
2337
2368
  ], exportAs: ["mask", "ngxMask"], usesOnChanges: true, ngImport: i0 });
2338
2369
  }
2339
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgxMaskDirective, decorators: [{
2370
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskDirective, decorators: [{
2340
2371
  type: Directive,
2341
2372
  args: [{
2342
2373
  selector: 'input[mask], textarea[mask]',
@@ -2469,10 +2500,10 @@ class NgxMaskPipe {
2469
2500
  });
2470
2501
  }
2471
2502
  }
2472
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgxMaskPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
2473
- static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.0.3", ngImport: i0, type: NgxMaskPipe, isStandalone: true, name: "mask" });
2503
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
2504
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskPipe, isStandalone: true, name: "mask" });
2474
2505
  }
2475
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgxMaskPipe, decorators: [{
2506
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskPipe, decorators: [{
2476
2507
  type: Pipe,
2477
2508
  args: [{
2478
2509
  name: 'mask',