@weasel-js/renderer 0.0.0-stage → 1.10.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 orochi235
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,62 @@
1
- # Temporary Holding Version
1
+ # @weasel-js/renderer
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A WebGL2 renderer that turns a list of draw commands into pixels.
4
+
5
+ Part of [weasel](https://github.com/orochi235/weasel), a domain-agnostic 2D
6
+ scene-graph canvas kit for React. See the
7
+ [API reference](https://orochi235.github.io/weasel/api/).
8
+
9
+ ```sh
10
+ npm install @weasel-js/renderer
11
+ ```
12
+
13
+ It knows nothing about a scene graph and has no React in it. `@weasel-js/core`
14
+ builds draw commands from scene nodes and hands them here; anything else that
15
+ can build a `DrawCommand[]` can do the same.
16
+
17
+ ## Drawing
18
+
19
+ ```ts
20
+ import { WeaselRenderer, type DrawCommand } from '@weasel-js/renderer';
21
+
22
+ const renderer = new WeaselRenderer({ canvas, width: 800, height: 600, dpr: devicePixelRatio });
23
+ renderer.render(commands);
24
+ ```
25
+
26
+ A `DrawCommand` is a path, a group, text, an image, a run of sprites, or a
27
+ shader quad. Paths carry a fill and a stroke from `@weasel-js/paint`; a group
28
+ carries a transform, a clip, a color matrix, and effects. Neighboring commands
29
+ that can share a draw call are merged into one.
30
+
31
+ `cullDrawCommands` drops the commands that cannot reach a screen rectangle.
32
+
33
+ ## Paint
34
+
35
+ - `commandPaint` and `commandStroke` resolve a `Paint` or `Stroke` against a
36
+ pose box into what a command carries.
37
+ - `createTilePattern` builds a repeating tile; `resolvePatternSpec` builds one
38
+ from a serializable `TilePatternSpec`. The named tiles (`hatch`, `crosshatch`,
39
+ `dots`, `chunks`) are under `@weasel-js/renderer/patterns-builtin`.
40
+ - `registerPaintDrawKind` adds a fill kind the renderer can bind: its shader
41
+ programs and how its geometry moves between a pose frame and a bounds frame.
42
+ The mesh gradient is one, under `@weasel-js/renderer/mesh`.
43
+
44
+ ## Shaders and effects
45
+
46
+ `registerProgram` registers a fragment shader a `kind: 'shader'` command draws
47
+ with, and `registerTexture` a texture it can sample. `registerEffect` adds a
48
+ full-screen pass a group names in `effects`; `blur` and `vignette` are built in.
49
+
50
+ ## Text and images
51
+
52
+ `textCommand`, `textCommandFromRuns`, and `textCommandFromPose` build a text
53
+ command from laid-out runs. Fonts are registered through `@weasel-js/font`,
54
+ which this package re-exports.
55
+
56
+ `getImageBitmap` decodes and caches an image by its `src`, and
57
+ `subscribeImageReady` reports when one a frame asked for has arrived.
58
+
59
+ ## Testing
60
+
61
+ `@weasel-js/renderer/testing/glRecorder` is a WebGL2 stand-in that records
62
+ every call, for asserting what a frame drew without a GPU.
@@ -0,0 +1,11 @@
1
+ import { rasterizeTile, registerTexture } from './chunk-Q4SIHV7Q.js';
2
+
3
+ // src/patterns/index.ts
4
+ function createTilePattern(opts) {
5
+ const bitmap = rasterizeTile(opts);
6
+ return bitmap ? registerTexture(bitmap) : null;
7
+ }
8
+
9
+ export { createTilePattern };
10
+ //# sourceMappingURL=chunk-43YL7HZV.js.map
11
+ //# sourceMappingURL=chunk-43YL7HZV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/patterns/index.ts"],"names":[],"mappings":";;;AA2BO,SAAS,kBAAkB,IAAA,EAA6C;AAC7E,EAAA,MAAM,MAAA,GAAS,cAAc,IAAI,CAAA;AACjC,EAAA,OAAO,MAAA,GAAS,eAAA,CAAgB,MAAM,CAAA,GAAI,IAAA;AAC5C","file":"chunk-43YL7HZV.js","sourcesContent":["/**\n * Tile-pattern primitive — a small helper for building repeating texture\n * tiles from a draw callback. The result plugs into a `Paint` of\n * `{ kind: 'texture', texture }` (see `@weasel-js/paint`).\n *\n * For ready-to-use named patterns (hatch, crosshatch, dots, chunks),\n * see the `@weasel-js/renderer/patterns-builtin` subpath.\n */\n\nimport { registerTexture } from '../textures/registerTexture';\nimport type { TextureHandle } from '../textures/registerTexture';\nimport { rasterizeTile } from './rasterizeTile';\n\n/** Options for `createTilePattern`. */\nexport interface TilePatternOpts {\n /** Edge length (in pixels) of the square offscreen tile. */\n size: number;\n /** Paint one tile at integer-pixel coordinates `(0, 0) .. (size, size)`. */\n draw: (oc: CanvasRenderingContext2D, size: number) => void;\n}\n\n/**\n * Render a single tile and register it as a GL texture, returning a\n * `TextureHandle` you can wrap in a `Paint` of\n * `{ kind: 'texture', texture }`. Returns `null` only when an\n * `OffscreenCanvas`/2D context can't be acquired.\n */\nexport function createTilePattern(opts: TilePatternOpts): TextureHandle | null {\n const bitmap = rasterizeTile(opts);\n return bitmap ? registerTexture(bitmap) : null;\n}\n"]}