@hyperframes/producer 0.2.0-alpha.1 → 0.2.0

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.
@@ -101852,10 +101852,14 @@ function hasAttr(tag, attr) {
101852
101852
  function injectAttr(tag, attr, value) {
101853
101853
  return tag.replace(/>$/, ` ${attr}="${value}">`);
101854
101854
  }
101855
- function compileTag(tag, isVideo) {
101855
+ function compileTag(tag, isVideo, generateId) {
101856
101856
  let result = tag;
101857
101857
  let unresolved = null;
101858
- const id = getAttr(result, "id");
101858
+ let id = getAttr(result, "id");
101859
+ if (!id) {
101860
+ id = `${isVideo ? "hf-video" : "hf-audio"}-${generateId()}`;
101861
+ result = injectAttr(result, "id", id);
101862
+ }
101859
101863
  const startStr = getAttr(result, "data-start");
101860
101864
  const start = startStr !== null ? parseFloat(startStr) : 0;
101861
101865
  const mediaStartStr = getAttr(result, "data-media-start");
@@ -101882,13 +101886,15 @@ function compileTag(tag, isVideo) {
101882
101886
  }
101883
101887
  function compileTimingAttrs(html) {
101884
101888
  const unresolved = [];
101889
+ let nextVideoId = 0;
101890
+ let nextAudioId = 0;
101885
101891
  html = html.replace(/<video[^>]*>/gi, (match2) => {
101886
- const { tag, unresolved: u } = compileTag(match2, true);
101892
+ const { tag, unresolved: u } = compileTag(match2, true, () => nextVideoId++);
101887
101893
  if (u) unresolved.push(u);
101888
101894
  return tag;
101889
101895
  });
101890
101896
  html = html.replace(/<audio[^>]*>/gi, (match2) => {
101891
- const { tag, unresolved: u } = compileTag(match2, false);
101897
+ const { tag, unresolved: u } = compileTag(match2, false, () => nextAudioId++);
101892
101898
  if (u) unresolved.push(u);
101893
101899
  return tag;
101894
101900
  });
@@ -104425,19 +104431,15 @@ function isHttpUrl(path12) {
104425
104431
  function parseVideoElements(html) {
104426
104432
  const videos = [];
104427
104433
  const { document: document2 } = parseHTML(html);
104428
- const videoEls = Array.from(
104429
- /* @__PURE__ */ new Set([
104430
- ...Array.from(document2.querySelectorAll("video[id][src]")),
104431
- ...Array.from(document2.querySelectorAll("video[src][data-start]"))
104432
- ])
104433
- );
104434
- videoEls.forEach((el, i) => {
104435
- if (!el.id) el.id = `hf-video-${i}`;
104436
- });
104434
+ const videoEls = document2.querySelectorAll("video[src]");
104435
+ let autoIdCounter = 0;
104437
104436
  for (const el of videoEls) {
104438
- const id = el.getAttribute("id");
104439
104437
  const src = el.getAttribute("src");
104440
- if (!id || !src) continue;
104438
+ if (!src) continue;
104439
+ const id = el.getAttribute("id") || `hf-video-${autoIdCounter++}`;
104440
+ if (!el.getAttribute("id")) {
104441
+ el.setAttribute("id", id);
104442
+ }
104441
104443
  const startAttr = el.getAttribute("data-start");
104442
104444
  const endAttr = el.getAttribute("data-end");
104443
104445
  const durationAttr = el.getAttribute("data-duration");
@@ -106334,8 +106336,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir) {
106334
106336
  );
106335
106337
  const mainVideos = parseVideoElements(html);
106336
106338
  const mainAudios = parseAudioElements(html);
106337
- const videos = dedupeElementsById([...subVideos, ...mainVideos]);
106338
- const audios = dedupeElementsById([...subAudios, ...mainAudios]);
106339
+ const videos = dedupeElementsById([...mainVideos, ...subVideos]);
106340
+ const audios = dedupeElementsById([...mainAudios, ...subAudios]);
106339
106341
  for (const video of videos) {
106340
106342
  if (isHttpUrl(video.src)) continue;
106341
106343
  const videoPath = resolve8(projectDir, video.src);
@@ -106354,22 +106356,6 @@ async function compileForRender(projectDir, htmlPath, downloadDir) {
106354
106356
  }).catch(() => {
106355
106357
  });
106356
106358
  }
106357
- const autoIdVideos = videos.filter((v) => v.id.startsWith("hf-video-"));
106358
- let htmlWithIds = html;
106359
- if (autoIdVideos.length > 0) {
106360
- const { document: idDoc } = parseHTML(html);
106361
- let changed = false;
106362
- for (const v of autoIdVideos) {
106363
- const el = idDoc.querySelector(`video[src="${v.src}"]:not([id])`);
106364
- if (el) {
106365
- el.id = v.id;
106366
- changed = true;
106367
- }
106368
- }
106369
- if (changed) {
106370
- htmlWithIds = idDoc.documentElement?.outerHTML ?? html;
106371
- }
106372
- }
106373
106359
  const { document: document2 } = parseHTML(html);
106374
106360
  const rootEl = document2.querySelector("[data-composition-id]");
106375
106361
  const width = rootEl ? parseInt(rootEl.getAttribute("data-width") || "1080", 10) : 1080;
@@ -106378,7 +106364,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir) {
106378
106364
  rootEl.getAttribute("data-duration") || rootEl.getAttribute("data-composition-duration") || "0"
106379
106365
  ) : 0;
106380
106366
  return {
106381
- html: htmlWithIds,
106367
+ html,
106382
106368
  subCompositions,
106383
106369
  videos,
106384
106370
  audios,
@@ -106468,8 +106454,8 @@ async function recompileWithResolutions(compiled, resolutions, projectDir, downl
106468
106454
  } = await parseSubCompositions(html, projectDir, downloadDir);
106469
106455
  const mainVideos = parseVideoElements(html);
106470
106456
  const mainAudios = parseAudioElements(html);
106471
- const videos = dedupeElementsById([...subVideos, ...mainVideos]);
106472
- const audios = dedupeElementsById([...subAudios, ...mainAudios]);
106457
+ const videos = dedupeElementsById([...mainVideos, ...subVideos]);
106458
+ const audios = dedupeElementsById([...mainAudios, ...subAudios]);
106473
106459
  const remaining = compiled.unresolvedCompositions.filter(
106474
106460
  (c) => !resolutions.some((r) => r.id === c.id)
106475
106461
  );