@just-web/css 0.5.0 → 0.6.1
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/cjs/convertors/px_2_rem.d.ts +21 -0
- package/cjs/convertors/px_2_rem.js +17 -0
- package/cjs/convertors/rem_2_px.d.ts +21 -0
- package/cjs/convertors/rem_2_px.js +17 -0
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +22 -0
- package/cjs/tailwind.css +1 -1
- package/cjs/testing/log-panel.js +1 -1
- package/esm/convertors/px_2_rem.d.ts +22 -0
- package/esm/convertors/px_2_rem.d.ts.map +1 -0
- package/esm/convertors/px_2_rem.js +26 -0
- package/esm/convertors/px_2_rem.js.map +1 -0
- package/esm/convertors/rem_2_px.d.ts +22 -0
- package/esm/convertors/rem_2_px.d.ts.map +1 -0
- package/esm/convertors/rem_2_px.js +26 -0
- package/esm/convertors/rem_2_px.js.map +1 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +2 -0
- package/esm/index.js.map +1 -1
- package/esm/testing/log-panel.js +1 -1
- package/esm/testing/log-panel.js.map +1 -1
- package/package.json +2 -2
- package/src/convertors/px_2_rem.ts +30 -0
- package/src/convertors/rem_2_px.ts +30 -0
- package/src/index.ts +2 -0
- package/src/tailwind.css +3 -1
- package/src/testing/log-panel.tsx +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts pixel values to rem units.
|
|
3
|
+
*
|
|
4
|
+
* @param px - The pixel value to convert. Can be a number or string (e.g. '16px' or '16')
|
|
5
|
+
* @param options - Optional configuration
|
|
6
|
+
* @param options.base - Base pixel value to calculate rem units from. Defaults to 16
|
|
7
|
+
* @param options.precision - Number of decimal places in the output. Defaults to 4
|
|
8
|
+
* @returns The converted value as a string with 'rem' units
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* px2rem(16) // '1.0000'
|
|
13
|
+
* px2rem('32px') // '2.0000'
|
|
14
|
+
* px2rem(20, { base: 20 }) // '1.0000'
|
|
15
|
+
* px2rem(13, { precision: 2 }) // '0.81'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function px2rem(px: number | string, options?: {
|
|
19
|
+
base?: number | undefined;
|
|
20
|
+
precision?: number | undefined;
|
|
21
|
+
}): number;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.px2rem = px2rem;
|
|
7
|
+
function px2rem(px, options) {
|
|
8
|
+
const {
|
|
9
|
+
base = 16,
|
|
10
|
+
precision = 4
|
|
11
|
+
} = options ?? {};
|
|
12
|
+
if (typeof px === "string") {
|
|
13
|
+
px = px.replace(/px$/, "");
|
|
14
|
+
px = Number.parseFloat(px);
|
|
15
|
+
}
|
|
16
|
+
return Number((px / base).toFixed(precision));
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts rem values to pixel units.
|
|
3
|
+
*
|
|
4
|
+
* @param rem - The rem value to convert. Can be a number or string (e.g. '1rem' or '1')
|
|
5
|
+
* @param options - Optional configuration
|
|
6
|
+
* @param options.base - Base pixel value to calculate pixels from. Defaults to 16
|
|
7
|
+
* @param options.precision - Number of decimal places in the output. Defaults to 4
|
|
8
|
+
* @returns The converted value as a string with 'px' units
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* rem2px(1) // '16.0000'
|
|
13
|
+
* rem2px('2rem') // '32.0000'
|
|
14
|
+
* rem2px(1, { base: 20 }) // '20.0000'
|
|
15
|
+
* rem2px(0.8125, { precision: 2 }) // '13.00'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function rem2px(rem: number | string, options?: {
|
|
19
|
+
base?: number | undefined;
|
|
20
|
+
precision?: number | undefined;
|
|
21
|
+
}): number;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.rem2px = rem2px;
|
|
7
|
+
function rem2px(rem, options) {
|
|
8
|
+
const {
|
|
9
|
+
base = 16,
|
|
10
|
+
precision = 4
|
|
11
|
+
} = options ?? {};
|
|
12
|
+
if (typeof rem === "string") {
|
|
13
|
+
rem = rem.replace(/rem$/, "");
|
|
14
|
+
rem = Number.parseFloat(rem);
|
|
15
|
+
}
|
|
16
|
+
return Number((rem * base).toFixed(precision));
|
|
17
|
+
}
|
package/cjs/index.d.ts
CHANGED
package/cjs/index.js
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _px_2_rem = require("./convertors/px_2_rem.ts");
|
|
7
|
+
Object.keys(_px_2_rem).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _px_2_rem[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _px_2_rem[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _rem_2_px = require("./convertors/rem_2_px.ts");
|
|
18
|
+
Object.keys(_rem_2_px).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _rem_2_px[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _rem_2_px[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
6
28
|
var _cssProperties = require("./css-properties/css-properties.ts");
|
|
7
29
|
Object.keys(_cssProperties).forEach(function (key) {
|
|
8
30
|
if (key === "default" || key === "__esModule") return;
|
package/cjs/tailwind.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@import "tailwindcss";
|
|
1
|
+
@import "tailwindcss";@custom-variant dark (&:where(.dark, .dark *));
|
package/cjs/testing/log-panel.js
CHANGED
|
@@ -9,7 +9,7 @@ function LogPanel({
|
|
|
9
9
|
log
|
|
10
10
|
}) {
|
|
11
11
|
return /* @__PURE__ */React.createElement("div", {
|
|
12
|
-
className: "bg-neutral-100 p-4 rounded overflow-y-auto"
|
|
12
|
+
className: "bg-neutral-100 dark:bg-neutral-900 p-4 rounded overflow-y-auto"
|
|
13
13
|
}, /* @__PURE__ */React.createElement("h4", {
|
|
14
14
|
className: "mb-2"
|
|
15
15
|
}, title), log.map((entry, i) => /* @__PURE__ */React.createElement("pre", {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts pixel values to rem units.
|
|
3
|
+
*
|
|
4
|
+
* @param px - The pixel value to convert. Can be a number or string (e.g. '16px' or '16')
|
|
5
|
+
* @param options - Optional configuration
|
|
6
|
+
* @param options.base - Base pixel value to calculate rem units from. Defaults to 16
|
|
7
|
+
* @param options.precision - Number of decimal places in the output. Defaults to 4
|
|
8
|
+
* @returns The converted value as a string with 'rem' units
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* px2rem(16) // '1.0000'
|
|
13
|
+
* px2rem('32px') // '2.0000'
|
|
14
|
+
* px2rem(20, { base: 20 }) // '1.0000'
|
|
15
|
+
* px2rem(13, { precision: 2 }) // '0.81'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function px2rem(px: number | string, options?: {
|
|
19
|
+
base?: number | undefined;
|
|
20
|
+
precision?: number | undefined;
|
|
21
|
+
}): number;
|
|
22
|
+
//# sourceMappingURL=px_2_rem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"px_2_rem.d.ts","sourceRoot":"","sources":["../../src/convertors/px_2_rem.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CACrB,EAAE,EAAE,MAAM,GAAG,MAAM,EACnB,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACrE,MAAM,CASR"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts pixel values to rem units.
|
|
3
|
+
*
|
|
4
|
+
* @param px - The pixel value to convert. Can be a number or string (e.g. '16px' or '16')
|
|
5
|
+
* @param options - Optional configuration
|
|
6
|
+
* @param options.base - Base pixel value to calculate rem units from. Defaults to 16
|
|
7
|
+
* @param options.precision - Number of decimal places in the output. Defaults to 4
|
|
8
|
+
* @returns The converted value as a string with 'rem' units
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* px2rem(16) // '1.0000'
|
|
13
|
+
* px2rem('32px') // '2.0000'
|
|
14
|
+
* px2rem(20, { base: 20 }) // '1.0000'
|
|
15
|
+
* px2rem(13, { precision: 2 }) // '0.81'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function px2rem(px, options) {
|
|
19
|
+
const { base = 16, precision = 4 } = options ?? {};
|
|
20
|
+
if (typeof px === 'string') {
|
|
21
|
+
px = px.replace(/px$/, '');
|
|
22
|
+
px = Number.parseFloat(px);
|
|
23
|
+
}
|
|
24
|
+
return Number((px / base).toFixed(precision));
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=px_2_rem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"px_2_rem.js","sourceRoot":"","sources":["../../src/convertors/px_2_rem.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,MAAM,CACrB,EAAmB,EACnB,OAAuE;IAEvE,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,SAAS,GAAG,CAAC,EAAE,GAAG,OAAO,IAAI,EAAE,CAAA;IAElD,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;QAC5B,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QAC1B,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IAC3B,CAAC;IAED,OAAO,MAAM,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;AAC9C,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts rem values to pixel units.
|
|
3
|
+
*
|
|
4
|
+
* @param rem - The rem value to convert. Can be a number or string (e.g. '1rem' or '1')
|
|
5
|
+
* @param options - Optional configuration
|
|
6
|
+
* @param options.base - Base pixel value to calculate pixels from. Defaults to 16
|
|
7
|
+
* @param options.precision - Number of decimal places in the output. Defaults to 4
|
|
8
|
+
* @returns The converted value as a string with 'px' units
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* rem2px(1) // '16.0000'
|
|
13
|
+
* rem2px('2rem') // '32.0000'
|
|
14
|
+
* rem2px(1, { base: 20 }) // '20.0000'
|
|
15
|
+
* rem2px(0.8125, { precision: 2 }) // '13.00'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function rem2px(rem: number | string, options?: {
|
|
19
|
+
base?: number | undefined;
|
|
20
|
+
precision?: number | undefined;
|
|
21
|
+
}): number;
|
|
22
|
+
//# sourceMappingURL=rem_2_px.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rem_2_px.d.ts","sourceRoot":"","sources":["../../src/convertors/rem_2_px.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CACrB,GAAG,EAAE,MAAM,GAAG,MAAM,EACpB,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACrE,MAAM,CASR"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts rem values to pixel units.
|
|
3
|
+
*
|
|
4
|
+
* @param rem - The rem value to convert. Can be a number or string (e.g. '1rem' or '1')
|
|
5
|
+
* @param options - Optional configuration
|
|
6
|
+
* @param options.base - Base pixel value to calculate pixels from. Defaults to 16
|
|
7
|
+
* @param options.precision - Number of decimal places in the output. Defaults to 4
|
|
8
|
+
* @returns The converted value as a string with 'px' units
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* rem2px(1) // '16.0000'
|
|
13
|
+
* rem2px('2rem') // '32.0000'
|
|
14
|
+
* rem2px(1, { base: 20 }) // '20.0000'
|
|
15
|
+
* rem2px(0.8125, { precision: 2 }) // '13.00'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function rem2px(rem, options) {
|
|
19
|
+
const { base = 16, precision = 4 } = options ?? {};
|
|
20
|
+
if (typeof rem === 'string') {
|
|
21
|
+
rem = rem.replace(/rem$/, '');
|
|
22
|
+
rem = Number.parseFloat(rem);
|
|
23
|
+
}
|
|
24
|
+
return Number((rem * base).toFixed(precision));
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=rem_2_px.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rem_2_px.js","sourceRoot":"","sources":["../../src/convertors/rem_2_px.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,MAAM,CACrB,GAAoB,EACpB,OAAuE;IAEvE,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,SAAS,GAAG,CAAC,EAAE,GAAG,OAAO,IAAI,EAAE,CAAA;IAElD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC7B,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QAC7B,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;IAC7B,CAAC;IAED,OAAO,MAAM,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;AAC/C,CAAC"}
|
package/esm/index.d.ts
CHANGED
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA;AAClD,cAAc,kCAAkC,CAAA;AAChD,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAChC,cAAc,uBAAuB,CAAA;AACrC,cAAc,2BAA2B,CAAA;AACzC,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,iCAAiC,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AACxC,cAAc,oCAAoC,CAAA;AAClD,cAAc,kCAAkC,CAAA;AAChD,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAChC,cAAc,uBAAuB,CAAA;AACrC,cAAc,2BAA2B,CAAA;AACzC,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,iCAAiC,CAAA"}
|
package/esm/index.js
CHANGED
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA;AAClD,cAAc,kCAAkC,CAAA;AAChD,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAChC,cAAc,uBAAuB,CAAA;AACrC,cAAc,2BAA2B,CAAA;AACzC,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,iCAAiC,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AACxC,cAAc,oCAAoC,CAAA;AAClD,cAAc,kCAAkC,CAAA;AAChD,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAChC,cAAc,uBAAuB,CAAA;AACrC,cAAc,2BAA2B,CAAA;AACzC,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,iCAAiC,CAAA"}
|
package/esm/testing/log-panel.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
export function LogPanel({ title, log }) {
|
|
3
|
-
return (_jsxs("div", { className: "bg-neutral-100 p-4 rounded overflow-y-auto", children: [_jsx("h4", { className: "mb-2", children: title }), log.map((entry, i) => (_jsx("pre", { className: "font-mono", children: entry }, i)))] }));
|
|
3
|
+
return (_jsxs("div", { className: "bg-neutral-100 dark:bg-neutral-900 p-4 rounded overflow-y-auto", children: [_jsx("h4", { className: "mb-2", children: title }), log.map((entry, i) => (_jsx("pre", { className: "font-mono", children: entry }, i)))] }));
|
|
4
4
|
}
|
|
5
5
|
//# sourceMappingURL=log-panel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-panel.js","sourceRoot":"","sources":["../../src/testing/log-panel.tsx"],"names":[],"mappings":";AAAA,MAAM,UAAU,QAAQ,CAAC,EAAE,KAAK,EAAE,GAAG,EAAoC;IACxE,OAAO,CACN,eAAK,SAAS,EAAC,
|
|
1
|
+
{"version":3,"file":"log-panel.js","sourceRoot":"","sources":["../../src/testing/log-panel.tsx"],"names":[],"mappings":";AAAA,MAAM,UAAU,QAAQ,CAAC,EAAE,KAAK,EAAE,GAAG,EAAoC;IACxE,OAAO,CACN,eAAK,SAAS,EAAC,gEAAgE,aAC9E,aAAI,SAAS,EAAC,MAAM,YAAE,KAAK,GAAM,EAChC,GAAG,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CACtB,cAAa,SAAS,EAAC,WAAW,YAChC,KAAK,IADG,CAAC,CAEL,CACN,CAAC,IACG,CACN,CAAA;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@just-web/css",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "CSS types and utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"type-plus": "8.0.0-beta.7"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@repobuddy/storybook": "^0.
|
|
27
|
+
"@repobuddy/storybook": "^0.12.0",
|
|
28
28
|
"@repobuddy/vitest": "^1.2.2",
|
|
29
29
|
"@storybook/addon-essentials": "^8.6.12",
|
|
30
30
|
"@storybook/addon-storysource": "^8.6.12",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts pixel values to rem units.
|
|
3
|
+
*
|
|
4
|
+
* @param px - The pixel value to convert. Can be a number or string (e.g. '16px' or '16')
|
|
5
|
+
* @param options - Optional configuration
|
|
6
|
+
* @param options.base - Base pixel value to calculate rem units from. Defaults to 16
|
|
7
|
+
* @param options.precision - Number of decimal places in the output. Defaults to 4
|
|
8
|
+
* @returns The converted value as a string with 'rem' units
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* px2rem(16) // '1.0000'
|
|
13
|
+
* px2rem('32px') // '2.0000'
|
|
14
|
+
* px2rem(20, { base: 20 }) // '1.0000'
|
|
15
|
+
* px2rem(13, { precision: 2 }) // '0.81'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function px2rem(
|
|
19
|
+
px: number | string,
|
|
20
|
+
options?: { base?: number | undefined; precision?: number | undefined },
|
|
21
|
+
): number {
|
|
22
|
+
const { base = 16, precision = 4 } = options ?? {}
|
|
23
|
+
|
|
24
|
+
if (typeof px === 'string') {
|
|
25
|
+
px = px.replace(/px$/, '')
|
|
26
|
+
px = Number.parseFloat(px)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return Number((px / base).toFixed(precision))
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts rem values to pixel units.
|
|
3
|
+
*
|
|
4
|
+
* @param rem - The rem value to convert. Can be a number or string (e.g. '1rem' or '1')
|
|
5
|
+
* @param options - Optional configuration
|
|
6
|
+
* @param options.base - Base pixel value to calculate pixels from. Defaults to 16
|
|
7
|
+
* @param options.precision - Number of decimal places in the output. Defaults to 4
|
|
8
|
+
* @returns The converted value as a string with 'px' units
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* rem2px(1) // '16.0000'
|
|
13
|
+
* rem2px('2rem') // '32.0000'
|
|
14
|
+
* rem2px(1, { base: 20 }) // '20.0000'
|
|
15
|
+
* rem2px(0.8125, { precision: 2 }) // '13.00'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function rem2px(
|
|
19
|
+
rem: number | string,
|
|
20
|
+
options?: { base?: number | undefined; precision?: number | undefined },
|
|
21
|
+
): number {
|
|
22
|
+
const { base = 16, precision = 4 } = options ?? {}
|
|
23
|
+
|
|
24
|
+
if (typeof rem === 'string') {
|
|
25
|
+
rem = rem.replace(/rem$/, '')
|
|
26
|
+
rem = Number.parseFloat(rem)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return Number((rem * base).toFixed(precision))
|
|
30
|
+
}
|
package/src/index.ts
CHANGED
package/src/tailwind.css
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export function LogPanel({ title, log }: { title: string; log: string[] }) {
|
|
2
2
|
return (
|
|
3
|
-
<div className="bg-neutral-100 p-4 rounded overflow-y-auto">
|
|
3
|
+
<div className="bg-neutral-100 dark:bg-neutral-900 p-4 rounded overflow-y-auto">
|
|
4
4
|
<h4 className="mb-2">{title}</h4>
|
|
5
5
|
{log.map((entry, i) => (
|
|
6
6
|
<pre key={i} className="font-mono">
|