ngx-currency
Advanced tools
Comparing version 2.0.2 to 2.2.0
@@ -1,9 +0,763 @@ | ||
/** | ||
* ngx-currency - A very simple currency mask directive that allows using a number attribute with the ngModel. | ||
* @version v2.0.2 | ||
* @author Neri Bez Fontana | ||
* @link https://github.com/nbfontana/ngx-currency#readme | ||
* @license MIT | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@angular/core"),require("@angular/forms"),require("@angular/common")):"function"==typeof define&&define.amd?define(["@angular/core","@angular/forms","@angular/common"],t):"object"==typeof exports?exports.ngxBr=t(require("@angular/core"),require("@angular/forms"),require("@angular/common")):e.ngxBr=t(e.ng.core,e.ng.forms,e.ng.common)}(window,(function(e,t,n){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=4)}([function(t,n){t.exports=e},function(e,t,n){"use strict";var i=this&&this.__decorate||function(e,t,n,i){var r,o=arguments.length,s=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,i);else for(var u=e.length-1;u>=0;u--)(r=e[u])&&(s=(o<3?r(s):o>3?r(t,n,s):r(t,n))||s);return o>3&&s&&Object.defineProperty(t,n,s),s},r=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},o=this&&this.__param||function(e,t){return function(n,i){t(n,i,e)}};Object.defineProperty(t,"__esModule",{value:!0});var s=n(0),u=n(2),a=n(3),l=n(5);t.CURRENCYMASKDIRECTIVE_VALUE_ACCESSOR={provide:u.NG_VALUE_ACCESSOR,useExisting:s.forwardRef((function(){return p})),multi:!0};var p=function(){function e(e,t,n){this.currencyMaskConfig=e,this.elementRef=t,this.keyValueDiffers=n,this.options={},this.optionsTemplate={align:"right",allowNegative:!0,allowZero:!0,decimal:".",precision:2,prefix:"$ ",suffix:"",thousands:",",nullable:!1},e&&(this.optionsTemplate=e),this.keyValueDiffer=n.find({}).create()}return e.prototype.ngAfterViewInit=function(){this.elementRef.nativeElement.style.textAlign=this.options&&this.options.align?this.options.align:this.optionsTemplate.align},e.prototype.ngDoCheck=function(){this.keyValueDiffer.diff(this.options)&&(this.elementRef.nativeElement.style.textAlign=this.options.align?this.options.align:this.optionsTemplate.align,this.inputHandler.updateOptions(Object.assign({},this.optionsTemplate,this.options)))},e.prototype.ngOnInit=function(){this.inputHandler=new l.InputHandler(this.elementRef.nativeElement,Object.assign({},this.optionsTemplate,this.options))},e.prototype.handleBlur=function(e){this.inputHandler.getOnModelTouched().apply(e)},e.prototype.handleCut=function(e){this.isChromeAndroid()||this.inputHandler.handleCut(e)},e.prototype.handleInput=function(e){this.isChromeAndroid()&&this.inputHandler.handleInput(e)},e.prototype.handleKeydown=function(e){this.isChromeAndroid()||this.inputHandler.handleKeydown(e)},e.prototype.handleKeypress=function(e){this.isChromeAndroid()||this.inputHandler.handleKeypress(e)},e.prototype.handlePaste=function(e){this.isChromeAndroid()||this.inputHandler.handlePaste(e)},e.prototype.isChromeAndroid=function(){return/chrome/i.test(navigator.userAgent)&&/android/i.test(navigator.userAgent)},e.prototype.registerOnChange=function(e){this.inputHandler.setOnModelChange(e)},e.prototype.registerOnTouched=function(e){this.inputHandler.setOnModelTouched(e)},e.prototype.setDisabledState=function(e){this.elementRef.nativeElement.disabled=e},e.prototype.writeValue=function(e){this.inputHandler.setValue(e)},i([s.Input(),r("design:type",Object)],e.prototype,"options",void 0),i([s.HostListener("blur",["$event"]),r("design:type",Function),r("design:paramtypes",[Object]),r("design:returntype",void 0)],e.prototype,"handleBlur",null),i([s.HostListener("cut",["$event"]),r("design:type",Function),r("design:paramtypes",[Object]),r("design:returntype",void 0)],e.prototype,"handleCut",null),i([s.HostListener("input",["$event"]),r("design:type",Function),r("design:paramtypes",[Object]),r("design:returntype",void 0)],e.prototype,"handleInput",null),i([s.HostListener("keydown",["$event"]),r("design:type",Function),r("design:paramtypes",[Object]),r("design:returntype",void 0)],e.prototype,"handleKeydown",null),i([s.HostListener("keypress",["$event"]),r("design:type",Function),r("design:paramtypes",[Object]),r("design:returntype",void 0)],e.prototype,"handleKeypress",null),i([s.HostListener("paste",["$event"]),r("design:type",Function),r("design:paramtypes",[Object]),r("design:returntype",void 0)],e.prototype,"handlePaste",null),e=i([s.Directive({selector:"[currencyMask]",providers:[t.CURRENCYMASKDIRECTIVE_VALUE_ACCESSOR]}),o(0,s.Optional()),o(0,s.Inject(a.CURRENCY_MASK_CONFIG)),r("design:paramtypes",[Object,s.ElementRef,s.KeyValueDiffers])],e)}();t.CurrencyMaskDirective=p},function(e,n){e.exports=t},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=n(0);t.CURRENCY_MASK_CONFIG=new i.InjectionToken("currency.mask.config")},function(e,t,n){"use strict";function i(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}Object.defineProperty(t,"__esModule",{value:!0}),i(n(1)),i(n(8))},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=n(6),r=function(){function e(e,t){this.inputService=new i.InputService(e,t)}return e.prototype.handleCut=function(e){var t=this;setTimeout((function(){t.inputService.updateFieldValue(),t.setValue(t.inputService.value),t.onModelChange(t.inputService.value)}),0)},e.prototype.handleInput=function(e){var t=this.inputService.rawValue.charCodeAt(this.inputService.rawValue.length-1),n=this.inputService.rawValue.length,i=this.inputService.inputSelection.selectionEnd,r=this.inputService.storedRawValue.length;if(this.inputService.rawValue=this.inputService.storedRawValue,n==i&&1==Math.abs(n-r)){if(n<r&&this.inputService.removeNumber(8),n>r)switch(t){case 43:this.inputService.changeToPositive();break;case 45:this.inputService.changeToNegative();break;default:if(!this.inputService.canInputMoreNumbers)return;this.inputService.addNumber(t)}this.setCursorPosition(e),this.onModelChange(this.inputService.value)}else this.setCursorPosition(e)},e.prototype.handleKeydown=function(e){var t=e.which||e.charCode||e.keyCode;if(8==t||46==t||63272==t){e.preventDefault();var n=Math.abs(this.inputService.inputSelection.selectionEnd-this.inputService.inputSelection.selectionStart);0==n&&(this.inputService.removeNumber(t),this.onModelChange(this.inputService.value)),n>=this.inputService.rawValue.length-this.inputService.prefixLength()&&this.clearValue()}},e.prototype.clearValue=function(){this.setValue(this.inputService.isNullable()?null:0),this.onModelChange(this.inputService.value)},e.prototype.handleKeypress=function(e){var t=e.which||e.charCode||e.keyCode;if(97!==t||!e.ctrlKey){switch(t){case void 0:case 9:case 13:case 37:case 39:return;case 43:this.inputService.changeToPositive();break;case 45:this.inputService.changeToNegative();break;default:if(this.inputService.canInputMoreNumbers)Math.abs(this.inputService.inputSelection.selectionEnd-this.inputService.inputSelection.selectionStart)==this.inputService.rawValue.length&&this.setValue(0),this.inputService.addNumber(t)}e.preventDefault(),this.onModelChange(this.inputService.value)}},e.prototype.handlePaste=function(e){var t=this;setTimeout((function(){t.inputService.updateFieldValue(),t.setValue(t.inputService.value),t.onModelChange(t.inputService.value)}),1)},e.prototype.updateOptions=function(e){this.inputService.updateOptions(e)},e.prototype.getOnModelChange=function(){return this.onModelChange},e.prototype.setOnModelChange=function(e){this.onModelChange=e},e.prototype.getOnModelTouched=function(){return this.onModelTouched},e.prototype.setOnModelTouched=function(e){this.onModelTouched=e},e.prototype.setValue=function(e){this.inputService.value=e},e.prototype.setCursorPosition=function(e){setTimeout((function(){e.target.setSelectionRange(e.target.value.length,e.target.value.length)}),0)},e}();t.InputHandler=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=n(7),r=function(){function e(e,t){this.htmlInputElement=e,this.options=t,this.PER_AR_NUMBER=new Map,this.inputManager=new i.InputManager(e),this.initialize()}return e.prototype.initialize=function(){this.PER_AR_NUMBER.set("۰","0"),this.PER_AR_NUMBER.set("۱","1"),this.PER_AR_NUMBER.set("۲","2"),this.PER_AR_NUMBER.set("۳","3"),this.PER_AR_NUMBER.set("۴","4"),this.PER_AR_NUMBER.set("۵","5"),this.PER_AR_NUMBER.set("۶","6"),this.PER_AR_NUMBER.set("۷","7"),this.PER_AR_NUMBER.set("۸","8"),this.PER_AR_NUMBER.set("۹","9"),this.PER_AR_NUMBER.set("٠","0"),this.PER_AR_NUMBER.set("١","1"),this.PER_AR_NUMBER.set("٢","2"),this.PER_AR_NUMBER.set("٣","3"),this.PER_AR_NUMBER.set("٤","4"),this.PER_AR_NUMBER.set("٥","5"),this.PER_AR_NUMBER.set("٦","6"),this.PER_AR_NUMBER.set("٧","7"),this.PER_AR_NUMBER.set("٨","8"),this.PER_AR_NUMBER.set("٩","9")},e.prototype.addNumber=function(e){this.rawValue||(this.rawValue=this.applyMask(!1,"0"));var t=String.fromCharCode(e),n=this.inputSelection.selectionStart,i=this.inputSelection.selectionEnd;this.rawValue=this.rawValue.substring(0,n)+t+this.rawValue.substring(i,this.rawValue.length),this.updateFieldValue(n+1)},e.prototype.applyMask=function(e,t){var n=this.options,i=n.allowNegative,r=n.decimal,o=n.precision,s=n.prefix,u=n.suffix,a=n.thousands,l=(n.nullable,(t=e?new Number(t).toFixed(o):t).replace(/[^0-9\u0660-\u0669\u06F0-\u06F9]/g,""));if(!l)return"";var p=l.slice(0,l.length-o).replace(/^\u0660*/g,"").replace(/^\u06F0*/g,"").replace(/^0*/g,"").replace(/\B(?=([0-9\u0660-\u0669\u06F0-\u06F9]{3})+(?![0-9\u0660-\u0669\u06F0-\u06F9]))/g,a);a&&p.startsWith(a)&&(p=p.substring(1)),""==p&&(p="0");var c=p,h=l.slice(l.length-o);o>0&&("0"==c&&h.length<o?c+=r+"0".repeat(o-1)+h:c+=r+h);var d=0==parseInt(p)&&(0==parseInt(h)||""==h);return(t.indexOf("-")>-1&&i&&!d?"-":"")+s+c+u},e.prototype.clearMask=function(e){if(this.isNullable()&&""===e)return null;var t=(e||"0").replace(this.options.prefix,"").replace(this.options.suffix,"");return this.options.thousands&&(t=t.replace(new RegExp("\\"+this.options.thousands,"g"),"")),this.options.decimal&&(t=t.replace(this.options.decimal,".")),this.PER_AR_NUMBER.forEach((function(e,n){var i=new RegExp(n,"g");t=t.replace(i,e)})),parseFloat(t)},e.prototype.changeToNegative=function(){this.options.allowNegative&&""!=this.rawValue&&"-"!=this.rawValue.charAt(0)&&0!=this.value&&(this.rawValue="-"+this.rawValue)},e.prototype.changeToPositive=function(){this.rawValue=this.rawValue.replace("-","")},e.prototype.removeNumber=function(e){if(this.isNullable()&&0==this.value)this.rawValue=null;else{var t=this.inputSelection.selectionEnd,n=this.inputSelection.selectionStart;n>this.rawValue.length-this.options.suffix.length&&(t=this.rawValue.length-this.options.suffix.length,n=this.rawValue.length-this.options.suffix.length);var i=this.rawValue.substr(n-1,1).match(/\d/)?0:-1;(8!=e||n-1!=0||this.rawValue.substr(n,1).match(/\d/))&&(46!=e&&63272!=e||0!==n||this.rawValue.substr(n+1,1).match(/\d/))||(i=1),t=46==e||63272==e?t+1:t,n=8==e?n-1:n,this.rawValue=this.rawValue.substring(0,n)+this.rawValue.substring(t,this.rawValue.length),this.updateFieldValue(n+i)}},e.prototype.updateFieldValue=function(e){var t=this.applyMask(!1,this.rawValue||"");e=null==e?this.rawValue.length:e,this.inputManager.updateValueAndCursor(t,this.rawValue.length,e)},e.prototype.updateOptions=function(e){var t=this.value;this.options=e,this.value=t},e.prototype.prefixLength=function(){return this.options.prefix.length},e.prototype.isNullable=function(){return this.options.nullable},Object.defineProperty(e.prototype,"canInputMoreNumbers",{get:function(){return this.inputManager.canInputMoreNumbers},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"inputSelection",{get:function(){return this.inputManager.inputSelection},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rawValue",{get:function(){return this.inputManager.rawValue},set:function(e){this.inputManager.rawValue=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"storedRawValue",{get:function(){return this.inputManager.storedRawValue},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.clearMask(this.rawValue)},set:function(e){this.rawValue=this.applyMask(!0,""+e)},enumerable:!0,configurable:!0}),e}();t.InputService=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e){this.htmlInputElement=e}return e.prototype.setCursorAt=function(e){if(this.htmlInputElement.setSelectionRange)this.htmlInputElement.focus(),this.htmlInputElement.setSelectionRange(e,e);else if(this.htmlInputElement.createTextRange){var t=this.htmlInputElement.createTextRange();t.collapse(!0),t.moveEnd("character",e),t.moveStart("character",e),t.select()}},e.prototype.updateValueAndCursor=function(e,t,n){this.rawValue=e,n-=t-e.length,this.setCursorAt(n)},Object.defineProperty(e.prototype,"canInputMoreNumbers",{get:function(){var e=!(this.rawValue.length>=this.htmlInputElement.maxLength&&this.htmlInputElement.maxLength>=0),t=this.inputSelection.selectionStart,n=this.inputSelection.selectionEnd,i=!(t==n||!this.htmlInputElement.value.substring(t,n).match(/[^0-9\u0660-\u0669\u06F0-\u06F9]/)),r="0"==this.htmlInputElement.value.substring(0,1);return e||i||r},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"inputSelection",{get:function(){var e=0,t=0;if("number"==typeof this.htmlInputElement.selectionStart&&"number"==typeof this.htmlInputElement.selectionEnd)e=this.htmlInputElement.selectionStart,t=this.htmlInputElement.selectionEnd;else{var n=document.selection.createRange();if(n&&n.parentElement()==this.htmlInputElement){var i=this.htmlInputElement.value.length,r=this.htmlInputElement.value.replace(/\r\n/g,"\n"),o=this.htmlInputElement.createTextRange();o.moveToBookmark(n.getBookmark());var s=this.htmlInputElement.createTextRange();s.collapse(!1),o.compareEndPoints("StartToEnd",s)>-1?e=t=i:(e=-o.moveStart("character",-i),e+=r.slice(0,e).split("\n").length-1,o.compareEndPoints("EndToEnd",s)>-1?t=i:(t=-o.moveEnd("character",-i),t+=r.slice(0,t).split("\n").length-1))}}return{selectionStart:e,selectionEnd:t}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rawValue",{get:function(){return this.htmlInputElement&&this.htmlInputElement.value},set:function(e){this._storedRawValue=e,this.htmlInputElement&&(this.htmlInputElement.value=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"storedRawValue",{get:function(){return this._storedRawValue},enumerable:!0,configurable:!0}),e}();t.InputManager=i},function(e,t,n){"use strict";var i=this&&this.__decorate||function(e,t,n,i){var r,o=arguments.length,s=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,i);else for(var u=e.length-1;u>=0;u--)(r=e[u])&&(s=(o<3?r(s):o>3?r(t,n,s):r(t,n))||s);return o>3&&s&&Object.defineProperty(t,n,s),s};Object.defineProperty(t,"__esModule",{value:!0});var r=n(0),o=n(9),s=n(2),u=n(1),a=n(3),l=function(){function e(){}var t;return t=e,e.forRoot=function(e){return{ngModule:t,providers:[{provide:a.CURRENCY_MASK_CONFIG,useValue:e}]}},e=t=i([r.NgModule({imports:[o.CommonModule,s.FormsModule],declarations:[u.CurrencyMaskDirective],exports:[u.CurrencyMaskDirective]})],e)}();t.NgxCurrencyModule=l},function(e,t){e.exports=n}])})); | ||
//# sourceMappingURL=ngx-currency.umd.js.map | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms'), require('@angular/common')) : | ||
typeof define === 'function' && define.amd ? define('ngx-currency', ['exports', '@angular/core', '@angular/forms', '@angular/common'], factory) : | ||
(global = global || self, factory(global['ngx-currency'] = {}, global.ng.core, global.ng.forms, global.ng.common)); | ||
}(this, (function (exports, core, forms, common) { 'use strict'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = function(d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
function __extends(d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __rest(s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
} | ||
function __decorate(decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
} | ||
function __param(paramIndex, decorator) { | ||
return function (target, key) { decorator(target, key, paramIndex); } | ||
} | ||
function __metadata(metadataKey, metadataValue) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); | ||
} | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
} | ||
function __exportStar(m, exports) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
function __values(o) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; | ||
if (m) return m.call(o); | ||
return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
} | ||
function __read(o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
} | ||
function __spread() { | ||
for (var ar = [], i = 0; i < arguments.length; i++) | ||
ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
} | ||
function __spreadArrays() { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
function __await(v) { | ||
return this instanceof __await ? (this.v = v, this) : new __await(v); | ||
} | ||
function __asyncGenerator(thisArg, _arguments, generator) { | ||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
var g = generator.apply(thisArg, _arguments || []), i, q = []; | ||
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; | ||
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } | ||
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } | ||
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } | ||
function fulfill(value) { resume("next", value); } | ||
function reject(value) { resume("throw", value); } | ||
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } | ||
} | ||
function __asyncDelegator(o) { | ||
var i, p; | ||
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; | ||
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } | ||
} | ||
function __asyncValues(o) { | ||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
var m = o[Symbol.asyncIterator], i; | ||
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); | ||
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } | ||
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } | ||
} | ||
function __makeTemplateObject(cooked, raw) { | ||
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } | ||
return cooked; | ||
}; | ||
function __importStar(mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result.default = mod; | ||
return result; | ||
} | ||
function __importDefault(mod) { | ||
return (mod && mod.__esModule) ? mod : { default: mod }; | ||
} | ||
var CURRENCY_MASK_CONFIG = new core.InjectionToken("currency.mask.config"); | ||
var InputManager = /** @class */ (function () { | ||
function InputManager(htmlInputElement) { | ||
this.htmlInputElement = htmlInputElement; | ||
} | ||
InputManager.prototype.setCursorAt = function (position) { | ||
if (this.htmlInputElement.setSelectionRange) { | ||
this.htmlInputElement.focus(); | ||
this.htmlInputElement.setSelectionRange(position, position); | ||
} | ||
else if (this.htmlInputElement.createTextRange) { | ||
var textRange = this.htmlInputElement.createTextRange(); | ||
textRange.collapse(true); | ||
textRange.moveEnd("character", position); | ||
textRange.moveStart("character", position); | ||
textRange.select(); | ||
} | ||
}; | ||
InputManager.prototype.updateValueAndCursor = function (newRawValue, oldLength, selectionStart) { | ||
this.rawValue = newRawValue; | ||
var newLength = newRawValue.length; | ||
selectionStart = selectionStart - (oldLength - newLength); | ||
this.setCursorAt(selectionStart); | ||
}; | ||
Object.defineProperty(InputManager.prototype, "canInputMoreNumbers", { | ||
get: function () { | ||
var haventReachedMaxLength = !(this.rawValue.length >= this.htmlInputElement.maxLength && this.htmlInputElement.maxLength >= 0); | ||
var selectionStart = this.inputSelection.selectionStart; | ||
var selectionEnd = this.inputSelection.selectionEnd; | ||
var haveNumberSelected = !!(selectionStart != selectionEnd && | ||
this.htmlInputElement.value.substring(selectionStart, selectionEnd).match(/[^0-9\u0660-\u0669\u06F0-\u06F9]/)); | ||
var startWithZero = (this.htmlInputElement.value.substring(0, 1) == "0"); | ||
return haventReachedMaxLength || haveNumberSelected || startWithZero; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(InputManager.prototype, "inputSelection", { | ||
get: function () { | ||
var selectionStart = 0; | ||
var selectionEnd = 0; | ||
if (typeof this.htmlInputElement.selectionStart == "number" && typeof this.htmlInputElement.selectionEnd == "number") { | ||
selectionStart = this.htmlInputElement.selectionStart; | ||
selectionEnd = this.htmlInputElement.selectionEnd; | ||
} | ||
else { | ||
var range = document.selection.createRange(); | ||
if (range && range.parentElement() == this.htmlInputElement) { | ||
var lenght = this.htmlInputElement.value.length; | ||
var normalizedValue = this.htmlInputElement.value.replace(/\r\n/g, "\n"); | ||
var startRange = this.htmlInputElement.createTextRange(); | ||
startRange.moveToBookmark(range.getBookmark()); | ||
var endRange = this.htmlInputElement.createTextRange(); | ||
endRange.collapse(false); | ||
if (startRange.compareEndPoints("StartToEnd", endRange) > -1) { | ||
selectionStart = selectionEnd = lenght; | ||
} | ||
else { | ||
selectionStart = -startRange.moveStart("character", -lenght); | ||
selectionStart += normalizedValue.slice(0, selectionStart).split("\n").length - 1; | ||
if (startRange.compareEndPoints("EndToEnd", endRange) > -1) { | ||
selectionEnd = lenght; | ||
} | ||
else { | ||
selectionEnd = -startRange.moveEnd("character", -lenght); | ||
selectionEnd += normalizedValue.slice(0, selectionEnd).split("\n").length - 1; | ||
} | ||
} | ||
} | ||
} | ||
return { | ||
selectionStart: selectionStart, | ||
selectionEnd: selectionEnd | ||
}; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(InputManager.prototype, "rawValue", { | ||
get: function () { | ||
return this.htmlInputElement && this.htmlInputElement.value; | ||
}, | ||
set: function (value) { | ||
this._storedRawValue = value; | ||
if (this.htmlInputElement) { | ||
this.htmlInputElement.value = value; | ||
} | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(InputManager.prototype, "storedRawValue", { | ||
get: function () { | ||
return this._storedRawValue; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return InputManager; | ||
}()); | ||
var InputService = /** @class */ (function () { | ||
function InputService(htmlInputElement, options) { | ||
this.htmlInputElement = htmlInputElement; | ||
this.options = options; | ||
this.PER_AR_NUMBER = new Map(); | ||
this.inputManager = new InputManager(htmlInputElement); | ||
this.initialize(); | ||
} | ||
InputService.prototype.initialize = function () { | ||
this.PER_AR_NUMBER.set("\u06F0", "0"); | ||
this.PER_AR_NUMBER.set("\u06F1", "1"); | ||
this.PER_AR_NUMBER.set("\u06F2", "2"); | ||
this.PER_AR_NUMBER.set("\u06F3", "3"); | ||
this.PER_AR_NUMBER.set("\u06F4", "4"); | ||
this.PER_AR_NUMBER.set("\u06F5", "5"); | ||
this.PER_AR_NUMBER.set("\u06F6", "6"); | ||
this.PER_AR_NUMBER.set("\u06F7", "7"); | ||
this.PER_AR_NUMBER.set("\u06F8", "8"); | ||
this.PER_AR_NUMBER.set("\u06F9", "9"); | ||
this.PER_AR_NUMBER.set("\u0660", "0"); | ||
this.PER_AR_NUMBER.set("\u0661", "1"); | ||
this.PER_AR_NUMBER.set("\u0662", "2"); | ||
this.PER_AR_NUMBER.set("\u0663", "3"); | ||
this.PER_AR_NUMBER.set("\u0664", "4"); | ||
this.PER_AR_NUMBER.set("\u0665", "5"); | ||
this.PER_AR_NUMBER.set("\u0666", "6"); | ||
this.PER_AR_NUMBER.set("\u0667", "7"); | ||
this.PER_AR_NUMBER.set("\u0668", "8"); | ||
this.PER_AR_NUMBER.set("\u0669", "9"); | ||
}; | ||
InputService.prototype.addNumber = function (keyCode) { | ||
if (!this.rawValue) { | ||
this.rawValue = this.applyMask(false, "0"); | ||
} | ||
var keyChar = String.fromCharCode(keyCode); | ||
var selectionStart = this.inputSelection.selectionStart; | ||
var selectionEnd = this.inputSelection.selectionEnd; | ||
this.rawValue = this.rawValue.substring(0, selectionStart) + keyChar + this.rawValue.substring(selectionEnd, this.rawValue.length); | ||
this.updateFieldValue(selectionStart + 1); | ||
}; | ||
InputService.prototype.applyMask = function (isNumber, rawValue) { | ||
var _a = this.options, allowNegative = _a.allowNegative, decimal = _a.decimal, precision = _a.precision, prefix = _a.prefix, suffix = _a.suffix, thousands = _a.thousands, nullable = _a.nullable; | ||
rawValue = isNumber ? new Number(rawValue).toFixed(precision) : rawValue; | ||
var onlyNumbers = rawValue.replace(/[^0-9\u0660-\u0669\u06F0-\u06F9]/g, ""); | ||
if (!onlyNumbers) { | ||
return ""; | ||
} | ||
var integerPart = onlyNumbers.slice(0, onlyNumbers.length - precision) | ||
.replace(/^\u0660*/g, "") | ||
.replace(/^\u06F0*/g, "") | ||
.replace(/^0*/g, "") | ||
.replace(/\B(?=([0-9\u0660-\u0669\u06F0-\u06F9]{3})+(?![0-9\u0660-\u0669\u06F0-\u06F9]))/g, thousands); | ||
if (thousands && integerPart.startsWith(thousands)) { | ||
integerPart = integerPart.substring(1); | ||
} | ||
if (integerPart == "") { | ||
integerPart = "0"; | ||
} | ||
var newRawValue = integerPart; | ||
var decimalPart = onlyNumbers.slice(onlyNumbers.length - precision); | ||
if (precision > 0) { | ||
if (newRawValue == "0" && decimalPart.length < precision) { | ||
newRawValue += decimal + "0".repeat(precision - 1) + decimalPart; | ||
} | ||
else { | ||
newRawValue += decimal + decimalPart; | ||
} | ||
} | ||
var isZero = parseInt(integerPart) == 0 && (parseInt(decimalPart) == 0 || decimalPart == ""); | ||
var operator = (rawValue.indexOf("-") > -1 && allowNegative && !isZero) ? "-" : ""; | ||
return operator + prefix + newRawValue + suffix; | ||
}; | ||
InputService.prototype.clearMask = function (rawValue) { | ||
if (this.isNullable() && rawValue === "") | ||
return null; | ||
var value = (rawValue || "0").replace(this.options.prefix, "").replace(this.options.suffix, ""); | ||
if (this.options.thousands) { | ||
value = value.replace(new RegExp("\\" + this.options.thousands, "g"), ""); | ||
} | ||
if (this.options.decimal) { | ||
value = value.replace(this.options.decimal, "."); | ||
} | ||
this.PER_AR_NUMBER.forEach(function (val, key) { | ||
var re = new RegExp(key, "g"); | ||
value = value.replace(re, val); | ||
}); | ||
return parseFloat(value); | ||
}; | ||
InputService.prototype.changeToNegative = function () { | ||
if (this.options.allowNegative && this.rawValue != "" && this.rawValue.charAt(0) != "-" && this.value != 0) { | ||
this.rawValue = "-" + this.rawValue; | ||
} | ||
}; | ||
InputService.prototype.changeToPositive = function () { | ||
this.rawValue = this.rawValue.replace("-", ""); | ||
}; | ||
InputService.prototype.removeNumber = function (keyCode) { | ||
if (this.isNullable() && this.value == 0) { | ||
this.rawValue = null; | ||
return; | ||
} | ||
var selectionEnd = this.inputSelection.selectionEnd; | ||
var selectionStart = this.inputSelection.selectionStart; | ||
if (selectionStart > this.rawValue.length - this.options.suffix.length) { | ||
selectionEnd = this.rawValue.length - this.options.suffix.length; | ||
selectionStart = this.rawValue.length - this.options.suffix.length; | ||
} | ||
var move = this.rawValue.substr(selectionStart - 1, 1).match(/\d/) ? 0 : -1; | ||
if ((keyCode == 8 && | ||
selectionStart - 1 === 0 && | ||
!(this.rawValue.substr(selectionStart, 1).match(/\d/))) || | ||
((keyCode == 46 || keyCode == 63272) && | ||
selectionStart === 0 && | ||
!(this.rawValue.substr(selectionStart + 1, 1).match(/\d/)))) { | ||
move = 1; | ||
} | ||
; | ||
selectionEnd = keyCode == 46 || keyCode == 63272 ? selectionEnd + 1 : selectionEnd; | ||
selectionStart = keyCode == 8 ? selectionStart - 1 : selectionStart; | ||
this.rawValue = this.rawValue.substring(0, selectionStart) + this.rawValue.substring(selectionEnd, this.rawValue.length); | ||
this.updateFieldValue(selectionStart + move); | ||
}; | ||
InputService.prototype.updateFieldValue = function (selectionStart) { | ||
var newRawValue = this.applyMask(false, this.rawValue || ""); | ||
selectionStart = selectionStart == undefined ? this.rawValue.length : selectionStart; | ||
this.inputManager.updateValueAndCursor(newRawValue, this.rawValue.length, selectionStart); | ||
}; | ||
InputService.prototype.updateOptions = function (options) { | ||
var value = this.value; | ||
this.options = options; | ||
this.value = value; | ||
}; | ||
InputService.prototype.prefixLength = function () { | ||
return this.options.prefix.length; | ||
}; | ||
InputService.prototype.isNullable = function () { | ||
return this.options.nullable; | ||
}; | ||
Object.defineProperty(InputService.prototype, "canInputMoreNumbers", { | ||
get: function () { | ||
return this.inputManager.canInputMoreNumbers; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(InputService.prototype, "inputSelection", { | ||
get: function () { | ||
return this.inputManager.inputSelection; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(InputService.prototype, "rawValue", { | ||
get: function () { | ||
return this.inputManager.rawValue; | ||
}, | ||
set: function (value) { | ||
this.inputManager.rawValue = value; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(InputService.prototype, "storedRawValue", { | ||
get: function () { | ||
return this.inputManager.storedRawValue; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(InputService.prototype, "value", { | ||
get: function () { | ||
return this.clearMask(this.rawValue); | ||
}, | ||
set: function (value) { | ||
this.rawValue = this.applyMask(true, "" + value); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return InputService; | ||
}()); | ||
var InputHandler = /** @class */ (function () { | ||
function InputHandler(htmlInputElement, options) { | ||
this.inputService = new InputService(htmlInputElement, options); | ||
} | ||
InputHandler.prototype.handleCut = function (event) { | ||
var _this = this; | ||
setTimeout(function () { | ||
_this.inputService.updateFieldValue(); | ||
_this.setValue(_this.inputService.value); | ||
_this.onModelChange(_this.inputService.value); | ||
}, 0); | ||
}; | ||
InputHandler.prototype.handleInput = function (event) { | ||
var keyCode = this.inputService.rawValue.charCodeAt(this.inputService.rawValue.length - 1); | ||
var rawValueLength = this.inputService.rawValue.length; | ||
var rawValueSelectionEnd = this.inputService.inputSelection.selectionEnd; | ||
var storedRawValueLength = this.inputService.storedRawValue.length; | ||
this.inputService.rawValue = this.inputService.storedRawValue; | ||
if (rawValueLength != rawValueSelectionEnd || Math.abs(rawValueLength - storedRawValueLength) != 1) { | ||
this.setCursorPosition(event); | ||
return; | ||
} | ||
if (rawValueLength < storedRawValueLength) { | ||
this.inputService.removeNumber(8); | ||
} | ||
if (rawValueLength > storedRawValueLength) { | ||
switch (keyCode) { | ||
case 43: | ||
this.inputService.changeToPositive(); | ||
break; | ||
case 45: | ||
this.inputService.changeToNegative(); | ||
break; | ||
default: | ||
if (!this.inputService.canInputMoreNumbers) { | ||
return; | ||
} | ||
this.inputService.addNumber(keyCode); | ||
} | ||
} | ||
this.setCursorPosition(event); | ||
this.onModelChange(this.inputService.value); | ||
}; | ||
InputHandler.prototype.handleKeydown = function (event) { | ||
var keyCode = event.which || event.charCode || event.keyCode; | ||
if (keyCode == 8 || keyCode == 46 || keyCode == 63272) { | ||
event.preventDefault(); | ||
var selectionRangeLength = Math.abs(this.inputService.inputSelection.selectionEnd - this.inputService.inputSelection.selectionStart); | ||
if (selectionRangeLength == 0) { | ||
this.inputService.removeNumber(keyCode); | ||
this.onModelChange(this.inputService.value); | ||
} | ||
if (selectionRangeLength >= (this.inputService.rawValue.length - this.inputService.prefixLength())) { | ||
this.clearValue(); | ||
} | ||
} | ||
}; | ||
InputHandler.prototype.clearValue = function () { | ||
this.setValue(this.inputService.isNullable() ? null : 0); | ||
this.onModelChange(this.inputService.value); | ||
}; | ||
InputHandler.prototype.handleKeypress = function (event) { | ||
var keyCode = event.which || event.charCode || event.keyCode; | ||
if (keyCode === 97 && event.ctrlKey) { | ||
return; | ||
} | ||
switch (keyCode) { | ||
case undefined: | ||
case 9: | ||
case 13: | ||
case 37: | ||
case 39: | ||
return; | ||
case 43: | ||
this.inputService.changeToPositive(); | ||
break; | ||
case 45: | ||
this.inputService.changeToNegative(); | ||
break; | ||
default: | ||
if (this.inputService.canInputMoreNumbers) { | ||
var selectionRangeLength = Math.abs(this.inputService.inputSelection.selectionEnd - this.inputService.inputSelection.selectionStart); | ||
if (selectionRangeLength == this.inputService.rawValue.length) { | ||
this.setValue(0); | ||
} | ||
this.inputService.addNumber(keyCode); | ||
} | ||
} | ||
event.preventDefault(); | ||
this.onModelChange(this.inputService.value); | ||
}; | ||
InputHandler.prototype.handlePaste = function (event) { | ||
var _this = this; | ||
setTimeout(function () { | ||
_this.inputService.updateFieldValue(); | ||
_this.setValue(_this.inputService.value); | ||
_this.onModelChange(_this.inputService.value); | ||
}, 1); | ||
}; | ||
InputHandler.prototype.updateOptions = function (options) { | ||
this.inputService.updateOptions(options); | ||
}; | ||
InputHandler.prototype.getOnModelChange = function () { | ||
return this.onModelChange; | ||
}; | ||
InputHandler.prototype.setOnModelChange = function (callbackFunction) { | ||
this.onModelChange = callbackFunction; | ||
}; | ||
InputHandler.prototype.getOnModelTouched = function () { | ||
return this.onModelTouched; | ||
}; | ||
InputHandler.prototype.setOnModelTouched = function (callbackFunction) { | ||
this.onModelTouched = callbackFunction; | ||
}; | ||
InputHandler.prototype.setValue = function (value) { | ||
this.inputService.value = value; | ||
}; | ||
InputHandler.prototype.setCursorPosition = function (event) { | ||
setTimeout(function () { | ||
event.target.setSelectionRange(event.target.value.length, event.target.value.length); | ||
}, 0); | ||
}; | ||
return InputHandler; | ||
}()); | ||
var CURRENCYMASKDIRECTIVE_VALUE_ACCESSOR = { | ||
provide: forms.NG_VALUE_ACCESSOR, | ||
useExisting: core.forwardRef(function () { return CurrencyMaskDirective; }), | ||
multi: true, | ||
}; | ||
var CurrencyMaskDirective = /** @class */ (function () { | ||
function CurrencyMaskDirective(currencyMaskConfig, elementRef, keyValueDiffers) { | ||
this.currencyMaskConfig = currencyMaskConfig; | ||
this.elementRef = elementRef; | ||
this.keyValueDiffers = keyValueDiffers; | ||
this.options = {}; | ||
this.optionsTemplate = { | ||
align: "right", | ||
allowNegative: true, | ||
allowZero: true, | ||
decimal: ".", | ||
precision: 2, | ||
prefix: "$ ", | ||
suffix: "", | ||
thousands: ",", | ||
nullable: false | ||
}; | ||
if (currencyMaskConfig) { | ||
this.optionsTemplate = currencyMaskConfig; | ||
} | ||
this.keyValueDiffer = keyValueDiffers.find({}).create(); | ||
} | ||
CurrencyMaskDirective.prototype.ngAfterViewInit = function () { | ||
this.elementRef.nativeElement.style.textAlign = this.options && this.options.align ? this.options.align : this.optionsTemplate.align; | ||
}; | ||
CurrencyMaskDirective.prototype.ngDoCheck = function () { | ||
if (this.keyValueDiffer.diff(this.options)) { | ||
this.elementRef.nativeElement.style.textAlign = this.options.align ? this.options.align : this.optionsTemplate.align; | ||
this.inputHandler.updateOptions(Object.assign({}, this.optionsTemplate, this.options)); | ||
} | ||
}; | ||
CurrencyMaskDirective.prototype.ngOnInit = function () { | ||
this.inputHandler = new InputHandler(this.elementRef.nativeElement, Object.assign({}, this.optionsTemplate, this.options)); | ||
}; | ||
CurrencyMaskDirective.prototype.handleBlur = function (event) { | ||
this.inputHandler.getOnModelTouched().apply(event); | ||
}; | ||
CurrencyMaskDirective.prototype.handleCut = function (event) { | ||
if (!this.isChromeAndroid()) { | ||
this.inputHandler.handleCut(event); | ||
} | ||
}; | ||
CurrencyMaskDirective.prototype.handleInput = function (event) { | ||
if (this.isChromeAndroid()) { | ||
this.inputHandler.handleInput(event); | ||
} | ||
}; | ||
CurrencyMaskDirective.prototype.handleKeydown = function (event) { | ||
if (!this.isChromeAndroid()) { | ||
this.inputHandler.handleKeydown(event); | ||
} | ||
}; | ||
CurrencyMaskDirective.prototype.handleKeypress = function (event) { | ||
if (!this.isChromeAndroid()) { | ||
this.inputHandler.handleKeypress(event); | ||
} | ||
}; | ||
CurrencyMaskDirective.prototype.handlePaste = function (event) { | ||
if (!this.isChromeAndroid()) { | ||
this.inputHandler.handlePaste(event); | ||
} | ||
}; | ||
CurrencyMaskDirective.prototype.isChromeAndroid = function () { | ||
return /chrome/i.test(navigator.userAgent) && /android/i.test(navigator.userAgent); | ||
}; | ||
CurrencyMaskDirective.prototype.registerOnChange = function (callbackFunction) { | ||
this.inputHandler.setOnModelChange(callbackFunction); | ||
}; | ||
CurrencyMaskDirective.prototype.registerOnTouched = function (callbackFunction) { | ||
this.inputHandler.setOnModelTouched(callbackFunction); | ||
}; | ||
CurrencyMaskDirective.prototype.setDisabledState = function (value) { | ||
this.elementRef.nativeElement.disabled = value; | ||
}; | ||
CurrencyMaskDirective.prototype.writeValue = function (value) { | ||
this.inputHandler.setValue(value); | ||
}; | ||
CurrencyMaskDirective.ctorParameters = function () { return [ | ||
{ type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [CURRENCY_MASK_CONFIG,] }] }, | ||
{ type: core.ElementRef }, | ||
{ type: core.KeyValueDiffers } | ||
]; }; | ||
__decorate([ | ||
core.Input() | ||
], CurrencyMaskDirective.prototype, "options", void 0); | ||
__decorate([ | ||
core.HostListener("blur", ["$event"]) | ||
], CurrencyMaskDirective.prototype, "handleBlur", null); | ||
__decorate([ | ||
core.HostListener("cut", ["$event"]) | ||
], CurrencyMaskDirective.prototype, "handleCut", null); | ||
__decorate([ | ||
core.HostListener("input", ["$event"]) | ||
], CurrencyMaskDirective.prototype, "handleInput", null); | ||
__decorate([ | ||
core.HostListener("keydown", ["$event"]) | ||
], CurrencyMaskDirective.prototype, "handleKeydown", null); | ||
__decorate([ | ||
core.HostListener("keypress", ["$event"]) | ||
], CurrencyMaskDirective.prototype, "handleKeypress", null); | ||
__decorate([ | ||
core.HostListener("paste", ["$event"]) | ||
], CurrencyMaskDirective.prototype, "handlePaste", null); | ||
CurrencyMaskDirective = __decorate([ | ||
core.Directive({ | ||
selector: "[currencyMask]", | ||
providers: [CURRENCYMASKDIRECTIVE_VALUE_ACCESSOR] | ||
}), | ||
__param(0, core.Optional()), __param(0, core.Inject(CURRENCY_MASK_CONFIG)) | ||
], CurrencyMaskDirective); | ||
return CurrencyMaskDirective; | ||
}()); | ||
var NgxCurrencyModule = /** @class */ (function () { | ||
function NgxCurrencyModule() { | ||
} | ||
NgxCurrencyModule_1 = NgxCurrencyModule; | ||
NgxCurrencyModule.forRoot = function (config) { | ||
return { | ||
ngModule: NgxCurrencyModule_1, | ||
providers: [{ | ||
provide: CURRENCY_MASK_CONFIG, | ||
useValue: config, | ||
}] | ||
}; | ||
}; | ||
var NgxCurrencyModule_1; | ||
NgxCurrencyModule = NgxCurrencyModule_1 = __decorate([ | ||
core.NgModule({ | ||
imports: [common.CommonModule, forms.FormsModule], | ||
declarations: [CurrencyMaskDirective], | ||
exports: [CurrencyMaskDirective] | ||
}) | ||
], NgxCurrencyModule); | ||
return NgxCurrencyModule; | ||
}()); | ||
exports.CURRENCYMASKDIRECTIVE_VALUE_ACCESSOR = CURRENCYMASKDIRECTIVE_VALUE_ACCESSOR; | ||
exports.CurrencyMaskDirective = CurrencyMaskDirective; | ||
exports.NgxCurrencyModule = NgxCurrencyModule; | ||
exports.ɵa = CURRENCY_MASK_CONFIG; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
//# sourceMappingURL=ngx-currency.umd.js.map |
@@ -1,9 +0,16 @@ | ||
/** | ||
* ngx-currency - A very simple currency mask directive that allows using a number attribute with the ngModel. | ||
* @version v2.0.2 | ||
* @author Neri Bez Fontana | ||
* @link https://github.com/nbfontana/ngx-currency#readme | ||
* @license MIT | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@angular/core"),require("@angular/forms"),require("@angular/common")):"function"==typeof define&&define.amd?define(["@angular/core","@angular/forms","@angular/common"],t):"object"==typeof exports?exports.ngxBr=t(require("@angular/core"),require("@angular/forms"),require("@angular/common")):e.ngxBr=t(e.ng.core,e.ng.forms,e.ng.common)}(window,(function(e,t,n){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=4)}([function(t,n){t.exports=e},function(e,t,n){"use strict";var i=this&&this.__decorate||function(e,t,n,i){var r,o=arguments.length,s=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,i);else for(var u=e.length-1;u>=0;u--)(r=e[u])&&(s=(o<3?r(s):o>3?r(t,n,s):r(t,n))||s);return o>3&&s&&Object.defineProperty(t,n,s),s},r=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},o=this&&this.__param||function(e,t){return function(n,i){t(n,i,e)}};Object.defineProperty(t,"__esModule",{value:!0});var s=n(0),u=n(2),a=n(3),l=n(5);t.CURRENCYMASKDIRECTIVE_VALUE_ACCESSOR={provide:u.NG_VALUE_ACCESSOR,useExisting:s.forwardRef((function(){return p})),multi:!0};var p=function(){function e(e,t,n){this.currencyMaskConfig=e,this.elementRef=t,this.keyValueDiffers=n,this.options={},this.optionsTemplate={align:"right",allowNegative:!0,allowZero:!0,decimal:".",precision:2,prefix:"$ ",suffix:"",thousands:",",nullable:!1},e&&(this.optionsTemplate=e),this.keyValueDiffer=n.find({}).create()}return e.prototype.ngAfterViewInit=function(){this.elementRef.nativeElement.style.textAlign=this.options&&this.options.align?this.options.align:this.optionsTemplate.align},e.prototype.ngDoCheck=function(){this.keyValueDiffer.diff(this.options)&&(this.elementRef.nativeElement.style.textAlign=this.options.align?this.options.align:this.optionsTemplate.align,this.inputHandler.updateOptions(Object.assign({},this.optionsTemplate,this.options)))},e.prototype.ngOnInit=function(){this.inputHandler=new l.InputHandler(this.elementRef.nativeElement,Object.assign({},this.optionsTemplate,this.options))},e.prototype.handleBlur=function(e){this.inputHandler.getOnModelTouched().apply(e)},e.prototype.handleCut=function(e){this.isChromeAndroid()||this.inputHandler.handleCut(e)},e.prototype.handleInput=function(e){this.isChromeAndroid()&&this.inputHandler.handleInput(e)},e.prototype.handleKeydown=function(e){this.isChromeAndroid()||this.inputHandler.handleKeydown(e)},e.prototype.handleKeypress=function(e){this.isChromeAndroid()||this.inputHandler.handleKeypress(e)},e.prototype.handlePaste=function(e){this.isChromeAndroid()||this.inputHandler.handlePaste(e)},e.prototype.isChromeAndroid=function(){return/chrome/i.test(navigator.userAgent)&&/android/i.test(navigator.userAgent)},e.prototype.registerOnChange=function(e){this.inputHandler.setOnModelChange(e)},e.prototype.registerOnTouched=function(e){this.inputHandler.setOnModelTouched(e)},e.prototype.setDisabledState=function(e){this.elementRef.nativeElement.disabled=e},e.prototype.writeValue=function(e){this.inputHandler.setValue(e)},i([s.Input(),r("design:type",Object)],e.prototype,"options",void 0),i([s.HostListener("blur",["$event"]),r("design:type",Function),r("design:paramtypes",[Object]),r("design:returntype",void 0)],e.prototype,"handleBlur",null),i([s.HostListener("cut",["$event"]),r("design:type",Function),r("design:paramtypes",[Object]),r("design:returntype",void 0)],e.prototype,"handleCut",null),i([s.HostListener("input",["$event"]),r("design:type",Function),r("design:paramtypes",[Object]),r("design:returntype",void 0)],e.prototype,"handleInput",null),i([s.HostListener("keydown",["$event"]),r("design:type",Function),r("design:paramtypes",[Object]),r("design:returntype",void 0)],e.prototype,"handleKeydown",null),i([s.HostListener("keypress",["$event"]),r("design:type",Function),r("design:paramtypes",[Object]),r("design:returntype",void 0)],e.prototype,"handleKeypress",null),i([s.HostListener("paste",["$event"]),r("design:type",Function),r("design:paramtypes",[Object]),r("design:returntype",void 0)],e.prototype,"handlePaste",null),e=i([s.Directive({selector:"[currencyMask]",providers:[t.CURRENCYMASKDIRECTIVE_VALUE_ACCESSOR]}),o(0,s.Optional()),o(0,s.Inject(a.CURRENCY_MASK_CONFIG)),r("design:paramtypes",[Object,s.ElementRef,s.KeyValueDiffers])],e)}();t.CurrencyMaskDirective=p},function(e,n){e.exports=t},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=n(0);t.CURRENCY_MASK_CONFIG=new i.InjectionToken("currency.mask.config")},function(e,t,n){"use strict";function i(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}Object.defineProperty(t,"__esModule",{value:!0}),i(n(1)),i(n(8))},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=n(6),r=function(){function e(e,t){this.inputService=new i.InputService(e,t)}return e.prototype.handleCut=function(e){var t=this;setTimeout((function(){t.inputService.updateFieldValue(),t.setValue(t.inputService.value),t.onModelChange(t.inputService.value)}),0)},e.prototype.handleInput=function(e){var t=this.inputService.rawValue.charCodeAt(this.inputService.rawValue.length-1),n=this.inputService.rawValue.length,i=this.inputService.inputSelection.selectionEnd,r=this.inputService.storedRawValue.length;if(this.inputService.rawValue=this.inputService.storedRawValue,n==i&&1==Math.abs(n-r)){if(n<r&&this.inputService.removeNumber(8),n>r)switch(t){case 43:this.inputService.changeToPositive();break;case 45:this.inputService.changeToNegative();break;default:if(!this.inputService.canInputMoreNumbers)return;this.inputService.addNumber(t)}this.setCursorPosition(e),this.onModelChange(this.inputService.value)}else this.setCursorPosition(e)},e.prototype.handleKeydown=function(e){var t=e.which||e.charCode||e.keyCode;if(8==t||46==t||63272==t){e.preventDefault();var n=Math.abs(this.inputService.inputSelection.selectionEnd-this.inputService.inputSelection.selectionStart);0==n&&(this.inputService.removeNumber(t),this.onModelChange(this.inputService.value)),n>=this.inputService.rawValue.length-this.inputService.prefixLength()&&this.clearValue()}},e.prototype.clearValue=function(){this.setValue(this.inputService.isNullable()?null:0),this.onModelChange(this.inputService.value)},e.prototype.handleKeypress=function(e){var t=e.which||e.charCode||e.keyCode;if(97!==t||!e.ctrlKey){switch(t){case void 0:case 9:case 13:case 37:case 39:return;case 43:this.inputService.changeToPositive();break;case 45:this.inputService.changeToNegative();break;default:if(this.inputService.canInputMoreNumbers)Math.abs(this.inputService.inputSelection.selectionEnd-this.inputService.inputSelection.selectionStart)==this.inputService.rawValue.length&&this.setValue(0),this.inputService.addNumber(t)}e.preventDefault(),this.onModelChange(this.inputService.value)}},e.prototype.handlePaste=function(e){var t=this;setTimeout((function(){t.inputService.updateFieldValue(),t.setValue(t.inputService.value),t.onModelChange(t.inputService.value)}),1)},e.prototype.updateOptions=function(e){this.inputService.updateOptions(e)},e.prototype.getOnModelChange=function(){return this.onModelChange},e.prototype.setOnModelChange=function(e){this.onModelChange=e},e.prototype.getOnModelTouched=function(){return this.onModelTouched},e.prototype.setOnModelTouched=function(e){this.onModelTouched=e},e.prototype.setValue=function(e){this.inputService.value=e},e.prototype.setCursorPosition=function(e){setTimeout((function(){e.target.setSelectionRange(e.target.value.length,e.target.value.length)}),0)},e}();t.InputHandler=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=n(7),r=function(){function e(e,t){this.htmlInputElement=e,this.options=t,this.PER_AR_NUMBER=new Map,this.inputManager=new i.InputManager(e),this.initialize()}return e.prototype.initialize=function(){this.PER_AR_NUMBER.set("۰","0"),this.PER_AR_NUMBER.set("۱","1"),this.PER_AR_NUMBER.set("۲","2"),this.PER_AR_NUMBER.set("۳","3"),this.PER_AR_NUMBER.set("۴","4"),this.PER_AR_NUMBER.set("۵","5"),this.PER_AR_NUMBER.set("۶","6"),this.PER_AR_NUMBER.set("۷","7"),this.PER_AR_NUMBER.set("۸","8"),this.PER_AR_NUMBER.set("۹","9"),this.PER_AR_NUMBER.set("٠","0"),this.PER_AR_NUMBER.set("١","1"),this.PER_AR_NUMBER.set("٢","2"),this.PER_AR_NUMBER.set("٣","3"),this.PER_AR_NUMBER.set("٤","4"),this.PER_AR_NUMBER.set("٥","5"),this.PER_AR_NUMBER.set("٦","6"),this.PER_AR_NUMBER.set("٧","7"),this.PER_AR_NUMBER.set("٨","8"),this.PER_AR_NUMBER.set("٩","9")},e.prototype.addNumber=function(e){this.rawValue||(this.rawValue=this.applyMask(!1,"0"));var t=String.fromCharCode(e),n=this.inputSelection.selectionStart,i=this.inputSelection.selectionEnd;this.rawValue=this.rawValue.substring(0,n)+t+this.rawValue.substring(i,this.rawValue.length),this.updateFieldValue(n+1)},e.prototype.applyMask=function(e,t){var n=this.options,i=n.allowNegative,r=n.decimal,o=n.precision,s=n.prefix,u=n.suffix,a=n.thousands,l=(n.nullable,(t=e?new Number(t).toFixed(o):t).replace(/[^0-9\u0660-\u0669\u06F0-\u06F9]/g,""));if(!l)return"";var p=l.slice(0,l.length-o).replace(/^\u0660*/g,"").replace(/^\u06F0*/g,"").replace(/^0*/g,"").replace(/\B(?=([0-9\u0660-\u0669\u06F0-\u06F9]{3})+(?![0-9\u0660-\u0669\u06F0-\u06F9]))/g,a);a&&p.startsWith(a)&&(p=p.substring(1)),""==p&&(p="0");var c=p,h=l.slice(l.length-o);o>0&&("0"==c&&h.length<o?c+=r+"0".repeat(o-1)+h:c+=r+h);var d=0==parseInt(p)&&(0==parseInt(h)||""==h);return(t.indexOf("-")>-1&&i&&!d?"-":"")+s+c+u},e.prototype.clearMask=function(e){if(this.isNullable()&&""===e)return null;var t=(e||"0").replace(this.options.prefix,"").replace(this.options.suffix,"");return this.options.thousands&&(t=t.replace(new RegExp("\\"+this.options.thousands,"g"),"")),this.options.decimal&&(t=t.replace(this.options.decimal,".")),this.PER_AR_NUMBER.forEach((function(e,n){var i=new RegExp(n,"g");t=t.replace(i,e)})),parseFloat(t)},e.prototype.changeToNegative=function(){this.options.allowNegative&&""!=this.rawValue&&"-"!=this.rawValue.charAt(0)&&0!=this.value&&(this.rawValue="-"+this.rawValue)},e.prototype.changeToPositive=function(){this.rawValue=this.rawValue.replace("-","")},e.prototype.removeNumber=function(e){if(this.isNullable()&&0==this.value)this.rawValue=null;else{var t=this.inputSelection.selectionEnd,n=this.inputSelection.selectionStart;n>this.rawValue.length-this.options.suffix.length&&(t=this.rawValue.length-this.options.suffix.length,n=this.rawValue.length-this.options.suffix.length);var i=this.rawValue.substr(n-1,1).match(/\d/)?0:-1;(8!=e||n-1!=0||this.rawValue.substr(n,1).match(/\d/))&&(46!=e&&63272!=e||0!==n||this.rawValue.substr(n+1,1).match(/\d/))||(i=1),t=46==e||63272==e?t+1:t,n=8==e?n-1:n,this.rawValue=this.rawValue.substring(0,n)+this.rawValue.substring(t,this.rawValue.length),this.updateFieldValue(n+i)}},e.prototype.updateFieldValue=function(e){var t=this.applyMask(!1,this.rawValue||"");e=null==e?this.rawValue.length:e,this.inputManager.updateValueAndCursor(t,this.rawValue.length,e)},e.prototype.updateOptions=function(e){var t=this.value;this.options=e,this.value=t},e.prototype.prefixLength=function(){return this.options.prefix.length},e.prototype.isNullable=function(){return this.options.nullable},Object.defineProperty(e.prototype,"canInputMoreNumbers",{get:function(){return this.inputManager.canInputMoreNumbers},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"inputSelection",{get:function(){return this.inputManager.inputSelection},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rawValue",{get:function(){return this.inputManager.rawValue},set:function(e){this.inputManager.rawValue=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"storedRawValue",{get:function(){return this.inputManager.storedRawValue},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.clearMask(this.rawValue)},set:function(e){this.rawValue=this.applyMask(!0,""+e)},enumerable:!0,configurable:!0}),e}();t.InputService=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e){this.htmlInputElement=e}return e.prototype.setCursorAt=function(e){if(this.htmlInputElement.setSelectionRange)this.htmlInputElement.focus(),this.htmlInputElement.setSelectionRange(e,e);else if(this.htmlInputElement.createTextRange){var t=this.htmlInputElement.createTextRange();t.collapse(!0),t.moveEnd("character",e),t.moveStart("character",e),t.select()}},e.prototype.updateValueAndCursor=function(e,t,n){this.rawValue=e,n-=t-e.length,this.setCursorAt(n)},Object.defineProperty(e.prototype,"canInputMoreNumbers",{get:function(){var e=!(this.rawValue.length>=this.htmlInputElement.maxLength&&this.htmlInputElement.maxLength>=0),t=this.inputSelection.selectionStart,n=this.inputSelection.selectionEnd,i=!(t==n||!this.htmlInputElement.value.substring(t,n).match(/[^0-9\u0660-\u0669\u06F0-\u06F9]/)),r="0"==this.htmlInputElement.value.substring(0,1);return e||i||r},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"inputSelection",{get:function(){var e=0,t=0;if("number"==typeof this.htmlInputElement.selectionStart&&"number"==typeof this.htmlInputElement.selectionEnd)e=this.htmlInputElement.selectionStart,t=this.htmlInputElement.selectionEnd;else{var n=document.selection.createRange();if(n&&n.parentElement()==this.htmlInputElement){var i=this.htmlInputElement.value.length,r=this.htmlInputElement.value.replace(/\r\n/g,"\n"),o=this.htmlInputElement.createTextRange();o.moveToBookmark(n.getBookmark());var s=this.htmlInputElement.createTextRange();s.collapse(!1),o.compareEndPoints("StartToEnd",s)>-1?e=t=i:(e=-o.moveStart("character",-i),e+=r.slice(0,e).split("\n").length-1,o.compareEndPoints("EndToEnd",s)>-1?t=i:(t=-o.moveEnd("character",-i),t+=r.slice(0,t).split("\n").length-1))}}return{selectionStart:e,selectionEnd:t}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rawValue",{get:function(){return this.htmlInputElement&&this.htmlInputElement.value},set:function(e){this._storedRawValue=e,this.htmlInputElement&&(this.htmlInputElement.value=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"storedRawValue",{get:function(){return this._storedRawValue},enumerable:!0,configurable:!0}),e}();t.InputManager=i},function(e,t,n){"use strict";var i=this&&this.__decorate||function(e,t,n,i){var r,o=arguments.length,s=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,i);else for(var u=e.length-1;u>=0;u--)(r=e[u])&&(s=(o<3?r(s):o>3?r(t,n,s):r(t,n))||s);return o>3&&s&&Object.defineProperty(t,n,s),s};Object.defineProperty(t,"__esModule",{value:!0});var r=n(0),o=n(9),s=n(2),u=n(1),a=n(3),l=function(){function e(){}var t;return t=e,e.forRoot=function(e){return{ngModule:t,providers:[{provide:a.CURRENCY_MASK_CONFIG,useValue:e}]}},e=t=i([r.NgModule({imports:[o.CommonModule,s.FormsModule],declarations:[u.CurrencyMaskDirective],exports:[u.CurrencyMaskDirective]})],e)}();t.NgxCurrencyModule=l},function(e,t){e.exports=n}])})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/forms"),require("@angular/common")):"function"==typeof define&&define.amd?define("ngx-currency",["exports","@angular/core","@angular/forms","@angular/common"],t):t((e=e||self)["ngx-currency"]={},e.ng.core,e.ng.forms,e.ng.common)}(this,(function(e,t,n,i){"use strict"; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */function r(e,t,n,i){var r,o=arguments.length,s=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(s=(o<3?r(s):o>3?r(t,n,s):r(t,n))||s);return o>3&&s&&Object.defineProperty(t,n,s),s}function o(e,t){return function(n,i){t(n,i,e)}}var s=new t.InjectionToken("currency.mask.config"),a=function(){function e(e){this.htmlInputElement=e}return e.prototype.setCursorAt=function(e){if(this.htmlInputElement.setSelectionRange)this.htmlInputElement.focus(),this.htmlInputElement.setSelectionRange(e,e);else if(this.htmlInputElement.createTextRange){var t=this.htmlInputElement.createTextRange();t.collapse(!0),t.moveEnd("character",e),t.moveStart("character",e),t.select()}},e.prototype.updateValueAndCursor=function(e,t,n){this.rawValue=e,n-=t-e.length,this.setCursorAt(n)},Object.defineProperty(e.prototype,"canInputMoreNumbers",{get:function(){var e=!(this.rawValue.length>=this.htmlInputElement.maxLength&&this.htmlInputElement.maxLength>=0),t=this.inputSelection.selectionStart,n=this.inputSelection.selectionEnd,i=!(t==n||!this.htmlInputElement.value.substring(t,n).match(/[^0-9\u0660-\u0669\u06F0-\u06F9]/)),r="0"==this.htmlInputElement.value.substring(0,1);return e||i||r},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"inputSelection",{get:function(){var e=0,t=0;if("number"==typeof this.htmlInputElement.selectionStart&&"number"==typeof this.htmlInputElement.selectionEnd)e=this.htmlInputElement.selectionStart,t=this.htmlInputElement.selectionEnd;else{var n=document.selection.createRange();if(n&&n.parentElement()==this.htmlInputElement){var i=this.htmlInputElement.value.length,r=this.htmlInputElement.value.replace(/\r\n/g,"\n"),o=this.htmlInputElement.createTextRange();o.moveToBookmark(n.getBookmark());var s=this.htmlInputElement.createTextRange();s.collapse(!1),o.compareEndPoints("StartToEnd",s)>-1?e=t=i:(e=-o.moveStart("character",-i),e+=r.slice(0,e).split("\n").length-1,o.compareEndPoints("EndToEnd",s)>-1?t=i:(t=-o.moveEnd("character",-i),t+=r.slice(0,t).split("\n").length-1))}}return{selectionStart:e,selectionEnd:t}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rawValue",{get:function(){return this.htmlInputElement&&this.htmlInputElement.value},set:function(e){this._storedRawValue=e,this.htmlInputElement&&(this.htmlInputElement.value=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"storedRawValue",{get:function(){return this._storedRawValue},enumerable:!0,configurable:!0}),e}(),u=function(){function e(e,t){this.htmlInputElement=e,this.options=t,this.PER_AR_NUMBER=new Map,this.inputManager=new a(e),this.initialize()}return e.prototype.initialize=function(){this.PER_AR_NUMBER.set("۰","0"),this.PER_AR_NUMBER.set("۱","1"),this.PER_AR_NUMBER.set("۲","2"),this.PER_AR_NUMBER.set("۳","3"),this.PER_AR_NUMBER.set("۴","4"),this.PER_AR_NUMBER.set("۵","5"),this.PER_AR_NUMBER.set("۶","6"),this.PER_AR_NUMBER.set("۷","7"),this.PER_AR_NUMBER.set("۸","8"),this.PER_AR_NUMBER.set("۹","9"),this.PER_AR_NUMBER.set("٠","0"),this.PER_AR_NUMBER.set("١","1"),this.PER_AR_NUMBER.set("٢","2"),this.PER_AR_NUMBER.set("٣","3"),this.PER_AR_NUMBER.set("٤","4"),this.PER_AR_NUMBER.set("٥","5"),this.PER_AR_NUMBER.set("٦","6"),this.PER_AR_NUMBER.set("٧","7"),this.PER_AR_NUMBER.set("٨","8"),this.PER_AR_NUMBER.set("٩","9")},e.prototype.addNumber=function(e){this.rawValue||(this.rawValue=this.applyMask(!1,"0"));var t=String.fromCharCode(e),n=this.inputSelection.selectionStart,i=this.inputSelection.selectionEnd;this.rawValue=this.rawValue.substring(0,n)+t+this.rawValue.substring(i,this.rawValue.length),this.updateFieldValue(n+1)},e.prototype.applyMask=function(e,t){var n=this.options,i=n.allowNegative,r=n.decimal,o=n.precision,s=n.prefix,a=n.suffix,u=n.thousands,l=(n.nullable,(t=e?new Number(t).toFixed(o):t).replace(/[^0-9\u0660-\u0669\u06F0-\u06F9]/g,""));if(!l)return"";var p=l.slice(0,l.length-o).replace(/^\u0660*/g,"").replace(/^\u06F0*/g,"").replace(/^0*/g,"").replace(/\B(?=([0-9\u0660-\u0669\u06F0-\u06F9]{3})+(?![0-9\u0660-\u0669\u06F0-\u06F9]))/g,u);u&&p.startsWith(u)&&(p=p.substring(1)),""==p&&(p="0");var h=p,c=l.slice(l.length-o);o>0&&("0"==h&&c.length<o?h+=r+"0".repeat(o-1)+c:h+=r+c);var d=0==parseInt(p)&&(0==parseInt(c)||""==c);return(t.indexOf("-")>-1&&i&&!d?"-":"")+s+h+a},e.prototype.clearMask=function(e){if(this.isNullable()&&""===e)return null;var t=(e||"0").replace(this.options.prefix,"").replace(this.options.suffix,"");return this.options.thousands&&(t=t.replace(new RegExp("\\"+this.options.thousands,"g"),"")),this.options.decimal&&(t=t.replace(this.options.decimal,".")),this.PER_AR_NUMBER.forEach((function(e,n){var i=new RegExp(n,"g");t=t.replace(i,e)})),parseFloat(t)},e.prototype.changeToNegative=function(){this.options.allowNegative&&""!=this.rawValue&&"-"!=this.rawValue.charAt(0)&&0!=this.value&&(this.rawValue="-"+this.rawValue)},e.prototype.changeToPositive=function(){this.rawValue=this.rawValue.replace("-","")},e.prototype.removeNumber=function(e){if(this.isNullable()&&0==this.value)this.rawValue=null;else{var t=this.inputSelection.selectionEnd,n=this.inputSelection.selectionStart;n>this.rawValue.length-this.options.suffix.length&&(t=this.rawValue.length-this.options.suffix.length,n=this.rawValue.length-this.options.suffix.length);var i=this.rawValue.substr(n-1,1).match(/\d/)?0:-1;(8!=e||n-1!=0||this.rawValue.substr(n,1).match(/\d/))&&(46!=e&&63272!=e||0!==n||this.rawValue.substr(n+1,1).match(/\d/))||(i=1),t=46==e||63272==e?t+1:t,n=8==e?n-1:n,this.rawValue=this.rawValue.substring(0,n)+this.rawValue.substring(t,this.rawValue.length),this.updateFieldValue(n+i)}},e.prototype.updateFieldValue=function(e){var t=this.applyMask(!1,this.rawValue||"");e=null==e?this.rawValue.length:e,this.inputManager.updateValueAndCursor(t,this.rawValue.length,e)},e.prototype.updateOptions=function(e){var t=this.value;this.options=e,this.value=t},e.prototype.prefixLength=function(){return this.options.prefix.length},e.prototype.isNullable=function(){return this.options.nullable},Object.defineProperty(e.prototype,"canInputMoreNumbers",{get:function(){return this.inputManager.canInputMoreNumbers},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"inputSelection",{get:function(){return this.inputManager.inputSelection},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rawValue",{get:function(){return this.inputManager.rawValue},set:function(e){this.inputManager.rawValue=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"storedRawValue",{get:function(){return this.inputManager.storedRawValue},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.clearMask(this.rawValue)},set:function(e){this.rawValue=this.applyMask(!0,""+e)},enumerable:!0,configurable:!0}),e}(),l=function(){function e(e,t){this.inputService=new u(e,t)}return e.prototype.handleCut=function(e){var t=this;setTimeout((function(){t.inputService.updateFieldValue(),t.setValue(t.inputService.value),t.onModelChange(t.inputService.value)}),0)},e.prototype.handleInput=function(e){var t=this.inputService.rawValue.charCodeAt(this.inputService.rawValue.length-1),n=this.inputService.rawValue.length,i=this.inputService.inputSelection.selectionEnd,r=this.inputService.storedRawValue.length;if(this.inputService.rawValue=this.inputService.storedRawValue,n==i&&1==Math.abs(n-r)){if(n<r&&this.inputService.removeNumber(8),n>r)switch(t){case 43:this.inputService.changeToPositive();break;case 45:this.inputService.changeToNegative();break;default:if(!this.inputService.canInputMoreNumbers)return;this.inputService.addNumber(t)}this.setCursorPosition(e),this.onModelChange(this.inputService.value)}else this.setCursorPosition(e)},e.prototype.handleKeydown=function(e){var t=e.which||e.charCode||e.keyCode;if(8==t||46==t||63272==t){e.preventDefault();var n=Math.abs(this.inputService.inputSelection.selectionEnd-this.inputService.inputSelection.selectionStart);0==n&&(this.inputService.removeNumber(t),this.onModelChange(this.inputService.value)),n>=this.inputService.rawValue.length-this.inputService.prefixLength()&&this.clearValue()}},e.prototype.clearValue=function(){this.setValue(this.inputService.isNullable()?null:0),this.onModelChange(this.inputService.value)},e.prototype.handleKeypress=function(e){var t=e.which||e.charCode||e.keyCode;if(97!==t||!e.ctrlKey){switch(t){case void 0:case 9:case 13:case 37:case 39:return;case 43:this.inputService.changeToPositive();break;case 45:this.inputService.changeToNegative();break;default:if(this.inputService.canInputMoreNumbers)Math.abs(this.inputService.inputSelection.selectionEnd-this.inputService.inputSelection.selectionStart)==this.inputService.rawValue.length&&this.setValue(0),this.inputService.addNumber(t)}e.preventDefault(),this.onModelChange(this.inputService.value)}},e.prototype.handlePaste=function(e){var t=this;setTimeout((function(){t.inputService.updateFieldValue(),t.setValue(t.inputService.value),t.onModelChange(t.inputService.value)}),1)},e.prototype.updateOptions=function(e){this.inputService.updateOptions(e)},e.prototype.getOnModelChange=function(){return this.onModelChange},e.prototype.setOnModelChange=function(e){this.onModelChange=e},e.prototype.getOnModelTouched=function(){return this.onModelTouched},e.prototype.setOnModelTouched=function(e){this.onModelTouched=e},e.prototype.setValue=function(e){this.inputService.value=e},e.prototype.setCursorPosition=function(e){setTimeout((function(){e.target.setSelectionRange(e.target.value.length,e.target.value.length)}),0)},e}(),p={provide:n.NG_VALUE_ACCESSOR,useExisting:t.forwardRef((function(){return h})),multi:!0},h=function(){function e(e,t,n){this.currencyMaskConfig=e,this.elementRef=t,this.keyValueDiffers=n,this.options={},this.optionsTemplate={align:"right",allowNegative:!0,allowZero:!0,decimal:".",precision:2,prefix:"$ ",suffix:"",thousands:",",nullable:!1},e&&(this.optionsTemplate=e),this.keyValueDiffer=n.find({}).create()}return e.prototype.ngAfterViewInit=function(){this.elementRef.nativeElement.style.textAlign=this.options&&this.options.align?this.options.align:this.optionsTemplate.align},e.prototype.ngDoCheck=function(){this.keyValueDiffer.diff(this.options)&&(this.elementRef.nativeElement.style.textAlign=this.options.align?this.options.align:this.optionsTemplate.align,this.inputHandler.updateOptions(Object.assign({},this.optionsTemplate,this.options)))},e.prototype.ngOnInit=function(){this.inputHandler=new l(this.elementRef.nativeElement,Object.assign({},this.optionsTemplate,this.options))},e.prototype.handleBlur=function(e){this.inputHandler.getOnModelTouched().apply(e)},e.prototype.handleCut=function(e){this.isChromeAndroid()||this.inputHandler.handleCut(e)},e.prototype.handleInput=function(e){this.isChromeAndroid()&&this.inputHandler.handleInput(e)},e.prototype.handleKeydown=function(e){this.isChromeAndroid()||this.inputHandler.handleKeydown(e)},e.prototype.handleKeypress=function(e){this.isChromeAndroid()||this.inputHandler.handleKeypress(e)},e.prototype.handlePaste=function(e){this.isChromeAndroid()||this.inputHandler.handlePaste(e)},e.prototype.isChromeAndroid=function(){return/chrome/i.test(navigator.userAgent)&&/android/i.test(navigator.userAgent)},e.prototype.registerOnChange=function(e){this.inputHandler.setOnModelChange(e)},e.prototype.registerOnTouched=function(e){this.inputHandler.setOnModelTouched(e)},e.prototype.setDisabledState=function(e){this.elementRef.nativeElement.disabled=e},e.prototype.writeValue=function(e){this.inputHandler.setValue(e)},e.ctorParameters=function(){return[{type:void 0,decorators:[{type:t.Optional},{type:t.Inject,args:[s]}]},{type:t.ElementRef},{type:t.KeyValueDiffers}]},r([t.Input()],e.prototype,"options",void 0),r([t.HostListener("blur",["$event"])],e.prototype,"handleBlur",null),r([t.HostListener("cut",["$event"])],e.prototype,"handleCut",null),r([t.HostListener("input",["$event"])],e.prototype,"handleInput",null),r([t.HostListener("keydown",["$event"])],e.prototype,"handleKeydown",null),r([t.HostListener("keypress",["$event"])],e.prototype,"handleKeypress",null),r([t.HostListener("paste",["$event"])],e.prototype,"handlePaste",null),e=r([t.Directive({selector:"[currencyMask]",providers:[p]}),o(0,t.Optional()),o(0,t.Inject(s))],e)}(),c=function(){function e(){}var o;return o=e,e.forRoot=function(e){return{ngModule:o,providers:[{provide:s,useValue:e}]}},e=o=r([t.NgModule({imports:[i.CommonModule,n.FormsModule],declarations:[h],exports:[h]})],e)}();e.CURRENCYMASKDIRECTIVE_VALUE_ACCESSOR=p,e.CurrencyMaskDirective=h,e.NgxCurrencyModule=c,e.ɵa=s,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=ngx-currency.umd.min.js.map |
@@ -5,2 +5,12 @@ # Changelog | ||
## [2.2.0](https://github.com/nbfontana/ngx-currency/compare/v2.0.2...v2.2.0) (2019-12-26) | ||
### Features | ||
* **build:** Install and setup ng-packagr ([c718bae](https://github.com/nbfontana/ngx-currency/commit/c718bae)) | ||
* **build:** Remove unused NPM build scripts ([bbf4d69](https://github.com/nbfontana/ngx-currency/commit/bbf4d69)) | ||
### [2.0.2](https://github.com/nbfontana/ngx-currency/compare/v2.0.1...v2.0.2) (2019-11-26) | ||
@@ -7,0 +17,0 @@ |
{ | ||
"$schema": "./node_modules/ng-packagr/package.schema.json", | ||
"name": "ngx-currency", | ||
"version": "2.0.2", | ||
"version": "2.2.0", | ||
"description": "A very simple currency mask directive that allows using a number attribute with the ngModel.", | ||
"main": "./bundles/ngx-currency.umd.js", | ||
"module": "./index.js", | ||
"typings": "./index.d.ts", | ||
"scripts": { | ||
@@ -12,5 +10,3 @@ "start": "concurrently --raw \"webpack-dev-server --open\" \"npm run test:watch\"", | ||
"build:demo": "webpack -p", | ||
"build:umd": "webpack --mode=production --config webpack.config.umd.ts", | ||
"build:ngc": "ngc -p tsconfig-ngc.json", | ||
"build:dist": "npm run build:umd && npm run build:ngc", | ||
"build:dist": "ng-packagr -p package.json", | ||
"build:clean": "del-cli dist", | ||
@@ -52,10 +48,10 @@ "test": "nyc --reporter=html karma start --coverage --single-run && npm run build:dist && npm run build:clean", | ||
"devDependencies": { | ||
"@angular/common": "7.2.15", | ||
"@angular/compiler": "7.2.15", | ||
"@angular/compiler-cli": "7.2.15", | ||
"@angular/core": "7.2.15", | ||
"@angular/forms": "7.2.15", | ||
"@angular/language-service": "7.2.15", | ||
"@angular/platform-browser": "7.2.15", | ||
"@angular/platform-browser-dynamic": "7.2.15", | ||
"@angular/common": "8.2.14", | ||
"@angular/compiler": "8.2.14", | ||
"@angular/compiler-cli": "8.2.14", | ||
"@angular/core": "8.2.14", | ||
"@angular/forms": "8.2.14", | ||
"@angular/language-service": "8.2.14", | ||
"@angular/platform-browser": "8.2.14", | ||
"@angular/platform-browser-dynamic": "8.2.14", | ||
"@compodoc/compodoc": "1.0.0-beta.3", | ||
@@ -91,4 +87,5 @@ "@types/chai": "4.1.7", | ||
"mocha": "6.1.4", | ||
"ng-packagr": "^5.7.1", | ||
"nyc": "14.1.0", | ||
"rxjs": "6.5.1", | ||
"rxjs": "6.5.3", | ||
"rxjs-compat": "6.5.1", | ||
@@ -102,3 +99,3 @@ "sinon": "7.3.2", | ||
"tslint-loader": "3.5.4", | ||
"typescript": "3.2.4", | ||
"typescript": "3.5.3", | ||
"validate-commit-msg": "2.14.0", | ||
@@ -110,3 +107,3 @@ "webpack": "4.31.0", | ||
"webpack-rxjs-externals": "2.0.0", | ||
"zone.js": "0.8.29" | ||
"zone.js": "0.9.1" | ||
}, | ||
@@ -122,3 +119,8 @@ "config": { | ||
} | ||
}, | ||
"ngPackage": { | ||
"lib": { | ||
"entryFile": "index.ts" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
464029
37
3068
1
57
1
1