physics-animator 0.10.0 → 0.12.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,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Animator = void 0;
3
+ exports.StepResult = exports.Animator = void 0;
4
4
  const event_signal_1 = require("@haxiomic/event-signal");
5
- const IFieldAnimator_js_1 = require("./IFieldAnimator.js");
6
5
  const SpringAnimator_js_1 = require("./animators/SpringAnimator.js");
7
6
  const TweenAnimator_js_1 = require("./animators/TweenAnimator.js");
8
7
  /**
@@ -155,7 +154,7 @@ class Animator {
155
154
  this.dispatchChangeFieldEvent(object, field);
156
155
  // handle animation completion
157
156
  switch (result) {
158
- case IFieldAnimator_js_1.StepResult.Complete:
157
+ case StepResult.Complete:
159
158
  {
160
159
  objectAnims.delete(field);
161
160
  this.events.completeField.dispatch({ object, field });
@@ -374,6 +373,11 @@ class Animator {
374
373
  }
375
374
  }
376
375
  exports.Animator = Animator;
376
+ var StepResult;
377
+ (function (StepResult) {
378
+ StepResult[StepResult["Continue"] = 0] = "Continue";
379
+ StepResult[StepResult["Complete"] = 1] = "Complete";
380
+ })(StepResult || (exports.StepResult = StepResult = {}));
377
381
  function forObjectFieldsRecursive(sourceObj, targetObj, callback) {
378
382
  for (let field in targetObj) {
379
383
  if (Object.prototype.hasOwnProperty.call(targetObj, field)) {
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Spring = exports.SpringAnimator = void 0;
4
- const IFieldAnimator_js_1 = require("../IFieldAnimator.js");
4
+ const Animator_js_1 = require("../Animator.js");
5
5
  const defaultSpringParameters = {
6
6
  duration_s: 0.5,
7
7
  };
@@ -35,27 +35,27 @@ exports.SpringAnimator = {
35
35
  // complete the animation if it's close enough to the target and velocity is close to 0
36
36
  if (Math.abs(state.x - state.targetX) < 0.0001 && Math.abs(state.v) < 0.0001) {
37
37
  object[field] = state.targetX;
38
- return IFieldAnimator_js_1.StepResult.Complete;
38
+ return Animator_js_1.StepResult.Complete;
39
39
  }
40
40
  else {
41
- return IFieldAnimator_js_1.StepResult.Continue;
41
+ return Animator_js_1.StepResult.Continue;
42
42
  }
43
43
  }
44
44
  };
45
45
  var Spring;
46
46
  (function (Spring) {
47
47
  /**
48
- * Starting with 0 velocity, this parameter describes how long it would take to reach half-way to the target
48
+ * Exponential decay without any bounce
49
49
  *
50
- * `damping = 3.356694 / approxHalfLife_s`
51
- *
52
- * `strength = damping * damping / 4`
50
+ * Control with either duration_s or halfLife_s
53
51
  */
54
52
  function Exponential(options) {
55
53
  // found numerically
56
54
  const halfLifeConstant = 3.356694; // from solve (1+u)*exp(-u)=0.5 for u, and constant = 2u
57
55
  const pointOnePercentConstant = 18.46682; // from solve (1+u)*exp(-u)=0.001 for u, and constant = 2u
58
- const damping = pointOnePercentConstant / options.duration_s;
56
+ const damping = ('halfLife_s' in options)
57
+ ? halfLifeConstant / options.halfLife_s
58
+ : pointOnePercentConstant / options.duration_s;
59
59
  let strength = damping * damping / 4;
60
60
  return { damping, strength };
61
61
  }
@@ -5,7 +5,7 @@ exports.linearStep = linearStep;
5
5
  exports.easeInOutStep = easeInOutStep;
6
6
  exports.easeInStep = easeInStep;
7
7
  exports.easeOutStep = easeOutStep;
