@wandelbots/wandelbots-js-react-components 2.26.0-pr.feature-update-to-react-19.361.23b1e20 → 2.26.0-pr.feature-update-to-react-19.361.fbd0985

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,48 +1,34 @@
1
1
  /**
2
- * Smooth value interpolation utility for animating between values
3
- * even with rapid updates. Uses THREE.MathUtils.lerp for optimized interpolation.
2
+ * Smooth value interpolation utility using spring physics with tension and friction.
3
+ * Designed for React Three Fiber applications with smooth, natural animations.
4
4
  *
5
- * Follows React Three Fiber best practices:
6
- * - Uses frame deltas for refresh-rate independence
7
- * - Avoids object creation in animation loops
8
- * - Direct mutation for performance
5
+ * Features:
6
+ * - Spring physics with configurable tension and friction
7
+ * - Frame-rate independent using delta timing
8
+ * - Handles irregular frame timing and rapid target updates
9
9
  * - Manual update() calls for useFrame integration (no automatic RAF loop)
10
- *
11
- * Note: When using with useFrame(), call update(delta) manually.
12
- * For standalone usage, call startAutoInterpolation() to begin automatic updates.
10
+ * - Direct mutation for performance
13
11
  *
14
12
  * @example
15
13
  * ```tsx
16
- * // Basic usage with spring-like animation (similar to react-spring)
14
+ * // Basic spring animation
17
15
  * const interpolator = new ValueInterpolator([0, 0, 0], {
18
- * alpha: 0.1, // Interpolation alpha (0-1, frame-rate independent)
19
- * easing: 'spring', // Spring-like animation with slight overshoot
16
+ * tension: 120, // Higher = faster, stiffer spring (default: 120)
17
+ * friction: 20, // Higher = more damping, less oscillation (default: 20)
20
18
  * onChange: (values) => {
21
- * // Update your objects with interpolated values
22
19
  * robot.joints.forEach((joint, i) => {
23
20
  * joint.rotation.y = values[i]
24
21
  * })
25
22
  * }
26
23
  * })
27
24
  *
28
- * // Different easing options:
29
- * // 'linear' - smooth linear interpolation
30
- * // 'spring' - spring-like with overshoot (similar to react-spring)
31
- * // 'easeOut' - smooth deceleration
32
- * // 'easeInOut' - smooth acceleration and deceleration
33
- *
34
- * // Set new target values
35
25
  * interpolator.setTarget([1.5, -0.8, 2.1])
36
26
  *
37
- * // React hook usage with useFrame
27
+ * // React Three Fiber usage
38
28
  * function MyComponent() {
39
- * const [interpolator] = useInterpolation([0, 0, 0], {
40
- * alpha: 0.1,
41
- * easing: 'spring'
42
- * })
29
+ * const [interpolator] = useInterpolation([0, 0, 0])
43
30
  *
44
31
  * useFrame((state, delta) => {
45
- * // Frame-rate independent updates
46
32
  * interpolator.update(delta)
47
33
  * })
48
34
  *
@@ -54,14 +40,13 @@
54
40
  * }
55
41
  * ```
56
42
  */
