Skip to content

Commit 53e2e20

Browse files
fix(registry): six blocks load their own files and variables when mounted (#4452)
* feat(core): a composition's script can load its own files with __hyperframes.assetUrl * test(core): a template composition inside a mounted file resolves assets from that file * docs: assetUrl is for paths beside the composition, not project-root paths * docs: say assetUrl misses a project-root path * fix(core): a mounted composition's import map and module scripts run as such * refactor(core): scope a mounted module script under the same condition as a classic one * fix(core): a mounted module script loaded by src stays a module * fix(core): a mounted import map keeps the trailing slash of a prefix address * fix(registry): six blocks load their own files and variables when mounted * fix(registry): keep frost's variable declarations on its html element * fix(registry): orbit-card uses its own variables; frost font and catalog maps follow * chore(core): keep the module-script helpers' comment share at the base * fix(catalog): frost's payload runs its driving script, not the asset-base one * test(catalog): check import-map keys by membership, not a built regex
1 parent f873734 commit 53e2e20

9 files changed

Lines changed: 356 additions & 277 deletions

File tree

‎registry/blocks/canopy-part-title/canopy-part-title.html‎

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,11 @@
106106
document.getElementById("cpt-scene").appendChild(c);
107107
})();
108108

109-
var V = Object.fromEntries(
110-
JSON.parse(
111-
document
112-
.querySelector("[data-composition-variables]")
113-
.getAttribute("data-composition-variables"),
114-
).map((e) => [e.id, e.default]),
115-
);
109+
// getVariables carries the declared defaults, standalone and mounted.
110+
var V = {};
116111
try {
117112
if (window.__hyperframes && window.__hyperframes.getVariables)
118-
V = Object.assign(V, window.__hyperframes.getVariables() || {});
113+
V = window.__hyperframes.getVariables() || {};
119114
} catch (e) {
120115
/* corrupt declarations must not blank the composition */
121116
}
@@ -347,31 +342,26 @@
347342
const W = 1920,
348343
H = 1080,
349344
DUR = 12;
350-
let V = Object.fromEntries(
351-
JSON.parse(
352-
document
353-
.querySelector("[data-composition-variables]")
354-
.getAttribute("data-composition-variables"),
355-
).map((e) => [e.id, e.default]),
356-
);
345+
// Bare __hyperframes is this composition's own in a module; getVariables carries the defaults.
346+
let V = {};
357347
try {
358-
if (window.__hyperframes && window.__hyperframes.getVariables)
359-
V = Object.assign(V, window.__hyperframes.getVariables() || {});
348+
if (typeof __hyperframes !== "undefined" && __hyperframes.getVariables)
349+
V = __hyperframes.getVariables() || {};
360350
} catch (e) {
361351
/* corrupt declarations must not blank the composition */
362352
}
363353
const HEADLINE1 = String(V.headline1 ?? "Understory");
364-
const HEADLINE2 = String(V.headline2 ?? "MOVE SLOWLY");
354+
const HEADLINE2 = String(V.headline2 ?? "Move slowly");
365355
/* Headline typography is a PARAMETER — never a Design-panel edit. Any
366356
Google Fonts family name works; falls back through Gelasio/serif
367357
while (or if never) loading. */
368-
const FONT = (String(V.font || "Gelasio").trim() || "Gelasio").replace(/["']/g, "");
358+
const FONT = (String(V.font || "Helvetica").trim() || "Helvetica").replace(/["']/g, "");
369359
const FONT_WEIGHT = Math.max(
370360
100,
371361
Math.min(
372362
900,
373363
Math.round(
374-
isFinite(Number(V.fontWeight)) && Number(V.fontWeight) ? Number(V.fontWeight) : 500,
364+
isFinite(Number(V.fontWeight)) && Number(V.fontWeight) ? Number(V.fontWeight) : 900,
375365
),
376366
),
377367
);
@@ -386,7 +376,7 @@
386376
);
387377
const LETTER_SP = Math.max(
388378
-0.2,
389-
Math.min(1, isFinite(Number(V.letterSpacing)) ? Number(V.letterSpacing) : 0.1),
379+
Math.min(1, isFinite(Number(V.letterSpacing)) ? Number(V.letterSpacing) : 0.01),
390380
);
391381
const FONT_STACK = '"' + FONT + '", Gelasio, Georgia, serif';
392382
if (!/^(Helvetica|Arial|Gelasio|Georgia|serif|sans-serif|monospace)$/i.test(FONT)) {
@@ -650,10 +640,15 @@
650640
return { map, bump };
651641
}
652642

643+
// Beside this file when mounted; a runtime without assetUrl keeps the plain path.
644+
const assetUrl = (path) =>
645+
typeof __hyperframes !== "undefined" && __hyperframes.assetUrl
646+
? __hyperframes.assetUrl(path)
647+
: path;
653648
const textureLoader = new THREE.TextureLoader();
654649
const [photoSurface, photoNormal] = await Promise.all([
655-
textureLoader.loadAsync("assets/leaf-surface-color.webp"),
656-
textureLoader.loadAsync("assets/leaf-surface-normal.webp"),
650+
textureLoader.loadAsync(assetUrl("assets/leaf-surface-color.webp")),
651+
textureLoader.loadAsync(assetUrl("assets/leaf-surface-normal.webp")),
657652
]);
658653
photoSurface.colorSpace = THREE.SRGBColorSpace;
659654
photoSurface.wrapS = photoSurface.wrapT = THREE.RepeatWrapping;

‎registry/blocks/cuboid-carousel/cuboid-carousel.html‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
{
1313
"imports": {
1414
"three": "./assets/three.module.min.js",
15-
"three/addons/": "./assets/addons/"
15+
"three/addons/": "./assets/addons/",
16+
"cuboid-carousel/motion": "./assets/cuboid-motion.js"
1617
}
1718
}
1819
</script>
@@ -103,12 +104,13 @@
103104
import { RoomEnvironment } from "three/addons/environments/RoomEnvironment.js";
104105
import { mergeVertices } from "three/addons/utils/BufferGeometryUtils.js";
105106

106-
import { MOTION } from "./assets/cuboid-motion.js";
107+
import { MOTION } from "cuboid-carousel/motion";
107108

108109
const DUR = MOTION.endFrame / MOTION.fps;
110+
// Bare __hyperframes is this composition's own in a module.
109111
const V =
110-
window.__hyperframes && window.__hyperframes.getVariables
111-
? window.__hyperframes.getVariables()
112+
typeof __hyperframes !== "undefined" && __hyperframes.getVariables
113+
? __hyperframes.getVariables()
112114
: {};
113115

114116
// ---- variable readers (every one clamped to the DialKit range) ----

‎registry/blocks/frost-sequence-camera-orbit/frost-sequence-camera-orbit.html‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
<meta name="viewport" content="width=1920, height=1080" />
99
<title>Frost Sequence Rig</title>
1010
<script src="assets/gsap-3.14.2.min.js"></script>
11+
<script>
12+
// frost.js reads its asset base when it loads; beside this file when mounted.
13+
if (typeof __hyperframes !== "undefined" && __hyperframes.assetUrl)
14+
window.__frostAssetBase = __hyperframes.assetUrl("assets/");
15+
</script>
1116
<script src="assets/frost.js"></script>
1217
<style>
1318
* {
@@ -2523,6 +2528,9 @@
25232528
? window.__hyperframes.getVariables()
25242529
: {}),
25252530
};
2531+
// The default logo ships beside this file; a logo the user sets is their project's path.
2532+
if (values.logoUrl === defaults.logoUrl && window.__frostAssetBase)
2533+
values.logoUrl = window.__frostAssetBase + "logo.svg";
25262534
window.Frost.setRendererProfile(values.rendererProfile);
25272535
console.info("[Frost renderer]", JSON.stringify(window.__rewrite));
25282536
const matcapKeys = [
@@ -3160,7 +3168,7 @@
31603168
...opts,
31613169
previewPixelRatio,
31623170
rig: { duration: DURATION, mode: values.assemblyMode, sequence: true, sample: sampleRig },
3163-
fontUrl: "assets/fonts/Geist-Bold.ttf",
3171+
fontUrl: (window.__frostAssetBase || "assets/") + "fonts/Geist-Bold.ttf",
31643172
onProgress: (msg) => {
31653173
stage.dataset.state = msg;
31663174
buildStatus.textContent = "Building Frost · " + msg;

‎registry/blocks/lottie-character-walk/lottie-character-walk.html‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,19 @@
100100
if (vars.title) document.getElementById("lcw-title").textContent = vars.title;
101101
if (vars.body) document.getElementById("lcw-body").textContent = vars.body;
102102

103+
// Beside this file when mounted; a runtime without assetUrl keeps the plain path.
104+
const assetUrl = (path) =>
105+
typeof __hyperframes !== "undefined" && __hyperframes.assetUrl
106+
? __hyperframes.assetUrl(path)
107+
: path;
103108
// The character's body acting (walk, stop, point, idle) lives in the Lottie file.
104109
// The runtime seeks every player on window.__hfLottie to composition time.
105110
var mascot = lottie.loadAnimation({
106111
container: document.getElementById("lcw-mascot"),
107112
renderer: "svg",
108113
loop: false,
109114
autoplay: false,
110-
path: "assets/mascot.json",
115+
path: assetUrl("assets/mascot.json"),
111116
});
112117
window.__hfLottie = window.__hfLottie || [];
113118
window.__hfLottie.push(mascot);

0 commit comments

Comments
 (0)