@oscarpalmer/atoms 0.150.0 → 0.151.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/atoms.full.js +4 -28
- package/dist/index.js +1 -2
- package/dist/internal/function/limiter.js +3 -4
- package/package.json +1 -1
- package/src/index.ts +0 -4
- package/src/internal/function/limiter.ts +3 -4
- package/types/index.d.ts +0 -2
- package/dist/internal/frame-rate.js +0 -25
- package/src/internal/frame-rate.ts +0 -63
- package/types/internal/frame-rate.d.ts +0 -2
package/dist/atoms.full.js
CHANGED
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
function calculate() {
|
|
2
|
-
return new Promise((resolve) => {
|
|
3
|
-
const values = [];
|
|
4
|
-
let last;
|
|
5
|
-
function step(now) {
|
|
6
|
-
if (last != null) values.push(now - last);
|
|
7
|
-
last = now;
|
|
8
|
-
if (values.length >= TOTAL) resolve(values.sort().slice(TRIM_PART, -TRIM_PART).reduce((first, second) => first + second, 0) / (values.length - TRIM_TOTAL));
|
|
9
|
-
else requestAnimationFrame(step);
|
|
10
|
-
}
|
|
11
|
-
requestAnimationFrame(step);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
const TOTAL = 10;
|
|
15
|
-
const TRIM_PART = 2;
|
|
16
|
-
const TRIM_TOTAL = 4;
|
|
17
|
-
let FRAME_RATE_MS = 1e3 / 60;
|
|
18
|
-
/**
|
|
19
|
-
* A calculated average of the refresh rate of the display _(in milliseconds)_
|
|
20
|
-
*/
|
|
21
|
-
calculate().then((value) => {
|
|
22
|
-
FRAME_RATE_MS = value;
|
|
23
|
-
});
|
|
24
|
-
var frame_rate_default = FRAME_RATE_MS;
|
|
25
1
|
function getArrayCallback(value) {
|
|
26
2
|
switch (typeof value) {
|
|
27
3
|
case "function": return value;
|
|
@@ -702,9 +678,9 @@ function unique(array, key) {
|
|
|
702
678
|
return array.length > 1 ? findValues("unique", array, [key, void 0]).matched : array;
|
|
703
679
|
}
|
|
704
680
|
function getLimiter(callback, throttler, time) {
|
|
705
|
-
const interval = typeof time === "number" && time
|
|
681
|
+
const interval = typeof time === "number" && time > 0 ? time : 0;
|
|
706
682
|
function step(now, parameters) {
|
|
707
|
-
if (interval ===
|
|
683
|
+
if (interval === 0 || now - timestamp >= interval) {
|
|
708
684
|
if (throttler) timestamp = now;
|
|
709
685
|
callback(...parameters);
|
|
710
686
|
} else frame = requestAnimationFrame((next) => {
|
|
@@ -716,7 +692,7 @@ function getLimiter(callback, throttler, time) {
|
|
|
716
692
|
const limiter = (...parameters) => {
|
|
717
693
|
limiter.cancel();
|
|
718
694
|
frame = requestAnimationFrame((now) => {
|
|
719
|
-
timestamp ??= now
|
|
695
|
+
timestamp ??= now;
|
|
720
696
|
step(now, parameters);
|
|
721
697
|
});
|
|
722
698
|
};
|
|
@@ -3725,4 +3701,4 @@ var SizedSet = class extends Set {
|
|
|
3725
3701
|
}
|
|
3726
3702
|
}
|
|
3727
3703
|
};
|
|
3728
|
-
export { CancelablePromise,
|
|
3704
|
+
export { CancelablePromise, PromiseTimeoutError, QueueError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, floor, flow, toResult as fromPromise, toResult, fromQuery, toPromise as fromResult, toPromise, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toSet, toggle, trim, truncate, tryDecode, tryEncode, unique, unsmush, unwrap, update, upperCase, words };
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,6 @@ import { rgbToHex, rgbToHsl, rgbToHsla } from "./color/space/rgb.js";
|
|
|
36
36
|
import { getNormalizedHex, hexToHsl, hexToHsla, hexToRgb, hexToRgba } from "./color/space/hex.js";
|
|
37
37
|
import { hslToHex, hslToRgb, hslToRgba } from "./color/space/hsl.js";
|
|
38
38
|
import { getColor } from "./color/index.js";
|
|
39
|
-
import frame_rate_default from "./internal/frame-rate.js";
|
|
40
39
|
import { debounce } from "./function/debounce.js";
|
|
41
40
|
import { SizedMap } from "./sized/map.js";
|
|
42
41
|
import { memoize } from "./function/memoize.js";
|
|
@@ -72,4 +71,4 @@ import { QueueError, queue } from "./queue.js";
|
|
|
72
71
|
import { getRandomBoolean, getRandomCharacters, getRandomColor, getRandomHex, getRandomItem, getRandomItems } from "./random.js";
|
|
73
72
|
import { attempt } from "./result/index.js";
|
|
74
73
|
import { SizedSet } from "./sized/set.js";
|
|
75
|
-
export { CancelablePromise,
|
|
74
|
+
export { CancelablePromise, PromiseTimeoutError, QueueError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, floor, flow, toResult as fromPromise, fromQuery, toPromise as fromResult, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, times, titleCase, toMap, toPromise, toQuery, toRecord, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, unique, unsmush, unwrap, update, upperCase, words };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import frame_rate_default from "../frame-rate.js";
|
|
2
1
|
function getLimiter(callback, throttler, time) {
|
|
3
|
-
const interval = typeof time === "number" && time
|
|
2
|
+
const interval = typeof time === "number" && time > 0 ? time : 0;
|
|
4
3
|
function step(now, parameters) {
|
|
5
|
-
if (interval ===
|
|
4
|
+
if (interval === 0 || now - timestamp >= interval) {
|
|
6
5
|
if (throttler) timestamp = now;
|
|
7
6
|
callback(...parameters);
|
|
8
7
|
} else frame = requestAnimationFrame((next) => {
|
|
@@ -14,7 +13,7 @@ function getLimiter(callback, throttler, time) {
|
|
|
14
13
|
const limiter = (...parameters) => {
|
|
15
14
|
limiter.cancel();
|
|
16
15
|
frame = requestAnimationFrame((now) => {
|
|
17
|
-
timestamp ??= now
|
|
16
|
+
timestamp ??= now;
|
|
18
17
|
step(now, parameters);
|
|
19
18
|
});
|
|
20
19
|
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import FRAME_RATE_MS from './internal/frame-rate';
|
|
2
|
-
|
|
3
1
|
export * from './array/group-by';
|
|
4
2
|
export * from './array/misc';
|
|
5
3
|
export * from './array/to-map';
|
|
@@ -45,5 +43,3 @@ export * from './random';
|
|
|
45
43
|
export * from './result/index';
|
|
46
44
|
export * from './sized/map';
|
|
47
45
|
export * from './sized/set';
|
|
48
|
-
|
|
49
|
-
export {FRAME_RATE_MS};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type {CancelableCallback} from '../../models';
|
|
2
2
|
import type {GenericCallback} from '../../models';
|
|
3
|
-
import FRAME_RATE_MS from '../frame-rate';
|
|
4
3
|
|
|
5
4
|
// #region Functions
|
|
6
5
|
|
|
@@ -9,10 +8,10 @@ export function getLimiter<Callback extends GenericCallback>(
|
|
|
9
8
|
throttler: boolean,
|
|
10
9
|
time?: number,
|
|
11
10
|
): CancelableCallback<Callback> {
|
|
12
|
-
const interval = typeof time === 'number' && time
|
|
11
|
+
const interval = typeof time === 'number' && time > 0 ? time : 0;;
|
|
13
12
|
|
|
14
13
|
function step(now: DOMHighResTimeStamp, parameters: Parameters<Callback>): void {
|
|
15
|
-
if (interval ===
|
|
14
|
+
if (interval === 0 || now - timestamp >= interval) {
|
|
16
15
|
if (throttler) {
|
|
17
16
|
timestamp = now;
|
|
18
17
|
}
|
|
@@ -32,7 +31,7 @@ export function getLimiter<Callback extends GenericCallback>(
|
|
|
32
31
|
limiter.cancel();
|
|
33
32
|
|
|
34
33
|
frame = requestAnimationFrame(now => {
|
|
35
|
-
timestamp ??= now
|
|
34
|
+
timestamp ??= now;
|
|
36
35
|
|
|
37
36
|
step(now, parameters);
|
|
38
37
|
});
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import FRAME_RATE_MS from './internal/frame-rate';
|
|
2
1
|
export * from './array/group-by';
|
|
3
2
|
export * from './array/misc';
|
|
4
3
|
export * from './array/to-map';
|
|
@@ -39,4 +38,3 @@ export * from './random';
|
|
|
39
38
|
export * from './result/index';
|
|
40
39
|
export * from './sized/map';
|
|
41
40
|
export * from './sized/set';
|
|
42
|
-
export { FRAME_RATE_MS };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
function calculate() {
|
|
2
|
-
return new Promise((resolve) => {
|
|
3
|
-
const values = [];
|
|
4
|
-
let last;
|
|
5
|
-
function step(now) {
|
|
6
|
-
if (last != null) values.push(now - last);
|
|
7
|
-
last = now;
|
|
8
|
-
if (values.length >= TOTAL) resolve(values.sort().slice(TRIM_PART, -TRIM_PART).reduce((first, second) => first + second, 0) / (values.length - TRIM_TOTAL));
|
|
9
|
-
else requestAnimationFrame(step);
|
|
10
|
-
}
|
|
11
|
-
requestAnimationFrame(step);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
var TOTAL = 10;
|
|
15
|
-
var TRIM_PART = 2;
|
|
16
|
-
var TRIM_TOTAL = 4;
|
|
17
|
-
var FRAME_RATE_MS = 1e3 / 60;
|
|
18
|
-
/**
|
|
19
|
-
* A calculated average of the refresh rate of the display _(in milliseconds)_
|
|
20
|
-
*/
|
|
21
|
-
calculate().then((value) => {
|
|
22
|
-
FRAME_RATE_MS = value;
|
|
23
|
-
});
|
|
24
|
-
var frame_rate_default = FRAME_RATE_MS;
|
|
25
|
-
export { frame_rate_default as default };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// #region Functions
|
|
2
|
-
|
|
3
|
-
function calculate(): Promise<number> {
|
|
4
|
-
return new Promise(resolve => {
|
|
5
|
-
const values: number[] = [];
|
|
6
|
-
|
|
7
|
-
let last: DOMHighResTimeStamp;
|
|
8
|
-
|
|
9
|
-
function step(now: DOMHighResTimeStamp): void {
|
|
10
|
-
if (last != null) {
|
|
11
|
-
values.push(now - last);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
last = now;
|
|
15
|
-
|
|
16
|
-
if (values.length >= TOTAL) {
|
|
17
|
-
const median =
|
|
18
|
-
values
|
|
19
|
-
.sort()
|
|
20
|
-
.slice(TRIM_PART, -TRIM_PART)
|
|
21
|
-
.reduce((first, second) => first + second, 0) /
|
|
22
|
-
(values.length - TRIM_TOTAL);
|
|
23
|
-
|
|
24
|
-
resolve(median);
|
|
25
|
-
} else {
|
|
26
|
-
requestAnimationFrame(step);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
requestAnimationFrame(step);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// #endregion
|
|
35
|
-
|
|
36
|
-
// #region Variables
|
|
37
|
-
|
|
38
|
-
const TOTAL = 10;
|
|
39
|
-
|
|
40
|
-
const TRIM_PART = 2;
|
|
41
|
-
|
|
42
|
-
const TRIM_TOTAL = 4;
|
|
43
|
-
|
|
44
|
-
let FRAME_RATE_MS = 1000 / 60;
|
|
45
|
-
|
|
46
|
-
// #endregion
|
|
47
|
-
|
|
48
|
-
// #region Initialization
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* A calculated average of the refresh rate of the display _(in milliseconds)_
|
|
52
|
-
*/
|
|
53
|
-
calculate().then(value => {
|
|
54
|
-
FRAME_RATE_MS = value;
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// #endregion
|
|
58
|
-
|
|
59
|
-
// #region Exports
|
|
60
|
-
|
|
61
|
-
export default FRAME_RATE_MS;
|
|
62
|
-
|
|
63
|
-
// #endregion
|