We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 445b694 commit 51e52e5Copy full SHA for 51e52e5
2 files changed
packages/flexible/package.json
@@ -1,6 +1,6 @@
1
{
2
"name": "@cherrywind/flexible",
3
- "version": "0.1.2",
+ "version": "0.1.3",
4
"private": false,
5
"keywords": [
6
"flexible"
packages/flexible/src/index.ts
@@ -311,3 +311,20 @@ function getScrollbarWidth(): number {
311
document.body.removeChild(scrollDiv);
312
return scrollbarWidth;
313
}
314
+
315
+/**
316
+ * 将像素值转换为响应式单位
317
+ * @param px 像素值
318
+ * @param options 配置选项
319
+ * @returns 响应式单位字符串
320
+ */
321
+export function px2Response(
322
+ px: number,
323
+ options: {
324
+ baseWidth?: number;
325
+ localVarName?: string;
326
+ },
327
+) {
328
+ const { baseWidth = 19.2, localVarName = '--local-scope-rem' } = options;
329
+ return `calc(${(px / baseWidth).toFixed(4)} * var(${localVarName}, 1rem))`;
330
+}
0 commit comments