ngx-mask 19.0.4 → 19.0.6

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,51 @@ 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
+ if (this.actualValue.includes(this.decimalMarker[0]) ||
260
+ this.actualValue.includes(this.decimalMarker[1])) {
261
+ decimalMarker = this.actualValue.includes(this.decimalMarker[0])
262
+ ? this.decimalMarker[0]
263
+ : this.decimalMarker[1];
264
+ }
265
+ else {
266
+ decimalMarker = this.decimalMarker.find((dm) => dm !== this.thousandSeparator);
267
+ }
268
+ }
269
+ if (backspaced) {
270
+ const { decimalMarkerIndex, nonZeroIndex } = this._findFirstNonZeroAndDecimalIndex(processedValue, decimalMarker);
271
+ const zeroIndexMinus = processedValue[0] === MaskExpression.MINUS;
272
+ const zeroIndexNumberZero = processedValue[0] === MaskExpression.NUMBER_ZERO;
273
+ const zeroIndexDecimalMarker = processedValue[0] === decimalMarker;
274
+ const firstIndexDecimalMarker = processedValue[1] === decimalMarker;
275
+ if ((zeroIndexDecimalMarker && !nonZeroIndex) ||
276
+ (zeroIndexMinus && firstIndexDecimalMarker && !nonZeroIndex) ||
277
+ (zeroIndexNumberZero && !decimalMarkerIndex && !nonZeroIndex)) {
278
+ processedValue = MaskExpression.NUMBER_ZERO;
279
+ }
280
+ if (decimalMarkerIndex &&
281
+ nonZeroIndex &&
282
+ zeroIndexMinus &&
283
+ processedPosition === 1) {
284
+ if (decimalMarkerIndex < nonZeroIndex || decimalMarkerIndex > nonZeroIndex) {
285
+ processedValue = MaskExpression.MINUS + processedValue.slice(nonZeroIndex);
286
+ }
287
+ }
288
+ if (!decimalMarkerIndex && nonZeroIndex && processedValue.length > nonZeroIndex) {
289
+ processedValue = zeroIndexMinus
290
+ ? MaskExpression.MINUS + processedValue.slice(nonZeroIndex)
291
+ : processedValue.slice(nonZeroIndex);
292
+ }
293
+ if (decimalMarkerIndex && nonZeroIndex && processedPosition === 0) {
294
+ if (decimalMarkerIndex < nonZeroIndex) {
295
+ processedValue = processedValue.slice(decimalMarkerIndex - 1);
296
+ }
297
+ if (decimalMarkerIndex > nonZeroIndex) {
298
+ processedValue = processedValue.slice(nonZeroIndex);
299
+ }
300
+ }
301
+ }
262
302
  if (precision === 0) {
263
303
  processedValue = this.allowNegativeNumbers
264
304
  ? processedValue.length > 2 &&
@@ -294,7 +334,8 @@ class NgxMaskApplierService {
294
334
  }
295
335
  if (processedValue[0] === MaskExpression.NUMBER_ZERO &&
296
336
  processedValue[1] !== decimalMarker &&
297
- processedValue[1] !== this.thousandSeparator) {
337
+ processedValue[1] !== this.thousandSeparator &&
338
+ !backspaced) {
298
339
  processedValue =
299
340
  processedValue.length > 1
300
341
  ? processedValue.slice(0, 1) +
@@ -304,6 +345,7 @@ class NgxMaskApplierService {
304
345
  this.plusOnePosition = true;
305
346
  }
306
347
  if (this.allowNegativeNumbers &&
348
+ !backspaced &&
307
349
  processedValue[0] === MaskExpression.MINUS &&
308
350
  (processedValue[1] === decimalMarker ||
309
351
  processedValue[1] === MaskExpression.NUMBER_ZERO)) {
@@ -322,47 +364,6 @@ class NgxMaskApplierService {
322
364
  this.plusOnePosition = true;
323
365
  }
324
366
  }
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
367
  const thousandSeparatorCharEscaped = this._charToRegExpExpression(this.thousandSeparator);
367
368
  let invalidChars = '@#!$%^&*()_+|~=`{}\\[\\]:\\s,\\.";<>?\\/'.replace(thousandSeparatorCharEscaped, '');
368
369
  if (Array.isArray(this.decimalMarker)) {
@@ -856,19 +857,30 @@ class NgxMaskApplierService {
856
857
  : `${emptyOrMinus}${integerString}${decimal}${decimalPart}`;
857
858
  }
858
859
  }
859
- _findFirstNonZeroDigitIndex(inputString) {
860
+ _findFirstNonZeroAndDecimalIndex(inputString, decimalMarker) {
861
+ let decimalMarkerIndex = null;
862
+ let nonZeroIndex = null;
860
863
  for (let i = 0; i < inputString.length; i++) {
861
864
  const char = inputString[i];
862
- if (char && char >= '1' && char <= '9') {
863
- return i;
865
+ if (char === decimalMarker && decimalMarkerIndex === null) {
866
+ decimalMarkerIndex = i;
867
+ }
868
+ if (char && char >= '1' && char <= '9' && nonZeroIndex === null) {
869
+ nonZeroIndex = i;
870
+ }
871
+ if (decimalMarkerIndex !== null && nonZeroIndex !== null) {
872
+ break;
864
873
  }
865
874
  }
866
- return -1;
875
+ return {
876
+ decimalMarkerIndex,
877
+ nonZeroIndex,
878
+ };
867
879
  }
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 });
880
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskApplierService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
881
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskApplierService });
870
882
  }
