@just-web/toolkits 3.0.0 → 3.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/index.cjs +13 -2
- package/dist/index.d.cts +8 -2
- package/dist/index.d.mts +8 -2
- package/dist/index.mjs +7 -2
- package/dist/style/css-properties.d.cts +2 -1
- package/dist/style/css-properties.d.cts.map +1 -1
- package/dist/style/css-properties.d.mts +2 -1
- package/dist/style/css-properties.d.mts.map +1 -1
- package/dist/units/convert-css-unit.cjs +173 -0
- package/dist/units/convert-css-unit.cjs.map +1 -0
- package/dist/units/convert-css-unit.d.cts +25 -0
- package/dist/units/convert-css-unit.d.cts.map +1 -0
- package/dist/units/convert-css-unit.d.mts +25 -0
- package/dist/units/convert-css-unit.d.mts.map +1 -0
- package/dist/units/convert-css-unit.mjs +173 -0
- package/dist/units/convert-css-unit.mjs.map +1 -0
- package/dist/units/create-css-unit-converter.cjs +33 -0
- package/dist/units/create-css-unit-converter.cjs.map +1 -0
- package/dist/units/create-css-unit-converter.d.cts +28 -0
- package/dist/units/create-css-unit-converter.d.cts.map +1 -0
- package/dist/units/create-css-unit-converter.d.mts +28 -0
- package/dist/units/create-css-unit-converter.d.mts.map +1 -0
- package/dist/units/create-css-unit-converter.mjs +33 -0
- package/dist/units/create-css-unit-converter.mjs.map +1 -0
- package/dist/units/css-unit-converter.types.d.cts +35 -0
- package/dist/units/css-unit-converter.types.d.cts.map +1 -0
- package/dist/units/css-unit-converter.types.d.mts +35 -0
- package/dist/units/css-unit-converter.types.d.mts.map +1 -0
- package/dist/units/get-css-unit.cjs +29 -0
- package/dist/units/get-css-unit.cjs.map +1 -0
- package/dist/units/get-css-unit.d.cts +23 -0
- package/dist/units/get-css-unit.d.cts.map +1 -0
- package/dist/units/get-css-unit.d.mts +23 -0
- package/dist/units/get-css-unit.d.mts.map +1 -0
- package/dist/units/get-css-unit.mjs +29 -0
- package/dist/units/get-css-unit.mjs.map +1 -0
- package/dist/units/is-effectively-zero.cjs +35 -0
- package/dist/units/is-effectively-zero.cjs.map +1 -0
- package/dist/units/is-effectively-zero.d.cts +28 -0
- package/dist/units/is-effectively-zero.d.cts.map +1 -0
- package/dist/units/is-effectively-zero.d.mts +28 -0
- package/dist/units/is-effectively-zero.d.mts.map +1 -0
- package/dist/units/is-effectively-zero.mjs +35 -0
- package/dist/units/is-effectively-zero.mjs.map +1 -0
- package/dist/units/parse-css-number.cjs +29 -0
- package/dist/units/parse-css-number.cjs.map +1 -0
- package/dist/units/parse-css-number.d.cts +24 -0
- package/dist/units/parse-css-number.d.cts.map +1 -0
- package/dist/units/parse-css-number.d.mts +24 -0
- package/dist/units/parse-css-number.d.mts.map +1 -0
- package/dist/units/parse-css-number.mjs +29 -0
- package/dist/units/parse-css-number.mjs.map +1 -0
- package/dist/units/parse-css-value.cjs +32 -0
- package/dist/units/parse-css-value.cjs.map +1 -0
- package/dist/units/parse-css-value.d.cts +22 -0
- package/dist/units/parse-css-value.d.cts.map +1 -0
- package/dist/units/parse-css-value.d.mts +22 -0
- package/dist/units/parse-css-value.d.mts.map +1 -0
- package/dist/units/parse-css-value.mjs +31 -0
- package/dist/units/parse-css-value.mjs.map +1 -0
- package/dist/units/px-2-rem.cjs +8 -5
- package/dist/units/px-2-rem.cjs.map +1 -1
- package/dist/units/px-2-rem.d.cts +9 -7
- package/dist/units/px-2-rem.d.cts.map +1 -1
- package/dist/units/px-2-rem.d.mts +9 -7
- package/dist/units/px-2-rem.d.mts.map +1 -1
- package/dist/units/px-2-rem.mjs +8 -5
- package/dist/units/px-2-rem.mjs.map +1 -1
- package/dist/units/rem-2-px.cjs +8 -5
- package/dist/units/rem-2-px.cjs.map +1 -1
- package/dist/units/rem-2-px.d.cts +9 -7
- package/dist/units/rem-2-px.d.cts.map +1 -1
- package/dist/units/rem-2-px.d.mts +9 -7
- package/dist/units/rem-2-px.d.mts.map +1 -1
- package/dist/units/rem-2-px.mjs +8 -5
- package/dist/units/rem-2-px.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +7 -0
- package/src/style/css-properties.ts +3 -1
- package/src/units/convert-css-unit.ts +292 -0
- package/src/units/create-css-unit-converter.ts +30 -0
- package/src/units/css-unit-converter.types.ts +49 -0
- package/src/units/get-css-unit.ts +24 -0
- package/src/units/is-effectively-zero.ts +35 -0
- package/src/units/parse-css-number.ts +26 -0
- package/src/units/parse-css-value.ts +35 -0
- package/src/units/px-2-num.ts +5 -4
- package/src/units/px-2-rem.ts +12 -8
- package/src/units/rem-2-px.ts +11 -9
- package/dist/units/px-2-num.cjs +0 -23
- package/dist/units/px-2-num.cjs.map +0 -1
- package/dist/units/px-2-num.d.cts +0 -19
- package/dist/units/px-2-num.d.cts.map +0 -1
- package/dist/units/px-2-num.d.mts +0 -19
- package/dist/units/px-2-num.d.mts.map +0 -1
- package/dist/units/px-2-num.mjs +0 -22
- package/dist/units/px-2-num.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-css-unit-converter.cjs","names":["convertCssUnit"],"sources":["../../src/units/create-css-unit-converter.ts"],"sourcesContent":["import { convertCssUnit } from './convert-css-unit.ts'\nimport type { CssLengthUnit, CssUnitConverterContext } from './css-unit-converter.types.ts'\n\n/**\n * Creates a pre-configured CSS unit converter with fixed context.\n *\n * @param context - Root font size, viewport, line height, etc. Omitted values use browser auto-detect when available.\n * @returns A converter function that accepts value and toUnit (and optional fromUnit override).\n *\n * @example\n * ```ts\n * const convert = createCssUnitConverter({\n * rootFontSize: 16,\n * viewportWidth: 375,\n * viewportHeight: 812,\n * })\n * convert('1rem', 'px') // 16\n * convert('10vw', 'px') // 37.5\n * convert(16, 'rem', { fromUnit: 'px' }) // 1\n * ```\n */\nexport function createCssUnitConverter(context?: CssUnitConverterContext) {\n\treturn function convert(\n\t\tvalue: number | string,\n\t\ttoUnit: CssLengthUnit,\n\t\toptions?: { fromUnit?: CssLengthUnit | undefined } | undefined\n\t): number | null | undefined {\n\t\treturn convertCssUnit(value, toUnit, { ...context, ...options })\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,uBAAuB,SAAmC;AACzE,QAAO,SAAS,QACf,OACA,QACA,SAC4B;AAC5B,SAAOA,wCAAe,OAAO,QAAQ;GAAE,GAAG;GAAS,GAAG;GAAS,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CssLengthUnit, CssUnitConverterContext } from "./css-unit-converter.types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/units/create-css-unit-converter.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a pre-configured CSS unit converter with fixed context.
|
|
7
|
+
*
|
|
8
|
+
* @param context - Root font size, viewport, line height, etc. Omitted values use browser auto-detect when available.
|
|
9
|
+
* @returns A converter function that accepts value and toUnit (and optional fromUnit override).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const convert = createCssUnitConverter({
|
|
14
|
+
* rootFontSize: 16,
|
|
15
|
+
* viewportWidth: 375,
|
|
16
|
+
* viewportHeight: 812,
|
|
17
|
+
* })
|
|
18
|
+
* convert('1rem', 'px') // 16
|
|
19
|
+
* convert('10vw', 'px') // 37.5
|
|
20
|
+
* convert(16, 'rem', { fromUnit: 'px' }) // 1
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare function createCssUnitConverter(context?: CssUnitConverterContext): (value: number | string, toUnit: CssLengthUnit, options?: {
|
|
24
|
+
fromUnit?: CssLengthUnit | undefined;
|
|
25
|
+
} | undefined) => number | null | undefined;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { createCssUnitConverter };
|
|
28
|
+
//# sourceMappingURL=create-css-unit-converter.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-css-unit-converter.d.cts","names":[],"sources":["../../src/units/create-css-unit-converter.ts"],"sourcesContent":[],"mappings":";;;;;;AAqBA;;;;;;;;;;;;;;;;iBAAgB,sBAAA,WAAiC,2DAGvC;aACe"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CssLengthUnit, CssUnitConverterContext } from "./css-unit-converter.types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/units/create-css-unit-converter.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a pre-configured CSS unit converter with fixed context.
|
|
7
|
+
*
|
|
8
|
+
* @param context - Root font size, viewport, line height, etc. Omitted values use browser auto-detect when available.
|
|
9
|
+
* @returns A converter function that accepts value and toUnit (and optional fromUnit override).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const convert = createCssUnitConverter({
|
|
14
|
+
* rootFontSize: 16,
|
|
15
|
+
* viewportWidth: 375,
|
|
16
|
+
* viewportHeight: 812,
|
|
17
|
+
* })
|
|
18
|
+
* convert('1rem', 'px') // 16
|
|
19
|
+
* convert('10vw', 'px') // 37.5
|
|
20
|
+
* convert(16, 'rem', { fromUnit: 'px' }) // 1
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare function createCssUnitConverter(context?: CssUnitConverterContext): (value: number | string, toUnit: CssLengthUnit, options?: {
|
|
24
|
+
fromUnit?: CssLengthUnit | undefined;
|
|
25
|
+
} | undefined) => number | null | undefined;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { createCssUnitConverter };
|
|
28
|
+
//# sourceMappingURL=create-css-unit-converter.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-css-unit-converter.d.mts","names":[],"sources":["../../src/units/create-css-unit-converter.ts"],"sourcesContent":[],"mappings":";;;;;;AAqBA;;;;;;;;;;;;;;;;iBAAgB,sBAAA,WAAiC,2DAGvC;aACe"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { convertCssUnit } from "./convert-css-unit.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/units/create-css-unit-converter.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a pre-configured CSS unit converter with fixed context.
|
|
6
|
+
*
|
|
7
|
+
* @param context - Root font size, viewport, line height, etc. Omitted values use browser auto-detect when available.
|
|
8
|
+
* @returns A converter function that accepts value and toUnit (and optional fromUnit override).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const convert = createCssUnitConverter({
|
|
13
|
+
* rootFontSize: 16,
|
|
14
|
+
* viewportWidth: 375,
|
|
15
|
+
* viewportHeight: 812,
|
|
16
|
+
* })
|
|
17
|
+
* convert('1rem', 'px') // 16
|
|
18
|
+
* convert('10vw', 'px') // 37.5
|
|
19
|
+
* convert(16, 'rem', { fromUnit: 'px' }) // 1
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function createCssUnitConverter(context) {
|
|
23
|
+
return function convert(value, toUnit, options) {
|
|
24
|
+
return convertCssUnit(value, toUnit, {
|
|
25
|
+
...context,
|
|
26
|
+
...options
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { createCssUnitConverter };
|
|
33
|
+
//# sourceMappingURL=create-css-unit-converter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-css-unit-converter.mjs","names":[],"sources":["../../src/units/create-css-unit-converter.ts"],"sourcesContent":["import { convertCssUnit } from './convert-css-unit.ts'\nimport type { CssLengthUnit, CssUnitConverterContext } from './css-unit-converter.types.ts'\n\n/**\n * Creates a pre-configured CSS unit converter with fixed context.\n *\n * @param context - Root font size, viewport, line height, etc. Omitted values use browser auto-detect when available.\n * @returns A converter function that accepts value and toUnit (and optional fromUnit override).\n *\n * @example\n * ```ts\n * const convert = createCssUnitConverter({\n * rootFontSize: 16,\n * viewportWidth: 375,\n * viewportHeight: 812,\n * })\n * convert('1rem', 'px') // 16\n * convert('10vw', 'px') // 37.5\n * convert(16, 'rem', { fromUnit: 'px' }) // 1\n * ```\n */\nexport function createCssUnitConverter(context?: CssUnitConverterContext) {\n\treturn function convert(\n\t\tvalue: number | string,\n\t\ttoUnit: CssLengthUnit,\n\t\toptions?: { fromUnit?: CssLengthUnit | undefined } | undefined\n\t): number | null | undefined {\n\t\treturn convertCssUnit(value, toUnit, { ...context, ...options })\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,uBAAuB,SAAmC;AACzE,QAAO,SAAS,QACf,OACA,QACA,SAC4B;AAC5B,SAAO,eAAe,OAAO,QAAQ;GAAE,GAAG;GAAS,GAAG;GAAS,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/units/css-unit-converter.types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Supported CSS length units for conversion.
|
|
4
|
+
*/
|
|
5
|
+
type CssLengthUnit = 'px' | 'pt' | 'pc' | 'in' | 'cm' | 'mm' | 'rem' | 'em' | 'vw' | 'vh' | 'vmin' | 'vmax' | 'lh' | 'rlh' | 'ch' | '%';
|
|
6
|
+
/**
|
|
7
|
+
* Options for convertCssUnit.
|
|
8
|
+
*/
|
|
9
|
+
interface ConvertCssUnitOptions {
|
|
10
|
+
/** Override when value is number or unitless string. Default: 'px'. */
|
|
11
|
+
fromUnit?: CssLengthUnit | undefined;
|
|
12
|
+
/** Root font size in px for rem. Auto: getRemToPxScale() in browser. Default: 16. */
|
|
13
|
+
rootFontSize?: number | undefined;
|
|
14
|
+
/** Element font size in px for em. Default: 16. */
|
|
15
|
+
elementFontSize?: number | undefined;
|
|
16
|
+
/** Viewport width in px for vw, vmin, vmax. Auto: window.innerWidth in browser. */
|
|
17
|
+
viewportWidth?: number | undefined;
|
|
18
|
+
/** Viewport height in px for vh, vmin, vmax. Auto: window.innerHeight in browser. */
|
|
19
|
+
viewportHeight?: number | undefined;
|
|
20
|
+
/** Line height in px for lh, rlh. */
|
|
21
|
+
lineHeight?: number | undefined;
|
|
22
|
+
/** Width of "0" character in px for ch. Default: ~0.5em. */
|
|
23
|
+
chWidth?: number | undefined;
|
|
24
|
+
/** Value that 100% equals (for % conversions). */
|
|
25
|
+
percentReference?: number | undefined;
|
|
26
|
+
/** Decimal places for output. Default: 4. */
|
|
27
|
+
precision?: number | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Context for createCssUnitConverter (pre-configured values).
|
|
31
|
+
*/
|
|
32
|
+
type CssUnitConverterContext = Omit<ConvertCssUnitOptions, 'fromUnit'>;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { ConvertCssUnitOptions, CssLengthUnit, CssUnitConverterContext };
|
|
35
|
+
//# sourceMappingURL=css-unit-converter.types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-unit-converter.types.d.cts","names":[],"sources":["../../src/units/css-unit-converter.types.ts"],"sourcesContent":[],"mappings":";;AAGA;AAqBA;AAwBY,KA7CA,aAAA,GA6CA,IAAuB,GAAA,IAAA,GAAQ,IAAA,GAAA,IAAA,GAAA,IAAA,GAAA,IAAL,GAAI,KAAA,GAAA,IAAA,GAAA,IAAA,GAAA,IAAA,GAAA,MAAA,GAAA,MAAA,GAAA,IAAA,GAAA,KAAA,GAAA,IAAA,GAAA,GAAA;;;;UAxBzB,qBAAA;;aAEL;;;;;;;;;;;;;;;;;;;;;KAsBA,uBAAA,GAA0B,KAAK"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/units/css-unit-converter.types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Supported CSS length units for conversion.
|
|
4
|
+
*/
|
|
5
|
+
type CssLengthUnit = 'px' | 'pt' | 'pc' | 'in' | 'cm' | 'mm' | 'rem' | 'em' | 'vw' | 'vh' | 'vmin' | 'vmax' | 'lh' | 'rlh' | 'ch' | '%';
|
|
6
|
+
/**
|
|
7
|
+
* Options for convertCssUnit.
|
|
8
|
+
*/
|
|
9
|
+
interface ConvertCssUnitOptions {
|
|
10
|
+
/** Override when value is number or unitless string. Default: 'px'. */
|
|
11
|
+
fromUnit?: CssLengthUnit | undefined;
|
|
12
|
+
/** Root font size in px for rem. Auto: getRemToPxScale() in browser. Default: 16. */
|
|
13
|
+
rootFontSize?: number | undefined;
|
|
14
|
+
/** Element font size in px for em. Default: 16. */
|
|
15
|
+
elementFontSize?: number | undefined;
|
|
16
|
+
/** Viewport width in px for vw, vmin, vmax. Auto: window.innerWidth in browser. */
|
|
17
|
+
viewportWidth?: number | undefined;
|
|
18
|
+
/** Viewport height in px for vh, vmin, vmax. Auto: window.innerHeight in browser. */
|
|
19
|
+
viewportHeight?: number | undefined;
|
|
20
|
+
/** Line height in px for lh, rlh. */
|
|
21
|
+
lineHeight?: number | undefined;
|
|
22
|
+
/** Width of "0" character in px for ch. Default: ~0.5em. */
|
|
23
|
+
chWidth?: number | undefined;
|
|
24
|
+
/** Value that 100% equals (for % conversions). */
|
|
25
|
+
percentReference?: number | undefined;
|
|
26
|
+
/** Decimal places for output. Default: 4. */
|
|
27
|
+
precision?: number | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Context for createCssUnitConverter (pre-configured values).
|
|
31
|
+
*/
|
|
32
|
+
type CssUnitConverterContext = Omit<ConvertCssUnitOptions, 'fromUnit'>;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { ConvertCssUnitOptions, CssLengthUnit, CssUnitConverterContext };
|
|
35
|
+
//# sourceMappingURL=css-unit-converter.types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-unit-converter.types.d.mts","names":[],"sources":["../../src/units/css-unit-converter.types.ts"],"sourcesContent":[],"mappings":";;AAGA;AAqBA;AAwBY,KA7CA,aAAA,GA6CA,IAAuB,GAAA,IAAA,GAAQ,IAAA,GAAA,IAAA,GAAA,IAAA,GAAA,IAAL,GAAI,KAAA,GAAA,IAAA,GAAA,IAAA,GAAA,IAAA,GAAA,MAAA,GAAA,MAAA,GAAA,IAAA,GAAA,KAAA,GAAA,IAAA,GAAA,GAAA;;;;UAxBzB,qBAAA;;aAEL;;;;;;;;;;;;;;;;;;;;;KAsBA,uBAAA,GAA0B,KAAK"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const require_parse_css_value = require('./parse-css-value.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/units/get-css-unit.ts
|
|
4
|
+
/**
|
|
5
|
+
* Extracts the unit from a CSS value string.
|
|
6
|
+
* Thin wrapper around parseCssValue.
|
|
7
|
+
*
|
|
8
|
+
* @param value - The CSS value to parse (e.g. '16px', '1.5rem', '100%'). Pass-through for null/undefined.
|
|
9
|
+
* @returns The unit string, undefined for numbers or unitless strings, or null/undefined when input is null/undefined
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* getCssUnit('16px') // 'px'
|
|
14
|
+
* getCssUnit('1rem') // 'rem'
|
|
15
|
+
* getCssUnit('100%') // '%'
|
|
16
|
+
* getCssUnit('0') // undefined
|
|
17
|
+
* getCssUnit('16') // undefined
|
|
18
|
+
* getCssUnit(null) // null
|
|
19
|
+
* getCssUnit(undefined) // undefined
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function getCssUnit(value) {
|
|
23
|
+
if (value === null || value === void 0) return value;
|
|
24
|
+
return require_parse_css_value.parseCssValue(value)[1];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.getCssUnit = getCssUnit;
|
|
29
|
+
//# sourceMappingURL=get-css-unit.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-css-unit.cjs","names":["parseCssValue"],"sources":["../../src/units/get-css-unit.ts"],"sourcesContent":["import { parseCssValue } from './parse-css-value.ts'\n\n/**\n * Extracts the unit from a CSS value string.\n * Thin wrapper around parseCssValue.\n *\n * @param value - The CSS value to parse (e.g. '16px', '1.5rem', '100%'). Pass-through for null/undefined.\n * @returns The unit string, undefined for numbers or unitless strings, or null/undefined when input is null/undefined\n *\n * @example\n * ```ts\n * getCssUnit('16px') // 'px'\n * getCssUnit('1rem') // 'rem'\n * getCssUnit('100%') // '%'\n * getCssUnit('0') // undefined\n * getCssUnit('16') // undefined\n * getCssUnit(null) // null\n * getCssUnit(undefined) // undefined\n * ```\n */\nexport function getCssUnit(value: number | string | null | undefined): string | null | undefined {\n\tif (value === null || value === undefined) return value\n\treturn parseCssValue(value)[1]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,WAAW,OAAsE;AAChG,KAAI,UAAU,QAAQ,UAAU,OAAW,QAAO;AAClD,QAAOA,sCAAc,MAAM,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/units/get-css-unit.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the unit from a CSS value string.
|
|
4
|
+
* Thin wrapper around parseCssValue.
|
|
5
|
+
*
|
|
6
|
+
* @param value - The CSS value to parse (e.g. '16px', '1.5rem', '100%'). Pass-through for null/undefined.
|
|
7
|
+
* @returns The unit string, undefined for numbers or unitless strings, or null/undefined when input is null/undefined
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* getCssUnit('16px') // 'px'
|
|
12
|
+
* getCssUnit('1rem') // 'rem'
|
|
13
|
+
* getCssUnit('100%') // '%'
|
|
14
|
+
* getCssUnit('0') // undefined
|
|
15
|
+
* getCssUnit('16') // undefined
|
|
16
|
+
* getCssUnit(null) // null
|
|
17
|
+
* getCssUnit(undefined) // undefined
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function getCssUnit(value: number | string | null | undefined): string | null | undefined;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { getCssUnit };
|
|
23
|
+
//# sourceMappingURL=get-css-unit.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-css-unit.d.cts","names":[],"sources":["../../src/units/get-css-unit.ts"],"sourcesContent":[],"mappings":";;AAoBA;;;;;;;;;;;;;;;;;iBAAgB,UAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/units/get-css-unit.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the unit from a CSS value string.
|
|
4
|
+
* Thin wrapper around parseCssValue.
|
|
5
|
+
*
|
|
6
|
+
* @param value - The CSS value to parse (e.g. '16px', '1.5rem', '100%'). Pass-through for null/undefined.
|
|
7
|
+
* @returns The unit string, undefined for numbers or unitless strings, or null/undefined when input is null/undefined
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* getCssUnit('16px') // 'px'
|
|
12
|
+
* getCssUnit('1rem') // 'rem'
|
|
13
|
+
* getCssUnit('100%') // '%'
|
|
14
|
+
* getCssUnit('0') // undefined
|
|
15
|
+
* getCssUnit('16') // undefined
|
|
16
|
+
* getCssUnit(null) // null
|
|
17
|
+
* getCssUnit(undefined) // undefined
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function getCssUnit(value: number | string | null | undefined): string | null | undefined;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { getCssUnit };
|
|
23
|
+
//# sourceMappingURL=get-css-unit.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-css-unit.d.mts","names":[],"sources":["../../src/units/get-css-unit.ts"],"sourcesContent":[],"mappings":";;AAoBA;;;;;;;;;;;;;;;;;iBAAgB,UAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { parseCssValue } from "./parse-css-value.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/units/get-css-unit.ts
|
|
4
|
+
/**
|
|
5
|
+
* Extracts the unit from a CSS value string.
|
|
6
|
+
* Thin wrapper around parseCssValue.
|
|
7
|
+
*
|
|
8
|
+
* @param value - The CSS value to parse (e.g. '16px', '1.5rem', '100%'). Pass-through for null/undefined.
|
|
9
|
+
* @returns The unit string, undefined for numbers or unitless strings, or null/undefined when input is null/undefined
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* getCssUnit('16px') // 'px'
|
|
14
|
+
* getCssUnit('1rem') // 'rem'
|
|
15
|
+
* getCssUnit('100%') // '%'
|
|
16
|
+
* getCssUnit('0') // undefined
|
|
17
|
+
* getCssUnit('16') // undefined
|
|
18
|
+
* getCssUnit(null) // null
|
|
19
|
+
* getCssUnit(undefined) // undefined
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function getCssUnit(value) {
|
|
23
|
+
if (value === null || value === void 0) return value;
|
|
24
|
+
return parseCssValue(value)[1];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { getCssUnit };
|
|
29
|
+
//# sourceMappingURL=get-css-unit.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-css-unit.mjs","names":[],"sources":["../../src/units/get-css-unit.ts"],"sourcesContent":["import { parseCssValue } from './parse-css-value.ts'\n\n/**\n * Extracts the unit from a CSS value string.\n * Thin wrapper around parseCssValue.\n *\n * @param value - The CSS value to parse (e.g. '16px', '1.5rem', '100%'). Pass-through for null/undefined.\n * @returns The unit string, undefined for numbers or unitless strings, or null/undefined when input is null/undefined\n *\n * @example\n * ```ts\n * getCssUnit('16px') // 'px'\n * getCssUnit('1rem') // 'rem'\n * getCssUnit('100%') // '%'\n * getCssUnit('0') // undefined\n * getCssUnit('16') // undefined\n * getCssUnit(null) // null\n * getCssUnit(undefined) // undefined\n * ```\n */\nexport function getCssUnit(value: number | string | null | undefined): string | null | undefined {\n\tif (value === null || value === undefined) return value\n\treturn parseCssValue(value)[1]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,WAAW,OAAsE;AAChG,KAAI,UAAU,QAAQ,UAAU,OAAW,QAAO;AAClD,QAAO,cAAc,MAAM,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const require_parse_css_number = require('./parse-css-number.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/units/is-effectively-zero.ts
|
|
4
|
+
/**
|
|
5
|
+
* Determines if a CSS value is effectively 0 regardless of unit.
|
|
6
|
+
*
|
|
7
|
+
* @param value - The CSS value to check. Can be a number or string (e.g. '0px', '0rem', '0%'). Pass-through for null/undefined.
|
|
8
|
+
* @param options - Optional configuration
|
|
9
|
+
* @param options.epsilon - Floating-point tolerance. Default 1e-10. Use 0 for strict equality.
|
|
10
|
+
* @returns true if the value is effectively zero, false otherwise, or null/undefined when input is null/undefined
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* isEffectivelyZero(0) // true
|
|
15
|
+
* isEffectivelyZero('0px') // true
|
|
16
|
+
* isEffectivelyZero('0rem') // true
|
|
17
|
+
* isEffectivelyZero('0%') // true
|
|
18
|
+
* isEffectivelyZero('1px') // false
|
|
19
|
+
* isEffectivelyZero(0.00000000001) // true (within default epsilon)
|
|
20
|
+
* isEffectivelyZero(0.0001, { epsilon: 0.001 }) // true
|
|
21
|
+
* isEffectivelyZero(null) // null
|
|
22
|
+
* isEffectivelyZero(undefined) // undefined
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function isEffectivelyZero(value, options) {
|
|
26
|
+
const parsed = require_parse_css_number.parseCssNumber(value);
|
|
27
|
+
if (parsed === null || parsed === void 0) return parsed;
|
|
28
|
+
if (!Number.isFinite(parsed)) return false;
|
|
29
|
+
const epsilon = options?.epsilon ?? 1e-10;
|
|
30
|
+
return Math.abs(parsed) <= epsilon;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
exports.isEffectivelyZero = isEffectivelyZero;
|
|
35
|
+
//# sourceMappingURL=is-effectively-zero.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-effectively-zero.cjs","names":["parseCssNumber"],"sources":["../../src/units/is-effectively-zero.ts"],"sourcesContent":["import { parseCssNumber } from './parse-css-number.ts'\n\n/**\n * Determines if a CSS value is effectively 0 regardless of unit.\n *\n * @param value - The CSS value to check. Can be a number or string (e.g. '0px', '0rem', '0%'). Pass-through for null/undefined.\n * @param options - Optional configuration\n * @param options.epsilon - Floating-point tolerance. Default 1e-10. Use 0 for strict equality.\n * @returns true if the value is effectively zero, false otherwise, or null/undefined when input is null/undefined\n *\n * @example\n * ```ts\n * isEffectivelyZero(0) // true\n * isEffectivelyZero('0px') // true\n * isEffectivelyZero('0rem') // true\n * isEffectivelyZero('0%') // true\n * isEffectivelyZero('1px') // false\n * isEffectivelyZero(0.00000000001) // true (within default epsilon)\n * isEffectivelyZero(0.0001, { epsilon: 0.001 }) // true\n * isEffectivelyZero(null) // null\n * isEffectivelyZero(undefined) // undefined\n * ```\n */\nexport function isEffectivelyZero(\n\tvalue: number | string | null | undefined,\n\toptions?: { epsilon?: number | undefined } | undefined\n): boolean | null | undefined {\n\tconst parsed = parseCssNumber(value)\n\tif (parsed === null || parsed === undefined) return parsed\n\tif (!Number.isFinite(parsed)) {\n\t\treturn false\n\t}\n\tconst epsilon = options?.epsilon ?? 1e-10\n\treturn Math.abs(parsed) <= epsilon\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,kBACf,OACA,SAC6B;CAC7B,MAAM,SAASA,wCAAe,MAAM;AACpC,KAAI,WAAW,QAAQ,WAAW,OAAW,QAAO;AACpD,KAAI,CAAC,OAAO,SAAS,OAAO,CAC3B,QAAO;CAER,MAAM,UAAU,SAAS,WAAW;AACpC,QAAO,KAAK,IAAI,OAAO,IAAI"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/units/is-effectively-zero.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Determines if a CSS value is effectively 0 regardless of unit.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The CSS value to check. Can be a number or string (e.g. '0px', '0rem', '0%'). Pass-through for null/undefined.
|
|
6
|
+
* @param options - Optional configuration
|
|
7
|
+
* @param options.epsilon - Floating-point tolerance. Default 1e-10. Use 0 for strict equality.
|
|
8
|
+
* @returns true if the value is effectively zero, false otherwise, or null/undefined when input is null/undefined
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* isEffectivelyZero(0) // true
|
|
13
|
+
* isEffectivelyZero('0px') // true
|
|
14
|
+
* isEffectivelyZero('0rem') // true
|
|
15
|
+
* isEffectivelyZero('0%') // true
|
|
16
|
+
* isEffectivelyZero('1px') // false
|
|
17
|
+
* isEffectivelyZero(0.00000000001) // true (within default epsilon)
|
|
18
|
+
* isEffectivelyZero(0.0001, { epsilon: 0.001 }) // true
|
|
19
|
+
* isEffectivelyZero(null) // null
|
|
20
|
+
* isEffectivelyZero(undefined) // undefined
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare function isEffectivelyZero(value: number | string | null | undefined, options?: {
|
|
24
|
+
epsilon?: number | undefined;
|
|
25
|
+
} | undefined): boolean | null | undefined;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { isEffectivelyZero };
|
|
28
|
+
//# sourceMappingURL=is-effectively-zero.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-effectively-zero.d.cts","names":[],"sources":["../../src/units/is-effectively-zero.ts"],"sourcesContent":[],"mappings":";;AAuBA;;;;;;;;;;;;;;;;;;;;iBAAgB,iBAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/units/is-effectively-zero.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Determines if a CSS value is effectively 0 regardless of unit.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The CSS value to check. Can be a number or string (e.g. '0px', '0rem', '0%'). Pass-through for null/undefined.
|
|
6
|
+
* @param options - Optional configuration
|
|
7
|
+
* @param options.epsilon - Floating-point tolerance. Default 1e-10. Use 0 for strict equality.
|
|
8
|
+
* @returns true if the value is effectively zero, false otherwise, or null/undefined when input is null/undefined
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* isEffectivelyZero(0) // true
|
|
13
|
+
* isEffectivelyZero('0px') // true
|
|
14
|
+
* isEffectivelyZero('0rem') // true
|
|
15
|
+
* isEffectivelyZero('0%') // true
|
|
16
|
+
* isEffectivelyZero('1px') // false
|
|
17
|
+
* isEffectivelyZero(0.00000000001) // true (within default epsilon)
|
|
18
|
+
* isEffectivelyZero(0.0001, { epsilon: 0.001 }) // true
|
|
19
|
+
* isEffectivelyZero(null) // null
|
|
20
|
+
* isEffectivelyZero(undefined) // undefined
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare function isEffectivelyZero(value: number | string | null | undefined, options?: {
|
|
24
|
+
epsilon?: number | undefined;
|
|
25
|
+
} | undefined): boolean | null | undefined;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { isEffectivelyZero };
|
|
28
|
+
//# sourceMappingURL=is-effectively-zero.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-effectively-zero.d.mts","names":[],"sources":["../../src/units/is-effectively-zero.ts"],"sourcesContent":[],"mappings":";;AAuBA;;;;;;;;;;;;;;;;;;;;iBAAgB,iBAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { parseCssNumber } from "./parse-css-number.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/units/is-effectively-zero.ts
|
|
4
|
+
/**
|
|
5
|
+
* Determines if a CSS value is effectively 0 regardless of unit.
|
|
6
|
+
*
|
|
7
|
+
* @param value - The CSS value to check. Can be a number or string (e.g. '0px', '0rem', '0%'). Pass-through for null/undefined.
|
|
8
|
+
* @param options - Optional configuration
|
|
9
|
+
* @param options.epsilon - Floating-point tolerance. Default 1e-10. Use 0 for strict equality.
|
|
10
|
+
* @returns true if the value is effectively zero, false otherwise, or null/undefined when input is null/undefined
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* isEffectivelyZero(0) // true
|
|
15
|
+
* isEffectivelyZero('0px') // true
|
|
16
|
+
* isEffectivelyZero('0rem') // true
|
|
17
|
+
* isEffectivelyZero('0%') // true
|
|
18
|
+
* isEffectivelyZero('1px') // false
|
|
19
|
+
* isEffectivelyZero(0.00000000001) // true (within default epsilon)
|
|
20
|
+
* isEffectivelyZero(0.0001, { epsilon: 0.001 }) // true
|
|
21
|
+
* isEffectivelyZero(null) // null
|
|
22
|
+
* isEffectivelyZero(undefined) // undefined
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function isEffectivelyZero(value, options) {
|
|
26
|
+
const parsed = parseCssNumber(value);
|
|
27
|
+
if (parsed === null || parsed === void 0) return parsed;
|
|
28
|
+
if (!Number.isFinite(parsed)) return false;
|
|
29
|
+
const epsilon = options?.epsilon ?? 1e-10;
|
|
30
|
+
return Math.abs(parsed) <= epsilon;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { isEffectivelyZero };
|
|
35
|
+
//# sourceMappingURL=is-effectively-zero.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-effectively-zero.mjs","names":[],"sources":["../../src/units/is-effectively-zero.ts"],"sourcesContent":["import { parseCssNumber } from './parse-css-number.ts'\n\n/**\n * Determines if a CSS value is effectively 0 regardless of unit.\n *\n * @param value - The CSS value to check. Can be a number or string (e.g. '0px', '0rem', '0%'). Pass-through for null/undefined.\n * @param options - Optional configuration\n * @param options.epsilon - Floating-point tolerance. Default 1e-10. Use 0 for strict equality.\n * @returns true if the value is effectively zero, false otherwise, or null/undefined when input is null/undefined\n *\n * @example\n * ```ts\n * isEffectivelyZero(0) // true\n * isEffectivelyZero('0px') // true\n * isEffectivelyZero('0rem') // true\n * isEffectivelyZero('0%') // true\n * isEffectivelyZero('1px') // false\n * isEffectivelyZero(0.00000000001) // true (within default epsilon)\n * isEffectivelyZero(0.0001, { epsilon: 0.001 }) // true\n * isEffectivelyZero(null) // null\n * isEffectivelyZero(undefined) // undefined\n * ```\n */\nexport function isEffectivelyZero(\n\tvalue: number | string | null | undefined,\n\toptions?: { epsilon?: number | undefined } | undefined\n): boolean | null | undefined {\n\tconst parsed = parseCssNumber(value)\n\tif (parsed === null || parsed === undefined) return parsed\n\tif (!Number.isFinite(parsed)) {\n\t\treturn false\n\t}\n\tconst epsilon = options?.epsilon ?? 1e-10\n\treturn Math.abs(parsed) <= epsilon\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,kBACf,OACA,SAC6B;CAC7B,MAAM,SAAS,eAAe,MAAM;AACpC,KAAI,WAAW,QAAQ,WAAW,OAAW,QAAO;AACpD,KAAI,CAAC,OAAO,SAAS,OAAO,CAC3B,QAAO;CAER,MAAM,UAAU,SAAS,WAAW;AACpC,QAAO,KAAK,IAAI,OAAO,IAAI"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const require_parse_css_value = require('./parse-css-value.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/units/parse-css-number.ts
|
|
4
|
+
/**
|
|
5
|
+
* Extracts the numeric part from any CSS length/percentage value.
|
|
6
|
+
* Thin wrapper around parseCssValue.
|
|
7
|
+
*
|
|
8
|
+
* @param value - The CSS value to parse. Can be a number or string (e.g. '16px', '1.5rem', '100%')
|
|
9
|
+
* @returns The numeric value, or NaN for invalid input. Passes through null and undefined.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* parseCssNumber('16px') // 16
|
|
14
|
+
* parseCssNumber('1.5rem') // 1.5
|
|
15
|
+
* parseCssNumber('100%') // 100
|
|
16
|
+
* parseCssNumber('0lh') // 0
|
|
17
|
+
* parseCssNumber(16) // 16
|
|
18
|
+
* parseCssNumber('abc') // NaN
|
|
19
|
+
* parseCssNumber(null) // null
|
|
20
|
+
* parseCssNumber(undefined) // undefined
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function parseCssNumber(value) {
|
|
24
|
+
return require_parse_css_value.parseCssValue(value)[0];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.parseCssNumber = parseCssNumber;
|
|
29
|
+
//# sourceMappingURL=parse-css-number.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-css-number.cjs","names":["parseCssValue"],"sources":["../../src/units/parse-css-number.ts"],"sourcesContent":["import { parseCssValue } from './parse-css-value.ts'\n\n/**\n * Extracts the numeric part from any CSS length/percentage value.\n * Thin wrapper around parseCssValue.\n *\n * @param value - The CSS value to parse. Can be a number or string (e.g. '16px', '1.5rem', '100%')\n * @returns The numeric value, or NaN for invalid input. Passes through null and undefined.\n *\n * @example\n * ```ts\n * parseCssNumber('16px') // 16\n * parseCssNumber('1.5rem') // 1.5\n * parseCssNumber('100%') // 100\n * parseCssNumber('0lh') // 0\n * parseCssNumber(16) // 16\n * parseCssNumber('abc') // NaN\n * parseCssNumber(null) // null\n * parseCssNumber(undefined) // undefined\n * ```\n */\nexport function parseCssNumber(\n\tvalue: number | string | null | undefined\n): number | null | undefined {\n\treturn parseCssValue(value)[0]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,eACf,OAC4B;AAC5B,QAAOA,sCAAc,MAAM,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/units/parse-css-number.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the numeric part from any CSS length/percentage value.
|
|
4
|
+
* Thin wrapper around parseCssValue.
|
|
5
|
+
*
|
|
6
|
+
* @param value - The CSS value to parse. Can be a number or string (e.g. '16px', '1.5rem', '100%')
|
|
7
|
+
* @returns The numeric value, or NaN for invalid input. Passes through null and undefined.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* parseCssNumber('16px') // 16
|
|
12
|
+
* parseCssNumber('1.5rem') // 1.5
|
|
13
|
+
* parseCssNumber('100%') // 100
|
|
14
|
+
* parseCssNumber('0lh') // 0
|
|
15
|
+
* parseCssNumber(16) // 16
|
|
16
|
+
* parseCssNumber('abc') // NaN
|
|
17
|
+
* parseCssNumber(null) // null
|
|
18
|
+
* parseCssNumber(undefined) // undefined
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function parseCssNumber(value: number | string | null | undefined): number | null | undefined;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { parseCssNumber };
|
|
24
|
+
//# sourceMappingURL=parse-css-number.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-css-number.d.cts","names":[],"sources":["../../src/units/parse-css-number.ts"],"sourcesContent":[],"mappings":";;AAqBA;;;;;;;;;;;;;;;;;;iBAAgB,cAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/units/parse-css-number.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the numeric part from any CSS length/percentage value.
|
|
4
|
+
* Thin wrapper around parseCssValue.
|
|
5
|
+
*
|
|
6
|
+
* @param value - The CSS value to parse. Can be a number or string (e.g. '16px', '1.5rem', '100%')
|
|
7
|
+
* @returns The numeric value, or NaN for invalid input. Passes through null and undefined.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* parseCssNumber('16px') // 16
|
|
12
|
+
* parseCssNumber('1.5rem') // 1.5
|
|
13
|
+
* parseCssNumber('100%') // 100
|
|
14
|
+
* parseCssNumber('0lh') // 0
|
|
15
|
+
* parseCssNumber(16) // 16
|
|
16
|
+
* parseCssNumber('abc') // NaN
|
|
17
|
+
* parseCssNumber(null) // null
|
|
18
|
+
* parseCssNumber(undefined) // undefined
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function parseCssNumber(value: number | string | null | undefined): number | null | undefined;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { parseCssNumber };
|
|
24
|
+
//# sourceMappingURL=parse-css-number.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-css-number.d.mts","names":[],"sources":["../../src/units/parse-css-number.ts"],"sourcesContent":[],"mappings":";;AAqBA;;;;;;;;;;;;;;;;;;iBAAgB,cAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { parseCssValue } from "./parse-css-value.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/units/parse-css-number.ts
|
|
4
|
+
/**
|
|
5
|
+
* Extracts the numeric part from any CSS length/percentage value.
|
|
6
|
+
* Thin wrapper around parseCssValue.
|
|
7
|
+
*
|
|
8
|
+
* @param value - The CSS value to parse. Can be a number or string (e.g. '16px', '1.5rem', '100%')
|
|
9
|
+
* @returns The numeric value, or NaN for invalid input. Passes through null and undefined.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* parseCssNumber('16px') // 16
|
|
14
|
+
* parseCssNumber('1.5rem') // 1.5
|
|
15
|
+
* parseCssNumber('100%') // 100
|
|
16
|
+
* parseCssNumber('0lh') // 0
|
|
17
|
+
* parseCssNumber(16) // 16
|
|
18
|
+
* parseCssNumber('abc') // NaN
|
|
19
|
+
* parseCssNumber(null) // null
|
|
20
|
+
* parseCssNumber(undefined) // undefined
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function parseCssNumber(value) {
|
|
24
|
+
return parseCssValue(value)[0];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { parseCssNumber };
|
|
29
|
+
//# sourceMappingURL=parse-css-number.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-css-number.mjs","names":[],"sources":["../../src/units/parse-css-number.ts"],"sourcesContent":["import { parseCssValue } from './parse-css-value.ts'\n\n/**\n * Extracts the numeric part from any CSS length/percentage value.\n * Thin wrapper around parseCssValue.\n *\n * @param value - The CSS value to parse. Can be a number or string (e.g. '16px', '1.5rem', '100%')\n * @returns The numeric value, or NaN for invalid input. Passes through null and undefined.\n *\n * @example\n * ```ts\n * parseCssNumber('16px') // 16\n * parseCssNumber('1.5rem') // 1.5\n * parseCssNumber('100%') // 100\n * parseCssNumber('0lh') // 0\n * parseCssNumber(16) // 16\n * parseCssNumber('abc') // NaN\n * parseCssNumber(null) // null\n * parseCssNumber(undefined) // undefined\n * ```\n */\nexport function parseCssNumber(\n\tvalue: number | string | null | undefined\n): number | null | undefined {\n\treturn parseCssValue(value)[0]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,eACf,OAC4B;AAC5B,QAAO,cAAc,MAAM,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/units/parse-css-value.ts
|
|
3
|
+
/**
|
|
4
|
+
* Parses a CSS value in one pass and returns both the numeric part and the unit.
|
|
5
|
+
* Powers parseCssNumber, getCssUnit, and isEffectivelyZero.
|
|
6
|
+
*
|
|
7
|
+
* @param value - The CSS value to parse. Can be a number or string (e.g. '16px', '1.5rem', '100%')
|
|
8
|
+
* @returns A tuple of [number, unit | undefined]. Unit is undefined for numbers or unitless strings.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* parseCssValue('16px') // [16, 'px']
|
|
13
|
+
* parseCssValue('1.5rem') // [1.5, 'rem']
|
|
14
|
+
* parseCssValue('100%') // [100, '%']
|
|
15
|
+
* parseCssValue('0') // [0, undefined]
|
|
16
|
+
* parseCssValue(16) // [16, undefined]
|
|
17
|
+
* parseCssValue('abc') // [NaN, undefined]
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
function parseCssValue(value) {
|
|
21
|
+
if (value === void 0 || value === null) return [value, void 0];
|
|
22
|
+
if (typeof value === "number") return [value, void 0];
|
|
23
|
+
const match = String(value).trim().match(/^(-?\d*\.?\d+)\s*(.*)$/);
|
|
24
|
+
if (!match) return [NaN, void 0];
|
|
25
|
+
const num = Number.parseFloat(match[1] ?? "");
|
|
26
|
+
const unit = (match[2] ?? "").trim();
|
|
27
|
+
return [num, unit === "" ? void 0 : unit];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
exports.parseCssValue = parseCssValue;
|
|
32
|
+
//# sourceMappingURL=parse-css-value.cjs.map
|