diff --git a/packages/cli/src/commands/info.ts b/packages/cli/src/commands/info.ts index 2d79faa9c..f5074d375 100644 --- a/packages/cli/src/commands/info.ts +++ b/packages/cli/src/commands/info.ts @@ -7,7 +7,7 @@ export const examples: Example[] = [ ["Output as JSON", "hyperframes info --json"], ]; import { join } from "node:path"; -import { parseHtml } from "@hyperframes/core"; +import { parseHtml, CANVAS_DIMENSIONS } from "@hyperframes/core"; import { c } from "../ui/colors.js"; import { formatBytes, label } from "../ui/format.js"; import { ensureDOMParser } from "../utils/dom.js"; @@ -52,16 +52,9 @@ export default defineCommand({ const heightMatch = html.match(/data-composition-id[^>]*data-height=["'](\d+)["']/) || html.match(/data-height=["'](\d+)["'][^>]*data-composition-id/); - const width = widthMatch?.[1] - ? parseInt(widthMatch[1], 10) - : parsed.resolution === "portrait" - ? 1080 - : 1920; - const height = heightMatch?.[1] - ? parseInt(heightMatch[1], 10) - : parsed.resolution === "portrait" - ? 1920 - : 1080; + const fallback = CANVAS_DIMENSIONS[parsed.resolution]; + const width = widthMatch?.[1] ? parseInt(widthMatch[1], 10) : fallback.width; + const height = heightMatch?.[1] ? parseInt(heightMatch[1], 10) : fallback.height; const resolution = `${width}x${height}`; const size = totalSize(project.dir); diff --git a/packages/core/src/core.types.ts b/packages/core/src/core.types.ts index 929fef6de..d46da4a6b 100644 --- a/packages/core/src/core.types.ts +++ b/packages/core/src/core.types.ts @@ -19,11 +19,13 @@ export interface Asset { export type TimelineElementType = "video" | "image" | "text" | "audio" | "composition"; export type MediaElementType = "video" | "image" | "audio"; -export type CanvasResolution = "landscape" | "portrait"; +export type CanvasResolution = "landscape" | "portrait" | "landscape-4k" | "portrait-4k"; export const CANVAS_DIMENSIONS = { landscape: { width: 1920, height: 1080 }, portrait: { width: 1080, height: 1920 }, + "landscape-4k": { width: 3840, height: 2160 }, + "portrait-4k": { width: 2160, height: 3840 }, } as const; export interface TimelineElementBase { diff --git a/packages/core/src/index.test.ts b/packages/core/src/index.test.ts index 97757c1d9..0c0bf94be 100644 --- a/packages/core/src/index.test.ts +++ b/packages/core/src/index.test.ts @@ -8,6 +8,8 @@ describe("@hyperframes/core public API exports", () => { expect(core.CANVAS_DIMENSIONS).toBeDefined(); expect(core.CANVAS_DIMENSIONS.landscape).toEqual({ width: 1920, height: 1080 }); expect(core.CANVAS_DIMENSIONS.portrait).toEqual({ width: 1080, height: 1920 }); + expect(core.CANVAS_DIMENSIONS["landscape-4k"]).toEqual({ width: 3840, height: 2160 }); + expect(core.CANVAS_DIMENSIONS["portrait-4k"]).toEqual({ width: 2160, height: 3840 }); }); it("exports TIMELINE_COLORS", () => { diff --git a/packages/core/src/parsers/htmlParser.test.ts b/packages/core/src/parsers/htmlParser.test.ts index a4c79ea63..119284df9 100644 --- a/packages/core/src/parsers/htmlParser.test.ts +++ b/packages/core/src/parsers/htmlParser.test.ts @@ -212,6 +212,51 @@ describe("parseHtml", () => { expect(result.resolution).toBe("portrait"); }); + it("detects landscape-4k resolution from data attribute", () => { + const html = ` + +
+