diff --git a/docs/concepts/compositions.mdx b/docs/concepts/compositions.mdx index 768e3bd534..fd6c754c82 100644 --- a/docs/concepts/compositions.mdx +++ b/docs/concepts/compositions.mdx @@ -242,6 +242,35 @@ script, CLI overrides, and which value wins. If you are building tooling on `@hyperframes/core`, `extractCompositionMetadata()` reads the same `data-composition-variables` array — that is how Studio builds its editing UI. +## Load a composition's own files from its script + +When a composition is mounted, a `src` or `href` attribute that points at a +file next to it is rewritten to where that file lives, so +`` keeps working. A path your script builds is a +plain string and is never rewritten, so resolve it with +`window.__hyperframes.assetUrl()`. It takes a path written relative to the +composition's own file and returns a URL the page can load, whether the file is +mounted, previewed or opened on its own. + +A path meant from the project root, such as `assets/logo.png` in a composition +at `compositions/intro.html` whose image sits in the project's own `assets/` +folder, already resolves from the page. Leave it as a plain string: +`assetUrl()` would look for it beside the composition and miss. + +```html compositions/globe/globe.html +
+ +
+``` + +A separate script file (` +`, + }); + + const bundled = await bundleToSingleHtml(dir); + + expect(bundled).toContain('var __hfCompositionSrc = "compositions/blk/blk.html";'); + }); + + it("binds a