@cardenelabs/dragon 0.36.3 → 0.37.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/index.cjs CHANGED
@@ -55,6 +55,7 @@ var ja = {
55
55
  minimum: (limit) => `${limit} \u4EE5\u4E0A\u306B\u3059\u308B`,
56
56
  const: (value2) => `${value2} \u306B\u3059\u308B`,
57
57
  not: (allowed) => allowed ? `${allowed.field} \u306E\u6B04\u306F kind \u304C ${allowed.kind} \u306E\u6642\u3060\u3051\u66F8\u3051\u308B` : "\u3053\u306E\u6B04\u306E\u7D44\u307F\u5408\u308F\u305B\u306F\u66F8\u3051\u306A\u3044",
58
+ reserved: (names) => `${names.join(" \u3068 ")} \u306F\u72B6\u614B\u9077\u79FB\u56F3\u306E\u59CB\u307E\u308A\u3068\u7D42\u308F\u308A\u306E\u5370\u306E\u540D\u524D\u3067\u3001\u7BB1\u306E\u540D\u672D\u306B\u4F7F\u3048\u306A\u3044`,
58
59
  anyOf: (fields) => fields.length > 0 ? `${fields.join(" \u304B ")} \u306E${fields.length === 2 ? "\u3069\u3061\u3089\u304B" : "\u3069\u308C\u304B"}\u306E\u6B04\u304C\u8981\u308B` : "\u66F8\u3051\u308B\u5F62\u306E\u3069\u308C\u306B\u3082\u5408\u308F\u306A\u3044",
59
60
  oneOf: "\u66F8\u3051\u308B\u5F62\u306E\u3069\u308C\u304B 1 \u3064\u3060\u3051\u306B\u5408\u308F\u305B\u308B",
60
61
  discriminator: (tag, values) => `${tag} \u306F ${values.join(" / ")} \u306E\u3069\u308C\u304B\u306B\u3059\u308B`,
@@ -71,6 +72,7 @@ var en = {
71
72
  minimum: (limit) => `Use ${limit} or greater`,
72
73
  const: (value2) => `Use ${value2}`,
73
74
  not: (allowed) => allowed ? `The ${allowed.field} field is allowed only when kind is ${allowed.kind}` : "This combination of fields is not allowed",
75
+ reserved: (names) => `${names.join(" and ")} name the start and end marks of a state diagram and cannot be box ids`,
74
76
  anyOf: (fields) => fields.length > 0 ? `Write one of the ${fields.join(" or ")} fields` : "Does not match any of the allowed shapes",
75
77
  oneOf: "Match exactly one of the allowed shapes",
76
78
  discriminator: (tag, values) => `${tag} is one of ${values.join(" / ")}`,
@@ -85,7 +87,7 @@ function ucs2length(str) {
85
87
  return length;
86
88
  }
87
89
  var validate_diagram_default = validate10;
88
- var schema11 = { "properties": { "version": { "description": "\u5F62\u5F0F\u306E\u7248", "type": "integer", "minimum": 1 }, "kind": { "description": "\u56F3\u306E\u7A2E\u985E", "enum": ["sequence", "architecture"] }, "title": { "$ref": "#/definitions/text" }, "view": { "description": "\u898B\u305B\u65B9\u3002\u66F8\u304B\u306A\u3051\u308C\u3070\u5B57\u306E\u5927\u304D\u3055\u3067\u9078\u3076\u3002fixed \u306F\u5168\u4F53\u3092\u6B62\u3081\u3066\u4E2D\u3060\u3051\u52D5\u304B\u3057\u3001follow \u306F\u5BC4\u3063\u3066\u52D5\u304B\u3057\u5168\u4F53\u56F3\u3067\u4ECA\u3069\u3053\u304B\u3092\u793A\u3059", "enum": ["fixed", "follow"] }, "regions": { "type": "array", "items": { "$ref": "#/definitions/region" } }, "boxes": { "type": "array", "minItems": 1, "items": { "$ref": "#/definitions/box" } }, "strip": { "$ref": "#/definitions/strip" }, "steps": { "type": "array", "minItems": 1, "items": { "$ref": "#/definitions/step" } }, "sequence": { "$ref": "#/definitions/sequence" } }};
90
+ var schema11 = { "properties": { "version": { "description": "\u5F62\u5F0F\u306E\u7248", "type": "integer", "minimum": 1 }, "kind": { "description": "\u56F3\u306E\u7A2E\u985E", "enum": ["sequence", "architecture", "state"] }, "title": { "$ref": "#/definitions/text" }, "view": { "description": "\u898B\u305B\u65B9\u3002\u66F8\u304B\u306A\u3051\u308C\u3070\u5B57\u306E\u5927\u304D\u3055\u3067\u9078\u3076\u3002fixed \u306F\u5168\u4F53\u3092\u6B62\u3081\u3066\u4E2D\u3060\u3051\u52D5\u304B\u3057\u3001follow \u306F\u5BC4\u3063\u3066\u52D5\u304B\u3057\u5168\u4F53\u56F3\u3067\u4ECA\u3069\u3053\u304B\u3092\u793A\u3059", "enum": ["fixed", "follow"] }, "regions": { "type": "array", "items": { "$ref": "#/definitions/region" } }, "boxes": { "type": "array", "minItems": 1, "items": { "$ref": "#/definitions/box" } }, "strip": { "$ref": "#/definitions/strip" }, "steps": { "type": "array", "minItems": 1, "items": { "$ref": "#/definitions/step" } }, "sequence": { "$ref": "#/definitions/sequence" }, "state": { "$ref": "#/definitions/state" } }};
89
91
  var func2 = Object.prototype.hasOwnProperty;
90
92
  var func3 = ucs2length;
91
93
  var schema17 = { "enum": ["blue", "amber", "green", "violet", "rose", "slate", "coin"] };
@@ -1479,6 +1481,182 @@ function validate23(data, { instancePath = "", parentData, parentDataProperty, r
1479
1481
  validate23.errors = vErrors;
1480
1482
  return errors === 0;
1481
1483
  }
1484
+ function validate26(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
1485
+ let vErrors = null;
1486
+ let errors = 0;
1487
+ if (data && typeof data == "object" && !Array.isArray(data)) {
1488
+ if (data.from === void 0) {
1489
+ const err0 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "from" }, message: "must have required property 'from'" };
1490
+ if (vErrors === null) {
1491
+ vErrors = [err0];
1492
+ } else {
1493
+ vErrors.push(err0);
1494
+ }
1495
+ errors++;
1496
+ }
1497
+ if (data.to === void 0) {
1498
+ const err1 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "to" }, message: "must have required property 'to'" };
1499
+ if (vErrors === null) {
1500
+ vErrors = [err1];
1501
+ } else {
1502
+ vErrors.push(err1);
1503
+ }
1504
+ errors++;
1505
+ }
1506
+ for (const key0 in data) {
1507
+ if (!(key0 === "from" || key0 === "to" || key0 === "label")) {
1508
+ const err2 = { instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" };
1509
+ if (vErrors === null) {
1510
+ vErrors = [err2];
1511
+ } else {
1512
+ vErrors.push(err2);
1513
+ }
1514
+ errors++;
1515
+ }
1516
+ }
1517
+ if (data.from !== void 0) {
1518
+ let data0 = data.from;
1519
+ if (typeof data0 === "string") {
1520
+ if (!pattern0.test(data0)) {
1521
+ const err3 = { instancePath: instancePath + "/from", schemaPath: "#/definitions/id/pattern", keyword: "pattern", params: { pattern: "^[^\\s\\[\\]\u300C\u300D=:]+$" }, message: 'must match pattern "^[^\\s\\[\\]\u300C\u300D=:]+$"' };
1522
+ if (vErrors === null) {
1523
+ vErrors = [err3];
1524
+ } else {
1525
+ vErrors.push(err3);
1526
+ }
1527
+ errors++;
1528
+ }
1529
+ } else {
1530
+ const err4 = { instancePath: instancePath + "/from", schemaPath: "#/definitions/id/type", keyword: "type", params: { type: "string" }, message: "must be string" };
1531
+ if (vErrors === null) {
1532
+ vErrors = [err4];
1533
+ } else {
1534
+ vErrors.push(err4);
1535
+ }
1536
+ errors++;
1537
+ }
1538
+ }
1539
+ if (data.to !== void 0) {
1540
+ let data1 = data.to;
1541
+ if (typeof data1 === "string") {
1542
+ if (!pattern0.test(data1)) {
1543
+ const err5 = { instancePath: instancePath + "/to", schemaPath: "#/definitions/id/pattern", keyword: "pattern", params: { pattern: "^[^\\s\\[\\]\u300C\u300D=:]+$" }, message: 'must match pattern "^[^\\s\\[\\]\u300C\u300D=:]+$"' };
1544
+ if (vErrors === null) {
1545
+ vErrors = [err5];
1546
+ } else {
1547
+ vErrors.push(err5);
1548
+ }
1549
+ errors++;
1550
+ }
1551
+ } else {
1552
+ const err6 = { instancePath: instancePath + "/to", schemaPath: "#/definitions/id/type", keyword: "type", params: { type: "string" }, message: "must be string" };
1553
+ if (vErrors === null) {
1554
+ vErrors = [err6];
1555
+ } else {
1556
+ vErrors.push(err6);
1557
+ }
1558
+ errors++;
1559
+ }
1560
+ }
1561
+ if (data.label !== void 0) {
1562
+ let data2 = data.label;
1563
+ if (typeof data2 === "string") {
1564
+ if (func3(data2) < 1) {
1565
+ const err7 = { instancePath: instancePath + "/label", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
1566
+ if (vErrors === null) {
1567
+ vErrors = [err7];
1568
+ } else {
1569
+ vErrors.push(err7);
1570
+ }
1571
+ errors++;
1572
+ }
1573
+ } else {
1574
+ const err8 = { instancePath: instancePath + "/label", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
1575
+ if (vErrors === null) {
1576
+ vErrors = [err8];
1577
+ } else {
1578
+ vErrors.push(err8);
1579
+ }
1580
+ errors++;
1581
+ }
1582
+ }
1583
+ } else {
1584
+ const err9 = { instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" };
1585
+ if (vErrors === null) {
1586
+ vErrors = [err9];
1587
+ } else {
1588
+ vErrors.push(err9);
1589
+ }
1590
+ errors++;
1591
+ }
1592
+ validate26.errors = vErrors;
1593
+ return errors === 0;
1594
+ }
1595
+ function validate25(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
1596
+ let vErrors = null;
1597
+ let errors = 0;
1598
+ if (data && typeof data == "object" && !Array.isArray(data)) {
1599
+ if (data.paths === void 0) {
1600
+ const err0 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "paths" }, message: "must have required property 'paths'" };
1601
+ if (vErrors === null) {
1602
+ vErrors = [err0];
1603
+ } else {
1604
+ vErrors.push(err0);
1605
+ }
1606
+ errors++;
1607
+ }
1608
+ for (const key0 in data) {
1609
+ if (!(key0 === "paths")) {
1610
+ const err1 = { instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" };
1611
+ if (vErrors === null) {
1612
+ vErrors = [err1];
1613
+ } else {
1614
+ vErrors.push(err1);
1615
+ }
1616
+ errors++;
1617
+ }
1618
+ }
1619
+ if (data.paths !== void 0) {
1620
+ let data0 = data.paths;
1621
+ if (Array.isArray(data0)) {
1622
+ if (data0.length < 1) {
1623
+ const err2 = { instancePath: instancePath + "/paths", schemaPath: "#/properties/paths/minItems", keyword: "minItems", params: { limit: 1 }, message: "must NOT have fewer than 1 items" };
1624
+ if (vErrors === null) {
1625
+ vErrors = [err2];
1626
+ } else {
1627
+ vErrors.push(err2);
1628
+ }
1629
+ errors++;
1630
+ }
1631
+ const len0 = data0.length;
1632
+ for (let i0 = 0; i0 < len0; i0++) {
1633
+ if (!validate26(data0[i0], { instancePath: instancePath + "/paths/" + i0, parentData: data0, parentDataProperty: i0, rootData })) {
1634
+ vErrors = vErrors === null ? validate26.errors : vErrors.concat(validate26.errors);
1635
+ errors = vErrors.length;
1636
+ }
1637
+ }
1638
+ } else {
1639
+ const err3 = { instancePath: instancePath + "/paths", schemaPath: "#/properties/paths/type", keyword: "type", params: { type: "array" }, message: "must be array" };
1640
+ if (vErrors === null) {
1641
+ vErrors = [err3];
1642
+ } else {
1643
+ vErrors.push(err3);
1644
+ }
1645
+ errors++;
1646
+ }
1647
+ }
1648
+ } else {
1649
+ const err4 = { instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" };
1650
+ if (vErrors === null) {
1651
+ vErrors = [err4];
1652
+ } else {
1653
+ vErrors.push(err4);
1654
+ }
1655
+ errors++;
1656
+ }
1657
+ validate25.errors = vErrors;
1658
+ return errors === 0;
1659
+ }
1482
1660
  function validate10(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
1483
1661
  let vErrors = null;
1484
1662
  let errors = 0;
@@ -1520,9 +1698,11 @@ function validate10(data, { instancePath = "", parentData, parentDataProperty, r
1520
1698
  let ifClause0;
1521
1699
  if (_valid0) {
1522
1700
  const _errs4 = errors;
1701
+ const _errs5 = errors;
1702
+ const _errs6 = errors;
1523
1703
  if (data && typeof data == "object" && !Array.isArray(data)) {
1524
- if (data.sequence === void 0) {
1525
- const err2 = { instancePath, schemaPath: "#/then/required", keyword: "required", params: { missingProperty: "sequence" }, message: "must have required property 'sequence'" };
1704
+ if (data.state === void 0 && ("state")) {
1705
+ const err2 = {};
1526
1706
  if (vErrors === null) {
1527
1707
  vErrors = [err2];
1528
1708
  } else {
@@ -1531,227 +1711,391 @@ function validate10(data, { instancePath = "", parentData, parentDataProperty, r
1531
1711
  errors++;
1532
1712
  }
1533
1713
  }
1714
+ var valid2 = _errs6 === errors;
1715
+ if (valid2) {
1716
+ const err3 = { instancePath, schemaPath: "#/then/not", keyword: "not", params: {}, message: "must NOT be valid" };
1717
+ if (vErrors === null) {
1718
+ vErrors = [err3];
1719
+ } else {
1720
+ vErrors.push(err3);
1721
+ }
1722
+ errors++;
1723
+ } else {
1724
+ errors = _errs5;
1725
+ if (vErrors !== null) {
1726
+ if (_errs5) {
1727
+ vErrors.length = _errs5;
1728
+ } else {
1729
+ vErrors = null;
1730
+ }
1731
+ }
1732
+ }
1733
+ if (data && typeof data == "object" && !Array.isArray(data)) {
1734
+ if (data.sequence === void 0) {
1735
+ const err4 = { instancePath, schemaPath: "#/then/required", keyword: "required", params: { missingProperty: "sequence" }, message: "must have required property 'sequence'" };
1736
+ if (vErrors === null) {
1737
+ vErrors = [err4];
1738
+ } else {
1739
+ vErrors.push(err4);
1740
+ }
1741
+ errors++;
1742
+ }
1743
+ }
1534
1744
  var _valid0 = _errs4 === errors;
1535
1745
  valid0 = _valid0;
1536
1746
  ifClause0 = "then";
1537
1747
  } else {
1538
- const _errs5 = errors;
1539
- const _errs6 = errors;
1540
1748
  const _errs7 = errors;
1749
+ const _errs8 = errors;
1750
+ const _errs9 = errors;
1541
1751
  if (data && typeof data == "object" && !Array.isArray(data)) {
1542
1752
  if (data.sequence === void 0 && ("sequence")) {
1543
- const err3 = {};
1753
+ const err5 = {};
1544
1754
  if (vErrors === null) {
1545
- vErrors = [err3];
1755
+ vErrors = [err5];
1546
1756
  } else {
1547
- vErrors.push(err3);
1757
+ vErrors.push(err5);
1548
1758
  }
1549
1759
  errors++;
1550
1760
  }
1551
1761
  }
1552
- var valid2 = _errs7 === errors;
1553
- if (valid2) {
1554
- const err4 = { instancePath, schemaPath: "#/else/not", keyword: "not", params: {}, message: "must NOT be valid" };
1762
+ var valid3 = _errs9 === errors;
1763
+ if (valid3) {
1764
+ const err6 = { instancePath, schemaPath: "#/else/not", keyword: "not", params: {}, message: "must NOT be valid" };
1555
1765
  if (vErrors === null) {
1556
- vErrors = [err4];
1766
+ vErrors = [err6];
1557
1767
  } else {
1558
- vErrors.push(err4);
1768
+ vErrors.push(err6);
1559
1769
  }
1560
1770
  errors++;
1561
1771
  } else {
1562
- errors = _errs6;
1772
+ errors = _errs8;
1563
1773
  if (vErrors !== null) {
1564
- if (_errs6) {
1565
- vErrors.length = _errs6;
1774
+ if (_errs8) {
1775
+ vErrors.length = _errs8;
1566
1776
  } else {
1567
1777
  vErrors = null;
1568
1778
  }
1569
1779
  }
1570
1780
  }
1571
- var _valid0 = _errs5 === errors;
1781
+ const _errs10 = errors;
1782
+ let valid4 = true;
1783
+ const _errs11 = errors;
1784
+ if (data && typeof data == "object" && !Array.isArray(data)) {
1785
+ if (data.kind === void 0 && ("kind")) {
1786
+ const err7 = {};
1787
+ if (vErrors === null) {
1788
+ vErrors = [err7];
1789
+ } else {
1790
+ vErrors.push(err7);
1791
+ }
1792
+ errors++;
1793
+ } else {
1794
+ if (data.kind !== void 0) {
1795
+ if ("state" !== data.kind) {
1796
+ const err8 = {};
1797
+ if (vErrors === null) {
1798
+ vErrors = [err8];
1799
+ } else {
1800
+ vErrors.push(err8);
1801
+ }
1802
+ errors++;
1803
+ }
1804
+ }
1805
+ }
1806
+ }
1807
+ var _valid1 = _errs11 === errors;
1808
+ errors = _errs10;
1809
+ if (vErrors !== null) {
1810
+ if (_errs10) {
1811
+ vErrors.length = _errs10;
1812
+ } else {
1813
+ vErrors = null;
1814
+ }
1815
+ }
1816
+ let ifClause1;
1817
+ if (_valid1) {
1818
+ const _errs13 = errors;
1819
+ if (data && typeof data == "object" && !Array.isArray(data)) {
1820
+ if (data.boxes !== void 0) {
1821
+ let data2 = data.boxes;
1822
+ if (Array.isArray(data2)) {
1823
+ const len0 = data2.length;
1824
+ for (let i0 = 0; i0 < len0; i0++) {
1825
+ let data3 = data2[i0];
1826
+ if (data3 && typeof data3 == "object" && !Array.isArray(data3)) {
1827
+ if (data3.id !== void 0) {
1828
+ let data4 = data3.id;
1829
+ const _errs17 = errors;
1830
+ const _errs18 = errors;
1831
+ if (!(data4 === "start" || data4 === "finish")) {
1832
+ const err9 = {};
1833
+ if (vErrors === null) {
1834
+ vErrors = [err9];
1835
+ } else {
1836
+ vErrors.push(err9);
1837
+ }
1838
+ errors++;
1839
+ }
1840
+ var valid10 = _errs18 === errors;
1841
+ if (valid10) {
1842
+ const err10 = { instancePath: instancePath + "/boxes/" + i0 + "/id", schemaPath: "#/else/then/properties/boxes/items/properties/id/not", keyword: "not", params: {}, message: "must NOT be valid" };
1843
+ if (vErrors === null) {
1844
+ vErrors = [err10];
1845
+ } else {
1846
+ vErrors.push(err10);
1847
+ }
1848
+ errors++;
1849
+ } else {
1850
+ errors = _errs17;
1851
+ if (vErrors !== null) {
1852
+ if (_errs17) {
1853
+ vErrors.length = _errs17;
1854
+ } else {
1855
+ vErrors = null;
1856
+ }
1857
+ }
1858
+ }
1859
+ }
1860
+ }
1861
+ }
1862
+ }
1863
+ }
1864
+ }
1865
+ var _valid1 = _errs13 === errors;
1866
+ valid4 = _valid1;
1867
+ ifClause1 = "then";
1868
+ } else {
1869
+ const _errs19 = errors;
1870
+ const _errs20 = errors;
1871
+ const _errs21 = errors;
1872
+ if (data && typeof data == "object" && !Array.isArray(data)) {
1873
+ if (data.state === void 0 && ("state")) {
1874
+ const err11 = {};
1875
+ if (vErrors === null) {
1876
+ vErrors = [err11];
1877
+ } else {
1878
+ vErrors.push(err11);
1879
+ }
1880
+ errors++;
1881
+ }
1882
+ }
1883
+ var valid11 = _errs21 === errors;
1884
+ if (valid11) {
1885
+ const err12 = { instancePath, schemaPath: "#/else/else/not", keyword: "not", params: {}, message: "must NOT be valid" };
1886
+ if (vErrors === null) {
1887
+ vErrors = [err12];
1888
+ } else {
1889
+ vErrors.push(err12);
1890
+ }
1891
+ errors++;
1892
+ } else {
1893
+ errors = _errs20;
1894
+ if (vErrors !== null) {
1895
+ if (_errs20) {
1896
+ vErrors.length = _errs20;
1897
+ } else {
1898
+ vErrors = null;
1899
+ }
1900
+ }
1901
+ }
1902
+ var _valid1 = _errs19 === errors;
1903
+ valid4 = _valid1;
1904
+ ifClause1 = "else";
1905
+ }
1906
+ if (!valid4) {
1907
+ const err13 = { instancePath, schemaPath: "#/else/if", keyword: "if", params: { failingKeyword: ifClause1 }, message: 'must match "' + ifClause1 + '" schema' };
1908
+ if (vErrors === null) {
1909
+ vErrors = [err13];
1910
+ } else {
1911
+ vErrors.push(err13);
1912
+ }
1913
+ errors++;
1914
+ }
1915
+ var _valid0 = _errs7 === errors;
1572
1916
  valid0 = _valid0;
1573
1917
  ifClause0 = "else";
1574
1918
  }
1575
1919
  if (!valid0) {
1576
- const err5 = { instancePath, schemaPath: "#/if", keyword: "if", params: { failingKeyword: ifClause0 }, message: 'must match "' + ifClause0 + '" schema' };
1920
+ const err14 = { instancePath, schemaPath: "#/if", keyword: "if", params: { failingKeyword: ifClause0 }, message: 'must match "' + ifClause0 + '" schema' };
1577
1921
  if (vErrors === null) {
1578
- vErrors = [err5];
1922
+ vErrors = [err14];
1579
1923
  } else {
1580
- vErrors.push(err5);
1924
+ vErrors.push(err14);
1581
1925
  }
1582
1926
  errors++;
1583
1927
  }
1584
1928
  if (data && typeof data == "object" && !Array.isArray(data)) {
1585
1929
  if (data.version === void 0) {
1586
- const err6 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "version" }, message: "must have required property 'version'" };
1930
+ const err15 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "version" }, message: "must have required property 'version'" };
1587
1931
  if (vErrors === null) {
1588
- vErrors = [err6];
1932
+ vErrors = [err15];
1589
1933
  } else {
1590
- vErrors.push(err6);
1934
+ vErrors.push(err15);
1591
1935
  }
1592
1936
  errors++;
1593
1937
  }
1594
1938
  if (data.kind === void 0) {
1595
- const err7 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "kind" }, message: "must have required property 'kind'" };
1939
+ const err16 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "kind" }, message: "must have required property 'kind'" };
1596
1940
  if (vErrors === null) {
1597
- vErrors = [err7];
1941
+ vErrors = [err16];
1598
1942
  } else {
1599
- vErrors.push(err7);
1943
+ vErrors.push(err16);
1600
1944
  }
1601
1945
  errors++;
1602
1946
  }
1603
1947
  if (data.title === void 0) {
1604
- const err8 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "title" }, message: "must have required property 'title'" };
1948
+ const err17 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "title" }, message: "must have required property 'title'" };
1605
1949
  if (vErrors === null) {
1606
- vErrors = [err8];
1950
+ vErrors = [err17];
1607
1951
  } else {
1608
- vErrors.push(err8);
1952
+ vErrors.push(err17);
1609
1953
  }
1610
1954
  errors++;
1611
1955
  }
1612
1956
  if (data.boxes === void 0) {
1613
- const err9 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "boxes" }, message: "must have required property 'boxes'" };
1957
+ const err18 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "boxes" }, message: "must have required property 'boxes'" };
1614
1958
  if (vErrors === null) {
1615
- vErrors = [err9];
1959
+ vErrors = [err18];
1616
1960
  } else {
1617
- vErrors.push(err9);
1961
+ vErrors.push(err18);
1618
1962
  }
