@amritk/nish-aarch64-linux 0.39.0 → 0.41.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.
Files changed (57) hide show
  1. package/INSTALL.md +79 -133
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +112 -33
  4. package/package.json +1 -1
  5. package/runtime/nish.d.ts +21 -17
  6. package/runtime/nish.h +10 -0
  7. package/runtime/page-frame.d.ts +123 -0
  8. package/runtime/page-frame.mjs +736 -0
  9. package/runtime/page-game.d.ts +132 -0
  10. package/runtime/page-game.mjs +738 -0
  11. package/runtime/runtime-aes.c +85 -8
  12. package/runtime/runtime-bytes.c +88 -4
  13. package/runtime/runtime-net.c +32 -0
  14. package/runtime/runtime-sandbox.c +55 -28
  15. package/runtime/runtime-uring.c +1194 -0
  16. package/runtime/runtime-wasm.c +422 -0
  17. package/runtime/vite.mjs +1 -1
  18. package/scripts/build.sh +22 -6
  19. package/std/README.md +74 -87
  20. package/std/array.ts +36 -3
  21. package/std/collections.ts +51 -0
  22. package/std/crypto/hmac.ts +37 -10
  23. package/std/crypto/p256.ts +1388 -2664
  24. package/std/crypto/pki.ts +116 -4
  25. package/std/crypto/sha256.ts +34 -6
  26. package/std/crypto/x509.ts +7 -0
  27. package/std/host/game.ts +273 -0
  28. package/std/input.ts +56 -0
  29. package/std/json-tokenizer.ts +325 -112
  30. package/std/json-typed.ts +43 -8
  31. package/std/json-value.ts +144 -3
  32. package/std/json.ts +63 -8
  33. package/std/net/fetch.ts +22 -4
  34. package/std/net/http-server.ts +3382 -0
  35. package/std/net/http1-client-codec.ts +6 -2
  36. package/std/net/http1-codec.ts +137 -12
  37. package/std/net/http1-server.ts +83 -29
  38. package/std/net/http2.ts +47 -14
  39. package/std/net/http3-server.ts +29 -3
  40. package/std/net/http3.ts +180 -7
  41. package/std/net/prefork.ts +49 -13
  42. package/std/net/quic-recovery.ts +240 -9
  43. package/std/net/quic-stream.ts +21 -1
  44. package/std/net/quic.ts +98 -4
  45. package/std/net/router.ts +378 -31
  46. package/std/net/serve.ts +873 -65
  47. package/std/net/tls/verify.ts +19 -1
  48. package/std/net/url.ts +83 -35
  49. package/std/net/websocket.ts +74 -1
  50. package/std/net/webtransport.ts +7 -1
  51. package/std/raster.ts +837 -0
  52. package/std/release.ts +593 -0
  53. package/std/synth.ts +143 -0
  54. package/std/temporal.ts +3091 -0
  55. package/std/threads.ts +298 -0
  56. package/std/yaml-json.ts +368 -28
  57. 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>;