1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00

Libs updates and new version with option to pin videos on channel

This commit is contained in:
Daniel Neto 2024-08-05 11:37:04 -03:00
parent e1f2188de0
commit 1beab3b1c0
8565 changed files with 149805 additions and 165674 deletions

1010
node_modules/inputmask/Changelog.md generated vendored Normal file

File diff suppressed because it is too large Load diff

3
node_modules/inputmask/bundle.js generated vendored
View file

@ -8,4 +8,5 @@ import "./lib/extensions/inputmask.date.extensions";
import "./lib/extensions/inputmask.numeric.extensions";
import "./lib/inputmaskElement";
import Inputmask from "./lib/inputmask";
export default Inputmask;
export default Inputmask;

View file

@ -5,22 +5,27 @@
Licensed under the MIT license
*/
(function (factory) {
factory(jQuery, window.Inputmask, window);
}
(function ($, Inputmask, window) {
$(window.document).ajaxComplete(function (event, xmlHttpRequest, ajaxOptions) {
if ($.inArray("html", ajaxOptions.dataTypes) !== -1) {
$(".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias], [data-inputmask-regex]").each(function (ndx, lmnt) {
if (lmnt.inputmask === undefined) {
Inputmask().mask(lmnt);
}
});
}
}).ready(function () {
$(".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias],[data-inputmask-regex]").each(function (ndx, lmnt) {
if (lmnt.inputmask === undefined) {
Inputmask().mask(lmnt);
}
});
});
}));
factory(jQuery, window.Inputmask, window);
})(function ($, Inputmask, window) {
$(window.document)
.ajaxComplete(function (event, xmlHttpRequest, ajaxOptions) {
if ($.inArray("html", ajaxOptions.dataTypes) !== -1) {
$(
".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias], [data-inputmask-regex]"
).each(function (ndx, lmnt) {
if (lmnt.inputmask === undefined) {
Inputmask().mask(lmnt);
}
});
}
})
.ready(function () {
$(
".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias],[data-inputmask-regex]"
).each(function (ndx, lmnt) {
if (lmnt.inputmask === undefined) {
Inputmask().mask(lmnt);
}
});
});
});

65
node_modules/inputmask/dist/colormask.css generated vendored Normal file
View file

@ -0,0 +1,65 @@
mark.im-caret {
animation: 1s blink step-end infinite !important;
}
mark.im-caret-select {
background-color: rgba(0, 0, 0, 0.25);
}
@keyframes blink {
from, to {
border-right-color: black;
}
50% {
/*border-right-color: transparent;*/
border-right-color: white;
}
}
span.im-static {
color: grey;
}
div.im-colormask {
display: inline-block;
border-style: groove;
border-width: 1px;
appearance: textfield;
cursor: text;
}
div.im-colormask > input, div.im-colormask > input:-webkit-autofill {
position: absolute !important;
display: inline-block;
background-color: transparent;
color: transparent;
-webkit-text-fill-color: transparent;
transition: background-color 5000s ease-in-out 0s;
caret-color: transparent;
text-shadow: none;
appearance: textfield;
border-style: none;
left: 0; /*calculated*/
}
div.im-colormask > input:focus {
outline: none;
}
div.im-colormask > input::selection {
background: none;
}
div.im-colormask > input::-moz-selection {
background: none;
}
div.im-colormask > input:-webkit-autofill ~ div {
background-color: rgb(255, 255, 255);
}
div.im-colormask > div {
color: black;
display: inline-block;
width: 100px; /*calculated*/
}

3883
node_modules/inputmask/dist/colormask.js generated vendored Normal file

File diff suppressed because it is too large Load diff

8
node_modules/inputmask/dist/colormask.min.js generated vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,6 @@
// eslint-disable-next-line import/no-unresolved
import "./inputmask.js";
const inputmask = window.Inputmask;
window.Inputmask = undefined;
export default inputmask;
export default inputmask;

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -5,22 +5,27 @@
Licensed under the MIT license
*/
(function (factory) {
factory(jQuery, window.Inputmask, window);
}
(function ($, Inputmask, window) {
$(window.document).ajaxComplete(function (event, xmlHttpRequest, ajaxOptions) {
if ($.inArray("html", ajaxOptions.dataTypes) !== -1) {
$(".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias], [data-inputmask-regex]").each(function (ndx, lmnt) {
if (lmnt.inputmask === undefined) {
Inputmask().mask(lmnt);
}
});
}
}).ready(function () {
$(".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias],[data-inputmask-regex]").each(function (ndx, lmnt) {
if (lmnt.inputmask === undefined) {
Inputmask().mask(lmnt);
}
});
});
}));
factory(jQuery, window.Inputmask, window);
})(function ($, Inputmask, window) {
$(window.document)
.ajaxComplete(function (event, xmlHttpRequest, ajaxOptions) {
if ($.inArray("html", ajaxOptions.dataTypes) !== -1) {
$(
".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias], [data-inputmask-regex]"
).each(function (ndx, lmnt) {
if (lmnt.inputmask === undefined) {
Inputmask().mask(lmnt);
}
});
}
})
.ready(function () {
$(
".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias],[data-inputmask-regex]"
).each(function (ndx, lmnt) {
if (lmnt.inputmask === undefined) {
Inputmask().mask(lmnt);
}
});
});
});

View file

@ -1,5 +1,6 @@
// eslint-disable-next-line import/no-unresolved
import "./inputmask.js";
const inputmask = window.Inputmask;
window.Inputmask = undefined;
export default inputmask;
export default inputmask;

View file

@ -1,7 +0,0 @@
const canUseDOM = !!(
typeof window !== "undefined" &&
window.document &&
window.document.createElement
);
export default canUseDOM;

View file

@ -1,107 +1,64 @@
import {keys} from "./keycode.js";
export default {
_maxTestPos: 500,
placeholder: "_",
optionalmarker: ["[", "]"],
quantifiermarker: ["{", "}"],
groupmarker: ["(", ")"],
alternatormarker: "|",
escapeChar: "\\",
mask: null, //needs tobe null instead of undefined as the extend method does not consider props with the undefined value
regex: null, //regular expression as a mask
oncomplete: () => {
}, //executes when the mask is complete
onincomplete: () => {
}, //executes when the mask is incomplete and focus is lost
oncleared: () => {
}, //executes when the mask is cleared
repeat: 0, //repetitions of the mask: * ~ forever, otherwise specify an integer
greedy: false, //true: allocated buffer for the mask and repetitions - false: allocate only if needed
autoUnmask: false, //automatically unmask when retrieving the value with $.fn.val or value if the browser supports __lookupGetter__ or getOwnPropertyDescriptor
removeMaskOnSubmit: false, //remove the mask before submitting the form.
clearMaskOnLostFocus: true,
insertMode: true, //insert the input or overwrite the input
insertModeVisual: true, //show selected caret when insertmode = false
clearIncomplete: false, //clear the incomplete input on blur
alias: null,
onKeyDown: () => {
}, //callback to implement autocomplete on certain keys for example. args => event, buffer, caretPos, opts
onBeforeMask: null, //executes before masking the initial value to allow preprocessing of the initial value. args => initialValue, opts => return processedValue
onBeforePaste: function (pastedValue, opts) {
return typeof opts.onBeforeMask === "function" ? opts.onBeforeMask.call(this, pastedValue, opts) : pastedValue;
}, //executes before masking the pasted value to allow preprocessing of the pasted value. args => pastedValue, opts => return processedValue
onBeforeWrite: null, //executes before writing to the masked element. args => event, opts
onUnMask: null, //executes after unmasking to allow postprocessing of the unmaskedvalue. args => maskedValue, unmaskedValue, opts
showMaskOnFocus: true, //show the mask-placeholder when the input has focus
showMaskOnHover: true, //show the mask-placeholder when hovering the empty input
onKeyValidation: () => {
}, //executes on every key-press with the result of isValid. Params: key, result, opts
skipOptionalPartCharacter: " ", //a character which can be used to skip an optional part of a mask
numericInput: false, //numericInput input direction style (input shifts to the left while holding the caret position)
rightAlign: false, //align to the right
undoOnEscape: true, //pressing escape reverts the value to the value before focus
//numeric basic properties
radixPoint: "", //".", // | ","
_radixDance: false, //dance around the radixPoint
groupSeparator: "", //",", // | "."
//numeric basic properties
keepStatic: null, //try to keep the mask static while typing. Decisions to alter the mask will be posponed if possible
positionCaretOnTab: true, //when enabled the caret position is set after the latest valid position on TAB
tabThrough: false, //allows for tabbing through the different parts of the masked field
supportsInputType: ["text", "tel", "url", "password", "search"], //list with the supported input types
//specify keyCodes which should not be considered in the keypress event, otherwise the preventDefault will stop their default behavior especially in FF
ignorables: [
keys.Backspace,
keys.Tab,
keys.Pause,
keys.Escape,
keys.PageUp,
keys.PageDown,
keys.End,
keys.Home,
keys.ArrowLeft,
keys.ArrowUp,
keys.ArrowRight,
keys.ArrowDown,
keys.Insert,
keys.Delete,
keys.ContextMenu,
keys.F1,
keys.F2,
keys.F3,
keys.F4,
keys.F5,
keys.F6,
keys.F7,
keys.F8,
keys.F9,
keys.F10,
keys.F11,
keys.F12,
keys.Process,
keys.Unidentified,
keys.Shift,
keys.Control,
keys.Alt,
keys.Tab,
keys.AltGraph,
keys.CapsLock
],
isComplete: null, //override for isComplete - args => buffer, opts - return true || false
preValidation: null, //hook to preValidate the input. Usefull for validating regardless the definition. args => buffer, pos, char, isSelection, opts, maskset, caretPos, strict => return true/false/command object
postValidation: null, //hook to postValidate the result from isValid. Usefull for validating the entry as a whole. args => buffer, pos, c, currentResult, opts, maskset, strict, fromCheckval => return true/false/json
staticDefinitionSymbol: undefined, //specify a definitionSymbol for static content, used to make matches for alternators
jitMasking: false, //just in time masking ~ only mask while typing, can n (number), true or false
nullable: true, //return nothing instead of the buffertemplate when the user hasn't entered anything.
inputEventOnly: false, //dev option - testing inputfallback behavior
noValuePatching: false, //disable value property patching
positionCaretOnClick: "lvp", //none, lvp (based on the last valid position (default), radixFocus (position caret to radixpoint on initial click), select (select the whole input), ignore (ignore the click and continue the mask)
casing: null, //mask-level casing. Options: null, "upper", "lower" or "title" or callback args => elem, test, pos, validPositions return charValue
inputmode: "text", //specify the inputmode
importDataAttributes: true, //import data-inputmask attributes
shiftPositions: true, //shift position of the mask entries on entry and deletion.
usePrototypeDefinitions: true, //use the default defined definitions from the prototype
validationEventTimeOut: 3000, //Time to show validation error on form submit
substitutes: {} //define character substitutes
_maxTestPos: 500,
placeholder: "_",
optionalmarker: ["[", "]"],
quantifiermarker: ["{", "}"],
groupmarker: ["(", ")"],
alternatormarker: "|",
escapeChar: "\\",
mask: null, // needs tobe null instead of undefined as the extend method does not consider props with the undefined value
regex: null, // regular expression as a mask
oncomplete: () => {}, // executes when the mask is complete
onincomplete: () => {}, // executes when the mask is incomplete and focus is lost
oncleared: () => {}, // executes when the mask is cleared
repeat: 0, // repetitions of the mask: * ~ forever, otherwise specify an integer
greedy: false, // true: allocated buffer for the mask and repetitions - false: allocate only if needed
autoUnmask: false, // automatically unmask when retrieving the value with $.fn.val or value if the browser supports __lookupGetter__ or getOwnPropertyDescriptor
removeMaskOnSubmit: false, // remove the mask before submitting the form.
clearMaskOnLostFocus: true,
insertMode: true, // insert the input or overwrite the input
insertModeVisual: true, // show selected caret when insertmode = false
clearIncomplete: false, // clear the incomplete input on blur
alias: null,
onKeyDown: () => {}, // callback to implement autocomplete on certain keys for example. args => event, buffer, caretPos, opts
onBeforeMask: null, // executes before masking the initial value to allow preprocessing of the initial value. args => initialValue, opts => return processedValue
onBeforePaste: function (pastedValue, opts) {
return typeof opts.onBeforeMask === "function"
? opts.onBeforeMask.call(this, pastedValue, opts)
: pastedValue;
}, // executes before masking the pasted value to allow preprocessing of the pasted value. args => pastedValue, opts => return processedValue
onBeforeWrite: null, // executes before writing to the masked element. args => event, opts
onUnMask: null, // executes after unmasking to allow postprocessing of the unmaskedvalue. args => maskedValue, unmaskedValue, opts
showMaskOnFocus: true, // show the mask-placeholder when the input has focus
showMaskOnHover: true, // show the mask-placeholder when hovering the empty input
onKeyValidation: () => {}, // executes on every key-press with the result of isValid. Params: key, result, opts
skipOptionalPartCharacter: " ", // a character which can be used to skip an optional part of a mask
numericInput: false, // numericInput input direction style (input shifts to the left while holding the caret position)
rightAlign: false, // align to the right
undoOnEscape: true, // pressing escape reverts the value to the value before focus
// numeric basic properties
radixPoint: "", // ".", // | ","
_radixDance: false, // dance around the radixPoint
groupSeparator: "", // ",", // | "."
// numeric basic properties
keepStatic: null, // try to keep the mask static while typing. Decisions to alter the mask will be posponed if possible
positionCaretOnTab: true, // when enabled the caret position is set after the latest valid position on TAB
tabThrough: false, // allows for tabbing through the different parts of the masked field
supportsInputType: ["text", "tel", "url", "password", "search"], // list with the supported input types
isComplete: null, // override for isComplete - args => buffer, opts - return true || false
preValidation: null, // hook to preValidate the input. Usefull for validating regardless the definition. args => buffer, pos, char, isSelection, opts, maskset, caretPos, strict => return true/false/command object
postValidation: null, // hook to postValidate the result from isValid. Usefull for validating the entry as a whole. args => buffer, pos, c, currentResult, opts, maskset, strict, fromCheckval => return true/false/json
staticDefinitionSymbol: undefined, // specify a definitionSymbol for static content, used to make matches for alternators
jitMasking: false, // just in time masking ~ only mask while typing, can n (number), true or false
nullable: true, // return nothing instead of the buffertemplate when the user hasn't entered anything.
inputEventOnly: false, // dev option - testing inputfallback behavior
noValuePatching: false, // disable value property patching
positionCaretOnClick: "lvp", // none, lvp (based on the last valid position (default), radixFocus (position caret to radixpoint on initial click), select (select the whole input), ignore (ignore the click and continue the mask)
casing: null, // mask-level casing. Options: null, "upper", "lower" or "title" or callback args => elem, test, pos, validPositions return charValue
inputmode: "text", // specify the inputmode
importDataAttributes: true, // import data-inputmask attributes
shiftPositions: true, // shift position of the mask entries on entry and deletion.
usePrototypeDefinitions: true, // use the default defined definitions from the prototype
validationEventTimeOut: 3000, // Time to show validation error on form submit
substitutes: {} // define character substitutes
};

View file

@ -1,13 +1,16 @@
export default {
"9": { //\uFF11-\uFF19 #1606
validator: "[0-9\uFF10-\uFF19]",
definitionSymbol: "*"
},
"a": { //\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5 #76
validator: "[A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
definitionSymbol: "*"
},
"*": {
validator: "[0-9\uFF10-\uFF19A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]"
}
};
9: {
// \uFF11-\uFF19 #1606
validator: "[0-9\uFF10-\uFF19]",
definitionSymbol: "*"
},
a: {
// \u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5 #76
validator: "[A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
definitionSymbol: "*"
},
"*": {
validator:
"[0-9\uFF10-\uFF19A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]"
}
};

View file

@ -1,8 +1,8 @@
export default function (owner, key, value) {
if (value === undefined) {
return owner.__data ? owner.__data[key] : null;
} else {
owner.__data = owner.__data || {};
owner.__data[key] = value;
}
}
if (value === undefined) {
return owner.__data ? owner.__data[key] : null;
} else {
owner.__data = owner.__data || {};
owner.__data[key] = value;
}
}

View file

