coily 0.8.0 → 0.8.2

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.
package/dist/api.cjs CHANGED
@@ -181,7 +181,7 @@ var __privateMethod = (obj, member, method) => {
181
181
  __accessCheck$2(obj, member, "access private method");
182
182
  return method;
183
183
  };
184
- var _mass, _tension, _damping, _state, _underdampedSolver, _criticallyDampedSolver, _overdampedSolver, _currentSolver, _needsUpdate, _needsReset, _emitter, _updateSolver, updateSolver_fn, _solver$1, _state2, _dampedFrequency, _t, _c1, _c2, _solver2, _state3, _t2, _c12, _c22, _solver3, _state4, _dampedFrequency2, _t3, _c13, _c23;
184
+ var _mass, _tension, _damping, _state, _lazyPosition, _underdampedSolver, _criticallyDampedSolver, _overdampedSolver, _currentSolver, _needsUpdate, _needsReset, _emitter, _updateSolver, updateSolver_fn, _solver$1, _state2, _dampedFrequency, _t, _c1, _c2, _solver2, _state3, _t2, _c12, _c22, _solver3, _state4, _dampedFrequency2, _t3, _c13, _c23;
185
185
  class Solver {
186
186
  constructor(options) {
187
187
  __privateAdd$2(this, _updateSolver);
@@ -189,6 +189,7 @@ class Solver {
189
189
  __privateAdd$2(this, _tension, void 0);
190
190
  __privateAdd$2(this, _damping, void 0);
191
191
  __privateAdd$2(this, _state, void 0);
192
+ __privateAdd$2(this, _lazyPosition, void 0);
192
193
  __privateAdd$2(this, _underdampedSolver, null);
193
194
  __privateAdd$2(this, _criticallyDampedSolver, null);
194
195
  __privateAdd$2(this, _overdampedSolver, null);
@@ -204,6 +205,7 @@ class Solver {
204
205
  options.velocity,
205
206
  options.precision
206
207
  ));
208
+ __privateSet$2(this, _lazyPosition, options.position);
207
209
  __privateSet$2(this, _emitter, new Emitter());
208
210
  __privateMethod(this, _updateSolver, updateSolver_fn).call(this);
209
211
  }
@@ -238,6 +240,9 @@ class Solver {
238
240
  __privateGet$2(this, _emitter).emit("start");
239
241
  }
240
242
  }
243
+ get lazyPosition() {
244
+ return __privateGet$2(this, _lazyPosition);
245
+ }
241
246
  get velocity() {
242
247
  return __privateGet$2(this, _state).velocity;
243
248
  }
@@ -263,7 +268,7 @@ class Solver {
263
268
  get dampingRatio() {
264
269
  return __privateGet$2(this, _damping) / this.criticalDamping;
265
270
  }
266
- tick(dt) {
271
+ tick(dt, emit = true) {
267
272
  if (__privateGet$2(this, _needsUpdate)) {
268
273
  __privateMethod(this, _updateSolver, updateSolver_fn).call(this);
269
274
  __privateSet$2(this, _needsUpdate, false);
@@ -273,9 +278,12 @@ class Solver {
273
278
  __privateSet$2(this, _needsReset, false);
274
279
  }
275
280
  __privateGet$2(this, _currentSolver).tick(dt);
276
- __privateGet$2(this, _emitter).emit("update");
277
- if (__privateGet$2(this, _state).resting) {
278
- __privateGet$2(this, _emitter).emit("stop");
281
+ __privateSet$2(this, _lazyPosition, __privateGet$2(this, _state).position);
282
+ if (emit) {
283
+ __privateGet$2(this, _emitter).emit("update");
284
+ if (__privateGet$2(this, _state).resting) {
285
+ __privateGet$2(this, _emitter).emit("stop");
286
+ }
279
287
  }
280
288
  }
281
289
  onUpdate(callback) {
@@ -292,6 +300,7 @@ _mass = new WeakMap();
292
300
  _tension = new WeakMap();
293
301
  _damping = new WeakMap();
294
302
  _state = new WeakMap();
303
+ _lazyPosition = new WeakMap();
295
304
  _underdampedSolver = new WeakMap();
296
305
  _criticallyDampedSolver = new WeakMap();
297
306
  _overdampedSolver = new WeakMap();
@@ -480,6 +489,9 @@ class Spring {
480
489
  }
481
490
  set target(value) {
482
491
  if (value !== __privateGet$1(this, _target)) {
492
+ if (__privateGet$1(this, _solver).position !== __privateGet$1(this, _solver).lazyPosition) {
493
+ __privateGet$1(this, _solver).tick(0);
494
+ }
483
495
  if (!__privateGet$1(this, _scheduler$1).has(__privateGet$1(this, _solver))) {
484
496
  __privateGet$1(this, _scheduler$1).add(__privateGet$1(this, _solver));
485
497
  }
@@ -492,10 +504,16 @@ class Spring {
492
504
  return __privateGet$1(this, _target) + __privateGet$1(this, _solver).position;
493
505
  }
494
506
  set value(value) {
495
- if (!__privateGet$1(this, _scheduler$1).has(__privateGet$1(this, _solver))) {
496
- __privateGet$1(this, _scheduler$1).add(__privateGet$1(this, _solver));
507
+ const position = value - __privateGet$1(this, _target);
508
+ if (position !== __privateGet$1(this, _solver).position) {
509
+ if (__privateGet$1(this, _solver).position !== __privateGet$1(this, _solver).lazyPosition) {
510
+ __privateGet$1(this, _solver).tick(0);
511
+ }
512
+ if (!__privateGet$1(this, _scheduler$1).has(__privateGet$1(this, _solver))) {
513
+ __privateGet$1(this, _scheduler$1).add(__privateGet$1(this, _solver));
514
+ }
515
+ __privateGet$1(this, _solver).position = position;
497
516
  }
498
- __privateGet$1(this, _solver).position = __privateGet$1(this, _target) - value;
499
517
  }
500
518
  get velocity() {
501
519
  return __privateGet$1(this, _solver).velocity;
package/dist/api.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as SpringSystem } from './shared/coily.c7e32732.cjs';
2
- export { a as Spring } from './shared/coily.c7e32732.cjs';
1
+ import { S as SpringSystem } from './shared/coily.fc8a32a3.cjs';
2
+ export { a as Spring } from './shared/coily.fc8a32a3.cjs';
3
3
 
4
4
  declare function createSpringSystem(): SpringSystem;
5
5
 
package/dist/api.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as SpringSystem } from './shared/coily.c7e32732.mjs';
2
- export { a as Spring } from './shared/coily.c7e32732.mjs';
1
+ import { S as SpringSystem } from './shared/coily.fc8a32a3.mjs';
2
+ export { a as Spring } from './shared/coily.fc8a32a3.mjs';
3
3
 
4
4
  declare function createSpringSystem(): SpringSystem;
5
5
 
package/dist/api.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as SpringSystem } from './shared/coily.c7e32732.js';
2
- export { a as Spring } from './shared/coily.c7e32732.js';
1
+ import { S as SpringSystem } from './shared/coily.fc8a32a3.js';
2
+ export { a as Spring } from './shared/coily.fc8a32a3.js';
3
3
 
4
4
  declare function createSpringSystem(): SpringSystem;
5
5
 
package/dist/api.mjs CHANGED
@@ -179,7 +179,7 @@ var __privateMethod = (obj, member, method) => {
179
179
  __accessCheck$2(obj, member, "access private method");
180
180
  return method;
181
181
  };
182
- var _mass, _tension, _damping, _state, _underdampedSolver, _criticallyDampedSolver, _overdampedSolver, _currentSolver, _needsUpdate, _needsReset, _emitter, _updateSolver, updateSolver_fn, _solver$1, _state2, _dampedFrequency, _t, _c1, _c2, _solver2, _state3, _t2, _c12, _c22, _solver3, _state4, _dampedFrequency2, _t3, _c13, _c23;
182
+ var _mass, _tension, _damping, _state, _lazyPosition, _underdampedSolver, _criticallyDampedSolver, _overdampedSolver, _currentSolver, _needsUpdate, _needsReset, _emitter, _updateSolver, updateSolver_fn, _solver$1, _state2, _dampedFrequency, _t, _c1, _c2, _solver2, _state3, _t2, _c12, _c22, _solver3, _state4, _dampedFrequency2, _t3, _c13, _c23;
183
183
  class Solver {
184
184
  constructor(options) {
185
185
  __privateAdd$2(this, _updateSolver);
@@ -187,6 +187,7 @@ class Solver {
187
187
  __privateAdd$2(this, _tension, void 0);
188
188
  __privateAdd$2(this, _damping, void 0);
189
189
  __privateAdd$2(this, _state, void 0);
190
+ __privateAdd$2(this, _lazyPosition, void 0);
190
191
  __privateAdd$2(this, _underdampedSolver, null);
191
192
  __privateAdd$2(this, _criticallyDampedSolver, null);
192
193
  __privateAdd$2(this, _overdampedSolver, null);
@@ -202,6 +203,7 @@ class Solver {
202
203
  options.velocity,
203
204
  options.precision
204
205
  ));
206
+ __privateSet$2(this, _lazyPosition, options.position);
205
207
  __privateSet$2(this, _emitter, new Emitter());
206
208
  __privateMethod(this, _updateSolver, updateSolver_fn).call(this);
207
209
  }
@@ -236,6 +238,9 @@ class Solver {
236
238
  __privateGet$2(this, _emitter).emit("start");
237
239
  }
238
240
  }
241
+ get lazyPosition() {
242
+ return __privateGet$2(this, _lazyPosition);
243
+ }
239
244
  get velocity() {
240
245
  return __privateGet$2(this, _state).velocity;
241
246
  }
@@ -261,7 +266,7 @@ class Solver {
261
266
  get dampingRatio() {
262
267
  return __privateGet$2(this, _damping) / this.criticalDamping;
263
268
  }
264
- tick(dt) {
269
+ tick(dt, emit = true) {
265
270
  if (__privateGet$2(this, _needsUpdate)) {
266
271
  __privateMethod(this, _updateSolver, updateSolver_fn).call(this);
267
272
  __privateSet$2(this, _needsUpdate, false);
@@ -271,9 +276,12 @@ class Solver {
271
276
  __privateSet$2(this, _needsReset, false);
272
277
  }
273
278
  __privateGet$2(this, _currentSolver).tick(dt);
274
- __privateGet$2(this, _emitter).emit("update");
275
- if (__privateGet$2(this, _state).resting) {
276
- __privateGet$2(this, _emitter).emit("stop");
279
+ __privateSet$2(this, _lazyPosition, __privateGet$2(this, _state).position);
280
+ if (emit) {
281
+ __privateGet$2(this, _emitter).emit("update");
282
+ if (__privateGet$2(this, _state).resting) {
283
+ __privateGet$2(this, _emitter).emit("stop");
284
+ }
277
285
  }
278
286
  }
279
287
  onUpdate(callback) {
@@ -290,6 +298,7 @@ _mass = new WeakMap();
290
298
  _tension = new WeakMap();
291
299
  _damping = new WeakMap();
292
300
  _state = new WeakMap();
301
+ _lazyPosition = new WeakMap();
293
302
  _underdampedSolver = new WeakMap();
294
303
  _criticallyDampedSolver = new WeakMap();
295
304
  _overdampedSolver = new WeakMap();
@@ -478,6 +487,9 @@ class Spring {
478
487
  }
479
488
  set target(value) {
480
489
  if (value !== __privateGet$1(this, _target)) {
490
+ if (__privateGet$1(this, _solver).position !== __privateGet$1(this, _solver).lazyPosition) {
491
+ __privateGet$1(this, _solver).tick(0);
492
+ }
481
493
  if (!__privateGet$1(this, _scheduler$1).has(__privateGet$1(this, _solver))) {
482
494
  __privateGet$1(this, _scheduler$1).add(__privateGet$1(this, _solver));
483
495
  }
@@ -490,10 +502,16 @@ class Spring {
490
502
  return __privateGet$1(this, _target) + __privateGet$1(this, _solver).position;
491
503
  }
492
504
  set value(value) {
493
- if (!__privateGet$1(this, _scheduler$1).has(__privateGet$1(this, _solver))) {
494
- __privateGet$1(this, _scheduler$1).add(__privateGet$1(this, _solver));
505
+ const position = value - __privateGet$1(this, _target);
506
+ if (position !== __privateGet$1(this, _solver).position) {
507
+ if (__privateGet$1(this, _solver).position !== __privateGet$1(this, _solver).lazyPosition) {
508
+ __privateGet$1(this, _solver).tick(0);
509
+ }
510
+ if (!__privateGet$1(this, _scheduler$1).has(__privateGet$1(this, _solver))) {
511
+ __privateGet$1(this, _scheduler$1).add(__privateGet$1(this, _solver));
512
+ }
513
+ __privateGet$1(this, _solver).position = position;
495
514
  }
496
- __privateGet$1(this, _solver).position = __privateGet$1(this, _target) - value;
497
515
  }
498
516
  get velocity() {
499
517
  return __privateGet$1(this, _solver).velocity;
package/dist/loop.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as SpringSystem } from './shared/coily.c7e32732.cjs';
1
+ import { S as SpringSystem } from './shared/coily.fc8a32a3.cjs';
2
2
 
3
3
  declare function start(system: SpringSystem): () => void;
4
4
 
package/dist/loop.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as SpringSystem } from './shared/coily.c7e32732.mjs';
1
+ import { S as SpringSystem } from './shared/coily.fc8a32a3.mjs';
2
2
 
3
3
  declare function start(system: SpringSystem): () => void;
4
4
 
package/dist/loop.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as SpringSystem } from './shared/coily.c7e32732.js';
1
+ import { S as SpringSystem } from './shared/coily.fc8a32a3.js';
2
2
 
3
3
  declare function start(system: SpringSystem): () => void;
4
4
 
@@ -17,6 +17,7 @@ declare class Solver {
17
17
  set damping(value: number);
18
18
  get position(): number;
19
19
  set position(value: number);
20
+ get lazyPosition(): number;
20
21
  get velocity(): number;
21
22
  set velocity(value: number);
22
23
  get precision(): number;
@@ -25,7 +26,7 @@ declare class Solver {
25
26
  get naturalFrequency(): number;
26
27
  get criticalDamping(): number;
27
28
  get dampingRatio(): number;
28
- tick(dt: number): void;
29
+ tick(dt: number, emit?: boolean): void;
29
30
  onUpdate(callback: () => void): () => void;
30
31
  onStart(callback: () => void): () => void;
31
32
  onStop(callback: () => void): () => void;
@@ -17,6 +17,7 @@ declare class Solver {
17
17
  set damping(value: number);
18
18
  get position(): number;
19
19
  set position(value: number);
20
+ get lazyPosition(): number;
20
21
  get velocity(): number;
21
22
  set velocity(value: number);
22
23
  get precision(): number;
@@ -25,7 +26,7 @@ declare class Solver {
25
26
  get naturalFrequency(): number;
26
27
  get criticalDamping(): number;
27
28
  get dampingRatio(): number;
28
- tick(dt: number): void;
29
+ tick(dt: number, emit?: boolean): void;
29
30
  onUpdate(callback: () => void): () => void;
30
31
  onStart(callback: () => void): () => void;
31
32
  onStop(callback: () => void): () => void;
@@ -17,6 +17,7 @@ declare class Solver {
17
17
  set damping(value: number);
18
18
  get position(): number;
19
19
  set position(value: number);
20
+ get lazyPosition(): number;
20
21
  get velocity(): number;
21
22
  set velocity(value: number);
22
23
  get precision(): number;
@@ -25,7 +26,7 @@ declare class Solver {
25
26
  get naturalFrequency(): number;
26
27
  get criticalDamping(): number;
27
28
  get dampingRatio(): number;
28
- tick(dt: number): void;
29
+ tick(dt: number, emit?: boolean): void;
29
30
  onUpdate(callback: () => void): () => void;
30
31
  onStart(callback: () => void): () => void;
31
32
  onStop(callback: () => void): () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coily",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "Simulate values using spring physics",
5
5
  "author": "Tim Morris <timthewebguy@gmail.com>",
6
6
  "homepage": "https://github.com/tkofh/coily#readme",