yummies 7.10.0 → 7.12.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/async.cjs +162 -48
- package/async.cjs.map +1 -1
- package/async.d.ts +112 -13
- package/async.js +163 -54
- package/async.js.map +1 -1
- package/chunk-CVq3Gv4J.cjs +50 -0
- package/chunk-YKewjYmz.js +37 -0
- package/common.cjs +48 -8
- package/common.cjs.map +1 -1
- package/common.d.ts +35 -2
- package/common.js +49 -11
- package/common.js.map +1 -1
- package/complex.cjs +275 -104
- package/complex.cjs.map +1 -1
- package/complex.d.ts +133 -13
- package/complex.js +275 -109
- package/complex.js.map +1 -1
- package/cookie.cjs +17 -7
- package/cookie.cjs.map +1 -1
- package/cookie.d.ts +8 -0
- package/cookie.js +18 -9
- package/cookie.js.map +1 -1
- package/css.cjs +147 -39
- package/css.cjs.map +1 -1
- package/css.d.ts +98 -6
- package/css.js +143 -41
- package/css.js.map +1 -1
- package/data.cjs +90 -55
- package/data.cjs.map +1 -1
- package/data.d.ts +32 -0
- package/data.js +91 -61
- package/data.js.map +1 -1
- package/date-time.cjs +578 -412
- package/date-time.cjs.map +1 -1
- package/date-time.d.ts +88 -0
- package/date-time.js +575 -421
- package/date-time.js.map +1 -1
- package/device.cjs +48 -23
- package/device.cjs.map +1 -1
- package/device.d.ts +32 -0
- package/device.js +49 -31
- package/device.js.map +1 -1
- package/encodings.cjs +275 -266
- package/encodings.cjs.map +1 -1
- package/encodings.d.ts +8 -0
- package/encodings.js +276 -268
- package/encodings.js.map +1 -1
- package/errors.cjs +20 -18
- package/errors.cjs.map +1 -1
- package/errors.js +19 -19
- package/errors.js.map +1 -1
- package/file.cjs +42 -24
- package/file.cjs.map +1 -1
- package/file.d.ts +16 -0
- package/file.js +43 -27
- package/file.js.map +1 -1
- package/format.cjs +125 -83
- package/format.cjs.map +1 -1
- package/format.d.ts +89 -4
- package/format.js +118 -82
- package/format.js.map +1 -1
- package/html.cjs +226 -137
- package/html.cjs.map +1 -1
- package/html.d.ts +67 -3
- package/html.js +223 -150
- package/html.js.map +1 -1
- package/id.cjs +74 -17
- package/id.cjs.map +1 -1
- package/id.d.ts +10 -10
- package/id.js +73 -24
- package/id.js.map +1 -1
- package/imports.cjs +41 -29
- package/imports.cjs.map +1 -1
- package/imports.d.ts +13 -4
- package/imports.js +40 -31
- package/imports.js.map +1 -1
- package/math.cjs +32 -6
- package/math.cjs.map +1 -1
- package/math.d.ts +17 -1
- package/math.js +33 -10
- package/math.js.map +1 -1
- package/media.cjs +275 -84
- package/media.cjs.map +1 -1
- package/media.d.ts +188 -2
- package/media.js +274 -93
- package/media.js.map +1 -1
- package/mobx.cjs +353 -193
- package/mobx.cjs.map +1 -1
- package/mobx.d.ts +172 -6
- package/mobx.js +351 -200
- package/mobx.js.map +1 -1
- package/ms.cjs +21 -10
- package/ms.cjs.map +1 -1
- package/ms.d.ts +1 -1
- package/ms.js +22 -13
- package/ms.js.map +1 -1
- package/number.cjs +13 -7
- package/number.cjs.map +1 -1
- package/number.js +14 -9
- package/number.js.map +1 -1
- package/package.json +13 -5
- package/parser.cjs +117 -64
- package/parser.cjs.map +1 -1
- package/parser.d.ts +63 -0
- package/parser.js +111 -64
- package/parser.js.map +1 -1
- package/price.cjs +24 -18
- package/price.cjs.map +1 -1
- package/price.d.ts +8 -0
- package/price.js +25 -20
- package/price.js.map +1 -1
- package/random.cjs +79 -13
- package/random.cjs.map +1 -1
- package/random.d.ts +64 -0
- package/random.js +80 -22
- package/random.js.map +1 -1
- package/react.cjs +673 -214
- package/react.cjs.map +1 -1
- package/react.d.ts +428 -9
- package/react.js +674 -239
- package/react.js.map +1 -1
- package/sound.cjs +14 -9
- package/sound.cjs.map +1 -1
- package/sound.d.ts +1 -1
- package/sound.js +15 -11
- package/sound.js.map +1 -1
- package/storage.cjs +49 -50
- package/storage.cjs.map +1 -1
- package/storage.d.ts +15 -6
- package/storage.js +50 -53
- package/storage.js.map +1 -1
- package/text.cjs +51 -34
- package/text.cjs.map +1 -1
- package/text.d.ts +5 -5
- package/text.js +52 -37
- package/text.js.map +1 -1
- package/type-guard.cjs +292 -72
- package/type-guard.cjs.map +1 -1
- package/type-guard.d.ts +199 -42
- package/type-guard.js +288 -73
- package/type-guard.js.map +1 -1
- package/types.cjs +0 -2
- package/types.global.cjs +0 -2
- package/types.global.js +0 -2
- package/types.js +0 -2
- package/vibrate.cjs +31 -6
- package/vibrate.cjs.map +1 -1
- package/vibrate.d.ts +23 -1
- package/vibrate.js +32 -8
- package/vibrate.js.map +1 -1
- package/types.cjs.map +0 -1
- package/types.global.cjs.map +0 -1
- package/types.global.js.map +0 -1
- package/types.js.map +0 -1
package/format.js
CHANGED
|
@@ -1,87 +1,123 @@
|
|
|
1
|
+
import { n as __exportAll } from "./chunk-YKewjYmz.js";
|
|
1
2
|
import { parser } from "yummies/parser";
|
|
2
3
|
import { typeGuard } from "yummies/type-guard";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return emptyText;
|
|
4
|
+
//#region src/format/number.ts
|
|
5
|
+
/**
|
|
6
|
+
* Formats a numeric value with thousands separators, fractional digit control
|
|
7
|
+
* and optional postfix text.
|
|
8
|
+
*
|
|
9
|
+
* Invalid, empty or unsupported values fall back to `emptyText`.
|
|
10
|
+
*
|
|
11
|
+
* @param rawValue Number or numeric string to format.
|
|
12
|
+
* @param userSettings Formatting overrides merged with `number.defaultSettings`.
|
|
13
|
+
* @returns Formatted number string or fallback text.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* number(12000); // '12 000'
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* number(12.5, { digits: 1, postfix: '%' }); // '12.5%'
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
var number = (rawValue, userSettings) => {
|
|
26
|
+
const settings = {
|
|
27
|
+
...number.defaultSettings,
|
|
28
|
+
...userSettings
|
|
29
|
+
};
|
|
30
|
+
const digits = settings.digits ?? 0;
|
|
31
|
+
const cutZeros = settings?.cutZeros ?? false;
|
|
32
|
+
const delimiter = settings.delimiter ?? " ";
|
|
33
|
+
const postfix = settings.postfix ?? "";
|
|
34
|
+
const emptyText = settings.emptyText ?? "–";
|
|
35
|
+
const digitsOnlyForFloat = settings.digitsOnlyForFloat ?? true;
|
|
36
|
+
let value;
|
|
37
|
+
if (typeGuard.isString(rawValue)) value = parser.number(value, { fallback: void 0 });
|
|
38
|
+
else value = rawValue;
|
|
39
|
+
if (typeGuard.isNumber(value)) {
|
|
40
|
+
let raw = `${value}`;
|
|
41
|
+
if (digits !== false) if (settings.cropDigitsOnly) {
|
|
42
|
+
const [integerPart, decimalPart] = `${raw}`.split(".");
|
|
43
|
+
const leftPart = integerPart;
|
|
44
|
+
const rightPart = (decimalPart || "").slice(0, digits).padEnd(digits, "0");
|
|
45
|
+
if (rightPart) raw = `${leftPart}.${rightPart}`;
|
|
46
|
+
else raw = leftPart;
|
|
47
|
+
} else raw = value.toFixed(digits);
|
|
48
|
+
if (cutZeros) raw = `${+raw}`;
|
|
49
|
+
const [integerPart, decimalPart] = raw.split(".", 2);
|
|
50
|
+
let formattedIntegerPart = integerPart;
|
|
51
|
+
let formattedDecimalPart = "";
|
|
52
|
+
if (decimalPart && (!digitsOnlyForFloat || !/^0+$/.test(decimalPart))) formattedDecimalPart = `.${decimalPart}`;
|
|
53
|
+
const rgx = /(\d+)(\d{3})/;
|
|
54
|
+
while (rgx.test(formattedIntegerPart) && delimiter) formattedIntegerPart = formattedIntegerPart.replace(rgx, `$1${delimiter}$2`);
|
|
55
|
+
return formattedIntegerPart + formattedDecimalPart + postfix;
|
|
56
|
+
}
|
|
57
|
+
return emptyText;
|
|
58
58
|
};
|
|
59
59
|
number.defaultSettings = {};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/format/percent.ts
|
|
62
|
+
/**
|
|
63
|
+
* Formats a value as a percent string with configurable decimal precision,
|
|
64
|
+
* decimal divider and suffix symbol.
|
|
65
|
+
*
|
|
66
|
+
* @param value Number or numeric string to format.
|
|
67
|
+
* @param settings Parser and formatting options.
|
|
68
|
+
* @returns Formatted percent string or fallback text for invalid values.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* percent(12.345); // '12.35%'
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* percent(12.345, { divider: ',', symbol: ' pct' }); // '12,35 pct'
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
var percent = (value, settings) => {
|
|
81
|
+
const numericValue = parser.number(value, {
|
|
82
|
+
...settings,
|
|
83
|
+
digits: settings?.digits ?? 2,
|
|
84
|
+
fallback: NaN
|
|
85
|
+
});
|
|
86
|
+
if (typeGuard.isNumber(numericValue)) {
|
|
87
|
+
const divider = settings?.divider ?? ".";
|
|
88
|
+
return `${divider === "." ? numericValue : `${numericValue}`.replace(".", divider)}${settings?.delimiter ?? ""}${settings?.symbol ?? "%"}`;
|
|
89
|
+
} else return settings?.emptyText ?? "–";
|
|
73
90
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/format/skip-spaces.ts
|
|
93
|
+
/**
|
|
94
|
+
* Removes all whitespace characters from a string.
|
|
95
|
+
*
|
|
96
|
+
* @param value Source string.
|
|
97
|
+
* @returns String without spaces, tabs and line breaks.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* skipSpaces('1 000 000'); // '1000000'
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* skipSpaces('a\tb\nc'); // 'abc'
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
var skipSpaces = (value) => value.replaceAll(/\s/g, "");
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/format/_exports.ts
|
|
112
|
+
var _exports_exports = /* @__PURE__ */ __exportAll({
|
|
113
|
+
HYPHEN: () => "-",
|
|
114
|
+
INFINITY: () => "∞",
|
|
115
|
+
NO_VALUE: () => "–",
|
|
116
|
+
number: () => number,
|
|
117
|
+
percent: () => percent,
|
|
118
|
+
skipSpaces: () => skipSpaces
|
|
119
|
+
});
|
|
120
|
+
//#endregion
|
|
121
|
+
export { _exports_exports as format };
|
|
122
|
+
|
|
123
|
+
//# sourceMappingURL=format.js.map
|
package/format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sources":["../src/format/
|
|
1
|
+
{"version":3,"file":"format.js","names":[],"sources":["../src/format/number.ts","../src/format/percent.ts","../src/format/skip-spaces.ts","../src/format/_exports.ts"],"sourcesContent":["import { parser } from 'yummies/parser';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\nimport { NO_VALUE } from './constants.js';\n\nexport interface NumberFormatSettings {\n delimiter?: string;\n /**\n * digitsOnlyForFloat - Show digits after decimal point only if they are not zeros after converting to number.\n * Example: \"0.00\" -> \"0\", \"0.10\" -> \"0.1\", but \"0.003\" -> \"0.003\"\n *\n * @default true\n */\n digitsOnlyForFloat?: boolean;\n /**\n * Text which will be returned if the value is undefined, null, NaN, Infinity or empty string.\n * Example: \"–\" will be returned if the value is undefined and emptyText is \"–\".\n */\n emptyText?: string;\n /**\n * Text to append to the end of the formatted number.\n * Example: if value is 1000 and postfix is \"₽\", result will be \"1 000₽\".\n */\n postfix?: string;\n /**\n * Fixed number of digits after the decimal point (number.toFixed() method)\n * If set to false, the truncation is ignored!\n */\n digits?: number | false;\n /**\n * Remove trailing zeros from the end of the number\n * Example: 0.010000000000000000000000000000000000000000000 -> 0.01\n */\n cutZeros?: boolean;\n cropDigitsOnly?: boolean;\n}\n\n/**\n * Formats a numeric value with thousands separators, fractional digit control\n * and optional postfix text.\n *\n * Invalid, empty or unsupported values fall back to `emptyText`.\n *\n * @param rawValue Number or numeric string to format.\n * @param userSettings Formatting overrides merged with `number.defaultSettings`.\n * @returns Formatted number string or fallback text.\n *\n * @example\n * ```ts\n * number(12000); // '12 000'\n * ```\n *\n * @example\n * ```ts\n * number(12.5, { digits: 1, postfix: '%' }); // '12.5%'\n * ```\n */\nexport const number = (\n rawValue: Maybe<string | number>,\n userSettings?: Maybe<NumberFormatSettings>,\n): string => {\n const settings = {\n ...number.defaultSettings,\n ...userSettings,\n };\n\n const digits = settings.digits ?? 0;\n const cutZeros = settings?.cutZeros ?? false;\n const delimiter = settings.delimiter ?? ' ';\n const postfix = settings.postfix ?? '';\n const emptyText = settings.emptyText ?? NO_VALUE;\n const digitsOnlyForFloat = settings.digitsOnlyForFloat ?? true;\n\n let value: Maybe<number>;\n\n if (typeGuard.isString(rawValue)) {\n value = parser.number(value, { fallback: undefined });\n } else {\n value = rawValue;\n }\n\n if (typeGuard.isNumber(value)) {\n let raw: string = `${value}`;\n\n if (digits !== false) {\n if (settings.cropDigitsOnly) {\n const [integerPart, decimalPart] = `${raw}`.split('.');\n const leftPart = integerPart;\n const rightPart = (decimalPart || '')\n .slice(0, digits)\n .padEnd(digits, '0');\n\n if (rightPart) {\n raw = `${leftPart}.${rightPart}`;\n } else {\n raw = leftPart;\n }\n } else {\n raw = value.toFixed(digits);\n }\n }\n\n if (cutZeros) {\n raw = `${+raw}`;\n }\n\n const [integerPart, decimalPart] = raw.split('.', 2);\n\n let formattedIntegerPart = integerPart;\n let formattedDecimalPart = '';\n\n if (decimalPart && (!digitsOnlyForFloat || !/^0+$/.test(decimalPart))) {\n formattedDecimalPart = `.${decimalPart}`;\n }\n\n const rgx = /(\\d+)(\\d{3})/;\n\n while (rgx.test(formattedIntegerPart) && delimiter) {\n formattedIntegerPart = formattedIntegerPart.replace(\n rgx,\n `$1${delimiter}$2`,\n );\n }\n\n return formattedIntegerPart + formattedDecimalPart + postfix;\n }\n\n return emptyText;\n};\n\nnumber.defaultSettings = {} as NumberFormatSettings;\n","import { parser } from 'yummies/parser';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\nimport { NO_VALUE } from './constants.js';\n\nexport interface PercentFormatSettings\n extends Omit<parser.NumberParserSettings, 'fallback'> {\n divider?: string;\n delimiter?: string;\n symbol?: string;\n emptyText?: string;\n}\n\n/**\n * Formats a value as a percent string with configurable decimal precision,\n * decimal divider and suffix symbol.\n *\n * @param value Number or numeric string to format.\n * @param settings Parser and formatting options.\n * @returns Formatted percent string or fallback text for invalid values.\n *\n * @example\n * ```ts\n * percent(12.345); // '12.35%'\n * ```\n *\n * @example\n * ```ts\n * percent(12.345, { divider: ',', symbol: ' pct' }); // '12,35 pct'\n * ```\n */\nexport const percent = (\n value: Maybe<number | string>,\n settings?: PercentFormatSettings,\n) => {\n const numericValue = parser.number(value, {\n ...settings,\n digits: settings?.digits ?? 2,\n fallback: Number.NaN,\n });\n\n if (typeGuard.isNumber(numericValue)) {\n const divider = settings?.divider ?? '.';\n\n const formattedPercent =\n divider === '.' ? numericValue : `${numericValue}`.replace('.', divider);\n\n return `${formattedPercent}${settings?.delimiter ?? ''}${settings?.symbol ?? '%'}`;\n } else {\n return settings?.emptyText ?? NO_VALUE;\n }\n};\n","/**\n * Removes all whitespace characters from a string.\n *\n * @param value Source string.\n * @returns String without spaces, tabs and line breaks.\n *\n * @example\n * ```ts\n * skipSpaces('1 000 000'); // '1000000'\n * ```\n *\n * @example\n * ```ts\n * skipSpaces('a\\tb\\nc'); // 'abc'\n * ```\n */\nexport const skipSpaces = (value: string) => value.replaceAll(/\\s/g, '');\n","export * from './constants.js';\nexport * from './number.js';\nexport * from './percent.js';\nexport * from './skip-spaces.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyDA,IAAa,UACX,UACA,iBACW;CACX,MAAM,WAAW;EACf,GAAG,OAAO;EACV,GAAG;EACJ;CAED,MAAM,SAAS,SAAS,UAAU;CAClC,MAAM,WAAW,UAAU,YAAY;CACvC,MAAM,YAAY,SAAS,aAAa;CACxC,MAAM,UAAU,SAAS,WAAW;CACpC,MAAM,YAAY,SAAS,aAAA;CAC3B,MAAM,qBAAqB,SAAS,sBAAsB;CAE1D,IAAI;AAEJ,KAAI,UAAU,SAAS,SAAS,CAC9B,SAAQ,OAAO,OAAO,OAAO,EAAE,UAAU,KAAA,GAAW,CAAC;KAErD,SAAQ;AAGV,KAAI,UAAU,SAAS,MAAM,EAAE;EAC7B,IAAI,MAAc,GAAG;AAErB,MAAI,WAAW,MACb,KAAI,SAAS,gBAAgB;GAC3B,MAAM,CAAC,aAAa,eAAe,GAAG,MAAM,MAAM,IAAI;GACtD,MAAM,WAAW;GACjB,MAAM,aAAa,eAAe,IAC/B,MAAM,GAAG,OAAO,CAChB,OAAO,QAAQ,IAAI;AAEtB,OAAI,UACF,OAAM,GAAG,SAAS,GAAG;OAErB,OAAM;QAGR,OAAM,MAAM,QAAQ,OAAO;AAI/B,MAAI,SACF,OAAM,GAAG,CAAC;EAGZ,MAAM,CAAC,aAAa,eAAe,IAAI,MAAM,KAAK,EAAE;EAEpD,IAAI,uBAAuB;EAC3B,IAAI,uBAAuB;AAE3B,MAAI,gBAAgB,CAAC,sBAAsB,CAAC,OAAO,KAAK,YAAY,EAClE,wBAAuB,IAAI;EAG7B,MAAM,MAAM;AAEZ,SAAO,IAAI,KAAK,qBAAqB,IAAI,UACvC,wBAAuB,qBAAqB,QAC1C,KACA,KAAK,UAAU,IAChB;AAGH,SAAO,uBAAuB,uBAAuB;;AAGvD,QAAO;;AAGT,OAAO,kBAAkB,EAAE;;;;;;;;;;;;;;;;;;;;;AClG3B,IAAa,WACX,OACA,aACG;CACH,MAAM,eAAe,OAAO,OAAO,OAAO;EACxC,GAAG;EACH,QAAQ,UAAU,UAAU;EAC5B,UAAU;EACX,CAAC;AAEF,KAAI,UAAU,SAAS,aAAa,EAAE;EACpC,MAAM,UAAU,UAAU,WAAW;AAKrC,SAAO,GAFL,YAAY,MAAM,eAAe,GAAG,eAAe,QAAQ,KAAK,QAAQ,GAE7C,UAAU,aAAa,KAAK,UAAU,UAAU;OAE7E,QAAO,UAAU,aAAA;;;;;;;;;;;;;;;;;;;;AClCrB,IAAa,cAAc,UAAkB,MAAM,WAAW,OAAO,GAAG"}
|
package/html.cjs
CHANGED
|
@@ -1,156 +1,244 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
const require_chunk = require("./chunk-CVq3Gv4J.cjs");
|
|
3
|
+
let dompurify = require("dompurify");
|
|
4
|
+
dompurify = require_chunk.__toESM(dompurify);
|
|
5
|
+
let yummies_media = require("yummies/media");
|
|
6
|
+
//#region src/html.ts
|
|
7
|
+
/**
|
|
8
|
+
* Extracts an RGB value from any valid CSS color.
|
|
9
|
+
*
|
|
10
|
+
* Not recommended for frequent use because it triggers a reflow.
|
|
11
|
+
*/
|
|
12
|
+
var getComputedColor = (color) => {
|
|
13
|
+
if (!color) return null;
|
|
14
|
+
const d = document.createElement("div");
|
|
15
|
+
d.style.color = color;
|
|
16
|
+
document.body.append(d);
|
|
17
|
+
const rgbcolor = globalThis.getComputedStyle(d).color;
|
|
18
|
+
const match = /rgba?\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*\d+[.d+]*)*\)/g.exec(rgbcolor);
|
|
19
|
+
d.remove();
|
|
20
|
+
if (!match) return null;
|
|
21
|
+
return `${match[1]}, ${match[2]}, ${match[3]}`;
|
|
15
22
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Triggers a file download by creating and clicking a temporary anchor element.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* downloadUsingAnchor('/report.pdf', 'report.pdf');
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
var downloadUsingAnchor = (urlOrBlob, fileName) => {
|
|
32
|
+
const url = (0, yummies_media.blobToUrl)(urlOrBlob);
|
|
33
|
+
const a = document.createElement("a");
|
|
34
|
+
a.href = url;
|
|
35
|
+
a.download = fileName ?? "file";
|
|
36
|
+
a.target = "_blank";
|
|
37
|
+
document.body.append(a);
|
|
38
|
+
a.click();
|
|
39
|
+
a.remove();
|
|
25
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* Surrounds string in an anchor tag
|
|
43
|
+
*/
|
|
26
44
|
function wrapTextToTagLink(link) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
const descr = String(link).replace(/^(https?:\/{0,2})?(w{3}\.)?/, "www.");
|
|
46
|
+
if (!/^https?:\/{2}/.test(link)) link = `http://${link}`;
|
|
47
|
+
return `<a href=${link} target="_blank">${descr}</a>`;
|
|
30
48
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Collects the cumulative `offsetTop` value through the element parent chain.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const offsetTop = collectOffsetTop(document.getElementById('section'));
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
var collectOffsetTop = (element) => {
|
|
58
|
+
let offsetTop = 0;
|
|
59
|
+
let node = element;
|
|
60
|
+
while (node != null) {
|
|
61
|
+
offsetTop += node.offsetTop;
|
|
62
|
+
node = node.parentElement;
|
|
63
|
+
}
|
|
64
|
+
return offsetTop;
|
|
39
65
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Prevents the default browser action and stops event propagation.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* button.addEventListener('click', (event) => skipEvent(event));
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
var skipEvent = (e) => {
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
e.stopPropagation();
|
|
77
|
+
return false;
|
|
44
78
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Scrolls the page vertically to the viewport section containing the target element.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* globalScrollIntoViewForY(document.getElementById('footer')!);
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
var globalScrollIntoViewForY = (node) => {
|
|
88
|
+
const scrollContainer = document.body;
|
|
89
|
+
const pageHeight = window.innerHeight;
|
|
90
|
+
const nodeBounding = node.getBoundingClientRect();
|
|
91
|
+
const scrollPagesCount = scrollContainer.scrollHeight / pageHeight;
|
|
92
|
+
const scrollPageNumber = Math.min(Math.max(nodeBounding.top / pageHeight, 1), scrollPagesCount);
|
|
93
|
+
window.scroll({
|
|
94
|
+
top: scrollPageNumber * pageHeight,
|
|
95
|
+
behavior: "smooth"
|
|
96
|
+
});
|
|
58
97
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
var sanitizeDefaults = {
|
|
99
|
+
ALLOWED_TAGS: [
|
|
100
|
+
"a",
|
|
101
|
+
"article",
|
|
102
|
+
"b",
|
|
103
|
+
"blockquote",
|
|
104
|
+
"br",
|
|
105
|
+
"caption",
|
|
106
|
+
"code",
|
|
107
|
+
"del",
|
|
108
|
+
"details",
|
|
109
|
+
"div",
|
|
110
|
+
"em",
|
|
111
|
+
"h1",
|
|
112
|
+
"h2",
|
|
113
|
+
"h3",
|
|
114
|
+
"h4",
|
|
115
|
+
"h5",
|
|
116
|
+
"h6",
|
|
117
|
+
"hr",
|
|
118
|
+
"i",
|
|
119
|
+
"img",
|
|
120
|
+
"ins",
|
|
121
|
+
"kbd",
|
|
122
|
+
"li",
|
|
123
|
+
"main",
|
|
124
|
+
"ol",
|
|
125
|
+
"p",
|
|
126
|
+
"pre",
|
|
127
|
+
"section",
|
|
128
|
+
"span",
|
|
129
|
+
"strong",
|
|
130
|
+
"sub",
|
|
131
|
+
"summary",
|
|
132
|
+
"sup",
|
|
133
|
+
"table",
|
|
134
|
+
"tbody",
|
|
135
|
+
"td",
|
|
136
|
+
"th",
|
|
137
|
+
"thead",
|
|
138
|
+
"tr",
|
|
139
|
+
"u",
|
|
140
|
+
"ul"
|
|
141
|
+
],
|
|
142
|
+
ALLOWED_ATTR: [
|
|
143
|
+
"href",
|
|
144
|
+
"target",
|
|
145
|
+
"name",
|
|
146
|
+
"src",
|
|
147
|
+
"class"
|
|
148
|
+
]
|
|
104
149
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Sanitizes HTML using the default allowlist merged with custom DOMPurify config.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* sanitizeHtml('<img src=x onerror=alert(1) />');
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
var sanitizeHtml = (html, config) => {
|
|
159
|
+
return dompurify.default.sanitize(html || "", {
|
|
160
|
+
...sanitizeDefaults,
|
|
161
|
+
...config
|
|
162
|
+
});
|
|
110
163
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Checks whether the element is nested inside the provided parent element.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* checkElementHasParent(childElement, modalElement);
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
var checkElementHasParent = (element, parent) => {
|
|
173
|
+
let node = element;
|
|
174
|
+
if (!parent) return false;
|
|
175
|
+
while (node != null) if (node === parent) return true;
|
|
176
|
+
else node = node.parentElement;
|
|
177
|
+
return false;
|
|
122
178
|
};
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Executes a function within a view transition if supported by the browser.
|
|
181
|
+
*
|
|
182
|
+
* @param {VoidFunction} fn - The function to be executed.
|
|
183
|
+
* @returns {ViewTransition} - The result of the executed function.
|
|
184
|
+
*
|
|
185
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition | MDN: Document.startViewTransition}
|
|
186
|
+
*/
|
|
187
|
+
var startViewTransitionSafety = (fn, params) => {
|
|
188
|
+
if (typeof document !== "undefined" && document.startViewTransition && !params?.disabled) return document.startViewTransition(fn);
|
|
189
|
+
fn();
|
|
128
190
|
};
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
191
|
+
/**
|
|
192
|
+
* Calculates the scrollbar width.
|
|
193
|
+
*/
|
|
194
|
+
var calcScrollbarWidth = (elementToAppend = document.body) => {
|
|
195
|
+
const outer = document.createElement("div");
|
|
196
|
+
outer.style.visibility = "hidden";
|
|
197
|
+
outer.style.width = "100px";
|
|
198
|
+
outer.style.overflow = "scroll";
|
|
199
|
+
elementToAppend.append(outer);
|
|
200
|
+
const inner = document.createElement("div");
|
|
201
|
+
inner.style.width = "100%";
|
|
202
|
+
outer.append(inner);
|
|
203
|
+
const scrollbarWidth = outer.offsetWidth - inner.offsetWidth;
|
|
204
|
+
outer.parentNode?.removeChild(outer);
|
|
205
|
+
return scrollbarWidth;
|
|
141
206
|
};
|
|
207
|
+
/**
|
|
208
|
+
* Calculates the inner height of an HTML element, accounting for padding.
|
|
209
|
+
*/
|
|
142
210
|
function getElementInnerHeight(element) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
211
|
+
const { clientHeight } = element;
|
|
212
|
+
const { paddingTop, paddingBottom } = getComputedStyle(element);
|
|
213
|
+
return clientHeight - Number.parseFloat(paddingTop) - Number.parseFloat(paddingBottom);
|
|
146
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Calculates the inner width of an HTML element, accounting for padding.
|
|
217
|
+
*/
|
|
147
218
|
function getElementInnerWidth(el) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
219
|
+
const { clientWidth } = el;
|
|
220
|
+
const { paddingLeft, paddingRight } = getComputedStyle(el);
|
|
221
|
+
return clientWidth - Number.parseFloat(paddingLeft) - Number.parseFloat(paddingRight);
|
|
151
222
|
}
|
|
152
|
-
|
|
153
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Checks whether the user prefers a dark color scheme.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* const prefersDark = isPrefersDarkTheme();
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
var isPrefersDarkTheme = () => !!globalThis.matchMedia?.("(prefers-color-scheme: dark)")?.matches;
|
|
232
|
+
/**
|
|
233
|
+
* Checks whether the user prefers a light color scheme.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* const prefersLight = isPrefersLightTheme();
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
var isPrefersLightTheme = () => !!globalThis.matchMedia?.("(prefers-color-scheme: light)")?.matches;
|
|
241
|
+
//#endregion
|
|
154
242
|
exports.calcScrollbarWidth = calcScrollbarWidth;
|
|
155
243
|
exports.checkElementHasParent = checkElementHasParent;
|
|
156
244
|
exports.collectOffsetTop = collectOffsetTop;
|
|
@@ -165,4 +253,5 @@ exports.sanitizeHtml = sanitizeHtml;
|
|
|
165
253
|
exports.skipEvent = skipEvent;
|
|
166
254
|
exports.startViewTransitionSafety = startViewTransitionSafety;
|
|
167
255
|
exports.wrapTextToTagLink = wrapTextToTagLink;
|
|
168
|
-
|
|
256
|
+
|
|
257
|
+
//# sourceMappingURL=html.cjs.map
|