8
- const IFieldAnimator_js_1 = require("../IFieldAnimator.js");
8
+ const Animator_js_1 = require("../Animator.js");
9
9
  const defaultParams = {
10
10
  duration_s: 0.5, // default duration of the tween in seconds
11
11
  easingFn: linearStep, // default easing function is linear
@@ -37,10 +37,10 @@ exports.TweenAnimator = {
37
37
  let deltaTime_s = (performance.now() - state.t0_ms) / 1000;
38
38
  if (deltaTime_s >= state.duration_s) {
39
39
  object[field] = state.target;
40
- return IFieldAnimator_js_1.StepResult.Complete;
40
+ return Animator_js_1.StepResult.Complete;
41
41
  }
42
42
  else {
43
- return IFieldAnimator_js_1.StepResult.Continue;
43
+ return Animator_js_1.StepResult.Continue;
44
44
  }
45
45
  }
46
46
  };
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./SpringAnimator.js"), exports);
18
18
  __exportStar(require("./TweenAnimator.js"), exports);
19
+ __exportStar(require("./IFieldAnimator.js"), exports);
package/dist/cjs/index.js CHANGED
@@ -14,8 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./AnimationSequencer.js"), exports);
18
17
  __exportStar(require("./Animator.js"), exports);
19
- __exportStar(require("./IFieldAnimator.js"), exports);
20
- __exportStar(require("./animators/index.js"), exports);
21
- __exportStar(require("./react/index.js"), exports);
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./AnimationSequencer.js"), exports);
@@ -1,5 +1,4 @@
1
1
  import { EventSignal } from "@haxiomic/event-signal";
2
- import { StepResult } from "./IFieldAnimator.js";
3
2
  import { SpringAnimator } from "./animators/SpringAnimator.js";
4
3
  import { easeInOutStep, easeInStep, easeOutStep, linearStep, TweenAnimator } from "./animators/TweenAnimator.js";
5
4
  /**
@@ -370,6 +369,11 @@ export class Animator {
370
369
  return animation;
371
370
  }
372
371
  }
372
+ export var StepResult;
373
+ (function (StepResult) {
374
+ StepResult[StepResult["Continue"] = 0] = "Continue";
375
+ StepResult[StepResult["Complete"] = 1] = "Complete";
376
+ })(StepResult || (StepResult = {}));
373
377
  function forObjectFieldsRecursive(sourceObj, targetObj, callback) {
374
378
  for (let field in targetObj) {
375
379
  if (Object.prototype.hasOwnProperty.call(targetObj, field)) {
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { StepResult } from "../IFieldAnimator.js";
1
+ import { StepResult } from "../Animator.js";
2
2
  const defaultSpringParameters = {
3
3
  duration_s: 0.5,
4
4
  };
@@ -42,17 +42,17 @@ export const SpringAnimator = {
42
42
  export var Spring;
43
43
  (function (Spring) {
44
44
  /**
45
- * Starting with 0 velocity, this parameter describes how long it would take to reach half-way to the target
45
+ * Exponential decay without any bounce
46
46
  *
47
- * `damping = 3.356694 / approxHalfLife_s`
48
- *
49
- * `strength = damping * damping / 4`
47
+ * Control with either duration_s or halfLife_s
50
48
  */
51
49
  function Exponential(options) {
52
50
  // found numerically
53
51
  const halfLifeConstant = 3.356694; // from solve (1+u)*exp(-u)=0.5 for u, and constant = 2u
54
52
  const pointOnePercentConstant = 18.46682; // from solve (1+u)*exp(-u)=0.001 for u, and constant = 2u
55
- const damping = pointOnePercentConstant / options.duration_s;
53
+ const damping = ('halfLife_s' in options)
54
+ ? halfLifeConstant / options.halfLife_s
55
+ : pointOnePercentConstant / options.duration_s;
56
56
  let strength = damping * damping / 4;
57
57
  return { damping, strength };
58
58
  }
@@ -1,4 +1,4 @@
1
- import { StepResult } from "../IFieldAnimator.js";
1
+ import { StepResult } from "../Animator.js";
2
2
  const defaultParams = {
3
3
  duration_s: 0.5, // default duration of the tween in seconds
4
4
  easingFn: linearStep, // default easing function is linear
@@ -1,2 +1,3 @@
1
1
  export * from './SpringAnimator.js';
2
2
  export * from './TweenAnimator.js';
3
+ export * from './IFieldAnimator.js';
package/dist/esm/index.js CHANGED
@@ -1,5 +1 @@
1
- export * from './AnimationSequencer.js';
2
1
  export * from './Animator.js';
3
- export * from './IFieldAnimator.js';
4
- export * from './animators/index.js';
5
- export * from './react/index.js';
@@ -0,0 +1 @@
1
+ export * from './AnimationSequencer.js';
@@ -1,5 +1,5 @@
1
1
  import { EventSignal } from "@haxiomic/event-signal";
2
- import { IFieldAnimator } from "./IFieldAnimator.js";
2
+ import { IFieldAnimator } from "./animators/IFieldAnimator.js";
3
3
  import { SpringParameters } from "./animators/SpringAnimator.js";
4
4
  import { EasingStepFn } from "./animators/TweenAnimator.js";
5
5
  /**
@@ -141,6 +141,10 @@ export declare class Animator {
141
141
  */
142
142
  private syncAnimation;
143
143
  }
