@solidrt/core 0.0.17 → 0.0.18

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.
@@ -24,4 +24,10 @@ for the element/prop model see `@solidrt/core/AGENTS.md`.
24
24
 
25
25
  ## Images and GPU
26
26
  - `image.tsx` - `createImage` (async value: fetch + decode + upload) read inside a `<Loading>` boundary and shown with `<texture>`.
27
- - `gpu-shader.tsx` - a GLSL fragment shader rendered to a texture, animated via `setShaderParams`.
27
+ - `gpu-shader.tsx` - a GLSL fragment shader rendered to a texture, animated via `setShaderParams`.
28
+
29
+ ## Vector graphics
30
+ - `svg.tsx` - `<svg src={...}>` draws a whole SVG *document string* (not HTML/JSX children); multi-color fills vs a `currentColor` icon recolored by the `color` prop. This is how to use existing icon libraries (Lucide, Heroicons, etc.) - hand their SVG source to `src`.
31
+
32
+ ## Bundling assets
33
+ - `binary-import.tsx` - `import bytes from "./file" with { type: "binary" }` inlines a file's bytes into the bundle as a `Uint8Array` (combine with `image.tsx` to display an inlined image). `with { type: "text" }` works the same way for a string.
@@ -0,0 +1,26 @@
1
+ // Importing a file with `with { type: "binary" }` inlines its bytes into the
2
+ // bundle as a Uint8Array. The data travels inside the compiled bytecode, so it
3
+ // is available synchronously - no runtime fetch, works offline. Reach for this
4
+ // with small assets you want baked in; for large or many assets prefer a string
5
+ // URL source loaded at runtime instead.
6
+ //
7
+ // This example shows only the binary import itself: it reports the imported
8
+ // file's length and leading bytes. What you do with the bytes afterwards is a
9
+ // separate concern - e.g. hand them to createImage to decode and display an
10
+ // image (see image.tsx), or to decodeImage/createTexture for manual control.
11
+ import { render } from "@solidrt/core"
12
+ import bytes from "./logo.png" with { type: "binary" }
13
+
14
+ // The PNG magic number: 89 50 4e 47 ... - proof the real bytes are inlined.
15
+ let head = Array.from(bytes.slice(0, 8), (b) => b.toString(16).padStart(2, "0")).join(" ")
16
+
17
+ function App() {
18
+ return (
19
+ <window alignItems="center" justifyContent="center" gap={8}>
20
+ <text fontSize={18} color="#e6e6e6">{bytes.length} bytes inlined</text>
21
+ <text color="#888">starts with {head}</text>
22
+ </window>
23
+ )
24
+ }
25
+
26
+ render(() => <App />)
Binary file
@@ -0,0 +1,45 @@
1
+ // <svg> draws a whole SVG *document* passed as a STRING in the `src` prop. This
2
+ // is not HTML: there are no per-element <rect>/<circle>/<path> JSX children to
3
+ // nest. You hand it the SVG source text and usvg parses it (CSS, transforms,
4
+ // defs/use, gradients, clips) into a flat path tree the element renders. So an
5
+ // SVG is a value (a string you import, fetch, or inline), not markup you author
6
+ // inline with JSX.
7
+ //
8
+ // width/height set the drawn box (percentages work too); a multi-color document
9
+ // keeps each shape's own fill, while a monochrome icon using stroke/fill
10
+ // "currentColor" is recolored by the host `color` prop. For per-shape authored
11
+ // or animated vector art, compose <d-path> instead of this document layer.
12
+ //
13
+ // This is how you use an existing icon library (Lucide, Heroicons, Feather,
14
+ // Material, etc.): those ship SVG source, so import/inline the icon string and
15
+ // hand it to `src`. The `currentColor` convention they follow means the `color`
16
+ // prop recolors them, exactly as `currentColor` would in a browser.
17
+ import { render } from "@solidrt/core"
18
+
19
+ // Multi-color document: each shape carries its own fill, no host color needed.
20
+ const HOUSE = `
21
+ <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
22
+ <rect x="20" y="45" width="60" height="45" fill="#457b9d"/>
23
+ <path d="M10 50 L50 15 L90 50 Z" fill="#e63946"/>
24
+ <rect x="42" y="62" width="16" height="28" fill="#f1faee"/>
25
+ <circle cx="50" cy="35" r="6" fill="#ffd166"/>
26
+ </svg>`
27
+
28
+ // Monochrome icon (Lucide arrow-right) drawn with currentColor, recolored below.
29
+ const ARROW = `
30
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
31
+ stroke-linecap="round" stroke-linejoin="round">
32
+ <path d="M5 12h14"/>
33
+ <path d="M12 5l7 7-7 7"/>
34
+ </svg>`
35
+
36
+ function App() {
37
+ return (
38
+ <window justifyContent="center" alignItems="center" flexDirection="row" gap={32}>
39
+ <svg width={120} height={120} src={HOUSE} />
40
+ <svg width={120} height={120} src={ARROW} color="#4f8cff" />
41
+ </window>
42
+ )
43
+ }
44
+
45
+ render(() => <App />)
package/jsx-runtime.d.ts CHANGED
@@ -8,13 +8,14 @@ import type {
8
8
  TextProps,
9
9
  TextureProps,
10
10
  AudioProps,
11
- LayoutProps
11
+ LayoutProps,
12
+ Element as CoreElement,
13
+ ElementChildrenAttribute as CoreElementChildrenAttribute
12
14
  } from "./src/types"
13
- import type { JSX as SolidJSX } from "@solidjs/signals"
14
15
 
