@mkbabb/keyframes.js 1.0.0 → 1.1.0

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.
@@ -1,3 +1,4 @@
1
+ import { HueInterpolationMethod } from '@mkbabb/value.js';
1
2
  import { InterpolatedVar } from '@mkbabb/value.js';
2
3
  import { timingFunctions } from '@mkbabb/value.js';
3
4
  import { ValueArray } from '@mkbabb/value.js';
@@ -23,8 +24,11 @@ declare class Animation_2<V extends Vars = any> {
23
24
  done: boolean;
24
25
  reversed: boolean;
25
26
  paused: boolean;
27
+ /** When true, this animation is managed by an AnimationGroup and should not run its own rAF loop. */
28
+ managed: boolean;
26
29
  unflatten: boolean;
27
30
  private resolvePromise;
31
+ private dispatchAnimationEvent;
28
32
  constructor(options?: Partial<InputAnimationOptions>, targets?: HTMLElement[] | HTMLElement | undefined, name?: string | undefined, superKey?: string | undefined);
29
33
  convertFrameStart(frame: TemplateAnimationFrame<V>): TemplateAnimationFrame<V>;
30
34
  addFrame<K extends V>(start: number | string | ValueUnit<number>, vars: Partial<K>, transform?: TransformFunction<K>, timingFunction?: TimingFunction | TimingFunctionNames): Animation_2<K>;
@@ -37,19 +41,28 @@ declare class Animation_2<V extends Vars = any> {
37
41
  setDelay(delay: InputAnimationOptions["delay"]): this;
38
42
  setDirection(direction: InputAnimationOptions["direction"]): this;
39
43
  setFillMode(fillMode: InputAnimationOptions["fillMode"]): this;
44
+ setUseWAAPI(useWAAPI: InputAnimationOptions["useWAAPI"]): this;
45
+ setColorSpace(colorSpace: InputAnimationOptions["colorSpace"]): this;
46
+ setHueMethod(hueMethod: InputAnimationOptions["hueMethod"]): this;
40
47
  setOptions(options: Partial<InputAnimationOptions>): this;
41
48
  reverse(): this;
42
49
  fillForwards(): void;
43
50
  fillBackwards(): void;
44
- interpFrames(t: number, transformFrames?: boolean): {};
51
+ interpFrames(t: number, transformFrames?: boolean): Record<string, any>;
45
52
  onStart(): Promise<void>;
46
53
  onEnd(): Promise<void>;
47
54
  tick(t: number): Promise<number>;
48
55
  draw(t: number): Promise<void>;
56
+ /** Internal rAF-based play loop. */
57
+ private _playRAF;
58
+ /** Play via the Web Animations API for compositor-thread execution. */
59
+ private _playWAAPI;
49
60
  play(): Promise<void>;
50
61
  pause(draw?: boolean): this;
51
62
  stop(): void;
52
63
  playing(): boolean;
64
+ /** Returns the effective time accounting for direction reversal. */
65
+ get effectiveT(): number;
53
66
  reset(): this;
54
67
  setTargets(...targets: HTMLElement[]): this;
55
68
  group(...animations: Animation_2<V>[]): AnimationGroup<V>;
@@ -86,7 +99,7 @@ declare class AnimationGroup<V extends Vars> {
86
99
  singleTarget: boolean;
87
100
  handleId: number | any;
88
101
  resolvePromise: ((value: void | PromiseLike<void>) => void) | null;
89
- constructor(...animations: Animation_2<V>[]);
102
+ constructor(...inputs: (Animation_2<V> | AnimationGroupInput<V>)[]);
90
103
  setSuperKey(superKey: string): this;
91
104
  setTargets(...targets: HTMLElement[]): this;
92
105
  onStart(): this;
@@ -101,13 +114,41 @@ declare class AnimationGroup<V extends Vars> {
101
114
  playing(): boolean;
102
115
  forcePause(): void;
103
116
  forcePlay(): void;
117
+ /** Set layer config for an animation by name or reference. Chainable. */
118
+ setLayerConfig(nameOrAnim: string | Animation_2<V>, config: Partial<AnimationLayerConfig>): this;
119
+ /** Convenience toggle for enabling/disabling a layer. Chainable. */
120
+ setLayerEnabled(nameOrAnim: string | Animation_2<V>, enabled: boolean): this;
121
+ /** Read the layer config for an animation. */
122
+ getLayerConfig(nameOrAnim: string | Animation_2<V>): AnimationLayerConfig | undefined;
104
123
  }
105
124
 
125
+ declare interface AnimationGroupEntry<V extends Vars> {
126
+ animation: Animation_2<V>;
127
+ values: Vars<ValueArray>;
128
+ layer: AnimationLayerConfig;
129
+ }
130
+
131
+ /** Input type for AnimationGroup constructor — bare Animation or Animation with layer config. */
132
+ declare type AnimationGroupInput<V extends Vars> = Animation_2<V> | {
133
+ animation: Animation_2<V>;
134
+ layer?: Partial<AnimationLayerConfig>;
135
+ };
136
+
106
137
  declare interface AnimationGroupObject<V extends Vars> {
107
- [key: string]: {
108
- animation: Animation_2<V>;
109
- values: Vars<ValueArray>;
110
- };
138
+ [key: string]: AnimationGroupEntry<V>;
139
+ }
140
+
141
+ declare interface AnimationLayerConfig {
142
+ /** Higher wins. Default: 0 */
143
+ zIndex: number;
144
+ /** 0–1 for 'weighted' blend mode. Default: 1 */
145
+ weight: number;
146
+ /** Default: 'replace' (backward compat) */
147
+ blendMode: BlendMode;
148
+ /** Layer toggle. Default: true */
149
+ enabled: boolean;
150
+ /** Optional property whitelist — only these properties will be output from this layer */
151
+ properties?: Set<string>;
111
152
  }
112
153
 
113
154
  declare type AnimationOptions = {
@@ -117,8 +158,13 @@ declare type AnimationOptions = {
117
158
  direction: (typeof DIRECTIONS)[number];
118
159
  fillMode: (typeof FILL_MODES)[number];
119
160
  timingFunction: TimingFunction;
161
+ useWAAPI: boolean;
162
+ colorSpace: string;
163
+ hueMethod?: HueInterpolationMethod;
120
164
  };
121
165
 
166
+ declare type BlendMode = "replace" | "add" | "weighted";
167
+
122
168
  export declare class CSSKeyframesAnimation<V extends Vars> extends Animation_2<V> {
123
169
  constructor(options?: Partial<InputAnimationOptions>, ...targets: HTMLElement[]);
124
170
  fromVars(vars: V[], transform?: TransformFunction<V>): this;
@@ -140,6 +186,10 @@ declare type InputAnimationOptions = Partial<{
140
186
  direction: (typeof DIRECTIONS)[number];
141
187
  fillMode: (typeof FILL_MODES)[number];
142
188
  timingFunction: TimingFunction | TimingFunctionNames | undefined;
189
+ /** When true (default), eligible animations may use the Web Animations API for compositor-thread execution. Set to false to force rAF. */
190
+ useWAAPI: boolean;
191
+ colorSpace?: string;
192
+ hueMethod?: HueInterpolationMethod;
143
193
  }>;
144
194
 
145
195
  declare interface TemplateAnimationFrame<V extends Vars> {