Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore base64 when convert style #6114

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/two-buses-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/jsx-runtime': patch
---

fix: ignore base64 when convert style
7 changes: 5 additions & 2 deletions packages/jsx-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ function isObject(obj: any): obj is object {
return typeof obj === 'object';
}

const REG_BASE64 = /data:image\/(png|jpg|jpeg|gif|svg|webp|bmp|dpg);base64,/;
function isBase64(str: any) {
return typeof str === 'string' && REG_BASE64.test(str);
}
// Support rpx unit.
export function hijackElementProps(props: { style?: object } | object): object {
if (props && STYLE in props) {
Expand All @@ -35,8 +39,7 @@ export function hijackElementProps(props: { style?: object } | object): object {
const result = Object.assign({}, props);
const convertedStyle = {};
for (const prop in style) {
// @ts-ignore
convertedStyle[prop] = convertUnit(style[prop]);
convertedStyle[prop] = isBase64(style[prop]) ? style[prop] : convertUnit(style[prop]);
}
result['style'] = convertedStyle;
return result;
Expand Down
11 changes: 10 additions & 1 deletion packages/jsx-runtime/tests/hijackElememt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ describe('hijack element', () => {
},
});
});
});

it('hijackElementProps base64', () => {
const props = hijackElementProps({ style: { backgroundImage: 'url(\'data:image/png;base64,iVBORwrpx...)' } });
expect(props).toStrictEqual({
style: {
backgroundImage: 'url(\'data:image/png;base64,iVBORwrpx...)',
},
});
});
});
24 changes: 7 additions & 17 deletions packages/jsx-runtime/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
{
"compileOnSave": false,
"buildOnSave": false,
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "build",
"module": "esnext",
"target": "esnext",
"jsx": "react",
"moduleResolution": "node",
"lib": ["es6", "dom"],
"sourceMap": true,
"allowJs": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"skipLibCheck": true
"baseUrl": "./",
"rootDir": "src",
"outDir": "esm",
"module": "ES2020",
"moduleResolution": "NodeNext",
},
"include": ["src/*.ts", "src/*.tsx"],
"exclude": ["node_modules", "build", "public"]
"include": ["src"]
}