/** * `NodeGraph/GraphNode` — the node alone, off canvas (design §12.1). * * Off canvas still means inside a `ReactFlowProvider`: `useUpdateNodeInternals` * reads the React Flow store, and a node that cannot report a port change is * not the node that ships. The provider is the whole canvas this story needs. * * `FontProof` is task 2.5: design 6.3's corrupted-first-family control, live. */ import { Preset, Surface, fontCategoryStacks } from "@multiplatform.one/theme"; import type { Meta, StoryObj } from "@storybook/react-native-web-vite"; import { type ReactNode, useEffect, useRef, useState } from "react"; import { SizableText as TamaguiSizableText, Theme, XStack, YStack } from "tamagui"; import { hasDomRealm } from "../native/DomOnlyStory"; import { ReactFlowProvider } from "../react-flow/xy"; import { GraphFaces } from "../theme/GraphFaces"; import type { GraphFaceStatus } from "../theme/GraphFaces"; import { corruptFirstFamily, probeRenderedFamily } from "../theme/faces"; import type { FaceProbe } from "../theme/faces"; import { GraphNode } from "./GraphNode"; import type { GraphNodePort } from "./nodeMeasure"; import { SizableText } from "@multiplatform.one/components"; const oneIn: GraphNodePort[] = [{ id: "in", side: "left", direction: "in", label: "source" }]; const inOut: GraphNodePort[] = [ { id: "in", side: "left", direction: "in", label: "records" }, { id: "out", side: "right", direction: "out", label: "result" }, ]; const fourPorts: GraphNodePort[] = [ { id: "rows", side: "left", direction: "in", label: "rows" }, { id: "schema", side: "left", direction: "in", label: "schema" }, { id: "ok", side: "right", direction: "out", label: "ok" }, { id: "err", side: "right", direction: "out", label: "error" }, ]; const meta: Meta = { title: "NodeGraph/GraphNode", component: GraphNode, parameters: { status: { type: "beta" }, docs: { description: { component: "The Tamagui node body, resolved through the real useResolvedKnobs stack (Preset / Surface / Intent). Width rides the per-kind measure table rather than the control-height ladder; radius is CONTAINER-CAP so a corner never clips a child; the frame is never overflow:hidden, because handles overhang it. This is where the knob fuzz for MPO-191 runs.", }, }, }, argTypes: { title: { control: "text" }, subtitle: { control: "text" }, intent: { control: "select", options: [undefined, "accent", "error", "warning", "success"] }, selected: { control: "boolean" }, dragging: { control: "boolean" }, coarsePointer: { control: "boolean", description: "Touch surface — widens the port pitch to 44", }, renderMode: { control: "inline-radio", options: ["detail", "overview"] }, }, decorators: [ (Story) => ( ), ], }; export default meta; type Story = StoryObj; export const Main: Story = { args: { id: "transform", title: "Transform", subtitle: "Maps each row through the mapping expression", ports: inOut, }, }; export const Intents: Story = { render: () => ( {[undefined, "accent", "error", "warning", "success"].map((intent) => ( {intent ?? "no intent"} ))} ), }; export const Ports: Story = { render: () => ( {( [ ["none", []], ["one in", oneIn], ["in and out", inOut], ["four, two a side", fourPorts], ] as const ).map(([label, ports]) => ( {label} ))} ), }; /** * §7.1 H6 made visible. The magenta marker is positioned to overhang the * frame the way a port's painted disc and its 44pt `::after` region will. If * the frame ever becomes `overflow: hidden`, half of it disappears here before * any spec runs. */ export const Overflow: Story = { render: () => ( {(["small", "medium", "large", "full"] as const).map((borderRadius) => ( borderRadius: {borderRadius} ))} ), }; /** * Seed `MPO-191-graphnode`, 3 combos, both schemes — the exact combos * `node scripts/knob-fuzz.mjs MPO-191-graphnode 3` prints, so the verdicts * posted on MPO-191 and this page are the same subject. */ const fuzzCombos = [ { label: "combo 1", knobs: { fillStyle: "filled", borderRadius: "medium", borderWidth: "none", elevation: "none", textAccent: "medium", headingFont: "geometric", bodyFont: "sans-serif", fontWeight: "bold", animation: "slow", }, }, { label: "combo 2", knobs: { fillStyle: "filled", borderRadius: "none", borderWidth: "none", elevation: "small", textAccent: "medium", headingFont: "rounded", bodyFont: "cursive", fontWeight: "regular", animation: "none", }, }, { label: "combo 3", knobs: { fillStyle: "filled", borderRadius: "full", borderWidth: "small", elevation: "large", textAccent: "high", headingFont: "mono", bodyFont: "serif", fontWeight: "bold", animation: "bouncy", }, }, ] as const; function FuzzColumn({ scheme, children }: { scheme: "light" | "dark"; children: ReactNode }) { return ( {scheme} {children} ); } export const KnobFuzz: Story = { parameters: { docs: { description: { story: "Seed MPO-191-graphnode, 3 combos, light and dark. Measure the GraphNode FRAME against knob-laws.md § Radius › GraphNode frame (CONTAINER-CAP), § Size › GraphNode frame (remap to the measure table) and § Elevation › GraphNode frame (declared honour). Measuring an inset against the frame's row is the false FAIL the procedure warns about.", }, }, }, render: () => ( {(["light", "dark"] as const).map((scheme) => ( {fuzzCombos.map((combo) => ( {combo.label} ))} ))} ), }; // ── FontProof (task 2.5) ───────────────────────────────────────────────────── /** * One probe row: what was measured, and whether the first family painted. * * Rendered as text on purpose. This story is read off a SCREENSHOT — on the * iOS simulator and an Android emulator at tasks 2.7 and 2.8, where there is no * console to open — so every number the control produces has to be legible in * the picture. */ function ProbeRow({ label, probe }: { label: string; probe: FaceProbe | null }) { if (!probe) { return ( {label}: measuring… ); } const verdict = !probe.conclusive ? "INCONCLUSIVE" : probe.matched ? "MATCHED — first family painted" : "MISS — first family never painted"; return ( {label}: {verdict} stack {probe.widthStack.toFixed(2)}px · first-corrupted{" "} {probe.widthFirstCorrupted.toFixed(2)}px {probe.stack} ); } /** * The corrupted-first-family control, live, with its own negative case beside * it. * * Two targets, and the second is the point. A single MATCHED row proves nothing * on its own — the gate's probe produced one of those while Inter had not * rendered at all. So the story also probes a span whose first family is * ALREADY absent, and shows the control reporting MISS for it. Two rows, * opposite verdicts, same probe: that is the evidence. * * `assetUris` points at the URLs `apps/storybook` serves from * `apps/storybook/public/fonts` (`staticDirs: ["../public"]`), so the web run * exercises design §6.3's PRIMARY mechanism and the face table below says * `asset` rather than `inline`. The preview head registers Inter from the same * file, which is why the real cascade matches here even before `GraphFaces` * mounts; the device runs at 2.7/2.8 are where the base64 path carries it * alone. */ /** * Whether this story is running somewhere the probe can run at all. * * A module constant, not a per-render check: it is the PLATFORM, and a value * that could change between renders would put the hooks below in danger. */ /** * The same check `DomOnlyStory` exports, imported rather than restated (task * 6.8). It was declared here first, and a second copy is how two stories end up * disagreeing about what "has a DOM" means. */ const hasDom = hasDomRealm; function FontProofPanel() { const hostRef = useRef(null); const [real, setReal] = useState(null); const [absent, setAbsent] = useState(null); const [statuses, setStatuses] = useState([]); useEffect(() => { if (!hasDom) return; let live = true; const run = async () => { // The faces have to be resolved before a width means anything. await document.fonts.ready; if (!live) return; const host = hostRef.current; if (!host) return; const title = host.querySelector("[data-graph-node-title]"); const control = host.querySelector("[data-font-proof-absent]"); if (title) setReal(probeRenderedFamily(title)); if (control) setAbsent(probeRenderedFamily(control)); }; void run(); return () => { live = false; }; }, []); const controlStack = corruptFirstFamily(fontCategoryStacks["sans-serif"]); /** * NATIVE STOPS HERE, and it is not a limitation of the story — it is the * measurement being meaningless (MPO-211). * * Two things below are DOM and nothing else: the `` negative control, * and `probeRenderedFamily`, which measures on a `` context against * an element's computed style. React Native answers a lowercase intrinsic it * does not know with `View config getter callback for component "span" must * be a function` and takes the whole tree down — measured on the iPhone 16e, * where the Kitchen Sink showed a red box for this story. * * Guarding it would be pointless if the answer were simply unavailable on * device, and it is not: the probe runs INSIDE the WebView, on the canvas's * way to `ready`, and `NodeGraph/Diagnostics` → `Live` renders the result. * That is the story AC-3's DOM half is read from, so this one says so * instead of pretending. */ if (!hasDom) { return ( probe not run — there is no DOM here The node above is the real Tamagui body, resolved through the real knob stack. The corrupted-first-family control needs a document and a canvas measurer, so on device it runs inside the WebView instead and its result arrives on the canvas's ready event. Read it at NodeGraph → Diagnostics → Live. ); } return ( {/* The negative control. Its first family is absent by construction. */} AaBbGgQqRrWw0123456789 {statuses.map((status) => ( {status.id} · {status.family} {status.weight} · delivered by {status.source} ))} ); } export const FontProof: Story = { parameters: { docs: { description: { story: "Design 6.3's corrupted-first-family control, live. The first row probes the GraphNode title through the real knob cascade and must read MATCHED; the second probes a span whose first family is already absent and must read MISS. Equal widths mean the first family never rendered — the gate's probe compared against a wholly bogus family and could not tell that apart from the second family rendering. The face table says which of the two mechanisms of 6.3 delivered each face. WEB ONLY: the control is a span and a canvas measurer, so on device this story says where the on-device probe is read instead — NodeGraph → Diagnostics → Live, which renders the probe the canvas ran inside its own WebView.", }, }, }, render: () => , };