Skip to content

fix(extension): base64导出支持画布局部渲染时导出&修复相对路径图片导出问题&补充文档 #2114

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

DymoneLewis
Copy link
Collaborator

fix #1872

Copy link

changeset-bot bot commented Mar 24, 2025

⚠️ No Changeset found

Latest commit: ffcfce3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@DymoneLewis DymoneLewis requested a review from boyongjiong March 24, 2025 08:22
@DymoneLewis DymoneLewis changed the title fix(extension): base64导出支持画布局部渲染时导出&修复相对路径图片导出问题 fix(extension): base64导出支持画布局部渲染时导出&修复相对路径图片导出问题&补充文档 Apr 28, 2025
@@ -38,6 +38,16 @@ export default {
y: 100,
text: '菱形',
},
{
Copy link
Collaborator Author

@DymoneLewis DymoneLewis Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新增了一个展示上面所示的项目路径下图片的节点

@@ -28,8 +28,43 @@ class ImageNode extends RectNode {
}
}

export default {
class TestImageModel extends RectNodeModel {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

图片展示节点的定义

lfRef.current
.getSnapshotBlob(backgroundColor, fileType)
.getSnapshotBlob(backgroundColor, fileType, params)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

导出blob支持传入ToImageOptions

@@ -156,9 +163,18 @@ export default function SnapshotExample() {
// 预览 blob
const previewBlob = () => {
if (lfRef.current) {
setBase64Data('')
setBlobData('')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里setBase64改成setBlob主要是觉得base64的图片和blob的图片展示并不互斥,所以这里改成了setBlobData,在赋值前重置一下

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔这么一看感觉好像能删了,毕竟下面会直接赋值

padding,
quality,
}
const result = await lfRef.current.getSnapshotBase64(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base64的新调用方法

{blobData && (
<>
<h2>blobData</h2>
<img key="blob" src={blobData} />
<img style={{ width: '100%' }} key="blob" src={blobData} />
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前父元素比较窄,导出图片小的时候图挤成一团,图片大的时候又得左右滚动页面看,交互太难受了所以就调整了一下布局

@@ -70,14 +70,18 @@ export class Snapshot {
) => await this.getSnapshot(fileName, toImageOptions)

/* 获取Blob对象 */
lf.getSnapshotBlob = async (backgroundColor?: string, fileType?: string) =>
await this.getSnapshotBlob(backgroundColor, fileType)
lf.getSnapshotBlob = async (
Copy link
Collaborator Author

@DymoneLewis DymoneLewis Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个文件里都是CR重头戏

// 计算实际宽高,考虑缩放因素
// 在宽画布情况下,getBoundingClientRect可能无法获取到所有元素的边界
// 因此我们添加一个安全系数来确保能够容纳所有元素
const safetyFactor = 1.1 // 安全系数,增加20%的空间
Copy link
Collaborator Author

@DymoneLewis DymoneLewis Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

导出宽宽的图时,会出现最左边元素的边框被从中竖向截断的问题,所以这里加了这个安全系数,用于下面计算导出画布的宽高(一开始是1.2,看起来太大了,所以改成了1.1

this.removeRotateControl(element.firstChild!)
})
}
private async withExportPreparation<T>(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在snapshotBase64和snapshotBlob支持toImageOptions后,三个导出方法有一段实现逻辑高度相似,所以就提成了这个通用方法

@@ -9,151 +9,243 @@ toc: content
tag: Optimization
---

We often need to export the canvas content as an image. We provide an independent plug-in package `Snapshot` to use this function.
We often need to export the canvas content as an image. LogicFlow provides an independent plug-in package `Snapshot` to support exporting the canvas as an image.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

根据中文直接翻译的,要传递的信息和中文相同,可以直接看中文文档

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant