mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-04 07:19:52 +00:00
## Summary Extracts the GSAP parser/writer suite, HTML parser, hf-ids, spring-ease, and the shared composition data types out of `@hyperframes/core/src/parsers/` into a new, independently-publishable **`@hyperframes/parsers`** package. This is the foundation of the [#1749](https://github.com/heygen-com/hyperframes/issues/1749) effort: make HyperFrames' parsing/linting/validation usable as plain libraries in a Node app, without shelling out to the CLI. Parsers is the standalone base every other extracted package builds on. **Part 1 of 3** — splits #1754 into independently-reviewable pieces. Parts 2 (lint) and 3 (studio-server) stack on this branch. ## What moves | | | |---|---| | Source moved out of core | **~9,900 LOC** (`src/parsers/` → `packages/parsers/src/`) | | Total lines removed from core (incl. tests + goldens) | ~19,600 | | Files relocated | 39 | | Tests carried over | **660 passing** (5 skipped, 3 todo) | The big movers: `gsapParser` / `gsapParserAcorn` (the recast + acorn dual parsers), `gsapWriterAcorn`, `gsapSerialize`, `gsapUnroll`, `htmlParser`, `hfIds`, `springEase`, `stableIds`, plus the `__goldens__` corpus. ## Bundle footprint of the new package | Artifact | Size | |---|---| | `dist/` (unpacked) | 1.7 MB | | npm tarball (packed) | 409 KB | | `dist/index.js` | 90 KB (**~21 KB gzipped**) | | Heaviest entries | `gsapWriterAcorn.js` 93 KB · `gsapParser.js` 91 KB | Most of the weight is the GSAP AST machinery (recast/babel/acorn). It's tree-shakeable via subpath entries (`@hyperframes/parsers/hf-ids`, `/gsap-constants`, etc.) so a consumer that only needs `hf-ids` (2 KB) doesn't pull the parsers. ## How `@hyperframes/core` changes The interesting part: **core sheds its entire AST toolchain.** | core `dependencies` | before | after | |---|---|---| | count | 9 | 6 | | removed | — | `@babel/parser`, `acorn`, `acorn-walk`, `magic-string`, `recast` | | added | — | `@hyperframes/parsers`, `linkedom` | Before this PR, importing `@hyperframes/core` at all dragged in babel + recast + acorn just to construct types. Now those live behind `@hyperframes/parsers`, and a consumer that only wants core's runtime/compiler types never resolves the parser stack. Core keeps thin `@deprecated` re-export stubs at the old subpaths (`@hyperframes/core/gsap-parser`, `/gsap-constants`, …) so nothing downstream breaks. ## Design notes - **`"bun"` export condition before `"node"`** in every package export. Bun resolves the TypeScript source directly (no pre-built `dist/`), while Node/tsx/Docker contexts fall through to `"node"` → `dist/`. This keeps the dev loop zero-build while published artifacts stay Node-consumable. - `@hyperframes/parsers` is **standalone** — zero `@hyperframes/*` dependencies — so it can be the base of the stack. ## Test plan - [x] `bun run --filter @hyperframes/parsers test` — 660 tests pass - [x] `bun run --filter @hyperframes/sdk test` — 382 tests pass - [x] `bun run build` — full monorepo build succeeds - [x] Fallow audit passes on CI
125 lines
3.1 KiB
TypeScript
125 lines
3.1 KiB
TypeScript
/**
|
|
* GSAP property and ease constants.
|
|
*
|
|
* Extracted into a standalone module so browser code can import them
|
|
* without pulling in gsapParser (which depends on recast / @babel/parser).
|
|
*/
|
|
|
|
export const SUPPORTED_PROPS = [
|
|
// 2D Transforms
|
|
"x",
|
|
"y",
|
|
"scale",
|
|
"scaleX",
|
|
"scaleY",
|
|
"rotation",
|
|
"skewX",
|
|
"skewY",
|
|
// 3D Transforms
|
|
"z",
|
|
"rotationX",
|
|
"rotationY",
|
|
"rotationZ",
|
|
"perspective",
|
|
"transformPerspective",
|
|
"transformOrigin",
|
|
// Visibility
|
|
"opacity",
|
|
"visibility",
|
|
"autoAlpha",
|
|
// Dimensions
|
|
"width",
|
|
"height",
|
|
// Colors
|
|
"color",
|
|
"backgroundColor",
|
|
"borderColor",
|
|
// Box model
|
|
"borderRadius",
|
|
// Typography
|
|
"fontSize",
|
|
"letterSpacing",
|
|
// Filter & Clipping
|
|
"filter",
|
|
"clipPath",
|
|
// DOM content (number counters, text roll-ups)
|
|
"innerText",
|
|
];
|
|
|
|
// ── Property Groups ─────────────────────────────────────────────────────────
|
|
// Each group maps to an independent GSAP tween so editing one property
|
|
// (e.g. drag → x/y) never contaminates another (e.g. scale, rotation).
|
|
|
|
export type PropertyGroupName = "position" | "scale" | "size" | "rotation" | "visual" | "other";
|
|
|
|
export const PROPERTY_GROUPS: Record<PropertyGroupName, ReadonlySet<string>> = {
|
|
position: new Set(["x", "y", "xPercent", "yPercent"]),
|
|
scale: new Set(["scale", "scaleX", "scaleY"]),
|
|
size: new Set(["width", "height"]),
|
|
rotation: new Set(["rotation", "skewX", "skewY"]),
|
|
visual: new Set(["opacity", "autoAlpha"]),
|
|
other: new Set<string>(),
|
|
};
|
|
|
|
const PROP_TO_GROUP = new Map<string, PropertyGroupName>();
|
|
for (const [group, props] of Object.entries(PROPERTY_GROUPS) as [
|
|
PropertyGroupName,
|
|
ReadonlySet<string>,
|
|
][]) {
|
|
for (const p of props) PROP_TO_GROUP.set(p, group);
|
|
}
|
|
|
|
export function classifyPropertyGroup(prop: string): PropertyGroupName {
|
|
return PROP_TO_GROUP.get(prop) ?? "other";
|
|
}
|
|
|
|
export function classifyTweenPropertyGroup(
|
|
properties: Record<string, unknown>,
|
|
): PropertyGroupName | undefined {
|
|
const groups = new Set<PropertyGroupName>();
|
|
for (const key of Object.keys(properties)) {
|
|
// transformOrigin is a modifier; `_auto` is Studio's internal endpoint marker;
|
|
// `data` is GSAP-reserved (carries the Studio hold-set tag). None is an animated
|
|
// property, so none should affect the group.
|
|
if (key === "transformOrigin" || key === "_auto" || key === "data") continue;
|
|
const g = classifyPropertyGroup(key);
|
|
groups.add(g);
|
|
}
|
|
if (groups.size === 1) return groups.values().next().value;
|
|
return undefined;
|
|
}
|
|
|
|
export const SUPPORTED_EASES = [
|
|
"none",
|
|
"power1.in",
|
|
"power1.out",
|
|
"power1.inOut",
|
|
"power2.in",
|
|
"power2.out",
|
|
"power2.inOut",
|
|
"power3.in",
|
|
"power3.out",
|
|
"power3.inOut",
|
|
"power4.in",
|
|
"power4.out",
|
|
"power4.inOut",
|
|
"back.in",
|
|
"back.out",
|
|
"back.inOut",
|
|
"elastic.in",
|
|
"elastic.out",
|
|
"elastic.inOut",
|
|
"bounce.in",
|
|
"bounce.out",
|
|
"bounce.inOut",
|
|
"expo.in",
|
|
"expo.out",
|
|
"expo.inOut",
|
|
"spring-gentle",
|
|
"spring-bouncy",
|
|
"spring-stiff",
|
|
"spring-wobbly",
|
|
"spring-heavy",
|
|
"steps(1)",
|
|
];
|