@hyperframes/parsers 0.8.49 → 0.8.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ /** Structural view of a markup node; lint (source tags) and Studio (DOM) adapt to it. */
2
+ type StructureNode<N = unknown> = {
3
+ tag: string;
4
+ attrs: Readonly<Record<string, string | undefined>>;
5
+ children: readonly N[];
6
+ };
7
+ type TrackKind = "video" | "audio" | "captions" | "graphics";
8
+ type TrackKindSource = "attribute" | "tag" | "legacy-captions" | "sub-composition";
9
+ declare function isSubCompositionHost(node: StructureNode): boolean;
10
+ /** Mirrors the runtime's clip selector; a data-track-index layer container without a duration is not a clip. */
11
+ declare function isTimedElement(node: StructureNode): boolean;
12
+ /**
13
+ * The elements that own a timeline row: a sub-composition host or timed element is one row
14
+ * and is never descended into; untimed wrappers are descended. The root itself is not a row.
15
+ */
16
+ declare function topLevelElements<N extends StructureNode<N>>(root: N): N[];
17
+ declare function trackKindOf(node: StructureNode): {
18
+ kind: TrackKind;
19
+ source: TrackKindSource;
20
+ };
21
+
22
+ export { type StructureNode, type TrackKind, type TrackKindSource, isSubCompositionHost, isTimedElement, topLevelElements, trackKindOf };
@@ -0,0 +1,40 @@
1
+ // src/topLevelElements.ts
2
+ var NON_RENDERED_TAGS = /* @__PURE__ */ new Set(["script", "style", "template", "noscript", "link", "meta"]);
3
+ var MEDIA_TAGS = /* @__PURE__ */ new Set(["video", "audio", "img"]);
4
+ var TRACK_KINDS = ["video", "audio", "captions", "graphics"];
5
+ function isSubCompositionHost(node) {
6
+ return node.attrs["data-composition-src"] !== void 0 || node.attrs["data-composition-id"] !== void 0;
7
+ }
8
+ function isTimedElement(node) {
9
+ const { attrs } = node;
10
+ return attrs["data-start"] !== void 0 || attrs["data-track-index"] !== void 0 && attrs["data-duration"] !== void 0 || MEDIA_TAGS.has(node.tag.toLowerCase());
11
+ }
12
+ function topLevelElements(root) {
13
+ const rows = [];
14
+ const visit = (node) => {
15
+ if (NON_RENDERED_TAGS.has(node.tag.toLowerCase())) return;
16
+ if (isSubCompositionHost(node) || isTimedElement(node)) rows.push(node);
17
+ else node.children.forEach(visit);
18
+ };
19
+ root.children.forEach(visit);
20
+ return rows;
21
+ }
22
+ function trackKindOf(node) {
23
+ const explicit = node.attrs["data-track-kind"]?.trim().toLowerCase();
24
+ if (explicit && TRACK_KINDS.includes(explicit))
25
+ return { kind: explicit, source: "attribute" };
26
+ const tag = node.tag.toLowerCase();
27
+ if (tag === "video" || tag === "audio") return { kind: tag, source: "tag" };
28
+ if (isSubCompositionHost(node)) {
29
+ const legacy = node.attrs["data-composition-id"] === "captions" || /(?:^|\s)caption[-_]/.test(node.attrs.class ?? "");
30
+ return legacy ? { kind: "captions", source: "legacy-captions" } : { kind: "graphics", source: "sub-composition" };
31
+ }
32
+ return { kind: "graphics", source: "tag" };
33
+ }
34
+ export {
35
+ isSubCompositionHost,
36
+ isTimedElement,
37
+ topLevelElements,
38
+ trackKindOf
39
+ };
40
+ //# sourceMappingURL=topLevelElements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/topLevelElements.ts"],"sourcesContent":["/** Structural view of a markup node; lint (source tags) and Studio (DOM) adapt to it. */\nexport type StructureNode<N = unknown> = {\n tag: string;\n attrs: Readonly<Record<string, string | undefined>>;\n children: readonly N[];\n};\n\nexport type TrackKind = \"video\" | \"audio\" | \"captions\" | \"graphics\";\nexport type TrackKindSource = \"attribute\" | \"tag\" | \"legacy-captions\" | \"sub-composition\";\n\nconst NON_RENDERED_TAGS = new Set([\"script\", \"style\", \"template\", \"noscript\", \"link\", \"meta\"]);\nconst MEDIA_TAGS = new Set([\"video\", \"audio\", \"img\"]);\nconst TRACK_KINDS: readonly string[] = [\"video\", \"audio\", \"captions\", \"graphics\"];\n\nexport function isSubCompositionHost(node: StructureNode): boolean {\n return (\n node.attrs[\"data-composition-src\"] !== undefined ||\n node.attrs[\"data-composition-id\"] !== undefined\n );\n}\n\n/** Mirrors the runtime's clip selector; a data-track-index layer container without a duration is not a clip. */\nexport function isTimedElement(node: StructureNode): boolean {\n const { attrs } = node;\n return (\n attrs[\"data-start\"] !== undefined ||\n (attrs[\"data-track-index\"] !== undefined && attrs[\"data-duration\"] !== undefined) ||\n MEDIA_TAGS.has(node.tag.toLowerCase())\n );\n}\n\n/**\n * The elements that own a timeline row: a sub-composition host or timed element is one row\n * and is never descended into; untimed wrappers are descended. The root itself is not a row.\n */\nexport function topLevelElements<N extends StructureNode<N>>(root: N): N[] {\n const rows: N[] = [];\n const visit = (node: N): void => {\n if (NON_RENDERED_TAGS.has(node.tag.toLowerCase())) return;\n if (isSubCompositionHost(node) || isTimedElement(node)) rows.push(node);\n else node.children.forEach(visit);\n };\n root.children.forEach(visit);\n return rows;\n}\n\nexport function trackKindOf(node: StructureNode): { kind: TrackKind; source: TrackKindSource } {\n const explicit = node.attrs[\"data-track-kind\"]?.trim().toLowerCase();\n if (explicit && TRACK_KINDS.includes(explicit))\n return { kind: explicit as TrackKind, source: \"attribute\" };\n const tag = node.tag.toLowerCase();\n if (tag === \"video\" || tag === \"audio\") return { kind: tag, source: \"tag\" };\n if (isSubCompositionHost(node)) {\n const legacy =\n node.attrs[\"data-composition-id\"] === \"captions\" ||\n /(?:^|\\s)caption[-_]/.test(node.attrs.class ?? \"\");\n return legacy\n ? { kind: \"captions\", source: \"legacy-captions\" }\n : { kind: \"graphics\", source: \"sub-composition\" };\n }\n return { kind: \"graphics\", source: \"tag\" };\n}\n"],"mappings":";AAUA,IAAM,oBAAoB,oBAAI,IAAI,CAAC,UAAU,SAAS,YAAY,YAAY,QAAQ,MAAM,CAAC;AAC7F,IAAM,aAAa,oBAAI,IAAI,CAAC,SAAS,SAAS,KAAK,CAAC;AACpD,IAAM,cAAiC,CAAC,SAAS,SAAS,YAAY,UAAU;AAEzE,SAAS,qBAAqB,MAA8B;AACjE,SACE,KAAK,MAAM,sBAAsB,MAAM,UACvC,KAAK,MAAM,qBAAqB,MAAM;AAE1C;AAGO,SAAS,eAAe,MAA8B;AAC3D,QAAM,EAAE,MAAM,IAAI;AAClB,SACE,MAAM,YAAY,MAAM,UACvB,MAAM,kBAAkB,MAAM,UAAa,MAAM,eAAe,MAAM,UACvE,WAAW,IAAI,KAAK,IAAI,YAAY,CAAC;AAEzC;AAMO,SAAS,iBAA6C,MAAc;AACzE,QAAM,OAAY,CAAC;AACnB,QAAM,QAAQ,CAAC,SAAkB;AAC/B,QAAI,kBAAkB,IAAI,KAAK,IAAI,YAAY,CAAC,EAAG;AACnD,QAAI,qBAAqB,IAAI,KAAK,eAAe,IAAI,EAAG,MAAK,KAAK,IAAI;AAAA,QACjE,MAAK,SAAS,QAAQ,KAAK;AAAA,EAClC;AACA,OAAK,SAAS,QAAQ,KAAK;AAC3B,SAAO;AACT;AAEO,SAAS,YAAY,MAAmE;AAC7F,QAAM,WAAW,KAAK,MAAM,iBAAiB,GAAG,KAAK,EAAE,YAAY;AACnE,MAAI,YAAY,YAAY,SAAS,QAAQ;AAC3C,WAAO,EAAE,MAAM,UAAuB,QAAQ,YAAY;AAC5D,QAAM,MAAM,KAAK,IAAI,YAAY;AACjC,MAAI,QAAQ,WAAW,QAAQ,QAAS,QAAO,EAAE,MAAM,KAAK,QAAQ,MAAM;AAC1E,MAAI,qBAAqB,IAAI,GAAG;AAC9B,UAAM,SACJ,KAAK,MAAM,qBAAqB,MAAM,cACtC,sBAAsB,KAAK,KAAK,MAAM,SAAS,EAAE;AACnD,WAAO,SACH,EAAE,MAAM,YAAY,QAAQ,kBAAkB,IAC9C,EAAE,MAAM,YAAY,QAAQ,kBAAkB;AAAA,EACpD;AACA,SAAO,EAAE,MAAM,YAAY,QAAQ,MAAM;AAC3C;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/parsers",
3
- "version": "0.8.49",
3
+ "version": "0.8.50",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/heygen-com/hyperframes",
@@ -64,6 +64,10 @@
64
64
  "import": "./dist/compositionContract.js",
65
65
  "types": "./dist/compositionContract.d.ts"
66
66
  },
67
+ "./top-level-elements": {
68
+ "import": "./dist/topLevelElements.js",
69
+ "types": "./dist/topLevelElements.d.ts"
70
+ },
67
71
  "./color-grading-contract": {
68
72
  "import": "./dist/colorGradingContract.js",
69
73
  "types": "./dist/colorGradingContract.d.ts"
@@ -98,7 +102,7 @@
98
102
  "tsx": "^4.21.0",
99
103
  "typescript": "^5.0.0",
100
104
  "vitest": "^4.1.11",
101
- "@hyperframes/core": "0.8.49"
105
+ "@hyperframes/core": "0.8.50"
102
106
  },
103
107
  "scripts": {
104
108
  "build": "tsup",