1619
1963
  errors++;
1620
1964
  }
1621
1965
  if (data.steps === void 0) {
1622
- const err10 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "steps" }, message: "must have required property 'steps'" };
1966
+ const err19 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "steps" }, message: "must have required property 'steps'" };
1623
1967
  if (vErrors === null) {
1624
- vErrors = [err10];
1968
+ vErrors = [err19];
1625
1969
  } else {
1626
- vErrors.push(err10);
1970
+ vErrors.push(err19);
1627
1971
  }
1628
1972
  errors++;
1629
1973
  }
1630
1974
  for (const key0 in data) {
1631
1975
  if (!func2.call(schema11.properties, key0)) {
1632
- const err11 = { instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" };
1976
+ const err20 = { instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" };
1633
1977
  if (vErrors === null) {
1634
- vErrors = [err11];
1978
+ vErrors = [err20];
1635
1979
  } else {
1636
- vErrors.push(err11);
1980
+ vErrors.push(err20);
1637
1981
  }
1638
1982
  errors++;
1639
1983
  }
1640
1984
  }
1641
1985
  if (data.version !== void 0) {
1642
- let data1 = data.version;
1643
- if (!(typeof data1 == "number" && (!(data1 % 1) && !isNaN(data1)) && isFinite(data1))) {
1644
- const err12 = { instancePath: instancePath + "/version", schemaPath: "#/properties/version/type", keyword: "type", params: { type: "integer" }, message: "must be integer" };
1986
+ let data5 = data.version;
1987
+ if (!(typeof data5 == "number" && (!(data5 % 1) && !isNaN(data5)) && isFinite(data5))) {
1988
+ const err21 = { instancePath: instancePath + "/version", schemaPath: "#/properties/version/type", keyword: "type", params: { type: "integer" }, message: "must be integer" };
1645
1989
  if (vErrors === null) {
1646
- vErrors = [err12];
1990
+ vErrors = [err21];
1647
1991
  } else {
1648
- vErrors.push(err12);
1992
+ vErrors.push(err21);
1649
1993
  }
1650
1994
  errors++;
1651
1995
  }
1652
- if (typeof data1 == "number" && isFinite(data1)) {
1653
- if (data1 < 1 || isNaN(data1)) {
1654
- const err13 = { instancePath: instancePath + "/version", schemaPath: "#/properties/version/minimum", keyword: "minimum", params: { comparison: ">=", limit: 1 }, message: "must be >= 1" };
1996
+ if (typeof data5 == "number" && isFinite(data5)) {
1997
+ if (data5 < 1 || isNaN(data5)) {
1998
+ const err22 = { instancePath: instancePath + "/version", schemaPath: "#/properties/version/minimum", keyword: "minimum", params: { comparison: ">=", limit: 1 }, message: "must be >= 1" };
1655
1999
  if (vErrors === null) {
1656
- vErrors = [err13];
2000
+ vErrors = [err22];
1657
2001
  } else {
1658
- vErrors.push(err13);
2002
+ vErrors.push(err22);
1659
2003
  }
1660
2004
  errors++;
1661
2005
  }
1662
2006
  }
1663
2007
  }
1664
2008
  if (data.kind !== void 0) {
1665
- let data2 = data.kind;
1666
- if (!(data2 === "sequence" || data2 === "architecture")) {
1667
- const err14 = { instancePath: instancePath + "/kind", schemaPath: "#/properties/kind/enum", keyword: "enum", params: { allowedValues: schema11.properties.kind.enum }, message: "must be equal to one of the allowed values" };
2009
+ let data6 = data.kind;
2010
+ if (!(data6 === "sequence" || data6 === "architecture" || data6 === "state")) {
2011
+ const err23 = { instancePath: instancePath + "/kind", schemaPath: "#/properties/kind/enum", keyword: "enum", params: { allowedValues: schema11.properties.kind.enum }, message: "must be equal to one of the allowed values" };
1668
2012
  if (vErrors === null) {
1669
- vErrors = [err14];
2013
+ vErrors = [err23];
1670
2014
  } else {
1671
- vErrors.push(err14);
2015
+ vErrors.push(err23);
1672
2016
  }
1673
2017
  errors++;
1674
2018
  }
1675
2019
  }
1676
2020
  if (data.title !== void 0) {
1677
- let data3 = data.title;
1678
- if (typeof data3 === "string") {
1679
- if (func3(data3) < 1) {
1680
- const err15 = { instancePath: instancePath + "/title", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
2021
+ let data7 = data.title;
2022
+ if (typeof data7 === "string") {
2023
+ if (func3(data7) < 1) {
2024
+ const err24 = { instancePath: instancePath + "/title", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
1681
2025
  if (vErrors === null) {
1682
- vErrors = [err15];
2026
+ vErrors = [err24];
1683
2027
  } else {
1684
- vErrors.push(err15);
2028
+ vErrors.push(err24);
1685
2029
  }
1686
2030
  errors++;
1687
2031
  }
1688
2032
  } else {
1689
- const err16 = { instancePath: instancePath + "/title", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
2033
+ const err25 = { instancePath: instancePath + "/title", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
1690
2034
  if (vErrors === null) {
1691
- vErrors = [err16];
2035
+ vErrors = [err25];
1692
2036
  } else {
1693
- vErrors.push(err16);
2037
+ vErrors.push(err25);
1694
2038
  }
1695
2039
  errors++;
1696
2040
  }
1697
2041
  }
1698
2042
  if (data.view !== void 0) {
1699
- let data4 = data.view;
1700
- if (!(data4 === "fixed" || data4 === "follow")) {
1701
- const err17 = { instancePath: instancePath + "/view", schemaPath: "#/properties/view/enum", keyword: "enum", params: { allowedValues: schema11.properties.view.enum }, message: "must be equal to one of the allowed values" };
2043
+ let data8 = data.view;
2044
+ if (!(data8 === "fixed" || data8 === "follow")) {
2045
+ const err26 = { instancePath: instancePath + "/view", schemaPath: "#/properties/view/enum", keyword: "enum", params: { allowedValues: schema11.properties.view.enum }, message: "must be equal to one of the allowed values" };
1702
2046
  if (vErrors === null) {
1703
- vErrors = [err17];
2047
+ vErrors = [err26];
1704
2048
  } else {
1705
- vErrors.push(err17);
2049
+ vErrors.push(err26);
1706
2050
  }
1707
2051
  errors++;
1708
2052
  }
1709
2053
  }
1710
2054
  if (data.regions !== void 0) {
1711
- let data5 = data.regions;
1712
- if (Array.isArray(data5)) {
1713
- const len0 = data5.length;
1714
- for (let i0 = 0; i0 < len0; i0++) {
1715
- if (!validate11(data5[i0], { instancePath: instancePath + "/regions/" + i0, parentData: data5, parentDataProperty: i0, rootData })) {
2055
+ let data9 = data.regions;
2056
+ if (Array.isArray(data9)) {
2057
+ const len1 = data9.length;
2058
+ for (let i1 = 0; i1 < len1; i1++) {
2059
+ if (!validate11(data9[i1], { instancePath: instancePath + "/regions/" + i1, parentData: data9, parentDataProperty: i1, rootData })) {
1716
2060
  vErrors = vErrors === null ? validate11.errors : vErrors.concat(validate11.errors);
1717
2061
  errors = vErrors.length;
1718
2062
  }
1719
2063
  }
1720
2064
  } else {
1721
- const err18 = { instancePath: instancePath + "/regions", schemaPath: "#/properties/regions/type", keyword: "type", params: { type: "array" }, message: "must be array" };
2065
+ const err27 = { instancePath: instancePath + "/regions", schemaPath: "#/properties/regions/type", keyword: "type", params: { type: "array" }, message: "must be array" };
1722
2066
  if (vErrors === null) {
1723
- vErrors = [err18];
2067
+ vErrors = [err27];
1724
2068
  } else {
1725
- vErrors.push(err18);
2069
+ vErrors.push(err27);
1726
2070
  }
1727
2071
  errors++;
1728
2072
  }
1729
2073
  }
1730
2074
  if (data.boxes !== void 0) {
1731
- let data7 = data.boxes;
1732
- if (Array.isArray(data7)) {
1733
- if (data7.length < 1) {
1734
- const err19 = { instancePath: instancePath + "/boxes", schemaPath: "#/properties/boxes/minItems", keyword: "minItems", params: { limit: 1 }, message: "must NOT have fewer than 1 items" };
2075
+ let data11 = data.boxes;
2076
+ if (Array.isArray(data11)) {
2077
+ if (data11.length < 1) {
2078
+ const err28 = { instancePath: instancePath + "/boxes", schemaPath: "#/properties/boxes/minItems", keyword: "minItems", params: { limit: 1 }, message: "must NOT have fewer than 1 items" };
1735
2079
  if (vErrors === null) {
1736
- vErrors = [err19];
2080
+ vErrors = [err28];
1737
2081
  } else {
1738
- vErrors.push(err19);
2082
+ vErrors.push(err28);
1739
2083
  }
1740
2084
  errors++;
1741
2085
  }
1742
- const len1 = data7.length;
1743
- for (let i1 = 0; i1 < len1; i1++) {
1744
- if (!validate13(data7[i1], { instancePath: instancePath + "/boxes/" + i1, parentData: data7, parentDataProperty: i1, rootData })) {
2086
+ const len2 = data11.length;
2087
+ for (let i2 = 0; i2 < len2; i2++) {
2088
+ if (!validate13(data11[i2], { instancePath: instancePath + "/boxes/" + i2, parentData: data11, parentDataProperty: i2, rootData })) {
1745
2089
  vErrors = vErrors === null ? validate13.errors : vErrors.concat(validate13.errors);
1746
2090
  errors = vErrors.length;
1747
2091
  }
1748
2092
  }
1749
2093
  } else {
1750
- const err20 = { instancePath: instancePath + "/boxes", schemaPath: "#/properties/boxes/type", keyword: "type", params: { type: "array" }, message: "must be array" };
2094
+ const err29 = { instancePath: instancePath + "/boxes", schemaPath: "#/properties/boxes/type", keyword: "type", params: { type: "array" }, message: "must be array" };
1751
2095
  if (vErrors === null) {
1752
- vErrors = [err20];
2096
+ vErrors = [err29];
1753
2097
  } else {
1754
- vErrors.push(err20);
2098
+ vErrors.push(err29);
1755
2099
  }
1756
2100
  errors++;
1757
2101
  }
@@ -1763,30 +2107,30 @@ function validate10(data, { instancePath = "", parentData, parentDataProperty, r
1763
2107
  }
1764
2108
  }
1765
2109
  if (data.steps !== void 0) {
1766
- let data10 = data.steps;
1767
- if (Array.isArray(data10)) {
1768
- if (data10.length < 1) {
1769
- const err21 = { instancePath: instancePath + "/steps", schemaPath: "#/properties/steps/minItems", keyword: "minItems", params: { limit: 1 }, message: "must NOT have fewer than 1 items" };
2110
+ let data14 = data.steps;
2111
+ if (Array.isArray(data14)) {
2112
+ if (data14.length < 1) {
2113
+ const err30 = { instancePath: instancePath + "/steps", schemaPath: "#/properties/steps/minItems", keyword: "minItems", params: { limit: 1 }, message: "must NOT have fewer than 1 items" };
1770
2114
  if (vErrors === null) {
1771
- vErrors = [err21];
2115
+ vErrors = [err30];
1772
2116
  } else {
1773
- vErrors.push(err21);
2117
+ vErrors.push(err30);
1774
2118
  }
1775
2119
  errors++;
1776
2120
  }
1777
- const len2 = data10.length;
1778
- for (let i2 = 0; i2 < len2; i2++) {
1779
- if (!validate17(data10[i2], { instancePath: instancePath + "/steps/" + i2, parentData: data10, parentDataProperty: i2, rootData })) {
2121
+ const len3 = data14.length;
2122
+ for (let i3 = 0; i3 < len3; i3++) {
2123
+ if (!validate17(data14[i3], { instancePath: instancePath + "/steps/" + i3, parentData: data14, parentDataProperty: i3, rootData })) {
1780
2124
  vErrors = vErrors === null ? validate17.errors : vErrors.concat(validate17.errors);
1781
2125
  errors = vErrors.length;
1782
2126
  }
1783
2127
  }
1784
2128
  } else {
1785
- const err22 = { instancePath: instancePath + "/steps", schemaPath: "#/properties/steps/type", keyword: "type", params: { type: "array" }, message: "must be array" };
2129
+ const err31 = { instancePath: instancePath + "/steps", schemaPath: "#/properties/steps/type", keyword: "type", params: { type: "array" }, message: "must be array" };
1786
2130
  if (vErrors === null) {
1787
- vErrors = [err22];
2131
+ vErrors = [err31];
1788
2132
  } else {
1789
- vErrors.push(err22);
2133
+ vErrors.push(err31);
1790
2134
  }
1791
2135
  errors++;
1792
2136
  }
@@ -1797,12 +2141,18 @@ function validate10(data, { instancePath = "", parentData, parentDataProperty, r
1797
2141
  errors = vErrors.length;
1798
2142
  }
1799
2143
  }
2144
+ if (data.state !== void 0) {
2145
+ if (!validate25(data.state, { instancePath: instancePath + "/state", parentData: data, parentDataProperty: "state", rootData })) {
2146
+ vErrors = vErrors === null ? validate25.errors : vErrors.concat(validate25.errors);
2147
+ errors = vErrors.length;
2148
+ }
2149
+ }
1800
2150
  } else {
1801
- const err23 = { instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" };
2151
+ const err32 = { instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" };
1802
2152
  if (vErrors === null) {
1803
- vErrors = [err23];
2153
+ vErrors = [err32];
1804
2154
  } else {
1805
- vErrors.push(err23);
2155
+ vErrors.push(err32);
1806
2156
  }
1807
2157
  errors++;
1808
2158
  }
@@ -1810,13 +2160,43 @@ function validate10(data, { instancePath = "", parentData, parentDataProperty, r
1810
2160
  return errors === 0;
1811
2161
  }
1812
2162
 
2163
+ // src/words.ts
2164
+ var keys = (table) => Object.keys(table);
2165
+ var KINDS = keys({ sequence: true, architecture: true, state: true });
2166
+ var STATE_ENDS = ["start", "finish"];
2167
+ var HEADS = ["group", "end", "box", "strip", "step", "say", "code", "act", "note", "set"];
2168
+ var AS = "as";
2169
+ var ATTRS = {
2170
+ diagram: ["view"],
2171
+ group: ["note", "color", "icon"],
2172
+ box: ["note", "color", "icon"],
2173
+ edge: ["carry", "tag", "side"],
2174
+ set: ["tag"]
2175
+ };
2176
+ var CARRIES = keys({ coin: true, none: true });
2177
+ var VIEWS = keys({ fixed: true, follow: true });
2178
+ var SIDES = keys({ above: true, below: true, left: true, right: true });
2179
+ var OLD_HEADS = {
2180
+ \u6642\u7CFB\u5217\u56F3: "sequence",
2181
+ \u69CB\u6210\u56F3: "architecture",
2182
+ \u533A\u753B: "group",
2183
+ \u898B\u305B\u65B9: "view",
2184
+ region: "group",
2185
+ view: "view"
2186
+ };
2187
+
1813
2188
  // src/schema.ts
1814
2189
  var COLORS = ["blue", "amber", "green", "violet", "rose", "slate", "coin"];
1815
2190
  var EVENT_TYPES = ["edge", "action", "swap", "strip"];
2191
+ var ROOT_NOT_ALLOWED = {
2192
+ "#/else/not": { field: "sequence", kind: "sequence" },
2193
+ "#/then/not": { field: "state", kind: "state" },
2194
+ "#/else/else/not": { field: "state", kind: "state" }
2195
+ };
1816
2196
  var NOT_ALLOWED = {
1817
- "": { field: "sequence", kind: "sequence" },
1818
2197
  carry: { field: "text", kind: "tag" }
1819
2198
  };
2199
+ var RESERVED_ID = /\/boxes\/items\/properties\/id\/not$/u;
1820
2200
  var escape = (key2) => key2.replaceAll("~", "~0").replaceAll("/", "~1");
1821
2201
  function forbiddenOf(pattern) {
1822
2202
  const inside = /^\^\[\^(.+)\]\+\$$/u.exec(pattern)?.[1];
@@ -1840,7 +2220,8 @@ function toFieldError(error, errors, m) {
1840
2220
  return { pointer: `${at}/${escape(key2)}`, message: m.required(key2) };
1841
2221
  }
1842
2222
  case "not": {
1843
- const allowed = NOT_ALLOWED[at.slice(at.lastIndexOf("/") + 1)];
2223
+ if (RESERVED_ID.test(error.schemaPath)) return { pointer: at, message: m.reserved(STATE_ENDS) };
2224
+ const allowed = at === "" ? ROOT_NOT_ALLOWED[error.schemaPath] : NOT_ALLOWED[at.slice(at.lastIndexOf("/") + 1)];
1844
2225
  return { pointer: allowed ? `${at}/${allowed.field}` : at, message: m.not(allowed) };
1845
2226
  }
1846
2227
  case "anyOf": {
@@ -1881,30 +2262,6 @@ function validateDiagram(input, options = {}) {
1881
2262
  return { ok: false, errors };
1882
2263
  }
1883
2264
 
1884
- // src/words.ts
1885
- var keys = (table) => Object.keys(table);
1886
- var KINDS = keys({ sequence: true, architecture: true });
1887
- var HEADS = ["group", "end", "box", "strip", "step", "say", "code", "act", "note", "set"];
1888
- var AS = "as";
1889
- var ATTRS = {
1890
- diagram: ["view"],
1891
- group: ["note", "color", "icon"],
1892
- box: ["note", "color", "icon"],
1893
- edge: ["carry", "tag", "side"],
1894
- set: ["tag"]
1895
- };
1896
- var CARRIES = keys({ coin: true, none: true });
1897
- var VIEWS = keys({ fixed: true, follow: true });
1898
- var SIDES = keys({ above: true, below: true, left: true, right: true });
1899
- var OLD_HEADS = {
1900
- \u6642\u7CFB\u5217\u56F3: "sequence",
1901
- \u69CB\u6210\u56F3: "architecture",
1902
- \u533A\u753B: "group",
1903
- \u898B\u305B\u65B9: "view",
1904
- region: "group",
1905
- view: "view"
1906
- };
1907
-
1908
2265
  // src/messages.ts
1909
2266
  var list = (words) => words.join(" / ");
1910
2267
  var ja2 = () => {
@@ -1969,7 +2326,11 @@ var ja2 = () => {
1969
2326
  badView: `view \u306F ${list(VIEWS)} \u306E\u3069\u308C\u304B`,
1970
2327
  badCarry: `carry \u306F ${list(CARRIES)} \u306E\u3069\u308C\u304B\u3002\u672D\u306F tag: <\u5024> \u3067\u66F8\u304F`,
1971
2328
  badSide: `side \u306F ${list(SIDES)} \u306E\u3069\u308C\u304B`,
1972
- carryTwice: "\u904B\u3076\u7269\u306F 1 \u672C\u306E\u7DDA\u306B 1 \u3064\u307E\u3067\u3002carry \u3068 tag \u306F\u4E00\u7DD2\u306B\u66F8\u304B\u306A\u3044"
2329
+ carryTwice: "\u904B\u3076\u7269\u306F 1 \u672C\u306E\u7DDA\u306B 1 \u3064\u307E\u3067\u3002carry \u3068 tag \u306F\u4E00\u7DD2\u306B\u66F8\u304B\u306A\u3044",
2330
+ reservedId: (id) => `${id} \u306F\u72B6\u614B\u9077\u79FB\u56F3\u306E\u59CB\u307E\u308A\u3068\u7D42\u308F\u308A\u306E\u5370\u306E\u540D\u524D\u3067\u3001\u7BB1\u306E\u540D\u672D\u306B\u4F7F\u3048\u306A\u3044`,
2331
+ intoStart: "start \u3078\u5165\u308B\u7DDA\u306F\u66F8\u3051\u306A\u3044\u3002start \u306F\u59CB\u307E\u308A\u306E\u5370\u3067\u3001\u7DDA\u306F start \u304B\u3089\u51FA\u308B",
2332
+ outOfFinish: "finish \u304B\u3089\u51FA\u308B\u7DDA\u306F\u66F8\u3051\u306A\u3044\u3002finish \u306F\u7D42\u308F\u308A\u306E\u5370\u3067\u3001\u7DDA\u306F finish \u3078\u5165\u308B",
2333
+ pathNoAttrs: "\u6700\u521D\u306E step \u3088\u308A\u524D\u306E\u7DDA\u306F\u4ECA\u56DE\u306F\u901A\u3089\u306A\u3044\u9053\u306A\u306E\u3067\u3001\u5C5E\u6027 (carry \u3068 tag \u3068 side) \u3092\u66F8\u3051\u306A\u3044"
1973
2334
  };
1974
2335
  };
1975
2336
  var en2 = () => {
@@ -2034,7 +2395,11 @@ var en2 = () => {
2034
2395
  badView: `view is one of ${list(VIEWS)}`,
2035
2396
  badCarry: `carry is one of ${list(CARRIES)}. Write a tag as tag: <value>`,
2036
2397
  badSide: `side is one of ${list(SIDES)}`,
2037
- carryTwice: "A line carries one thing. Do not write carry and tag together"
2398
+ carryTwice: "A line carries one thing. Do not write carry and tag together",
2399
+ reservedId: (id) => `${id} names the start or end mark of a state diagram and cannot be a box id`,
2400
+ intoStart: "A line cannot go into start. start is the start mark, and lines leave it",
2401
+ outOfFinish: "A line cannot leave finish. finish is the end mark, and lines go into it",
2402
+ pathNoAttrs: "A line before the first step is a path not taken, so it takes no attributes (carry, tag, side)"
2038
2403
  };
2039
2404
  };
2040
2405
  var MESSAGES = { ja: ja2(), en: en2() };
@@ -2070,19 +2435,19 @@ function readDiagram(input, options = {}) {
2070
2435
  if (!checked.ok) return checked;
2071
2436
  return { ok: true, diagram: input, warnings: [] };
2072
2437
  }
2073
- async function migrateFile(path) {
2438
+ async function migrateFile(path2) {
2074
2439
  const { readFile } = await import('fs/promises');
2075
- const input = JSON.parse(await readFile(path, "utf8"));
2440
+ const input = JSON.parse(await readFile(path2, "utf8"));
2076
2441
  const read = readDiagram(input);
2077
- if (!read.ok) throw new Error(`${path} \u3092\u79FB\u305B\u306A\u3044: ${read.errors.map((error) => `${error.pointer} ${error.message}`).join(" / ")}`);
2442
+ if (!read.ok) throw new Error(`${path2} \u3092\u79FB\u305B\u306A\u3044: ${read.errors.map((error) => `${error.pointer} ${error.message}`).join(" / ")}`);
2078
2443
  return { changed: false, from: read.diagram.version, to: FORMAT_VERSION };
2079
2444
  }
2080
2445
 
2081
2446
  // src/parser.ts
2082
2447
  var NotationError = class extends Error {
2083
- constructor(line, column, message) {
2448
+ constructor(line2, column, message) {
2084
2449
  super(message);
2085
- this.line = line;
2450
+ this.line = line2;
2086
2451
  this.column = column;
2087
2452
  }
2088
2453
  line;
@@ -2238,8 +2603,10 @@ function parseLines(lines, m) {
2238
2603
  const shown2 = titled.rest < head.text.length ? readAttrs(head, titled.rest, ATTRS.diagram, m).get("view") : void 0;
2239
2604
  if (shown2 && !isOneOf(VIEWS, shown2.value)) throw fail(head, shown2.at, m.badView);
2240
2605
  const view = shown2?.value;
2606
+ const isState = kind === "state";
2241
2607
  const regions = [];
2242
2608
  const boxes = [];
2609
+ const paths = [];
2243
2610
  const ids = /* @__PURE__ */ new Set();
2244
2611
  let strip2;
2245
2612
  const steps = [];
@@ -2253,6 +2620,14 @@ function parseLines(lines, m) {
2253
2620
  if (!boxes.some((box) => box.id === id)) throw fail(source, at, m.undeclaredBox(id));
2254
2621
  return id;
2255
2622
  };
2623
+ const endAt = (source, id, at, side2) => {
2624
+ if (!isState || !isOneOf(STATE_ENDS, id)) return boxAt(source, id, at);
2625
+ if (id === "start" !== (side2 === "from")) throw fail(source, at, id === "start" ? m.intoStart : m.outOfFinish);
2626
+ return id;
2627
+ };
2628
+ const notReserved = (source, id, at) => {
2629
+ if (isState && isOneOf(STATE_ENDS, id)) throw fail(source, at, m.reservedId(id));
2630
+ };
2256
2631
  const inStep = (source) => {
2257
2632
  if (!building) throw fail(source, 0, m.stepLineBeforeStep);
2258
2633
  return building;
@@ -2277,7 +2652,8 @@ function parseLines(lines, m) {
2277
2652
  const text2 = source.text;
2278
2653
  const edge2 = EDGE.exec(text2);
2279
2654
  if (edge2) {
2280
- inStep(source).events.push(readEdge(source, edge2));
2655
+ if (isState && !building) paths.push(readPath(source, edge2));
2656
+ else inStep(source).events.push(readEdge(source, edge2));
2281
2657
  continue;
2282
2658
  }
2283
2659
  const word = text2.split(/\s/u)[0] ?? "";
@@ -2349,7 +2725,8 @@ function parseLines(lines, m) {
2349
2725
  boxes,
2350
2726
  ...strip2 ? { strip: strip2 } : {},
2351
2727
  steps,
2352
- ...kind === "sequence" ? { sequence: { lifelines: boxes.map((box) => box.id) } } : {}
2728
+ ...kind === "sequence" ? { sequence: { lifelines: boxes.map((box) => box.id) } } : {},
2729
+ ...paths.length > 0 ? { state: { paths } } : {}
2353
2730
  };
2354
2731
  function readGroup(source) {
2355
2732
  beforeSteps(source);
@@ -2358,6 +2735,7 @@ function parseLines(lines, m) {
2358
2735
  if (regions.some((region) => region.id === declared.id)) {
2359
2736
  if (declared.name !== void 0 || declared.attrs.size > 0) throw fail(source, 0, m.regionReopened(declared.id));
2360
2737
  } else {
2738
+ notReserved(source, declared.id, declared.idAt);
2361
2739
  declare(source, declared.id, declared.idAt);
2362
2740
  regions.push({ id: declared.id, name: declared.name ?? declared.id, ...lookOf(source, declared.attrs, m) });
2363
2741
  }
@@ -2366,6 +2744,7 @@ function parseLines(lines, m) {
2366
2744
  function readBox(source) {
2367
2745
  beforeSteps(source);
2368
2746
  const declared = readDeclared(source, "box", ATTRS.box, m);
2747
+ notReserved(source, declared.id, declared.idAt);
2369
2748
  declare(source, declared.id, declared.idAt);
2370
2749
  const { note, ...look } = lookOf(source, declared.attrs, m);
2371
2750
  boxes.push({
@@ -2423,26 +2802,32 @@ function parseLines(lines, m) {
2423
2802
  if (!found || idAt === void 0 || (found[2] ?? "") === "") throw fail(source, 0, shape);
2424
2803
  return { box: boxAt(source, found[1] ?? "", idAt), text: found[2] ?? "" };
2425
2804
  }
2805
+ function readLine(source, edge2) {
2806
+ const text2 = source.text;
2807
+ const from = endAt(source, edge2[1] ?? "", edge2.indices?.[1]?.[0] ?? 0, "from");
2808
+ const to = endAt(source, edge2[2] ?? "", edge2.indices?.[2]?.[0] ?? 0, "to");
2809
+ const at = skipSpaces(text2, edge2[0].length);
2810
+ if (text2[at] !== ":") return { from, to, at };
2811
+ const named = readName(source, at + 1, m);
2812
+ if (named.value === "") throw fail(source, at, m.emptyLabel);
2813
+ return { from, to, label: named.value, at: named.rest };
2814
+ }
2815
+ function readPath(source, edge2) {
2816
+ const { from, to, label: label2, at } = readLine(source, edge2);
2817
+ if (at < source.text.length) throw fail(source, at, source.text[at] === "[" ? m.pathNoAttrs : m.edgeShape);
2818
+ return { from, to, ...label2 !== void 0 ? { label: label2 } : {} };
2819
+ }
2426
2820
  function readEdge(source, edge2) {
2427
2821
  const text2 = source.text;
2428
- const from = boxAt(source, edge2[1] ?? "", edge2.indices?.[1]?.[0] ?? 0);
2429
- const to = boxAt(source, edge2[2] ?? "", edge2.indices?.[2]?.[0] ?? 0);
2430
- let at = skipSpaces(text2, edge2[0].length);
2431
- let label2;
2432
- if (text2[at] === ":") {
2433
- const named = readName(source, at + 1, m);
2434
- if (named.value === "") throw fail(source, at, m.emptyLabel);
2435
- label2 = named.value;
2436
- at = named.rest;
2437
- }
2822
+ const { from, to, label: label2, at } = readLine(source, edge2);
2438
2823
  if (at < text2.length && text2[at] !== "[") throw fail(source, at, m.edgeShape);
2439
2824
  const attrs2 = at < text2.length ? readAttrs(source, at, ATTRS.edge, m) : /* @__PURE__ */ new Map();
2440
2825
  const tag = attrs2.get("tag");
2441
2826
  const carried = attrs2.get("carry");
2442
2827
  if (tag && carried) throw fail(source, Math.max(tag.at, carried.at), m.carryTwice);
2443
2828
  if (carried && !isOneOf(CARRIES, carried.value)) throw fail(source, carried.at, m.badCarry);
2444
- const side = attrs2.get("side");
2445
- if (side && !isOneOf(SIDES, side.value)) throw fail(source, side.at, m.badSide);
2829
+ const side2 = attrs2.get("side");
2830
+ if (side2 && !isOneOf(SIDES, side2.value)) throw fail(source, side2.at, m.badSide);
2446
2831
  let carry = { kind: "envelope" };
2447
2832
  if (tag) carry = { kind: "tag", text: tag.value };
2448
2833
  else if (carried) carry = carried.value === "coin" ? { kind: "coin" } : { kind: "none" };
@@ -2452,7 +2837,7 @@ function parseLines(lines, m) {
2452
2837
  to,
2453
2838
  ...label2 !== void 0 ? { label: label2 } : {},
2454
2839
  carry,
2455
- ...side ? { labelSide: side.value } : {}
2840
+ ...side2 ? { labelSide: side2.value } : {}
2456
2841
  };
2457
2842
  }
2458
2843
  function readSet(source) {
@@ -2520,11 +2905,12 @@ var declareBox = (b) => `box ${b.id}${shown(b.id, b.name)}${attrs([
2520
2905
  ["color", b.color],
2521
2906
  ["icon", b.icon]
2522
2907
  ])}`;
2908
+ var line = (from, to, label2) => `${from} -> ${to}${label2 === void 0 ? "" : `: ${name(label2)}`}`;
2523
2909
  function event(e) {
2524
2910
  switch (e.type) {
2525
2911
  case "edge": {
2526
2912
  const carry = e.carry.kind === "tag" ? [["tag", e.carry.text]] : e.carry.kind === "envelope" ? [] : [["carry", e.carry.kind]];
2527
- return `${e.from} -> ${e.to}${e.label === void 0 ? "" : `: ${name(e.label)}`}${attrs([...carry, ["side", e.labelSide]])}`;
2913
+ return `${line(e.from, e.to, e.label)}${attrs([...carry, ["side", e.labelSide]])}`;
2528
2914
  }
2529
2915
  case "action":
2530
2916
  return `act ${e.box}: ${e.label}`;
@@ -2562,16 +2948,17 @@ end`);
2562
2948
  const region = regions.find((r) => r.id === run.region);
2563
2949
  const open = declared.has(run.region) || !region ? `group ${run.region}` : declareRegion(region);
2564
2950
  declared.add(run.region);
2565
- blocks.push([open, ...lines.map((line) => ` ${line}`), "end"].join("\n"));
2951
+ blocks.push([open, ...lines.map((line2) => ` ${line2}`), "end"].join("\n"));
2566
2952
  }
2567
2953
  return blocks;
2568
2954
  }
2569
2955
  function printNotation(diagram) {
2570
2956
  const blocks = [`${diagram.kind} ${name(diagram.title)}${attrs([["view", diagram.view]])}`, ...declarations(diagram)];
2571
2957
  if (diagram.strip) blocks.push(`strip ${key(diagram.strip.title)}: ${diagram.strip.fields.map(field).join(", ")}`);
2958
+ if (diagram.state) blocks.push(diagram.state.paths.map((p) => line(p.from, p.to, p.label)).join("\n"));
2572
2959
  for (const step of diagram.steps) {
2573
2960
  const body = step.body.split("\n");
2574
- const say = body.length === 1 ? [` say ${step.body}`] : [" say", ...body.map((line) => line === "" ? "" : ` ${line}`)];
2961
+ const say = body.length === 1 ? [` say ${step.body}`] : [" say", ...body.map((line2) => line2 === "" ? "" : ` ${line2}`)];
2575
2962
  blocks.push(
2576
2963
  [`step ${step.title}`, ...say, ...step.code === void 0 ? [] : [` code ${step.code}`], ...step.events.map((e) => ` ${event(e)}`)].join("\n")
2577
2964
  );
@@ -2850,13 +3237,46 @@ var LOOK = {
2850
3237
  region: { pad: 18, gap: 10, radius: 14, inset: 14, icon: 24, iconRadius: 7, iconScale: 0.68, nameY: 58, line: 16, minH: 108 },
2851
3238
  architecture: { columns: 4, columnGap: 56, maxColumnGap: 160, rowGap: 44, labelRoom: 16 },
2852
3239
  sequence: { columnGap: 40, labelRoom: 16, firstRow: 22, rowGap: 14, stepGap: 8, minPitch: 40, tail: 18, selfW: 34, selfH: 18 },
2853
- edge: { inset: 3, arrow: 6, arrowHalf: 3.5, parallel: 5, ghostDash: 5, flowDash: 9 },
3240
+ /**
3241
+ * 状態遷移図 (#3163)。状態は `columns` つずつ並べて次の段へ折り返し、段の間 (`rowGap`) の真ん中を、段をまたぐ線が通る。
3242
+ * `start` と `end` は始まりと終わりの印の半径と、印の中の丸の半径。`drop` は最初の状態の上端から始まりの印の中心まで、
3243
+ * `below` は状態の下端から終わりの印の中心まで、`beside` は状態の右端から右に置く終わりの印の中心まで、`text` は印の中心から字の左端まで。
3244
+ * `loop` は同じ状態へ戻る輪の幅と深さ。`side` は脇道の囲みの内側の余白、1 段目の上端との間、脇道へ入る線が横に通る所の囲みの下端からの離れ、
3245
+ * 点線の線が箱へ入る所を箱の端から離す幅。
3246
+ * `ghost` は脇道の点線の札で、絵柄を左に、名前と下の字を右に並べる (#3171)。`h` は札の高さ、`pad` は左右の余白、`gap` は絵柄と字の間、
3247
+ * `nameY` と `subY` は札の真ん中から名前と下の字の基準線まで。
3248
+ * `done` は出た状態の右上の済んだ印の半径と、箱の右上の角からの離れ。
3249
+ * `loop` の `samples` は同じ状態へ戻る弧を区切る点の数、`badgeAt` は弧の段の番号を弧の上端から深さのどこに置くかの割合。
3250
+ * `pastLabel` は段が終わった後に薄く残す線の名前の濃さ (#3171)
3251
+ */
3252
+ state: {
3253
+ columns: 4,
3254
+ columnGap: 64,
3255
+ rowGap: 108,
3256
+ labelRoom: 16,
3257
+ start: 7,
3258
+ end: { r: 9, inner: 5 },
3259
+ drop: 56,
3260
+ below: 64,
3261
+ beside: 38,
3262
+ text: 16,
3263
+ loop: { w: 24, h: 34, samples: 12, badgeAt: 0.6 },
3264
+ side: { pad: 16, gap: 76, lane: 30, entry: 28 },
3265
+ ghost: { h: 52, pad: 12, gap: 10, nameY: -2, subY: 14 },
3266
+ done: { r: 6.5, inset: 13 },
3267
+ pastLabel: 0.85
3268
+ },
3269
+ /** `bend` は線の曲がりを丸める半径 (#3171) */
3270
+ edge: { inset: 3, arrow: 6, arrowHalf: 3.5, parallel: 5, ghostDash: 5, flowDash: 9, bend: 12 },
2854
3271
  label: { h: 20, padX: 9, radius: 10, offset: 22, side: 14, search: 4, searchMax: 400, soft: 6 },
2855
3272
  action: { h: 22, padX: 10, radius: 11 },
2856
3273
  badge: { r: 9.5, ring: 9, inset: 4, along: 14, short: 44 },
2857
3274
  carrier: { envW: 24, envH: 17, coinR: 6.5, coinIn: 3.8, tagH: 18, tagPadX: 8, samples: 16 },
2858
- strip: { h: 72, line: 44, pad: 12, icon: 24, titleX: 44, fieldGap: 22, sepInset: 14, tagGap: 6, tagH: 15, tagPadX: 7, nameY: 22, valueY: 43 },
2859
- stroke: { hair: 1, edge: 1.7, edgeOn: 2.25, arrow: 1.5, flow: 1.3, halo: 7, on: 1.75, glyph: 2, lifeline: 1.2, envelope: 1.5, badgeRing: 1.5 },
3275
+ /**
3276
+ * `trail` は状態遷移図の帯の最後の、通った状態の点 (#3171)。`r` は点の半径、`step` は点の中心どうしの間、`now` は変わった値の欄の名前の横の点の半径と、名前からの離れ
3277
+ */
3278
+ strip: { h: 72, line: 44, pad: 12, icon: 24, titleX: 44, fieldGap: 22, sepInset: 14, tagGap: 6, tagH: 15, tagPadX: 7, nameY: 22, valueY: 43, trail: { r: 5.4, step: 16 }, now: { r: 3, gap: 7 } },
3279
+ stroke: { hair: 1, edge: 1.7, edgeOn: 2.25, arrow: 1.5, flow: 1.3, halo: 7, on: 1.75, glyph: 2, lifeline: 1.2, envelope: 1.5, badgeRing: 1.5, path: 1.6, end: 1.6, done: 1.2, trail: 1.2 },
2860
3280
  shadow: { near: 0.8, far: 4, nearY: 1, farY: 3 },
2861
3281
  mini: { w: 168, pad: 8, title: 14, inset: 12, radius: 10 },
2862
3282
  /**
@@ -2870,9 +3290,9 @@ var LOOK = {
2870
3290
  */
2871
3291
  follow: { aspect: 0.75, minH: 320, fitMinH: 160, ease: 0.6, narrow: 440, badgeRoom: 8, headRoom: 10, head: { pad: 8, h: 40, nameY: 17, subY: 31 } },
2872
3292
  /** 色を混ぜる割合 (%) */
2873
- mix: { icon: 14, regionIcon: 16, regionIconEdge: 34, cap: 12, capEdge: 42, badgePast: 14, badgePastEdge: 70, mini: 62, miniBand: 16, miniBandEdge: 36, view: 6 },
3293
+ mix: { icon: 14, regionIcon: 16, regionIconEdge: 34, cap: 12, capEdge: 42, badgePast: 14, badgePastEdge: 70, mini: 62, miniBand: 16, miniBandEdge: 36, view: 6, side: 4, sideEdge: 36, ghostEdge: 60, path: 55, past: 72 },
2874
3294
  /** 字の並びの基準線を、置きたい高さの真ん中からどれだけ下げるか */
2875
- baseline: { label: 3.8, badge: 3.5, carrier: 3.7, stripTitle: 4.5, tag: 3.6, action: 3.8 },
3295
+ baseline: { label: 3.8, badge: 3.5, carrier: 3.7, stripTitle: 4.5, tag: 3.6, action: 3.8, mark: 4 },
2876
3296
  /** 浮いて出る物が下から上がる長さと、弾んで出る物の始まりの大きさ */
2877
3297
  rise: 5,
2878
3298
  popFrom: 0.4,
@@ -2913,7 +3333,9 @@ var MOTION = {
2913
3333
  popFade: 0.4,
2914
3334
  untilFade: 0.2,
2915
3335
  /** 段の止め絵を撮る時刻を、段の終わりからどれだけ前にするか */
2916
- still: 0.45
3336
+ still: 0.45,
3337
+ /** 状態遷移図で、札が状態を出てから済んだ印が出るまで */
3338
+ done: 0.3
2917
3339
  };
2918
3340
  var READABLE_PX = 10.5;
2919
3341
  var EASE = {
@@ -2931,7 +3353,13 @@ var FIGURE_TEXT = {
2931
3353
  pause: "\u6B62\u3081\u308B",
2932
3354
  play: "\u52D5\u304B\u3059",
2933
3355
  next: "\u6B21\u306E\u6BB5",
2934
- steps: (title) => `${title} \u306E\u6BB5`
3356
+ steps: (title) => `${title} \u306E\u6BB5`,
3357
+ side: "\u8107\u9053",
3358
+ sideNote: "\u4ECA\u56DE\u306F\u901A\u3089\u306A\u3044",
3359
+ sideFrom: (count) => `${count} \u3064\u306E\u72B6\u614B\u304B\u3089\u5165\u308C\u308B`,
3360
+ trail: "\u901A\u3063\u305F\u72B6\u614B",
3361
+ start: "\u59CB\u307E\u308A",
3362
+ end: "\u7D42\u308F\u308A"
2935
3363
  },
2936
3364
  en: {
2937
3365
  cannotDraw: (detail) => `Cannot draw the diagram: ${detail}`,
@@ -2940,7 +3368,13 @@ var FIGURE_TEXT = {
2940
3368
  pause: "Pause",
2941
3369
  play: "Play",
2942
3370
  next: "Next step",
2943
- steps: (title) => `Steps of ${title}`
3371
+ steps: (title) => `Steps of ${title}`,
3372
+ side: "Side path",
3373
+ sideNote: "Not taken this time",
3374
+ sideFrom: (count) => `Enterable from ${count} ${count === 1 ? "state" : "states"}`,
3375
+ trail: "States passed",
3376
+ start: "Start",
3377
+ end: "End"
2944
3378
  }
2945
3379
  };
2946
3380
 
@@ -3035,12 +3469,12 @@ function placeLabel(request, obstacles) {
3035
3469
  const segment = longest(request.points);
3036
3470
  const mx = (segment.a[0] + segment.b[0]) / 2;
3037
3471
  const my = (segment.a[1] + segment.b[1]) / 2;
3038
- const side = request.side ?? (segment.vertical ? "right" : "above");
3472
+ const side2 = request.side ?? (segment.vertical ? "right" : "above");
3039
3473
  const { offset, side: sideGap } = LOOK.label;
3040
- const base = side === "above" ? { x: mx - w / 2, y: my - offset - h / 2, w, h } : side === "below" ? { x: mx - w / 2, y: my + offset - h / 2, w, h } : side === "left" ? { x: mx - sideGap - w, y: my - h / 2, w, h } : { x: mx + sideGap, y: my - h / 2, w, h };
3041
- const away = side === "above" ? [0, -1] : side === "below" ? [0, 1] : side === "left" ? [-1, 0] : [1, 0];
3474
+ const base = side2 === "above" ? { x: mx - w / 2, y: my - offset - h / 2, w, h } : side2 === "below" ? { x: mx - w / 2, y: my + offset - h / 2, w, h } : side2 === "left" ? { x: mx - sideGap - w, y: my - h / 2, w, h } : { x: mx + sideGap, y: my - h / 2, w, h };
3475
+ const away = side2 === "above" ? [0, -1] : side2 === "below" ? [0, 1] : side2 === "left" ? [-1, 0] : [1, 0];
3042
3476
  const slideAxis = [Math.abs(away[1]), Math.abs(away[0])];
3043
- const slideMax = side === "above" || side === "below" ? w : h * 4;
3477
+ const slideMax = side2 === "above" || side2 === "below" ? w : h * 4;
3044
3478
  const clear = (rect) => obstacles.hard.every((box) => gapBetween(rect, box) >= LOOK.gap) && obstacles.soft.every((other) => gapBetween(rect, other) >= LOOK.label.soft);
3045
3479
  const { search, searchMax } = LOOK.label;
3046
3480
  for (let d = 0; d <= searchMax; d += search) {
@@ -3066,29 +3500,36 @@ function fieldWidth(diagram, name2) {
3066
3500
  const both = value2 + (tag > 0 ? (value2 > 0 ? LOOK.strip.tagGap : 0) + tag : 0);
3067
3501
  return Math.max(textWidth(name2, TYPE.fieldName), both);
3068
3502
  }
3069
- function stripNeed(diagram) {
3503
+ var trailWidth = (trail) => Math.max(textWidth(trail.title, TYPE.fieldName), trail.states.length * LOOK.strip.trail.step);
3504
+ function stripNeed(diagram, trail) {
3070
3505
  if (!diagram.strip) return 0;
3071
3506
  const { titleX, fieldGap, pad: pad2 } = LOOK.strip;
3072
3507
  const start = titleX + textWidth(diagram.strip.title, TYPE.stripTitle) + fieldGap;
3073
- return start + diagram.strip.fields.reduce((sum, name2) => sum + fieldWidth(diagram, name2) + fieldGap, 0) - fieldGap + pad2;
3508
+ const widths = [...diagram.strip.fields.map((name2) => fieldWidth(diagram, name2)), ...trail ? [trailWidth(trail)] : []];
3509
+ return start + widths.reduce((sum, w) => sum + w + fieldGap, 0) - fieldGap + pad2;
3074
3510
  }
3075
- function layoutStrip(diagram, x, y, width) {
3511
+ function layoutStrip(diagram, x, y, width, trail) {
3076
3512
  if (!diagram.strip) return void 0;
3077
- const { titleX, fieldGap, pad: pad2, line, h } = LOOK.strip;
3513
+ const { titleX, fieldGap, pad: pad2, line: line2, h } = LOOK.strip;
3078
3514
  const start = titleX + textWidth(diagram.strip.title, TYPE.stripTitle) + fieldGap;
3079
3515
  const fields = [];
3080
3516
  let cx = start;
3081
3517
  let row = 0;
3082
- for (const name2 of diagram.strip.fields) {
3083
- const w = fieldWidth(diagram, name2);
3518
+ const place = (w) => {
3084
3519
  if (cx > start && cx + w > width - pad2) {
3085
3520
  cx = start;
3086
3521
  row++;
3087
3522
  }
3088
- fields.push({ name: name2, x: x + cx, y: y + row * line, w });
3523
+ const at = { x: x + cx, y: y + row * line2 };
3089
3524
  cx += w + fieldGap;
3525
+ return at;
3526
+ };
3527
+ for (const name2 of diagram.strip.fields) {
3528
+ const w = fieldWidth(diagram, name2);
3529
+ fields.push({ name: name2, ...place(w), w });
3090
3530
  }
3091
- return { x, y, w: width, h: h + row * line, title: diagram.strip.title, fields };
3531
+ const laidTrail = trail ? { ...trail, ...place(trailWidth(trail)), w: trailWidth(trail) } : void 0;
3532
+ return { x, y, w: width, h: h + row * line2, title: diagram.strip.title, fields, ...laidTrail ? { trail: laidTrail } : {} };
3092
3533
  }
3093
3534
  function shiftContent(layout, dx, dy) {
3094
3535
  const move = (rect) => {
@@ -3104,16 +3545,25 @@ function shiftContent(layout, dx, dy) {
3104
3545
  region.y += dy;
3105
3546
  move(region.header);
3106
3547
  }
3107
- for (const line of layout.lifelines) {
3108
- line.x += dx;
3109
- line.y1 += dy;
3110
- line.y2 += dy;
3548
+ for (const line2 of layout.lifelines) {
3549
+ line2.x += dx;
3550
+ line2.y1 += dy;
3551
+ line2.y2 += dy;
3111
3552
  }
3112
3553
  for (const edge2 of layout.edges) {
3113
3554
  edge2.points = edge2.points.map(([px2, py]) => [px2 + dx, py + dy]);
3114
3555
  if (edge2.settle) edge2.settle = [edge2.settle[0] + dx, edge2.settle[1] + dy];
3115
3556
  }
3116
3557
  for (const label2 of layout.labels) move(label2);
3558
+ for (const path2 of layout.paths) {
3559
+ path2.points = path2.points.map(([px2, py]) => [px2 + dx, py + dy]);
3560
+ if (path2.label) move(path2.label);
3561
+ }
3562
+ for (const end of layout.ends) {
3563
+ end.x += dx;
3564
+ end.y += dy;
3565
+ }
3566
+ if (layout.side) move(layout.side);
3117
3567
  for (const action2 of layout.actions) move(action2);
3118
3568
  for (const badge2 of layout.badges) {
3119
3569
  badge2.x += dx;
@@ -3125,6 +3575,10 @@ function shiftContent(layout, dx, dy) {
3125
3575
  field2.x += dx;
3126
3576
  field2.y += dy;
3127
3577
  }
3578
+ if (layout.strip.trail) {
3579
+ layout.strip.trail.x += dx;
3580
+ layout.strip.trail.y += dy;
3581
+ }
3128
3582
  }
3129
3583
  }
3130
3584
  function cornerBadge(events, step, layout) {
@@ -3156,7 +3610,7 @@ function groupsOf(diagram) {
3156
3610
  if (loose.length > 0) groups.push({ members: loose });
3157
3611
  return groups;
3158
3612
  }
3159
- var vertical = (side) => side === "left" || side === "right";
3613
+ var vertical = (side2) => side2 === "left" || side2 === "right";
3160
3614
  function placeBoxes(diagram, groups) {
3161
3615
  const columns = LOOK.architecture.columns;
3162
3616
  const edges = edgesOf(diagram).map((e) => e.edge);
@@ -3223,10 +3677,10 @@ function nameLines(name2) {
3223
3677
  return [name2.slice(0, at), name2.slice(at + 1)];
3224
3678
  }
3225
3679
  function headerSize(region) {
3226
- const { icon, nameY, line, inset } = LOOK.region;
3680
+ const { icon, nameY, line: line2, inset } = LOOK.region;
3227
3681
  const lines = nameLines(region.name);
3228
3682
  const w = Math.max(icon, ...lines.map((l) => textWidth(l, TYPE.regionName)), textWidth(region.note ?? "", TYPE.regionNote));
3229
- const h = nameY - inset + (lines.length - 1) * line + (region.note ? line : 0) + LOOK.gap / 2;
3683
+ const h = nameY - inset + (lines.length - 1) * line2 + (region.note ? line2 : 0) + LOOK.gap / 2;
3230
3684
  return { w, h, lines };
3231
3685
  }
3232
3686
  function arrange(diagram, groups, slots, rooms) {
@@ -3403,7 +3857,7 @@ function arrange(diagram, groups, slots, rooms) {
3403
3857
  )
3404
3858
  );
3405
3859
  }
3406
- const layout = { kind: "architecture", width: 0, height: 0, regions, boxes, lifelines: [], edges: sceneEdges, labels, actions: [], badges: [] };
3860
+ const layout = { kind: "architecture", width: 0, height: 0, regions, boxes, lifelines: [], edges: sceneEdges, labels, actions: [], badges: [], paths: [], ends: [] };
3407
3861
  const shift = labels.length > 0 ? Math.max(0, margin + LOOK.label.soft - Math.min(...labels.map((l) => l.x))) : 0;
3408
3862
  if (shift > 0) shiftContent(layout, shift, 0);
3409
3863
  const contentRight = Math.max(...boxes.map((b) => b.x + b.w + R.pad), ...labels.map((l) => l.x + l.w + LOOK.label.soft), ...sceneEdges.flatMap((e) => e.points.map((p) => p[0] + R.pad)));
@@ -3510,11 +3964,11 @@ function layoutSequence(diagram) {
3510
3964
  let above;
3511
3965
  let under;
3512
3966
  if (event2.type === "edge") {
3513
- const side = event2.labelSide ?? "above";
3967
+ const side2 = event2.labelSide ?? "above";
3514
3968
  const self = event2.from === event2.to;
3515
3969
  const named = event2.label !== void 0;
3516
- above = named && side === "above" ? L.offset + L.h / 2 : gap;
3517
- under = self ? Q.selfH + gap : named && side === "below" ? L.offset + L.h / 2 : gap;
3970
+ above = named && side2 === "above" ? L.offset + L.h / 2 : gap;
3971
+ under = self ? Q.selfH + gap : named && side2 === "below" ? L.offset + L.h / 2 : gap;
3518
3972
  } else {
3519
3973
  above = LOOK.action.h / 2;
3520
3974
  under = LOOK.action.h / 2;
@@ -3561,7 +4015,7 @@ function layoutSequence(diagram) {
3561
4015
  const soft = [...labels.filter((l) => l.step === request.step), ...actions];
3562
4016
  labels.push(placeLabel(request, { hard: boxes, soft }));
3563
4017
  }
3564
- const layout = { kind: "sequence", width: 0, height: 0, regions: [], boxes, lifelines, edges, labels, actions, badges: [] };
4018
+ const layout = { kind: "sequence", width: 0, height: 0, regions: [], boxes, lifelines, edges, labels, actions, badges: [], paths: [], ends: [] };
3565
4019
  const lefts = [...boxes.map((b) => b.x), ...labels.map((l) => l.x), ...actions.map((a) => a.x)];
3566
4020
  const shift = Math.max(0, margin - Math.min(...lefts));
3567
4021
  if (shift > 0) shiftContent(layout, shift, 0);
@@ -3588,6 +4042,301 @@ function badges(diagram, layout) {
3588
4042
  });
3589
4043
  }
3590
4044
 
4045
+ // src/layout/state.ts
4046
+ var isEnd = (id) => STATE_ENDS.includes(id);
4047
+ function visitOrder(diagram) {
4048
+ const order = [];
4049
+ const add = (id) => {
4050
+ if (!isEnd(id) && !order.includes(id)) order.push(id);
4051
+ };
4052
+ for (const { edge: edge2 } of edgesOf(diagram)) {
4053
+ add(edge2.from);
4054
+ add(edge2.to);
4055
+ }
4056
+ return order;
4057
+ }
4058
+ function carrierHalf(carry) {
4059
+ const C = LOOK.carrier;
4060
+ if (carry.kind === "tag") return (textWidth(carry.text, hasWide(carry.text) ? TYPE.carrierJa : TYPE.carrier) + C.tagPadX * 2) / 2;
4061
+ if (carry.kind === "coin") return C.coinR;
4062
+ return C.envW / 2;
4063
+ }
4064
+ var same = (a, b) => a.from === b.from && a.to === b.to;
4065
+ function layoutState(diagram, lang) {
4066
+ const { box: B, state: T, margin, gap } = LOOK;
4067
+ const inset = LOOK.edge.inset;
4068
+ const words = FIGURE_TEXT[lang];
4069
+ const colors = boxColors(diagram);
4070
+ const steps = edgesOf(diagram);
4071
+ const walked = visitOrder(diagram);
4072
+ const ghosts = diagram.boxes.map((b) => b.id).filter((id) => !walked.includes(id));
4073
+ const notTaken = (diagram.state?.paths ?? []).filter((p) => !steps.some(({ edge: edge2 }) => same(edge2, p)));
4074
+ const lines = [...steps.map(({ edge: edge2 }) => edge2), ...notTaken];
4075
+ const G = T.ghost;
4076
+ const ghostWidth = (id) => {
4077
+ const source = diagram.boxes.find((b) => b.id === id);
4078
+ return G.pad * 2 + B.icon + G.gap + Math.max(textWidth(source?.name ?? id, TYPE.boxName), textWidth(source?.sub ?? "", TYPE.boxSub));
4079
+ };
4080
+ const widths = new Map(diagram.boxes.map((b) => [b.id, ghosts.includes(b.id) ? ghostWidth(b.id) : boxWidth(diagram, b.id, true)]));
4081
+ const columnCount = Math.max(1, Math.min(T.columns, walked.length));
4082
+ const rowCount = Math.max(1, Math.ceil(walked.length / T.columns));
4083
+ const slot = new Map(
4084
+ walked.map((id, k) => {
4085
+ const row = Math.floor(k / T.columns);
4086
+ const at = k % T.columns;
4087
+ return [id, { row, col: row % 2 === 0 ? at : columnCount - 1 - at }];
4088
+ })
4089
+ );
4090
+ const colW = Array.from({ length: columnCount }, (_, c) => Math.max(B.minW, ...walked.filter((id) => slot.get(id)?.col === c).map((id) => widths.get(id) ?? B.minW)));
4091
+ const between = Array.from({ length: Math.max(0, columnCount - 1) }, () => T.columnGap);
4092
+ for (const line2 of lines) {
4093
+ const a = slot.get(line2.from);
4094
+ const b = slot.get(line2.to);
4095
+ if (!a || !b || line2.label === void 0 || a.row !== b.row || Math.abs(a.col - b.col) !== 1) continue;
4096
+ const i = Math.min(a.col, b.col);
4097
+ between[i] = Math.max(between[i] ?? 0, textWidth(line2.label, labelStyle(line2.label)) + LOOK.label.padX * 2 + T.labelRoom * 2);
4098
+ }
4099
+ const colLeft = [];
4100
+ for (let c = 0; c < columnCount; c++) colLeft.push(c === 0 ? margin : colLeft[c - 1] + colW[c - 1] + between[c - 1]);
4101
+ const center = (c) => colLeft[c] + colW[c] / 2;
4102
+ const isGhost = (id) => ghosts.includes(id);
4103
+ const enteringFrom = new Set(notTaken.filter((p) => isGhost(p.to) && !isGhost(p.from) && !isEnd(p.from)).map((p) => p.from));
4104
+ const notes = [words.sideNote, ...enteringFrom.size > 0 ? [words.sideFrom(enteringFrom.size)] : []];
4105
+ const titleW = Math.max(textWidth(words.side, TYPE.regionName), ...notes.map((note) => textWidth(note, TYPE.regionNote)));
4106
+ const sideH = T.side.pad * 2 + Math.max(G.h, TYPE.regionName.size + LOOK.region.line * notes.length + T.side.pad / 4);
4107
+ const starts = lines.some((line2) => line2.from === "start");
4108
+ const top0 = margin + (ghosts.length > 0 ? sideH + T.side.gap : starts ? T.start + T.drop : 0);
4109
+ const rowY = (row) => top0 + row * (B.h + T.rowGap);
4110
+ const boxOf = (id, cx, y, ghost) => {
4111
+ const source = diagram.boxes.find((b) => b.id === id);
4112
+ const w = widths.get(id) ?? B.minW;
4113
+ const h = ghost ? G.h : B.h;
4114
+ return {
4115
+ id,
4116
+ name: source?.name ?? id,
4117
+ ...source?.sub !== void 0 ? { sub: source.sub } : {},
4118
+ ...source?.icon !== void 0 ? { icon: source.icon } : {},
4119
+ color: colors.get(id) ?? "slate",
4120
+ x: cx - w / 2,
4121
+ y,
4122
+ w,
4123
+ h,
4124
+ cx,
4125
+ cy: y + h / 2,
4126
+ ...ghost ? { ghost: true } : {}
4127
+ };
4128
+ };
4129
+ const boxes = walked.map((id) => {
4130
+ const s = slot.get(id);
4131
+ return boxOf(id, center(s.col), rowY(s.row), false);
4132
+ });
4133
+ const byId = new Map(boxes.map((b) => [b.id, b]));
4134
+ const below = (box) => boxes.some((other) => other !== box && Math.abs(other.cx - box.cx) < 0.5 && other.y > box.y);
4135
+ const ends = [];
4136
+ const first = boxes[0];
4137
+ const contentRight = Math.max(...boxes.map((b) => b.x + b.w));
4138
+ let side2;
4139
+ const lane = margin + sideH + T.side.lane;
4140
+ if (ghosts.length > 0) {
4141
+ const sourcesOf = (id) => notTaken.filter((p) => p.to === id).flatMap((p) => byId.get(p.from) ?? []);
4142
+ const all = ghosts.flatMap(sourcesOf);
4143
+ const x = Math.max(margin, Math.min(...all.length > 0 ? all.map((b) => b.x) : [margin + T.side.pad]) - T.side.pad);
4144
+ let cursor = x + T.side.pad + titleW + gap * 2;
4145
+ const wanted = ghosts.map((id) => {
4146
+ const from = sourcesOf(id);
4147
+ return { id, cx: from.length > 0 ? from.reduce((sum, b) => sum + b.cx, 0) / from.length : cursor };
4148
+ });
4149
+ wanted.sort((a, b) => a.cx - b.cx);
4150
+ let right = x;
4151
+ for (const { id, cx } of wanted) {
4152
+ const w = widths.get(id) ?? B.minW;
4153
+ const left = Math.max(cx - w / 2, cursor);
4154
+ const ghost = boxOf(id, left + w / 2, margin + (sideH - G.h) / 2, true);
4155
+ boxes.push(ghost);
4156
+ byId.set(id, ghost);
4157
+ const finishes = notTaken.some((p) => p.from === id && p.to === "finish");
4158
+ if (finishes) ends.push({ kind: "finish", x: ghost.x + ghost.w + T.beside, y: ghost.cy, r: T.end.r, ghost: true, text: "", box: id });
4159
+ right = finishes ? ghost.x + ghost.w + T.beside + T.end.r : ghost.x + ghost.w;
4160
+ cursor = right + gap * 2;
4161
+ }
4162
+ const rightmost = Math.max(right + T.side.pad, contentRight);
4163
+ side2 = { x, y: margin, w: rightmost - x, h: sideH, title: words.side, notes };
4164
+ }
4165
+ if (first && starts) {
4166
+ const reach = first.cx + T.start + T.text + textWidth(words.start, TYPE.regionNote) + gap;
4167
+ const y = side2 && reach < side2.x ? side2.y + T.side.pad + T.start : first.y - T.drop;
4168
+ ends.unshift({ kind: "start", x: first.cx, y, r: T.start, ghost: false, text: words.start });
4169
+ }
4170
+ for (const box of boxes.filter((b) => !b.ghost && lines.some((line2) => line2.from === b.id && line2.to === "finish"))) {
4171
+ ends.push(
4172
+ below(box) ? { kind: "finish", x: box.x + box.w + T.beside, y: box.cy, r: T.end.r, ghost: false, text: words.end, box: box.id } : { kind: "finish", x: box.cx, y: box.y + box.h + T.below, r: T.end.r, ghost: false, text: words.end, box: box.id }
4173
+ );
4174
+ }
4175
+ const between2 = (a, b) => {
4176
+ const sa = slot.get(a.id);
4177
+ const sb = slot.get(b.id);
4178
+ if (!sa || !sb) return [[a.cx, a.y + a.h], [b.cx, b.y - inset]];
4179
+ if (sa.row === sb.row && Math.abs(sa.col - sb.col) === 1) {
4180
+ return b.cx > a.cx ? [[a.x + a.w, a.cy], [b.x - inset, b.cy]] : [[a.x, a.cy], [b.x + b.w + inset, b.cy]];
4181
+ }
4182
+ if (sa.row === sb.row) {
4183
+ const y2 = a.y + a.h + T.rowGap / 4;
4184
+ return [[a.cx, a.y + a.h], [a.cx, y2], [b.cx, y2], [b.cx, b.y + b.h + inset]];
4185
+ }
4186
+ if (sb.row > sa.row) {
4187
+ if (Math.abs(a.cx - b.cx) < 0.5) return [[a.cx, a.y + a.h], [b.cx, b.y - inset]];
4188
+ const y2 = a.y + a.h + T.rowGap / 2;
4189
+ return [[a.cx, a.y + a.h], [a.cx, y2], [b.cx, y2], [b.cx, b.y - inset]];
4190
+ }
4191
+ if (Math.abs(a.cx - b.cx) < 0.5) return [[a.cx, a.y], [b.cx, b.y + b.h + inset]];
4192
+ const y = b.y + b.h + T.rowGap / 2;
4193
+ return [[a.cx, a.y], [a.cx, y], [b.cx, y], [b.cx, b.y + b.h + inset]];
4194
+ };
4195
+ const entryOf = (from, to) => {
4196
+ const sources = notTaken.filter((p) => p.to === to.id).flatMap((p) => byId.get(p.from) ?? []).sort((a, b) => a.cx - b.cx);
4197
+ const k = sources.findIndex((b) => b.id === from);
4198
+ if (sources.length <= 1) return Math.min(Math.max(sources[0]?.cx ?? to.cx, to.x + T.side.entry), to.x + to.w - T.side.entry);
4199
+ return to.x + T.side.entry + (to.w - T.side.entry * 2) * Math.max(0, k) / (sources.length - 1);
4200
+ };
4201
+ const exitX = (box) => starts && box === first ? box.cx + T.side.entry : box.cx;
4202
+ const finishOf = (id) => ends.find((e) => e.kind === "finish" && e.box === id);
4203
+ const loopOf = (box) => {
4204
+ const { w, h, samples } = T.loop;
4205
+ const bottom2 = box.y + box.h;
4206
+ const p0 = [box.cx + w / 2, bottom2];
4207
+ const c1 = [box.cx + w * 3 / 4, bottom2 + h * 4 / 3];
4208
+ const c2 = [box.cx - w * 3 / 4, bottom2 + h * 4 / 3];
4209
+ const p3 = [box.cx - w / 2, bottom2 + inset];
4210
+ return Array.from({ length: samples + 1 }, (_, k) => {
4211
+ const t = k / samples;
4212
+ const u = 1 - t;
4213
+ const at = (i) => u * u * u * p0[i] + 3 * u * u * t * c1[i] + 3 * u * t * t * c2[i] + t * t * t * p3[i];
4214
+ return [at(0), at(1)];
4215
+ });
4216
+ };
4217
+ const route = (from, to) => {
4218
+ if (from === "start") {
4219
+ const start = ends.find((e) => e.kind === "start");
4220
+ const target = byId.get(to);
4221
+ if (!start || !target) return [];
4222
+ return [[start.x, start.y + start.r], [target.cx, target.y - inset]];
4223
+ }
4224
+ const a = byId.get(from);
4225
+ if (!a) return [];
4226
+ if (to === "finish") {
4227
+ const end = finishOf(from);
4228
+ if (!end) return [];
4229
+ return Math.abs(end.x - a.cx) < 0.5 ? [[a.cx, a.y + a.h], [a.cx, end.y - end.r - inset]] : [[a.x + a.w, a.cy], [end.x - end.r - inset, a.cy]];
4230
+ }
4231
+ const b = byId.get(to);
4232
+ if (!b) return [];
4233
+ if (from === to) return loopOf(a);
4234
+ if (b.ghost && !a.ghost) {
4235
+ const sx = exitX(a);
4236
+ const ex = entryOf(from, b);
4237
+ return Math.abs(sx - ex) < 0.5 ? [[sx, a.y], [ex, b.y + b.h + inset]] : [[sx, a.y], [sx, lane], [ex, lane], [ex, b.y + b.h + inset]];
4238
+ }
4239
+ if (a.ghost && b.ghost) return [[a.x + a.w, a.cy], [b.x - inset, b.cy]];
4240
+ if (a.ghost) return [[a.cx, a.y + a.h], [a.cx, lane], [b.cx, lane], [b.cx, b.y - inset]];
4241
+ return between2(a, b);
4242
+ };
4243
+ const settleOf = (edge2) => {
4244
+ const target = byId.get(edge2.to);
4245
+ if (target) return [target.cx, target.cy + B.iconY];
4246
+ const end = edge2.to === "finish" ? finishOf(edge2.from) : void 0;
4247
+ if (!end) return void 0;
4248
+ const from = byId.get(edge2.from);
4249
+ return from && Math.abs(end.x - from.cx) < 0.5 ? [end.x - end.r - gap - carrierHalf(edge2.carry), end.y] : [end.x, end.y + end.r + gap + LOOK.carrier.tagH / 2];
4250
+ };
4251
+ const sceneEdges = steps.map(({ step, event: event2, edge: edge2 }) => {
4252
+ const settle = settleOf(edge2);
4253
+ return {
4254
+ step,
4255
+ event: event2,
4256
+ from: edge2.from,
4257
+ to: edge2.to,
4258
+ points: route(edge2.from, edge2.to),
4259
+ color: colorOf(edge2, colors),
4260
+ carry: edge2.carry,
4261
+ ...settle ? { settle } : {}
4262
+ };
4263
+ });
4264
+ for (const e of sceneEdges) {
4265
+ if (e.points.length !== 2 || !sceneEdges.some((o) => o.from === e.to && o.to === e.from && o.points.length === 2)) continue;
4266
+ const [p, q] = e.points;
4267
+ const flat = Math.abs(q[1] - p[1]) < Math.abs(q[0] - p[0]);
4268
+ const d = (e.from < e.to ? 1 : -1) * LOOK.edge.parallel;
4269
+ e.points = e.points.map(([x, y]) => flat ? [x, y + d] : [x + d, y]);
4270
+ }
4271
+ const paths = notTaken.map((p) => ({ from: p.from, to: p.to, points: route(p.from, p.to) }));
4272
+ const labels = [];
4273
+ const soft = side2 ? [{ x: side2.x, y: side2.y, w: T.side.pad + titleW, h: side2.h }] : [];
4274
+ for (const e of sceneEdges) {
4275
+ const source = diagram.steps[e.step]?.events[e.event];
4276
+ if (source?.type !== "edge" || source.label === void 0) continue;
4277
+ const style = labelStyle(source.label);
4278
+ if (e.from === e.to) {
4279
+ const w = textWidth(source.label, style) + LOOK.label.padX * 2;
4280
+ const bottom2 = Math.max(...e.points.map(([, y]) => y));
4281
+ labels.push({ step: e.step, event: e.event, text: source.label, family: style.family, color: e.color, x: (e.points[0]?.[0] ?? 0) - T.loop.w / 2 - w / 2, y: bottom2 + LOOK.label.soft, w, h: LOOK.label.h });
4282
+ continue;
4283
+ }
4284
+ const side22 = source.labelSide ?? (e.to === "finish" ? "left" : void 0);
4285
+ labels.push(
4286
+ placeLabel(
4287
+ { step: e.step, event: e.event, text: source.label, points: e.points, color: e.color, ...side22 ? { side: side22 } : {} },
4288
+ { hard: boxes, soft: [...soft, ...labels.filter((l) => l.step === e.step)] }
4289
+ )
4290
+ );
4291
+ }
4292
+ notTaken.forEach((p, i) => {
4293
+ const path2 = paths[i];
4294
+ if (p.label === void 0 || path2.points.length === 0) return;
4295
+ const style = labelStyle(p.label);
4296
+ const into = byId.get(p.to)?.ghost === true && byId.get(p.from)?.ghost !== true;
4297
+ const rect = into ? { x: path2.points[0][0] + LOOK.label.soft, y: lane + LOOK.label.soft, w: textWidth(p.label, style) + LOOK.label.padX * 2, h: LOOK.label.h } : placeLabel({ step: -1, event: i, text: p.label, points: path2.points, color: "slate" }, { hard: boxes, soft });
4298
+ path2.label = { x: rect.x, y: rect.y, w: rect.w, h: rect.h, text: p.label, family: style.family };
4299
+ });
4300
+ const layout = { kind: "state", width: 0, height: 0, regions: [], boxes, lifelines: [], edges: sceneEdges, labels, actions: [], badges: [], paths, ends, ...side2 ? { side: side2 } : {} };
4301
+ const lefts = [...boxes.map((b) => b.x), ...labels.map((l) => l.x), ...paths.flatMap((p) => p.label ? [p.label.x] : [])];
4302
+ const shift = Math.max(0, margin - Math.min(...lefts));
4303
+ if (shift > 0) shiftContent(layout, shift, 0);
4304
+ const endRight = (e) => e.x + (e.text === "" ? e.r : T.text + textWidth(e.text, TYPE.regionNote));
4305
+ const rights = [
4306
+ ...boxes.map((b) => b.x + b.w),
4307
+ ...labels.map((l) => l.x + l.w),
4308
+ ...ends.map(endRight),
4309
+ ...sceneEdges.flatMap((e) => e.points.map((p) => p[0])),
4310
+ ...paths.flatMap((p) => [...p.points.map((q) => q[0]), ...p.label ? [p.label.x + p.label.w] : []]),
4311
+ ...side2 ? [side2.x + side2.w] : []
4312
+ ];
4313
+ const bottoms = [...boxes.map((b) => b.y + b.h), ...labels.map((l) => l.y + l.h), ...ends.map((e) => e.y + e.r), ...sceneEdges.flatMap((e) => e.points.map((p) => p[1]))];
4314
+ const trail = { title: words.trail, states: walked.map((id) => ({ box: id, color: colors.get(id) ?? "slate" })) };
4315
+ const width = Math.max(Math.max(...rights) + margin, stripNeed(diagram, trail) + margin * 2);
4316
+ const bottom = Math.max(...bottoms, rowY(rowCount - 1) + B.h);
4317
+ const strip2 = layoutStrip(diagram, margin, bottom + gap, width - margin * 2, trail);
4318
+ layout.width = width;
4319
+ layout.height = (strip2 ? strip2.y + strip2.h : bottom) + margin;
4320
+ if (strip2) layout.strip = strip2;
4321
+ layout.badges = diagram.steps.map((step, s) => {
4322
+ const edge2 = sceneEdges.find((e) => e.step === s && e.points.length > 0);
4323
+ if (!edge2) return cornerBadge(step.events, s, layout);
4324
+ if (edge2.from === edge2.to) {
4325
+ const right = Math.max(...edge2.points.map(([px2]) => px2));
4326
+ const top = edge2.points[0][1];
4327
+ const deep = Math.max(...edge2.points.map(([, py]) => py));
4328
+ return { step: s, x: right + LOOK.badge.r + LOOK.badge.inset, y: top + (deep - top) * T.loop.badgeAt, color: edge2.color };
4329
+ }
4330
+ const [x, y] = badgeOnPath(edge2.points);
4331
+ return { step: s, x, y, color: edge2.color };
4332
+ });
4333
+ return layout;
4334
+ }
4335
+ function colorOf(edge2, colors) {
4336
+ if (edge2.carry.kind === "coin") return edgeColor(edge2, colors);
4337
+ return colors.get(edge2.to === "finish" ? edge2.from : edge2.to) ?? "slate";
4338
+ }
4339
+
3591
4340
  // src/timeline.ts
3592
4341
  function plan(step) {
3593
4342
  const out = { edges: [], events: [], busy: 0 };
@@ -3647,6 +4396,7 @@ function buildTimeline(diagram) {
3647
4396
  const later = named[k + 2];
3648
4397
  if (later) label2.end = Math.min(label2.end, later.start);
3649
4398
  });
4399
+ if (diagram.kind === "state") for (const label2 of named) label2.after = { start: label2.end, end: last };
3650
4400
  labels.push(...named);
3651
4401
  for (const event2 of p.events) events.push({ step: s, event: event2.event, at: span.start + event2.at });
3652
4402
  });
@@ -3670,6 +4420,7 @@ function buildTimeline(diagram) {
3670
4420
  });
3671
4421
  }
3672
4422
  carriers.sort((x, y) => x.depart - y.depart);
4423
+ const states = diagram.kind === "state" ? stateTimes(diagram, edges, last) : void 0;
3673
4424
  return {
3674
4425
  total,
3675
4426
  last,
@@ -3679,9 +4430,33 @@ function buildTimeline(diagram) {
3679
4430
  labels,
3680
4431
  badges: steps.map((span, s) => ({ step: s, appears: span.start })),
3681
4432
  events,
3682
- stills: steps.map((span) => span.end - MOTION.still)
4433
+ stills: steps.map((span) => span.end - MOTION.still),
4434
+ ...states ? { states } : {}
3683
4435
  };
3684
4436
  }
4437
+ var isEnd2 = (id) => STATE_ENDS.includes(id);
4438
+ function stateTimes(diagram, edges, last) {
4439
+ const times = /* @__PURE__ */ new Map();
4440
+ const of = (box) => {
4441
+ const found = times.get(box) ?? { box, lit: [] };
4442
+ times.set(box, found);
4443
+ return found;
4444
+ };
4445
+ let on;
4446
+ for (const edge2 of edges) {
4447
+ const event2 = diagram.steps[edge2.step]?.events[edge2.event];
4448
+ if (event2?.type !== "edge" || event2.from === event2.to) continue;
4449
+ if (on) {
4450
+ const left = of(on.box);
4451
+ left.lit.push({ start: on.since, end: edge2.start });
4452
+ if (on.box === event2.from && left.done === void 0) left.done = edge2.start + MOTION.done;
4453
+ on = void 0;
4454
+ }
4455
+ if (!isEnd2(event2.to)) on = { box: event2.to, since: edge2.drawn };
4456
+ }
4457
+ if (on) of(on.box).lit.push({ start: on.since, end: last });
4458
+ return [...times.values()];
4459
+ }
3685
4460
 
3686
4461
  // src/render/icons.ts
3687
4462
  var ICONS = {
@@ -3715,6 +4490,8 @@ var ICONS = {
3715
4490
  branch: "M -4 -4.5 v9 M 5 0.5 c0 4 -9 3 -9 6.5 M -6.2 -7 a2.2 2.2 0 1 0 4.4 0 a2.2 2.2 0 1 0 -4.4 0 M -6.2 7 a2.2 2.2 0 1 0 4.4 0 a2.2 2.2 0 1 0 -4.4 0 M 2.8 -2 a2.2 2.2 0 1 0 4.4 0 a2.2 2.2 0 1 0 -4.4 0",
3716
4491
  cloud: "M -7 6 h13 a4.5 4.5 0 0 0 0.5 -9 a6 6 0 0 0 -11.5 -1 a4.5 4.5 0 0 0 -2 10 z",
3717
4492
  refresh: "M 7 -3 a7.5 7.5 0 1 0 0.5 5 M 7.5 -8 v5 h-5",
4493
+ undo: "M -7 -2 h10 a5 5 0 0 1 0 10 h-6 M -3 -6 l-4 4 l4 4",
4494
+ yen: "M -6 -8 l6 7 l6 -7 M 0 -1 v9 M -5 1.5 h10 M -5 5 h10",
3718
4495
  layers: "M 0 -8 l9 4.5 l-9 4.5 l-9 -4.5 z M -9 2.5 l9 4.5 l9 -4.5",
3719
4496
  code: "M -4 -6 l-5 6 l5 6 M 4 -6 l5 6 l-5 6",
3720
4497
  paint: "M -8 8 c 0 -3 2 -5 4.5 -5 l 9 -9 l 3.5 3.5 l -9 9 c 0 2.5 -2 4.5 -5 4.5 z",
@@ -3729,7 +4506,30 @@ function glyph(name2, x, y, scale, cls = "dg-gl") {
3729
4506
  const d = name2 === void 0 ? void 0 : ICONS[name2];
3730
4507
  return d ? `<path class="${cls}" transform="translate(${r1(x)} ${r1(y)}) scale(${scale})" d="${d}"/>` : "";
3731
4508
  }
3732
- var pathOf = (points) => points.map(([x, y], i) => `${i === 0 ? "M" : "L"} ${r1(x)} ${r1(y)}`).join(" ");
4509
+ function iconSvg(name2) {
4510
+ if (!Object.hasOwn(ICONS, name2)) return void 0;
4511
+ const width = LOOK.stroke.glyph * LOOK.box.iconScale;
4512
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="-12 -12 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="${width}" stroke-linecap="round" stroke-linejoin="round"><path d="${ICONS[name2]}"/></svg>`;
4513
+ }
4514
+ function pathOf(points) {
4515
+ const pts = points.filter((p, i) => i === 0 || p[0] !== points[i - 1][0] || p[1] !== points[i - 1][1]);
4516
+ const [x0, y0] = pts[0];
4517
+ let d = `M ${r1(x0)} ${r1(y0)}`;
4518
+ for (let i = 1; i < pts.length - 1; i++) {
4519
+ const [ax, ay] = pts[i - 1];
4520
+ const [bx, by] = pts[i];
4521
+ const [cx, cy] = pts[i + 1];
4522
+ const l1 = Math.hypot(bx - ax, by - ay);
4523
+ const l2 = Math.hypot(cx - bx, cy - by);
4524
+ const a = Math.min(LOOK.edge.bend, l1 / 2, l2 / 2);
4525
+ d += ` L ${r1(bx - (bx - ax) / l1 * a)} ${r1(by - (by - ay) / l1 * a)} Q ${r1(bx)} ${r1(by)} ${r1(bx + (cx - bx) / l2 * a)} ${r1(by + (cy - by) / l2 * a)}`;
4526
+ }
4527
+ if (pts.length > 1) {
4528
+ const [lx, ly] = pts[pts.length - 1];
4529
+ d += ` L ${r1(lx)} ${r1(ly)}`;
4530
+ }
4531
+ return d;
4532
+ }
3733
4533
  function arrowHead(points) {
3734
4534
  const [ex, ey] = points[points.length - 1];
3735
4535
  const [px2, py] = points[points.length - 2];
@@ -3756,10 +4556,10 @@ function activeKf(ctx, on) {
3756
4556
  return rangeKf(ctx.m, ranges);
3757
4557
  }
3758
4558
  function band(region) {
3759
- const { radius, icon, iconRadius, iconScale, nameY, line } = LOOK.region;
4559
+ const { radius, icon, iconRadius, iconScale, nameY, line: line2 } = LOOK.region;
3760
4560
  const { x, y } = region.header;
3761
- const lines = region.lines.map((t, k) => `<text class="dg-bz" x="${r1(x)}" y="${r1(region.y + nameY + k * line)}">${esc(t)}</text>`).join("");
3762
- const note = region.note ? `<text class="dg-bx" x="${r1(x)}" y="${r1(region.y + nameY + region.lines.length * line + 1)}">${esc(region.note)}</text>` : "";
4561
+ const lines = region.lines.map((t, k) => `<text class="dg-bz" x="${r1(x)}" y="${r1(region.y + nameY + k * line2)}">${esc(t)}</text>`).join("");
4562
+ const note = region.note ? `<text class="dg-bx" x="${r1(x)}" y="${r1(region.y + nameY + region.lines.length * line2 + 1)}">${esc(region.note)}</text>` : "";
3763
4563
  const mark = region.icon && ICONS[region.icon] ? `<rect class="dg-bi" x="${r1(x)}" y="${r1(y)}" width="${icon}" height="${icon}" rx="${iconRadius}"/>${glyph(region.icon, x + icon / 2, y + icon / 2, iconScale)}` : "";
3764
4564
  return `<g style="${cs(region.color)}"><rect class="dg-band" x="${r1(region.x + 0.5)}" y="${r1(region.y + 0.5)}" width="${r1(region.w - 1)}" height="${r1(region.h - 1)}" rx="${radius}"/>${mark}${lines}${note}</g>`;
3765
4565
  }
@@ -3776,10 +4576,10 @@ function cardFrame(box, ctx, act, y, h) {
3776
4576
  const rect = (cls, extra = "") => `<rect class="${cls}" x="${r1(box.x)}" y="${r1(y)}" width="${r1(box.w)}" height="${h}" rx="${LOOK.box.radius}"${extra}/>`;
3777
4577
  return `${act ? `<g class="dg-a" style="${act}">${rect("dg-halo")}</g>` : ""}${rect("dg-st", ` ${ctx.sh}`)}${act ? `<g class="dg-a" style="${act}">${rect("dg-on")}</g>` : ""}`;
3778
4578
  }
3779
- function card(box, ctx, on, changes) {
4579
+ function card(box, ctx, on, changes, lit) {
3780
4580
  const { icon, iconRadius, iconScale, iconY, nameY, subY } = LOOK.box;
3781
4581
  const subs = subLines(box, ctx.m, changes, box.cy + subY);
3782
- const act = on.length > 0 ? activeKf(ctx, on) : void 0;
4582
+ const act = lit ? lit.length > 0 ? rangeKf(ctx.m, lit.map((s) => [s.start, s.end])) : void 0 : on.length > 0 ? activeKf(ctx, on) : void 0;
3783
4583
  const mark = box.icon && ICONS[box.icon] ? `<rect class="dg-ic" x="${r1(box.cx - icon / 2)}" y="${r1(box.cy + iconY - icon / 2)}" width="${icon}" height="${icon}" rx="${iconRadius}"/>${glyph(box.icon, box.cx, box.cy + iconY, iconScale)}` : "";
3784
4584
  return `<g style="${cs(box.color)}">${cardFrame(box, ctx, act, box.y, box.h)}${mark}<text class="dg-sn" x="${r1(box.cx)}" y="${r1(box.cy + nameY)}" text-anchor="middle">${esc(box.name)}</text>${subs}</g>`;
3785
4585
  }
@@ -3789,15 +4589,54 @@ function headCard(box, ctx, on, changes) {
3789
4589
  const act = on.length > 0 ? activeKf(ctx, on) : void 0;
3790
4590
  return `<g style="${cs(box.color)}">${cardFrame(box, ctx, act, pad2, h)}<text class="dg-sn" x="${r1(box.cx)}" y="${r1(pad2 + nameY)}" text-anchor="middle">${esc(box.name)}</text>${subs}</g>`;
3791
4591
  }
4592
+ function ghostCard(box) {
4593
+ const { icon, iconRadius, iconScale, radius } = LOOK.box;
4594
+ const G = LOOK.state.ghost;
4595
+ const ix = box.x + G.pad + icon / 2;
4596
+ const tx = box.x + G.pad + icon + G.gap;
4597
+ const mark = box.icon && ICONS[box.icon] ? `<rect class="dg-ic" x="${r1(ix - icon / 2)}" y="${r1(box.cy - icon / 2)}" width="${icon}" height="${icon}" rx="${iconRadius}"/>${glyph(box.icon, ix, box.cy, iconScale)}` : "";
4598
+ const nameY = box.sub ? G.nameY : LOOK.baseline.mark;
4599
+ const sub = box.sub ? `<text class="dg-ss" x="${r1(tx)}" y="${r1(box.cy + G.subY)}" text-anchor="start">${esc(box.sub)}</text>` : "";
4600
+ return `<g data-ghost="${esc(box.id)}" style="${cs(box.color)}"><rect class="dg-ghost" x="${r1(box.x)}" y="${r1(box.y)}" width="${r1(box.w)}" height="${box.h}" rx="${radius}"/>${mark}<text class="dg-sn" x="${r1(tx)}" y="${r1(box.cy + nameY)}" text-anchor="start">${esc(box.name)}</text>${sub}</g>`;
4601
+ }
4602
+ function doneMark(box, at, ctx) {
4603
+ const { r, inset } = LOOK.state.done;
4604
+ const x = box.x + box.w - inset;
4605
+ const y = box.y + inset;
4606
+ return `<g class="dg-popc dg-a" data-done="${esc(box.id)}" style="${cs(box.color)};${ctx.m.pop(at)}"><circle class="dg-done" cx="${r1(x)}" cy="${r1(y)}" r="${r}"/>${glyph("check", x, y, 0.5, "dg-done-ck")}</g>`;
4607
+ }
4608
+ function path(p, color) {
4609
+ const label2 = p.label ? `<text class="dg-path-t${p.label.family === "sans" ? " dg-path-tj" : ""}" x="${r1(p.label.x + LOOK.label.padX)}" y="${r1(p.label.y + p.label.h / 2 + LOOK.baseline.label)}">${esc(p.label.text)}</text>` : "";
4610
+ return `<g data-path="${esc(`${p.from}->${p.to}`)}" style="${cs(color)}"><path class="dg-path" d="${pathOf(p.points)}"/><path class="dg-path-h" d="${arrowHead(p.points)}"/>${label2}</g>`;
4611
+ }
4612
+ function side(s, color) {
4613
+ const { pad: pad2 } = LOOK.state.side;
4614
+ const title = s.y + pad2 + TYPE.regionName.size;
4615
+ const notes = s.notes.map((note, k) => `<text class="dg-side-n" x="${r1(s.x + pad2)}" y="${r1(title + LOOK.region.line * (k + 1))}">${esc(note)}</text>`).join("");
4616
+ return `<g style="${cs(color)}"><rect class="dg-side" x="${r1(s.x + 0.5)}" y="${r1(s.y + 0.5)}" width="${r1(s.w - 1)}" height="${r1(s.h - 1)}" rx="${LOOK.region.radius}"/><text class="dg-side-t" x="${r1(s.x + pad2)}" y="${r1(title)}">${esc(s.title)}</text>${notes}</g>`;
4617
+ }
4618
+ function endMark(e, color) {
4619
+ const { end } = LOOK.state;
4620
+ const text2 = e.text === "" ? "" : `<text class="dg-mark" x="${r1(e.x + LOOK.state.text)}" y="${r1(e.y + LOOK.baseline.mark)}">${esc(e.text)}</text>`;
4621
+ const x = r1(e.x);
4622
+ const y = r1(e.y);
4623
+ if (e.kind === "start") return `<g data-end="start"><circle class="dg-start" cx="${x}" cy="${y}" r="${e.r}"/>${text2}</g>`;
4624
+ if (e.ghost) return `<g data-end="finish" style="${cs(color)}"><circle class="dg-end-x" cx="${x}" cy="${y}" r="${e.r}"/><circle class="dg-end-xi" cx="${x}" cy="${y}" r="${end.inner}"/>${text2}</g>`;
4625
+ return `<g data-end="finish"><circle class="dg-end" cx="${x}" cy="${y}" r="${e.r}"/><circle class="dg-end-in" cx="${x}" cy="${y}" r="${end.inner}"/>${text2}</g>`;
4626
+ }
3792
4627
  function lifeline(x, y1, y2) {
3793
4628
  return `<line class="dg-ll" x1="${r1(x)}" y1="${r1(y1)}" x2="${r1(x)}" y2="${r1(y2)}"/>`;
3794
4629
  }
3795
- function edge(e, time, ctx) {
4630
+ function edge(e, time, ctx, past = false) {
3796
4631
  const { m } = ctx;
3797
4632
  const d = pathOf(e.points);
3798
4633
  const head = arrowHead(e.points);
3799
4634
  const { start: a, drawn: b, end } = time;
3800
- const tail = [
4635
+ const tail = past ? [
4636
+ [end, { opacity: 1 }, EASE.inOut],
4637
+ [end + 0.4, { opacity: 0 }],
4638
+ [m.total, { opacity: 0 }]
4639
+ ] : [
3801
4640
  [end, { opacity: 1 }, EASE.inOut],
3802
4641
  [end + 0.4, { opacity: 0.45 }],
3803
4642
  [ctx.end + 0.3, { opacity: 0.45 }, EASE.inOut],
@@ -3805,7 +4644,7 @@ function edge(e, time, ctx) {
3805
4644
  [m.last, { opacity: 0.95 }, EASE.inOut],
3806
4645
  [m.total, { opacity: 0 }]
3807
4646
  ];
3808
- const line = m.kf([
4647
+ const line2 = m.kf([
3809
4648
  [0, { opacity: 0, "stroke-dashoffset": 1 }],
3810
4649
  [a, { opacity: 0, "stroke-dashoffset": 1 }, EASE.inOut],
3811
4650
  [a + 0.05, { opacity: 1 }],
@@ -3824,15 +4663,19 @@ function edge(e, time, ctx) {
3824
4663
  [end + 0.2, { opacity: 0, "stroke-dashoffset": run }],
3825
4664
  [m.total, { opacity: 0, "stroke-dashoffset": run }]
3826
4665
  ]);
4666
+ const grey = past ? m.kf([[0, { opacity: 0 }], [end, { opacity: 0 }, EASE.inOut], [end + 0.4, { opacity: 1 }], [m.last, { opacity: 1 }, EASE.inOut], [m.total, { opacity: 0 }]]) : "";
3827
4667
  return {
3828
- base: `<path class="dg-e" d="${d}"/><path class="dg-eh" d="${head}"/>`,
3829
- lit: `<g style="${cs(e.color)}"><path class="dg-e-on dg-a" pathLength="1" d="${d}" style="${line}"/><path class="dg-eh-on dg-a" d="${head}" style="${hk}"/><path class="dg-flow dg-a" d="${d}" style="${flow}"/></g>`
4668
+ base: `<path class="dg-e" d="${d}"/><path class="dg-eh" d="${head}"/>${past ? `<path class="dg-e-past dg-a" d="${d}" style="${grey}"/><path class="dg-eh-past dg-a" d="${head}" style="${grey}"/>` : ""}`,
4669
+ lit: `<g style="${cs(e.color)}"><path class="dg-e-on dg-a" pathLength="1" d="${d}" style="${line2}"/><path class="dg-eh-on dg-a" d="${head}" style="${hk}"/><path class="dg-flow dg-a" d="${d}" style="${flow}"/></g>`
3830
4670
  };
3831
4671
  }
3832
4672
  function label(l, time, ctx) {
3833
4673
  const ja3 = l.family === "sans" ? " dg-capj" : "";
3834
4674
  const { radius } = LOOK.label;
3835
- return `<g class="dg-cap${ja3} dg-a" style="${cs(l.color)};${ctx.m.rise(time.start, time.end, true)}"><rect x="${r1(l.x)}" y="${r1(l.y)}" width="${r1(l.w)}" height="${l.h}" rx="${radius}"/><text x="${r1(l.x + l.w / 2)}" y="${r1(l.y + l.h / 2 + LOOK.baseline.label)}" text-anchor="middle">${esc(l.text)}</text></g>`;
4675
+ const x = r1(l.x + l.w / 2);
4676
+ const y = r1(l.y + l.h / 2 + LOOK.baseline.label);
4677
+ const past = time.after ? `<g class="dg-cap-past${l.family === "sans" ? " dg-cap-pastj" : ""} dg-a" style="${ctx.m.vis(time.after.start, time.after.end)}"><text x="${x}" y="${y}" text-anchor="middle">${esc(l.text)}</text></g>` : "";
4678
+ return `${past}<g class="dg-cap${ja3} dg-a" style="${cs(l.color)};${ctx.m.rise(time.start, time.end, true)}"><rect x="${r1(l.x)}" y="${r1(l.y)}" width="${r1(l.w)}" height="${l.h}" rx="${radius}"/><text x="${x}" y="${y}" text-anchor="middle">${esc(l.text)}</text></g>`;
3836
4679
  }
3837
4680
  function action(a, at, until, ctx) {
3838
4681
  return `<g class="dg-act dg-a" style="${cs(a.color)};${ctx.m.rise(at, until, true)}"><rect x="${r1(a.x)}" y="${r1(a.y)}" width="${r1(a.w)}" height="${a.h}" rx="${LOOK.action.radius}"/><text x="${r1(a.x + a.w / 2)}" y="${r1(a.y + a.h / 2 + LOOK.baseline.action)}" text-anchor="middle">${esc(a.text)}</text></g>`;
@@ -3854,21 +4697,21 @@ function carrier(e, time, ctx) {
3854
4697
  const n = LOOK.carrier.samples;
3855
4698
  const length = pathLength(e.points);
3856
4699
  const { depart: a, arrive: b, start: from, end: gone } = time;
3857
- const path = [];
4700
+ const path2 = [];
3858
4701
  for (let k = 0; k <= n; k++) {
3859
4702
  const [x, y] = along(e.points, easeInOut(k / n) * length);
3860
- path.push([a + (b - a) * k / n, x, y]);
4703
+ path2.push([a + (b - a) * k / n, x, y]);
3861
4704
  }
3862
- const first = path[0];
3863
- const lastPoint = path[path.length - 1];
4705
+ const first = path2[0];
4706
+ const lastPoint = path2[path2.length - 1];
3864
4707
  const rest = e.settle ?? [lastPoint[1], lastPoint[2]];
3865
- const pts = [[0, first[1], first[2]], ...path];
4708
+ const pts = [[0, first[1], first[2]], ...path2];
3866
4709
  if (e.settle) pts.push([Math.min(b + 0.3, Math.max(gone, b + 0.01)), rest[0], rest[1]]);
3867
4710
  pts.push([gone, rest[0], rest[1]], [m.total, rest[0], rest[1]]);
3868
4711
  const fade = gone < m.last ? 0.05 : 0.18;
3869
4712
  return `<g class="dg-a" style="${m.move(pts, m.blink(from + 0.02, gone, fade))}">${carrierShape(e, ctx.sh)}</g>`;
3870
4713
  }
3871
- function badge(b, ctx) {
4714
+ function badge(b, ctx, grey = false) {
3872
4715
  const { m } = ctx;
3873
4716
  const span = ctx.t.steps[b.step];
3874
4717
  const a = span.start;
@@ -3894,9 +4737,9 @@ function badge(b, ctx) {
3894
4737
  const y = r1(b.y);
3895
4738
  const ty = r1(b.y + LOOK.baseline.badge);
3896
4739
  const no = b.step + 1;
3897
- return `<g class="dg-bd" data-step="${b.step}" style="${cs(b.color)}"><circle class="dg-bdr dg-popc dg-a" cx="${x}" cy="${y}" r="${rr}" style="${ring}"/><g class="dg-a" style="${past}"><circle class="dg-bdp" cx="${x}" cy="${y}" r="${rr}"/><text class="dg-bdpt" x="${x}" y="${ty}" text-anchor="middle">${no}</text></g><g class="dg-popc dg-a" style="${fill}"><circle class="dg-bdf" cx="${x}" cy="${y}" r="${r}"/><text class="dg-bdft" x="${x}" y="${ty}" text-anchor="middle">${no}</text></g></g>`;
4740
+ return `<g class="dg-bd" data-step="${b.step}" style="${cs(b.color)}"><circle class="dg-bdr dg-popc dg-a" cx="${x}" cy="${y}" r="${rr}" style="${ring}"/><g class="dg-a" style="${past}"><circle class="${grey ? "dg-bdp-g" : "dg-bdp"}" cx="${x}" cy="${y}" r="${rr}"/><text class="${grey ? "dg-bdpt-g" : "dg-bdpt"}" x="${x}" y="${ty}" text-anchor="middle">${no}</text></g><g class="dg-popc dg-a" style="${fill}"><circle class="dg-bdf" cx="${x}" cy="${y}" r="${r}"/><text class="dg-bdft" x="${x}" y="${ty}" text-anchor="middle">${no}</text></g></g>`;
3898
4741
  }
3899
- function strip(s, changes, ctx) {
4742
+ function strip(s, changes, ctx, now = false, arrivals = /* @__PURE__ */ new Map()) {
3900
4743
  const { m, sh } = ctx;
3901
4744
  const S2 = LOOK.strip;
3902
4745
  const my = s.y + S2.h / 2;
@@ -3918,8 +4761,18 @@ function strip(s, changes, ctx) {
3918
4761
  values.forEach((c, k) => {
3919
4762
  const next = values[k + 1]?.at;
3920
4763
  const value2 = c.value;
3921
- const anim = next === void 0 ? m.rise(c.at) : m.rise(c.at, next - MOTION.untilFade);
3922
- parts.push(`<g class="dg-a" style="${anim}"><text class="${hasWide(value2) ? "dg-fvj" : "dg-fv"}" x="${r1(field2.x)}" y="${r1(field2.y + S2.valueY)}">${esc(value2)}</text></g>`);
4764
+ const cls = hasWide(value2) ? "dg-fvj" : "dg-fv";
4765
+ const textOf = (c2) => `<text class="${c2}" x="${r1(field2.x)}" y="${r1(field2.y + S2.valueY)}">${esc(value2)}</text>`;
4766
+ const text2 = textOf(cls);
4767
+ if (!now) {
4768
+ const anim = next === void 0 ? m.rise(c.at) : m.rise(c.at, next - MOTION.untilFade);
4769
+ parts.push(`<g class="dg-a" style="${anim}">${text2}</g>`);
4770
+ return;
4771
+ }
4772
+ const until = Math.min(c.until, next ?? c.until);
4773
+ const dot = `<circle class="dg-fl-now" cx="${r1(field2.x + textWidth(field2.name, TYPE.fieldName) + S2.now.gap)}" cy="${r1(field2.y + S2.nameY - TYPE.fieldName.size / 3)}" r="${S2.now.r}"/>`;
4774
+ parts.push(`<g class="dg-fv-now dg-a" data-step="${c.step}" style="${cs(c.color)};${m.rise(c.at, until - MOTION.untilFade)}">${textOf(`${cls} dg-fv-c`)}${dot}</g>`);
4775
+ if (next === void 0 || next > until) parts.push(`<g class="dg-a" style="${m.vis(until - MOTION.untilFade, next === void 0 ? m.last : next - MOTION.untilFade)}">${text2}</g>`);
3923
4776
  });
3924
4777
  tags.forEach((c, k) => {
3925
4778
  const next = tags[k + 1]?.at;
@@ -3933,6 +4786,22 @@ function strip(s, changes, ctx) {
3933
4786
  );
3934
4787
  });
3935
4788
  });
4789
+ if (s.trail) {
4790
+ const t = s.trail;
4791
+ const last = s.fields[s.fields.length - 1];
4792
+ if (last && last.y === t.y) {
4793
+ const sx = t.x - S2.fieldGap / 2;
4794
+ parts.push(`<line class="dg-sep" x1="${r1(sx)}" y1="${r1(t.y + S2.sepInset)}" x2="${r1(sx)}" y2="${r1(t.y + S2.h - S2.sepInset)}"/>`);
4795
+ }
4796
+ parts.push(`<text class="dg-fl" x="${r1(t.x)}" y="${r1(t.y + S2.nameY)}">${esc(t.title)}</text>`);
4797
+ const dy = t.y + S2.valueY - TYPE.fieldValue.size / 3;
4798
+ t.states.forEach((state, k) => {
4799
+ const cx = r1(t.x + S2.trail.r + k * S2.trail.step);
4800
+ const at = arrivals.get(state.box);
4801
+ const fill = at === void 0 ? "" : `<circle class="dg-tr-fill dg-a" cx="${cx}" cy="${r1(dy)}" r="${S2.trail.r}" style="${m.pop(at)}"/>`;
4802
+ parts.push(`<g data-trail="${esc(state.box)}" style="${cs(state.color)}"><circle class="dg-tr-ring" cx="${cx}" cy="${r1(dy)}" r="${S2.trail.r}"/>${fill}</g>`);
4803
+ });
4804
+ }
3936
4805
  return parts.join("");
3937
4806
  }
3938
4807
 
@@ -4029,6 +4898,7 @@ var font = (t) => `font:${t.weight} ${t.size}px var(--${t.family})`;
4029
4898
  var mix = (pct, base = "var(--surf)") => `color-mix(in srgb,var(--c) ${pct}%,${base})`;
4030
4899
  var S = LOOK.stroke;
4031
4900
  var X = LOOK.mix;
4901
+ var PAST = `color-mix(in srgb,var(--mute) ${X.past}%,var(--bg))`;
4032
4902
  var PART_CSS = [
4033
4903
  ".dg{display:block;width:100%;height:auto;overflow:visible}",
4034
4904
  ".dg .dg-a{animation-duration:var(--T);animation-timing-function:linear;animation-iteration-count:infinite;animation-fill-mode:both;animation-delay:calc(var(--at,0) * -1s);animation-play-state:var(--play,running)}",
@@ -4053,15 +4923,21 @@ var PART_CSS = [
4053
4923
  `.dg-e-on{fill:none;stroke:var(--c);stroke-width:${S.edgeOn};stroke-linecap:round;stroke-dasharray:1 2}`,
4054
4924
  `.dg-eh-on{fill:none;stroke:var(--c);stroke-width:${S.edgeOn};stroke-linecap:round;stroke-linejoin:round}`,
4055
4925
  `.dg-flow{fill:none;stroke:var(--surf);stroke-width:${S.flow};stroke-linecap:round;stroke-dasharray:1.5 ${LOOK.edge.flowDash}}`,
4926
+ `.dg-e-past{fill:none;stroke:${PAST};stroke-width:${S.edge};stroke-linecap:round}`,
4927
+ `.dg-eh-past{fill:none;stroke:${PAST};stroke-width:${S.arrow};stroke-linecap:round;stroke-linejoin:round}`,
4056
4928
  ".dg-bd{cursor:pointer}",
4057
4929
  ".dg-bdf{fill:var(--c)}",
4058
4930
  `.dg-bdft{${font(TYPE.badge)};fill:var(--on-c)}`,
4059
4931
  `.dg-bdr{fill:none;stroke:var(--c);stroke-width:${S.badgeRing}}`,
4060
4932
  `.dg-bdp{fill:${mix(X.badgePast)};stroke:${mix(X.badgePastEdge, "transparent")};stroke-width:${S.hair}}`,
4061
4933
  `.dg-bdpt{${font(TYPE.badge)};fill:var(--ct)}`,
4934
+ `.dg-bdp-g{fill:var(--surf);stroke:${PAST};stroke-width:${S.hair}}`,
4935
+ `.dg-bdpt-g{${font(TYPE.badge)};fill:var(--mute)}`,
4062
4936
  `.dg-cap rect,.dg-act rect{fill:${mix(X.cap)};stroke:${mix(X.capEdge, "transparent")}}`,
4063
4937
  `.dg-cap text{${font(TYPE.label)};fill:var(--ct)}`,
4064
4938
  `.dg-capj text{${font(TYPE.labelJa)}}`,
4939
+ `.dg-cap-past text{${font(TYPE.label)};fill:var(--mute);fill-opacity:${LOOK.state.pastLabel}}`,
4940
+ `.dg-cap-pastj text{${font(TYPE.labelJa)}}`,
4065
4941
  `.dg-act text{${font(TYPE.action)};fill:var(--ct)}`,
4066
4942
  ".dg-car{fill:var(--carry,var(--ink))}",
4067
4943
  `.dg-car-t{${font(TYPE.carrier)};fill:var(--bg)}`,
@@ -4076,8 +4952,28 @@ var PART_CSS = [
4076
4952
  `.dg-fl{${font(TYPE.fieldName)};fill:var(--mute)}`,
4077
4953
  `.dg-fv{${font(TYPE.fieldValue)};fill:var(--ink)}`,
4078
4954
  `.dg-fvj{${font(TYPE.fieldValueJa)};fill:var(--ink)}`,
4955
+ ".dg-fv-c{fill:var(--ct)}",
4956
+ ".dg-fl-now{fill:var(--c)}",
4957
+ `.dg-tr-ring{fill:none;stroke:var(--line);stroke-width:${S.trail}}`,
4958
+ ".dg-tr-fill{fill:var(--c)}",
4079
4959
  ".dg-tg rect{fill:var(--c)}",
4080
4960
  `.dg-tg text{${font(TYPE.tag)};fill:var(--on-c)}`,
4961
+ `.dg-side{fill:color-mix(in srgb,var(--c) ${X.side}%,var(--bg));stroke:${mix(X.sideEdge, "transparent")};stroke-dasharray:4 4}`,
4962
+ `.dg-side-t{${font(TYPE.regionName)};fill:var(--ct)}`,
4963
+ `.dg-side-n{${font(TYPE.regionNote)};fill:var(--mute)}`,
4964
+ `.dg-ghost{fill:var(--surf);stroke:${mix(X.ghostEdge, "transparent")};stroke-dasharray:4 3}`,
4965
+ `.dg-path{fill:none;stroke:${mix(X.path, "transparent")};stroke-width:${S.path};stroke-linecap:round;stroke-dasharray:0 ${LOOK.edge.ghostDash}}`,
4966
+ `.dg-path-h{fill:none;stroke:${mix(X.path, "transparent")};stroke-width:${S.arrow};stroke-linecap:round;stroke-linejoin:round}`,
4967
+ `.dg-path-t{${font(TYPE.label)};fill:var(--ct)}`,
4968
+ `.dg-path-tj{${font(TYPE.labelJa)}}`,
4969
+ ".dg-start{fill:var(--ink)}",
4970
+ `.dg-end{fill:var(--bg);stroke:var(--ink);stroke-width:${S.end}}`,
4971
+ ".dg-end-in{fill:var(--ink)}",
4972
+ `.dg-end-x{fill:var(--bg);stroke:${mix(X.path, "transparent")};stroke-width:${S.arrow};stroke-dasharray:2 2.5}`,
4973
+ `.dg-end-xi{fill:${mix(X.path, "transparent")}}`,
4974
+ `.dg-mark{${font(TYPE.regionNote)};fill:var(--mute)}`,
4975
+ `.dg-done{fill:var(--ink);stroke:var(--surf);stroke-width:${S.done}}`,
4976
+ `.dg-done-ck{fill:none;stroke:var(--surf);stroke-width:${S.glyph};stroke-linecap:round;stroke-linejoin:round}`,
4081
4977
  ".dg-vp-bg{fill:var(--bg)}",
4082
4978
  ".dg-vp-frame{fill:none;stroke:var(--hair)}",
4083
4979
  ".dg-hd-bg{fill:var(--bg)}",
@@ -4155,7 +5051,8 @@ function fieldChanges(diagram, timeline, layout) {
4155
5051
  if (event2?.type !== "strip") continue;
4156
5052
  const color = layout.badges[time.step]?.color ?? "slate";
4157
5053
  const list2 = out.get(event2.field) ?? [];
4158
- list2.push({ at: time.at, color, ...event2.value !== void 0 ? { value: event2.value } : {}, ...event2.tag !== void 0 ? { tag: event2.tag } : {} });
5054
+ const until = timeline.steps[time.step].end;
5055
+ list2.push({ at: time.at, color, step: time.step, until, ...event2.value !== void 0 ? { value: event2.value } : {}, ...event2.tag !== void 0 ? { tag: event2.tag } : {} });
4159
5056
  out.set(event2.field, list2);
4160
5057
  }
4161
5058
  return out;
@@ -4165,20 +5062,36 @@ function drawSvg(diagram, layout, timeline, palette, theme, follow) {
4165
5062
  const m = new Motion(`dg${id}`, timeline.total, timeline.last);
4166
5063
  const ctx = { m, t: timeline, sh: `filter="url(#dg-sh-${id})"`, end: timeline.steps[timeline.steps.length - 1].end };
4167
5064
  const on = involved(diagram);
4168
- const subs = subChanges(diagram, timeline, layout.kind === "architecture");
5065
+ const subs = subChanges(diagram, timeline, layout.kind !== "sequence");
4169
5066
  const L = { band: [], base: [], lit: [], node: [], badge: [], top: [] };
4170
5067
  for (const region of layout.regions) L.band.push(band(region));
4171
- if (layout.strip) L.band.push(strip(layout.strip, fieldChanges(diagram, timeline, layout), ctx));
4172
- for (const line of layout.lifelines) L.base.push(lifeline(line.x, line.y1, line.y2));
5068
+ const ghostColor = layout.boxes.find((b) => b.ghost)?.color ?? "slate";
5069
+ if (layout.side) L.band.push(side(layout.side, ghostColor));
5070
+ const boxColor = (id2, ghost) => layout.boxes.find((b) => b.id === id2 && (ghost === void 0 || b.ghost === ghost))?.color;
5071
+ for (const p of layout.paths) L.base.push(path(p, boxColor(p.to, true) ?? boxColor(p.from) ?? ghostColor));
5072
+ for (const e of layout.ends) L.node.push(endMark(e, ghostColor));
5073
+ const isState = layout.kind === "state";
5074
+ const arrivals = new Map((timeline.states ?? []).flatMap((s) => s.lit[0] ? [[s.box, s.lit[0].start]] : []));
5075
+ if (layout.strip) L.band.push(strip(layout.strip, fieldChanges(diagram, timeline, layout), ctx, isState, arrivals));
5076
+ for (const line2 of layout.lifelines) L.base.push(lifeline(line2.x, line2.y1, line2.y2));
4173
5077
  for (const e of layout.edges) {
4174
5078
  const time = timeline.edges.find((t) => t.step === e.step && t.event === e.event);
4175
5079
  if (!time) continue;
4176
- const drawn = edge(e, time, ctx);
5080
+ const drawn = edge(e, time, ctx, isState);
4177
5081
  L.base.push(drawn.base);
4178
5082
  L.lit.push(drawn.lit);
4179
5083
  }
4180
- for (const box of layout.boxes) L.node.push(card(box, ctx, on.get(box.id) ?? [], subs.get(box.id) ?? []));
4181
- for (const b of layout.badges) L.badge.push(badge(b, ctx));
5084
+ const states = new Map((timeline.states ?? []).map((s) => [s.box, s]));
5085
+ for (const box of layout.boxes) {
5086
+ if (box.ghost) {
5087
+ L.node.push(ghostCard(box));
5088
+ continue;
5089
+ }
5090
+ const state = states.get(box.id);
5091
+ L.node.push(card(box, ctx, on.get(box.id) ?? [], subs.get(box.id) ?? [], isState ? state?.lit ?? [] : void 0));
5092
+ if (state?.done !== void 0) L.node.push(doneMark(box, state.done, ctx));
5093
+ }
5094
+ for (const b of layout.badges) L.badge.push(badge(b, ctx, isState));
4182
5095
  for (const l of layout.labels) {
4183
5096
  const time = timeline.labels.find((t) => t.step === l.step && t.event === l.event);
4184
5097
  if (time) L.top.push(label(l, time, ctx));
@@ -4314,7 +5227,7 @@ function renderDiagram(input, options = {}) {
4314
5227
  const diagram = read.diagram;
4315
5228
  const palette = resolvePalette(options.palette);
4316
5229
  const theme = options.theme === "dark" ? "dark" : "light";
4317
- const layout = diagram.kind === "sequence" ? layoutSequence(diagram) : layoutArchitecture(diagram);
5230
+ const layout = diagram.kind === "sequence" ? layoutSequence(diagram) : diagram.kind === "state" ? layoutState(diagram, lang) : layoutArchitecture(diagram);
4318
5231
  const timeline = buildTimeline(diagram);
4319
5232
  return {
4320
5233
  svg: drawSvg(diagram, layout, timeline, palette, theme),
@@ -4462,9 +5375,9 @@ function mountDiagram(host, diagram, options = {}) {
4462
5375
  const head = doc.createElement("strong");
4463
5376
  head.textContent = step2.title;
4464
5377
  item.append(head);
4465
- for (const line of step2.body.split("\n")) {
5378
+ for (const line2 of step2.body.split("\n")) {
4466
5379
  const p = doc.createElement("p");
4467
- p.textContent = line;
5380
+ p.textContent = line2;
4468
5381
  item.append(p);
4469
5382
  }
4470
5383
  list2.append(item);
@@ -4602,10 +5515,12 @@ function mountDiagram(host, diagram, options = {}) {
4602
5515
  exports.DEFAULT_PALETTE = DEFAULT_PALETTE;
4603
5516
  exports.FONTS = FONTS;
4604
5517
  exports.FORMAT_VERSION = FORMAT_VERSION;
5518
+ exports.ICONS = ICONS;
4605
5519
  exports.PALETTES = PALETTES;
4606
5520
  exports.READABLE_PX = READABLE_PX;
4607
5521
  exports.chooseView = chooseView;
4608
5522
  exports.extractDiagrams = extractDiagrams;
5523
+ exports.iconSvg = iconSvg;
4609
5524
  exports.migrateFile = migrateFile;
4610
5525
  exports.mountDiagram = mountDiagram;
4611
5526
  exports.parseNotation = parseNotation;