@hyperframes/parsers 0.7.16 → 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.
@@ -0,0 +1,166 @@
1
+ import { K as Keyframe, V as ValidationResult } from './types-Cg0ZTXEf.js';
2
+ import { PropertyGroupName } from './gsapConstants.js';
3
+
4
+ /**
5
+ * Recast-free GSAP helpers: serialization, keyframe<->animation conversion,
6
+ * validation, and shared types.
7
+ *
8
+ * This module MUST NOT import recast / @babel/parser. It is part of the
9
+ * isomorphic core layer that the barrel and browser code depend on. AST
10
+ * parsing of GSAP source lives in the Node-only `./gsapParser` module.
11
+ */
12
+
13
+ type GsapMethod = "set" | "to" | "from" | "fromTo";
14
+ /** How a tween was constructed in source — drives display classification and editability. */
15
+ type GsapProvenanceKind = "literal" | "helper" | "loop" | "runtime-dynamic";
16
+ /**
17
+ * Origin of a parsed tween. `literal` tweens map 1:1 to a source call and edit
18
+ * directly; `helper`/`loop` tweens are expanded from a reused construct (unroll
19
+ * to edit); `runtime-dynamic` tweens come from live introspection (override to
20
+ * edit). Absent provenance is treated as `literal`.
21
+ */
22
+ interface GsapProvenance {
23
+ kind: GsapProvenanceKind;
24
+ /** Helper function name (kind === "helper"). */
25
+ fn?: string;
26
+ /** 1-based ordinal of the originating call site / loop construct in source order. */
27
+ callSite?: number;
28
+ /** 0-based iteration index (kind === "loop"). */
29
+ iteration?: number;
30
+ /** Source offset [start, end] of the originating call/loop, when known. */
31
+ sourceRange?: [number, number];
32
+ }
33
+ /** How a tween's keyframes can be edited, derived from its provenance. */
34
+ type KeyframeEditability = "direct" | "unroll" | "source";
35
+ /**
36
+ * Map provenance to an editing strategy:
37
+ * - `direct` — literal tween, maps 1:1 to source; edit in place.
38
+ * - `unroll` — helper/loop expansion; unroll to literal tweens, then edit.
39
+ * - `source` — runtime-dynamic value; not statically editable, edit the code.
40
+ */
41
+ declare function editabilityForProvenance(provenance?: GsapProvenance): KeyframeEditability;
42
+ interface GsapAnimation {
43
+ id: string;
44
+ targetSelector: string;
45
+ method: GsapMethod;
46
+ position: number | string;
47
+ properties: Record<string, number | string>;
48
+ fromProperties?: Record<string, number | string>;
49
+ duration?: number;
50
+ ease?: string;
51
+ /** Non-editable GSAP config (stagger, yoyo, repeat, etc.) preserved for round-trips. */
52
+ extras?: Record<string, unknown>;
53
+ /** Native GSAP keyframes data — present when the tween uses keyframes: { ... }. */
54
+ keyframes?: GsapKeyframesData;
55
+ /** Arc motion path config — present when the tween uses motionPath for curved position interpolation. */
56
+ arcPath?: ArcPathConfig;
57
+ /** True when the tween has a `keyframes` property that couldn't be statically resolved (dynamic). */
58
+ hasUnresolvedKeyframes?: boolean;
59
+ /** True when the tween's target selector couldn't be statically resolved (dynamic). */
60
+ hasUnresolvedSelector?: boolean;
61
+ /** Absolute start time computed by walking the timeline chain (handles +=, -=, <, >, labels). */
62
+ resolvedStart?: number;
63
+ /** True when no position arg was authored — the tween is sequentially placed by GSAP. */
64
+ implicitPosition?: boolean;
65
+ /** Which property group this tween belongs to (position, scale, size, rotation, visual, other).
66
+ * Undefined for legacy mixed tweens that bundle multiple groups. */
67
+ propertyGroup?: PropertyGroupName;
68
+ /** True for a base `gsap.set(...)` (a static hold that runs immediately, OFF the
69
+ * timeline) rather than `tl.set(...)`. Carries no timeline position and shows no
70
+ * keyframe marker — used to persist a static value (e.g. a 3D transform) without
71
+ * introducing a 0% keyframe. */
72
+ global?: boolean;
73
+ /** How this tween was constructed in source. Absent ⇒ literal. */
74
+ provenance?: GsapProvenance;
75
+ }
76
+ interface GsapPercentageKeyframe {
77
+ percentage: number;
78
+ properties: Record<string, number | string>;
79
+ ease?: string;
80
+ }
81
+ type GsapKeyframeFormat = "percentage" | "object-array" | "simple-array";
82
+ interface GsapKeyframesData {
83
+ format: GsapKeyframeFormat;
84
+ keyframes: GsapPercentageKeyframe[];
85
+ ease?: string;
86
+ easeEach?: string;
87
+ }
88
+ interface ArcPathSegment {
89
+ curviness: number;
90
+ cp1?: {
91
+ x: number;
92
+ y: number;
93
+ };
94
+ cp2?: {
95
+ x: number;
96
+ y: number;
97
+ };
98
+ }
99
+ interface ArcPathConfig {
100
+ enabled: boolean;
101
+ autoRotate: boolean | number;
102
+ segments: ArcPathSegment[];
103
+ }
104
+ interface MotionPathShape {
105
+ arcPath: ArcPathConfig;
106
+ waypoints: Array<{
107
+ x: number;
108
+ y: number;
109
+ }>;
110
+ }
111
+ /**
112
+ * Build arcPath segments + waypoints from resolved path coordinates. Shared by
113
+ * the AST parser (coords from literal nodes) and the runtime scanner (coords
114
+ * from a live `vars.motionPath`), so both produce identical arc config.
115
+ */
116
+ declare function buildArcPath(coords: Array<{
117
+ x: number;
118
+ y: number;
119
+ }>, curviness: number, autoRotate: boolean | number, isCubic: boolean): MotionPathShape | undefined;
120
+ interface ParsedGsap {
121
+ animations: GsapAnimation[];
122
+ timelineVar: string;
123
+ preamble: string;
124
+ postamble: string;
125
+ multipleTimelines?: boolean;
126
+ unsupportedTimelinePattern?: boolean;
127
+ }
128
+
129
+ interface SplitAnimationsOptions {
130
+ originalId: string;
131
+ newId: string;
132
+ splitTime: number;
133
+ elementStart: number;
134
+ elementDuration: number;
135
+ }
136
+ interface SplitAnimationsResult {
137
+ script: string;
138
+ /** Non-ID-selector animations that the engine cannot safely retarget. */
139
+ skippedSelectors: string[];
140
+ }
141
+ declare function serializeGsapAnimations(animations: GsapAnimation[], timelineVar?: string, options?: {
142
+ includeMediaSync?: boolean;
143
+ preamble?: string;
144
+ postamble?: string;
145
+ }): string;
146
+ /**
147
+ * Filter animations to those targeting `#<elementId>` (id-only match). For the
148
+ * studio panel's id-OR-selector matching, see `getAnimationsForElement` in
149
+ * `useGsapTweenCache.ts` — distinct on purpose, hence the distinct name.
150
+ */
151
+ declare function getAnimationsForElementId(animations: GsapAnimation[], elementId: string): GsapAnimation[];
152
+ declare function validateCompositionGsap(script: string): ValidationResult;
153
+ declare function keyframesToGsapAnimations(elementId: string, keyframes: Keyframe[], elementStartTime: number, base?: {
154
+ x?: number;
155
+ y?: number;
156
+ scale?: number;
157
+ }): GsapAnimation[];
158
+ declare function gsapAnimationsToKeyframes(animations: GsapAnimation[], elementStartTime: number, options?: {
159
+ baseX?: number;
160
+ baseY?: number;
161
+ baseScale?: number;
162
+ clampTimeToZero?: boolean;
163
+ skipBaseSet?: boolean;
164
+ }): Keyframe[];
165
+
166
+ export { type ArcPathConfig as A, type GsapAnimation as G, type KeyframeEditability as K, type MotionPathShape as M, type ParsedGsap as P, type SplitAnimationsOptions as S, type ArcPathSegment as a, type GsapKeyframesData as b, type GsapMethod as c, type GsapPercentageKeyframe as d, type GsapProvenance as e, type GsapProvenanceKind as f, type SplitAnimationsResult as g, editabilityForProvenance as h, getAnimationsForElementId as i, gsapAnimationsToKeyframes as j, keyframesToGsapAnimations as k, buildArcPath as l, type GsapKeyframeFormat as m, serializeGsapAnimations as s, validateCompositionGsap as v };
@@ -1,4 +1,5 @@
1
- import { G as GsapAnimation, A as ArcPathConfig, S as SplitAnimationsOptions, g as SplitAnimationsResult, a as ArcPathSegment } from './gsapSerialize-B_JRTCeV.js';
1
+ import { G as GsapAnimation, A as ArcPathConfig, S as SplitAnimationsOptions, g as SplitAnimationsResult, a as ArcPathSegment } from './gsapSerialize-Bei7m7M7.js';
2
+ import './types-Cg0ZTXEf.js';
2
3
  import './gsapConstants.js';
