diff --git a/packages/sdk/src/document.ts b/packages/sdk/src/document.ts index 97c6a4a88..24da6051b 100644 --- a/packages/sdk/src/document.ts +++ b/packages/sdk/src/document.ts @@ -14,6 +14,7 @@ import { parseGsapScriptAcornForWrite } from "@hyperframes/core/gsap-parser-acor import { findRoot, getElementStyles, + getGsapScripts, getOwnText, isNewHostBoundary, querySelectorAllDeep, @@ -67,22 +68,22 @@ function parseLocatedCached(script: string): Array<{ id: string; selector: strin */ function buildAnimationIdMap(document: Document): Map { const map = new Map(); - const script = extractGsapScript(document); - if (!script) return map; - for (const { id, selector } of parseLocatedCached(script)) { - if (!selector) continue; - let matches: Element[] = []; - try { - matches = querySelectorAllDeep(document, selector); - } catch { - continue; // selector not valid for querySelectorAll — skip - } - for (const el of matches) { - const hfId = el.getAttribute("data-hf-id"); - if (!hfId) continue; - const list = map.get(hfId); - if (list) list.push(id); - else map.set(hfId, [id]); + for (const script of getGsapScripts(document)) { + for (const { id, selector } of parseLocatedCached(script)) { + if (!selector) continue; + let matches: Element[] = []; + try { + matches = querySelectorAllDeep(document, selector); + } catch { + continue; // selector not valid for querySelectorAll — skip + } + for (const el of matches) { + const hfId = el.getAttribute("data-hf-id"); + if (!hfId) continue; + const list = map.get(hfId); + if (list) list.push(id); + else map.set(hfId, [id]); + } } } return map; @@ -198,16 +199,7 @@ function buildElement( // fallow-ignore-next-line complexity function extractGsapScript(doc: Document): string | null { - // GSAP script is the first + + `); + + const animationIds = comp.getElement("hf-line")?.animationIds ?? []; + expect(animationIds).toHaveLength(1); + expect(comp.getAllAnimationIds()).toEqual(new Set(animationIds)); + }); }); // The authored sub-comp form `hyperframes add` scaffolds: the composition id is diff --git a/packages/sdk/src/session.ts b/packages/sdk/src/session.ts index d84d9c07c..3a98ae124 100644 --- a/packages/sdk/src/session.ts +++ b/packages/sdk/src/session.ts @@ -35,7 +35,12 @@ import type { PersistAdapter, PreviewAdapter } from "./adapters/types.js"; import { parseMutable } from "./engine/model.js"; import type { ParsedDocument } from "./engine/model.js"; import { applyOp, validateOp, type MutationResult } from "./engine/mutate.js"; -import { getGsapScript, resolveScoped, declarationElement } from "./engine/model.js"; +import { + getGsapScript, + getGsapScripts, + resolveScoped, + declarationElement, +} from "./engine/model.js"; import { extractGsapLabels } from "@hyperframes/core/gsap-parser-acorn"; import { stripEmbeddedRuntimeScripts } from "@hyperframes/core/compiler/html-document"; import { parseStartExpression } from "@hyperframes/core/runtime/start-expression"; @@ -555,8 +560,11 @@ class CompositionImpl implements Composition { } getAllAnimationIds(): Set { - const script = getGsapScript(this.parsed.document); - return script ? parsedAnimationIds(script) : new Set(); + const ids = new Set(); + for (const script of getGsapScripts(this.parsed.document)) { + for (const id of parsedAnimationIds(script)) ids.add(id); + } + return ids; } // ── Selection API ────────────────────────────────────────────────────────────