@hyperframes/parsers 0.7.15 → 0.7.17

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
@@ -1,10 +1,12 @@
1
- import { C as CompositionVariable, T as TimelineElement, n as CanvasResolution, o as Keyframe, p as StageZoomKeyframe, V as ValidationResult } from './gsapSerialize-B_JRTCeV.js';
2
- export { q as AddElementData, A as ArcPathConfig, a as ArcPathSegment, r as Asset, B as BooleanVariable, t as CANVAS_DIMENSIONS, u as COMPOSITION_VARIABLE_TYPES, w as ColorVariable, x as CompositionAPI, y as CompositionAsset, z as CompositionSpec, D as CompositionVariableBase, E as CompositionVariableType, F as DEFAULT_DURATIONS, H as ElementKeyframes, I as EnumVariable, J as FontVariable, G as GsapAnimation, b as GsapKeyframesData, c as GsapMethod, d as GsapPercentageKeyframe, e as GsapProvenance, f as GsapProvenanceKind, L as ImageVariable, K as KeyframeEditability, N as KeyframeProperties, O as MediaElementType, Q as MediaFile, R as NumberVariable, P as ParsedGsap, U as PlayerAPI, S as SplitAnimationsOptions, g as SplitAnimationsResult, W as StageZoom, X as StringVariable, Y as TIMELINE_COLORS, Z as TimelineCompositionElement, _ as TimelineElementBase, $ as TimelineElementType, a0 as TimelineMediaElement, a1 as TimelineTextElement, a2 as VALID_CANVAS_RESOLUTIONS, a3 as WaveformData, h as editabilityForProvenance, i as getAnimationsForElementId, a4 as getDefaultStageZoom, j as gsapAnimationsToKeyframes, a5 as isCompositionElement, a6 as isMediaElement, a7 as isTextElement, k as keyframesToGsapAnimations, a8 as normalizeResolutionFlag, s as serializeGsapAnimations, v as validateCompositionGsap } from './gsapSerialize-B_JRTCeV.js';
1
+ import { C as CompositionVariable, T as TimelineElement, a as CanvasResolution, K as Keyframe, S as StageZoomKeyframe, V as ValidationResult } from './types-Cg0ZTXEf.js';
2
+ export { A as AddElementData, b as Asset, B as BooleanVariable, c as CANVAS_DIMENSIONS, d as COMPOSITION_VARIABLE_TYPES, e as ColorVariable, f as CompositionAPI, g as CompositionAsset, h as CompositionSpec, i as CompositionVariableBase, j as CompositionVariableType, D as DEFAULT_DURATIONS, E as ElementKeyframes, k as EnumVariable, F as FontVariable, I as ImageVariable, l as KeyframeProperties, M as MediaElementType, m as MediaFile, N as NumberVariable, P as PlayerAPI, n as StageZoom, o as StringVariable, p as TIMELINE_COLORS, q as TimelineCompositionElement, r as TimelineElementBase, s as TimelineElementType, t as TimelineMediaElement, u as TimelineTextElement, v as VALID_CANVAS_RESOLUTIONS, W as WaveformData, w as getDefaultStageZoom, x as isCompositionElement, y as isMediaElement, z as isTextElement, G as normalizeResolutionFlag } from './types-Cg0ZTXEf.js';
3
+ export { A as ArcPathConfig, a as ArcPathSegment, G as GsapAnimation, b as GsapKeyframesData, c as GsapMethod, d as GsapPercentageKeyframe, e as GsapProvenance, f as GsapProvenanceKind, K as KeyframeEditability, P as ParsedGsap, S as SplitAnimationsOptions, g as SplitAnimationsResult, h as editabilityForProvenance, i as getAnimationsForElementId, j as gsapAnimationsToKeyframes, k as keyframesToGsapAnimations, s as serializeGsapAnimations, v as validateCompositionGsap } from './gsapSerialize-Bei7m7M7.js';
3
4
  export { isStudioHoldSet } from './gsapParser.js';
