Socket
Socket
Sign inDemoInstall

imask

Package Overview
Dependencies
1
Maintainers
1
Versions
95
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.1.0-alpha.1 to 7.1.0-alpha.2

88

esm/controls/html-contenteditable-mask-element.js

@@ -1,23 +0,38 @@

import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import _inheritsLoose from '@babel/runtime-corejs3/helpers/inheritsLoose';
import HTMLMaskElement from './html-mask-element.js';
import IMask from '../core/holder.js';
import '../keys-e9789594.js';
import '../object-keys-53d74329.js';
import './mask-element.js';
var HTMLContenteditableMaskElement = /*#__PURE__*/function (_HTMLMaskElement) {
_inheritsLoose(HTMLContenteditableMaskElement, _HTMLMaskElement);
function HTMLContenteditableMaskElement() {
return _HTMLMaskElement.apply(this, arguments) || this;
class HTMLContenteditableMaskElement extends HTMLMaskElement {
/** Returns HTMLElement selection start */
get _unsafeSelectionStart() {
const root = this.rootElement;
const selection = root.getSelection && root.getSelection();
const anchorOffset = selection && selection.anchorOffset;
const focusOffset = selection && selection.focusOffset;
if (focusOffset == null || anchorOffset == null || anchorOffset < focusOffset) {
return anchorOffset;
}
return focusOffset;
}
var _proto = HTMLContenteditableMaskElement.prototype;
/** Returns HTMLElement selection end */
get _unsafeSelectionEnd() {
const root = this.rootElement;
const selection = root.getSelection && root.getSelection();
const anchorOffset = selection && selection.anchorOffset;
const focusOffset = selection && selection.focusOffset;
if (focusOffset == null || anchorOffset == null || anchorOffset > focusOffset) {
return anchorOffset;
}
return focusOffset;
}
/** Sets HTMLElement selection */
_proto._unsafeSelect = function _unsafeSelect(start, end) {
_unsafeSelect(start, end) {
if (!this.rootElement.createRange) return;
var range = this.rootElement.createRange();
const range = this.rootElement.createRange();
range.setStart(this.input.firstChild || this.input, start);
range.setEnd(this.input.lastChild || this.input, end);
var root = this.rootElement;
var selection = root.getSelection && root.getSelection();
const root = this.rootElement;
const selection = root.getSelection && root.getSelection();
if (selection) {

@@ -29,43 +44,12 @@ selection.removeAllRanges();

/** HTMLElement value */;
_createClass(HTMLContenteditableMaskElement, [{
key: "_unsafeSelectionStart",
get: /** Returns HTMLElement selection start */
function get() {
var root = this.rootElement;
var selection = root.getSelection && root.getSelection();
var anchorOffset = selection && selection.anchorOffset;
var focusOffset = selection && selection.focusOffset;
if (focusOffset == null || anchorOffset == null || anchorOffset < focusOffset) {
return anchorOffset;
}
return focusOffset;
}
/** Returns HTMLElement selection end */
}, {
key: "_unsafeSelectionEnd",
get: function get() {
var root = this.rootElement;
var selection = root.getSelection && root.getSelection();
var anchorOffset = selection && selection.anchorOffset;
var focusOffset = selection && selection.focusOffset;
if (focusOffset == null || anchorOffset == null || anchorOffset > focusOffset) {
return anchorOffset;
}
return focusOffset;
}
}, {
key: "value",
get: function get() {
return this.input.textContent || '';
},
set: function set(value) {
this.input.textContent = value;
}
}]);
return HTMLContenteditableMaskElement;
}(HTMLMaskElement);
/** HTMLElement value */
get value() {
return this.input.textContent || '';
}
set value(value) {
this.input.textContent = value;
}
}
IMask.HTMLContenteditableMaskElement = HTMLContenteditableMaskElement;
export { HTMLContenteditableMaskElement as default };

@@ -1,53 +0,38 @@

import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import _inheritsLoose from '@babel/runtime-corejs3/helpers/inheritsLoose';
import HTMLMaskElement from './html-mask-element.js';
import IMask from '../core/holder.js';
import '../keys-e9789594.js';
import '../object-keys-53d74329.js';
import './mask-element.js';
/** Bridge between InputElement and {@link Masked} */
var HTMLInputMaskElement = /*#__PURE__*/function (_HTMLMaskElement) {
_inheritsLoose(HTMLInputMaskElement, _HTMLMaskElement);
class HTMLInputMaskElement extends HTMLMaskElement {
/** InputElement to use mask on */
function HTMLInputMaskElement(input) {
var _this;
_this = _HTMLMaskElement.call(this, input) || this;
_this.input = input;
_this._handlers = {};
return _this;
constructor(input) {
super(input);
this.input = input;
this._handlers = {};
}
/** Returns InputElement selection start */
var _proto = HTMLInputMaskElement.prototype;
get _unsafeSelectionStart() {
return this.input.selectionStart != null ? this.input.selectionStart : this.value.length;
}
/** Returns InputElement selection end */
get _unsafeSelectionEnd() {
return this.input.selectionEnd;
}
/** Sets InputElement selection */
_proto._unsafeSelect = function _unsafeSelect(start, end) {
_unsafeSelect(start, end) {
this.input.setSelectionRange(start, end);
};
_createClass(HTMLInputMaskElement, [{
key: "_unsafeSelectionStart",
get: function get() {
return this.input.selectionStart != null ? this.input.selectionStart : this.value.length;
}
/** Returns InputElement selection end */
}, {
key: "_unsafeSelectionEnd",
get: function get() {
return this.input.selectionEnd;
}
}, {
key: "value",
get: function get() {
return this.input.value;
},
set: function set(value) {
this.input.value = value;
}
}]);
return HTMLInputMaskElement;
}(HTMLMaskElement);
}
get value() {
return this.input.value;
}
set value(value) {
this.input.value = value;
}
}
IMask.HTMLMaskElement = HTMLMaskElement;
export { HTMLInputMaskElement as default };

@@ -1,29 +0,30 @@

import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import _inheritsLoose from '@babel/runtime-corejs3/helpers/inheritsLoose';
import { _ as _Object$keys } from '../keys-e9789594.js';
import MaskElement from './mask-element.js';
import IMask from '../core/holder.js';
import '../object-keys-53d74329.js';
/** Bridge between HTMLElement and {@link Masked} */
var HTMLMaskElement = /*#__PURE__*/function (_MaskElement) {
_inheritsLoose(HTMLMaskElement, _MaskElement);
class HTMLMaskElement extends MaskElement {
/** HTMLElement to use mask on */
function HTMLMaskElement(input) {
var _this;
_this = _MaskElement.call(this) || this;
_this.input = input;
_this._handlers = {};
return _this;
constructor(input) {
super();
this.input = input;
this._handlers = {};
}
var _proto = HTMLMaskElement.prototype;
get rootElement() {
var _this$input$getRootNo, _this$input$getRootNo2, _this$input;
return (_this$input$getRootNo = (_this$input$getRootNo2 = (_this$input = this.input).getRootNode) == null ? void 0 : _this$input$getRootNo2.call(_this$input)) != null ? _this$input$getRootNo : document;
}
/**
Is element in focus
*/
get isActive() {
return this.input === this.rootElement.activeElement;
}
/**
Binds HTMLElement events to mask internal events
*/
_proto.bindEvents = function bindEvents(handlers) {
var _this2 = this;
_Object$keys(handlers).forEach(function (event) {
return _this2._toggleEventHandler(HTMLMaskElement.EVENTS_MAP[event], handlers[event]);
});
bindEvents(handlers) {
Object.keys(handlers).forEach(event => this._toggleEventHandler(HTMLMaskElement.EVENTS_MAP[event], handlers[event]));
}

@@ -33,10 +34,7 @@

Unbinds HTMLElement events to mask internal events
*/;
_proto.unbindEvents = function unbindEvents() {
var _this3 = this;
_Object$keys(this._handlers).forEach(function (event) {
return _this3._toggleEventHandler(event);
});
};
_proto._toggleEventHandler = function _toggleEventHandler(event, handler) {
*/
unbindEvents() {
Object.keys(this._handlers).forEach(event => this._toggleEventHandler(event));
}
_toggleEventHandler(event, handler) {
if (this._handlers[event]) {

@@ -50,21 +48,4 @@ this.input.removeEventListener(event, this._handlers[event]);

}
};
_createClass(HTMLMaskElement, [{
key: "rootElement",
get: function get() {
var _this$input$getRootNo, _this$input$getRootNo2, _this$input;
return (_this$input$getRootNo = (_this$input$getRootNo2 = (_this$input = this.input).getRootNode) == null ? void 0 : _this$input$getRootNo2.call(_this$input)) != null ? _this$input$getRootNo : document;
}
/**
Is element in focus
*/
}, {
key: "isActive",
get: function get() {
return this.input === this.rootElement.activeElement;
}
}]);
return HTMLMaskElement;
}(MaskElement);
}
}
/** Mapping between HTMLElement events and mask internal events */

@@ -71,0 +52,0 @@ HTMLMaskElement.EVENTS_MAP = {

@@ -1,6 +0,2 @@

import _objectWithoutPropertiesLoose from '@babel/runtime-corejs3/helpers/objectWithoutPropertiesLoose';
import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import { _ as _indexOfInstanceProperty } from '../index-of-358e281e.js';
import { _ as _spliceInstanceProperty } from '../splice-dccbddd9.js';
import { o as objectIncludes, D as DIRECTION } from '../utils-e384b131.js';
import { objectIncludes, DIRECTION } from '../core/utils.js';
import ActionDetails from '../core/action-details.js';

@@ -12,17 +8,6 @@ import createMask, { maskedClass } from '../masked/factory.js';

import IMask from '../core/holder.js';
import '../object-keys-53d74329.js';
import '../classof-c2d10e36.js';
import '../slice-3858f58a.js';
import '../does-not-exceed-safe-integer-d06d288d.js';
import '../array-species-create-349ea110.js';
import '../delete-property-or-throw-2b53787c.js';
import '../keys-e9789594.js';
import '../assign-c82cbe95.js';
import '@babel/runtime-corejs3/helpers/extends';
import '@babel/runtime-corejs3/helpers/inheritsLoose';
import './html-mask-element.js';
var _excluded = ["mask"];
/** Listens to element events and controls changes between element and {@link Masked} */
var InputMask = /*#__PURE__*/function () {
class InputMask {
/**

@@ -34,3 +19,3 @@ View element

function InputMask(el, opts) {
constructor(el, opts) {
this.el = el instanceof MaskElement ? el : el.isContentEditable && el.tagName !== 'INPUT' && el.tagName !== 'TEXTAREA' ? new HTMLContenteditableMaskElement(el) : new HTMLInputMaskElement(el);

@@ -55,4 +40,3 @@ this.masked = createMask(opts);

}
var _proto = InputMask.prototype;
_proto.maskEquals = function maskEquals(mask) {
maskEquals(mask) {
var _this$masked;

@@ -62,5 +46,62 @@ return mask == null || ((_this$masked = this.masked) == null ? void 0 : _this$masked.maskEquals(mask));

/** Masked */;
/** Masked */
get mask() {
return this.masked.mask;
}
set mask(mask) {
if (this.maskEquals(mask)) return;
if (!(mask instanceof IMask.Masked) && this.masked.constructor === maskedClass(mask)) {
// TODO "any" no idea
this.masked.updateOptions({
mask
});
return;
}
const masked = mask instanceof IMask.Masked ? mask : createMask({
mask
});
masked.unmaskedValue = this.masked.unmaskedValue;
this.masked = masked;
}
/** Raw value */
get value() {
return this._value;
}
set value(str) {
if (this.value === str) return;
this.masked.value = str;
this.updateControl();
this.alignCursor();
}
/** Unmasked value */
get unmaskedValue() {
return this._unmaskedValue;
}
set unmaskedValue(str) {
if (this.unmaskedValue === str) return;
this.masked.unmaskedValue = str;
this.updateControl();
this.alignCursor();
}
/** Typed unmasked value */
get typedValue() {
return this.masked.typedValue;
}
set typedValue(val) {
if (this.masked.typedValueEquals(val)) return;
this.masked.typedValue = val;
this.updateControl();
this.alignCursor();
}
/** Display value */
get displayValue() {
return this.masked.displayValue;
}
/** Starts listening to element events */
_proto._bindEvents = function _bindEvents() {
_bindEvents() {
this.el.bindEvents({

@@ -76,19 +117,31 @@ selectionChange: this._saveSelection,

/** Stops listening to element events */;
_proto._unbindEvents = function _unbindEvents() {
/** Stops listening to element events */
_unbindEvents() {
if (this.el) this.el.unbindEvents();
}
/** Fires custom event */;
_proto._fireEvent = function _fireEvent(ev, e) {
var listeners = this._listeners[ev];
/** Fires custom event */
_fireEvent(ev, e) {
const listeners = this._listeners[ev];
if (!listeners) return;
listeners.forEach(function (l) {
return l(e);
});
listeners.forEach(l => l(e));
}
/** Current selection start */;
/** Current selection start */
get selectionStart() {
return this._cursorChanging ? this._changingCursorPos : this.el.selectionStart;
}
/** Current cursor position */
get cursorPos() {
return this._cursorChanging ? this._changingCursorPos : this.el.selectionEnd;
}
set cursorPos(pos) {
if (!this.el || !this.el.isActive) return;
this.el.select(pos, pos);
this._saveSelection();
}
/** Stores current selection */
_proto._saveSelection = function _saveSelection( /* ev */
_saveSelection( /* ev */
) {

@@ -105,4 +158,4 @@ if (this.displayValue !== this.el.value) {

/** Syncronizes model value from view */;
_proto.updateValue = function updateValue() {
/** Syncronizes model value from view */
updateValue() {
this.masked.value = this.el.value;

@@ -112,8 +165,8 @@ this._value = this.masked.value;

/** Syncronizes view from model value, fires change events */;
_proto.updateControl = function updateControl() {
var newUnmaskedValue = this.masked.unmaskedValue;
var newValue = this.masked.value;
var newDisplayValue = this.displayValue;
var isChanged = this.unmaskedValue !== newUnmaskedValue || this.value !== newValue;
/** Syncronizes view from model value, fires change events */
updateControl() {
const newUnmaskedValue = this.masked.unmaskedValue;
const newValue = this.masked.value;
const newDisplayValue = this.displayValue;
const isChanged = this.unmaskedValue !== newUnmaskedValue || this.value !== newValue;
this._unmaskedValue = newUnmaskedValue;

@@ -125,8 +178,10 @@ this._value = newValue;

/** Updates options with deep equal check, recreates {@link Masked} model if mask type changes */;
_proto.updateOptions = function updateOptions(opts) {
var mask = opts.mask,
restOpts = _objectWithoutPropertiesLoose(opts, _excluded);
var updateMask = !this.maskEquals(mask);
var updateOpts = !objectIncludes(this.masked, restOpts);
/** Updates options with deep equal check, recreates {@link Masked} model if mask type changes */
updateOptions(opts) {
const {
mask,
...restOpts
} = opts;
const updateMask = !this.maskEquals(mask);
const updateOpts = !objectIncludes(this.masked, restOpts);
if (updateMask) this.mask = mask;

@@ -138,4 +193,4 @@ if (updateOpts) this.masked.updateOptions(restOpts); // TODO

/** Updates cursor */;
_proto.updateCursor = function updateCursor(cursorPos) {
/** Updates cursor */
updateCursor(cursorPos) {
if (cursorPos == null) return;

@@ -148,16 +203,15 @@ this.cursorPos = cursorPos;

/** Delays cursor update to support mobile browsers */;
_proto._delayUpdateCursor = function _delayUpdateCursor(cursorPos) {
var _this = this;
/** Delays cursor update to support mobile browsers */
_delayUpdateCursor(cursorPos) {
this._abortUpdateCursor();
this._changingCursorPos = cursorPos;
this._cursorChanging = setTimeout(function () {
if (!_this.el) return; // if was destroyed
_this.cursorPos = _this._changingCursorPos;
_this._abortUpdateCursor();
this._cursorChanging = setTimeout(() => {
if (!this.el) return; // if was destroyed
this.cursorPos = this._changingCursorPos;
this._abortUpdateCursor();
}, 10);
}
/** Fires custom events */;
_proto._fireChangeEvents = function _fireChangeEvents() {
/** Fires custom events */
_fireChangeEvents() {
this._fireEvent('accept', this._inputEvent);

@@ -167,4 +221,4 @@ if (this.masked.isComplete) this._fireEvent('complete', this._inputEvent);

/** Aborts delayed cursor update */;
_proto._abortUpdateCursor = function _abortUpdateCursor() {
/** Aborts delayed cursor update */
_abortUpdateCursor() {
if (this._cursorChanging) {

@@ -176,9 +230,9 @@ clearTimeout(this._cursorChanging);

/** Aligns cursor to nearest available position */;
_proto.alignCursor = function alignCursor() {
/** Aligns cursor to nearest available position */
alignCursor() {
this.cursorPos = this.masked.nearestInputPos(this.masked.nearestInputPos(this.cursorPos, DIRECTION.LEFT));
}
/** Aligns cursor only if selection is empty */;
_proto.alignCursorFriendly = function alignCursorFriendly() {
/** Aligns cursor only if selection is empty */
alignCursorFriendly() {
if (this.selectionStart !== this.cursorPos) return; // skip if range is selected

@@ -188,4 +242,4 @@ this.alignCursor();

/** Adds listener on custom event */;
_proto.on = function on(ev, handler) {
/** Adds listener on custom event */
on(ev, handler) {
if (!this._listeners[ev]) this._listeners[ev] = [];

@@ -196,5 +250,4 @@ this._listeners[ev].push(handler);

/** Removes custom event listener */;
_proto.off = function off(ev, handler) {
var _context, _context2;
/** Removes custom event listener */
off(ev, handler) {
if (!this._listeners[ev]) return this;

@@ -205,10 +258,9 @@ if (!handler) {

}
var hIndex = _indexOfInstanceProperty(_context = this._listeners[ev]).call(_context, handler);
if (hIndex >= 0) _spliceInstanceProperty(_context2 = this._listeners[ev]).call(_context2, hIndex, 1);
const hIndex = this._listeners[ev].indexOf(handler);
if (hIndex >= 0) this._listeners[ev].splice(hIndex, 1);
return this;
}
/** Handles view input event */;
_proto._onInput = function _onInput(e) {
var _context3;
/** Handles view input event */
_onInput(e) {
this._inputEvent = e;

@@ -219,3 +271,3 @@ this._abortUpdateCursor();

if (!this._selection) return this.updateValue();
var details = new ActionDetails({
const details = new ActionDetails({
// new state

@@ -228,4 +280,4 @@ value: this.el.value,

});
var oldRawValue = this.masked.rawInputValue;
var offset = _spliceInstanceProperty(_context3 = this.masked).call(_context3, details.startChangePos, details.removed.length, details.inserted, details.removeDirection, {
const oldRawValue = this.masked.rawInputValue;
const offset = this.masked.splice(details.startChangePos, details.removed.length, details.inserted, details.removeDirection, {
input: true,

@@ -237,4 +289,4 @@ raw: true

// otherwise we still need to align with NONE (to get out from fixed symbols for instance)
var removeDirection = oldRawValue === this.masked.rawInputValue ? details.removeDirection : DIRECTION.NONE;
var cursorPos = this.masked.nearestInputPos(details.startChangePos + offset, removeDirection);
const removeDirection = oldRawValue === this.masked.rawInputValue ? details.removeDirection : DIRECTION.NONE;
let cursorPos = this.masked.nearestInputPos(details.startChangePos + offset, removeDirection);
if (removeDirection !== DIRECTION.NONE) cursorPos = this.masked.nearestInputPos(cursorPos, DIRECTION.NONE);

@@ -246,4 +298,4 @@ this.updateControl();

/** Handles view change event and commits model value */;
_proto._onChange = function _onChange() {
/** Handles view change event and commits model value */
_onChange() {
if (this.displayValue !== this.el.value) {

@@ -257,4 +309,4 @@ this.updateValue();

/** Handles view drop event, prevents by default */;
_proto._onDrop = function _onDrop(ev) {
/** Handles view drop event, prevents by default */
_onDrop(ev) {
ev.preventDefault();

@@ -264,106 +316,21 @@ ev.stopPropagation();

/** Restore last selection on focus */;
_proto._onFocus = function _onFocus(ev) {
/** Restore last selection on focus */
_onFocus(ev) {
this.alignCursorFriendly();
}
/** Restore last selection on focus */;
_proto._onClick = function _onClick(ev) {
/** Restore last selection on focus */
_onClick(ev) {
this.alignCursorFriendly();
}
/** Unbind view events and removes element reference */;
_proto.destroy = function destroy() {
/** Unbind view events and removes element reference */
destroy() {
this._unbindEvents();
this._listeners.length = 0;
delete this.el;
};
_createClass(InputMask, [{
key: "mask",
get: function get() {
return this.masked.mask;
},
set: function set(mask) {
if (this.maskEquals(mask)) return;
if (!(mask instanceof IMask.Masked) && this.masked.constructor === maskedClass(mask)) {
// TODO "any" no idea
this.masked.updateOptions({
mask: mask
});
return;
}
var masked = mask instanceof IMask.Masked ? mask : createMask({
mask: mask
});
masked.unmaskedValue = this.masked.unmaskedValue;
this.masked = masked;
}
/** Raw value */
}, {
key: "value",
get: function get() {
return this._value;
},
set: function set(str) {
if (this.value === str) return;
this.masked.value = str;
this.updateControl();
this.alignCursor();
}
/** Unmasked value */
}, {
key: "unmaskedValue",
get: function get() {
return this._unmaskedValue;
},
set: function set(str) {
if (this.unmaskedValue === str) return;
this.masked.unmaskedValue = str;
this.updateControl();
this.alignCursor();
}
/** Typed unmasked value */
}, {
key: "typedValue",
get: function get() {
return this.masked.typedValue;
},
set: function set(val) {
if (this.masked.typedValueEquals(val)) return;
this.masked.typedValue = val;
this.updateControl();
this.alignCursor();
}
/** Display value */
}, {
key: "displayValue",
get: function get() {
return this.masked.displayValue;
}
}, {
key: "selectionStart",
get: function get() {
return this._cursorChanging ? this._changingCursorPos : this.el.selectionStart;
}
/** Current cursor position */
}, {
key: "cursorPos",
get: function get() {
return this._cursorChanging ? this._changingCursorPos : this.el.selectionEnd;
},
set: function set(pos) {
if (!this.el || !this.el.isActive) return;
this.el.select(pos, pos);
this._saveSelection();
}
}]);
return InputMask;
}();
}
}
IMask.InputMask = InputMask;
export { InputMask as default };

@@ -1,55 +0,50 @@

import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import IMask from '../core/holder.js';
/** Generic element API to use with mask */
var MaskElement = /*#__PURE__*/function () {
function MaskElement() {}
var _proto = MaskElement.prototype;
class MaskElement {
/** */
/** */
/** */
/** Safely returns selection start */
get selectionStart() {
let start;
try {
start = this._unsafeSelectionStart;
} catch {}
return start != null ? start : this.value.length;
}
/** Safely returns selection end */
get selectionEnd() {
let end;
try {
end = this._unsafeSelectionEnd;
} catch {}
return end != null ? end : this.value.length;
}
/** Safely sets element selection */
_proto.select = function select(start, end) {
select(start, end) {
if (start == null || end == null || start === this.selectionStart && end === this.selectionEnd) return;
try {
this._unsafeSelect(start, end);
} catch (_unused) {}
} catch {}
}
/** */;
_createClass(MaskElement, [{
key: "selectionStart",
get: /** */
/** */
get isActive() {
return false;
}
/** */
/** */
/** */
/** */
/** */
}
/** Safely returns selection start */
function get() {
var start;
try {
start = this._unsafeSelectionStart;
} catch (_unused2) {}
return start != null ? start : this.value.length;
}
/** Safely returns selection end */
}, {
key: "selectionEnd",
get: function get() {
var end;
try {
end = this._unsafeSelectionEnd;
} catch (_unused3) {}
return end != null ? end : this.value.length;
}
}, {
key: "isActive",
get: function get() {
return false;
}
/** */
}]);
return MaskElement;
}();
IMask.MaskElement = MaskElement;
export { MaskElement as default };

@@ -1,11 +0,5 @@

import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import { _ as _Object$assign } from '../assign-c82cbe95.js';
import { _ as _sliceInstanceProperty } from '../slice-3858f58a.js';
import { D as DIRECTION } from '../utils-e384b131.js';
import '../object-keys-53d74329.js';
import '../classof-c2d10e36.js';
import '../keys-e9789594.js';
import { DIRECTION } from './utils.js';
/** Provides details of changing input */
var ActionDetails = /*#__PURE__*/function () {
class ActionDetails {
/** Current input value */

@@ -19,8 +13,7 @@

function ActionDetails(opts) {
_Object$assign(this, opts);
constructor(opts) {
Object.assign(this, opts);
// double check if left part was changed (autofilling, other non-standard input triggers)
while (_sliceInstanceProperty(_context = this.value).call(_context, 0, this.startChangePos) !== _sliceInstanceProperty(_context2 = this.oldValue).call(_context2, 0, this.startChangePos)) {
var _context, _context2;
while (this.value.slice(0, this.startChangePos) !== this.oldValue.slice(0, this.startChangePos)) {
--this.oldSelection.start;

@@ -31,68 +24,50 @@ }

/** Start changing position */
_createClass(ActionDetails, [{
key: "startChangePos",
get: function get() {
return Math.min(this.cursorPos, this.oldSelection.start);
}
get startChangePos() {
return Math.min(this.cursorPos, this.oldSelection.start);
}
/** Inserted symbols count */
}, {
key: "insertedCount",
get: function get() {
return this.cursorPos - this.startChangePos;
}
/** Inserted symbols count */
get insertedCount() {
return this.cursorPos - this.startChangePos;
}
/** Inserted symbols */
}, {
key: "inserted",
get: function get() {
return this.value.substr(this.startChangePos, this.insertedCount);
}
/** Inserted symbols */
get inserted() {
return this.value.substr(this.startChangePos, this.insertedCount);
}
/** Removed symbols count */
}, {
key: "removedCount",
get: function get() {
// Math.max for opposite operation
return Math.max(this.oldSelection.end - this.startChangePos ||
// for Delete
this.oldValue.length - this.value.length, 0);
}
/** Removed symbols count */
get removedCount() {
// Math.max for opposite operation
return Math.max(this.oldSelection.end - this.startChangePos ||
// for Delete
this.oldValue.length - this.value.length, 0);
}
/** Removed symbols */
}, {
key: "removed",
get: function get() {
return this.oldValue.substr(this.startChangePos, this.removedCount);
}
/** Removed symbols */
get removed() {
return this.oldValue.substr(this.startChangePos, this.removedCount);
}
/** Unchanged head symbols */
}, {
key: "head",
get: function get() {
return this.value.substring(0, this.startChangePos);
}
/** Unchanged head symbols */
get head() {
return this.value.substring(0, this.startChangePos);
}
/** Unchanged tail symbols */
}, {
key: "tail",
get: function get() {
return this.value.substring(this.startChangePos + this.insertedCount);
}
/** Unchanged tail symbols */
get tail() {
return this.value.substring(this.startChangePos + this.insertedCount);
}
/** Remove direction */
}, {
key: "removeDirection",
get: function get() {
if (!this.removedCount || this.insertedCount) return DIRECTION.NONE;
/** Remove direction */
get removeDirection() {
if (!this.removedCount || this.insertedCount) return DIRECTION.NONE;
// align right if delete at right
return (this.oldSelection.end === this.cursorPos || this.oldSelection.start === this.cursorPos) &&
// if not range removed (event with backspace)
this.oldSelection.end === this.oldSelection.start ? DIRECTION.RIGHT : DIRECTION.LEFT;
}
}]);
return ActionDetails;
}();
// align right if delete at right
return (this.oldSelection.end === this.cursorPos || this.oldSelection.start === this.cursorPos) &&
// if not range removed (event with backspace)
this.oldSelection.end === this.oldSelection.start ? DIRECTION.RIGHT : DIRECTION.LEFT;
}
}
export { ActionDetails as default };

@@ -1,17 +0,18 @@

import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import { _ as _Object$assign } from '../assign-c82cbe95.js';
import IMask from './holder.js';
import '../object-keys-53d74329.js';
/** Provides details of changing model value */
var ChangeDetails = /*#__PURE__*/function () {
class ChangeDetails {
/** Inserted symbols */
/** Can skip chars */
/** Additional offset if any changes occurred before tail */
/** Raw inserted is used by dynamic mask */
ChangeDetails.normalize = function normalize(prep) {
static normalize(prep) {
return Array.isArray(prep) ? prep : [prep, new ChangeDetails()];
};
function ChangeDetails(details) {
_Object$assign(this, {
}
constructor(details) {
Object.assign(this, {
inserted: '',

@@ -25,4 +26,3 @@ rawInserted: '',

/** Aggregate changes */
var _proto = ChangeDetails.prototype;
_proto.aggregate = function aggregate(details) {
aggregate(details) {
this.rawInserted += details.rawInserted;

@@ -35,13 +35,9 @@ this.skip = this.skip || details.skip;

/** Total offset considering all changes */;
_createClass(ChangeDetails, [{
key: "offset",
get: function get() {
return this.tailShift + this.inserted.length;
}
}]);
return ChangeDetails;
}();
/** Total offset considering all changes */
get offset() {
return this.tailShift + this.inserted.length;
}
}
IMask.ChangeDetails = ChangeDetails;
export { ChangeDetails as default };

@@ -1,9 +0,3 @@

import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import { _ as _sliceInstanceProperty } from '../slice-3858f58a.js';
import { _ as _Object$assign } from '../assign-c82cbe95.js';
import '../object-keys-53d74329.js';
import '../classof-c2d10e36.js';
/** Provides details of continuous extracted tail */
var ContinuousTailDetails = /*#__PURE__*/function () {
class ContinuousTailDetails {
/** Tail value as string */

@@ -15,3 +9,3 @@

function ContinuousTailDetails(value, from, stop) {
constructor(value, from, stop) {
if (value === void 0) {

@@ -27,44 +21,37 @@ value = '';

}
var _proto = ContinuousTailDetails.prototype;
_proto.toString = function toString() {
toString() {
return this.value;
};
_proto.extend = function extend(tail) {
}
extend(tail) {
this.value += String(tail);
};
_proto.appendTo = function appendTo(masked) {
}
appendTo(masked) {
return masked.append(this.toString(), {
tail: true
}).aggregate(masked._appendPlaceholder());
};
_proto.unshift = function unshift(beforePos) {
var _context;
}
get state() {
return {
value: this.value,
from: this.from,
stop: this.stop
};
}
set state(state) {
Object.assign(this, state);
}
unshift(beforePos) {
if (!this.value.length || beforePos != null && this.from >= beforePos) return '';
var shiftChar = this.value[0];
this.value = _sliceInstanceProperty(_context = this.value).call(_context, 1);
const shiftChar = this.value[0];
this.value = this.value.slice(1);
return shiftChar;
};
_proto.shift = function shift() {
var _context2;
}
shift() {
if (!this.value.length) return '';
var shiftChar = this.value[this.value.length - 1];
this.value = _sliceInstanceProperty(_context2 = this.value).call(_context2, 0, -1);
const shiftChar = this.value[this.value.length - 1];
this.value = this.value.slice(0, -1);
return shiftChar;
};
_createClass(ContinuousTailDetails, [{
key: "state",
get: function get() {
return {
value: this.value,
from: this.from,
stop: this.stop
};
},
set: function set(state) {
_Object$assign(this, state);
}
}]);
return ContinuousTailDetails;
}();
}
}
export { ContinuousTailDetails as default };

@@ -1,4 +0,82 @@

export { D as DIRECTION, e as escapeRegExp, f as forceDirection, d as isObject, i as isString, o as objectIncludes, p as pick } from '../utils-e384b131.js';
import '../keys-e9789594.js';
import '../object-keys-53d74329.js';
import '../classof-c2d10e36.js';
/** Checks if value is string */
function isString(str) {
return typeof str === 'string' || str instanceof String;
}
/** Checks if value is object */
function isObject(obj) {
var _obj$constructor;
return typeof obj === 'object' && obj != null && (obj == null || (_obj$constructor = obj.constructor) == null ? void 0 : _obj$constructor.name) === 'Object';
}
function pick(obj, keys) {
if (Array.isArray(keys)) return pick(obj, (_, k) => keys.includes(k));
return Object.entries(obj).reduce((acc, _ref) => {
let [k, v] = _ref;
if (keys(v, k)) acc[k] = v;
return acc;
}, {});
}
/** Direction */
const DIRECTION = {
NONE: 'NONE',
LEFT: 'LEFT',
FORCE_LEFT: 'FORCE_LEFT',
RIGHT: 'RIGHT',
FORCE_RIGHT: 'FORCE_RIGHT'
};
/** Direction */
function forceDirection(direction) {
switch (direction) {
case DIRECTION.LEFT:
return DIRECTION.FORCE_LEFT;
case DIRECTION.RIGHT:
return DIRECTION.FORCE_RIGHT;
default:
return direction;
}
}
/** Escapes regular expression control chars */
function escapeRegExp(str) {
return str.replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1');
}
// cloned from https://github.com/epoberezkin/fast-deep-equal with small changes
function objectIncludes(b, a) {
if (a === b) return true;
const arrA = Array.isArray(a),
arrB = Array.isArray(b);
let i;
if (arrA && arrB) {
if (a.length != b.length) return false;
for (i = 0; i < a.length; i++) if (!objectIncludes(a[i], b[i])) return false;
return true;
}
if (arrA != arrB) return false;
if (a && b && typeof a === 'object' && typeof b === 'object') {
const dateA = a instanceof Date,
dateB = b instanceof Date;
if (dateA && dateB) return a.getTime() == b.getTime();
if (dateA != dateB) return false;
const regexpA = a instanceof RegExp,
regexpB = b instanceof RegExp;
if (regexpA && regexpB) return a.toString() == b.toString();
if (regexpA != regexpB) return false;
const keys = Object.keys(a);
// if (keys.length !== Object.keys(b).length) return false;
for (i = 0; i < keys.length; i++) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
for (i = 0; i < keys.length; i++) if (!objectIncludes(b[keys[i]], a[keys[i]])) return false;
return true;
} else if (a && b && typeof a === 'function' && typeof b === 'function') {
return a.toString() === b.toString();
}
return false;
}
/** Selection range */
export { DIRECTION, escapeRegExp, forceDirection, isObject, isString, objectIncludes, pick };
import './controls/input.js';
import IMask from './core/holder.js';
import '@babel/runtime-corejs3/helpers/objectWithoutPropertiesLoose';
import '@babel/runtime-corejs3/helpers/createClass';
import './index-of-358e281e.js';
import './object-keys-53d74329.js';
import './utils-e384b131.js';
import './classof-c2d10e36.js';
import './keys-e9789594.js';
import './splice-dccbddd9.js';
import './slice-3858f58a.js';
import './does-not-exceed-safe-integer-d06d288d.js';
import './array-species-create-349ea110.js';
import './delete-property-or-throw-2b53787c.js';
import './core/utils.js';
import './core/action-details.js';
import './assign-c82cbe95.js';
import './masked/factory.js';
import '@babel/runtime-corejs3/helpers/extends';
import './controls/mask-element.js';
import './controls/html-input-mask-element.js';
import '@babel/runtime-corejs3/helpers/inheritsLoose';
import './controls/html-mask-element.js';

@@ -23,0 +9,0 @@ import './controls/html-contenteditable-mask-element.js';

@@ -1,2 +0,1 @@

import { _ as _export, z as global$1, g as getDefaultExportFromCjs } from './object-keys-53d74329.js';
export { default as InputMask } from './controls/input.js';

@@ -9,3 +8,3 @@ import IMask from './core/holder.js';

export { default as ChangeDetails } from './core/change-details.js';
export { D as DIRECTION, f as forceDirection } from './utils-e384b131.js';
export { DIRECTION, forceDirection } from './core/utils.js';
export { default as Masked } from './masked/base.js';

@@ -23,60 +22,12 @@ export { default as MaskedDate } from './masked/date.js';

export { PIPE_TYPE, createPipe, pipe } from './masked/pipe.js';
export { M as MaskedRange } from './range-8d4c25a9.js';
export { default as MaskedRange } from './masked/range.js';
export { default as MaskedRegExp } from './masked/regexp.js';
import '@babel/runtime-corejs3/helpers/objectWithoutPropertiesLoose';
import '@babel/runtime-corejs3/helpers/createClass';
import './index-of-358e281e.js';
import './classof-c2d10e36.js';
import './splice-dccbddd9.js';
import './slice-3858f58a.js';
import './does-not-exceed-safe-integer-d06d288d.js';
import './array-species-create-349ea110.js';
import './delete-property-or-throw-2b53787c.js';
import './core/action-details.js';
import './assign-c82cbe95.js';
import './keys-e9789594.js';
import '@babel/runtime-corejs3/helpers/extends';
import '@babel/runtime-corejs3/helpers/inheritsLoose';
import './core/continuous-tail-details.js';
import './map-4c47454e.js';
import './pad-end-35f0c153.js';
import './string-repeat-21c9f19e.js';
import './repeat-ac2db5c6.js';
import './sort-e1545525.js';
import './masked/pattern/cursor.js';
var $ = _export;
var global = global$1;
// `globalThis` object
// https://tc39.es/ecma262/#sec-globalthis
$({ global: true, forced: global.globalThis !== global }, {
globalThis: global
});
var globalThis$4 = global$1;
var parent$2 = globalThis$4;
var globalThis$3 = parent$2;
var parent$1 = globalThis$3;
var globalThis$2 = parent$1;
// TODO: remove from `core-js@4`
var parent = globalThis$2;
var globalThis$1 = parent;
var globalThis = globalThis$1;
var _globalThis = /*@__PURE__*/getDefaultExportFromCjs(globalThis);
try {
_globalThis.IMask = IMask;
} catch (_unused) {}
globalThis.IMask = IMask;
} catch {}
export { IMask as default };

@@ -1,13 +0,5 @@

import _extends from '@babel/runtime-corejs3/helpers/extends';
import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import { _ as _Object$keys } from '../keys-e9789594.js';
import { _ as _Object$assign } from '../assign-c82cbe95.js';
import { _ as _sliceInstanceProperty } from '../slice-3858f58a.js';
import { _ as _indexOfInstanceProperty } from '../index-of-358e281e.js';
import { i as isString, D as DIRECTION, f as forceDirection, _ as _includesInstanceProperty } from '../utils-e384b131.js';
import ChangeDetails from '../core/change-details.js';
import ContinuousTailDetails from '../core/continuous-tail-details.js';
import { isString, DIRECTION, forceDirection } from '../core/utils.js';
import IMask from '../core/holder.js';
import '../object-keys-53d74329.js';
import '../classof-c2d10e36.js';

@@ -19,4 +11,5 @@ /** Append flags */

// see https://github.com/microsoft/TypeScript/issues/6223
/** Provides common masking stuff */
var Masked = /*#__PURE__*/function () {
class Masked {
/** */

@@ -46,5 +39,8 @@

function Masked(opts) {
constructor(opts) {
this._value = '';
this._update(_extends({}, Masked.DEFAULTS, opts));
this._update({
...Masked.DEFAULTS,
...opts
});
this._initialized = true;

@@ -54,20 +50,38 @@ }

/** Sets and applies new options */
var _proto = Masked.prototype;
_proto.updateOptions = function updateOptions(opts) {
if (!_Object$keys(opts).length) return;
updateOptions(opts) {
if (!Object.keys(opts).length) return;
this.withValueRefresh(this._update.bind(this, opts));
}
/** Sets new options */;
_proto._update = function _update(opts) {
_Object$assign(this, opts);
/** Sets new options */
_update(opts) {
Object.assign(this, opts);
}
/** Mask state */;
/** Mask state */
get state() {
return {
_value: this.value,
_rawInputValue: this.rawInputValue
};
}
set state(state) {
this._value = state._value;
}
/** Resets value */
_proto.reset = function reset() {
reset() {
this._value = '';
};
}
get value() {
return this._value;
}
set value(value) {
this.resolve(value, {
input: true
});
}
/** Resolve new value */
_proto.resolve = function resolve(value, flags) {
resolve(value, flags) {
if (flags === void 0) {

@@ -81,8 +95,46 @@ flags = {

this.doCommit();
};
}
get unmaskedValue() {
return this.value;
}
set unmaskedValue(value) {
this.resolve(value, {});
}
get typedValue() {
return this.parse ? this.parse(this.value, this) : this.unmaskedValue;
}
set typedValue(value) {
if (this.format) {
this.value = this.format(value, this);
} else {
this.unmaskedValue = String(value);
}
}
/** Value that includes raw user input */
get rawInputValue() {
return this.extractInput(0, this.displayValue.length, {
raw: true
});
}
set rawInputValue(value) {
this.resolve(value, {
raw: true
});
}
get displayValue() {
return this.value;
}
get isComplete() {
return true;
}
get isFilled() {
return this.isComplete;
}
/** Finds nearest input position in direction */
_proto.nearestInputPos = function nearestInputPos(cursorPos, direction) {
nearestInputPos(cursorPos, direction) {
return cursorPos;
};
_proto.totalInputPositions = function totalInputPositions(fromPos, toPos) {
}
totalInputPositions(fromPos, toPos) {
if (fromPos === void 0) {

@@ -97,5 +149,4 @@ fromPos = 0;

/** Extracts value in range considering flags */;
_proto.extractInput = function extractInput(fromPos, toPos, flags) {
var _context;
/** Extracts value in range considering flags */
extractInput(fromPos, toPos, flags) {
if (fromPos === void 0) {

@@ -107,7 +158,7 @@ fromPos = 0;

}
return _sliceInstanceProperty(_context = this.displayValue).call(_context, fromPos, toPos);
return this.displayValue.slice(fromPos, toPos);
}
/** Extracts tail in range */;
_proto.extractTail = function extractTail(fromPos, toPos) {
/** Extracts tail in range */
extractTail(fromPos, toPos) {
if (fromPos === void 0) {

@@ -122,4 +173,4 @@ fromPos = 0;

/** Appends tail */;
_proto.appendTail = function appendTail(tail) {
/** Appends tail */
appendTail(tail) {
if (isString(tail)) tail = new ContinuousTailDetails(String(tail));

@@ -129,4 +180,4 @@ return tail.appendTo(this);

/** Appends char */;
_proto._appendCharRaw = function _appendCharRaw(ch, flags) {
/** Appends char */
_appendCharRaw(ch, flags) {
if (!ch) return new ChangeDetails();

@@ -140,19 +191,17 @@ this._value += ch;

/** Appends char */;
_proto._appendChar = function _appendChar(ch, flags, checkTail) {
/** Appends char */
_appendChar(ch, flags, checkTail) {
if (flags === void 0) {
flags = {};
}
var consistentState = this.state;
var details;
var _this$doPrepareChar = this.doPrepareChar(ch, flags);
ch = _this$doPrepareChar[0];
details = _this$doPrepareChar[1];
const consistentState = this.state;
let details;
[ch, details] = this.doPrepareChar(ch, flags);
details = details.aggregate(this._appendCharRaw(ch, flags));
if (details.inserted) {
var consistentTail;
var appended = this.doValidate(flags) !== false;
let consistentTail;
let appended = this.doValidate(flags) !== false;
if (appended && checkTail != null) {
// validation ok, check tail
var beforeTailState = this.state;
const beforeTailState = this.state;
if (this.overwrite === true) {

@@ -162,3 +211,3 @@ consistentTail = checkTail.state;

}
var tailDetails = this.appendTail(checkTail);
let tailDetails = this.appendTail(checkTail);
appended = tailDetails.rawInserted === checkTail.toString();

@@ -189,23 +238,21 @@

/** Appends optional placeholder at the end */;
_proto._appendPlaceholder = function _appendPlaceholder() {
/** Appends optional placeholder at the end */
_appendPlaceholder() {
return new ChangeDetails();
}
/** Appends optional eager placeholder at the end */;
_proto._appendEager = function _appendEager() {
/** Appends optional eager placeholder at the end */
_appendEager() {
return new ChangeDetails();
}
/** Appends symbols considering flags */;
_proto.append = function append(str, flags, tail) {
/** Appends symbols considering flags */
append(str, flags, tail) {
if (!isString(str)) throw new Error('value should be string');
var checkTail = isString(tail) ? new ContinuousTailDetails(String(tail)) : tail;
const checkTail = isString(tail) ? new ContinuousTailDetails(String(tail)) : tail;
if (flags != null && flags.tail) flags._beforeTailState = this.state;
var details;
var _this$doPrepare = this.doPrepare(str, flags);
str = _this$doPrepare[0];
details = _this$doPrepare[1];
for (var ci = 0; ci < str.length; ++ci) {
var d = this._appendChar(str[ci], flags, checkTail);
let details;
[str, details] = this.doPrepare(str, flags);
for (let ci = 0; ci < str.length; ++ci) {
const d = this._appendChar(str[ci], flags, checkTail);
if (!d.rawInserted && !this.doSkipInvalid(str[ci], flags, checkTail)) break;

@@ -227,5 +274,4 @@ details.aggregate(d);

return details;
};
_proto.remove = function remove(fromPos, toPos) {
var _context2, _context3;
}
remove(fromPos, toPos) {
if (fromPos === void 0) {

@@ -237,36 +283,36 @@ fromPos = 0;

}
this._value = _sliceInstanceProperty(_context2 = this.displayValue).call(_context2, 0, fromPos) + _sliceInstanceProperty(_context3 = this.displayValue).call(_context3, toPos);
this._value = this.displayValue.slice(0, fromPos) + this.displayValue.slice(toPos);
return new ChangeDetails();
}
/** Calls function and reapplies current value */;
_proto.withValueRefresh = function withValueRefresh(fn) {
/** Calls function and reapplies current value */
withValueRefresh(fn) {
if (this._refreshing || !this._initialized) return fn();
this._refreshing = true;
var rawInput = this.rawInputValue;
var value = this.value;
var ret = fn();
const rawInput = this.rawInputValue;
const value = this.value;
const ret = fn();
this.rawInputValue = rawInput;
// append lost trailing chars at the end
if (this.value && this.value !== value && _indexOfInstanceProperty(value).call(value, this.value) === 0) {
this.append(_sliceInstanceProperty(value).call(value, this.displayValue.length), {}, '');
if (this.value && this.value !== value && value.indexOf(this.value) === 0) {
this.append(value.slice(this.displayValue.length), {}, '');
}
delete this._refreshing;
return ret;
};
_proto.runIsolated = function runIsolated(fn) {
}
runIsolated(fn) {
if (this._isolated || !this._initialized) return fn(this);
this._isolated = true;
var state = this.state;
var ret = fn(this);
const state = this.state;
const ret = fn(this);
this.state = state;
delete this._isolated;
return ret;
};
_proto.doSkipInvalid = function doSkipInvalid(ch, flags, checkTail) {
}
doSkipInvalid(ch, flags, checkTail) {
return Boolean(this.skipInvalid);
}
/** Prepares string before mask processing */;
_proto.doPrepare = function doPrepare(str, flags) {
/** Prepares string before mask processing */
doPrepare(str, flags) {
if (flags === void 0) {

@@ -278,4 +324,4 @@ flags = {};

/** Prepares each char before mask processing */;
_proto.doPrepareChar = function doPrepareChar(str, flags) {
/** Prepares each char before mask processing */
doPrepareChar(str, flags) {
if (flags === void 0) {

@@ -287,12 +333,12 @@ flags = {};

/** Validates if value is acceptable */;
_proto.doValidate = function doValidate(flags) {
/** Validates if value is acceptable */
doValidate(flags) {
return (!this.validate || this.validate(this.value, this, flags)) && (!this.parent || this.parent.doValidate(flags));
}
/** Does additional processing at the end of editing */;
_proto.doCommit = function doCommit() {
/** Does additional processing at the end of editing */
doCommit() {
if (this.commit) this.commit(this.value, this);
};
_proto.splice = function splice(start, deleteCount, inserted, removeDirection, flags) {
}
splice(start, deleteCount, inserted, removeDirection, flags) {
if (removeDirection === void 0) {

@@ -306,6 +352,6 @@ removeDirection = DIRECTION.NONE;

}
var tailPos = start + deleteCount;
var tail = this.extractTail(tailPos);
var eagerRemove = this.eager === true || this.eager === 'remove';
var oldRawValue;
const tailPos = start + deleteCount;
const tail = this.extractTail(tailPos);
const eagerRemove = this.eager === true || this.eager === 'remove';
let oldRawValue;
if (eagerRemove) {

@@ -317,4 +363,4 @@ removeDirection = forceDirection(removeDirection);

}
var startChangePos = start;
var details = new ChangeDetails();
let startChangePos = start;
const details = new ChangeDetails();

@@ -331,3 +377,3 @@ // if it is just deletion without insertion

if (removeDirection === DIRECTION.FORCE_LEFT) {
var valLength;
let valLength;
while (oldRawValue === this.rawInputValue && (valLength = this.displayValue.length)) {

@@ -343,84 +389,11 @@ details.aggregate(new ChangeDetails({

return details.aggregate(this.append(inserted, flags, tail));
};
_proto.maskEquals = function maskEquals(mask) {
}
maskEquals(mask) {
return this.mask === mask;
};
_proto.typedValueEquals = function typedValueEquals(value) {
var _context4, _context5;
var tval = this.typedValue;
return value === tval || _includesInstanceProperty(_context4 = Masked.EMPTY_VALUES).call(_context4, value) && _includesInstanceProperty(_context5 = Masked.EMPTY_VALUES).call(_context5, tval) || (this.format ? this.format(value, this) === this.format(this.typedValue, this) : false);
};
_createClass(Masked, [{
key: "state",
get: function get() {
return {
_value: this.value,
_rawInputValue: this.rawInputValue
};
},
set: function set(state) {
this._value = state._value;
}
}, {
key: "value",
get: function get() {
return this._value;
},
set: function set(value) {
this.resolve(value, {
input: true
});
}
}, {
key: "unmaskedValue",
get: function get() {
return this.value;
},
set: function set(value) {
this.resolve(value, {});
}
}, {
key: "typedValue",
get: function get() {
return this.parse ? this.parse(this.value, this) : this.unmaskedValue;
},
set: function set(value) {
if (this.format) {
this.value = this.format(value, this);
} else {
this.unmaskedValue = String(value);
}
}
/** Value that includes raw user input */
}, {
key: "rawInputValue",
get: function get() {
return this.extractInput(0, this.displayValue.length, {
raw: true
});
},
set: function set(value) {
this.resolve(value, {
raw: true
});
}
}, {
key: "displayValue",
get: function get() {
return this.value;
}
}, {
key: "isComplete",
get: function get() {
return true;
}
}, {
key: "isFilled",
get: function get() {
return this.isComplete;
}
}]);
return Masked;
}();
}
typedValueEquals(value) {
const tval = this.typedValue;
return value === tval || Masked.EMPTY_VALUES.includes(value) && Masked.EMPTY_VALUES.includes(tval) || (this.format ? this.format(value, this) === this.format(this.typedValue, this) : false);
}
}
Masked.DEFAULTS = {

@@ -427,0 +400,0 @@ skipInvalid: true

@@ -1,22 +0,5 @@

import _extends from '@babel/runtime-corejs3/helpers/extends';
import _objectWithoutPropertiesLoose from '@babel/runtime-corejs3/helpers/objectWithoutPropertiesLoose';
import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import _inheritsLoose from '@babel/runtime-corejs3/helpers/inheritsLoose';
import { _ as _Object$assign } from '../assign-c82cbe95.js';
import { _ as _Object$keys } from '../keys-e9789594.js';
import { _ as _indexOfInstanceProperty } from '../index-of-358e281e.js';
import { M as MaskedRange, _ as _padStartInstanceProperty } from '../range-8d4c25a9.js';
import { _ as _mapInstanceProperty } from '../map-4c47454e.js';
import MaskedPattern from './pattern.js';
import MaskedRange from './range.js';
import IMask from '../core/holder.js';
import { i as isString } from '../utils-e384b131.js';
import '../object-keys-53d74329.js';
import '../classof-c2d10e36.js';
import '../pad-end-35f0c153.js';
import '../string-repeat-21c9f19e.js';
import '../slice-3858f58a.js';
import '../repeat-ac2db5c6.js';
import '../array-species-create-349ea110.js';
import '../sort-e1545525.js';
import '../delete-property-or-throw-2b53787c.js';
import { isString } from '../core/utils.js';
import '../core/change-details.js';

@@ -27,4 +10,2 @@ import './base.js';

import './pattern/chunk-tail-details.js';
import '../splice-dccbddd9.js';
import '../does-not-exceed-safe-integer-d06d288d.js';
import './pattern/cursor.js';

@@ -35,7 +16,4 @@ import './pattern/fixed-definition.js';

var _excluded = ["mask", "pattern"],
_excluded2 = ["mask", "pattern", "blocks"];
/** Date mask */
var MaskedDate = /*#__PURE__*/function (_MaskedPattern) {
_inheritsLoose(MaskedDate, _MaskedPattern);
class MaskedDate extends MaskedPattern {
/** Pattern mask for date according to {@link MaskedDate#format} */

@@ -53,22 +31,30 @@

function MaskedDate(opts) {
var _opts = _extends({}, MaskedDate.DEFAULTS, opts),
mask = _opts.mask,
pattern = _opts.pattern,
patternOpts = _objectWithoutPropertiesLoose(_opts, _excluded);
return _MaskedPattern.call(this, _extends({}, patternOpts, {
constructor(opts) {
const {
mask,
pattern,
...patternOpts
} = {
...MaskedDate.DEFAULTS,
...opts
};
super({
...patternOpts,
mask: isString(mask) ? mask : pattern
})) || this;
});
}
var _proto = MaskedDate.prototype;
_proto.updateOptions = function updateOptions(opts) {
_MaskedPattern.prototype.updateOptions.call(this, opts);
};
_proto._update = function _update(opts) {
var _MaskedDate$DEFAULTS$ = _extends({}, MaskedDate.DEFAULTS, opts),
mask = _MaskedDate$DEFAULTS$.mask,
pattern = _MaskedDate$DEFAULTS$.pattern,
blocks = _MaskedDate$DEFAULTS$.blocks,
patternOpts = _objectWithoutPropertiesLoose(_MaskedDate$DEFAULTS$, _excluded2);
var patternBlocks = _Object$assign({}, MaskedDate.GET_DEFAULT_BLOCKS());
updateOptions(opts) {
super.updateOptions(opts);
}
_update(opts) {
const {
mask,
pattern,
blocks,
...patternOpts
} = {
...MaskedDate.DEFAULTS,
...opts
};
const patternBlocks = Object.assign({}, MaskedDate.GET_DEFAULT_BLOCKS());
// adjust year block

@@ -85,86 +71,73 @@ if (opts.min) patternBlocks.Y.from = opts.min.getFullYear();

}
_Object$assign(patternBlocks, this.blocks, blocks);
Object.assign(patternBlocks, this.blocks, blocks);
// add autofix
_Object$keys(patternBlocks).forEach(function (bk) {
var b = patternBlocks[bk];
Object.keys(patternBlocks).forEach(bk => {
const b = patternBlocks[bk];
if (!('autofix' in b) && 'autofix' in opts) b.autofix = opts.autofix;
});
_MaskedPattern.prototype._update.call(this, _extends({}, patternOpts, {
super._update({
...patternOpts,
mask: isString(mask) ? mask : pattern,
blocks: patternBlocks
}));
};
_proto.doValidate = function doValidate(flags) {
var date = this.date;
return _MaskedPattern.prototype.doValidate.call(this, flags) && (!this.isComplete || this.isDateExist(this.value) && date != null && (this.min == null || this.min <= date) && (this.max == null || date <= this.max));
});
}
doValidate(flags) {
const date = this.date;
return super.doValidate(flags) && (!this.isComplete || this.isDateExist(this.value) && date != null && (this.min == null || this.min <= date) && (this.max == null || date <= this.max));
}
/** Checks if date is exists */;
_proto.isDateExist = function isDateExist(str) {
var _context;
return _indexOfInstanceProperty(_context = this.format(this.parse(str, this), this)).call(_context, str) >= 0;
/** Checks if date is exists */
isDateExist(str) {
return this.format(this.parse(str, this), this).indexOf(str) >= 0;
}
/** Parsed Date */;
_proto.maskEquals = function maskEquals(mask) {
return mask === Date || _MaskedPattern.prototype.maskEquals.call(this, mask);
};
_createClass(MaskedDate, [{
key: "date",
get: function get() {
return this.typedValue;
},
set: function set(date) {
this.typedValue = date;
}
}, {
key: "typedValue",
get: function get() {
return this.isComplete ? _MaskedPattern.prototype.typedValue : null;
},
set: function set(value) {
this.typedValue = value;
}
}]);
return MaskedDate;
}(MaskedPattern);
MaskedDate.GET_DEFAULT_BLOCKS = function () {
return {
d: {
mask: MaskedRange,
from: 1,
to: 31,
maxLength: 2
},
m: {
mask: MaskedRange,
from: 1,
to: 12,
maxLength: 2
},
Y: {
mask: MaskedRange,
from: 1900,
to: 9999
}
};
};
/** Parsed Date */
get date() {
return this.typedValue;
}
set date(date) {
this.typedValue = date;
}
get typedValue() {
return this.isComplete ? super.typedValue : null;
}
set typedValue(value) {
super.typedValue = value;
}
maskEquals(mask) {
return mask === Date || super.maskEquals(mask);
}
}
MaskedDate.GET_DEFAULT_BLOCKS = () => ({
d: {
mask: MaskedRange,
from: 1,
to: 31,
maxLength: 2
},
m: {
mask: MaskedRange,
from: 1,
to: 12,
maxLength: 2
},
Y: {
mask: MaskedRange,
from: 1900,
to: 9999
}
});
MaskedDate.DEFAULTS = {
mask: Date,
pattern: 'd{.}`m{.}`Y',
format: function format(date, masked) {
var _context2, _context3;
format: (date, masked) => {
if (!date) return '';
var day = _padStartInstanceProperty(_context2 = String(date.getDate())).call(_context2, 2, '0');
var month = _padStartInstanceProperty(_context3 = String(date.getMonth() + 1)).call(_context3, 2, '0');
var year = date.getFullYear();
const day = String(date.getDate()).padStart(2, '0');
const month = String(date.getMonth() + 1).padStart(2, '0');
const year = date.getFullYear();
return [day, month, year].join('.');
},
parse: function parse(str, masked) {
var _context4;
var _str$split$map = _mapInstanceProperty(_context4 = str.split('.')).call(_context4, Number),
day = _str$split$map[0],
month = _str$split$map[1],
year = _str$split$map[2];
parse: (str, masked) => {
const [day, month, year] = str.split('.').map(Number);
return new Date(year, month - 1, day);

@@ -171,0 +144,0 @@ }

@@ -1,9 +0,2 @@

import _objectWithoutPropertiesLoose from '@babel/runtime-corejs3/helpers/objectWithoutPropertiesLoose';
import _extends from '@babel/runtime-corejs3/helpers/extends';
import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import _inheritsLoose from '@babel/runtime-corejs3/helpers/inheritsLoose';
import { _ as _mapInstanceProperty } from '../map-4c47454e.js';
import { _ as _sliceInstanceProperty } from '../slice-3858f58a.js';
import { _ as _sortInstanceProperty } from '../sort-e1545525.js';
import { o as objectIncludes, D as DIRECTION } from '../utils-e384b131.js';
import { DIRECTION, objectIncludes } from '../core/utils.js';
import ChangeDetails from '../core/change-details.js';

@@ -13,17 +6,6 @@ import createMask, { normalizeOpts } from './factory.js';

import IMask from '../core/holder.js';
import '../object-keys-53d74329.js';
import '../array-species-create-349ea110.js';
import '../classof-c2d10e36.js';
import '../delete-property-or-throw-2b53787c.js';
import '../keys-e9789594.js';
import '../assign-c82cbe95.js';
import '../index-of-358e281e.js';
import '../core/continuous-tail-details.js';
var _excluded = ["expose"],
_excluded2 = ["mask"],
_excluded3 = ["compiledMasks", "currentMaskRef", "currentMask"];
/** Dynamic mask for choosing appropriate mask in run-time */
var MaskedDynamic = /*#__PURE__*/function (_Masked) {
_inheritsLoose(MaskedDynamic, _Masked);
class MaskedDynamic extends Masked {
/** Currently chosen mask */

@@ -37,29 +19,29 @@

function MaskedDynamic(opts) {
var _this;
_this = _Masked.call(this, _extends({}, MaskedDynamic.DEFAULTS, opts)) || this;
_this.currentMask = undefined;
return _this;
constructor(opts) {
super({
...MaskedDynamic.DEFAULTS,
...opts
});
this.currentMask = undefined;
}
var _proto = MaskedDynamic.prototype;
_proto.updateOptions = function updateOptions(opts) {
_Masked.prototype.updateOptions.call(this, opts);
};
_proto._update = function _update(opts) {
var _this2 = this;
_Masked.prototype._update.call(this, opts);
updateOptions(opts) {
super.updateOptions(opts);
}
_update(opts) {
super._update(opts);
if ('mask' in opts) {
var _context;
this.exposeMask = undefined;
// mask could be totally dynamic with only `dispatch` option
this.compiledMasks = Array.isArray(opts.mask) ? _mapInstanceProperty(_context = opts.mask).call(_context, function (m) {
var _ref = normalizeOpts(m),
expose = _ref.expose,
maskOpts = _objectWithoutPropertiesLoose(_ref, _excluded);
var masked = createMask(_extends({
overwrite: _this2._overwrite,
eager: _this2._eager,
skipInvalid: _this2._skipInvalid
}, maskOpts));
if (expose) _this2.exposeMask = masked;
this.compiledMasks = Array.isArray(opts.mask) ? opts.mask.map(m => {
const {
expose,
...maskOpts
} = normalizeOpts(m);
const masked = createMask({
overwrite: this._overwrite,
eager: this._eager,
skipInvalid: this._skipInvalid,
...maskOpts
});
if (expose) this.exposeMask = masked;
return masked;

@@ -70,8 +52,9 @@ }) : [];

}
};
_proto._appendCharRaw = function _appendCharRaw(ch, flags) {
}
_appendCharRaw(ch, flags) {
if (flags === void 0) {
flags = {};
}
var details = this._applyDispatch(ch, flags);
const details = this._applyDispatch(ch, flags);
if (this.currentMask) {

@@ -81,4 +64,4 @@ details.aggregate(this.currentMask._appendChar(ch, this.currentMaskFlags(flags)));

return details;
};
_proto._applyDispatch = function _applyDispatch(appended, flags, tail) {
}
_applyDispatch(appended, flags, tail) {
if (appended === void 0) {

@@ -93,12 +76,14 @@ appended = '';

}
var prevValueBeforeTail = flags.tail && flags._beforeTailState != null ? flags._beforeTailState._value : this.value;
var inputValue = this.rawInputValue;
var insertValue = flags.tail && flags._beforeTailState != null ? flags._beforeTailState._rawInputValue : inputValue;
var tailValue = _sliceInstanceProperty(inputValue).call(inputValue, insertValue.length);
var prevMask = this.currentMask;
var details = new ChangeDetails();
var prevMaskState = prevMask == null ? void 0 : prevMask.state;
const prevValueBeforeTail = flags.tail && flags._beforeTailState != null ? flags._beforeTailState._value : this.value;
const inputValue = this.rawInputValue;
const insertValue = flags.tail && flags._beforeTailState != null ? flags._beforeTailState._rawInputValue : inputValue;
const tailValue = inputValue.slice(insertValue.length);
const prevMask = this.currentMask;
const details = new ChangeDetails();
const prevMaskState = prevMask == null ? void 0 : prevMask.state;
// clone flags to prevent overwriting `_beforeTailState`
this.currentMask = this.doDispatch(appended, _extends({}, flags), tail);
this.currentMask = this.doDispatch(appended, {
...flags
}, tail);

@@ -111,3 +96,3 @@ // restore state after dispatch

if (insertValue) {
var d = this.currentMask.append(insertValue, {
const d = this.currentMask.append(insertValue, {
raw: true

@@ -130,5 +115,5 @@ });

return details;
};
_proto._appendPlaceholder = function _appendPlaceholder() {
var details = this._applyDispatch();
}
_appendPlaceholder() {
const details = this._applyDispatch();
if (this.currentMask) {

@@ -138,5 +123,5 @@ details.aggregate(this.currentMask._appendPlaceholder());

return details;
};
_proto._appendEager = function _appendEager() {
var details = this._applyDispatch();
}
_appendEager() {
const details = this._applyDispatch();
if (this.currentMask) {

@@ -146,15 +131,16 @@ details.aggregate(this.currentMask._appendEager());

return details;
};
_proto.appendTail = function appendTail(tail) {
var details = new ChangeDetails();
}
appendTail(tail) {
const details = new ChangeDetails();
if (tail) details.aggregate(this._applyDispatch('', {}, tail));
return details.aggregate(this.currentMask ? this.currentMask.appendTail(tail) : _Masked.prototype.appendTail.call(this, tail));
};
_proto.currentMaskFlags = function currentMaskFlags(flags) {
return details.aggregate(this.currentMask ? this.currentMask.appendTail(tail) : super.appendTail(tail));
}
currentMaskFlags(flags) {
var _flags$_beforeTailSta, _flags$_beforeTailSta2;
return _extends({}, flags, {
return {
...flags,
_beforeTailState: ((_flags$_beforeTailSta = flags._beforeTailState) == null ? void 0 : _flags$_beforeTailSta.currentMaskRef) === this.currentMask && ((_flags$_beforeTailSta2 = flags._beforeTailState) == null ? void 0 : _flags$_beforeTailSta2.currentMask) || flags._beforeTailState
});
};
_proto.doDispatch = function doDispatch(appended, flags, tail) {
};
}
doDispatch(appended, flags, tail) {
if (flags === void 0) {

@@ -167,48 +153,88 @@ flags = {};

return this.dispatch(appended, this, flags, tail);
};
_proto.doValidate = function doValidate(flags) {
return _Masked.prototype.doValidate.call(this, flags) && (!this.currentMask || this.currentMask.doValidate(this.currentMaskFlags(flags)));
};
_proto.doPrepare = function doPrepare(str, flags) {
}
doValidate(flags) {
return super.doValidate(flags) && (!this.currentMask || this.currentMask.doValidate(this.currentMaskFlags(flags)));
}
doPrepare(str, flags) {
if (flags === void 0) {
flags = {};
}
var _Masked$prototype$doP = _Masked.prototype.doPrepare.call(this, str, flags),
s = _Masked$prototype$doP[0],
details = _Masked$prototype$doP[1];
let [s, details] = super.doPrepare(str, flags);
if (this.currentMask) {
var currentDetails;
var _Masked$prototype$doP2 = _Masked.prototype.doPrepare.call(this, s, this.currentMaskFlags(flags));
s = _Masked$prototype$doP2[0];
currentDetails = _Masked$prototype$doP2[1];
let currentDetails;
[s, currentDetails] = super.doPrepare(s, this.currentMaskFlags(flags));
details = details.aggregate(currentDetails);
}
return [s, details];
};
_proto.doPrepareChar = function doPrepareChar(str, flags) {
}
doPrepareChar(str, flags) {
if (flags === void 0) {
flags = {};
}
var _Masked$prototype$doP3 = _Masked.prototype.doPrepareChar.call(this, str, flags),
s = _Masked$prototype$doP3[0],
details = _Masked$prototype$doP3[1];
let [s, details] = super.doPrepareChar(str, flags);
if (this.currentMask) {
var currentDetails;
var _Masked$prototype$doP4 = _Masked.prototype.doPrepareChar.call(this, s, this.currentMaskFlags(flags));
s = _Masked$prototype$doP4[0];
currentDetails = _Masked$prototype$doP4[1];
let currentDetails;
[s, currentDetails] = super.doPrepareChar(s, this.currentMaskFlags(flags));
details = details.aggregate(currentDetails);
}
return [s, details];
};
_proto.reset = function reset() {
}
reset() {
var _this$currentMask;
(_this$currentMask = this.currentMask) == null ? void 0 : _this$currentMask.reset();
this.compiledMasks.forEach(function (m) {
return m.reset();
});
};
_proto.remove = function remove(fromPos, toPos) {
var details = new ChangeDetails();
this.compiledMasks.forEach(m => m.reset());
}
get value() {
return this.exposeMask ? this.exposeMask.value : this.currentMask ? this.currentMask.value : '';
}
set value(value) {
if (this.exposeMask) {
this.exposeMask.value = value;
this.currentMask = this.exposeMask;
this._applyDispatch();
} else super.value = value;
}
get unmaskedValue() {
return this.exposeMask ? this.exposeMask.unmaskedValue : this.currentMask ? this.currentMask.unmaskedValue : '';
}
set unmaskedValue(unmaskedValue) {
if (this.exposeMask) {
this.exposeMask.unmaskedValue = unmaskedValue;
this.currentMask = this.exposeMask;
this._applyDispatch();
} else super.unmaskedValue = unmaskedValue;
}
get typedValue() {
return this.exposeMask ? this.exposeMask.typedValue : this.currentMask ? this.currentMask.typedValue : '';
}
set typedValue(typedValue) {
if (this.exposeMask) {
this.exposeMask.typedValue = typedValue;
this.currentMask = this.exposeMask;
this._applyDispatch();
return;
}
let unmaskedValue = String(typedValue);
// double check it
if (this.currentMask) {
this.currentMask.typedValue = typedValue;
unmaskedValue = this.currentMask.unmaskedValue;
}
this.unmaskedValue = unmaskedValue;
}
get displayValue() {
return this.currentMask ? this.currentMask.displayValue : '';
}
get isComplete() {
var _this$currentMask2;
return Boolean((_this$currentMask2 = this.currentMask) == null ? void 0 : _this$currentMask2.isComplete);
}
get isFilled() {
var _this$currentMask3;
return Boolean((_this$currentMask3 = this.currentMask) == null ? void 0 : _this$currentMask3.isFilled);
}
remove(fromPos, toPos) {
const details = new ChangeDetails();
if (this.currentMask) {
details.aggregate(this.currentMask.remove(fromPos, toPos))

@@ -219,157 +245,83 @@ // update with dispatch

return details;
};
_proto.extractInput = function extractInput(fromPos, toPos, flags) {
}
get state() {
var _this$currentMask4;
return {
...super.state,
_rawInputValue: this.rawInputValue,
compiledMasks: this.compiledMasks.map(m => m.state),
currentMaskRef: this.currentMask,
currentMask: (_this$currentMask4 = this.currentMask) == null ? void 0 : _this$currentMask4.state
};
}
set state(state) {
const {
compiledMasks,
currentMaskRef,
currentMask,
...maskedState
} = state;
if (compiledMasks) this.compiledMasks.forEach((m, mi) => m.state = compiledMasks[mi]);
if (currentMaskRef != null) {
this.currentMask = currentMaskRef;
this.currentMask.state = currentMask;
}
super.state = maskedState;
}
extractInput(fromPos, toPos, flags) {
return this.currentMask ? this.currentMask.extractInput(fromPos, toPos, flags) : '';
};
_proto.extractTail = function extractTail(fromPos, toPos) {
return this.currentMask ? this.currentMask.extractTail(fromPos, toPos) : _Masked.prototype.extractTail.call(this, fromPos, toPos);
};
_proto.doCommit = function doCommit() {
}
extractTail(fromPos, toPos) {
return this.currentMask ? this.currentMask.extractTail(fromPos, toPos) : super.extractTail(fromPos, toPos);
}
doCommit() {
if (this.currentMask) this.currentMask.doCommit();
_Masked.prototype.doCommit.call(this);
};
_proto.nearestInputPos = function nearestInputPos(cursorPos, direction) {
return this.currentMask ? this.currentMask.nearestInputPos(cursorPos, direction) : _Masked.prototype.nearestInputPos.call(this, cursorPos, direction);
};
_proto.maskEquals = function maskEquals(mask) {
return Array.isArray(mask) ? this.compiledMasks.every(function (m, mi) {
super.doCommit();
}
nearestInputPos(cursorPos, direction) {
return this.currentMask ? this.currentMask.nearestInputPos(cursorPos, direction) : super.nearestInputPos(cursorPos, direction);
}
get overwrite() {
return this.currentMask ? this.currentMask.overwrite : this._overwrite;
}
set overwrite(overwrite) {
this._overwrite = overwrite;
}
get eager() {
return this.currentMask ? this.currentMask.eager : this._eager;
}
set eager(eager) {
this._eager = eager;
}
get skipInvalid() {
return this.currentMask ? this.currentMask.skipInvalid : this._skipInvalid;
}
set skipInvalid(skipInvalid) {
this._skipInvalid = skipInvalid;
}
maskEquals(mask) {
return Array.isArray(mask) ? this.compiledMasks.every((m, mi) => {
if (!mask[mi]) return;
var _mask$mi = mask[mi],
oldMask = _mask$mi.mask,
restOpts = _objectWithoutPropertiesLoose(_mask$mi, _excluded2);
const {
mask: oldMask,
...restOpts
} = mask[mi];
return objectIncludes(m, restOpts) && m.maskEquals(oldMask);
}) : _Masked.prototype.maskEquals.call(this, mask);
};
_proto.typedValueEquals = function typedValueEquals(value) {
var _this$currentMask2;
return Boolean((_this$currentMask2 = this.currentMask) == null ? void 0 : _this$currentMask2.typedValueEquals(value));
};
_createClass(MaskedDynamic, [{
key: "value",
get: function get() {
return this.exposeMask ? this.exposeMask.value : this.currentMask ? this.currentMask.value : '';
},
set: function set(value) {
if (this.exposeMask) {
this.exposeMask.value = value;
this.currentMask = this.exposeMask;
this._applyDispatch();
} else this.value = value;
}
}, {
key: "unmaskedValue",
get: function get() {
return this.exposeMask ? this.exposeMask.unmaskedValue : this.currentMask ? this.currentMask.unmaskedValue : '';
},
set: function set(unmaskedValue) {
if (this.exposeMask) {
this.exposeMask.unmaskedValue = unmaskedValue;
this.currentMask = this.exposeMask;
this._applyDispatch();
} else this.unmaskedValue = unmaskedValue;
}
}, {
key: "typedValue",
get: function get() {
return this.exposeMask ? this.exposeMask.typedValue : this.currentMask ? this.currentMask.typedValue : '';
},
set: function set(typedValue) {
if (this.exposeMask) {
this.exposeMask.typedValue = typedValue;
this.currentMask = this.exposeMask;
this._applyDispatch();
return;
}
var unmaskedValue = String(typedValue);
// double check it
if (this.currentMask) {
this.currentMask.typedValue = typedValue;
unmaskedValue = this.currentMask.unmaskedValue;
}
this.unmaskedValue = unmaskedValue;
}
}, {
key: "displayValue",
get: function get() {
return this.currentMask ? this.currentMask.displayValue : '';
}
}, {
key: "isComplete",
get: function get() {
var _this$currentMask3;
return Boolean((_this$currentMask3 = this.currentMask) == null ? void 0 : _this$currentMask3.isComplete);
}
}, {
key: "isFilled",
get: function get() {
var _this$currentMask4;
return Boolean((_this$currentMask4 = this.currentMask) == null ? void 0 : _this$currentMask4.isFilled);
}
}, {
key: "state",
get: function get() {
var _context2, _this$currentMask5;
return _extends({}, _Masked.prototype.state, {
_rawInputValue: this.rawInputValue,
compiledMasks: _mapInstanceProperty(_context2 = this.compiledMasks).call(_context2, function (m) {
return m.state;
}),
currentMaskRef: this.currentMask,
currentMask: (_this$currentMask5 = this.currentMask) == null ? void 0 : _this$currentMask5.state
});
},
set: function set(state) {
var _ref2 = state,
compiledMasks = _ref2.compiledMasks,
currentMaskRef = _ref2.currentMaskRef,
currentMask = _ref2.currentMask,
maskedState = _objectWithoutPropertiesLoose(_ref2, _excluded3);
if (compiledMasks) this.compiledMasks.forEach(function (m, mi) {
return m.state = compiledMasks[mi];
});
if (currentMaskRef != null) {
this.currentMask = currentMaskRef;
this.currentMask.state = currentMask;
}
this.state = maskedState;
}
}, {
key: "overwrite",
get: function get() {
return this.currentMask ? this.currentMask.overwrite : this._overwrite;
},
set: function set(overwrite) {
this._overwrite = overwrite;
}
}, {
key: "eager",
get: function get() {
return this.currentMask ? this.currentMask.eager : this._eager;
},
set: function set(eager) {
this._eager = eager;
}
}, {
key: "skipInvalid",
get: function get() {
return this.currentMask ? this.currentMask.skipInvalid : this._skipInvalid;
},
set: function set(skipInvalid) {
this._skipInvalid = skipInvalid;
}
}]);
return MaskedDynamic;
}(Masked);
}) : super.maskEquals(mask);
}
typedValueEquals(value) {
var _this$currentMask5;
return Boolean((_this$currentMask5 = this.currentMask) == null ? void 0 : _this$currentMask5.typedValueEquals(value));
}
}
MaskedDynamic.DEFAULTS = void 0;
MaskedDynamic.DEFAULTS = {
dispatch: function dispatch(appended, masked, flags, tail) {
var _context3;
dispatch: (appended, masked, flags, tail) => {
if (!masked.compiledMasks.length) return;
var inputValue = masked.rawInputValue;
const inputValue = masked.rawInputValue;
// simulate input
var inputs = _mapInstanceProperty(_context3 = masked.compiledMasks).call(_context3, function (m, index) {
var isCurrent = masked.currentMask === m;
var startInputPos = isCurrent ? m.displayValue.length : m.nearestInputPos(m.displayValue.length, DIRECTION.FORCE_LEFT);
const inputs = masked.compiledMasks.map((m, index) => {
const isCurrent = masked.currentMask === m;
const startInputPos = isCurrent ? m.displayValue.length : m.nearestInputPos(m.displayValue.length, DIRECTION.FORCE_LEFT);
if (m.rawInputValue !== inputValue) {

@@ -386,3 +338,3 @@ m.reset();

return {
index: index,
index,
weight: m.rawInputValue.length,

@@ -394,5 +346,3 @@ totalInputPositions: m.totalInputPositions(0, Math.max(startInputPos, m.nearestInputPos(m.displayValue.length, DIRECTION.FORCE_LEFT)))

// pop masks with longer values first
_sortInstanceProperty(inputs).call(inputs, function (i1, i2) {
return i2.weight - i1.weight || i2.totalInputPositions - i1.totalInputPositions;
});
inputs.sort((i1, i2) => i2.weight - i1.weight || i2.totalInputPositions - i1.totalInputPositions);
return masked.compiledMasks[inputs[0].index];

@@ -399,0 +349,0 @@ }

@@ -1,21 +0,5 @@

import _objectWithoutPropertiesLoose from '@babel/runtime-corejs3/helpers/objectWithoutPropertiesLoose';
import _inheritsLoose from '@babel/runtime-corejs3/helpers/inheritsLoose';
import { _ as _repeatInstanceProperty } from '../repeat-ac2db5c6.js';
import { _ as _indexOfInstanceProperty } from '../index-of-358e281e.js';
import MaskedPattern from './pattern.js';
import IMask from '../core/holder.js';
import '../object-keys-53d74329.js';
import '../string-repeat-21c9f19e.js';
import '../utils-e384b131.js';
import '../classof-c2d10e36.js';
import '../keys-e9789594.js';
import '@babel/runtime-corejs3/helpers/extends';
import '@babel/runtime-corejs3/helpers/createClass';
import '../assign-c82cbe95.js';
import '../slice-3858f58a.js';
import '../map-4c47454e.js';
import '../array-species-create-349ea110.js';
import '../sort-e1545525.js';
import '../delete-property-or-throw-2b53787c.js';
import '../core/change-details.js';
import '../core/utils.js';
import './base.js';

@@ -25,4 +9,2 @@ import '../core/continuous-tail-details.js';

import './pattern/chunk-tail-details.js';
import '../splice-dccbddd9.js';
import '../does-not-exceed-safe-integer-d06d288d.js';
import './pattern/cursor.js';

@@ -33,33 +15,24 @@ import './pattern/fixed-definition.js';

var _excluded = ["enum"];
/** Pattern which validates enum values */
var MaskedEnum = /*#__PURE__*/function (_MaskedPattern) {
_inheritsLoose(MaskedEnum, _MaskedPattern);
function MaskedEnum() {
return _MaskedPattern.apply(this, arguments) || this;
class MaskedEnum extends MaskedPattern {
updateOptions(opts) {
super.updateOptions(opts);
}
var _proto = MaskedEnum.prototype;
_proto.updateOptions = function updateOptions(opts) {
_MaskedPattern.prototype.updateOptions.call(this, opts);
};
_proto._update = function _update(opts) {
var _enum = opts.enum,
eopts = _objectWithoutPropertiesLoose(opts, _excluded);
_update(opts) {
const {
enum: _enum,
...eopts
} = opts;
if (_enum) {
var _context;
eopts.mask = _repeatInstanceProperty(_context = '*').call(_context, _enum[0].length);
eopts.mask = '*'.repeat(_enum[0].length);
this.enum = _enum;
}
_MaskedPattern.prototype._update.call(this, eopts);
};
_proto.doValidate = function doValidate(flags) {
var _this = this;
return this.enum.some(function (e) {
return _indexOfInstanceProperty(e).call(e, _this.unmaskedValue) >= 0;
}) && _MaskedPattern.prototype.doValidate.call(this, flags);
};
return MaskedEnum;
}(MaskedPattern);
super._update(eopts);
}
doValidate(flags) {
return this.enum.some(e => e.indexOf(this.unmaskedValue) >= 0) && super.doValidate(flags);
}
}
IMask.MaskedEnum = MaskedEnum;
export { MaskedEnum as default };

@@ -1,60 +0,4 @@

import _extends from '@babel/runtime-corejs3/helpers/extends';
import _objectWithoutPropertiesLoose from '@babel/runtime-corejs3/helpers/objectWithoutPropertiesLoose';
import { _ as _export, h as functionUncurryThisClause, u as toLength$1, r as requireObjectCoercible$1, e as objectIsPrototypeOf, g as getDefaultExportFromCjs } from '../object-keys-53d74329.js';
import { t as toString$1, n as notARegexp, c as correctIsRegexpLogic, i as isString, d as isObject, p as pick } from '../utils-e384b131.js';
import { e as entryVirtual$1 } from '../classof-c2d10e36.js';
import { isString, isObject, pick } from '../core/utils.js';
import IMask from '../core/holder.js';
import '../keys-e9789594.js';
var $ = _export;
var uncurryThis = functionUncurryThisClause;
var toLength = toLength$1;
var toString = toString$1;
var notARegExp = notARegexp;
var requireObjectCoercible = requireObjectCoercible$1;
var correctIsRegExpLogic = correctIsRegexpLogic;
// eslint-disable-next-line es/no-string-prototype-startswith -- safe
var nativeStartsWith = uncurryThis(''.startsWith);
var stringSlice = uncurryThis(''.slice);
var min = Math.min;
var CORRECT_IS_REGEXP_LOGIC = correctIsRegExpLogic('startsWith');
// `String.prototype.startsWith` method
// https://tc39.es/ecma262/#sec-string.prototype.startswith
$({ target: 'String', proto: true, forced: !CORRECT_IS_REGEXP_LOGIC }, {
startsWith: function startsWith(searchString /* , position = 0 */) {
var that = toString(requireObjectCoercible(this));
notARegExp(searchString);
var index = toLength(min(arguments.length > 1 ? arguments[1] : undefined, that.length));
var search = toString(searchString);
return nativeStartsWith
? nativeStartsWith(that, search, index)
: stringSlice(that, index, index + search.length) === search;
}
});
var entryVirtual = entryVirtual$1;
var startsWith$2 = entryVirtual('String').startsWith;
var isPrototypeOf = objectIsPrototypeOf;
var method = startsWith$2;
var StringPrototype = String.prototype;
var startsWith$1 = function (it) {
var own = it.startsWith;
return typeof it == 'string' || it === StringPrototype
|| (isPrototypeOf(StringPrototype, it) && own === StringPrototype.startsWith) ? method : own;
};
var parent = startsWith$1;
var startsWith = parent;
var _startsWithInstanceProperty = /*@__PURE__*/getDefaultExportFromCjs(startsWith);
var _excluded = ["mask"];
// TODO can't use overloads here because of https://github.com/microsoft/TypeScript/issues/50754

@@ -112,16 +56,16 @@ // export function maskedClass(mask: string): typeof MaskedPattern;

*/
var _ref = opts instanceof IMask.Masked ? {
mask: opts
} : isObject(opts) && opts.mask instanceof IMask.Masked ? opts : {},
_ref$mask = _ref.mask,
mask = _ref$mask === void 0 ? undefined : _ref$mask,
instanceOpts = _objectWithoutPropertiesLoose(_ref, _excluded);
const {
mask = undefined,
...instanceOpts
} = opts instanceof IMask.Masked ? {
mask: opts
} : isObject(opts) && opts.mask instanceof IMask.Masked ? opts : {};
if (mask) {
var _mask = mask.mask;
return _extends({}, pick(mask, function (_, k) {
return !_startsWithInstanceProperty(k).call(k, '_');
}), {
const _mask = mask.mask;
return {
...pick(mask, (_, k) => !k.startsWith('_')),
mask: mask.constructor,
_mask: _mask
}, instanceOpts);
_mask,
...instanceOpts
};
}

@@ -132,3 +76,5 @@ }

};
return _extends({}, opts);
return {
...opts
};
}

@@ -164,4 +110,4 @@

if (IMask.Masked && opts instanceof IMask.Masked) return opts;
var nOpts = normalizeOpts(opts);
var MaskedClass = maskedClass(nOpts.mask);
const nOpts = normalizeOpts(opts);
const MaskedClass = maskedClass(nOpts.mask);
if (!MaskedClass) throw new Error('Masked class is not found for provided mask, appropriate module needs to be imported manually before creating mask.');

@@ -168,0 +114,0 @@ if (nOpts.mask === MaskedClass) delete nOpts.mask;

@@ -1,39 +0,29 @@

import _extends from '@babel/runtime-corejs3/helpers/extends';
import _inheritsLoose from '@babel/runtime-corejs3/helpers/inheritsLoose';
import Masked from './base.js';
import IMask from '../core/holder.js';
import '@babel/runtime-corejs3/helpers/createClass';
import '../keys-e9789594.js';
import '../object-keys-53d74329.js';
import '../assign-c82cbe95.js';
import '../slice-3858f58a.js';
import '../classof-c2d10e36.js';
import '../index-of-358e281e.js';
import '../utils-e384b131.js';
import '../core/change-details.js';
import '../core/continuous-tail-details.js';
import '../core/utils.js';
/** Masking by custom Function */
var MaskedFunction = /*#__PURE__*/function (_Masked) {
_inheritsLoose(MaskedFunction, _Masked);
function MaskedFunction() {
return _Masked.apply(this, arguments) || this;
}
var _proto = MaskedFunction.prototype;
class MaskedFunction extends Masked {
/** */
/** Enable characters overwriting */
/** */
/** */
_proto.updateOptions = function updateOptions(opts) {
_Masked.prototype.updateOptions.call(this, opts);
};
_proto._update = function _update(opts) {
_Masked.prototype._update.call(this, _extends({}, opts, {
updateOptions(opts) {
super.updateOptions(opts);
}
_update(opts) {
super._update({
...opts,
validate: opts.mask
}));
};
return MaskedFunction;
}(Masked);
});
}
}
IMask.MaskedFunction = MaskedFunction;
export { MaskedFunction as default };

@@ -1,137 +0,11 @@

import _extends from '@babel/runtime-corejs3/helpers/extends';
import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import _inheritsLoose from '@babel/runtime-corejs3/helpers/inheritsLoose';
import { _ as _mapInstanceProperty } from '../map-4c47454e.js';
import { _ as _indexOfInstanceProperty } from '../index-of-358e281e.js';
import { c as createProperty$1, b as arrayMethodHasSpeciesSupport$1, i as isArray$1, _ as _sliceInstanceProperty } from '../slice-3858f58a.js';
import { _ as _padEndInstanceProperty } from '../pad-end-35f0c153.js';
import { e as escapeRegExp, D as DIRECTION, _ as _includesInstanceProperty } from '../utils-e384b131.js';
import { _ as _export, f as fails$1, b as toObject$1, m as lengthOfArrayLike$1, w as wellKnownSymbol$1, B as engineV8Version, i as isObject$1, e as objectIsPrototypeOf, g as getDefaultExportFromCjs } from '../object-keys-53d74329.js';
import { d as doesNotExceedSafeInteger$1 } from '../does-not-exceed-safe-integer-d06d288d.js';
import { a as arraySpeciesCreate$1 } from '../array-species-create-349ea110.js';
import { e as entryVirtual$1 } from '../classof-c2d10e36.js';
import { escapeRegExp, DIRECTION } from '../core/utils.js';
import ChangeDetails from '../core/change-details.js';
import Masked from './base.js';
import IMask from '../core/holder.js';
import '../string-repeat-21c9f19e.js';
import '../keys-e9789594.js';
import '../assign-c82cbe95.js';
import '../core/continuous-tail-details.js';
var $$2 = _export;
var fails = fails$1;
var isArray = isArray$1;
var isObject = isObject$1;
var toObject = toObject$1;
var lengthOfArrayLike = lengthOfArrayLike$1;
var doesNotExceedSafeInteger = doesNotExceedSafeInteger$1;
var createProperty = createProperty$1;
var arraySpeciesCreate = arraySpeciesCreate$1;
var arrayMethodHasSpeciesSupport = arrayMethodHasSpeciesSupport$1;
var wellKnownSymbol = wellKnownSymbol$1;
var V8_VERSION = engineV8Version;
var IS_CONCAT_SPREADABLE = wellKnownSymbol('isConcatSpreadable');
// We can't use this feature detection in V8 since it causes
// deoptimization and serious performance degradation
// https://github.com/zloirock/core-js/issues/679
var IS_CONCAT_SPREADABLE_SUPPORT = V8_VERSION >= 51 || !fails(function () {
var array = [];
array[IS_CONCAT_SPREADABLE] = false;
return array.concat()[0] !== array;
});
var isConcatSpreadable = function (O) {
if (!isObject(O)) return false;
var spreadable = O[IS_CONCAT_SPREADABLE];
return spreadable !== undefined ? !!spreadable : isArray(O);
};
var FORCED = !IS_CONCAT_SPREADABLE_SUPPORT || !arrayMethodHasSpeciesSupport('concat');
// `Array.prototype.concat` method
// https://tc39.es/ecma262/#sec-array.prototype.concat
// with adding support of @@isConcatSpreadable and @@species
$$2({ target: 'Array', proto: true, arity: 1, forced: FORCED }, {
// eslint-disable-next-line no-unused-vars -- required for `.length`
concat: function concat(arg) {
var O = toObject(this);
var A = arraySpeciesCreate(O, 0);
var n = 0;
var i, k, length, len, E;
for (i = -1, length = arguments.length; i < length; i++) {
E = i === -1 ? O : arguments[i];
if (isConcatSpreadable(E)) {
len = lengthOfArrayLike(E);
doesNotExceedSafeInteger(n + len);
for (k = 0; k < len; k++, n++) if (k in E) createProperty(A, n, E[k]);
} else {
doesNotExceedSafeInteger(n + 1);
createProperty(A, n++, E);
}
}
A.length = n;
return A;
}
});
var entryVirtual = entryVirtual$1;
var concat$2 = entryVirtual('Array').concat;
var isPrototypeOf = objectIsPrototypeOf;
var method = concat$2;
var ArrayPrototype = Array.prototype;
var concat$1 = function (it) {
var own = it.concat;
return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.concat) ? method : own;
};
var parent$2 = concat$1;
var concat = parent$2;
var _concatInstanceProperty = /*@__PURE__*/getDefaultExportFromCjs(concat);
var $$1 = _export;
// `Number.MIN_SAFE_INTEGER` constant
// https://tc39.es/ecma262/#sec-number.min_safe_integer
$$1({ target: 'Number', stat: true, nonConfigurable: true, nonWritable: true }, {
MIN_SAFE_INTEGER: -0x1FFFFFFFFFFFFF
});
var minSafeInteger$1 = -0x1FFFFFFFFFFFFF;
var parent$1 = minSafeInteger$1;
var minSafeInteger = parent$1;
var _Number$MIN_SAFE_INTEGER = /*@__PURE__*/getDefaultExportFromCjs(minSafeInteger);
var $ = _export;
// `Number.MAX_SAFE_INTEGER` constant
// https://tc39.es/ecma262/#sec-number.max_safe_integer
$({ target: 'Number', stat: true, nonConfigurable: true, nonWritable: true }, {
MAX_SAFE_INTEGER: 0x1FFFFFFFFFFFFF
});
var maxSafeInteger$1 = 0x1FFFFFFFFFFFFF;
var parent = maxSafeInteger$1;
var maxSafeInteger = parent;
var _Number$MAX_SAFE_INTEGER = /*@__PURE__*/getDefaultExportFromCjs(maxSafeInteger);
var _context10;
/**
Number mask
*/
var MaskedNumber = /*#__PURE__*/function (_Masked) {
_inheritsLoose(MaskedNumber, _Masked);
class MaskedNumber extends Masked {
/** Single char */

@@ -163,32 +37,33 @@

function MaskedNumber(opts) {
return _Masked.call(this, _extends({}, MaskedNumber.DEFAULTS, opts)) || this;
constructor(opts) {
super({
...MaskedNumber.DEFAULTS,
...opts
});
}
var _proto = MaskedNumber.prototype;
_proto.updateOptions = function updateOptions(opts) {
_Masked.prototype.updateOptions.call(this, opts);
};
_proto._update = function _update(opts) {
_Masked.prototype._update.call(this, opts);
updateOptions(opts) {
super.updateOptions(opts);
}
_update(opts) {
super._update(opts);
this._updateRegExps();
};
_proto._updateRegExps = function _updateRegExps() {
var _context;
var start = '^' + (this.allowNegative ? '[+|\\-]?' : '');
var mid = '\\d*';
var end = (this.scale ? "(" + escapeRegExp(this.radix) + "\\d{0," + this.scale + "})?" : '') + '$';
}
_updateRegExps() {
const start = '^' + (this.allowNegative ? '[+|\\-]?' : '');
const mid = '\\d*';
const end = (this.scale ? "(" + escapeRegExp(this.radix) + "\\d{0," + this.scale + "})?" : '') + '$';
this._numberRegExp = new RegExp(start + mid + end);
this._mapToRadixRegExp = new RegExp("[" + _mapInstanceProperty(_context = this.mapToRadix).call(_context, escapeRegExp).join('') + "]", 'g');
this._mapToRadixRegExp = new RegExp("[" + this.mapToRadix.map(escapeRegExp).join('') + "]", 'g');
this._thousandsSeparatorRegExp = new RegExp(escapeRegExp(this.thousandsSeparator), 'g');
};
_proto._removeThousandsSeparators = function _removeThousandsSeparators(value) {
}
_removeThousandsSeparators(value) {
return value.replace(this._thousandsSeparatorRegExp, '');
};
_proto._insertThousandsSeparators = function _insertThousandsSeparators(value) {
}
_insertThousandsSeparators(value) {
// https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript
var parts = value.split(this.radix);
const parts = value.split(this.radix);
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, this.thousandsSeparator);
return parts.join(this.radix);
};
_proto.doPrepareChar = function doPrepareChar(ch, flags) {
}
doPrepareChar(ch, flags) {
if (flags === void 0) {

@@ -207,17 +82,14 @@ flags = {};

flags.input && flags.raw || !flags.input && !flags.raw) ? ch.replace(this._mapToRadixRegExp, this.radix) : ch);
var _Masked$prototype$doP = _Masked.prototype.doPrepareChar.call(this, ch, flags),
prepCh = _Masked$prototype$doP[0],
details = _Masked$prototype$doP[1];
const [prepCh, details] = super.doPrepareChar(ch, flags);
if (ch && !prepCh) details.skip = true;
if (prepCh && !this.allowPositive && !this.value && prepCh !== '-') details.aggregate(this._appendChar('-'));
return [prepCh, details];
};
_proto._separatorsCount = function _separatorsCount(to, extendOnSeparators) {
}
_separatorsCount(to, extendOnSeparators) {
if (extendOnSeparators === void 0) {
extendOnSeparators = false;
}
var count = 0;
for (var pos = 0; pos < to; ++pos) {
var _context2;
if (_indexOfInstanceProperty(_context2 = this._value).call(_context2, this.thousandsSeparator, pos) === pos) {
let count = 0;
for (let pos = 0; pos < to; ++pos) {
if (this._value.indexOf(this.thousandsSeparator, pos) === pos) {
++count;

@@ -228,4 +100,4 @@ if (extendOnSeparators) to += this.thousandsSeparator.length;

return count;
};
_proto._separatorsCountFromSlice = function _separatorsCountFromSlice(slice) {
}
_separatorsCountFromSlice(slice) {
if (slice === void 0) {

@@ -235,4 +107,4 @@ slice = this._value;

return this._separatorsCount(this._removeThousandsSeparators(slice).length, true);
};
_proto.extractInput = function extractInput(fromPos, toPos, flags) {
}
extractInput(fromPos, toPos, flags) {
if (fromPos === void 0) {

@@ -244,41 +116,37 @@ fromPos = 0;

}
var _this$_adjustRangeWit = this._adjustRangeWithSeparators(fromPos, toPos);
fromPos = _this$_adjustRangeWit[0];
toPos = _this$_adjustRangeWit[1];
return this._removeThousandsSeparators(_Masked.prototype.extractInput.call(this, fromPos, toPos, flags));
};
_proto._appendCharRaw = function _appendCharRaw(ch, flags) {
[fromPos, toPos] = this._adjustRangeWithSeparators(fromPos, toPos);
return this._removeThousandsSeparators(super.extractInput(fromPos, toPos, flags));
}
_appendCharRaw(ch, flags) {
if (flags === void 0) {
flags = {};
}
if (!this.thousandsSeparator) return _Masked.prototype._appendCharRaw.call(this, ch, flags);
var prevBeforeTailValue = flags.tail && flags._beforeTailState ? flags._beforeTailState._value : this._value;
var prevBeforeTailSeparatorsCount = this._separatorsCountFromSlice(prevBeforeTailValue);
if (!this.thousandsSeparator) return super._appendCharRaw(ch, flags);
const prevBeforeTailValue = flags.tail && flags._beforeTailState ? flags._beforeTailState._value : this._value;
const prevBeforeTailSeparatorsCount = this._separatorsCountFromSlice(prevBeforeTailValue);
this._value = this._removeThousandsSeparators(this.value);
var appendDetails = _Masked.prototype._appendCharRaw.call(this, ch, flags);
const appendDetails = super._appendCharRaw(ch, flags);
this._value = this._insertThousandsSeparators(this._value);
var beforeTailValue = flags.tail && flags._beforeTailState ? flags._beforeTailState._value : this._value;
var beforeTailSeparatorsCount = this._separatorsCountFromSlice(beforeTailValue);
const beforeTailValue = flags.tail && flags._beforeTailState ? flags._beforeTailState._value : this._value;
const beforeTailSeparatorsCount = this._separatorsCountFromSlice(beforeTailValue);
appendDetails.tailShift += (beforeTailSeparatorsCount - prevBeforeTailSeparatorsCount) * this.thousandsSeparator.length;
appendDetails.skip = !appendDetails.rawInserted && ch === this.thousandsSeparator;
return appendDetails;
};
_proto._findSeparatorAround = function _findSeparatorAround(pos) {
}
_findSeparatorAround(pos) {
if (this.thousandsSeparator) {
var _context3;
var searchFrom = pos - this.thousandsSeparator.length + 1;
var separatorPos = _indexOfInstanceProperty(_context3 = this.value).call(_context3, this.thousandsSeparator, searchFrom);
const searchFrom = pos - this.thousandsSeparator.length + 1;
const separatorPos = this.value.indexOf(this.thousandsSeparator, searchFrom);
if (separatorPos <= pos) return separatorPos;
}
return -1;
};
_proto._adjustRangeWithSeparators = function _adjustRangeWithSeparators(from, to) {
var separatorAroundFromPos = this._findSeparatorAround(from);
}
_adjustRangeWithSeparators(from, to) {
const separatorAroundFromPos = this._findSeparatorAround(from);
if (separatorAroundFromPos >= 0) from = separatorAroundFromPos;
var separatorAroundToPos = this._findSeparatorAround(to);
const separatorAroundToPos = this._findSeparatorAround(to);
if (separatorAroundToPos >= 0) to = separatorAroundToPos + this.thousandsSeparator.length;
return [from, to];
};
_proto.remove = function remove(fromPos, toPos) {
var _context4, _context5;
}
remove(fromPos, toPos) {
if (fromPos === void 0) {

@@ -290,15 +158,13 @@ fromPos = 0;

}
var _this$_adjustRangeWit2 = this._adjustRangeWithSeparators(fromPos, toPos);
fromPos = _this$_adjustRangeWit2[0];
toPos = _this$_adjustRangeWit2[1];
var valueBeforePos = _sliceInstanceProperty(_context4 = this.value).call(_context4, 0, fromPos);
var valueAfterPos = _sliceInstanceProperty(_context5 = this.value).call(_context5, toPos);
var prevBeforeTailSeparatorsCount = this._separatorsCount(valueBeforePos.length);
[fromPos, toPos] = this._adjustRangeWithSeparators(fromPos, toPos);
const valueBeforePos = this.value.slice(0, fromPos);
const valueAfterPos = this.value.slice(toPos);
const prevBeforeTailSeparatorsCount = this._separatorsCount(valueBeforePos.length);
this._value = this._insertThousandsSeparators(this._removeThousandsSeparators(valueBeforePos + valueAfterPos));
var beforeTailSeparatorsCount = this._separatorsCountFromSlice(valueBeforePos);
const beforeTailSeparatorsCount = this._separatorsCountFromSlice(valueBeforePos);
return new ChangeDetails({
tailShift: (beforeTailSeparatorsCount - prevBeforeTailSeparatorsCount) * this.thousandsSeparator.length
});
};
_proto.nearestInputPos = function nearestInputPos(cursorPos, direction) {
}
nearestInputPos(cursorPos, direction) {
if (!this.thousandsSeparator) return cursorPos;

@@ -310,5 +176,5 @@ switch (direction) {

{
var separatorAtLeftPos = this._findSeparatorAround(cursorPos - 1);
const separatorAtLeftPos = this._findSeparatorAround(cursorPos - 1);
if (separatorAtLeftPos >= 0) {
var separatorAtLeftEndPos = separatorAtLeftPos + this.thousandsSeparator.length;
const separatorAtLeftEndPos = separatorAtLeftPos + this.thousandsSeparator.length;
if (cursorPos < separatorAtLeftEndPos || this.value.length <= separatorAtLeftEndPos || direction === DIRECTION.FORCE_LEFT) {

@@ -323,3 +189,3 @@ return separatorAtLeftPos;

{
var separatorAtRightPos = this._findSeparatorAround(cursorPos);
const separatorAtRightPos = this._findSeparatorAround(cursorPos);
if (separatorAtRightPos >= 0) {

@@ -331,9 +197,9 @@ return separatorAtRightPos + this.thousandsSeparator.length;

return cursorPos;
};
_proto.doValidate = function doValidate(flags) {
}
doValidate(flags) {
// validate as string
var valid = Boolean(this._removeThousandsSeparators(this.value).match(this._numberRegExp));
let valid = Boolean(this._removeThousandsSeparators(this.value).match(this._numberRegExp));
if (valid) {
// validate as number
var number = this.number;
const number = this.number;
valid = valid && !isNaN(number) && (

@@ -345,8 +211,8 @@ // check min bound for negative values

}
return valid && _Masked.prototype.doValidate.call(this, flags);
};
_proto.doCommit = function doCommit() {
return valid && super.doValidate(flags);
}
doCommit() {
if (this.value) {
var number = this.number;
var validnum = number;
const number = this.number;
let validnum = number;

@@ -357,3 +223,3 @@ // check bounds

if (validnum !== number) this.unmaskedValue = this.format(validnum, this);
var formatted = this.value;
let formatted = this.value;
if (this.normalizeZeros) formatted = this._normalizeZeros(formatted);

@@ -363,11 +229,9 @@ if (this.padFractionalZeros && this.scale > 0) formatted = this._padFractionalZeros(formatted);

}
_Masked.prototype.doCommit.call(this);
};
_proto._normalizeZeros = function _normalizeZeros(value) {
var parts = this._removeThousandsSeparators(value).split(this.radix);
super.doCommit();
}
_normalizeZeros(value) {
const parts = this._removeThousandsSeparators(value).split(this.radix);
// remove leading zeros
parts[0] = parts[0].replace(/^(\D*)(0*)(\d*)/, function (match, sign, zeros, num) {
return sign + num;
});
parts[0] = parts[0].replace(/^(\D*)(0*)(\d*)/, (match, sign, zeros, num) => sign + num);
// add leading zero

@@ -381,74 +245,59 @@ if (value.length && !/\d$/.test(parts[0])) parts[0] = parts[0] + '0';

return this._insertThousandsSeparators(parts.join(this.radix));
};
_proto._padFractionalZeros = function _padFractionalZeros(value) {
var _context6;
}
_padFractionalZeros(value) {
if (!value) return value;
var parts = value.split(this.radix);
const parts = value.split(this.radix);
if (parts.length < 2) parts.push('');
parts[1] = _padEndInstanceProperty(_context6 = parts[1]).call(_context6, this.scale, '0');
parts[1] = parts[1].padEnd(this.scale, '0');
return parts.join(this.radix);
};
_proto.doSkipInvalid = function doSkipInvalid(ch, flags, checkTail) {
var _context7;
}
doSkipInvalid(ch, flags, checkTail) {
if (flags === void 0) {
flags = {};
}
var dropFractional = this.scale === 0 && ch !== this.thousandsSeparator && (ch === this.radix || ch === MaskedNumber.UNMASKED_RADIX || _includesInstanceProperty(_context7 = this.mapToRadix).call(_context7, ch));
return _Masked.prototype.doSkipInvalid.call(this, ch, flags, checkTail) && !dropFractional;
};
_proto.typedValueEquals = function typedValueEquals(value) {
var _context8, _context9;
// handle 0 -> '' case (typed = 0 even if value = '')
// for details see https://github.com/uNmAnNeR/imaskjs/issues/134
return (_Masked.prototype.typedValueEquals.call(this, value) || _includesInstanceProperty(_context8 = MaskedNumber.EMPTY_VALUES).call(_context8, value) && _includesInstanceProperty(_context9 = MaskedNumber.EMPTY_VALUES).call(_context9, this.typedValue)) && !(value === 0 && this.value === '');
};
_createClass(MaskedNumber, [{
key: "unmaskedValue",
get: function get() {
return this._removeThousandsSeparators(this._normalizeZeros(this.value)).replace(this.radix, MaskedNumber.UNMASKED_RADIX);
},
set: function set(unmaskedValue) {
this.unmaskedValue = unmaskedValue;
}
}, {
key: "typedValue",
get: function get() {
return this.parse(this.unmaskedValue, this);
},
set: function set(n) {
this.rawInputValue = this.format(n, this).replace(MaskedNumber.UNMASKED_RADIX, this.radix);
}
const dropFractional = this.scale === 0 && ch !== this.thousandsSeparator && (ch === this.radix || ch === MaskedNumber.UNMASKED_RADIX || this.mapToRadix.includes(ch));
return super.doSkipInvalid(ch, flags, checkTail) && !dropFractional;
}
get unmaskedValue() {
return this._removeThousandsSeparators(this._normalizeZeros(this.value)).replace(this.radix, MaskedNumber.UNMASKED_RADIX);
}
set unmaskedValue(unmaskedValue) {
super.unmaskedValue = unmaskedValue;
}
get typedValue() {
return this.parse(this.unmaskedValue, this);
}
set typedValue(n) {
this.rawInputValue = this.format(n, this).replace(MaskedNumber.UNMASKED_RADIX, this.radix);
}
/** Parsed Number */
}, {
key: "number",
get: function get() {
return this.typedValue;
},
set: function set(number) {
this.typedValue = number;
}
/** Parsed Number */
get number() {
return this.typedValue;
}
set number(number) {
this.typedValue = number;
}
/**
Is negative allowed
*/
}, {
key: "allowNegative",
get: function get() {
return this.min != null && this.min < 0 || this.max != null && this.max < 0;
}
/**
Is negative allowed
*/
get allowNegative() {
return this.min != null && this.min < 0 || this.max != null && this.max < 0;
}
/**
Is positive allowed
*/
}, {
key: "allowPositive",
get: function get() {
return this.min != null && this.min > 0 || this.max != null && this.max > 0;
}
}]);
return MaskedNumber;
}(Masked);
/**
Is positive allowed
*/
get allowPositive() {
return this.min != null && this.min > 0 || this.max != null && this.max > 0;
}
typedValueEquals(value) {
// handle 0 -> '' case (typed = 0 even if value = '')
// for details see https://github.com/uNmAnNeR/imaskjs/issues/134
return (super.typedValueEquals(value) || MaskedNumber.EMPTY_VALUES.includes(value) && MaskedNumber.EMPTY_VALUES.includes(this.typedValue)) && !(value === 0 && this.value === '');
}
}
MaskedNumber.UNMASKED_RADIX = '.';
MaskedNumber.EMPTY_VALUES = _concatInstanceProperty(_context10 = []).call(_context10, Masked.EMPTY_VALUES, [0]);
MaskedNumber.EMPTY_VALUES = [...Masked.EMPTY_VALUES, 0];
MaskedNumber.DEFAULTS = {

@@ -459,4 +308,4 @@ mask: Number,

mapToRadix: [MaskedNumber.UNMASKED_RADIX],
min: _Number$MIN_SAFE_INTEGER,
max: _Number$MAX_SAFE_INTEGER,
min: Number.MIN_SAFE_INTEGER,
max: Number.MAX_SAFE_INTEGER,
scale: 2,

@@ -466,8 +315,6 @@ normalizeZeros: true,

parse: Number,
format: function format(n) {
return n.toLocaleString('en-US', {
useGrouping: false,
maximumFractionDigits: 20
});
}
format: n => n.toLocaleString('en-US', {
useGrouping: false,
maximumFractionDigits: 20
})
};

@@ -474,0 +321,0 @@ IMask.MaskedNumber = MaskedNumber;

@@ -1,16 +0,4 @@

import _objectWithoutPropertiesLoose from '@babel/runtime-corejs3/helpers/objectWithoutPropertiesLoose';
import _extends from '@babel/runtime-corejs3/helpers/extends';
import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import _inheritsLoose from '@babel/runtime-corejs3/helpers/inheritsLoose';
import { _ as _Object$assign } from '../assign-c82cbe95.js';
import { b as arrayMethodHasSpeciesSupport$1, _ as _sliceInstanceProperty } from '../slice-3858f58a.js';
import { _ as _export, e as objectIsPrototypeOf, g as getDefaultExportFromCjs } from '../object-keys-53d74329.js';
import { a as arrayIteration, _ as _mapInstanceProperty } from '../map-4c47454e.js';
import { e as entryVirtual$1 } from '../classof-c2d10e36.js';
import { _ as _Object$keys } from '../keys-e9789594.js';
import { _ as _indexOfInstanceProperty } from '../index-of-358e281e.js';
import { _ as _sortInstanceProperty } from '../sort-e1545525.js';
import { b as _reduceInstanceProperty, D as DIRECTION } from '../utils-e384b131.js';
import ChangeDetails from '../core/change-details.js';
import IMask from '../core/holder.js';
import { DIRECTION } from '../core/utils.js';
import Masked from './base.js';

@@ -23,48 +11,6 @@ import createMask, { normalizeOpts } from './factory.js';

import './regexp.js';
import '../array-species-create-349ea110.js';
import '../delete-property-or-throw-2b53787c.js';
import '../core/continuous-tail-details.js';
import '../splice-dccbddd9.js';
import '../does-not-exceed-safe-integer-d06d288d.js';
var $ = _export;
var $filter = arrayIteration.filter;
var arrayMethodHasSpeciesSupport = arrayMethodHasSpeciesSupport$1;
var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('filter');
// `Array.prototype.filter` method
// https://tc39.es/ecma262/#sec-array.prototype.filter
// with adding support of @@species
$({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT }, {
filter: function filter(callbackfn /* , thisArg */) {
return $filter(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
}
});
var entryVirtual = entryVirtual$1;
var filter$2 = entryVirtual('Array').filter;
var isPrototypeOf = objectIsPrototypeOf;
var method = filter$2;
var ArrayPrototype = Array.prototype;
var filter$1 = function (it) {
var own = it.filter;
return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.filter) ? method : own;
};
var parent = filter$1;
var filter = parent;
var _filterInstanceProperty = /*@__PURE__*/getDefaultExportFromCjs(filter);
var _excluded = ["expose"],
_excluded2 = ["_blocks"];
/** Pattern mask */
var MaskedPattern = /*#__PURE__*/function (_Masked) {
_inheritsLoose(MaskedPattern, _Masked);
class MaskedPattern extends Masked {
/** */

@@ -86,19 +32,19 @@

function MaskedPattern(opts) {
return _Masked.call(this, _extends({}, MaskedPattern.DEFAULTS, opts, {
definitions: _Object$assign({}, PatternInputDefinition.DEFAULT_DEFINITIONS, opts == null ? void 0 : opts.definitions)
})) || this;
constructor(opts) {
super({
...MaskedPattern.DEFAULTS,
...opts,
definitions: Object.assign({}, PatternInputDefinition.DEFAULT_DEFINITIONS, opts == null ? void 0 : opts.definitions)
});
}
var _proto = MaskedPattern.prototype;
_proto.updateOptions = function updateOptions(opts) {
_Masked.prototype.updateOptions.call(this, opts);
};
_proto._update = function _update(opts) {
opts.definitions = _Object$assign({}, this.definitions, opts.definitions);
_Masked.prototype._update.call(this, opts);
updateOptions(opts) {
super.updateOptions(opts);
}
_update(opts) {
opts.definitions = Object.assign({}, this.definitions, opts.definitions);
super._update(opts);
this._rebuildMask();
};
_proto._rebuildMask = function _rebuildMask() {
var _this = this;
var defs = this.definitions;
}
_rebuildMask() {
const defs = this.definitions;
this._blocks = [];

@@ -108,112 +54,155 @@ this.exposeBlock = undefined;

this._maskedBlocks = {};
var pattern = this.mask;
const pattern = this.mask;
if (!pattern || !defs) return;
var unmaskingBlock = false;
var optionalBlock = false;
var _loop = function _loop(_i) {
if (_this.blocks) {
var _context;
var p = _sliceInstanceProperty(pattern).call(pattern, _i);
var bNames = _filterInstanceProperty(_context = _Object$keys(_this.blocks)).call(_context, function (bName) {
return _indexOfInstanceProperty(p).call(p, bName) === 0;
});
let unmaskingBlock = false;
let optionalBlock = false;
for (let i = 0; i < pattern.length; ++i) {
if (this.blocks) {
const p = pattern.slice(i);
const bNames = Object.keys(this.blocks).filter(bName => p.indexOf(bName) === 0);
// order by key length
_sortInstanceProperty(bNames).call(bNames, function (a, b) {
return b.length - a.length;
});
bNames.sort((a, b) => b.length - a.length);
// use block name with max length
var bName = bNames[0];
const bName = bNames[0];
if (bName) {
var _ref = normalizeOpts(_this.blocks[bName]),
expose = _ref.expose,
blockOpts = _objectWithoutPropertiesLoose(_ref, _excluded);
var maskedBlock = createMask(_extends({
lazy: _this.lazy,
eager: _this.eager,
placeholderChar: _this.placeholderChar,
displayChar: _this.displayChar,
overwrite: _this.overwrite
}, blockOpts, {
parent: _this
}));
const {
expose,
...blockOpts
} = normalizeOpts(this.blocks[bName]);
const maskedBlock = createMask({
lazy: this.lazy,
eager: this.eager,
placeholderChar: this.placeholderChar,
displayChar: this.displayChar,
overwrite: this.overwrite,
...blockOpts,
parent: this
});
if (maskedBlock) {
_this._blocks.push(maskedBlock);
if (expose) _this.exposeBlock = maskedBlock;
this._blocks.push(maskedBlock);
if (expose) this.exposeBlock = maskedBlock;
// store block index
if (!_this._maskedBlocks[bName]) _this._maskedBlocks[bName] = [];
_this._maskedBlocks[bName].push(_this._blocks.length - 1);
if (!this._maskedBlocks[bName]) this._maskedBlocks[bName] = [];
this._maskedBlocks[bName].push(this._blocks.length - 1);
}
_i += bName.length - 1;
i = _i;
return "continue";
i += bName.length - 1;
continue;
}
}
var char = pattern[_i];
var isInput = (char in defs);
let char = pattern[i];
let isInput = (char in defs);
if (char === MaskedPattern.STOP_CHAR) {
_this._stops.push(_this._blocks.length);
i = _i;
return "continue";
this._stops.push(this._blocks.length);
continue;
}
if (char === '{' || char === '}') {
unmaskingBlock = !unmaskingBlock;
i = _i;
return "continue";
continue;
}
if (char === '[' || char === ']') {
optionalBlock = !optionalBlock;
i = _i;
return "continue";
continue;
}
if (char === MaskedPattern.ESCAPE_CHAR) {
++_i;
char = pattern[_i];
if (!char) {
i = _i;
return "break";
}
++i;
char = pattern[i];
if (!char) break;
isInput = false;
}
var def = isInput ? new PatternInputDefinition(_extends({
const def = isInput ? new PatternInputDefinition({
isOptional: optionalBlock,
lazy: _this.lazy,
eager: _this.eager,
placeholderChar: _this.placeholderChar,
displayChar: _this.displayChar
}, normalizeOpts(defs[char]), {
parent: _this
})) : new PatternFixedDefinition({
char: char,
eager: _this.eager,
lazy: this.lazy,
eager: this.eager,
placeholderChar: this.placeholderChar,
displayChar: this.displayChar,
...normalizeOpts(defs[char]),
parent: this
}) : new PatternFixedDefinition({
char,
eager: this.eager,
isUnmasking: unmaskingBlock
});
_this._blocks.push(def);
i = _i;
this._blocks.push(def);
}
}
get state() {
return {
...super.state,
_blocks: this._blocks.map(b => b.state)
};
for (var i = 0; i < pattern.length; ++i) {
var _ret = _loop(i);
if (_ret === "continue") continue;
if (_ret === "break") break;
}
};
_proto.reset = function reset() {
_Masked.prototype.reset.call(this);
this._blocks.forEach(function (b) {
return b.reset();
});
};
_proto.doCommit = function doCommit() {
this._blocks.forEach(function (b) {
return b.doCommit();
});
_Masked.prototype.doCommit.call(this);
};
_proto.appendTail = function appendTail(tail) {
return _Masked.prototype.appendTail.call(this, tail).aggregate(this._appendPlaceholder());
};
_proto._appendEager = function _appendEager() {
}
set state(state) {
const {
_blocks,
...maskedState
} = state;
this._blocks.forEach((b, bi) => b.state = _blocks[bi]);
super.state = maskedState;
}
reset() {
super.reset();
this._blocks.forEach(b => b.reset());
}
get isComplete() {
return this.exposeBlock ? this.exposeBlock.isComplete : this._blocks.every(b => b.isComplete);
}
get isFilled() {
return this._blocks.every(b => b.isFilled);
}
get isFixed() {
return this._blocks.every(b => b.isFixed);
}
get isOptional() {
return this._blocks.every(b => b.isOptional);
}
doCommit() {
this._blocks.forEach(b => b.doCommit());
super.doCommit();
}
get unmaskedValue() {
return this.exposeBlock ? this.exposeBlock.unmaskedValue : this._blocks.reduce((str, b) => str += b.unmaskedValue, '');
}
set unmaskedValue(unmaskedValue) {
if (this.exposeBlock) {
const tail = this.extractTail(this._blockStartPos(this._blocks.indexOf(this.exposeBlock)) + this.exposeBlock.displayValue.length);
this.exposeBlock.unmaskedValue = unmaskedValue;
this.appendTail(tail);
this.doCommit();
} else super.unmaskedValue = unmaskedValue;
}
get value() {
return this.exposeBlock ? this.exposeBlock.value :
// TODO return _value when not in change?
this._blocks.reduce((str, b) => str += b.value, '');
}
set value(value) {
if (this.exposeBlock) {
const tail = this.extractTail(this._blockStartPos(this._blocks.indexOf(this.exposeBlock)) + this.exposeBlock.displayValue.length);
this.exposeBlock.value = value;
this.appendTail(tail);
this.doCommit();
} else super.value = value;
}
get typedValue() {
return this.exposeBlock ? this.exposeBlock.typedValue : super.typedValue;
}
set typedValue(value) {
if (this.exposeBlock) {
const tail = this.extractTail(this._blockStartPos(this._blocks.indexOf(this.exposeBlock)) + this.exposeBlock.displayValue.length);
this.exposeBlock.typedValue = value;
this.appendTail(tail);
this.doCommit();
} else super.typedValue = value;
}
get displayValue() {
return this._blocks.reduce((str, b) => str += b.displayValue, '');
}
appendTail(tail) {
return super.appendTail(tail).aggregate(this._appendPlaceholder());
}
_appendEager() {
var _this$_mapPosToBlock;
var details = new ChangeDetails();
var startBlockIndex = (_this$_mapPosToBlock = this._mapPosToBlock(this.displayValue.length)) == null ? void 0 : _this$_mapPosToBlock.index;
const details = new ChangeDetails();
let startBlockIndex = (_this$_mapPosToBlock = this._mapPosToBlock(this.displayValue.length)) == null ? void 0 : _this$_mapPosToBlock.index;
if (startBlockIndex == null) return details;

@@ -223,4 +212,4 @@

if (this._blocks[startBlockIndex].isFilled) ++startBlockIndex;
for (var bi = startBlockIndex; bi < this._blocks.length; ++bi) {
var d = this._blocks[bi]._appendEager();
for (let bi = startBlockIndex; bi < this._blocks.length; ++bi) {
const d = this._blocks[bi]._appendEager();
if (!d.inserted) break;

@@ -230,18 +219,19 @@ details.aggregate(d);

return details;
};
_proto._appendCharRaw = function _appendCharRaw(ch, flags) {
}
_appendCharRaw(ch, flags) {
if (flags === void 0) {
flags = {};
}
var blockIter = this._mapPosToBlock(this.displayValue.length);
var details = new ChangeDetails();
const blockIter = this._mapPosToBlock(this.displayValue.length);
const details = new ChangeDetails();
if (!blockIter) return details;
for (var bi = blockIter.index;; ++bi) {
for (let bi = blockIter.index;; ++bi) {
var _flags$_beforeTailSta;
var _block = this._blocks[bi];
if (!_block) break;
var blockDetails = _block._appendChar(ch, _extends({}, flags, {
const block = this._blocks[bi];
if (!block) break;
const blockDetails = block._appendChar(ch, {
...flags,
_beforeTailState: (_flags$_beforeTailSta = flags._beforeTailState) == null || (_flags$_beforeTailSta = _flags$_beforeTailSta._blocks) == null ? void 0 : _flags$_beforeTailSta[bi]
}));
var skip = blockDetails.skip;
});
const skip = blockDetails.skip;
details.aggregate(blockDetails);

@@ -252,5 +242,4 @@ if (skip || blockDetails.rawInserted) break; // go next char

return details;
};
_proto.extractTail = function extractTail(fromPos, toPos) {
var _this2 = this;
}
extractTail(fromPos, toPos) {
if (fromPos === void 0) {

@@ -262,8 +251,8 @@ fromPos = 0;

}
var chunkTail = new ChunksTailDetails();
const chunkTail = new ChunksTailDetails();
if (fromPos === toPos) return chunkTail;
this._forEachBlocksInRange(fromPos, toPos, function (b, bi, bFromPos, bToPos) {
var blockChunk = b.extractTail(bFromPos, bToPos);
blockChunk.stop = _this2._findStopBefore(bi);
blockChunk.from = _this2._blockStartPos(bi);
this._forEachBlocksInRange(fromPos, toPos, (b, bi, bFromPos, bToPos) => {
const blockChunk = b.extractTail(bFromPos, bToPos);
blockChunk.stop = this._findStopBefore(bi);
blockChunk.from = this._blockStartPos(bi);
if (blockChunk instanceof ChunksTailDetails) blockChunk.blockIndex = bi;

@@ -273,4 +262,4 @@ chunkTail.extend(blockChunk);

return chunkTail;
};
_proto.extractInput = function extractInput(fromPos, toPos, flags) {
}
extractInput(fromPos, toPos, flags) {
if (fromPos === void 0) {

@@ -286,12 +275,12 @@ fromPos = 0;

if (fromPos === toPos) return '';
var input = '';
this._forEachBlocksInRange(fromPos, toPos, function (b, _, fromPos, toPos) {
let input = '';
this._forEachBlocksInRange(fromPos, toPos, (b, _, fromPos, toPos) => {
input += b.extractInput(fromPos, toPos, flags);
});
return input;
};
_proto._findStopBefore = function _findStopBefore(blockIndex) {
var stopBefore;
for (var si = 0; si < this._stops.length; ++si) {
var stop = this._stops[si];
}
_findStopBefore(blockIndex) {
let stopBefore;
for (let si = 0; si < this._stops.length; ++si) {
const stop = this._stops[si];
if (stop <= blockIndex) stopBefore = stop;else break;

@@ -302,17 +291,15 @@ }

/** Appends placeholder depending on laziness */;
_proto._appendPlaceholder = function _appendPlaceholder(toBlockIndex) {
var _context2,
_this3 = this;
var details = new ChangeDetails();
/** Appends placeholder depending on laziness */
_appendPlaceholder(toBlockIndex) {
const details = new ChangeDetails();
if (this.lazy && toBlockIndex == null) return details;
var startBlockIter = this._mapPosToBlock(this.displayValue.length);
const startBlockIter = this._mapPosToBlock(this.displayValue.length);
if (!startBlockIter) return details;
var startBlockIndex = startBlockIter.index;
var endBlockIndex = toBlockIndex != null ? toBlockIndex : this._blocks.length;
_sliceInstanceProperty(_context2 = this._blocks).call(_context2, startBlockIndex, endBlockIndex).forEach(function (b) {
const startBlockIndex = startBlockIter.index;
const endBlockIndex = toBlockIndex != null ? toBlockIndex : this._blocks.length;
this._blocks.slice(startBlockIndex, endBlockIndex).forEach(b => {
if (!b.lazy || toBlockIndex != null) {
var _blocks2;
var bDetails = b._appendPlaceholder((_blocks2 = b._blocks) == null ? void 0 : _blocks2.length);
_this3._value += bDetails.inserted;
const bDetails = b._appendPlaceholder((_blocks2 = b._blocks) == null ? void 0 : _blocks2.length);
this._value += bDetails.inserted;
details.aggregate(bDetails);

@@ -324,9 +311,9 @@ }

/** Finds block in pos */;
_proto._mapPosToBlock = function _mapPosToBlock(pos) {
var accVal = '';
for (var bi = 0; bi < this._blocks.length; ++bi) {
var _block2 = this._blocks[bi];
var blockStartPos = accVal.length;
accVal += _block2.displayValue;
/** Finds block in pos */
_mapPosToBlock(pos) {
let accVal = '';
for (let bi = 0; bi < this._blocks.length; ++bi) {
const block = this._blocks[bi];
const blockStartPos = accVal.length;
accVal += block.displayValue;
if (pos <= accVal.length) {

@@ -339,24 +326,21 @@ return {

}
};
_proto._blockStartPos = function _blockStartPos(blockIndex) {
var _context3, _context4;
return _reduceInstanceProperty(_context3 = _sliceInstanceProperty(_context4 = this._blocks).call(_context4, 0, blockIndex)).call(_context3, function (pos, b) {
return pos += b.displayValue.length;
}, 0);
};
_proto._forEachBlocksInRange = function _forEachBlocksInRange(fromPos, toPos, fn) {
}
_blockStartPos(blockIndex) {
return this._blocks.slice(0, blockIndex).reduce((pos, b) => pos += b.displayValue.length, 0);
}
_forEachBlocksInRange(fromPos, toPos, fn) {
if (toPos === void 0) {
toPos = this.displayValue.length;
}
var fromBlockIter = this._mapPosToBlock(fromPos);
const fromBlockIter = this._mapPosToBlock(fromPos);
if (fromBlockIter) {
var toBlockIter = this._mapPosToBlock(toPos);
const toBlockIter = this._mapPosToBlock(toPos);
// process first block
var isSameBlock = toBlockIter && fromBlockIter.index === toBlockIter.index;
var fromBlockStartPos = fromBlockIter.offset;
var fromBlockEndPos = toBlockIter && isSameBlock ? toBlockIter.offset : this._blocks[fromBlockIter.index].displayValue.length;
const isSameBlock = toBlockIter && fromBlockIter.index === toBlockIter.index;
const fromBlockStartPos = fromBlockIter.offset;
const fromBlockEndPos = toBlockIter && isSameBlock ? toBlockIter.offset : this._blocks[fromBlockIter.index].displayValue.length;
fn(this._blocks[fromBlockIter.index], fromBlockIter.index, fromBlockStartPos, fromBlockEndPos);
if (toBlockIter && !isSameBlock) {
// process intermediate blocks
for (var bi = fromBlockIter.index + 1; bi < toBlockIter.index; ++bi) {
for (let bi = fromBlockIter.index + 1; bi < toBlockIter.index; ++bi) {
fn(this._blocks[bi], bi, 0, this._blocks[bi].displayValue.length);

@@ -369,4 +353,4 @@ }

}
};
_proto.remove = function remove(fromPos, toPos) {
}
remove(fromPos, toPos) {
if (fromPos === void 0) {

@@ -378,9 +362,9 @@ fromPos = 0;

}
var removeDetails = _Masked.prototype.remove.call(this, fromPos, toPos);
this._forEachBlocksInRange(fromPos, toPos, function (b, _, bFromPos, bToPos) {
const removeDetails = super.remove(fromPos, toPos);
this._forEachBlocksInRange(fromPos, toPos, (b, _, bFromPos, bToPos) => {
removeDetails.aggregate(b.remove(bFromPos, bToPos));
});
return removeDetails;
};
_proto.nearestInputPos = function nearestInputPos(cursorPos, direction) {
}
nearestInputPos(cursorPos, direction) {
if (direction === void 0) {

@@ -390,3 +374,3 @@ direction = DIRECTION.NONE;

if (!this._blocks.length) return 0;
var cursor = new PatternCursor(this, cursorPos);
const cursor = new PatternCursor(this, cursorPos);
if (direction === DIRECTION.NONE) {

@@ -448,4 +432,4 @@ // -------------------------------------------------

return cursorPos;
};
_proto.totalInputPositions = function totalInputPositions(fromPos, toPos) {
}
totalInputPositions(fromPos, toPos) {
if (fromPos === void 0) {

@@ -457,4 +441,4 @@ fromPos = 0;

}
var total = 0;
this._forEachBlocksInRange(fromPos, toPos, function (b, _, bFromPos, bToPos) {
let total = 0;
this._forEachBlocksInRange(fromPos, toPos, (b, _, bFromPos, bToPos) => {
total += b.totalInputPositions(bFromPos, bToPos);

@@ -465,123 +449,14 @@ });

/** Get block by name */;
_proto.maskedBlock = function maskedBlock(name) {
/** Get block by name */
maskedBlock(name) {
return this.maskedBlocks(name)[0];
}
/** Get all blocks by name */;
_proto.maskedBlocks = function maskedBlocks(name) {
var _this4 = this;
var indices = this._maskedBlocks[name];
/** Get all blocks by name */
maskedBlocks(name) {
const indices = this._maskedBlocks[name];
if (!indices) return [];
return _mapInstanceProperty(indices).call(indices, function (gi) {
return _this4._blocks[gi];
});
};
_createClass(MaskedPattern, [{
key: "state",
get: function get() {
var _context5;
return _extends({}, _Masked.prototype.state, {
_blocks: _mapInstanceProperty(_context5 = this._blocks).call(_context5, function (b) {
return b.state;
})
});
},
set: function set(state) {
var _blocks = state._blocks,
maskedState = _objectWithoutPropertiesLoose(state, _excluded2);
this._blocks.forEach(function (b, bi) {
return b.state = _blocks[bi];
});
this.state = maskedState;
}
}, {
key: "isComplete",
get: function get() {
return this.exposeBlock ? this.exposeBlock.isComplete : this._blocks.every(function (b) {
return b.isComplete;
});
}
}, {
key: "isFilled",
get: function get() {
return this._blocks.every(function (b) {
return b.isFilled;
});
}
}, {
key: "isFixed",
get: function get() {
return this._blocks.every(function (b) {
return b.isFixed;
});
}
}, {
key: "isOptional",
get: function get() {
return this._blocks.every(function (b) {
return b.isOptional;
});
}
}, {
key: "unmaskedValue",
get: function get() {
var _context6;
return this.exposeBlock ? this.exposeBlock.unmaskedValue : _reduceInstanceProperty(_context6 = this._blocks).call(_context6, function (str, b) {
return str += b.unmaskedValue;
}, '');
},
set: function set(unmaskedValue) {
if (this.exposeBlock) {
var _context7;
var tail = this.extractTail(this._blockStartPos(_indexOfInstanceProperty(_context7 = this._blocks).call(_context7, this.exposeBlock)) + this.exposeBlock.displayValue.length);
this.exposeBlock.unmaskedValue = unmaskedValue;
this.appendTail(tail);
this.doCommit();
} else this.unmaskedValue = unmaskedValue;
}
}, {
key: "value",
get: function get() {
var _context8;
return this.exposeBlock ? this.exposeBlock.value :
// TODO return _value when not in change?
_reduceInstanceProperty(_context8 = this._blocks).call(_context8, function (str, b) {
return str += b.value;
}, '');
},
set: function set(value) {
if (this.exposeBlock) {
var _context9;
var tail = this.extractTail(this._blockStartPos(_indexOfInstanceProperty(_context9 = this._blocks).call(_context9, this.exposeBlock)) + this.exposeBlock.displayValue.length);
this.exposeBlock.value = value;
this.appendTail(tail);
this.doCommit();
} else this.value = value;
}
}, {
key: "typedValue",
get: function get() {
return this.exposeBlock ? this.exposeBlock.typedValue : _Masked.prototype.typedValue;
},
set: function set(value) {
if (this.exposeBlock) {
var _context10;
var tail = this.extractTail(this._blockStartPos(_indexOfInstanceProperty(_context10 = this._blocks).call(_context10, this.exposeBlock)) + this.exposeBlock.displayValue.length);
this.exposeBlock.typedValue = value;
this.appendTail(tail);
this.doCommit();
} else this.typedValue = value;
}
}, {
key: "displayValue",
get: function get() {
var _context11;
return _reduceInstanceProperty(_context11 = this._blocks).call(_context11, function (str, b) {
return str += b.displayValue;
}, '');
}
}]);
return MaskedPattern;
}(Masked);
return indices.map(gi => this._blocks[gi]);
}
}
MaskedPattern.DEFAULTS = {

@@ -588,0 +463,0 @@ lazy: true,

@@ -1,24 +0,10 @@

import _objectWithoutPropertiesLoose from '@babel/runtime-corejs3/helpers/objectWithoutPropertiesLoose';
import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import { _ as _mapInstanceProperty } from '../../map-4c47454e.js';
import { _ as _indexOfInstanceProperty } from '../../index-of-358e281e.js';
import { _ as _sliceInstanceProperty } from '../../slice-3858f58a.js';
import { _ as _spliceInstanceProperty } from '../../splice-dccbddd9.js';
import { _ as _Object$assign } from '../../assign-c82cbe95.js';
import ChangeDetails from '../../core/change-details.js';
import { i as isString } from '../../utils-e384b131.js';
import { isString } from '../../core/utils.js';
import ContinuousTailDetails from '../../core/continuous-tail-details.js';
import IMask from '../../core/holder.js';
import '../../object-keys-53d74329.js';
import '../../array-species-create-349ea110.js';
import '../../classof-c2d10e36.js';
import '../../does-not-exceed-safe-integer-d06d288d.js';
import '../../delete-property-or-throw-2b53787c.js';
import '../../keys-e9789594.js';
var _excluded = ["chunks"];
var ChunksTailDetails = /*#__PURE__*/function () {
class ChunksTailDetails {
/** */
function ChunksTailDetails(chunks, from) {
constructor(chunks, from) {
if (chunks === void 0) {

@@ -33,12 +19,10 @@ chunks = [];

}
var _proto = ChunksTailDetails.prototype;
_proto.toString = function toString() {
var _context;
return _mapInstanceProperty(_context = this.chunks).call(_context, String).join('');
};
_proto.extend = function extend(tailChunk) {
toString() {
return this.chunks.map(String).join('');
}
extend(tailChunk) {
if (!String(tailChunk)) return;
tailChunk = isString(tailChunk) ? new ContinuousTailDetails(String(tailChunk)) : tailChunk;
var lastChunk = this.chunks[this.chunks.length - 1];
var extendLast = lastChunk && (
const lastChunk = this.chunks[this.chunks.length - 1];
const extendLast = lastChunk && (
// if stops are same or tail has no stop

@@ -60,3 +44,3 @@ lastChunk.stop === tailChunk.stop || tailChunk.stop == null) &&

// unwrap floating chunks to parent, keeping `from` pos
var firstTailChunk;
let firstTailChunk;
while (tailChunk.chunks.length && tailChunk.chunks[0].stop == null) {

@@ -76,22 +60,21 @@ firstTailChunk = tailChunk.chunks.shift(); // not possible to be `undefined` because length was checked above

}
};
_proto.appendTo = function appendTo(masked) {
}
appendTo(masked) {
if (!(masked instanceof IMask.MaskedPattern)) {
var tail = new ContinuousTailDetails(this.toString());
const tail = new ContinuousTailDetails(this.toString());
return tail.appendTo(masked);
}
var details = new ChangeDetails();
for (var ci = 0; ci < this.chunks.length && !details.skip; ++ci) {
var chunk = this.chunks[ci];
var lastBlockIter = masked._mapPosToBlock(masked.displayValue.length);
var stop = chunk.stop;
var chunkBlock = void 0;
const details = new ChangeDetails();
for (let ci = 0; ci < this.chunks.length && !details.skip; ++ci) {
const chunk = this.chunks[ci];
const lastBlockIter = masked._mapPosToBlock(masked.displayValue.length);
const stop = chunk.stop;
let chunkBlock;
if (stop != null && (
// if block not found or stop is behind lastBlock
!lastBlockIter || lastBlockIter.index <= stop)) {
var _context2;
if (chunk instanceof ChunksTailDetails ||
// for continuous block also check if stop is exist
_indexOfInstanceProperty(_context2 = masked._stops).call(_context2, stop) >= 0) {
var phDetails = masked._appendPlaceholder(stop);
masked._stops.indexOf(stop) >= 0) {
const phDetails = masked._appendPlaceholder(stop);
details.aggregate(phDetails);

@@ -102,4 +85,3 @@ }

if (chunkBlock) {
var _context3;
var tailDetails = chunkBlock.appendTail(chunk);
const tailDetails = chunkBlock.appendTail(chunk);
tailDetails.skip = false; // always ignore skip, it will be set on last

@@ -110,3 +92,3 @@ details.aggregate(tailDetails);

// get not inserted chars
var remainChars = _sliceInstanceProperty(_context3 = chunk.toString()).call(_context3, tailDetails.rawInserted.length);
const remainChars = chunk.toString().slice(tailDetails.rawInserted.length);
if (remainChars) details.aggregate(masked.append(remainChars, {

@@ -122,10 +104,30 @@ tail: true

return details;
};
_proto.unshift = function unshift(beforePos) {
}
get state() {
return {
chunks: this.chunks.map(c => c.state),
from: this.from,
stop: this.stop,
blockIndex: this.blockIndex
};
}
set state(state) {
const {
chunks,
...props
} = state;
Object.assign(this, props);
this.chunks = chunks.map(cstate => {
const chunk = "chunks" in cstate ? new ChunksTailDetails() : new ContinuousTailDetails();
chunk.state = cstate;
return chunk;
});
}
unshift(beforePos) {
if (!this.chunks.length || beforePos != null && this.from >= beforePos) return '';
var chunkShiftPos = beforePos != null ? beforePos - this.from : beforePos;
var ci = 0;
const chunkShiftPos = beforePos != null ? beforePos - this.from : beforePos;
let ci = 0;
while (ci < this.chunks.length) {
var chunk = this.chunks[ci];
var shiftChar = chunk.unshift(chunkShiftPos);
const chunk = this.chunks[ci];
const shiftChar = chunk.unshift(chunkShiftPos);
if (chunk.toString()) {

@@ -137,5 +139,4 @@ // chunk still contains value

} else {
var _context4;
// clean if chunk has no value
_spliceInstanceProperty(_context4 = this.chunks).call(_context4, ci, 1);
this.chunks.splice(ci, 1);
}

@@ -145,9 +146,9 @@ if (shiftChar) return shiftChar;

return '';
};
_proto.shift = function shift() {
}
shift() {
if (!this.chunks.length) return '';
var ci = this.chunks.length - 1;
let ci = this.chunks.length - 1;
while (0 <= ci) {
var chunk = this.chunks[ci];
var shiftChar = chunk.shift();
const chunk = this.chunks[ci];
const shiftChar = chunk.shift();
if (chunk.toString()) {

@@ -159,5 +160,4 @@ // chunk still contains value

} else {
var _context5;
// clean if chunk has no value
_spliceInstanceProperty(_context5 = this.chunks).call(_context5, ci, 1);
this.chunks.splice(ci, 1);
}

@@ -167,30 +167,5 @@ if (shiftChar) return shiftChar;

return '';
};
_createClass(ChunksTailDetails, [{
key: "state",
get: function get() {
var _context6;
return {
chunks: _mapInstanceProperty(_context6 = this.chunks).call(_context6, function (c) {
return c.state;
}),
from: this.from,
stop: this.stop,
blockIndex: this.blockIndex
};
},
set: function set(state) {
var chunks = state.chunks,
props = _objectWithoutPropertiesLoose(state, _excluded);
_Object$assign(this, props);
this.chunks = _mapInstanceProperty(chunks).call(chunks, function (cstate) {
var chunk = "chunks" in cstate ? new ChunksTailDetails() : new ContinuousTailDetails();
chunk.state = cstate;
return chunk;
});
}
}]);
return ChunksTailDetails;
}();
}
}
export { ChunksTailDetails as default };

@@ -1,25 +0,21 @@

import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import { _ as _Object$assign } from '../../assign-c82cbe95.js';
import { D as DIRECTION } from '../../utils-e384b131.js';
import '../../object-keys-53d74329.js';
import '../../classof-c2d10e36.js';
import '../../keys-e9789594.js';
import { DIRECTION } from '../../core/utils.js';
var PatternCursor = /*#__PURE__*/function () {
function PatternCursor(masked, pos) {
class PatternCursor {
constructor(masked, pos) {
this.masked = masked;
this._log = [];
var _ref = masked._mapPosToBlock(pos) || (pos < 0 ?
// first
{
index: 0,
offset: 0
} :
// last
{
index: this.masked._blocks.length,
offset: 0
}),
offset = _ref.offset,
index = _ref.index;
const {
offset,
index
} = masked._mapPosToBlock(pos) || (pos < 0 ?
// first
{
index: 0,
offset: 0
} :
// last
{
index: this.masked._blocks.length,
offset: 0
});
this.offset = offset;

@@ -29,12 +25,27 @@ this.index = index;

}
var _proto = PatternCursor.prototype;
_proto.pushState = function pushState() {
get block() {
return this.masked._blocks[this.index];
}
get pos() {
return this.masked._blockStartPos(this.index) + this.offset;
}
get state() {
return {
index: this.index,
offset: this.offset,
ok: this.ok
};
}
set state(s) {
Object.assign(this, s);
}
pushState() {
this._log.push(this.state);
};
_proto.popState = function popState() {
var s = this._log.pop();
}
popState() {
const s = this._log.pop();
if (s) this.state = s;
return s;
};
_proto.bindBlock = function bindBlock() {
}
bindBlock() {
if (this.block) return;

@@ -49,4 +60,5 @@ if (this.index < 0) {

}
};
_proto._pushLeft = function _pushLeft(fn) {
}
_pushLeft(fn) {
this.pushState();

@@ -58,4 +70,4 @@ for (this.bindBlock(); 0 <= this.index; --this.index, this.offset = ((_this$block = this.block) == null ? void 0 : _this$block.displayValue.length) || 0) {

return this.ok = false;
};
_proto._pushRight = function _pushRight(fn) {
}
_pushRight(fn) {
this.pushState();

@@ -66,13 +78,11 @@ for (this.bindBlock(); this.index < this.masked._blocks.length; ++this.index, this.offset = 0) {

return this.ok = false;
};
_proto.pushLeftBeforeFilled = function pushLeftBeforeFilled() {
var _this = this;
return this._pushLeft(function () {
if (_this.block.isFixed || !_this.block.value) return;
_this.offset = _this.block.nearestInputPos(_this.offset, DIRECTION.FORCE_LEFT);
if (_this.offset !== 0) return true;
}
pushLeftBeforeFilled() {
return this._pushLeft(() => {
if (this.block.isFixed || !this.block.value) return;
this.offset = this.block.nearestInputPos(this.offset, DIRECTION.FORCE_LEFT);
if (this.offset !== 0) return true;
});
};
_proto.pushLeftBeforeInput = function pushLeftBeforeInput() {
var _this2 = this;
}
pushLeftBeforeInput() {
// cases:

@@ -82,31 +92,28 @@ // filled input: 00|

// nested block: XX<[]>|
return this._pushLeft(function () {
if (_this2.block.isFixed) return;
_this2.offset = _this2.block.nearestInputPos(_this2.offset, DIRECTION.LEFT);
return this._pushLeft(() => {
if (this.block.isFixed) return;
this.offset = this.block.nearestInputPos(this.offset, DIRECTION.LEFT);
return true;
});
};
_proto.pushLeftBeforeRequired = function pushLeftBeforeRequired() {
var _this3 = this;
return this._pushLeft(function () {
if (_this3.block.isFixed || _this3.block.isOptional && !_this3.block.value) return;
_this3.offset = _this3.block.nearestInputPos(_this3.offset, DIRECTION.LEFT);
}
pushLeftBeforeRequired() {
return this._pushLeft(() => {
if (this.block.isFixed || this.block.isOptional && !this.block.value) return;
this.offset = this.block.nearestInputPos(this.offset, DIRECTION.LEFT);
return true;
});
};
_proto.pushRightBeforeFilled = function pushRightBeforeFilled() {
var _this4 = this;
return this._pushRight(function () {
if (_this4.block.isFixed || !_this4.block.value) return;
_this4.offset = _this4.block.nearestInputPos(_this4.offset, DIRECTION.FORCE_RIGHT);
if (_this4.offset !== _this4.block.value.length) return true;
}
pushRightBeforeFilled() {
return this._pushRight(() => {
if (this.block.isFixed || !this.block.value) return;
this.offset = this.block.nearestInputPos(this.offset, DIRECTION.FORCE_RIGHT);
if (this.offset !== this.block.value.length) return true;
});
};
_proto.pushRightBeforeInput = function pushRightBeforeInput() {
var _this5 = this;
return this._pushRight(function () {
if (_this5.block.isFixed) return;
}
pushRightBeforeInput() {
return this._pushRight(() => {
if (this.block.isFixed) return;
// const o = this.offset;
_this5.offset = _this5.block.nearestInputPos(_this5.offset, DIRECTION.NONE);
this.offset = this.block.nearestInputPos(this.offset, DIRECTION.NONE);
// HACK cases like (STILL DOES NOT WORK FOR NESTED)

@@ -118,39 +125,14 @@ // aa|X

});
};
_proto.pushRightBeforeRequired = function pushRightBeforeRequired() {
var _this6 = this;
return this._pushRight(function () {
if (_this6.block.isFixed || _this6.block.isOptional && !_this6.block.value) return;
}
pushRightBeforeRequired() {
return this._pushRight(() => {
if (this.block.isFixed || this.block.isOptional && !this.block.value) return;
// TODO check |[*]XX_
_this6.offset = _this6.block.nearestInputPos(_this6.offset, DIRECTION.NONE);
this.offset = this.block.nearestInputPos(this.offset, DIRECTION.NONE);
return true;
});
};
_createClass(PatternCursor, [{
key: "block",
get: function get() {
return this.masked._blocks[this.index];
}
}, {
key: "pos",
get: function get() {
return this.masked._blockStartPos(this.index) + this.offset;
}
}, {
key: "state",
get: function get() {
return {
index: this.index,
offset: this.offset,
ok: this.ok
};
},
set: function set(s) {
_Object$assign(this, s);
}
}]);
return PatternCursor;
}();
}
}
export { PatternCursor as default };

@@ -1,13 +0,7 @@

import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import { _ as _Object$assign } from '../../assign-c82cbe95.js';
import { _ as _sliceInstanceProperty } from '../../slice-3858f58a.js';
import ChangeDetails from '../../core/change-details.js';
import { D as DIRECTION, i as isString } from '../../utils-e384b131.js';
import { DIRECTION, isString } from '../../core/utils.js';
import ContinuousTailDetails from '../../core/continuous-tail-details.js';
import '../../object-keys-53d74329.js';
import '../../classof-c2d10e36.js';
import '../../core/holder.js';
import '../../keys-e9789594.js';
var PatternFixedDefinition = /*#__PURE__*/function () {
class PatternFixedDefinition {
/** */

@@ -25,14 +19,24 @@

function PatternFixedDefinition(opts) {
_Object$assign(this, opts);
constructor(opts) {
Object.assign(this, opts);
this._value = '';
this.isFixed = true;
}
var _proto = PatternFixedDefinition.prototype;
_proto.reset = function reset() {
get value() {
return this._value;
}
get unmaskedValue() {
return this.isUnmasking ? this.value : '';
}
get rawInputValue() {
return this._isRawInput ? this.value : '';
}
get displayValue() {
return this.value;
}
reset() {
this._isRawInput = false;
this._value = '';
};
_proto.remove = function remove(fromPos, toPos) {
var _context, _context2;
}
remove(fromPos, toPos) {
if (fromPos === void 0) {

@@ -44,12 +48,12 @@ fromPos = 0;

}
this._value = _sliceInstanceProperty(_context = this._value).call(_context, 0, fromPos) + _sliceInstanceProperty(_context2 = this._value).call(_context2, toPos);
this._value = this._value.slice(0, fromPos) + this._value.slice(toPos);
if (!this._value) this._isRawInput = false;
return new ChangeDetails();
};
_proto.nearestInputPos = function nearestInputPos(cursorPos, direction) {
}
nearestInputPos(cursorPos, direction) {
if (direction === void 0) {
direction = DIRECTION.NONE;
}
var minPos = 0;
var maxPos = this._value.length;
const minPos = 0;
const maxPos = this._value.length;
switch (direction) {

@@ -65,4 +69,4 @@ case DIRECTION.LEFT:

}
};
_proto.totalInputPositions = function totalInputPositions(fromPos, toPos) {
}
totalInputPositions(fromPos, toPos) {
if (fromPos === void 0) {

@@ -75,5 +79,4 @@ fromPos = 0;

return this._isRawInput ? toPos - fromPos : 0;
};
_proto.extractInput = function extractInput(fromPos, toPos, flags) {
var _context3;
}
extractInput(fromPos, toPos, flags) {
if (fromPos === void 0) {

@@ -88,13 +91,19 @@ fromPos = 0;

}
return flags.raw && this._isRawInput && _sliceInstanceProperty(_context3 = this._value).call(_context3, fromPos, toPos) || '';
};
_proto._appendChar = function _appendChar(ch, flags) {
return flags.raw && this._isRawInput && this._value.slice(fromPos, toPos) || '';
}
get isComplete() {
return true;
}
get isFilled() {
return Boolean(this._value);
}
_appendChar(ch, flags) {
if (flags === void 0) {
flags = {};
}
var details = new ChangeDetails();
const details = new ChangeDetails();
if (this.isFilled) return details;
var appendEager = this.eager === true || this.eager === 'append';
var appended = this.char === ch;
var isResolved = appended && (this.isUnmasking || flags.input || flags.raw) && (!flags.raw || !appendEager) && !flags.tail;
const appendEager = this.eager === true || this.eager === 'append';
const appended = this.char === ch;
const isResolved = appended && (this.isUnmasking || flags.input || flags.raw) && (!flags.raw || !appendEager) && !flags.tail;
if (isResolved) details.rawInserted = this.char;

@@ -104,23 +113,23 @@ this._value = details.inserted = this.char;

return details;
};
_proto._appendEager = function _appendEager() {
}
_appendEager() {
return this._appendChar(this.char, {
tail: true
});
};
_proto._appendPlaceholder = function _appendPlaceholder() {
var details = new ChangeDetails();
}
_appendPlaceholder() {
const details = new ChangeDetails();
if (this.isFilled) return details;
this._value = details.inserted = this.char;
return details;
};
_proto.extractTail = function extractTail() {
}
extractTail() {
return new ContinuousTailDetails('');
};
_proto.appendTail = function appendTail(tail) {
}
appendTail(tail) {
if (isString(tail)) tail = new ContinuousTailDetails(String(tail));
return tail.appendTo(this);
};
_proto.append = function append(str, flags, tail) {
var details = this._appendChar(str[0], flags);
}
append(str, flags, tail) {
const details = this._appendChar(str[0], flags);
if (tail != null) {

@@ -130,50 +139,16 @@ details.tailShift += this.appendTail(tail).tailShift;

return details;
};
_proto.doCommit = function doCommit() {};
_createClass(PatternFixedDefinition, [{
key: "value",
get: function get() {
return this._value;
}
}, {
key: "unmaskedValue",
get: function get() {
return this.isUnmasking ? this.value : '';
}
}, {
key: "rawInputValue",
get: function get() {
return this._isRawInput ? this.value : '';
}
}, {
key: "displayValue",
get: function get() {
return this.value;
}
}, {
key: "isComplete",
get: function get() {
return true;
}
}, {
key: "isFilled",
get: function get() {
return Boolean(this._value);
}
}, {
key: "state",
get: function get() {
return {
_value: this._value,
_rawInputValue: this.rawInputValue
};
},
set: function set(state) {
this._value = state._value;
this._isRawInput = Boolean(state._rawInputValue);
}
}]);
return PatternFixedDefinition;
}();
}
doCommit() {}
get state() {
return {
_value: this._value,
_rawInputValue: this.rawInputValue
};
}
set state(state) {
this._value = state._value;
this._isRawInput = Boolean(state._rawInputValue);
}
}
export { PatternFixedDefinition as default };

@@ -1,16 +0,7 @@

import _extends from '@babel/runtime-corejs3/helpers/extends';
import _objectWithoutPropertiesLoose from '@babel/runtime-corejs3/helpers/objectWithoutPropertiesLoose';
import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import { _ as _Object$assign } from '../../assign-c82cbe95.js';
import { _ as _sliceInstanceProperty } from '../../slice-3858f58a.js';
import createMask from '../factory.js';
import ChangeDetails from '../../core/change-details.js';
import { D as DIRECTION } from '../../utils-e384b131.js';
import '../../object-keys-53d74329.js';
import '../../classof-c2d10e36.js';
import { DIRECTION } from '../../core/utils.js';
import '../../core/holder.js';
import '../../keys-e9789594.js';
var _excluded = ["parent", "isOptional", "placeholderChar", "displayChar", "lazy", "eager"];
var PatternInputDefinition = /*#__PURE__*/function () {
class PatternInputDefinition {
/** */

@@ -32,26 +23,27 @@

function PatternInputDefinition(opts) {
var parent = opts.parent,
isOptional = opts.isOptional,
placeholderChar = opts.placeholderChar,
displayChar = opts.displayChar,
lazy = opts.lazy,
eager = opts.eager,
maskOpts = _objectWithoutPropertiesLoose(opts, _excluded);
constructor(opts) {
const {
parent,
isOptional,
placeholderChar,
displayChar,
lazy,
eager,
...maskOpts
} = opts;
this.masked = createMask(maskOpts);
_Object$assign(this, {
parent: parent,
isOptional: isOptional,
placeholderChar: placeholderChar,
displayChar: displayChar,
lazy: lazy,
eager: eager
Object.assign(this, {
parent,
isOptional,
placeholderChar,
displayChar,
lazy,
eager
});
}
var _proto = PatternInputDefinition.prototype;
_proto.reset = function reset() {
reset() {
this.isFilled = false;
this.masked.reset();
};
_proto.remove = function remove(fromPos, toPos) {
}
remove(fromPos, toPos) {
if (fromPos === void 0) {

@@ -68,4 +60,19 @@ fromPos = 0;

return new ChangeDetails();
};
_proto._appendChar = function _appendChar(ch, flags) {
}
get value() {
return this.masked.value || (this.isFilled && !this.isOptional ? this.placeholderChar : '');
}
get unmaskedValue() {
return this.masked.unmaskedValue;
}
get rawInputValue() {
return this.masked.rawInputValue;
}
get displayValue() {
return this.masked.value && this.displayChar || this.value;
}
get isComplete() {
return Boolean(this.masked.value) || this.isOptional;
}
_appendChar(ch, flags) {
if (flags === void 0) {

@@ -75,5 +82,5 @@ flags = {};

if (this.isFilled) return new ChangeDetails();
var state = this.masked.state;
const state = this.masked.state;
// simulate input
var details = this.masked._appendChar(ch, this.currentMaskFlags(flags));
const details = this.masked._appendChar(ch, this.currentMaskFlags(flags));
if (details.inserted && this.doValidate(flags) === false) {

@@ -89,9 +96,9 @@ details.inserted = details.rawInserted = '';

return details;
};
_proto.append = function append(str, flags, tail) {
}
append(str, flags, tail) {
// TODO probably should be done via _appendChar
return this.masked.append(str, this.currentMaskFlags(flags), tail);
};
_proto._appendPlaceholder = function _appendPlaceholder() {
var details = new ChangeDetails();
}
_appendPlaceholder() {
const details = new ChangeDetails();
if (this.isFilled || this.isOptional) return details;

@@ -101,13 +108,13 @@ this.isFilled = true;

return details;
};
_proto._appendEager = function _appendEager() {
}
_appendEager() {
return new ChangeDetails();
};
_proto.extractTail = function extractTail(fromPos, toPos) {
}
extractTail(fromPos, toPos) {
return this.masked.extractTail(fromPos, toPos);
};
_proto.appendTail = function appendTail(tail) {
}
appendTail(tail) {
return this.masked.appendTail(tail);
};
_proto.extractInput = function extractInput(fromPos, toPos, flags) {
}
extractInput(fromPos, toPos, flags) {
if (fromPos === void 0) {

@@ -120,10 +127,10 @@ fromPos = 0;

return this.masked.extractInput(fromPos, toPos, flags);
};
_proto.nearestInputPos = function nearestInputPos(cursorPos, direction) {
}
nearestInputPos(cursorPos, direction) {
if (direction === void 0) {
direction = DIRECTION.NONE;
}
var minPos = 0;
var maxPos = this.value.length;
var boundPos = Math.min(Math.max(cursorPos, minPos), maxPos);
const minPos = 0;
const maxPos = this.value.length;
const boundPos = Math.min(Math.max(cursorPos, minPos), maxPos);
switch (direction) {

@@ -140,5 +147,4 @@ case DIRECTION.LEFT:

}
};
_proto.totalInputPositions = function totalInputPositions(fromPos, toPos) {
var _context;
}
totalInputPositions(fromPos, toPos) {
if (fromPos === void 0) {

@@ -150,58 +156,30 @@ fromPos = 0;

}
return _sliceInstanceProperty(_context = this.value).call(_context, fromPos, toPos).length;
};
_proto.doValidate = function doValidate(flags) {
return this.value.slice(fromPos, toPos).length;
}
doValidate(flags) {
return this.masked.doValidate(this.currentMaskFlags(flags)) && (!this.parent || this.parent.doValidate(this.currentMaskFlags(flags)));
};
_proto.doCommit = function doCommit() {
}
doCommit() {
this.masked.doCommit();
};
_proto.currentMaskFlags = function currentMaskFlags(flags) {
}
get state() {
return {
_value: this.value,
_rawInputValue: this.rawInputValue,
masked: this.masked.state,
isFilled: this.isFilled
};
}
set state(state) {
this.masked.state = state.masked;
this.isFilled = state.isFilled;
}
currentMaskFlags(flags) {
var _flags$_beforeTailSta;
return _extends({}, flags, {
return {
...flags,
_beforeTailState: (flags == null || (_flags$_beforeTailSta = flags._beforeTailState) == null ? void 0 : _flags$_beforeTailSta.masked) || (flags == null ? void 0 : flags._beforeTailState)
});
};
_createClass(PatternInputDefinition, [{
key: "value",
get: function get() {
return this.masked.value || (this.isFilled && !this.isOptional ? this.placeholderChar : '');
}
}, {
key: "unmaskedValue",
get: function get() {
return this.masked.unmaskedValue;
}
}, {
key: "rawInputValue",
get: function get() {
return this.masked.rawInputValue;
}
}, {
key: "displayValue",
get: function get() {
return this.masked.value && this.displayChar || this.value;
}
}, {
key: "isComplete",
get: function get() {
return Boolean(this.masked.value) || this.isOptional;
}
}, {
key: "state",
get: function get() {
return {
_value: this.value,
_rawInputValue: this.rawInputValue,
masked: this.masked.state,
isFilled: this.isFilled
};
},
set: function set(state) {
this.masked.state = state.masked;
this.isFilled = state.isFilled;
}
}]);
return PatternInputDefinition;
}();
};
}
}
PatternInputDefinition.DEFAULT_DEFINITIONS = {

@@ -208,0 +186,0 @@ '0': /\d/,

import createMask from './factory.js';
import IMask from '../core/holder.js';
import '@babel/runtime-corejs3/helpers/extends';
import '@babel/runtime-corejs3/helpers/objectWithoutPropertiesLoose';
import '../object-keys-53d74329.js';
import '../utils-e384b131.js';
import '../classof-c2d10e36.js';
import '../keys-e9789594.js';
import '../core/utils.js';
/** Mask pipe source and destination types */
var PIPE_TYPE = {
const PIPE_TYPE = {
MASKED: 'value',

@@ -24,9 +19,7 @@ UNMASKED: 'unmaskedValue',

}
var masked = createMask(arg);
return function (value) {
return masked.runIsolated(function (m) {
m[from] = value;
return m[to];
});
};
const masked = createMask(arg);
return value => masked.runIsolated(m => {
m[from] = value;
return m[to];
});
}

@@ -33,0 +26,0 @@

@@ -1,23 +0,5 @@

import '@babel/runtime-corejs3/helpers/objectWithoutPropertiesLoose';
import '@babel/runtime-corejs3/helpers/createClass';
import '@babel/runtime-corejs3/helpers/inheritsLoose';
export { M as default } from '../range-8d4c25a9.js';
import '../slice-3858f58a.js';
import '../repeat-ac2db5c6.js';
import '../pad-end-35f0c153.js';
import '../core/holder.js';
import './pattern.js';
import '../object-keys-53d74329.js';
import '../classof-c2d10e36.js';
import '../string-repeat-21c9f19e.js';
import '../utils-e384b131.js';
import '../keys-e9789594.js';
import '@babel/runtime-corejs3/helpers/extends';
import '../assign-c82cbe95.js';
import '../map-4c47454e.js';
import '../array-species-create-349ea110.js';
import '../index-of-358e281e.js';
import '../sort-e1545525.js';
import '../delete-property-or-throw-2b53787c.js';
import IMask from '../core/holder.js';
import MaskedPattern from './pattern.js';
import '../core/change-details.js';
import '../core/utils.js';
import './base.js';

@@ -27,4 +9,2 @@ import '../core/continuous-tail-details.js';

import './pattern/chunk-tail-details.js';
import '../splice-dccbddd9.js';
import '../does-not-exceed-safe-integer-d06d288d.js';
import './pattern/cursor.js';

@@ -34,1 +14,91 @@ import './pattern/fixed-definition.js';

import './regexp.js';
/** Pattern which accepts ranges */
class MaskedRange extends MaskedPattern {
/**
Optionally sets max length of pattern.
Used when pattern length is longer then `to` param length. Pads zeros at start in this case.
*/
/** Min bound */
/** Max bound */
/** */
get _matchFrom() {
return this.maxLength - String(this.from).length;
}
constructor(opts) {
super(opts); // mask will be created in _update
}
updateOptions(opts) {
super.updateOptions(opts);
}
_update(opts) {
const {
to = this.to || 0,
from = this.from || 0,
maxLength = this.maxLength || 0,
autofix = this.autofix,
...patternOpts
} = opts;
this.to = to;
this.from = from;
this.maxLength = Math.max(String(to).length, maxLength);
this.autofix = autofix;
const fromStr = String(this.from).padStart(this.maxLength, '0');
const toStr = String(this.to).padStart(this.maxLength, '0');
let sameCharsCount = 0;
while (sameCharsCount < toStr.length && toStr[sameCharsCount] === fromStr[sameCharsCount]) ++sameCharsCount;
patternOpts.mask = toStr.slice(0, sameCharsCount).replace(/0/g, '\\0') + '0'.repeat(this.maxLength - sameCharsCount);
super._update(patternOpts);
}
get isComplete() {
return super.isComplete && Boolean(this.value);
}
boundaries(str) {
let minstr = '';
let maxstr = '';
const [, placeholder, num] = str.match(/^(\D*)(\d*)(\D*)/) || [];
if (num) {
minstr = '0'.repeat(placeholder.length) + num;
maxstr = '9'.repeat(placeholder.length) + num;
}
minstr = minstr.padEnd(this.maxLength, '0');
maxstr = maxstr.padEnd(this.maxLength, '9');
return [minstr, maxstr];
}
doPrepareChar(ch, flags) {
if (flags === void 0) {
flags = {};
}
let details;
[ch, details] = super.doPrepareChar(ch.replace(/\D/g, ''), flags);
if (!this.autofix || !ch) return [ch, details];
const fromStr = String(this.from).padStart(this.maxLength, '0');
const toStr = String(this.to).padStart(this.maxLength, '0');
const nextVal = this.value + ch;
if (nextVal.length > this.maxLength) return ['', details];
const [minstr, maxstr] = this.boundaries(nextVal);
if (Number(maxstr) < this.from) return [fromStr[nextVal.length - 1], details];
if (Number(minstr) > this.to) {
if (this.autofix === 'pad' && nextVal.length < this.maxLength) {
return ['', details.aggregate(this.append(fromStr[nextVal.length - 1] + ch, flags))];
}
return [toStr[nextVal.length - 1], details];
}
return [ch, details];
}
doValidate(flags) {
const str = this.value;
const firstNonZero = str.search(/[^0]/);
if (firstNonZero === -1 && str.length <= this._matchFrom) return true;
const [minstr, maxstr] = this.boundaries(str);
return this.from <= Number(maxstr) && Number(minstr) <= this.to && super.doValidate(flags);
}
}
IMask.MaskedRange = MaskedRange;
export { MaskedRange as default };

@@ -1,41 +0,28 @@

import _inheritsLoose from '@babel/runtime-corejs3/helpers/inheritsLoose';
import Masked from './base.js';
import IMask from '../core/holder.js';
import '@babel/runtime-corejs3/helpers/extends';
import '@babel/runtime-corejs3/helpers/createClass';
import '../keys-e9789594.js';
import '../object-keys-53d74329.js';
import '../assign-c82cbe95.js';
import '../slice-3858f58a.js';
import '../classof-c2d10e36.js';
import '../index-of-358e281e.js';
import '../utils-e384b131.js';
import '../core/change-details.js';
import '../core/continuous-tail-details.js';
import '../core/utils.js';
/** Masking by RegExp */
var MaskedRegExp = /*#__PURE__*/function (_Masked) {
_inheritsLoose(MaskedRegExp, _Masked);
function MaskedRegExp() {
return _Masked.apply(this, arguments) || this;
}
var _proto = MaskedRegExp.prototype;
class MaskedRegExp extends Masked {
/** */
/** Enable characters overwriting */
/** */
/** */
_proto.updateOptions = function updateOptions(opts) {
_Masked.prototype.updateOptions.call(this, opts);
};
_proto._update = function _update(opts) {
var mask = opts.mask;
if (mask) opts.validate = function (value) {
return value.search(mask) >= 0;
};
_Masked.prototype._update.call(this, opts);
};
return MaskedRegExp;
}(Masked);
updateOptions(opts) {
super.updateOptions(opts);
}
_update(opts) {
const mask = opts.mask;
if (mask) opts.validate = value => value.search(mask) >= 0;
super._update(opts);
}
}
IMask.MaskedRegExp = MaskedRegExp;
export { MaskedRegExp as default };
{
"name": "imask",
"version": "7.1.0-alpha.1",
"version": "7.1.0-alpha.2",
"author": "Alexey Kryazhev",

@@ -23,2 +23,3 @@ "license": "MIT",

},
"./esm": "./esm/index.js",
"./*": "./*"

@@ -40,3 +41,3 @@ },

],
"gitHead": "259cbd3af35425e29fd23a2a49b558daf0a0b1ab",
"gitHead": "1a94d24b5c6428c363dc63ca2c2f824e08155c50",
"dependencies": {

@@ -43,0 +44,0 @@ "@babel/runtime-corejs3": "^7.22.6"

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc