@mekari/pixel3-mask 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mask.js ADDED
@@ -0,0 +1,272 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var __publicField = (obj, key, value) => {
22
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
23
+ return value;
24
+ };
25
+
26
+ // src/mask.ts
27
+ var mask_exports = {};
28
+ __export(mask_exports, {
29
+ Mask: () => Mask
30
+ });
31
+ module.exports = __toCommonJS(mask_exports);
32
+
33
+ // src/tokens.ts
34
+ var tokens = {
35
+ "#": {
36
+ pattern: /[0-9]/
37
+ },
38
+ "S": {
39
+ pattern: /[a-zA-Z]/
40
+ },
41
+ "X": {
42
+ pattern: /[a-zA-Z0-9]/
43
+ },
44
+ "A": {
45
+ pattern: /[A-Z]/
46
+ },
47
+ "a": {
48
+ pattern: /[a-z]/
49
+ }
50
+ };
51
+
52
+ // src/number.ts
53
+ var prepare = /* @__PURE__ */ __name((input, group, decimal) => input.replaceAll(group, "").replace(decimal, ".").replace("..", ".").replace(/[^.\d]/g, ""), "prepare");
54
+ var createFormatter = /* @__PURE__ */ __name((min, max, opts) => {
55
+ var _a, _b;
56
+ return new Intl.NumberFormat((_b = (_a = opts.number) == null ? void 0 : _a.locale) != null ? _b : "en", {
57
+ minimumFractionDigits: min,
58
+ maximumFractionDigits: max,
59
+ roundingMode: "trunc"
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
+ });
62
+ }, "createFormatter");
63
+ var processNumber = /* @__PURE__ */ __name((value, masked = true, opts) => {
64
+ var _a, _b, _c, _d, _e, _f, _g;
65
+ const sign = ((_a = opts.number) == null ? void 0 : _a.unsigned) !== true && value.startsWith("-") ? "-" : "";
66
+ const fraction = (_c = (_b = opts.number) == null ? void 0 : _b.fraction) != null ? _c : 0;
67
+ let formatter = createFormatter(0, fraction, opts);
68
+ const parts = formatter.formatToParts(1000.12);
69
+ const group = (_e = (_d = parts.find((part) => part.type === "group")) == null ? void 0 : _d.value) != null ? _e : " ";
70
+ const decimal = (_g = (_f = parts.find((part) => part.type === "decimal")) == null ? void 0 : _f.value) != null ? _g : ".";
71
+ const float = prepare(value, group, decimal);
72
+ if (Number.isNaN(parseFloat(float)))
73
+ return sign;
74
+ const floatParts = float.split(".");
75
+ if (floatParts[1] != null && floatParts[1].length >= 1) {
76
+ const min = floatParts[1].length <= fraction ? floatParts[1].length : fraction;
77
+ formatter = createFormatter(min, fraction, opts);
78
+ }
79
+ let result = formatter.format(parseFloat(float));
80
+ if (!masked) {
81
+ result = prepare(result, group, decimal);
82
+ } else if (fraction > 0 && float.endsWith(".") && !float.slice(0, -1).includes(".")) {
83
+ result += decimal;
84
+ }
85
+ return sign + result;
86
+ }, "processNumber");
87
+
88
+ // src/mask.ts
89
+ var _Mask = class _Mask {
90
+ constructor(defaults = {}) {
91
+ __publicField(this, "opts", {});
92
+ __publicField(this, "memo", /* @__PURE__ */ new Map());
93
+ var _a;
94
+ const opts = {
95
+ ...defaults
96
+ };
97
+ if (opts.tokens != null) {
98
+ opts.tokens = opts.tokensReplace ? {
99
+ ...opts.tokens
100
+ } : {
101
+ ...tokens,
102
+ ...opts.tokens
103
+ };
104
+ for (const token of Object.values(opts.tokens)) {
105
+ if (typeof token.pattern === "string") {
106
+ token.pattern = new RegExp(token.pattern);
107
+ }
108
+ }
109
+ } else {
110
+ opts.tokens = tokens;
111
+ }
112
+ if (Array.isArray(opts.mask)) {
113
+ if (opts.mask.length > 1) {
114
+ opts.mask = [...opts.mask].sort((a, b) => a.length - b.length);
115
+ } else {
116
+ opts.mask = (_a = opts.mask[0]) != null ? _a : "";
117
+ }
118
+ }
119
+ if (opts.mask === "") {
120
+ opts.mask = null;
121
+ }
122
+ this.opts = opts;
123
+ }
124
+ masked(value) {
125
+ return this.process(String(value), this.findMask(String(value)));
126
+ }
127
+ unmasked(value) {
128
+ return this.process(String(value), this.findMask(String(value)), false);
129
+ }
130
+ isEager() {
131
+ return this.opts.eager === true;
132
+ }
133
+ isReversed() {
134
+ return this.opts.reversed === true;
135
+ }
136
+ completed(value) {
137
+ const mask = this.findMask(String(value));
138
+ if (this.opts.mask == null || mask == null)
139
+ return false;
140
+ const length = this.process(String(value), mask).length;
141
+ if (typeof this.opts.mask === "string") {
142
+ return length >= this.opts.mask.length;
143
+ }
144
+ return length >= mask.length;
145
+ }
146
+ findMask(value) {
147
+ var _a, _b;
148
+ const mask = this.opts.mask;
149
+ if (mask == null) {
150
+ return null;
151
+ } else if (typeof mask === "string") {
152
+ return mask;
153
+ } else if (typeof mask === "function") {
154
+ return mask(value);
155
+ }
156
+ const l = this.process(value, (_a = mask.slice(-1).pop()) != null ? _a : "", false);
157
+ return (_b = mask.find((el) => this.process(value, el, false).length >= l.length)) != null ? _b : "";
158
+ }
159
+ escapeMask(maskRaw) {
160
+ const chars = [];
161
+ const escaped = [];
162
+ maskRaw.split("").forEach((ch, i) => {
163
+ if (ch === "!" && maskRaw[i - 1] !== "!") {
164
+ escaped.push(i - escaped.length);
165
+ } else {
166
+ chars.push(ch);
167
+ }
168
+ });
169
+ return {
170
+ mask: chars.join(""),
171
+ escaped
172
+ };
173
+ }
174
+ process(value, maskRaw, masked = true) {
175
+ if (this.opts.number != null)
176
+ return processNumber(value, masked, this.opts);
177
+ if (maskRaw == null)
178
+ return value;
179
+ const memoKey = `v=${value},mr=${maskRaw},m=${masked ? 1 : 0}`;
180
+ if (this.memo.has(memoKey))
181
+ return this.memo.get(memoKey);
182
+ const {
183
+ mask,
184
+ escaped
185
+ } = this.escapeMask(maskRaw);
186
+ const result = [];
187
+ const tokens2 = this.opts.tokens != null ? this.opts.tokens : {};
188
+ const offset = this.isReversed() ? -1 : 1;
189
+ const method = this.isReversed() ? "unshift" : "push";
190
+ const lastMaskChar = this.isReversed() ? 0 : mask.length - 1;
191
+ const check = this.isReversed() ? () => m > -1 && v > -1 : () => m < mask.length && v < value.length;
192
+ const notLastMaskChar = /* @__PURE__ */ __name((m2) => !this.isReversed() && m2 <= lastMaskChar || this.isReversed() && m2 >= lastMaskChar, "notLastMaskChar");
193
+ let lastRawMaskChar;
194
+ let repeatedPos = -1;
195
+ let m = this.isReversed() ? mask.length - 1 : 0;
196
+ let v = this.isReversed() ? value.length - 1 : 0;
197
+ let multipleMatched = false;
198
+ while (check()) {
199
+ const maskChar = mask.charAt(m);
200
+ const token = tokens2[maskChar];
201
+ const valueChar = (token == null ? void 0 : token.transform) != null ? token.transform(value.charAt(v)) : value.charAt(v);
202
+ if (!escaped.includes(m) && token != null) {
203
+ if (valueChar.match(token.pattern) != null) {
204
+ result[method](valueChar);
205
+ if (token.repeated) {
206
+ if (repeatedPos === -1) {
207
+ repeatedPos = m;
208
+ } else if (m === lastMaskChar && m !== repeatedPos) {
209
+ m = repeatedPos - offset;
210
+ }
211
+ if (lastMaskChar === repeatedPos) {
212
+ m -= offset;
213
+ }
214
+ } else if (token.multiple) {
215
+ multipleMatched = true;
216
+ m -= offset;
217
+ }
218
+ m += offset;
219
+ } else if (token.multiple) {
220
+ if (multipleMatched) {
221
+ m += offset;
222
+ v -= offset;
223
+ multipleMatched = false;
224
+ } else {
225
+ }
226
+ } else if (valueChar === lastRawMaskChar) {
227
+ lastRawMaskChar = void 0;
228
+ } else if (token.optional) {
229
+ m += offset;
230
+ v -= offset;
231
+ } else {
232
+ }
233
+ v += offset;
234
+ } else {
235
+ if (masked && !this.isEager()) {
236
+ result[method](maskChar);
237
+ }
238
+ if (valueChar === maskChar && !this.isEager()) {
239
+ v += offset;
240
+ } else {
241
+ lastRawMaskChar = maskChar;
242
+ }
243
+ if (!this.isEager()) {
244
+ m += offset;
245
+ }
246
+ }
247
+ if (this.isEager()) {
248
+ while (notLastMaskChar(m) && (tokens2[mask.charAt(m)] == null || escaped.includes(m))) {
249
+ if (masked) {
250
+ result[method](mask.charAt(m));
251
+ if (value.charAt(v) === mask.charAt(m)) {
252
+ m += offset;
253
+ v += offset;
254
+ continue;
255
+ }
256
+ } else if (mask.charAt(m) === value.charAt(v)) {
257
+ v += offset;
258
+ }
259
+ m += offset;
260
+ }
261
+ }
262
+ }
263
+ this.memo.set(memoKey, result.join(""));
264
+ return this.memo.get(memoKey);
265
+ }
266
+ };
267
+ __name(_Mask, "Mask");
268
+ var Mask = _Mask;
269
+ // Annotate the CommonJS export names for ESM import in node:
270
+ 0 && (module.exports = {
271
+ Mask
272
+ });
package/dist/mask.mjs ADDED
@@ -0,0 +1,9 @@
1
+ import {
2
+ Mask
3
+ } from "./chunk-YR2EYYGF.mjs";
4
+ import "./chunk-SPWFCSFT.mjs";
5
+ import "./chunk-5TJYDLDA.mjs";
6
+ import "./chunk-VYPKVKAE.mjs";
7
+ export {
8
+ Mask
9
+ };
@@ -0,0 +1 @@
1
+ {"inputs":{"src/tokens.ts":{"bytes":507,"imports":[],"format":"esm"},"src/number.ts":{"bytes":1738,"imports":[{"path":"./mask","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/mask.ts":{"bytes":6612,"imports":[{"path":"src/tokens.ts","kind":"import-statement","original":"./tokens"},{"path":"src/number.ts","kind":"import-statement","original":"./number"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/parser.ts":{"bytes":2213,"imports":[{"path":"./mask","kind":"import-statement","external":true},{"path":"./tokens","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/input.ts":{"bytes":5185,"imports":[{"path":"src/mask.ts","kind":"import-statement","original":"./mask"},{"path":"src/parser.ts","kind":"import-statement","original":"./parser"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/directive.ts":{"bytes":1731,"imports":[{"path":"vue","kind":"import-statement","external":true},{"path":"src/input.ts","kind":"import-statement","original":"./input"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":507,"imports":[{"path":"src/mask.ts","kind":"import-statement","original":"./mask"},{"path":"src/input.ts","kind":"import-statement","original":"./input"},{"path":"src/tokens.ts","kind":"import-statement","original":"./tokens"},{"path":"src/directive.ts","kind":"import-statement","original":"./directive"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/directive.js":{"imports":[],"exports":[],"entryPoint":"src/directive.ts","inputs":{"src/directive.ts":{"bytesInOutput":1557},"src/tokens.ts":{"bytesInOutput":201},"src/number.ts":{"bytesInOutput":1836},"src/mask.ts":{"bytesInOutput":5588},"src/parser.ts":{"bytesInOutput":2006},"src/input.ts":{"bytesInOutput":3915}},"bytes":16516},"dist/index.js":{"imports":[],"exports":[],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":340},"src/tokens.ts":{"bytesInOutput":201},"src/number.ts":{"bytesInOutput":1836},"src/mask.ts":{"bytesInOutput":5588},"src/parser.ts":{"bytesInOutput":2006},"src/input.ts":{"bytesInOutput":3915},"src/directive.ts":{"bytesInOutput":1424}},"bytes":16788},"dist/input.js":{"imports":[],"exports":[],"entryPoint":"src/input.ts","inputs":{"src/input.ts":{"bytesInOutput":4044},"src/tokens.ts":{"bytesInOutput":201},"src/number.ts":{"bytesInOutput":1836},"src/mask.ts":{"bytesInOutput":5588},"src/parser.ts":{"bytesInOutput":2006}},"bytes":15067},"dist/mask.js":{"imports":[],"exports":[],"entryPoint":"src/mask.ts","inputs":{"src/mask.ts":{"bytesInOutput":5704},"src/tokens.ts":{"bytesInOutput":201},"src/number.ts":{"bytesInOutput":1836}},"bytes":9092},"dist/number.js":{"imports":[],"exports":[],"entryPoint":"src/number.ts","inputs":{"src/number.ts":{"bytesInOutput":1976}},"bytes":2990},"dist/parser.js":{"imports":[],"exports":[],"entryPoint":"src/parser.ts","inputs":{"src/parser.ts":{"bytesInOutput":2137}},"bytes":3148},"dist/tokens.js":{"imports":[],"exports":[],"entryPoint":"src/tokens.ts","inputs":{"src/tokens.ts":{"bytesInOutput":327}},"bytes":1244}}}
@@ -0,0 +1 @@
1
+ {"inputs":{"src/tokens.ts":{"bytes":507,"imports":[],"format":"esm"},"src/number.ts":{"bytes":1738,"imports":[{"path":"./mask","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/mask.ts":{"bytes":6612,"imports":[{"path":"src/tokens.ts","kind":"import-statement","original":"./tokens"},{"path":"src/number.ts","kind":"import-statement","original":"./number"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/parser.ts":{"bytes":2213,"imports":[{"path":"./mask","kind":"import-statement","external":true},{"path":"./tokens","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/input.ts":{"bytes":5185,"imports":[{"path":"src/mask.ts","kind":"import-statement","original":"./mask"},{"path":"src/parser.ts","kind":"import-statement","original":"./parser"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/directive.ts":{"bytes":1731,"imports":[{"path":"vue","kind":"import-statement","external":true},{"path":"src/input.ts","kind":"import-statement","original":"./input"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":507,"imports":[{"path":"src/mask.ts","kind":"import-statement","original":"./mask"},{"path":"src/input.ts","kind":"import-statement","original":"./input"},{"path":"src/tokens.ts","kind":"import-statement","original":"./tokens"},{"path":"src/directive.ts","kind":"import-statement","original":"./directive"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/directive.mjs":{"imports":[{"path":"dist/chunk-T4KAZ3CC.mjs","kind":"import-statement"},{"path":"dist/chunk-GPEHQJAT.mjs","kind":"import-statement"},{"path":"dist/chunk-YR2EYYGF.mjs","kind":"import-statement"},{"path":"dist/chunk-SPWFCSFT.mjs","kind":"import-statement"},{"path":"dist/chunk-MAURZ3LV.mjs","kind":"import-statement"},{"path":"dist/chunk-5TJYDLDA.mjs","kind":"import-statement"},{"path":"dist/chunk-VYPKVKAE.mjs","kind":"import-statement"}],"exports":["vMask"],"entryPoint":"src/directive.ts","inputs":{},"bytes":254},"dist/index.mjs":{"imports":[{"path":"dist/chunk-T4KAZ3CC.mjs","kind":"import-statement"},{"path":"dist/chunk-GPEHQJAT.mjs","kind":"import-statement"},{"path":"dist/chunk-YR2EYYGF.mjs","kind":"import-statement"},{"path":"dist/chunk-SPWFCSFT.mjs","kind":"import-statement"},{"path":"dist/chunk-MAURZ3LV.mjs","kind":"import-statement"},{"path":"dist/chunk-5TJYDLDA.mjs","kind":"import-statement"},{"path":"dist/chunk-VYPKVKAE.mjs","kind":"import-statement"}],"exports":["Mask","MaskInput","defineMaskOptions","tokens","vMask"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":105}},"bytes":501},"dist/chunk-T4KAZ3CC.mjs":{"imports":[{"path":"dist/chunk-GPEHQJAT.mjs","kind":"import-statement"},{"path":"dist/chunk-VYPKVKAE.mjs","kind":"import-statement"}],"exports":["vMask"],"inputs":{"src/directive.ts":{"bytesInOutput":1424}},"bytes":1567},"dist/input.mjs":{"imports":[{"path":"dist/chunk-GPEHQJAT.mjs","kind":"import-statement"},{"path":"dist/chunk-YR2EYYGF.mjs","kind":"import-statement"},{"path":"dist/chunk-SPWFCSFT.mjs","kind":"import-statement"},{"path":"dist/chunk-MAURZ3LV.mjs","kind":"import-statement"},{"path":"dist/chunk-5TJYDLDA.mjs","kind":"import-statement"},{"path":"dist/chunk-VYPKVKAE.mjs","kind":"import-statement"}],"exports":["MaskInput"],"entryPoint":"src/input.ts","inputs":{},"bytes":231},"dist/chunk-GPEHQJAT.mjs":{"imports":[{"path":"dist/chunk-YR2EYYGF.mjs","kind":"import-statement"},{"path":"dist/chunk-MAURZ3LV.mjs","kind":"import-statement"},{"path":"dist/chunk-VYPKVKAE.mjs","kind":"import-statement"}],"exports":["MaskInput"],"inputs":{"src/input.ts":{"bytesInOutput":3915}},"bytes":4123},"dist/mask.mjs":{"imports":[{"path":"dist/chunk-YR2EYYGF.mjs","kind":"import-statement"},{"path":"dist/chunk-SPWFCSFT.mjs","kind":"import-statement"},{"path":"dist/chunk-5TJYDLDA.mjs","kind":"import-statement"},{"path":"dist/chunk-VYPKVKAE.mjs","kind":"import-statement"}],"exports":["Mask"],"entryPoint":"src/mask.ts","inputs":{},"bytes":159},"dist/chunk-YR2EYYGF.mjs":{"imports":[{"path":"dist/chunk-SPWFCSFT.mjs","kind":"import-statement"},{"path":"dist/chunk-5TJYDLDA.mjs","kind":"import-statement"},{"path":"dist/chunk-VYPKVKAE.mjs","kind":"import-statement"}],"exports":["Mask"],"inputs":{"src/mask.ts":{"bytesInOutput":5588}},"bytes":5795},"dist/number.mjs":{"imports":[{"path":"dist/chunk-SPWFCSFT.mjs","kind":"import-statement"},{"path":"dist/chunk-VYPKVKAE.mjs","kind":"import-statement"}],"exports":["processNumber"],"entryPoint":"src/number.ts","inputs":{},"bytes":115},"dist/chunk-SPWFCSFT.mjs":{"imports":[{"path":"dist/chunk-VYPKVKAE.mjs","kind":"import-statement"}],"exports":["processNumber"],"inputs":{"src/number.ts":{"bytesInOutput":1836}},"bytes":1932},"dist/parser.mjs":{"imports":[{"path":"dist/chunk-MAURZ3LV.mjs","kind":"import-statement"},{"path":"dist/chunk-VYPKVKAE.mjs","kind":"import-statement"}],"exports":["parseInput"],"entryPoint":"src/parser.ts","inputs":{},"bytes":109},"dist/chunk-MAURZ3LV.mjs":{"imports":[{"path":"dist/chunk-VYPKVKAE.mjs","kind":"import-statement"}],"exports":["parseInput"],"inputs":{"src/parser.ts":{"bytesInOutput":2003}},"bytes":2096},"dist/tokens.mjs":{"imports":[{"path":"dist/chunk-5TJYDLDA.mjs","kind":"import-statement"},{"path":"dist/chunk-VYPKVKAE.mjs","kind":"import-statement"}],"exports":["tokens"],"entryPoint":"src/tokens.ts","inputs":{},"bytes":101},"dist/chunk-5TJYDLDA.mjs":{"imports":[],"exports":["tokens"],"inputs":{"src/tokens.ts":{"bytesInOutput":201}},"bytes":240},"dist/chunk-VYPKVKAE.mjs":{"imports":[],"exports":["__name","__publicField"],"inputs":{},"bytes":464}}}
@@ -0,0 +1,6 @@
1
+ import { MaskOptions } from './mask.mjs';
2
+ import './tokens.mjs';
3
+
4
+ declare const processNumber: (value: string, masked: boolean | undefined, opts: MaskOptions) => string;
5
+
6
+ export { processNumber };
@@ -0,0 +1,6 @@
1
+ import { MaskOptions } from './mask.js';
2
+ import './tokens.js';
3
+
4
+ declare const processNumber: (value: string, masked: boolean | undefined, opts: MaskOptions) => string;
5
+
6
+ export { processNumber };
package/dist/number.js ADDED
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/number.ts
22
+ var number_exports = {};
23
+ __export(number_exports, {
24
+ processNumber: () => processNumber
25
+ });
26
+ module.exports = __toCommonJS(number_exports);
27
+ var prepare = /* @__PURE__ */ __name((input, group, decimal) => input.replaceAll(group, "").replace(decimal, ".").replace("..", ".").replace(/[^.\d]/g, ""), "prepare");
28
+ var createFormatter = /* @__PURE__ */ __name((min, max, opts) => {
29
+ var _a, _b;
30
+ return new Intl.NumberFormat((_b = (_a = opts.number) == null ? void 0 : _a.locale) != null ? _b : "en", {
31
+ minimumFractionDigits: min,
32
+ maximumFractionDigits: max,
33
+ roundingMode: "trunc"
34
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
+ });
36
+ }, "createFormatter");
37
+ var processNumber = /* @__PURE__ */ __name((value, masked = true, opts) => {
38
+ var _a, _b, _c, _d, _e, _f, _g;
39
+ const sign = ((_a = opts.number) == null ? void 0 : _a.unsigned) !== true && value.startsWith("-") ? "-" : "";
40
+ const fraction = (_c = (_b = opts.number) == null ? void 0 : _b.fraction) != null ? _c : 0;
41
+ let formatter = createFormatter(0, fraction, opts);
42
+ const parts = formatter.formatToParts(1000.12);
43
+ const group = (_e = (_d = parts.find((part) => part.type === "group")) == null ? void 0 : _d.value) != null ? _e : " ";
44
+ const decimal = (_g = (_f = parts.find((part) => part.type === "decimal")) == null ? void 0 : _f.value) != null ? _g : ".";
45
+ const float = prepare(value, group, decimal);
46
+ if (Number.isNaN(parseFloat(float)))
47
+ return sign;
48
+ const floatParts = float.split(".");
49
+ if (floatParts[1] != null && floatParts[1].length >= 1) {
50
+ const min = floatParts[1].length <= fraction ? floatParts[1].length : fraction;
51
+ formatter = createFormatter(min, fraction, opts);
52
+ }
53
+ let result = formatter.format(parseFloat(float));
54
+ if (!masked) {
55
+ result = prepare(result, group, decimal);
56
+ } else if (fraction > 0 && float.endsWith(".") && !float.slice(0, -1).includes(".")) {
57
+ result += decimal;
58
+ }
59
+ return sign + result;
60
+ }, "processNumber");
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ processNumber
64
+ });
@@ -0,0 +1,7 @@
1
+ import {
2
+ processNumber
3
+ } from "./chunk-SPWFCSFT.mjs";
4
+ import "./chunk-VYPKVKAE.mjs";
5
+ export {
6
+ processNumber
7
+ };
@@ -0,0 +1,6 @@
1
+ import { MaskOptions } from './mask.mjs';
2
+ import './tokens.mjs';
3
+
4
+ declare const parseInput: (input: HTMLInputElement, defaults?: MaskOptions) => MaskOptions;
5
+
6
+ export { parseInput };
@@ -0,0 +1,6 @@
1
+ import { MaskOptions } from './mask.js';
2
+ import './tokens.js';
3
+
4
+ declare const parseInput: (input: HTMLInputElement, defaults?: MaskOptions) => MaskOptions;
5
+
6
+ export { parseInput };
package/dist/parser.js ADDED
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/parser.ts
22
+ var parser_exports = {};
23
+ __export(parser_exports, {
24
+ parseInput: () => parseInput
25
+ });
26
+ module.exports = __toCommonJS(parser_exports);
27
+ var parseJson = /* @__PURE__ */ __name((value) => JSON.parse(value.replaceAll("'", '"')), "parseJson");
28
+ var parseInput = /* @__PURE__ */ __name((input, defaults = {}) => {
29
+ const opts = {
30
+ ...defaults
31
+ };
32
+ if (input.dataset.maska != null && input.dataset.maska !== "") {
33
+ opts.mask = parseMask(input.dataset.maska);
34
+ }
35
+ if (input.dataset.maskaEager != null) {
36
+ opts.eager = parseBool(input.dataset.maskaEager);
37
+ }
38
+ if (input.dataset.maskaReversed != null) {
39
+ opts.reversed = parseBool(input.dataset.maskaReversed);
40
+ }
41
+ if (input.dataset.maskaTokensReplace != null) {
42
+ opts.tokensReplace = parseBool(input.dataset.maskaTokensReplace);
43
+ }
44
+ if (input.dataset.maskaTokens != null) {
45
+ opts.tokens = parseTokens(input.dataset.maskaTokens);
46
+ }
47
+ const number = {};
48
+ if (input.dataset.maskaNumberLocale != null) {
49
+ number.locale = input.dataset.maskaNumberLocale;
50
+ }
51
+ if (input.dataset.maskaNumberFraction != null) {
52
+ number.fraction = parseInt(input.dataset.maskaNumberFraction);
53
+ }
54
+ if (input.dataset.maskaNumberUnsigned != null) {
55
+ number.unsigned = parseBool(input.dataset.maskaNumberUnsigned);
56
+ }
57
+ if (input.dataset.maskaNumber != null || Object.values(number).length > 0) {
58
+ opts.number = number;
59
+ }
60
+ return opts;
61
+ }, "parseInput");
62
+ var parseBool = /* @__PURE__ */ __name((value) => value !== "" ? Boolean(JSON.parse(value)) : true, "parseBool");
63
+ var parseMask = /* @__PURE__ */ __name((value) => value.startsWith("[") && value.endsWith("]") ? parseJson(value) : value, "parseMask");
64
+ var parseTokens = /* @__PURE__ */ __name((value) => {
65
+ if (value.startsWith("{") && value.endsWith("}")) {
66
+ return parseJson(value);
67
+ }
68
+ const tokens = {};
69
+ value.split("|").forEach((token) => {
70
+ const parts = token.split(":");
71
+ tokens[parts[0]] = {
72
+ pattern: new RegExp(parts[1]),
73
+ optional: parts[2] === "optional",
74
+ multiple: parts[2] === "multiple",
75
+ repeated: parts[2] === "repeated"
76
+ };
77
+ });
78
+ return tokens;
79
+ }, "parseTokens");
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ parseInput
83
+ });
@@ -0,0 +1,7 @@
1
+ import {
2
+ parseInput
3
+ } from "./chunk-MAURZ3LV.mjs";
4
+ import "./chunk-VYPKVKAE.mjs";
5
+ export {
6
+ parseInput
7
+ };
@@ -0,0 +1,11 @@
1
+ interface MaskToken {
2
+ pattern: RegExp;
3
+ multiple?: boolean;
4
+ optional?: boolean;
5
+ repeated?: boolean;
6
+ transform?: (char: string) => string;
7
+ }
8
+ type MaskTokens = Record<string, MaskToken>;
9
+ declare const tokens: MaskTokens;
10
+
11
+ export { MaskTokens, tokens };
@@ -0,0 +1,11 @@
1
+ interface MaskToken {
2
+ pattern: RegExp;
3
+ multiple?: boolean;
4
+ optional?: boolean;
5
+ repeated?: boolean;
6
+ transform?: (char: string) => string;
7
+ }
8
+ type MaskTokens = Record<string, MaskToken>;
9
+ declare const tokens: MaskTokens;
10
+
11
+ export { MaskTokens, tokens };
package/dist/tokens.js ADDED
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/tokens.ts
21
+ var tokens_exports = {};
22
+ __export(tokens_exports, {
23
+ tokens: () => tokens
24
+ });
25
+ module.exports = __toCommonJS(tokens_exports);
26
+ var tokens = {
27
+ "#": {
28
+ pattern: /[0-9]/
29
+ },
30
+ "S": {
31
+ pattern: /[a-zA-Z]/
32
+ },
33
+ "X": {
34
+ pattern: /[a-zA-Z0-9]/
35
+ },
36
+ "A": {
37
+ pattern: /[A-Z]/
38
+ },
39
+ "a": {
40
+ pattern: /[a-z]/
41
+ }
42
+ };
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ tokens
46
+ });
@@ -0,0 +1,7 @@
1
+ import {
2
+ tokens
3
+ } from "./chunk-5TJYDLDA.mjs";
4
+ import "./chunk-VYPKVKAE.mjs";
5
+ export {
6
+ tokens
7
+ };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@mekari/pixel3-mask",
3
+ "description": "Mask directive for mekari pixel 3",
4
+ "version": "0.1.0",
5
+ "main": "dist/index.js",
6
+ "license": "MIT",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "dependencies": {
11
+ "@mekari/pixel3-styled-system": "0.1.4",
12
+ "@mekari/pixel3-utils": "0.0.7"
13
+ },
14
+ "peerDependencies": {
15
+ "vue": "^3.4.9"
16
+ },
17
+ "devDependencies": {
18
+ "vue": "^3.4.9"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "module": "dist/index.mjs",
24
+ "types": "dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "require": "./dist/index.js",
29
+ "default": "./dist/index.mjs"
30
+ }
31
+ },
32
+ "scripts": {
33
+ "clean": "rimraf dist .turbo",
34
+ "build": "tsup && pnpm build:types",
35
+ "build:fast": "tsup",
36
+ "build:types": "tsup src --dts-only",
37
+ "types:check": "tsc --noEmit",
38
+ "replace-config": "clean-package",
39
+ "restore-config": "clean-package restore",
40
+ "types:vue": "vue-tsc --noEmit"
41
+ }
42
+ }