mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-05 03:19:52 +08:00
chore: merge blocksuite source code (#9213)
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* XYWH represents the x, y, width, and height of an element or block.
|
||||
*/
|
||||
export type XYWH = [number, number, number, number];
|
||||
|
||||
/**
|
||||
* SerializedXYWH is a string that represents the x, y, width, and height of a block.
|
||||
*/
|
||||
export type SerializedXYWH = `[${number},${number},${number},${number}]`;
|
||||
|
||||
export function serializeXYWH(
|
||||
x: number,
|
||||
y: number,
|
||||
w: number,
|
||||
h: number
|
||||
): SerializedXYWH {
|
||||
return `[${x},${y},${w},${h}]`;
|
||||
}
|
||||
|
||||
export function deserializeXYWH(xywh: string): XYWH {
|
||||
try {
|
||||
return JSON.parse(xywh) as XYWH;
|
||||
} catch (e) {
|
||||
console.error('Failed to deserialize xywh', xywh);
|
||||
console.error(e);
|
||||
|
||||
return [0, 0, 0, 0];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user