@oscarpalmer/timer 0.29.0 → 0.31.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.
@@ -2,6 +2,23 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
+ function stepper(now) {
6
+ if (values.length === 7) {
7
+ exports.milliseconds = Math.floor(
8
+ values.slice(2).reduce((first, second) => first + second) / 5 * 2
9
+ ) / 2;
10
+ last = void 0;
11
+ values.length = 0;
12
+ } else {
13
+ last ??= now;
14
+ const difference = now - last;
15
+ if (difference > 0) {
16
+ values.push(difference);
17
+ }
18
+ last = now;
19
+ requestAnimationFrame(stepper);
20
+ }
21
+ }
5
22
  const activeTimers = /* @__PURE__ */ new Set();
6
23
  const beginTypes = /* @__PURE__ */ new Set(["continue", "start"]);
7
24
  const destroyedMessage = "Timer has already been destroyed";
@@ -16,25 +33,8 @@ const pauseTypes = /* @__PURE__ */ new Set(["continue", "pause"]);
16
33
  const startedMessage = "Timer has already been started";
17
34
  const values = [];
18
35
  let last;
19
- exports.milliseconds = void 0;
20
- function step(now) {
21
- if (values.length === 10) {
22
- exports.milliseconds = Math.floor(
23
- values.slice(2, -2).reduce((first, second) => first + second) / 6
24
- );
25
- last = void 0;
26
- values.length = 0;
27
- } else {
28
- last ??= now;
29
- const difference = now - last;
30
- if (difference > 0) {
31
- values.push(difference);
32
- }
33
- last = now;
34
- requestAnimationFrame(step);
35
- }
36
- }
37
- requestAnimationFrame(step);
36
+ exports.milliseconds = Math.floor(1e3 / 60 * 2) / 2;
37
+ requestAnimationFrame(stepper);
38
38
 
39
39
  exports.activeTimers = activeTimers;
40
40
  exports.beginTypes = beginTypes;
package/dist/constants.js CHANGED
@@ -1,3 +1,20 @@
1
+ function stepper(now) {
2
+ if (values.length === 7) {
3
+ milliseconds = Math.floor(
4
+ values.slice(2).reduce((first, second) => first + second) / 5 * 2
5
+ ) / 2;
6
+ last = void 0;
7
+ values.length = 0;
8
+ } else {
9
+ last ??= now;
10
+ const difference = now - last;
11
+ if (difference > 0) {
12
+ values.push(difference);
13
+ }
14
+ last = now;
15
+ requestAnimationFrame(stepper);
16
+ }
17
+ }
1
18
  const activeTimers = /* @__PURE__ */ new Set();
2
19
  const beginTypes = /* @__PURE__ */ new Set(["continue", "start"]);
3
20
  const destroyedMessage = "Timer has already been destroyed";
@@ -12,24 +29,7 @@ const pauseTypes = /* @__PURE__ */ new Set(["continue", "pause"]);
12
29
  const startedMessage = "Timer has already been started";
13
30
  const values = [];
14
31
  let last;
15
- let milliseconds;
16
- function step(now) {
17
- if (values.length === 10) {
18
- milliseconds = Math.floor(
19
- values.slice(2, -2).reduce((first, second) => first + second) / 6
20
- );
21
- last = void 0;
22
- values.length = 0;
23
- } else {
24
- last ??= now;
25
- const difference = now - last;
26
- if (difference > 0) {
27
- values.push(difference);
28
- }
29
- last = now;
30
- requestAnimationFrame(step);
31
- }
32
- }
33
- requestAnimationFrame(step);
32
+ let milliseconds = Math.floor(1e3 / 60 * 2) / 2;
33
+ requestAnimationFrame(stepper);
34
34
 
35
35
  export { activeTimers, beginTypes, destroyedMessage, endOrRestartTypes, endTypes, hiddenTimers, milliseconds, pauseTypes, startedMessage };
package/dist/get.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const _function = require('./node_modules/@oscarpalmer/atoms/dist/function.cjs');
5
+ const _function = require('@oscarpalmer/atoms/function');
6
6
 