4
5
  export { PROPERTY_GROUPS, PropertyGroupName, SUPPORTED_EASES, SUPPORTED_PROPS, classifyPropertyGroup, classifyTweenPropertyGroup } from './gsapConstants.js';
5
6
  export { SPRING_PRESETS, SpringPreset, generateSpringEaseData } from './springEase.js';
6
7
  export { parseGsapScriptAcorn as parseGsapScript } from './gsapParserAcorn.js';
7
8
  export { EXCLUDED_TAGS, ensureHfIds, mintHfId } from './hfIds.js';
9
+ export { CANONICAL_FONT_DISPLAY_NAMES, FONT_ALIAS_KEYS, FONT_ALIAS_MAP, decodeUrlPathVariants, resolveAliasDisplayName } from './composition.js';
8
10
 
9
11
  interface ParsedHtml {
10
12
  elements: TimelineElement[];
package/dist/index.js CHANGED
@@ -1051,6 +1051,34 @@ function objectExpressionToRecord(node, scope, source) {
1051
1051
  function isGsapTimelineCall(node) {
1052
1052
  return node?.type === "CallExpression" && node.callee?.type === "MemberExpression" && node.callee.object?.name === "gsap" && node.callee.property?.name === "timeline";
1053
1053
  }
1054
+ function staticMemberKey(node) {
1055
+ if (!node || node.type !== "MemberExpression") return null;
1056
+ if (node.computed) {
1057
+ const p = node.property;
1058
+ if (p?.type === "Literal" && typeof p.value === "string") return p.value;
1059
+ return null;
1060
+ }
1061
+ return node.property?.type === "Identifier" ? node.property.name : null;
1062
+ }
1063
+ function isStaticMemberRef(node) {
1064
+ return node?.type === "MemberExpression" && staticMemberKey(node) !== null;
1065
+ }
1066
+ function sameMemberAccess(a, b) {
1067
+ if (a?.type !== "MemberExpression" || b?.type !== "MemberExpression") return false;
1068
+ if (staticMemberKey(a) !== staticMemberKey(b) || staticMemberKey(a) === null) return false;
1069
+ const ao = a.object;
1070
+ const bo = b.object;
1071
+ if (ao?.type === "Identifier" && bo?.type === "Identifier") return ao.name === bo.name;
1072
+ if (ao?.type === "MemberExpression" && bo?.type === "MemberExpression")
1073
+ return sameMemberAccess(ao, bo);
1074
+ return false;
1075
+ }
1076
+ function timelineRootSource(ref, script) {
1077
+ return ref.kind === "identifier" ? ref.name : script.slice(ref.node.start, ref.node.end);
1078
+ }
1079
+ function escapeRegExp(s) {
1080
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1081
+ }
1054
1082
  function extractTimelineDefaults(callNode, scope) {
1055
1083
  const arg = callNode.arguments?.[0];
1056
1084
  if (!arg || arg.type !== "ObjectExpression") return void 0;
@@ -1070,6 +1098,7 @@ function extractTimelineDefaults(callNode, scope) {
1070
1098
  }
1071
1099
  function findTimelineVar(ast, scope) {
1072
1100
  let timelineVar = null;
1101
+ let ref = null;
1073
1102
  let timelineCount = 0;
1074
1103
  let defaults;
1075
1104
  const emptyScope = scope ?? /* @__PURE__ */ new Map();
@@ -1077,8 +1106,9 @@ function findTimelineVar(ast, scope) {
1077
1106
  VariableDeclarator(node) {
1078
1107
  if (isGsapTimelineCall(node.init)) {
1079
1108
  timelineCount += 1;
1080
- if (!timelineVar) {
1081
- timelineVar = node.id?.name ?? null;
1109
+ if (!ref && node.id?.type === "Identifier") {
1110
+ timelineVar = node.id.name;
1111
+ ref = { kind: "identifier", name: node.id.name };
1082
1112
  defaults = extractTimelineDefaults(node.init, emptyScope);
1083
1113
  }
1084
1114
  }
@@ -1086,15 +1116,21 @@ function findTimelineVar(ast, scope) {
1086
1116
  AssignmentExpression(node) {
1087
1117
  if (isGsapTimelineCall(node.right)) {
1088
1118
  timelineCount += 1;
1089
- if (!timelineVar) {
1119
+ if (!ref) {
1090
1120
  const left = node.left;
1091
- if (left?.type === "Identifier") timelineVar = left.name;
1092
- defaults = extractTimelineDefaults(node.right, emptyScope);
1121
+ if (left?.type === "Identifier") {
1122
+ timelineVar = left.name;
1123
+ ref = { kind: "identifier", name: left.name };
1124
+ defaults = extractTimelineDefaults(node.right, emptyScope);
1125
+ } else if (isStaticMemberRef(left)) {
1126
+ ref = { kind: "member", node: left };
1127
+ defaults = extractTimelineDefaults(node.right, emptyScope);
1128
+ }
1093
1129
  }
1094
1130
  }
1095
1131
  }
1096
1132
  });
1097
- return { timelineVar, timelineCount, defaults };
1133
+ return { timelineVar, ref, timelineCount, defaults };
1098
1134
  }
1099
1135
  var BUILTIN_VAR_KEYS = /* @__PURE__ */ new Set(["duration", "ease", "delay"]);
1100
1136
  var DROPPED_VAR_KEYS = /* @__PURE__ */ new Set(["onComplete", "onStart", "onUpdate", "onRepeat"]);
@@ -1107,14 +1143,15 @@ var EXTRAS_KEYS = /* @__PURE__ */ new Set([
1107
1143
  "overwrite",
1108
1144
  "immediateRender"
1109
1145
  ]);
1110
- function isTimelineRootedCall(callNode, timelineVar) {
1146
+ function isTimelineRootedCall(callNode, ref) {
1111
1147
  let obj = callNode.callee?.object;
1112
1148
  while (obj?.type === "CallExpression") {
1113
1149
  obj = obj.callee?.object;
1114
1150
  }
1115
- return obj?.type === "Identifier" && obj.name === timelineVar;
1151
+ if (ref.kind === "identifier") return obj?.type === "Identifier" && obj.name === ref.name;
1152
+ return sameMemberAccess(obj, ref.node);
1116
1153
  }
1117
- function findAllTweenCalls(ast, timelineVar, scope, targetBindings) {
1154
+ function findAllTweenCalls(ast, ref, scope, targetBindings) {
1118
1155
  const results = [];
1119
1156
  function visit(node, ancestors) {
1120
1157
  if (!node || typeof node !== "object") return;
@@ -1123,7 +1160,7 @@ function findAllTweenCalls(ast, timelineVar, scope, targetBindings) {
1123
1160
  const callee = node.callee;
1124
1161
  const gsapSetArg = node.arguments?.[0];
1125
1162
  const isGlobalSet = callee?.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.name === "gsap" && callee.property?.type === "Identifier" && callee.property.name === "set" && (gsapSetArg?.type === "StringLiteral" || gsapSetArg?.type === "Literal" && typeof gsapSetArg.value === "string");
1126
- if (callee?.type === "MemberExpression" && callee.property?.type === "Identifier" && (isTimelineRootedCall(node, timelineVar) || isGlobalSet) && GSAP_METHODS2.has(callee.property.name)) {
1163
+ if (callee?.type === "MemberExpression" && callee.property?.type === "Identifier" && (isTimelineRootedCall(node, ref) || isGlobalSet) && GSAP_METHODS2.has(callee.property.name)) {
1127
1164
  const method = callee.property.name;
1128
1165
  const args = node.arguments;
1129
1166
  const selectorValue = args.length >= 1 ? resolveTargetSelector(args[0], nodeAncestors, scope, targetBindings) ?? "__unresolved__" : "__unresolved__";
@@ -1576,8 +1613,9 @@ function parseGsapScriptAcornForWrite(script) {
1576
1613
  const scope = collectScopeBindings(ast);
1577
1614
  const targetBindings = collectTargetBindings(ast, scope);
1578
1615
  const detection = findTimelineVar(ast, scope);
1579
- const timelineVar = detection.timelineVar ?? "tl";
1580
- const calls = findAllTweenCalls(ast, timelineVar, scope, targetBindings);
1616
+ const ref = detection.ref ?? { kind: "identifier", name: "tl" };
1617
+ const timelineVar = timelineRootSource(ref, script);
1618
+ const calls = findAllTweenCalls(ast, ref, scope, targetBindings);
1581
1619
  sortBySourcePosition(calls);
1582
1620
  const rawAnims = calls.map((call) => tweenCallToAnimation(call, scope, script));
1583
1621
  applyTimelineDefaults(rawAnims, detection.defaults);
@@ -1588,7 +1626,7 @@ function parseGsapScriptAcornForWrite(script) {
1588
1626
  call,
1589
1627
  animation: animations[i]
1590
1628
  }));
1591
- return { ast, timelineVar, hasTimeline: detection.timelineVar !== null, located };
1629
+ return { ast, timelineVar, hasTimeline: detection.ref !== null, located };
1592
1630
  } catch {
1593
1631
  return null;
1594
1632
  }
@@ -1602,24 +1640,25 @@ function parseGsapScriptAcorn(script) {
1602
1640
  });
1603
1641
  const scope = collectScopeBindings(ast);
1604
1642
  const detection = findTimelineVar(ast, scope);
1605
- const timelineVar = detection.timelineVar ?? "tl";
1606
- try {
1607
- inlineComputedTimelines(ast, timelineVar, (node) => resolveNode(node, scope));
1608
- } catch {
1643
+ const ref = detection.ref ?? { kind: "identifier", name: "tl" };
1644
+ const timelineVar = timelineRootSource(ref, script);
1645
+ if (ref.kind === "identifier") {
1646
+ try {
1647
+ inlineComputedTimelines(ast, timelineVar, (node) => resolveNode(node, scope));
1648
+ } catch {
1649
+ }
1609
1650
  }
1610
1651
  const targetBindings = collectTargetBindings(ast, scope);
1611
- const calls = findAllTweenCalls(ast, timelineVar, scope, targetBindings);
1652
+ const calls = findAllTweenCalls(ast, ref, scope, targetBindings);
1612
1653
  sortBySourcePosition(calls);
1613
1654
  const rawAnims = calls.map((call) => tweenCallToAnimation(call, scope, script));
1614
1655
  applyTimelineDefaults(rawAnims, detection.defaults);
1615
1656
  resolveTimelinePositions(rawAnims);
1616
1657
  const animations = assignStableIds(rawAnims);
1617
- const timelineMatch = script.match(
1618
- new RegExp(
1619
- `^[\\s\\S]*?(?:const|let|var)\\s+${timelineVar}\\s*=\\s*gsap\\.timeline\\s*\\([^)]*\\)\\s*;?`
1620
- )
1621
- );
1622
- const preamble = timelineMatch?.[0] ?? `const ${timelineVar} = gsap.timeline({ paused: true });`;
1658
+ const declPattern = ref.kind === "identifier" ? `(?:const|let|var)\\s+${timelineVar}\\s*=\\s*gsap\\.timeline\\s*\\([^)]*\\)\\s*;?` : `${escapeRegExp(timelineVar)}\\s*=\\s*gsap\\.timeline\\s*\\([^)]*\\)\\s*;?`;
1659
+ const timelineMatch = script.match(new RegExp(`^[\\s\\S]*?${declPattern}`));
1660
+ const fallbackPreamble = ref.kind === "identifier" ? `const ${timelineVar} = gsap.timeline({ paused: true });` : `${timelineVar} = gsap.timeline({ paused: true });`;
1661
+ const preamble = timelineMatch?.[0] ?? fallbackPreamble;
1623
1662
  const lastCallIdx = script.lastIndexOf(`${timelineVar}.`);
1624
1663
  let postamble = "";
1625
1664
  if (lastCallIdx !== -1) {
@@ -1631,7 +1670,7 @@ function parseGsapScriptAcorn(script) {
1631
1670
  }
1632
1671
  const result = { animations, timelineVar, preamble, postamble };
1633
1672
  if (detection.timelineCount > 1) result.multipleTimelines = true;
1634
- if (detection.timelineCount > 0 && detection.timelineVar === null)
1673
+ if (detection.timelineCount > 0 && detection.ref === null)
1635
1674
  result.unsupportedTimelinePattern = true;
1636
1675
  return result;
1637
1676
  } catch {
@@ -2459,11 +2498,131 @@ function unrollComputedTimeline(script) {
2459
2498
  }
2460
2499
  return ms.toString();
2461
2500
  }
2501
+
2502
+ // src/utils/urlPath.ts
2503
+ function decodeUrlPathVariants(path) {
2504
+ const variants = [path];
2505
+ try {
2506
+ const decoded = decodeURIComponent(path);
2507
+ if (decoded !== path) variants.unshift(decoded);
2508
+ } catch {
2509
+ }
2510
+ return variants;
2511
+ }
2512
+
2513
+ // src/fontAliases.ts
2514
+ var FONT_ALIAS_MAP = {
2515
+ // ── Canonical bundled fonts (self-referencing) ────────────────────────
2516
+ inter: "inter",
2517
+ montserrat: "montserrat",
2518
+ outfit: "outfit",
2519
+ nunito: "nunito",
2520
+ oswald: "oswald",
2521
+ "league gothic": "league-gothic",
2522
+ "archivo black": "archivo-black",
2523
+ "space mono": "space-mono",
2524
+ "ibm plex mono": "ibm-plex-mono",
2525
+ "jetbrains mono": "jetbrains-mono",
2526
+ "eb garamond": "eb-garamond",
2527
+ "playfair display": "playfair-display",
2528
+ "source code pro": "source-code-pro",
2529
+ "noto sans jp": "noto-sans-jp",
2530
+ roboto: "roboto",
2531
+ "open sans": "open-sans",
2532
+ lato: "lato",
2533
+ poppins: "poppins",
2534
+ // ── Common aliases → nearest canonical ────────────────────────────────
2535
+ "helvetica neue": "inter",
2536
+ helvetica: "inter",
2537
+ arial: "inter",
2538
+ "helvetica bold": "inter",
2539
+ futura: "montserrat",
2540
+ "din alternate": "montserrat",
2541
+ "arial black": "montserrat",
2542
+ "bebas neue": "league-gothic",
2543
+ "courier new": "jetbrains-mono",
2544
+ courier: "jetbrains-mono",
2545
+ garamond: "eb-garamond",
2546
+ "noto sans japanese": "noto-sans-jp",
2547
+ "segoe ui": "roboto",
2548
+ // ── macOS sans-serif system fonts → inter ─────────────────────────────
2549
+ "sf pro": "inter",
2550
+ "sf pro display": "inter",
2551
+ "sf pro text": "inter",
2552
+ "sf pro rounded": "inter",
2553
+ avenir: "inter",
2554
+ "avenir next": "inter",
2555
+ "lucida grande": "inter",
2556
+ geneva: "inter",
2557
+ optima: "inter",
2558
+ // ── Windows sans-serif system fonts → inter ───────────────────────────
2559
+ verdana: "inter",
2560
+ tahoma: "inter",
2561
+ "trebuchet ms": "inter",
2562
+ calibri: "inter",
2563
+ candara: "inter",
2564
+ corbel: "inter",
2565
+ "lucida sans": "inter",
2566
+ "lucida sans unicode": "inter",
2567
+ // ── Linux sans-serif system fonts → inter ─────────────────────────────
2568
+ "noto sans": "inter",
2569
+ "dejavu sans": "inter",
2570
+ "liberation sans": "inter",
2571
+ // ── Monospace system fonts → jetbrains-mono ───────────────────────────
2572
+ "sf mono": "jetbrains-mono",
2573
+ menlo: "jetbrains-mono",
2574
+ monaco: "jetbrains-mono",
2575
+ consolas: "jetbrains-mono",
2576
+ "lucida console": "jetbrains-mono",
2577
+ "lucida sans typewriter": "jetbrains-mono",
2578
+ "andale mono": "jetbrains-mono",
2579
+ "dejavu sans mono": "jetbrains-mono",
2580
+ "liberation mono": "jetbrains-mono",
2581
+ // ── Serif system fonts → eb-garamond ──────────────────────────────────
2582
+ georgia: "eb-garamond",
2583
+ palatino: "eb-garamond",
2584
+ "palatino linotype": "eb-garamond",
2585
+ "book antiqua": "eb-garamond",
2586
+ cambria: "eb-garamond",
2587
+ times: "eb-garamond",
2588
+ "times new roman": "eb-garamond",
2589
+ "dejavu serif": "eb-garamond",
2590
+ "liberation serif": "eb-garamond"
2591
+ };
2592
+ var FONT_ALIAS_KEYS = new Set(Object.keys(FONT_ALIAS_MAP));
2593
+ var CANONICAL_FONT_DISPLAY_NAMES = {
2594
+ inter: "Inter",
2595
+ montserrat: "Montserrat",
2596
+ outfit: "Outfit",
2597
+ nunito: "Nunito",
2598
+ oswald: "Oswald",
2599
+ "league-gothic": "League Gothic",
2600
+ "archivo-black": "Archivo Black",
2601
+ "space-mono": "Space Mono",
2602
+ "ibm-plex-mono": "IBM Plex Mono",
2603
+ "jetbrains-mono": "JetBrains Mono",
2604
+ "eb-garamond": "EB Garamond",
2605
+ "playfair-display": "Playfair Display",
2606
+ "source-code-pro": "Source Code Pro",
2607
+ "noto-sans-jp": "Noto Sans JP",
2608
+ roboto: "Roboto",
2609
+ "open-sans": "Open Sans",
2610
+ lato: "Lato",
2611
+ poppins: "Poppins"
2612
+ };
2613
+ function resolveAliasDisplayName(alias) {
2614
+ const slug = FONT_ALIAS_MAP[alias.toLowerCase()];
2615
+ if (!slug) return void 0;
2616
+ return CANONICAL_FONT_DISPLAY_NAMES[slug];
2617
+ }
2462
2618
  export {
2619
+ CANONICAL_FONT_DISPLAY_NAMES,
2463
2620
  CANVAS_DIMENSIONS,
2464
2621
  COMPOSITION_VARIABLE_TYPES,
2465
2622
  DEFAULT_DURATIONS,
2466
2623
  EXCLUDED_TAGS,
2624
+ FONT_ALIAS_KEYS,
2625
+ FONT_ALIAS_MAP,
2467
2626
  PROPERTY_GROUPS,
2468
2627
  SPRING_PRESETS,
2469
2628
  SUPPORTED_EASES,
@@ -2473,6 +2632,7 @@ export {
2473
2632
  addElementToHtml,
2474
2633
  classifyPropertyGroup,
2475
2634
  classifyTweenPropertyGroup,
2635
+ decodeUrlPathVariants,
2476
2636
  editabilityForProvenance,
2477
2637
  ensureHfIds,
2478
2638
  extractCompositionMetadata,
@@ -2491,6 +2651,7 @@ export {
2491
2651
  parseHtml,
2492
2652
  queryByAttr,
2493
2653
  removeElementFromHtml,
2654
+ resolveAliasDisplayName,
2494
2655
  serializeGsapAnimations,
2495
2656
  unrollComputedTimeline,
2496
2657
  updateElementInHtml,