@hyperframes/parsers 0.8.31 → 0.8.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -135,4 +135,12 @@ declare function unrollComputedTimeline(script: string): string;
135
135
 
136
136
  declare function queryByAttr(root: ParentNode, attr: string, value: string, tag?: string): Element | null;
137
137
 
138
- export { CanvasResolution, CompositionHtmlParseError, type CompositionMetadata, CompositionVariable, Keyframe, type OutputResolutionCompatibility, type OutputResolutionIssueKind, type ParsedHtml, StageZoomKeyframe, TimelineElement, ValidationResult, addElementToHtml, checkOutputResolutionCompatibility, extractCompositionMetadata, parseHtml, queryByAttr, removeElementFromHtml, removeElementWithGsapCascade, suggestMatchingPreset, unrollComputedTimeline, updateElementInHtml, validateCompositionHtml };
138
+ interface MediaSrcMutation {
139
+ selector: string;
140
+ operation: "src_assignment" | "set_attribute";
141
+ raw: string;
142
+ }
143
+ /** Find literal source writes whose target is a statically resolvable DOM lookup. */
144
+ declare function extractMediaSrcMutations(script: string): MediaSrcMutation[];
145
+
146
+ export { CanvasResolution, CompositionHtmlParseError, type CompositionMetadata, CompositionVariable, Keyframe, type MediaSrcMutation, type OutputResolutionCompatibility, type OutputResolutionIssueKind, type ParsedHtml, StageZoomKeyframe, TimelineElement, ValidationResult, addElementToHtml, checkOutputResolutionCompatibility, extractCompositionMetadata, extractMediaSrcMutations, parseHtml, queryByAttr, removeElementFromHtml, removeElementWithGsapCascade, suggestMatchingPreset, unrollComputedTimeline, updateElementInHtml, validateCompositionHtml };
package/dist/index.js CHANGED
@@ -3631,6 +3631,80 @@ function scanVariableUsage(scriptText) {
3631
3631
  return { usedIds, scanIncomplete };
3632
3632
  }
3633
3633
 
3634
+ // src/mediaSrcMutation.ts
3635
+ import * as acorn4 from "acorn";
3636
+ import * as acornWalk4 from "acorn-walk";
3637
+ function parseProgram2(script) {
3638
+ try {
3639
+ return acorn4.parse(script, { ecmaVersion: "latest", sourceType: "script" });
3640
+ } catch {
3641
+ return acorn4.parse(script, { ecmaVersion: "latest", sourceType: "module" });
3642
+ }
3643
+ }
3644
+ function literalString(node) {
3645
+ if (node?.type === "Literal" && typeof node.value === "string") return node.value;
3646
+ if (node?.type === "TemplateLiteral" && node.expressions?.length === 0) {
3647
+ return node.quasis?.[0]?.value?.cooked;
3648
+ }
3649
+ return void 0;
3650
+ }
3651
+ function memberName(node) {
3652
+ if (node?.type !== "MemberExpression") return void 0;
3653
+ if (!node.computed && node.property?.type === "Identifier") return node.property.name;
3654
+ return literalString(node.property);
3655
+ }
3656
+ function lookupSelector(node, bindings) {
3657
+ if (node?.type === "Identifier") return bindings.get(node.name);
3658
+ if (node?.type !== "CallExpression" || node.callee?.type !== "MemberExpression") {
3659
+ return void 0;
3660
+ }
3661
+ const method = memberName(node.callee);
3662
+ if (method !== "getElementById" && method !== "querySelector") return void 0;
3663
+ const value = literalString(node.arguments?.[0]);
3664
+ if (!value) return void 0;
3665
+ return method === "getElementById" ? `#${value}` : value;
3666
+ }
3667
+ function extractMediaSrcMutations(script) {
3668
+ try {
3669
+ const ast = parseProgram2(script);
3670
+ const bindings = /* @__PURE__ */ new Map();
3671
+ acornWalk4.simple(ast, {
3672
+ VariableDeclarator(node) {
3673
+ if (node.id?.type !== "Identifier") return;
3674
+ const selector = lookupSelector(node.init, bindings);
3675
+ if (selector) bindings.set(node.id.name, selector);
3676
+ }
3677
+ });
3678
+ const mutations = [];
3679
+ acornWalk4.simple(ast, {
3680
+ AssignmentExpression(node) {
3681
+ if (node.operator !== "=" || memberName(node.left) !== "src") return;
3682
+ const selector = lookupSelector(node.left.object, bindings);
3683
+ if (!selector) return;
3684
+ mutations.push({
3685
+ selector,
3686
+ operation: "src_assignment",
3687
+ raw: script.slice(node.start, node.end)
3688
+ });
3689
+ },
3690
+ CallExpression(node) {
3691
+ if (memberName(node.callee) !== "setAttribute") return;
3692
+ if (literalString(node.arguments?.[0])?.toLowerCase() !== "src") return;
3693
+ const selector = lookupSelector(node.callee.object, bindings);
3694
+ if (!selector) return;
3695
+ mutations.push({
3696
+ selector,
3697
+ operation: "set_attribute",
3698
+ raw: script.slice(node.start, node.end)
3699
+ });
3700
+ }
3701
+ });
3702
+ return mutations;
3703
+ } catch {
3704
+ return [];
3705
+ }
3706
+ }
3707
+
3634
3708
  // src/fontAliases.ts
3635
3709
  var FONT_ALIAS_MAP = {
3636
3710
  // ── Canonical bundled fonts (self-referencing) ────────────────────────
@@ -3766,6 +3840,7 @@ export {
3766
3840
  editabilityForProvenance,
3767
3841
  ensureHfIds,
3768
3842
  extractCompositionMetadata,
3843
+ extractMediaSrcMutations,
3769
3844
  generateSpringEaseData,
3770
3845
  getAnimationsForElementId,
3771
3846
  getDefaultStageZoom,