@oscarpalmer/atoms 0.32.0 → 0.33.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/css/a11y.css CHANGED
@@ -4,8 +4,10 @@
4
4
  .visually-hidden:not(:active):not(:focus):not(:focus-within) {
5
5
  width: 1px !important;
6
6
  height: 1px !important;
7
+ padding: 0 !important;
7
8
  clip: rect(1px, 1px 1px, 1px) !important;
8
9
  clip-path: inset(50%) !important;
9
10
  overflow: hidden !important;
11
+ border: 0 !important;
10
12
  white-space: nowrap !important;
11
13
  }
@@ -39,7 +39,6 @@
39
39
 
40
40
  ::before,
41
41
  ::after {
42
- box-sizing: inherit;
43
42
  text-decoration: inherit;
44
43
  vertical-align: inherit;
45
44
  }
@@ -83,6 +82,10 @@
83
82
  font-weight: bolder;
84
83
  }
85
84
 
85
+ :where(button, h1, h2, h3, h4, h5, h6, input, label, legend) {
86
+ line-height: 1.125;
87
+ }
88
+
86
89
  :where(button, [type=button i], [type=reset i], [type=submit i]) {
87
90
  -webkit-appearance: button;
88
91
  cursor: pointer;
@@ -109,10 +112,6 @@
109
112
  margin: 0;
110
113
  }
111
114
 
112
- :where(h1, h2, h3, h4, h5, h6, label, legend) {
113
- line-height: 1.125;
114
- }
115
-
116
115
  :where(h1, h2, h3, h4, h5, h6) {
117
116
  text-wrap: balance;
118
117
  }
@@ -180,10 +179,6 @@
180
179
  letter-spacing: inherit;
181
180
  }
182
181
 
183
- :where(button, input) {
184
- line-height: 1.25;
185
- }
186
-
187
182
  :where(fieldset) {
188
183
  border: 1px solid darkgrey;
189
184
  }
package/dist/js/array.js CHANGED
@@ -11,15 +11,15 @@ var _getCallbacks = function(bool, key) {
11
11
  return;
12
12
  }
13
13
  return {
14
- key: (item) => item?.[key]
14
+ key: (value) => value?.[key]
15
15
  };
16
16
  };
