@amritk/nish-x86_64-linux 0.38.0 → 0.40.1
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/INSTALL.md +74 -129
- package/bin/nish +0 -0
- package/docs/AI.md +455 -65
- package/package.json +1 -1
- package/runtime/core/host.d.ts +11 -0
- package/runtime/core/host.mjs +35 -0
- package/runtime/nish.d.ts +320 -33
- package/runtime/nish.h +84 -10
- package/runtime/nish.mjs +69 -6
- package/runtime/node.mjs +117 -0
- package/runtime/page-frame.d.ts +123 -0
- package/runtime/page-frame.mjs +736 -0
- package/runtime/page-game.d.ts +132 -0
- package/runtime/page-game.mjs +738 -0
- package/runtime/runtime-aes.c +97 -12
- package/runtime/runtime-async.c +43 -10
- package/runtime/runtime-bytes.c +88 -4
- package/runtime/runtime-checksum.c +207 -15
- package/runtime/runtime-net.c +64 -3
- package/runtime/runtime-os.c +174 -27
- package/runtime/runtime-region.c +94 -10
- package/runtime/runtime-sandbox.c +404 -17
- package/runtime/runtime-sha256.c +11 -4
- package/runtime/runtime-wasm.c +437 -0
- package/runtime/runtime.c +5 -0
- package/runtime/vite.mjs +1 -1
- package/scripts/build.sh +42 -8
- package/std/README.md +78 -91
- package/std/array.ts +36 -3
- package/std/collections.ts +51 -0
- package/std/compress/checksum.ts +13 -0
- package/std/compress/deflate.ts +0 -2
- package/std/crypto/hmac.ts +37 -10
- package/std/crypto/p256.ts +1629 -2732
- package/std/crypto/p384.ts +3 -1
- package/std/crypto/pki.ts +151 -13
- package/std/crypto/sha256.ts +34 -6
- package/std/crypto/x25519.ts +153 -64
- package/std/crypto/x509.ts +120 -10
- package/std/host/game.ts +273 -0
- package/std/input.ts +56 -0
- package/std/json-tokenizer.ts +344 -111
- package/std/json-typed.ts +256 -12
- package/std/json-value.ts +144 -3
- package/std/json.ts +63 -8
- package/std/net/fetch.ts +22 -4
- package/std/net/handler.ts +130 -16
- package/std/net/http-server.ts +3382 -0
- package/std/net/http1-client-codec.ts +6 -2
- package/std/net/http1-codec.ts +636 -162
- package/std/net/http1-server.ts +569 -42
- package/std/net/http2-cleartext.ts +526 -0
- package/std/net/http2-tls.ts +48 -0
- package/std/net/http2.ts +131 -14
- package/std/net/http3-server.ts +29 -3
- package/std/net/http3.ts +180 -7
- package/std/net/postgres-async.ts +1304 -86
- package/std/net/postgres-carrier.ts +343 -10
- package/std/net/postgres.ts +122 -7
- package/std/net/prefork.ts +195 -11
- package/std/net/quic-datagram.ts +30 -0
- package/std/net/quic-listener.ts +38 -12
- package/std/net/quic-packet.ts +19 -6
- package/std/net/quic-recovery.ts +373 -27
- package/std/net/quic-stream.ts +195 -37
- package/std/net/quic.ts +516 -22
- package/std/net/router.ts +407 -38
- package/std/net/serve.ts +1022 -110
- package/std/net/tls/codec.ts +110 -32
- package/std/net/tls/record-server.ts +37 -7
- package/std/net/tls/verify.ts +19 -1
- package/std/net/tls-tcp.ts +56 -1
- package/std/net/tls.ts +196 -50
- package/std/net/url.ts +83 -35
- package/std/net/websocket.ts +129 -19
- package/std/net/webtransport.ts +185 -1
- package/std/raster.ts +837 -0
- package/std/regex.ts +69 -47
- package/std/region.ts +62 -11
- package/std/release.ts +593 -0
- package/std/secret.ts +26 -59
- package/std/synth.ts +143 -0
- package/std/text.ts +233 -0
- package/std/threads.ts +298 -0
- package/std/yaml-json.ts +368 -28
- package/std/yaml.ts +122 -27
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `nish/page/game`: runs a wasm module built over `nish/host/game` on a
|
|
3
|
+
* canvas: the keyboard, pointer and touch read into its input ring, its
|
|
4
|
+
* sounds played through Web Audio, its framebuffer presented by
|
|
5
|
+
* `nish/page/frame` at a fixed step rate (docs/guide/using-nish/browser-games.md).
|
|
6
|
+
*/
|
|
7
|
+
import type { Backend, Presenter } from "./page-frame.js";
|
|
8
|
+
|
|
9
|
+
export type { Backend, Presenter } from "./page-frame.js";
|
|
10
|
+
|
|
11
|
+
/** A rectangle of the canvas, in fractions of its CSS box, that holds a key down while a finger is on it. */
|
|
12
|
+
export interface TouchZone {
|
|
13
|
+
/** The left edge, 0 at the canvas's left and 1 at its right. */
|
|
14
|
+
readonly x: number;
|
|
15
|
+
/** The top edge, 0 at the canvas's top and 1 at its bottom. */
|
|
16
|
+
readonly y: number;
|
|
17
|
+
/** The width, as a fraction of the canvas's width. */
|
|
18
|
+
readonly width: number;
|
|
19
|
+
/** The height, as a fraction of the canvas's height. */
|
|
20
|
+
readonly height: number;
|
|
21
|
+
/** The `KeyboardEvent.key` the zone holds down, such as `"ArrowLeft"`. */
|
|
22
|
+
readonly key: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** How touches reach the game: as keys held by zones, and a tap. */
|
|
26
|
+
export interface TouchOptions {
|
|
27
|
+
/** The zones, first match wins; a touch outside every zone holds nothing. */
|
|
28
|
+
readonly zones: readonly TouchZone[];
|
|
29
|
+
/** The key a short, still touch presses and releases, such as `"Enter"`; none when absent or empty. */
|
|
30
|
+
readonly tap?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The generated loader of a module built with `--emit-dts` (`game.mjs`), as far as `startGame` reads it. */
|
|
34
|
+
export interface GameLoader {
|
|
35
|
+
/**
|
|
36
|
+
* Instantiates the module.
|
|
37
|
+
*
|
|
38
|
+
* @param source - the compiled module
|
|
39
|
+
* @param imports - the page's imports, passed through from `GameOptions.imports`
|
|
40
|
+
* @returns the module's exports
|
|
41
|
+
*/
|
|
42
|
+
load(source: WebAssembly.Module, imports?: object): Promise<unknown>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** What `startGame` takes beyond the canvas and the module's URL. */
|
|
46
|
+
export interface GameOptions {
|
|
47
|
+
/** The seed passed to `init`, a whole number that fits in an i32; the clock's milliseconds by default. */
|
|
48
|
+
readonly seed?: number;
|
|
49
|
+
/**
|
|
50
|
+
* The `KeyboardEvent.key` names the game reads; others, and any key held
|
|
51
|
+
* with Ctrl, Alt or Meta, reach the page untouched. `DEFAULT_KEYS` by default.
|
|
52
|
+
*/
|
|
53
|
+
readonly keys?: readonly string[];
|
|
54
|
+
/** The touch zones and tap; `false` reads touches as nothing. `DEFAULT_TOUCH` by default. */
|
|
55
|
+
readonly touch?: TouchOptions | false;
|
|
56
|
+
/** How many times a second `step` runs. 60 by default. */
|
|
57
|
+
readonly stepsPerSecond?: number;
|
|
58
|
+
/** The most steps one display frame runs; the backlog past it is dropped. 8 by default. */
|
|
59
|
+
readonly maxStepsPerFrame?: number;
|
|
60
|
+
/** `false` asks the module for no sounds; `{ muted: true }` starts muted. On by default. */
|
|
61
|
+
readonly sound?: false | { readonly muted?: boolean };
|
|
62
|
+
/** The presenter tier to start from; the tiers above it are not tried. WebGPU by default. */
|
|
63
|
+
readonly prefer?: Backend;
|
|
64
|
+
/**
|
|
65
|
+
* Called each time a presenter tier is given up for the next one. The
|
|
66
|
+
* game's listeners have already moved to `canvas`.
|
|
67
|
+
*
|
|
68
|
+
* @param from - the tier given up
|
|
69
|
+
* @param to - the tier tried next
|
|
70
|
+
* @param reason - why `from` was given up
|
|
71
|
+
* @param canvas - the canvas `to` presents on
|
|
72
|
+
*/
|
|
73
|
+
onFallback?(from: Backend, to: Backend, reason: string, canvas: HTMLCanvasElement): void;
|
|
74
|
+
/**
|
|
75
|
+
* Called once when the module throws (a panic) in `step` or `draw`, or its
|
|
76
|
+
* frame cannot be presented. The game has already stopped, as `stop()`
|
|
77
|
+
* stops it. Without it the error is thrown from the animation frame.
|
|
78
|
+
*
|
|
79
|
+
* @param error - what was thrown
|
|
80
|
+
*/
|
|
81
|
+
onError?(error: unknown): void;
|
|
82
|
+
/** Aborting it rejects a start still loading with its reason, or stops a running game. */
|
|
83
|
+
readonly signal?: AbortSignal;
|
|
84
|
+
/** The module's generated loader; the `.mjs` beside the `.wasm` is imported when absent. */
|
|
85
|
+
readonly loader?: GameLoader;
|
|
86
|
+
/** The loader's URL, read against the page's base URL, when `loader` is absent and it is not the `.mjs` beside the `.wasm`. */
|
|
87
|
+
readonly loaderUrl?: string | URL;
|
|
88
|
+
/** Imports passed to the loader's `load`, such as `onPanic`. */
|
|
89
|
+
readonly imports?: object;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** A game started by `startGame`. */
|
|
93
|
+
export interface Game {
|
|
94
|
+
/** The presenter drawing the frames; read `presenter.canvas` again after a fallback. */
|
|
95
|
+
readonly presenter: Presenter;
|
|
96
|
+
/** The module's exports, as its loader returned them. */
|
|
97
|
+
readonly module: unknown;
|
|
98
|
+
/** Frames drawn per second over the last half second or so; 0 until one has passed. */
|
|
99
|
+
readonly fps: number;
|
|
100
|
+
/** The display's refresh rate; 0 before the second frame. */
|
|
101
|
+
readonly refreshHz: number;
|
|
102
|
+
/** Whether sounds the game plays are dropped. */
|
|
103
|
+
muted: boolean;
|
|
104
|
+
/** Whether the loop runs: false after `stop()`, an abort, or an error. */
|
|
105
|
+
readonly running: boolean;
|
|
106
|
+
/** Ends the loop, removes the listeners, closes the audio and releases the presenter. */
|
|
107
|
+
stop(): void;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The keys a game reads unless `GameOptions.keys` says otherwise: the arrows, space, Enter and Escape. */
|
|
111
|
+
export declare const DEFAULT_KEYS: readonly string[];
|
|
112
|
+
|
|
113
|
+
/** The touch zones unless `GameOptions.touch` says otherwise: each half of the canvas steers, and a tap is Enter. */
|
|
114
|
+
export declare const DEFAULT_TOUCH: TouchOptions;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Loads a game built over `nish/host/game` and runs it on `canvas`. The
|
|
118
|
+
* module must export `init(seed)`, `step(nowMs)` and `draw(alpha, frameMs)`;
|
|
119
|
+
* `sound(id)` and `resize(width, height)` are optional. `init` runs once;
|
|
120
|
+
* `sound` runs for ids 0, 1, ... until it answers 0; then `step` runs
|
|
121
|
+
* `stepsPerSecond` times a second and `draw` once per display frame.
|
|
122
|
+
*
|
|
123
|
+
* @param canvas - the canvas to draw on; a fallback may replace it, see `presenter.canvas`
|
|
124
|
+
* @param wasmUrl - the module's URL, read against the page's base URL
|
|
125
|
+
* @param options - the seed, the keys and touch zones the game reads, the sound, the tier, the loader
|
|
126
|
+
* @returns the running game; it rejects when an option is malformed, the start is aborted, or the module cannot be fetched or lacks an export or storage it needs
|
|
127
|
+
*/
|
|
128
|
+
export declare function startGame(
|
|
129
|
+
canvas: HTMLCanvasElement,
|
|
130
|
+
wasmUrl: string | URL,
|
|
131
|
+
options?: GameOptions
|
|
132
|
+
): Promise<Game>;
|