gnō- Architecture
gno/ is a client-side application with no build step: two pages, the
editor (authoring/index.html) and the standalone
player (player/index.html), and the code they share
in lib/. There is no bundler and no package.json; the pages load
their scripts with plain <script src> tags and also work opened directly
from disk. This is a deliberate scope choice, not a placeholder: gno/ is
isolated from the rest of the platform (see the root CLAUDE.md) and doesn’t
share tooling or code with backend//frontend/ or noid/.
For the narrative format itself (scenes, entities, dialogs, diverts,
Player pause rules), see ../README.md. This document covers
how the applications that read/write that format are built.
Stack
| Concern | Choice | How it’s loaded |
|---|---|---|
| UI framework | Vue 3 (Composition-ish createApp with ref/reactive/computed/watch) |
unpkg.com/vue@3/dist/vue.global.prod.js |
| Markdown rendering | marked |
cdnjs |
| Zip read/write (Download / Upload) | JSZip |
cdnjs |
YAML read/write (_graph.yaml, _presentation.yaml) |
js-yaml |
cdnjs |
| Icons | Tabler Icons webfont | jsdelivr |
| Fonts | Lora / Outfit / JetBrains Mono | Google Fonts |
All libraries are pulled from CDNs via <script>/<link> tags in each
page — no local node_modules. This mirrors the “no build step”
constraint but is otherwise independent from the CSS design-token system
shared with the rest of the platform (--c-* custom properties), which gno/
also follows even though it doesn’t import assets/tokens.css from
frontend/.
Files
| File | What it holds |
|---|---|
lib/gno-core.js |
Plain functions and constants, no Vue and no app state: the browser-save prefix, the language versions and converters, the .gno parser, the entity analyzer, the Markdown renderer, the Player pipeline (beats, stage frames, speech routing, layout, subscene placement), the image-catalog adapter, scenario-SVG build/parse, the persisted-shape sanitizers, the package decoders (readZipPackage, decodePresentationYaml, decodeLayoutYaml) and small helpers both pages need (listSavedNarratives, readSavedNarrative, withSceneBounds, catalogImage, loadCatalog). |
lib/gno-player.js |
The Player as a Vue component, GnoPlayer (<gno-player>): its template, the reader’s place, graphic mode, entity options, the entities panel and full screen. |
lib/gno.css |
The design tokens (--c-*/--font-*, light and dark), base elements, the narrative pills and blocks that the preview and the Player both render, and the Player’s styles. |
authoring/index.html |
The editor: its own styles, the Vue template (topbar, left nav, four views), and one script with what only the editor uses (the demo narrative, the autosave draft, syntax highlighting, the graph layout) and its createApp. |
player/index.html |
The standalone player: the case picker, loading and caching cases, and a <gno-player>. |
Each page loads lib/gno.css before its own styles, then the CDN libraries,
lib/gno-core.js, lib/gno-player.js and its own script. They are classic
scripts, not modules (which wouldn’t load from disk): the top-level
declarations of gno-core.js are globals the later scripts use directly;
gno-player.js is wrapped in a function and defines only GnoPlayer. Each
page registers it with .component('gno-player', GnoPlayer).
The editor’s favicon is an inline SVG data: URI of the app-tile icon from
design/icons/gno-icon-tile.svg, and so is the player’s.
There is no component decomposition inside the editor: it is one Vue root
instance with template v-if/v-show blocks per view, and the Player is its
only component. Given the files’ size, when making changes prefer grep -n
for the section comments (each major function is preceded by a comment
explaining its why) over reading them top to bottom.
Resizable side panels
Each side panel has a .panel-splitter on its inner edge (the left
navigation’s sits absolutely at the left of #main-area). startPanelResize
tracks the pointer on window and writes panelWidths (nav, preview —
null means half and half with the source —, scenarioSide), clamped by
PANEL_LIMITS; double-click resets one. While
dragging, #app.resizing turns off the grid transition and pointer events
elsewhere. Widths are a per-browser convenience in their own localStorage
key (gno-panel-widths), not part of the narrative bundle. The Graph’s scene
panel keeps its own older handle (onPanelResizeDown, nodePanelWidth),
and the Player’s entities panel is the component’s own
(startEntitiesResize, key gno-player-entities-width), so it works the
same in the standalone player.
The four views
The editor is one Vue app with a view ref switching between four panels;
all four share the same in-memory narrative (source, the raw .gno text)
and its derived state.
Editor
Split pane: a plain <textarea> for the raw .gno source, with a read-only
<pre> overlay behind it (highlightGno) providing the colored-token
syntax highlighting, plus a live preview pane rendered by renderGno
(.gno → HTML via marked, with scene headings, diverts, and @entity
mentions substituted into styled spans first).
Graph
A node-per-scene diagram. layoutGraphNodes auto-arranges scenes into
left-to-right topological columns (BFS from root scenes, orphans handled
separately); layoutGraphEdges draws cubic-bezier divert arrows between
nodes based on their final rendered position (sceneDiverts: choices,
entity diverts and entity options; a subscene divert, ~>, is drawn dotted
instead of dashed).
Nodes can be dragged anywhere, including above or left of the origin (the
canvas and its arrow layer don’t clip, so there is no lower bound); a
dragged position, a chosen color, and a free-text annotation are stored per
scene title in nodeMeta (title, not id, so the graph survives scene
reordering/renumbering). nodeMeta round-trips through the session
autosave and the downloadable _graph.yaml, but is not part of named
browser-storage saves or the .gno file itself — it’s presentation
metadata, not narrative content.
Zoom (wheel or toolbar) is bounded by ZOOM_MIN/ZOOM_MAX (0.05–4) only to
keep the view usable; the toolbar’s Fit button (fitView) zooms and pans
so every node is in view, which is also how to find nodes dragged far away.
Presentation
Four sub-tabs building the visual/staging layer on top of the narrative,
all persisted together as _presentation.yaml:
- Image Libraries — external image catalogs registered by URL. A
catalog can be gnō’s own simple list (
gno-catalog.yaml, or its restricted Markdown twingno-catalog.md— a bullet list of* items), an IIIF Collection, or a schema.orgImageGallery;detectAndParseCatalogsniffs the format (.mdby extension) andresolveCatalogUrlstreats a bare directory URL as “fetchgno-catalog.yamlinside it, elsegno-catalog.md” (fetchCatalog). - Entity — associates narrative
@ids with one or more library images (entityAssociations). Entities the narrative never mentions (scenery, props) can be declared with the “Add entity” field; those ids live inextraEntities(extra_entities:in_presentation.yaml) because, unlike narrative entities, nothing in the text would bring them back on reload. They appear in the Scenarios palette like any other entity and can be removed again; narrative entities can’t (the text defines them). Groups (@king + @queen) are entities too, keyed byentityGroupKey(members sorted, joined with ` +), so a group's images live inentityAssociationslike any entity's. They come from the narrative (analyzeEntitiesreads the joined form) or from typing them with+in "Add entity" (normalizeEntityRef, spaces around+optional, any number of members). Resolution goes by key, but a group is *shown* in the order it was written (entityWrittenRef):extraEntitieskeeps the typed form (re-typing a declared group in another order replaces it), occurrences carrywritten, and the app'sentityLabel(key)picks the typed form first, then the narrative's first one. The Editor preview and the text Player show each occurrence as written (entityBlockHtmlusesocc.written`; the roster lists a group’s members in written order). - Scenarios — a small SVG design canvas per scenario
(
buildScenarioSvg/parseScenarioSvg), downloaded as one.svgfile per scenario inside the export zip.- Canvas: its size, which the background always fills, is set by dragging the bottom-right corner or by typing width/height.
- Modes: the toolbar’s mode decides what a press on the canvas does
(
placeMode). With no mode selected, items are locked in place. Edit selects, moves and resizes them; it is the only mode in which items take the pointer (.scenario-svg.editing) and the inspector shows a selection. Place: Text / Place: Vertical stack / Place: Horizontal stack draw a new text area or stack, and then switch to Edit with it selected. Entities are added by dragging a tile from the palette, in any mode. - Items: entities, text areas and stacks are placed on it; anchors are
made from entities (see below). Every item
has an ID, edited in the sidebar inspector after placement. Text areas
and the other items have separate IDs, so a text area and an entity can
share one and play a role as a pair (
action_1,speech). InternallysvgIdstays unique: a text area’s always carriesTEXT_ID_SUFFIX(_text);itemRoleIdgives the authored ID,roleSvgId(kind, id)the svgId for a typed one (dropping a typed_text/_label). Text areas of version 1 designs named without the suffix are renamed by the 1 → 1.1 converter, not by the decoders. The UI always showsitemRoleId. New anchors, text areas and stacks start asanchor_n/text_n/layout_n(lowest freenfrom 1); entities start as their entity id. The inspector suggests IDs for entities and text areas: first the action and speech IDs the other sort uses without a partner, thenaction_n,action_proceed,action_regress,speech,_.speech,entity.speech. - Moving and resizing: every item can be moved by dragging it or by typing its X/Y in the inspector. The X/Y fields always show the top-left corner, including for anchors, whose stored x/y is their center. The canvas and every item can be resized by dragging a corner handle or typing width/height. Holding Shift while dragging, or the lock toggle beside the inputs (one for the canvas, one for items), keeps the current proportion.
- Anchors are made by placing an entity, sizing it while its image is
still visible, then using the inspector’s “Convert to anchor” button: the
image is dropped and the footprint (size, and position as its center) is
kept. The ID becomes the next
anchor_nunless the user had already renamed it. Anchors are drawn as a dashed rectangle of the image’s footprint and exported as a<g>withdata-gno-width/data-gno-height(36×36 if absent, e.g. in older files). Their x/y is their center, so they grow around it when resized. The conversion is one-way. - Text areas are drawn by dragging in “Place: Text” mode and exported as a
<foreignObject>wrapping an HTML<div>, since SVG<text>cannot wrap lines; text, font, size and color are set in the inspector. - Stacks (
kind: 'layout') are flexbox-like: a box, adirection(column|row),justify,align,gap, and an ordered list of child ids (children), which may include other stacks. The layout itself is the purelayoutBoxes. While designing, every child counts as visible, and a deep watcher (relayoutDesign) writes the positions back into the children, so the canvas, the inspector and the exported SVG agree. A child is selected but not dragged, and its X/Y fields are disabled. Items are added with the inspector’s “Insert items” (click items on the canvas), reordered or removed from its list, or taken out from the child’s own inspector. Renaming or removing an item updates the lists that reference it (renameLayoutRefs). A stack is exported as an empty<g data-gno-layout="column|row">whose settings and child ids are indata-gno-*attributes. The children stay flat in the SVG’s z-order. - Groups (
kind: 'group',cleanGroup) are the other container:children, with no area and no placement rule of their own. Their box is always the union of their children’s (fitGroups, run after each relayout, inner groups first), which is what a stack sizes them by; it is only drawn, as a frame around the items. “New group” makes an empty one and starts inserting into it. Children keep their absolute x/y; moving the group (drag or X/Y) moves them along (translateItem), and when a stack places the group,layoutBoxesshifts them by the group’s displacement. Stacks and groups nest freely (isContainer); an item sits in at most one container. A group’schildrenare back to front and mirror the design’s z-order: inserting files the item by its z-index, and reordering permutes the children’s slots initems(moveLayoutChild). Inserting also grows the box to Visibility in play: a group is shown while any child that can hide (anything but a plain, non-action entity image,isDecorItem) is, else everything inside it is hidden (layoutBoxesreturns that set ashidden). Exported as an empty<g data-gno-group data-gno-children=…>. - Hierarchy: the sidebar lists the design as a tree (
designTree): top-level items in z-order, containers with their children indented. A row selects its item (switching to Edit), or inserts it while a container is collecting items. Shift/Ctrl/Cmd-click builds a multiple selection (treeSelection; the last one picked is the inspector’sselectedItemId, and a canvas selection resets it).wrapTreeSelectionputs it into a new group (children in z-order) or stack (children in their order along its direction, box = their union), which takes their place in their container when they all shared one. Rows are draggable (HTML5 DnD,treeDrag): dropped on a container they go in throughinsertIntoLayout(no cycles), dropped on empty space in the panel they go to the top level. A row’s arrows (moveTreeItem) move it among its siblings: inside a container throughmoveLayoutChild; at the top level it passes its neighbour initems, each moving with its whole subtree (subtreeOf), so the tree order stays the z-order. Its trash button, or the head’s one for the selection, deletes (deleteTreeItems→removeScenarioItem); a deleted container’s children take its place in its own container (or go to the top level). - Subscene preview: the toolbar’s Preview subscene picks another
scenario (
subscenePreviewChoice, per browser session, never saved or exported) to draw as a ghost (subscenePreviews) where it would open as a subscene: the samesubscenePlaceholders+subsceneBoxthe Player uses, from the items’ current boxes. It takes no pointer events, so the box under it can still be dragged.subsceneCandidateslists first the scenarios this one opens with~>(subsceneTargetsOf), which also feed the inspector’s ID suggestions (anchors get only those). - Wide editor: a toolbar button lifts the whole workspace (toolbar,
canvas, sidebar) into a fixed full-window layer (
.scenario-workspace.wide), hiding the app’s top bar, navigation and the 900px page column. Esc (or the same button) leaves it. It is a layout switch only — the canvas is still shown at 1:1, so a large background scrolls inside it.
- Player — narrative-wide Player settings (
player:in_presentation.yaml). For now one:entityOptionsMode(entity_options: hover | click,sanitizeEntityOptionsMode), how the reader opens an entity’s options;hoverwhen absent.
Player
The Player is the shared component GnoPlayer (lib/gno-player.js), which
the editor shows as its fourth view and the standalone player shows alone.
It is given one narrative as props: source (the .gno text, which it
parses itself), scenarioDesigns, entityAssociations, libraryCatalogs
(the fetched catalogs, { id: { status, images } }, read through
catalogImage) and entityOptionsMode. The editor binds them to its live
state, so the Player follows every edit. active says whether it is on
screen (it starts at the start scene when first shown, and only then takes
the Space key); bumping restartKey sends the reader back to the start,
which the editor does whenever it loads another narrative
(resetPlayerProgress). The toolbar’s full-screen button calls
requestFullscreen on the component’s root (with the webkit fallbacks),
and fullscreenchange keeps isFullscreen in step, including after Esc; it
is hidden when the browser has no element full screen. In full screen the
template drops the toolbar, the start warning and the scene heading. With a
stage, the root gets fs-stage: the stage is centered on black, sized by
stageWrapStyle to fit the window but at most min(iw/W, ih/H) times the
design’s W×H, iw×ih being the background image’s natural size (loaded
once per URL into backgroundSizes), since the background covers the design
(slice); never less than the design’s size, and the design’s size when
there is no background. The fallback buttons (.player-below) float over the
stage, and .player-fs-exit (top right) shows while the pointer moves
(pokeFsExit), for touch screens without Esc.
It steps through the narrative as a reader would. buildScenePlayback splits
a scene’s body into beats (pause points), per the rules documented in
README.md (a lone -- line, or the end of a dialog/dialog-set unless
only diverts follow). Alongside beats it tracks which entities are “on
stage” — present since first mention, carrying their last-given state,
until an explicit @entity => exit or the scene ends — rendered in a
separate panel independent of the narrative text itself. It also lists, per
beat, the entity diverts on stage (entityDiverts), the entity options on
stage (entityOptions; an entity has either a divert or options, the latest
line giving one replaces both) and, for carrying, every entity on stage with
the states given to it since it entered (stages).
Entity options open one entity at a time in the top frame
(playerOpenOptions, keyed by the moment it was opened at, so a move to
another beat or scene closes it; playerActiveOptions is the live value).
onStageClick toggles them (in hover mode a click only opens), and in hover
mode onStageLayerEnter/onStageLayerLeave open them on the entity and keep
them open over the options, closing after a short grace. An option with =>
(carry) makes playerDivert put the entity’s stages entry in the new
frame’s carried; buildScenePlayback replays those states before the
scene’s first line, so the entity is on stage from the first beat.
The reader’s place is a stack of frames, playerStack ({ sceneId, reveal, carried? }):
the scene being played at the bottom, then any subscene opened over it with
~> (playerDivert pushes; a -> divert replaces the whole stack;
playerRegress pops a subscene, or steps back a beat at the bottom). Only the
top frame advances and takes clicks. playerSceneData holds what doesn’t
depend on the beat (the scene’s playback, design and folded stage frames), so
advancing doesn’t re-parse; playerFrames adds each frame’s beat. Before the
Player starts, the stack is empty and the start scene stands in for it
(playerFrameList). A watcher closes subscene frames whose scene was edited
away.
Graphic mode plays the same beats on the scenario’s designed SVG (rules in
README.md, “Graphic play”). It is on by default when scenarioDesigns has an
entry for the scene’s scenario; playerGraphic is only the reader’s
preference and playerUseGraphic the effective mode. The stage is not the
exported SVG file loaded into the DOM: it is drawn by the Player’s own
<svg> from the live scenarioDesigns data (like the Scenarios canvas), so it
tracks edits to the design, the associations and the narrative without a
round-trip. The pipeline is a chain of pure functions:
buildScenePlayback additionally returns per-beat events (entity mentions)
and speeches (prose and dialogs, in order) → foldStageFrames replays the
events into who is on stage and where, using pickEntityImage (best label
match, first on ties); a member mentioned alone splits an on-stage group
(splitGroupsOf: each member re-enters with the image the group’s last
labels pick for it, at its own earlier anchor or the group’s, and the
mention then applies on top) → routeSpeech assigns speech to text areas (by their authored ID; an
entity sharing a speech area’s ID, isSpeechRole, is shown only while that
area has speech, and both items of an action_* pair follow actionRole) →
buildPlayerStage first settles what each item shows at this moment (and so
which items are hidden), then runs layoutBoxes so stacks close up around
the hidden items, and finally emits drawable layers in the design’s z-order,
with action_* items, and entities carrying a divert, turned into click
targets ({ type: 'divert', divert } for both kinds of divert). An entity
with options gets { type: 'options', … }, and the <owner>.action_N
items (actionRole kind option, owner by optionOwnerKey) are shown only
for the entity in ctx.openOptions. Entity images come
from the live library catalogs (findCatalogImage), not from anything stored
in the design, so an entity is drawn only once its catalog has loaded. The
Vue template binds the SVG’s viewBox through v-bind="{viewBox: …}"
because the template is parsed as HTML, which lowercases a :viewBox name.
playerStage draws every frame into that one <svg>, each in a <g>
transformed into its box: the bottom frame fills the stage, a subscene sits
where subsceneBox puts it, behind a backdrop rect, and a subscene with no
design becomes a text card (<foreignObject>). The place comes from the
frame below: buildPlayerStage is told which subscene is open over it
(ctx.subscene) and returns, beside its layers, the box of the matching
subscene.<scenario> / subscene item (subscenePlaceholders, boxes before
entity frames) as laid out by layoutBoxes; it counts as visible then, so
stacks make room for it, and is hidden otherwise. Without one, subsceneBox
centers the subscene at its design’s size. Each box is in its parent frame’s
units, so the transforms compose down the stack. Frames below the top are .stage-inert. Whether the
Player is graphic follows the bottom frame’s design; the controls’ fallbacks
(playerActionSlots) follow the top frame’s.
Standalone player
player/index.html is a small Vue app around one <gno-player>. It reads
the case from the page’s address (openFromLocation): ?id=<name> opens a
named save (readSavedNarrative), ?url=<zip>&cache=0|1|2 a zip on the web,
and neither shows the picker. The parameters and the cache modes are
described for users in README.md, “Standalone player”.
A web case is downloaded with fetch (cache: 'no-cache' for a forced
update, so the HTTP cache can’t serve a stale zip) and read with the same
readZipPackage the editor uses for an uploaded zip, so it is converted like
any zip. The cache keeps the zip’s bytes, base64, in localStorage under
gno-player-cache:<absolute url> ({ url, name, size, cachedAt, zip }):
keeping the file rather than the decoded package means a cached case is
decoded and converted each time, by whatever version the player is then.
A zip is cached only after it has been read successfully. Writing can fail
when the storage is full; the case still plays, with a notice.
The decoded package goes into the player’s own reactive state
(applyBundle: the same sanitizers as the editor’s), its image libraries’
catalogs are fetched with loadCatalog, and restartKey is bumped. Every
load takes a sequence number, so the results of a load (or a catalog fetch)
overtaken by a newer one are dropped. A case chosen in the picker is opened
with history.pushState, carrying { picker: true } in the history state,
which is what keeps the Cases button for it (also after a reload); a
popstate listener reopens whatever the address names.
Persistence model
Three independent mechanisms share the same underlying bundle shape (narrative source + graph layout + presentation setup):
| Mechanism | Trigger | Shape |
|---|---|---|
| Session autosave | Debounced (~600ms) on every edit, flushed immediately on tab hide/close | One localStorage draft key; restores work after a reload even without an explicit Save |
| Named save (Save/Load buttons) | Explicit user action | One JSON blob per name in localStorage, prefix gno-narrative-v2:<name> (see README.md for the older plain-text saves) |
| Download / Upload | Explicit user action | A .zip containing manifest.json + <name>.gno + <name>_graph.yaml + <name>_presentation.yaml + one scene/*.svg per scenario design |
Named saves and the session draft keep scenario_designs as live data (the
same structure buildScenarioSvg renders from) rather than pre-rendered
SVG, so the two representations can never drift apart; only the downloadable
zip materializes the SVGs, as files meant to be viewed outside the app.
Uploading a single .gno/.md/.txt file (not a zip) loads narrative text
only and clears graph/presentation state, since there’s nothing else to
restore it from.
Language versions and converters
All three carry the gnō language version in a manifest
(makeManifest: { format, version, … }): manifest.json in the zip
(which also names the zip’s narrative, graph and presentation files),
the manifest field of a named save and of the draft. The YAML and SVG files
hold no version. The protocol for changing versions is in
gno/CLAUDE.md; what changed in each version is in
versions.md.
Every way in goes through one path: decode into a package
{ source, layout, presentation: { image_libraries, entities,
extra_entities, player, scenario_designs } } (a zip via readZipPackage,
decodeLayoutYaml and decodePresentationYaml; a save or the draft is
already one), bring it to GNO_VERSION with upgradeBundle, then
applyBundle swaps it into the live state. manifestVersion reads the
version, GNO_FIRST_VERSION (1) when there is no manifest.
converterChain walks CONVERTERS ({ from, to, bundle, files? }) from
that version up; each step’s bundle(pkg) returns { bundle, notes }. A
zip’s raw files ({ path: text }) first go through the steps’ optional
files stages (upgradeFiles), for versions that change how something is
written in the files, so the current decoders can read them. The notes, or
an error for a version with no path to the current one (newer, or unknown),
become versionNotice, shown until dismissed. The draft is upgraded in
loadCurrentDraft, before the app state is built from it.
Converters are pure, and each keeps its own copies of the patterns it
matches (convert_1_to_1_1 has its own entity and heading regexes) so that
later changes to the parser can’t alter what an old converter does. The
parser, the Player and the editor know only the latest version.
Parsing pipeline
source (raw text) flows through a small set of pure functions, each
independent and re-run reactively as the user types:
parseGno(source)— splits the text into scenes by# Title: Scenario (\*|\*\*)?headings (sceneMarkerturns the marker intostart/end), extracting each scene’s body, its choices (* Label -> Target, or~>for a subscene) and its entity diverts (@door -> Target, matched byENTITY_DIVERT_RE; lines of a dialog’s text are skipped), and its entity options (OPTION_RElines right under a standalone entity line,ENTITY_LINE_RE). Choices, entity diverts and entity options are separate lists becauseaction_Nnumbers the choices only.analyzeEntities(source)— regex-based detection of the three@entityforms (standalone, dialog-leading, inline), using Unicode letter/number classes so accented ids are matched in full. A standalone occurrence takes the option lines under it asoptions, itslineEndcovering them.renderGno(source, scenes, entities)— produces the live preview HTML, substituting scene headings/diverts/entity mentions with styled spans before handing the rest of each line tomarked.highlightGno(source, entities)— tokenizes each line for the editor’s syntax-highlight overlay.buildScenePlayback(scene, ...)— (Player-only) turns one scene’s body into the beat/pause sequence described above, plus the entity events and speech the graphic mode consumes (foldStageFrames,routeSpeech,buildPlayerStage).
None of these functions depend on Vue; they operate on plain strings/arrays and are called from computed properties inside the app.