17
17
  var _findValue = function(type, array, value, key) {
18
18
  const callbacks = _getCallbacks(value, key);
19
- if (callbacks?.bool === undefined && callbacks?.key === undefined) {
19
+ if (callbacks?.bool == null && callbacks?.key == null) {
20
20
  return type === "index" ? array.indexOf(value) : array.find((item) => item === value);
21
21
  }
22
- if (callbacks.bool !== undefined) {
22
+ if (callbacks.bool != null) {
23
23
  const index2 = array.findIndex(callbacks.bool);
24
24
  return type === "index" ? index2 : index2 > -1 ? array[index2] : undefined;
25
25
  }
@@ -36,13 +36,13 @@ var _findValue = function(type, array, value, key) {
36
36
  var _findValues = function(type, array, value, key) {
37
37
  const callbacks = _getCallbacks(value, key);
38
38
  const { length } = array;
39
- if (type === "unique" && callbacks?.key === undefined && length >= 100) {
39
+ if (type === "unique" && callbacks?.key == null && length >= 100) {
40
40
  return Array.from(new Set(array));
41
41
  }
42
42
  if (typeof callbacks?.bool === "function") {
43
43
  return array.filter(callbacks.bool);
44
44
  }
45
- if (type === "all" && key === undefined) {
45
+ if (type === "all" && key == null) {
46
46
  return array.filter((item) => item === value);
47
47
  }
48
48
  const hasCallback = typeof callbacks?.key === "function";
@@ -68,7 +68,7 @@ var _insertValues = function(type, array, values, start, deleteCount) {
68
68
  let returned;
69
69
  for (;index < length; index += 1) {
70
70
  const result = array.splice(start, index === 0 ? deleteCount : 0, ...chunked[index]);
71
- if (returned === undefined) {
71
+ if (returned == null) {
72
72
  returned = result;
73
73
  }
74
74
  }
@@ -99,7 +99,7 @@ function find(array, value, key) {
99
99
  }
100
100
  function groupBy(array, key) {
101
101
  const callbacks = _getCallbacks(undefined, key);
102
- if (callbacks?.key === undefined) {
102
+ if (callbacks?.key == null) {
103
103
  return {};
104
104
  }
105
105
  const grouped = {};
@@ -125,8 +125,9 @@ function insert(array, index, values) {
125
125
  function push(array, values) {
126
126
  return _insertValues("push", array, values, array.length, 0);
127
127
  }
128
- function splice(array, start, deleteCount, values) {
129
- return _insertValues("splice", array, values, start, deleteCount);
128
+ function splice(array, start, amountOrValues, values) {
129
+ const amoutOrValuesIsArray = Array.isArray(amountOrValues);
130
+ return _insertValues("splice", array, amoutOrValuesIsArray ? amountOrValues : values ?? [], start, amoutOrValuesIsArray ? array.length : typeof amountOrValues === "number" && amountOrValues > 0 ? amountOrValues : 0);
130
131
  }
131
132
  function unique(array, key) {
132
133
  return _findValues("unique", array, undefined, key);
package/dist/js/array.mjs CHANGED
@@ -11,15 +11,15 @@ var _getCallbacks = function(bool, key) {
11
11
  return;
12
12
  }
13
13
  return {
14
- key: (item) => item?.[key]
14
+ key: (value) => value?.[key]
15
15
  };
16
16
  };
17
17
  var _findValue = function(type, array, value, key) {
18
18
  const callbacks = _getCallbacks(value, key);
19
- if (callbacks?.bool === undefined && callbacks?.key === undefined) {
19
+ if (callbacks?.bool == null && callbacks?.key == null) {
20
20
  return type === "index" ? array.indexOf(value) : array.find((item) => item === value);
21
21
  }
22
- if (callbacks.bool !== undefined) {
22
+ if (callbacks.bool != null) {
23
23
  const index2 = array.findIndex(callbacks.bool);
24
24
  return type === "index" ? index2 : index2 > -1 ? array[index2] : undefined;
25
25
  }
@@ -36,13 +36,13 @@ var _findValue = function(type, array, value, key) {
36
36
  var _findValues = function(type, array, value, key) {
37
37
  const callbacks = _getCallbacks(value, key);
38
38
  const { length } = array;
39
- if (type === "unique" && callbacks?.key === undefined && length >= 100) {
39
+ if (type === "unique" && callbacks?.key == null && length >= 100) {
40
40
  return Array.from(new Set(array));
41
41
  }
42
42
  if (typeof callbacks?.bool === "function") {
43
43
  return array.filter(callbacks.bool);
44
44
  }
45
- if (type === "all" && key === undefined) {
45
+ if (type === "all" && key == null) {
46
46
  return array.filter((item) => item === value);
47
47
  }
48
48
  const hasCallback = typeof callbacks?.key === "function";
@@ -68,7 +68,7 @@ var _insertValues = function(type, array, values, start, deleteCount) {
68
68
  let returned;
69
69
  for (;index < length; index += 1) {
70
70
  const result = array.splice(start, index === 0 ? deleteCount : 0, ...chunked[index]);
71
- if (returned === undefined) {
71
+ if (returned == null) {
72
72
  returned = result;
73
73
  }
74
74
  }
@@ -99,7 +99,7 @@ function find(array, value, key) {
99
99
  }
100
100
  function groupBy(array, key) {
101
101
  const callbacks = _getCallbacks(undefined, key);
102
- if (callbacks?.key === undefined) {
102
+ if (callbacks?.key == null) {
103
103
  return {};
104
104
  }
105
105
  const grouped = {};
@@ -125,8 +125,9 @@ function insert(array, index, values) {
125
125
  function push(array, values) {
126
126
  return _insertValues("push", array, values, array.length, 0);
127
127
  }
128
- function splice(array, start, deleteCount, values) {
129
- return _insertValues("splice", array, values, start, deleteCount);
128
+ function splice(array, start, amountOrValues, values) {
129
+ const amoutOrValuesIsArray = Array.isArray(amountOrValues);
130
+ return _insertValues("splice", array, amoutOrValuesIsArray ? amountOrValues : values ?? [], start, amoutOrValuesIsArray ? array.length : typeof amountOrValues === "number" && amountOrValues > 0 ? amountOrValues : 0);
130
131
  }
131
132
  function unique(array, key) {
132
133
  return _findValues("unique", array, undefined, key);
package/dist/js/index.js CHANGED
@@ -11,15 +11,15 @@ var _getCallbacks = function(bool, key) {
11
11
  return;
12
12
  }
13
13
  return {
14
- key: (item) => item?.[key]
14
+ key: (value) => value?.[key]
15
15
  };
16
16
  };
17
17
  var _findValue = function(type, array, value, key) {
18
18
  const callbacks = _getCallbacks(value, key);
19
- if (callbacks?.bool === undefined && callbacks?.key === undefined) {
19
+ if (callbacks?.bool == null && callbacks?.key == null) {
20
20
  return type === "index" ? array.indexOf(value) : array.find((item) => item === value);
21
21
  }
22
- if (callbacks.bool !== undefined) {
22
+ if (callbacks.bool != null) {
23
23
  const index2 = array.findIndex(callbacks.bool);
24
24
  return type === "index" ? index2 : index2 > -1 ? array[index2] : undefined;
25
25
  }
@@ -36,13 +36,13 @@ var _findValue = function(type, array, value, key) {
36
36
  var _findValues = function(type, array, value, key) {
37
37
  const callbacks = _getCallbacks(value, key);
38
38
  const { length } = array;
39
- if (type === "unique" && callbacks?.key === undefined && length >= 100) {
39
+ if (type === "unique" && callbacks?.key == null && length >= 100) {
40
40
  return Array.from(new Set(array));
41
41
  }
42
42
  if (typeof callbacks?.bool === "function") {
43
43
  return array.filter(callbacks.bool);
44
44
  }
45
- if (type === "all" && key === undefined) {
45
+ if (type === "all" && key == null) {
46
46
  return array.filter((item) => item === value);
47
47
  }
48
48
  const hasCallback = typeof callbacks?.key === "function";
@@ -68,7 +68,7 @@ var _insertValues = function(type, array, values, start, deleteCount) {
68
68
  let returned;
69
69
  for (;index < length; index += 1) {
70
70
  const result = array.splice(start, index === 0 ? deleteCount : 0, ...chunked[index]);
71
- if (returned === undefined) {
71
+ if (returned == null) {
72
72
  returned = result;
73
73
  }
74
74
  }
@@ -99,7 +99,7 @@ function find(array, value, key) {
99
99
  }
100
100
  function groupBy(array, key) {
101
101
  const callbacks = _getCallbacks(undefined, key);
102
- if (callbacks?.key === undefined) {
102
+ if (callbacks?.key == null) {
103
103
  return {};
104
104
  }
105
105
  const grouped = {};
@@ -125,8 +125,9 @@ function insert(array, index, values) {
125
125
  function push(array, values) {
126
126
  return _insertValues("push", array, values, array.length, 0);
127
127
  }
128
- function splice(array, start, deleteCount, values) {
129
- return _insertValues("splice", array, values, start, deleteCount);
128
+ function splice(array, start, amountOrValues, values) {
129
+ const amoutOrValuesIsArray = Array.isArray(amountOrValues);
130
+ return _insertValues("splice", array, amoutOrValuesIsArray ? amountOrValues : values ?? [], start, amoutOrValuesIsArray ? array.length : typeof amountOrValues === "number" && amountOrValues > 0 ? amountOrValues : 0);
130
131
  }
131
132
  function unique(array, key) {
132
133
  return _findValues("unique", array, undefined, key);
@@ -268,7 +269,7 @@ function queue(callback) {
268
269
  });
269
270
  }
270
271
  }
271
- if (globalThis._atomic_queued === undefined) {
272
+ if (globalThis._atomic_queued == null) {
272
273
  const queued = new Set;
273
274
  Object.defineProperty(globalThis, "_atomic_queued", {
274
275
  get() {
@@ -288,21 +289,65 @@ function getString(value) {
288
289
  return result?.toString?.() ?? String(result);
289
290
  }
290
291
  // src/js/timer.ts
292
+ function isRepeated(value) {
293
+ return /^repeat$/.test(value?.$timer ?? "");
294
+ }
295
+ function isTimer(value) {
296
+ return /^repeat|wait$/.test(value?.$timer ?? "");
297
+ }
298
+ function isWaited(value) {
299
+ return /^wait$/.test(value?.$timer ?? "");
300
+ }
291
301
  function repeat(callback, options) {
292
302
  const count = typeof options?.count === "number" ? options.count : Number.POSITIVE_INFINITY;
293
- return new Timer(callback, { ...options ?? {}, ...{ count } }).start();
303
+ return timer("repeat", callback, { ...options ?? {}, ...{ count } }).start();
294
304
  }
305
+ var timer = function(type, callback, options) {
306
+ const extended = {
307
+ afterCallback: options.afterCallback,
308
+ count: typeof options.count === "number" && options.count > 0 ? options.count : 1,
309
+ interval: typeof options.interval === "number" && options.interval >= 0 ? options.interval : 0
310
+ };
311
+ const state = {
312
+ callback,
313
+ active: false
314
+ };
315
+ const instance = Object.create({
316
+ restart() {
317
+ return work("restart", this, state, extended);
318
+ },
319
+ start() {
320
+ return work("start", this, state, extended);
321
+ },
322
+ stop() {
323
+ return work("stop", this, state, extended);
324
+ }
325
+ });
326
+ Object.defineProperties(instance, {
327
+ $timer: {
328
+ get() {
329
+ return type;
330
+ }
331
+ },
332
+ active: {
333
+ get() {
334
+ return state.active;
335
+ }
336
+ }
337
+ });
338
+ return instance.start();
339
+ };
295
340
  function wait(callback, time) {
296
- return new Timer(callback, {
341
+ return timer("wait", callback, {
297
342
  count: 1,
298
- interval: time
299
- }).start();
343
+ interval: time ?? 0
344
+ });
300
345
  }
301
- var work = function(type, timer, state, options) {
302
- if (type === "start" && timer.active || type === "stop" && !timer.active) {
303
- return timer;
346
+ var work = function(type, timer2, state, options) {
347
+ if (type === "start" && state.active || type === "stop" && !state.active) {
348
+ return timer2;
304
349
  }
305
- const { afterCallback, callback, count, interval } = options;
350
+ const { afterCallback, count, interval } = options;
306
351
  if (typeof state.frame === "number") {
307
352
  cancelAnimationFrame(state.frame);
308
353
  afterCallback?.(false);
@@ -310,10 +355,10 @@ var work = function(type, timer, state, options) {
310
355
  if (type === "stop") {
311
356
  state.active = false;
312
357
  state.frame = undefined;
313
- return timer;
358
+ return timer2;
314
359
  }
315
360
  state.active = true;
316
- const isRepeated = count > 0;
361
+ const isRepeated2 = count > 0;
317
362
  let index = 0;
318
363
  let total = count * interval;
319
364
  if (total < milliseconds) {
@@ -329,7 +374,7 @@ var work = function(type, timer, state, options) {
329
374
  const finished = elapsed >= total;
330
375
  if (finished || elapsed - 2 < interval && interval < elapsed + 2) {
331
376
  if (state.active) {
332
- callback(isRepeated ? index : undefined);
377
+ state.callback(isRepeated2 ? index : undefined);
333
378
  }
334
379
  index += 1;
335
380
  if (!finished && index < count) {
@@ -344,39 +389,13 @@ var work = function(type, timer, state, options) {
344
389
  state.frame = requestAnimationFrame(step);
345
390
  }
346
391
  state.frame = requestAnimationFrame(step);
347
- return timer;
392
+ return timer2;
348
393
  };
349
394
  var milliseconds = 0;
350
-
351
- class Timer {
352
- get active() {
353
- return this.state.active;
354
- }
355
- constructor(callback, options) {
356
- this.options = {
357
- afterCallback: options.afterCallback,
358
- callback,
359
- count: typeof options.count === "number" && options.count > 0 ? options.count : 1,
360
- interval: typeof options.interval === "number" && options.interval >= 0 ? options.interval : 0
361
- };
362
- this.state = {
363
- active: false
364
- };
365
- }
366
- restart() {
367
- return work("restart", this, this.state, this.options);
368
- }
369
- start() {
370
- return work("start", this, this.state, this.options);
371
- }
372
- stop() {
373
- return work("stop", this, this.state, this.options);
374
- }
375
- }
376
395
  (() => {
377
396
  let start;
378
397
  function fn(time) {
379
- if (start === undefined) {
398
+ if (start == null) {
380
399
  start = time;
381
400
  requestAnimationFrame(fn);
382
401
  } else {
@@ -453,22 +472,14 @@ var _getDiffs = function(first, second, prefix) {
453
472
  return changes;
454
473
  };
455
474
  var _getKey = function(...parts) {
456
- return parts.filter((part) => part !== undefined).join(".");
475
+ return parts.filter((part) => part != null).join(".");
457
476
  };
458
- var _getValue = function(data, key) {
459
- if (typeof data !== "object" || data === null || /^(__proto__|constructor|prototype)$/i.test(key)) {
460
- return;
461
- }
462
- return data instanceof Map ? data.get(key) : data[key];
463
- };
464
- var _setValue = function(data, key, value) {
465
- if (typeof data !== "object" || data === null || /^(__proto__|constructor|prototype)$/i.test(key)) {
466
- return;
467
- }
468
- if (data instanceof Map) {
469
- data.set(key, value);
470
- } else {
471
- data[key] = value;
477
+ var _handleValue = function(data, path, value, get) {
478
+ if (typeof data === "object" && data !== null && !/^(__proto__|constructor|prototype)$/i.test(path)) {
479
+ if (get) {
480
+ return data[path];
481
+ }
482
+ data[path] = value;
472
483
  }
473
484
  };
474
485
  function clone(value) {
@@ -527,12 +538,13 @@ function diff(first, second) {
527
538
  }
528
539
  return result;
529
540
  }
530
- function getValue(data, key) {
531
- const parts = getString(key).split(".");
541
+ function getValue(data, path) {
542
+ const parts = getString(path).split(".");
543
+ const { length } = parts;
532
544
  let index = 0;
533
545
  let value = typeof data === "object" ? data ?? {} : {};
534
- while (value != null) {
535
- value = _getValue(value, parts[index++]);
546
+ while (index < length && value != null) {
547
+ value = _handleValue(value, parts[index++], null, true);
536
548
  }
537
549
  return value;
538
550
  }
@@ -562,8 +574,8 @@ function merge(...values) {
562
574
  }
563
575
  return result;
564
576
  }
565
- function setValue(data, key, value) {
566
- const parts = getString(key).split(".");
577
+ function setValue(data, path, value) {
578
+ const parts = getString(path).split(".");
567
579
  const { length } = parts;
568
580
  const lastIndex = length - 1;
569
581
  let index = 0;
@@ -571,10 +583,10 @@ function setValue(data, key, value) {
571
583
  for (;index < length; index += 1) {
572
584
  const part = parts[index];
573
585
  if (parts.indexOf(part) === lastIndex) {
574
- _setValue(target, part, value);
586
+ _handleValue(target, part, value, false);
575
587
  break;
576
588
  }
577
- let next = _getValue(target, part);
589
+ let next = _handleValue(target, part, null, true);
578
590
  if (typeof next !== "object" || next === null) {
579
591
  next = /^\d+$/.test(part) ? [] : {};
580
592
  target[part] = next;
@@ -592,6 +604,9 @@ export {
592
604
  queue,
593
605
  push,
594
606
  merge,
607
+ isWaited,
608
+ isTimer,
609
+ isRepeated,
595
610
  insert,
596
611
  indexOf,
597
612
  groupBy,
@@ -613,7 +628,6 @@ export {
613
628
  clamp,
614
629
  chunk,
615
630
  between,
616
- Timer,
617
631
  findElements as $$,
618
632
  findElement as $
619
633
  };
package/dist/js/is.js CHANGED
@@ -15,7 +15,7 @@ function isNullable(value) {
15
15
  return value == null;
16
16
  }
17
17
  function isNullableOrWhitespace(value) {
18
- return value == null || getString(value).trim().length === 0;
18
+ return value == null || /^\s*$/.test(getString(value));
19
19
  }
20
20
  function isNumber(value) {
21
21
  return typeof value === "number" && !Number.isNaN(value);
@@ -33,7 +33,11 @@ function isPlainObject(value) {
33
33
  const prototype = Object.getPrototypeOf(value);
34
34
  return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
35
35
  }
36
+ function isPrimitive(value) {
37
+ return value == null || /^(bigint|boolean|number|string|symbol)$/.test(typeof value);
38
+ }
36
39
  export {
40
+ isPrimitive,
37
41
  isPlainObject,
38
42
  isObject,
39
43
  isNumerical,
package/dist/js/is.mjs CHANGED
@@ -7,7 +7,7 @@ function isNullable(value) {
7
7
  return value == null;
8
8
  }
9
9
  function isNullableOrWhitespace(value) {
10
- return value == null || getString(value).trim().length === 0;
10
+ return value == null || /^\s*$/.test(getString(value));
11
11
  }
12
12
  function isNumber(value) {
13
13
  return typeof value === "number" && !Number.isNaN(value);
@@ -25,7 +25,11 @@ function isPlainObject(value) {
25
25
  const prototype = Object.getPrototypeOf(value);
26
26
  return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
27
27
  }
28
+ function isPrimitive(value) {
29
+ return value == null || /^(bigint|boolean|number|string|symbol)$/.test(typeof value);
30
+ }
28
31
  export {
32
+ isPrimitive,
29
33
  isPlainObject,
30
34
  isObject,
31
35
  isNumerical,
package/dist/js/queue.js CHANGED
@@ -11,7 +11,7 @@ function queue(callback) {
11
11
  });
12
12
  }
13
13
  }
14
- if (globalThis._atomic_queued === undefined) {
14
+ if (globalThis._atomic_queued == null) {
15
15
  const queued = new Set;
16
16
  Object.defineProperty(globalThis, "_atomic_queued", {
17
17
  get() {
package/dist/js/queue.mjs CHANGED
@@ -11,7 +11,7 @@ function queue(callback) {
11
11
  });
12
12
  }
13
13
  }
14
- if (globalThis._atomic_queued === undefined) {
14
+ if (globalThis._atomic_queued == null) {
15
15
  const queued = new Set;
16
16
  Object.defineProperty(globalThis, "_atomic_queued", {
17
17
  get() {
package/dist/js/timer.js CHANGED
@@ -1,19 +1,63 @@
1
1
  // src/js/timer.ts
2
+ function isRepeated(value) {
3
+ return /^repeat$/.test(value?.$timer ?? "");
4
+ }
5
+ function isTimer(value) {
6
+ return /^repeat|wait$/.test(value?.$timer ?? "");
7
+ }
8
+ function isWaited(value) {
9
+ return /^wait$/.test(value?.$timer ?? "");
10
+ }
2
11
  function repeat(callback, options) {
3
12
  const count = typeof options?.count === "number" ? options.count : Number.POSITIVE_INFINITY;
4
- return new Timer(callback, { ...options ?? {}, ...{ count } }).start();
13
+ return timer("repeat", callback, { ...options ?? {}, ...{ count } }).start();
5
14
  }
15
+ var timer = function(type, callback, options) {
16
+ const extended = {
17
+ afterCallback: options.afterCallback,
18
+ count: typeof options.count === "number" && options.count > 0 ? options.count : 1,
19
+ interval: typeof options.interval === "number" && options.interval >= 0 ? options.interval : 0
20
+ };
21
+ const state = {
22
+ callback,
23
+ active: false
24
+ };
25
+ const instance = Object.create({
26
+ restart() {
27
+ return work("restart", this, state, extended);
28
+ },
29
+ start() {
30
+ return work("start", this, state, extended);
31
+ },
32
+ stop() {
33
+ return work("stop", this, state, extended);
34
+ }
35
+ });
36
+ Object.defineProperties(instance, {
37
+ $timer: {
38
+ get() {
39
+ return type;
40
+ }
41
+ },
42
+ active: {
43
+ get() {
44
+ return state.active;
45
+ }
46
+ }
47
+ });
48
+ return instance.start();
49
+ };
6
50
  function wait(callback, time) {
7
- return new Timer(callback, {
51
+ return timer("wait", callback, {
8
52
  count: 1,
9
- interval: time
10
- }).start();
53
+ interval: time ?? 0
54
+ });
11
55
  }
12
- var work = function(type, timer, state, options) {
13
- if (type === "start" && timer.active || type === "stop" && !timer.active) {
14
- return timer;
56
+ var work = function(type, timer2, state, options) {
57
+ if (type === "start" && state.active || type === "stop" && !state.active) {
58
+ return timer2;
15
59
  }
16
- const { afterCallback, callback, count, interval } = options;
60
+ const { afterCallback, count, interval } = options;
17
61
  if (typeof state.frame === "number") {
18
62
  cancelAnimationFrame(state.frame);
19
63
  afterCallback?.(false);
@@ -21,10 +65,10 @@ var work = function(type, timer, state, options) {
21
65
  if (type === "stop") {
22
66
  state.active = false;
23
67
  state.frame = undefined;
24
- return timer;
68
+ return timer2;
25
69
  }
26
70
  state.active = true;
27
- const isRepeated = count > 0;
71
+ const isRepeated2 = count > 0;
28
72
  let index = 0;
29
73
  let total = count * interval;
30
74
  if (total < milliseconds) {
@@ -40,7 +84,7 @@ var work = function(type, timer, state, options) {
40
84
  const finished = elapsed >= total;
41
85
  if (finished || elapsed - 2 < interval && interval < elapsed + 2) {
42
86
  if (state.active) {
43
- callback(isRepeated ? index : undefined);
87
+ state.callback(isRepeated2 ? index : undefined);
44
88
  }
45
89
  index += 1;
46
90
  if (!finished && index < count) {
@@ -55,39 +99,13 @@ var work = function(type, timer, state, options) {
55
99
  state.frame = requestAnimationFrame(step);
56
100
  }
57
101
  state.frame = requestAnimationFrame(step);
58
- return timer;
102
+ return timer2;
59
103
  };
60
104
  var milliseconds = 0;
61
-
62
- class Timer {
63
- get active() {
64
- return this.state.active;
65
- }
66
- constructor(callback, options) {
67
- this.options = {
68
- afterCallback: options.afterCallback,
69
- callback,
70
- count: typeof options.count === "number" && options.count > 0 ? options.count : 1,
71
- interval: typeof options.interval === "number" && options.interval >= 0 ? options.interval : 0
72
- };
73
- this.state = {
74
- active: false
75
- };
76
- }
77
- restart() {
78
- return work("restart", this, this.state, this.options);
79
- }
80
- start() {
81
- return work("start", this, this.state, this.options);
82
- }
83
- stop() {
84
- return work("stop", this, this.state, this.options);
85
- }
86
- }
87
105
  (() => {
88
106
  let start;
89
107
  function fn(time) {
90
- if (start === undefined) {
108
+ if (start == null) {
91
109
  start = time;
92
110
  requestAnimationFrame(fn);
93
111
  } else {
@@ -99,5 +117,7 @@ class Timer {
99
117
  export {
100
118
  wait,
101
119
  repeat,
102
- Timer
120
+ isWaited,
121
+ isTimer,
122
+ isRepeated
103
123
  };