@cgtk/std 0.0.192 → 0.0.194
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.d.ts +1 -1
- package/array.js +1 -1
- package/assign.d.ts +1 -1
- package/assign.js +1 -1
- package/async.d.ts +3 -3
- package/async.js +5 -4
- package/basen.js +1 -1
- package/buffer.d.ts +1 -1
- package/buffer.js +1 -1
- package/checks.d.ts +2 -2
- package/checks.js +2 -2
- package/dom.d.ts +2 -2
- package/dom.js +3 -3
- package/fn.d.ts +3 -3
- package/fn.js +3 -3
- package/http.d.ts +6 -7
- package/http.js +11 -15
- package/iterable.d.ts +1 -1
- package/iterable.js +3 -3
- package/json.d.ts +1 -1
- package/json.js +1 -1
- package/map.d.ts +3 -3
- package/map.js +2 -2
- package/math.js +1 -1
- package/npy.d.ts +1 -1
- package/number.js +1 -1
- package/object.d.ts +2 -2
- package/package.json +2 -2
- package/port.d.ts +2 -1
- package/port.js +7 -4
- package/progress.d.ts +1 -1
- package/rect.d.ts +1 -1
- package/rect.js +1 -1
- package/resource.d.ts +10 -8
- package/resource.js +22 -15
- package/schedule.d.ts +1 -1
- package/schedule.js +2 -2
- package/set.d.ts +1 -0
- package/set.js +1 -0
- package/signal.d.ts +18 -5
- package/signal.js +56 -15
- package/src/array.d.ts +14 -0
- package/src/array.js +21 -0
- package/src/assign.d.ts +8 -0
- package/src/assign.js +26 -0
- package/src/async.d.ts +8 -0
- package/src/async.js +31 -0
- package/src/base64.d.ts +1 -0
- package/src/base64.js +7 -0
- package/src/basen.d.ts +12 -0
- package/src/basen.js +31 -0
- package/src/buffer.d.ts +14 -0
- package/src/buffer.js +54 -0
- package/src/checks.d.ts +29 -0
- package/src/checks.js +44 -0
- package/src/constants.d.ts +5 -0
- package/src/constants.js +1 -0
- package/src/dom.d.ts +50 -0
- package/src/dom.js +36 -0
- package/src/fn.d.ts +33 -0
- package/src/fn.js +61 -0
- package/src/http.d.ts +9 -0
- package/src/http.js +33 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/iterable.d.ts +43 -0
- package/src/iterable.js +158 -0
- package/src/json.d.ts +1 -0
- package/src/json.js +1 -0
- package/src/map.d.ts +12 -0
- package/src/map.js +35 -0
- package/src/math.d.ts +34 -0
- package/src/math.js +43 -0
- package/src/npy.d.ts +10 -0
- package/src/npy.js +29 -0
- package/src/number.d.ts +4 -0
- package/src/number.js +13 -0
- package/src/object.d.ts +15 -0
- package/src/object.js +13 -0
- package/src/port.d.ts +30 -0
- package/src/port.js +56 -0
- package/src/progress.d.ts +6 -0
- package/src/progress.js +1 -0
- package/src/rect.d.ts +5 -0
- package/src/rect.js +16 -0
- package/src/resource.d.ts +12 -0
- package/src/resource.js +28 -0
- package/src/schedule.d.ts +10 -0
- package/src/schedule.js +33 -0
- package/src/set.d.ts +2 -0
- package/src/set.js +2 -0
- package/src/signal.d.ts +37 -0
- package/src/signal.js +89 -0
- package/src/stream.d.ts +6 -0
- package/src/stream.js +26 -0
- package/src/string.d.ts +8 -0
- package/src/string.js +29 -0
- package/src/struct.d.ts +42 -0
- package/src/struct.js +58 -0
- package/src/tree.d.ts +11 -0
- package/src/tree.js +25 -0
- package/src/treemap.d.ts +13 -0
- package/src/treemap.js +71 -0
- package/src/typedarray.d.ts +31 -0
- package/src/typedarray.js +39 -0
- package/src/types.d.ts +63 -0
- package/src/types.js +1 -0
- package/src/utils.d.ts +4 -0
- package/src/utils.js +30 -0
- package/src/weak.d.ts +2 -0
- package/src/weak.js +5 -0
- package/stream.d.ts +1 -1
- package/stream.js +2 -2
- package/string.d.ts +2 -1
- package/string.js +3 -2
- package/struct.d.ts +2 -2
- package/struct.js +2 -2
- package/tree.d.ts +3 -3
- package/tree.js +8 -10
- package/treemap.d.ts +12 -12
- package/treemap.js +62 -59
- package/typedarray.d.ts +1 -1
- package/typedarray.js +3 -3
- package/types.d.ts +3 -7
- package/utils.d.ts +1 -1
- package/utils.js +1 -1
- package/weak.d.ts +2 -2
- package/weak.js +1 -1
package/array.d.ts
CHANGED
package/array.js
CHANGED
package/assign.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RecordOf } from "./types";
|
|
1
|
+
import type { RecordOf } from "./types.js";
|
|
2
2
|
type PO = RecordOf<unknown>;
|
|
3
3
|
type Merge<T extends PO, S extends PO> = {
|
|
4
4
|
[K in keyof (T & S)]: K extends keyof S ? (K extends keyof T ? (S[K] extends PO ? (T[K] extends PO ? Merge<T[K], S[K]> : S[K]) : S[K]) : S[K]) : (K extends keyof T ? T[K] : never);
|
package/assign.js
CHANGED
package/async.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Fn, Constantly,
|
|
1
|
+
import type { Fn, Constantly, Maybe, Dispose, MaybePromise } from "./types.js";
|
|
2
2
|
export declare const timeout: (ms: number, signal?: AbortSignal) => Promise<unknown>;
|
|
3
|
-
export declare const delay: (ms: number) => <T>(x: T) => Promise<T>;
|
|
4
|
-
export declare const probing: <T>(p: Promise<T>) => Constantly<
|
|
3
|
+
export declare const delay: (ms: number, signal?: AbortSignal) => <T>(x: T) => Promise<T>;
|
|
4
|
+
export declare const probing: <T>(p: Promise<T>) => Constantly<Maybe<T>>;
|
|
5
5
|
export declare const resolved: <T>(p: Promise<T>) => (f: Fn<T>) => () => void;
|
|
6
6
|
export declare const promise: <T>(x: MaybePromise<T>) => Promise<any>;
|
|
7
7
|
export declare const then: <T>(p: Promise<T>) => <R>(f: Fn<T, R>) => Promise<R>;
|
package/async.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { filterT, disposable } from "./fn";
|
|
2
|
-
import { isDefined } from "./checks";
|
|
1
|
+
import { filterT, disposable } from "./fn.js";
|
|
2
|
+
import { isDefined } from "./checks.js";
|
|
3
3
|
export const timeout = (ms, signal) => new Promise((resolve, reject) => {
|
|
4
4
|
if (signal?.aborted)
|
|
5
5
|
reject(signal.reason);
|
|
6
6
|
else {
|
|
7
|
-
setTimeout(() => {
|
|
7
|
+
const t = setTimeout(() => {
|
|
8
8
|
if (signal?.aborted)
|
|
9
9
|
reject(signal.reason);
|
|
10
10
|
else
|
|
11
11
|
resolve(undefined);
|
|
12
12
|
}, ms);
|
|
13
|
+
signal?.addEventListener("abort", () => (clearTimeout(t), reject(signal.reason)), { once: true });
|
|
13
14
|
}
|
|
14
15
|
});
|
|
15
|
-
export const delay = (ms) => async (x) => (await timeout(ms), x);
|
|
16
|
+
export const delay = (ms, signal) => async (x) => (await timeout(ms, signal), x);
|
|
16
17
|
export const probing = (p) => {
|
|
17
18
|
let value = undefined;
|
|
18
19
|
p.then(x => value = x);
|
package/basen.js
CHANGED
package/buffer.d.ts
CHANGED
package/buffer.js
CHANGED
package/checks.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { TypedArray, NumberArray, BigIntArray, Pred, TPred,
|
|
1
|
+
import type { TypedArray, NumberArray, BigIntArray, Pred, TPred, Maybe } from "./types.js";
|
|
2
2
|
export declare const isTypedArray: (x: any) => x is TypedArray;
|
|
3
3
|
export declare const isNumberArray: (x: any) => x is NumberArray;
|
|
4
4
|
export declare const isBigIntArray: (x: any) => x is BigIntArray;
|
|
5
5
|
export declare const isUndefined: (x: any) => x is undefined;
|
|
6
6
|
export declare const isNull: (x: any) => x is null;
|
|
7
|
-
export declare const isDefined: <T>(x:
|
|
7
|
+
export declare const isDefined: <T>(x: Maybe<T>) => x is T;
|
|
8
8
|
export declare function assert(condition: boolean, msg: string): asserts condition;
|
|
9
9
|
export declare function assertType<T>(x: any, pred: TPred<T>, msg: string): asserts x is T;
|
|
10
10
|
export declare const isObject: TPred<Object>;
|
package/checks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { comp, not, apply, and } from "./fn";
|
|
2
|
-
import { retain } from "./array";
|
|
1
|
+
import { comp, not, apply, and } from "./fn.js";
|
|
2
|
+
import { retain } from "./array.js";
|
|
3
3
|
export const isTypedArray = (x) => x && (x instanceof Uint8Array || x instanceof Uint8ClampedArray ||
|
|
4
4
|
x instanceof Uint16Array || x instanceof Uint32Array ||
|
|
5
5
|
x instanceof Int8Array || x instanceof Int16Array || x instanceof Int32Array ||
|
package/dom.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fn, Dispose, RecordOf,
|
|
1
|
+
import type { Fn, Dispose, RecordOf, Maybe } from "./types.js";
|
|
2
2
|
export declare const customEvent: <T>(type: string, detail: T, { composed, bubbles, cancelable }?: EventInit) => CustomEvent<T>;
|
|
3
3
|
type ListenOpts = boolean | AddEventListenerOptions;
|
|
4
4
|
export declare const on: {
|
|
@@ -46,5 +46,5 @@ export declare const onResize: (el: Element, f: Fn<ResizeObserverEntry[]>, optio
|
|
|
46
46
|
export declare const preventDefault: <T extends Event>(e: T) => void;
|
|
47
47
|
export declare const loadImage: (img: HTMLImageElement, src: string) => Promise<HTMLImageElement>;
|
|
48
48
|
export declare const pushState: (path: string, query?: RecordOf<string>, data?: any) => void;
|
|
49
|
-
export declare const qs: (search?: string) =>
|
|
49
|
+
export declare const qs: (search?: string) => Maybe<RecordOf<string>>;
|
|
50
50
|
export {};
|
package/dom.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { forEach, noop } from "./fn";
|
|
2
|
-
import { isDefined } from "./checks";
|
|
3
|
-
import { EMPTY } from "./constants";
|
|
1
|
+
import { forEach, noop } from "./fn.js";
|
|
2
|
+
import { isDefined } from "./checks.js";
|
|
3
|
+
import { EMPTY } from "./constants.js";
|
|
4
4
|
export const customEvent = (type, detail, { composed = false, bubbles = false, cancelable = false } = EMPTY.OBJ) => new CustomEvent(type, { bubbles, cancelable, composed, detail });
|
|
5
5
|
export const on = (el, name, listener, opts = false) => {
|
|
6
6
|
el.addEventListener(name, listener, opts);
|
package/fn.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fn, FnV, FnF, Pred, TPred, FirstParam, Last, Constantly,
|
|
1
|
+
import type { Fn, FnV, FnF, Pred, TPred, FirstParam, Last, Constantly, Maybe, Dispose, Reactive } from "./types.js";
|
|
2
2
|
export declare const tee: <T>(f: Fn<T, void>) => Fn<T, T>;
|
|
3
3
|
export declare const comp: <Fs extends Fn[]>(...fs: Fs) => (x: FirstParam<Fs[0]>) => Last<Fs> extends Fn<any, infer R> ? R : never;
|
|
4
4
|
export declare const pipe: <T, Fs extends [Fn<T>, ...Fn[]]>(x: T, ...fs: Fs) => Last<Fs> extends Fn<any, infer R> ? R : never;
|
|
@@ -23,9 +23,9 @@ export declare const filter: <T>(p: Pred<T>, f: Fn<T>) => (x: T) => void;
|
|
|
23
23
|
export declare const filterT: <T>(p: TPred<T>, f: Fn<T>) => <S>(x: S) => void;
|
|
24
24
|
export declare const scan: <T, S>(f: FnV<[S, T], S>, a: S) => Fn<T, S>;
|
|
25
25
|
export declare const memoize: <T extends any[], K, V>(f: FnV<T, V>, key?: FnV<T, K>, cache?: Map<K, V>) => (...xs: T) => NonNullable<V>;
|
|
26
|
-
export declare const abortable: <T = any>(f: Fn<AbortSignal
|
|
26
|
+
export declare const abortable: <T = any>(f: Fn<AbortSignal>) => (reason?: T) => void;
|
|
27
27
|
export declare const disposable: (f: Fn<Fn<Dispose, Dispose>>, disposes?: Set<Dispose>) => Dispose;
|
|
28
|
-
export declare const disposing: () => <F extends FnV<any[],
|
|
28
|
+
export declare const disposing: () => <F extends FnV<any[], Maybe<Dispose>>>(f: F) => FnV<Parameters<F>, Dispose>;
|
|
29
29
|
export declare const disposeWith: <T>(f: Fn<T, Dispose>) => (g: Fn<Fn<T>>) => Dispose;
|
|
30
30
|
export declare const idemp: <F extends FnV<any[], Dispose | void>>(d: Fn<Dispose, Dispose>, f: F) => FnV<Parameters<F>, Dispose>;
|
|
31
31
|
export declare const toggler: (f: Fn<void, Dispose>) => (x: boolean) => Dispose;
|
package/fn.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { add } from "./set";
|
|
1
|
+
import { add } from "./set.js";
|
|
2
2
|
export const tee = f => x => (f(x), x);
|
|
3
3
|
export const comp = (...fs) => (x) => fs.reduce((x, f) => f(x), x);
|
|
4
4
|
export const pipe = (x, ...fs) => fs.reduce((x, f) => f(x), x);
|
|
@@ -34,10 +34,10 @@ export const memoize = (f, key = (...xs) => xs[0], cache = new Map()) => (...xs)
|
|
|
34
34
|
cache.set(k, f(...xs));
|
|
35
35
|
return cache.get(k);
|
|
36
36
|
};
|
|
37
|
-
export const abortable = (f
|
|
37
|
+
export const abortable = (f) => {
|
|
38
38
|
const ctrl = new AbortController();
|
|
39
39
|
f(ctrl.signal);
|
|
40
|
-
return () => ctrl.abort(reason);
|
|
40
|
+
return (reason) => ctrl.abort(reason);
|
|
41
41
|
};
|
|
42
42
|
export const disposable = (f, disposes = new Set()) => {
|
|
43
43
|
f(bind(add, disposes));
|
package/http.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
export declare const assertStatus: (status: number) => (resp: Response) => void;
|
|
2
2
|
export declare const contentLength: (response: Response) => number;
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const fetchDOM: (url: string, init?: RequestInit) => Promise<HTMLElement>;
|
|
3
|
+
export declare const fetchBuffer: (url: string | URL | Request, init?: RequestInit) => Promise<ArrayBuffer>;
|
|
4
|
+
export declare const fetchText: (url: string | URL | Request, init?: RequestInit) => Promise<string>;
|
|
5
|
+
export declare const fetchDOM: (url: string | URL | Request, init?: RequestInit) => Promise<HTMLElement>;
|
|
7
6
|
export declare const fetchImage: (src: string) => Promise<HTMLImageElement>;
|
|
8
|
-
export declare const fetchImageBitmap: (url: string, init?: RequestInit) => Promise<ImageBitmap>;
|
|
9
|
-
export declare const fetchJSON: (url: string, init?: RequestInit) => Promise<any>;
|
|
10
|
-
export declare const fetchDataUrl: (url: string) => Promise<string>;
|
|
7
|
+
export declare const fetchImageBitmap: (url: string | URL | Request, init?: RequestInit) => Promise<ImageBitmap>;
|
|
8
|
+
export declare const fetchJSON: (url: string | URL | Request, init?: RequestInit) => Promise<any>;
|
|
9
|
+
export declare const fetchDataUrl: (url: string | URL | Request, init?: RequestInit) => Promise<string>;
|
package/http.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { tee } from "./fn";
|
|
2
|
-
import { assert } from "./checks";
|
|
3
|
-
import { reduceArray } from './stream';
|
|
4
|
-
import { concat } from "./typedarray";
|
|
5
|
-
import { fromBytes } from "./json";
|
|
1
|
+
import { tee } from "./fn.js";
|
|
2
|
+
import { assert } from "./checks.js";
|
|
6
3
|
export const assertStatus = (status) => (resp) => assert(resp.status == status, `Invalid HTTP Status ${resp.status}: ${resp.url}`);
|
|
7
4
|
export const contentLength = (response) => {
|
|
8
5
|
const cl = response.headers.get("content-length");
|
|
9
6
|
return cl ? parseInt(cl) : -1;
|
|
10
7
|
};
|
|
11
|
-
export const toByteArray = async (stream) => concat(await reduceArray(stream));
|
|
12
8
|
export const fetchBuffer = (url, init) => fetch(url, init)
|
|
13
9
|
.then(tee(assertStatus(200)))
|
|
14
|
-
.then(resp => resp.
|
|
15
|
-
.then(
|
|
10
|
+
.then(resp => resp.blob())
|
|
11
|
+
.then(blob => blob.arrayBuffer());
|
|
16
12
|
export const fetchText = (url, init) => fetchBuffer(url, init).then(buf => new TextDecoder("utf-8").decode(buf));
|
|
17
13
|
export const fetchDOM = (url, init) => fetchText(url, init).then(txt => new DOMParser().parseFromString(txt, "image/svg+xml").documentElement);
|
|
18
14
|
export const fetchImage = (src) => new Promise((resolve, reject) => {
|
|
@@ -22,13 +18,13 @@ export const fetchImage = (src) => new Promise((resolve, reject) => {
|
|
|
22
18
|
image.onload = () => resolve(image);
|
|
23
19
|
image.onerror = reject;
|
|
24
20
|
});
|
|
25
|
-
export const fetchImageBitmap = async (url, init) =>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export const
|
|
31
|
-
|
|
21
|
+
export const fetchImageBitmap = async (url, init) => fetch(url, init)
|
|
22
|
+
.then(tee(assertStatus(200)))
|
|
23
|
+
.then(resp => resp.blob())
|
|
24
|
+
.then(blob => createImageBitmap(blob, { colorSpaceConversion: "none" }));
|
|
25
|
+
export const fetchJSON = (url, init) => fetchText(url, init).then(JSON.parse);
|
|
26
|
+
export const fetchDataUrl = (url, init) => fetch(url, init)
|
|
27
|
+
.then(tee(assertStatus(200)))
|
|
32
28
|
.then(resp => resp.blob())
|
|
33
29
|
.then(blob => new Promise(resolve => {
|
|
34
30
|
const f = new FileReader();
|
package/iterable.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fn, FnV, Indexed, Pred } from "./types";
|
|
1
|
+
import type { Fn, FnV, Indexed, Pred } from "./types.js";
|
|
2
2
|
export declare const next: <T>(xs: Iterator<T>) => T;
|
|
3
3
|
export declare const repeat: (n: number) => <A>(x: A) => Iterator<A>;
|
|
4
4
|
export declare const just: <T>(x: T) => IteratorObject<T>;
|
package/iterable.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { assert, isDefined } from "./checks";
|
|
2
|
-
import { pipe, comp, scan, apply, noop, identity, constantly } from "./fn";
|
|
3
|
-
import { set } from "./map";
|
|
1
|
+
import { assert, isDefined } from "./checks.js";
|
|
2
|
+
import { pipe, comp, scan, apply, noop, identity, constantly } from "./fn.js";
|
|
3
|
+
import { set } from "./map.js";
|
|
4
4
|
export const next = (xs) => {
|
|
5
5
|
const { done, value } = xs.next();
|
|
6
6
|
assert(isDefined(done) && !done, "iterator done");
|
package/json.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const fromBytes: (data:
|
|
1
|
+
export declare const fromBytes: (data: AllowSharedBufferSource, options?: TextDecodeOptions) => any;
|
package/json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const fromBytes = (data) => JSON.parse(new TextDecoder("utf-8").decode(data));
|
|
1
|
+
export const fromBytes = (data, options) => JSON.parse(new TextDecoder("utf-8").decode(data, options));
|
package/map.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FnV,
|
|
1
|
+
import type { FnV, Maybe } from "./types.js";
|
|
2
2
|
export declare const transform: <K, S, V>({ create, update, remove }: {
|
|
3
3
|
create: FnV<[S, K, Map<K, V>], V>;
|
|
4
4
|
update: FnV<[V, S, K, Map<K, V>], V>;
|
|
@@ -7,6 +7,6 @@ export declare const transform: <K, S, V>({ create, update, remove }: {
|
|
|
7
7
|
export declare const set: <K, V>(m: Map<K, V>, [i, x]: [K, V]) => Map<K, V>;
|
|
8
8
|
export declare const get: <K, V>(m: Map<K, V>, k: K, d: V) => V;
|
|
9
9
|
export declare const update: <K, V>(m: Map<K, V>, k: K, f: FnV<[V | undefined, K, Map<K, V>], V>) => Map<K, V>;
|
|
10
|
-
export declare const first: <K, V>(m: Map<K, V>) =>
|
|
11
|
-
export declare const shift: <K, V>(m: Map<K, V>) =>
|
|
10
|
+
export declare const first: <K, V>(m: Map<K, V>) => Maybe<V>;
|
|
11
|
+
export declare const shift: <K, V>(m: Map<K, V>) => Maybe<[K, V]>;
|
|
12
12
|
export declare const reduce: <K, V, T>(m: Map<K, V>, f: FnV<[T, V, K, Map<K, V>], T>, a: T) => T;
|
package/map.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isDefined } from "./checks";
|
|
2
|
-
import * as I from "./iterable";
|
|
1
|
+
import { isDefined } from "./checks.js";
|
|
2
|
+
import * as I from "./iterable.js";
|
|
3
3
|
export const transform = ({ create, update, remove }, dst = new Map()) => (src) => {
|
|
4
4
|
for (const k of dst.keys())
|
|
5
5
|
if (!src.has(k)) {
|
package/math.js
CHANGED
package/npy.d.ts
CHANGED
package/number.js
CHANGED
package/object.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RecordOf, Elements,
|
|
1
|
+
import type { RecordOf, Elements, Maybe, FnV, ValueOf, EntriesTuple, UnionToTuple, Entry } from "./types.js";
|
|
2
2
|
export declare const entries: <T extends RecordOf<any>>(o: T) => EntriesTuple<T>;
|
|
3
3
|
export declare const keys: <T extends RecordOf<any>>(o: T) => UnionToTuple<keyof T>;
|
|
4
4
|
export declare const entry: <K extends PropertyKey, V>(k: K, v: V) => Entry<K, V>;
|
|
@@ -11,5 +11,5 @@ export declare const assoc: <T extends RecordOf<any>>(a: T, [k, v]: [keyof T, Va
|
|
|
11
11
|
type Merge<T extends RecordOf<unknown>, S extends RecordOf<unknown>, V> = {
|
|
12
12
|
[K in keyof (T & S)]: V;
|
|
13
13
|
};
|
|
14
|
-
export declare const merge: <T, S = T, V = T>(f: FnV<[
|
|
14
|
+
export declare const merge: <T, S = T, V = T>(f: FnV<[Maybe<T>, Maybe<S>], V>) => <X extends RecordOf<T>, Y extends RecordOf<T>>(x: X, y: Y) => Merge<X, Y, V>;
|
|
15
15
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cgtk/std",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.194",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"exports": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"./utils": "./utils.js"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"typescript": "^
|
|
44
|
+
"typescript": "^6.0.2"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
package/port.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Dispose, Fn, Fns, FnV, RecordOf, MaybePromise } from "./types";
|
|
1
|
+
import type { Dispose, Fn, Fns, FnV, RecordOf, MaybePromise, Reactive } from "./types.js";
|
|
2
2
|
export interface Message<K, V> {
|
|
3
3
|
type: K;
|
|
4
4
|
payload: V;
|
|
@@ -8,6 +8,7 @@ export type Port = {
|
|
|
8
8
|
};
|
|
9
9
|
export declare const onMessages: <S extends RecordOf<any>, T = Worker>(target: MessageEventTarget<T>, fs: Fns<S>) => Dispose;
|
|
10
10
|
export declare const onMessage: <K extends string, S, T = Worker>(target: MessageEventTarget<T>, name: K, f: Fn<S>) => Dispose;
|
|
11
|
+
export declare const messageSources: <T extends RecordOf<any>, S = Worker>(worker: MessageEventTarget<S>) => { [K in keyof T]: Reactive<T[K]>; };
|
|
11
12
|
export declare const postMessages: <T extends RecordOf<any>>(port: Port) => { [k in keyof T]: FnV<[T[k], (StructuredSerializeOptions | undefined)?]>; };
|
|
12
13
|
export interface Request {
|
|
13
14
|
id: number;
|
package/port.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { forEach, noop } from "./fn";
|
|
2
|
-
import { isDefined } from "./checks";
|
|
3
|
-
import { on } from "./dom";
|
|
4
|
-
import { promise } from "./async";
|
|
1
|
+
import { forEach, noop, bind } from "./fn.js";
|
|
2
|
+
import { isDefined } from "./checks.js";
|
|
3
|
+
import { on } from "./dom.js";
|
|
4
|
+
import { promise } from "./async.js";
|
|
5
5
|
;
|
|
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
|
+
export const messageSources = (worker) => new Proxy({}, {
|
|
9
|
+
get: (_, k) => bind((onMessage), worker, k)
|
|
10
|
+
});
|
|
8
11
|
export const postMessages = (port) => new Proxy({}, {
|
|
9
12
|
get: (_, type) => (payload, options) => port.postMessage({ type, payload }, options)
|
|
10
13
|
});
|
package/progress.d.ts
CHANGED
package/rect.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Tuple } from "./types";
|
|
1
|
+
import type { Tuple } from "./types.js";
|
|
2
2
|
export type Rect = Tuple<number, 4>;
|
|
3
3
|
export declare const rect: (x: number, y: number, w: number, h: number) => Rect;
|
|
4
4
|
export declare const vertical: (ratio: number[]) => (i: number) => ([x, _, w, h]: Rect) => Rect;
|
package/rect.js
CHANGED
package/resource.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type { Fn, Dispose,
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type Resolved<T extends Structure<Resource<any>>> = {
|
|
7
|
-
[K in keyof T]: T[K] extends Resource<infer R> ? R : T[K] extends Structure<Resource<any>> ? Resolved<T[K]> : never;
|
|
1
|
+
import type { Fn, Dispose, Structure, Reactive } from "./types.js";
|
|
2
|
+
export type Resource<T> = Reactive<T, Dispose | void> & {
|
|
3
|
+
value: T;
|
|
4
|
+
dispose: Dispose;
|
|
5
|
+
map<S>(f: Fn<T, S>): Resource<S>;
|
|
8
6
|
};
|
|
9
|
-
export declare const
|
|
7
|
+
export declare const resource: <T>(value: T, dispose?: Dispose) => Resource<T>;
|
|
8
|
+
type Unwrapped<T> = T extends Resource<infer U> ? U : {
|
|
9
|
+
[K in keyof T]: Unwrapped<T[K]>;
|
|
10
|
+
};
|
|
11
|
+
export declare const compose: <R extends Structure<Resource<any>>>(rs: R) => Resource<Unwrapped<R>>;
|
|
10
12
|
export {};
|
package/resource.js
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
import { forEach, noop
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { forEach, noop } from "./fn.js";
|
|
2
|
+
import { isFunction } from "./checks.js";
|
|
3
|
+
export const resource = (value, dispose = noop) => {
|
|
4
|
+
const res = ((f) => forEach(f(value) ?? noop, dispose));
|
|
5
|
+
res.value = value;
|
|
6
|
+
res.dispose = dispose;
|
|
7
|
+
res.map = (f) => resource(f(value), dispose);
|
|
8
|
+
return res;
|
|
9
|
+
};
|
|
10
|
+
const isResource = (r) => isFunction(r)
|
|
11
|
+
&& Object.hasOwn(r, "value")
|
|
12
|
+
&& Object.hasOwn(r, "dispose")
|
|
13
|
+
&& isFunction(r["dispose"]);
|
|
14
|
+
export const compose = (rs) => {
|
|
15
|
+
const disposes = [];
|
|
16
|
+
const rec = (rs) => {
|
|
12
17
|
if (isResource(rs)) {
|
|
13
|
-
|
|
18
|
+
disposes.push(rs.dispose);
|
|
19
|
+
return rs.value;
|
|
14
20
|
}
|
|
15
21
|
else if (Array.isArray(rs)) {
|
|
16
|
-
return
|
|
22
|
+
return rs.map(rec);
|
|
17
23
|
}
|
|
18
|
-
return
|
|
24
|
+
return Object.fromEntries(Object.entries(rs).map(([k, v]) => [k, rec(v)]));
|
|
19
25
|
};
|
|
20
|
-
|
|
26
|
+
const value = rec(rs);
|
|
27
|
+
return resource(value, forEach(...disposes));
|
|
21
28
|
};
|
package/schedule.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Dispose, Fn, FnV, Reactive } from './types';
|
|
1
|
+
import type { Dispose, Fn, FnV, Reactive } from './types.js';
|
|
2
2
|
export declare const raf: Reactive<number>;
|
|
3
3
|
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>;
|
package/schedule.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isUndefined, isDefined, counted } from './checks';
|
|
2
|
-
import { comp, lazy, bind, apply, call, where, disposing, noop } from './fn';
|
|
1
|
+
import { isUndefined, isDefined, counted } from './checks.js';
|
|
2
|
+
import { comp, lazy, bind, apply, call, where, disposing, noop } from './fn.js';
|
|
3
3
|
export const raf = f => bind(cancelAnimationFrame, requestAnimationFrame(f));
|
|
4
4
|
export const timeout = (ms) => f => bind(clearTimeout, setTimeout(f, ms));
|
|
5
5
|
export const schedule = (s) => (f) => call(comp(apply(bind((lazy), f)), s));
|
package/set.d.ts
CHANGED
package/set.js
CHANGED
package/signal.d.ts
CHANGED
|
@@ -1,24 +1,37 @@
|
|
|
1
|
-
import type { Fn, FnV, Fns, Reactive, RecordOf } from "./types";
|
|
1
|
+
import type { Fn, FnV, Fns, Pred, Reactive, RecordOf, Structure } from "./types.js";
|
|
2
2
|
export type Signal<T> = Fn<T> & {
|
|
3
3
|
on: Reactive<T>;
|
|
4
4
|
};
|
|
5
5
|
export declare const create: <T>(f: Fn<T>, on: Reactive<T>) => Signal<T>;
|
|
6
6
|
export declare const signal: <T>(fns?: Set<Fn<T>>) => Signal<T>;
|
|
7
|
-
export
|
|
7
|
+
export declare const map: <T, S>(source: Reactive<T>, f: Fn<T, S>) => Reactive<S>;
|
|
8
|
+
export declare const filter: <T>(source: Reactive<T>, p: Pred<T>) => Reactive<T>;
|
|
9
|
+
export declare const cache: <T>(source: Reactive<T>) => Reactive<T>;
|
|
10
|
+
export interface ValueLike<T> {
|
|
8
11
|
value: T;
|
|
9
12
|
on: Reactive<T>;
|
|
13
|
+
}
|
|
14
|
+
export interface Box<T, F extends RecordOf<FnV>> extends ValueLike<T> {
|
|
15
|
+
ops: F;
|
|
16
|
+
}
|
|
17
|
+
export interface Value<T> extends ValueLike<T> {
|
|
10
18
|
op: <F extends FnV>(f: Fn<T, F>) => F;
|
|
11
19
|
ops: <F extends RecordOf<FnV>>(f: Fn<T, F>) => F;
|
|
12
20
|
set: Fn<T>;
|
|
13
21
|
update(): void;
|
|
22
|
+
map<S>(f: Fn<T, S>): Reactive<S>;
|
|
23
|
+
box: <F extends RecordOf<FnV>>(f: Fn<T, F>) => Box<T, F>;
|
|
14
24
|
}
|
|
15
|
-
export declare const value: <T>(x: T) => Value<T>;
|
|
25
|
+
export declare const value: <T>(x: T, fs?: Set<Fn<T>>) => Value<T>;
|
|
16
26
|
export type Values<T extends RecordOf<any>> = {
|
|
17
27
|
[k in keyof T]: Value<T[k]>;
|
|
18
28
|
};
|
|
19
29
|
export declare const values: <T extends RecordOf<any>>(vals: T) => Values<T>;
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
type Unwrapped<T> = T extends ValueLike<infer U> ? U : {
|
|
31
|
+
[K in keyof T]: Unwrapped<T[K]>;
|
|
32
|
+
};
|
|
33
|
+
export declare const compose: <T extends Structure<ValueLike<any>>, S = Unwrapped<T>>(xs: T, transform?: Fn<Unwrapped<T>, S>) => Reactive<S>;
|
|
22
34
|
export declare const mux: <I extends RecordOf<any>, O extends RecordOf<any>>(init: Fn<Fns<O>, Fns<I>>) => Fns<I> & {
|
|
23
35
|
on: { [k in keyof O]: Reactive<O[k]>; };
|
|
24
36
|
};
|
|
37
|
+
export {};
|