871
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgxMaskApplierService, decorators: [{
883
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskApplierService, decorators: [{
872
884
  type: Injectable
873
885
  }] });
874
886
 
@@ -1293,6 +1305,7 @@ class NgxMaskService extends NgxMaskApplierService {
1293
1305
  this.triggerOnMaskChange && this.maskChanged
1294
1306
  ? this.onChange(this.outputTransformFn(this._toNumber(this._checkSymbols(this._removeSuffix(this._removePrefix(inputValue))))))
1295
1307
  : '';
1308
+ this.writingValue = false;
1296
1309
  this.maskChanged = false;
1297
1310
  return;
1298
1311
  }
@@ -1458,10 +1471,10 @@ class NgxMaskService extends NgxMaskApplierService {
1458
1471
  currentLocaleDecimalMarker() {
1459
1472
  return (1.1).toLocaleString().substring(1, 2);
1460
1473
  }
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 });
1474
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
1475
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskService });
1463
1476
  }
1464
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgxMaskService, decorators: [{
1477
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskService, decorators: [{
1465
1478
  type: Injectable
1466
1479
  }] });
1467
1480
 
@@ -1581,6 +1594,27 @@ class NgxMaskDirective {
1581
1594
  }
1582
1595
  if (thousandSeparator) {
1583
1596
  this._maskService.thousandSeparator = thousandSeparator.currentValue;
1597
+ if (thousandSeparator.previousValue && thousandSeparator.currentValue) {
1598
+ const previousDecimalMarker = this._maskService.decimalMarker;
1599
+ if (thousandSeparator.currentValue === this._maskService.decimalMarker) {
1600
+ this._maskService.decimalMarker =
1601
+ thousandSeparator.currentValue === MaskExpression.COMMA
1602
+ ? MaskExpression.DOT
1603
+ : MaskExpression.COMMA;
1604
+ }
1605
+ if (this._maskService.dropSpecialCharacters === true) {
1606
+ this._maskService.specialCharacters = this._config.specialCharacters;
1607
+ }
1608
+ if (typeof previousDecimalMarker === 'string' &&
1609
+ typeof this._maskService.decimalMarker === 'string') {
1610
+ this._inputValue.set(this._inputValue()
1611
+ .split(thousandSeparator.previousValue)
1612
+ .join('')
1613
+ .replace(previousDecimalMarker, this._maskService.decimalMarker));
1614
+ this._maskService.actualValue = this._inputValue();
1615
+ }
1616
+ this._maskService.writingValue = true;
1617
+ }
1584
1618
  }
1585
1619
  if (decimalMarker) {
1586
1620
  this._maskService.decimalMarker = decimalMarker.currentValue;
@@ -2321,8 +2355,8 @@ class NgxMaskDirective {
2321
2355
  return uniqueCharacters.size === 1;
2322
2356
  });
2323
2357
  }
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: [
2358
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
2359
+ 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
2360
  {
2327
2361
  provide: NG_VALUE_ACCESSOR,
2328
2362
  useExisting: NgxMaskDirective,
@@ -2336,7 +2370,7 @@ class NgxMaskDirective {
2336
2370
  NgxMaskService,
2337
2371
  ], exportAs: ["mask", "ngxMask"], usesOnChanges: true, ngImport: i0 });
2338
2372
  }
2339
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgxMaskDirective, decorators: [{
2373
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskDirective, decorators: [{
2340
2374
  type: Directive,
2341
2375
  args: [{
2342
2376
  selector: 'input[mask], textarea[mask]',
@@ -2469,10 +2503,10 @@ class NgxMaskPipe {
2469
2503
  });
2470
2504
  }
2471
2505
  }
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" });
2506
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
2507
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskPipe, isStandalone: true, name: "mask" });
2474
2508
  }
2475
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgxMaskPipe, decorators: [{
2509
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxMaskPipe, decorators: [{
2476
2510
  type: Pipe,
2477
2511
  args: [{
2478
2512
  name: 'mask',