@flatkit/sugarflat 0.2.1 → 0.2.2

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 CHANGED
@@ -238,7 +238,8 @@ function takeRaw(text) {
238
238
  const openBrace = m.index + m[0].length - 1;
239
239
  const end = blockEnd(text, openBrace);
240
240
  if (end < 0) break;
241
- const body = text.slice(openBrace + 1, end).replace(/^\r?\n/, "").replace(/\r?\n[ \t]*$/, "");
241
+ const raw = text.slice(openBrace + 1, end);
242
+ const body = raw.includes("\n") ? raw.replace(/^\r?\n/, "").replace(/\r?\n[ \t]*$/, "") : raw.trim();
242
243
  const bucket = m[0].includes("scene") ? m[1] ? out.under : out.over : out.top;
243
244
  bucket.push(body);
244
245
  out.rest += text.slice(cursor, m.index);
@@ -298,7 +299,7 @@ function desugar(src, opts = {}) {
298
299
  const tail = takeRaw(after);
299
300
  const expanded = spliceIntoScene(flatink, [...head.under, ...tail.under], [...head.over, ...tail.over]);
300
301
  const topLevel = (p) => [p.rest.trim(), ...p.top.length ? [RAW_NOTE, ...p.top] : []].filter(Boolean).join("\n");
301
- const whole = [topLevel(head), expanded, topLevel(tail)].filter(Boolean).join("\n\n");
302
+ const whole = [topLevel(head), topLevel(tail), expanded].filter(Boolean).join("\n\n");
302
303
  return { flatink: ensureHeader(whole, doc), kind: gesture.keyword, expanded: true, meta };
303
304
  }
304
305
  if (keyword && keyword !== "raw" && !FLATINK_BLOCKS.has(keyword)) throw new UnknownSugarError(keyword, gestures2.map((g) => g.keyword));
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/document.ts","../src/ident.ts","../src/theme.ts","../src/gestures.ts","../src/index.ts"],"sourcesContent":["// ─────────────────────────────────────────────────────────────────────────────\n// document.ts — the document a sugar block expands into.\n//\n// Two things a sugar MUST know and an author MUST be able to read: the canvas the gesture is laid out\n// for, and the timeline it rides. Both were literals buried inside an expander, which cost twice:\n// • the expansion never emitted `size` at all, so it fell back on the compiler's 800x600 default\n// while the board was painted for 760x620 -- everything past x=760 was clipped in silence, on the\n// whole corpus, for months (nothing says so: a missing `size` still compiles);\n// • prompting a model for the right coordinates meant reading the generator's source.\n// Exposed here, overridable per call, and stamped onto every expansion by `ensureHeader`.\n// ─────────────────────────────────────────────────────────────────────────────\n\n/** The canvas + timeline a sugar block expands into. */\nexport type DocumentSpec = {\n width: number\n height: number\n fps: number\n /** Timeline length. Long enough that `time` does not wrap mid-activity (the compiler warns under 120). */\n durationFrames: number\n}\n\n/** The board the gestures are laid out for. Override per call when a host uses another canvas. */\nexport const DEFAULT_DOCUMENT: DocumentSpec = { width: 760, height: 620, fps: 24, durationFrames: 120 }\n\n/** `true` if the source already declares its canvas — `size` must be the FIRST statement of a program. */\nexport const hasSizeHeader = (src: string): boolean => /^[ \\t]*size\\s+-?[\\d.]+\\s+-?[\\d.]+/m.test(src)\n\n/** `true` if the source already declares a root timeline. */\nexport const hasTimelineHeader = (src: string): boolean => /^[ \\t]*timeline\\s+\\d+/m.test(src)\n\n/**\n * Prepend whatever header the expansion is missing. `size` is REQUIRED by the format and silently\n * defaulted by the compiler when absent, so emitting it is not a nicety: it is the difference between\n * the document the author designed and the one that gets drawn.\n */\nexport function ensureHeader(flatink: string, doc: DocumentSpec = DEFAULT_DOCUMENT): string {\n const head: string[] = []\n if (!hasSizeHeader(flatink)) head.push(`size ${doc.width} ${doc.height}`)\n if (!hasTimelineHeader(flatink)) head.push(`timeline ${doc.fps} ${doc.durationFrames}`)\n return head.length ? `${head.join('\\n')}\\n${flatink}` : flatink\n}\n","// ─────────────────────────────────────────────────────────────────────────────\n// ident.ts — a human label -> a FlatInk identifier.\n//\n// A sugar lets an author name things in their own language (\"chene\", \"Vegetaux\", \"21 janvier 1793\"),\n// and those names become identifiers (`var`, `object`). FlatInk identifiers are `[A-Za-z0-9_]`, so an\n// accent does not error -- the lexer stops at it and reads the tail. `chene` written with its accent\n// became `var <accented>X`, read as `neX`: two variables where the author wrote one, and no diagnostic.\n// Transliterate here, once, rather than in every gesture.\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * A FlatInk identifier derived from a human label: accents folded to ASCII, anything else to `_`, and\n * a leading digit prefixed (an identifier may not start with one). Stable and idempotent, so the same\n * label always yields the same name — the sugar's variables and the author's references must agree.\n */\nexport function ident(label: string): string {\n const ascii = label.normalize('NFD').replace(/\\p{Diacritic}/gu, '').replace(/[^A-Za-z0-9_]/g, '_')\n return /^[0-9]/.test(ascii) ? `n${ascii}` : ascii\n}\n\n/** `true` if the label survives `ident` unchanged — i.e. it is already a usable identifier. */\nexport const isIdent = (label: string): boolean => ident(label) === label && label.length > 0\n","// ─────────────────────────────────────────────────────────────────────────────\n// theme.ts — where appearance lives, so that gestures do not carry any.\n//\n// A gesture emits STRUCTURE and BEHAVIOR: named groups at the coordinates the author gave, their drop\n// boxes, their state, their handlers. It must never decide what any of it LOOKS like — a sugar that\n// ships a look hands every activity built on it the same face, and that has already happened once.\n//\n// So appearance is a parameter. `BLANK` draws nothing at all, which is what makes the claim testable\n// rather than aspirational: expand a gesture with `BLANK` and the output must not contain one colour,\n// one font, or one stroke. `GREYBOX` is a deliberately plain default so a freshly written block is\n// playable immediately — it is provisional by design, and swapping it is a single argument.\n// ─────────────────────────────────────────────────────────────────────────────\n\n/** What a drawn thing is FOR. Four roles cover every gesture; a theme need not distinguish more. */\nexport type Role =\n | 'item' // something the learner moves\n | 'target' // where an item belongs\n | 'card' // a panel the learner reads and taps\n | 'chip' // a small tappable value\n\nexport type Theme = {\n readonly name: string\n /** Footprint of a role. The gesture uses it for drop boxes; the theme must draw within it. */\n size(role: Role): { w: number; h: number }\n /** Drawing statements for a role, in LOCAL coordinates centred on 0,0. May be empty. */\n draw(role: Role, label: string): string[]\n}\n\n/** Every role, in a stable order — for a reference card, or to sweep a theme. */\nexport const ROLES: Role[] = ['item', 'target', 'card', 'chip']\n\nconst SIZES: Record<Role, { w: number; h: number }> = {\n item: { w: 92, h: 92 },\n target: { w: 208, h: 118 },\n card: { w: 180, h: 140 },\n chip: { w: 96, h: 96 },\n}\n\n/**\n * Draws nothing. The gesture still emits every group, every box and every handler, so an author (or a\n * skin) supplies the whole appearance — and the test suite uses it to prove the gestures themselves\n * carry no visual opinion.\n */\nexport const BLANK: Theme = {\n name: 'blank',\n size: (role) => SIZES[role],\n draw: () => [],\n}\n\n/** Rounded rectangle path, centred on the origin — the greybox's only shape vocabulary. */\nconst plate = (w: number, h: number, r: number): string => `rect ${-w / 2} ${-h / 2} ${w} ${h} ${r}`\n\n/**\n * A plain, provisional greybox: readable, anonymous, and meant to be replaced. It exists so `place x {\n * … }` is playable the moment it is written; it is not a design, and anything built for an audience\n * should pass its own theme (or redraw beside the gesture with `raw { … }`).\n */\nexport const GREYBOX: Theme = {\n name: 'greybox',\n size: (role) => SIZES[role],\n draw(role, label) {\n const { w, h } = SIZES[role]\n const text = (size: number, boxW: number, boxH: number, colour: string, y: number) =>\n `text \"${label.replace(/\"/g, \"'\")}\" at ${-boxW / 2},${y} font \"system-ui, sans-serif\" size ${size} align center line 1.2 color ${colour} box ${boxW} ${boxH} wrap`\n switch (role) {\n case 'item':\n return [`circle 0 0 ${w / 2 - 12} fill #e8c46b`, `circle 0 0 ${w / 2 - 12} nofill stroke #b8923f 2`, text(14, w - 8, 20, '#4a3a1e', -9)]\n case 'target':\n return [`${plate(w - 8, h - 8, 14)} fill #2e3a4e`, `${plate(w - 8, h - 8, 14)} nofill stroke #5a6f8a 2 dash 8,6`, text(16, w - 28, 22, '#aeb6c4', -h / 2 + 10)]\n case 'card':\n return [`${plate(w, h, 16)} fill #2b3447`, `${plate(w, h, 16)} nofill stroke #44516a 2`, text(15, w - 20, h - 40, '#d7deea', -h / 2 + 26)]\n case 'chip':\n return [`circle 0 0 ${w / 2 - 8} fill #e8c46b`, `circle 0 0 ${w / 2 - 8} nofill stroke #b8923f 3`, text(22, w - 16, 28, '#4a3a1e', -13)]\n }\n },\n}\n","// ─────────────────────────────────────────────────────────────────────────────\n// gestures.ts — the three primitives.\n//\n// Five named gestures came in (`tri`, `ordonner`, `placement`, `composer`, `etapes`). Read side by\n// side, the first three share ONE implementation: the only thing that differed between them was which\n// shape their targets were drawn as -- rectangles, squares or dotted discs. That is appearance, and\n// appearance is now the theme's business, so they collapse into a single `place`. Five public promises\n// became three.\n//\n// Each gesture emits state, structure and behavior. Not one colour, not one font: `BLANK` proves it.\n// Coordinates DO appear, and that is not an opinion -- they are the ones the author wrote in the block.\n// ─────────────────────────────────────────────────────────────────────────────\nimport type { Expansion, Gesture } from './index'\nimport { ident } from './ident'\nimport { GREYBOX, ROLES, type Role, type Theme } from './theme'\n\n/** Everything a gesture needs beyond the author's text. */\nexport type GestureOptions = { theme?: Theme }\n\nconst q = (s: string) => s.replace(/\"/g, \"'\")\n\n/** Statements of a named group placed at `x,y`, drawn by the theme, optionally a drop box. */\nfunction container(name: string, x: string, y: string, art: string[], hitbox?: { w: number; h: number }): string[] {\n const box = hitbox ? ` hitbox ${hitbox.w} ${hitbox.h}` : ''\n return [` group \"${name}\" at ${x},${y} pivot 0,0${box} {`, ' layer \"art\" {', ...art.map((l) => ` ${l}`), ' }', ' }']\n}\n\n/** Split a block body into its non-empty, comment-free lines. */\nconst lines = (body: string): string[] => body.split('\\n').map((l) => l.replace(/\\/\\/.*$/, '').trim()).filter(Boolean)\n\n// ── place ────────────────────────────────────────────────────────────────────\n// The drop gesture: items belong on targets. Several items may share a target (a sort) or each may have\n// its own (an ordering, a labelled diagram) -- that falls out of the data, it is not a separate gesture.\n\ntype PlaceModel = {\n prompt: string\n targets: { id: string; label: string; x: string; y: string }[]\n items: { id: string; label: string; target: string; x: string; y: string }[]\n}\n\nfunction parsePlace(name: string, body: string): PlaceModel {\n const m: PlaceModel = { prompt: '', targets: [], items: [] }\n for (const line of lines(body)) {\n let x: RegExpMatchArray | null\n if ((x = line.match(/^prompt\\s+\"(.*)\"$/))) m.prompt = x[1]\n else if ((x = line.match(/^target\\s+(?:\"([^\"]+)\"|(\\S+))\\s+at\\s+(-?[\\d.]+),(-?[\\d.]+)$/))) {\n const label = x[1] ?? x[2]\n m.targets.push({ id: `T${ident(label)}`, label, x: x[3], y: x[4] })\n } else if ((x = line.match(/^item\\s+(?:\"([^\"]+)\"|(\\S+))\\s*->\\s*(?:\"([^\"]+)\"|(\\S+))\\s+at\\s+(-?[\\d.]+),(-?[\\d.]+)$/))) {\n const label = x[1] ?? x[2]\n m.items.push({ id: `I${ident(label)}`, label, target: `T${ident(x[3] ?? x[4])}`, x: x[5], y: x[6] })\n } else throw new Error(`place \"${name}\": unrecognised line: ${line}`)\n }\n if (!m.targets.length) throw new Error(`place \"${name}\": no target — an item has nowhere to go`)\n if (!m.items.length) throw new Error(`place \"${name}\": no item — nothing for the learner to do`)\n const known = new Set(m.targets.map((t) => t.id))\n for (const it of m.items) {\n if (!known.has(it.target)) throw new Error(`place \"${name}\": item \"${it.label}\" points at an unknown target`)\n }\n return m\n}\n\nfunction expandPlace(name: string, body: string, theme: Theme): Expansion {\n const m = parsePlace(name, body)\n const n = m.items.length\n const out: string[] = [`// place \"${q(name)}\" — generated. The expansion is the artefact of record: edit it, or edit the block.`]\n if (m.prompt) out.push(`// prompt: ${q(m.prompt)}`)\n\n out.push('var progress = 0', 'var done = 0')\n for (const it of m.items) out.push(`var ${it.id}X = ${it.x}`, `var ${it.id}Y = ${it.y}`, `var ${it.id}Placed = 0`)\n\n out.push('', 'scene {', ' layer \"targets\" {')\n for (const t of m.targets) out.push(...container(t.id, t.x, t.y, theme.draw('target', t.label), theme.size('target')))\n out.push(' }', ' layer \"items\" {')\n for (const it of m.items) out.push(...container(it.id, it.x, it.y, theme.draw('item', it.label)))\n out.push(' }', '}', '')\n\n m.items.forEach((it, i) => {\n out.push(`object \"${it.id}\" {`)\n out.push(` drag ${it.id}X, ${it.id}Y { enabled ${it.id}Placed == 0 }`)\n out.push(` when dropped on ${it.target} at pointer {`)\n out.push(` if ${it.id}Placed < 0.5 {`)\n out.push(` ${it.id}Placed = 1`, ' progress = progress + 1')\n // Snap onto the target it was dropped on, reading the target's LIVE position -- so a skin may move\n // the target anywhere and the item still lands on it.\n out.push(` ${it.id}X = ${it.target}.x`, ` ${it.id}Y = ${it.target}.y`)\n out.push(` send \"correct\", { item = ${i} }`)\n out.push(` if progress == ${n} {`, ' done = 1', ' send \"completed\"', ' }')\n out.push(' }', ' }')\n for (const t of m.targets) {\n if (t.id === it.target) continue\n out.push(` when dropped on ${t.id} at pointer {`)\n out.push(` ${it.id}X = ${it.x}`, ` ${it.id}Y = ${it.y}`) // back where it started\n out.push(` send \"incorrect\", { item = ${i} }`)\n out.push(' }')\n }\n out.push(` x = ${it.id}X`, ` y = ${it.id}Y`, '}', '')\n })\n return {\n flatink: out.join('\\n'),\n meta: { keyword: 'place', name, prompt: m.prompt, items: m.items.map((i) => i.label), targets: m.targets.map((t) => t.label) },\n }\n}\n\n// ── compose ──────────────────────────────────────────────────────────────────\n// Tap values until they add up to a target. Overshooting resets the total -- the whole point of the\n// exercise is that going over is a mistake you feel, not one you are prevented from making.\n\nfunction expandCompose(name: string, body: string, theme: Theme): Expansion {\n let target = 0\n const chips: { value: string; x: string; y: string }[] = []\n let prompt = ''\n for (const line of lines(body)) {\n let x: RegExpMatchArray | null\n if ((x = line.match(/^prompt\\s+\"(.*)\"$/))) prompt = x[1]\n else if ((x = line.match(/^total\\s+(\\d+)$/))) target = Number(x[1])\n else if ((x = line.match(/^chip\\s+(\\d+)\\s+at\\s+(-?[\\d.]+),(-?[\\d.]+)$/))) chips.push({ value: x[1], x: x[2], y: x[3] })\n else throw new Error(`compose \"${name}\": unrecognised line: ${line}`)\n }\n if (!target) throw new Error(`compose \"${name}\": no \\`total <n>\\` — there is nothing to reach`)\n if (!chips.length) throw new Error(`compose \"${name}\": no chip — nothing for the learner to tap`)\n\n const out: string[] = [`// compose \"${q(name)}\" — generated.`, ...(prompt ? [`// prompt: ${q(prompt)}`] : []), 'var total = 0', 'var done = 0', '', 'scene {', ' layer \"chips\" {']\n chips.forEach((c, i) => out.push(...container(`C${i}`, c.x, c.y, theme.draw('chip', c.value), theme.size('chip'))))\n out.push(' }', '}', '')\n chips.forEach((c, i) => {\n out.push(`object \"C${i}\" {`, ' when clicked {', ' if done < 0.5 {')\n out.push(` if total + ${c.value} > ${target} {`)\n out.push(' total = 0', ` send \"incorrect\", { chip = ${i} }`)\n out.push(' } else {')\n out.push(` total = total + ${c.value}`, ` send \"correct\", { chip = ${i} }`)\n out.push(` if total == ${target} {`, ' done = 1', ' send \"completed\"', ' }')\n out.push(' }', ' }', ' }', '}', '')\n })\n return { flatink: out.join('\\n'), meta: { keyword: 'compose', name, prompt, items: chips.map((c) => c.value), targets: [] } }\n}\n\n// ── steps ────────────────────────────────────────────────────────────────────\n// A gated sequence: step i only responds when it is the current one. Tapping out of order does nothing\n// at all -- no error, no penalty, which is what makes it usable as an escape-room stage.\n\nfunction expandSteps(name: string, body: string, theme: Theme): Expansion {\n let prompt = ''\n const steps: { label: string; x: string; y: string }[] = []\n for (const line of lines(body)) {\n let x: RegExpMatchArray | null\n if ((x = line.match(/^prompt\\s+\"(.*)\"$/))) prompt = x[1]\n else if ((x = line.match(/^step\\s+\"(.*)\"\\s+at\\s+(-?[\\d.]+),(-?[\\d.]+)$/))) steps.push({ label: x[1], x: x[2], y: x[3] })\n else throw new Error(`steps \"${name}\": unrecognised line: ${line}`)\n }\n if (!steps.length) throw new Error(`steps \"${name}\": no step — the sequence is empty`)\n\n const out: string[] = [`// steps \"${q(name)}\" — generated.`, ...(prompt ? [`// prompt: ${q(prompt)}`] : []), 'var step = 0', '', 'scene {', ' layer \"steps\" {']\n steps.forEach((s, i) => out.push(...container(`S${i}`, s.x, s.y, theme.draw('card', s.label), theme.size('card'))))\n out.push(' }', '}', '')\n steps.forEach((_s, i) => {\n out.push(`object \"S${i}\" {`, ' when clicked {', ` if step == ${i} {`, ` step = step + 1`, ` send \"step\", { index = ${i} }`)\n if (i === steps.length - 1) out.push(' send \"completed\"')\n out.push(' }', ' }')\n // The only thing the gesture says about looks: a step that is not current is dimmed, because\n // \"which one is live\" is STATE, not decoration. A theme that disagrees rebinds opacity itself.\n out.push(` opacity = step == ${i} ? 1 : 0.45`, '}', '')\n })\n return { flatink: out.join('\\n'), meta: { keyword: 'steps', name, prompt, items: steps.map((s2) => s2.label), targets: [] } }\n}\n\n/** `208x118` — the footprint of a role under a theme, for a summary or a prompt. */\nconst footprint = (theme: Theme, role: Role): string => {\n const { w, h } = theme.size(role)\n return `${w}x${h}`\n}\n\n/**\n * Build the shipped gestures against a theme. `GREYBOX` unless the caller supplies one.\n *\n * Each `summary` carries the FOOTPRINTS of the roles it places, because the author writes positions and\n * two overlapping surfaces make a drop ambiguous. Measured on ten model-written activities: a prompt\n * giving only \"space them out\" produced overlapping hitboxes in 4 of 10; the same prompt with the\n * numbers, 0 of 10. The sizes were public all along — nothing said you had to go and read them.\n */\nexport function gestures(opts: GestureOptions = {}): Gesture[] {\n const theme = opts.theme ?? GREYBOX\n return [\n {\n keyword: 'place',\n summary: `place <name> { prompt \"…\" target <T> at x,y item <i> -> <T> at x,y } — drag items onto where they belong. Footprints: target ${footprint(theme, 'target')}, item ${footprint(theme, 'item')}; keep centres at least one footprint apart or the drop is ambiguous`,\n expand: (name, body) => expandPlace(name, body, theme),\n },\n {\n keyword: 'compose',\n summary: `compose <name> { prompt \"…\" total <n> chip <v> at x,y } — tap values until they add up; overshooting resets. Footprint: chip ${footprint(theme, 'chip')}`,\n expand: (name, body) => expandCompose(name, body, theme),\n },\n {\n keyword: 'steps',\n summary: `steps <name> { prompt \"…\" step \"…\" at x,y } — a gated sequence; out-of-order taps do nothing. Footprint: card ${footprint(theme, 'card')}`,\n expand: (name, body) => expandSteps(name, body, theme),\n },\n ]\n}\n\n/**\n * The paste-ready reference for a model writing sugar: the grammar of every gesture, the footprints it\n * must respect, and the canvas it is laying out on. This is the artefact `summary` was being used as by\n * hand — assembled here so nobody has to know that the sizes live on the theme.\n */\nexport function sugarCard(opts: GestureOptions & { document?: { width: number; height: number } } = {}): string {\n const theme = opts.theme ?? GREYBOX\n const doc = opts.document ?? { width: 760, height: 620 }\n return [\n '# FlatInk sugar — one block, one activity',\n '',\n `Canvas: ${doc.width}x${doc.height}, origin top-left. Write ONE block, nothing else. Coordinates are the`,\n 'CENTRE of each thing. Anything you do not describe is not drawn.',\n '',\n '## Blocks',\n ...gestures({ theme }).map((g) => `- ${g.summary}`),\n '',\n '## Footprints — respect them or two things overlap and the drop becomes ambiguous',\n ...ROLES.map((role) => `- ${role}: ${footprint(theme, role)}`),\n '',\n `A row of targets fits about ${Math.floor(doc.width / (theme.size('target').w + 20))} across; a row of items about ${Math.floor(doc.width / (theme.size('item').w + 20))}.`,\n 'Leave a gap the size of the thing itself between two centres.',\n '',\n '## Escape hatch — three forms, and they are not interchangeable',\n 'The block draws NOTHING beyond the pieces above. Everything else goes through one of these:',\n '',\n 'raw scene under { layer \"bg\" { … } } <- BACKGROUND and decor. Drawn BEHIND the activity.',\n 'raw scene { layer \"banner\" { … } } <- overlays drawn ON TOP: a title, a frame, a caption.',\n 'raw { var lives = 3 object \"X\" { … } } <- header and behavior: var, fn, asset, object blocks.',\n '',\n 'A `layer` written in a plain `raw { … }` lands OUTSIDE the scene and is a compile error — anything',\n 'that is drawn belongs in one of the two `raw scene` forms. Either may be written on one line.',\n ].join('\\n')\n}\n","// ─────────────────────────────────────────────────────────────────────────────\n// @flatkit/sugarflat — declarative sugar for FlatInk.\n//\n// A compact block expands into INSPECTABLE `.flatink`. The expansion is the artefact of record: the\n// sugar is an authoring tool, never a runtime, and anything it writes can be written by hand instead.\n//\n// WHY IT LIVES IN THIS REPO. Not to put authoring opinions into the language — it is a separate\n// package, out of the lockstep group, and `@flatkit/compiler` never depends on it. It lives here so\n// the two move together: a grammar change breaks these tests in the same CI run. That is the whole\n// argument, and it was demonstrated rather than argued — the previous out-of-tree sugar never emitted\n// the format's REQUIRED `size` line, on its entire corpus, for months, unnoticed.\n//\n// THE LINE THIS PACKAGE DOES NOT CROSS: no visual opinion. A gesture emits state and behavior; it\n// never emits a coordinate, a colour or a font. The language already ships interaction opinions\n// (`drag`, `when dropped on … at pointer`, `hitbox`, `match`, `feedback`, `spring`) — what it has\n// never shipped is a look, and a sugar that shipped one would hand every activity the same face.\n// ─────────────────────────────────────────────────────────────────────────────\nimport { DEFAULT_DOCUMENT, ensureHeader, type DocumentSpec } from './document'\nimport { gestures } from './gestures'\n\nexport { DEFAULT_DOCUMENT, ensureHeader, hasSizeHeader, hasTimelineHeader, type DocumentSpec } from './document'\nexport { ident, isIdent } from './ident'\nexport { gestures, sugarCard, type GestureOptions } from './gestures'\nexport { BLANK, GREYBOX, ROLES, type Role, type Theme } from './theme'\n\n/**\n * What a gesture parsed out of the author's block, beside the DSL it wrote.\n *\n * A host needs this. The expansion deliberately carries no text a host can read back — the prompt is the\n * learner's instruction and the payloads are indices (`send \"correct\", { item = 2 }`), so without the\n * labels there is nothing to display and nothing to map an index onto. Re-parsing the block by hand to\n * recover data the package already parsed is not an integration; it is a second parser waiting to drift.\n */\nexport type GestureMeta = {\n keyword: string\n /** The block's name. */\n name: string\n /** The learner's instruction, verbatim. Drawn by the host or a theme — never by the gesture. */\n prompt: string\n /** Labels in payload order: `{ item = 2 }` is `items[2]`. */\n items: string[]\n /** Target labels, in the order they were declared. Empty when the gesture has none. */\n targets: string[]\n}\n\n/** What a gesture returns: the DSL, and what it understood. */\nexport type Expansion = { flatink: string; meta: GestureMeta }\n\n/** A sugar block: the keyword that opens it, and how it expands. */\nexport type Gesture = {\n /** The opening keyword, e.g. `place`. Matched only at column 0, followed by a name and `{`. */\n keyword: string\n /** One line, for diagnostics and for the reference a model is prompted with. */\n summary: string\n /** `body` is the text between the braces; `name` the block's name. */\n expand: (name: string, body: string, doc: DocumentSpec) => Expansion\n}\n\nexport type DesugarOptions = {\n /** The canvas + timeline the expansion targets. */\n document?: DocumentSpec\n /** Gestures to recognise. Defaults to the registered set. */\n gestures?: Gesture[]\n}\n\nexport type DesugarResult = {\n /** The expanded (or passed-through) FlatInk. */\n flatink: string\n /** Which gesture matched — `raw` for an escape-only source, `null` for plain FlatInk. */\n kind: string | null\n expanded: boolean\n /** What the gesture understood: the prompt and the labels behind the payload indices. `null` when\n * nothing was expanded, since there is no block to have understood anything from. */\n meta: GestureMeta | null\n}\n\n/** Raised when a source opens a block that looks like sugar but no gesture claims it. */\nexport class UnknownSugarError extends Error {\n constructor(readonly keyword: string, known: string[]) {\n super(\n `unknown sugar block \"${keyword}\" — no gesture claims it, so nothing was expanded. ` +\n `Known blocks: ${known.length ? known.join(', ') : '(none registered)'}. ` +\n `If this is meant to be plain FlatInk, it is not: \"${keyword}\" is not a FlatInk statement either.`,\n )\n this.name = 'UnknownSugarError'\n }\n}\n\n/** The gestures this package ships, drawn by the default theme. Each entry is a public promise. */\nexport const GESTURES: Gesture[] = gestures()\n\n/** A block opens at column 0: `<keyword> <name> {`. The name may be quoted (so it can hold spaces). */\nconst BLOCK_OPEN = /^([a-zA-Z][\\w-]*)[ \\t]+(?:\"([^\"]+)\"|([^\\s{\"]+))[ \\t]*\\{/m\n\n/**\n * The escape hatch, in three forms. A sugar that cannot be opted out of stops being scaffolding and\n * becomes a cage: the previous generation of this idea flattened every activity into the same shape\n * until the template was pulled apart. Anything a gesture writes must remain writable by hand, beside it.\n *\n * raw { … } verbatim at TOP LEVEL — header (`asset`, `var`, `fn`) and `object` blocks\n * raw scene { … } verbatim inside the generated scene, ON TOP of it — banners, overlays\n * raw scene under { … } verbatim inside the generated scene, UNDERNEATH it — backgrounds\n *\n * `under` is not a nicety. A gesture emits no appearance by design, so a background is the FIRST thing\n * any skin needs — and spliced on top, an opaque full-canvas rect hides the entire activity while\n * `checkProgram` reports a clean program. Ten activities shipped that way, read as broken assets.\n */\nconst RAW_OPEN = /^raw(?:[ \\t]+scene(?:[ \\t]+(under))?)?[ \\t]*\\{/gm\n\ntype RawParts = { top: string[]; over: string[]; under: string[]; rest: string }\n\n/**\n * Pull every `raw …` block out of `text`. Brace-counted rather than line-anchored, so the one-line form\n * works — the README and `sugarCard()` both write `raw { … }` on one line, and a regex demanding a\n * newline after `{` left the keyword to travel on to the compiler, which reported `unexpected statement\n * \"raw\"`: a sugar defect described in FlatInk's vocabulary, the very thing `UnknownSugarError` fixed.\n */\nfunction takeRaw(text: string): RawParts {\n const out: RawParts = { top: [], over: [], under: [], rest: '' }\n let cursor = 0\n RAW_OPEN.lastIndex = 0\n for (let m = RAW_OPEN.exec(text); m; m = RAW_OPEN.exec(text)) {\n const openBrace = m.index + m[0].length - 1\n const end = blockEnd(text, openBrace)\n if (end < 0) break // unbalanced: leave it alone, the compiler will say so\n const body = text.slice(openBrace + 1, end).replace(/^\\r?\\n/, '').replace(/\\r?\\n[ \\t]*$/, '')\n const bucket = m[0].includes('scene') ? (m[1] ? out.under : out.over) : out.top\n bucket.push(body)\n out.rest += text.slice(cursor, m.index)\n cursor = end + 1\n RAW_OPEN.lastIndex = cursor\n }\n out.rest += text.slice(cursor)\n return out\n}\n\n/** Index of the `}` closing the brace at `openBrace`, or -1 if unbalanced. */\nfunction blockEnd(text: string, openBrace: number): number {\n let depth = 1\n for (let i = openBrace + 1; i < text.length; i++) {\n if (text[i] === '{') depth++\n else if (text[i] === '}' && --depth === 0) return i\n }\n return -1\n}\n\nconst RAW_NOTE = '// -- raw (escape hatch: verbatim FlatInk) --'\n\n/** Splice verbatim bodies into the generated `scene`: `under` first (drawn behind), `over` last. */\nfunction spliceIntoScene(flatink: string, under: string[], over: string[]): string {\n if (!under.length && !over.length) return flatink\n const at = flatink.search(/^scene[ \\t]*\\{/m)\n if (at < 0) throw new Error('`raw scene { … }` has nowhere to go: this expansion emits no `scene` block — use a plain `raw { … }` instead.')\n const openBrace = flatink.indexOf('{', at)\n const close = blockEnd(flatink, openBrace)\n const head = under.length ? `\\n // -- raw scene under (verbatim, drawn BEHIND the gesture) --\\n${under.join('\\n')}` : ''\n const tail = over.length ? ` // -- raw scene (verbatim, drawn ON TOP of the gesture) --\\n${over.join('\\n')}\\n` : ''\n return `${flatink.slice(0, openBrace + 1)}${head}${flatink.slice(openBrace + 1, close)}${tail}${flatink.slice(close)}`\n}\n\n/** Raised when a source holds more than one gesture block. */\nexport class MultipleGesturesError extends Error {\n constructor(first: string, second: string) {\n super(\n `two gesture blocks in one source (\"${first}\" and \"${second}\") — a document holds ONE. Each gesture ` +\n 'emits its own `scene`, and a program may only have one, so the second cannot be merged in. ' +\n 'Split them into two documents, or write the extra part by hand in `raw { … }` / `raw scene { … }`.',\n )\n this.name = 'MultipleGesturesError'\n }\n}\n\n/**\n * Expand a sugar source into `.flatink`.\n *\n * Plain FlatInk passes through untouched. A source whose first block matches no gesture RAISES rather\n * than passing through: a silent fall-through sent the author's block downstream as if it were FlatInk,\n * to fail a hundred lines later on messages that only talk about FlatInk.\n *\n * ```ts\n * import { desugar } from '@flatkit/sugarflat'\n * import { checkProgram } from '@flatkit/compiler'\n *\n * const { flatink } = desugar(srcFromAnLLM)\n * const { ok, report } = checkProgram(flatink) // the expansion is the artefact of record\n * ```\n */\nexport function desugar(src: string, opts: DesugarOptions = {}): DesugarResult {\n const doc = opts.document ?? DEFAULT_DOCUMENT\n const gestures = opts.gestures ?? GESTURES\n\n const open = BLOCK_OPEN.exec(src)\n const keyword = open?.[1]\n const gesture = keyword ? gestures.find((g) => g.keyword === keyword) : undefined\n\n if (gesture) {\n const name = open?.[2] ?? open?.[3] ?? gesture.keyword\n const braceAt = open!.index + open![0].length - 1\n const body = blockBody(src, braceAt)\n // Everything OUTSIDE the block travels with the expansion. Dropping it made the escape hatch — the\n // one guard-rail this package rests on — a no-op beside a gesture: an author wrote decor, the\n // expansion compiled, `checkProgram` said ok, and nothing was there.\n const before = src.slice(0, open!.index)\n const after = src.slice(braceAt + 1 + body.length + 1)\n const other = findGesture(before + '\\n' + after, gestures)\n if (other) throw new MultipleGesturesError(gesture.keyword, other)\n\n const { flatink, meta } = gesture.expand(name, body, doc)\n const head = takeRaw(before)\n const tail = takeRaw(after)\n const expanded = spliceIntoScene(flatink, [...head.under, ...tail.under], [...head.over, ...tail.over])\n const topLevel = (p: RawParts) => [p.rest.trim(), ...(p.top.length ? [RAW_NOTE, ...p.top] : [])].filter(Boolean).join('\\n')\n const whole = [topLevel(head), expanded, topLevel(tail)].filter(Boolean).join('\\n\\n')\n return { flatink: ensureHeader(whole, doc), kind: gesture.keyword, expanded: true, meta }\n }\n // A keyword that opens a block at column 0 and is NOT a FlatInk statement is a sugar block we do not\n // know — never a program. Say so here, with the list, rather than downstream in another vocabulary.\n // `raw` is this package's own keyword, handled below.\n if (keyword && keyword !== 'raw' && !FLATINK_BLOCKS.has(keyword)) throw new UnknownSugarError(keyword, gestures.map((g) => g.keyword))\n\n // No gesture: plain FlatInk, plus any `raw { … }` the author used on its own. `raw scene` has no\n // generated scene to splice into here, so it would silently vanish — say so instead.\n const parts = takeRaw(src)\n if (parts.over.length || parts.under.length) {\n throw new Error('`raw scene { … }` needs a gesture block to splice into — this source has none. Write a plain `scene { … }` yourself.')\n }\n const out = [parts.rest.trim(), ...(parts.top.length ? [RAW_NOTE, ...parts.top] : [])].filter(Boolean).join('\\n')\n return { flatink: parts.top.length ? out : src, kind: parts.top.length ? 'raw' : null, expanded: parts.top.length > 0, meta: null }\n}\n\n/** Block keywords that belong to FlatINK itself — a source opening with one of these is a program. */\nconst FLATINK_BLOCKS = new Set(['scene', 'object', 'symbol', 'layer', 'group', 'match', 'each', 'states', 'params', 'when', 'every', 'repeat', 'fn', 'at'])\n\n/** The keyword of the first gesture block in `text`, if any — used to refuse a second one loudly. */\nfunction findGesture(text: string, gestures: Gesture[]): string | null {\n const re = new RegExp(BLOCK_OPEN.source, 'gm')\n for (let m = re.exec(text); m; m = re.exec(text)) {\n if (gestures.some((g) => g.keyword === m![1])) return m[1]\n }\n return null\n}\n\n/** Text between the braces opened at `openIndex`, brace-counting so nested blocks survive. */\nfunction blockBody(src: string, openIndex: number): string {\n let depth = 1\n let i = openIndex + 1\n for (; i < src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EAAG,QAAO,EAAE,CAAC;AAAA,EAC3D;AACA,SAAO;AACT;AAGA,SAAS,UAAU,KAAa,WAA2B;AACzD,MAAI,QAAQ;AACZ,MAAI,IAAI,YAAY;AACpB,SAAO,IAAI,IAAI,UAAU,QAAQ,GAAG,KAAK;AACvC,QAAI,IAAI,CAAC,MAAM,IAAK;AAAA,aACX,IAAI,CAAC,MAAM,IAAK;AAAA,EAC3B;AACA,SAAO,IAAI,MAAM,YAAY,GAAG,UAAU,IAAI,IAAI,IAAI,IAAI,MAAM;AAClE;","names":["gestures"]}
1
+ {"version":3,"sources":["../src/document.ts","../src/ident.ts","../src/theme.ts","../src/gestures.ts","../src/index.ts"],"sourcesContent":["// ─────────────────────────────────────────────────────────────────────────────\n// document.ts — the document a sugar block expands into.\n//\n// Two things a sugar MUST know and an author MUST be able to read: the canvas the gesture is laid out\n// for, and the timeline it rides. Both were literals buried inside an expander, which cost twice:\n// • the expansion never emitted `size` at all, so it fell back on the compiler's 800x600 default\n// while the board was painted for 760x620 -- everything past x=760 was clipped in silence, on the\n// whole corpus, for months (nothing says so: a missing `size` still compiles);\n// • prompting a model for the right coordinates meant reading the generator's source.\n// Exposed here, overridable per call, and stamped onto every expansion by `ensureHeader`.\n// ─────────────────────────────────────────────────────────────────────────────\n\n/** The canvas + timeline a sugar block expands into. */\nexport type DocumentSpec = {\n width: number\n height: number\n fps: number\n /** Timeline length. Long enough that `time` does not wrap mid-activity (the compiler warns under 120). */\n durationFrames: number\n}\n\n/** The board the gestures are laid out for. Override per call when a host uses another canvas. */\nexport const DEFAULT_DOCUMENT: DocumentSpec = { width: 760, height: 620, fps: 24, durationFrames: 120 }\n\n/** `true` if the source already declares its canvas — `size` must be the FIRST statement of a program. */\nexport const hasSizeHeader = (src: string): boolean => /^[ \\t]*size\\s+-?[\\d.]+\\s+-?[\\d.]+/m.test(src)\n\n/** `true` if the source already declares a root timeline. */\nexport const hasTimelineHeader = (src: string): boolean => /^[ \\t]*timeline\\s+\\d+/m.test(src)\n\n/**\n * Prepend whatever header the expansion is missing. `size` is REQUIRED by the format and silently\n * defaulted by the compiler when absent, so emitting it is not a nicety: it is the difference between\n * the document the author designed and the one that gets drawn.\n */\nexport function ensureHeader(flatink: string, doc: DocumentSpec = DEFAULT_DOCUMENT): string {\n const head: string[] = []\n if (!hasSizeHeader(flatink)) head.push(`size ${doc.width} ${doc.height}`)\n if (!hasTimelineHeader(flatink)) head.push(`timeline ${doc.fps} ${doc.durationFrames}`)\n return head.length ? `${head.join('\\n')}\\n${flatink}` : flatink\n}\n","// ─────────────────────────────────────────────────────────────────────────────\n// ident.ts — a human label -> a FlatInk identifier.\n//\n// A sugar lets an author name things in their own language (\"chene\", \"Vegetaux\", \"21 janvier 1793\"),\n// and those names become identifiers (`var`, `object`). FlatInk identifiers are `[A-Za-z0-9_]`, so an\n// accent does not error -- the lexer stops at it and reads the tail. `chene` written with its accent\n// became `var <accented>X`, read as `neX`: two variables where the author wrote one, and no diagnostic.\n// Transliterate here, once, rather than in every gesture.\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * A FlatInk identifier derived from a human label: accents folded to ASCII, anything else to `_`, and\n * a leading digit prefixed (an identifier may not start with one). Stable and idempotent, so the same\n * label always yields the same name — the sugar's variables and the author's references must agree.\n */\nexport function ident(label: string): string {\n const ascii = label.normalize('NFD').replace(/\\p{Diacritic}/gu, '').replace(/[^A-Za-z0-9_]/g, '_')\n return /^[0-9]/.test(ascii) ? `n${ascii}` : ascii\n}\n\n/** `true` if the label survives `ident` unchanged — i.e. it is already a usable identifier. */\nexport const isIdent = (label: string): boolean => ident(label) === label && label.length > 0\n","// ─────────────────────────────────────────────────────────────────────────────\n// theme.ts — where appearance lives, so that gestures do not carry any.\n//\n// A gesture emits STRUCTURE and BEHAVIOR: named groups at the coordinates the author gave, their drop\n// boxes, their state, their handlers. It must never decide what any of it LOOKS like — a sugar that\n// ships a look hands every activity built on it the same face, and that has already happened once.\n//\n// So appearance is a parameter. `BLANK` draws nothing at all, which is what makes the claim testable\n// rather than aspirational: expand a gesture with `BLANK` and the output must not contain one colour,\n// one font, or one stroke. `GREYBOX` is a deliberately plain default so a freshly written block is\n// playable immediately — it is provisional by design, and swapping it is a single argument.\n// ─────────────────────────────────────────────────────────────────────────────\n\n/** What a drawn thing is FOR. Four roles cover every gesture; a theme need not distinguish more. */\nexport type Role =\n | 'item' // something the learner moves\n | 'target' // where an item belongs\n | 'card' // a panel the learner reads and taps\n | 'chip' // a small tappable value\n\nexport type Theme = {\n readonly name: string\n /** Footprint of a role. The gesture uses it for drop boxes; the theme must draw within it. */\n size(role: Role): { w: number; h: number }\n /** Drawing statements for a role, in LOCAL coordinates centred on 0,0. May be empty. */\n draw(role: Role, label: string): string[]\n}\n\n/** Every role, in a stable order — for a reference card, or to sweep a theme. */\nexport const ROLES: Role[] = ['item', 'target', 'card', 'chip']\n\nconst SIZES: Record<Role, { w: number; h: number }> = {\n item: { w: 92, h: 92 },\n target: { w: 208, h: 118 },\n card: { w: 180, h: 140 },\n chip: { w: 96, h: 96 },\n}\n\n/**\n * Draws nothing. The gesture still emits every group, every box and every handler, so an author (or a\n * skin) supplies the whole appearance — and the test suite uses it to prove the gestures themselves\n * carry no visual opinion.\n */\nexport const BLANK: Theme = {\n name: 'blank',\n size: (role) => SIZES[role],\n draw: () => [],\n}\n\n/** Rounded rectangle path, centred on the origin — the greybox's only shape vocabulary. */\nconst plate = (w: number, h: number, r: number): string => `rect ${-w / 2} ${-h / 2} ${w} ${h} ${r}`\n\n/**\n * A plain, provisional greybox: readable, anonymous, and meant to be replaced. It exists so `place x {\n * … }` is playable the moment it is written; it is not a design, and anything built for an audience\n * should pass its own theme (or redraw beside the gesture with `raw { … }`).\n */\nexport const GREYBOX: Theme = {\n name: 'greybox',\n size: (role) => SIZES[role],\n draw(role, label) {\n const { w, h } = SIZES[role]\n const text = (size: number, boxW: number, boxH: number, colour: string, y: number) =>\n `text \"${label.replace(/\"/g, \"'\")}\" at ${-boxW / 2},${y} font \"system-ui, sans-serif\" size ${size} align center line 1.2 color ${colour} box ${boxW} ${boxH} wrap`\n switch (role) {\n case 'item':\n return [`circle 0 0 ${w / 2 - 12} fill #e8c46b`, `circle 0 0 ${w / 2 - 12} nofill stroke #b8923f 2`, text(14, w - 8, 20, '#4a3a1e', -9)]\n case 'target':\n return [`${plate(w - 8, h - 8, 14)} fill #2e3a4e`, `${plate(w - 8, h - 8, 14)} nofill stroke #5a6f8a 2 dash 8,6`, text(16, w - 28, 22, '#aeb6c4', -h / 2 + 10)]\n case 'card':\n return [`${plate(w, h, 16)} fill #2b3447`, `${plate(w, h, 16)} nofill stroke #44516a 2`, text(15, w - 20, h - 40, '#d7deea', -h / 2 + 26)]\n case 'chip':\n return [`circle 0 0 ${w / 2 - 8} fill #e8c46b`, `circle 0 0 ${w / 2 - 8} nofill stroke #b8923f 3`, text(22, w - 16, 28, '#4a3a1e', -13)]\n }\n },\n}\n","// ─────────────────────────────────────────────────────────────────────────────\n// gestures.ts — the three primitives.\n//\n// Five named gestures came in (`tri`, `ordonner`, `placement`, `composer`, `etapes`). Read side by\n// side, the first three share ONE implementation: the only thing that differed between them was which\n// shape their targets were drawn as -- rectangles, squares or dotted discs. That is appearance, and\n// appearance is now the theme's business, so they collapse into a single `place`. Five public promises\n// became three.\n//\n// Each gesture emits state, structure and behavior. Not one colour, not one font: `BLANK` proves it.\n// Coordinates DO appear, and that is not an opinion -- they are the ones the author wrote in the block.\n// ─────────────────────────────────────────────────────────────────────────────\nimport type { Expansion, Gesture } from './index'\nimport { ident } from './ident'\nimport { GREYBOX, ROLES, type Role, type Theme } from './theme'\n\n/** Everything a gesture needs beyond the author's text. */\nexport type GestureOptions = { theme?: Theme }\n\nconst q = (s: string) => s.replace(/\"/g, \"'\")\n\n/** Statements of a named group placed at `x,y`, drawn by the theme, optionally a drop box. */\nfunction container(name: string, x: string, y: string, art: string[], hitbox?: { w: number; h: number }): string[] {\n const box = hitbox ? ` hitbox ${hitbox.w} ${hitbox.h}` : ''\n return [` group \"${name}\" at ${x},${y} pivot 0,0${box} {`, ' layer \"art\" {', ...art.map((l) => ` ${l}`), ' }', ' }']\n}\n\n/** Split a block body into its non-empty, comment-free lines. */\nconst lines = (body: string): string[] => body.split('\\n').map((l) => l.replace(/\\/\\/.*$/, '').trim()).filter(Boolean)\n\n// ── place ────────────────────────────────────────────────────────────────────\n// The drop gesture: items belong on targets. Several items may share a target (a sort) or each may have\n// its own (an ordering, a labelled diagram) -- that falls out of the data, it is not a separate gesture.\n\ntype PlaceModel = {\n prompt: string\n targets: { id: string; label: string; x: string; y: string }[]\n items: { id: string; label: string; target: string; x: string; y: string }[]\n}\n\nfunction parsePlace(name: string, body: string): PlaceModel {\n const m: PlaceModel = { prompt: '', targets: [], items: [] }\n for (const line of lines(body)) {\n let x: RegExpMatchArray | null\n if ((x = line.match(/^prompt\\s+\"(.*)\"$/))) m.prompt = x[1]\n else if ((x = line.match(/^target\\s+(?:\"([^\"]+)\"|(\\S+))\\s+at\\s+(-?[\\d.]+),(-?[\\d.]+)$/))) {\n const label = x[1] ?? x[2]\n m.targets.push({ id: `T${ident(label)}`, label, x: x[3], y: x[4] })\n } else if ((x = line.match(/^item\\s+(?:\"([^\"]+)\"|(\\S+))\\s*->\\s*(?:\"([^\"]+)\"|(\\S+))\\s+at\\s+(-?[\\d.]+),(-?[\\d.]+)$/))) {\n const label = x[1] ?? x[2]\n m.items.push({ id: `I${ident(label)}`, label, target: `T${ident(x[3] ?? x[4])}`, x: x[5], y: x[6] })\n } else throw new Error(`place \"${name}\": unrecognised line: ${line}`)\n }\n if (!m.targets.length) throw new Error(`place \"${name}\": no target — an item has nowhere to go`)\n if (!m.items.length) throw new Error(`place \"${name}\": no item — nothing for the learner to do`)\n const known = new Set(m.targets.map((t) => t.id))\n for (const it of m.items) {\n if (!known.has(it.target)) throw new Error(`place \"${name}\": item \"${it.label}\" points at an unknown target`)\n }\n return m\n}\n\nfunction expandPlace(name: string, body: string, theme: Theme): Expansion {\n const m = parsePlace(name, body)\n const n = m.items.length\n const out: string[] = [`// place \"${q(name)}\" — generated. The expansion is the artefact of record: edit it, or edit the block.`]\n if (m.prompt) out.push(`// prompt: ${q(m.prompt)}`)\n\n out.push('var progress = 0', 'var done = 0')\n for (const it of m.items) out.push(`var ${it.id}X = ${it.x}`, `var ${it.id}Y = ${it.y}`, `var ${it.id}Placed = 0`)\n\n out.push('', 'scene {', ' layer \"targets\" {')\n for (const t of m.targets) out.push(...container(t.id, t.x, t.y, theme.draw('target', t.label), theme.size('target')))\n out.push(' }', ' layer \"items\" {')\n for (const it of m.items) out.push(...container(it.id, it.x, it.y, theme.draw('item', it.label)))\n out.push(' }', '}', '')\n\n m.items.forEach((it, i) => {\n out.push(`object \"${it.id}\" {`)\n out.push(` drag ${it.id}X, ${it.id}Y { enabled ${it.id}Placed == 0 }`)\n out.push(` when dropped on ${it.target} at pointer {`)\n out.push(` if ${it.id}Placed < 0.5 {`)\n out.push(` ${it.id}Placed = 1`, ' progress = progress + 1')\n // Snap onto the target it was dropped on, reading the target's LIVE position -- so a skin may move\n // the target anywhere and the item still lands on it.\n out.push(` ${it.id}X = ${it.target}.x`, ` ${it.id}Y = ${it.target}.y`)\n out.push(` send \"correct\", { item = ${i} }`)\n out.push(` if progress == ${n} {`, ' done = 1', ' send \"completed\"', ' }')\n out.push(' }', ' }')\n for (const t of m.targets) {\n if (t.id === it.target) continue\n out.push(` when dropped on ${t.id} at pointer {`)\n out.push(` ${it.id}X = ${it.x}`, ` ${it.id}Y = ${it.y}`) // back where it started\n out.push(` send \"incorrect\", { item = ${i} }`)\n out.push(' }')\n }\n out.push(` x = ${it.id}X`, ` y = ${it.id}Y`, '}', '')\n })\n return {\n flatink: out.join('\\n'),\n meta: { keyword: 'place', name, prompt: m.prompt, items: m.items.map((i) => i.label), targets: m.targets.map((t) => t.label) },\n }\n}\n\n// ── compose ──────────────────────────────────────────────────────────────────\n// Tap values until they add up to a target. Overshooting resets the total -- the whole point of the\n// exercise is that going over is a mistake you feel, not one you are prevented from making.\n\nfunction expandCompose(name: string, body: string, theme: Theme): Expansion {\n let target = 0\n const chips: { value: string; x: string; y: string }[] = []\n let prompt = ''\n for (const line of lines(body)) {\n let x: RegExpMatchArray | null\n if ((x = line.match(/^prompt\\s+\"(.*)\"$/))) prompt = x[1]\n else if ((x = line.match(/^total\\s+(\\d+)$/))) target = Number(x[1])\n else if ((x = line.match(/^chip\\s+(\\d+)\\s+at\\s+(-?[\\d.]+),(-?[\\d.]+)$/))) chips.push({ value: x[1], x: x[2], y: x[3] })\n else throw new Error(`compose \"${name}\": unrecognised line: ${line}`)\n }\n if (!target) throw new Error(`compose \"${name}\": no \\`total <n>\\` — there is nothing to reach`)\n if (!chips.length) throw new Error(`compose \"${name}\": no chip — nothing for the learner to tap`)\n\n const out: string[] = [`// compose \"${q(name)}\" — generated.`, ...(prompt ? [`// prompt: ${q(prompt)}`] : []), 'var total = 0', 'var done = 0', '', 'scene {', ' layer \"chips\" {']\n chips.forEach((c, i) => out.push(...container(`C${i}`, c.x, c.y, theme.draw('chip', c.value), theme.size('chip'))))\n out.push(' }', '}', '')\n chips.forEach((c, i) => {\n out.push(`object \"C${i}\" {`, ' when clicked {', ' if done < 0.5 {')\n out.push(` if total + ${c.value} > ${target} {`)\n out.push(' total = 0', ` send \"incorrect\", { chip = ${i} }`)\n out.push(' } else {')\n out.push(` total = total + ${c.value}`, ` send \"correct\", { chip = ${i} }`)\n out.push(` if total == ${target} {`, ' done = 1', ' send \"completed\"', ' }')\n out.push(' }', ' }', ' }', '}', '')\n })\n return { flatink: out.join('\\n'), meta: { keyword: 'compose', name, prompt, items: chips.map((c) => c.value), targets: [] } }\n}\n\n// ── steps ────────────────────────────────────────────────────────────────────\n// A gated sequence: step i only responds when it is the current one. Tapping out of order does nothing\n// at all -- no error, no penalty, which is what makes it usable as an escape-room stage.\n\nfunction expandSteps(name: string, body: string, theme: Theme): Expansion {\n let prompt = ''\n const steps: { label: string; x: string; y: string }[] = []\n for (const line of lines(body)) {\n let x: RegExpMatchArray | null\n if ((x = line.match(/^prompt\\s+\"(.*)\"$/))) prompt = x[1]\n else if ((x = line.match(/^step\\s+\"(.*)\"\\s+at\\s+(-?[\\d.]+),(-?[\\d.]+)$/))) steps.push({ label: x[1], x: x[2], y: x[3] })\n else throw new Error(`steps \"${name}\": unrecognised line: ${line}`)\n }\n if (!steps.length) throw new Error(`steps \"${name}\": no step — the sequence is empty`)\n\n const out: string[] = [`// steps \"${q(name)}\" — generated.`, ...(prompt ? [`// prompt: ${q(prompt)}`] : []), 'var step = 0', '', 'scene {', ' layer \"steps\" {']\n steps.forEach((s, i) => out.push(...container(`S${i}`, s.x, s.y, theme.draw('card', s.label), theme.size('card'))))\n out.push(' }', '}', '')\n steps.forEach((_s, i) => {\n out.push(`object \"S${i}\" {`, ' when clicked {', ` if step == ${i} {`, ` step = step + 1`, ` send \"step\", { index = ${i} }`)\n if (i === steps.length - 1) out.push(' send \"completed\"')\n out.push(' }', ' }')\n // The only thing the gesture says about looks: a step that is not current is dimmed, because\n // \"which one is live\" is STATE, not decoration. A theme that disagrees rebinds opacity itself.\n out.push(` opacity = step == ${i} ? 1 : 0.45`, '}', '')\n })\n return { flatink: out.join('\\n'), meta: { keyword: 'steps', name, prompt, items: steps.map((s2) => s2.label), targets: [] } }\n}\n\n/** `208x118` — the footprint of a role under a theme, for a summary or a prompt. */\nconst footprint = (theme: Theme, role: Role): string => {\n const { w, h } = theme.size(role)\n return `${w}x${h}`\n}\n\n/**\n * Build the shipped gestures against a theme. `GREYBOX` unless the caller supplies one.\n *\n * Each `summary` carries the FOOTPRINTS of the roles it places, because the author writes positions and\n * two overlapping surfaces make a drop ambiguous. Measured on ten model-written activities: a prompt\n * giving only \"space them out\" produced overlapping hitboxes in 4 of 10; the same prompt with the\n * numbers, 0 of 10. The sizes were public all along — nothing said you had to go and read them.\n */\nexport function gestures(opts: GestureOptions = {}): Gesture[] {\n const theme = opts.theme ?? GREYBOX\n return [\n {\n keyword: 'place',\n summary: `place <name> { prompt \"…\" target <T> at x,y item <i> -> <T> at x,y } — drag items onto where they belong. Footprints: target ${footprint(theme, 'target')}, item ${footprint(theme, 'item')}; keep centres at least one footprint apart or the drop is ambiguous`,\n expand: (name, body) => expandPlace(name, body, theme),\n },\n {\n keyword: 'compose',\n summary: `compose <name> { prompt \"…\" total <n> chip <v> at x,y } — tap values until they add up; overshooting resets. Footprint: chip ${footprint(theme, 'chip')}`,\n expand: (name, body) => expandCompose(name, body, theme),\n },\n {\n keyword: 'steps',\n summary: `steps <name> { prompt \"…\" step \"…\" at x,y } — a gated sequence; out-of-order taps do nothing. Footprint: card ${footprint(theme, 'card')}`,\n expand: (name, body) => expandSteps(name, body, theme),\n },\n ]\n}\n\n/**\n * The paste-ready reference for a model writing sugar: the grammar of every gesture, the footprints it\n * must respect, and the canvas it is laying out on. This is the artefact `summary` was being used as by\n * hand — assembled here so nobody has to know that the sizes live on the theme.\n */\nexport function sugarCard(opts: GestureOptions & { document?: { width: number; height: number } } = {}): string {\n const theme = opts.theme ?? GREYBOX\n const doc = opts.document ?? { width: 760, height: 620 }\n return [\n '# FlatInk sugar — one block, one activity',\n '',\n `Canvas: ${doc.width}x${doc.height}, origin top-left. Write ONE block, nothing else. Coordinates are the`,\n 'CENTRE of each thing. Anything you do not describe is not drawn.',\n '',\n '## Blocks',\n ...gestures({ theme }).map((g) => `- ${g.summary}`),\n '',\n '## Footprints — respect them or two things overlap and the drop becomes ambiguous',\n ...ROLES.map((role) => `- ${role}: ${footprint(theme, role)}`),\n '',\n `A row of targets fits about ${Math.floor(doc.width / (theme.size('target').w + 20))} across; a row of items about ${Math.floor(doc.width / (theme.size('item').w + 20))}.`,\n 'Leave a gap the size of the thing itself between two centres.',\n '',\n '## Escape hatch — three forms, and they are not interchangeable',\n 'The block draws NOTHING beyond the pieces above. Everything else goes through one of these:',\n '',\n 'raw scene under { layer \"bg\" { … } } <- BACKGROUND and decor. Drawn BEHIND the activity.',\n 'raw scene { layer \"banner\" { … } } <- overlays drawn ON TOP: a title, a frame, a caption.',\n 'raw { var lives = 3 object \"X\" { … } } <- header and behavior: var, fn, asset, object blocks.',\n '',\n 'A `layer` written in a plain `raw { … }` lands OUTSIDE the scene and is a compile error — anything',\n 'that is drawn belongs in one of the two `raw scene` forms. Either may be written on one line.',\n ].join('\\n')\n}\n","// ─────────────────────────────────────────────────────────────────────────────\n// @flatkit/sugarflat — declarative sugar for FlatInk.\n//\n// A compact block expands into INSPECTABLE `.flatink`. The expansion is the artefact of record: the\n// sugar is an authoring tool, never a runtime, and anything it writes can be written by hand instead.\n//\n// WHY IT LIVES IN THIS REPO. Not to put authoring opinions into the language — it is a separate\n// package, out of the lockstep group, and `@flatkit/compiler` never depends on it. It lives here so\n// the two move together: a grammar change breaks these tests in the same CI run. That is the whole\n// argument, and it was demonstrated rather than argued — the previous out-of-tree sugar never emitted\n// the format's REQUIRED `size` line, on its entire corpus, for months, unnoticed.\n//\n// THE LINE THIS PACKAGE DOES NOT CROSS: no visual opinion. A gesture emits state and behavior; it\n// never emits a coordinate, a colour or a font. The language already ships interaction opinions\n// (`drag`, `when dropped on … at pointer`, `hitbox`, `match`, `feedback`, `spring`) — what it has\n// never shipped is a look, and a sugar that shipped one would hand every activity the same face.\n// ─────────────────────────────────────────────────────────────────────────────\nimport { DEFAULT_DOCUMENT, ensureHeader, type DocumentSpec } from './document'\nimport { gestures } from './gestures'\n\nexport { DEFAULT_DOCUMENT, ensureHeader, hasSizeHeader, hasTimelineHeader, type DocumentSpec } from './document'\nexport { ident, isIdent } from './ident'\nexport { gestures, sugarCard, type GestureOptions } from './gestures'\nexport { BLANK, GREYBOX, ROLES, type Role, type Theme } from './theme'\n\n/**\n * What a gesture parsed out of the author's block, beside the DSL it wrote.\n *\n * A host needs this. The expansion deliberately carries no text a host can read back — the prompt is the\n * learner's instruction and the payloads are indices (`send \"correct\", { item = 2 }`), so without the\n * labels there is nothing to display and nothing to map an index onto. Re-parsing the block by hand to\n * recover data the package already parsed is not an integration; it is a second parser waiting to drift.\n */\nexport type GestureMeta = {\n keyword: string\n /** The block's name. */\n name: string\n /** The learner's instruction, verbatim. Drawn by the host or a theme — never by the gesture. */\n prompt: string\n /** Labels in payload order: `{ item = 2 }` is `items[2]`. */\n items: string[]\n /** Target labels, in the order they were declared. Empty when the gesture has none. */\n targets: string[]\n}\n\n/** What a gesture returns: the DSL, and what it understood. */\nexport type Expansion = { flatink: string; meta: GestureMeta }\n\n/** A sugar block: the keyword that opens it, and how it expands. */\nexport type Gesture = {\n /** The opening keyword, e.g. `place`. Matched only at column 0, followed by a name and `{`. */\n keyword: string\n /** One line, for diagnostics and for the reference a model is prompted with. */\n summary: string\n /** `body` is the text between the braces; `name` the block's name. */\n expand: (name: string, body: string, doc: DocumentSpec) => Expansion\n}\n\nexport type DesugarOptions = {\n /** The canvas + timeline the expansion targets. */\n document?: DocumentSpec\n /** Gestures to recognise. Defaults to the registered set. */\n gestures?: Gesture[]\n}\n\nexport type DesugarResult = {\n /** The expanded (or passed-through) FlatInk. */\n flatink: string\n /** Which gesture matched — `raw` for an escape-only source, `null` for plain FlatInk. */\n kind: string | null\n expanded: boolean\n /** What the gesture understood: the prompt and the labels behind the payload indices. `null` when\n * nothing was expanded, since there is no block to have understood anything from. */\n meta: GestureMeta | null\n}\n\n/** Raised when a source opens a block that looks like sugar but no gesture claims it. */\nexport class UnknownSugarError extends Error {\n constructor(readonly keyword: string, known: string[]) {\n super(\n `unknown sugar block \"${keyword}\" — no gesture claims it, so nothing was expanded. ` +\n `Known blocks: ${known.length ? known.join(', ') : '(none registered)'}. ` +\n `If this is meant to be plain FlatInk, it is not: \"${keyword}\" is not a FlatInk statement either.`,\n )\n this.name = 'UnknownSugarError'\n }\n}\n\n/** The gestures this package ships, drawn by the default theme. Each entry is a public promise. */\nexport const GESTURES: Gesture[] = gestures()\n\n/** A block opens at column 0: `<keyword> <name> {`. The name may be quoted (so it can hold spaces). */\nconst BLOCK_OPEN = /^([a-zA-Z][\\w-]*)[ \\t]+(?:\"([^\"]+)\"|([^\\s{\"]+))[ \\t]*\\{/m\n\n/**\n * The escape hatch, in three forms. A sugar that cannot be opted out of stops being scaffolding and\n * becomes a cage: the previous generation of this idea flattened every activity into the same shape\n * until the template was pulled apart. Anything a gesture writes must remain writable by hand, beside it.\n *\n * raw { … } verbatim at TOP LEVEL — header (`asset`, `var`, `fn`) and `object` blocks\n * raw scene { … } verbatim inside the generated scene, ON TOP of it — banners, overlays\n * raw scene under { … } verbatim inside the generated scene, UNDERNEATH it — backgrounds\n *\n * `under` is not a nicety. A gesture emits no appearance by design, so a background is the FIRST thing\n * any skin needs — and spliced on top, an opaque full-canvas rect hides the entire activity while\n * `checkProgram` reports a clean program. Ten activities shipped that way, read as broken assets.\n */\nconst RAW_OPEN = /^raw(?:[ \\t]+scene(?:[ \\t]+(under))?)?[ \\t]*\\{/gm\n\ntype RawParts = { top: string[]; over: string[]; under: string[]; rest: string }\n\n/**\n * Pull every `raw …` block out of `text`. Brace-counted rather than line-anchored, so the one-line form\n * works — the README and `sugarCard()` both write `raw { … }` on one line, and a regex demanding a\n * newline after `{` left the keyword to travel on to the compiler, which reported `unexpected statement\n * \"raw\"`: a sugar defect described in FlatInk's vocabulary, the very thing `UnknownSugarError` fixed.\n */\nfunction takeRaw(text: string): RawParts {\n const out: RawParts = { top: [], over: [], under: [], rest: '' }\n let cursor = 0\n RAW_OPEN.lastIndex = 0\n for (let m = RAW_OPEN.exec(text); m; m = RAW_OPEN.exec(text)) {\n const openBrace = m.index + m[0].length - 1\n const end = blockEnd(text, openBrace)\n if (end < 0) break // unbalanced: leave it alone, the compiler will say so\n const raw = text.slice(openBrace + 1, end)\n // One-line form (`raw { var x = 1 }`) keeps the spaces that hugged the braces; the multi-line form\n // keeps its own indentation, which is the author's.\n const body = raw.includes('\\n') ? raw.replace(/^\\r?\\n/, '').replace(/\\r?\\n[ \\t]*$/, '') : raw.trim()\n const bucket = m[0].includes('scene') ? (m[1] ? out.under : out.over) : out.top\n bucket.push(body)\n out.rest += text.slice(cursor, m.index)\n cursor = end + 1\n RAW_OPEN.lastIndex = cursor\n }\n out.rest += text.slice(cursor)\n return out\n}\n\n/** Index of the `}` closing the brace at `openBrace`, or -1 if unbalanced. */\nfunction blockEnd(text: string, openBrace: number): number {\n let depth = 1\n for (let i = openBrace + 1; i < text.length; i++) {\n if (text[i] === '{') depth++\n else if (text[i] === '}' && --depth === 0) return i\n }\n return -1\n}\n\nconst RAW_NOTE = '// -- raw (escape hatch: verbatim FlatInk) --'\n\n/** Splice verbatim bodies into the generated `scene`: `under` first (drawn behind), `over` last. */\nfunction spliceIntoScene(flatink: string, under: string[], over: string[]): string {\n if (!under.length && !over.length) return flatink\n const at = flatink.search(/^scene[ \\t]*\\{/m)\n if (at < 0) throw new Error('`raw scene { … }` has nowhere to go: this expansion emits no `scene` block — use a plain `raw { … }` instead.')\n const openBrace = flatink.indexOf('{', at)\n const close = blockEnd(flatink, openBrace)\n const head = under.length ? `\\n // -- raw scene under (verbatim, drawn BEHIND the gesture) --\\n${under.join('\\n')}` : ''\n const tail = over.length ? ` // -- raw scene (verbatim, drawn ON TOP of the gesture) --\\n${over.join('\\n')}\\n` : ''\n return `${flatink.slice(0, openBrace + 1)}${head}${flatink.slice(openBrace + 1, close)}${tail}${flatink.slice(close)}`\n}\n\n/** Raised when a source holds more than one gesture block. */\nexport class MultipleGesturesError extends Error {\n constructor(first: string, second: string) {\n super(\n `two gesture blocks in one source (\"${first}\" and \"${second}\") — a document holds ONE. Each gesture ` +\n 'emits its own `scene`, and a program may only have one, so the second cannot be merged in. ' +\n 'Split them into two documents, or write the extra part by hand in `raw { … }` / `raw scene { … }`.',\n )\n this.name = 'MultipleGesturesError'\n }\n}\n\n/**\n * Expand a sugar source into `.flatink`.\n *\n * Plain FlatInk passes through untouched. A source whose first block matches no gesture RAISES rather\n * than passing through: a silent fall-through sent the author's block downstream as if it were FlatInk,\n * to fail a hundred lines later on messages that only talk about FlatInk.\n *\n * ```ts\n * import { desugar } from '@flatkit/sugarflat'\n * import { checkProgram } from '@flatkit/compiler'\n *\n * const { flatink } = desugar(srcFromAnLLM)\n * const { ok, report } = checkProgram(flatink) // the expansion is the artefact of record\n * ```\n */\nexport function desugar(src: string, opts: DesugarOptions = {}): DesugarResult {\n const doc = opts.document ?? DEFAULT_DOCUMENT\n const gestures = opts.gestures ?? GESTURES\n\n const open = BLOCK_OPEN.exec(src)\n const keyword = open?.[1]\n const gesture = keyword ? gestures.find((g) => g.keyword === keyword) : undefined\n\n if (gesture) {\n const name = open?.[2] ?? open?.[3] ?? gesture.keyword\n const braceAt = open!.index + open![0].length - 1\n const body = blockBody(src, braceAt)\n // Everything OUTSIDE the block travels with the expansion. Dropping it made the escape hatch — the\n // one guard-rail this package rests on — a no-op beside a gesture: an author wrote decor, the\n // expansion compiled, `checkProgram` said ok, and nothing was there.\n const before = src.slice(0, open!.index)\n const after = src.slice(braceAt + 1 + body.length + 1)\n const other = findGesture(before + '\\n' + after, gestures)\n if (other) throw new MultipleGesturesError(gesture.keyword, other)\n\n const { flatink, meta } = gesture.expand(name, body, doc)\n const head = takeRaw(before)\n const tail = takeRaw(after)\n const expanded = spliceIntoScene(flatink, [...head.under, ...tail.under], [...head.over, ...tail.over])\n // Everything top-level goes BEFORE the expansion, wherever the author wrote it. `var` (and `asset`,\n // `use`, `def`) are header declarations and are a parse error after `scene`, while `object`/`fn` are\n // accepted on either side -- so the header position is the only one where all of it is valid. Moving\n // an `object` up changes nothing: behavior binds by name, not by position.\n const topLevel = (p: RawParts) => [p.rest.trim(), ...(p.top.length ? [RAW_NOTE, ...p.top] : [])].filter(Boolean).join('\\n')\n const whole = [topLevel(head), topLevel(tail), expanded].filter(Boolean).join('\\n\\n')\n return { flatink: ensureHeader(whole, doc), kind: gesture.keyword, expanded: true, meta }\n }\n // A keyword that opens a block at column 0 and is NOT a FlatInk statement is a sugar block we do not\n // know — never a program. Say so here, with the list, rather than downstream in another vocabulary.\n // `raw` is this package's own keyword, handled below.\n if (keyword && keyword !== 'raw' && !FLATINK_BLOCKS.has(keyword)) throw new UnknownSugarError(keyword, gestures.map((g) => g.keyword))\n\n // No gesture: plain FlatInk, plus any `raw { … }` the author used on its own. `raw scene` has no\n // generated scene to splice into here, so it would silently vanish — say so instead.\n const parts = takeRaw(src)\n if (parts.over.length || parts.under.length) {\n throw new Error('`raw scene { … }` needs a gesture block to splice into — this source has none. Write a plain `scene { … }` yourself.')\n }\n const out = [parts.rest.trim(), ...(parts.top.length ? [RAW_NOTE, ...parts.top] : [])].filter(Boolean).join('\\n')\n return { flatink: parts.top.length ? out : src, kind: parts.top.length ? 'raw' : null, expanded: parts.top.length > 0, meta: null }\n}\n\n/** Block keywords that belong to FlatINK itself — a source opening with one of these is a program. */\nconst FLATINK_BLOCKS = new Set(['scene', 'object', 'symbol', 'layer', 'group', 'match', 'each', 'states', 'params', 'when', 'every', 'repeat', 'fn', 'at'])\n\n/** The keyword of the first gesture block in `text`, if any — used to refuse a second one loudly. */\nfunction findGesture(text: string, gestures: Gesture[]): string | null {\n const re = new RegExp(BLOCK_OPEN.source, 'gm')\n for (let m = re.exec(text); m; m = re.exec(text)) {\n if (gestures.some((g) => g.keyword === m![1])) return m[1]\n }\n return null\n}\n\n/** Text between the braces opened at `openIndex`, brace-counting so nested blocks survive. */\nfunction blockBody(src: string, openIndex: number): string {\n let depth = 1\n let i = openIndex + 1\n for (; i < src.length && depth > 0; i++) {\n if (src[i] === '{') depth++\n else if (src[i] === '}') depth--\n }\n return src.slice(openIndex + 1, depth === 0 ? i - 1 : src.length)\n}\n"],"mappings":";AAsBO,IAAM,mBAAiC,EAAE,OAAO,KAAK,QAAQ,KAAK,KAAK,IAAI,gBAAgB,IAAI;AAG/F,IAAM,gBAAgB,CAAC,QAAyB,qCAAqC,KAAK,GAAG;AAG7F,IAAM,oBAAoB,CAAC,QAAyB,yBAAyB,KAAK,GAAG;AAOrF,SAAS,aAAa,SAAiB,MAAoB,kBAA0B;AAC1F,QAAM,OAAiB,CAAC;AACxB,M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AI,IAAI,MAAM;AAClE;","names":["gestures"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flatkit/sugarflat",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Declarative sugar for FlatInk: a compact block expands into inspectable .flatink. An authoring tool, never a runtime.",
5
5
  "license": "MIT",
6
6
  "author": "Zwyk Studio",