feat(core): frame editor settings (#9970)

Co-authored-by: L-Sun <zover.v@gmail.com>
Co-authored-by: Mirone <Saul-Mirone@outlook.com>
This commit is contained in:
Oleg
2025-02-10 08:23:32 +01:00
committed by GitHub
parent 03b806384c
commit d4f0c53a0c
14 changed files with 211 additions and 84 deletions

View File

@@ -16,5 +16,4 @@ export * from './slot.js';
export * from './types.js';
export * from './with-disposable.js';
export type { SerializedXYWH, XYWH } from './xywh.js';
export { SerializedXYWHZodSchema } from './xywh.js';
export { deserializeXYWH, serializeXYWH } from './xywh.js';

View File

@@ -1,5 +1,3 @@
import { z } from 'zod';
/**
* XYWH represents the x, y, width, and height of an element or block.
*/
@@ -10,30 +8,6 @@ export type XYWH = [number, number, number, number];
*/
export type SerializedXYWH = `[${number},${number},${number},${number}]`;
export const SerializedXYWHZodSchema = z.custom<SerializedXYWH>((val: any) => {
if (typeof val !== 'string') {
throw new Error('SerializedXYWH should be a string');
}
if (!val.startsWith('[') || !val.endsWith(']')) {
throw new Error('SerializedXYWH should be wrapped in square brackets');
}
const parts = val.slice(1, -1).split(',');
if (parts.length !== 4) {
throw new Error('SerializedXYWH should have 4 parts');
}
for (const part of parts) {
if (!/^\d+$/.test(part)) {
throw new Error('Each part of SerializedXYWH should be a number');
}
}
return val as SerializedXYWH;
});
export function serializeXYWH(
x: number,
y: number,