Add supporting themes required for Lotusdocs

This commit is contained in:
Abner Coimbre
2026-01-11 16:48:19 -08:00
parent 8a4d04db58
commit f8d40c4e41
1289 changed files with 234948 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
import mask from '../src/index.js'
document.addEventListener('alpine:init', () => {
window.Alpine.plugin(mask)
})

View File

@@ -0,0 +1,5 @@
import mask, { stripDown } from '../src/index.js'
export default mask
export { mask, stripDown }

View File

@@ -0,0 +1,179 @@
(() => {
// packages/mask/src/index.js
function src_default(Alpine) {
Alpine.directive("mask", (el, { value, expression }, { effect, evaluateLater, cleanup }) => {
let templateFn = () => expression;
let lastInputValue = "";
queueMicrotask(() => {
if (["function", "dynamic"].includes(value)) {
let evaluator = evaluateLater(expression);
effect(() => {
templateFn = (input) => {
let result;
Alpine.dontAutoEvaluateFunctions(() => {
evaluator((value2) => {
result = typeof value2 === "function" ? value2(input) : value2;
}, { scope: {
// These are "magics" we'll make available to the x-mask:function:
"$input": input,
"$money": formatMoney.bind({ el })
} });
});
return result;
};
processInputValue(el, false);
});
} else {
processInputValue(el, false);
}
if (el._x_model)
el._x_model.set(el.value);
});
const controller = new AbortController();
cleanup(() => {
controller.abort();
});
el.addEventListener("input", () => processInputValue(el), {
signal: controller.signal,
// Setting this as a capture phase listener to ensure it runs
// before wire:model or x-model added as a latent binding...
capture: true
});
el.addEventListener("blur", () => processInputValue(el, false), { signal: controller.signal });
function processInputValue(el2, shouldRestoreCursor = true) {
let input = el2.value;
let template = templateFn(input);
if (!template || template === "false")
return false;
if (lastInputValue.length - el2.value.length === 1) {
return lastInputValue = el2.value;
}
let setInput = () => {
lastInputValue = el2.value = formatInput(input, template);
};
if (shouldRestoreCursor) {
restoreCursorPosition(el2, template, () => {
setInput();
});
} else {
setInput();
}
}
function formatInput(input, template) {
if (input === "")
return "";
let strippedDownInput = stripDown(template, input);
let rebuiltInput = buildUp(template, strippedDownInput);
return rebuiltInput;
}
}).before("model");
}
function restoreCursorPosition(el, template, callback) {
let cursorPosition = el.selectionStart;
let unformattedValue = el.value;
callback();
let beforeLeftOfCursorBeforeFormatting = unformattedValue.slice(0, cursorPosition);
let newPosition = buildUp(
template,
stripDown(
template,
beforeLeftOfCursorBeforeFormatting
)
).length;
el.setSelectionRange(newPosition, newPosition);
}
function stripDown(template, input) {
let inputToBeStripped = input;
let output = "";
let regexes = {
"9": /[0-9]/,
"a": /[a-zA-Z]/,
"*": /[a-zA-Z0-9]/
};
let wildcardTemplate = "";
for (let i = 0; i < template.length; i++) {
if (["9", "a", "*"].includes(template[i])) {
wildcardTemplate += template[i];
continue;
}
for (let j = 0; j < inputToBeStripped.length; j++) {
if (inputToBeStripped[j] === template[i]) {
inputToBeStripped = inputToBeStripped.slice(0, j) + inputToBeStripped.slice(j + 1);
break;
}
}
}
for (let i = 0; i < wildcardTemplate.length; i++) {
let found = false;
for (let j = 0; j < inputToBeStripped.length; j++) {
if (regexes[wildcardTemplate[i]].test(inputToBeStripped[j])) {
output += inputToBeStripped[j];
inputToBeStripped = inputToBeStripped.slice(0, j) + inputToBeStripped.slice(j + 1);
found = true;
break;
}
}
if (!found)
break;
}
return output;
}
function buildUp(template, input) {
let clean = Array.from(input);
let output = "";
for (let i = 0; i < template.length; i++) {
if (!["9", "a", "*"].includes(template[i])) {
output += template[i];
continue;
}
if (clean.length === 0)
break;
output += clean.shift();
}
return output;
}
function formatMoney(input, delimiter = ".", thousands, precision = 2) {
if (input === "-")
return "-";
if (/^\D+$/.test(input))
return "9";
if (thousands === null || thousands === void 0) {
thousands = delimiter === "," ? "." : ",";
}
let addThousands = (input2, thousands2) => {
let output = "";
let counter = 0;
for (let i = input2.length - 1; i >= 0; i--) {
if (input2[i] === thousands2)
continue;
if (counter === 3) {
output = input2[i] + thousands2 + output;
counter = 0;
} else {
output = input2[i] + output;
}
counter++;
}
return output;
};
let minus = input.startsWith("-") ? "-" : "";
let strippedInput = input.replaceAll(new RegExp(`[^0-9\\${delimiter}]`, "g"), "");
let template = Array.from({ length: strippedInput.split(delimiter)[0].length }).fill("9").join("");
template = `${minus}${addThousands(template, thousands)}`;
if (precision > 0 && input.includes(delimiter))
template += `${delimiter}` + "9".repeat(precision);
queueMicrotask(() => {
if (this.el.value.endsWith(delimiter))
return;
if (this.el.value[this.el.selectionStart - 1] === delimiter) {
this.el.setSelectionRange(this.el.selectionStart - 1, this.el.selectionStart - 1);
}
});
return template;
}
// packages/mask/builds/cdn.js
document.addEventListener("alpine:init", () => {
window.Alpine.plugin(src_default);
});
})();