15
16
  export namespace JSX {
16
- type Element = SolidJSX.Element
17
- type ElementChildrenAttribute = SolidJSX.ElementChildrenAttribute
17
+ type Element = CoreElement
18
+ type ElementChildrenAttribute = CoreElementChildrenAttribute
18
19
 
19
20
  // Return type is unconstrained: a ref callback's return value is ignored, so
20
21
  // an arrow like `ref={n => (this.node = n)}` (which returns the assignment)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidrt/core",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "license": "MIT",
5
5
  "author": "Antoine van Wel",
6
6
  "type": "module",
package/src/image.ts CHANGED
@@ -56,7 +56,7 @@ export function createImage(src: ImageSource | (() => ImageSource)): () => numbe
56
56
  // If the source changed while we were loading, this run is superseded. Skip
57
57
  // the GPU upload and stay pending: a texture created here would leak, since
58
58
  // superseded async runs are not otherwise cleaned up. The newer run wins.
59
- if (mine !== generation) throw new NotReadyError()
59
+ if (mine !== generation) throw new NotReadyError(source)
60
60
 
61
61
  let { data, width, height } = decodeImage(bytes)
62
62
  holder.id = createTexture(data, width, height)
@@ -0,0 +1,52 @@
1
+ // Lattice runner builtin modules (the "srt:*" surface). These are ambient
2
+ // module declarations, so they live in this global-script .d.ts (no top-level
3
+ // import/export) rather than in types.d.ts: an ambient `declare module` only
4
+ // becomes globally visible to consumers from a non-module declaration file.
5
+
6
+ declare module "*.svg" {
7
+ const content: string
8
+ export default content
9
+ }
10
+
11
+ // Binary asset imports: `import data from "./pic.png" with { type: "binary" }`.
12
+ // The bundler inlines the file's bytes as a Uint8Array (see packages/cli
13
+ // bundler `binaryImport`); feed it straight into createImage/decodeImage.
14
+ declare module "*.png" {
15
+ const bytes: Uint8Array
16
+ export default bytes
17
+ }
18
+ declare module "*.jpg" {
19
+ const bytes: Uint8Array
20
+ export default bytes
21
+ }
22
+ declare module "*.jpeg" {
23
+ const bytes: Uint8Array
24
+ export default bytes
25
+ }
26
+
27
+ // UI event bus (lattice), provided by the runtime as a builtin module.
28
+ // on/once return an unsubscribe function.
29
+ declare module "srt:events" {
30
+ export function on(event: string, callback: (data: any) => void): () => void
31
+ export function once(event: string, callback: (data: any) => void): () => void
32
+ }
33
+
34
+ // Dev-server control surface (lattice). Present only in dev/go builds; in other
35
+ // builds `available` is false and the functions are no-ops.
36
+ declare module "srt:dev" {
37
+ export const available: boolean
38
+ export const canDiscover: boolean
39
+ export const recents: string[]
40
+ export function connect(address: string): void
41
+ export function discover(): void
42
+ export function stop(): void
43
+ }
44
+
45
+ // Frame draw (lattice runner). renderFrame() synchronously renders the current
46
+ // frame: layout, the postLayout hook, paint and hover refresh, then builds and
47
+ // submits the display list. To schedule a future frame instead, use
48
+ // requestFrame() from "flux:rendertree". The tree-building surface itself is
49
+ // "flux:rendertree" (from @solidrt/flux-types).
50
+ declare module "srt:render" {
51
+ export function renderFrame(): void
52
+ }
package/src/types.d.ts CHANGED
@@ -1,34 +1,12 @@
1
1
  /// <reference types="@solidrt/flux-types" />
2
+ /// <reference path="./runtime-modules.d.ts" />
2
3
 
3
- import type { JSX as SolidJSX } from "@solidjs/signals"
4
4
  import type { Gradient } from "./color"
5
+ import type { Element } from "solid-js"
5
6
 
6
- // UI event bus (lattice), provided by the runtime as a builtin module.
7
- // on/once return an unsubscribe function.
8
- declare module "srt:events" {
9
- export function on(event: string, callback: (data: any) => void): () => void
10
- export function once(event: string, callback: (data: any) => void): () => void
11
- }
12
-
13
- // Dev-server control surface (lattice). Present only in dev/go builds; in other
14
- // builds `available` is false and the functions are no-ops.
15
- declare module "srt:dev" {
16
- export const available: boolean
17
- export const canDiscover: boolean
18
- export const recents: string[]
19
- export function connect(address: string): void
20
- export function discover(): void
21
- export function stop(): void
22
- }
23
-
24
- // Frame draw (lattice runner). renderFrame() synchronously renders the current
25
- // frame: layout, the postLayout hook, paint and hover refresh, then builds and
26
- // submits the display list. To schedule a future frame instead, use
27
- // requestFrame() from "flux:rendertree". The tree-building surface itself is
28
- // "flux:rendertree" (from @solidrt/flux-types).
29
- declare module "srt:render" {
30
- export function renderFrame(): void
31
- }
7
+ // The "srt:*" lattice runner modules are declared in ./runtime-modules.d.ts
8
+ // (referenced above) - ambient `declare module` only reaches consumers from a
9
+ // non-module declaration file, and this file is a module.
32
10
 
33
11
  declare global {
34
12
  let image: {
@@ -48,7 +26,16 @@ declare global {
48
26
  }
49
27
  }
50
28
 
51
- type Children = SolidJSX.Element
29
+ // JSX value model. The element type is solid-js's (its control-flow components
30
+ // like <For> return it, so JSX.Element must match). @solidjs/signals ships no
31
+ // JSX namespace and solid-js defines no ElementChildrenAttribute, so we supply
32
+ // that here - its single key tells TS which prop receives JSX children.
33
+ export type { Element }
34
+ export interface ElementChildrenAttribute {
35
+ children: {}
36
+ }
37
+
38
+ type Children = Element
52
39
 
53
40
  interface FlexboxProps {
54
41
  gap?: number