@hyperframes/parsers 0.8.116 → 0.8.118

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.
@@ -15,6 +15,11 @@ type PositionWrite = Pick<GsapAnimation, "propertyGroup" | "properties" | "fromP
15
15
  declare function isXYPositionWrite(a: PositionWrite): boolean;
16
16
  declare function classifyPropertyGroup(prop: string): PropertyGroupName;
17
17
  declare function classifyTweenPropertyGroup(properties: Record<string, unknown>): PropertyGroupName | undefined;
18
+ /**
19
+ * What a Studio hold pins from t=0 before a later keyframed tween: its first keyframe's position props,
20
+ * minus those an earlier timeline tween on the target writes (a global `gsap.set` is a base value).
21
+ */
22
+ declare function positionHoldForAnimation(animation: GsapAnimation, animations: readonly GsapAnimation[]): Record<string, number> | null;
18
23
  declare const SUPPORTED_EASES: string[];
19
24
 
20
25
  /**
@@ -203,4 +208,4 @@ declare function gsapAnimationsToKeyframes(animations: GsapAnimation[], elementS
203
208
  skipBaseSet?: boolean;
204
209
  }): Keyframe[];
205
210
 
206
- export { type ArcPathConfig as A, type GsapAnimation as G, type KeyframeEditability as K, type MotionPathShape as M, PROPERTY_GROUPS as P, SUPPORTED_EASES 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 ParsedGsap as g, type PropertyGroupName as h, SUPPORTED_PROPS as i, type SourcedGsapPercentageKeyframe as j, type SplitAnimationsOptions as k, type SplitAnimationsResult as l, classifyPropertyGroup as m, classifyTweenPropertyGroup as n, editabilityForProvenance as o, getAnimationsForElementId as p, gsapAnimationsToKeyframes as q, keyframesToGsapAnimations as r, serializeGsapAnimations as s, buildArcPath as t, type GsapKeyframeFormat as u, validateCompositionGsap as v, isXYPositionWrite as w };
211
+ export { type ArcPathConfig as A, type GsapAnimation as G, type KeyframeEditability as K, type MotionPathShape as M, PROPERTY_GROUPS as P, SUPPORTED_EASES 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 ParsedGsap as g, type PropertyGroupName as h, SUPPORTED_PROPS as i, type SourcedGsapPercentageKeyframe as j, type SplitAnimationsOptions as k, type SplitAnimationsResult as l, classifyPropertyGroup as m, classifyTweenPropertyGroup as n, editabilityForProvenance as o, getAnimationsForElementId as p, gsapAnimationsToKeyframes as q, keyframesToGsapAnimations as r, serializeGsapAnimations as s, buildArcPath as t, type GsapKeyframeFormat as u, validateCompositionGsap as v, isXYPositionWrite as w, positionHoldForAnimation as x };
@@ -1,4 +1,4 @@
1
- import { G as GsapAnimation, A as ArcPathConfig, k as SplitAnimationsOptions, l as SplitAnimationsResult, a as ArcPathSegment } from './gsapSerialize-g8oprts9.js';
1
+ import { G as GsapAnimation, A as ArcPathConfig, k as SplitAnimationsOptions, l as SplitAnimationsResult, a as ArcPathSegment } from './gsapSerialize-CVwsMItk.js';
2
2
  import './types-Ejqndkej.js';
3
3
 
4
4
  type TweenTarget = Pick<GsapAnimation, "targetSelector" | "hasPartialSelector">;
@@ -14,9 +14,11 @@ var PROP_TO_GROUP = /* @__PURE__ */ new Map();
14
14
  for (const [group, props] of Object.entries(PROPERTY_GROUPS)) {
15
15
  for (const p of props) PROP_TO_GROUP.set(p, group);
16
16
  }
17
+ function writesProperty(animation, property) {
18
+ return property in animation.properties || !!animation.fromProperties && property in animation.fromProperties || !!animation.keyframes?.keyframes.some((k) => property in k.properties);
19
+ }
17
20
  function isXYPositionWrite(a) {
18
- const xy = (props) => !!props && ("x" in props || "y" in props);
19
- return a.propertyGroup === "position" && (xy(a.properties) || xy(a.fromProperties) || !!a.keyframes?.keyframes.some((k) => xy(k.properties)));
21
+ return a.propertyGroup === "position" && (writesProperty(a, "x") || writesProperty(a, "y"));
20
22
  }