View File

@@ -0,0 +1 @@
(()=>{function v(n){n.directive("mask",(e,{value:t,expression:u},{effect:s,evaluateLater:a,cleanup:l})=>{let r=()=>u,o="";queueMicrotask(()=>{if(["function","dynamic"].includes(t)){let i=a(u);s(()=>{r=p=>{let d;return n.dontAutoEvaluateFunctions(()=>{i(c=>{d=typeof c=="function"?c(p):c},{scope:{$input:p,$money:x.bind({el:e})}})}),d},f(e,!1)})}else f(e,!1);e._x_model&&e._x_model.set(e.value)});let g=new AbortController;l(()=>{g.abort()}),e.addEventListener("input",()=>f(e),{signal:g.signal,capture:!0}),e.addEventListener("blur",()=>f(e,!1),{signal:g.signal});function f(i,p=!0){let d=i.value,c=r(d);if(!c||c==="false")return!1;if(o.length-i.value.length===1)return o=i.value;let b=()=>{o=i.value=h(d,c)};p?w(i,c,()=>{b()}):b()}function h(i,p){if(i==="")return"";let d=k(p,i);return m(p,d)}}).before("model")}function w(n,e,t){let u=n.selectionStart,s=n.value;t();let a=s.slice(0,u),l=m(e,k(e,a)).length;n.setSelectionRange(l,l)}function k(n,e){let t=e,u="",s={9:/[0-9]/,a:/[a-zA-Z]/,"*":/[a-zA-Z0-9]/},a="";for(let l=0;l<n.length;l++){if(["9","a","*"].includes(n[l])){a+=n[l];continue}for(let r=0;r<t.length;r++)if(t[r]===n[l]){t=t.slice(0,r)+t.slice(r+1);break}}for(let l=0;l<a.length;l++){let r=!1;for(let o=0;o<t.length;o++)if(s[a[l]].test(t[o])){u+=t[o],t=t.slice(0,o)+t.slice(o+1),r=!0;break}if(!r)break}return u}function m(n,e){let t=Array.from(e),u="";for(let s=0;s<n.length;s++){if(!["9","a","*"].includes(n[s])){u+=n[s];continue}if(t.length===0)break;u+=t.shift()}return u}function x(n,e=".",t,u=2){if(n==="-")return"-";if(/^\D+$/.test(n))return"9";t==null&&(t=e===","?".":",");let s=(o,g)=>{let f="",h=0;for(let i=o.length-1;i>=0;i--)o[i]!==g&&(h===3?(f=o[i]+g+f,h=0):f=o[i]+f,h++);return f},a=n.startsWith("-")?"-":"",l=n.replaceAll(new RegExp(`[^0-9\\${e}]`,"g"),""),r=Array.from({length:l.split(e)[0].length}).fill("9").join("");return r=`${a}${s(r,t)}`,u>0&&n.includes(e)&&(r+=`${e}`+"9".repeat(u)),queueMicrotask(()=>{this.el.value.endsWith(e)||this.el.value[this.el.selectionStart-1]===e&&this.el.setSelectionRange(this.el.selectionStart-1,this.el.selectionStart-1)}),r}document.addEventListener("alpine:init",()=>{window.Alpine.plugin(v)});})();

