Skip to content

Commit

Permalink
fix: 修复出码数值错误
Browse files Browse the repository at this point in the history
  • Loading branch information
吖克 committed Aug 28, 2024
1 parent c500e9c commit 9cc5faf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ export const parseNumberValue = (value) => {
return 0;
}
});

if (/^\-?[\d\.]+$/.test(value)) {
value = parseFloat(value);
if (cssUnit == 'rpx') {
Expand Down Expand Up @@ -454,10 +455,14 @@ export const parseStyle = (style) => {
case 'borderTopRightRadius':
case 'borderTopLeftRadius':
case 'borderRadius':
resultStyle[key] = parseInt(style[key]) * scale;
const values = String(style[key]).split(' ');

// 响应式缩放后数字
const scaleValues = values.map(val => parseInt(val, 10) * scale);
if (style[key]) {
resultStyle[key] = parseNumberValue(style[key]);
resultStyle[key] = scaleValues.map(val=> parseNumberValue(val)).join(' ')
}

break;
default:
if (style[key] && String(style[key]).includes('px')) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const parserBabel= require('prettier/parser-babel');
const parserCss =require('prettier/parser-postcss');
const parserMarkDown=require('prettier/parser-markdown');

const entry = require('../dist/entry')
const entry = require('../src/index')
const browerParser = {
babel: parserBabel,
json: parserBabel,
Expand Down Expand Up @@ -77,7 +77,7 @@ const runCode = (data, dslConfig) => {
co(function*() {
const panelDisplay = runCode(data, {
componentStyle: "hooks",
cssUnit: "px",
cssUnit: "rpx",
dsl: "rax",
globalCss: true,
htmlFontSize: "16",
Expand Down

0 comments on commit 9cc5faf

Please sign in to comment.