7
7
  function getCallback(value) {
8
8
  return typeof value === "function" ? value : _function.noop;
package/dist/get.js CHANGED
@@ -1,4 +1,4 @@
1
- import { noop } from './node_modules/@oscarpalmer/atoms/dist/function.js';
1
+ import { noop } from '@oscarpalmer/atoms/function';
2
2
 
3
3
  function getCallback(value) {
4
4
  return typeof value === "function" ? value : noop;
package/dist/timer.cjs CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
+ const _function = require('@oscarpalmer/atoms/function');
6
+
5
7
  class Timer {
6
8
  constructor(type, worker, state, options, start) {
7
9
  this.worker = worker;
@@ -57,6 +59,10 @@ class Timer {
57
59
  */
58
60
  destroy() {
59
61
  this.state.destroyed = true;
62
+ this.options.onAfter = _function.noop;
63
+ this.options.onError = _function.noop;
64
+ this.state.callback = _function.noop;
65
+ this.state.trace = void 0;
60
66
  this.#work("stop");
61
67
  }
62
68
  /**
@@ -1,3 +1,22 @@
1
+ /**
2
+ * Stepper to calculate the average refresh rate of the display
3
+ */
4
+ function stepper(now) {
5
+ if (values.length === 7) {
6
+ milliseconds = Math.floor((values.slice(2).reduce((first, second) => first + second) / 5) * 2) / 2;
7
+ last = undefined;
8
+ values.length = 0;
9
+ }
10
+ else {
11
+ last ??= now;
12
+ const difference = now - last;
13
+ if (difference > 0) {
14
+ values.push(difference);
15
+ }
16
+ last = now;
17
+ requestAnimationFrame(stepper);
18
+ }
19
+ }
1
20
  /**
2
21
  * A set of all active timers
3
22
  */
@@ -35,26 +54,10 @@ const startedMessage = 'Timer has already been started';
35
54
  const values = [];
36
55
  let last;
37
56
  /**
38
- * A calculated average of the refresh rate of the display
57
+ * A calculated average of the refresh rate of the display _(in milliseconds)_
39
58
  */
40
- let milliseconds;
41
- function step(now) {
42
- if (values.length === 10) {
43
- milliseconds = Math.floor(values.slice(2, -2).reduce((first, second) => first + second) / 6);
44
- last = undefined;
45
- values.length = 0;
46
- }
47
- else {
48
- last ??= now;
49
- const difference = now - last;
50
- if (difference > 0) {
51
- values.push(difference);
52
- }
53
- last = now;
54
- requestAnimationFrame(step);
55
- }
56
- }
57
- requestAnimationFrame(step);
59
+ let milliseconds = Math.floor((1000 / 60) * 2) / 2;
60
+ requestAnimationFrame(stepper);
58
61
 
59
62
  if (globalThis._oscarpalmer_timers == null) {
60
63
  Object.defineProperty(globalThis, '_oscarpalmer_timers', {
@@ -204,6 +207,10 @@ class Timer {
204
207
  */
205
208
  destroy() {
206
209
  this.state.destroyed = true;
210
+ this.options.onAfter = noop;
211
+ this.options.onError = noop;
212
+ this.state.callback = noop;
213
+ this.state.trace = undefined;
207
214
  this.#work('stop');
208
215
  }
209
216
  /**
package/dist/timer.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { noop } from '@oscarpalmer/atoms/function';
2
+
1
3
  class Timer {
2
4
  constructor(type, worker, state, options, start) {
3
5
  this.worker = worker;
@@ -53,6 +55,10 @@ class Timer {
53
55
  */
54
56
  destroy() {
55
57
  this.state.destroyed = true;
58
+ this.options.onAfter = noop;
59
+ this.options.onError = noop;
60
+ this.state.callback = noop;
61
+ this.state.trace = void 0;
56
62
  this.#work("stop");
57
63
  }
58
64
  /**
package/dist/when.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const _function = require('./node_modules/@oscarpalmer/atoms/dist/function.cjs');
5
+ const _function = require('@oscarpalmer/atoms/function');
6
6
  const constants = require('./constants.cjs');
7
7
  const get = require('./get.cjs');
8
8
  const models = require('./models.cjs');
package/dist/when.js CHANGED
@@ -1,4 +1,4 @@
1
- import { noop } from './node_modules/@oscarpalmer/atoms/dist/function.js';
1
+ import { noop } from '@oscarpalmer/atoms/function';
2
2
  import { milliseconds, destroyedMessage, startedMessage } from './constants.js';
3
3
  import { getValidNumber } from './get.js';
4
4
  import { TimerTrace } from './models.js';
package/package.json CHANGED
@@ -15,7 +15,6 @@
15
15
  "@vitest/coverage-istanbul": "^3.1",
16
16
  "dts-bundle-generator": "^9.5",
17
17
  "glob": "^11",
18
- "happy-dom": "^17.4",
19
18
  "jsdom": "^26.1",
20
19
  "tslib": "^2.8",
21
20
  "typescript": "^5.8",
@@ -95,5 +94,5 @@
95
94
  },
96
95
  "type": "module",
97
96
  "types": "types/index.d.cts",
98
- "version": "0.29.0"
97
+ "version": "0.31.0"
99
98
  }
package/src/constants.ts CHANGED
@@ -1,6 +1,32 @@
1
1
  import type {WorkHandlerType} from './models';
2
2
  import type {Timer} from './timer';
3
3
 
4
+ /**
5
+ * Stepper to calculate the average refresh rate of the display
6
+ */
7
+ function stepper(now: DOMHighResTimeStamp): void {
8
+ if (values.length === 7) {
9
+ milliseconds = Math.floor(
10
+ (values.slice(2).reduce((first, second) => first + second) / 5) * 2,
11
+ ) / 2;
12
+
13
+ last = undefined;
14
+ values.length = 0;
15
+ } else {
16
+ last ??= now;
17
+
18
+ const difference = now - last;
19
+
20
+ if (difference > 0) {
21
+ values.push(difference);
22
+ }
23
+
24
+ last = now;
25
+
26
+ requestAnimationFrame(stepper);
27
+ }
28
+ }
29
+
4
30
  /**
5
31
  * A set of all active timers
6
32
  */
@@ -48,31 +74,8 @@ const values: number[] = [];
48
74
  let last: DOMHighResTimeStamp | undefined;
49
75
 
50
76
  /**
51
- * A calculated average of the refresh rate of the display
77
+ * A calculated average of the refresh rate of the display _(in milliseconds)_
52
78
  */
53
- export let milliseconds: number;
54
-
55
- function step(now: DOMHighResTimeStamp): void {
56
- if (values.length === 10) {
57
- milliseconds = Math.floor(
58
- values.slice(2, -2).reduce((first, second) => first + second) / 6,
59
- );
60
-
61
- last = undefined;
62
- values.length = 0;
63
- } else {
64
- last ??= now;
65
-
66
- const difference = now - last;
67
-
68
- if (difference > 0) {
69
- values.push(difference);
70
- }
71
-
72
- last = now;
73
-
74
- requestAnimationFrame(step);
75
- }
76
- }
79
+ export let milliseconds = Math.floor((1000 / 60) * 2) / 2;
77
80
 
78
- requestAnimationFrame(step);
81
+ requestAnimationFrame(stepper);
package/src/timer.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import {noop} from '@oscarpalmer/atoms/function';
1
2
  import type {
2
3
  TimerOptions,
3
4
  TimerState,
@@ -79,6 +80,12 @@ export class Timer {
79
80
  destroy(): void {
80
81
  this.state.destroyed = true;
81
82
 
83
+ this.options.onAfter = noop;
84
+ this.options.onError = noop;
85
+
86
+ this.state.callback = noop;
87
+ this.state.trace = undefined;
88
+
82
89
  this.#work('stop');
83
90
  }
84
91
 
@@ -103,7 +103,7 @@ export declare const pauseTypes: Set<WorkHandlerType>;
103
103
  */
104
104
  export declare const startedMessage = "Timer has already been started";
105
105
  /**
106
- * A calculated average of the refresh rate of the display
106
+ * A calculated average of the refresh rate of the display _(in milliseconds)_
107
107
  */
108
108
  export declare let milliseconds: number;
109
109
 
@@ -30,6 +30,6 @@ export declare const pauseTypes: Set<WorkHandlerType>;
30
30
  */
31
31
  export declare const startedMessage = "Timer has already been started";
32
32
  /**
33
- * A calculated average of the refresh rate of the display
33
+ * A calculated average of the refresh rate of the display _(in milliseconds)_
34
34
  */
35
35
  export declare let milliseconds: number;
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- function noop() {
6
- }
7
-
8
- exports.noop = noop;
@@ -1,4 +0,0 @@
1
- function noop() {
2
- }
3
-
4
- export { noop };