@@ -13,7 +13,7 @@ import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
1313
1414import { createHash } from "node:crypto" ;
1515import { createReadStream , existsSync , mkdirSync , readFileSync } from "fs" ;
16- import { join , dirname , resolve , basename , relative } from "path" ;
16+ import { join , dirname , resolve , basename , relative , sep } from "path" ;
1717import { parseHTML } from "linkedom" ;
1818import {
1919 COMPOSITION_SOURCE_URL ,
@@ -74,7 +74,7 @@ import {
7474 readTextFile ,
7575} from "@hyperframes/parsers/asset-resolution" ;
7676import { extractMediaMetadata , extractAudioMetadata } from "../utils/ffprobe.js" ;
77- import { isPathInside , toExternalAssetKey } from "../utils/paths.js" ;
77+ import { isPathInside , resolveCompositionSrc , toExternalAssetKey } from "../utils/paths.js" ;
7878import { collectHiddenVideoIds , collectRenderMedia } from "./renderMediaCollector.js" ;
7979import {
8080 type VideoElement ,
@@ -213,6 +213,16 @@ class EmptyCompositionError extends Error {
213213 }
214214}
215215
216+ /** The html with each data-composition-src as the project-relative path it names (%xx decoded, no leading /). */
217+ function normalizeCompositionSrcs ( html : string , projectDir : string ) : string {
218+ return html . replace ( / ( \b d a t a - c o m p o s i t i o n - s r c = ) ( [ " ' ] ) ( [ ^ " ' ] * ) \2/ g, ( whole , name , quote , value ) => {
219+ if ( ! value . includes ( "%" ) && ! value . startsWith ( "/" ) ) return whole ;
220+ const file = resolveCompositionSrc ( projectDir , value ) ;
221+ if ( file === null ) return whole ;
222+ return `${ name } ${ quote } ${ relative ( projectDir , file ) . split ( sep ) . join ( "/" ) } ${ quote } ` ;
223+ } ) ;
224+ }
225+
216226/**
217227 * Recursively walk every `data-composition-src` reference reachable from
218228 * `html` (including nested sub-compositions) and verify each resolves to a
@@ -242,7 +252,11 @@ function assertSubCompositionsUsable(
242252 if ( ! srcPath ) continue ;
243253 if ( isUnresolvedAssetPlaceholder ( srcPath ) ) continue ; // __UPPER__ placeholder or unresolved templating token — not a real reference (shared with lint via @hyperframes/parsers)
244254
245- const filePath = resolve ( projectDir , srcPath ) ;
255+ const filePath = resolveCompositionSrc ( projectDir , srcPath ) ;
256+ if ( filePath === null ) {
257+ problems . push ( { srcPath, detail : "it is outside the project folder" } ) ;
258+ continue ;
259+ }
246260 // Circular reference guard. parseSubCompositions (below) silently
247261 // `continue`s on a repeat visit with no reporting at all — mirror that
248262 // silence here rather than pretend it surfaces an error somewhere else.
@@ -779,7 +793,8 @@ async function parseSubCompositions(
779793 const srcPath = el . getAttribute ( "data-composition-src" ) ;
780794 if ( ! srcPath ) continue ;
781795
782- const filePath = resolve ( projectDir , srcPath ) ;
796+ const filePath = resolveCompositionSrc ( projectDir , srcPath ) ;
797+ if ( filePath === null ) continue ;
783798
784799 // Circular reference guard
785800 if ( visited . has ( filePath ) ) {
@@ -791,7 +806,7 @@ async function parseSubCompositions(
791806 continue ;
792807 }
793808
794- const rawSubHtml = read . text ;
809+ const rawSubHtml = normalizeCompositionSrcs ( read . text , projectDir ) ;
795810 const nestedVisited = new Set ( visited ) ;
796811 nestedVisited . add ( filePath ) ;
797812
@@ -1072,8 +1087,9 @@ function inlineSubCompositions(
10721087 resolveHtml : ( srcPath : string ) => {
10731088 let compHtml = subCompositions . get ( srcPath ) || null ;
10741089 if ( ! compHtml ) {
1075- const read = readProjectFile ( resolve ( projectDir , srcPath ) ) ;
1076- if ( read . kind === "file" ) {
1090+ const filePath = resolveCompositionSrc ( projectDir , srcPath ) ;
1091+ const read = filePath ? readProjectFile ( filePath ) : null ;
1092+ if ( read ?. kind === "file" ) {
10771093 compHtml = rewriteUnresolvableGsapToCdn ( read . text , projectDir , srcPath ) ;
10781094 }
10791095 }
@@ -2067,7 +2083,10 @@ export async function compileForRender(
20672083 options : CompileForRenderOptions = { } ,
20682084) : Promise < CompiledComposition > {
20692085 const entryHtml = rebaseDirectEntryAssetPaths ( readTextFile ( htmlPath ) , projectDir , htmlPath ) ;
2070- const rawHtml = rewriteUnresolvableGsapToCdn ( entryHtml , projectDir ) ;
2086+ const rawHtml = normalizeCompositionSrcs (
2087+ rewriteUnresolvableGsapToCdn ( entryHtml , projectDir ) ,
2088+ projectDir ,
2089+ ) ;
20712090
20722091 // Pre-flight: every data-composition-src reference must resolve to a
20732092 // usable file before we spend any time compiling, launching a browser, or
0 commit comments