57
- export type EasingFunction = "linear" | "spring" | "easeOut" | "easeInOut";
58
43
  export interface InterpolationOptions {
59
- /** Interpolation alpha factor (0-1, frame-rate independent) */
60
- alpha?: number;
61
- /** Minimum threshold to consider interpolation complete */
44
+ /** Spring tension (higher = faster, stiffer spring) - default: 120 */
45
+ tension?: number;
46
+ /** Spring friction (higher = more damping, less oscillation) - default: 20 */
47
+ friction?: number;
48
+ /** Minimum threshold to consider interpolation complete - default: 0.001 */
62
49
  threshold?: number;
63
- /** Easing function to use for interpolation */
64
- easing?: EasingFunction;
65
50
  /** Callback when values change during interpolation */
66
51
  onChange?: (values: number[]) => void;
67
52
  /** Callback when interpolation reaches target values */
@@ -70,32 +55,49 @@ export interface InterpolationOptions {
70
55
  export declare class ValueInterpolator {
71
56
  private currentValues;
72
57
  private targetValues;
58
+ private previousTargetValues;
59
+ private targetUpdateTime;
73
60
  private animationId;
74
61
  private options;
62
+ private velocities;
75
63
  constructor(initialValues?: number[], options?: InterpolationOptions);
76
64
  /**
77
- * Update interpolation (call this in useFrame for frame-rate independence)
78
- * @param delta - Frame delta time for smooth animation
65
+ * Update interpolation using spring physics
66
+ *
67
+ * Call this method every frame for smooth animation. In React Three Fiber,
68
+ * call from within useFrame callback with the provided delta time.
69
+ *
70
+ * @param delta - Time elapsed since last update in seconds (e.g., 1/60 ≈ 0.0167 for 60fps)
71
+ * @returns true when interpolation is complete (all values reached their targets)
79
72
  */
80
73
  update(delta?: number): boolean;
81
74
  /**
82
- * Set new target values to interpolate towards
75
+ * Set new target values for the interpolation to move towards
76
+ *
77
+ * Includes smart blending for very rapid target updates (faster than 120fps)
78
+ * to prevent jarring movements when targets change frequently.
83
79
  */
84
80
  setTarget(newValues: number[]): void;
85
81
  /**
86
- * Get the current interpolated values
82
+ * Get a copy of all current interpolated values
87
83
  */
88
84
  getCurrentValues(): number[];
89
85
  /**
90
- * Get a specific interpolated value by index
86
+ * Get a single interpolated value by its array index
91
87
  */
92
88
  getValue(index: number): number;
93
89
  /**
94
- * Check if interpolation is currently active
90
+ * Check if automatic interpolation is currently running
91
+ *
92
+ * This only tracks auto-interpolation started with startAutoInterpolation().
93
+ * Manual update() calls are not tracked by this method.
95
94
  */
96
95
  isInterpolating(): boolean;
97
96
  /**
98
- * Stop the current interpolation
97
+ * Stop automatic interpolation if it's running
98
+ *
99
+ * This cancels the internal animation frame loop but does not affect
100
+ * manual update() calls.
99
101
  */
100
102
  stop(): void;
101
103
  /**
@@ -107,31 +109,36 @@ export declare class ValueInterpolator {
107
109
  */
108
110
  updateOptions(newOptions: Partial<InterpolationOptions>): void;
109
111
  /**
110
- * Start automatic interpolation (use when not calling update() manually)
112
+ * Start automatic interpolation with an animation loop
113
+ *
114
+ * This begins a requestAnimationFrame loop that calls update() automatically.
115
+ * For React Three Fiber components, prefer using manual update() calls
116
+ * within useFrame hooks instead.
111
117
  */
112
118
  startAutoInterpolation(): void;
113
119
  /**
114
- * Destroy the interpolator and clean up resources
120
+ * Clean up all resources and stop any running animations
121
+ *
122
+ * This cancels any active animation frames and resets internal state.
123
+ * Call this when the component unmounts or is no longer needed.
115
124
  */
116
125
  destroy(): void;
117
- /**
118
- * Apply easing function to the interpolation with frame-rate independence
119
- */
120
- private applyEasing;
121
126
  private startInterpolation;
122
127
  private animate;
123
128
  }
124
129
  /**
125
130
  * React hook for using the ValueInterpolator with useFrame
126
131
  *
127
- * This hook creates a ValueInterpolator that's designed for manual updates
128
- * via useFrame(). It will not start automatic interpolation - you must
129
- * call interpolator.update(delta) in your useFrame callback.
132
+ * This hook creates a ValueInterpolator that uses spring physics for smooth,
133
+ * natural animations. Call interpolator.update(delta) in your useFrame callback.
130
134
  *
131
135
  * @example
132
136
  * ```tsx
133
137
  * function AnimatedMesh() {
134
- * const [interpolator] = useInterpolation([0, 0, 0], { alpha: 0.1 })
138
+ * const [interpolator] = useInterpolation([0, 0, 0], {
139
+ * tension: 120, // Higher = faster spring
140
+ * friction: 20 // Higher = more damping
141
+ * })
135
142
  * const meshRef = useRef()
136
143
  *
137
144
  * useFrame((state, delta) => {
@@ -1 +1 @@
1
- {"version":3,"file":"interpolation.d.ts","sourceRoot":"","sources":["../../../src/components/utils/interpolation.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAEH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAA;AAE1E,MAAM,WAAW,oBAAoB;IACnC,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;IACrC,wDAAwD;IACxD,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;CACxC;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,OAAO,CAAgC;gBAG7C,aAAa,GAAE,MAAM,EAAO,EAC5B,OAAO,GAAE,oBAAyB;IAepC;;;OAGG;IACH,MAAM,CAAC,KAAK,G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