mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-24 16:06:34 +00:00
fix(core): figma mapper prefixes digit-leading element ids
slugify("3D Object - Headphones") produced id="3d-object-headphones" —
valid HTML, but querySelector("#3d-…") throws (CSS idents cannot start
with a digit), which kills GSAP targeting and figma-motion translation
against imported components. uniqueSlug now prefixes digit-leading slugs
("n3d-object-headphones"). Found translating a real Figma Motion timeline.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
dfe63af3ae
commit
63ff046c30
@@ -84,6 +84,24 @@ describe("nodeToHtml", () => {
|
||||
expect(out.html).not.toContain("left: 520px");
|
||||
});
|
||||
|
||||
it("prefixes digit-leading slugs so ids stay CSS-selector-safe", () => {
|
||||
const out = nodeToHtml(
|
||||
frame([
|
||||
{
|
||||
id: "1:2",
|
||||
name: "3D Object - Headphones",
|
||||
type: "RECTANGLE",
|
||||
absoluteBoundingBox: BOX(120, 220, 100, 40),
|
||||
fills: [SOLID_BLUE],
|
||||
},
|
||||
]),
|
||||
{ resolved: [], unresolved: [] },
|
||||
);
|
||||
// "#3d-object-headphones" would throw in querySelector/GSAP targeting
|
||||
expect(out.html).toContain('id="n3d-object-headphones"');
|
||||
expect(out.html).not.toContain('id="3d-object-headphones"');
|
||||
});
|
||||
|
||||
it("emits var() with literal fallback for resolved bindings", () => {
|
||||
const out = nodeToHtml(
|
||||
frame([
|
||||
|
||||
@@ -162,7 +162,12 @@ interface RenderContext {
|
||||
}
|
||||
|
||||
function uniqueSlug(ctx: RenderContext, name: string): string {
|
||||
const base = slugify(name);
|
||||
const raw = slugify(name);
|
||||
// A digit-leading id ("3D Object" → "3d-object") is valid HTML but not a
|
||||
// valid CSS selector — querySelector("#3d-object") throws, which breaks
|
||||
// GSAP targeting and figma-motion translation. Prefix so ids stay
|
||||
// selector-safe.
|
||||
const base = /^[0-9]/.test(raw) ? `n${raw}` : raw;
|
||||
let slug = base;
|
||||
let n = 2;
|
||||
while (ctx.usedSlugs.has(slug)) slug = `${base}-${n++}`;
|
||||
|
||||
Reference in New Issue
Block a user