From bedd598fc78a026cffb2c006c50332594c944e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Wed, 21 Apr 2021 09:44:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor(perf):=20=E4=BC=98=E5=8C=96=E6=8F=92?= =?UTF-8?q?=E5=85=A5=20style=20=E8=8A=82=E7=82=B9=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91,=20=E9=81=BF=E5=85=8D=E6=97=A0=E6=84=8F=E4=B9=89?= =?UTF-8?q?=E7=9A=84=E5=88=A0=E9=99=A4=E5=92=8C=E6=8F=92=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/src/builtin-simulator/host.ts | 2 +- .../src/transducers/addon-combine.ts | 2 +- .../react-simulator-renderer/src/renderer.ts | 2 +- .../src/props-reducers/style-reducer.ts | 55 +++++++++++++------ 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/packages/designer/src/builtin-simulator/host.ts b/packages/designer/src/builtin-simulator/host.ts index bbcc36fce..49ae0f443 100644 --- a/packages/designer/src/builtin-simulator/host.ts +++ b/packages/designer/src/builtin-simulator/host.ts @@ -291,6 +291,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost { - return `${b / 2}px`; - }).replace(/:root/g, `.${cssClass}`))); + s.appendChild(doc.createTextNode(newStyleStr)); } } + +function stringEquals(str: string, targetStr: string): boolean { + return removeWhitespace(str) === removeWhitespace(targetStr); +} + +function removeWhitespace(str: string = ''): string { + return str.replace(/\s/g, ''); +} + +function transformStyleStr(styleStr: string = '', cssClass: string): string { + return styleStr + .replace(/(\d+)rpx/g, (all, num) => { + return `${num / 2}px`; + }) + .replace(/:root/g, `.${cssClass}`); +}