项目文件夹

文件
wehub-resource-sync adf0d17497
publish / version_or_publish (push) Has been cancelled
storybook-build / changes (push) Has been cancelled
storybook-build / :storybook-build (push) Has been cancelled
Sync Gradio Skills to Hugging Face / sync-skills (push) Has been cancelled
functional / changes (push) Has been cancelled
functional / build-frontend (push) Has been cancelled
functional / functional-test-SSR=false (push) Has been cancelled
functional / functional-reload (push) Has been cancelled
js / changes (push) Has been cancelled
js / js-test (push) Has been cancelled
docs-build / changes (push) Has been cancelled
docs-build / docs-build (push) Has been cancelled
docs-build / website-build (push) Has been cancelled
functional / functional-test-SSR=true (push) Has been cancelled
hygiene / hygiene-test (push) Has been cancelled
python / changes (push) Has been cancelled
python / build (push) Has been cancelled
python / test-ubuntu-latest-flaky (push) Has been cancelled
python / test-ubuntu-latest-not-flaky (push) Has been cancelled
python / test-windows-latest-flaky (push) Has been cancelled
python / test-windows-latest-not-flaky (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:17:32 +08:00

47 行
1.1 KiB
TypeScript

export interface Viewport {
x: number;
y: number;
zoom: number;
}
const DEFAULT_VIEWPORT: Viewport = { x: 0, y: 0, zoom: 1 };
export function viewport_storage_key(name: string): string {
return `gradio_workflow_viewport:${name}`;
}
export function load_viewport(
name: string,
storage: Storage | undefined = typeof localStorage !== "undefined"
? localStorage
: undefined
): Viewport {
if (!storage) return { ...DEFAULT_VIEWPORT };
try {
const raw = storage.getItem(viewport_storage_key(name));
if (!raw) return { ...DEFAULT_VIEWPORT };
const v = JSON.parse(raw);
if (
typeof v?.x === "number" &&
typeof v?.y === "number" &&
typeof v?.zoom === "number"
) {
return { x: v.x, y: v.y, zoom: v.zoom };
}
} catch {}
return { ...DEFAULT_VIEWPORT };
}
export function save_viewport(
name: string,
viewport: Viewport,
storage: Storage | undefined = typeof localStorage !== "undefined"
? localStorage
: undefined
): void {
if (!storage) return;
try {
storage.setItem(viewport_storage_key(name), JSON.stringify(viewport));
} catch {}
}