mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
* feat(parsers): share top-level timeline element and track kind definitions One pure definition of which elements own a timeline row (sub-composition hosts and timed elements; untimed wrappers are descended) and of a row's track kind, so the linter and Studio's timeline agree. * fix(parsers): align top-level rows with the runtime clip selector Rows now follow the runtime's clip selector (data-start, data-track-index, media tags), match tags case-insensitively for DOM adapters, and skip noscript. * fix(parsers): treat a track-index layer without a duration as a wrapper Matches the runtime, which skips such elements as clips, so their timed children stay visible to the lint.
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { topLevelElements, trackKindOf, type StructureNode } from "./topLevelElements.js";
|
|
|
|
type N = StructureNode<N> & { id?: string };
|
|
const n = (tag: string, attrs: Record<string, string> = {}, children: N[] = []): N => ({
|
|
tag,
|
|
attrs,
|
|
children,
|
|
id: attrs.id,
|
|
});
|
|
|
|
describe("topLevelElements", () => {
|
|
it("returns timed elements and sub-composition hosts, descending untimed wrappers", () => {
|
|
const root = n("div", {}, [
|
|
n("div", {}, [n("video", { id: "v" })]),
|
|
n("div", { "data-composition-id": "intro", "data-start": "0", id: "host" }, [
|
|
n("div", { "data-start": "1", id: "inner" }),
|
|
]),
|
|
n("div", { "data-start": "2", id: "t" }, [n("span", { "data-start": "3", id: "nested" })]),
|
|
n("script", { "data-start": "9", id: "s" }),
|
|
n("NOSCRIPT", { "data-start": "9", id: "ns" }),
|
|
n("div", { "data-track-index": "2", id: "lane" }, [
|
|
n("div", { "data-start": "1", id: "inLane" }),
|
|
]),
|
|
n("div", { "data-track-index": "3", "data-duration": "2", id: "laneTimed" }),
|
|
n("IMG", { id: "pic" }),
|
|
n("div", { class: "clip", id: "classOnly" }),
|
|
n("div", { "data-duration": "4", id: "durOnly" }),
|
|
]);
|
|
expect(topLevelElements(root).map((e) => e.id)).toEqual([
|
|
"v",
|
|
"host",
|
|
"t",
|
|
"inLane",
|
|
"laneTimed",
|
|
"pic",
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe("trackKindOf", () => {
|
|
it.each([
|
|
[n("div", { "data-track-kind": "Captions" }), "captions", "attribute"],
|
|
[n("audio"), "audio", "tag"],
|
|
[n("VIDEO"), "video", "tag"],
|
|
[
|
|
n("div", { class: "x caption-line", "data-composition-src": "a.html" }),
|
|
"captions",
|
|
"legacy-captions",
|
|
],
|
|
[n("div", { "data-composition-src": "a.html" }), "graphics", "sub-composition"],
|
|
[n("div", { "data-composition-id": "captions" }), "captions", "legacy-captions"],
|
|
[
|
|
n("div", { "data-track-kind": "bogus", "data-composition-id": "x" }),
|
|
"graphics",
|
|
"sub-composition",
|
|
],
|
|
])("%#", (node, kind, source) => {
|
|
expect(trackKindOf(node)).toEqual({ kind, source });
|
|
});
|
|
});
|