21
23
  function classifyPropertyGroup(prop) {
22
24
  return PROP_TO_GROUP.get(prop) ?? "other";
@@ -31,6 +33,30 @@ function classifyTweenPropertyGroup(properties) {
31
33
  if (groups.size === 1) return groups.values().next().value;
32
34
  return void 0;
33
35
  }
36
+ function knownStart(animation) {
37
+ if (animation.resolvedStart !== void 0) return animation.resolvedStart;
38
+ return typeof animation.position === "number" ? animation.position : void 0;
39
+ }
40
+ function positionHoldForAnimation(animation, animations) {
41
+ if (!animation.keyframes) return null;
42
+ const start = knownStart(animation) ?? 0;
43
+ if (!(start > 1e-3)) return null;
44
+ const first = [...animation.keyframes.keyframes].sort(
45
+ (left, right) => left.percentage - right.percentage
46
+ )[0];
47
+ if (!first) return null;
48
+ const earlier = animations.filter((other) => {
49
+ const otherStart = knownStart(other);
50
+ return other !== animation && !other.global && other.targetSelector === animation.targetSelector && otherStart !== void 0 && otherStart < start - 1e-3;
51
+ });
52
+ const position = {};
53
+ for (const [property, value] of Object.entries(first.properties)) {
54
+ if (classifyPropertyGroup(property) !== "position" || typeof value !== "number") continue;
55
+ if (earlier.some((other) => writesProperty(other, property))) continue;
56
+ position[property] = value;
57
+ }
58
+ return Object.keys(position).length > 0 ? position : null;
59
+ }
34
60
 
35
61
  // src/gsapSerialize.ts
36
62
  function mergePercentageKeyframes(keyframes) {
@@ -2809,7 +2835,8 @@ function insertInheritedStateSetInScript(script, selector, position, properties)
2809
2835
  const tlDecl = findTimelineDeclarationStatement(parsed.ast, parsed.timelineVar);
2810
2836
  const firstLocated = parsed.located[0];
2811
2837
  if (tlDecl) {
2812
- ms.appendLeft(tlDecl.end, "\n" + code);
2838
+ const ownLineEnd = script[tlDecl.end] === "\n" ? "" : "\n";
2839
+ ms.appendLeft(tlDecl.end, "\n" + code + ownLineEnd);
2813
2840
  } else if (firstLocated) {
2814
2841
  const firstCall = firstLocated.call;
2815
2842
  const exprStmt = findEnclosingExpressionStatement(firstCall.ancestors);
@@ -2831,38 +2858,15 @@ function removeStudioHoldSets(script, parsed) {
2831
2858
  for (const hold of staleHolds) removeCallFromMagicString(ms, hold.call, script);
2832
2859
  return ms.toString();
2833
2860
  }
2834
- function animationStart(animation) {
2835
- if (animation.resolvedStart !== void 0) return animation.resolvedStart;
2836
- return typeof animation.position === "number" ? animation.position : 0;
2837
- }
2838
- function positionProperties(properties) {
2839
- const position = {};
2840
- for (const [property, value] of Object.entries(properties)) {
2841
- if (classifyPropertyGroup(property) === "position" && typeof value === "number") {
2842
- position[property] = value;
2843
- }
2844
- }
2845
- return position;
2846
- }
2847
- function positionHoldForAnimation(animation) {
2848
- if (!animation.keyframes) return null;
2849
- if (!(animationStart(animation) > 1e-3)) return null;
2850
- const first = [...animation.keyframes.keyframes].sort(
2851
- (left, right) => left.percentage - right.percentage
2852
- )[0];
2853
- if (!first) return null;
2854
- const position = positionProperties(first.properties);
2855
- return Object.keys(position).length > 0 ? position : null;
2856
- }
2857
2861
  function syncPositionHoldsBeforeKeyframes(script) {
2858
2862
  const parsed = parseGsapScriptAcornForWrite(script);
2859
2863
  if (!parsed) return script;
2860
2864
  let result = removeStudioHoldSets(script, parsed);
2861
2865
  const current = parseGsapScriptAcornForWrite(result);
2862
2866
  if (!current) return result;
2863
- for (const entry of current.located) {
2864
- const animation = entry.animation;
2865
- const position = positionHoldForAnimation(animation);
2867
+ const animations = current.located.map((entry) => entry.animation);
2868
+ for (const animation of animations) {
2869
+ const position = positionHoldForAnimation(animation, animations);
2866
2870
  if (!position) continue;
2867
2871
  result = insertInheritedStateSetInScript(result, animation.targetSelector, 0, {
2868
2872
  ...position,