View File

@@ -0,0 +1,207 @@
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/mask/builds/module.js
var module_exports = {};
__export(module_exports, {
default: () => module_default,
mask: () => src_default,
stripDown: () => stripDown
});
module.exports = __toCommonJS(module_exports);
// packages/mask/src/index.js
function src_default(Alpine) {
Alpine.directive("mask", (el, { value, expression }, { effect, evaluateLater, cleanup }) => {
let templateFn = () => expression;
let lastInputValue = "";
queueMicrotask(() => {
if (["function", "dynamic"].includes(value)) {
let evaluator = evaluateLater(expression);
effect(() => {
templateFn = (input) => {
let result;
Alpine.dontAutoEvaluateFunctions(() => {
evaluator((value2) => {
result = typeof value2 === "function" ? value2(input) : value2;
}, { scope: {
// These are "magics" we'll make available to the x-mask:function:
"$input": input,
"$money": formatMoney.bind({ el })
} });
});
return result;
};
processInputValue(el, false);
});
} else {
processInputValue(el, false);
}
if (el._x_model)
el._x_model.set(el.value);
});
const controller = new AbortController();
cleanup(() => {
controller.abort();
});
el.addEventListener("input", () => processInputValue(el), {
signal: controller.signal,
// Setting this as a capture phase listener to ensure it runs
// before wire:model or x-model added as a latent binding...
capture: true
});
el.addEventListener("blur", () => processInputValue(el, false), { signal: controller.signal });
function processInputValue(el2, shouldRestoreCursor = true) {
let input = el2.value;
let template = templateFn(input);
if (!template || template === "false")
return false;
if (lastInputValue.length - el2.value.length === 1) {
return lastInputValue = el2.value;
}
let setInput = () => {
lastInputValue = el2.value = formatInput(input, template);
};
if (shouldRestoreCursor) {
restoreCursorPosition(el2, template, () => {
setInput();
});
} else {
setInput();
}
}
function formatInput(input, template) {
if (input === "")
return "";
let strippedDownInput = stripDown(template, input);
let rebuiltInput = buildUp(template, strippedDownInput);
return rebuiltInput;
}
}).before("model");
}
function restoreCursorPosition(el, template, callback) {
let cursorPosition = el.selectionStart;
let unformattedValue = el.value;
callback();
let beforeLeftOfCursorBeforeFormatting = unformattedValue.slice(0, cursorPosition);
let newPosition = buildUp(
template,
stripDown(
template,
beforeLeftOfCursorBeforeFormatting
)
).length;
el.setSelectionRange(newPosition, newPosition);
}
function stripDown(template, input) {
let inputToBeStripped = input;
let output = "";
let regexes = {
"9": /[0-9]/,
"a": /[a-zA-Z]/,
"*": /[a-zA-Z0-9]/
};
let wildcardTemplate = "";
for (let i = 0; i < template.length; i++) {
if (["9", "a", "*"].includes(template[i])) {
wildcardTemplate += template[i];
continue;
}
for (let j = 0; j < inputToBeStripped.length; j++) {
if (inputToBeStripped[j] === template[i]) {
inputToBeStripped = inputToBeStripped.slice(0, j) + inputToBeStripped.slice(j + 1);
break;
}
}
}
for (let i = 0; i < wildcardTemplate.length; i++) {
let found = false;
for (let j = 0; j < inputToBeStripped.length; j++) {
if (regexes[wildcardTemplate[i]].test(inputToBeStripped[j])) {
output += inputToBeStripped[j];
inputToBeStripped = inputToBeStripped.slice(0, j) + inputToBeStripped.slice(j + 1);
found = true;
break;
}
}
if (!found)
break;
}
return output;
}
function buildUp(template, input) {
let clean = Array.from(input);
let output = "";
for (let i = 0; i < template.length; i++) {
if (!["9", "a", "*"].includes(template[i])) {
output += template[i];
continue;
}
if (clean.length === 0)
break;
output += clean.shift();
}
return output;
}
function formatMoney(input, delimiter = ".", thousands, precision = 2) {
if (input === "-")
return "-";
if (/^\D+$/.test(input))
return "9";
if (thousands === null || thousands === void 0) {
thousands = delimiter === "," ? "." : ",";
}
let addThousands = (input2, thousands2) => {
let output = "";
let counter = 0;
for (let i = input2.length - 1; i >= 0; i--) {
if (input2[i] === thousands2)
continue;
if (counter === 3) {
output = input2[i] + thousands2 + output;
counter = 0;
} else {
output = input2[i] + output;
}
counter++;
}
return output;
};
let minus = input.startsWith("-") ? "-" : "";
let strippedInput = input.replaceAll(new RegExp(`[^0-9\\${delimiter}]`, "g"), "");
let template = Array.from({ length: strippedInput.split(delimiter)[0].length }).fill("9").join("");
template = `${minus}${addThousands(template, thousands)}`;
if (precision > 0 && input.includes(delimiter))
template += `${delimiter}` + "9".repeat(precision);
queueMicrotask(() => {
if (this.el.value.endsWith(delimiter))
return;
if (this.el.value[this.el.selectionStart - 1] === delimiter) {
this.el.setSelectionRange(this.el.selectionStart - 1, this.el.selectionStart - 1);
}
});
return template;
}
// packages/mask/builds/module.js
var module_default = src_default;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
mask,
stripDown
});

