@hyperframes/parsers 0.9.59 → 0.9.61

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.
@@ -1,3 +1,5 @@
1
+ import { A as AssetExists } from './rewriteSubCompPaths-DrZlWrIk.js';
2
+
1
3
  /** The subset of `node:path` that `isWithinProjectRoot` needs to run under
2
4
  * an injected platform (tests pass `path.win32` / `path.posix`). */
3
5
  interface PathModuleLike {
@@ -50,6 +52,8 @@ declare function cleanAssetUrl(url: string): string;
50
52
  declare function isWithinProjectRoot(projectDir: string, candidate: string, pathModule?: PathModuleLike): boolean;
51
53
  declare function resolveLocalAssetCandidates(projectDir: string, url: string): string[];
52
54
  declare function namesAnotherNetworkRoot(base: string, target: string): boolean;
55
+ /** `AssetExists` for a project on disk; a path outside it (a share, another drive) is missing, never looked at. */
56
+ declare function projectAssetExists(projectDir: string): AssetExists;
53
57
  declare function srcOnAnotherNetworkRoot(projectDir: string, src: string): boolean;
54
58
  /** The project file a data-composition-src names, as the preview reads it; null when it leaves the project. */
55
59
  declare function resolveCompositionSrc(projectDir: string, src: string): string | null;
@@ -78,4 +82,4 @@ declare const readTextFile: (path: string) => string;
78
82
  /** Reads through one descriptor, so the file-type check and the read see the same file. */
79
83
  declare function readProjectFile(path: string): ProjectFileRead;
80
84
 
81
- export { type ProjectFileRead, cleanAssetUrl, collectSubCompositionSrcs, decodeTextHonoringBom, hasUnresolvedTemplatingToken, isRemoteOrInlineUrl, isUnresolvedAssetPlaceholder, isWithinProjectRoot, localAbsoluteAssetFile, maskNonScannableRanges, namesAnotherNetworkRoot, readProjectFile, readTextFile, resolveAuthoredAssetFile, resolveCompositionSrc, resolveExistingLocalAsset, resolveLocalAssetCandidates, resolveProjectRelativeSrc, srcOnAnotherNetworkRoot };
85
+ export { type ProjectFileRead, cleanAssetUrl, collectSubCompositionSrcs, decodeTextHonoringBom, hasUnresolvedTemplatingToken, isRemoteOrInlineUrl, isUnresolvedAssetPlaceholder, isWithinProjectRoot, localAbsoluteAssetFile, maskNonScannableRanges, namesAnotherNetworkRoot, projectAssetExists, readProjectFile, readTextFile, resolveAuthoredAssetFile, resolveCompositionSrc, resolveExistingLocalAsset, resolveLocalAssetCandidates, resolveProjectRelativeSrc, srcOnAnotherNetworkRoot };
@@ -210,6 +210,12 @@ function namesAnotherNetworkRoot(base, target) {
210
210
  const root = parse(resolve3(target)).root;
211
211
  return /^[\\/]{2}/.test(root) && root.toLowerCase() !== parse(resolve3(base)).root.toLowerCase();
212
212
  }
213
+ function projectAssetExists(projectDir) {
214
+ return (path) => {
215
+ const file = resolve3(projectDir, path);
216
+ return isWithinProjectRoot(projectDir, file) && existsSync(file);
217
+ };
218
+ }
213
219
  function srcOnAnotherNetworkRoot(projectDir, src) {
214
220
  const path = fileUrlAsPath(cleanAssetUrl(src));
215
221
  return isAbsolute2(path) && namesAnotherNetworkRoot(projectDir, path);
@@ -338,6 +344,7 @@ export {
338
344
  localAbsoluteAssetFile,
339
345
  maskNonScannableRanges,
340
346
  namesAnotherNetworkRoot,
347
+ projectAssetExists,
341
348
  readProjectFile,
342
349
  readTextFile,
343
350
  resolveAuthoredAssetFile,
package/dist/assets.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { A as AssetExists, r as rewriteAssetPath, a as rewriteAssetPaths, b as rewriteCssAssetUrls, c as rewriteInlineStyleAssetUrls } from './rewriteSubCompPaths-DrZlWrIk.js';
1
2
  export { a as decodeCssEscapes, b as decodeWellFormedEscapes, c as decodedUrlPath, e as encodeUrlPath, s as splitUrlSuffix } from './urlPath-CYK47t9W.js';
2
3
 
3
4
  /**
@@ -20,71 +21,6 @@ declare const PATH_ATTRS: readonly ["src", "href"];
20
21
  declare function isNonRelativeUrl(val: string): boolean;
21
22
  declare function isPathInside(childPath: string, parentPath: string): boolean;
22
23
 
23
- /**
24
- * Rewrite relative asset paths in sub-composition content so they resolve
25
- * correctly after the content is inlined into the root document.
26
- *
27
- * A sub-composition at "compositions/scene.html" referencing "../icon.svg"
28
- * means the project root — but after inlining into root index.html, the
29
- * "../" escapes the project directory and causes 404s. This function
30
- * resolves each relative path against the sub-composition's directory,
31
- * then normalizes it to be relative to the project root.
32
- *
33
- * Used by both the core bundler (preview) and the producer compiler (render)
34
- * to ensure consistent behavior.
35
- */
36
- /**
37
- * Probe for "does this project-root-relative path exist?", supplied by callers
38
- * that can see the filesystem (the studio preview builder, the bundler, the
39
- * producer). Keeps this module free of `node:fs` so it stays browser-safe.
40
- *
41
- * It disambiguates the two conventions for a plain relative path authored in a
42
- * sub-composition that lives in a subdirectory:
43
- *
44
- * 1. A SIBLING file — `<link href="_shared.css">` next to the composition.
45
- * This is what a browser resolves when the file is opened directly, and
46
- * what an author means. Once the content moves into the project-root
47
- * document it must become `design/styleframes/_shared.css` or it 404s.
48
- * 2. A PROJECT-ROOT asset — registry blocks are installed into a
49
- * subdirectory but reference `assets/logo.png` at the root. Already
50
- * correct in the root document; rewriting would break it.
51
- *
52
- * A sibling that exists on disk means (1); anything else is left as authored.
53
- * Without a probe the behavior is unchanged — plain relative paths pass through.
54
- */
55
- type AssetExists = (projectRelativePath: string) => boolean;
56
- /**
57
- * Rewrite a single relative path from a sub-composition's context to the
58
- * project root context.
59
- *
60
- * @param compSrcPath - The `data-composition-src` value (e.g. "compositions/scene.html")
61
- * @param relativePath - The asset path to rewrite (e.g. "../icon.svg")
62
- * @param assetExists - Optional filesystem probe; see `AssetExists`.
63
- * @returns The rewritten path relative to project root (e.g. "icon.svg"), or
64
- * the original path if no rewriting is needed.
65
- */
66
- declare function rewriteAssetPath(compSrcPath: string, relativePath: string, assetExists?: AssetExists): string;
67
- /**
68
- * Rewrite all relative `src` and `href` attributes on elements within a
69
- * DOM tree, adjusting paths from the sub-composition's directory context
70
- * to the project root.
71
- *
72
- * @param elements - Iterable of DOM elements to scan (e.g. from querySelectorAll)
73
- * @param compSrcPath - The `data-composition-src` value
74
- * @param getAttr - Function to read an attribute from an element
75
- * @param setAttr - Function to set an attribute on an element
76
- */
77
- declare function rewriteAssetPaths<T>(elements: Iterable<T>, compSrcPath: string, getAttr: (el: T, attr: string) => string | null | undefined, setAttr: (el: T, attr: string, value: string) => void, assetExists?: AssetExists): void;
78
- /**
79
- * Rewrite CSS url(...) references inside inline style attributes.
80
- */
81
- declare function rewriteInlineStyleAssetUrls<T>(elements: Iterable<T>, compSrcPath: string, getStyle: (el: T) => string | null | undefined, setStyle: (el: T, value: string) => void, assetExists?: AssetExists): void;
82
- /**
83
- * Rewrite CSS url(...) references in a sub-composition's inline styles so
84
- * ../foo.woff2 remains valid after the CSS is hoisted into the root document.
85
- */
86
- declare function rewriteCssAssetUrls(cssText: string, compSrcPath: string, assetExists?: AssetExists): string;
87
-
88
24
  declare function rewriteSrcsetUrls(srcset: string, rewriteUrl: (url: string) => string): string;
89
25
 
90
- export { type AssetExists, CSS_URL_RE, PATH_ATTRS, isNonRelativeUrl, isPathInside, rewriteAssetPath, rewriteAssetPaths, rewriteCssAssetUrls, rewriteInlineStyleAssetUrls, rewriteSrcsetUrls };
26
+ export { CSS_URL_RE, PATH_ATTRS, isNonRelativeUrl, isPathInside, rewriteSrcsetUrls };
@@ -1,3 +1,6 @@
1
+ import { Readable } from 'node:stream';
2
+ export { assertLiteralMediaInput } from './literalMediaInput.js';
3
+
1
4
  /** Whether a program in `dir` may be run without the person naming it. */
2
5
  declare function isTrustedDirectory(dir: string): boolean;
3
6
  /** Whether `file` is an absolute path in a folder {@link isTrustedDirectory} accepts. */
@@ -10,12 +13,6 @@ declare function trustedPathDirs(pathValue?: string, platform?: NodeJS.Platform,
10
13
  declare function executableIn(dir: string, name: string): string | undefined;
11
14
  declare function findTrustedExecutable(name: string): string | undefined;
12
15
 
13
- /**
14
- * Shared FFmpeg/FFprobe binary resolution for every package that shells out
15
- * to them (engine, cli, lint, studio-server). Node-only: import via the
16
- * `@hyperframes/parsers/ff-binaries` subpath, never from a browser bundle.
17
- */
18
-
19
16
  declare const FFMPEG_PATH_ENV = "HYPERFRAMES_FFMPEG_PATH";
20
17
  declare const FFPROBE_PATH_ENV = "HYPERFRAMES_FFPROBE_PATH";
21
18
  type FfBinaryName = "ffmpeg" | "ffprobe";
@@ -50,7 +47,10 @@ declare function clearFfBinaryLookupCache(): void;
50
47
  declare const SELF_CONTAINED_FORMATS = "mov,matroska,mxf,avi,mpeg,mpegts,mpegvideo,flv,asf,ogg,wav,mp3,aac,flac,aiff,gif,image2,png_pipe,jpeg_pipe,webp_pipe,bmp_pipe,tiff_pipe";
51
48
  /** Tests feed a `-demuxers` listing so none spawns a binary; no argument forgets it. */
52
49
  declare function _setDemuxerListingForTests(listing?: string): void;
53
- /** Every demuxer `listingBinary` reports that opens nothing by itself and is not text art; one that cannot be asked gets the self-contained list, and is asked again. */
54
- declare function mediaInputFormatArgs(listingBinary: string): string[];
55
50
 
56
- export { FFMPEG_PATH_ENV, FFPROBE_PATH_ENV, type FfBinaryName, type FindFfBinaryOptions, SELF_CONTAINED_FORMATS, _setDemuxerListingForTests, clearFfBinaryLookupCache, executableIn, findFfBinary, findTrustedExecutable, getSkippedX86Binary, isTrustedDirectory, isTrustedExecutablePath, isX86OnlyMachO, mediaInputFormatArgs, pathEntries, requireFfBinary, trustedPathDirs };
51
+ /** Every demuxer `listingBinary` reports that opens nothing by itself and is not text art, for reading `input`; one that cannot be asked gets the self-contained list, and is asked again. */
52
+ declare function mediaInputFormatArgs(listingBinary: string, input: string): string[];
53
+ /** Hears the furthest output time, in seconds, that ffmpeg's `-progress pipe:1` lines on `stream` report. */
54
+ declare function followFfmpegProgress(stream: Readable, onSeconds: (seconds: number) => void): void;
55
+
56
+ export { FFMPEG_PATH_ENV, FFPROBE_PATH_ENV, type FfBinaryName, type FindFfBinaryOptions, SELF_CONTAINED_FORMATS, _setDemuxerListingForTests, clearFfBinaryLookupCache, executableIn, findFfBinary, findTrustedExecutable, followFfmpegProgress, getSkippedX86Binary, isTrustedDirectory, isTrustedExecutablePath, isX86OnlyMachO, mediaInputFormatArgs, pathEntries, requireFfBinary, trustedPathDirs };
@@ -139,6 +139,17 @@ function findTrustedExecutable(name) {
139
139
  return void 0;
140
140
  }
141
141
 
142
+ // src/literalMediaInput.ts
143
+ var PATTERN_IMAGE2_EXPANDS = /%(?:\d*d|[%*?[\]{}])/;
144
+ var URL_SCHEME = /^[a-z][a-z0-9+.-]+:/i;
145
+ function assertLiteralMediaInput(input) {
146
+ const local = !URL_SCHEME.test(input) || /^file:/i.test(input);
147
+ if (!local || !PATTERN_IMAGE2_EXPANDS.test(input)) return;
148
+ throw new Error(
149
+ `[FFmpeg] refused media path "${input.split(/[\\/]/).pop()}": a "%" followed by a number and "d", another "%" or a wildcard would make ffmpeg read it as a pattern of other files. Rename the file or folder.`
150
+ );
151
+ }
152
+
142
153
  // src/ffBinaries.ts
143
154
  var FFMPEG_PATH_ENV = "HYPERFRAMES_FFMPEG_PATH";
144
155
  var FFPROBE_PATH_ENV = "HYPERFRAMES_FFPROBE_PATH";
@@ -311,7 +322,8 @@ function _setDemuxerListingForTests(listing) {
311
322
  listingOverride = listing;
312
323
  demuxerLists.clear();
313
324
  }
314
- function mediaInputFormatArgs(listingBinary) {
325
+ function mediaInputFormatArgs(listingBinary, input) {
326
+ assertLiteralMediaInput(input);
315
327
  let formats = demuxerLists.get(listingBinary);
316
328
  if (formats === void 0) {
317
329
  try {
@@ -331,15 +343,34 @@ function mediaInputFormatArgs(listingBinary) {
331
343
  }
332
344
  return ["-format_whitelist", formats];
333
345
  }
346
+ var OUT_TIME = /^out_time_(?:us|ms)=(\d+)$/;
347
+ function followFfmpegProgress(stream, onSeconds) {
348
+ let furthest = 0;
349
+ let lineTail = "";
350
+ stream.on("data", (chunk) => {
351
+ const lines = (lineTail + chunk.toString()).split("\n");
352
+ lineTail = lines.pop() ?? "";
353
+ for (const line of lines) {
354
+ const reached = OUT_TIME.exec(line.trim());
355
+ if (!reached) continue;
356
+ const seconds = Number(reached[1]) / 1e6;
357
+ if (seconds <= furthest) continue;
358
+ furthest = seconds;
359
+ onSeconds(seconds);
360
+ }
361
+ });
362
+ }
334
363
  export {
335
364
  FFMPEG_PATH_ENV,
336
365
  FFPROBE_PATH_ENV,
337
366
  SELF_CONTAINED_FORMATS,
338
367
  _setDemuxerListingForTests,
368
+ assertLiteralMediaInput,
339
369
  clearFfBinaryLookupCache,
340
370
  executableIn,
341
371
  findFfBinary,
342
372
  findTrustedExecutable,
373
+ followFfmpegProgress,
343
374
  getSkippedX86Binary,
344
375
  isTrustedDirectory,
345
376
  isTrustedExecutablePath,
@@ -0,0 +1,4 @@
1
+ /** ffmpeg's image2 demuxer would open other files, folders included, than the one a project check approved. */
2
+ declare function assertLiteralMediaInput(input: string): void;
3
+
4
+ export { assertLiteralMediaInput };
@@ -0,0 +1,13 @@
1
+ // src/literalMediaInput.ts
2
+ var PATTERN_IMAGE2_EXPANDS = /%(?:\d*d|[%*?[\]{}])/;
3
+ var URL_SCHEME = /^[a-z][a-z0-9+.-]+:/i;
4
+ function assertLiteralMediaInput(input) {
5
+ const local = !URL_SCHEME.test(input) || /^file:/i.test(input);
6
+ if (!local || !PATTERN_IMAGE2_EXPANDS.test(input)) return;
7
+ throw new Error(
8
+ `[FFmpeg] refused media path "${input.split(/[\\/]/).pop()}": a "%" followed by a number and "d", another "%" or a wildcard would make ffmpeg read it as a pattern of other files. Rename the file or folder.`
9
+ );
10
+ }
11
+ export {
12
+ assertLiteralMediaInput
13
+ };
@@ -27,6 +27,7 @@ var STUDIO_FILES = /* @__PURE__ */ new Set([
27
27
  ".hyperframes/studio-manual-edits.json"
28
28
  ]);
29
29
  var STUDIO_FOLDERS = [".hyperframes/prepared-assets", ".hyperframes/requests"];
30
+ var UNCONVERTED_PREVIEW_DOWNLOADS = ".hyperframes/prepared-assets/downloads";
30
31
  var CREDENTIAL_FILES = /* @__PURE__ */ new Set([
31
32
  ".npmrc",
32
33
  ".yarnrc",
@@ -81,6 +82,8 @@ function isStudioPrivatePath(relPath) {
81
82
  var MEDIA_FOLDER = ".media";
82
83
  var LOADED_ASSET_TYPE = /.\.(?:png|jpe?g|gif|webp|avif|svg|ico|bmp|tiff?|heic|heif|mp4|m4v|mov|webm|mkv|mxf|avi|mp3|wav|m4a|aac|ogg|oga|opus|flac|woff2?|ttf|otf|css|m?js|cjs)$/;
83
84
  function isStudioOwnFile(path) {
85
+ if (path === UNCONVERTED_PREVIEW_DOWNLOADS || path.startsWith(`${UNCONVERTED_PREVIEW_DOWNLOADS}/`))
86
+ return false;
84
87
  return STUDIO_FILES.has(path) || STUDIO_FOLDERS.some((folder) => path === folder || path.startsWith(`${folder}/`));
85
88
  }
86
89
  function isPrivateFileUnder(projectDir, filePath, isPrivate) {
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Rewrite relative asset paths in sub-composition content so they resolve
3
+ * correctly after the content is inlined into the root document.
4
+ *
5
+ * A sub-composition at "compositions/scene.html" referencing "../icon.svg"
6
+ * means the project root — but after inlining into root index.html, the
7
+ * "../" escapes the project directory and causes 404s. This function
8
+ * resolves each relative path against the sub-composition's directory,
9
+ * then normalizes it to be relative to the project root.
10
+ *
11
+ * Used by both the core bundler (preview) and the producer compiler (render)
12
+ * to ensure consistent behavior.
13
+ */
14
+ /**
15
+ * Probe for "does this project-root-relative path exist?", supplied by callers
16
+ * that can see the filesystem (the studio preview builder, the bundler, the
17
+ * producer). Keeps this module free of `node:fs` so it stays browser-safe.
18
+ *
19
+ * It disambiguates the two conventions for a plain relative path authored in a
20
+ * sub-composition that lives in a subdirectory:
21
+ *
22
+ * 1. A SIBLING file — `<link href="_shared.css">` next to the composition.
23
+ * This is what a browser resolves when the file is opened directly, and
24
+ * what an author means. Once the content moves into the project-root
25
+ * document it must become `design/styleframes/_shared.css` or it 404s.
26
+ * 2. A PROJECT-ROOT asset — registry blocks are installed into a
27
+ * subdirectory but reference `assets/logo.png` at the root. Already
28
+ * correct in the root document; rewriting would break it.
29
+ *
30
+ * A sibling that exists on disk means (1); anything else is left as authored.
31
+ * Without a probe the behavior is unchanged — plain relative paths pass through.
32
+ */
33
+ type AssetExists = (projectRelativePath: string) => boolean;
34
+ /**
35
+ * Rewrite a single relative path from a sub-composition's context to the
36
+ * project root context.
37
+ *
38
+ * @param compSrcPath - The `data-composition-src` value (e.g. "compositions/scene.html")
39
+ * @param relativePath - The asset path to rewrite (e.g. "../icon.svg")
40
+ * @param assetExists - Optional filesystem probe; see `AssetExists`.
41
+ * @returns The rewritten path relative to project root (e.g. "icon.svg"), or
42
+ * the original path if no rewriting is needed.
43
+ */
44
+ declare function rewriteAssetPath(compSrcPath: string, relativePath: string, assetExists?: AssetExists): string;
45
+ /**
46
+ * Rewrite all relative `src` and `href` attributes on elements within a
47
+ * DOM tree, adjusting paths from the sub-composition's directory context
48
+ * to the project root.
49
+ *
50
+ * @param elements - Iterable of DOM elements to scan (e.g. from querySelectorAll)
51
+ * @param compSrcPath - The `data-composition-src` value
52
+ * @param getAttr - Function to read an attribute from an element
53
+ * @param setAttr - Function to set an attribute on an element
54
+ */
55
+ declare function rewriteAssetPaths<T>(elements: Iterable<T>, compSrcPath: string, getAttr: (el: T, attr: string) => string | null | undefined, setAttr: (el: T, attr: string, value: string) => void, assetExists?: AssetExists): void;
56
+ /**
57
+ * Rewrite CSS url(...) references inside inline style attributes.
58
+ */
59
+ declare function rewriteInlineStyleAssetUrls<T>(elements: Iterable<T>, compSrcPath: string, getStyle: (el: T) => string | null | undefined, setStyle: (el: T, value: string) => void, assetExists?: AssetExists): void;
60
+ /**
61
+ * Rewrite CSS url(...) references in a sub-composition's inline styles so
62
+ * ../foo.woff2 remains valid after the CSS is hoisted into the root document.
63
+ */
64
+ declare function rewriteCssAssetUrls(cssText: string, compSrcPath: string, assetExists?: AssetExists): string;
65
+
66
+ export { type AssetExists as A, rewriteAssetPaths as a, rewriteCssAssetUrls as b, rewriteInlineStyleAssetUrls as c, rewriteAssetPath as r };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/parsers",
3
- "version": "0.9.59",
3
+ "version": "0.9.61",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/heygen-com/hyperframes",
@@ -92,6 +92,10 @@
92
92
  "import": "./dist/ffBinaries.js",
93
93
  "types": "./dist/ffBinaries.d.ts"
94
94
  },
95
+ "./literal-media-input": {
96
+ "import": "./dist/literalMediaInput.js",
97
+ "types": "./dist/literalMediaInput.d.ts"
98
+ },
95
99
  "./media-alpha": {
96
100
  "import": "./dist/mediaAlpha.js",
97
101
  "types": "./dist/mediaAlpha.d.ts"
@@ -147,7 +151,7 @@
147
151
  "tsx": "^4.21.0",
148
152
  "typescript": "^5.0.0",
149
153
  "vitest": "^4.1.12",
150
- "@hyperframes/core": "0.9.59"
154
+ "@hyperframes/core": "0.9.61"
151
155
  },
152
156
  "scripts": {
153
157
  "build": "tsup",