diff --git a/.changeset/two-buses-heal.md b/.changeset/two-buses-heal.md new file mode 100644 index 0000000000..7805243626 --- /dev/null +++ b/.changeset/two-buses-heal.md @@ -0,0 +1,5 @@ +--- +'@ice/jsx-runtime': patch +--- + +fix: ignore base64 when convert style diff --git a/packages/jsx-runtime/src/index.ts b/packages/jsx-runtime/src/index.ts index eee3cec494..8f1202bed9 100644 --- a/packages/jsx-runtime/src/index.ts +++ b/packages/jsx-runtime/src/index.ts @@ -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) { @@ -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; diff --git a/packages/jsx-runtime/tests/hijackElememt.test.ts b/packages/jsx-runtime/tests/hijackElememt.test.ts index 7fdeff8e43..f850580e30 100644 --- a/packages/jsx-runtime/tests/hijackElememt.test.ts +++ b/packages/jsx-runtime/tests/hijackElememt.test.ts @@ -19,4 +19,13 @@ describe('hijack element', () => { }, }); }); -}); \ No newline at end of file + + 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...)', + }, + }); + }); +}); diff --git a/packages/jsx-runtime/tsconfig.json b/packages/jsx-runtime/tsconfig.json index e624667b31..79cf8a2f2d 100644 --- a/packages/jsx-runtime/tsconfig.json +++ b/packages/jsx-runtime/tsconfig.json @@ -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"] }