View File

@@ -0,0 +1,180 @@
// packages/mask/src/index.js
function src_default(Alpine) {
Alpine.directive("mask", (el, { value, expression }, { effect, evaluateLater, cleanup }) => {
let templateFn = () => expression;
let lastInputValue = "";
queueMicrotask(() => {
if (["function", "dynamic"].includes(value)) {
let evaluator = evaluateLater(expression);
effect(() => {
templateFn = (input) => {
let result;
Alpine.dontAutoEvaluateFunctions(() => {
evaluator((value2) => {
result = typeof value2 === "function" ? value2(input) : value2;
}, { scope: {
// These are "magics" we'll make available to the x-mask:function:
"$input": input,
"$money": formatMoney.bind({ el })
} });
});
return result;
};
processInputValue(el, false);
});
} else {
processInputValue(el, false);
}
if (el._x_model)
el._x_model.set(el.value);
});
const controller = new AbortController();
cleanup(() => {
controller.abort();
});
el.addEventListener("input", () => processInputValue(el), {
signal: controller.signal,
// Setting this as a capture phase listener to ensure it runs
// before wire:model or x-model added as a latent binding...
capture: true
});
el.addEventListener("blur", () => processInputValue(el, false), { signal: controller.signal });
function processInputValue(el2, shouldRestoreCursor = true) {
let input = el2.value;
let template = templateFn(input);
if (!template || template === "false")
return false;
if (lastInputValue.length - el2.value.length === 1) {
return lastInputValue = el2.value;
}
let setInput = () => {
lastInputValue = el2.value = formatInput(input, template);
};
if (shouldRestoreCursor) {
restoreCursorPosition(el2, template, () => {
setInput();
});
} else {
setInput();
}
}
function formatInput(input, template) {
if (input === "")
return "";
let strippedDownInput = stripDown(template, input);
let rebuiltInput = buildUp(template, strippedDownInput);
return rebuiltInput;
}
}).before("model");
}
function restoreCursorPosition(el, template, callback) {
let cursorPosition = el.selectionStart;
let unformattedValue = el.value;
callback();
let beforeLeftOfCursorBeforeFormatting = unformattedValue.slice(0, cursorPosition);
let newPosition = buildUp(
template,
stripDown(
template,
beforeLeftOfCursorBeforeFormatting
)
).length;
el.setSelectionRange(newPosition, newPosition);
}
function stripDown(template, input) {
let inputToBeStripped = input;
let output = "";
let regexes = {
"9": /[0-9]/,
"a": /[a-zA-Z]/,
"*": /[a-zA-Z0-9]/
};
let wildcardTemplate = "";
for (let i = 0; i < template.length; i++) {
if (["9", "a", "*"].includes(template[i])) {
wildcardTemplate += template[i];
continue;
}
for (let j = 0; j < inputToBeStripped.length; j++) {
if (inputToBeStripped[j] === template[i]) {
inputToBeStripped = inputToBeStripped.slice(0, j) + inputToBeStripped.slice(j + 1);
break;
}
}
}
for (let i = 0; i < wildcardTemplate.length; i++) {
let found = false;
for (let j = 0; j < inputToBeStripped.length; j++) {
if (regexes[wildcardTemplate[i]].test(inputToBeStripped[j])) {
output += inputToBeStripped[j];
inputToBeStripped = inputToBeStripped.slice(0, j) + inputToBeStripped.slice(j + 1);
found = true;
break;
}
}
if (!found)
break;
}
return output;
}
function buildUp(template, input) {
let clean = Array.from(input);
let output = "";
for (let i = 0; i < template.length; i++) {
if (!["9", "a", "*"].includes(template[i])) {
output += template[i];
continue;
}
if (clean.length === 0)
break;
output += clean.shift();
}
return output;
}
function formatMoney(input, delimiter = ".", thousands, precision = 2) {
if (input === "-")
return "-";
if (/^\D+$/.test(input))
return "9";
if (thousands === null || thousands === void 0) {
thousands = delimiter === "," ? "." : ",";
}
let addThousands = (input2, thousands2) => {
let output = "";
let counter = 0;
for (let i = input2.length - 1; i >= 0; i--) {
if (input2[i] === thousands2)
continue;
if (counter === 3) {
output = input2[i] + thousands2 + output;
counter = 0;
} else {
output = input2[i] + output;
}
counter++;
}
return output;
};
let minus = input.startsWith("-") ? "-" : "";
let strippedInput = input.replaceAll(new RegExp(`[^0-9\\${delimiter}]`, "g"), "");
let template = Array.from({ length: strippedInput.split(delimiter)[0].length }).fill("9").join("");
template = `${minus}${addThousands(template, thousands)}`;
if (precision > 0 && input.includes(delimiter))
template += `${delimiter}` + "9".repeat(precision);
queueMicrotask(() => {
if (this.el.value.endsWith(delimiter))
return;
if (this.el.value[this.el.selectionStart - 1] === delimiter) {
this.el.setSelectionRange(this.el.selectionStart - 1, this.el.selectionStart - 1);
}
});
return template;
}
// packages/mask/builds/module.js
var module_default = src_default;
export {
module_default as default,
src_default as mask,
stripDown
};

