@@ -2,6 +2,8 @@ import { convertToExcalidrawElements } from "@excalidraw/excalidraw";
|
||||
import type { FileId } from "@excalidraw/excalidraw/element/types";
|
||||
import type { BinaryFileData, BinaryFiles, DataURL } from "@excalidraw/excalidraw/types";
|
||||
|
||||
import { createClientId } from "@/lib/client-id";
|
||||
|
||||
const INITIAL_DRAWING_SHAPE_MAX_DIMENSION = 1200;
|
||||
|
||||
type DrawingImageSource = {
|
||||
@@ -14,7 +16,7 @@ type DrawingImageSource = {
|
||||
|
||||
export function createExcalidrawDrawingFromImage(source: DrawingImageSource) {
|
||||
const now = Date.now();
|
||||
const fileId = crypto.randomUUID() as FileId;
|
||||
const fileId = createClientId() as FileId;
|
||||
const scale = Math.min(1, INITIAL_DRAWING_SHAPE_MAX_DIMENSION / Math.max(source.width, source.height));
|
||||
const width = Math.max(1, Math.round(source.width * scale));
|
||||
const height = Math.max(1, Math.round(source.height * scale));
|
||||
|
||||
6
web/src/lib/client-id.ts
Normal file
6
web/src/lib/client-id.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { nanoid } from "nanoid";
|
||||
|
||||
export function createClientId() {
|
||||
// randomUUID 在 HTTP 内网地址下不可用;nanoid 依赖仍可用的 getRandomValues。
|
||||
return nanoid();
|
||||
}
|
||||
Reference in New Issue
Block a user