figdown 0.1.7 → 0.2.0

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/figdown.mjs CHANGED
@@ -1,8 +1,8 @@
1
- // figdown.mjs — FigDown embeddable library (0.1.7)
1
+ // figdown.mjs — FigDown embeddable library (0.2.0)
2
2
  // GENERATED FILE, DO NOT EDIT. Built from editor/figdown.html.
3
3
  // Regenerate with: node tools/make-lib.js
4
4
  'use strict';
5
- var VERSION = "0.1.7";
5
+ var VERSION = "0.2.0";
6
6
 
7
7
  // ---- engine (extracted verbatim from editor/figdown.html) ----
8
8
  var __engine = (function () {
@@ -16,13 +16,30 @@ const SHAPES = ['box','rounded','circle','ellipse','diamond','cylinder'];
16
16
  // input to that promise, and under core §13 a 0.x renderer may differ from
17
17
  // the next — which makes the recorded version the only thing that can
18
18
  // explain a diff between two renderings of one source.
19
- const FIGDOWN_VERSION = '0.1.7';
19
+ const FIGDOWN_VERSION = '0.2.0';
20
+ // `STATECHART-GENRE-SCOPE`: the language number moved for the first time. The dev
21
+ // counter does NOT reset (core §13.0.4 — `N` counts source states of the
22
+ // engine and only ever increases), so 0.1 is followed by
23
+ // 0.2, not by 0.2.
24
+ //
25
+ // LANGUAGE VERSIONS THIS ENGINE ACCEPTS (core §13.7 second bullet: an engine
26
+ // MUST state this, and stating the release version alone does not satisfy
27
+ // it). Declared here, in ONE place, so the header check and the documented
28
+ // interface cannot drift:
29
+ const LANG_VERSIONS = ['0.1', '0.2'];
30
+ // Genres per declared language version. `Y` never removes (core §13.0), so
31
+ // each row is a superset of the one above it, and `figdown 0.1 <anything>`
32
+ // resolves against exactly the list it resolved against before `STATECHART-GENRE-SCOPE`.
33
+ const GENRES_BY_VERSION = {
34
+ '0.1': ['block','topology','flowchart','bitfield','table','timing'],
35
+ '0.2': ['block','topology','flowchart','bitfield','table','timing','statechart']
36
+ };
20
37
  // Retired shape VALUES keep a named diagnostic (PROCESS §5(d)), the same way
21
38
  // retired option keys do: `cloud` was the one value that named a domain
22
39
  // (the internet cloud) in an enum the language keeps purely geometric
23
40
  // (`SHAPE-ENUM-VOCABULARY`/`EXTERNAL-EDGE-ENDPOINTS`), so it was removed rather than demoted.
24
41
  const RETIRED_SHAPES = {
25
- cloud: 'shape=cloud has been retired: use shape=ellipse and put the meaning in the label or a class= (shapes are pure geometry, `SHAPE-ENUM-VOCABULARY`) (MIGRATIONS)'
42
+ cloud: 'shape=cloud has been retired: use shape=ellipse and put the meaning in the label or a class= (shapes are pure geometry, `SHAPE-ENUM-VOCABULARY`) (MIGRATIONS 0.1)'
26
43
  };
27
44
  // Colors are CSS hex (#rgb / #rrggbb) or CSS named colors (spec §1) — the
28
45
  // 147 CSS/SVG color keywords (lowercase) plus `transparent`. Anything else
@@ -277,9 +294,17 @@ const DIRECTIVE_OPTS={
277
294
  process:['shape','fill','stroke','style','class','in','plane','width','height'],
278
295
  decision:['shape','fill','stroke','style','class','in','plane','width','height'],
279
296
  terminator:['shape','fill','stroke','style','class','in','plane','width','height'],
297
+ // `GENRE-NODE-SPELLING`: `state` IS `node` under `statechart` — a rename, not a
298
+ // new directive, so it takes `node`'s keys exactly and nothing more.
299
+ state:['shape','fill','stroke','style','class','in','plane','width','height'],
280
300
  group:['fill','stroke','style','gap','class','plane'],
281
301
  external:['plane'],
282
302
  edge:['style','class','fill','stroke','plane','label','taillabel','headlabel'],
303
+ // `GENRE-CONNECTOR-SPELLING`/`GENRE-NODE-SPELLING`: same rename argument — the connector's option set is one set
304
+ // under three spellings, listed three times only because the tables are
305
+ // keyed by the surface word an author actually wrote.
306
+ flowline:['style','class','fill','stroke','plane','label','taillabel','headlabel'],
307
+ transition:['style','class','fill','stroke','plane','label','taillabel','headlabel'],
283
308
  plane:['z','z-index'], flow:[], rank:[],
284
309
  bundle:['fill','stroke','style','plane'],
285
310
  threshold:['in','at','offset','fill','stroke','style','plane'],
@@ -362,10 +387,10 @@ const ENUM_OPT_KEYS=['shape','style','numbering','extend','type'];
362
387
  // `color=` sets the TEXT — and once `color=` is live again the engine can no
363
388
  // longer diagnose a pre-0.1 document at all.
364
389
  const RETIRED_OPT_KEYS={
365
- w:'w= has been renamed: use width= (SVG, CSS, DOT, mxGraph and D2 all spell it in full — no standard abbreviates it) (MIGRATIONS)',
366
- h:'h= has been renamed: use height= (SVG, CSS, DOT, mxGraph and D2 all spell it in full — no standard abbreviates it) (MIGRATIONS)',
367
- dir:'dir= has been renamed: use extend= (HTML\'s dir= is text writing direction; this one says which way the band extends from its anchor) (MIGRATIONS)',
368
- text:'text= has been retired: v0.1 has NO label-colour key — the label colour is DERIVED from the fill it sits on (core §5), and the owner-level key that could replace it would colour an edge\'s [tail]/[mid]/[head] labels identically, which is the wrong shape (core §9 `ANNOTATION-LOCATOR-SPLIT`). Delete the key; if the distinction was knowledge, write it in the label or a class= meaning (§5, `PRESENTATION-AS-MEANING-CARRIER`) (MIGRATIONS)',
390
+ w:'w= has been renamed: use width= (SVG, CSS, DOT, mxGraph and D2 all spell it in full — no standard abbreviates it) (MIGRATIONS 0.1)',
391
+ h:'h= has been renamed: use height= (SVG, CSS, DOT, mxGraph and D2 all spell it in full — no standard abbreviates it) (MIGRATIONS 0.1)',
392
+ dir:'dir= has been renamed: use extend= (HTML\'s dir= is text writing direction; this one says which way the band extends from its anchor) (MIGRATIONS 0.1)',
393
+ text:'text= has been retired: v0.1 has NO label-colour key — the label colour is DERIVED from the fill it sits on (core §5), and the owner-level key that could replace it would colour an edge\'s [tail]/[mid]/[head] labels identically, which is the wrong shape (core §9 `ANNOTATION-LOCATOR-SPLIT`). Delete the key; if the distinction was knowledge, write it in the label or a class= meaning (§5, `PRESENTATION-AS-MEANING-CARRIER`) (MIGRATIONS 0.1)',
369
394
  // `COLOUR-KEY-STATUS`. This is the ONLY key in the language whose diagnostic
370
395
  // must name two eras and refuse to choose between them: the same six
371
396
  // characters meant the FILL before this release and the LABEL after
@@ -384,10 +409,10 @@ const RETIRED_OPT_KEYS={
384
409
  // those observables, says plainly when a file has neither, and cites the
385
410
  // release only as a MIGRATIONS lookup. Same rule as the migration tool's
386
411
  // `color=` family, which reads the same evidence to decide its refusals.
387
- color:'color= has been retired: the same six characters set the box FILL in one era of this language and the LABEL colour in another, and this line does not say which — which is why the key is gone rather than renamed. READ IT OFF THE REST OF THE DOCUMENT. A file that also writes fill= cannot be from the FILL era (the two keys never coexisted), so its color= was a LABEL colour: delete it and let the derived default apply (core §5). A file still writing the spellings that were retired before the LABEL era (w= h= unit= via= dir= kind= layer= boundary wrap optional) cannot be from that era, so its color= was a FILL: write fill= instead. A file with NEITHER carries no evidence at all, and the two readings then differ only in what was DRAWN — as a FILL the value painted the box interior, as a LABEL colour it painted only the text. If the colour carried meaning, put that meaning in the label or a class= (§5, `PRESENTATION-AS-MEANING-CARRIER`). tools/migrate-figdown.js reads this evidence for you and REFUSES the wrong --color-means=fill|text (MIGRATIONS)',
412
+ color:'color= has been retired: the same six characters set the box FILL in one era of this language and the LABEL colour in another, and this line does not say which — which is why the key is gone rather than renamed. READ IT OFF THE REST OF THE DOCUMENT. A file that also writes fill= cannot be from the FILL era (the two keys never coexisted), so its color= was a LABEL colour: delete it and let the derived default apply (core §5). A file still writing the spellings that were retired before the LABEL era (w= h= unit= via= dir= kind= layer= boundary wrap optional) cannot be from that era, so its color= was a FILL: write fill= instead. A file with NEITHER carries no evidence at all, and the two readings then differ only in what was DRAWN — as a FILL the value painted the box interior, as a LABEL colour it painted only the text. If the colour carried meaning, put that meaning in the label or a class= (§5, `PRESENTATION-AS-MEANING-CARRIER`). tools/migrate-figdown.js reads this evidence for you and REFUSES the wrong --color-means=fill|text (MIGRATIONS 0.1)',
388
413
  kind:'kind= has been renamed: on a node use shape= (geometric; the label text carries the device semantics — MIGRATIONS 0.1), on a chart use type= (Vega, Chart.js and ECharts all spell the chart-type key "type" — MIGRATIONS 0.1). One spelling was retired on node and live on plot at the same time, inside one namespace; 0.1 closed that.',
389
- layer:'layer= has been renamed: use plane= (mxGraph makes a layer a containment parent that establishes coordinates; Inkscape layers can carry a transform; OGC WMS layers carry an SRS; CSS @layer is cascade priority. None of those is what this key does, and SVG has no layer at all) (MIGRATIONS)',
390
- labels:'labels= has been renamed: use data= (WaveDrom\'s own key for exactly this is `data`, "an array of signal labels" — one per value cell of the lane) (MIGRATIONS)',
414
+ layer:'layer= has been renamed: use plane= (mxGraph makes a layer a containment parent that establishes coordinates; Inkscape layers can carry a transform; OGC WMS layers carry an SRS; CSS @layer is cascade priority. None of those is what this key does, and SVG has no layer at all) (MIGRATIONS 0.1)',
415
+ labels:'labels= has been renamed: use data= (WaveDrom\'s own key for exactly this is `data`, "an array of signal labels" — one per value cell of the lane) (MIGRATIONS 0.1)',
391
416
  // 0.1 (`EDGE-GEOMETRY-CONSTRUCTS`). These six keys end in a WITHDRAWAL, not a rename, so
392
417
  // their messages have a shape no earlier retirement in this table has: they
393
418
  // name no replacement spelling, because there is none. `via=`/`src=`/`dst=`
@@ -401,28 +426,28 @@ const RETIRED_OPT_KEYS={
401
426
  tailport:'tailport= has been WITHDRAWN with the `path` directive (`EDGE-GEOMETRY-CONSTRUCTS`): the construct is removed from the language, not renamed, so there is no spelling to migrate to. Attachment to a named site addressed by semantic role IS inside the stable prior-art intersection; FigDown\'s realisation was not (a fraction on the EDGE is mxGraph-only, and written-order attachment has zero prior art in any surveyed system). Restoring it needs an edge-identity construct first. Delete the line; the edge draws under auto layout. The decision and its evidence: MIGRATIONS 0.1, core §9 `EDGE-IDENTITY-AND-GEOMETRY`, decisions/registry.md',
402
427
  headport:'headport= has been WITHDRAWN with the `path` directive (`EDGE-GEOMETRY-CONSTRUCTS`): the construct is removed from the language, not renamed, so there is no spelling to migrate to. Attachment to a named site addressed by semantic role IS inside the stable prior-art intersection; FigDown\'s realisation was not (a fraction on the EDGE is mxGraph-only, and written-order attachment has zero prior art in any surveyed system). Restoring it needs an edge-identity construct first. Delete the line; the edge draws under auto layout. The decision and its evidence: MIGRATIONS 0.1, core §9 `EDGE-IDENTITY-AND-GEOMETRY`, decisions/registry.md',
403
428
  routing:'routing= has been WITHDRAWN with the `path` directive (`EDGE-GEOMETRY-CONSTRUCTS`): the construct is removed from the language, not renamed, so there is no spelling to migrate to. The per-edge routing SCOPE was inside the stable prior-art intersection and is deliberately lost with its host line — an override needs an edge to address, and FigDown has no edge-identity construct. Delete the line. The decision and its evidence: MIGRATIONS 0.1, core §9 `EDGE-IDENTITY-AND-GEOMETRY`, decisions/registry.md',
404
- unit:'unit= has been renamed: use word= (RFC 2360 §3.1: "a sequence of long words in network byte order, with each word horizontal on the page"; RFC 791 §3.1 measures the header in "32 bit words". Mermaid names the identical setting bitsPerRow — semantically right, camelCase barred. `unit=32` also inverts count-vs-unit, reading as "the unit is 32", and C\'s "unit" is the addressable storage unit, not the row width) (MIGRATIONS)',
405
- z:'z= has been renamed: use z-index= (CSS spells the stacking concept z-index, and RULE 4.2 takes the standard spelling in full; a single-letter key is structurally risky next to the closed timing lane alphabet, `LANE-ALPHABET-KEY-RESERVATION`) (MIGRATIONS)',
429
+ unit:'unit= has been renamed: use word= (RFC 2360 §3.1: "a sequence of long words in network byte order, with each word horizontal on the page"; RFC 791 §3.1 measures the header in "32 bit words". Mermaid names the identical setting bitsPerRow — semantically right, camelCase barred. `unit=32` also inverts count-vs-unit, reading as "the unit is 32", and C\'s "unit" is the addressable storage unit, not the row width) (MIGRATIONS 0.1)',
430
+ z:'z= has been renamed: use z-index= (CSS spells the stacking concept z-index, and RULE 4.2 takes the standard spelling in full; a single-letter key is structurally risky next to the closed timing lane alphabet, `LANE-ALPHABET-KEY-RESERVATION`) (MIGRATIONS 0.1)',
406
431
  // `DESCRIPTION-KEY-SPELLING`. The spelling leaves the LANGUAGE, so the message fires
407
432
  // wherever it appears (the `w=`/`h=`/`unit=` placement test, RULE 6.2).
408
- note:'note= has been renamed: use description= (IEEE 1685-2022 spells this channel `description`; SystemRDL\'s `desc` is barred by RULE 4.2 as an abbreviation. The rename is defensive: `ANNOTATION-LOCATOR-SPLIT` files `note` as the highest-demand v0.2 annotation construct — ~66 figure-identities, 20 independent reinventions — and that one will be a DRAWN callout, so a never-drawing `note=` beside an always-drawing `note` would be one spelling with two opposite behaviours) (MIGRATIONS)',
409
- level:'level= has been DELETED, not renamed: it drew a reference plane through a 3-D bar chart, has zero uses in either downstream corpus and zero 3-D bar charts to draw it on, was the only construct whose caption the ENGINE wrote rather than the author, and its parseFloat grammar uniquely accepted 1e3 where every other number in the language is \\d+(\\.\\d+)? — delete the key (MIGRATIONS)'
433
+ note:'note= has been renamed: use description= (IEEE 1685-2022 spells this channel `description`; SystemRDL\'s `desc` is barred by RULE 4.2 as an abbreviation. The rename is defensive: `ANNOTATION-LOCATOR-SPLIT` files `note` as the highest-demand v0.2 annotation construct — ~66 figure-identities, 20 independent reinventions — and that one will be a DRAWN callout, so a never-drawing `note=` beside an always-drawing `note` would be one spelling with two opposite behaviours) (MIGRATIONS 0.1)',
434
+ level:'level= has been DELETED, not renamed: it drew a reference plane through a 3-D bar chart, has zero uses in either downstream corpus and zero 3-D bar charts to draw it on, was the only construct whose caption the ENGINE wrote rather than the author, and its parseFloat grammar uniquely accepted 1e3 where every other number in the language is \\d+(\\.\\d+)? — delete the key (MIGRATIONS 0.1)'
410
435
  };
411
436
  // `PLANE-KEYWORD-SPELLING`: the keyword `plane`/`plane=` was spelled `layer`/`layer=`.
412
- const RETIRED_LAYER='layer has been renamed: use plane (in mxGraph — the geometry model FigDown adopted — a layer is a CONTAINMENT PARENT that establishes coordinates, so layer=overlay reads as "reparent and re-origin this element", which FigDown does not do; Inkscape layers are <g> and may carry a transform, OGC WMS layers each carry an SRS, and CSS @layer is cascade priority with no visual meaning. SVG has no layer concept at all. `plane` is claimed by no standard for a conflicting meaning and removes the layout/layer near-miss) (MIGRATIONS)';
437
+ const RETIRED_LAYER='layer has been renamed: use plane (in mxGraph — the geometry model FigDown adopted — a layer is a CONTAINMENT PARENT that establishes coordinates, so layer=overlay reads as "reparent and re-origin this element", which FigDown does not do; Inkscape layers are <g> and may carry a transform, OGC WMS layers each carry an SRS, and CSS @layer is cascade priority with no visual meaning. SVG has no layer concept at all. `plane` is claimed by no standard for a conflicting meaning and removes the layout/layer near-miss) (MIGRATIONS 0.1)';
413
438
  // `THRESHOLD-KEYWORD-SPELLING`: the scene keyword `guide` became `threshold`.
414
- const RETIRED_GUIDE='guide has been renamed: use threshold (in Illustrator, Inkscape, Figma and draw.io a "guide" is an author-only construction line that is NEVER rendered, while FigDown\'s is drawn output — an INVERTED name, which `UNSAFE-DEFAULT-ELIMINATION` rates worse than an unfamiliar one, and no counter-example was found where "guide" names rendered output. `guide` was also a FigDown coinage, and `SIZE-AND-DIRECTION-KEY-NAMING` makes coining a last resort; `threshold` comes whole from Grafana, whose "Show thresholds" render option offers "As lines", "As filled regions" and "As filled regions and lines" — FigDown\'s marker + region pair, split the same way — with IETF RED/AQM as the secondary source (RFC 2309: "Two RED parameters, minth (minimum threshold) and maxth (maximum threshold)"; RFC 7567: "an AQM algorithm configured with a threshold"). 78% of the measured corpus marks are thresholds; target/mean/reference marks: 0) (MIGRATIONS)';
439
+ const RETIRED_GUIDE='guide has been renamed: use threshold (in Illustrator, Inkscape, Figma and draw.io a "guide" is an author-only construction line that is NEVER rendered, while FigDown\'s is drawn output — an INVERTED name, which `UNSAFE-DEFAULT-ELIMINATION` rates worse than an unfamiliar one, and no counter-example was found where "guide" names rendered output. `guide` was also a FigDown coinage, and `SIZE-AND-DIRECTION-KEY-NAMING` makes coining a last resort; `threshold` comes whole from Grafana, whose "Show thresholds" render option offers "As lines", "As filled regions" and "As filled regions and lines" — FigDown\'s marker + region pair, split the same way — with IETF RED/AQM as the secondary source (RFC 2309: "Two RED parameters, minth (minimum threshold) and maxth (maximum threshold)"; RFC 7567: "an AQM algorithm configured with a threshold"). 78% of the measured corpus marks are thresholds; target/mean/reference marks: 0) (MIGRATIONS 0.1)';
415
440
  // `EXTERNAL-ENDPOINT-NAMING`: the scene keyword `boundary` became `external`.
416
- const RETIRED_BOUNDARY='boundary has been renamed: use external (it declares an external I/O endpoint — the spec\'s own words — while UML\'s «boundary» is an INTERNAL interface object, C4\'s System_Boundary is a dashed grouping container FigDown already spells `group`, and BPMN\'s Boundary Event is a third meaning) (MIGRATIONS)';
441
+ const RETIRED_BOUNDARY='boundary has been renamed: use external (it declares an external I/O endpoint — the spec\'s own words — while UML\'s «boundary» is an INTERNAL interface object, C4\'s System_Boundary is a dashed grouping container FigDown already spells `group`, and BPMN\'s Boundary Event is a third meaning) (MIGRATIONS 0.1)';
417
442
  // `ROW-BREAK-NAMING`: the `bitfield` child keyword `wrap` became `break`.
418
- const RETIRED_WRAP='wrap has been renamed: use break (in CSS and typography `wrap` is AUTOMATIC reflow — a mode — while this directive is an EXPLICIT row break, an event; CSS Fragmentation calls it "a forced break … explicitly indicated by the … author", HTML spells it `br`) (MIGRATIONS)';
443
+ const RETIRED_WRAP='wrap has been renamed: use break (in CSS and typography `wrap` is AUTOMATIC reflow — a mode — while this directive is an EXPLICIT row break, an event; CSS Fragmentation calls it "a forced break … explicitly indicated by the … author", HTML spells it `br`) (MIGRATIONS 0.1)';
419
444
  // `PRESENCE-FLAG-SPELLING`: the 0.1 rename `optional` -> `conditional` (`PRESENCE-FLAG-SPELLING`)
420
445
  // is REVERTED. `conditional` has zero attestation as a wire-format field
421
446
  // marker and zero uses in the downstream corpus, while "optional" appears in
422
447
  // 34 downstream field LABELS — authors wrote the word in the label precisely
423
448
  // because the keyword no longer said it. The MODEL key moves with the surface
424
449
  // (`NORMATIVE-SEMANTIC-MODEL`): it is `optional` again on both sides.
425
- const RETIRED_FIELD_CONDITIONAL='the field flag "conditional" has been retired: write present="<the condition>" (or present="" if the condition is not stated). "conditional" was attested as a wire-format field marker nowhere — zero hits in RFC 2784, ASN.1 X.680, draft-mcquistin-augmented-ascii-diagrams, SystemRDL, IP-XACT, Kaitai Struct and protobuf — and the flag it briefly replaced, "optional", is retired too: an option key carrying the CONDITION says what a bare flag could not (MIGRATIONS)';
450
+ const RETIRED_FIELD_CONDITIONAL='the field flag "conditional" has been retired: write present="<the condition>" (or present="" if the condition is not stated). "conditional" was attested as a wire-format field marker nowhere — zero hits in RFC 2784, ASN.1 X.680, draft-mcquistin-augmented-ascii-diagrams, SystemRDL, IP-XACT, Kaitai Struct and protobuf — and the flag it briefly replaced, "optional", is retired too: an option key carrying the CONDITION says what a bare flag could not (MIGRATIONS 0.1)';
426
451
  // `PRESENCE-CONDITION-EXPRESSION`: the positional flag `optional` becomes the option key
427
452
  // `present=`, whose VALUE is the presence condition. A bare flag could say
428
453
  // only THAT a field is conditional; every RFC that draws one also states WHY
@@ -431,7 +456,7 @@ const RETIRED_FIELD_CONDITIONAL='the field flag "conditional" has been retired:
431
456
  // prose the model may not read. `present` is the attested spelling: X.680
432
457
  // PRESENT, IP-XACT isPresent, SystemRDL ispresent, RFC 2784 "present only
433
458
  // if", draft-mcquistin "present only when".
434
- const RETIRED_FIELD_OPTIONAL='the field flag "optional" has been retired and replaced by an option key that carries the CONDITION: write present="<the condition>" (e.g. field "Checksum" 16 present="C = 1"), or present="" when the condition is not stated. The bare flag could say only THAT the field was conditional, so the condition had to live in note= — invisible to the human reading the figure, and prose the model may not parse (`BITFIELD-CONDITIONAL-OFFSETS`). present= DRAWS: the field stays dashed and a stated condition becomes a caption under the block (MIGRATIONS)';
459
+ const RETIRED_FIELD_OPTIONAL='the field flag "optional" has been retired and replaced by an option key that carries the CONDITION: write present="<the condition>" (e.g. field "Checksum" 16 present="C = 1"), or present="" when the condition is not stated. The bare flag could say only THAT the field was conditional, so the condition had to live in note= — invisible to the human reading the figure, and prose the model may not parse (`BITFIELD-CONDITIONAL-OFFSETS`). present= DRAWS: the field stays dashed and a stated condition becomes a caption under the block (MIGRATIONS 0.1)';
435
460
  // `TIMING-GENRE-NAMING`: the EXPERIMENTAL genre `wave` became `timing`, both as
436
461
  // the header genre token and as the block opener. The old name was WaveDrom's
437
462
  // MEMBER KEY, not its figure name: in WaveJSON `signal` is the root object and
@@ -448,8 +473,8 @@ const RETIRED_FIELD_OPTIONAL='the field flag "optional" has been retired and rep
448
473
  // to know that the keys survive unchanged and only their carrier moved.
449
474
  // RULE 6.2 placement: the spelling left the LANGUAGE, so this fires wherever
450
475
  // it appears at line start, in every genre, ahead of the `GENRE-KEYWORD-ALLOWLIST` allowlist.
451
- const RETIRED_SIZE='size has been retired: its keys moved onto pin — write pin <id> width=<px> height=<px> (one directive carries an element\'s whole declared geometry: at= places it, width=/height= extend it; all three keys are optional and a pin with none of them declares nothing) (MIGRATIONS)';
452
- const RETIRED_WAVE='wave has been renamed: use timing (in WaveJSON `signal` is the root object and `wave` is a PROPERTY of one signal — its lane activity string — so `wave` named a member key, not a figure kind; WaveDrom\'s own name for the figure is "Digital Timing Diagram", "timing diagram" is the datasheet/JEDEC term for it, and UML 2.5.1\'s Timing Diagram is the same concept. The rename frees `wave` for the lane) (MIGRATIONS)';
476
+ const RETIRED_SIZE='size has been retired: its keys moved onto pin — write pin <id> width=<px> height=<px> (one directive carries an element\'s whole declared geometry: at= places it, width=/height= extend it; all three keys are optional and a pin with none of them declares nothing) (MIGRATIONS 0.1)';
477
+ const RETIRED_WAVE='wave has been renamed: use timing (in WaveJSON `signal` is the root object and `wave` is a PROPERTY of one signal — its lane activity string — so `wave` named a member key, not a figure kind; WaveDrom\'s own name for the figure is "Digital Timing Diagram", "timing diagram" is the datasheet/JEDEC term for it, and UML 2.5.1\'s Timing Diagram is the same concept. The rename frees `wave` for the lane) (MIGRATIONS 0.1)';
453
478
  // `EDGE-GEOMETRY-CONSTRUCTS`: `path` and `routing` are WITHDRAWN from the language.
454
479
  // These two diagnostics are a NEW SHAPE for this table. Every retirement
455
480
  // before them named a replacement spelling — `size` named `pin`, `guide` named
@@ -467,15 +492,15 @@ const WITHDRAWN_WHERE=' The decision and its evidence: MIGRATIONS 0.1, core §9
467
492
  const RETIRED_PATH='path has been WITHDRAWN from the language (`EDGE-GEOMETRY-CONSTRUCTS`) — removed, not renamed, so there is no replacement spelling. A prior-art study of Visio, draw.io/mxGraph, Graphviz and ELK found author waypoints OUTSIDE the stable intersection: only 2 of the 4 model them, and those 2 disagree on what happens when an endpoint moves. The dock realisation was outside it too — written-order attachment has zero prior art in any surveyed system. Delete the line: the edge draws under auto layout, and `rank`, `flow`, declaration order and `pin` are the content-zone means of shaping it.'+WITHDRAWN_WHERE;
468
493
  const RETIRED_ROUTING='routing has been WITHDRAWN from the language (`EDGE-GEOMETRY-CONSTRUCTS`) — removed, not renamed, so there is no replacement spelling. Two routing modes and two scopes ARE inside the stable prior-art intersection, so the need is recognised and its shape is known; what is missing is the evidence and the implementation (6 of the 8 in-repo `routing=orthogonal` writings were provable no-ops, and downstream adoption was zero), and the per-edge scope cannot be restored without an edge-identity construct FigDown does not have. Delete the line; the edges draw straight.'+WITHDRAWN_WHERE;
469
494
  // `TIMING-LANE-ALPHABET`: the timing lane digits `2`-`9` left the closed alphabet.
470
- const RETIRED_LANE_DIGIT='timing lane digits 2-9 have been retired: write "=" for a data cell and name it in data= (WaveDrom defines 2..9 as "value with color N" and "=" as "value (default color 2)" — the same brick with a palette index, while FigDown drew the digit character itself as the box label and consumed no data entry, so the two readings of one lane differed silently) (MIGRATIONS)';
495
+ const RETIRED_LANE_DIGIT='timing lane digits 2-9 have been retired: write "=" for a data cell and name it in data= (WaveDrom defines 2..9 as "value with color N" and "=" as "value (default color 2)" — the same brick with a palette index, while FigDown drew the digit character itself as the box label and consumed no data entry, so the two readings of one lane differed silently) (MIGRATIONS 0.1)';
471
496
  // 0.1 (§8.4): `edge`, `threshold` and `bundle` have NO interior, so
472
497
  // `fill=` and `stroke=` named the SAME channel and `stroke=` won silently —
473
498
  // two keys for one channel, resolved by an undocumented precedence that
474
499
  // produced a legal, wrong figure whenever both were written (16 lines in
475
500
  // this repository, 3 of them writing both on one line). Same defect shape as
476
501
  // the retired `color=`; same cure, a named diagnostic.
477
- const NO_INTERIOR=new Set(['edge','threshold','bundle']);
478
- const FILL_NO_INTERIOR=k=>k+' has no interior, so fill= and stroke= name the same channel (stroke= won silently) — write stroke= (MIGRATIONS)';
502
+ const NO_INTERIOR=new Set(['edge','flowline','transition','threshold','bundle']);
503
+ const FILL_NO_INTERIOR=k=>k+' has no interior, so fill= and stroke= name the same channel (stroke= won silently) — write stroke= (MIGRATIONS 0.1)';
479
504
  // `STYLE-KEY-SCOPE`: `style=` left these three directives (it stays live on
480
505
  // node/group/edge/class/bundle/threshold/band). The generic
481
506
  // "<directive> does not take style=" would be true but would not say why, and
@@ -486,8 +511,8 @@ const FILL_NO_INTERIOR=k=>k+' has no interior, so fill= and stroke= name the sam
486
511
  // are closed here the way every other one-channel-two-keys collision in this
487
512
  // language was closed — a named line error, not a precedence rule. A
488
513
  // precedence rule is what `STYLE-KEY-SCOPE` had just finished removing from `field`.
489
- const CELL_HL_ON_CELL='highlight is a ROW mark and takes the single-valued row form (cell <row> highlight) — on a cell address it was SILENTLY DISCARDED and never reached the model, while the cell fill drew. A row tint and a cell fill paint the same channel, so writing both for one cell has no honest resolution: tint the row (cell <row> highlight) or paint the cell (cell (<row>,<col>) fill=…/class=…), not both (MIGRATIONS)';
490
- const CELL_HL_ROW_CONFLICT=(r,c)=>'cell ('+r+','+c+') resolves to a fill on row '+r+', which is highlighted — the cell fill overrides the row tint, so the model says "row '+r+' is highlighted" while the drawing shows only part of the row tinted (`PRESENTATION-AS-MEANING-CARRIER`: presentation may render meaning, never delete it). Drop the row highlight, or move the cell fill to a row that carries none (MIGRATIONS)';
514
+ const CELL_HL_ON_CELL='highlight is a ROW mark and takes the single-valued row form (cell <row> highlight) — on a cell address it was SILENTLY DISCARDED and never reached the model, while the cell fill drew. A row tint and a cell fill paint the same channel, so writing both for one cell has no honest resolution: tint the row (cell <row> highlight) or paint the cell (cell (<row>,<col>) fill=…/class=…), not both (MIGRATIONS 0.1)';
515
+ const CELL_HL_ROW_CONFLICT=(r,c)=>'cell ('+r+','+c+') resolves to a fill on row '+r+', which is highlighted — the cell fill overrides the row tint, so the model says "row '+r+' is highlighted" while the drawing shows only part of the row tinted (`PRESENTATION-AS-MEANING-CARRIER`: presentation may render meaning, never delete it). Drop the row highlight, or move the cell fill to a row that carries none (MIGRATIONS 0.1)';
491
516
  const NO_ITEM_STYLE=new Set(['field','cell','signal']);
492
517
  const STYLE_NO_ITEM=k=>k+' does not take style= — '+(k==='field'
493
518
  ? 'on a field the dash IS conditional presence (`present=`, spelled `optional` until this release), and style=solid erased it while the model still recorded the field as conditionally present (`PRESENTATION-AS-MEANING-CARRIER`: presentation may render meaning, never be its only carrier)'
@@ -499,7 +524,7 @@ const STYLE_NO_ITEM=k=>k+' does not take style= — '+(k==='field'
499
524
  // human, which is the same defect `STYLE-KEY-SCOPE` exists to close. The two channels
500
525
  // that DRAW are the name/label and a `class` meaning (which also earns a
501
526
  // legend entry).
502
- +'. Delete the key; if the distinction is knowledge, write it in the name/label or in a class= meaning — both of which DRAW; description= is documentation prose and produces no ink beyond a tooltip (MIGRATIONS)';
527
+ +'. Delete the key; if the distinction is knowledge, write it in the name/label or in a class= meaning — both of which DRAW; description= is documentation prose and produces no ink beyond a tooltip (MIGRATIONS 0.1)';
503
528
  function splitOpts(toks, laneMode){
504
529
  // a repeated option key on one line is a line error, never
505
530
  // silent last-wins. `dup` names the first key that appeared twice.
@@ -549,7 +574,7 @@ const ID_RE=/^[A-Za-z_][A-Za-z0-9_-]*$/;
549
574
  // `a`+`x--b`) and the greedy member regex silently committed to the first,
550
575
  // making the second unreachable and undiagnosed — RULE 6.3 says malformed
551
576
  // input is an error, never a guess. Zero ids in either corpus contain `--`.
552
- const DD_ID='"--" is not allowed inside an id — it is the link operator (edge a -- b, bundle t1 a--b); write a single "-" or "_" (MIGRATIONS)';
577
+ const DD_ID='"--" is not allowed inside an id — it is the link operator (edge a -- b, bundle t1 a--b); write a single "-" or "_" (MIGRATIONS 0.1)';
553
578
  // `QUOTED-IDS`: ONE wording for every id position. It covers both
554
579
  // halves of the defect it closes — a needlessly quoted legal id
555
580
  // (`node "a"`, silently accepted before) and a quoted token that is not a
@@ -568,7 +593,7 @@ const DD_ID='"--" is not allowed inside an id — it is the link operator (edge
568
593
  // old failure named the wrong thing (`node a Cache miss` reported
569
594
  // `unexpected argument "miss"` — a surplus argument, when the defect was a
570
595
  // missing quote).
571
- const Q_WHY='whitespace also separates positionals, so a bare token cannot express a phrase (MIGRATIONS)';
596
+ const Q_WHY='whitespace also separates positionals, so a bare token cannot express a phrase (MIGRATIONS 0.1)';
572
597
  const ID_RULE='ids are bare and match [A-Za-z_][A-Za-z0-9_-]* — text with spaces or punctuation belongs in the label: node <id> "your text"';
573
598
  // isId: the whole id test, used at every id position in the language.
574
599
  const isId=v=>typeof v==='string'&&ID_RE.test(v)&&!v.includes('--');
@@ -756,7 +781,9 @@ function parseIndexRange(v){
756
781
  const CORE_KW=['figdown','title','layout'];
757
782
  const LAYOUT_KW=['pin']; // `LAYOUT-ZONE-NAMESPACE`, NORMATIVE — the whole namespace
758
783
  const GENRE_FREE_KW=CORE_KW.concat(LAYOUT_KW);
759
- const SCENE_KW_TOP=['node','group','external','edge','class','flow','rank'];
784
+ // `GENRE-CONNECTOR-SPELLING`/`GENRE-NODE-SPELLING`: the NODE and CONNECTOR spellings are per genre, so
785
+ // they are NOT in the shared list — every scene genre concats its own two.
786
+ const SCENE_KW_TOP=['group','external','class','flow','rank'];
760
787
  const SCENE_EXP_KW=['threshold','band','bundle','plane'];
761
788
  const SCENE_HOST_KW=GENRE_FREE_KW.concat(SCENE_KW_TOP, SCENE_EXP_KW, ['bitfield','table','timing','chart']);
762
789
  // `FLOWCHART-ROLE-KEYWORDS`: the flowchart ROLE vocabulary — the FIRST exercise of
@@ -772,10 +799,88 @@ const FLOWCHART_ROLE_KW=['process','decision','terminator'];
772
799
  // only its default drawing, and `shape=` on the same line overrides the
773
800
  // drawing without touching the role (§12.7).
774
801
  const ROLE_SHAPE={process:'box',decision:'diamond',terminator:'rounded'};
802
+
803
+ // `GENRE-CONNECTOR-SPELLING`/`GENRE-NODE-SPELLING`: PER-GENRE NODE AND CONNECTOR SPELLINGS.
804
+ // Each scene genre takes the word its own domain uses for the line between
805
+ // two things, and for the thing itself. The criterion is THE TERM THE DOMAIN
806
+ // ACTUALLY USES, not the standard's exact orthography (see the vocabulary
807
+ // rows: `flowline` carries the same ISO-clause verification debt
808
+ // `terminator` does, recorded rather than claimed away).
809
+ //
810
+ // block / topology node edge (DOT, unchanged)
811
+ // flowchart node flowline (ISO 5807)
812
+ // statechart state transition (OMG UML 2.5.1 §14)
813
+ //
814
+ // The ASYMMETRY is deliberate and is the whole of `GENRE-CONNECTOR-SPELLING` vs `GENRE-NODE-SPELLING`: `node`
815
+ // STAYS in `flowchart`, because there a stage can have a role THE SOURCE
816
+ // DOES NOT STATE, and `node` is the only spelling for that — forcing
817
+ // `process` would make the transcriber assert what the source never said.
818
+ // `statechart` has exactly ONE kind of node, so nothing can be left unstated
819
+ // and `state` loses nothing. `BARE-NODE-MEANING` CORRECTS the reason this
820
+ // comment used to give ("ISO has ~ten symbol kinds and we carry three"): a
821
+ // symbol this genre cannot spell is a COVERAGE GAP in FigDown, not a state
822
+ // of the figure, and `node` is not its spelling — see
823
+ // the project’s working record for the coverage ledger.
824
+ const GENRE_NODE_KW={block:'node',topology:'node',flowchart:'node',statechart:'state'};
825
+ const GENRE_CONNECTOR_KW={block:'edge',topology:'edge',flowchart:'flowline',statechart:'transition'};
826
+ const NODE_SPELLINGS=new Set(['node','state']);
827
+ const CONNECTOR_SPELLINGS=new Set(['edge','flowline','transition']);
828
+ // `KEYWORD-RENAME-SCOPE`: the flowchart rename is GATED BY THE DECLARED LANGUAGE
829
+ // VERSION, because `GENRE-CONNECTOR-SPELLING` applied it to `figdown 0.1` and that BROKE documents
830
+ // legal at v0.1.8 — `figdown 0.1 flowchart` + `edge` stopped parsing, with
831
+ // nothing recording the break as a decision. Under core §13.0 only X removes,
832
+ // so 0.1 keeps its spelling:
833
+ //
834
+ // figdown 0.1 flowchart `edge` legal, `flowline` is a VERSION error
835
+ // figdown 0.2 flowchart `flowline` legal, `edge` is the WRONG_WORD error
836
+ //
837
+ // Two spellings inside ONE version is what the no-alias rule (`IDENTITY-ASSERTION`)
838
+ // forbids; two spellings across VERSIONS is ordinary language evolution, and
839
+ // each version accepts exactly one. `statechart` needs no gate of its own —
840
+ // the GENRE requires 0.2 (GENRES_BY_VERSION), so `state`/`transition` cannot
841
+ // be reached from a 0.1 document at all.
842
+ const GENRE_CONNECTOR_KW_AT={
843
+ '0.1':{block:'edge',topology:'edge',flowchart:'edge'},
844
+ '0.2':GENRE_CONNECTOR_KW
845
+ };
846
+ const connectorKwAt=(genre,ver)=>
847
+ ((GENRE_CONNECTOR_KW_AT[ver]||GENRE_CONNECTOR_KW)[genre])||undefined;
848
+ // The version a connector spelling FIRST becomes legal in, so the diagnostic
849
+ // can name it the way the genre gate already names `figdown 0.2`.
850
+ const CONNECTOR_MIN_VERSION={flowline:'0.2',transition:'0.2'};
851
+ const WRONG_VERSION_WORD=(surf,want,genre,need,have)=>
852
+ '"'+surf+'" requires figdown '+need+' (this document declares '+have+'): '+
853
+ 'under figdown '+have+' genre '+genre+' spells this "'+want+'". The rename is '+
854
+ 'gated by the language version — a figdown '+have+' document keeps the spelling it '+
855
+ 'was written with (core §13.0: only a MAJOR version removes) — so raise the header '+
856
+ 'to figdown '+need+' or write "'+want+'" (MIGRATIONS 0.2)';
857
+ // Why each genre's word is its word — quoted in the diagnostic, because
858
+ // "not allowed in genre X" tells an author nothing about what to write.
859
+ const WORD_WHY={
860
+ edge:'a block or topology figure is a graph, and `edge` is the graph word (DOT)',
861
+ flowline:'the connecting line in a flowchart is a FLOWLINE — the term ISO 5807 uses for it',
862
+ transition:'the connecting line in a statechart is a TRANSITION — the term UML 2.5.1 §14 uses for it',
863
+ node:'this genre has more kinds of thing than it has words for, so `node` is the general one',
864
+ state:'a statechart has exactly ONE kind of node and it is a STATE (UML 2.5.1 §14)'
865
+ };
866
+ // The named diagnostic `GENRE-CONNECTOR-SPELLING`/`GENRE-NODE-SPELLING` owe: it says WHICH word this genre uses and
867
+ // WHY, and it names the migration, because every connector line in a
868
+ // reclassified document has to be rewritten (the cost `GENRE-CONNECTOR-SPELLING` accepted).
869
+ const WRONG_WORD=(surf,want,genre)=>
870
+ '"'+surf+'" is not the word genre '+genre+' uses for this — write "'+want+'": '+WORD_WHY[want]+
871
+ '. Each scene genre takes the term its own domain uses (block/topology `node` `edge`, flowchart `node` `flowline`, statechart `state` `transition`) — run tools/migrate-figdown.js to rewrite it (MIGRATIONS 0.2)';
775
872
  const GENRE_KW={
776
- block:new Set(SCENE_HOST_KW),
777
- topology:new Set(SCENE_HOST_KW),
778
- flowchart:new Set(SCENE_HOST_KW.concat(FLOWCHART_ROLE_KW)),
873
+ block:new Set(SCENE_HOST_KW.concat(['node','edge'])),
874
+ topology:new Set(SCENE_HOST_KW.concat(['node','edge'])),
875
+ flowchart:new Set(SCENE_HOST_KW.concat(['node','flowline'], FLOWCHART_ROLE_KW)),
876
+ // `STATECHART-GENRE-SCOPE`: `statechart` added no keyword of its own — it was the
877
+ // scene host set and nothing else. `GENRE-NODE-SPELLING` gives it its two: the
878
+ // scene host set with `state` and `transition` in the slots `node` and
879
+ // `edge` occupy elsewhere. It still does NOT inherit `process`/`decision`/
880
+ // `terminator`: those are flowchart's words (`GENRE-NAMESPACE` `GENRE-VOCABULARY-OBLIGATION`), and a `decision` in a
881
+ // statechart is a category error, not a shorthand. The allowlist is what
882
+ // makes that a line error with no extra code.
883
+ statechart:new Set(SCENE_HOST_KW.concat(['state','transition'])),
779
884
  bitfield:new Set(GENRE_FREE_KW.concat(['class','bitfield'])),
780
885
  // chart is experimental and attaches to a table id in the same document
781
886
  table:new Set(GENRE_FREE_KW.concat(['class','table','chart'])),
@@ -878,8 +983,13 @@ function parseOne(text){
878
983
  // operator into halves: -[x]- -[x]-> <-[x]- <-[x]->. Bracket content:
879
984
  // balanced brackets nest verbatim ([flags[3:0]] just works); ["..."] takes
880
985
  // the standard quoted-string escapes for unbalanced brackets / \n.
881
- function parseEdgeLine(s,n){
882
- let i=4; // past 'edge'
986
+ // `GENRE-CONNECTOR-SPELLING`/`GENRE-NODE-SPELLING`: `kw` is the SURFACE spelling the author wrote —
987
+ // `edge`, `flowline` or `transition`. One scanner, three words: every
988
+ // message names the word on the line, and nothing downstream of here knows
989
+ // the difference (the model records a connector, not a spelling).
990
+ function parseEdgeLine(s,n,kw){
991
+ kw=kw||'edge';
992
+ let i=kw.length; // past the connector keyword
883
993
  const ws=()=>{ while(i<s.length&&/\s/.test(s[i])) i++; };
884
994
  // `LINK-OPERATOR-IN-IDS`: a hyphen is an id character only when it is NOT
885
995
  // followed by a second one, because `--` is the link operator. This is
@@ -927,7 +1037,7 @@ function parseOne(text){
927
1037
  ws();
928
1038
  if(s[i]==='"'){ err(n,ID_RULE); return; }
929
1039
  const a=readId();
930
- if(!a){ err(n, idHere()?ID_RULE:'edge needs <id> ->|<-|--|<-> <id>'); return; }
1040
+ if(!a){ err(n, idHere()?ID_RULE:kw+' needs <id> ->|<-|--|<-> <id>'); return; }
931
1041
  if(idHere()){ err(n,ID_RULE); return; }
932
1042
  ws(); let tail=null;
933
1043
  if(s[i]==='['){ const r=readLbl(); if(r.error){ err(n,r.error); return; } tail=r.v; }
@@ -935,7 +1045,7 @@ function parseOne(text){
935
1045
  let lh=null;
936
1046
  if(s.startsWith('<-',i)){ lh='<-'; i+=2; }
937
1047
  else if(s[i]==='-'){ lh='-'; i++; }
938
- else { err(n,'edge needs an operator: -> <- -- <-> (a [mid] label splits it: -[x]->)'); return; }
1048
+ else { err(n,kw+' needs an operator: -> <- -- <-> (a [mid] label splits it: -[x]->)'); return; }
939
1049
  let mid=null, op=null;
940
1050
  if(s[i]==='['){
941
1051
  const r=readLbl(); if(r.error){ err(n,r.error); return; } mid=r.v;
@@ -947,14 +1057,14 @@ function parseOne(text){
947
1057
  } else {
948
1058
  if(s[i]==='-'){ op='--'; i++; }
949
1059
  else if(s[i]==='>'){ op='->'; i++; }
950
- else { err(n,'edge needs an operator: -> <- -- <->'); return; }
1060
+ else { err(n,kw+' needs an operator: -> <- -- <->'); return; }
951
1061
  }
952
1062
  ws(); let head=null;
953
1063
  if(s[i]==='['){ const r=readLbl(); if(r.error){ err(n,r.error); return; } head=r.v; }
954
1064
  ws();
955
1065
  if(s[i]==='"'){ err(n,ID_RULE); return; }
956
1066
  const b=readId();
957
- if(!b){ err(n, idHere()?ID_RULE:'edge needs a target id after the operator'); return; }
1067
+ if(!b){ err(n, idHere()?ID_RULE:kw+' needs a target id after the operator'); return; }
958
1068
  if(idHere()){ err(n,ID_RULE); return; }
959
1069
  const tk2=tokenize(s.slice(i).trim());
960
1070
  if(tk2.error){ err(n,tk2.error); return; }
@@ -968,10 +1078,10 @@ function parseOne(text){
968
1078
  for(const rk in RETIRED_OPT_KEYS)
969
1079
  if(o2[rk]!==undefined){ err(n,RETIRED_OPT_KEYS[rk]); return; }
970
1080
  for(const k in o2)
971
- if(!DIRECTIVE_OPTS.edge.includes(k)){ err(n,'edge does not take '+k+'='); return; }
1081
+ if(!DIRECTIVE_OPTS[kw].includes(k)){ err(n,kw+' does not take '+k+'='); return; }
972
1082
  for(const k of ['label','taillabel','headlabel'])
973
- if(o2[k]!==undefined){ err(n,k+'= is retired — write the label inline: edge A [tail] -[mid]-> [head] B (MIGRATIONS)'); return; }
974
- if(o2.fill!==undefined){ err(n,FILL_NO_INTERIOR('edge')); return; }
1083
+ if(o2[k]!==undefined){ err(n,k+'= is retired — write the label inline: '+kw+' A [tail] -[mid]-> [head] B (MIGRATIONS 0.1)'); return; }
1084
+ if(o2.fill!==undefined){ err(n,FILL_NO_INTERIOR(kw)); return; }
975
1085
  for(const k of ['fill','stroke'])
976
1086
  if(o2[k]!==undefined && !isColor(o2[k])){ err(n,'unknown color "'+o2[k]+'" (#hex or CSS color name)'); return; }
977
1087
  // `RULE-POSITION-ENUMERATION`: `edge` was the ONE id position in the language that
@@ -1073,17 +1183,41 @@ function parseOne(text){
1073
1183
  if(findReservedSemi(raw)>=0){ err(n,RESERVED_SEMI); continue; }
1074
1184
  // edge lines carry inline [labels] with free text — dedicated scanner,
1075
1185
  // not the generic tokenizer
1076
- if(/^edge(\s|$)/.test(raw.trim())){
1186
+ // `GENRE-CONNECTOR-SPELLING`/`GENRE-NODE-SPELLING`: all THREE connector spellings are scanned here.
1187
+ // The wrong one for the genre must reach the named diagnostic below, so
1188
+ // the dispatch cannot be narrowed to the genre's own word — a `flowline`
1189
+ // under `block` would then fall through to `unrecognized line`, which is
1190
+ // exactly the answer these rulings owe an author better than.
1191
+ const mConn=/^(edge|flowline|transition)(\s|$)/.exec(raw.trim());
1192
+ if(mConn){
1193
+ const ckw=mConn[1];
1077
1194
  if(firstContent){ firstContent=false; err(n,'first line must be "figdown 0.1 <genre>"'); }
1078
1195
  cur=null;
1079
- // `CONTENT-LAYOUT-ZONE-SPLIT`: `edge` is a semantic directive, and it is dispatched here —
1196
+ // `CONTENT-LAYOUT-ZONE-SPLIT`: a connector is a semantic directive, and it is dispatched here —
1080
1197
  // before the generic layout-zone gate below — so it needs its own copy
1081
1198
  // of that gate, or it is the one semantic line that escapes the zone.
1082
- if(sawLayout){ err(n,'"edge" is a semantic directive — it must appear before the layout zone (`CONTENT-LAYOUT-ZONE-SPLIT`)'); continue; }
1083
- // `GENRE-KEYWORD-ALLOWLIST`: edge is scene vocabulary only
1084
- if(sawHeader && doc.genre && GENRE_KW[doc.genre] && !GENRE_KW[doc.genre].has('edge')){
1085
- err(n,'"edge" is not allowed in genre '+doc.genre); continue; }
1086
- parseEdgeLine(raw.trim(),n);
1199
+ if(sawLayout){ err(n,'"'+ckw+'" is a semantic directive — it must appear before the layout zone (`CONTENT-LAYOUT-ZONE-SPLIT`)'); continue; }
1200
+ // `GENRE-KEYWORD-ALLOWLIST`: a connector is scene vocabulary only — and in a scene genre it is
1201
+ // THAT genre's connector word (`GENRE-CONNECTOR-SPELLING`/`GENRE-NODE-SPELLING`), not any of the three.
1202
+ // `KEYWORD-RENAME-SCOPE`: the word this genre uses is read AT THE DECLARED VERSION, not
1203
+ // at the newest one. A genre with no connector at all (bitfield, table,
1204
+ // timing) still gets the allowlist message.
1205
+ if(sawHeader && doc.genre && GENRE_KW[doc.genre]){
1206
+ const want=connectorKwAt(doc.genre, doc.version);
1207
+ if(!want){ err(n,'"'+ckw+'" is not allowed in genre '+doc.genre); continue; }
1208
+ if(ckw!==want){
1209
+ const need=CONNECTOR_MIN_VERSION[ckw];
1210
+ // The author wrote a word this genre really does use — just not in
1211
+ // the version they declared. That is a different mistake from the
1212
+ // wrong domain's word, and it has a different one-step fix.
1213
+ if(need && doc.version && need>doc.version &&
1214
+ GENRE_CONNECTOR_KW[doc.genre]===ckw)
1215
+ err(n, WRONG_VERSION_WORD(ckw,want,doc.genre,need,doc.version));
1216
+ else
1217
+ err(n, WRONG_WORD(ckw,want,doc.genre));
1218
+ continue; }
1219
+ }
1220
+ parseEdgeLine(raw.trim(),n,ckw);
1087
1221
  continue;
1088
1222
  }
1089
1223
  const tk=tokenize(raw.trim());
@@ -1195,25 +1329,53 @@ function parseOne(text){
1195
1329
  // line. So the quoting check runs first and suppresses the value
1196
1330
  // check for that token, exactly as `badOpts` does for `shape=`.
1197
1331
  const hq1=!!posq[1], hq2=!!posq[2];
1332
+ // `STATECHART-GENRE-SCOPE`: the language version is now a SET, not a constant, so every
1333
+ // message that echoes a corrected header echoes the version the
1334
+ // author actually declared — an author on `0.2` must not be shown a
1335
+ // `0.1` example. An unrecognised version falls back to `0.1` for the
1336
+ // purpose of these examples only; it has already errored on its own.
1337
+ const verOK=!hq1 && LANG_VERSIONS.includes(pos[1]);
1338
+ const ver=verOK?pos[1]:'0.1';
1198
1339
  if(hq1) err(n,ENUM_BARE('figdown '+pos[1]+' <genre>'));
1199
- else if(hq2) err(n,ENUM_BARE('figdown 0.1 '+pos[2]));
1200
- if(!hq1 && pos[1]!=='0.1') err(n,'unsupported version "'+(pos[1]||'')+'" (expected 0.1)');
1201
- const GENRES=['block','topology','flowchart','bitfield','table','timing'];
1340
+ else if(hq2) err(n,ENUM_BARE('figdown '+ver+' '+pos[2]));
1341
+ if(!hq1 && !LANG_VERSIONS.includes(pos[1])) err(n,'unsupported version "'+(pos[1]||'')+'" (expected '+LANG_VERSIONS.join(' or ')+')');
1202
1342
  // 0.1: the genre token is REQUIRED. `bitfield`/`table`/`timing`
1203
1343
  // documents declare their kind in their content, but `block`,
1204
1344
  // `topology` and `flowchart` share the SAME vocabulary
1205
1345
  // (node/edge/group) and differ only in default flow — so the header
1206
1346
  // is the ONLY place such a document states which kind of figure it
1207
1347
  // is, and omitting it destroys the distinction with no recoverable
1208
- // fallback. The message lists the six legal values so an authoring
1209
- // agent fixes it in one step.
1210
- if(pos[2]===undefined) err(n,'figdown header requires a genre (block|topology|flowchart|bitfield|table|timing)');
1348
+ // fallback. The message lists the legal values so an authoring
1349
+ // agent fixes it in one step — the values legal AT THE DECLARED
1350
+ // VERSION, since listing `statechart` to a `figdown 0.1` author would
1351
+ // name a genre that document may not use.
1352
+ const GENRES=GENRES_BY_VERSION[ver];
1353
+ const GLIST='('+GENRES.join('|')+')';
1354
+ if(pos[2]===undefined) err(n,'figdown header requires a genre '+GLIST);
1211
1355
  else if(hq2){ /* the quoting error above is this token's one error */ }
1212
1356
  else if(pos[2]==='wave') err(n,RETIRED_WAVE);
1213
- else if(!GENRES.includes(pos[2])) err(n,'unknown genre "'+pos[2]+'" (block|topology|flowchart|bitfield|table|timing)');
1357
+ else if(!GENRES.includes(pos[2])){
1358
+ // A genre that exists but only LATER is its own diagnostic, not
1359
+ // `unknown genre`. core §13.7 forbids guessing a version, and the
1360
+ // author's one-step fix is to raise the header — which the message
1361
+ // SPELLS OUT, because "unknown genre statechart" would send them
1362
+ // looking for a typo that is not there. The trailing `— write: …`
1363
+ // is the same shape WRONG_VERSION_WORD ends with: name the fix, do
1364
+ // not leave the author to derive it.
1365
+ const later=Object.keys(GENRES_BY_VERSION).sort()
1366
+ .find(v=>v>ver && GENRES_BY_VERSION[v].includes(pos[2]));
1367
+ if(later) err(n,'genre "'+pos[2]+'" requires figdown '+later+' (this document declares '+ver+') — write: figdown '+later+' '+pos[2]);
1368
+ else err(n,'unknown genre "'+pos[2]+'" '+GLIST);
1369
+ }
1214
1370
  else{ doc.genre=pos[2];
1371
+ // The DECLARED language version is part of the model (core §12.5
1372
+ // `header.version`): a reader must be able to tell what contract
1373
+ // the author wrote against without re-reading the source.
1374
+ doc.version=ver;
1215
1375
  // genre defaults (`GENRE-NAMESPACE`/`DEFAULT-VALUE-SELECTION`): flowchart figures flow down —
1216
- // the census-dominant direction; an explicit flow line overrides
1376
+ // the census-dominant direction; an explicit `flow` directive overrides.
1377
+ // `statechart` takes the SCENE default (`right`) and adds no rule
1378
+ // of its own — `STATECHART-GENRE-SCOPE` lands a dispatch point, not a layout.
1217
1379
  if(pos[2]==='flowchart') doc.flow='down'; }
1218
1380
  // §1: a directive line carrying positional arguments its grammar does
1219
1381
  // not accept MUST be rejected — the header is a directive like any other
@@ -1257,19 +1419,19 @@ function parseOne(text){
1257
1419
  // the first entries in it that name NO replacement. `route`'s own message
1258
1420
  // has to change with them: it pointed at `path`, which no longer exists,
1259
1421
  // so it now states the whole chain and ends where the others end.
1260
- if(kw==='line'){ err(n,'line has been renamed: use threshold (a labelled reference value drawn across the target'+"'"+'s box; "line" now only names a source line number, and the 0.1 replacement `guide` was itself retired) (MIGRATIONS)'); continue; }
1422
+ if(kw==='line'){ err(n,'line has been renamed: use threshold (a labelled reference value drawn across the target'+"'"+'s box; "line" now only names a source line number, and the 0.1 replacement `guide` was itself retired) (MIGRATIONS 0.1)'); continue; }
1261
1423
  if(kw==='fill'){ err(n,'fill has been renamed: use band (a range band; the KEYWORD is retired — fill= is the presentation option key)'); continue; }
1262
1424
  if(kw==='route'){ err(n,'route has been WITHDRAWN: it was renamed path, and path was withdrawn from the language (`EDGE-GEOMETRY-CONSTRUCTS`). There is no replacement spelling. Delete the line: the edge draws under auto layout.'+WITHDRAWN_WHERE); continue; }
1263
1425
  if(kw==='path'){ err(n,RETIRED_PATH); continue; }
1264
1426
  if(kw==='routing'){ err(n,RETIRED_ROUTING); continue; }
1265
- if(kw==='render'){ err(n,'render has been renamed: use layout (the zone takes only pin — geometry, not presentation) (MIGRATIONS)'); continue; }
1427
+ if(kw==='render'){ err(n,'render has been renamed: use layout (the zone takes only pin — geometry, not presentation) (MIGRATIONS 0.1)'); continue; }
1266
1428
  if(kw==='wrap'){ err(n,RETIRED_WRAP); continue; }
1267
1429
  if(kw==='boundary'){ err(n,RETIRED_BOUNDARY); continue; }
1268
1430
  if(kw==='layer'){ err(n,RETIRED_LAYER); continue; }
1269
1431
  if(kw==='guide'){ err(n,RETIRED_GUIDE); continue; }
1270
1432
  if(kw==='wave'){ err(n,RETIRED_WAVE); continue; }
1271
1433
  if(kw==='size'){ err(n,RETIRED_SIZE); continue; }
1272
- if(kw==='plot'){ err(n,'plot has been renamed: use chart (plot reads as an imperative — the reason render was retired — while every other block opener is a noun; ECharts, Chart.js and Mermaid all name the object a chart) (MIGRATIONS)'); continue; }
1434
+ if(kw==='plot'){ err(n,'plot has been renamed: use chart (plot reads as an imperative — the reason render was retired — while every other block opener is a noun; ECharts, Chart.js and Mermaid all name the object a chart) (MIGRATIONS 0.1)'); continue; }
1273
1435
 
1274
1436
  // typed-block children
1275
1437
  if(cur && ['field','break','cell','width','signal','gap'].includes(kw)){
@@ -1347,7 +1509,7 @@ function parseOne(text){
1347
1509
  if(opts.index!==undefined){
1348
1510
  err(n,'index= is not available on the compact field form — the range would apply LINE-wide, saying that every item repeats over the same indices. Write the repeated element in the classic form on its own line: field "<name>" <width> index=0..7'); continue; }
1349
1511
  if(items0.length>1){
1350
- err(n,'field: the item list is ONE comma-delimited token — unexpected argument "'+items0[1]+'" (write field a:1,b:2 with no space after the comma; quote a name that contains whitespace: "Long Name":16) (MIGRATIONS)'); continue; }
1512
+ err(n,'field: the item list is ONE comma-delimited token — unexpected argument "'+items0[1]+'" (write field a:1,b:2 with no space after the comma; quote a name that contains whitespace: "Long Name":16) (MIGRATIONS 0.1)'); continue; }
1351
1513
  let bad=null; const parsed=[];
1352
1514
  for(const el of splitList(posT[1],0)){
1353
1515
  const it=el.v; if(!it) continue;
@@ -1412,7 +1574,7 @@ function parseOne(text){
1412
1574
  // `POSITIONAL-LIST-SPELLING`: comma form only; the space form is retired.
1413
1575
  const wtoks=pos.slice(1);
1414
1576
  if(wtoks.length>1){
1415
- err(n,'width takes ONE comma-delimited token: write width '+joinListForm(wtoks)+' — the space form is retired (MIGRATIONS)'); continue; }
1577
+ err(n,'width takes ONE comma-delimited token: write width '+joinListForm(wtoks)+' — the space form is retired (MIGRATIONS 0.1)'); continue; }
1416
1578
  const vals=wtoks.length?splitList(posT[1],0).map(e=>e.v):[];
1417
1579
  if(!vals.length){ err(n,'width needs one value per column (auto | <px> | <n>%)'); continue; }
1418
1580
  let badw=null;
@@ -1441,7 +1603,7 @@ function parseOne(text){
1441
1603
  // stays bare, exactly as `threshold offset=50%` does.
1442
1604
  const cadr=pos[1]||'';
1443
1605
  if(/^h?\d+,\d+$/.test(cadr)){
1444
- err(n,'cell address is now a paren point: cell ('+cadr+') — a bare comma pair is a list of two numbers, not an address (MIGRATIONS)'); continue; }
1606
+ err(n,'cell address is now a paren point: cell ('+cadr+') — a bare comma pair is a list of two numbers, not an address (MIGRATIONS 0.1)'); continue; }
1445
1607
  const rc=/^\((h?)(\d+),(\d+)\)$/.exec(cadr)||/^(h?)(\d+)$/.exec(cadr);
1446
1608
  // `RULE-POSITION-ENUMERATION`: `highlight` is a bare keyword FLAG
1447
1609
  // (vocabulary-sources.tsv `cell.highlight`), so RULE 2.4 governs it
@@ -1536,7 +1698,16 @@ function parseOne(text){
1536
1698
  // must be in the header genre allowlist. Child keywords still use the
1537
1699
  // "needs a bitfield/table/timing above" path when they appear with no cur.
1538
1700
  if(sawHeader && doc.genre && GENRE_KW[doc.genre] && !CHILD_KW.has(kw) && !GENRE_KW[doc.genre].has(kw)){
1539
- err(n,'"'+kw+'" is not allowed in genre '+doc.genre);
1701
+ // `GENRE-NODE-SPELLING`: a word this genre SPELLS DIFFERENTLY is not an
1702
+ // unknown word, and "not allowed in genre statechart" would send an
1703
+ // author looking for a construct they cannot have instead of the one
1704
+ // they already wrote. The named diagnostic says which word and why.
1705
+ // (`edge`/`flowline`/`transition` never reach here — they are
1706
+ // dispatched by their own scanner above.)
1707
+ if(NODE_SPELLINGS.has(kw) && GENRE_NODE_KW[doc.genre])
1708
+ err(n, WRONG_WORD(kw, GENRE_NODE_KW[doc.genre], doc.genre));
1709
+ else
1710
+ err(n,'"'+kw+'" is not allowed in genre '+doc.genre);
1540
1711
  continue;
1541
1712
  }
1542
1713
  if(badOpts(kw)) continue;
@@ -1562,7 +1733,7 @@ function parseOne(text){
1562
1733
  // meaning: the token is a normal quoted string and the generic
1563
1734
  // tokenizer above has already resolved its escapes.
1564
1735
  const t0=tk.toks[1];
1565
- if(!t0||!t0.q){ err(n,'title needs a quoted string: title "<text>" (MIGRATIONS)'); break; }
1736
+ if(!t0||!t0.q){ err(n,'title needs a quoted string: title "<text>" (MIGRATIONS 0.1)'); break; }
1566
1737
  if(tk.toks.length>2){ err(n,'unexpected argument "'+tk.toks[2].v+'"'); break; }
1567
1738
  doc.title=t0.v; sawTitle=true; break;
1568
1739
  }
@@ -1624,9 +1795,15 @@ function parseOne(text){
1624
1795
  // being wrong is harmless, and a flowchart node may be a datastore, an
1625
1796
  // annotation or a state, so `role:"process"` by default would let the
1626
1797
  // model assert a falsehood the figure cannot be inspected to catch.
1798
+ // `GENRE-NODE-SPELLING`: `state` joins the same case. It is `node` renamed
1799
+ // for one genre, not a role — a statechart node has exactly one kind,
1800
+ // so there is no role to record and `role` stays null, exactly as a
1801
+ // bare `node` does. The DRAWING is unchanged too (`shape=box` default),
1802
+ // which is what let the five corpus figures migrate byte-identically.
1627
1803
  case 'process': case 'decision': case 'terminator':
1804
+ case 'state':
1628
1805
  case 'node': {
1629
- const role=kw==='node'?null:kw;
1806
+ const role=(kw==='node'||kw==='state')?null:kw;
1630
1807
  const id=pos[1];
1631
1808
  { const e=idErr(id,posq[1],kw+' needs an id'); if(e){ err(n,e); break; } }
1632
1809
  if(dupId(id)){ err(n,'duplicate id "'+id+'"'); break; }
@@ -1695,7 +1872,7 @@ function parseOne(text){
1695
1872
  break;
1696
1873
  }
1697
1874
  case 'flow': {
1698
- if(sawFlow){ err(n,'duplicate flow line'); break; }
1875
+ if(sawFlow){ err(n,'duplicate flow directive'); break; }
1699
1876
  // `RULE-POSITION-ENUMERATION`: `flow.direction` is an enum position — bare.
1700
1877
  if(posq[1]){ err(n,ENUM_BARE('flow '+pos[1])); break; }
1701
1878
  if(!['right','down','left','up'].includes(pos[1])){ err(n,'flow needs right|down|left|up'); break; }
@@ -1728,7 +1905,7 @@ function parseOne(text){
1728
1905
  // could not even detect a half-converted line.
1729
1906
  const rtoks=pos.slice(1), rT=posT.slice(1);
1730
1907
  if(rtoks.length>1){
1731
- err(n,'rank takes ONE comma-delimited token: write rank '+joinListForm(rtoks)+' — the space form is retired (MIGRATIONS)'); break; }
1908
+ err(n,'rank takes ONE comma-delimited token: write rank '+joinListForm(rtoks)+' — the space form is retired (MIGRATIONS 0.1)'); break; }
1732
1909
  const rels=rtoks.length?splitList(rT[0],0):[];
1733
1910
  let badr=null;
1734
1911
  for(const e of rels){
@@ -1768,7 +1945,7 @@ function parseOne(text){
1768
1945
  // is now detectable — a second positional token after the label is
1769
1946
  // the half-converted line the old tolerance could not report.
1770
1947
  if(restT.length>1){
1771
- err(n,'bundle members take ONE comma-delimited token: write bundle '+id+(tlabel===null?'':' "'+tlabel+'"')+' '+joinListForm(restT.map(t=>t.v))+' — the space form is retired (MIGRATIONS)'); break; }
1948
+ err(n,'bundle members take ONE comma-delimited token: write bundle '+id+(tlabel===null?'':' "'+tlabel+'"')+' '+joinListForm(restT.map(t=>t.v))+' — the space form is retired (MIGRATIONS 0.1)'); break; }
1772
1949
  const pairs=[]; let badp=null;
1773
1950
  outerB:
1774
1951
  for(const t of restT){
@@ -1818,7 +1995,7 @@ function parseOne(text){
1818
1995
  // percentage" `offset` (on <stop>), which is the same source the
1819
1996
  // paint keys come from, so nothing is invented.
1820
1997
  if(opts.at!==undefined){
1821
- err(n,'threshold at= has been renamed: use offset=<0..100>% (at= is the pin POINT in canvas px; SVG spells a position along an extent "offset") (MIGRATIONS)'); break; }
1998
+ err(n,'threshold at= has been renamed: use offset=<0..100>% (at= is the pin POINT in canvas px; SVG spells a position along an extent "offset") (MIGRATIONS 0.1)'); break; }
1822
1999
  const m=/^(\d+(?:\.\d+)?)%$/.exec(opts.offset||''); // % is mandatory (`BARE-FRACTION-VALUES`)
1823
2000
  if(!m||+m[1]<0||+m[1]>100){ err(n,'threshold needs offset=<0..100>% (with the % sign)'); break; }
1824
2001
  // §5: `stroke=` is the marker colour, `color=` the label colour,
@@ -1869,7 +2046,7 @@ function parseOne(text){
1869
2046
  // reads the same way. `OPTION-POSITION-PARSING` quotedness is `pos`-aligned, so an option
1870
2047
  // may still precede it.
1871
2048
  const flabel=posq[1]?pos[1]:null;
1872
- if(flabel===null){ err(n,'band needs a quoted "<label>" first: band "<name>" <a>..<b>% in=<node-or-group-id> (a band with no label asserts nothing a reader may keep — fill= is presentation, and §5 forbids meaning riding on colour alone) (MIGRATIONS)'); break; }
2049
+ if(flabel===null){ err(n,'band needs a quoted "<label>" first: band "<name>" <a>..<b>% in=<node-or-group-id> (a band with no label asserts nothing a reader may keep — fill= is presentation, and §5 forbids meaning riding on colour alone) (MIGRATIONS 0.1)'); break; }
1873
2050
  if(!opts['in']){ err(n,'band needs in=<node-or-group-id>'); break; }
1874
2051
  // 0.1: the `%` is MANDATORY, matching `threshold offset=` (`BARE-FRACTION-VALUES`).
1875
2052
  // `band 15`, `band 15-35` and `band 15%-35` all parsed before (the
@@ -1884,7 +2061,7 @@ function parseOne(text){
1884
2061
  // cited by `bitfield`. `band` is EXPERIMENTAL (`CONSTRUCT-STATUS-TIERS`), so no
1885
2062
  // compatibility promise is owed; the diagnostic is owed anyway.
1886
2063
  if(/^(\d+(?:\.\d+)?)-(\d+(?:\.\d+)?)%$/.test(pos[2]||'')){
1887
- err(n,'the hyphen range "'+pos[2]+'" is no longer the spelling: write band "'+flabel+'" '+String(pos[2]).replace('-','..')+' in=… — FigDown has ONE range grammar, "..", and a hyphen between two numbers reads as subtraction (MIGRATIONS)'); break; }
2064
+ err(n,'the hyphen range "'+pos[2]+'" is no longer the spelling: write band "'+flabel+'" '+String(pos[2]).replace('-','..')+' in=… — FigDown has ONE range grammar, "..", and a hyphen between two numbers reads as subtraction (MIGRATIONS 0.1)'); break; }
1888
2065
  const m=/^(\d+(?:\.\d+)?)%$|^(\d+(?:\.\d+)?)\.\.(\d+(?:\.\d+)?)%$/.exec(pos[2]||'');
1889
2066
  if(!m){ err(n,'band needs a range with the % sign: band "<label>" <pct>% or band "<label>" <a>..<b>%'); break; }
1890
2067
  if(pos.length>3){ err(n,'unexpected argument "'+pos[3]+'"'); break; }
@@ -1917,7 +2094,7 @@ function parseOne(text){
1917
2094
  if(!id){ err(n,PIN_SHAPE); break; }
1918
2095
  // 0.1 (RULE 1.1a): the pair is PARENTHESISED — at=(x,y).
1919
2096
  if(at!==undefined&&/^-?\d+(?:\.\d+)?,-?\d+(?:\.\d+)?$/.test(at)){
1920
- err(n,'pin at= now takes a paren point: at=('+at+') — a bare comma pair is a list of two numbers, not a point (MIGRATIONS)'); break; }
2097
+ err(n,'pin at= now takes a paren point: at=('+at+') — a bare comma pair is a list of two numbers, not a point (MIGRATIONS 0.1)'); break; }
1921
2098
  const m=at===undefined?null:/^\((-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)\)$/.exec(at);
1922
2099
  // A WRITTEN `at=` that does not parse is its own error, never the
1923
2100
  // whole-line shape message: the author declared a point and got the
@@ -2126,9 +2303,9 @@ function parseOne(text){
2126
2303
  if(!c||c.stroke!==undefined) continue;
2127
2304
  if(c.fill===undefined&&c.style!==undefined) continue;
2128
2305
  if(c.fill!==undefined)
2129
- errs.push('Line '+e.line+': class "'+cid+'" sets fill= but no stroke=, and an edge has no interior — add stroke= to the class (it paints the edge; fill= keeps painting members that have an interior) (MIGRATIONS)');
2306
+ errs.push('Line '+e.line+': class "'+cid+'" sets fill= but no stroke=, and an edge has no interior — add stroke= to the class (it paints the edge; fill= keeps painting members that have an interior) (MIGRATIONS 0.1)');
2130
2307
  else
2131
- errs.push('Line '+e.line+': class "'+cid+'" declares no channel an edge has — add stroke= (an edge has only stroke= and style=: no interior, and v0.1 has no label-colour key). Without one the edge takes the default colour and the class shows nothing in the legend (MIGRATIONS)');
2308
+ errs.push('Line '+e.line+': class "'+cid+'" declares no channel an edge has — add stroke= (an edge has only stroke= and style=: no interior, and v0.1 has no label-colour key). Without one the edge takes the default colour and the class shows nothing in the legend (MIGRATIONS 0.1)');
2132
2309
  }
2133
2310
  }
2134
2311
  { // class references must resolve (closed grammar)
@@ -2305,7 +2482,7 @@ function findReservedSemi(s){
2305
2482
  }
2306
2483
  return -1;
2307
2484
  }
2308
- const RESERVED_SEMI='";" is reserved for a future statement separator and has no meaning in v0.1 — write one directive per line; a literal ";" belongs inside a quoted string, an [edge label] or a comment (MIGRATIONS)';
2485
+ const RESERVED_SEMI='";" is reserved for a future statement separator and has no meaning in v0.1 — write one directive per line; a literal ";" belongs inside a quoted string, an [edge label] or a comment (MIGRATIONS 0.1)';
2309
2486
 
2310
2487
  function findComment(s){
2311
2488
  // '#' starts a comment only at line start or after whitespace,
@@ -2350,6 +2527,80 @@ function findComment(s){
2350
2527
  // 2. LAYOUT + RENDER (deterministic; no randomness, no Date)
2351
2528
  // ============================================================
2352
2529
  const FONT=13, CH=7.2, PADX=14, NH=36, GAPX=56, GAPY=44;
2530
+
2531
+ // ---- cw(): script-aware advance width --------------------------------
2532
+ // Every px-per-character constant in this file — CH here, and its siblings at
2533
+ // the other font sizes (8.6 title, 6.6 legend, 6.5 edge label, 6.3/6.2 bitfield
2534
+ // caption) — is calibrated on LATIN, where one character advances ~0.554 em.
2535
+ // That is a claim about SCRIPT, not about font: a CJK ideograph advances a full
2536
+ // em, so counting characters undersizes a Chinese label by 45% and the engine
2537
+ // draws the text outside the box it has just sized for it. cw() is the measure
2538
+ // those constants multiply — a string's advance in Latin units. Every codepoint
2539
+ // below U+0300 weighs exactly 1, so an all-ASCII string returns exactly its
2540
+ // .length and every figure that was already right stays byte-identical.
2541
+ //
2542
+ // The classes are Unicode East Asian Width (UAX #11), a fixed character
2543
+ // property: a lookup by codepoint range, deterministic, no font-metrics library
2544
+ // and no canvas measurement at render time. The WEIGHTS are measured, not
2545
+ // chosen — probe strings rendered through librsvg at font-size 13 in the
2546
+ // engine's own stack (font-family="system-ui,sans-serif" → Noto Sans + Noto
2547
+ // Sans CJK), advance recovered as the slope of ink extent over repeat count:
2548
+ // ideograph 封 一 㐀, kana あ ア, bopomofo ㄅ, fullwidth A ,, U+3000 13.000px = 1.000em
2549
+ // emoji U+1F600 U+1F680 (Noto Color Emoji) 16.188px = 1.245em
2550
+ // combining U+0301 standalone, U+200B, U+FEFF 0.000px = 0.000em
2551
+ // Latin — the calibration these constants already carry 7.200px = 0.554em
2552
+ // hence WIDE = 1.000/0.554 = 1.806, rounded UP to 1.81 so a wide glyph is never
2553
+ // UNDER-measured at the node-label site, and EMOJI = 1.245/0.554 = 2.25.
2554
+ // Halfwidth katakana (U+FF61..FF9F) measured 0.500 em: it stays in the default
2555
+ // class, which over-measures it by 11% — the safe direction.
2556
+ //
2557
+ // EAW *Ambiguous* — §, —, –, →, ←, ✓, ≤, •, the only non-ASCII this
2558
+ // repository's figures actually draw — is deliberately NARROW, the
2559
+ // wcwidth/POSIX reading for a non-East-Asian context. Measured, an em dash is
2560
+ // a full em in this font, so a label carrying one is still under-measured by
2561
+ // 0.45 unit; that is a different question from this defect (it needs a
2562
+ // context rule, not a table) and is not decided here.
2563
+ const CW_ZERO=[[0x0300,0x036F],[0x0483,0x0489],[0x0591,0x05BD],[0x0610,0x061A],
2564
+ [0x064B,0x065F],[0x0670,0x0670],[0x06D6,0x06DC],[0x0711,0x0711],[0x0730,0x074A],
2565
+ [0x07A6,0x07B0],[0x0816,0x0819],[0x093C,0x093C],[0x0951,0x0954],[0x0E31,0x0E31],
2566
+ [0x0E34,0x0E3A],[0x0E47,0x0E4E],[0x1AB0,0x1AFF],[0x1DC0,0x1DFF],[0x200B,0x200F],
2567
+ [0x2060,0x2064],[0x20D0,0x20F0],[0xFE00,0xFE0F],[0xFE20,0xFE2F],[0xFEFF,0xFEFF]];
2568
+ const CW_EMOJI=[[0x1F004,0x1F0CF],[0x1F18E,0x1F19A],[0x1F300,0x1F5FF],
2569
+ [0x1F600,0x1F64F],[0x1F680,0x1F6FF],[0x1F7E0,0x1F7EB],[0x1F900,0x1F9FF],
2570
+ [0x1FA70,0x1FAFF]];
2571
+ const CW_WIDE=[[0x1100,0x115F],[0x2E80,0x303E],[0x3041,0x33FF],[0x3400,0x4DBF],
2572
+ [0x4E00,0x9FFF],[0xA000,0xA4CF],[0xA960,0xA97F],[0xAC00,0xD7A3],[0xF900,0xFAFF],
2573
+ [0xFE10,0xFE19],[0xFE30,0xFE6F],[0xFF01,0xFF60],[0xFFE0,0xFFE6],
2574
+ [0x17000,0x18AFF],[0x1B000,0x1B2FF],[0x20000,0x3FFFD]];
2575
+ // ranges are sorted and disjoint, so the scan stops at the first range that
2576
+ // starts above the codepoint
2577
+ function cwIn(cp,rs){
2578
+ for(let i=0;i<rs.length;i++){ if(cp<rs[i][0]) return false; if(cp<=rs[i][1]) return true; }
2579
+ return false;
2580
+ }
2581
+ function cwOf(cp){
2582
+ if(cp<0x0300) return 1; // ASCII and Latin-1: the calibrated case
2583
+ if(cwIn(cp,CW_ZERO)) return 0;
2584
+ if(cwIn(cp,CW_EMOJI)) return 2.25;
2585
+ if(cwIn(cp,CW_WIDE)) return 1.81;
2586
+ return 1;
2587
+ }
2588
+ // Iterate CODEPOINTS, not UTF-16 units: an astral character is one advance,
2589
+ // not two. A ZWJ emoji sequence still counts each codepoint, so it is
2590
+ // over-measured — the safe direction, and the only way to avoid it is a
2591
+ // grapheme segmenter this engine will not carry.
2592
+ function cw(s){
2593
+ s=String(s); let w=0;
2594
+ for(let i=0;i<s.length;i++){
2595
+ const cp=s.codePointAt(i);
2596
+ if(cp>0xFFFF) i++;
2597
+ w+=cwOf(cp);
2598
+ }
2599
+ return w;
2600
+ }
2601
+ // the widest line of a multi-line string, in Latin units
2602
+ function cwMax(s){ return Math.max(...String(s).split('\n').map(cw)); }
2603
+
2353
2604
  // §5 style= → SVG dash pattern. `def` is the construct's conventional
2354
2605
  // default (the bundle ring and the threshold line are dashed by convention);
2355
2606
  // an explicit style= always wins.
@@ -2359,7 +2610,7 @@ function dashOf(style,def){
2359
2610
  }
2360
2611
  function esc(s){return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');}
2361
2612
  function tw(s){
2362
- const longest=Math.max(...String(s).split('\n').map(l=>l.length));
2613
+ const longest=cwMax(s);
2363
2614
  return Math.max(30,longest*CH+2*PADX);
2364
2615
  }
2365
2616
  // ---- shape geometry (one source of truth for size and for clipping) ----
@@ -2478,7 +2729,7 @@ function inscribedHalfW(g,v){
2478
2729
  const LBLPADX=6, LBLPADY=4;
2479
2730
  function labelBox(label){
2480
2731
  const ls=String(label).split('\n');
2481
- return [Math.max(...ls.map(l=>l.length))*CH+2*LBLPADX,
2732
+ return [Math.max(...ls.map(cw))*CH+2*LBLPADX,
2482
2733
  ((ls.length-1)*1.3+1.2)*FONT+2*LBLPADY];
2483
2734
  }
2484
2735
  // fitOutline: grow the box by the smallest factor that pulls an iw x ih box,
@@ -2570,7 +2821,7 @@ function render(doc,ropts){
2570
2821
  }
2571
2822
  const parts=[]; let y=0, maxW=0;
2572
2823
  if(doc.title && RO.title===true){ parts.push('<text x="0" y="16" font-size="15" font-weight="600">'+esc(doc.title)+'</text>'); y=30;
2573
- maxW=Math.max(maxW, doc.title.length*8.6); } // canvas must fit the title
2824
+ maxW=Math.max(maxW, cw(doc.title)*8.6); } // canvas must fit the title
2574
2825
  let sceneMeta=null;
2575
2826
  if(doc.nodes.length||doc.edges.length||(doc.boundaries||[]).length){
2576
2827
  const s=renderScene(doc,y); parts.push(s.svg); y=s.y; maxW=Math.max(maxW,s.w);
@@ -2608,7 +2859,7 @@ function render(doc,ropts){
2608
2859
  // `style`) is drawn, so "declared but not shown" is now unreachable.
2609
2860
  for(const c of legendCls){
2610
2861
  const paints=c.fill!==undefined||c.stroke!==undefined||c.style!==undefined;
2611
- const tw=String(c.label).length*6.6+(paints?30:9);
2862
+ const tw=cw(c.label)*6.6+(paints?30:9);
2612
2863
  if(lx>0 && lx+tw>wrapW){ lx=0; ly+=rowH; }
2613
2864
  if(paints){
2614
2865
  const dash=c.style==='dashed'?' stroke-dasharray="6 4"':(c.style==='dotted'?' stroke-dasharray="2 4"':'');
@@ -2721,7 +2972,7 @@ function renderScene(doc,y0){
2721
2972
  // ALL nodes participate in auto layout (pinned ones hold their slot so
2722
2973
  // that pinning X never reflows Y); pins override coordinates afterwards.
2723
2974
  const horiz=(doc.flow==='right'||doc.flow==='left');
2724
- const lblPx=s=>Math.max(...String(s).split('\n').map(l=>l.length))*6.5;
2975
+ const lblPx=s=>cwMax(s)*6.5;
2725
2976
  const lay=[...nodes]; // layout participants
2726
2977
  const chains=new Map(); // edge -> [A, ...waypoints, B]
2727
2978
  for(const e of doc.edges){
@@ -3405,7 +3656,7 @@ function renderScene(doc,y0){
3405
3656
  const CLAMP=t=>Math.max(0.06,Math.min(0.94,t));
3406
3657
  const cand=(r,t,side)=>{
3407
3658
  const lines=String(r.text).split('\n'), n=lines.length;
3408
- const w=Math.max(...lines.map(l=>l.length))*6.5*r.fs/11;
3659
+ const w=Math.max(...lines.map(cw))*6.5*r.fs/11;
3409
3660
  const lh=r.fs*1.3, h=(n-1)*lh+r.fs*1.1;
3410
3661
  const up=(n-1)*lh/2+r.fs*0.85; // baseline y = box top + up
3411
3662
  const mx=r.p[0]+(r.q[0]-r.p[0])*t, my=r.p[1]+(r.q[1]-r.p[1])*t;
@@ -3511,7 +3762,7 @@ function renderScene(doc,y0){
3511
3762
  // label with shrink-to-fit when size is rigid (`UNDECLARED-ATTRIBUTE-BEHAVIOUR`); multi-line via "\n"
3512
3763
  let fs=FONT;
3513
3764
  const nl=String(n.label).split('\n');
3514
- const need=Math.max(...nl.map(l=>l.length))*CH;
3765
+ const need=Math.max(...nl.map(cw))*CH;
3515
3766
  // budget = the width the OUTLINE offers at the label's own height, minus
3516
3767
  // 8 px clearance each side. For a box that is n.w-16, exactly as before;
3517
3768
  // for a rhombus or an ellipse it is the inscribed width, so a rigid
@@ -4055,7 +4306,7 @@ function renderBitfield(b,y0){
4055
4306
  const cap=bi===0?String(f.name)+suffix:CONT;
4056
4307
  let lead=bx[0]; for(const s of bx) if(s.w>lead.w) lead=s;
4057
4308
  const ly=flat ? bx[0].y+bx.length*rh/2 : lead.y+rh/2;
4058
- let fs=11; const need=cap.length*6.2;
4309
+ let fs=11; const need=cw(cap)*6.2;
4059
4310
  // The font shrinks to fit the segment that carries it, floor 7px — the
4060
4311
  // rule a too-narrow one-row field has always had. Below the floor the
4061
4312
  // caption overflows its box rather than vanishing: a name half outside
@@ -4149,7 +4400,7 @@ function renderBitfield(b,y0){
4149
4400
  // job.
4150
4401
  svg.push('<line x1="'+e.x+'" y1="'+e.y+'" x2="'+e.x+'" y2="'+(e.y+EL_H)+'" stroke="'+st+'" stroke-dasharray="2 3"/>');
4151
4402
  svg.push('<line x1="'+(e.x+e.w)+'" y1="'+e.y+'" x2="'+(e.x+e.w)+'" y2="'+(e.y+EL_H)+'" stroke="'+st+'" stroke-dasharray="2 3"/>');
4152
- let fs=10.5; const need=e.text.length*6.2;
4403
+ let fs=10.5; const need=cw(e.text)*6.2;
4153
4404
  if(need>e.w-6) fs=Math.max(7,10.5*(e.w-6)/need);
4154
4405
  svg.push('<text x="'+(e.x+e.w/2)+'" y="'+(e.y+EL_H/2+fs*0.35)+'" font-size="'+fs+'" text-anchor="middle" fill="#6f6e69">'+esc(e.text)+'</text>');
4155
4406
  }
@@ -4169,7 +4420,7 @@ function renderBitfield(b,y0){
4169
4420
  for(const f of capt){
4170
4421
  const s=f.name+' — present: '+f.present;
4171
4422
  svg.push('<text x="0" y="'+(yb+9)+'" font-size="10.5" fill="#6f6e69">'+esc(s)+'</text>');
4172
- wb=Math.max(wb, s.length*6.3+2); yb+=14;
4423
+ wb=Math.max(wb, cw(s)*6.3+2); yb+=14;
4173
4424
  }
4174
4425
  yb+=2;
4175
4426
  }