diff --git a/packages/example/components/doc-render.tsx b/packages/example/components/doc-render.tsx index 2e4dc00..717249f 100644 --- a/packages/example/components/doc-render.tsx +++ b/packages/example/components/doc-render.tsx @@ -13,7 +13,7 @@ export default function DocDemo() { height={elementSize} // @ts-ignore render={({ scale, attrs }) => { - const width = attrs.style!.width as number; + const width = parseFloat((attrs?.style?.width ?? 0) as string); const offset = (width - elementSize) / elementSize; // 保持子节点的 scale 的稳定 const childScale = scale === 1 ? scale + offset : 1 + offset; diff --git a/packages/example/pages/docs/getting-started.en-US.mdx b/packages/example/pages/docs/getting-started.en-US.mdx index a91988b..b25c792 100644 --- a/packages/example/pages/docs/getting-started.en-US.mdx +++ b/packages/example/pages/docs/getting-started.en-US.mdx @@ -262,7 +262,7 @@ function MyComponent() { width={elementSize} height={elementSize} render={({ scale, attrs }) => { - const width = attrs.style.width; + const width = parseFloat((attrs?.style?.width ?? 0) as string); const offset = (width - elementSize) / elementSize; const childScale = scale === 1 ? scale + offset : 1 + offset; diff --git a/packages/example/pages/docs/getting-started.zh-CN.mdx b/packages/example/pages/docs/getting-started.zh-CN.mdx index fd41eeb..34ac5db 100644 --- a/packages/example/pages/docs/getting-started.zh-CN.mdx +++ b/packages/example/pages/docs/getting-started.zh-CN.mdx @@ -261,7 +261,7 @@ function MyComponent() { width={elementSize} height={elementSize} render={({ scale, attrs }) => { - const width = attrs.style.width; + const width = parseFloat((attrs?.style?.width ?? 0) as string); const offset = (width - elementSize) / elementSize; const childScale = scale === 1 ? scale + offset : 1 + offset;