A JSON Canvas (.canvas) renderer with three layers on one document model:
src/core/: spec-pure JSON Canvas (parser, serialiser, spatial index, state, colour presets). No React, no rendering, and no community conventions such as cssclasses or callouts.src/renderer/: the React Native renderer (Skia + Reanimated) for iOS, Android and macOS, consumed from the package root.src/gtk/: the GTK4 / libadwaita renderer (Cairo, through GTKX) for Linux, consumed as./gtk.src/menu/: a card's long-press menu on Android (Material 3's dropdown, from@expo/ui's Compose components), consumed as./menu. It's its own entry point so the package root never imports@expo/ui, an optional peer: nothing undersrc/renderer/orsrc/index.tsmay import fromsrc/menu/.
Workspace consumes all three. Issue numbers written workspace#N are in workspace-sh/workspace.
npm test # jest: src/**/__tests__
npm run typecheck # tsc --noEmit (leaves src/gtk out)
npm run lint # eslint srcNothing here can typecheck or test src/gtk: GTKX generates its bindings (@gtkx/gi/*, @gtkx/jsx/*) inside the consuming app. Workspace's Linux client (apps/linux) does both: yarn workspace linux run check, plus scripts/headless-shot.sh (with SCHEME=dark for the other scheme) for a picture. A change to src/gtk isn't verified until that has run.
src/gtk/package.jsondeclares"type": "module", because GTKX is ESM-only and the rest of this package is CommonJS-mode TypeScript. So relative imports there carry.jsextensions.- GTKX elements come from
@gtkx/jsx/<namespace>, and classes and enums from@gtkx/gi/<namespace>. Signal callbacks omitselfunless they need it. Never infer a prop from C, PyGObject or GJS; the consuming app's.gtkx/reference/index.mdis the authority. - Anything Cairo paints must be told the colour scheme.
CanvasViewtakescolorSchemeand otherwise followsAdw.StyleManagerlive (useCanvasColorScheme). Keep that fallback: a libadwaita app gets a matching canvas with no wiring. - Icon names must exist in the Adwaita icon theme.
@gtkx/reactand@gtkx/cairoare optional peers, so React Native installs don't fetch them. A consumer that links a checkout of this repo must point its peers at its own copies: Viteresolve.dedupe(React and@gtkx/*) and matching tsconfigpaths. Without them it gets this checkout's React (hooks fail) and no GTKX at all.- It draws less than Skia: no markdown in text nodes, images, Canvas Candy, minimap, edge labels or end styles yet. The README says so; keep that list current.
extensions/cssclasses.tsandextensions/callouts.tsenrich nodes with rendering properties. They are lazy:hasCssClasses()andhasCallouts()check first, so a standard canvas pays nothing.- Enrichment runs once, through
useMemoinSkiaCanvasLayer, producing theEnrichedNode[]every renderer consumes.
Every rendering change goes into BOTH:
- The live Skia tree: the declarative components in
SkiaCanvasLayer.tsxand the node renderers. - The imperative Picture recording:
drawCard,drawTextNodeand the rest inuseCanvasPicture.ts.
If they diverge, the Picture overlay shows something different from the live tree.
- During a pinch, a pre-recorded
SkPictureoverlays the live tree via<Group opacity={pictureOpacity}>. isPinchingis a shared value set directly in the pinch worklet: norunOnJS, no React reconciliation.- SVG file images render ABOVE the Picture overlay, for vector fidelity at any zoom.
- The live tree is always mounted, so hooks like
useImagestay alive. Never unmount it to switch modes. - Image loading is separate from recording: two separate effects in
useCanvasPicture.
- The gesture system is stable. Don't touch pan, pinch or scroll-wheel handling without explicit approval.
- Pan has
.maxPointers(1), so it only starts with one finger. It is direct manipulation on every platform. - Pinch
onStartcallscancelAnimationon translateX, translateY and scale before capturing its baseline. - Pinch
onUpdatehas three guards: the pointer count (fewer than 2 freezes translation), a 30px per-frame focal cap (PINCH_FOCAL_DELTA_CAP), and a 10px drift deadzone (PINCH_DRIFT_DEADZONE). - Pinch
onEndtreats a scale change under 2% as a no-op (PINCH_NOOP_THRESHOLD) and restores the pre-pinch state. - Inertial panning (
withDecay) is not used on macOS: click-and-drag there has no momentum. - On macOS, trackpad pan and Smart Zoom come from the
WorkspaceJsonCanvasGestureSwift module. A consumer's ownScrollWheelBridgeis preferred when present.
- Resolve relative asset paths with
utils/resolveFileUri.ts(resolveFileUri(file, basePath)). Both rendering paths, the liveSkiaImageRendereranduseCanvasPicture's raster cache, must call it, so the resolved URIs match exactly. basePathis passed all the way down: app →CanvasView→SkiaCanvasLayer→ renderers anduseCanvasPicture. Renderers that touch file content take it as a prop.- SVGs go through
utils/useValidatedSvg.ts, neveruseSVGfrom@shopify/react-native-skiadirectly. The hook fetches the text, checks the<svg>root, strips DOCTYPE entities and the document'swidth/height, then builds the SVG withSkia.SVG.MakeFromString. A failed load shows the "broken image" placeholder fromassets/brokenImageSvg.ts. - Never call
svg.width()/svg.height()on a Skia SVG. They segfault when the underlyingSkSVGDOMis null, which happens silently when parsing fails (workspace#122). Pass viewBox-derived dimensions to<ImageSVG>as explicitwidthandheight.
- Text-node markdown goes through
unified+remark-parse+remark-gfm+remark-frontmatter(markdown/parseToSegments.ts). HTML inside markdown goes throughhast-util-from-html, cssclasses frontmatter throughjs-yaml, and callouts come from walking remark blockquote nodes (extensions/callouts.ts). - One preprocessing step on the source string remains:
normaliseEmphasis, for Obsidian's newline-trailing-marker quirk (workspace#131). - Inline content walks
PhrasingContent[], and block content walksContent[]. A new node type has to be handled in bothwalkInlineandwalkTree. - A host can't inject a markdown component: a native view can't be drawn into the Skia canvas, which is why the old
renderMarkdownprop was removed. #88 tracks drawing markdown as well as a document does. - The README's "Markdown in text nodes" section lists what draws and what is dropped. Keep it current when
parseToSegments.tschanges.
<Group clip>and<Group transform>don't apply to children when the Group is inside an element array (workspace#96). They do work at a component's top-level return. Label-only nodes use an early return as a workaround; labels on mixed-zone cards still fall back to horizontal.canvas.drawSvg()doesn't record into Picture command buffers, so SVGs are left out of the recording and render live above the Picture overlay during a pinch.- Some valid SVGs (
<text>,<foreignObject>, some filter combinations) parse without error but render empty, because Skia's SVG renderer is incomplete compared with a browser's (workspace#124). There's no reliable way to detect them from their content.
CanvasViewexposesfitToViewportandrecenterthrough itsonReadycallback.- Never remount the Skia Canvas on macOS: repeated unmount/mount cycles corrupt the Metal GPU context.