@hyperframes/producer 0.9.73 → 0.9.75

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.
@@ -2558,6 +2558,7 @@ import { linksOutside as linksOutside2 } from "@hyperframes/studio-server/outsid
2558
2558
  import {
2559
2559
  assertCompositionFileSize,
2560
2560
  CompositionExpansionBudget,
2561
+ ENTRY_PAGE,
2561
2562
  REMOTE_SCRIPTS,
2562
2563
  REMOTE_STYLESHEETS
2563
2564
  } from "@hyperframes/core/compiler";
@@ -3813,13 +3814,18 @@ function detectShaderTransitionUsage(html) {
3813
3814
  var MAX_REMOTE_ASSETS = 1e3;
3814
3815
  var ASSET_DOWNLOADS_AT_ONCE = 8;
3815
3816
  var AssetDownloads = class {
3816
- constructor(signal) {
3817
- this.signal = signal;
3818
- }
3819
- signal;
3820
3817
  reserved = /* @__PURE__ */ new Set();
3821
3818
  running = 0;
3822
3819
  queued = [];
3820
+ ended = new AbortController();
3821
+ signal;
3822
+ constructor(cancel) {
3823
+ this.signal = cancel ? AbortSignal.any([cancel, this.ended.signal]) : this.ended.signal;
3824
+ }
3825
+ /** Stops every download still running or queued: the compile that owns them has returned. */
3826
+ end() {
3827
+ this.ended.abort(new Error("The compile that started this download has ended"));
3828
+ }
3823
3829
  /** Throws before any of `urls` downloads when they would take the compile past the cap. */
3824
3830
  reserve(urls) {
3825
3831
  this.signal?.throwIfAborted();
@@ -3890,13 +3896,17 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
3890
3896
  const probe = () => withMediaProbeSlot(async () => {
3891
3897
  try {
3892
3898
  await assertMediaPayload(filePath, elementIdentity);
3893
- const profile = await probeMediaProfile2(filePath);
3899
+ const signal = run?.assets.signal;
3900
+ const profile = await probeMediaProfile2(filePath, { signal });
3894
3901
  if (tagName === "video") {
3895
- return { profile, fileDuration: (await extractMediaMetadata(filePath)).durationSeconds };
3902
+ const { durationSeconds } = await extractMediaMetadata(filePath, { signal });
3903
+ return { profile, fileDuration: durationSeconds };
3896
3904
  }
3897
3905
  try {
3898
- return { profile, fileDuration: (await extractAudioMetadata(filePath)).durationSeconds };
3906
+ const { durationSeconds } = await extractAudioMetadata(filePath, { signal });
3907
+ return { profile, fileDuration: durationSeconds };
3899
3908
  } catch {
3909
+ if (signal?.aborted) throw signal.reason;
3900
3910
  return { profile, fileDuration: null };
3901
3911
  }
3902
3912
  } catch (error) {
@@ -3952,6 +3962,7 @@ async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlB
3952
3962
  (el) => (el.tagName === "video" || el.tagName === "audio") && el.src
3953
3963
  );
3954
3964
  const unresolvedCompositions = unresolved.filter((el) => el.tagName === "div");
3965
+ run?.assets.reserve(mediaUnresolved.map((el) => el.src).filter(isHttpUrl));
3955
3966
  const resolvedResults = await Promise.all(
3956
3967
  mediaUnresolved.map(
3957
3968
  (el) => resolveMediaDuration(
@@ -3977,8 +3988,10 @@ async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlB
3977
3988
  let compiledHtml = resolutions.length > 0 ? injectDurations(markedStaticHtml, resolutions) : markedStaticHtml;
3978
3989
  const preResolved = extractResolvedMedia(compiledHtml);
3979
3990
  const hiddenVideoIds = collectHiddenVideoIds(compiledHtml);
3991
+ const clampable = preResolved.filter((el) => !!el.src && !el.loop && !hiddenVideoIds.has(el.id));
3992
+ run?.assets.reserve(clampable.map((el) => el.src).filter(isHttpUrl));
3980
3993
  const clampResults = await Promise.all(
3981
- preResolved.filter((el) => !!el.src && !el.loop && !hiddenVideoIds.has(el.id)).map(async (el) => {
3994
+ clampable.map(async (el) => {
3982
3995
  const { duration: maxDuration } = await resolveMediaDuration(
3983
3996
  el.src,
3984
3997
  el.mediaStart,
@@ -4115,13 +4128,28 @@ function promoteCssImportsToLinkTags(html) {
4115
4128
  return document2.toString();
4116
4129
  }
4117
4130
  var ProducerHostIdentityMap = class extends Map {
4118
- #document;
4119
4131
  #lateInstanceByCompositionId = /* @__PURE__ */ new Map();
4132
+ /** How many elements carry each composition id: the page once, then each mount's copy once. */
4133
+ #idCounts = /* @__PURE__ */ new Map();
4134
+ /** Hosts whose copied content has not been counted yet; the inliner fills a host after asking for it. */
4135
+ #uncounted;
4120
4136
  constructor(document2, initialHosts) {
4121
4137
  super(assignBundledRuntimeCompositionIds(initialHosts));
4122
- this.#document = document2;
4138
+ this.#uncounted = [document2];
4139
+ }
4140
+ #countUncopied() {
4141
+ for (const root of this.#uncounted.splice(0)) {
4142
+ for (const element of Array.from(root.querySelectorAll("[data-composition-id]"))) {
4143
+ this.#adjust(element.getAttribute("data-composition-id"), 1);
4144
+ }
4145
+ }
4146
+ }
4147
+ #adjust(id, by) {
4148
+ if (id) this.#idCounts.set(id, (this.#idCounts.get(id) ?? 0) + by);
4123
4149
  }
4124
4150
  get(host) {
4151
+ this.#countUncopied();
4152
+ this.#uncounted.push(host);
4125
4153
  const existing = super.get(host);
4126
4154
  if (existing) return existing;
4127
4155
  const authoredCompositionId = (host.getAttribute("data-hf-original-composition-id") || host.getAttribute("data-composition-id") || "").trim() || null;
@@ -4130,17 +4158,19 @@ var ProducerHostIdentityMap = class extends Map {
4130
4158
  this.set(host, identity2);
4131
4159
  return identity2;
4132
4160
  }
4161
+ const ownId = host.getAttribute("data-composition-id");
4162
+ const heldByOthers = (id) => (this.#idCounts.get(id) ?? 0) - (id === ownId ? 1 : 0) > 0;
4133
4163
  let instanceIndex = this.#lateInstanceByCompositionId.get(authoredCompositionId) || 0;
4134
4164
  let runtimeCompositionId;
4135
4165
  do {
4136
4166
  instanceIndex += 1;
4137
4167
  runtimeCompositionId = `${authoredCompositionId}__hf${instanceIndex}`;
4138
- } while (Array.from(this.#document.querySelectorAll("[data-composition-id]")).some(
4139
- (element) => element !== host && element.getAttribute("data-composition-id") === runtimeCompositionId
4140
- ));
4168
+ } while (heldByOthers(runtimeCompositionId));
4141
4169
  this.#lateInstanceByCompositionId.set(authoredCompositionId, instanceIndex);
4142
4170
  host.setAttribute("data-hf-original-composition-id", authoredCompositionId);
4143
4171
  host.setAttribute("data-composition-id", runtimeCompositionId);
4172
+ this.#adjust(ownId, -1);
4173
+ this.#adjust(runtimeCompositionId, 1);
4144
4174
  const identity = { authoredCompositionId, runtimeCompositionId };
4145
4175
  this.set(host, identity);
4146
4176
  return identity;
@@ -4198,6 +4228,7 @@ function coalesceHeadStylesAndBodyScripts(html) {
4198
4228
  }
4199
4229
  function inlineSubCompositions(html, subCompositions, projectDir, variableOverrides, assetRoot, outsideFiles, budget) {
4200
4230
  const { document: document2 } = parseHTML5(html);
4231
+ budget.chargeElements(ENTRY_PAGE, document2.querySelectorAll("*").length);
4201
4232
  const head = document2.querySelector("head");
4202
4233
  const body = document2.querySelector("body");
4203
4234
  const hosts = Array.from(document2.querySelectorAll("[data-composition-src]"));
@@ -5039,6 +5070,14 @@ function bindVariableMediaSources(html, variables, budget, log) {
5039
5070
  }
5040
5071
  var entryFileName = (projectDir, htmlPath) => isPathInside(htmlPath, projectDir) ? relative2(projectDir, htmlPath).split(sep3).join("/") : basename3(htmlPath);
5041
5072
  async function compileForRender(projectDir, htmlPath, downloadDir, options = {}) {
5073
+ const assets = new AssetDownloads(options.abortSignal);
5074
+ try {
5075
+ return await compileWithAssets(projectDir, htmlPath, downloadDir, options, assets);
5076
+ } finally {
5077
+ assets.end();
5078
+ }
5079
+ }
5080
+ async function compileWithAssets(projectDir, htmlPath, downloadDir, options, assets) {
5042
5081
  const assetRoot = options.allowOutsideProjectAssets ? void 0 : projectDir;
5043
5082
  const outsideFiles = { includeScripts: options.includeOutsideScripts };
5044
5083
  if (isPathInside(htmlPath, projectDir) && escapesAssetRoot(htmlPath, assetRoot)) {
@@ -5065,7 +5104,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
5065
5104
  options.log
5066
5105
  );
5067
5106
  assertSubCompositionsUsable(rawHtml, projectDir, assetRoot, outsideFiles);
5068
- const run = { probes: /* @__PURE__ */ new Map(), assets: new AssetDownloads(options.abortSignal) };
5107
+ const run = { probes: /* @__PURE__ */ new Map(), assets };
5069
5108
  const { html: compiledHtml, unresolvedCompositions } = await compileHtmlFile(
5070
5109
  rawHtml,
5071
5110
  projectDir,
@@ -6953,13 +6992,19 @@ async function runExtractVideosStage(input) {
6953
6992
  const videoPath = resolveProjectRelativeSrc4(v.src, projectDir, compiledDir);
6954
6993
  if (!opensLocally(videoPath, assetRoots)) return null;
6955
6994
  try {
6956
- const attempted = extractionPolicy.maxTransientRetries === 0 ? { result: await extractMediaMetadata4(videoPath), retries: 0 } : await runVideoExtractionWithRetry2(() => extractMediaMetadata4(videoPath), {
6957
- signal: abortSignal,
6958
- maxTransientRetries: extractionPolicy.maxTransientRetries,
6959
- onRetry: () => {
6960
- hdrProbeTransientRetries += 1;
6995
+ const attempted = extractionPolicy.maxTransientRetries === 0 ? {
6996
+ result: await extractMediaMetadata4(videoPath, { signal: abortSignal }),
6997
+ retries: 0
6998
+ } : await runVideoExtractionWithRetry2(
6999
+ () => extractMediaMetadata4(videoPath, { signal: abortSignal }),
7000
+ {
7001
+ signal: abortSignal,
7002
+ maxTransientRetries: extractionPolicy.maxTransientRetries,
7003
+ onRetry: () => {
7004
+ hdrProbeTransientRetries += 1;
7005
+ }
6961
7006
  }
6962
- });
7007
+ );
6963
7008
  const meta = attempted.result;
6964
7009
  if (isHdrColorSpace2(meta.colorSpace)) {
6965
7010
  nativeHdrVideoIds.add(v.id);
@@ -7154,7 +7199,7 @@ async function appendVideoAudioFromProbe(input) {
7154
7199
  videos.map(async (video) => {
7155
7200
  const readFrom = isHttpUrl3(video.src) ? await remoteProbeSource(video, input) : localProbeSource(video.src, input);
7156
7201
  if (readFrom === null) return null;
7157
- const metadata = await extractMediaMetadata4(readFrom);
7202
+ const metadata = await extractMediaMetadata4(readFrom, { signal: input.signal });
7158
7203
  const window2 = await resolveFinalFrameExtractionWindow2(
7159
7204
  readFrom,
7160
7205
  video,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": "0.1.0",
3
3
  "buildId": "dev",
4
- "sha256": "2b9ec8bd63b637eb9a55697e43432e9dafb356f2790240c74fbf1994ff07281c",
4
+ "sha256": "1e2a241564d840aa1cfbaca8eae45d3a961f5f1b1ec3352782c07a04088d213b",
5
5
  "artifacts": {
6
6
  "iife": "hyperframe.runtime.iife.js",
7
7
  "esm": "hyperframe.runtime.mjs"