10 KiB
ADR 0066: Dynamic and input text fields
- Status: accepted (2026-11-11), first slice built
- Relates to: ADR 0012 (text), ADR 0014 (text from Animate documents), ADR 0013 and ADR 0052 (ActionScript tiers 2 and 2.5), ADR 0024 (the pure player and Test Movie), ADR 0028 (HTML canvas export), ADR 0022 (accessibility), roadmap M5, requirements (static, dynamic and input text, P1)
Context
Animate has three text types. Static text is artwork. Dynamic text is a field scripts fill in while the movie plays (a score, a question, a name). Input text is a field the viewer types into (a name, an answer, a password), which scripts then read. AniCraft's text (ADR 0012) was static only: a block's outlines are laid out by the engine when it is edited and stored, so rendering never needs fonts. XFL import (ADR 0014) brought dynamic and input fields in as static text, keeping only the instance name. Scripts (ADR 0013, 0052) could not name text at all.
Two constraints shape the design. Time is a function: the authoring stage and every export
evaluate the document, never a played session, and the player is pure and deterministic.
Layering: the player lives in anicraft-doc (layer 1), and the fonts in anicraft-text,
also layer 1, which anicraft-doc may not use.
Decision
- A field is a text block with field settings.
TextBlock.field: Option<TextField>(None: static text, so every older file opens unchanged and saves byte for byte the same;#[serde(default)]throughout).TextFieldholds the kind (Dynamic, Input), the line type (Single line, Multiline, Multiline no wrap, Password; password only for input), Selectable, border and background with their colours, the maximum characters a viewer may type, and an ActionScript 1/2 variable name kept from Animate documents (not run). The element's name is its instance name (instance.set_namenow takes fields; static text has none). - The block's box is the field's box. For a field,
box_width × box_heightis the fixed box the author drew, not the text's size, and the stored outline is the shown text laid out 2 px (FIELD_GUTTER, Animate's inset) inside it, aligned in the box, wrapped at the box less the gutters when multiline, as*when a password. So everything that measures, picks, transforms, finds or breaks apart text works on fields unchanged, and the stage and every non-interactive export (PNG, GIF, APNG, WebP, SVG, Lottie, video, sprite sheets) draw a field with its authored text, purely and deterministically.evaluateadds what a field has that static text doesn't: its background, a clip to its box (a mask clip, so every renderer already supports it) and a 1 px border. - Fields are instances in the player. The player's instance tree gets text nodes
(
NodeKind::Text) for dynamic and input fields, so instance-name paths reach them (panel.name_txt), and properties scripts set (x,alpha,visible, …) apply to them as to movie clips.PlayerState.fieldsholds, per field instance, the text once a script or the viewer changed it (None: the timeline's own, so a later keyframe's words still show), its laid-out look, caret, selection and scroll;PlayerState.focusis the field with the keyboard. A field's state leaves with the field, as a clip's playhead does. - Scripts:
field.text,field.appendText(…),field.length. The script IR gainsProp::TextandProp::Length(read) andLValue::Text(write);appendText(v)lowers totext += v, so it needs no new statement. They are member-only (score_txt.text): a baretextstays a variable, as it is in ActionScript frame scripts. Settingnullstops the script with a message (ActionScript throws);\rand\r\nare line breaks, as ActionScript writes them; text is capped at 16,384 characters. Naming a movie clip or the stage as a field writes the same messages as other wrong-kind names. - Runtime layout through the host. The player can't reach the fonts, so
ScriptHost(the interface it already uses for plug-in frame scripts) gainslay_out_field(block, shown). The engine'sScriptRunneranswers it withanicraft-textand the samefield_layoutthe commands use, so a field looks the same before and after a script sets its text. The result (FieldLook: outline and caret stops per line) is stored in the state; drawing a state needs nothing else, and the same document, state and events always give the same picture on one computer. A host that can't lay out (NoScripts) still sets and reads text; the field then draws only its box.anicraft-text'sLayoutnow reports caret stops (each line's character range and the x of every boundary a glyph starts at), which input editing and click-to-place need. - Input editing is a pure state machine (
anicraft_doc::field): a press in an input field (or a selectable dynamic one) focuses it and places the caret; dragging selects; typed characters (Event::Char) replace the selection, respecting the line type and the maximum; Backspace, Delete, the arrows, Home and End move and edit by key code (Shift, key code 16, extends the selection); Enter starts a line in multiline fields; Tab moves to the next input field and selects its text;Event::SelectAllselects all. Keys still reach the stage's key listeners after editing, as they reach the stage from a focused field in ActionScript, so "press Enter to submit" scripts work. A one-line field scrolls sideways to keep the caret in view, a multiline one downwards. Dynamic fields select but never change. - Test Movie sends typed text, pastes and input-method commits as
Chars, Ctrl+A (⌘A) as Select All and Ctrl+C (⌘C) as a copy of the selection (never a password's) while a field has the keyboard; it shows a text cursor over fields and tells the system's input methods where the field is. Accessibility: every field on the stage is an AccessKit node: input fields as text inputs (password and multiline inputs by their roles), dynamic fields as labels, named by instance name, with their current text as their value.control.test_movietakes{type: text, text}and{type: select_all}events and lists every field's text (and the focused field's caret and selection) in its state. - HTML canvas export: native inputs, canvas text, authored outlines kept.
- Fields are exported with their box, settings and font. Until a script or the viewer
changes a field's text, the page draws its authored outline, exactly as AniCraft
does.
player.jsmirrors the Rust player's fields (tree nodes,text,length,appendText, messages), checked step by step against it in the Boa parity tests. - Input fields are real, positioned
<input>/<textarea>elements over the canvas (type=passwordfor passwords,maxlength,aria-labelfrom the instance name), placed by the field's stage transform, transparent so the canvas draws the box. The browser then gives the viewer everything a text field should have that a canvas-drawn imitation would have to rebuild and would get wrong: input methods for every script, the on-screen keyboard on phones and tablets, the clipboard, each platform's own editing shortcuts, selection by touch, and screen readers. Theirinputevent hands the value to the player, so scripts read what was typed. Canvas-drawn editing was rejected for these reasons; its one advantage (pixel parity of the caret with Test Movie) doesn't matter to viewers. - Text a script sets is drawn with
fillTextin the field's family, then the genericsans-serif, wrapped and aligned in the box as AniCraft does. Its glyphs come from the viewer's browser and may differ in shape and width from Test Movie when the family isn't on the viewer's computer. The export report says so for every page with fields ("text fields (their authored text keeps its outlines; text a script or the viewer changes is drawn with the browser's fonts)").
- Fields are exported with their box, settings and font. Until a script or the viewer
changes a field's text, the page draws its authored outline, exactly as AniCraft
does.
- Font embedding: not in this slice, by decision. Embedding font files in the page would redistribute fonts the author may not be licensed to redistribute (most commercial desktop licences forbid web embedding), and the export can't know. Embedding outlines for a declared character set (as Animate's "Embed" does) has the same licensing question for glyph data, plus a UI and a size cost. Authored text is already exact (its outlines are in the page); only text scripts set at run time uses the viewer's fonts. When we add embedding it will be an explicit per-field character set the author opts into, with the licence question asked in the UI, recorded as its own decision.
- XFL import keeps fields.
DOMDynamicTextandDOMInputTextbecome one field each (a field is one instance, so it takes its main style; mixed styles are counted), with their instance name, box (width,height,left,top; auto-size fields grow to their text), line type (lineType),border(a black line round a white box, as Animate's "Show border"),isSelectable,maxCharactersandvariableName(kept, counted under "kept, not run"). Empty input fields are kept. The report lists them under "Runs in Test Movie". A self-authored corpus package (textfields) has golden renders.
Consequences
- Animate projects with scores, quizzes and name entry play in Test Movie and in the HTML page without changes, and their fields stay editable as text in AniCraft.
- Exports other than HTML canvas show fields as authored; that matches Animate's video export.
- The document format is unchanged for files without fields; fields add one small object.
- Not yet:
htmlTextand HTML rendering in fields, per-character styles (ADR 0012),Event.CHANGE/TextEventlisteners and focus events,restrict,scrollV/maxScrollV,selectionBeginIndex/setSelectionand otherTextFieldproperties and methods, text colour or format set by scripts, Cut, double-click word selection, a blinking caret, mouse wheel scrolling, embedded fonts in the HTML page (above), selecting dynamic text in the HTML page, clipping the HTML page's input elements by mask layers,mouseX/mouseYwhile the pointer is over one, and running ActionScript 1/2 variables.