import type { SurfaceBlockComponent } from '@blocksuite/affine-block-surface'; import { ExportManager } from '@blocksuite/affine-block-surface'; import type { SurfaceRefBlockComponent } from '@blocksuite/affine-block-surface-ref'; import { BlockSuiteError } from '@blocksuite/global/exceptions'; import { Bound } from '@blocksuite/global/gfx'; import { assertType } from '@blocksuite/global/utils'; import { GfxControllerIdentifier } from '@blocksuite/std/gfx'; import { html } from 'lit'; export const noContentPlaceholder = html` `; export const surfaceRefToBlob = async ( surfaceRefBlock: SurfaceRefBlockComponent ): Promise => { const { referenceModel, previewEditor } = surfaceRefBlock; if (!referenceModel || !previewEditor) return null; const exportManager = previewEditor.std.get(ExportManager); const gfx = previewEditor.std.get(GfxControllerIdentifier); const { surface } = gfx; if (!surface) return null; const surfaceBlock = previewEditor.std.view.getBlock(surface.id); if (!surfaceBlock) return null; assertType(surfaceBlock); const canvas = await exportManager.edgelessToCanvas( surfaceBlock.renderer, Bound.deserialize(referenceModel.xywh), gfx, undefined, undefined, { zoom: surfaceBlock.renderer.viewport.zoom } ); if (!canvas) { throw new BlockSuiteError( BlockSuiteError.ErrorCode.ValueNotExists, 'Failed to export edgeless to canvas' ); } return new Promise((resolve, reject) => { canvas.toBlob(blob => (blob ? resolve(blob) : reject(null)), 'image/png'); }); }; export const writeImageBlobToClipboard = async (blob: Blob) => { await navigator.clipboard.write([new ClipboardItem({ [blob.type]: blob })]); };