Skip to content

Commit e6fba28

Browse files
jbernard077claude
andauthored
fix(registry): centre mk-callout-highlight with flex instead of a script-time measurement (#5118)
* fix(registry): centre mk-callout-highlight with flex instead of a script-time measurement The text box becomes a flex item of a full-frame wrapper (#mk-ch-center), so its position is laid out by the browser rather than read from a getBoundingClientRect() taken at script time. That measurement depends on which font faces are loaded when the script runs; the fonts gate covers only faces that static markup already uses, so script-built text measures against the fallback face (#5112). A non-null CONFIG.x / CONFIG.y becomes a margin offset on that axis. The GSAP y entrance stays on the box, which carries no CSS transform. Also drops the scene-exit visibility tail (the runtime hides the clip at its window end; the 0.02 s tail never reached a frame at 30 fps) and removes data-layout-allow-occlusion from #mk-ch-box: nothing beneath the block is text, and the attribute made the contrast audit skip the block's own words whenever a later full-frame host answered the hit-test probe. Renders are bit-identical to the measured version when the face is loaded (nine-scene project at v0.8.135, 1380/1380 frames). CONFIG and the sweep mechanic are unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * fix(registry): keep only the flex centring in mk-callout-highlight Address review: restore the scene-exit visibility tail and the layout occlusion attribute, which belong to family-wide conventions and are out of scope here, and note the x + maxWidth clip edge in CONFIG. Refs #5112 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 0648f1e commit e6fba28

1 file changed

Lines changed: 35 additions & 9 deletions

File tree

‎registry/blocks/mk-callout-highlight/mk-callout-highlight.html‎

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,20 @@
3030
overflow: hidden;
3131
background: transparent; /* overlays footage or mk-background */
3232
}
33-
#mk-ch-box {
33+
#mk-ch-center {
34+
/* CSS centring. The box is a flex item of this full-frame wrapper, so its
35+
place is laid out by the browser rather than measured from a DOM rect
36+
taken before web fonts are ready. An explicit CONFIG.x / CONFIG.y turns
37+
that axis into an edge offset (see the script). No pointer-events:none
38+
here: it inherits to the word spans and the contrast audit skips them. */
3439
position: absolute;
40+
inset: 0;
41+
display: flex;
42+
align-items: center;
43+
justify-content: center;
44+
}
45+
#mk-ch-box {
46+
flex: none; /* max-content width, clamped by max-width; never shrunk */
3547
font-family: var(--mk-font);
3648
font-weight: 500;
3749
letter-spacing: -0.015em;
@@ -50,7 +62,9 @@
5062
data-width="1920"
5163
data-height="1080"
5264
>
53-
<div id="mk-ch-box" data-layout-allow-occlusion></div>
65+
<div id="mk-ch-center">
66+
<div id="mk-ch-box" data-layout-allow-occlusion></div>
67+
</div>
5468
<div
5569
id="mk-ch-drv"
5670
class="clip"
@@ -74,7 +88,9 @@
7488
fontSize: 60,
7589
lineHeight: 1.3,
7690
maxWidth: 700, // px; sentence wraps inside this
77-
x: 1030, // box left edge; null = centered horizontally
91+
x: 1030, // box left edge; null = centered horizontally. Keep x + maxWidth <= 1920:
92+
// the box never shrinks (flex: none), so past the frame edge it is clipped
93+
// by the root's overflow instead of wrapping earlier.
7894
y: null, // box top edge; null = centered vertically
7995
align: "left",
8096
sweep: { start: 1.2, end: 6.2 }, // block-local seconds, linear
@@ -107,12 +123,19 @@
107123
wordEls.push(span);
108124
});
109125

110-
/* position (measure after building) */
111-
var rect = box.getBoundingClientRect();
112-
box.style.left =
113-
(CONFIG.x === null ? Math.round((1920 - rect.width) / 2) : CONFIG.x) + "px";
114-
box.style.top =
115-
(CONFIG.y === null ? Math.round((1080 - rect.height) / 2) : CONFIG.y) + "px";
126+
/* position: #mk-ch-center centres the box with flex (no measurement, so the
127+
placement does not depend on font timing). A non-null CONFIG.x / CONFIG.y
128+
switches that axis to an edge offset: the box keeps its content width
129+
(clamped by maxWidth) and is pushed from the frame edge by a margin. */
130+
var center = document.getElementById("mk-ch-center");
131+
if (CONFIG.x !== null) {
132+
center.style.justifyContent = "flex-start";
133+
box.style.marginLeft = CONFIG.x + "px";
134+
}
135+
if (CONFIG.y !== null) {
136+
center.style.alignItems = "flex-start";
137+
box.style.marginTop = CONFIG.y + "px";
138+
}
116139

117140
/* state proxy: GSAP animates st.p, render derives every word color from it */
118141
var st = { p: 0 };
@@ -127,6 +150,9 @@
127150

128151
var tl = gsap.timeline({ paused: true });
129152

153+
/* entrance / exit motion stays a GSAP transform on the box itself: the box
154+
carries no CSS transform (centring is flex on the parent), so there is
155+
nothing for the tween to fight. */
130156
if (CONFIG.animationIn) {
131157
gsap.set(box, { opacity: 0, y: 24 });
132158
tl.to(box, { opacity: 1, y: 0, duration: 0.7, ease: "power3.out" }, 0.3);

0 commit comments

Comments
 (0)