@sandom/glint
v0.1.0
Published
The Glint implementation: the Glint server, client, clip recorder and clip player on Sandom, with the Glint core.
Readme
@sandom/glint
The Glint implementation on Sandom's renderer: the Glint server, client,
clip recorder and clip player, and the Glint core. Glint sends the paint of
a document as frames, and a clip keeps them in a file. The specification of
Glint and of its clips is at glint.sandom.dev.
License
This package is under the GNU Affero General Public License, version 3 or
any later version (LICENSE, NOTICE). DevBlanket AB also offers it under
commercial license terms. The contribution terms are in CONTRIBUTING.md.
Install
Install the package beside the npm package sandom. The peer dependency of
this package names one exact version of sandom: the Glint core holds the
renderer core of that version, and the modules of sandom call its exports.
npm install @sandom/glint sandom@<the version of the peer dependency>The renderer core
The Glint core is Sandom's renderer core with the Glint parts. Sandom must load the Glint core in place of its own core.
- Deno, Node and Bun: import
@sandom/glint/install-corebefore any module ofsandom. Sandom compiles its core once in a process; when a module ofsandomloads first, the import fails and tells you so. - A page: the import map maps
sandom/renderer-core.wasmto the file of@sandom/glint/glint-core.wasm. A page that only plays clips with the WebGPU backend can map@sandom/glint/player-core.wasm, the Glint core reduced to the exports that the clip player calls.
Record and play a still
import "@sandom/glint/install-core";
import { createSandomDOM } from "sandom/dom";
import { sharedDomCore } from "sandom/dom-wasm/core";
import { createRemoteRasterClipRecorder } from "@sandom/glint/raster-clip";
import { openGlintClip } from "@sandom/glint/raster-clip-player";
const dom = createSandomDOM({ viewportW: 320, viewportH: 200 });
const root = dom.createElement("main");
root.style.background = "rgb(32, 96, 160)";
const recorder = createRemoteRasterClipRecorder({ core: sharedDomCore });
const surface = dom.createRenderSurface(root, {
viewportWidth: 320,
viewportHeight: 200,
now: () => 0,
requestFrame: () => 1,
cancelFrame: () => {},
graphicsBackend: "plan",
onRasterPlan: recorder.onRasterPlan,
});
const still = await recorder.still(surface);
await surface.shutdown();
const player = await openGlintClip(still, {
readback: "float32",
onFrame: (result) => console.log(result.width, result.height),
requestFrame: () => 0,
cancelFrame: () => {},
});
await player.settled();
await player.close();Entries
| Entry | Content |
| --- | --- |
| @sandom/glint/install-core | Makes the Glint core the renderer core of a Deno, Node or Bun process. |
| @sandom/glint/raster-clip | createRemoteRasterClipRecorder, openRemoteRasterClip, clipSegments and clipParts. |
| @sandom/glint/raster-clip-player | openGlintClip, the clip player. |
| @sandom/glint/raster-stream-server | The Glint server of a render surface. |
| @sandom/glint/raster-stream-client | The Glint client, which draws the frames of a server. |
| @sandom/glint/raster-stream-error | RemoteRasterError, the error of the Glint core. |
| @sandom/glint/raster-records | The input and document state records. |
| @sandom/glint/raster-webtransport | A Glint connection over WebTransport. |
| @sandom/glint/glint-page | A document presented to Glint clients. |
| @sandom/glint/glint-core.wasm | The Glint core. |
| @sandom/glint/player-core.wasm | The Glint core reduced to the exports of the clip player. |
| @sandom/glint/reduce-core | reduceGlintCore: the Glint core reduced to the modules of a page. |
Clip parts
clipParts(core, clip) divides a clip of codec none into
[{ prefix, payload }]. Each payload is the bytes of one font file or one
image. The prefixes and payloads in order are the clip, and one resource
gives equal payload bytes in every clip. A store can thus keep each payload
once, with its SHA-256 as its key. A clip of another codec has no parts:
clipParts throws.
Reduce the core for a page
reduceGlintCore({ binaryen, coreBytes, moduleSources }) keeps the exports
that the modules of a page name. binaryen is your instance of the npm
package binaryen (version 123 or later). coreBytes are the bytes of
GLINT_CORE_URL. moduleSources are the texts of the modules of the page,
of sandom and of this package. The page's import map then maps
sandom/renderer-core.wasm to the reduced core.
import binaryen from "binaryen";
import { readFile } from "node:fs/promises";
import { GLINT_CORE_URL, reduceGlintCore } from "@sandom/glint/reduce-core";
const { bytes } = reduceGlintCore({ binaryen, coreBytes: await readFile(GLINT_CORE_URL), moduleSources });