@oscarpalmer/atoms 0.45.0 → 0.46.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.
package/dist/js/index.js CHANGED
@@ -960,6 +960,7 @@ var work2 = function(type, timer2, state, options, isRepeated2) {
960
960
  options.afterCallback?.(false);
961
961
  }
962
962
  if (type === "stop") {
963
+ activeTimers.delete(timer2);
963
964
  state.active = false;
964
965
  state.frame = undefined;
965
966
  return timer2;
@@ -1005,9 +1006,25 @@ var work2 = function(type, timer2, state, options, isRepeated2) {
1005
1006
  }
1006
1007
  state.frame = requestAnimationFrame(step);
1007
1008
  }
1009
+ activeTimers.add(timer2);
1008
1010
  state.frame = requestAnimationFrame(step);
1009
1011
  return timer2;
1010
1012
  };
1013
+ var activeTimers = new Set;
1014
+ var hiddenTimers = new Set;
1015
+ document.addEventListener("visibilitychange", () => {
1016
+ if (document.hidden) {
1017
+ for (const timer2 of activeTimers) {
1018
+ hiddenTimers.add(timer2);
1019
+ timer2.stop();
1020
+ }
1021
+ } else {
1022
+ for (const timer2 of hiddenTimers) {
1023
+ timer2.start();
1024
+ }
1025
+ hiddenTimers.clear();
1026
+ }
1027
+ });
1011
1028
  // src/js/touch.ts
1012
1029
  var supportsTouch = (() => {
1013
1030
  let value = false;
package/dist/js/timer.js CHANGED
@@ -119,6 +119,7 @@ var work = function(type, timer2, state, options, isRepeated2) {
119
119
  options.afterCallback?.(false);
120
120
  }
121
121
  if (type === "stop") {
122
+ activeTimers.delete(timer2);
122
123
  state.active = false;
123
124
  state.frame = undefined;
124
125
  return timer2;
@@ -164,9 +165,25 @@ var work = function(type, timer2, state, options, isRepeated2) {
164
165
  }
165
166
  state.frame = requestAnimationFrame(step);
166
167
  }
168
+ activeTimers.add(timer2);
167
169
  state.frame = requestAnimationFrame(step);
168
170
  return timer2;
169
171
  };
172
+ var activeTimers = new Set;
173
+ var hiddenTimers = new Set;
174
+ document.addEventListener("visibilitychange", () => {
175
+ if (document.hidden) {
176
+ for (const timer2 of activeTimers) {
177
+ hiddenTimers.add(timer2);
178
+ timer2.stop();
179
+ }
180
+ } else {
181
+ for (const timer2 of hiddenTimers) {
182
+ timer2.start();
183
+ }
184
+ hiddenTimers.clear();
185
+ }
186
+ });
170
187
  export {
171
188
  when,
172
189
  wait,
package/dist/js/timer.mjs CHANGED
@@ -119,6 +119,7 @@ var work = function(type, timer2, state, options, isRepeated2) {
119
119
  options.afterCallback?.(false);
120
120
  }
121
121
  if (type === "stop") {
122
+ activeTimers.delete(timer2);
122
123
  state.active = false;
123
124
  state.frame = undefined;
124
125
  return timer2;
@@ -164,9 +165,25 @@ var work = function(type, timer2, state, options, isRepeated2) {
164
165
  }
165
166
  state.frame = requestAnimationFrame(step);
166
167
  }
168
+ activeTimers.add(timer2);
167
169
  state.frame = requestAnimationFrame(step);
168
170
  return timer2;
169
171
  };
172
+ var activeTimers = new Set;
173
+ var hiddenTimers = new Set;
174
+ document.addEventListener("visibilitychange", () => {
175
+ if (document.hidden) {
176
+ for (const timer2 of activeTimers) {
177
+ hiddenTimers.add(timer2);
178
+ timer2.stop();
179
+ }
180
+ } else {
181
+ for (const timer2 of hiddenTimers) {
182
+ timer2.start();
183
+ }
184
+ hiddenTimers.clear();
185
+ }
186
+ });
170
187
  export {
171
188
  when,
172
189
  wait,
package/package.json CHANGED
@@ -131,5 +131,5 @@
131
131
  },
132
132
  "type": "module",
133
133
  "types": "./types/index.d.ts",
134
- "version": "0.45.0"
134
+ "version": "0.46.0"
135
135
  }
package/src/js/timer.ts CHANGED
@@ -101,6 +101,9 @@ type WhenOptions = {} & OptionsWithCount;
101
101
 
102
102
  type WorkType = 'restart' | 'start' | 'stop';
103
103
 
104
+ const activeTimers = new Set<Timer>();
105
+ const hiddenTimers = new Set<Timer>();
106
+
104
107
  function getValueOrDefault(value: unknown, defaultValue: number): number {
105
108
  return typeof value === 'number' && value > 0 ? value : defaultValue;
106
109
  }
@@ -331,6 +334,8 @@ function work(
331
334
  }
332
335
 
333
336
  if (type === 'stop') {
337
+ activeTimers.delete(timer);
338
+
334
339
  state.active = false;
335
340
  state.frame = undefined;
336
341
 
@@ -398,7 +403,24 @@ function work(
398
403
  state.frame = requestAnimationFrame(step);
399
404
  }
400
405
 
406
+ activeTimers.add(timer);
407
+
401
408
  state.frame = requestAnimationFrame(step);
402
409
 
403
410
  return timer;
404
411
  }
412
+
413
+ document.addEventListener('visibilitychange', () => {
414
+ if (document.hidden) {
415
+ for (const timer of activeTimers) {
416
+ hiddenTimers.add(timer);
417
+ timer.stop();
418
+ }
419
+ } else {
420
+ for (const timer of hiddenTimers) {
421
+ timer.start();
422
+ }
423
+
424
+ hiddenTimers.clear();
425
+ }
426
+ });