3
4
 
4
5
  declare function updateAnimationInScript(script: string, animationId: string, updates: Partial<GsapAnimation> & {
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
@@ -2498,11 +2498,131 @@ function unrollComputedTimeline(script) {
2498
2498
  }
2499
2499
  return ms.toString();
2500
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
+ }
2501
2618
  export {
2619
+ CANONICAL_FONT_DISPLAY_NAMES,
2502
2620
  CANVAS_DIMENSIONS,
2503
2621
  COMPOSITION_VARIABLE_TYPES,
2504
2622
  DEFAULT_DURATIONS,
2505
2623
  EXCLUDED_TAGS,
2624
+ FONT_ALIAS_KEYS,
2625
+ FONT_ALIAS_MAP,
2506
2626
  PROPERTY_GROUPS,
2507
2627
  SPRING_PRESETS,
2508
2628
  SUPPORTED_EASES,
@@ -2512,6 +2632,7 @@ export {
2512
2632
  addElementToHtml,
2513
2633
  classifyPropertyGroup,
2514
2634
  classifyTweenPropertyGroup,
2635
+ decodeUrlPathVariants,
2515
2636
  editabilityForProvenance,
2516
2637
  ensureHfIds,
2517
2638
  extractCompositionMetadata,
@@ -2530,6 +2651,7 @@ export {
2530
2651
  parseHtml,
2531
2652
  queryByAttr,
2532
2653
  removeElementFromHtml,
2654
+ resolveAliasDisplayName,
2533
2655
  serializeGsapAnimations,
2534
2656
  unrollComputedTimeline,
2535
2657
  updateElementInHtml,