@hyperframes/parsers 0.9.70 → 0.9.72

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.
package/dist/hfIds.js CHANGED
@@ -1,6 +1,14 @@
1
1
  // src/hfIds.ts
2
2
  import { parseHTML } from "linkedom";
3
3
 
4
+ // src/subCompositionValidity.ts
5
+ function isHtmlTemplate(el) {
6
+ return el.localName === "template" && "content" in el;
7
+ }
8
+ function templateContent(el) {
9
+ return isHtmlTemplate(el) ? el.content ?? null : null;
10
+ }
11
+
4
12
  // src/hfIdAssignment.ts
5
13
  var EXCLUDED_TAGS = /* @__PURE__ */ new Set([
6
14
  "script",
@@ -56,8 +64,8 @@ function mintHfId(el, assigned) {
56
64
  }
57
65
  function getChildElements(parent) {
58
66
  const directChildren = Array.from(parent.children);
59
- if (directChildren.length || parent.tagName.toLowerCase() !== "template") return directChildren;
60
- const content = parent.content;
67
+ if (directChildren.length) return directChildren;
68
+ const content = templateContent(parent);
61
69
  if (content?.children.length) return Array.from(content.children);
62
70
  return directChildren;
63
71
  }
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ export { getObjectArrayKeyframeTiming } from './gsapParserExports.js';
6
6
  export { SPRING_PRESETS, SpringPreset, generateSpringEaseData } from './springEase.js';
7
7
  export { parseGsapScriptAcorn as parseGsapScript } from './gsapParserAcorn.js';
8
8
  export { EXCLUDED_TAGS, ensureHfIds, isCompositionTemplate, mintHfId, stampHfIdsInPlace, walkCompositionDescendants } from './hfIds.js';
9
- export { ParsableDocumentLike, SceneTemplateLike, SubCompositionValidity, SubCompositionValidityReason, checkSubCompositionUsability, findSceneTemplate, resolveSubCompositionContent } from './subCompositionValidity.js';
9
+ export { ParsableDocumentLike, SceneTemplateLike, SubCompositionValidity, SubCompositionValidityReason, checkSubCompositionUsability, findSceneTemplate, firstHtmlTemplate, firstTemplateContent, isHtmlTemplate, resolveSubCompositionContent, templateContent } from './subCompositionValidity.js';
10
10
  export { CANONICAL_AUTHORED_TIMING_ATTRIBUTES, COMPOSITION_ATTRIBUTES, COMPOSITION_CONTRACT_VERSION, ClipAttributeReader, ClipAttributeWriter, ClipTiming, ClipTimingDiagnostic, ClipTimingDiagnosticCode, ClipTimingUpdate, ClipTimingWriteError, DERIVED_TIMING_ATTRIBUTES, LEGACY_TIMING_ATTRIBUTES, ReadClipTimingOptions, ReferenceExpression, SPLIT_BOUNDARY_EPSILON_S, parseNumeric, parseStartExpression, readClipTiming, writeClipTiming } from './compositionContract.js';
11
11
  export { C as CANONICAL_FONT_DISPLAY_NAMES, a as CanvasScaffoldMatch, F as FONT_ALIAS_KEYS, b as FONT_ALIAS_MAP, M as MediaSrcMutation, V as VariableUsageScan, e as extractMediaSrcMutations, m as matchHtmlBodyCssHeightFirst, h as matchHtmlBodyCssWidthFirst, j as matchViewportMetaSize, p as parseCompositionVariables, k as replaceCanvasScaffoldSize, l as resolveAliasDisplayName, s as scanVariableUsage } from './fontAliases-6Aft6tHT.js';
12
12
  export { StructureNode, TrackKind, TrackKindSource, isSubCompositionHost, isTimedElement, topLevelElements, trackKindOf } from './topLevelElements.js';
package/dist/index.js CHANGED
@@ -2471,6 +2471,76 @@ function parseCompositionVariables(htmlEl) {
2471
2471
  // src/hfIds.ts
2472
2472
  import { parseHTML } from "linkedom";
2473
2473
 
2474
+ // src/subCompositionValidity.ts
2475
+ function isHtmlTemplate(el) {
2476
+ return el.localName === "template" && "content" in el;
2477
+ }
2478
+ function templateContent(el) {
2479
+ return isHtmlTemplate(el) ? el.content ?? null : null;
2480
+ }
2481
+ function firstHtmlTemplate(templates) {
2482
+ return Array.from(templates).find(isHtmlTemplate);
2483
+ }
2484
+ function firstTemplateContent(root) {
2485
+ const template = firstHtmlTemplate(root.querySelectorAll("template"));
2486
+ return template ? templateContent(template) : null;
2487
+ }
2488
+ function findSceneTemplate(templates) {
2489
+ return Array.from(templates).find(
2490
+ (template) => templateContent(template)?.querySelector("[data-composition-id]") != null
2491
+ );
2492
+ }
2493
+ function resolveSubCompositionContent(html, document) {
2494
+ const templates = Array.from(document.querySelectorAll("template"));
2495
+ const template = findSceneTemplate(templates) ?? firstHtmlTemplate(templates);
2496
+ if (template) return { contentHtml: template.innerHTML ?? "", hasTemplate: true };
2497
+ const body = document.querySelector("body");
2498
+ if (body) return { contentHtml: body.innerHTML ?? "", hasTemplate: false };
2499
+ const contentHtml = document.querySelector("html") ? "" : html;
2500
+ return { contentHtml, hasTemplate: false };
2501
+ }
2502
+ function checkSubCompositionUsability(html, parseHtml2) {
2503
+ if (html == null || !html.trim()) {
2504
+ return {
2505
+ ok: false,
2506
+ reason: "empty",
2507
+ detail: "the file is empty (0 bytes or whitespace-only)"
2508
+ };
2509
+ }
2510
+ const compDoc = parseHtml2(html);
2511
+ if (!compDoc.documentElement) {
2512
+ return {
2513
+ ok: false,
2514
+ reason: "unparsable",
2515
+ detail: "the file's contents could not be parsed as HTML"
2516
+ };
2517
+ }
2518
+ const { contentHtml } = resolveSubCompositionContent(html, compDoc);
2519
+ if (!contentHtml.trim()) {
2520
+ return {
2521
+ ok: false,
2522
+ reason: "no-content",
2523
+ detail: "the file has no <template> or <body> content to render"
2524
+ };
2525
+ }
2526
+ const contentDoc = parseHtml2(contentHtml);
2527
+ if (!contentDoc.documentElement) {
2528
+ return {
2529
+ ok: false,
2530
+ reason: "unparsable",
2531
+ detail: "the file's resolved contents could not be parsed as HTML"
2532
+ };
2533
+ }
2534
+ if (!contentDoc.querySelector("[data-composition-id]")) {
2535
+ return {
2536
+ ok: false,
2537
+ reason: "no-composition-root",
2538
+ detail: "the file's resolved content has no element with a data-composition-id attribute"
2539
+ };
2540
+ }
2541
+ return { ok: true };
2542
+ }
2543
+
2474
2544
  // src/hfIdAssignment.ts
2475
2545
  var EXCLUDED_TAGS = /* @__PURE__ */ new Set([
2476
2546
  "script",
@@ -2526,8 +2596,8 @@ function mintHfId(el, assigned) {
2526
2596
  }
2527
2597
  function getChildElements(parent) {
2528
2598
  const directChildren = Array.from(parent.children);
2529
- if (directChildren.length || parent.tagName.toLowerCase() !== "template") return directChildren;
2530
- const content = parent.content;
2599
+ if (directChildren.length) return directChildren;
2600
+ const content = templateContent(parent);
2531
2601
  if (content?.children.length) return Array.from(content.children);
2532
2602
  return directChildren;
2533
2603
  }
@@ -3658,9 +3728,7 @@ function extractCompositionMetadata(html) {
3658
3728
  const compositionId = htmlEl.getAttribute("data-composition-id");
3659
3729
  const durationStr = htmlEl.getAttribute("data-composition-duration");
3660
3730
  const compositionDuration = durationStr ? parseFloat(durationStr) : null;
3661
- const root = (doc.querySelector("template")?.content ?? doc).querySelector(
3662
- "[data-composition-id]"
3663
- );
3731
+ const root = (firstTemplateContent(doc) ?? doc).querySelector("[data-composition-id]");
3664
3732
  const variables = [
3665
3733
  ...new Map(
3666
3734
  [
@@ -3745,63 +3813,6 @@ function extractGsapScripts(doc) {
3745
3813
  return gsapScripts;
3746
3814
  }
3747
3815
 
3748
- // src/subCompositionValidity.ts
3749
- function findSceneTemplate(templates) {
3750
- return Array.from(templates).find(
3751
- (template) => template.content.querySelector("[data-composition-id]") != null
3752
- );
3753
- }
3754
- function resolveSubCompositionContent(html, document) {
3755
- const templates = Array.from(document.querySelectorAll("template"));
3756
- const template = findSceneTemplate(templates) ?? templates[0];
3757
- if (template) return { contentHtml: template.innerHTML ?? "", hasTemplate: true };
3758
- const body = document.querySelector("body");
3759
- if (body) return { contentHtml: body.innerHTML ?? "", hasTemplate: false };
3760
- const contentHtml = document.querySelector("html") ? "" : html;
3761
- return { contentHtml, hasTemplate: false };
3762
- }
3763
- function checkSubCompositionUsability(html, parseHtml2) {
3764
- if (html == null || !html.trim()) {
3765
- return {
3766
- ok: false,
3767
- reason: "empty",
3768
- detail: "the file is empty (0 bytes or whitespace-only)"
3769
- };
3770
- }
3771
- const compDoc = parseHtml2(html);
3772
- if (!compDoc.documentElement) {
3773
- return {
3774
- ok: false,
3775
- reason: "unparsable",
3776
- detail: "the file's contents could not be parsed as HTML"
3777
- };
3778
- }
3779
- const { contentHtml } = resolveSubCompositionContent(html, compDoc);
3780
- if (!contentHtml.trim()) {
3781
- return {
3782
- ok: false,
3783
- reason: "no-content",
3784
- detail: "the file has no <template> or <body> content to render"
3785
- };
3786
- }
3787
- const contentDoc = parseHtml2(contentHtml);
3788
- if (!contentDoc.documentElement) {
3789
- return {
3790
- ok: false,
3791
- reason: "unparsable",
3792
- detail: "the file's resolved contents could not be parsed as HTML"
3793
- };
3794
- }
3795
- if (!contentDoc.querySelector("[data-composition-id]")) {
3796
- return {
3797
- ok: false,
3798
- reason: "no-composition-root",
3799
- detail: "the file's resolved content has no element with a data-composition-id attribute"
3800
- };
3801
- }
3802
- return { ok: true };
3803
- }
3804
-
3805
3816
  // src/outputResolutionCompatibility.ts
3806
3817
  var OK = { ok: true };
3807
3818
  function suggestMatchingPreset(compositionWidth, compositionHeight, chosen) {
@@ -4978,6 +4989,8 @@ export {
4978
4989
  extractCompositionMetadata,
4979
4990
  extractMediaSrcMutations,
4980
4991
  findSceneTemplate,
4992
+ firstHtmlTemplate,
4993
+ firstTemplateContent,
4981
4994
  generateSpringEaseData,
4982
4995
  getAnimationsForElementId,
4983
4996
  getDefaultStageZoom,
@@ -4986,6 +4999,7 @@ export {
4986
4999
  isAspectAgnosticResolutionAlias,
4987
5000
  isCompositionElement,
4988
5001
  isCompositionTemplate,
5002
+ isHtmlTemplate,
4989
5003
  isMediaElement,
4990
5004
  isStudioHoldSet,
4991
5005
  isSubCompositionHost,
@@ -5023,6 +5037,7 @@ export {
5023
5037
  serializeGsapAnimations,
5024
5038
  stampHfIdsInPlace,
5025
5039
  suggestMatchingPreset,
5040
+ templateContent,
5026
5041
  timingMismatches,
5027
5042
  topLevelElements,
5028
5043
  trackKindOf,
@@ -59,10 +59,13 @@ interface ParsableDocumentLike {
59
59
  } & SceneTemplateLike>;
60
60
  }
61
61
  interface SceneTemplateLike {
62
- content: {
63
- querySelector(selector: string): unknown;
64
- };
62
+ localName: string;
65
63
  }
64
+ /** Whether `el` is an HTML `<template>`; an SVG `template` has no content. Reads no content, which linkedom copies. */
65
+ declare function isHtmlTemplate(el: SceneTemplateLike): boolean;
66
+ declare function templateContent(el: SceneTemplateLike): DocumentFragment | null;
67
+ declare function firstHtmlTemplate<T extends SceneTemplateLike>(templates: ArrayLike<T>): T | undefined;
68
+ declare function firstTemplateContent(root: ParentNode): DocumentFragment | null;
66
69
  declare function findSceneTemplate<T extends SceneTemplateLike>(templates: ArrayLike<T>): T | undefined;
67
70
  /** Resolve authored content without invoking linkedom's synthetic body getter. */
68
71
  declare function resolveSubCompositionContent(html: string, document: ParsableDocumentLike): {
@@ -90,4 +93,4 @@ declare function resolveSubCompositionContent(html: string, document: ParsableDo
90
93
  */
91
94
  declare function checkSubCompositionUsability(html: string | null | undefined, parseHtml: (html: string) => ParsableDocumentLike): SubCompositionValidity;
92
95
 
93
- export { type ParsableDocumentLike, type SceneTemplateLike, type SubCompositionValidity, type SubCompositionValidityReason, checkSubCompositionUsability, findSceneTemplate, resolveSubCompositionContent };
96
+ export { type ParsableDocumentLike, type SceneTemplateLike, type SubCompositionValidity, type SubCompositionValidityReason, checkSubCompositionUsability, findSceneTemplate, firstHtmlTemplate, firstTemplateContent, isHtmlTemplate, resolveSubCompositionContent, templateContent };
@@ -1,12 +1,25 @@
1
1
  // src/subCompositionValidity.ts
2
+ function isHtmlTemplate(el) {
3
+ return el.localName === "template" && "content" in el;
4
+ }
5
+ function templateContent(el) {
6
+ return isHtmlTemplate(el) ? el.content ?? null : null;
7
+ }
8
+ function firstHtmlTemplate(templates) {
9
+ return Array.from(templates).find(isHtmlTemplate);
10
+ }
11
+ function firstTemplateContent(root) {
12
+ const template = firstHtmlTemplate(root.querySelectorAll("template"));
13
+ return template ? templateContent(template) : null;
14
+ }
2
15
  function findSceneTemplate(templates) {
3
16
  return Array.from(templates).find(
4
- (template) => template.content.querySelector("[data-composition-id]") != null
17
+ (template) => templateContent(template)?.querySelector("[data-composition-id]") != null
5
18
  );
6
19
  }
7
20
  function resolveSubCompositionContent(html, document) {
8
21
  const templates = Array.from(document.querySelectorAll("template"));
9
- const template = findSceneTemplate(templates) ?? templates[0];
22
+ const template = findSceneTemplate(templates) ?? firstHtmlTemplate(templates);
10
23
  if (template) return { contentHtml: template.innerHTML ?? "", hasTemplate: true };
11
24
  const body = document.querySelector("body");
12
25
  if (body) return { contentHtml: body.innerHTML ?? "", hasTemplate: false };
@@ -57,5 +70,9 @@ function checkSubCompositionUsability(html, parseHtml) {
57
70
  export {
58
71
  checkSubCompositionUsability,
59
72
  findSceneTemplate,
60
- resolveSubCompositionContent
73
+ firstHtmlTemplate,
74
+ firstTemplateContent,
75
+ isHtmlTemplate,
76
+ resolveSubCompositionContent,
77
+ templateContent
61
78
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/parsers",
3
- "version": "0.9.70",
3
+ "version": "0.9.72",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/heygen-com/hyperframes",
@@ -151,7 +151,7 @@
151
151
  "tsx": "^4.21.0",
152
152
  "typescript": "^5.0.0",
153
153
  "vitest": "^4.1.12",
154
- "@hyperframes/core": "0.9.70"
154
+ "@hyperframes/core": "0.9.72"
155
155
  },
156
156
  "scripts": {
157
157
  "build": "tsup",