@hyperframes/parsers 0.7.15

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,30 @@
1
+ /**
2
+ * Damped harmonic oscillator solver for GSAP CustomEase spring curves.
3
+ *
4
+ * Generates an SVG path data string compatible with `CustomEase.create(id, data)`.
5
+ * The solver supports underdamped (bouncy), critically damped, and overdamped
6
+ * spring configurations. Output is normalized to x ∈ [0,1] with y starting at 0
7
+ * and settling to 1.
8
+ */
9
+ interface SpringPreset {
10
+ name: string;
11
+ label: string;
12
+ mass: number;
13
+ stiffness: number;
14
+ damping: number;
15
+ }
16
+ declare const SPRING_PRESETS: SpringPreset[];
17
+ /**
18
+ * Solve a damped harmonic oscillator and return a GSAP CustomEase data string.
19
+ *
20
+ * The output is an SVG path (`M0,0 L... L...`) that CustomEase.create() accepts.
21
+ * The curve is normalized so x spans [0,1] and the spring settles at y = 1.
22
+ *
23
+ * @param mass - Spring mass (> 0)
24
+ * @param stiffness - Spring stiffness constant (> 0)
25
+ * @param damping - Damping coefficient (> 0)
26
+ * @param steps - Number of sample points (default 120)
27
+ */
28
+ declare function generateSpringEaseData(mass: number, stiffness: number, damping: number, steps?: number): string;
29
+
30
+ export { SPRING_PRESETS, type SpringPreset, generateSpringEaseData };
@@ -0,0 +1,44 @@
1
+ // src/springEase.ts
2
+ var SPRING_PRESETS = [
3
+ { name: "spring-gentle", label: "Gentle", mass: 1, stiffness: 100, damping: 15 },
4
+ { name: "spring-bouncy", label: "Bouncy", mass: 1, stiffness: 180, damping: 12 },
5
+ { name: "spring-stiff", label: "Stiff", mass: 1, stiffness: 300, damping: 20 },
6
+ { name: "spring-wobbly", label: "Wobbly", mass: 1, stiffness: 120, damping: 8 },
7
+ { name: "spring-heavy", label: "Heavy", mass: 3, stiffness: 200, damping: 20 }
8
+ ];
9
+ function generateSpringEaseData(mass, stiffness, damping, steps = 120) {
10
+ const w0 = Math.sqrt(stiffness / mass);
11
+ const zeta = damping / (2 * Math.sqrt(stiffness * mass));
12
+ let settleDuration;
13
+ if (zeta < 1) {
14
+ settleDuration = Math.min(5 / (zeta * w0), 10);
15
+ } else {
16
+ const decayRate = zeta * w0 - w0 * Math.sqrt(zeta * zeta - 1);
17
+ settleDuration = Math.min(4 / Math.max(decayRate, 0.01), 10);
18
+ }
19
+ const simDuration = Math.max(settleDuration, 1);
20
+ const segments = ["M0,0"];
21
+ for (let i = 1; i <= steps; i++) {
22
+ const t = i / steps;
23
+ const simT = t * simDuration;
24
+ let value;
25
+ if (zeta < 1) {
26
+ const wd = w0 * Math.sqrt(1 - zeta * zeta);
27
+ value = 1 - Math.exp(-zeta * w0 * simT) * (Math.cos(wd * simT) + zeta * w0 / wd * Math.sin(wd * simT));
28
+ } else if (zeta === 1) {
29
+ value = 1 - (1 + w0 * simT) * Math.exp(-w0 * simT);
30
+ } else {
31
+ const s1 = -w0 * (zeta - Math.sqrt(zeta * zeta - 1));
32
+ const s2 = -w0 * (zeta + Math.sqrt(zeta * zeta - 1));
33
+ value = 1 + (s1 * Math.exp(s2 * simT) - s2 * Math.exp(s1 * simT)) / (s2 - s1);
34
+ }
35
+ segments.push(`${t.toFixed(4)},${value.toFixed(4)}`);
36
+ }
37
+ segments[segments.length - 1] = "1,1";
38
+ return `${segments[0]} L${segments.slice(1).join(" ")}`;
39
+ }
40
+ export {
41
+ SPRING_PRESETS,
42
+ generateSpringEaseData
43
+ };
44
+ //# sourceMappingURL=springEase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/springEase.ts"],"sourcesContent":["/**\n * Damped harmonic oscillator solver for GSAP CustomEase spring curves.\n *\n * Generates an SVG path data string compatible with `CustomEase.create(id, data)`.\n * The solver supports underdamped (bouncy), critically damped, and overdamped\n * spring configurations. Output is normalized to x ∈ [0,1] with y starting at 0\n * and settling to 1.\n */\n\nexport interface SpringPreset {\n name: string;\n label: string;\n mass: number;\n stiffness: number;\n damping: number;\n}\n\nexport const SPRING_PRESETS: SpringPreset[] = [\n { name: \"spring-gentle\", label: \"Gentle\", mass: 1, stiffness: 100, damping: 15 },\n { name: \"spring-bouncy\", label: \"Bouncy\", mass: 1, stiffness: 180, damping: 12 },\n { name: \"spring-stiff\", label: \"Stiff\", mass: 1, stiffness: 300, damping: 20 },\n { name: \"spring-wobbly\", label: \"Wobbly\", mass: 1, stiffness: 120, damping: 8 },\n { name: \"spring-heavy\", label: \"Heavy\", mass: 3, stiffness: 200, damping: 20 },\n];\n\n/**\n * Solve a damped harmonic oscillator and return a GSAP CustomEase data string.\n *\n * The output is an SVG path (`M0,0 L... L...`) that CustomEase.create() accepts.\n * The curve is normalized so x spans [0,1] and the spring settles at y = 1.\n *\n * @param mass - Spring mass (> 0)\n * @param stiffness - Spring stiffness constant (> 0)\n * @param damping - Damping coefficient (> 0)\n * @param steps - Number of sample points (default 120)\n */\nexport function generateSpringEaseData(\n mass: number,\n stiffness: number,\n damping: number,\n steps = 120,\n): string {\n const w0 = Math.sqrt(stiffness / mass);\n const zeta = damping / (2 * Math.sqrt(stiffness * mass));\n\n // Determine simulation duration: time until oscillation settles within threshold of 1.0.\n // Underdamped: ~5 time constants. Critically/overdamped: characteristic decay time.\n let settleDuration: number;\n if (zeta < 1) {\n settleDuration = Math.min(5 / (zeta * w0), 10);\n } else {\n const decayRate = zeta * w0 - w0 * Math.sqrt(zeta * zeta - 1);\n settleDuration = Math.min(4 / Math.max(decayRate, 0.01), 10);\n }\n const simDuration = Math.max(settleDuration, 1);\n\n const segments: string[] = [\"M0,0\"];\n\n for (let i = 1; i <= steps; i++) {\n const t = i / steps;\n const simT = t * simDuration;\n let value: number;\n\n if (zeta < 1) {\n // Underdamped — oscillates before settling\n const wd = w0 * Math.sqrt(1 - zeta * zeta);\n value =\n 1 -\n Math.exp(-zeta * w0 * simT) *\n (Math.cos(wd * simT) + ((zeta * w0) / wd) * Math.sin(wd * simT));\n } else if (zeta === 1) {\n // Critically damped — fastest approach without oscillation\n value = 1 - (1 + w0 * simT) * Math.exp(-w0 * simT);\n } else {\n // Overdamped — slow exponential approach\n const s1 = -w0 * (zeta - Math.sqrt(zeta * zeta - 1));\n const s2 = -w0 * (zeta + Math.sqrt(zeta * zeta - 1));\n value = 1 + (s1 * Math.exp(s2 * simT) - s2 * Math.exp(s1 * simT)) / (s2 - s1);\n }\n\n segments.push(`${t.toFixed(4)},${value.toFixed(4)}`);\n }\n\n // Force exact endpoint\n segments[segments.length - 1] = \"1,1\";\n\n return `${segments[0]} L${segments.slice(1).join(\" \")}`;\n}\n"],"mappings":";AAiBO,IAAM,iBAAiC;AAAA,EAC5C,EAAE,MAAM,iBAAiB,OAAO,UAAU,MAAM,GAAG,WAAW,KAAK,SAAS,GAAG;AAAA,EAC/E,EAAE,MAAM,iBAAiB,OAAO,UAAU,MAAM,GAAG,WAAW,KAAK,SAAS,GAAG;AAAA,EAC/E,EAAE,MAAM,gBAAgB,OAAO,SAAS,MAAM,GAAG,WAAW,KAAK,SAAS,GAAG;AAAA,EAC7E,EAAE,MAAM,iBAAiB,OAAO,UAAU,MAAM,GAAG,WAAW,KAAK,SAAS,EAAE;AAAA,EAC9E,EAAE,MAAM,gBAAgB,OAAO,SAAS,MAAM,GAAG,WAAW,KAAK,SAAS,GAAG;AAC/E;AAaO,SAAS,uBACd,MACA,WACA,SACA,QAAQ,KACA;AACR,QAAM,KAAK,KAAK,KAAK,YAAY,IAAI;AACrC,QAAM,OAAO,WAAW,IAAI,KAAK,KAAK,YAAY,IAAI;AAItD,MAAI;AACJ,MAAI,OAAO,GAAG;AACZ,qBAAiB,KAAK,IAAI,KAAK,OAAO,KAAK,EAAE;AAAA,EAC/C,OAAO;AACL,UAAM,YAAY,OAAO,KAAK,KAAK,KAAK,KAAK,OAAO,OAAO,CAAC;AAC5D,qBAAiB,KAAK,IAAI,IAAI,KAAK,IAAI,WAAW,IAAI,GAAG,EAAE;AAAA,EAC7D;AACA,QAAM,cAAc,KAAK,IAAI,gBAAgB,CAAC;AAE9C,QAAM,WAAqB,CAAC,MAAM;AAElC,WAAS,IAAI,GAAG,KAAK,OAAO,KAAK;AAC/B,UAAM,IAAI,IAAI;AACd,UAAM,OAAO,IAAI;AACjB,QAAI;AAEJ,QAAI,OAAO,GAAG;AAEZ,YAAM,KAAK,KAAK,KAAK,KAAK,IAAI,OAAO,IAAI;AACzC,cACE,IACA,KAAK,IAAI,CAAC,OAAO,KAAK,IAAI,KACvB,KAAK,IAAI,KAAK,IAAI,IAAM,OAAO,KAAM,KAAM,KAAK,IAAI,KAAK,IAAI;AAAA,IACpE,WAAW,SAAS,GAAG;AAErB,cAAQ,KAAK,IAAI,KAAK,QAAQ,KAAK,IAAI,CAAC,KAAK,IAAI;AAAA,IACnD,OAAO;AAEL,YAAM,KAAK,CAAC,MAAM,OAAO,KAAK,KAAK,OAAO,OAAO,CAAC;AAClD,YAAM,KAAK,CAAC,MAAM,OAAO,KAAK,KAAK,OAAO,OAAO,CAAC;AAClD,cAAQ,KAAK,KAAK,KAAK,IAAI,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI,KAAK,IAAI,MAAM,KAAK;AAAA,IAC5E;AAEA,aAAS,KAAK,GAAG,EAAE,QAAQ,CAAC,CAAC,IAAI,MAAM,QAAQ,CAAC,CAAC,EAAE;AAAA,EACrD;AAGA,WAAS,SAAS,SAAS,CAAC,IAAI;AAEhC,SAAO,GAAG,SAAS,CAAC,CAAC,KAAK,SAAS,MAAM,CAAC,EAAE,KAAK,GAAG,CAAC;AACvD;","names":[]}
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@hyperframes/parsers",
3
+ "version": "0.7.15",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/heygen-com/hyperframes",
7
+ "directory": "packages/parsers"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "README.md"
12
+ ],
13
+ "type": "module",
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "import": "./dist/index.js",
19
+ "types": "./dist/index.d.ts"
20
+ },
21
+ "./package.json": "./package.json",
22
+ "./gsap-parser": {
23
+ "import": "./dist/gsapParserExports.js",
24
+ "types": "./dist/gsapParserExports.d.ts"
25
+ },
26
+ "./gsap-parser-acorn": {
27
+ "import": "./dist/gsapParserAcorn.js",
28
+ "types": "./dist/gsapParserAcorn.d.ts"
29
+ },
30
+ "./gsap-writer-acorn": {
31
+ "import": "./dist/gsapWriterAcorn.js",
32
+ "types": "./dist/gsapWriterAcorn.d.ts"
33
+ },
34
+ "./gsap-constants": {
35
+ "import": "./dist/gsapConstants.js",
36
+ "types": "./dist/gsapConstants.d.ts"
37
+ },
38
+ "./spring-ease": {
39
+ "import": "./dist/springEase.js",
40
+ "types": "./dist/springEase.d.ts"
41
+ },
42
+ "./hf-ids": {
43
+ "import": "./dist/hfIds.js",
44
+ "types": "./dist/hfIds.d.ts"
45
+ },
46
+ "./gsap-parser-recast": {
47
+ "import": "./dist/gsapParser.js",
48
+ "types": "./dist/gsapParser.d.ts"
49
+ }
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "dependencies": {
55
+ "@babel/parser": "^7.27.0",
56
+ "acorn": "^8.17.0",
57
+ "acorn-walk": "^8.3.5",
58
+ "linkedom": "^0.18.12",
59
+ "magic-string": "^0.30.21",
60
+ "recast": "^0.23.11"
61
+ },
62
+ "devDependencies": {
63
+ "@types/node": "^25.0.10",
64
+ "tsup": "^8.0.0",
65
+ "tsx": "^4.21.0",
66
+ "typescript": "^5.0.0",
67
+ "vitest": "^3.2.4",
68
+ "@hyperframes/core": "0.7.15"
69
+ },
70
+ "scripts": {
71
+ "build": "tsup",
72
+ "test": "vitest run",
73
+ "test:watch": "vitest",
74
+ "typecheck": "tsc --noEmit"
75
+ }
76
+ }