View File

@@ -0,0 +1,15 @@
{
"name": "@alpinejs/mask",
"version": "3.13.8",
"description": "An Alpine plugin for input masking",
"homepage": "https://alpinejs.dev/plugins/mask",
"repository": {
"type": "git",
"url": "https://github.com/alpinejs/alpine.git",
"directory": "packages/mask"
},
"author": "Caleb Porzio",
"license": "MIT",
"main": "dist/module.cjs.js",
"module": "dist/module.esm.js"
}

View File

@@ -0,0 +1,230 @@
export default function (Alpine) {
Alpine.directive('mask', (el, { value, expression }, { effect, evaluateLater, cleanup }) => {
let templateFn = () => expression
let lastInputValue = ''
queueMicrotask(() => {
if (['function', 'dynamic'].includes(value)) {
// This is an x-mask:function directive.
let evaluator = evaluateLater(expression)
effect(() => {
templateFn = input => {
let result
// We need to prevent "auto-evaluation" of functions like
// x-on expressions do so that we can use them as mask functions.
Alpine.dontAutoEvaluateFunctions(() => {
evaluator(value => {
result = typeof value === 'function' ? value(input) : value
}, { scope: {
// These are "magics" we'll make available to the x-mask:function:
'$input': input,
'$money': formatMoney.bind({ el }),
}})
})
return result
}
// Run on initialize which serves a dual purpose:
// - Initializing the mask on the input if it has an initial value.
// - Running the template function to set up reactivity, so that
// when a dependency inside it changes, the input re-masks.
processInputValue(el, false)
})
} else {
processInputValue(el, false)
}
// Override x-model's initial value...
if (el._x_model) el._x_model.set(el.value)
})
const controller = new AbortController()
cleanup(() => {
controller.abort()
})
el.addEventListener('input', () => processInputValue(el), {
signal: controller.signal,
// Setting this as a capture phase listener to ensure it runs
// before wire:model or x-model added as a latent binding...
capture: true,
})
// Don't "restoreCursorPosition" on "blur", because Safari
// will re-focus the input and cause a focus trap.
el.addEventListener('blur', () => processInputValue(el, false), { signal: controller.signal })
function processInputValue (el, shouldRestoreCursor = true) {
let input = el.value
let template = templateFn(input)
// If a template value is `falsy`, then don't process the input value
if(!template || template === 'false') return false
// If they hit backspace, don't process input.
if (lastInputValue.length - el.value.length === 1) {
return lastInputValue = el.value
}
let setInput = () => {
lastInputValue = el.value = formatInput(input, template)
}
if (shouldRestoreCursor) {
// When an input element's value is set, it moves the cursor to the end
// therefore we need to track, estimate, and restore the cursor after
// a change was made.
restoreCursorPosition(el, template, () => {
setInput()
})
} else {
setInput()
}
}
function formatInput(input, template) {
// Let empty inputs be empty inputs.
if (input === '') return ''
let strippedDownInput = stripDown(template, input)
let rebuiltInput = buildUp(template, strippedDownInput)
return rebuiltInput
}
}).before('model')
}
export function restoreCursorPosition(el, template, callback) {
let cursorPosition = el.selectionStart
let unformattedValue = el.value
callback()
let beforeLeftOfCursorBeforeFormatting = unformattedValue.slice(0, cursorPosition)
let newPosition = buildUp(
template, stripDown(
template, beforeLeftOfCursorBeforeFormatting
)
).length
el.setSelectionRange(newPosition, newPosition)
}
export function stripDown(template, input) {
let inputToBeStripped = input
let output = ''
let regexes = {
'9': /[0-9]/,
'a': /[a-zA-Z]/,
'*': /[a-zA-Z0-9]/,
}
let wildcardTemplate = ''
// Strip away non wildcard template characters.
for (let i = 0; i < template.length; i++) {
if (['9', 'a', '*'].includes(template[i])) {
wildcardTemplate += template[i]
continue;
}
for (let j = 0; j < inputToBeStripped.length; j++) {
if (inputToBeStripped[j] === template[i]) {
inputToBeStripped = inputToBeStripped.slice(0, j) + inputToBeStripped.slice(j+1)
break;
}
}
}
for (let i = 0; i < wildcardTemplate.length; i++) {
let found = false
for (let j = 0; j < inputToBeStripped.length; j++) {
if (regexes[wildcardTemplate[i]].test(inputToBeStripped[j])) {
output += inputToBeStripped[j]
inputToBeStripped = inputToBeStripped.slice(0, j) + inputToBeStripped.slice(j+1)
found = true
break;
}
}
if (! found) break;
}
return output
}
export function buildUp(template, input) {
let clean = Array.from(input)
let output = ''
for (let i = 0; i < template.length; i++) {
if (! ['9', 'a', '*'].includes(template[i])) {
output += template[i]
continue;
}
if (clean.length === 0) break;
output += clean.shift()
}
return output
}
export function formatMoney(input, delimiter = '.', thousands, precision = 2) {
if (input === '-') return '-'
if (/^\D+$/.test(input)) return '9'
if (thousands === null || thousands === undefined) {
thousands = delimiter === "," ? "." : ","
}
let addThousands = (input, thousands) => {
let output = ''
let counter = 0
for (let i = input.length - 1; i >= 0; i--) {
if (input[i] === thousands) continue;
if (counter === 3) {
output = input[i] + thousands + output
counter = 0
} else {
output = input[i] + output
}
counter++
}
return output
}
let minus = input.startsWith('-') ? '-' : ''
let strippedInput = input.replaceAll(new RegExp(`[^0-9\\${delimiter}]`, 'g'), '')
let template = Array.from({ length: strippedInput.split(delimiter)[0].length }).fill('9').join('')
template = `${minus}${addThousands(template, thousands)}`
if (precision > 0 && input.includes(delimiter))
template += `${delimiter}` + '9'.repeat(precision)
queueMicrotask(() => {
if (this.el.value.endsWith(delimiter)) return
if (this.el.value[this.el.selectionStart - 1] === delimiter) {
this.el.setSelectionRange(this.el.selectionStart - 1, this.el.selectionStart - 1)
}
})
return template
}