@cgtk/std 0.0.200 → 0.0.202
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/array.js +2 -2
- package/checks.js +1 -1
- package/dom.js +3 -3
- package/math.d.ts +1 -1
- package/package.json +1 -1
- package/port.js +1 -1
- package/schedule.d.ts +2 -1
- package/schedule.js +6 -2
- package/stream.js +1 -1
- package/string.js +1 -1
- package/typedarray.d.ts +1 -1
- package/typedarray.js +12 -12
package/array.js
CHANGED
|
@@ -11,8 +11,8 @@ export const cap = (n, f) => xs => {
|
|
|
11
11
|
f(xs);
|
|
12
12
|
return xs;
|
|
13
13
|
};
|
|
14
|
-
export const sliding = (n, xs = []) => comp(scan(
|
|
15
|
-
export const dropping = (n, xs = []) => comp(scan(
|
|
14
|
+
export const sliding = (n, xs = []) => comp(scan(push, xs), cap(n, shift));
|
|
15
|
+
export const dropping = (n, xs = []) => comp(scan(push, xs), cap(n, pop));
|
|
16
16
|
export const tuple = (...xs) => xs;
|
|
17
17
|
export const seek = (arr, vals, offset = 0) => {
|
|
18
18
|
for (let i = offset, n = arr.length; i < n; i++)
|
package/checks.js
CHANGED
|
@@ -29,7 +29,7 @@ export const isclose = (a, b, eps = Number.EPSILON) => Math.abs(a - b) < eps;
|
|
|
29
29
|
export const allclose = (a, b, eps) => a.length == b.length && a.every((x, i) => isclose(x, b[i], eps));
|
|
30
30
|
export const equal = (a, b) => a == b;
|
|
31
31
|
export const strictEqual = (a, b) => a === b;
|
|
32
|
-
export const isDiffPrev = (eq =
|
|
32
|
+
export const isDiffPrev = (eq = strictEqual) => comp(sliding(2), not(apply(eq)));
|
|
33
33
|
export const isLonger = (delta) => comp((x) => [performance.now(), x], sliding(2), (xs) => xs.length < 2 || xs[1][0] - xs[0][0] > delta);
|
|
34
34
|
export const isFunction = (x) => typeof x === "function";
|
|
35
35
|
export const isAborted = (signal) => () => signal.aborted;
|
package/dom.js
CHANGED
|
@@ -100,11 +100,11 @@ const NS = {
|
|
|
100
100
|
};
|
|
101
101
|
const tag = (ns, name) => document.createElementNS(NS[ns], name);
|
|
102
102
|
export const h = new Proxy({}, ({
|
|
103
|
-
get: (_, name) => F.bind(
|
|
103
|
+
get: (_, name) => F.bind(element, tag("HTML", name))
|
|
104
104
|
}));
|
|
105
105
|
export const s = new Proxy({}, {
|
|
106
|
-
get: (_, name) => F.bind(
|
|
106
|
+
get: (_, name) => F.bind(element, tag("SVG", name))
|
|
107
107
|
});
|
|
108
108
|
export const m = new Proxy({}, {
|
|
109
|
-
get: (_, name) => F.bind(
|
|
109
|
+
get: (_, name) => F.bind(element, tag("MathML", name))
|
|
110
110
|
});
|
package/math.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare const logn: (n: number, x: number) => number;
|
|
|
30
30
|
export declare const floordiv: (x: number, b: number) => number;
|
|
31
31
|
export declare const zoom: (x: number, s: number, p: number) => number;
|
|
32
32
|
export declare const align: (x: number, b: number) => number;
|
|
33
|
-
export declare const sign11: (x: number) => 1 |
|
|
33
|
+
export declare const sign11: (x: number) => -1 | 1;
|
|
34
34
|
export declare const nudge: (x: number, v?: number, eps?: number) => number;
|
|
35
35
|
export declare const divCeil: (a: number, b: number) => number;
|
|
36
36
|
export declare const trunc: (num: number, precision: number) => number;
|
package/package.json
CHANGED
package/port.js
CHANGED
|
@@ -6,7 +6,7 @@ import { promisify } from "./async.js";
|
|
|
6
6
|
export const onMessages = (target, fs) => on(target, "message", ({ data: { type, payload } }) => (type in fs) && fs[type](payload));
|
|
7
7
|
export const onMessage = (target, name, f) => on(target, "message", ({ data: { type, payload } }) => type == name && f(payload));
|
|
8
8
|
export const messageSources = (worker) => new Proxy({}, {
|
|
9
|
-
get: (_, k) => bind(
|
|
9
|
+
get: (_, k) => bind(onMessage, worker, k)
|
|
10
10
|
});
|
|
11
11
|
export const postMessages = (port) => new Proxy({}, {
|
|
12
12
|
get: (_, type) => (payload, options) => port.postMessage({ type, payload }, options)
|
package/schedule.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const timeout: (ms?: number) => Reactive<void>;
|
|
|
4
4
|
export declare const schedule: <T>(s: Reactive<T>) => <F extends FnV>(f: F) => FnV<Parameters<F>, Dispose>;
|
|
5
5
|
export declare const debounce: <T>(sched?: Reactive<T>) => Reactive<T>;
|
|
6
6
|
export declare const reset: <T>(sched?: Reactive<T>) => Reactive<T>;
|
|
7
|
-
export declare const repeatedly: <T = number>(
|
|
7
|
+
export declare const repeatedly: <T = number>(f: Fn<T>, sched?: Reactive<T>) => () => any;
|
|
8
|
+
export declare const repeatedlyCounted: <T = number>(n: number, f: Fn<number>, sched?: Reactive<T>) => () => any;
|
|
8
9
|
export declare const delayAfter: <F extends FnV<any>>(delta: number, n: number, f: F) => (x: any) => any;
|
|
9
10
|
export declare const micro: <F extends FnV>(f: F) => (...xs: Parameters<F>) => (reason?: any) => void;
|
package/schedule.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isUndefined, isDefined, counted } from './checks.js';
|
|
|
2
2
|
import { comp, lazy, bind, apply, call, where, noop, abortable } from './fn.js';
|
|
3
3
|
export const raf = f => bind(cancelAnimationFrame, requestAnimationFrame(f));
|
|
4
4
|
export const timeout = (ms = 0) => f => bind(clearTimeout, setTimeout(f, ms));
|
|
5
|
-
export const schedule = (s) => (f) => call(comp(apply(bind(
|
|
5
|
+
export const schedule = (s) => (f) => call(comp(apply(bind(lazy, f)), s));
|
|
6
6
|
export const debounce = (sched = raf) => {
|
|
7
7
|
let cancel;
|
|
8
8
|
const stop = () => { if (isDefined(cancel))
|
|
@@ -22,13 +22,17 @@ export const reset = (sched = raf) => {
|
|
|
22
22
|
return stop;
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
-
export const repeatedly = (sched = raf) =>
|
|
25
|
+
export const repeatedly = (f, sched = raf) => {
|
|
26
26
|
let cancel;
|
|
27
27
|
const g = (x) => { if (f(x) !== false)
|
|
28
28
|
cancel = sched(g); };
|
|
29
29
|
cancel = sched(g);
|
|
30
30
|
return () => cancel();
|
|
31
31
|
};
|
|
32
|
+
export const repeatedlyCounted = (n, f, sched) => {
|
|
33
|
+
let i = 0;
|
|
34
|
+
return repeatedly(() => f(i) !== false && ++i < n, sched);
|
|
35
|
+
};
|
|
32
36
|
export const delayAfter = (delta, n, f) => where(counted(n), f, schedule(reset(timeout(delta)))(f));
|
|
33
37
|
export const micro = (f) => (...xs) => abortable(signal => queueMicrotask(() => { if (!signal.aborted)
|
|
34
38
|
f(...xs); }));
|
package/stream.js
CHANGED
package/string.js
CHANGED
|
@@ -10,7 +10,7 @@ export const dirname = (path) => {
|
|
|
10
10
|
export const splitext = (path) => {
|
|
11
11
|
const idx = path.lastIndexOf(".");
|
|
12
12
|
if (idx == -1)
|
|
13
|
-
return [path,
|
|
13
|
+
return [path, EMPTY.STR];
|
|
14
14
|
return [path.slice(0, idx), path.slice(idx + 1)];
|
|
15
15
|
};
|
|
16
16
|
export const objectURL = (data, type) => URL.createObjectURL(new Blob([data], { type }));
|
package/typedarray.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare const i64: (length: number) => View<BigInt64Array<ArrayBufferLike
|
|
|
19
19
|
export declare const f16: (length: number) => View<Float16Array<ArrayBufferLike>>;
|
|
20
20
|
export declare const f32: (length: number) => View<Float32Array<ArrayBufferLike>>;
|
|
21
21
|
export declare const f64: (length: number) => View<Float64Array<ArrayBufferLike>>;
|
|
22
|
-
export declare const UintArray: (n: number) =>
|
|
22
|
+
export declare const UintArray: (n: number) => Uint16ArrayConstructor | Uint32ArrayConstructor | Uint8ArrayConstructor;
|
|
23
23
|
export declare const ctor: <T extends TypedArray>(x: T) => Constructor<T>;
|
|
24
24
|
export declare const emptyLike: <T extends TypedArray>(x: T) => T;
|
|
25
25
|
export declare const set: <T extends TypedArray>(xs: T, x: ArrayLike<Number<T>> | T, i: number) => T;
|
package/typedarray.js
CHANGED
|
@@ -2,17 +2,17 @@ import { bind } from "./fn.js";
|
|
|
2
2
|
import { zmap } from "./iterable.js";
|
|
3
3
|
import { push, tuple } from "./array.js";
|
|
4
4
|
export const view = (type, length) => (buf = new ArrayBuffer(type.BYTES_PER_ELEMENT * length), offset = 0) => new type(buf, offset, length);
|
|
5
|
-
export const u8 = bind(
|
|
6
|
-
export const u16 = bind(
|
|
7
|
-
export const u32 = bind(
|
|
8
|
-
export const u64 = bind(
|
|
9
|
-
export const i8 = bind(
|
|
10
|
-
export const i16 = bind(
|
|
11
|
-
export const i32 = bind(
|
|
12
|
-
export const i64 = bind(
|
|
13
|
-
export const f16 = bind(
|
|
14
|
-
export const f32 = bind(
|
|
15
|
-
export const f64 = bind(
|
|
5
|
+
export const u8 = bind(view, Uint8Array);
|
|
6
|
+
export const u16 = bind(view, Uint16Array);
|
|
7
|
+
export const u32 = bind(view, Uint32Array);
|
|
8
|
+
export const u64 = bind(view, BigUint64Array);
|
|
9
|
+
export const i8 = bind(view, Int8Array);
|
|
10
|
+
export const i16 = bind(view, Int16Array);
|
|
11
|
+
export const i32 = bind(view, Int32Array);
|
|
12
|
+
export const i64 = bind(view, BigInt64Array);
|
|
13
|
+
export const f16 = bind(view, Float16Array);
|
|
14
|
+
export const f32 = bind(view, Float32Array);
|
|
15
|
+
export const f64 = bind(view, Float64Array);
|
|
16
16
|
export const UintArray = (n) => n < 256 ? Uint8Array : n < 65536 ? Uint16Array : Uint32Array;
|
|
17
17
|
export const ctor = (x) => x.constructor;
|
|
18
18
|
export const emptyLike = (x) => new (ctor(x))(x.length);
|
|
@@ -57,4 +57,4 @@ export const tile = (n) => (out, x) => {
|
|
|
57
57
|
};
|
|
58
58
|
export const tileEvery = (m, n) => (xs, out = new (ctor(xs))(xs.length * n)) => (zmap(tile(n))(iter(out, m * n), iter(xs, m)), out);
|
|
59
59
|
export const strided = (data, size, stride = size, out = new (ctor(data))(data.length / size * stride)) => (iter(data, size).forEach((p, i) => set(out, p, i * stride)), out);
|
|
60
|
-
export const toFixed = (n, sep = ',') => (xs) => Iterator.from(xs).map(x => x.toFixed(n)).reduce(
|
|
60
|
+
export const toFixed = (n, sep = ',') => (xs) => Iterator.from(xs).map(x => x.toFixed(n)).reduce(push, []).join(sep);
|