@sdeck/react 0.1.0 → 0.3.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/dist/index.js +5 -7
- package/dist/index.js.map +4 -5
- package/dist/render.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/render.ts +6 -4
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
// ../core/src/element.ts
|
|
2
|
-
var runtime;
|
|
3
|
-
function registerElementRuntime(next) {
|
|
4
|
-
runtime = next;
|
|
5
|
-
}
|
|
6
1
|
// src/render.ts
|
|
2
|
+
import {
|
|
3
|
+
registerElementRuntime
|
|
4
|
+
} from "@sdeck/core";
|
|
7
5
|
function isReactElement(value) {
|
|
8
6
|
return typeof value === "object" && value !== null && "$$typeof" in value;
|
|
9
7
|
}
|
|
@@ -171,7 +169,7 @@ function loadReconciler() {
|
|
|
171
169
|
setCurrentUpdatePriority: (next) => {
|
|
172
170
|
priority = next;
|
|
173
171
|
},
|
|
174
|
-
resolveUpdatePriority: () =>
|
|
172
|
+
resolveUpdatePriority: () => flushing > 0 ? constants.DiscreteEventPriority : priority !== constants.NoEventPriority ? priority : constants.DefaultEventPriority,
|
|
175
173
|
resolveEventType: () => null,
|
|
176
174
|
resolveEventTimeStamp: () => -1.1,
|
|
177
175
|
shouldAttemptEagerTransition: () => false,
|
|
@@ -352,4 +350,4 @@ export {
|
|
|
352
350
|
renderReact
|
|
353
351
|
};
|
|
354
352
|
|
|
355
|
-
//# debugId=
|
|
353
|
+
//# debugId=C776FFC11407F3A964756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../src/render.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { Renderable } from \"./index.ts\";\n\nexport interface Size {\n width: number;\n height: number;\n}\n\n/** Decoded pixels: 3 (RGB) or 4 (RGBA) interleaved 8-bit channels. */\nexport interface RawImage {\n data: Uint8Array;\n width: number;\n height: number;\n channels: 3 | 4;\n}\n\nexport const isRawImage = (value: unknown): value is RawImage =>\n typeof value === \"object\" &&\n value !== null &&\n !ArrayBuffer.isView(value) &&\n \"data\" in value &&\n \"width\" in value &&\n \"height\" in value &&\n \"channels\" in value;\n\n/** A font for rendering text in elements (TTF, OTF or WOFF; not WOFF2). */\nexport interface DeckFont {\n name: string;\n data: Uint8Array | ArrayBuffer;\n weight?: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;\n style?: \"normal\" | \"italic\";\n}\n\nexport interface ElementOptions {\n /** Extra fonts for text (a renderer has a built-in fallback font). */\n fonts?: readonly DeckFont[];\n /** Called when rendering or sending a frame fails after the initial render (default: log). */\n onError?: (error: unknown) => void;\n /**\n * Draws everything this many times larger: the element is laid out at the target size divided\n * by `scale` (default 1).\n */\n scale?: number;\n /** Set `false` to draw no text at all, whatever the element holds (default `true`). */\n text?: boolean;\n}\n\n/**\n * A live element tree that redraws its target whenever its state changes. Frames are coalesced:\n * if state changes while one is being sent, only the latest is drawn next.\n */\nexport interface ElementRoot {\n /** Renders `element` (replacing the previous one, keeping state where types match). */\n render(element: Renderable): void;\n /** Resolves once every pending frame has been drawn. */\n idle(): Promise<void>;\n /** Unmounts the tree (running cleanups) and stops drawing. */\n unmount(): Promise<void>;\n}\n\n/** What a renderer package (such as `@sdeck/react`) provides to the core. */\nexport interface ElementRuntime {\n /** True if `value` is an element this runtime can draw. */\n matches(value: unknown): boolean;\n /** Renders `element` once to upright pixels of exactly `size`. */\n render(element: Renderable, size: Size, options?: ElementOptions): Promise<RawImage>;\n /** Mounts a live tree; every change is passed to `onFrame` as upright pixels of `size`. */\n createRoot(\n size: Size,\n onFrame: (frame: RawImage) => void | Promise<void>,\n options?: ElementOptions,\n ): Promise<ElementRoot>;\n}\n\nlet runtime: ElementRuntime | undefined;\n\n/** Registers the renderer used for elements. `@sdeck/react` does this when imported. */\nexport function registerElementRuntime(next: ElementRuntime): void {\n runtime = next;\n}\n\nexport function getElementRuntime(): ElementRuntime {\n if (!runtime) {\n throw new Error(\n \"Drawing elements needs a renderer: install and import `@sdeck/react` (once, anywhere)\",\n );\n }\n return runtime;\n}\n\n/** True for elements the registered renderer can draw (false if none is registered). */\nexport const isRenderable = (value: unknown): value is Renderable =>\n runtime !== undefined && typeof value === \"object\" && value !== null && runtime.matches(value);\n",
|
|
6
|
-
"import {\n type DeckFont,\n type ElementOptions,\n type ElementRoot,\n type RawImage,\n registerElementRuntime,\n type Size,\n} from \"@sdeck/core\";\nimport type { Renderer } from \"@takumi-rs/core\";\nimport type { ReactElement, ReactNode } from \"react\";\n\n/** A font for rendering text in React elements (TTF, OTF or WOFF; not WOFF2). */\nexport type ReactFont = DeckFont;\n\nexport interface ReactRenderOptions extends ElementOptions {}\n\n/**\n * A live React tree that redraws its target whenever state changes. Hooks, effects, context,\n * suspense and timers all work, because this is a real React renderer.\n */\nexport interface ReactRoot extends ElementRoot {\n /** Renders `element` (replacing the previous one, keeping state where types match). */\n render(element: ReactNode): void;\n}\n\ndeclare module \"@sdeck/core\" {\n interface RenderableRegistry {\n react: ReactNode;\n }\n}\n\n/** True for anything created by `React.createElement` / JSX. */\nexport function isReactElement(value: unknown): value is ReactElement {\n return typeof value === \"object\" && value !== null && \"$$typeof\" in value;\n}\n\n// --- Takumi ------------------------------------------------------------------------------------\n\nconst defaultRenderer: { current?: Promise<Renderer> } = {};\nconst fontRenderers = new WeakMap<readonly DeckFont[], Promise<Renderer>>();\n\nasync function createRenderer(fonts: readonly DeckFont[]): Promise<Renderer> {\n const { Renderer } = await import(\"@takumi-rs/core\");\n const renderer = new Renderer();\n for (const font of fonts) {\n await renderer.registerFont({\n name: font.name,\n data: font.data,\n ...(font.weight !== undefined && { weight: font.weight }),\n ...(font.style !== undefined && { style: font.style }),\n });\n }\n return renderer;\n}\n\n/** One Renderer for the built-in font, and one per distinct `fonts` array. */\nfunction getRenderer(fonts: readonly DeckFont[] | undefined): Promise<Renderer> {\n if (!fonts?.length) {\n defaultRenderer.current ??= createRenderer([]);\n defaultRenderer.current.catch(() => {\n defaultRenderer.current = undefined;\n });\n return defaultRenderer.current;\n }\n let renderer = fontRenderers.get(fonts);\n if (!renderer) {\n renderer = createRenderer(fonts);\n renderer.catch(() => fontRenderers.delete(fonts));\n fontRenderers.set(fonts, renderer);\n }\n return renderer;\n}\n\n// --- The renderer: React elements -> a plain host tree -> Takumi nodes. ---------------------------\n\ninterface HostText {\n text: string;\n}\ninterface HostElement {\n type: string;\n props: Record<string, unknown>;\n children: Array<HostElement | HostText>;\n}\ninterface Container {\n children: Array<HostElement | HostText>;\n onCommit: () => void;\n}\n\ntype TakumiNode =\n | { type: \"text\"; text: string; style?: object; tw?: string }\n | { type: \"image\"; src: string; width?: number; height?: number; style?: object; tw?: string }\n | { type: \"container\"; children: TakumiNode[]; style?: object; tw?: string };\n\nconst number = (value: unknown): number | undefined =>\n typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n\n/**\n * Host elements follow HTML names: `<img src width height>` is an image, everything else\n * (`div`, `span`, ...) is a flex container, like in satori. Text and numbers are text nodes.\n * `style` is Takumi's style object (camelCase CSS), and `tw` takes Tailwind classes. Without\n * `text`, text nodes are left out.\n */\nfunction toNode(node: HostElement | HostText, text = true): TakumiNode {\n if (\"text\" in node) {\n return text ? { type: \"text\", text: node.text } : { type: \"container\", children: [] };\n }\n\n const { style, tw, src, width, height } = node.props;\n const common = {\n ...(typeof tw === \"string\" && { tw }),\n };\n if (node.type === \"img\") {\n if (typeof src !== \"string\") throw new Error(\"<img> needs a string `src` (URL or data: URI)\");\n return {\n type: \"image\",\n src,\n ...(number(width) !== undefined && { width: number(width) }),\n ...(number(height) !== undefined && { height: number(height) }),\n ...(typeof style === \"object\" && style !== null && { style }),\n ...common,\n };\n }\n return {\n type: \"container\",\n style: { display: \"flex\", ...(typeof style === \"object\" ? style : {}) },\n children: node.children\n .filter((child) => text || !(\"text\" in child))\n .map((child) => toNode(child, text)),\n ...common,\n };\n}\n\n/** The subset of react-reconciler that we use. */\ninterface Reconciler {\n createContainer(...args: unknown[]): unknown;\n updateContainer(element: ReactNode, root: unknown, parent: null, callback: null): unknown;\n updateContainerSync(element: ReactNode, root: unknown, parent: null, callback: null): unknown;\n flushSyncWork(): boolean;\n flushPassiveEffects(): boolean;\n}\n\nlet reconciler: Promise<Reconciler> | undefined;\n\n/**\n * Above zero while a root flushes its effects. State set by those effects is then rendered at once,\n * rather than in a later task, so a one-shot frame never misses it.\n */\nlet flushing = 0;\n\n/** Flushes the sync commit, then any effects and the renders they cause. */\nfunction flushAll(renderer: Reconciler) {\n flushing++;\n try {\n renderer.flushSyncWork();\n for (let i = 0; i < 20 && renderer.flushPassiveEffects(); i++) renderer.flushSyncWork();\n } finally {\n flushing--;\n }\n}\n\nfunction loadReconciler(): Promise<Reconciler> {\n reconciler ??= (async () => {\n let factoryModule: unknown;\n let constants: typeof import(\"react-reconciler/constants.js\");\n let React: typeof import(\"react\");\n try {\n [factoryModule, constants, React] = await Promise.all([\n import(\"react-reconciler\"),\n import(\"react-reconciler/constants.js\"),\n import(\"react\"),\n ]);\n } catch (cause) {\n throw new Error(\"Rendering React elements requires `react` (>=19.3) to be installed\", {\n cause,\n });\n }\n\n let priority: number = constants.NoEventPriority;\n const noop = () => {};\n const hostConfig = {\n supportsMutation: true,\n supportsPersistence: false,\n supportsHydration: false,\n isPrimaryRenderer: true,\n warnsIfNotActing: false,\n noTimeout: -1,\n scheduleTimeout: setTimeout,\n cancelTimeout: clearTimeout,\n supportsMicrotasks: true,\n scheduleMicrotask: queueMicrotask,\n\n createInstance: (type: string, props: Record<string, unknown>): HostElement => {\n const { children: _children, ...rest } = props;\n return { type, props: rest, children: [] };\n },\n createTextInstance: (text: string): HostText => ({ text }),\n shouldSetTextContent: () => false,\n appendInitialChild: (parent: HostElement, child: HostElement | HostText) =>\n parent.children.push(child),\n appendChild: (parent: HostElement, child: HostElement | HostText) =>\n parent.children.push(child),\n appendChildToContainer: (container: Container, child: HostElement | HostText) =>\n container.children.push(child),\n insertBefore: (parent: HostElement, child: HostElement | HostText, before: HostElement) => {\n const children = parent.children;\n const existing = children.indexOf(child);\n if (existing !== -1) children.splice(existing, 1);\n children.splice(children.indexOf(before), 0, child);\n },\n insertInContainerBefore: (\n container: Container,\n child: HostElement | HostText,\n before: HostElement,\n ) => {\n const children = container.children;\n const existing = children.indexOf(child);\n if (existing !== -1) children.splice(existing, 1);\n children.splice(children.indexOf(before), 0, child);\n },\n removeChild: (parent: HostElement, child: HostElement | HostText) => {\n parent.children.splice(parent.children.indexOf(child), 1);\n },\n removeChildFromContainer: (container: Container, child: HostElement | HostText) => {\n container.children.splice(container.children.indexOf(child), 1);\n },\n clearContainer: (container: Container) => {\n container.children = [];\n },\n commitUpdate: (\n instance: HostElement,\n _type: string,\n _prev: Record<string, unknown>,\n next: Record<string, unknown>,\n ) => {\n const { children: _children, ...rest } = next;\n instance.props = rest;\n },\n commitTextUpdate: (text: HostText, _old: string, next: string) => {\n text.text = next;\n },\n finalizeInitialChildren: () => false,\n getPublicInstance: (instance: unknown) => instance,\n // React requires a non-null host context.\n getRootHostContext: () => ({}),\n getChildHostContext: (parent: object) => parent,\n prepareForCommit: () => null,\n resetAfterCommit: (container: Container) => container.onCommit(),\n preparePortalMount: noop,\n detachDeletedInstance: noop,\n hideInstance: noop,\n unhideInstance: noop,\n hideTextInstance: noop,\n unhideTextInstance: noop,\n getInstanceFromNode: () => null,\n beforeActiveInstanceBlur: noop,\n afterActiveInstanceBlur: noop,\n prepareScopeUpdate: noop,\n getInstanceFromScope: () => null,\n bindToConsole: (method: string, args: unknown[]) =>\n (console as unknown as Record<string, (...a: unknown[]) => void>)[method]?.bind(\n console,\n ...args,\n ) ?? noop,\n extraDevToolsConfig: null,\n rendererVersion: \"0.0.0\",\n rendererPackageName: \"sdeck\",\n\n // React 19 scheduling and transition hooks.\n getCurrentUpdatePriority: () => priority,\n setCurrentUpdatePriority: (next: number) => {\n priority = next;\n },\n resolveUpdatePriority: () =>\n priority !== constants.NoEventPriority\n ? priority\n : flushing > 0\n ? constants.DiscreteEventPriority\n : constants.DefaultEventPriority,\n resolveEventType: () => null,\n resolveEventTimeStamp: () => -1.1,\n shouldAttemptEagerTransition: () => false,\n trackSchedulerEvent: noop,\n requestPostPaintCallback: noop,\n maySuspendCommit: () => false,\n preloadInstance: () => true,\n startSuspendingCommit: noop,\n suspendInstance: noop,\n waitForCommitToBeReady: () => null,\n getSuspendedCommitReason: () => null,\n NotPendingTransition: null,\n HostTransitionContext: React.createContext(null),\n resetFormInstance: noop,\n };\n\n // CommonJS module: the factory is `default` under ESM interop, or the module itself.\n type Factory = (config: never) => Reconciler;\n const factory = (factoryModule as { default?: Factory }).default ?? (factoryModule as Factory);\n return factory(hostConfig as never);\n })();\n reconciler.catch(() => {\n reconciler = undefined;\n });\n return reconciler;\n}\n\nfunction noopIndicator() {}\n\n/**\n * Mounts a live React tree. Every committed change is laid out and rasterised by\n * [Takumi](https://takumi.kane.tw) (flexbox and CSS via `style` / `tw` props) and passed to\n * `onFrame` as upright RGBA pixels of exactly `size`. Frames are coalesced: if state changes while\n * one is being sent, only the latest is drawn next.\n */\nexport async function createReactRoot(\n size: Size,\n onFrame: (frame: RawImage) => void | Promise<void>,\n options: ReactRenderOptions = {},\n): Promise<ReactRoot> {\n const [takumi, renderer] = await Promise.all([getRenderer(options.fonts), loadReconciler()]);\n\n let dirty = false;\n let drawing: Promise<void> | undefined;\n let lastTree: string | undefined;\n let unmounted = false;\n let renderError: { error: unknown } | undefined;\n let initial = true;\n\n const fail = (error: unknown) => {\n if (initial) renderError ??= { error };\n else (options.onError ?? ((e) => console.error(\"sdeck: React render failed:\", e)))(error);\n };\n\n async function draw() {\n // Yield first so `drawing` is assigned before this can finish and clear it.\n await Promise.resolve();\n while (dirty && !unmounted) {\n dirty = false;\n try {\n const [root] = container.children;\n if (!root) continue;\n const tree = toNode(root, options.text !== false);\n const key = JSON.stringify(tree);\n if (key === lastTree) continue; // nothing visible changed\n lastTree = key;\n const pixels = await takumi.render(tree as never, {\n width: size.width,\n height: size.height,\n format: \"raw\",\n ...(options.scale !== undefined && { devicePixelRatio: options.scale }),\n });\n await onFrame({\n data: new Uint8Array(pixels.buffer, pixels.byteOffset, pixels.byteLength),\n width: size.width,\n height: size.height,\n channels: 4,\n });\n } catch (error) {\n lastTree = undefined; // a failed frame was not drawn: draw it again next time\n fail(error);\n }\n }\n drawing = undefined;\n }\n\n const container: Container = {\n children: [],\n onCommit() {\n dirty = true;\n drawing ??= draw();\n },\n };\n\n const onError = (error: unknown) => fail(error);\n // An error caught by an error boundary is handled: the boundary draws its fallback.\n const onCaughtError = () => {};\n const root = renderer.createContainer(\n container,\n 1, // ConcurrentRoot\n null,\n false,\n null,\n \"\",\n onError, // uncaught\n onCaughtError,\n onError, // recoverable\n noopIndicator,\n null,\n );\n\n const flush = () => flushAll(renderer);\n\n const handle: ReactRoot = {\n render(element) {\n if (unmounted) throw new Error(\"This React root was unmounted\");\n renderer.updateContainerSync(element, root, null, null);\n flush();\n },\n async idle() {\n while (drawing) await drawing;\n if (initial && renderError) {\n const { error } = renderError;\n renderError = undefined;\n throw error;\n }\n initial = false;\n },\n async unmount() {\n if (unmounted) return;\n renderer.updateContainerSync(null, root, null, null);\n flush();\n unmounted = true;\n await drawing;\n },\n };\n return handle;\n}\n\n/**\n * Renders a React element once to upright RGBA pixels of exactly `size`. Hooks, context and\n * effects work; effects and the state updates they cause are applied before the frame is taken,\n * but timers are not awaited (use `createReactRoot` or `deck.mountKey` for live updates).\n */\nexport async function renderReact(\n element: ReactNode,\n size: Size,\n fonts?: readonly ReactFont[],\n scale?: number,\n): Promise<RawImage> {\n let frame: RawImage | undefined;\n const root = await createReactRoot(\n size,\n (next) => {\n frame = next;\n },\n { ...(fonts && { fonts }), ...(scale !== undefined && { scale }) },\n );\n try {\n root.render(element);\n await root.idle();\n } finally {\n await root.unmount();\n }\n if (!frame) throw new Error(\"React element rendered nothing\");\n return frame;\n}\n\nregisterElementRuntime({\n matches: isReactElement,\n render: (element, size, options) => renderReact(element, size, options?.fonts),\n createRoot: (size, onFrame, options) => createReactRoot(size, onFrame, options),\n});\n\n/** Where one element ends up when laid out, in the pixels of the target. */\nexport interface MeasuredElement {\n /** The element's `data-measure` prop. */\n id: string;\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\ninterface TakumiMeasurement {\n width: number;\n height: number;\n /** A 2D matrix `[a, b, c, d, e, f]`; `e` and `f` place the node's top left corner. */\n transform: readonly number[];\n children: readonly TakumiMeasurement[];\n}\n\n/**\n * Lays a React element out like {@link renderReact}, without drawing it, and reports where every\n * element with a `data-measure` prop is.\n */\nexport async function measureReact(\n element: ReactNode,\n size: Size,\n fonts?: readonly ReactFont[],\n): Promise<MeasuredElement[]> {\n const [takumi, renderer] = await Promise.all([getRenderer(fonts), loadReconciler()]);\n const container: Container = { children: [], onCommit() {} };\n let failure: { error: unknown } | undefined;\n const fail = (error: unknown) => {\n failure ??= { error };\n };\n const root = renderer.createContainer(\n container,\n 1,\n null,\n false,\n null,\n \"\",\n fail,\n () => {},\n fail,\n noopIndicator,\n null,\n );\n try {\n renderer.updateContainerSync(element, root, null, null);\n flushAll(renderer);\n if (failure) throw failure.error;\n const [host] = container.children;\n if (!host) return [];\n const measured = (await takumi.measure(toNode(host) as never, {\n width: size.width,\n height: size.height,\n })) as TakumiMeasurement;\n const found: MeasuredElement[] = [];\n // The measured tree has the same shape as the host tree.\n const walk = (node: HostElement | HostText, box: TakumiMeasurement | undefined) => {\n if (!box || \"text\" in node) return;\n const id = node.props[\"data-measure\"];\n if (typeof id === \"string\") {\n found.push({\n id,\n x: box.transform[4] ?? 0,\n y: box.transform[5] ?? 0,\n width: box.width,\n height: box.height,\n });\n }\n for (const [i, child] of node.children.entries()) walk(child, box.children[i]);\n };\n walk(host, measured);\n return found;\n } finally {\n renderer.updateContainerSync(null, root, null, null);\n renderer.flushSyncWork();\n }\n}\n"
|
|
5
|
+
"import {\n type DeckFont,\n type ElementOptions,\n type ElementRoot,\n type RawImage,\n registerElementRuntime,\n type Size,\n} from \"@sdeck/core\";\nimport type { Renderer } from \"@takumi-rs/core\";\nimport type { ReactElement, ReactNode } from \"react\";\n\n/** A font for rendering text in React elements (TTF, OTF or WOFF; not WOFF2). */\nexport type ReactFont = DeckFont;\n\nexport interface ReactRenderOptions extends ElementOptions {}\n\n/**\n * A live React tree that redraws its target whenever state changes. Hooks, effects, context,\n * suspense and timers all work, because this is a real React renderer.\n */\nexport interface ReactRoot extends ElementRoot {\n /** Renders `element` (replacing the previous one, keeping state where types match). */\n render(element: ReactNode): void;\n}\n\ndeclare module \"@sdeck/core\" {\n interface RenderableRegistry {\n react: ReactNode;\n }\n}\n\n/** True for anything created by `React.createElement` / JSX. */\nexport function isReactElement(value: unknown): value is ReactElement {\n return typeof value === \"object\" && value !== null && \"$$typeof\" in value;\n}\n\n// --- Takumi ------------------------------------------------------------------------------------\n\nconst defaultRenderer: { current?: Promise<Renderer> } = {};\nconst fontRenderers = new WeakMap<readonly DeckFont[], Promise<Renderer>>();\n\nasync function createRenderer(fonts: readonly DeckFont[]): Promise<Renderer> {\n const { Renderer } = await import(\"@takumi-rs/core\");\n const renderer = new Renderer();\n for (const font of fonts) {\n await renderer.registerFont({\n name: font.name,\n data: font.data,\n ...(font.weight !== undefined && { weight: font.weight }),\n ...(font.style !== undefined && { style: font.style }),\n });\n }\n return renderer;\n}\n\n/** One Renderer for the built-in font, and one per distinct `fonts` array. */\nfunction getRenderer(fonts: readonly DeckFont[] | undefined): Promise<Renderer> {\n if (!fonts?.length) {\n defaultRenderer.current ??= createRenderer([]);\n defaultRenderer.current.catch(() => {\n defaultRenderer.current = undefined;\n });\n return defaultRenderer.current;\n }\n let renderer = fontRenderers.get(fonts);\n if (!renderer) {\n renderer = createRenderer(fonts);\n renderer.catch(() => fontRenderers.delete(fonts));\n fontRenderers.set(fonts, renderer);\n }\n return renderer;\n}\n\n// --- The renderer: React elements -> a plain host tree -> Takumi nodes. ---------------------------\n\ninterface HostText {\n text: string;\n}\ninterface HostElement {\n type: string;\n props: Record<string, unknown>;\n children: Array<HostElement | HostText>;\n}\ninterface Container {\n children: Array<HostElement | HostText>;\n onCommit: () => void;\n}\n\ntype TakumiNode =\n | { type: \"text\"; text: string; style?: object; tw?: string }\n | { type: \"image\"; src: string; width?: number; height?: number; style?: object; tw?: string }\n | { type: \"container\"; children: TakumiNode[]; style?: object; tw?: string };\n\nconst number = (value: unknown): number | undefined =>\n typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n\n/**\n * Host elements follow HTML names: `<img src width height>` is an image, everything else\n * (`div`, `span`, ...) is a flex container, like in satori. Text and numbers are text nodes.\n * `style` is Takumi's style object (camelCase CSS), and `tw` takes Tailwind classes. Without\n * `text`, text nodes are left out.\n */\nfunction toNode(node: HostElement | HostText, text = true): TakumiNode {\n if (\"text\" in node) {\n return text ? { type: \"text\", text: node.text } : { type: \"container\", children: [] };\n }\n\n const { style, tw, src, width, height } = node.props;\n const common = {\n ...(typeof tw === \"string\" && { tw }),\n };\n if (node.type === \"img\") {\n if (typeof src !== \"string\") throw new Error(\"<img> needs a string `src` (URL or data: URI)\");\n return {\n type: \"image\",\n src,\n ...(number(width) !== undefined && { width: number(width) }),\n ...(number(height) !== undefined && { height: number(height) }),\n ...(typeof style === \"object\" && style !== null && { style }),\n ...common,\n };\n }\n return {\n type: \"container\",\n style: { display: \"flex\", ...(typeof style === \"object\" ? style : {}) },\n children: node.children\n .filter((child) => text || !(\"text\" in child))\n .map((child) => toNode(child, text)),\n ...common,\n };\n}\n\n/** The subset of react-reconciler that we use. */\ninterface Reconciler {\n createContainer(...args: unknown[]): unknown;\n updateContainer(element: ReactNode, root: unknown, parent: null, callback: null): unknown;\n updateContainerSync(element: ReactNode, root: unknown, parent: null, callback: null): unknown;\n flushSyncWork(): boolean;\n flushPassiveEffects(): boolean;\n}\n\nlet reconciler: Promise<Reconciler> | undefined;\n\n/**\n * Above zero while a root flushes its effects. State set by those effects is then rendered at once,\n * rather than in a later task, so a one-shot frame never misses it.\n */\nlet flushing = 0;\n\n/** Flushes the sync commit, then any effects and the renders they cause. */\nfunction flushAll(renderer: Reconciler) {\n flushing++;\n try {\n renderer.flushSyncWork();\n for (let i = 0; i < 20 && renderer.flushPassiveEffects(); i++) renderer.flushSyncWork();\n } finally {\n flushing--;\n }\n}\n\nfunction loadReconciler(): Promise<Reconciler> {\n reconciler ??= (async () => {\n let factoryModule: unknown;\n let constants: typeof import(\"react-reconciler/constants.js\");\n let React: typeof import(\"react\");\n try {\n [factoryModule, constants, React] = await Promise.all([\n import(\"react-reconciler\"),\n import(\"react-reconciler/constants.js\"),\n import(\"react\"),\n ]);\n } catch (cause) {\n throw new Error(\"Rendering React elements requires `react` (>=19.3) to be installed\", {\n cause,\n });\n }\n\n let priority: number = constants.NoEventPriority;\n const noop = () => {};\n const hostConfig = {\n supportsMutation: true,\n supportsPersistence: false,\n supportsHydration: false,\n isPrimaryRenderer: true,\n warnsIfNotActing: false,\n noTimeout: -1,\n scheduleTimeout: setTimeout,\n cancelTimeout: clearTimeout,\n supportsMicrotasks: true,\n scheduleMicrotask: queueMicrotask,\n\n createInstance: (type: string, props: Record<string, unknown>): HostElement => {\n const { children: _children, ...rest } = props;\n return { type, props: rest, children: [] };\n },\n createTextInstance: (text: string): HostText => ({ text }),\n shouldSetTextContent: () => false,\n appendInitialChild: (parent: HostElement, child: HostElement | HostText) =>\n parent.children.push(child),\n appendChild: (parent: HostElement, child: HostElement | HostText) =>\n parent.children.push(child),\n appendChildToContainer: (container: Container, child: HostElement | HostText) =>\n container.children.push(child),\n insertBefore: (parent: HostElement, child: HostElement | HostText, before: HostElement) => {\n const children = parent.children;\n const existing = children.indexOf(child);\n if (existing !== -1) children.splice(existing, 1);\n children.splice(children.indexOf(before), 0, child);\n },\n insertInContainerBefore: (\n container: Container,\n child: HostElement | HostText,\n before: HostElement,\n ) => {\n const children = container.children;\n const existing = children.indexOf(child);\n if (existing !== -1) children.splice(existing, 1);\n children.splice(children.indexOf(before), 0, child);\n },\n removeChild: (parent: HostElement, child: HostElement | HostText) => {\n parent.children.splice(parent.children.indexOf(child), 1);\n },\n removeChildFromContainer: (container: Container, child: HostElement | HostText) => {\n container.children.splice(container.children.indexOf(child), 1);\n },\n clearContainer: (container: Container) => {\n container.children = [];\n },\n commitUpdate: (\n instance: HostElement,\n _type: string,\n _prev: Record<string, unknown>,\n next: Record<string, unknown>,\n ) => {\n const { children: _children, ...rest } = next;\n instance.props = rest;\n },\n commitTextUpdate: (text: HostText, _old: string, next: string) => {\n text.text = next;\n },\n finalizeInitialChildren: () => false,\n getPublicInstance: (instance: unknown) => instance,\n // React requires a non-null host context.\n getRootHostContext: () => ({}),\n getChildHostContext: (parent: object) => parent,\n prepareForCommit: () => null,\n resetAfterCommit: (container: Container) => container.onCommit(),\n preparePortalMount: noop,\n detachDeletedInstance: noop,\n hideInstance: noop,\n unhideInstance: noop,\n hideTextInstance: noop,\n unhideTextInstance: noop,\n getInstanceFromNode: () => null,\n beforeActiveInstanceBlur: noop,\n afterActiveInstanceBlur: noop,\n prepareScopeUpdate: noop,\n getInstanceFromScope: () => null,\n bindToConsole: (method: string, args: unknown[]) =>\n (console as unknown as Record<string, (...a: unknown[]) => void>)[method]?.bind(\n console,\n ...args,\n ) ?? noop,\n extraDevToolsConfig: null,\n rendererVersion: \"0.0.0\",\n rendererPackageName: \"sdeck\",\n\n // React 19 scheduling and transition hooks.\n getCurrentUpdatePriority: () => priority,\n setCurrentUpdatePriority: (next: number) => {\n priority = next;\n },\n resolveUpdatePriority: () =>\n // First: React sets its own, lower priority while it runs effects, which would leave the\n // state they set to a later task that may miss the frame.\n flushing > 0\n ? constants.DiscreteEventPriority\n : priority !== constants.NoEventPriority\n ? priority\n : constants.DefaultEventPriority,\n resolveEventType: () => null,\n resolveEventTimeStamp: () => -1.1,\n shouldAttemptEagerTransition: () => false,\n trackSchedulerEvent: noop,\n requestPostPaintCallback: noop,\n maySuspendCommit: () => false,\n preloadInstance: () => true,\n startSuspendingCommit: noop,\n suspendInstance: noop,\n waitForCommitToBeReady: () => null,\n getSuspendedCommitReason: () => null,\n NotPendingTransition: null,\n HostTransitionContext: React.createContext(null),\n resetFormInstance: noop,\n };\n\n // CommonJS module: the factory is `default` under ESM interop, or the module itself.\n type Factory = (config: never) => Reconciler;\n const factory = (factoryModule as { default?: Factory }).default ?? (factoryModule as Factory);\n return factory(hostConfig as never);\n })();\n reconciler.catch(() => {\n reconciler = undefined;\n });\n return reconciler;\n}\n\nfunction noopIndicator() {}\n\n/**\n * Mounts a live React tree. Every committed change is laid out and rasterised by\n * [Takumi](https://takumi.kane.tw) (flexbox and CSS via `style` / `tw` props) and passed to\n * `onFrame` as upright RGBA pixels of exactly `size`. Frames are coalesced: if state changes while\n * one is being sent, only the latest is drawn next.\n */\nexport async function createReactRoot(\n size: Size,\n onFrame: (frame: RawImage) => void | Promise<void>,\n options: ReactRenderOptions = {},\n): Promise<ReactRoot> {\n const [takumi, renderer] = await Promise.all([getRenderer(options.fonts), loadReconciler()]);\n\n let dirty = false;\n let drawing: Promise<void> | undefined;\n let lastTree: string | undefined;\n let unmounted = false;\n let renderError: { error: unknown } | undefined;\n let initial = true;\n\n const fail = (error: unknown) => {\n if (initial) renderError ??= { error };\n else (options.onError ?? ((e) => console.error(\"sdeck: React render failed:\", e)))(error);\n };\n\n async function draw() {\n // Yield first so `drawing` is assigned before this can finish and clear it.\n await Promise.resolve();\n while (dirty && !unmounted) {\n dirty = false;\n try {\n const [root] = container.children;\n if (!root) continue;\n const tree = toNode(root, options.text !== false);\n const key = JSON.stringify(tree);\n if (key === lastTree) continue; // nothing visible changed\n lastTree = key;\n const pixels = await takumi.render(tree as never, {\n width: size.width,\n height: size.height,\n format: \"raw\",\n ...(options.scale !== undefined && { devicePixelRatio: options.scale }),\n });\n await onFrame({\n data: new Uint8Array(pixels.buffer, pixels.byteOffset, pixels.byteLength),\n width: size.width,\n height: size.height,\n channels: 4,\n });\n } catch (error) {\n lastTree = undefined; // a failed frame was not drawn: draw it again next time\n fail(error);\n }\n }\n drawing = undefined;\n }\n\n const container: Container = {\n children: [],\n onCommit() {\n dirty = true;\n drawing ??= draw();\n },\n };\n\n const onError = (error: unknown) => fail(error);\n // An error caught by an error boundary is handled: the boundary draws its fallback.\n const onCaughtError = () => {};\n const root = renderer.createContainer(\n container,\n 1, // ConcurrentRoot\n null,\n false,\n null,\n \"\",\n onError, // uncaught\n onCaughtError,\n onError, // recoverable\n noopIndicator,\n null,\n );\n\n const flush = () => flushAll(renderer);\n\n const handle: ReactRoot = {\n render(element) {\n if (unmounted) throw new Error(\"This React root was unmounted\");\n renderer.updateContainerSync(element, root, null, null);\n flush();\n },\n async idle() {\n while (drawing) await drawing;\n if (initial && renderError) {\n const { error } = renderError;\n renderError = undefined;\n throw error;\n }\n initial = false;\n },\n async unmount() {\n if (unmounted) return;\n renderer.updateContainerSync(null, root, null, null);\n flush();\n unmounted = true;\n await drawing;\n },\n };\n return handle;\n}\n\n/**\n * Renders a React element once to upright RGBA pixels of exactly `size`. Hooks, context and\n * effects work; effects and the state updates they cause are applied before the frame is taken,\n * but timers are not awaited (use `createReactRoot` or `deck.mountKey` for live updates).\n */\nexport async function renderReact(\n element: ReactNode,\n size: Size,\n fonts?: readonly ReactFont[],\n scale?: number,\n): Promise<RawImage> {\n let frame: RawImage | undefined;\n const root = await createReactRoot(\n size,\n (next) => {\n frame = next;\n },\n { ...(fonts && { fonts }), ...(scale !== undefined && { scale }) },\n );\n try {\n root.render(element);\n await root.idle();\n } finally {\n await root.unmount();\n }\n if (!frame) throw new Error(\"React element rendered nothing\");\n return frame;\n}\n\nregisterElementRuntime({\n matches: isReactElement,\n render: (element, size, options) => renderReact(element, size, options?.fonts),\n createRoot: (size, onFrame, options) => createReactRoot(size, onFrame, options),\n});\n\n/** Where one element ends up when laid out, in the pixels of the target. */\nexport interface MeasuredElement {\n /** The element's `data-measure` prop. */\n id: string;\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\ninterface TakumiMeasurement {\n width: number;\n height: number;\n /** A 2D matrix `[a, b, c, d, e, f]`; `e` and `f` place the node's top left corner. */\n transform: readonly number[];\n children: readonly TakumiMeasurement[];\n}\n\n/**\n * Lays a React element out like {@link renderReact}, without drawing it, and reports where every\n * element with a `data-measure` prop is.\n */\nexport async function measureReact(\n element: ReactNode,\n size: Size,\n fonts?: readonly ReactFont[],\n): Promise<MeasuredElement[]> {\n const [takumi, renderer] = await Promise.all([getRenderer(fonts), loadReconciler()]);\n const container: Container = { children: [], onCommit() {} };\n let failure: { error: unknown } | undefined;\n const fail = (error: unknown) => {\n failure ??= { error };\n };\n const root = renderer.createContainer(\n container,\n 1,\n null,\n false,\n null,\n \"\",\n fail,\n () => {},\n fail,\n noopIndicator,\n null,\n );\n try {\n renderer.updateContainerSync(element, root, null, null);\n flushAll(renderer);\n if (failure) throw failure.error;\n const [host] = container.children;\n if (!host) return [];\n const measured = (await takumi.measure(toNode(host) as never, {\n width: size.width,\n height: size.height,\n })) as TakumiMeasurement;\n const found: MeasuredElement[] = [];\n // The measured tree has the same shape as the host tree.\n const walk = (node: HostElement | HostText, box: TakumiMeasurement | undefined) => {\n if (!box || \"text\" in node) return;\n const id = node.props[\"data-measure\"];\n if (typeof id === \"string\") {\n found.push({\n id,\n x: box.transform[4] ?? 0,\n y: box.transform[5] ?? 0,\n width: box.width,\n height: box.height,\n });\n }\n for (const [i, child] of node.children.entries()) walk(child, box.children[i]);\n };\n walk(host, measured);\n return found;\n } finally {\n renderer.updateContainerSync(null, root, null, null);\n renderer.flushSyncWork();\n }\n}\n"
|
|
7
6
|
],
|
|
8
|
-
"mappings": ";
|
|
9
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAAA;AAAA;AAAA;AAgCO,SAAS,cAAc,CAAC,OAAuC;AAAA,EACpE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,cAAc;AAAA;AA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S,gBACpB,WACA,GACA,MACA,OACA,MACA,IACA,MACA,MAAM,IACN,MACA,eACA,IACF;AAAA,EACA,IAAI;AAAA,IACF,SAAS,oBAAoB,SAAS,MAAM,MAAM,IAAI;AAAA,IACtD,SAAS,QAAQ;AAAA,IACjB,IAAI;AAAA,MAAS,MAAM,QAAQ;AAAA,IAC3B,OAAO,QAAQ,UAAU;AAAA,IACzB,IAAI,CAAC;AAAA,MAAM,OAAO,CAAC;AAAA,IACnB,MAAM,WAAY,MAAM,OAAO,QAAQ,OAAO,IAAI,GAAY;AAAA,MAC5D,OAAO,KAAK;AAAA,MACZ,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,IACD,MAAM,QAA2B,CAAC;AAAA,IAElC,MAAM,OAAO,CAAC,MAA8B,QAAuC;AAAA,MACjF,IAAI,CAAC,OAAO,UAAU;AAAA,QAAM;AAAA,MAC5B,MAAM,KAAK,KAAK,MAAM;AAAA,MACtB,IAAI,OAAO,OAAO,UAAU;AAAA,QAC1B,MAAM,KAAK;AAAA,UACT;AAAA,UACA,GAAG,IAAI,UAAU,MAAM;AAAA,UACvB,GAAG,IAAI,UAAU,MAAM;AAAA,UACvB,OAAO,IAAI;AAAA,UACX,QAAQ,IAAI;AAAA,QACd,CAAC;AAAA,MACH;AAAA,MACA,YAAY,GAAG,UAAU,KAAK,SAAS,QAAQ;AAAA,QAAG,KAAK,OAAO,IAAI,SAAS,EAAE;AAAA;AAAA,IAE/E,KAAK,MAAM,QAAQ;AAAA,IACnB,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAS,oBAAoB,MAAM,MAAM,MAAM,IAAI;AAAA,IACnD,SAAS,cAAc;AAAA;AAAA;",
|
|
8
|
+
"debugId": "C776FFC11407F3A964756E2164756E21",
|
|
10
9
|
"names": []
|
|
11
10
|
}
|
package/dist/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"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AAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAmRD;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAClD,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,SAAS,CAAC,CAkGpB;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,SAAS,EAClB,IAAI,EAAE,IAAI,EACV,KAAK,CAAC,EAAE,SAAS,SAAS,EAAE,EAC5B,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,QAAQ,CAAC,CAiBnB;AAQD,4EAA4E;AAC5E,MAAM,WAAW,eAAe;IAC9B,yCAAyC;IACzC,EAAE,EAAE,MAAM,CAAC;IACX,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAUD;;;GAGG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,SAAS,EAClB,IAAI,EAAE,IAAI,EACV,KAAK,CAAC,EAAE,SAAS,SAAS,EAAE,GAC3B,OAAO,CAAC,eAAe,EAAE,CAAC,CAoD5B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdeck/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Draw React components on Stream Deck keys, sensor strips, windows and screens, rendered by Takumi.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"test": "bun test"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@sdeck/core": "0.
|
|
28
|
+
"@sdeck/core": "0.3.0",
|
|
29
29
|
"@takumi-rs/core": "^2.22.1",
|
|
30
30
|
"react-reconciler": "0.34.0"
|
|
31
31
|
},
|
package/src/render.ts
CHANGED
|
@@ -271,10 +271,12 @@ function loadReconciler(): Promise<Reconciler> {
|
|
|
271
271
|
priority = next;
|
|
272
272
|
},
|
|
273
273
|
resolveUpdatePriority: () =>
|
|
274
|
-
priority
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
274
|
+
// First: React sets its own, lower priority while it runs effects, which would leave the
|
|
275
|
+
// state they set to a later task that may miss the frame.
|
|
276
|
+
flushing > 0
|
|
277
|
+
? constants.DiscreteEventPriority
|
|
278
|
+
: priority !== constants.NoEventPriority
|
|
279
|
+
? priority
|
|
278
280
|
: constants.DefaultEventPriority,
|
|
279
281
|
resolveEventType: () => null,
|
|
280
282
|
resolveEventTimeStamp: () => -1.1,
|