mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-16 09:36:17 +08:00
30 lines
665 B
TypeScript
30 lines
665 B
TypeScript
/**
|
|
* 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];
|
|
}
|
|
}
|