matcha-components 20.98.0 → 20.100.0

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.
@@ -6215,6 +6215,35 @@ class MatchaMaskService extends MatchaMaskApplierService {
6215
6215
  : (v) => v;
6216
6216
  this.writingValue = false;
6217
6217
  this.maskChanged = false;
6218
+ // Para máscaras de separador (currency), fazer conversão direta para número
6219
+ if (this.maskExpression.startsWith("separator" /* MaskExpression.SEPARATOR */) && this.dropSpecialCharacters) {
6220
+ // Remover prefixo e sufixo
6221
+ let cleanValue = inputValue;
6222
+ if (this.prefix) {
6223
+ cleanValue = cleanValue.replace(this.prefix, '');
6224
+ }
6225
+ if (this.suffix) {
6226
+ cleanValue = cleanValue.replace(this.suffix, '');
6227
+ }
6228
+ // Remover separador de milhares
6229
+ if (this.thousandSeparator) {
6230
+ cleanValue = cleanValue.split(this.thousandSeparator).join('');
6231
+ }
6232
+ // Converter decimal marker para ponto
6233
+ const markers = Array.isArray(this.decimalMarker)
6234
+ ? this.decimalMarker
6235
+ : [this.decimalMarker];
6236
+ for (const marker of markers) {
6237
+ if (marker && marker !== '.') {
6238
+ cleanValue = cleanValue.replace(marker, '.');
6239
+ }
6240
+ }
6241
+ // Converter para número
6242
+ const numValue = parseFloat(cleanValue);
6243
+ const finalValue = isNaN(numValue) ? 0 : numValue;
6244
+ this.onChange(outputTransformFn(finalValue));
6245
+ return;
6246
+ }
6218
6247
  // Para máscaras de separador, garantir que isNumberValue é true
6219
6248
  // Isso assegura a conversão correta para número
6220
6249
  if (this.maskExpression.startsWith("separator" /* MaskExpression.SEPARATOR */)) {
@@ -6795,14 +6824,56 @@ class MatchaMaskCompatibleDirective {
6795
6824
  else {
6796
6825
  inputValue = String(value);
6797
6826
  }
6798
- // Se a máscara usa separator e o valor tem ponto decimal, converter para vírgula
6799
- // Isso é útil quando valores numéricos vêm do backend (ex: 10.5 -> 10,50)
6800
- if (this._mask && this._mask.trim().startsWith('separator.') && inputValue.includes('.')) {
6801
- // Converter ponto para vírgula se o decimalMarker é vírgula
6827
+ // Para máscaras de separador (currency), formatar o valor do backend corretamente
6828
+ // Exemplo: backend envia 10.5, devemos exibir "R$ 10,50"
6829
+ if (this._mask && this._mask.trim().startsWith('separator.')) {
6830
+ const precision = this._maskService.getPrecision(this._mask);
6802
6831
  const decimalMarker = this._maskService.decimalMarker;
6803
- if (decimalMarker === ',' || (Array.isArray(decimalMarker) && decimalMarker.includes(','))) {
6804
- inputValue = inputValue.replace('.', ',');
6832
+ const actualDecimalMarker = decimalMarker === ',' ||
6833
+ (Array.isArray(decimalMarker) && decimalMarker.includes(',')) ? ',' : '.';
6834
+ // Se o valor tem ponto decimal (formato backend), converter para formato de exibição
6835
+ if (inputValue.includes('.')) {
6836
+ // Separar parte inteira e decimal
6837
+ const parts = inputValue.split('.');
6838
+ const integerPart = parts[0] || '0';
6839
+ let decimalPart = parts[1] || '';
6840
+ // Ajustar casas decimais conforme precisão
6841
+ if (precision > 0) {
6842
+ decimalPart = decimalPart.padEnd(precision, '0').substring(0, precision);
6843
+ }
6844
+ // Aplicar separador de milhares na parte inteira
6845
+ let formattedInteger = integerPart;
6846
+ const rgx = /(\d+)(\d{3})/;
6847
+ while (this._maskService.thousandSeparator && rgx.test(formattedInteger)) {
6848
+ formattedInteger = formattedInteger.replace(rgx, '$1' + this._maskService.thousandSeparator + '$2');
6849
+ }
6850
+ // Montar valor formatado
6851
+ inputValue = precision > 0
6852
+ ? formattedInteger + actualDecimalMarker + decimalPart
6853
+ : formattedInteger;
6854
+ }
6855
+ else if (!inputValue.includes(actualDecimalMarker) && precision > 0) {
6856
+ // Valor sem casas decimais (ex: "10"), adicionar zeros
6857
+ let formattedInteger = inputValue;
6858
+ const rgx = /(\d+)(\d{3})/;
6859
+ while (this._maskService.thousandSeparator && rgx.test(formattedInteger)) {
6860
+ formattedInteger = formattedInteger.replace(rgx, '$1' + this._maskService.thousandSeparator + '$2');
6861
+ }
6862
+ inputValue = formattedInteger + actualDecimalMarker + '0'.repeat(precision);
6863
+ }
6864
+ // Adicionar prefixo se configurado
6865
+ if (this._maskService.prefix && !inputValue.startsWith(this._maskService.prefix)) {
6866
+ inputValue = this._maskService.prefix + inputValue;
6805
6867
  }
6868
+ // Adicionar sufixo se configurado
6869
+ if (this._maskService.suffix && !inputValue.endsWith(this._maskService.suffix)) {
6870
+ inputValue = inputValue + this._maskService.suffix;
6871
+ }
6872
+ this._inputValue = inputValue;
6873
+ this._maskService.currentValue = inputValue;
6874
+ this._maskService.previousValue = inputValue;
6875
+ this._maskService.writingValue = false;
6876
+ return;
6806
6877
  }
6807
6878
  this._inputValue = inputValue;
6808
6879
  // Aplicar máscara se definida