144
+ export declare enum StepResult {
145
+ Continue = 0,// continue stepping
146
+ Complete = 1
147
+ }
144
148
  type FieldAnimation<Params, State> = {
145
149
  animator: IFieldAnimator<Params, State, any>;
146
150
  state: State;
@@ -1,7 +1,4 @@
1
- export declare enum StepResult {
2
- Continue = 0,// continue stepping
3
- Complete = 1
4
- }
1
+ import { StepResult } from "../Animator.js";
5
2
  export interface IFieldAnimator<Params, State, FieldType> {
6
3
  createState<Name extends keyof Obj, Obj extends Record<Name, FieldType>>(object: Obj, field: Name, target: Obj[Name], params: Params | null): State;
7
4
  updateState<Name extends keyof Obj, Obj extends Record<Name, FieldType>>(state: State, object: Obj, field: Name, target: Obj[Name], params: Params | null): void;
@@ -1,4 +1,4 @@
1
- import { IFieldAnimator } from "../IFieldAnimator.js";
1
+ import { IFieldAnimator } from "./IFieldAnimator.js";
2
2
  export declare const SpringAnimator: IFieldAnimator<SpringParameters, SpringState, number>;
3
3
  /**
4
4
  * Spring
@@ -8,6 +8,8 @@ export declare const SpringAnimator: IFieldAnimator<SpringParameters, SpringStat
8
8
  type ExponentialParameters = {
9
9
  /** Defined as the point in time we'll reach within 0.01% of target from 0 velocity start */
10
10
  duration_s: number;
11
+ } | {
12
+ halfLife_s: number;
11
13
  };
12
14
  type UnderdampedParameters = {
13
15
  /** Defined as the point in time we'll reach within 0.01% of target from 0 velocity start */
@@ -31,11 +33,9 @@ export declare namespace Spring {
31
33
  damping: number;
32
34
  };
33
35
  /**
34
- * Starting with 0 velocity, this parameter describes how long it would take to reach half-way to the target
36
+ * Exponential decay without any bounce
35
37
  *
36
- * `damping = 3.356694 / approxHalfLife_s`
37
- *
38
- * `strength = damping * damping / 4`
38
+ * Control with either duration_s or halfLife_s
39
39
  */
40
40
  function Exponential(options: ExponentialParameters): PhysicsParameters;
41
41
  function Underdamped(options: UnderdampedParameters): PhysicsParameters;
@@ -1,4 +1,4 @@
1
- import { IFieldAnimator } from "../IFieldAnimator.js";
1
+ import { IFieldAnimator } from "./IFieldAnimator.js";
2
2
  export type TweenParameters = {
3
3
  duration_s: number;
4
4
  easingFn: EasingStepFn;
@@ -1,2 +1,3 @@
1
1
  export * from './SpringAnimator.js';
2
2
  export * from './TweenAnimator.js';
3
+ export * from './IFieldAnimator.js';
@@ -1,5 +1 @@
1
- export * from './AnimationSequencer.js';
2
1
  export * from './Animator.js';
3
- export * from './IFieldAnimator.js';
4
- export * from './animators/index.js';
5
- export * from './react/index.js';
@@ -1,5 +1,5 @@
1
1
  import { Animator } from "../Animator.js";
2
- import { SpringParameters } from "src/animators/SpringAnimator.js";
2
+ import { SpringParameters } from "../animators/SpringAnimator.js";
3
3
  /**
4
4
  * A value that animates to a target value using a spring animation.
5
5
  * This **will** cause a re-render when the value changes.
@@ -1,5 +1,5 @@
1
1
  import { Animator } from "../Animator.js";
2
- import { SpringParameters } from "src/animators/SpringAnimator.js";
2
+ import { SpringParameters } from "../animators/SpringAnimator.js";
3
3
  /**
4
4
  * A value that animates to a target value using a spring animation.
5
5
  * This will **not** cause a re-render when the value changes.
@@ -0,0 +1 @@
1
+ export * from './AnimationSequencer.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "physics-animator",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "author": "haxiomic (George Corney)",
5
5
  "license": "MIT",
6
6
  "description": "A TypeScript animation system grounded in physics with three.js and react support.",
@@ -17,9 +17,7 @@
17
17
  "main": "dist/cjs/index.js",
18
18
  "module": "dist/esm/index.js",
19
19
  "types": "dist/types/index.d.ts",
20
- "files": [
21
- "dist"
22
- ],
20
+ "files": ["dist"],
23
21
  "exports": {
24
22
  ".": {
25
23
  "types": "./dist/types/index.d.ts",
@@ -32,6 +30,15 @@
32
30
  "require": "./dist/cjs/*/index.js"
33
31
  }
34
32
  },
33
+ "scripts": {
34
+ "typecheck": "tsc --noEmit",
35
+ "prepack": "npm run clean && npm run build",
36
+ "build": "npm run clean && npm run build-esm && npm run build-cjs",
37
+ "build-esm": "tsc --project tsconfig.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",
38
+ "build-cjs": "tsc --project tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
39
+ "clean": "rm -rf dist",
40
+ "dev": "tsc --watch"
41
+ },
35
42
  "devDependencies": {
36
43
  "@types/react": "^19.0.12",
37
44
  "typescript": "^5.0.0"
@@ -47,13 +54,5 @@
47
54
  "react": {
48
55
  "optional": true
49
56
  }
50
- },
51
- "scripts": {
52
- "typecheck": "tsc --noEmit",
53
- "build": "npm run clean && npm run build-esm && npm run build-cjs",
54
- "build-esm": "tsc --project tsconfig.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",
55
- "build-cjs": "tsc --project tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
56
- "clean": "rm -rf dist",
57
- "dev": "tsc --watch"
58
57
  }
59
- }
58
+ }
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StepResult = void 0;
4
- var StepResult;
5
- (function (StepResult) {
6
- StepResult[StepResult["Continue"] = 0] = "Continue";
7
- StepResult[StepResult["Complete"] = 1] = "Complete";
8
- })(StepResult || (exports.StepResult = StepResult = {}));
@@ -1,5 +0,0 @@
1
- export var StepResult;
2
- (function (StepResult) {
3
- StepResult[StepResult["Continue"] = 0] = "Continue";
4
- StepResult[StepResult["Complete"] = 1] = "Complete";
5
- })(StepResult || (StepResult = {}));