@ -1,186 +1,230 @@
import extend from "./extend";
import window from "../global/window";
import DependencyLib from "./inputmask.dependencyLib";
import canUseDOM from "../canUseDOM";
export {on, off, trigger, Event};
import extend from "./extend";
import DependencyLib from "./inputmask.dependencyLib";
export { on, off, trigger, Evnt as Event };
const document = window.document;
function isValidElement(elem) {
return elem instanceof Element;
return elem instanceof Element;
}
let Event;
let Evnt;
if (typeof window.CustomEvent === "function") {
Event = window.CustomEvent;
} else {
if (canUseDOM) {
Event = function (event, params) {
params = params || {bubbles: false, cancelable: false, composed: true, detail: undefined};
var evt = document.createEvent("CustomEvent");
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
};
Event.prototype = window.Event.prototype;
}
Evnt = window.CustomEvent;
} else if (window.Event && document && document.createEvent) {
Evnt = function (event, params) {
params = params || {
bubbles: false,
cancelable: false,
composed: true,
detail: undefined
};
const evt = document.createEvent("CustomEvent");
evt.initCustomEvent(
event,
params.bubbles,
params.cancelable,
params.detail
);
return evt;
};
Evnt.prototype = window.Event.prototype;
} else if (typeof Event !== "undefined") {
// nodejs
Evnt = Event;
}
function on(events, handler) {
function addEvent(ev, namespace) {
//register domevent
if (elem.addEventListener) { // all browsers except IE before version 9
elem.addEventListener(ev, handler, false);
} else if (elem.attachEvent) { // IE before version 9
elem.attachEvent(`on${ev}`, handler);
}
eventRegistry[ev] = eventRegistry[ev] || {};
eventRegistry[ev][namespace] = eventRegistry[ev][namespace] || [];
eventRegistry[ev][namespace].push(handler);
}
function addEvent(ev, namespace) {
// register domevent
if (elem.addEventListener) {
// all browsers except IE before version 9
elem.addEventListener(ev, handler, false);
} else if (elem.attachEvent) {
// IE before version 9
elem.attachEvent(`on${ev}`, handler);
}
eventRegistry[ev] = eventRegistry[ev] || {};
eventRegistry[ev][namespace] = eventRegistry[ev][namespace] || [];
eventRegistry[ev][namespace].push(handler);
}
if (isValidElement(this[0])) {
var eventRegistry = this[0].eventRegistry,
elem = this[0];
if (isValidElement(this[0])) {
var eventRegistry = this[0].eventRegistry,
elem = this[0];
events.split(" ").forEach((event) => {
const [ev, namespace = "global"] = event.split(".");
addEvent(ev, namespace);
});
}
return this;
events.split(" ").forEach((event) => {
const [ev, namespace = "global"] = event.split(".");
addEvent(ev, namespace);
});
}
return this;
}
function off(events, handler) {
var eventRegistry, elem;
let eventRegistry, elem;
function removeEvent(ev, namespace, handler) {
if (ev in eventRegistry === true) {
//unbind to dom events
if (elem.removeEventListener) { // all browsers except IE before version 9
elem.removeEventListener(ev, handler, false);
} else if (elem.detachEvent) { // IE before version 9
elem.detachEvent(`on${ev}`, handler);
}
if (namespace === "global") {
for (var nmsp in eventRegistry[ev]) {
eventRegistry[ev][nmsp].splice(eventRegistry[ev][nmsp].indexOf(handler), 1);
}
} else {
eventRegistry[ev][namespace].splice(eventRegistry[ev][namespace].indexOf(handler), 1);
}
}
}
function removeEvent(ev, namespace, handler) {
if (ev in eventRegistry === true) {
// unbind to dom events
if (elem.removeEventListener) {
// all browsers except IE before version 9
elem.removeEventListener(ev, handler, false);
} else if (elem.detachEvent) {
// IE before version 9
elem.detachEvent(`on${ev}`, handler);
}
if (namespace === "global") {
for (const nmsp in eventRegistry[ev]) {
eventRegistry[ev][nmsp].splice(
eventRegistry[ev][nmsp].indexOf(handler),
1
);
}
} else {
eventRegistry[ev][namespace].splice(
eventRegistry[ev][namespace].indexOf(handler),
1
);
}
}
}
function resolveNamespace(ev, namespace) {
var evts = [],
hndx, hndL;
if (ev.length > 0) {
if (handler === undefined) {
for (hndx = 0, hndL = eventRegistry[ev][namespace].length; hndx < hndL; hndx++) {
evts.push({
ev: ev,
namespace: namespace && namespace.length > 0 ? namespace : "global",
handler: eventRegistry[ev][namespace][hndx]
});
}
} else {
evts.push({
ev: ev,
namespace: namespace && namespace.length > 0 ? namespace : "global",
handler: handler
});
}
} else if (namespace.length > 0) {
for (var evNdx in eventRegistry) {
for (var nmsp in eventRegistry[evNdx]) {
if (nmsp === namespace) {
if (handler === undefined) {
for (hndx = 0, hndL = eventRegistry[evNdx][nmsp].length; hndx < hndL; hndx++) {
evts.push({
ev: evNdx,
namespace: nmsp,
handler: eventRegistry[evNdx][nmsp][hndx]
});
}
} else {
evts.push({
ev: evNdx,
namespace: nmsp,
handler: handler
});
}
}
}
}
}
function resolveNamespace(ev, namespace) {
let evts = [],
hndx,
hndL;
if (ev.length > 0) {
if (handler === undefined) {
for (
hndx = 0, hndL = eventRegistry[ev][namespace].length;
hndx < hndL;
hndx++
) {
evts.push({
ev,
namespace: namespace && namespace.length > 0 ? namespace : "global",
handler: eventRegistry[ev][namespace][hndx]
});
}
} else {
evts.push({
ev,
namespace: namespace && namespace.length > 0 ? namespace : "global",
handler
});
}
} else if (namespace.length > 0) {
for (const evNdx in eventRegistry) {
for (const nmsp in eventRegistry[evNdx]) {
if (nmsp === namespace) {
if (handler === undefined) {
for (
hndx = 0, hndL = eventRegistry[evNdx][nmsp].length;
hndx < hndL;
hndx++
) {
evts.push({
ev: evNdx,
namespace: nmsp,
handler: eventRegistry[evNdx][nmsp][hndx]
});
}
} else {
evts.push({
ev: evNdx,
namespace: nmsp,
handler
});
}
}
}
}
}
return evts;
}
return evts;
}
if (isValidElement(this[0]) && events) {
eventRegistry = this[0].eventRegistry;
elem = this[0];
if (isValidElement(this[0]) && events) {
eventRegistry = this[0].eventRegistry;
elem = this[0];
events.split(" ").forEach((event) => {
const [ev, namespace] = event.split(".");
resolveNamespace(ev, namespace).forEach(({ev: ev1, handler: handler1, namespace: namespace1}) => {
removeEvent(ev1, namespace1, handler1);
});
});
}
return this;
events.split(" ").forEach((event) => {
const [ev, namespace] = event.split(".");
resolveNamespace(ev, namespace).forEach(
({ ev: ev1, handler: handler1, namespace: namespace1 }) => {
removeEvent(ev1, namespace1, handler1);
}
);
});
}
return this;
}
function trigger(events /* , args... */) {
if (isValidElement(this[0])) {
var eventRegistry = this[0].eventRegistry,
elem = this[0];
var _events = typeof events === "string" ? events.split(" ") : [events.type];
for (var endx = 0; endx < _events.length; endx++) {
var nsEvent = _events[endx].split("."),
ev = nsEvent[0],
namespace = nsEvent[1] || "global";
if (document !== undefined && namespace === "global") {
//trigger domevent
var evnt, i, params = {
bubbles: true,
cancelable: true,
composed: true,
detail: arguments[1]
};
// The custom event that will be created
if (document.createEvent) {
try {
switch (ev) {
case "input":
params.inputType = "insertText";
evnt = new InputEvent(ev, params);
break;
default:
evnt = new CustomEvent(ev, params);
}
} catch (e) {
evnt = document.createEvent("CustomEvent");
evnt.initCustomEvent(ev, params.bubbles, params.cancelable, params.detail);
}
if (events.type) extend(evnt, events);
elem.dispatchEvent(evnt);
} else {
evnt = document.createEventObject();
evnt.eventType = ev;
evnt.detail = arguments[1];
if (events.type) extend(evnt, events);
elem.fireEvent("on" + evnt.eventType, evnt);
}
} else if (eventRegistry[ev] !== undefined) {
arguments[0] = arguments[0].type ? arguments[0] : DependencyLib.Event(arguments[0]);
arguments[0].detail = arguments.slice(1);
if (isValidElement(this[0])) {
const eventRegistry = this[0].eventRegistry,
elem = this[0],
_events = typeof events === "string" ? events.split(" ") : [events.type];
for (let endx = 0; endx < _events.length; endx++) {
const nsEvent = _events[endx].split("."),
ev = nsEvent[0],
namespace = nsEvent[1] || "global";
if (document !== undefined && namespace === "global") {
// trigger domevent
var evnt,
params = {
bubbles: true,
cancelable: true,
composed: true,
detail: arguments[1]
};
// The custom event that will be created
if (document.createEvent) {
try {
switch (ev) {
case "input":
params.inputType = "insertText";
evnt = new InputEvent(ev, params);
break;
default:
evnt = new CustomEvent(ev, params);
}
} catch (e) {
evnt = document.createEvent("CustomEvent");
evnt.initCustomEvent(
ev,
params.bubbles,
params.cancelable,
params.detail
);
}
if (events.type) extend(evnt, events);
elem.dispatchEvent(evnt);
} else {
evnt = document.createEventObject();
evnt.eventType = ev;
evnt.detail = arguments[1];
if (events.type) extend(evnt, events);
elem.fireEvent("on" + evnt.eventType, evnt);
}
} else if (eventRegistry[ev] !== undefined) {
arguments[0] = arguments[0].type
? arguments[0]
: DependencyLib.Event(arguments[0]);
arguments[0].detail = arguments.slice(1);
const registry = eventRegistry[ev],
handlers = namespace === "global" ? Object.values(registry).flat() : registry[namespace];
handlers.forEach(handler => handler.apply(elem, arguments));
}
}
}
return this;
const registry = eventRegistry[ev],
handlers =
namespace === "global"
? Object.values(registry).flat()
: registry[namespace];
handlers.forEach((handler) => handler.apply(elem, arguments));
}
}
}
return this;
}

View file

@ -1,58 +1,70 @@
export default function extend() {
let options, name, src, copy, copyIsArray, clone,
target = arguments[0] || {},
i = 1,
length = arguments.length,
deep = false;
let options,
name,
src,
copy,
copyIsArray,
clone,
target = arguments[0] || {},
i = 1,
length = arguments.length,
deep = false;
// Handle a deep copy situation
if (typeof target === "boolean") {
deep = target;
// Handle a deep copy situation
if (typeof target === "boolean") {
deep = target;
// Skip the boolean and the target
target = arguments[i] || {};
i++;
}
// Skip the boolean and the target
target = arguments[i] || {};
i++;
}
// Handle case when target is a string or something (possible in deep copy)
if (typeof target !== "object" && typeof target !== "function") {
target = {};
}
// Handle case when target is a string or something (possible in deep copy)
if (typeof target !== "object" && typeof target !== "function") {
target = {};
}
for (; i < length; i++) {
// Only deal with non-null/undefined values
if ((options = arguments[i]) != null) {
// Extend the base object
for (name in options) {
src = target[name];
copy = options[name];
for (; i < length; i++) {
// Only deal with non-null/undefined values
if ((options = arguments[i]) != null) {
// Extend the base object
for (name in options) {
src = target[name];
copy = options[name];
// Prevent never-ending loop
if (target === copy) {
continue;
}
// Prevent never-ending loop
if (target === copy) {
continue;
}
// Recurse if we're merging plain objects or arrays
if (deep && copy && (Object.prototype.toString.call(copy) === "[object Object]" || (copyIsArray = Array.isArray(copy)))) {
if (copyIsArray) {
copyIsArray = false;
clone = src && Array.isArray(src) ? src : [];
// Recurse if we're merging plain objects or arrays
if (
deep &&
copy &&
(Object.prototype.toString.call(copy) === "[object Object]" ||
(copyIsArray = Array.isArray(copy)))
) {
if (copyIsArray) {
copyIsArray = false;
clone = src && Array.isArray(src) ? src : [];
} else {
clone =
src && Object.prototype.toString.call(src) === "[object Object]"
? src
: {};
}
} else {
clone = src && Object.prototype.toString.call(src) === "[object Object]" ? src : {};
}
// Never move original objects, clone them
target[name] = extend(deep, clone, copy);
// Never move original objects, clone them
target[name] = extend(deep, clone, copy);
// Don't bring in undefined values
} else if (copy !== undefined) {
target[name] = copy;
}
}
}
}
// Don't bring in undefined values
} else if (copy !== undefined) {
target[name] = copy;
}
}
}
}
// Return the modified object
return target;
}
// Return the modified object
return target;
}

View file

@ -8,6 +8,6 @@
import jQuery from "jquery";
if (jQuery === undefined) {
throw "jQuery not loaded!";
throw new Error("jQuery not loaded!");
}
export default jQuery;
export default jQuery;

View file

@ -5,35 +5,40 @@
Licensed under the MIT license
*/
import extend from "./extend";
import window from "../global/window";
import data from "./data";
import { on, off, trigger, Event} from "./events";
import { on, off, trigger, Event } from "./events";
import extend from "./extend";
const document = window.document;
function DependencyLib(elem) {
if (elem instanceof DependencyLib) {
return elem;
}
if (!(this instanceof DependencyLib)) {
return new DependencyLib(elem);
}
if (elem !== undefined && elem !== null && elem !== window) {
this[0] = elem.nodeName ? elem : (elem[0] !== undefined && elem[0].nodeName ? elem[0] : document.querySelector(elem));
if (this[0] !== undefined && this[0] !== null) {
this[0].eventRegistry = this[0].eventRegistry || {};
}
}
if (elem instanceof DependencyLib) {
return elem;
}
if (!(this instanceof DependencyLib)) {
return new DependencyLib(elem);
}
if (elem !== undefined && elem !== null && elem !== window) {
this[0] = elem.nodeName
? elem
: elem[0] !== undefined && elem[0].nodeName
? elem[0]
: document.querySelector(elem);
if (this[0] !== undefined && this[0] !== null) {
this[0].eventRegistry = this[0].eventRegistry || {};
}
}
}
DependencyLib.prototype = {
on: on,
off: off,
trigger: trigger
on,
off,
trigger
};
//static
// static
DependencyLib.extend = extend;
DependencyLib.data = data;
DependencyLib.Event = Event;

View file

@ -1,8 +1,13 @@
import window from "./global/window";
const ua = (window.navigator && window.navigator.userAgent) || "",
ie = (ua.indexOf("MSIE ") > 0) || (ua.indexOf("Trident/") > 0),
mobile = (navigator.userAgentData && navigator.userAgentData.mobile) || (window.navigator && window.navigator.maxTouchPoints) || "ontouchstart" in window, //not entirely correct but will currently do
iphone = /iphone/i.test(ua);
ie = ua.indexOf("MSIE ") > 0 || ua.indexOf("Trident/") > 0,
mobile =
(window.navigator &&
window.navigator.userAgentData &&
window.navigator.userAgentData.mobile) ||
(window.navigator && window.navigator.maxTouchPoints) ||
"ontouchstart" in window, // not entirely correct but will currently do
iphone = /iphone/i.test(ua);
export {ie, mobile, iphone};
export { ie, mobile, iphone };

View file

@ -1,4 +1,25 @@
const escapeRegexRegex = new RegExp("(\\" + ["/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^"].join("|\\") + ")", "gim");
const escapeRegexRegex = new RegExp(
"(\\" +
[
"/",
".",
"*",
"+",
"?",
"|",
"(",
")",
"[",
"]",
"{",
"}",
"\\",
"$",
"^"
].join("|\\") +
")",
"gim"
);
export default function (str) {
return str.replace(escapeRegexRegex, "\\$1");
}
return str.replace(escapeRegexRegex, "\\$1");
}

File diff suppressed because it is too large Load diff

View file

@ -1,107 +1,127 @@
import { HandleNativePlaceholder } from "./inputHandling";
import Inputmask from "./inputmask";
import {keys} from "./keycode.js";
import {getBufferTemplate} from "./positioning";
import {HandleNativePlaceholder} from "./inputHandling";
import { keys } from "./keycode.js";
import { getBufferTemplate } from "./positioning";
export {EventRuler};
export { EventRuler };
var EventRuler = {
on: function (input, eventName, eventHandler) {
const $ = input.inputmask.dependencyLib;
on: function (input, eventName, eventHandler) {
const $ = input.inputmask.dependencyLib;
var ev = function (e) {
if (e.originalEvent) {
e = e.originalEvent || e; //get original event from jquery evenbt
arguments[0] = e;
}
// console.log(e.type);
var that = this, args, inputmask = that.inputmask, opts = inputmask ? inputmask.opts : undefined;
if (inputmask === undefined && this.nodeName !== "FORM") { //happens when cloning an object with jquery.clone
var imOpts = $.data(that, "_inputmask_opts");
$(that).off(); //unbind all events
if (imOpts) {
(new Inputmask(imOpts)).mask(that);
}
} else if (!["submit", "reset", "setvalue"].includes(e.type) && this.nodeName !== "FORM" && (that.disabled || (that.readOnly && !(e.type === "keydown" && (e.ctrlKey && e.key === keys.c) || (opts.tabThrough === false && e.key === keys.Tab))))) {
e.preventDefault();
} else {
switch (e.type) {
case "input":
if (inputmask.skipInputEvent === true) {
inputmask.skipInputEvent = false;
return e.preventDefault();
}
// if (mobile) { //this causes problem see #2220
// args = arguments;
// setTimeout(function () { //needed for caret selection when entering a char on Android 8 - #1818
// eventHandler.apply(that, args);
// caret(that, that.inputmask.caretPos, undefined, true);
// }, 0);
// return false;
// }
break;
case "click":
case "focus":
if (inputmask.validationEvent) { // #841
inputmask.validationEvent = false;
input.blur();
HandleNativePlaceholder(input, (inputmask.isRTL ? getBufferTemplate.call(inputmask).slice().reverse() : getBufferTemplate.call(inputmask)).join(""));
setTimeout(function () {
input.focus();
}, opts.validationEventTimeOut);
return false;
}
args = arguments;
setTimeout(function () { //needed for Chrome ~ initial selection clears after the clickevent
if (!input.inputmask) {
// `inputmask.remove()` was called before this callback
return;
}
eventHandler.apply(that, args);
}, 0);
return /*false*/; //#2423
}
var returnVal = eventHandler.apply(that, arguments);
if (returnVal === false) {
e.preventDefault();
e.stopPropagation();
}
return returnVal;
}
};
if (["submit", "reset"].includes(eventName)) {
ev = ev.bind(input); //bind creates a new eventhandler (wrap)
if (input.form !== null) $(input.form).on(eventName, ev);
} else {
$(input).on(eventName, ev);
let ev = function (e) {
if (e.originalEvent) {
e = e.originalEvent || e; // get original event from jquery evenbt
arguments[0] = e;
}
// console.log(e.type);
let that = this,
args,
inputmask = that.inputmask,
opts = inputmask ? inputmask.opts : undefined;
if (inputmask === undefined && this.nodeName !== "FORM") {
// happens when cloning an object with jquery.clone
const imOpts = $.data(that, "_inputmask_opts");
$(that).off(); // unbind all events
if (imOpts) {
new Inputmask(imOpts).mask(that);
}
//keep instance of the event
input.inputmask.events[eventName] = input.inputmask.events[eventName] || [];
input.inputmask.events[eventName].push(ev);
},
off: function (input, event) {
if (input.inputmask && input.inputmask.events) {
const $ = input.inputmask.dependencyLib;
let events = input.inputmask.events;
if (event) {
events = [];
events[event] = input.inputmask.events[event];
} else if (
!["submit", "reset", "setvalue"].includes(e.type) &&
this.nodeName !== "FORM" &&
(that.disabled ||
(that.readOnly &&
!(
(e.type === "keydown" && e.ctrlKey && e.key === keys.c) ||
(opts.tabThrough === false && e.key === keys.Tab)
)))
) {
e.preventDefault();
} else {
switch (e.type) {
case "input":
if (inputmask.skipInputEvent === true) {
inputmask.skipInputEvent = false;
return e.preventDefault();
}
for (let eventName in events) {
let evArr = events[eventName];
while (evArr.length > 0) {
let ev = evArr.pop();
if (["submit", "reset",].includes(eventName)) {
if (input.form !== null) $(input.form).off(eventName, ev);
} else {
$(input).off(eventName, ev);
}
}
delete input.inputmask.events[eventName];
// if (mobile) { //this causes problem see #2220
// args = arguments;
// setTimeout(function () { //needed for caret selection when entering a char on Android 8 - #1818
// eventHandler.apply(that, args);
// caret(that, that.inputmask.caretPos, undefined, true);
// }, 0);
// return false;
// }
break;
case "click":
case "focus":
if (inputmask.validationEvent) {
// #841
inputmask.validationEvent = false;
input.blur();
HandleNativePlaceholder(
input,
(inputmask.isRTL
? getBufferTemplate.call(inputmask).slice().reverse()
: getBufferTemplate.call(inputmask)
).join("")
);
setTimeout(function () {
input.focus();
}, opts.validationEventTimeOut);
return false;
}
args = arguments;
setTimeout(function () {
// needed for Chrome ~ initial selection clears after the clickevent
if (!input.inputmask) {
// `inputmask.remove()` was called before this callback
return;
}
eventHandler.apply(that, args);
}, 0);
return /* false */; // #2423
}
const returnVal = eventHandler.apply(that, arguments);
if (returnVal === false) {
e.preventDefault();
e.stopPropagation();
}
return returnVal;
}
};
if (["submit", "reset"].includes(eventName)) {
ev = ev.bind(input); // bind creates a new eventhandler (wrap)
if (input.form !== null) $(input.form).on(eventName, ev);
} else {
$(input).on(eventName, ev);
}
// keep instance of the event
input.inputmask.events[eventName] = input.inputmask.events[eventName] || [];
input.inputmask.events[eventName].push(ev);
},
off: function (input, event) {
if (input.inputmask && input.inputmask.events) {
const $ = input.inputmask.dependencyLib;
let events = input.inputmask.events;
if (event) {
events = [];
events[event] = input.inputmask.events[event];
}
for (const eventName in events) {
const evArr = events[eventName];
while (evArr.length > 0) {
const ev = evArr.pop();
if (["submit", "reset"].includes(eventName)) {
if (input.form !== null) $(input.form).off(eventName, ev);
} else {
$(input).off(eventName, ev);
}
}
delete input.inputmask.events[eventName];
}
}
}
};

65
node_modules/inputmask/lib/extensions/colormask.css generated vendored Normal file
View file

@ -0,0 +1,65 @@
mark.im-caret {
animation: 1s blink step-end infinite !important;
}
mark.im-caret-select {
background-color: rgba(0, 0, 0, 0.25);
}
@keyframes blink {
from, to {
border-right-color: black;
}
50% {
/*border-right-color: transparent;*/
border-right-color: white;
}
}
span.im-static {
color: grey;
}
div.im-colormask {
display: inline-block;
border-style: groove;
border-width: 1px;
appearance: textfield;
cursor: text;
}
div.im-colormask > input, div.im-colormask > input:-webkit-autofill {
position: absolute !important;
display: inline-block;
background-color: transparent;
color: transparent;
-webkit-text-fill-color: transparent;
transition: background-color 5000s ease-in-out 0s;
caret-color: transparent;
text-shadow: none;
appearance: textfield;
border-style: none;
left: 0; /*calculated*/
}
div.im-colormask > input:focus {
outline: none;
}
div.im-colormask > input::selection {
background: none;
}
div.im-colormask > input::-moz-selection {
background: none;
}
div.im-colormask > input:-webkit-autofill ~ div {
background-color: rgb(255, 255, 255);
}
div.im-colormask > div {
color: black;
display: inline-block;
width: 100px; /*calculated*/
}

267
node_modules/inputmask/lib/extensions/colormask.js generated vendored Normal file
View file

@ -0,0 +1,267 @@
/*
Input Mask colormask extension
http://github.com/RobinHerbots/inputmask
Copyright (c) Robin Herbots
Licensed under the MIT license
*/
import { EventHandlers } from "../eventhandlers";
import Inputmask from "../inputmask";
import { keys } from "../keycode.js";
import {
caret,
getBuffer,
getLastValidPosition,
translatePosition
} from "../positioning";
import { getPlaceholder, getTestTemplate } from "../validation-tests";
const $ = Inputmask.dependencyLib;
function Colormask(alias, options, internal) {
// allow instanciating without new
if (!(this instanceof Inputmask)) {
return new Inputmask(alias, options, internal);
}
this.colorMask = undefined;
Object.getOwnPropertyNames(Inputmask).forEach(function (key) {
if (!Object.prototype.hasOwnProperty.call(this, key)) {
this[key] = Inputmask[key];
}
}, this);
}
Colormask.prototype = Inputmask.prototype;
Colormask.prototype.writeBufferHook = function (caretPos) {
renderColorMask.call(this, this.el, caretPos, false);
};
Colormask.prototype.caretHook = function (caretPos) {
renderColorMask.call(this, this.el, caretPos, false);
};
Colormask.prototype.applyMaskHook = function () {
initializeColorMask.call(this, this.el);
};
Colormask.prototype.keyEventHook = function (e) {
if (e.key === keys.ArrowRight || e.key === keys.ArrowLeft) {
const inputmask = this;
setTimeout(function () {
const caretPos = caret.call(
inputmask,
inputmask.el,
undefined,
undefined,
true
);
renderColorMask.call(inputmask, inputmask.el, caretPos);
}, 0);
}
};
function initializeColorMask(input) {
const computedStyle = (
input.ownerDocument.defaultView || window
).getComputedStyle(input, null);
function findCaretPos(clientx) {
// calculate text width
let e = document.createElement("span"),
caretPos = 0;
for (const style in computedStyle) {
// clone styles
if (isNaN(style) && style.indexOf("font") !== -1) {
e.style[style] = computedStyle[style];
}
}
e.style.textTransform = computedStyle.textTransform;
e.style.letterSpacing = computedStyle.letterSpacing;
e.style.position = "absolute";
e.style.height = "auto";
e.style.width = "auto";
e.style.visibility = "hidden";
e.style.whiteSpace = "nowrap";
document.body.appendChild(e);
let inputText = input.inputmask.__valueGet.call(input),
previousWidth = 0;
while (e.offsetWidth < clientx) {
const ichar = inputText.charAt(caretPos);
e.innerHTML += ichar === " " || ichar === "" ? "_" : ichar;
if (e.offsetWidth >= clientx) {
let offset1 = clientx - previousWidth,
offset2 = e.offsetWidth - clientx;
e.innerHTML = inputText.charAt(caretPos);
offset1 += Math.round(e.offsetWidth / 2);
caretPos = (offset1 < offset2 ? caretPos - 1 : caretPos) - 1;
break;
}
previousWidth = e.offsetWidth;
caretPos++;
}
if (input.style.textAlign === "right") {
e.innerHTML = "_";
const maxChars = Math.ceil(input.offsetWidth / e.offsetWidth) - 1;
caretPos = inputText.length - (maxChars - caretPos) + 1;
}
document.body.removeChild(e);
return caretPos;
}
const template = document.createElement("div");
template.style.width = computedStyle.width;
template.style.textAlign = computedStyle.textAlign;
const colorMask = document.createElement("div");
input.inputmask.colorMask = colorMask;
colorMask.className = "im-colormask";
input.parentNode.insertBefore(colorMask, input);
input.parentNode.removeChild(input);
colorMask.appendChild(input);
colorMask.appendChild(template);
input.style.left = template.offsetLeft + "px";
$(colorMask).on("mouseleave", function (e) {
return EventHandlers.mouseleaveEvent.call(input, [e]);
});
$(colorMask).on("mouseenter", function (e) {
return EventHandlers.mouseenterEvent.call(input, [e]);
});
$(colorMask).on("click", function (e) {
caret.call(
input.inputmask,
input,
findCaretPos(e.clientX),
undefined,
true
);
return EventHandlers.clickEvent.call(input, [e]);
});
}
function positionColorMask(input, template) {
input.style.left = template.offsetLeft + "px";
}
export function renderColorMask(input, caretPos, clear) {
let inputmask = this,
{ isRTL, maskset, opts, maxLength } = inputmask,
maskTemplate = [],
isStatic = false,
test,
testPos,
ndxIntlzr,
pos = 0,
templates = {
static: {
start: isRTL ? "</span>" : "<span class='im-static'>",
end: isRTL ? "<span class='im-static'>" : "</span>"
},
caret: {
start:
'<mark class="im-caret" style="border-right-width: 1px;border-right-style: solid;">',
start_select: '<mark class="im-caret-select">',
end: "</mark>"
}
};
function setEntry(entry) {
if (entry === undefined) entry = "";
if (!isStatic && (test.static === true || testPos.input === undefined)) {
isStatic = true;
maskTemplate.push(templates.static.start + entry);
} else if (
isStatic &&
((test.static !== true && testPos.input !== undefined) || test.def === "")
) {
isStatic = false;
maskTemplate.push(templates.static.end + entry);
} else {
maskTemplate.push(entry);
}
}
function setCaret(begin, end, length) {
if (document.activeElement === input) {
maskTemplate.splice(
begin,
0,
begin === end || length > maskset.maskLength
? templates.caret.start
: templates.caret.start_select
);
maskTemplate.splice(end + (isRTL ? 0 : 1), 0, templates.caret.end);
}
}
if (input.inputmask.colorMask !== undefined) {
const buffer = getBuffer.call(inputmask);
if (caretPos === undefined) {
caretPos = caret.call(inputmask, input);
} else if (caretPos.begin === undefined) {
caretPos = {
begin: caretPos,
end: caretPos
};
}
if (isRTL) {
// translate caretPos
caretPos.begin = translatePosition.call(inputmask, caretPos.begin);
caretPos.end = translatePosition.call(inputmask, caretPos.end);
}
if (clear !== true) {
const lvp = getLastValidPosition.call(inputmask);
do {
if (maskset.validPositions[pos]) {
testPos = maskset.validPositions[pos];
test = testPos.match;
ndxIntlzr = testPos.locator.slice();
setEntry(buffer[pos]);
} else {
testPos = getTestTemplate.call(inputmask, pos, ndxIntlzr, pos - 1);
test = testPos.match;
ndxIntlzr = testPos.locator.slice();
const jitMasking =
opts.jitMasking !== false ? opts.jitMasking : test.jit;
if (
jitMasking === false ||
jitMasking === undefined /* || pos < lvp */ ||
(typeof jitMasking === "number" &&
isFinite(jitMasking) &&
jitMasking > pos)
) {
setEntry(getPlaceholder.call(inputmask, pos, test));
// } else {
// isStatic = false;
} // break infinite loop
}
pos++;
} while (
((maxLength === undefined || pos < maxLength) &&
(test.static !== true || test.def !== "")) ||
lvp > pos ||
isStatic
);
if (isStatic) setEntry();
setCaret(
isRTL ? caretPos.end : caretPos.begin,
isRTL ? caretPos.begin : caretPos.end,
caretPos.end
);
}
const template = input.inputmask.colorMask.getElementsByTagName("div")[0];
template.innerHTML = (isRTL ? maskTemplate.reverse() : maskTemplate).join(
""
);
positionColorMask(input, template);
// console.log(template.innerHTML)
// console.log(JSON.stringify(caretPos));
}
}
// make inputmask available
window.Colormask = Colormask;
export default Colormask;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,55 @@
/*
Input Mask plugin extensions
http://github.com/RobinHerbots/inputmask
Copyright (c) Robin Herbots
Licensed under the MIT license
*/
import Inputmask from "../inputmask";
const $ = Inputmask.dependencyLib;
$.extend(true, Inputmask.prototype.i18n, {
dayNames: [
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
],
monthNames: [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
],
ordinalSuffix: ["st", "nd", "rd", "th"]
});

View file

@ -1,132 +1,165 @@
/*
Input Mask plugin extensions
http://github.com/RobinHerbots/jquery.inputmask
http://github.com/RobinHerbots/inputmask
Copyright (c) Robin Herbots
Licensed under the MIT license
*/
import Inputmask from "../inputmask";
import {getLastValidPosition} from "../positioning";
import {getMaskTemplate} from "../validation-tests";
//extra definitions
import { getLastValidPosition } from "../positioning";
import { getMaskTemplate } from "../validation-tests";
// extra definitions
Inputmask.extendDefinitions({
"A": {
validator: "[A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
casing: "upper" //auto uppercasing
},
"&": { //alfanumeric uppercasing
validator: "[0-9A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
casing: "upper"
},
"#": { //hexadecimal
validator: "[0-9A-Fa-f]",
casing: "upper"
}
A: {
validator: "[A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
casing: "upper" // auto uppercasing
},
"&": {
// alfanumeric uppercasing
validator: "[0-9A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
casing: "upper"
},
"#": {
// hexadecimal
validator: "[0-9A-Fa-f]",
casing: "upper"
}
});
var ipValidatorRegex = new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]");
const ipValidatorRegex = /25[0-5]|2[0-4][0-9]|[01][0-9][0-9]/;
function ipValidator(chrs, maskset, pos, strict, opts) {
if (pos - 1 > -1 && maskset.buffer[pos - 1] !== ".") {
chrs = maskset.buffer[pos - 1] + chrs;
if (pos - 2 > -1 && maskset.buffer[pos - 2] !== ".") {
chrs = maskset.buffer[pos - 2] + chrs;
} else chrs = "0" + chrs;
} else chrs = "00" + chrs;
return ipValidatorRegex.test(chrs);
if (pos - 1 > -1 && maskset.buffer[pos - 1] !== ".") {
chrs = maskset.buffer[pos - 1] + chrs;
if (pos - 2 > -1 && maskset.buffer[pos - 2] !== ".") {
chrs = maskset.buffer[pos - 2] + chrs;
} else chrs = "0" + chrs;
} else chrs = "00" + chrs;
if (
opts.greedy &&
parseInt(chrs) > 255 &&
ipValidatorRegex.test("00" + chrs.charAt(2))
) {
const buffer = [...maskset.buffer.slice(0, pos), ".", chrs.charAt(2)];
if (buffer.join("").match(/\./g).length < 4) {
return {
refreshFromBuffer: true,
buffer,
caret: pos + 2
};
}
}
return ipValidatorRegex.test(chrs);
}
Inputmask.extendAliases({
"cssunit": {
regex: "[+-]?[0-9]+\\.?([0-9]+)?(px|em|rem|ex|%|in|cm|mm|pt|pc)"
cssunit: {
regex: "[+-]?[0-9]+\\.?([0-9]+)?(px|em|rem|ex|%|in|cm|mm|pt|pc)"
},
url: {
// needs update => https://en.wikipedia.org/wiki/URL
regex: "(https?|ftp)://.*",
autoUnmask: false,
keepStatic: false,
tabThrough: true
},
ip: {
// ip-address mask
mask: "i{1,3}.j{1,3}.k{1,3}.l{1,3}",
definitions: {
i: {
validator: ipValidator
},
j: {
validator: ipValidator
},
k: {
validator: ipValidator
},
l: {
validator: ipValidator
}
},
"url": { //needs update => https://en.wikipedia.org/wiki/URL
regex: "(https?|ftp)://.*",
autoUnmask: false,
keepStatic: false,
tabThrough: true
onUnMask: function (maskedValue, unmaskedValue, opts) {
return maskedValue;
},
"ip": { //ip-address mask
mask: "i{1,3}.j{1,3}.k{1,3}.l{1,3}",
definitions: {
"i": {
validator: ipValidator
},
"j": {
validator: ipValidator
},
"k": {
validator: ipValidator
},
"l": {
validator: ipValidator
}
},
onUnMask: function (maskedValue, unmaskedValue, opts) {
return maskedValue;
},
inputmode: "decimal",
substitutes: {",": "."}
},
"email": {
//https://en.wikipedia.org/wiki/Domain_name#Domain_name_space
//https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
//should be extended with the toplevel domains at the end
mask: function ({separator, quantifier}) {
var emailMask = "*{1,64}[.*{1,64}][.*{1,64}][.*{1,63}]@-{1,63}.-{1,63}[.-{1,63}][.-{1,63}]";
var mask = emailMask;
if (separator) {
for (let i = 0; i < quantifier; i++) {
mask += `[${separator}${emailMask}]`;
}
}
return mask;
},
greedy: false,
casing: "lower",
separator: null,
quantifier: 5,
skipOptionalPartCharacter: "",
onBeforePaste: function (pastedValue, opts) {
pastedValue = pastedValue.toLowerCase();
return pastedValue.replace("mailto:", "");
},
definitions: {
"*": {
validator: "[0-9\uFF11-\uFF19A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5!#$%&'*+/=?^_`{|}~-]"
},
"-": {
validator: "[0-9A-Za-z-]"
}
},
onUnMask: function (maskedValue, unmaskedValue, opts) {
return maskedValue;
},
inputmode: "email"
},
"mac": {
mask: "##:##:##:##:##:##"
},
//https://en.wikipedia.org/wiki/Vehicle_identification_number
// see issue #1199
"vin": {
mask: "V{13}9{4}",
definitions: {
"V": {
validator: "[A-HJ-NPR-Za-hj-npr-z\\d]",
casing: "upper"
}
},
clearIncomplete: true,
autoUnmask: true
},
//http://rion.io/2013/09/10/validating-social-security-numbers-through-regular-expressions-2/
//https://en.wikipedia.org/wiki/Social_Security_number
"ssn": {
mask: "999-99-9999",
postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict) {
var bffr = getMaskTemplate.call(this, true, getLastValidPosition.call(this), true, true);
return /^(?!219-09-9999|078-05-1120)(?!666|000|9.{2}).{3}-(?!00).{2}-(?!0{4}).{4}$/.test(bffr.join(""));
inputmode: "decimal",
substitutes: { ",": "." }
},
email: {
// https://en.wikipedia.org/wiki/Domain_name#Domain_name_space
// https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
// should be extended with the toplevel domains at the end
mask: function ({ separator, quantifier }) {
let emailMask =
"*{1,64}[.*{1,64}][.*{1,64}][.*{1,63}]@-{1,63}.-{1,63}[.-{1,63}][.-{1,63}]",
mask = emailMask;
if (separator) {
for (let i = 0; i < quantifier; i++) {
mask += `[${separator}${emailMask}]`;
}
}
return mask;
},
greedy: false,
casing: "lower",
separator: null,
quantifier: 5,
skipOptionalPartCharacter: "",
onBeforePaste: function (pastedValue, opts) {
pastedValue = pastedValue.toLowerCase();
return pastedValue.replace("mailto:", "");
},
definitions: {
"*": {
validator:
"[0-9\uFF11-\uFF19A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5!#$%&'*+/=?^_`{|}~-]"
},
"-": {
validator: "[0-9A-Za-z-]"
}
},
onUnMask: function (maskedValue, unmaskedValue, opts) {
return maskedValue;
},
inputmode: "email"
},
mac: {
mask: "##:##:##:##:##:##"
}, // https://en.wikipedia.org/wiki/Vehicle_identification_number
// see issue #1199
vin: {
mask: "V{13}9{4}",
definitions: {
V: {
validator: "[A-HJ-NPR-Za-hj-npr-z\\d]",
casing: "upper"
}
},
clearIncomplete: true,
autoUnmask: true
}, // http://rion.io/2013/09/10/validating-social-security-numbers-through-regular-expressions-2/
// https://en.wikipedia.org/wiki/Social_Security_number
ssn: {
mask: "999-99-9999",
postValidation: function (
buffer,
pos,
c,
currentResult,
opts,
maskset,
strict
) {
const bffr = getMaskTemplate.call(
this,
true,
getLastValidPosition.call(this),
true,
true
);
return /^(?!219-09-9999|078-05-1120)(?!666|000|9.{2}).{3}-(?!00).{2}-(?!0{4}).{4}$/.test(
bffr.join("")
);
}
}
});

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,7 @@
import canUseDOM from "../canUseDOM";
const canUseDOM = !!(
typeof window !== "undefined" &&
window.document &&
window.document.createElement
);
export default canUseDOM ? window : {};

View file

@ -1,252 +1,417 @@
import {keys} from "./keycode.js";
import {getMaskTemplate, getPlaceholder, getTest} from "./validation-tests";
import { ie } from "./environment";
import { EventHandlers } from "./eventhandlers";
import { keys } from "./keycode.js";
import {
caret,
determineNewCaretPosition,
getBuffer, getBufferTemplate,
getLastValidPosition,
isMask,
resetMaskSet,
seekNext
caret,
determineNewCaretPosition,
getBuffer,
getBufferTemplate,
getLastValidPosition,
isMask,
resetMaskSet,
seekNext
} from "./positioning";
import {isComplete, refreshFromBuffer} from "./validation";
import {ie} from "./environment";
import {EventHandlers} from "./eventhandlers";
import { isComplete, refreshFromBuffer } from "./validation";
import { getMaskTemplate, getPlaceholder, getTest } from "./validation-tests";
export {
applyInputValue,
clearOptionalTail,
checkVal,
HandleNativePlaceholder,
unmaskedvalue,
writeBuffer
};
export {applyInputValue, clearOptionalTail, checkVal, HandleNativePlaceholder, unmaskedvalue, writeBuffer};
function applyInputValue(input, value, initialEvent) {
const inputmask = input ? input.inputmask : this,
opts = inputmask.opts;
function applyInputValue(input, value) {
const inputmask = input ? input.inputmask : this, opts = inputmask.opts;
input.inputmask.refreshValue = false;
if (typeof opts.onBeforeMask === "function") value = opts.onBeforeMask.call(inputmask, value, opts) || value;
value = (value || "").toString().split("");
checkVal(input, true, false, value);
inputmask.undoValue = inputmask._valueGet(true);
if ((opts.clearMaskOnLostFocus || opts.clearIncomplete) && input.inputmask._valueGet() === getBufferTemplate.call(inputmask).join("") && getLastValidPosition.call(inputmask) === -1) {
input.inputmask._valueSet("");
}
input.inputmask.refreshValue = false;
if (typeof opts.onBeforeMask === "function")
value = opts.onBeforeMask.call(inputmask, value, opts) || value;
value = (value || "").toString().split("");
checkVal(input, true, false, value, initialEvent);
inputmask.undoValue = inputmask._valueGet(true);
if (
(opts.clearMaskOnLostFocus || opts.clearIncomplete) &&
input.inputmask._valueGet() ===
getBufferTemplate.call(inputmask).join("") &&
getLastValidPosition.call(inputmask) === -1
) {
input.inputmask._valueSet("");
}
}
//todo put on prototype?
// todo put on prototype?
function clearOptionalTail(buffer) {
const inputmask = this;
const inputmask = this;
buffer.length = 0;
var template = getMaskTemplate.call(inputmask, true, 0, true, undefined, true), lmnt;
while ((lmnt = template.shift()) !== undefined) buffer.push(lmnt);
return buffer;
buffer.length = 0;
let template = getMaskTemplate.call(
inputmask,
true,
0,
true,
undefined,
true
),
lmnt;
while ((lmnt = template.shift()) !== undefined) buffer.push(lmnt);
return buffer;
}
function checkVal(input, writeOut, strict, nptvl, initiatingEvent) {
const inputmask = input ? input.inputmask : this,
maskset = inputmask.maskset,
opts = inputmask.opts, $ = inputmask.dependencyLib;
const inputmask = input ? input.inputmask : this,
maskset = inputmask.maskset,
opts = inputmask.opts,
$ = inputmask.dependencyLib;
var inputValue = nptvl.slice(),
charCodes = "",
initialNdx = -1,
result = undefined, skipOptionalPartCharacter = opts.skipOptionalPartCharacter;
opts.skipOptionalPartCharacter = ""; //see issue #2311
let inputValue = nptvl.slice(),
charCodes = "",
initialNdx = -1,
result,
skipOptionalPartCharacter = opts.skipOptionalPartCharacter;
opts.skipOptionalPartCharacter = ""; // see issue #2311
function isTemplateMatch(ndx, charCodes) {
var targetTemplate = getMaskTemplate.call(inputmask, true, 0).slice(ndx, seekNext.call(inputmask, ndx, false, false)).join("").replace(/'/g, ""),
charCodeNdx = targetTemplate.indexOf(charCodes);
//strip spaces from targetTemplate
while (charCodeNdx > 0 && targetTemplate[charCodeNdx - 1] === " ") charCodeNdx--;
function isTemplateMatch(ndx, charCodes) {
let targetTemplate = getMaskTemplate
.call(inputmask, true, 0)
.slice(ndx, seekNext.call(inputmask, ndx, false, false))
.join("")
.replace(/'/g, ""),
charCodeNdx = targetTemplate.indexOf(charCodes);
// strip spaces from targetTemplate
while (charCodeNdx > 0 && targetTemplate[charCodeNdx - 1] === " ")
charCodeNdx--;
var match = charCodeNdx === 0 && !isMask.call(inputmask, ndx)
&& (getTest.call(inputmask, ndx).match.nativeDef === charCodes.charAt(0)
|| (getTest.call(inputmask, ndx).match.static === true && getTest.call(inputmask, ndx).match.nativeDef === ("'" + charCodes.charAt(0)))
|| (getTest.call(inputmask, ndx).match.nativeDef === " " && (getTest.call(inputmask, ndx + 1).match.nativeDef === charCodes.charAt(0)
|| (getTest.call(inputmask, ndx + 1).match.static === true && getTest.call(inputmask, ndx + 1).match.nativeDef === ("'" + charCodes.charAt(0))))));
const match =
charCodeNdx === 0 &&
!isMask.call(inputmask, ndx) &&
(getTest.call(inputmask, ndx).match.nativeDef === charCodes.charAt(0) ||
(getTest.call(inputmask, ndx).match.static === true &&
getTest.call(inputmask, ndx).match.nativeDef ===
"'" + charCodes.charAt(0)) ||
(getTest.call(inputmask, ndx).match.nativeDef === " " &&
(getTest.call(inputmask, ndx + 1).match.nativeDef ===
charCodes.charAt(0) ||
(getTest.call(inputmask, ndx + 1).match.static === true &&
getTest.call(inputmask, ndx + 1).match.nativeDef ===
"'" + charCodes.charAt(0)))));
if (!match && charCodeNdx > 0 && !isMask.call(inputmask, ndx, false, true)) {
var nextPos = seekNext.call(inputmask, ndx);
if (inputmask.caretPos.begin < nextPos) {
inputmask.caretPos = {begin: nextPos};
}
}
return match;
if (
!match &&
charCodeNdx > 0 &&
!isMask.call(inputmask, ndx, false, true)
) {
const nextPos = seekNext.call(inputmask, ndx);
if (inputmask.caretPos.begin < nextPos) {
inputmask.caretPos = { begin: nextPos };
}
}
return match;
}
resetMaskSet.call(inputmask);
maskset.tests = {}; //reset tests ~ possible after alternating
initialNdx = opts.radixPoint ? determineNewCaretPosition.call(inputmask, {
begin: 0,
end: 0
}, false, opts.__financeInput === false ? "radixFocus" : undefined).begin : 0;
maskset.p = initialNdx;
inputmask.caretPos = {begin: initialNdx};
resetMaskSet.call(inputmask, false);
inputmask.clicked = 0; // reset click counter to correctly determine the caretposition in checkval
initialNdx = opts.radixPoint
? determineNewCaretPosition.call(
inputmask,
{
begin: 0,
end: 0
},
false,
opts.__financeInput === false ? "radixFocus" : undefined
).begin
: 0;
maskset.p = initialNdx;
inputmask.caretPos = { begin: initialNdx };
var staticMatches = [], prevCaretPos = inputmask.caretPos;
inputValue.forEach(function (charCode, ndx) {
if (charCode !== undefined) { //inputfallback strips some elements out of the inputarray. $.each logically presents them as undefined
/*if (maskset.validPositions[ndx] === undefined && inputValue[ndx] === getPlaceholder.call(inputmask, ndx) && isMask.call(inputmask, ndx, true) &&
isValid.call(inputmask, ndx, inputValue[ndx], true, undefined, true, true) === false) {
inputmask.caretPos.begin++;
} else*/
{
var keypress = new $.Event("_checkval");
keypress.key = charCode;
charCodes += charCode;
var lvp = getLastValidPosition.call(inputmask, undefined, true);
if (!isTemplateMatch(initialNdx, charCodes)) {
result = EventHandlers.keypressEvent.call(inputmask, keypress, true, false, strict, inputmask.caretPos.begin);
let staticMatches = [],
prevCaretPos = inputmask.caretPos;
inputValue.forEach(function (charCode, ndx) {
if (charCode !== undefined) {
// inputfallback strips some elements out of the inputarray. $.each logically presents them as undefined
/* if (maskset.validPositions[ndx] === undefined && inputValue[ndx] === getPlaceholder.call(inputmask, ndx) && isMask.call(inputmask, ndx, true) &&
isValid.call(inputmask, ndx, inputValue[ndx], true, undefined, true, true) === false) {
inputmask.caretPos.begin++;
} else */
// console.log("caret " + inputmask.caretPos.begin);
const keypress = new $.Event("_checkval");
keypress.key = charCode;
charCodes += charCode;
const lvp = getLastValidPosition.call(inputmask, undefined, true);
if (!isTemplateMatch(initialNdx, charCodes)) {
result = EventHandlers.keypressEvent.call(
inputmask,
keypress,
true,
false,
strict,
inputmask.caretPos.begin
);
if (result) {
initialNdx = inputmask.caretPos.begin + 1;
charCodes = "";
}
} else {
result = EventHandlers.keypressEvent.call(inputmask, keypress, true, false, strict, lvp + 1);
}
if (result) {
if (result.pos !== undefined && maskset.validPositions[result.pos] && maskset.validPositions[result.pos].match.static === true && maskset.validPositions[result.pos].alternation === undefined) {
staticMatches.push(result.pos);
if (!inputmask.isRTL) {
result.forwardPosition = result.pos + 1;
}
}
writeBuffer.call(inputmask, undefined, getBuffer.call(inputmask), result.forwardPosition, keypress, false);
inputmask.caretPos = {begin: result.forwardPosition, end: result.forwardPosition};
prevCaretPos = inputmask.caretPos;
} else {
if (maskset.validPositions[ndx] === undefined && inputValue[ndx] === getPlaceholder.call(inputmask, ndx) && isMask.call(inputmask, ndx, true)) {
inputmask.caretPos.begin++;
} else inputmask.caretPos = prevCaretPos; //restore the caret position from before the failed validation
}
}
if (result) {
initialNdx = inputmask.caretPos.begin + 1;
charCodes = "";
}
});
if (staticMatches.length > 0) {
var sndx, validPos, nextValid = seekNext.call(inputmask, -1, undefined, false);
if ((!isComplete.call(inputmask, getBuffer.call(inputmask)) && staticMatches.length <= nextValid)
|| (isComplete.call(inputmask, getBuffer.call(inputmask)) && staticMatches.length > 0 && (staticMatches.length !== nextValid && staticMatches[0] === 0))) { //should check if is sequence starting from 0
var nextSndx = nextValid;
while ((sndx = staticMatches.shift()) !== undefined) {
var keypress = new $.Event("_checkval");
validPos = maskset.validPositions[sndx];
validPos.generatedInput = true;
keypress.key = validPos.input;
result = EventHandlers.keypressEvent.call(inputmask, keypress, true, false, strict, nextSndx);
if (result && result.pos !== undefined && result.pos !== sndx && maskset.validPositions[result.pos] && maskset.validPositions[result.pos].match.static === true) {
staticMatches.push(result.pos);
} else if (!result) break;
nextSndx++;
}
} else { //mark al statics as generated
// while ((sndx = staticMatches.pop())) {
// validPos = maskset.validPositions[sndx];
// if (validPos) {
// validPos.generatedInput = true;
// }
// }
} else {
result = EventHandlers.keypressEvent.call(
inputmask,
keypress,
true,
false,
strict,
lvp + 1
);
}
if (result) {
if (
result.pos !== undefined &&
maskset.validPositions[result.pos] &&
maskset.validPositions[result.pos].match.static === true &&
maskset.validPositions[result.pos].alternation === undefined
) {
staticMatches.push(result.pos);
if (!inputmask.isRTL) {
result.forwardPosition = result.pos + 1;
}
}
}
if (writeOut) {
writeBuffer.call(
inputmask,
input,
getBuffer.call(inputmask), result ? result.forwardPosition : inputmask.caretPos.begin,
initiatingEvent || new $.Event("checkval"),
initiatingEvent && ((initiatingEvent.type === "input" && inputmask.undoValue !== getBuffer.call(inputmask).join("")) || initiatingEvent.type === "paste"));
// for (var vndx in maskset.validPositions) {
// if (maskset.validPositions[vndx].match.generated !== true) { //only remove non forced generated
// delete maskset.validPositions[vndx].generatedInput; //clear generated markings ~ consider initializing with a value as fully typed
// }
// }
inputmask,
undefined,
getBuffer.call(inputmask),
result.forwardPosition,
keypress,
false
);
inputmask.caretPos = {
begin: result.forwardPosition,
end: result.forwardPosition
};
prevCaretPos = inputmask.caretPos;
} else {
if (
maskset.validPositions[ndx] === undefined &&
inputValue[ndx] === getPlaceholder.call(inputmask, ndx) &&
isMask.call(inputmask, ndx, true)
) {
inputmask.caretPos.begin++;
} else inputmask.caretPos = prevCaretPos; // restore the caret position from before the failed validation
}
}
opts.skipOptionalPartCharacter = skipOptionalPartCharacter;
});
if (staticMatches.length > 0) {
let sndx,
validPos,
nextValid = seekNext.call(inputmask, -1, undefined, false);
if (
(!isComplete.call(inputmask, getBuffer.call(inputmask)) &&
staticMatches.length <= nextValid) ||
(isComplete.call(inputmask, getBuffer.call(inputmask)) &&
staticMatches.length > 0 &&
staticMatches.length !== nextValid &&
staticMatches[0] === 0)
) {
// should check if is sequence starting from 0
let nextSndx = nextValid;
while ((sndx = staticMatches.shift()) !== undefined) {
if (sndx < nextSndx) {
const keypress = new $.Event("_checkval");
validPos = maskset.validPositions[sndx];
validPos.generatedInput = true;
keypress.key = validPos.input;
result = EventHandlers.keypressEvent.call(
inputmask,
keypress,
true,
false,
strict,
nextSndx
);
if (
result &&
result.pos !== undefined &&
result.pos !== sndx &&
maskset.validPositions[result.pos] &&
maskset.validPositions[result.pos].match.static === true
) {
staticMatches.push(result.pos);
} else if (!result) break;
nextSndx++;
}
}
} else {
// mark al statics as generated
// while ((sndx = staticMatches.pop())) {
// validPos = maskset.validPositions[sndx];
// if (validPos) {
// validPos.generatedInput = true;
// }
// }
}
}
if (writeOut) {
writeBuffer.call(
inputmask,
input,
getBuffer.call(inputmask),
result ? result.forwardPosition : inputmask.caretPos.begin,
initiatingEvent || new $.Event("checkval"),
initiatingEvent &&
((initiatingEvent.type === "input" &&
inputmask.undoValue !== getBuffer.call(inputmask).join("")) ||
initiatingEvent.type === "paste")
);
// for (var vndx in maskset.validPositions) {
// if (maskset.validPositions[vndx].match.generated !== true) { //only remove non forced generated
// delete maskset.validPositions[vndx].generatedInput; //clear generated markings ~ consider initializing with a value as fully typed
// }
// }
}
opts.skipOptionalPartCharacter = skipOptionalPartCharacter;
}
function HandleNativePlaceholder(npt, value) {
const inputmask = npt ? npt.inputmask : this;
const inputmask = npt ? npt.inputmask : this;
if (ie) {
if (npt.inputmask._valueGet() !== value && (npt.placeholder !== value || npt.placeholder === "")) {
var buffer = getBuffer.call(inputmask).slice(),
nptValue = npt.inputmask._valueGet();
if (nptValue !== value) {
var lvp = getLastValidPosition.call(inputmask);
if (lvp === -1 && nptValue === getBufferTemplate.call(inputmask).join("")) {
buffer = [];
} else if (lvp !== -1) { //clearout optional tail of the mask
clearOptionalTail.call(inputmask, buffer);
}
writeBuffer(npt, buffer);
}
if (ie) {
if (
npt.inputmask._valueGet() !== value &&
(npt.placeholder !== value || npt.placeholder === "")
) {
let buffer = getBuffer.call(inputmask).slice(),
nptValue = npt.inputmask._valueGet();
if (nptValue !== value) {
const lvp = getLastValidPosition.call(inputmask);
if (
lvp === -1 &&
nptValue === getBufferTemplate.call(inputmask).join("")
) {
buffer = [];
} else if (lvp !== -1) {
// clearout optional tail of the mask
clearOptionalTail.call(inputmask, buffer);
}
} else if (npt.placeholder !== value) {
npt.placeholder = value;
if (npt.placeholder === "") npt.removeAttribute("placeholder");
writeBuffer(npt, buffer);
}
}
} else if (npt.placeholder !== value) {
npt.placeholder = value;
if (npt.placeholder === "") npt.removeAttribute("placeholder");
}
}
function unmaskedvalue(input) {
const inputmask = input ? input.inputmask : this,
opts = inputmask.opts,
maskset = inputmask.maskset;
const inputmask = input ? input.inputmask : this,
opts = inputmask.opts,
maskset = inputmask.maskset;
if (input) {
if (input.inputmask === undefined) {
return input.value;
}
if (input.inputmask && input.inputmask.refreshValue) { //forced refresh from the value form.reset
applyInputValue(input, input.inputmask._valueGet(true));
}
if (input) {
if (input.inputmask === undefined) {
return input.value;
}
var umValue = [],
vps = maskset.validPositions;
for (let pndx = 0, vpl = vps.length; pndx < vpl; pndx++) {
if (vps[pndx] && vps[pndx].match && (vps[pndx].match.static != true || (Array.isArray(maskset.metadata) && vps[pndx].generatedInput !== true))) {
//only include generated input with multiple masks (check on metadata)
umValue.push(vps[pndx].input);
}
if (input.inputmask && input.inputmask.refreshValue) {
// forced refresh from the value form.reset
applyInputValue(input, input.inputmask._valueGet(true));
}
var unmaskedValue = umValue.length === 0 ? "" : (inputmask.isRTL ? umValue.reverse() : umValue).join("");
if (typeof opts.onUnMask === "function") {
var bufferValue = (inputmask.isRTL ? getBuffer.call(inputmask).slice().reverse() : getBuffer.call(inputmask)).join("");
unmaskedValue = opts.onUnMask.call(inputmask, bufferValue, unmaskedValue, opts);
}
const umValue = [],
vps = maskset.validPositions;
for (let pndx = 0, vpl = vps.length; pndx < vpl; pndx++) {
if (
vps[pndx] &&
vps[pndx].match &&
(vps[pndx].match.static != true ||
(Array.isArray(maskset.metadata) && vps[pndx].generatedInput !== true))
) {
// only include generated input with multiple masks (check on metadata)
umValue.push(vps[pndx].input);
}
return unmaskedValue;
}
let unmaskedValue =
umValue.length === 0
? ""
: (inputmask.isRTL ? umValue.reverse() : umValue).join("");
if (typeof opts.onUnMask === "function") {
const bufferValue = (
inputmask.isRTL
? getBuffer.call(inputmask).slice().reverse()
: getBuffer.call(inputmask)
).join("");
unmaskedValue = opts.onUnMask.call(
inputmask,
bufferValue,
unmaskedValue,
opts
);
}
return unmaskedValue;
}
function writeBuffer(input, buffer, caretPos, event, triggerEvents) {
const inputmask = input ? input.inputmask : this,
opts = inputmask.opts,
$ = inputmask.dependencyLib;
const inputmask = input ? input.inputmask : this,
opts = inputmask.opts,
$ = inputmask.dependencyLib;
if (event && typeof opts.onBeforeWrite === "function") {
// buffer = buffer.slice(); //prevent uncontrolled manipulation of the internal buffer
var result = opts.onBeforeWrite.call(inputmask, event, buffer, caretPos, opts);
if (result) {
if (result.refreshFromBuffer) {
var refresh = result.refreshFromBuffer;
refreshFromBuffer.call(inputmask, refresh === true ? refresh : refresh.start, refresh.end, result.buffer || buffer);
buffer = getBuffer.call(inputmask, true);
}
if (caretPos !== undefined) caretPos = result.caret !== undefined ? result.caret : caretPos;
}
if (event && typeof opts.onBeforeWrite === "function") {
// buffer = buffer.slice(); //prevent uncontrolled manipulation of the internal buffer
const result = opts.onBeforeWrite.call(
inputmask,
event,
buffer,
caretPos,
opts
);
if (result) {
if (result.refreshFromBuffer) {
const refresh = result.refreshFromBuffer;
refreshFromBuffer.call(
inputmask,
refresh === true ? refresh : refresh.start,
refresh.end,
result.buffer || buffer
);
buffer = getBuffer.call(inputmask, true);
}
if (caretPos !== undefined)
caretPos = result.caret !== undefined ? result.caret : caretPos;
}
if (input !== undefined) {
input.inputmask._valueSet(buffer.join(""));
if (caretPos !== undefined && (event === undefined || event.type !== "blur")) {
// console.log(caretPos);
caret.call(inputmask, input, caretPos, undefined, undefined, (event !== undefined && event.type === "keydown" && (event.key === keys.Delete || event.key === keys.Backspace)));
}
if (triggerEvents === true) {
var $input = $(input), nptVal = input.inputmask._valueGet();
input.inputmask.skipInputEvent = true;
$input.trigger("input");
setTimeout(function () { //timeout needed for IE
if (nptVal === getBufferTemplate.call(inputmask).join("")) {
$input.trigger("cleared");
} else if (isComplete.call(inputmask, buffer) === true) {
$input.trigger("complete");
}
}, 0);
}
}
if (input !== undefined) {
input.inputmask._valueSet(buffer.join(""));
if (
caretPos !== undefined &&
(event === undefined || event.type !== "blur")
) {
// console.log(caretPos);
caret.call(
inputmask,
input,
caretPos,
undefined,
undefined,
event !== undefined &&
event.type === "keydown" &&
(event.key === keys.Delete || event.key === keys.Backspace)
);
}
input.inputmask.writeBufferHook === undefined ||
input.inputmask.writeBufferHook(caretPos);
if (triggerEvents === true) {
const $input = $(input),
nptVal = input.inputmask._valueGet();
input.inputmask.skipInputEvent = true;
$input.trigger("input");
setTimeout(function () {
// timeout needed for IE
if (nptVal === getBufferTemplate.call(inputmask).join("")) {
$input.trigger("cleared");
} else if (isComplete.call(inputmask, buffer) === true) {
$input.trigger("complete");
}
}, 0);
}
}
}

View file

@ -5,350 +5,428 @@
* Licensed under the MIT license
*/
import {mask} from "./mask";
import $ from "./dependencyLibs/inputmask.dependencyLib";
import window from "./global/window";
import {generateMaskSet, analyseMask} from "./mask-lexer";
import {getMaskTemplate} from "./validation-tests";
import {determineLastRequiredPosition, getBuffer, getBufferTemplate, isMask} from "./positioning";
import {isComplete} from "./validation";
import {checkVal, unmaskedvalue} from "./inputHandling";
import {EventRuler} from "./eventruler";
import definitions from "./definitions";
import defaults from "./defaults";
import canUseDOM from "./canUseDOM";
import definitions from "./definitions";
import $ from "./dependencyLibs/inputmask.dependencyLib";
import { EventRuler } from "./eventruler";
import window from "./global/window";
import { checkVal, unmaskedvalue } from "./inputHandling";
import { mask } from "./mask";
import { generateMaskSet, analyseMask } from "./mask-lexer";
import {
determineLastRequiredPosition,
getBuffer,
getBufferTemplate,
isMask
} from "./positioning";
import { isComplete } from "./validation";
import { getMaskTemplate } from "./validation-tests";
const document = window.document, dataKey = "_inputmask_opts";
const document = window.document,
dataKey = "_inputmask_opts";
function Inputmask(alias, options, internal) {
if (!canUseDOM) {
return;
// allow instanciating without new
if (!(this instanceof Inputmask)) {
return new Inputmask(alias, options, internal);
}
this.dependencyLib = $;
this.el = undefined;
this.events = {};
this.maskset = undefined;
if (internal !== true) {
// init options
if (Object.prototype.toString.call(alias) === "[object Object]") {
options = alias;
} else {
options = options || {};
if (alias) options.alias = alias;
}
this.opts = $.extend(true, {}, this.defaults, options);
this.noMasksCache = options && options.definitions !== undefined;
this.userOptions = options || {}; // user passed options
resolveAlias(this.opts.alias, options, this.opts);
}
//allow instanciating without new
if (!(this instanceof Inputmask)) {
return new Inputmask(alias, options, internal);
}
this.dependencyLib = $;
this.el = undefined;
this.events = {};
this.maskset = undefined;
if (internal !== true) {
//init options
if (Object.prototype.toString.call(alias) === "[object Object]") {
options = alias;
} else {
options = options || {};
if (alias) options.alias = alias;
}
this.opts = $.extend(true, {}, this.defaults, options);
this.noMasksCache = options && options.definitions !== undefined;
this.userOptions = options || {}; //user passed options
resolveAlias(this.opts.alias, options, this.opts);
}
//maskscope properties
this.refreshValue = false; //indicate a refresh from the inputvalue is needed (form.reset)
this.undoValue = undefined;
this.$el = undefined;
this.skipInputEvent = false; //skip when triggered from within inputmask
this.validationEvent = false;
this.ignorable = false;
this.maxLength;
this.mouseEnter = false;
this.clicked = 0;
this.originalPlaceholder = undefined; //needed for FF
this.isComposing = false, //keydowncode == 229 compositionevent fallback
this.hasAlternator = false;
// maskscope properties
this.refreshValue = false; // indicate a refresh from the inputvalue is needed (form.reset)
this.undoValue = undefined;
this.$el = undefined;
this.skipInputEvent = false; // skip when triggered from within inputmask
this.validationEvent = false;
this.ignorable = false;
// eslint-disable-next-line no-unused-expressions
this.maxLength;
this.mouseEnter = false;
this.clicked = 0;
this.originalPlaceholder = undefined; // needed for FF
this.isComposing = false; // keydowncode == 229 compositionevent fallback
this.hasAlternator = false;
}
Inputmask.prototype = {
dataAttribute: "data-inputmask", //data attribute prefix used for attribute binding
//options default
defaults: defaults,
definitions: definitions,
aliases: {}, //aliases definitions
masksCache: {},
get isRTL() {
return this.opts.isRTL || this.opts.numericInput;
},
mask: function (elems) {
var that = this;
if (typeof elems === "string") {
elems = (document.getElementById(elems) || document.querySelectorAll(elems));
}
elems = elems.nodeName ? [elems] : (Array.isArray(elems) ? elems : [].slice.call(elems)); //[].slice as alternate for Array.from (Yandex browser)
elems.forEach(function (el, ndx) {
var scopedOpts = $.extend(true, {}, that.opts);
if (importAttributeOptions(el, scopedOpts, $.extend(true, {}, that.userOptions), that.dataAttribute)) {
var maskset = generateMaskSet(scopedOpts, that.noMasksCache);
if (maskset !== undefined) {
if (el.inputmask !== undefined) {
el.inputmask.opts.autoUnmask = true; //force autounmasking when remasking
el.inputmask.remove();
}
//store inputmask instance on the input with element reference
el.inputmask = new Inputmask(undefined, undefined, true);
el.inputmask.opts = scopedOpts;
el.inputmask.noMasksCache = that.noMasksCache;
el.inputmask.userOptions = $.extend(true, {}, that.userOptions);
// el.inputmask.isRTL = scopedOpts.isRTL || scopedOpts.numericInput;
el.inputmask.el = el;
el.inputmask.$el = $(el);
el.inputmask.maskset = maskset;
dataAttribute: "data-inputmask", // data attribute prefix used for attribute binding
// options default
defaults,
definitions,
aliases: {}, // aliases definitions
masksCache: {},
i18n: {},
get isRTL() {
return this.opts.isRTL || this.opts.numericInput;
},
mask: function (elems) {
const that = this;
if (typeof elems === "string") {
elems =
document.getElementById(elems) || document.querySelectorAll(elems);
}
elems = elems.nodeName
? [elems]
: Array.isArray(elems)
? elems
: [].slice.call(elems); // [].slice as alternate for Array.from (Yandex browser)
elems.forEach(function (el, ndx) {
const scopedOpts = $.extend(true, {}, that.opts);
if (
importAttributeOptions(
el,
scopedOpts,
$.extend(true, {}, that.userOptions),
that.dataAttribute
)
) {
const maskset = generateMaskSet(scopedOpts, that.noMasksCache);
if (maskset !== undefined) {
if (el.inputmask !== undefined) {
el.inputmask.opts.autoUnmask = true; // force autounmasking when remasking
el.inputmask.remove();
}
// store inputmask instance on the input with element reference
el.inputmask = new Inputmask(undefined, undefined, true);
el.inputmask.opts = scopedOpts;
el.inputmask.noMasksCache = that.noMasksCache;
el.inputmask.userOptions = $.extend(true, {}, that.userOptions);
// el.inputmask.isRTL = scopedOpts.isRTL || scopedOpts.numericInput;
el.inputmask.el = el;
el.inputmask.$el = $(el);
el.inputmask.maskset = maskset;
$.data(el, dataKey, that.userOptions);
mask.call(el.inputmask);
}
}
});
return elems && elems[0] ? (elems[0].inputmask || this) : this;
},
option: function (options, noremask) { //set extra options || retrieve value of a current option
if (typeof options === "string") {
return this.opts[options];
} else if (typeof options === "object") {
$.extend(this.userOptions, options); //user passed options
//remask
if (this.el && noremask !== true) {
this.mask(this.el);
}
return this;
$.data(el, dataKey, that.userOptions);
mask.call(el.inputmask);
}
},
unmaskedvalue: function (value) {
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
if (this.el === undefined || value !== undefined) {
var valueBuffer = (typeof this.opts.onBeforeMask === "function" ? (this.opts.onBeforeMask.call(this, value, this.opts) || value) : value).split("");
checkVal.call(this, undefined, false, false, valueBuffer);
if (typeof this.opts.onBeforeWrite === "function") this.opts.onBeforeWrite.call(this, undefined, getBuffer.call(this), 0, this.opts);
}
return unmaskedvalue.call(this, this.el);
},
remove: function () {
if (this.el) {
$.data(this.el, dataKey, null); //invalidate
//writeout the value
var cv = this.opts.autoUnmask ? unmaskedvalue(this.el) : this._valueGet(this.opts.autoUnmask);
if (cv !== getBufferTemplate.call(this).join("")) this._valueSet(cv, this.opts.autoUnmask); else this._valueSet("");
//unbind all events
EventRuler.off(this.el);
}
});
return elems && elems[0] ? elems[0].inputmask || this : this;
},
option: function (options, noremask) {
// set extra options || retrieve value of a current option
if (typeof options === "string") {
return this.opts[options];
} else if (typeof options === "object") {
$.extend(this.userOptions, options); // user passed options
// remask
if (this.el && noremask !== true) {
this.mask(this.el);
}
return this;
}
},
unmaskedvalue: function (value) {
this.maskset =
this.maskset || generateMaskSet(this.opts, this.noMasksCache);
if (this.el === undefined || value !== undefined) {
const valueBuffer = (
typeof this.opts.onBeforeMask === "function"
? this.opts.onBeforeMask.call(this, value, this.opts) || value
: value
).split("");
checkVal.call(this, undefined, false, false, valueBuffer);
if (typeof this.opts.onBeforeWrite === "function")
this.opts.onBeforeWrite.call(
this,
undefined,
getBuffer.call(this),
0,
this.opts
);
}
return unmaskedvalue.call(this, this.el);
},
remove: function () {
if (this.el) {
$.data(this.el, dataKey, null); // invalidate
// writeout the value
const cv = this.opts.autoUnmask
? unmaskedvalue(this.el)
: this._valueGet(this.opts.autoUnmask);
if (cv !== getBufferTemplate.call(this).join(""))
this._valueSet(cv, this.opts.autoUnmask);
else this._valueSet("");
// unbind all events
EventRuler.off(this.el);
//restore the value property
var valueProperty;
if (Object.getOwnPropertyDescriptor && Object.getPrototypeOf) {
valueProperty = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.el), "value");
if (valueProperty) {
if (this.__valueGet) {
Object.defineProperty(this.el, "value", {
get: this.__valueGet,
set: this.__valueSet,
configurable: true
});
}
}
} else if (document.__lookupGetter__ && this.el.__lookupGetter__("value")) {
if (this.__valueGet) {
this.el.__defineGetter__("value", this.__valueGet);
this.el.__defineSetter__("value", this.__valueSet);
}
}
//clear data
this.el.inputmask = undefined;
}
return this.el;
},
getemptymask: function () { //return the default (empty) mask value, usefull for setting the default value in validation
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
return (this.isRTL ? getBufferTemplate.call(this).reverse() : getBufferTemplate.call(this)).join("");
},
hasMaskedValue: function () { //check wheter the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value
return !this.opts.autoUnmask;
},
isComplete: function () {
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
return isComplete.call(this, getBuffer.call(this));
},
getmetadata: function () { //return mask metadata if exists
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
if (Array.isArray(this.maskset.metadata)) {
var maskTarget = getMaskTemplate.call(this, true, 0, false).join("");
this.maskset.metadata.forEach(function (mtdt) {
if (mtdt.mask === maskTarget) {
maskTarget = mtdt;
return false;
}
return true;
// restore the value property
let valueProperty;
if (Object.getOwnPropertyDescriptor && Object.getPrototypeOf) {
valueProperty = Object.getOwnPropertyDescriptor(
Object.getPrototypeOf(this.el),
"value"
);
if (valueProperty) {
if (this.__valueGet) {
Object.defineProperty(this.el, "value", {
get: this.__valueGet,
set: this.__valueSet,
configurable: true
});
return maskTarget;
}
}
return this.maskset.metadata;
},
isValid: function (value) {
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
if (value) {
var valueBuffer = (typeof this.opts.onBeforeMask === "function" ? (this.opts.onBeforeMask.call(this, value, this.opts) || value) : value).split("");
checkVal.call(this, undefined, true, false, valueBuffer);
} else {
value = this.isRTL ? getBuffer.call(this).slice().reverse().join("") : getBuffer.call(this).join("");
} else if (
document.__lookupGetter__ &&
this.el.__lookupGetter__("value")
) {
if (this.__valueGet) {
this.el.__defineGetter__("value", this.__valueGet);
this.el.__defineSetter__("value", this.__valueSet);
}
var buffer = getBuffer.call(this);
var rl = determineLastRequiredPosition.call(this),
lmib = buffer.length - 1;
for (; lmib > rl; lmib--) {
if (isMask.call(this, lmib)) break;
}
// clear data
this.el.inputmask = undefined;
}
return this.el;
},
getemptymask: function () {
// return the default (empty) mask value, usefull for setting the default value in validation
this.maskset =
this.maskset || generateMaskSet(this.opts, this.noMasksCache);
return (
this.isRTL
? getBufferTemplate.call(this).reverse()
: getBufferTemplate.call(this)
).join("");
},
hasMaskedValue: function () {
// check wheter the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value
return !this.opts.autoUnmask;
},
isComplete: function () {
this.maskset =
this.maskset || generateMaskSet(this.opts, this.noMasksCache);
return isComplete.call(this, getBuffer.call(this));
},
getmetadata: function () {
// return mask metadata if exists
this.maskset =
this.maskset || generateMaskSet(this.opts, this.noMasksCache);
if (Array.isArray(this.maskset.metadata)) {
let maskTarget = getMaskTemplate.call(this, true, 0, false).join("");
this.maskset.metadata.forEach(function (mtdt) {
if (mtdt.mask === maskTarget) {
maskTarget = mtdt;
return false;
}
buffer.splice(rl, lmib + 1 - rl);
return isComplete.call(this, buffer) && value === (this.isRTL ? getBuffer.call(this).slice().reverse().join("") : getBuffer.call(this).join(""));
return true;
});
return maskTarget;
}
return this.maskset.metadata;
},
isValid: function (value) {
this.maskset =
this.maskset || generateMaskSet(this.opts, this.noMasksCache);
if (value) {
const valueBuffer = (
typeof this.opts.onBeforeMask === "function"
? this.opts.onBeforeMask.call(this, value, this.opts) || value
: value
).split("");
checkVal.call(this, undefined, true, false, valueBuffer);
} else {
value = this.isRTL
? getBuffer.call(this).slice().reverse().join("")
: getBuffer.call(this).join("");
}
let buffer = getBuffer.call(this),
rl = determineLastRequiredPosition.call(this),
lmib = buffer.length - 1;
for (; lmib > rl; lmib--) {
if (isMask.call(this, lmib)) break;
}
buffer.splice(rl, lmib + 1 - rl);
},
format: function (value, metadata) {
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
let valueBuffer = (typeof this.opts.onBeforeMask === "function" ? (this.opts.onBeforeMask.call(this, value, this.opts) || value) : value).split("");
checkVal.call(this, undefined, true, false, valueBuffer);
let formattedValue = this.isRTL ? getBuffer.call(this).slice().reverse().join("") : getBuffer.call(this).join("");
return metadata ? {
value: formattedValue,
metadata: this.getmetadata()
} : formattedValue;
},
setValue: function (value) {
if (this.el) {
$(this.el).trigger("setvalue", [value]);
return (
isComplete.call(this, buffer) &&
value ===
(this.isRTL
? getBuffer.call(this).slice().reverse().join("")
: getBuffer.call(this).join(""))
);
},
format: function (value, metadata) {
this.maskset =
this.maskset || generateMaskSet(this.opts, this.noMasksCache);
const valueBuffer = (
typeof this.opts.onBeforeMask === "function"
? this.opts.onBeforeMask.call(this, value, this.opts) || value
: value
).split("");
checkVal.call(this, undefined, true, false, valueBuffer);
const formattedValue = this.isRTL
? getBuffer.call(this).slice().reverse().join("")
: getBuffer.call(this).join("");
return metadata
? {
value: formattedValue,
metadata: this.getmetadata()
}
},
analyseMask: analyseMask
: formattedValue;
},
setValue: function (value) {
if (this.el) {
$(this.el).trigger("setvalue", [value]);
}
},
analyseMask
};
function resolveAlias(aliasStr, options, opts) {
var aliasDefinition = Inputmask.prototype.aliases[aliasStr];
if (aliasDefinition) {
if (aliasDefinition.alias) resolveAlias(aliasDefinition.alias, undefined, opts); //alias is another alias
$.extend(true, opts, aliasDefinition); //merge alias definition in the options
$.extend(true, opts, options); //reapply extra given options
return true;
} else //alias not found - try as mask
if (opts.mask === null) {
opts.mask = aliasStr;
}
const aliasDefinition = Inputmask.prototype.aliases[aliasStr];
if (aliasDefinition) {
if (aliasDefinition.alias)
resolveAlias(aliasDefinition.alias, undefined, opts); // alias is another alias
$.extend(true, opts, aliasDefinition); // merge alias definition in the options
$.extend(true, opts, options); // reapply extra given options
return true;
} // alias not found - try as mask
else if (opts.mask === null) {
opts.mask = aliasStr;
}
return false;
return false;
}
function importAttributeOptions(npt, opts, userOptions, dataAttribute) {
function importOption(option, optionData) {
const attrOption = dataAttribute === "" ? option : dataAttribute + "-" + option;
optionData = optionData !== undefined ? optionData : npt.getAttribute(attrOption);
if (optionData !== null) {
if (typeof optionData === "string") {
if (option.indexOf("on") === 0) {
optionData = window[optionData];
}//get function definition
else if (optionData === "false") {
optionData = false;
} else if (optionData === "true") optionData = true;
}
userOptions[option] = optionData;
}
function importOption(option, optionData) {
const attrOption =
dataAttribute === "" ? option : dataAttribute + "-" + option;
optionData =
optionData !== undefined ? optionData : npt.getAttribute(attrOption);
if (optionData !== null) {
if (typeof optionData === "string") {
if (option.indexOf("on") === 0) {
optionData = window[optionData];
} // get function definition
else if (optionData === "false") {
optionData = false;
} else if (optionData === "true") optionData = true;
}
userOptions[option] = optionData;
}
}
if (opts.importDataAttributes === true) {
let attrOptions = npt.getAttribute(dataAttribute),
option,
dataoptions,
optionData,
p;
if (attrOptions && attrOptions !== "") {
attrOptions = attrOptions.replace(/'/g, '"');
dataoptions = JSON.parse("{" + attrOptions + "}");
}
if (opts.importDataAttributes === true) {
var attrOptions = npt.getAttribute(dataAttribute), option, dataoptions, optionData, p;
if (attrOptions && attrOptions !== "") {
attrOptions = attrOptions.replace(/'/g, "\"");
dataoptions = JSON.parse("{" + attrOptions + "}");
}
//resolve aliases
if (dataoptions) { //pickup alias from dataAttribute
optionData = undefined;
for (p in dataoptions) {
if (p.toLowerCase() === "alias") {
optionData = dataoptions[p];
break;
}
}
}
importOption("alias", optionData); //pickup alias from dataAttribute-alias
if (userOptions.alias) {
resolveAlias(userOptions.alias, userOptions, opts);
}
for (option in opts) {
if (dataoptions) {
optionData = undefined;
for (p in dataoptions) {
if (p.toLowerCase() === option.toLowerCase()) {
optionData = dataoptions[p];
break;
}
}
}
importOption(option, optionData);
// resolve aliases
if (dataoptions) {
// pickup alias from dataAttribute
optionData = undefined;
for (p in dataoptions) {
if (p.toLowerCase() === "alias") {
optionData = dataoptions[p];
break;
}
}
}
$.extend(true, opts, userOptions);
//handle dir=rtl
if (npt.dir === "rtl" || opts.rightAlign) {
npt.style.textAlign = "right";
importOption("alias", optionData); // pickup alias from dataAttribute-alias
if (userOptions.alias) {
resolveAlias(userOptions.alias, userOptions, opts);
}
if (npt.dir === "rtl" || opts.numericInput) {
npt.dir = "ltr";
npt.removeAttribute("dir");
opts.isRTL = true;
for (option in opts) {
if (dataoptions) {
optionData = undefined;
for (p in dataoptions) {
if (p.toLowerCase() === option.toLowerCase()) {
optionData = dataoptions[p];
break;
}
}
}
importOption(option, optionData);
}
}
$.extend(true, opts, userOptions);
return Object.keys(userOptions).length;
// handle dir=rtl
if (npt.dir === "rtl" || opts.rightAlign) {
npt.style.textAlign = "right";
}
if (npt.dir === "rtl" || opts.numericInput) {
npt.dir = "ltr";
npt.removeAttribute("dir");
opts.isRTL = true;
}
return Object.keys(userOptions).length;
}
//apply defaults, definitions, aliases
// apply defaults, definitions, aliases
Inputmask.extendDefaults = function (options) {
$.extend(true, Inputmask.prototype.defaults, options);
$.extend(true, Inputmask.prototype.defaults, options);
};
Inputmask.extendDefinitions = function (definition) {
$.extend(true, Inputmask.prototype.definitions, definition);
$.extend(true, Inputmask.prototype.definitions, definition);
};
Inputmask.extendAliases = function (alias) {
$.extend(true, Inputmask.prototype.aliases, alias);
$.extend(true, Inputmask.prototype.aliases, alias);
};
//static fn on inputmask
// static fn on inputmask
Inputmask.format = function (value, options, metadata) {
return Inputmask(options).format(value, metadata);
return Inputmask(options).format(value, metadata);
};
Inputmask.unmask = function (value, options) {
return Inputmask(options).unmaskedvalue(value);
return Inputmask(options).unmaskedvalue(value);
};
Inputmask.isValid = function (value, options) {
return Inputmask(options).isValid(value);
return Inputmask(options).isValid(value);
};
Inputmask.remove = function (elems) {
if (typeof elems === "string") {
elems = document.getElementById(elems) || document.querySelectorAll(elems);
}
elems = elems.nodeName ? [elems] : elems;
elems.forEach(function (el) {
if (el.inputmask) el.inputmask.remove();
});
if (typeof elems === "string") {
elems = document.getElementById(elems) || document.querySelectorAll(elems);
}
elems = elems.nodeName ? [elems] : elems;
elems.forEach(function (el) {
if (el.inputmask) el.inputmask.remove();
});
};
Inputmask.setValue = function (elems, value) {
if (typeof elems === "string") {
elems = document.getElementById(elems) || document.querySelectorAll(elems);
}
elems = elems.nodeName ? [elems] : elems;
elems.forEach(function (el) {
if (el.inputmask) el.inputmask.setValue(value); else $(el).trigger("setvalue", [value]);
});
if (typeof elems === "string") {
elems = document.getElementById(elems) || document.querySelectorAll(elems);
}
elems = elems.nodeName ? [elems] : elems;
elems.forEach(function (el) {
if (el.inputmask) el.inputmask.setValue(value);
else $(el).trigger("setvalue", [value]);
});
};
Inputmask.dependencyLib = $;
//make inputmask available
// make inputmask available
window.Inputmask = Inputmask;
export default Inputmask;

View file

@ -1,33 +1,54 @@
import window from "./global/window";
import Inputmask from "./inputmask";
import canUseDOM from "./canUseDOM";
const document = window.document;
// add check if it is supported by the browser
// integrate shadowroot into maskcope
if (canUseDOM && document && document.head && document.head.attachShadow && window.customElements && window.customElements.get("input-mask") === undefined) {
class InputmaskElement extends HTMLElement {
constructor() {
super();
var attributeNames = this.getAttributeNames(),
shadow = this.attachShadow({mode: "closed"}),
input = document.createElement("input");
input.type = "text";
shadow.appendChild(input);
if (
document &&
document.head &&
document.head.attachShadow &&
window.customElements &&
window.customElements.get("input-mask") === undefined
) {
class InputmaskElement extends HTMLElement {
constructor() {
super();
const attributeNames = this.getAttributeNames(),
shadow = this.attachShadow({ mode: "closed" });
this.input = document.createElement("input");
this.input.type = "text";
shadow.appendChild(this.input);
for (var attr in attributeNames) {
if (Object.prototype.hasOwnProperty.call(attributeNames, attr)) {
input.setAttribute(attributeNames[attr], this.getAttribute(attributeNames[attr]));
}
}
for (const attr in attributeNames) {
if (Object.prototype.hasOwnProperty.call(attributeNames, attr)) {
this.input.setAttribute(
attributeNames[attr],
this.getAttribute(attributeNames[attr])
);
}
}
var im = new Inputmask();
im.dataAttribute = "";
im.mask(input);
input.inputmask.shadowRoot = shadow; //make the shadowRoot available
}
}
const im = new Inputmask();
im.dataAttribute = "";
im.mask(this.input);
this.input.inputmask.shadowRoot = shadow; // make the shadowRoot available
}
window.customElements.define("input-mask", InputmaskElement);
attributeChangedCallback(attrName, oldVal, newVal) {
this.input.setAttribute(attrName, newVal);
}
// bind value
get value() {
return this.input.value;
}
set value(value) {
this.input.value = value;
}
}
window.customElements.define("input-mask", InputmaskElement);
}

View file

@ -5,77 +5,85 @@
* Licensed under the MIT license
*/
import $ from "jquery";
import Inputmask from "./inputmask";
if ($.fn.inputmask === undefined) {
//jquery plugin
$.fn.inputmask = function (fn, options) {
var nptmask, input = this[0];
if (options === undefined) options = {};
if (typeof fn === "string") {
switch (fn) {
case "unmaskedvalue":
return input && input.inputmask ? input.inputmask.unmaskedvalue() : $(input).val();
case "remove":
return this.each(function () {
if (this.inputmask) this.inputmask.remove();
});
case "getemptymask":
return input && input.inputmask ? input.inputmask.getemptymask() : "";
case "hasMaskedValue": //check whether the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value
return input && input.inputmask ? input.inputmask.hasMaskedValue() : false;
case "isComplete":
return input && input.inputmask ? input.inputmask.isComplete() : true;
case "getmetadata": //return mask metadata if exists
return input && input.inputmask ? input.inputmask.getmetadata() : undefined;
case "setvalue":
Inputmask.setValue(input, options);
break;
case "option":
if (typeof options === "string") {
if (input && input.inputmask !== undefined) {
return input.inputmask.option(options);
}
} else {
return this.each(function () {
if (this.inputmask !== undefined) {
return this.inputmask.option(options);
}
});
}
break;
default:
options.alias = fn;
nptmask = new Inputmask(options);
return this.each(function () {
nptmask.mask(this);
});
}
} else if (Array.isArray(fn)) {
options.alias = fn;
nptmask = new Inputmask(options);
return this.each(function () {
nptmask.mask(this);
});
} else if (typeof fn == "object") {
nptmask = new Inputmask(fn);
if (fn.mask === undefined && fn.alias === undefined) {
return this.each(function () {
if (this.inputmask !== undefined) {
return this.inputmask.option(fn);
} else nptmask.mask(this);
});
} else {
return this.each(function () {
nptmask.mask(this);
});
}
} else if (fn === undefined) {
//look for data-inputmask atributes
return this.each(function () {
nptmask = new Inputmask(options);
nptmask.mask(this);
});
}
};
// jquery plugin
$.fn.inputmask = function (fn, options) {
let nptmask,
input = this[0];
if (options === undefined) options = {};
if (typeof fn === "string") {
switch (fn) {
case "unmaskedvalue":
return input && input.inputmask
? input.inputmask.unmaskedvalue()
: $(input).val();
case "remove":
return this.each(function () {
if (this.inputmask) this.inputmask.remove();
});
case "getemptymask":
return input && input.inputmask ? input.inputmask.getemptymask() : "";
case "hasMaskedValue": // check whether the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value
return input && input.inputmask
? input.inputmask.hasMaskedValue()
: false;
case "isComplete":
return input && input.inputmask ? input.inputmask.isComplete() : true;
case "getmetadata": // return mask metadata if exists
return input && input.inputmask
? input.inputmask.getmetadata()
: undefined;
case "setvalue":
Inputmask.setValue(input, options);
break;
case "option":
if (typeof options === "string") {
if (input && input.inputmask !== undefined) {
return input.inputmask.option(options);
}
} else {
return this.each(function () {
if (this.inputmask !== undefined) {
return this.inputmask.option(options);
}
});
}
break;
default:
options.alias = fn;
nptmask = new Inputmask(options);
return this.each(function () {
nptmask.mask(this);
});
}
} else if (Array.isArray(fn)) {
options.alias = fn;
nptmask = new Inputmask(options);
return this.each(function () {
nptmask.mask(this);
});
} else if (typeof fn === "object") {
nptmask = new Inputmask(fn);
if (fn.mask === undefined && fn.alias === undefined) {
return this.each(function () {
if (this.inputmask !== undefined) {
return this.inputmask.option(fn);
} else nptmask.mask(this);
});
} else {
return this.each(function () {
nptmask.mask(this);
});
}
} else if (fn === undefined) {
// look for data-inputmask atributes
return this.each(function () {
nptmask = new Inputmask(options);
nptmask.mask(this);
});
}
};
}

120
node_modules/inputmask/lib/keycode.js generated vendored
View file

@ -1,57 +1,81 @@
export {keyCode, toKey, toKeyCode, keys};
export { keyCode, toKey, toKeyCode, keys };
const keyCode = {
"AltGraph": 18,
"ArrowDown": 40,
"ArrowLeft": 37,
"ArrowRight": 39,
"ArrowUp": 38,
"Backspace": 8,
"BACKSPACE_SAFARI": 127,
"CapsLock": 20,
"Delete": 46,
"End": 35,
"Enter": 13,
"Escape": 27,
"Home": 36,
"Insert": 45,
"PageDown": 34,
"PageUp": 33,
"Space": 32,
"Tab": 9,
"c": 67,
"x": 88,
"z": 90,
"Shift": 16,
"Control": 17,
"Alt": 18,
"Pause": 19,
"Meta_LEFT": 91,
"Meta_RIGHT": 92,
"ContextMenu": 93,
"Process": 229,
"Unidentified": 229,
"F1": 112,
"F2": 113,
"F3": 114,
"F4": 115,
"F5": 116,
"F6": 117,
"F7": 118,
"F8": 119,
"F9": 120,
"F10": 121,
"F11": 122,
"F12": 123
const ignorables = {
Alt: 18,
AltGraph: 18,
ArrowDown: 40,
ArrowLeft: 37,
ArrowRight: 39,
ArrowUp: 38,
Backspace: 8,
CapsLock: 20,
Control: 17,
ContextMenu: 93,
Dead: 221,
Delete: 46,
End: 35,
Escape: 27,
F1: 112,
F2: 113,
F3: 114,
F4: 115,
F5: 116,
F6: 117,
F7: 118,
F8: 119,
F9: 120,
F10: 121,
F11: 122,
F12: 123,
Home: 36,
Insert: 45,
NumLock: 144,
PageDown: 34,
PageUp: 33,
Pause: 19,
PrintScreen: 44,
Process: 229,
Shift: 16,
ScrollLock: 145,
Tab: 9,
Unidentified: 229
};
const keyCodeRev = Object.entries(keyCode).reduce((acc, [key, value]) => (acc[value] = acc[value] === undefined ? key : acc[value] , acc), {});
const keys = Object.entries(keyCode).reduce((acc, [key, value]) => (acc[key] = key === "Space" ? " " : key, acc), {});
var keyCode = {
c: 67,
x: 88,
z: 90,
BACKSPACE_SAFARI: 127,
Enter: 13,
Meta_LEFT: 91,
Meta_RIGHT: 92,
Space: 32,
...ignorables
};
const keyCodeRev = Object.entries(keyCode).reduce(
(acc, [key, value]) =>
(
// eslint-disable-next-line no-sequences
(acc[value] = acc[value] === undefined ? key : acc[value]), acc
),
{}
),
keys = Object.entries(keyCode).reduce(
// eslint-disable-next-line no-sequences
(acc, [key, value]) => ((acc[key] = key === "Space" ? " " : key), acc),
{}
);
function toKey(keyCode, shiftKey) {
return keyCodeRev[keyCode] || (shiftKey ? String.fromCharCode(keyCode) : String.fromCharCode(keyCode).toLowerCase());
return (
keyCodeRev[keyCode] ||
(shiftKey
? String.fromCharCode(keyCode)
: String.fromCharCode(keyCode).toLowerCase())
);
}
function toKeyCode(key) {
return keyCode[key];
return keyCode[key];
}

File diff suppressed because it is too large Load diff

536
node_modules/inputmask/lib/mask.js generated vendored
View file

@ -1,245 +1,325 @@
import {keys} from "./keycode.js";
import {caret, getBuffer, getBufferTemplate, getLastValidPosition, resetMaskSet, seekNext} from "./positioning";
import {applyInputValue, clearOptionalTail, writeBuffer} from "./inputHandling";
import {EventRuler} from "./eventruler";
import {iphone, mobile} from "./environment";
import {isComplete} from "./validation";
import {EventHandlers} from "./eventhandlers";
import { iphone, mobile } from "./environment";
import { EventHandlers } from "./eventhandlers";
import { EventRuler } from "./eventruler";
import {
applyInputValue,
clearOptionalTail,
writeBuffer
} from "./inputHandling";
import {
caret,
getBuffer,
getBufferTemplate,
getLastValidPosition,
resetMaskSet,
seekNext
} from "./positioning";
import { isComplete } from "./validation";
export {mask};
export { mask };
//todo put on the prototype?
// todo put on the prototype?
function mask() {
const inputmask = this,
opts = this.opts,
el = this.el, $ = this.dependencyLib;
const inputmask = this,
opts = this.opts,
el = this.el,
$ = this.dependencyLib;
function isElementTypeSupported(input, opts) {
function patchValueProperty(npt) {
let valueGet, valueSet;
function isElementTypeSupported(input, opts) {
function patchValueProperty(npt) {
var valueGet;
var valueSet;
function patchValhook(type) {
if (
$.valHooks &&
($.valHooks[type] === undefined ||
$.valHooks[type].inputmaskpatch !== true)
) {
const valhookGet =
$.valHooks[type] && $.valHooks[type].get
? $.valHooks[type].get
: function (elem) {
return elem.value;
},
valhookSet =
$.valHooks[type] && $.valHooks[type].set
? $.valHooks[type].set
: function (elem, value) {
elem.value = value;
return elem;
};
function patchValhook(type) {
if ($.valHooks && ($.valHooks[type] === undefined || $.valHooks[type].inputmaskpatch !== true)) {
var valhookGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function (elem) {
return elem.value;
};
var valhookSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function (elem, value) {
elem.value = value;
return elem;
};
$.valHooks[type] = {
get: function (elem) {
if (elem.inputmask) {
if (elem.inputmask.opts.autoUnmask) {
return elem.inputmask.unmaskedvalue();
} else {
var result = valhookGet(elem);
return getLastValidPosition.call(inputmask, undefined, undefined, elem.inputmask.maskset.validPositions) !== -1 || opts.nullable !== true ? result : "";
}
} else {
return valhookGet(elem);
}
},
set: function (elem, value) {
var result = valhookSet(elem, value);
if (elem.inputmask) {
applyInputValue(elem, value);
}
return result;
},
inputmaskpatch: true
};
}
}
function getter() {
if (this.inputmask) {
return this.inputmask.opts.autoUnmask ?
this.inputmask.unmaskedvalue() :
(getLastValidPosition.call(inputmask) !== -1 || opts.nullable !== true ?
(((this.inputmask.shadowRoot || this.ownerDocument).activeElement) === this && opts.clearMaskOnLostFocus ?
(inputmask.isRTL ? clearOptionalTail.call(inputmask, getBuffer.call(inputmask).slice()).reverse() : clearOptionalTail.call(inputmask, getBuffer.call(inputmask).slice())).join("") :
valueGet.call(this)) :
"");
$.valHooks[type] = {
get: function (elem) {
if (elem.inputmask) {
if (elem.inputmask.opts.autoUnmask) {
return elem.inputmask.unmaskedvalue();
} else {
return valueGet.call(this);
const result = valhookGet(elem);
return getLastValidPosition.call(
inputmask,
undefined,
undefined,
elem.inputmask.maskset.validPositions
) !== -1 || opts.nullable !== true
? result
: "";
}
}
function setter(value) {
valueSet.call(this, value);
if (this.inputmask) {
applyInputValue(this, value);
}
}
function installNativeValueSetFallback(npt) {
EventRuler.on(npt, "mouseenter", function () {
let input = this,
value = input.inputmask._valueGet(true),
bufferValue = (input.inputmask.isRTL ? getBuffer.call(input.inputmask).slice().reverse() : getBuffer.call(input.inputmask)).join("");
if (value != bufferValue) {
applyInputValue(input, value);
}
});
}
if (!npt.inputmask.__valueGet) {
if (opts.noValuePatching !== true) {
if (Object.getOwnPropertyDescriptor) {
var valueProperty = Object.getPrototypeOf ? Object.getOwnPropertyDescriptor(Object.getPrototypeOf(npt), "value") : undefined;
if (valueProperty && valueProperty.get && valueProperty.set) {
valueGet = valueProperty.get;
valueSet = valueProperty.set;
Object.defineProperty(npt, "value", {
get: getter,
set: setter,
configurable: true
});
} else if (npt.tagName.toLowerCase() !== "input") {
valueGet = function () {
return this.textContent;
};
valueSet = function (value) {
this.textContent = value;
};
Object.defineProperty(npt, "value", {
get: getter,
set: setter,
configurable: true
});
}
} else if (document.__lookupGetter__ && npt.__lookupGetter__("value")) {
valueGet = npt.__lookupGetter__("value");
valueSet = npt.__lookupSetter__("value");
npt.__defineGetter__("value", getter);
npt.__defineSetter__("value", setter);
}
npt.inputmask.__valueGet = valueGet; //store native property getter
npt.inputmask.__valueSet = valueSet; //store native property setter
}
npt.inputmask._valueGet = function (overruleRTL) {
return inputmask.isRTL && overruleRTL !== true ? valueGet.call(this.el).split("").reverse().join("") : valueGet.call(this.el);
};
npt.inputmask._valueSet = function (value, overruleRTL) { //null check is needed for IE8 => otherwise converts to "null"
valueSet.call(this.el, (value === null || value === undefined) ? "" : ((overruleRTL !== true && inputmask.isRTL) ? value.split("").reverse().join("") : value));
};
if (valueGet === undefined) { //jquery.val fallback
valueGet = function () {
return this.value;
};
valueSet = function (value) {
this.value = value;
};
patchValhook(npt.type);
installNativeValueSetFallback(npt);
}
}
} else {
return valhookGet(elem);
}
},
set: function (elem, value) {
const result = valhookSet(elem, value);
if (elem.inputmask) {
applyInputValue(elem, value);
}
return result;
},
inputmaskpatch: true
};
}
}
if (input.tagName.toLowerCase() !== "textarea") {
opts.ignorables.push(keys.Enter);
}
var elementType = input.getAttribute("type");
var isSupported = (input.tagName.toLowerCase() === "input" && opts.supportsInputType.includes(elementType)) || input.isContentEditable || input.tagName.toLowerCase() === "textarea";
if (!isSupported) {
if (input.tagName.toLowerCase() === "input") {
var el = document.createElement("input");
el.setAttribute("type", elementType);
isSupported = el.type === "text"; //apply mask only if the type is not natively supported
el = null;
} else {
isSupported = "partial";
}
}
if (isSupported !== false) {
patchValueProperty(input);
function getter() {
if (this.inputmask) {
return this.inputmask.opts.autoUnmask
? this.inputmask.unmaskedvalue()
: getLastValidPosition.call(inputmask) !== -1 ||
opts.nullable !== true
? (this.inputmask.shadowRoot || this.ownerDocument)
.activeElement === this && opts.clearMaskOnLostFocus
? (inputmask.isRTL
? clearOptionalTail
.call(inputmask, getBuffer.call(inputmask).slice())
.reverse()
: clearOptionalTail.call(
inputmask,
getBuffer.call(inputmask).slice()
)
).join("")
: valueGet.call(this)
: "";
} else {
input.inputmask = undefined;
return valueGet.call(this);
}
return isSupported;
}
function setter(value) {
valueSet.call(this, value);
if (this.inputmask) {
applyInputValue(this, value);
}
}
function installNativeValueSetFallback(npt) {
EventRuler.on(npt, "mouseenter", function () {
const input = this,
value = input.inputmask._valueGet(true),
bufferValue = (
input.inputmask.isRTL
? getBuffer.call(input.inputmask).slice().reverse()
: getBuffer.call(input.inputmask)
).join("");
if (value != bufferValue) {
applyInputValue(input, value);
}
});
}
if (!npt.inputmask.__valueGet) {
if (opts.noValuePatching !== true) {
if (Object.getOwnPropertyDescriptor) {
const valueProperty = Object.getPrototypeOf
? Object.getOwnPropertyDescriptor(
Object.getPrototypeOf(npt),
"value"
)
: undefined;
if (valueProperty && valueProperty.get && valueProperty.set) {
valueGet = valueProperty.get;
valueSet = valueProperty.set;
Object.defineProperty(npt, "value", {
get: getter,
set: setter,
configurable: true
});
} else if (npt.tagName.toLowerCase() !== "input") {
valueGet = function () {
return this.textContent;
};
valueSet = function (value) {
this.textContent = value;
};
Object.defineProperty(npt, "value", {
get: getter,
set: setter,
configurable: true
});
}
} else if (
document.__lookupGetter__ &&
npt.__lookupGetter__("value")
) {
valueGet = npt.__lookupGetter__("value");
valueSet = npt.__lookupSetter__("value");
npt.__defineGetter__("value", getter);
npt.__defineSetter__("value", setter);
}
npt.inputmask.__valueGet = valueGet; // store native property getter
npt.inputmask.__valueSet = valueSet; // store native property setter
}
npt.inputmask._valueGet = function (overruleRTL) {
return inputmask.isRTL && overruleRTL !== true
? valueGet.call(this.el).split("").reverse().join("")
: valueGet.call(this.el);
};
npt.inputmask._valueSet = function (value, overruleRTL) {
// null check is needed for IE8 => otherwise converts to "null"
valueSet.call(
this.el,
value === null || value === undefined
? ""
: overruleRTL !== true && inputmask.isRTL
? value.split("").reverse().join("")
: value
);
};
if (valueGet === undefined) {
// jquery.val fallback
valueGet = function () {
return this.value;
};
valueSet = function (value) {
this.value = value;
};
patchValhook(npt.type);
installNativeValueSetFallback(npt);
}
}
}
//unbind all events - to make sure that no other mask will interfere when re-masking
EventRuler.off(el);
var isSupported = isElementTypeSupported(el, opts);
// if (input.tagName.toLowerCase() !== "textarea") {
// opts.ignorables.push(keys.Enter);
// }
let elementType = input.getAttribute("type"),
isSupported =
(input.tagName.toLowerCase() === "input" &&
opts.supportsInputType.includes(elementType)) ||
input.isContentEditable ||
input.tagName.toLowerCase() === "textarea";
if (!isSupported) {
if (input.tagName.toLowerCase() === "input") {
let el = document.createElement("input");
el.setAttribute("type", elementType);
isSupported = el.type === "text"; // apply mask only if the type is not natively supported
el = null;
} else {
isSupported = "partial";
}
}
if (isSupported !== false) {
inputmask.originalPlaceholder = el.placeholder;
//read maxlength prop from el
inputmask.maxLength = el !== undefined ? el.maxLength : undefined;
if (inputmask.maxLength === -1) inputmask.maxLength = undefined;
if ("inputMode" in el && el.getAttribute("inputmode") === null) {
el.inputMode = opts.inputmode;
el.setAttribute("inputmode", opts.inputmode);
}
if (isSupported === true) {
opts.showMaskOnFocus = opts.showMaskOnFocus && ["cc-number", "cc-exp"].indexOf(el.autocomplete) === -1;
if (iphone) {
//selecting the caret shows as a selection on iphone
opts.insertModeVisual = false;
//disable autocorrect
el.setAttribute("autocorrect", "off");
}
//bind events
EventRuler.on(el, "submit", EventHandlers.submitEvent);
EventRuler.on(el, "reset", EventHandlers.resetEvent);
EventRuler.on(el, "blur", EventHandlers.blurEvent);
EventRuler.on(el, "focus", EventHandlers.focusEvent);
EventRuler.on(el, "invalid", EventHandlers.invalidEvent);
EventRuler.on(el, "click", EventHandlers.clickEvent);
EventRuler.on(el, "mouseleave", EventHandlers.mouseleaveEvent);
EventRuler.on(el, "mouseenter", EventHandlers.mouseenterEvent);
EventRuler.on(el, "paste", EventHandlers.pasteEvent);
EventRuler.on(el, "cut", EventHandlers.cutEvent);
EventRuler.on(el, "complete", opts.oncomplete);
EventRuler.on(el, "incomplete", opts.onincomplete);
EventRuler.on(el, "cleared", opts.oncleared);
if (opts.inputEventOnly !== true) {
EventRuler.on(el, "keydown", EventHandlers.keyEvent);
}
if (mobile || opts.inputEventOnly) {
el.removeAttribute("maxLength");
}
EventRuler.on(el, "input", EventHandlers.inputFallBackEvent);
// EventRuler.on(el, "beforeinput", EventHandlers.beforeInputEvent); //https://github.com/w3c/input-events - to implement
}
EventRuler.on(el, "setvalue", EventHandlers.setValueEvent);
//apply mask
getBufferTemplate.call(inputmask).join(""); //initialize the buffer and getmasklength
inputmask.undoValue = inputmask._valueGet(true);
var activeElement = (el.inputmask.shadowRoot || el.ownerDocument).activeElement;
if (el.inputmask._valueGet(true) !== "" || opts.clearMaskOnLostFocus === false || activeElement === el) {
applyInputValue(el, el.inputmask._valueGet(true), opts);
var buffer = getBuffer.call(inputmask).slice();
if (isComplete.call(inputmask, buffer) === false) {
if (opts.clearIncomplete) {
resetMaskSet.call(inputmask);
}
}
if (opts.clearMaskOnLostFocus && activeElement !== el) {
if (getLastValidPosition.call(inputmask) === -1) {
buffer = [];
} else {
clearOptionalTail.call(inputmask, buffer);
}
}
if (opts.clearMaskOnLostFocus === false || (opts.showMaskOnFocus && activeElement === el) || el.inputmask._valueGet(true) !== "") {
writeBuffer(el, buffer);
}
if (activeElement === el) { //position the caret when in focus
caret.call(inputmask, el, seekNext.call(inputmask, getLastValidPosition.call(inputmask)));
}
}
patchValueProperty(input);
} else {
input.inputmask = undefined;
}
return isSupported;
}
// unbind all events - to make sure that no other mask will interfere when re-masking
EventRuler.off(el);
const isSupported = isElementTypeSupported(el, opts);
if (isSupported !== false) {
inputmask.originalPlaceholder = el.placeholder;
// read maxlength prop from el
inputmask.maxLength = el !== undefined ? el.maxLength : undefined;
if (inputmask.maxLength === -1) inputmask.maxLength = undefined;
if ("inputMode" in el && el.getAttribute("inputmode") === null) {
el.inputMode = opts.inputmode;
el.setAttribute("inputmode", opts.inputmode);
}
if (isSupported === true) {
opts.showMaskOnFocus =
opts.showMaskOnFocus &&
["cc-number", "cc-exp"].indexOf(el.autocomplete) === -1;
if (iphone) {
// selecting the caret shows as a selection on iphone
opts.insertModeVisual = false;
// disable autocorrect
el.setAttribute("autocorrect", "off");
}
// bind events
EventRuler.on(el, "submit", EventHandlers.submitEvent);
EventRuler.on(el, "reset", EventHandlers.resetEvent);
EventRuler.on(el, "blur", EventHandlers.blurEvent);
EventRuler.on(el, "focus", EventHandlers.focusEvent);
EventRuler.on(el, "invalid", EventHandlers.invalidEvent);
EventRuler.on(el, "click", EventHandlers.clickEvent);
EventRuler.on(el, "mouseleave", EventHandlers.mouseleaveEvent);
EventRuler.on(el, "mouseenter", EventHandlers.mouseenterEvent);
EventRuler.on(el, "paste", EventHandlers.pasteEvent);
EventRuler.on(el, "cut", EventHandlers.cutEvent);
EventRuler.on(el, "complete", opts.oncomplete);
EventRuler.on(el, "incomplete", opts.onincomplete);
EventRuler.on(el, "cleared", opts.oncleared);
if (opts.inputEventOnly !== true) {
EventRuler.on(el, "keydown", EventHandlers.keyEvent);
}
if (mobile || opts.inputEventOnly) {
el.removeAttribute("maxLength");
}
EventRuler.on(el, "input", EventHandlers.inputFallBackEvent);
// EventRuler.on(el, "beforeinput", EventHandlers.beforeInputEvent); //https://github.com/w3c/input-events - to implement
}
EventRuler.on(el, "setvalue", EventHandlers.setValueEvent);
// apply mask
inputmask.applyMaskHook === undefined || inputmask.applyMaskHook();
getBufferTemplate.call(inputmask).join(""); // initialize the buffer and getmasklength
inputmask.undoValue = inputmask._valueGet(true);
const activeElement = (el.inputmask.shadowRoot || el.ownerDocument)
.activeElement;
if (
el.inputmask._valueGet(true) !== "" ||
opts.clearMaskOnLostFocus === false ||
activeElement === el
) {
applyInputValue(el, el.inputmask._valueGet(true), opts);
let buffer = getBuffer.call(inputmask).slice();
if (isComplete.call(inputmask, buffer) === false) {
if (opts.clearIncomplete) {
resetMaskSet.call(inputmask, false);
}
}
if (opts.clearMaskOnLostFocus && activeElement !== el) {
if (getLastValidPosition.call(inputmask) === -1) {
buffer = [];
} else {
clearOptionalTail.call(inputmask, buffer);
}
}
if (
opts.clearMaskOnLostFocus === false ||
(opts.showMaskOnFocus && activeElement === el) ||
el.inputmask._valueGet(true) !== ""
) {
writeBuffer(el, buffer);
}
if (activeElement === el) {
// position the caret when in focus
caret.call(
inputmask,
el,
seekNext.call(inputmask, getLastValidPosition.call(inputmask))
);
}
}
}
}

View file

@ -1,13 +1,13 @@
export default function (isGroup, isOptional, isQuantifier, isAlternator) {
this.matches = [];
this.openGroup = isGroup || false;
this.alternatorGroup = false;
this.isGroup = isGroup || false;
this.isOptional = isOptional || false;
this.isQuantifier = isQuantifier || false;
this.isAlternator = isAlternator || false;
this.quantifier = {
min: 1,
max: 1
};
}
this.matches = [];
this.openGroup = isGroup || false;
this.alternatorGroup = false;
this.isGroup = isGroup || false;
this.isOptional = isOptional || false;
this.isQuantifier = isQuantifier || false;
this.isAlternator = isAlternator || false;
this.quantifier = {
min: 1,
max: 1
};
}

View file

@ -1,48 +1,46 @@
// https://tc39.github.io/ecma262/#sec-array.prototype.includes
if (!Array.prototype.includes) {
Object.defineProperty(Array.prototype, "includes", {
value: function(searchElement, fromIndex) {
// eslint-disable-next-line no-extend-native
Object.defineProperty(Array.prototype, "includes", {
value: function (searchElement, fromIndex) {
// 1. Let O be ? ToObject(this value).
if (this == null) {
throw new TypeError('"this" is null or not defined');
}
// 1. Let O be ? ToObject(this value).
if (this == null) {
throw new TypeError("\"this\" is null or not defined");
}
const o = Object(this),
// 2. Let len be ? ToLength(? Get(O, "length")).
len = o.length >>> 0;
var o = Object(this);
// 3. If len is 0, return false.
if (len === 0) {
return false;
}
// 2. Let len be ? ToLength(? Get(O, "length")).
var len = o.length >>> 0;
// 4. Let n be ? ToInteger(fromIndex).
// (If fromIndex is undefined, this step produces the value 0.)
let n = fromIndex | 0,
// 5. If n ≥ 0, then
// a. Let k be n.
// 6. Else n < 0,
// a. Let k be len + n.
// b. If k < 0, let k be 0.
k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
// 3. If len is 0, return false.
if (len === 0) {
return false;
}
// 7. Repeat, while k < len
while (k < len) {
// a. Let elementK be the result of ? Get(O, ! ToString(k)).
// b. If SameValueZero(searchElement, elementK) is true, return true.
// c. Increase k by 1.
// NOTE: === provides the correct "SameValueZero" comparison needed here.
if (o[k] === searchElement) {
return true;
}
k++;
}
// 4. Let n be ? ToInteger(fromIndex).
// (If fromIndex is undefined, this step produces the value 0.)
var n = fromIndex | 0;
// 5. If n ≥ 0, then
// a. Let k be n.
// 6. Else n < 0,
// a. Let k be len + n.
// b. If k < 0, let k be 0.
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
// 7. Repeat, while k < len
while (k < len) {
// a. Let elementK be the result of ? Get(O, ! ToString(k)).
// b. If SameValueZero(searchElement, elementK) is true, return true.
// c. Increase k by 1.
// NOTE: === provides the correct "SameValueZero" comparison needed here.
if (o[k] === searchElement) {
return true;
}
k++;
}
// 8. Return false
return false;
}
});
}
// 8. Return false
return false;
}
});
}

View file

@ -1,10 +1,21 @@
const reduce = Function.bind.call(Function.call, Array.prototype.reduce);
const isEnumerable = Function.bind.call(Function.call, Object.prototype.propertyIsEnumerable);
const concat = Function.bind.call(Function.call, Array.prototype.concat);
const keys = Object.keys;
const reduce = Function.bind.call(Function.call, Array.prototype.reduce),
isEnumerable = Function.bind.call(
Function.call,
Object.prototype.propertyIsEnumerable
),
concat = Function.bind.call(Function.call, Array.prototype.concat),
keys = Object.keys;
if (!Object.entries) {
Object.entries = function entries(O) {
return reduce(keys(O), (e, k) => concat(e, typeof k === 'string' && isEnumerable(O, k) ? [[k, O[k]]] : []), []);
};
}
Object.entries = function entries(O) {
return reduce(
keys(O),
(e, k) =>
concat(
e,
typeof k === "string" && isEnumerable(O, k) ? [[k, O[k]]] : []
),
[]
);
};
}

View file

@ -1,7 +1,10 @@
if (typeof Object.getPrototypeOf !== "function") {
Object.getPrototypeOf = typeof "test".__proto__ === "object" ? function (object) {
return object.__proto__;
} : function (object) {
return object.constructor.prototype;
};
}
Object.getPrototypeOf =
typeof "test".__proto__ === "object"
? function (object) {
return object.__proto__;
}
: function (object) {
return object.constructor.prototype;
};
}

View file

@ -1,13 +1,14 @@
if (!String.prototype.includes) {
String.prototype.includes = function(search, start) {
if (typeof start !== 'number') {
start = 0;
}
// eslint-disable-next-line no-extend-native
String.prototype.includes = function (search, start) {
if (typeof start !== "number") {
start = 0;
}
if (start + search.length > this.length) {
return false;
} else {
return this.indexOf(search, start) !== -1;
}
};
}
if (start + search.length > this.length) {
return false;
} else {
return this.indexOf(search, start) !== -1;
}
};
}

View file

@ -1,346 +1,486 @@
import window from "./global/window";
import { checkAlternationMatch } from "./validation";
import {
determineTestTemplate,
getMaskTemplate,
getPlaceholder,
getTest,
getTests,
getTestTemplate
determineTestTemplate,
getMaskTemplate,
getPlaceholder,
getTest,
getTests,
getTestTemplate
} from "./validation-tests";
import {checkAlternationMatch} from "./validation";
export {
caret,
determineLastRequiredPosition,
determineNewCaretPosition,
getBuffer,
getBufferTemplate,
getLastValidPosition,
isMask,
resetMaskSet,
seekNext,
seekPrevious,
translatePosition
caret,
determineLastRequiredPosition,
determineNewCaretPosition,
getBuffer,
getBufferTemplate,
getLastValidPosition,
isMask,
resetMaskSet,
seekNext,
seekPrevious,
translatePosition
};
//tobe put on prototype?
// tobe put on prototype?
function caret(input, begin, end, notranslate, isDelete) {
const inputmask = this,
opts = this.opts;
const inputmask = this,
opts = this.opts;
var range;
if (begin !== undefined) {
if (Array.isArray(begin)) {
end = inputmask.isRTL ? begin[0] : begin[1];
begin = inputmask.isRTL ? begin[1] : begin[0];
}
if (begin.begin !== undefined) {
end = inputmask.isRTL ? begin.begin : begin.end;
begin = inputmask.isRTL ? begin.end : begin.begin;
}
if (typeof begin === "number") {
begin = notranslate ? begin : translatePosition.call(inputmask, begin);
end = notranslate ? end : translatePosition.call(inputmask, end);
end = (typeof end == "number") ? end : begin;
// if (!$(input).is(":visible")) {
// return;
// }
let range;
if (begin !== undefined) {
if (Array.isArray(begin)) {
end = inputmask.isRTL ? begin[0] : begin[1];
begin = inputmask.isRTL ? begin[1] : begin[0];
}
if (begin.begin !== undefined) {
end = inputmask.isRTL ? begin.begin : begin.end;
begin = inputmask.isRTL ? begin.end : begin.begin;
}
if (typeof begin === "number") {
begin = notranslate ? begin : translatePosition.call(inputmask, begin);
end = notranslate ? end : translatePosition.call(inputmask, end);
end = typeof end === "number" ? end : begin;
// if (!$(input).is(":visible")) {
// return;
// }
var scrollCalc = parseInt(((input.ownerDocument.defaultView || window).getComputedStyle ? (input.ownerDocument.defaultView || window).getComputedStyle(input, null) : input.currentStyle).fontSize) * end;
input.scrollLeft = scrollCalc > input.scrollWidth ? scrollCalc : 0;
input.inputmask.caretPos = {begin: begin, end: end}; //track caret internally
if (opts.insertModeVisual && opts.insertMode === false && begin === end) {
if (!isDelete) {
end++; //set visualization for insert/overwrite mode
}
}
if (input === (input.inputmask.shadowRoot || input.ownerDocument).activeElement) {
if ("setSelectionRange" in input) {
input.setSelectionRange(begin, end);
} else if (window.getSelection) {
range = document.createRange();
if (input.firstChild === undefined || input.firstChild === null) {
var textNode = document.createTextNode("");
input.appendChild(textNode);
}
range.setStart(input.firstChild, begin < input.inputmask._valueGet().length ? begin : input.inputmask._valueGet().length);
range.setEnd(input.firstChild, end < input.inputmask._valueGet().length ? end : input.inputmask._valueGet().length);
range.collapse(true);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
//input.focus();
} else if (input.createTextRange) {
range = input.createTextRange();
range.collapse(true);
range.moveEnd("character", end);
range.moveStart("character", begin);
range.select();
}
}
const scrollCalc =
parseInt(
((input.ownerDocument.defaultView || window).getComputedStyle
? (input.ownerDocument.defaultView || window).getComputedStyle(
input,
null
)
: input.currentStyle
).fontSize
) * end;
input.scrollLeft = scrollCalc > input.scrollWidth ? scrollCalc : 0;
input.inputmask.caretPos = { begin, end }; // track caret internally
if (opts.insertModeVisual && opts.insertMode === false && begin === end) {
if (!isDelete) {
end++; // set visualization for insert/overwrite mode
}
} else {
if ("selectionStart" in input && "selectionEnd" in input) {
begin = input.selectionStart;
end = input.selectionEnd;
}
if (
input ===
(input.inputmask.shadowRoot || input.ownerDocument).activeElement
) {
if ("setSelectionRange" in input) {
input.setSelectionRange(begin, end);
} else if (window.getSelection) {
range = window.getSelection().getRangeAt(0);
if (range.commonAncestorContainer.parentNode === input || range.commonAncestorContainer === input) {
begin = range.startOffset;
end = range.endOffset;
}
} else if (document.selection && document.selection.createRange) {
range = document.selection.createRange();
begin = 0 - range.duplicate().moveStart("character", -input.inputmask._valueGet().length);
end = begin + range.text.length;
range = document.createRange();
if (input.firstChild === undefined || input.firstChild === null) {
const textNode = document.createTextNode("");
input.appendChild(textNode);
}
range.setStart(
input.firstChild,
begin < input.inputmask._valueGet().length
? begin
: input.inputmask._valueGet().length
);
range.setEnd(
input.firstChild,
end < input.inputmask._valueGet().length
? end
: input.inputmask._valueGet().length
);
range.collapse(true);
const sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
// input.focus();
} else if (input.createTextRange) {
range = input.createTextRange();
range.collapse(true);
range.moveEnd("character", end);
range.moveStart("character", begin);
range.select();
}
// if (opts.insertModeVisual && opts.insertMode === false && begin === (end - 1)) end--; //correct caret for insert/overwrite mode
/*eslint-disable consistent-return */
return {
"begin": notranslate ? begin : translatePosition.call(inputmask, begin),
"end": notranslate ? end : translatePosition.call(inputmask, end)
};
/*eslint-enable consistent-return */
input.inputmask.caretHook === undefined ||
input.inputmask.caretHook.call(inputmask, { begin, end });
}
}
} else {
if ("selectionStart" in input && "selectionEnd" in input) {
begin = input.selectionStart;
end = input.selectionEnd;
} else if (window.getSelection) {
range = window.getSelection().getRangeAt(0);
if (
range.commonAncestorContainer.parentNode === input ||
range.commonAncestorContainer === input
) {
begin = range.startOffset;
end = range.endOffset;
}
} else if (document.selection && document.selection.createRange) {
range = document.selection.createRange();
begin =
0 -
range
.duplicate()
.moveStart("character", -input.inputmask._valueGet().length);
end = begin + range.text.length;
}
// if (opts.insertModeVisual && opts.insertMode === false && begin === (end - 1)) end--; //correct caret for insert/overwrite mode
/* eslint-disable consistent-return */
return {
begin: notranslate ? begin : translatePosition.call(inputmask, begin),
end: notranslate ? end : translatePosition.call(inputmask, end)
};
/* eslint-enable consistent-return */
}
}
//tobe put on prototype?
// tobe put on prototype?
function determineLastRequiredPosition(returnDefinition) {
const inputmask = this, {maskset, dependencyLib: $} = inputmask;
const inputmask = this,
{ maskset, dependencyLib: $ } = inputmask,
lvp = getLastValidPosition.call(inputmask),
positions = {},
lvTest = maskset.validPositions[lvp],
buffer = getMaskTemplate.call(
inputmask,
true,
getLastValidPosition.call(inputmask),
true,
true
);
let bl = buffer.length,
pos,
ndxIntlzr = lvTest !== undefined ? lvTest.locator.slice() : undefined,
testPos;
for (pos = lvp + 1; pos < buffer.length; pos++) {
testPos = getTestTemplate.call(inputmask, pos, ndxIntlzr, pos - 1);
ndxIntlzr = testPos.locator.slice();
positions[pos] = $.extend(true, {}, testPos);
}
var buffer = getMaskTemplate.call(inputmask, true, getLastValidPosition.call(inputmask), true, true),
bl = buffer.length,
pos, lvp = getLastValidPosition.call(inputmask),
positions = {},
lvTest = maskset.validPositions[lvp],
ndxIntlzr = lvTest !== undefined ? lvTest.locator.slice() : undefined,
testPos;
for (pos = lvp + 1; pos < buffer.length; pos++) {
testPos = getTestTemplate.call(inputmask, pos, ndxIntlzr, pos - 1);
ndxIntlzr = testPos.locator.slice();
positions[pos] = $.extend(true, {}, testPos);
const lvTestAlt =
lvTest && lvTest.alternation !== undefined
? lvTest.locator[lvTest.alternation]
: undefined;
for (pos = bl - 1; pos > lvp; pos--) {
testPos = positions[pos];
if (
(testPos.match.optionality ||
(testPos.match.optionalQuantifier && testPos.match.newBlockMarker) ||
(lvTestAlt &&
((lvTestAlt !== positions[pos].locator[lvTest.alternation] &&
testPos.match.static !== true) ||
(testPos.match.static === true &&
testPos.locator[lvTest.alternation] &&
checkAlternationMatch.call(
inputmask,
testPos.locator[lvTest.alternation].toString().split(","),
lvTestAlt.toString().split(",")
) &&
getTests.call(inputmask, pos)[0].def !== "")))) &&
buffer[pos] === getPlaceholder.call(inputmask, pos, testPos.match)
) {
bl--;
} else {
break;
}
var lvTestAlt = lvTest && lvTest.alternation !== undefined ? lvTest.locator[lvTest.alternation] : undefined;
for (pos = bl - 1; pos > lvp; pos--) {
testPos = positions[pos];
if ((testPos.match.optionality ||
(testPos.match.optionalQuantifier && testPos.match.newBlockMarker) ||
(lvTestAlt &&
(
(lvTestAlt !== positions[pos].locator[lvTest.alternation] && testPos.match.static != true) ||
(testPos.match.static === true &&
testPos.locator[lvTest.alternation] &&
checkAlternationMatch.call(inputmask, testPos.locator[lvTest.alternation].toString().split(","), lvTestAlt.toString().split(",")) &&
getTests.call(inputmask, pos)[0].def !== "")
)
)) &&
buffer[pos] === getPlaceholder.call(inputmask, pos, testPos.match)) {
bl--;
} else {
break;
}
}
return returnDefinition ? {
"l": bl,
"def": positions[bl] ? positions[bl].match : undefined
} : bl;
}
return returnDefinition
? {
l: bl,
def: positions[bl] ? positions[bl].match : undefined
}
: bl;
}
//tobe put on prototype?
function determineNewCaretPosition(selectedCaret, tabbed, positionCaretOnClick) {
const inputmask = this, {maskset, opts} = inputmask;
// tobe put on prototype?
function determineNewCaretPosition(
selectedCaret,
tabbed,
positionCaretOnClick
) {
const inputmask = this,
{ maskset, opts } = inputmask;
let clickPosition, lvclickPosition, lastPosition;
function doRadixFocus(clickPos) {
if (opts.radixPoint !== "" && opts.digits !== 0) {
var vps = maskset.validPositions;
if (vps[clickPos] === undefined || (vps[clickPos].input === getPlaceholder.call(inputmask, clickPos))) {
if (clickPos < seekNext.call(inputmask, -1)) return true;
var radixPos = getBuffer.call(inputmask).indexOf(opts.radixPoint);
if (radixPos !== -1) {
for (let vp = 0, vpl = vps.length; vp < vpl; vp++) {
if (vps[vp] && radixPos < vp && vps[vp].input !== getPlaceholder.call(inputmask, vp)) {
return false;
}
}
return true;
}
function doRadixFocus(clickPos) {
if (opts.radixPoint !== "" && opts.digits !== 0) {
const vps = maskset.validPositions;
if (vps[clickPos] === undefined || vps[clickPos].input === undefined) {
if (clickPos < seekNext.call(inputmask, -1)) return true;
const radixPos = getBuffer.call(inputmask).indexOf(opts.radixPoint);
if (radixPos !== -1) {
for (let vp = 0, vpl = vps.length; vp < vpl; vp++) {
if (
vps[vp] &&
radixPos < vp &&
vps[vp].input !== getPlaceholder.call(inputmask, vp)
) {
return false;
}
}
return true;
}
return false;
}
if (tabbed) {
if (inputmask.isRTL) {
selectedCaret.end = selectedCaret.begin;
} else {
selectedCaret.begin = selectedCaret.end;
}
}
if (selectedCaret.begin === selectedCaret.end) {
positionCaretOnClick = positionCaretOnClick || opts.positionCaretOnClick;
switch (positionCaretOnClick) {
case "none":
break;
case "select":
selectedCaret = {begin: 0, end: getBuffer.call(inputmask).length};
break;
case "ignore":
selectedCaret.end = selectedCaret.begin = seekNext.call(inputmask, getLastValidPosition.call(inputmask));
break;
case "radixFocus":
if (inputmask.clicked > 1 && maskset.validPositions.length == 0)
break;
if (doRadixFocus(selectedCaret.begin)) {
var radixPos = getBuffer.call(inputmask).join("").indexOf(opts.radixPoint);
selectedCaret.end = selectedCaret.begin = opts.numericInput ? seekNext.call(inputmask, radixPos) : radixPos;
break;
} //fallback to lvp
// eslint-disable-next-line no-fallthrough
default: //lvp:
var clickPosition = selectedCaret.begin,
lvclickPosition = getLastValidPosition.call(inputmask, clickPosition, true),
lastPosition = seekNext.call(inputmask, (lvclickPosition === -1 && !isMask.call(inputmask, 0)) ? -1 : lvclickPosition);
if (clickPosition <= lastPosition) {
selectedCaret.end = selectedCaret.begin = !isMask.call(inputmask, clickPosition, false, true) ? seekNext.call(inputmask, clickPosition) : clickPosition;
} else {
var lvp = maskset.validPositions[lvclickPosition],
tt = getTestTemplate.call(inputmask, lastPosition, lvp ? lvp.match.locator : undefined, lvp),
placeholder = getPlaceholder.call(inputmask, lastPosition, tt.match);
if ((placeholder !== "" && getBuffer.call(inputmask)[lastPosition] !== placeholder && tt.match.optionalQuantifier !== true && tt.match.newBlockMarker !== true) || (!isMask.call(inputmask, lastPosition, opts.keepStatic, true) && tt.match.def === placeholder)) {
var newPos = seekNext.call(inputmask, lastPosition);
if (clickPosition >= newPos || clickPosition === lastPosition) {
lastPosition = newPos;
}
}
selectedCaret.end = selectedCaret.begin = lastPosition;
}
}
return selectedCaret;
}
}
//tobe put on prototype?
function getBuffer(noCache) {
const inputmask = this, {maskset} = inputmask;
if (maskset.buffer === undefined || noCache === true) {
maskset.buffer = getMaskTemplate.call(inputmask, true, getLastValidPosition.call(inputmask), true);
if (maskset._buffer === undefined) maskset._buffer = maskset.buffer.slice();
}
return maskset.buffer;
}
//tobe put on prototype?
function getBufferTemplate() {
const inputmask = this, maskset = this.maskset;
if (maskset._buffer === undefined) {
//generate template
maskset._buffer = getMaskTemplate.call(inputmask, false, 1);
if (maskset.buffer === undefined) maskset.buffer = maskset._buffer.slice();
}
return maskset._buffer;
}
//tobe put on prototype?
function getLastValidPosition(closestTo, strict, validPositions) {
const maskset = this.maskset;
var before = -1,
after = -1,
valids = validPositions || maskset.validPositions; //for use in valhook ~ context switch
if (closestTo === undefined) closestTo = -1;
for (var psNdx = 0, vpl = valids.length; psNdx < vpl; psNdx++) {
if (valids[psNdx] && (strict || valids[psNdx].generatedInput !== true)) {
if (psNdx <= closestTo) before = psNdx;
if (psNdx >= closestTo) after = psNdx;
}
}
return (before === -1 || before == closestTo) ? after : after == -1 ? before : (closestTo - before) < (after - closestTo) ? before : after;
}
//tobe put on prototype?
function isMask(pos, strict, fuzzy) {
const inputmask = this, maskset = this.maskset;
var test = getTestTemplate.call(inputmask, pos).match;
if (test.def === "") test = getTest.call(inputmask, pos).match;
if (test.static !== true) {
return test.fn;
}
if (fuzzy === true && (maskset.validPositions[pos] !== undefined && maskset.validPositions[pos].generatedInput !== true)) {
return true;
}
if (strict !== true && pos > -1) {
if (fuzzy) { //check on the number of tests
var tests = getTests.call(inputmask, pos);
return tests.length > (1 + (tests[tests.length - 1].match.def === "" ? 1 : 0));
}
//else based on the template
var testTemplate = determineTestTemplate.call(inputmask, pos, getTests.call(inputmask, pos));
var testPlaceHolder = getPlaceholder.call(inputmask, pos, testTemplate.match);
return testTemplate.match.def !== testPlaceHolder;
}
}
return false;
}
if (tabbed) {
if (inputmask.isRTL) {
selectedCaret.end = selectedCaret.begin;
} else {
selectedCaret.begin = selectedCaret.end;
}
}
if (selectedCaret.begin === selectedCaret.end) {
positionCaretOnClick = positionCaretOnClick || opts.positionCaretOnClick;
switch (positionCaretOnClick) {
case "none":
break;
case "select":
selectedCaret = { begin: 0, end: getBuffer.call(inputmask).length };
break;
case "ignore":
selectedCaret.end = selectedCaret.begin = seekNext.call(
inputmask,
getLastValidPosition.call(inputmask)
);
break;
case "radixFocus":
if (inputmask.clicked > 1 && maskset.validPositions.length === 0) break;
if (doRadixFocus(selectedCaret.begin)) {
const radixPos = getBuffer
.call(inputmask)
.join("")
.indexOf(opts.radixPoint);
selectedCaret.end = selectedCaret.begin = opts.numericInput
? seekNext.call(inputmask, radixPos)
: radixPos;
break;
} // fallback to lvp
// eslint-disable-next-line no-fallthrough
default: // lvp:
clickPosition = selectedCaret.begin;
lvclickPosition = getLastValidPosition.call(
inputmask,
clickPosition,
true
);
lastPosition = seekNext.call(
inputmask,
lvclickPosition === -1 && !isMask.call(inputmask, 0)
? -1
: lvclickPosition
);
if (clickPosition <= lastPosition) {
selectedCaret.end = selectedCaret.begin = !isMask.call(
inputmask,
clickPosition,
false,
true
)
? seekNext.call(inputmask, clickPosition)
: clickPosition;
} else {
const lvp = maskset.validPositions[lvclickPosition],
tt = getTestTemplate.call(
inputmask,
lastPosition,
lvp ? lvp.match.locator : undefined,
lvp
),
placeholder = getPlaceholder.call(
inputmask,
lastPosition,
tt.match
);
if (
(placeholder !== "" &&
getBuffer.call(inputmask)[lastPosition] !== placeholder &&
tt.match.optionalQuantifier !== true &&
tt.match.newBlockMarker !== true) ||
(!isMask.call(inputmask, lastPosition, opts.keepStatic, true) &&
tt.match.def === placeholder)
) {
const newPos = seekNext.call(inputmask, lastPosition);
if (clickPosition >= newPos || clickPosition === lastPosition) {
lastPosition = newPos;
}
}
selectedCaret.end = selectedCaret.begin = lastPosition;
}
}
return selectedCaret;
}
}
//tobe put on prototype?
// tobe put on prototype?
function getBuffer(noCache) {
const inputmask = this,
{ maskset } = inputmask;
if (maskset.buffer === undefined || noCache === true) {
maskset.buffer = getMaskTemplate.call(
inputmask,
true,
getLastValidPosition.call(inputmask),
true
);
if (maskset._buffer === undefined) maskset._buffer = maskset.buffer.slice();
}
return maskset.buffer;
}
// tobe put on prototype?
function getBufferTemplate() {
const inputmask = this,
maskset = this.maskset;
if (maskset._buffer === undefined) {
// generate template
maskset._buffer = getMaskTemplate.call(inputmask, false, 1);
if (maskset.buffer === undefined) maskset.buffer = maskset._buffer.slice();
}
return maskset._buffer;
}
// tobe put on prototype?
function getLastValidPosition(closestTo, strict, validPositions) {
const maskset = this.maskset;
let before = -1,
after = -1;
const valids = validPositions || maskset.validPositions; // for use in valhook ~ context switch
if (closestTo === undefined) closestTo = -1;
for (let psNdx = 0, vpl = valids.length; psNdx < vpl; psNdx++) {
if (valids[psNdx] && (strict || valids[psNdx].generatedInput !== true)) {
if (psNdx <= closestTo) before = psNdx;
if (psNdx >= closestTo) after = psNdx;
}
}
return before === -1 || before === closestTo
? after
: after === -1
? before
: closestTo - before < after - closestTo
? before
: after;
}
// tobe put on prototype?
function isMask(pos, strict, fuzzy) {
const inputmask = this,
maskset = this.maskset;
let test = getTestTemplate.call(inputmask, pos).match;
if (test.def === "") test = getTest.call(inputmask, pos).match;
if (test.static !== true) {
return test.fn;
}
if (
fuzzy === true &&
maskset.validPositions[pos] !== undefined &&
maskset.validPositions[pos].generatedInput !== true
) {
return true;
}
if (strict !== true && pos > -1) {
if (fuzzy) {
// check on the number of tests
const tests = getTests.call(inputmask, pos);
return (
tests.length > 1 + (tests[tests.length - 1].match.def === "" ? 1 : 0)
);
}
// else based on the template
const testTemplate = determineTestTemplate.call(
inputmask,
pos,
getTests.call(inputmask, pos)
),
testPlaceHolder = getPlaceholder.call(inputmask, pos, testTemplate.match);
return testTemplate.match.def !== testPlaceHolder;
}
return false;
}
// tobe put on prototype?
// soft ~ undefined reset validpositions; soft = false also reset tests; soft = true only reset the maskset
function resetMaskSet(soft) {
const maskset = this.maskset;
const maskset = this.maskset;
maskset.buffer = undefined;
if (soft !== true) {
maskset.validPositions = [];
maskset.p = 0;
}
maskset.buffer = undefined;
if (soft !== true) {
maskset.validPositions = [];
maskset.p = 0;
}
if (soft === false) {
maskset.tests = {};
maskset.jitOffset = {};
}
}
//tobe put on prototype?
// tobe put on prototype?
function seekNext(pos, newBlock, fuzzy) {
const inputmask = this;
const inputmask = this;
if (fuzzy === undefined) fuzzy = true;
var position = pos + 1;
while (getTest.call(inputmask, position).match.def !== "" &&
((newBlock === true && (getTest.call(inputmask, position).match.newBlockMarker !== true || !isMask.call(inputmask, position, undefined, true))) ||
(newBlock !== true && !isMask.call(inputmask, position, undefined, fuzzy)))) {
position++;
}
return position;
if (fuzzy === undefined) fuzzy = true;
let position = pos + 1;
while (
getTest.call(inputmask, position).match.def !== "" &&
((newBlock === true &&
(getTest.call(inputmask, position).match.newBlockMarker !== true ||
!isMask.call(inputmask, position, undefined, true))) ||
(newBlock !== true &&
!isMask.call(inputmask, position, undefined, fuzzy)))
) {
position++;
}
return position;
}
//tobe put on prototype?
// tobe put on prototype?
function seekPrevious(pos, newBlock) {
const inputmask = this;
const inputmask = this;
var position = pos - 1;
if (pos <= 0) return 0;
let position = pos - 1;
if (pos <= 0) return 0;
while (position > 0 &&
((newBlock === true && (getTest.call(inputmask, position).match.newBlockMarker !== true || !isMask.call(inputmask, position, undefined, true))) ||
(newBlock !== true && !isMask.call(inputmask, position, undefined, true)))) {
position--;
}
return position;
while (
position > 0 &&
((newBlock === true &&
(getTest.call(inputmask, position).match.newBlockMarker !== true ||
!isMask.call(inputmask, position, undefined, true))) ||
(newBlock !== true && !isMask.call(inputmask, position, undefined, true)))
) {
position--;
}
return position;
}
//tobe put on prototype?
// tobe put on prototype?
function translatePosition(pos) {
const inputmask = this,
opts = this.opts,
el = this.el;
const inputmask = this,
opts = this.opts,
el = this.el;
if (inputmask.isRTL && typeof pos === "number" && (!opts.greedy || opts.placeholder !== "") && el) {
pos = inputmask._valueGet().length - pos;
if (pos < 0) pos = 0;
}
return pos;
if (
inputmask.isRTL &&
typeof pos === "number" &&
(!opts.greedy || opts.placeholder !== "") &&
el
) {
pos = inputmask._valueGet().length - pos;
if (pos < 0) pos = 0;
}
return pos;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

31
node_modules/inputmask/micromasks/mm.js generated vendored Normal file
View file

@ -0,0 +1,31 @@
(() => {
window.mm = (i, mask) => {
const d = { 9: "[0-9]", a: "[a-z]" },
msk = mask.split("");
i.addEventListener("input", handler);
i.addEventListener("focus", handler);
function handler(e) {
if (e.type == "focus" && i.value !== "") return;
const mskd = [];
let s = i.selectionStart - 1;
msk.forEach((el, n) => {
if (d[el]) {
const t = new RegExp(d[el], "i").test(i.value.charAt(n));
mskd.push(t ? i.value.charAt(n) : "_");
if (t && s === n && i.value.charAt(n) !== "_") {
s++;
}
} else {
mskd.push(el);
if (s === n) s++;
}
});
i.value = mskd.join("");
i.selectionStart = i.selectionEnd = s < 0 ? 0 : s;
setTimeout(function () {
i.selectionStart = i.selectionEnd = s < 0 ? 0 : s;
}, 0);
}
};
})();

51
node_modules/inputmask/package.json generated vendored
View file

@ -1,16 +1,25 @@
{
"name": "inputmask",
"version": "5.0.8",
"version": "5.0.9",
"description": "Inputmask is a javascript library which creates an input mask. Inputmask can run against vanilla javascript, jQuery and jqlite.",
"main": "dist/inputmask.js",
"exports": {
".": "./dist/inputmask.js",
"./dist/*.js": "./dist/*.js",
"./lib/*.js": "./lib/*.js",
"./micromasks/*.js": "./micromasks/*.js"
},
"files": [
"bundle.js",
"Changelog.md",
"dist/",
"lib/"
"lib/",
"micromasks/"
],
"scripts": {
"start": "webpack --progress --watch --config-name main --config webpack.config.js",
"jquery": "webpack --progress --watch --config-name jquery --config webpack.config.js",
"colormask": "webpack --progress --watch --config-name colormask --config webpack.config.js",
"test": "grunt validate"
},
"repository": {
@ -36,30 +45,40 @@
},
"homepage": "https://github.com/RobinHerbots/Inputmask",
"devDependencies": {
"@babel/core": "^7.20.5",
"@babel/plugin-transform-modules-commonjs": "^7.19.6",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@babel/core": "^7.23.2",
"@babel/eslint-parser": "^7.24.1",
"@babel/plugin-transform-modules-commonjs": "^7.23.0",
"@babel/preset-env": "^7.23.2",
"@babel/preset-typescript": "^7.23.2",
"@robinherbots/grunt-available-tasks": "^0.6.4",
"@robinherbots/grunt-nuget": "^0.3.3",
"babel-loader": "^9.1.0",
"grunt": "^1.5.3",
"babel-loader": "^9.1.3",
"grunt": "^1.6.1",
"grunt-bump": "^0.8.0",
"grunt-contrib-clean": "^2.0.1",
"grunt-contrib-copy": "^1.0.0",
"grunt-eslint": "^24.0.0",
"grunt-eslint": "^24.3.0",
"grunt-karma": "^4.0.2",
"grunt-release": "^0.14.0",
"grunt-webpack": "^5.0.0",
"jquery": "^3.6.1",
"karma": "^6.4.1",
"grunt-webpack": "^6.0.0",
"jquery": "^3.7.1",
"karma": "^6.4.2",
"karma-browserstack-launcher": "^1.6.0",
"karma-chrome-launcher": "^3.1.1",
"karma-chrome-launcher": "^3.2.0",
"karma-qunit": "^4.1.2",
"load-grunt-tasks": "^5.1.0",
"lodash": "^4.17.21",
"qunit": "^2.19.3",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.0"
"qunit": "^2.20.0",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"prettier": "3.0.0",
"eslint": "^8.46.0",
"eslint-config-prettier": "^8.9.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-n": "^16.0.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-promise": "^6.1.1"
}
}