schematex 0.6.5 → 0.6.6

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.
Files changed (164) hide show
  1. package/dist/ai/ai-sdk.cjs +22 -22
  2. package/dist/ai/ai-sdk.d.cts +3 -3
  3. package/dist/ai/ai-sdk.d.ts +3 -3
  4. package/dist/ai/ai-sdk.js +17 -17
  5. package/dist/ai/index.cjs +28 -28
  6. package/dist/ai/index.d.cts +3 -3
  7. package/dist/ai/index.d.ts +3 -3
  8. package/dist/ai/index.js +17 -17
  9. package/dist/{api-BXkOT7GL.d.cts → api-DA4-U-jn.d.cts} +2 -2
  10. package/dist/{api-BIqZjEDf.d.ts → api-QFMTlIi7.d.ts} +2 -2
  11. package/dist/browser.cjs +23 -23
  12. package/dist/browser.d.cts +3 -3
  13. package/dist/browser.d.ts +3 -3
  14. package/dist/browser.js +17 -17
  15. package/dist/{chunk-3C5DKCBJ.cjs → chunk-2SZJQVPN.cjs} +12 -12
  16. package/dist/{chunk-3C5DKCBJ.cjs.map → chunk-2SZJQVPN.cjs.map} +1 -1
  17. package/dist/{chunk-RVHOCGHT.js → chunk-3GAPHXCE.js} +3 -3
  18. package/dist/{chunk-RVHOCGHT.js.map → chunk-3GAPHXCE.js.map} +1 -1
  19. package/dist/{chunk-ZZHQBAC3.js → chunk-3HZW6K5I.js} +130 -4
  20. package/dist/chunk-3HZW6K5I.js.map +1 -0
  21. package/dist/{chunk-HCBXTBFA.cjs → chunk-5FYPSIGD.cjs} +12 -12
  22. package/dist/{chunk-HCBXTBFA.cjs.map → chunk-5FYPSIGD.cjs.map} +1 -1
  23. package/dist/{chunk-B7ATOBL7.js → chunk-6NUAGU6O.js} +3 -3
  24. package/dist/{chunk-B7ATOBL7.js.map → chunk-6NUAGU6O.js.map} +1 -1
  25. package/dist/{chunk-WZ5QBGPZ.cjs → chunk-77GPD4YQ.cjs} +4 -4
  26. package/dist/{chunk-WZ5QBGPZ.cjs.map → chunk-77GPD4YQ.cjs.map} +1 -1
  27. package/dist/{chunk-IPEHLRTI.js → chunk-7DAIEDQP.js} +3 -3
  28. package/dist/{chunk-IPEHLRTI.js.map → chunk-7DAIEDQP.js.map} +1 -1
  29. package/dist/{chunk-S2CHBZ4A.cjs → chunk-BL57NQKN.cjs} +13 -13
  30. package/dist/{chunk-S2CHBZ4A.cjs.map → chunk-BL57NQKN.cjs.map} +1 -1
  31. package/dist/{chunk-T3ZN5P32.cjs → chunk-CMZKAASF.cjs} +132 -6
  32. package/dist/{chunk-ZZHQBAC3.js.map → chunk-CMZKAASF.cjs.map} +1 -1
  33. package/dist/{chunk-XJJUJ2EF.cjs → chunk-DO2DDHTQ.cjs} +4 -4
  34. package/dist/{chunk-XJJUJ2EF.cjs.map → chunk-DO2DDHTQ.cjs.map} +1 -1
  35. package/dist/{chunk-I6UJR4SG.cjs → chunk-DR3DDDQY.cjs} +4 -4
  36. package/dist/{chunk-I6UJR4SG.cjs.map → chunk-DR3DDDQY.cjs.map} +1 -1
  37. package/dist/{chunk-W3IXH6BN.cjs → chunk-EUVUO3CL.cjs} +4 -4
  38. package/dist/chunk-EUVUO3CL.cjs.map +1 -0
  39. package/dist/{chunk-MI77LY6A.js → chunk-FOPOOV2P.js} +991 -377
  40. package/dist/chunk-FOPOOV2P.js.map +1 -0
  41. package/dist/{chunk-GV5QLYTW.js → chunk-HL5PS6MG.js} +3 -3
  42. package/dist/{chunk-GV5QLYTW.js.map → chunk-HL5PS6MG.js.map} +1 -1
  43. package/dist/{chunk-MKECYIWN.js → chunk-HPEAE3JM.js} +3 -3
  44. package/dist/{chunk-MKECYIWN.js.map → chunk-HPEAE3JM.js.map} +1 -1
  45. package/dist/{chunk-KPKGMOTS.js → chunk-JN6FHUC6.js} +3 -3
  46. package/dist/{chunk-KPKGMOTS.js.map → chunk-JN6FHUC6.js.map} +1 -1
  47. package/dist/{chunk-OHLNH7IO.js → chunk-K2D6VFLP.js} +3 -3
  48. package/dist/{chunk-OHLNH7IO.js.map → chunk-K2D6VFLP.js.map} +1 -1
  49. package/dist/{chunk-OANWVUBA.js → chunk-KCHUQXS3.js} +3 -3
  50. package/dist/chunk-KCHUQXS3.js.map +1 -0
  51. package/dist/{chunk-ZZFPXCAK.cjs → chunk-KGOZBABH.cjs} +12 -12
  52. package/dist/{chunk-ZZFPXCAK.cjs.map → chunk-KGOZBABH.cjs.map} +1 -1
  53. package/dist/{chunk-35XCP2E4.js → chunk-KJZCRHNR.js} +3 -3
  54. package/dist/{chunk-35XCP2E4.js.map → chunk-KJZCRHNR.js.map} +1 -1
  55. package/dist/{chunk-XO7WW3I6.cjs → chunk-LPAWZYDU.cjs} +4 -4
  56. package/dist/{chunk-XO7WW3I6.cjs.map → chunk-LPAWZYDU.cjs.map} +1 -1
  57. package/dist/{chunk-624UQ5R6.cjs → chunk-MLLARXOI.cjs} +1050 -435
  58. package/dist/chunk-MLLARXOI.cjs.map +1 -0
  59. package/dist/{chunk-ROX5KEZM.cjs → chunk-NFZMNKOR.cjs} +15 -15
  60. package/dist/{chunk-ROX5KEZM.cjs.map → chunk-NFZMNKOR.cjs.map} +1 -1
  61. package/dist/{chunk-R5E2LSN2.cjs → chunk-NZT5P2XZ.cjs} +73 -2
  62. package/dist/chunk-NZT5P2XZ.cjs.map +1 -0
  63. package/dist/{chunk-GPC5BWLI.js → chunk-OFKRELZK.js} +3 -3
  64. package/dist/{chunk-GPC5BWLI.js.map → chunk-OFKRELZK.js.map} +1 -1
  65. package/dist/{chunk-XEIVA2CT.js → chunk-T3FV73LM.js} +3 -3
  66. package/dist/{chunk-XEIVA2CT.js.map → chunk-T3FV73LM.js.map} +1 -1
  67. package/dist/{chunk-4THUHX2D.cjs → chunk-T5KHNJ67.cjs} +5 -5
  68. package/dist/{chunk-4THUHX2D.cjs.map → chunk-T5KHNJ67.cjs.map} +1 -1
  69. package/dist/{chunk-FXPOHPBE.cjs → chunk-TACTEF2N.cjs} +4 -4
  70. package/dist/{chunk-FXPOHPBE.cjs.map → chunk-TACTEF2N.cjs.map} +1 -1
  71. package/dist/{chunk-AORGFBEH.js → chunk-UK6HF6PE.js} +73 -3
  72. package/dist/chunk-UK6HF6PE.js.map +1 -0
  73. package/dist/{chunk-LGFB4H5B.js → chunk-WU2N6ZVM.js} +3 -3
  74. package/dist/{chunk-LGFB4H5B.js.map → chunk-WU2N6ZVM.js.map} +1 -1
  75. package/dist/{chunk-BXNOXOE4.cjs → chunk-XYHCAJMI.cjs} +4 -4
  76. package/dist/{chunk-BXNOXOE4.cjs.map → chunk-XYHCAJMI.cjs.map} +1 -1
  77. package/dist/{chunk-FHZTWWI6.js → chunk-YMZTXOUG.js} +3 -3
  78. package/dist/{chunk-FHZTWWI6.js.map → chunk-YMZTXOUG.js.map} +1 -1
  79. package/dist/{chunk-XSPENTEG.js → chunk-YTGOLTLJ.js} +3 -3
  80. package/dist/{chunk-XSPENTEG.js.map → chunk-YTGOLTLJ.js.map} +1 -1
  81. package/dist/{chunk-VZO2SX6Q.cjs → chunk-Z3A2UNK2.cjs} +4 -4
  82. package/dist/{chunk-VZO2SX6Q.cjs.map → chunk-Z3A2UNK2.cjs.map} +1 -1
  83. package/dist/{diagnostics-CzHW0RCo.d.cts → diagnostics-CSznf_sl.d.cts} +1 -1
  84. package/dist/{diagnostics-CzHW0RCo.d.ts → diagnostics-CSznf_sl.d.ts} +1 -1
  85. package/dist/diagrams/blockdiagram/index.d.cts +1 -1
  86. package/dist/diagrams/blockdiagram/index.d.ts +1 -1
  87. package/dist/diagrams/circuit/index.cjs +8 -8
  88. package/dist/diagrams/circuit/index.d.cts +1 -1
  89. package/dist/diagrams/circuit/index.d.ts +1 -1
  90. package/dist/diagrams/circuit/index.js +2 -2
  91. package/dist/diagrams/ecomap/index.cjs +7 -7
  92. package/dist/diagrams/ecomap/index.d.cts +1 -1
  93. package/dist/diagrams/ecomap/index.d.ts +1 -1
  94. package/dist/diagrams/ecomap/index.js +2 -2
  95. package/dist/diagrams/entity/index.cjs +6 -6
  96. package/dist/diagrams/entity/index.d.cts +1 -1
  97. package/dist/diagrams/entity/index.d.ts +1 -1
  98. package/dist/diagrams/entity/index.js +2 -2
  99. package/dist/diagrams/fishbone/index.cjs +8 -8
  100. package/dist/diagrams/fishbone/index.d.cts +1 -1
  101. package/dist/diagrams/fishbone/index.d.ts +1 -1
  102. package/dist/diagrams/fishbone/index.js +2 -2
  103. package/dist/diagrams/flowchart/index.cjs +8 -8
  104. package/dist/diagrams/flowchart/index.d.cts +2 -2
  105. package/dist/diagrams/flowchart/index.d.ts +2 -2
  106. package/dist/diagrams/flowchart/index.js +2 -2
  107. package/dist/diagrams/genogram/index.cjs +9 -9
  108. package/dist/diagrams/genogram/index.d.cts +1 -1
  109. package/dist/diagrams/genogram/index.d.ts +1 -1
  110. package/dist/diagrams/genogram/index.js +2 -2
  111. package/dist/diagrams/ladder/index.cjs +6 -6
  112. package/dist/diagrams/ladder/index.d.cts +1 -1
  113. package/dist/diagrams/ladder/index.d.ts +1 -1
  114. package/dist/diagrams/ladder/index.js +2 -2
  115. package/dist/diagrams/logic/index.cjs +8 -8
  116. package/dist/diagrams/logic/index.d.cts +1 -1
  117. package/dist/diagrams/logic/index.d.ts +1 -1
  118. package/dist/diagrams/logic/index.js +2 -2
  119. package/dist/diagrams/orgchart/index.cjs +7 -7
  120. package/dist/diagrams/orgchart/index.d.cts +1 -1
  121. package/dist/diagrams/orgchart/index.d.ts +1 -1
  122. package/dist/diagrams/orgchart/index.js +2 -2
  123. package/dist/diagrams/pedigree/index.cjs +7 -7
  124. package/dist/diagrams/pedigree/index.d.cts +1 -1
  125. package/dist/diagrams/pedigree/index.d.ts +1 -1
  126. package/dist/diagrams/pedigree/index.js +2 -2
  127. package/dist/diagrams/phylo/index.cjs +7 -7
  128. package/dist/diagrams/phylo/index.d.cts +1 -1
  129. package/dist/diagrams/phylo/index.d.ts +1 -1
  130. package/dist/diagrams/phylo/index.js +2 -2
  131. package/dist/diagrams/sld/index.cjs +8 -8
  132. package/dist/diagrams/sld/index.d.cts +1 -1
  133. package/dist/diagrams/sld/index.d.ts +1 -1
  134. package/dist/diagrams/sld/index.js +2 -2
  135. package/dist/diagrams/sociogram/index.cjs +6 -6
  136. package/dist/diagrams/sociogram/index.d.cts +1 -1
  137. package/dist/diagrams/sociogram/index.d.ts +1 -1
  138. package/dist/diagrams/sociogram/index.js +2 -2
  139. package/dist/diagrams/timing/index.d.cts +1 -1
  140. package/dist/diagrams/timing/index.d.ts +1 -1
  141. package/dist/diagrams/venn/index.cjs +9 -9
  142. package/dist/diagrams/venn/index.d.cts +1 -1
  143. package/dist/diagrams/venn/index.d.ts +1 -1
  144. package/dist/diagrams/venn/index.js +2 -2
  145. package/dist/{index-R0IwpG20.d.cts → index-CDpYuU7l.d.cts} +1 -1
  146. package/dist/{index-DdR1Auby.d.ts → index-jTwjudTW.d.ts} +1 -1
  147. package/dist/index.cjs +77 -73
  148. package/dist/index.d.cts +7 -5
  149. package/dist/index.d.ts +7 -5
  150. package/dist/index.js +21 -21
  151. package/dist/react.cjs +17 -17
  152. package/dist/react.d.cts +2 -2
  153. package/dist/react.d.ts +2 -2
  154. package/dist/react.js +16 -16
  155. package/dist/{tools-DHSVXHM9.d.cts → tools-CbuSbW6B.d.cts} +2 -2
  156. package/dist/{tools-B7EqXLgD.d.ts → tools-D344vOzR.d.ts} +2 -2
  157. package/package.json +1 -1
  158. package/dist/chunk-624UQ5R6.cjs.map +0 -1
  159. package/dist/chunk-AORGFBEH.js.map +0 -1
  160. package/dist/chunk-MI77LY6A.js.map +0 -1
  161. package/dist/chunk-OANWVUBA.js.map +0 -1
  162. package/dist/chunk-R5E2LSN2.cjs.map +0 -1
  163. package/dist/chunk-T3ZN5P32.cjs.map +0 -1
  164. package/dist/chunk-W3IXH6BN.cjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/diagrams/logic/parser.ts","../src/diagrams/logic/symbols.ts","../src/diagrams/logic/layout.ts","../src/diagrams/logic/renderer.ts","../src/diagrams/logic/lint.ts","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AAA,MACN,OAAA,EAAS,CAAA,MAAA,EAAS,CAAA,CAAE,EAAE,4BAA4B,GAAG,CAAA,iCAAA,CAAA;AAAA,MACrD,IAAA,EAAM,IAAI,GAAG,CAAA,4BAAA,EAA+B,WAAW,GAAA,CAAI,WAAA,EAAY,EAAG,WAAW,CAAC,CAAA,gFAAA,CAAA;AAAA,MACtF,KAAA,EAAO;AAAA,KACR,CAAA;AAAA,EACH;AACA,EAAA,OAAO,GAAA;AACT;;;ACrCO,IAAM,KAAA,GAAuB;AAAA,EAClC,IAAA,EAAM,OAAA;AAAA,EACN,OAAOA,KAAAA,EAAuB;AAC5B,IAAA,MAAM,KAAA,GAAQA,KAAAA,CAAK,IAAA,EAAK,CAAE,KAAA,CAAM,IAAI,CAAA,CAAE,CAAC,CAAA,EAAG,IAAA,EAAK,CAAE,WAAA,EAAY,IAAK,EAAA;AAClE,IAAA,OAAO,KAAA,CAAM,WAAW,OAAO,CAAA;AAAA,EACjC,CAAA;AAAA,EACA,KAAA,EAAO,UAAA;AAAA,EACP,IAAA,EAAM,SAAA;AAAA,EAEN,MAAA,CAAOA,OAAc,MAAA,EAAgB;AACnC,IAAA,MAAM,GAAA,GAAM,WAAWA,KAAI,CAAA;AAC3B,IAAA,OAAO,WAAA,CAAY,KAAK,MAAM,CAAA;AAAA,EAChC;AACF","file":"chunk-RVHOCGHT.js","sourcesContent":["import type {\n LogicGateAST,\n LogicGateInput,\n LogicGateOutput,\n LogicGateNode,\n LogicGateType,\n LogicGateStyle,\n LogicGateModule,\n} from \"../../core/types\";\nimport { matchQuotedTitle } from \"../../core/quotes\";\n\nexport class LogicParseError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"LogicParseError\";\n }\n}\n\nconst GATE_TYPES = new Set<string>([\n \"AND\", \"OR\", \"NOT\", \"NAND\", \"NOR\", \"XOR\", \"XNOR\", \"BUF\",\n \"TRISTATE_BUF\", \"TRISTATE_INV\", \"OPEN_DRAIN\", \"SCHMITT\",\n \"DFF\", \"JKFF\", \"SRFF\", \"TFF\", \"LATCH_SR\", \"LATCH_D\",\n \"MUX\", \"DEMUX\", \"DECODER\", \"ENCODER\", \"COUNTER\", \"SHIFT_REG\",\n]);\n\nfunction splitIds(s: string): string[] {\n return s\n .split(\",\")\n .map((x) => x.trim())\n .filter(Boolean);\n}\n\nfunction parseInputList(s: string): string[] {\n // Supports named (D=A) or positional. Returns raw tokens (keep ~ prefix for active-low).\n return s\n .split(\",\")\n .map((x) => x.trim())\n .filter(Boolean)\n .map((tok) => {\n const eq = tok.indexOf(\"=\");\n return eq >= 0 ? tok.slice(eq + 1).trim() : tok;\n });\n}\n\nexport function parseLogic(text: string): LogicGateAST {\n const lines = text.split(\"\\n\").map((l) => l.replace(/\\r$/, \"\").trim());\n let title: string | undefined;\n let style: LogicGateStyle | undefined;\n const inputs: LogicGateInput[] = [];\n const outputs: LogicGateOutput[] = [];\n const gates: LogicGateNode[] = [];\n const modules: LogicGateModule[] = [];\n const moduleStack: string[] = [];\n let moduleCounter = 0;\n const explicitOutputFrom = new Map<string, string>();\n const warnings: string[] = [];\n\n for (const rawLine of lines) {\n // Strip line comments\n const line = rawLine.replace(/#.*$/, \"\").replace(/--.*$/, \"\").trim();\n if (!line) continue;\n\n // module \"Label\" { or module Label {\n const modOpen = line.match(/^module\\s+(?:\"([^\"]+)\"|([a-zA-Z_][\\w]*))\\s*\\{$/);\n if (modOpen) {\n const label = modOpen[1] ?? modOpen[2];\n const id = `mod_${moduleCounter++}`;\n modules.push({ id, label });\n moduleStack.push(id);\n continue;\n }\n\n // close module\n if (line === \"}\") {\n if (moduleStack.length === 0) {\n throw new LogicParseError(\"Unmatched `}` — no open module\");\n }\n moduleStack.pop();\n continue;\n }\n\n // Header\n if (/^logic\\b/i.test(line)) {\n const t = matchQuotedTitle(line);\n if (t !== undefined) title = t;\n const s = line.match(/style\\s*:\\s*(ansi|iec)/i);\n if (s) style = s[1].toLowerCase() as LogicGateStyle;\n continue;\n }\n\n // input A, B, C\n const inputMatch = line.match(/^input\\s+(.+)$/i);\n if (inputMatch) {\n for (const id of splitIds(inputMatch[1])) {\n const isLow = id.startsWith(\"~\");\n const clean = isLow ? id.slice(1) : id;\n inputs.push({ id: clean, label: clean, isActiveLow: isLow || undefined });\n }\n continue;\n }\n\n // output X, Y\n const outputMatch = line.match(/^output\\s+(.+)$/i);\n if (outputMatch) {\n for (const id of splitIds(outputMatch[1])) {\n outputs.push({ id, label: id, from: id });\n }\n continue;\n }\n\n // OUTPUT <- GATE (map output to gate)\n const assignMatch = line.match(/^([a-zA-Z_][\\w]*)\\s*<-\\s*([a-zA-Z_][\\w]*)$/);\n if (assignMatch) {\n explicitOutputFrom.set(assignMatch[1], assignMatch[2]);\n continue;\n }\n\n // Gate: ID = GATE(a, b, ...)\n const gateMatch = line.match(/^([a-zA-Z_][\\w]*)\\s*=\\s*([A-Za-z_][\\w]*)\\s*\\(([^)]*)\\)$/);\n if (gateMatch) {\n const id = gateMatch[1];\n const rawType = gateMatch[2].toUpperCase();\n const gInputs = parseInputList(gateMatch[3]);\n const moduleId = moduleStack[moduleStack.length - 1];\n // Graceful degradation: an unrecognised gate is NOT fatal. Keep it with\n // the `unknown` sentinel + the raw token so the renderer draws a flagged\n // placeholder and the lint pass warns. Blanking the whole diagram on one\n // bad gate word is hostile to LLM-generated DSL.\n if (GATE_TYPES.has(rawType)) {\n gates.push({ id, gateType: rawType as LogicGateType, inputs: gInputs, moduleId });\n } else {\n gates.push({ id, gateType: \"unknown\", rawType: gateMatch[2], inputs: gInputs, moduleId });\n warnings.push(\n `Gate \"${id}\" has unrecognised type \"${gateMatch[2]}\"; drawn as a flagged placeholder.`\n );\n }\n continue;\n }\n }\n\n if (moduleStack.length > 0) {\n throw new LogicParseError(`Unclosed module (${moduleStack.length} open)`);\n }\n\n // Wire outputs: if output not explicitly mapped, look for gate with same id\n for (const out of outputs) {\n const mapped = explicitOutputFrom.get(out.id);\n if (mapped) out.from = mapped;\n else if (gates.some((g) => g.id === out.id)) out.from = out.id;\n }\n\n // Resolve undefined signal references: auto-declare them as inputs and\n // emit a warning. Hard-failing here is hostile to LLM-generated DSL where\n // the model often forgets the explicit `input` line — see playbook.\n const known = new Set<string>([\n ...inputs.map((i) => i.id),\n ...gates.map((g) => g.id),\n ]);\n const autoDeclared = new Set<string>();\n for (const g of gates) {\n for (const inp of g.inputs) {\n const isLow = inp.startsWith(\"~\");\n const clean = isLow ? inp.slice(1) : inp;\n if (!known.has(clean) && !autoDeclared.has(clean)) {\n autoDeclared.add(clean);\n inputs.push({\n id: clean,\n label: clean,\n isActiveLow: isLow || undefined,\n autoDeclared: true,\n });\n warnings.push(\n `Signal \"${clean}\" referenced in gate ${g.id} was not declared; auto-declared as input.`\n );\n }\n }\n }\n\n return {\n type: \"logic\",\n title,\n style: style ?? \"ansi\",\n inputs,\n outputs,\n gates,\n modules: modules.length > 0 ? modules : undefined,\n warnings: warnings.length > 0 ? warnings : undefined,\n };\n}\n","import type { LogicGateType } from \"../../core/types\";\n\n// Normalized gate geometry: combinational gates fit in 100×60; sequential in 60×80.\nexport interface GateGeometry {\n width: number;\n height: number;\n inputPins: Array<{ id: string; x: number; y: number; label?: string }>;\n outputPins: Array<{ id: string; x: number; y: number; label?: string; bubble?: boolean }>;\n /** Body SVG path (ANSI) */\n ansiPath: string;\n /** Output bubble? */\n outputBubble?: boolean;\n /** Clock triangle pin id (sequential) */\n clockPin?: string;\n /** IEC label inside rectangle */\n iecLabel?: string;\n}\n\nfunction combPins(nInputs: number, _width: number, leftX: number): Array<{ id: string; x: number; y: number }> {\n const pins: Array<{ id: string; x: number; y: number }> = [];\n if (nInputs === 1) {\n pins.push({ id: \"in1\", x: leftX, y: 30 });\n } else if (nInputs === 2) {\n pins.push({ id: \"in1\", x: leftX, y: 15 });\n pins.push({ id: \"in2\", x: leftX, y: 45 });\n } else {\n const step = 50 / (nInputs - 1);\n for (let i = 0; i < nInputs; i++) {\n pins.push({ id: `in${i + 1}`, x: leftX, y: 5 + step * i });\n }\n }\n return pins;\n}\n\nexport function getGateGeometry(\n gateType: LogicGateType,\n inputCount: number\n): GateGeometry {\n switch (gateType) {\n case \"AND\":\n case \"NAND\": {\n const bubble = gateType === \"NAND\";\n return {\n width: bubble ? 90 : 80,\n height: 60,\n inputPins: combPins(inputCount, 80, 20).map((p) => ({ ...p, x: 20 })),\n outputPins: [{ id: \"out\", x: bubble ? 90 : 80, y: 30, bubble }],\n ansiPath: \"M 20,60 L 20,0 Q 80,0 80,30 Q 80,60 20,60 Z\",\n outputBubble: bubble,\n iecLabel: \"&\",\n };\n }\n case \"OR\":\n case \"NOR\": {\n const bubble = gateType === \"NOR\";\n return {\n width: bubble ? 80 : 70,\n height: 60,\n inputPins: combPins(inputCount, 80, 18).map((p) => ({ ...p, x: 18 })),\n outputPins: [{ id: \"out\", x: bubble ? 80 : 70, y: 30, bubble }],\n ansiPath: \"M 15,60 Q 10,30 15,0 Q 30,15 70,30 Q 30,45 15,60 Z\",\n outputBubble: bubble,\n iecLabel: \"≥1\",\n };\n }\n case \"XOR\":\n case \"XNOR\": {\n const bubble = gateType === \"XNOR\";\n return {\n width: bubble ? 80 : 70,\n height: 60,\n inputPins: combPins(inputCount, 80, 12).map((p) => ({ ...p, x: 12 })),\n outputPins: [{ id: \"out\", x: bubble ? 80 : 70, y: 30, bubble }],\n ansiPath:\n \"M 15,60 Q 10,30 15,0 Q 30,15 70,30 Q 30,45 15,60 Z M 8,60 Q 3,30 8,0\",\n outputBubble: bubble,\n iecLabel: \"=1\",\n };\n }\n case \"NOT\": {\n return {\n width: 70,\n height: 60,\n inputPins: [{ id: \"in1\", x: 10, y: 30 }],\n outputPins: [{ id: \"out\", x: 70, y: 30, bubble: true }],\n ansiPath: \"M 10,55 L 60,30 L 10,5 Z\",\n outputBubble: true,\n iecLabel: \"1\",\n };\n }\n case \"BUF\":\n case \"SCHMITT\": {\n return {\n width: 60,\n height: 60,\n inputPins: [{ id: \"in1\", x: 10, y: 30 }],\n outputPins: [{ id: \"out\", x: 60, y: 30 }],\n ansiPath: \"M 10,55 L 60,30 L 10,5 Z\",\n iecLabel: \"1\",\n };\n }\n case \"TRISTATE_BUF\":\n case \"TRISTATE_INV\":\n case \"OPEN_DRAIN\": {\n const bubble = gateType === \"TRISTATE_INV\";\n return {\n width: bubble ? 70 : 60,\n height: 70,\n inputPins: [\n { id: \"in1\", x: 10, y: 30 },\n { id: \"en\", x: 35, y: 65, label: \"EN\" },\n ],\n outputPins: [{ id: \"out\", x: bubble ? 70 : 60, y: 30, bubble }],\n ansiPath: \"M 10,55 L 60,30 L 10,5 Z\",\n outputBubble: bubble,\n iecLabel: \"1\",\n };\n }\n case \"DFF\": {\n return {\n width: 60,\n height: 80,\n inputPins: [\n { id: \"D\", x: 0, y: 20, label: \"D\" },\n { id: \"CLK\", x: 0, y: 50, label: \"\" },\n ],\n outputPins: [\n { id: \"Q\", x: 60, y: 20, label: \"Q\" },\n { id: \"Qn\", x: 60, y: 60, label: \"Q̄\", bubble: true },\n ],\n ansiPath: \"M 0,0 H 60 V 80 H 0 Z\",\n clockPin: \"CLK\",\n iecLabel: \"DFF\",\n };\n }\n case \"JKFF\": {\n return {\n width: 60,\n height: 80,\n inputPins: [\n { id: \"J\", x: 0, y: 15, label: \"J\" },\n { id: \"CLK\", x: 0, y: 40 },\n { id: \"K\", x: 0, y: 65, label: \"K\" },\n ],\n outputPins: [\n { id: \"Q\", x: 60, y: 20, label: \"Q\" },\n { id: \"Qn\", x: 60, y: 60, label: \"Q̄\", bubble: true },\n ],\n ansiPath: \"M 0,0 H 60 V 80 H 0 Z\",\n clockPin: \"CLK\",\n iecLabel: \"JK\",\n };\n }\n case \"SRFF\":\n case \"LATCH_SR\": {\n return {\n width: 60,\n height: 80,\n inputPins: [\n { id: \"S\", x: 0, y: 20, label: \"S\" },\n { id: \"R\", x: 0, y: 60, label: \"R\" },\n ],\n outputPins: [\n { id: \"Q\", x: 60, y: 20, label: \"Q\" },\n { id: \"Qn\", x: 60, y: 60, label: \"Q̄\", bubble: true },\n ],\n ansiPath: \"M 0,0 H 60 V 80 H 0 Z\",\n iecLabel: \"SR\",\n };\n }\n case \"TFF\": {\n return {\n width: 60,\n height: 80,\n inputPins: [\n { id: \"T\", x: 0, y: 20, label: \"T\" },\n { id: \"CLK\", x: 0, y: 50 },\n ],\n outputPins: [\n { id: \"Q\", x: 60, y: 20, label: \"Q\" },\n { id: \"Qn\", x: 60, y: 60, label: \"Q̄\", bubble: true },\n ],\n ansiPath: \"M 0,0 H 60 V 80 H 0 Z\",\n clockPin: \"CLK\",\n iecLabel: \"T\",\n };\n }\n case \"LATCH_D\": {\n return {\n width: 60,\n height: 80,\n inputPins: [\n { id: \"D\", x: 0, y: 20, label: \"D\" },\n { id: \"E\", x: 0, y: 60, label: \"E\" },\n ],\n outputPins: [\n { id: \"Q\", x: 60, y: 20, label: \"Q\" },\n { id: \"Qn\", x: 60, y: 60, label: \"Q̄\", bubble: true },\n ],\n ansiPath: \"M 0,0 H 60 V 80 H 0 Z\",\n iecLabel: \"D\",\n };\n }\n case \"unknown\": {\n // Visibly-flagged placeholder for an unrecognised gate token. A box with\n // a \"?\" label — never a real gate shape, so it can't be mistaken for one.\n const ins = Math.max(inputCount, 1);\n const inputPins = combPins(ins, 90, 0).map((p) => ({ ...p, x: 0 }));\n return {\n width: 90,\n height: 70,\n inputPins,\n outputPins: [{ id: \"out\", x: 90, y: 35 }],\n ansiPath: \"M 0,0 H 90 V 70 H 0 Z\",\n iecLabel: \"?\",\n };\n }\n default: {\n // Generic box for MUX/DEMUX/DECODER/ENCODER/COUNTER/SHIFT_REG\n const ins = Math.max(inputCount, 2);\n const inputPins = combPins(ins, 100, 0).map((p, i) => ({\n ...p,\n x: 0,\n label: `I${i}`,\n }));\n return {\n width: 100,\n height: 80,\n inputPins,\n outputPins: [{ id: \"out\", x: 100, y: 40 }],\n ansiPath: \"M 0,0 H 100 V 80 H 0 Z\",\n iecLabel: gateType,\n };\n }\n }\n}\n","import type { LogicGateAST } from \"../../core/types\";\nimport { getGateGeometry, type GateGeometry } from \"./symbols\";\n\nexport interface LogicLayoutNode {\n id: string;\n kind: \"input\" | \"gate\" | \"output\";\n x: number;\n y: number;\n layer: number;\n geometry?: GateGeometry;\n gateType?: string;\n /** Original (unrecognised) gate token, set only when `gateType === \"unknown\"`. */\n rawType?: string;\n label: string;\n isActiveLow?: boolean;\n}\n\nexport interface LogicLayoutWire {\n fromNode: string;\n fromX: number;\n fromY: number;\n toNode: string;\n toX: number;\n toY: number;\n isActiveLow?: boolean;\n path: string;\n}\n\nexport interface LogicLayoutModule {\n id: string;\n label: string;\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport interface LogicLayoutResult {\n width: number;\n height: number;\n nodes: LogicLayoutNode[];\n wires: LogicLayoutWire[];\n modules: LogicLayoutModule[];\n}\n\nconst LAYER_GAP = 80; // extra horizontal gap between layers\nconst ROW_GAP = 40; // vertical gap between rows in same layer\nconst PORT_SIZE = 40; // input/output port pseudo-box width\nconst PORT_H = 30;\n\nexport function layoutLogic(ast: LogicGateAST): LogicLayoutResult {\n // Determine layer per signal id using longest-path layering\n const layerOf = new Map<string, number>();\n for (const inp of ast.inputs) layerOf.set(inp.id, 0);\n\n // Build dependency map for gates\n const pending = new Set(ast.gates.map((g) => g.id));\n let safety = 0;\n while (pending.size > 0 && safety++ < 1000) {\n for (const g of ast.gates) {\n if (!pending.has(g.id)) continue;\n let maxDep = -1;\n let ready = true;\n for (const inp of g.inputs) {\n const clean = inp.startsWith(\"~\") ? inp.slice(1) : inp;\n const l = layerOf.get(clean);\n if (l === undefined) {\n ready = false;\n break;\n }\n if (l > maxDep) maxDep = l;\n }\n if (ready) {\n layerOf.set(g.id, maxDep + 1);\n pending.delete(g.id);\n }\n }\n }\n if (pending.size > 0) {\n // cycle or unresolved: force layer 1\n for (const id of pending) layerOf.set(id, 1);\n }\n\n const outputLayer =\n Math.max(0, ...Array.from(layerOf.values())) + 1;\n // All outputs get a terminal label node. Use synthetic id to avoid colliding\n // with a gate that shares the output's name (e.g. `output Y; Y = AND(A,B)`).\n const outTermId = (o: { id: string }) => `$out$${o.id}`;\n const portOutputs = ast.outputs.map((o) => ({\n ...o,\n termId: outTermId(o),\n source: o.from,\n }));\n for (const o of portOutputs) layerOf.set(o.termId, outputLayer);\n\n // Group ids by layer\n const layers = new Map<number, string[]>();\n const addToLayer = (id: string, layer: number) => {\n if (!layers.has(layer)) layers.set(layer, []);\n layers.get(layer)!.push(id);\n };\n for (const i of ast.inputs) addToLayer(i.id, 0);\n for (const g of ast.gates) addToLayer(g.id, layerOf.get(g.id)!);\n for (const o of portOutputs) addToLayer(o.termId, outputLayer);\n\n // Compute sizes per node (precompute geometries for gates)\n const gateGeoms = new Map<string, GateGeometry>();\n for (const g of ast.gates) {\n gateGeoms.set(g.id, getGateGeometry(g.gateType, g.inputs.length));\n }\n\n // Assign coordinates\n const nodes: LogicLayoutNode[] = [];\n const sortedLayers = Array.from(layers.keys()).sort((a, b) => a - b);\n\n // compute each layer's widest node\n const layerWidth = new Map<number, number>();\n for (const [layerIdx, ids] of layers) {\n let maxW = 60;\n for (const id of ids) {\n const g = gateGeoms.get(id);\n if (g && g.width > maxW) maxW = g.width;\n if (!g && layerIdx === 0) maxW = Math.max(maxW, PORT_SIZE);\n if (!g && layerIdx === outputLayer) maxW = Math.max(maxW, PORT_SIZE);\n }\n layerWidth.set(layerIdx, maxW);\n }\n\n let cursorX = 20;\n const layerStartMap = new Map<number, number>();\n for (const layerIdx of sortedLayers) {\n layerStartMap.set(layerIdx, cursorX);\n cursorX += (layerWidth.get(layerIdx) ?? 60) + LAYER_GAP;\n }\n const totalW = cursorX;\n\n // Compute vertical placement per layer\n const heightOf = (id: string): number => {\n const g = gateGeoms.get(id);\n if (g) return g.height;\n return PORT_H;\n };\n\n // find max column height\n let maxColH = 0;\n for (const ids of layers.values()) {\n const total = ids.reduce((s, id) => s + heightOf(id), 0) + (ids.length - 1) * ROW_GAP;\n if (total > maxColH) maxColH = total;\n }\n const totalH = maxColH + 80;\n\n const nodeInfo = new Map<string, LogicLayoutNode>();\n for (const [layerIdx, ids] of layers) {\n const xStart = layerStartMap.get(layerIdx)!;\n const total = ids.reduce((s, id) => s + heightOf(id), 0) + (ids.length - 1) * ROW_GAP;\n let y = 40 + (maxColH - total) / 2;\n for (const id of ids) {\n const h = heightOf(id);\n const g = gateGeoms.get(id);\n let node: LogicLayoutNode;\n if (layerIdx === 0) {\n const inp = ast.inputs.find((i) => i.id === id)!;\n node = {\n id,\n kind: \"input\",\n x: xStart,\n y,\n layer: 0,\n label: inp.label,\n isActiveLow: inp.isActiveLow,\n };\n } else if (layerIdx === outputLayer && !g && id.startsWith(\"$out$\")) {\n const out = portOutputs.find((o) => o.termId === id)!;\n node = {\n id,\n kind: \"output\",\n x: xStart,\n y,\n layer: outputLayer,\n label: out.label,\n isActiveLow: out.isActiveLow,\n };\n } else {\n node = {\n id,\n kind: \"gate\",\n x: xStart,\n y,\n layer: layerIdx,\n geometry: g,\n gateType: ast.gates.find((gg) => gg.id === id)!.gateType,\n rawType: ast.gates.find((gg) => gg.id === id)!.rawType,\n label: id,\n };\n }\n nodes.push(node);\n nodeInfo.set(id, node);\n y += h + ROW_GAP;\n }\n }\n\n // Wires\n const wires: LogicLayoutWire[] = [];\n const getSourcePoint = (id: string) => {\n const n = nodeInfo.get(id);\n if (!n) return null;\n if (n.kind === \"input\") return { x: n.x + PORT_SIZE, y: n.y + PORT_H / 2 };\n if (n.kind === \"gate\" && n.geometry) {\n const out = n.geometry.outputPins[0];\n return { x: n.x + out.x, y: n.y + out.y };\n }\n return null;\n };\n\n for (const g of ast.gates) {\n const target = nodeInfo.get(g.id);\n if (!target || !target.geometry) continue;\n g.inputs.forEach((rawInp, idx) => {\n const isLow = rawInp.startsWith(\"~\");\n const srcId = isLow ? rawInp.slice(1) : rawInp;\n const src = getSourcePoint(srcId);\n if (!src) return;\n const pin = target.geometry!.inputPins[idx];\n if (!pin) return;\n const toX = target.x + pin.x;\n const toY = target.y + pin.y;\n const midX = (src.x + toX) / 2;\n const path = `M ${src.x},${src.y} L ${midX},${src.y} L ${midX},${toY} L ${toX},${toY}`;\n wires.push({\n fromNode: srcId,\n fromX: src.x,\n fromY: src.y,\n toNode: g.id,\n toX,\n toY,\n isActiveLow: isLow,\n path,\n });\n });\n }\n\n // Output port wires\n for (const o of portOutputs) {\n const src = getSourcePoint(o.source);\n const target = nodeInfo.get(o.termId);\n if (!src || !target || target.kind !== \"output\") continue;\n const toX = target.x;\n const toY = target.y + PORT_H / 2;\n let path: string;\n if (Math.abs(src.y - toY) < 0.5) {\n path = `M ${src.x},${src.y} L ${toX},${toY}`;\n } else {\n const midX = (src.x + toX) / 2;\n path = `M ${src.x},${src.y} L ${midX},${src.y} L ${midX},${toY} L ${toX},${toY}`;\n }\n wires.push({\n fromNode: o.source,\n fromX: src.x,\n fromY: src.y,\n toNode: o.termId,\n toX,\n toY,\n path,\n });\n }\n\n // Module bounding boxes (dashed enclosure for sub-circuits)\n const modules: LogicLayoutModule[] = [];\n if (ast.modules && ast.modules.length > 0) {\n const PAD = 14;\n for (const mod of ast.modules) {\n const memberIds = new Set(\n ast.gates.filter((g) => g.moduleId === mod.id).map((g) => g.id)\n );\n if (memberIds.size === 0) continue;\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const n of nodes) {\n if (!memberIds.has(n.id)) continue;\n const w = n.geometry?.width ?? 60;\n const h = n.geometry?.height ?? 60;\n if (n.x < minX) minX = n.x;\n if (n.y < minY) minY = n.y;\n if (n.x + w > maxX) maxX = n.x + w;\n if (n.y + h > maxY) maxY = n.y + h;\n }\n if (!isFinite(minX)) continue;\n modules.push({\n id: mod.id,\n label: mod.label,\n x: minX - PAD,\n y: minY - PAD - 4,\n width: maxX - minX + PAD * 2,\n height: maxY - minY + PAD * 2 + 4,\n });\n }\n }\n\n return { width: totalW, height: totalH, nodes, wires, modules };\n}\n","import type { LogicGateAST, LogicGateStyle, RenderConfig } from \"../../core/types\";\nimport { layoutLogic } from \"./layout\";\nimport {\n svgRoot,\n defs,\n group,\n el,\n circle,\n path as pathEl,\n text,\n title as titleEl,\n desc,\n polygon,\n} from \"../../core/svg\";\nimport { resolveIndustrialTheme } from \"../../core/theme\";\n\nconst PORT_SIZE = 40;\nconst PORT_H = 30;\n\nfunction renderGateBody(\n n: ReturnType<typeof layoutLogic>[\"nodes\"][number],\n style: LogicGateStyle\n): string[] {\n const out: string[] = [];\n if (!n.geometry) return out;\n const g = n.geometry;\n\n if (style === \"iec\") {\n // Rectangle\n out.push(\n el(\"rect\", {\n x: 0,\n y: 0,\n width: g.width,\n height: g.height,\n class: \"schematex-logic-gate-body\",\n })\n );\n if (g.iecLabel) {\n out.push(\n text(\n {\n x: g.width / 2,\n y: g.height / 2 + 4,\n class: \"schematex-logic-gate-iec-label\",\n \"text-anchor\": \"middle\",\n },\n g.iecLabel\n )\n );\n }\n } else {\n out.push(\n el(\"path\", { d: g.ansiPath, class: \"schematex-logic-gate-body\" })\n );\n }\n\n // Unrecognised gate: stamp a centred \"?\" so the ANSI box reads as a flagged\n // placeholder (IEC already centres the \"?\" via iecLabel above).\n if (n.gateType === \"unknown\" && style !== \"iec\") {\n out.push(\n text(\n {\n x: g.width / 2,\n y: g.height / 2 + 6,\n class: \"schematex-logic-gate-iec-label\",\n \"text-anchor\": \"middle\",\n },\n \"?\"\n )\n );\n }\n\n // Output bubble\n if (g.outputBubble) {\n const op = g.outputPins[0];\n out.push(\n circle({\n cx: op.x - 4,\n cy: op.y,\n r: 4,\n class: \"schematex-logic-bubble\",\n })\n );\n }\n\n // Clock triangle\n if (g.clockPin) {\n const cp = g.inputPins.find((p) => p.id === g.clockPin);\n if (cp) {\n out.push(\n polygon({\n points: `${cp.x},${cp.y - 5} ${cp.x + 8},${cp.y} ${cp.x},${cp.y + 5}`,\n class: \"schematex-logic-clock-tri\",\n })\n );\n }\n }\n\n // Qn bubble (sequential)\n for (const op of g.outputPins) {\n if (op.bubble && op.id !== \"out\") {\n out.push(\n circle({\n cx: op.x + 4,\n cy: op.y,\n r: 4,\n class: \"schematex-logic-bubble\",\n })\n );\n }\n }\n\n // Pin labels\n for (const pin of g.inputPins) {\n if (pin.label && pin.id !== g.clockPin) {\n out.push(\n text(\n {\n x: pin.x + 5,\n y: pin.y + 3,\n class: \"schematex-logic-pin-label\",\n },\n pin.label\n )\n );\n }\n }\n for (const pin of g.outputPins) {\n if (pin.label) {\n out.push(\n text(\n {\n x: pin.x - 6,\n y: pin.y + 3,\n class: \"schematex-logic-pin-label\",\n \"text-anchor\": \"end\",\n },\n pin.label\n )\n );\n }\n }\n\n // Gate type label (center top, small)\n if (style === \"ansi\" && g.iecLabel && g.height >= 60) {\n const labelX = g.width / 2;\n const labelY = g.height + 14;\n out.push(\n text(\n {\n x: labelX,\n y: labelY,\n class: \"schematex-logic-gate-type\",\n \"text-anchor\": \"middle\",\n },\n n.gateType === \"unknown\" ? n.rawType ?? \"?\" : n.gateType ?? \"\"\n )\n );\n }\n\n return out;\n}\n\nexport function renderLogic(ast: LogicGateAST, config?: RenderConfig): string {\n const style: LogicGateStyle = ast.style ?? \"ansi\";\n const layout = layoutLogic(ast);\n const { width, height } = layout;\n const t = resolveIndustrialTheme(config?.theme ?? \"default\");\n\n const gateSvgs: string[] = [];\n const portSvgs: string[] = [];\n const moduleSvgs: string[] = [];\n\n for (const m of layout.modules) {\n moduleSvgs.push(\n group({ \"data-module-id\": m.id }, [\n el(\"rect\", {\n x: m.x,\n y: m.y,\n width: m.width,\n height: m.height,\n rx: 6,\n class: \"schematex-logic-module\",\n }),\n text(\n {\n x: m.x + 10,\n y: m.y + 14,\n class: \"schematex-logic-module-label\",\n },\n m.label\n ),\n ])\n );\n }\n\n for (const n of layout.nodes) {\n if (n.kind === \"gate\") {\n gateSvgs.push(\n group(\n {\n transform: `translate(${n.x}, ${n.y})`,\n \"data-gate-id\": n.id,\n \"data-gate-type\": n.gateType ?? \"\",\n },\n renderGateBody(n, style)\n )\n );\n } else if (n.kind === \"input\") {\n // Label + short stub line; no rectangle.\n const cy = PORT_H / 2;\n portSvgs.push(\n group({ transform: `translate(${n.x}, ${n.y})`, \"data-port\": \"input\" }, [\n text(\n {\n x: 0,\n y: cy + 4,\n \"text-anchor\": \"start\",\n class: \"schematex-logic-port-label\",\n },\n n.label\n ),\n el(\"line\", {\n x1: PORT_SIZE - 12,\n y1: cy,\n x2: n.isActiveLow ? PORT_SIZE - 8 : PORT_SIZE,\n y2: cy,\n class: \"schematex-logic-wire\",\n }),\n n.isActiveLow\n ? circle({\n cx: PORT_SIZE - 4,\n cy,\n r: 4,\n class: \"schematex-logic-bubble\",\n })\n : \"\",\n ])\n );\n } else if (n.kind === \"output\") {\n const cy = PORT_H / 2;\n portSvgs.push(\n group({ transform: `translate(${n.x}, ${n.y})`, \"data-port\": \"output\" }, [\n el(\"line\", {\n x1: 0,\n y1: cy,\n x2: 12,\n y2: cy,\n class: \"schematex-logic-wire\",\n }),\n text(\n {\n x: 16,\n y: cy + 4,\n \"text-anchor\": \"start\",\n class: \"schematex-logic-port-label\",\n },\n n.label\n ),\n ])\n );\n }\n }\n\n const wireSvgs = layout.wires.map((w) => {\n const extras: string[] = [];\n if (w.isActiveLow) {\n extras.push(\n circle({\n cx: w.toX - 4,\n cy: w.toY,\n r: 4,\n class: \"schematex-logic-bubble\",\n })\n );\n }\n return [\n pathEl({\n d: w.path,\n class: \"schematex-logic-wire\",\n \"data-from\": w.fromNode,\n \"data-to\": w.toNode,\n }),\n ...extras,\n ].join(\"\");\n });\n\n const css = `\n.schematex-logic { font-family: system-ui, -apple-system, sans-serif; }\n.schematex-logic-gate-body { fill: none; stroke: ${t.strokeHeavy}; stroke-width: 1.75; stroke-linejoin: round; }\n.schematex-logic-bubble { fill: ${t.bg}; stroke: ${t.strokeHeavy}; stroke-width: 1.5; }\n.schematex-logic-clock-tri { fill: none; stroke: ${t.strokeHeavy}; stroke-width: 1.5; stroke-linejoin: round; }\n.schematex-logic-wire { stroke: ${t.strokeHeavy}; stroke-width: 1.5; fill: none; stroke-linecap: square; }\n.schematex-logic-port-label { font: 13px system-ui, sans-serif; fill: ${t.text}; }\n.schematex-logic-pin-label { font: 9px sans-serif; fill: ${t.stroke}; }\n.schematex-logic-gate-type { font: 10px sans-serif; fill: ${t.textMuted}; }\n.schematex-logic-gate-iec-label { font: bold 13px sans-serif; fill: ${t.text}; }\n.schematex-logic-title { font: bold 14px sans-serif; fill: ${t.text}; }\n.schematex-logic-module { fill: none; stroke: ${t.textMuted}; stroke-width: 1.25; stroke-dasharray: 6 4; }\n.schematex-logic-module-label { font: 11px sans-serif; fill: ${t.textMuted}; font-style: italic; }\n[data-gate-type=\"unknown\"] .schematex-logic-gate-body { stroke: ${t.accent}; stroke-dasharray: 5 3; }\n[data-gate-type=\"unknown\"] .schematex-logic-gate-iec-label { fill: ${t.accent}; }\n`.trim();\n\n const titleSvg = ast.title\n ? text(\n {\n x: width / 2,\n y: 18,\n \"text-anchor\": \"middle\",\n class: \"schematex-logic-title\",\n },\n ast.title\n )\n : \"\";\n\n return svgRoot(\n {\n class: \"schematex-logic\",\n viewBox: `0 0 ${width} ${height + (ast.title ? 20 : 0)}`,\n width,\n height: height + (ast.title ? 20 : 0),\n role: \"img\",\n \"data-diagram-type\": \"logic\",\n },\n [\n titleEl(ast.title ?? \"Logic Gate Diagram\"),\n desc(\n `Logic gate diagram with ${ast.gates.length} gates, ${ast.inputs.length} inputs, ${ast.outputs.length} outputs`\n ),\n defs([el(\"style\", {}, css)]),\n group(\n { transform: `translate(0, ${ast.title ? 20 : 0})` },\n [\n group({ class: \"schematex-logic-modules\" }, moduleSvgs),\n group({ class: \"schematex-logic-wires\" }, wireSvgs),\n group({ class: \"schematex-logic-gates\" }, gateSvgs),\n group({ class: \"schematex-logic-ports\" }, portSvgs),\n ]\n ),\n titleSvg,\n ]\n );\n}\n","import type { SchematexDiagnostic } from \"../../core/diagnostics\";\nimport type { LogicGateAST } from \"../../core/types\";\nimport { didYouMean } from \"../../core/dsl-suggest\";\nimport { parseLogic } from \"./parser\";\n\n// Canonical gate vocabulary for the did-you-mean suggestion on an unknown gate.\n// Kept in sync with GATE_TYPES in the parser.\nconst KNOWN_GATES = [\n \"AND\", \"OR\", \"NOT\", \"NAND\", \"NOR\", \"XOR\", \"XNOR\", \"BUF\",\n \"TRISTATE_BUF\", \"TRISTATE_INV\", \"OPEN_DRAIN\", \"SCHMITT\",\n \"DFF\", \"JKFF\", \"SRFF\", \"TFF\", \"LATCH_SR\", \"LATCH_D\",\n \"MUX\", \"DEMUX\", \"DECODER\", \"ENCODER\", \"COUNTER\", \"SHIFT_REG\",\n];\n\nexport function lintLogic(text: string): SchematexDiagnostic[] {\n let ast: LogicGateAST;\n try {\n ast = parseLogic(text);\n } catch {\n // Parse failures are reported by the normal error path; lint stays silent.\n return [];\n }\n return lintLogicAst(ast);\n}\n\nexport function lintLogicAst(ast: LogicGateAST): SchematexDiagnostic[] {\n const out: SchematexDiagnostic[] = [];\n // Unrecognised gate types are kept (drawn as a flagged placeholder) but\n // warned about so the partial render is analyzable and the engineer gets a\n // did-you-mean nudge. The engine never silently substitutes a real gate.\n for (const g of ast.gates) {\n if (g.gateType !== \"unknown\") continue;\n const raw = g.rawType ?? \"\";\n out.push({\n severity: \"warning\",\n code: \"LOGIC_UNKNOWN_GATE\",\n message: `gate \"${g.id}\" has unrecognised type \"${raw}\"; drawn as a flagged placeholder`,\n hint: `\"${raw}\" is not a known logic gate.${didYouMean(raw.toUpperCase(), KNOWN_GATES)} Valid gates include AND, OR, NOT, NAND, NOR, XOR, DFF, MUX. See docs/reference.`,\n fatal: false,\n });\n }\n return out;\n}\n","import type { DiagramPlugin } from \"../../core/types\";\nimport { parseLogic } from \"./parser\";\nimport { renderLogic } from \"./renderer\";\nimport { lintLogic } from \"./lint\";\n\nexport const logic: DiagramPlugin = {\n type: \"logic\",\n detect(text: string): boolean {\n const first = text.trim().split(\"\\n\")[0]?.trim().toLowerCase() ?? \"\";\n return first.startsWith(\"logic\");\n },\n parse: parseLogic,\n lint: lintLogic,\n\n render(text: string, config): string {\n const ast = parseLogic(text);\n return renderLogic(ast, config);\n },\n};\n\nexport { parseLogic } from \"./parser\";\nexport { renderLogic } from \"./renderer\";\nexport { layoutLogic } from \"./layout\";\nexport { lintLogic, lintLogicAst } from \"./lint\";\n"]}
1
+ {"version":3,"sources":["../src/diagrams/logic/parser.ts","../src/diagrams/logic/symbols.ts","../src/diagrams/logic/layout.ts","../src/diagrams/logic/renderer.ts","../src/diagrams/logic/lint.ts","../src/diagrams/logic/index.ts"],"names":["text","title","path","PORT_SIZE","PORT_H"],"mappings":";;;;;;AAWO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA,EACzC,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,iBAAA;AAAA,EACd;AACF,CAAA;AAEA,IAAM,UAAA,uBAAiB,GAAA,CAAY;AAAA,EACjC,KAAA;AAAA,EAAO,IAAA;AAAA,EAAM,KAAA;AAAA,EAAO,MAAA;AAAA,EAAQ,KAAA;AAAA,EAAO,KAAA;AAAA,EAAO,MAAA;AAAA,EAAQ,KAAA;AAAA,EAClD,cAAA;AAAA,EAAgB,cAAA;AAAA,EAAgB,YAAA;AAAA,EAAc,SAAA;AAAA,EAC9C,KAAA;AAAA,EAAO,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,KAAA;AAAA,EAAO,UAAA;AAAA,EAAY,SAAA;AAAA,EAC1C,KAAA;AAAA,EAAO,OAAA;AAAA,EAAS,SAAA;AAAA,EAAW,SAAA;AAAA,EAAW,SAAA;AAAA,EAAW;AACnD,CAAC,CAAA;AAED,SAAS,SAAS,CAAA,EAAqB;AACrC,EAAA,OAAO,CAAA,CACJ,KAAA,CAAM,GAAG,CAAA,CACT,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,IAAA,EAAM,CAAA,CACnB,MAAA,CAAO,OAAO,CAAA;AACnB;AAEA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icGateStyle,\n LogicGateModule,\n} from \"../../core/types\";\nimport { matchQuotedTitle } from \"../../core/quotes\";\n\nexport class LogicParseError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"LogicParseError\";\n }\n}\n\nconst GATE_TYPES = new Set<string>([\n \"AND\", \"OR\", \"NOT\", \"NAND\", \"NOR\", \"XOR\", \"XNOR\", \"BUF\",\n \"TRISTATE_BUF\", \"TRISTATE_INV\", \"OPEN_DRAIN\", \"SCHMITT\",\n \"DFF\", \"JKFF\", \"SRFF\", \"TFF\", \"LATCH_SR\", \"LATCH_D\",\n \"MUX\", \"DEMUX\", \"DECODER\", \"ENCODER\", \"COUNTER\", \"SHIFT_REG\",\n]);\n\nfunction splitIds(s: string): string[] {\n return s\n .split(\",\")\n .map((x) => x.trim())\n .filter(Boolean);\n}\n\nfunction parseInputList(s: string): string[] {\n // Supports named (D=A) or positional. Returns raw tokens (keep ~ prefix for active-low).\n return s\n .split(\",\")\n .map((x) => x.trim())\n .filter(Boolean)\n .map((tok) => {\n const eq = tok.indexOf(\"=\");\n return eq >= 0 ? tok.slice(eq + 1).trim() : tok;\n });\n}\n\nexport function parseLogic(text: string): LogicGateAST {\n const lines = text.split(\"\\n\").map((l) => l.replace(/\\r$/, \"\").trim());\n let title: string | undefined;\n let style: LogicGateStyle | undefined;\n const inputs: LogicGateInput[] = [];\n const outputs: LogicGateOutput[] = [];\n const gates: LogicGateNode[] = [];\n const modules: LogicGateModule[] = [];\n const moduleStack: string[] = [];\n let moduleCounter = 0;\n const explicitOutputFrom = new Map<string, string>();\n const warnings: string[] = [];\n\n for (const rawLine of lines) {\n // Strip line comments\n const line = rawLine.replace(/#.*$/, \"\").replace(/--.*$/, \"\").trim();\n if (!line) continue;\n\n // module \"Label\" { or module Label {\n const modOpen = line.match(/^module\\s+(?:\"([^\"]+)\"|([a-zA-Z_][\\w]*))\\s*\\{$/);\n if (modOpen) {\n const label = modOpen[1] ?? modOpen[2];\n const id = `mod_${moduleCounter++}`;\n modules.push({ id, label });\n moduleStack.push(id);\n continue;\n }\n\n // close module\n if (line === \"}\") {\n if (moduleStack.length === 0) {\n throw new LogicParseError(\"Unmatched `}` — no open module\");\n }\n moduleStack.pop();\n continue;\n }\n\n // Header\n if (/^logic\\b/i.test(line)) {\n const t = matchQuotedTitle(line);\n if (t !== undefined) title = t;\n const s = line.match(/style\\s*:\\s*(ansi|iec)/i);\n if (s) style = s[1].toLowerCase() as LogicGateStyle;\n continue;\n }\n\n // input A, B, C\n const inputMatch = line.match(/^input\\s+(.+)$/i);\n if (inputMatch) {\n for (const id of splitIds(inputMatch[1])) {\n const isLow = id.startsWith(\"~\");\n const clean = isLow ? id.slice(1) : id;\n inputs.push({ id: clean, label: clean, isActiveLow: isLow || undefined });\n }\n continue;\n }\n\n // output X, Y\n const outputMatch = line.match(/^output\\s+(.+)$/i);\n if (outputMatch) {\n for (const id of splitIds(outputMatch[1])) {\n outputs.push({ id, label: id, from: id });\n }\n continue;\n }\n\n // OUTPUT <- GATE (map output to gate)\n const assignMatch = line.match(/^([a-zA-Z_][\\w]*)\\s*<-\\s*([a-zA-Z_][\\w]*)$/);\n if (assignMatch) {\n explicitOutputFrom.set(assignMatch[1], assignMatch[2]);\n continue;\n }\n\n // Gate: ID = GATE(a, b, ...)\n const gateMatch = line.match(/^([a-zA-Z_][\\w]*)\\s*=\\s*([A-Za-z_][\\w]*)\\s*\\(([^)]*)\\)$/);\n if (gateMatch) {\n const id = gateMatch[1];\n const rawType = gateMatch[2].toUpperCase();\n const gInputs = parseInputList(gateMatch[3]);\n const moduleId = moduleStack[moduleStack.length - 1];\n // Graceful degradation: an unrecognised gate is NOT fatal. Keep it with\n // the `unknown` sentinel + the raw token so the renderer draws a flagged\n // placeholder and the lint pass warns. Blanking the whole diagram on one\n // bad gate word is hostile to LLM-generated DSL.\n if (GATE_TYPES.has(rawType)) {\n gates.push({ id, gateType: rawType as LogicGateType, inputs: gInputs, moduleId });\n } else {\n gates.push({ id, gateType: \"unknown\", rawType: gateMatch[2], inputs: gInputs, moduleId });\n warnings.push(\n `Gate \"${id}\" has unrecognised type \"${gateMatch[2]}\"; drawn as a flagged placeholder.`\n );\n }\n continue;\n }\n }\n\n if (moduleStack.length > 0) {\n throw new LogicParseError(`Unclosed module (${moduleStack.length} open)`);\n }\n\n // Wire outputs: if output not explicitly mapped, look for gate with same id\n for (const out of outputs) {\n const mapped = explicitOutputFrom.get(out.id);\n if (mapped) out.from = mapped;\n else if (gates.some((g) => g.id === out.id)) out.from = out.id;\n }\n\n // Resolve undefined signal references: auto-declare them as inputs and\n // emit a warning. Hard-failing here is hostile to LLM-generated DSL where\n // the model often forgets the explicit `input` line — see playbook.\n const known = new Set<string>([\n ...inputs.map((i) => i.id),\n ...gates.map((g) => g.id),\n ]);\n const autoDeclared = new Set<string>();\n for (const g of gates) {\n for (const inp of g.inputs) {\n const isLow = inp.startsWith(\"~\");\n const clean = isLow ? inp.slice(1) : inp;\n if (!known.has(clean) && !autoDeclared.has(clean)) {\n autoDeclared.add(clean);\n inputs.push({\n id: clean,\n label: clean,\n isActiveLow: isLow || undefined,\n autoDeclared: true,\n });\n warnings.push(\n `Signal \"${clean}\" referenced in gate ${g.id} was not declared; auto-declared as input.`\n );\n }\n }\n }\n\n return {\n type: \"logic\",\n title,\n style: style ?? \"ansi\",\n inputs,\n outputs,\n gates,\n modules: modules.length > 0 ? modules : undefined,\n warnings: warnings.length > 0 ? warnings : undefined,\n };\n}\n","import type { LogicGateType } from \"../../core/types\";\n\n// Normalized gate geometry: combinational gates fit in 100×60; sequential in 60×80.\nexport interface GateGeometry {\n width: number;\n height: number;\n inputPins: Array<{ id: string; x: number; y: number; label?: string }>;\n outputPins: Array<{ id: string; x: number; y: number; label?: string; bubble?: boolean }>;\n /** Body SVG path (ANSI) */\n ansiPath: string;\n /** Output bubble? */\n outputBubble?: boolean;\n /** Clock triangle pin id (sequential) */\n clockPin?: string;\n /** IEC label inside rectangle */\n iecLabel?: string;\n}\n\nfunction combPins(nInputs: number, _width: number, leftX: number): Array<{ id: string; x: number; y: number }> {\n const pins: Array<{ id: string; x: number; y: number }> = [];\n if (nInputs === 1) {\n pins.push({ id: \"in1\", x: leftX, y: 30 });\n } else if (nInputs === 2) {\n pins.push({ id: \"in1\", x: leftX, y: 15 });\n pins.push({ id: \"in2\", x: leftX, y: 45 });\n } else {\n const step = 50 / (nInputs - 1);\n for (let i = 0; i < nInputs; i++) {\n pins.push({ id: `in${i + 1}`, x: leftX, y: 5 + step * i });\n }\n }\n return pins;\n}\n\nexport function getGateGeometry(\n gateType: LogicGateType,\n inputCount: number\n): GateGeometry {\n switch (gateType) {\n case \"AND\":\n case \"NAND\": {\n const bubble = gateType === \"NAND\";\n return {\n width: bubble ? 90 : 80,\n height: 60,\n inputPins: combPins(inputCount, 80, 20).map((p) => ({ ...p, x: 20 })),\n outputPins: [{ id: \"out\", x: bubble ? 90 : 80, y: 30, bubble }],\n ansiPath: \"M 20,60 L 20,0 Q 80,0 80,30 Q 80,60 20,60 Z\",\n outputBubble: bubble,\n iecLabel: \"&\",\n };\n }\n case \"OR\":\n case \"NOR\": {\n const bubble = gateType === \"NOR\";\n return {\n width: bubble ? 80 : 70,\n height: 60,\n inputPins: combPins(inputCount, 80, 18).map((p) => ({ ...p, x: 18 })),\n outputPins: [{ id: \"out\", x: bubble ? 80 : 70, y: 30, bubble }],\n ansiPath: \"M 15,60 Q 10,30 15,0 Q 30,15 70,30 Q 30,45 15,60 Z\",\n outputBubble: bubble,\n iecLabel: \"≥1\",\n };\n }\n case \"XOR\":\n case \"XNOR\": {\n const bubble = gateType === \"XNOR\";\n return {\n width: bubble ? 80 : 70,\n height: 60,\n inputPins: combPins(inputCount, 80, 12).map((p) => ({ ...p, x: 12 })),\n outputPins: [{ id: \"out\", x: bubble ? 80 : 70, y: 30, bubble }],\n ansiPath:\n \"M 15,60 Q 10,30 15,0 Q 30,15 70,30 Q 30,45 15,60 Z M 8,60 Q 3,30 8,0\",\n outputBubble: bubble,\n iecLabel: \"=1\",\n };\n }\n case \"NOT\": {\n return {\n width: 70,\n height: 60,\n inputPins: [{ id: \"in1\", x: 10, y: 30 }],\n outputPins: [{ id: \"out\", x: 70, y: 30, bubble: true }],\n ansiPath: \"M 10,55 L 60,30 L 10,5 Z\",\n outputBubble: true,\n iecLabel: \"1\",\n };\n }\n case \"BUF\":\n case \"SCHMITT\": {\n return {\n width: 60,\n height: 60,\n inputPins: [{ id: \"in1\", x: 10, y: 30 }],\n outputPins: [{ id: \"out\", x: 60, y: 30 }],\n ansiPath: \"M 10,55 L 60,30 L 10,5 Z\",\n iecLabel: \"1\",\n };\n }\n case \"TRISTATE_BUF\":\n case \"TRISTATE_INV\":\n case \"OPEN_DRAIN\": {\n const bubble = gateType === \"TRISTATE_INV\";\n return {\n width: bubble ? 70 : 60,\n height: 70,\n inputPins: [\n { id: \"in1\", x: 10, y: 30 },\n { id: \"en\", x: 35, y: 65, label: \"EN\" },\n ],\n outputPins: [{ id: \"out\", x: bubble ? 70 : 60, y: 30, bubble }],\n ansiPath: \"M 10,55 L 60,30 L 10,5 Z\",\n outputBubble: bubble,\n iecLabel: \"1\",\n };\n }\n case \"DFF\": {\n return {\n width: 60,\n height: 80,\n inputPins: [\n { id: \"D\", x: 0, y: 20, label: \"D\" },\n { id: \"CLK\", x: 0, y: 50, label: \"\" },\n ],\n outputPins: [\n { id: \"Q\", x: 60, y: 20, label: \"Q\" },\n { id: \"Qn\", x: 60, y: 60, label: \"Q̄\", bubble: true },\n ],\n ansiPath: \"M 0,0 H 60 V 80 H 0 Z\",\n clockPin: \"CLK\",\n iecLabel: \"DFF\",\n };\n }\n case \"JKFF\": {\n return {\n width: 60,\n height: 80,\n inputPins: [\n { id: \"J\", x: 0, y: 15, label: \"J\" },\n { id: \"CLK\", x: 0, y: 40 },\n { id: \"K\", x: 0, y: 65, label: \"K\" },\n ],\n outputPins: [\n { id: \"Q\", x: 60, y: 20, label: \"Q\" },\n { id: \"Qn\", x: 60, y: 60, label: \"Q̄\", bubble: true },\n ],\n ansiPath: \"M 0,0 H 60 V 80 H 0 Z\",\n clockPin: \"CLK\",\n iecLabel: \"JK\",\n };\n }\n case \"SRFF\":\n case \"LATCH_SR\": {\n return {\n width: 60,\n height: 80,\n inputPins: [\n { id: \"S\", x: 0, y: 20, label: \"S\" },\n { id: \"R\", x: 0, y: 60, label: \"R\" },\n ],\n outputPins: [\n { id: \"Q\", x: 60, y: 20, label: \"Q\" },\n { id: \"Qn\", x: 60, y: 60, label: \"Q̄\", bubble: true },\n ],\n ansiPath: \"M 0,0 H 60 V 80 H 0 Z\",\n iecLabel: \"SR\",\n };\n }\n case \"TFF\": {\n return {\n width: 60,\n height: 80,\n inputPins: [\n { id: \"T\", x: 0, y: 20, label: \"T\" },\n { id: \"CLK\", x: 0, y: 50 },\n ],\n outputPins: [\n { id: \"Q\", x: 60, y: 20, label: \"Q\" },\n { id: \"Qn\", x: 60, y: 60, label: \"Q̄\", bubble: true },\n ],\n ansiPath: \"M 0,0 H 60 V 80 H 0 Z\",\n clockPin: \"CLK\",\n iecLabel: \"T\",\n };\n }\n case \"LATCH_D\": {\n return {\n width: 60,\n height: 80,\n inputPins: [\n { id: \"D\", x: 0, y: 20, label: \"D\" },\n { id: \"E\", x: 0, y: 60, label: \"E\" },\n ],\n outputPins: [\n { id: \"Q\", x: 60, y: 20, label: \"Q\" },\n { id: \"Qn\", x: 60, y: 60, label: \"Q̄\", bubble: true },\n ],\n ansiPath: \"M 0,0 H 60 V 80 H 0 Z\",\n iecLabel: \"D\",\n };\n }\n case \"unknown\": {\n // Visibly-flagged placeholder for an unrecognised gate token. A box with\n // a \"?\" label — never a real gate shape, so it can't be mistaken for one.\n const ins = Math.max(inputCount, 1);\n const inputPins = combPins(ins, 90, 0).map((p) => ({ ...p, x: 0 }));\n return {\n width: 90,\n height: 70,\n inputPins,\n outputPins: [{ id: \"out\", x: 90, y: 35 }],\n ansiPath: \"M 0,0 H 90 V 70 H 0 Z\",\n iecLabel: \"?\",\n };\n }\n default: {\n // Generic box for MUX/DEMUX/DECODER/ENCODER/COUNTER/SHIFT_REG\n const ins = Math.max(inputCount, 2);\n const inputPins = combPins(ins, 100, 0).map((p, i) => ({\n ...p,\n x: 0,\n label: `I${i}`,\n }));\n return {\n width: 100,\n height: 80,\n inputPins,\n outputPins: [{ id: \"out\", x: 100, y: 40 }],\n ansiPath: \"M 0,0 H 100 V 80 H 0 Z\",\n iecLabel: gateType,\n };\n }\n }\n}\n","import type { LogicGateAST } from \"../../core/types\";\nimport { getGateGeometry, type GateGeometry } from \"./symbols\";\n\nexport interface LogicLayoutNode {\n id: string;\n kind: \"input\" | \"gate\" | \"output\";\n x: number;\n y: number;\n layer: number;\n geometry?: GateGeometry;\n gateType?: string;\n /** Original (unrecognised) gate token, set only when `gateType === \"unknown\"`. */\n rawType?: string;\n label: string;\n isActiveLow?: boolean;\n}\n\nexport interface LogicLayoutWire {\n fromNode: string;\n fromX: number;\n fromY: number;\n toNode: string;\n toX: number;\n toY: number;\n isActiveLow?: boolean;\n path: string;\n}\n\nexport interface LogicLayoutModule {\n id: string;\n label: string;\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport interface LogicLayoutResult {\n width: number;\n height: number;\n nodes: LogicLayoutNode[];\n wires: LogicLayoutWire[];\n modules: LogicLayoutModule[];\n}\n\nconst LAYER_GAP = 80; // extra horizontal gap between layers\nconst ROW_GAP = 40; // vertical gap between rows in same layer\nconst PORT_SIZE = 40; // input/output port pseudo-box width\nconst PORT_H = 30;\n\nexport function layoutLogic(ast: LogicGateAST): LogicLayoutResult {\n // Determine layer per signal id using longest-path layering\n const layerOf = new Map<string, number>();\n for (const inp of ast.inputs) layerOf.set(inp.id, 0);\n\n // Build dependency map for gates\n const pending = new Set(ast.gates.map((g) => g.id));\n let safety = 0;\n while (pending.size > 0 && safety++ < 1000) {\n for (const g of ast.gates) {\n if (!pending.has(g.id)) continue;\n let maxDep = -1;\n let ready = true;\n for (const inp of g.inputs) {\n const clean = inp.startsWith(\"~\") ? inp.slice(1) : inp;\n const l = layerOf.get(clean);\n if (l === undefined) {\n ready = false;\n break;\n }\n if (l > maxDep) maxDep = l;\n }\n if (ready) {\n layerOf.set(g.id, maxDep + 1);\n pending.delete(g.id);\n }\n }\n }\n if (pending.size > 0) {\n // cycle or unresolved: force layer 1\n for (const id of pending) layerOf.set(id, 1);\n }\n\n const outputLayer =\n Math.max(0, ...Array.from(layerOf.values())) + 1;\n // All outputs get a terminal label node. Use synthetic id to avoid colliding\n // with a gate that shares the output's name (e.g. `output Y; Y = AND(A,B)`).\n const outTermId = (o: { id: string }) => `$out$${o.id}`;\n const portOutputs = ast.outputs.map((o) => ({\n ...o,\n termId: outTermId(o),\n source: o.from,\n }));\n for (const o of portOutputs) layerOf.set(o.termId, outputLayer);\n\n // Group ids by layer\n const layers = new Map<number, string[]>();\n const addToLayer = (id: string, layer: number) => {\n if (!layers.has(layer)) layers.set(layer, []);\n layers.get(layer)!.push(id);\n };\n for (const i of ast.inputs) addToLayer(i.id, 0);\n for (const g of ast.gates) addToLayer(g.id, layerOf.get(g.id)!);\n for (const o of portOutputs) addToLayer(o.termId, outputLayer);\n\n // Compute sizes per node (precompute geometries for gates)\n const gateGeoms = new Map<string, GateGeometry>();\n for (const g of ast.gates) {\n gateGeoms.set(g.id, getGateGeometry(g.gateType, g.inputs.length));\n }\n\n // Assign coordinates\n const nodes: LogicLayoutNode[] = [];\n const sortedLayers = Array.from(layers.keys()).sort((a, b) => a - b);\n\n // compute each layer's widest node\n const layerWidth = new Map<number, number>();\n for (const [layerIdx, ids] of layers) {\n let maxW = 60;\n for (const id of ids) {\n const g = gateGeoms.get(id);\n if (g && g.width > maxW) maxW = g.width;\n if (!g && layerIdx === 0) maxW = Math.max(maxW, PORT_SIZE);\n if (!g && layerIdx === outputLayer) maxW = Math.max(maxW, PORT_SIZE);\n }\n layerWidth.set(layerIdx, maxW);\n }\n\n let cursorX = 20;\n const layerStartMap = new Map<number, number>();\n for (const layerIdx of sortedLayers) {\n layerStartMap.set(layerIdx, cursorX);\n cursorX += (layerWidth.get(layerIdx) ?? 60) + LAYER_GAP;\n }\n const totalW = cursorX;\n\n // Compute vertical placement per layer\n const heightOf = (id: string): number => {\n const g = gateGeoms.get(id);\n if (g) return g.height;\n return PORT_H;\n };\n\n // find max column height\n let maxColH = 0;\n for (const ids of layers.values()) {\n const total = ids.reduce((s, id) => s + heightOf(id), 0) + (ids.length - 1) * ROW_GAP;\n if (total > maxColH) maxColH = total;\n }\n const totalH = maxColH + 80;\n\n const nodeInfo = new Map<string, LogicLayoutNode>();\n for (const [layerIdx, ids] of layers) {\n const xStart = layerStartMap.get(layerIdx)!;\n const total = ids.reduce((s, id) => s + heightOf(id), 0) + (ids.length - 1) * ROW_GAP;\n let y = 40 + (maxColH - total) / 2;\n for (const id of ids) {\n const h = heightOf(id);\n const g = gateGeoms.get(id);\n let node: LogicLayoutNode;\n if (layerIdx === 0) {\n const inp = ast.inputs.find((i) => i.id === id)!;\n node = {\n id,\n kind: \"input\",\n x: xStart,\n y,\n layer: 0,\n label: inp.label,\n isActiveLow: inp.isActiveLow,\n };\n } else if (layerIdx === outputLayer && !g && id.startsWith(\"$out$\")) {\n const out = portOutputs.find((o) => o.termId === id)!;\n node = {\n id,\n kind: \"output\",\n x: xStart,\n y,\n layer: outputLayer,\n label: out.label,\n isActiveLow: out.isActiveLow,\n };\n } else {\n node = {\n id,\n kind: \"gate\",\n x: xStart,\n y,\n layer: layerIdx,\n geometry: g,\n gateType: ast.gates.find((gg) => gg.id === id)!.gateType,\n rawType: ast.gates.find((gg) => gg.id === id)!.rawType,\n label: id,\n };\n }\n nodes.push(node);\n nodeInfo.set(id, node);\n y += h + ROW_GAP;\n }\n }\n\n // Wires\n const wires: LogicLayoutWire[] = [];\n const getSourcePoint = (id: string) => {\n const n = nodeInfo.get(id);\n if (!n) return null;\n if (n.kind === \"input\") return { x: n.x + PORT_SIZE, y: n.y + PORT_H / 2 };\n if (n.kind === \"gate\" && n.geometry) {\n const out = n.geometry.outputPins[0];\n return { x: n.x + out.x, y: n.y + out.y };\n }\n return null;\n };\n\n for (const g of ast.gates) {\n const target = nodeInfo.get(g.id);\n if (!target || !target.geometry) continue;\n g.inputs.forEach((rawInp, idx) => {\n const isLow = rawInp.startsWith(\"~\");\n const srcId = isLow ? rawInp.slice(1) : rawInp;\n const src = getSourcePoint(srcId);\n if (!src) return;\n const pin = target.geometry!.inputPins[idx];\n if (!pin) return;\n const toX = target.x + pin.x;\n const toY = target.y + pin.y;\n const midX = (src.x + toX) / 2;\n const path = `M ${src.x},${src.y} L ${midX},${src.y} L ${midX},${toY} L ${toX},${toY}`;\n wires.push({\n fromNode: srcId,\n fromX: src.x,\n fromY: src.y,\n toNode: g.id,\n toX,\n toY,\n isActiveLow: isLow,\n path,\n });\n });\n }\n\n // Output port wires\n for (const o of portOutputs) {\n const src = getSourcePoint(o.source);\n const target = nodeInfo.get(o.termId);\n if (!src || !target || target.kind !== \"output\") continue;\n const toX = target.x;\n const toY = target.y + PORT_H / 2;\n let path: string;\n if (Math.abs(src.y - toY) < 0.5) {\n path = `M ${src.x},${src.y} L ${toX},${toY}`;\n } else {\n const midX = (src.x + toX) / 2;\n path = `M ${src.x},${src.y} L ${midX},${src.y} L ${midX},${toY} L ${toX},${toY}`;\n }\n wires.push({\n fromNode: o.source,\n fromX: src.x,\n fromY: src.y,\n toNode: o.termId,\n toX,\n toY,\n path,\n });\n }\n\n // Module bounding boxes (dashed enclosure for sub-circuits)\n const modules: LogicLayoutModule[] = [];\n if (ast.modules && ast.modules.length > 0) {\n const PAD = 14;\n for (const mod of ast.modules) {\n const memberIds = new Set(\n ast.gates.filter((g) => g.moduleId === mod.id).map((g) => g.id)\n );\n if (memberIds.size === 0) continue;\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const n of nodes) {\n if (!memberIds.has(n.id)) continue;\n const w = n.geometry?.width ?? 60;\n const h = n.geometry?.height ?? 60;\n if (n.x < minX) minX = n.x;\n if (n.y < minY) minY = n.y;\n if (n.x + w > maxX) maxX = n.x + w;\n if (n.y + h > maxY) maxY = n.y + h;\n }\n if (!isFinite(minX)) continue;\n modules.push({\n id: mod.id,\n label: mod.label,\n x: minX - PAD,\n y: minY - PAD - 4,\n width: maxX - minX + PAD * 2,\n height: maxY - minY + PAD * 2 + 4,\n });\n }\n }\n\n return { width: totalW, height: totalH, nodes, wires, modules };\n}\n","import type { LogicGateAST, LogicGateStyle, RenderConfig } from \"../../core/types\";\nimport { layoutLogic } from \"./layout\";\nimport {\n svgRoot,\n defs,\n group,\n el,\n circle,\n path as pathEl,\n text,\n title as titleEl,\n desc,\n polygon,\n} from \"../../core/svg\";\nimport { resolveIndustrialTheme } from \"../../core/theme\";\n\nconst PORT_SIZE = 40;\nconst PORT_H = 30;\n\nfunction renderGateBody(\n n: ReturnType<typeof layoutLogic>[\"nodes\"][number],\n style: LogicGateStyle\n): string[] {\n const out: string[] = [];\n if (!n.geometry) return out;\n const g = n.geometry;\n\n if (style === \"iec\") {\n // Rectangle\n out.push(\n el(\"rect\", {\n x: 0,\n y: 0,\n width: g.width,\n height: g.height,\n class: \"schematex-logic-gate-body\",\n })\n );\n if (g.iecLabel) {\n out.push(\n text(\n {\n x: g.width / 2,\n y: g.height / 2 + 4,\n class: \"schematex-logic-gate-iec-label\",\n \"text-anchor\": \"middle\",\n },\n g.iecLabel\n )\n );\n }\n } else {\n out.push(\n el(\"path\", { d: g.ansiPath, class: \"schematex-logic-gate-body\" })\n );\n }\n\n // Unrecognised gate: stamp a centred \"?\" so the ANSI box reads as a flagged\n // placeholder (IEC already centres the \"?\" via iecLabel above).\n if (n.gateType === \"unknown\" && style !== \"iec\") {\n out.push(\n text(\n {\n x: g.width / 2,\n y: g.height / 2 + 6,\n class: \"schematex-logic-gate-iec-label\",\n \"text-anchor\": \"middle\",\n },\n \"?\"\n )\n );\n }\n\n // Output bubble\n if (g.outputBubble) {\n const op = g.outputPins[0];\n out.push(\n circle({\n cx: op.x - 4,\n cy: op.y,\n r: 4,\n class: \"schematex-logic-bubble\",\n })\n );\n }\n\n // Clock triangle\n if (g.clockPin) {\n const cp = g.inputPins.find((p) => p.id === g.clockPin);\n if (cp) {\n out.push(\n polygon({\n points: `${cp.x},${cp.y - 5} ${cp.x + 8},${cp.y} ${cp.x},${cp.y + 5}`,\n class: \"schematex-logic-clock-tri\",\n })\n );\n }\n }\n\n // Qn bubble (sequential)\n for (const op of g.outputPins) {\n if (op.bubble && op.id !== \"out\") {\n out.push(\n circle({\n cx: op.x + 4,\n cy: op.y,\n r: 4,\n class: \"schematex-logic-bubble\",\n })\n );\n }\n }\n\n // Pin labels\n for (const pin of g.inputPins) {\n if (pin.label && pin.id !== g.clockPin) {\n out.push(\n text(\n {\n x: pin.x + 5,\n y: pin.y + 3,\n class: \"schematex-logic-pin-label\",\n },\n pin.label\n )\n );\n }\n }\n for (const pin of g.outputPins) {\n if (pin.label) {\n out.push(\n text(\n {\n x: pin.x - 6,\n y: pin.y + 3,\n class: \"schematex-logic-pin-label\",\n \"text-anchor\": \"end\",\n },\n pin.label\n )\n );\n }\n }\n\n // Gate type label (center top, small)\n if (style === \"ansi\" && g.iecLabel && g.height >= 60) {\n const labelX = g.width / 2;\n const labelY = g.height + 14;\n out.push(\n text(\n {\n x: labelX,\n y: labelY,\n class: \"schematex-logic-gate-type\",\n \"text-anchor\": \"middle\",\n },\n n.gateType === \"unknown\" ? n.rawType ?? \"?\" : n.gateType ?? \"\"\n )\n );\n }\n\n return out;\n}\n\nexport function renderLogic(ast: LogicGateAST, config?: RenderConfig): string {\n const style: LogicGateStyle = ast.style ?? \"ansi\";\n const layout = layoutLogic(ast);\n const { width, height } = layout;\n const t = resolveIndustrialTheme(config?.theme ?? \"default\");\n\n const gateSvgs: string[] = [];\n const portSvgs: string[] = [];\n const moduleSvgs: string[] = [];\n\n for (const m of layout.modules) {\n moduleSvgs.push(\n group({ \"data-module-id\": m.id }, [\n el(\"rect\", {\n x: m.x,\n y: m.y,\n width: m.width,\n height: m.height,\n rx: 6,\n class: \"schematex-logic-module\",\n }),\n text(\n {\n x: m.x + 10,\n y: m.y + 14,\n class: \"schematex-logic-module-label\",\n },\n m.label\n ),\n ])\n );\n }\n\n for (const n of layout.nodes) {\n if (n.kind === \"gate\") {\n gateSvgs.push(\n group(\n {\n transform: `translate(${n.x}, ${n.y})`,\n \"data-gate-id\": n.id,\n \"data-gate-type\": n.gateType ?? \"\",\n },\n renderGateBody(n, style)\n )\n );\n } else if (n.kind === \"input\") {\n // Label + short stub line; no rectangle.\n const cy = PORT_H / 2;\n portSvgs.push(\n group({ transform: `translate(${n.x}, ${n.y})`, \"data-port\": \"input\" }, [\n text(\n {\n x: 0,\n y: cy + 4,\n \"text-anchor\": \"start\",\n class: \"schematex-logic-port-label\",\n },\n n.label\n ),\n el(\"line\", {\n x1: PORT_SIZE - 12,\n y1: cy,\n x2: n.isActiveLow ? PORT_SIZE - 8 : PORT_SIZE,\n y2: cy,\n class: \"schematex-logic-wire\",\n }),\n n.isActiveLow\n ? circle({\n cx: PORT_SIZE - 4,\n cy,\n r: 4,\n class: \"schematex-logic-bubble\",\n })\n : \"\",\n ])\n );\n } else if (n.kind === \"output\") {\n const cy = PORT_H / 2;\n portSvgs.push(\n group({ transform: `translate(${n.x}, ${n.y})`, \"data-port\": \"output\" }, [\n el(\"line\", {\n x1: 0,\n y1: cy,\n x2: 12,\n y2: cy,\n class: \"schematex-logic-wire\",\n }),\n text(\n {\n x: 16,\n y: cy + 4,\n \"text-anchor\": \"start\",\n class: \"schematex-logic-port-label\",\n },\n n.label\n ),\n ])\n );\n }\n }\n\n const wireSvgs = layout.wires.map((w) => {\n const extras: string[] = [];\n if (w.isActiveLow) {\n extras.push(\n circle({\n cx: w.toX - 4,\n cy: w.toY,\n r: 4,\n class: \"schematex-logic-bubble\",\n })\n );\n }\n return [\n pathEl({\n d: w.path,\n class: \"schematex-logic-wire\",\n \"data-from\": w.fromNode,\n \"data-to\": w.toNode,\n }),\n ...extras,\n ].join(\"\");\n });\n\n const css = `\n.schematex-logic { font-family: system-ui, -apple-system, sans-serif; }\n.schematex-logic-gate-body { fill: none; stroke: ${t.strokeHeavy}; stroke-width: 1.75; stroke-linejoin: round; }\n.schematex-logic-bubble { fill: ${t.bg}; stroke: ${t.strokeHeavy}; stroke-width: 1.5; }\n.schematex-logic-clock-tri { fill: none; stroke: ${t.strokeHeavy}; stroke-width: 1.5; stroke-linejoin: round; }\n.schematex-logic-wire { stroke: ${t.strokeHeavy}; stroke-width: 1.5; fill: none; stroke-linecap: square; }\n.schematex-logic-port-label { font: 13px system-ui, sans-serif; fill: ${t.text}; }\n.schematex-logic-pin-label { font: 9px sans-serif; fill: ${t.stroke}; }\n.schematex-logic-gate-type { font: 10px sans-serif; fill: ${t.textMuted}; }\n.schematex-logic-gate-iec-label { font: bold 13px sans-serif; fill: ${t.text}; }\n.schematex-logic-title { font: bold 14px sans-serif; fill: ${t.text}; }\n.schematex-logic-module { fill: none; stroke: ${t.textMuted}; stroke-width: 1.25; stroke-dasharray: 6 4; }\n.schematex-logic-module-label { font: 11px sans-serif; fill: ${t.textMuted}; font-style: italic; }\n[data-gate-type=\"unknown\"] .schematex-logic-gate-body { stroke: ${t.accent}; stroke-dasharray: 5 3; }\n[data-gate-type=\"unknown\"] .schematex-logic-gate-iec-label { fill: ${t.accent}; }\n`.trim();\n\n const titleSvg = ast.title\n ? text(\n {\n x: width / 2,\n y: 18,\n \"text-anchor\": \"middle\",\n class: \"schematex-logic-title\",\n },\n ast.title\n )\n : \"\";\n\n return svgRoot(\n {\n class: \"schematex-logic\",\n viewBox: `0 0 ${width} ${height + (ast.title ? 20 : 0)}`,\n width,\n height: height + (ast.title ? 20 : 0),\n role: \"img\",\n \"data-diagram-type\": \"logic\",\n },\n [\n titleEl(ast.title ?? \"Logic Gate Diagram\"),\n desc(\n `Logic gate diagram with ${ast.gates.length} gates, ${ast.inputs.length} inputs, ${ast.outputs.length} outputs`\n ),\n defs([el(\"style\", {}, css)]),\n group(\n { transform: `translate(0, ${ast.title ? 20 : 0})` },\n [\n group({ class: \"schematex-logic-modules\" }, moduleSvgs),\n group({ class: \"schematex-logic-wires\" }, wireSvgs),\n group({ class: \"schematex-logic-gates\" }, gateSvgs),\n group({ class: \"schematex-logic-ports\" }, portSvgs),\n ]\n ),\n titleSvg,\n ]\n );\n}\n","import type { SchematexDiagnostic } from \"../../core/diagnostics\";\nimport type { LogicGateAST } from \"../../core/types\";\nimport { didYouMean } from \"../../core/dsl-suggest\";\nimport { parseLogic } from \"./parser\";\n\n// Canonical gate vocabulary for the did-you-mean suggestion on an unknown gate.\n// Kept in sync with GATE_TYPES in the parser.\nconst KNOWN_GATES = [\n \"AND\", \"OR\", \"NOT\", \"NAND\", \"NOR\", \"XOR\", \"XNOR\", \"BUF\",\n \"TRISTATE_BUF\", \"TRISTATE_INV\", \"OPEN_DRAIN\", \"SCHMITT\",\n \"DFF\", \"JKFF\", \"SRFF\", \"TFF\", \"LATCH_SR\", \"LATCH_D\",\n \"MUX\", \"DEMUX\", \"DECODER\", \"ENCODER\", \"COUNTER\", \"SHIFT_REG\",\n];\n\nexport function lintLogic(text: string): SchematexDiagnostic[] {\n let ast: LogicGateAST;\n try {\n ast = parseLogic(text);\n } catch {\n // Parse failures are reported by the normal error path; lint stays silent.\n return [];\n }\n return lintLogicAst(ast);\n}\n\nexport function lintLogicAst(ast: LogicGateAST): SchematexDiagnostic[] {\n const out: SchematexDiagnostic[] = [];\n // Unrecognised gate types are kept (drawn as a flagged placeholder) but\n // warned about so the partial render is analyzable and the engineer gets a\n // did-you-mean nudge. The engine never silently substitutes a real gate.\n for (const g of ast.gates) {\n if (g.gateType !== \"unknown\") continue;\n const raw = g.rawType ?? \"\";\n out.push({\n severity: \"warning\",\n code: \"LOGIC_UNKNOWN_GATE\",\n message: `gate \"${g.id}\" has unrecognised type \"${raw}\"; drawn as a flagged placeholder`,\n hint: `\"${raw}\" is not a known logic gate.${didYouMean(raw.toUpperCase(), KNOWN_GATES)} Valid gates include AND, OR, NOT, NAND, NOR, XOR, DFF, MUX. See docs/reference.`,\n fatal: false,\n });\n }\n return out;\n}\n","import type { DiagramPlugin } from \"../../core/types\";\nimport { parseLogic } from \"./parser\";\nimport { renderLogic } from \"./renderer\";\nimport { lintLogic } from \"./lint\";\n\nexport const logic: DiagramPlugin = {\n type: \"logic\",\n detect(text: string): boolean {\n const first = text.trim().split(\"\\n\")[0]?.trim().toLowerCase() ?? \"\";\n return first.startsWith(\"logic\");\n },\n parse: parseLogic,\n lint: lintLogic,\n\n render(text: string, config): string {\n const ast = parseLogic(text);\n return renderLogic(ast, config);\n },\n};\n\nexport { parseLogic } from \"./parser\";\nexport { renderLogic } from \"./renderer\";\nexport { layoutLogic } from \"./layout\";\nexport { lintLogic, lintLogicAst } from \"./lint\";\n"]}
@@ -1,4 +1,4 @@
1
- import { parseResult, renderResult } from './chunk-MI77LY6A.js';
1
+ import { parseResult, renderResult } from './chunk-FOPOOV2P.js';
2
2
 
3
3
  // src/ai/registry.ts
4
4
  var DIAGRAM_REGISTRY = [
@@ -282,6 +282,15 @@ var DIAGRAM_REGISTRY = [
282
282
  standard: "NUREG-0492 Fault Tree Handbook + IEC 61025:2006 + NASA FT Handbook 2002; MOCUS cut sets (Fussell-Vesely 1972); see 37-FAULT-TREE-STANDARD.md",
283
283
  syntaxKey: "faulttree"
284
284
  },
285
+ {
286
+ type: "bowtie",
287
+ name: "Bowtie risk diagram",
288
+ tagline: "Barrier-based risk management \u2014 one hazard's top event (the knot) with threats fanning in through preventative barriers on the left and consequences fanning out through mitigative barriers on the right, the whole shaped like a bow tie.",
289
+ useWhen: 'Use for process-safety / barrier risk analysis (oil & gas, aviation SMS, chemical, rail): one hazard, one top event, the threats that could cause it and the consequences if it happens, with the controls (barriers) in between. Indentation-structured DSL mirrors the CCPS 7-step build: `hazard "\u2026"`, `topevent "\u2026"`, then each `threat "\u2026"` with indented `prevent "\u2026"` barrier chain, each `consequence "\u2026"` with indented `mitigate "\u2026"` chain; `escalation "\u2026"` nests under a barrier it degrades, `barrier "\u2026"` nests under an escalation. Correct-by-construction: the engine *rejects* a threat/consequence with no barrier and an escalation not attached to a barrier (CCPS/EI barrier rule set). Qualitative \u2014 no probability rollup (that is `faulttree`\'s job; a bowtie\'s left wing read backwards IS a fault tree). Distinct from `fishbone` (one-sided causes, no barriers) and `faulttree` (Boolean gates + cut sets, left wing only).',
290
+ cluster: "risk-reliability",
291
+ standard: "CCPS / Energy Institute 2018 (Bow Ties in Risk Management) + IEC 31010:2019 \xA7B.4.6 + ICAO Doc 9859; Swiss-cheese lineage (Reason 1990); see 38-BOWTIE-STANDARD.md",
292
+ syntaxKey: "bowtie"
293
+ },
285
294
  // ── Generic process / flow ───────────────────────────────────
286
295
  {
287
296
  type: "flowchart",
@@ -377,7 +386,9 @@ var DIAGRAM_SINCE = {
377
386
  // 0.6.4
378
387
  umlclass: "0.6.4",
379
388
  // 0.6.5
380
- faulttree: "0.6.5"
389
+ faulttree: "0.6.5",
390
+ // 0.6.6
391
+ bowtie: "0.6.6"
381
392
  };
382
393
  function getDiagramSince(type) {
383
394
  const resolved = resolveDiagramType(type);
@@ -442,6 +453,82 @@ var EXAMPLES = [
442
453
  "dsl": 'blockdiagram "PID control loop"\nC = block("PID C(s)") [role: controller]\nG = block("Plant G(s)") [role: plant]\nerr = sum(+r, -y)\nr = signal("r (setpoint)")\ny = signal("y (output)")\nin -> r\nr -> err\nerr -> C\nC -> G\nG -> y\nG -> err',
443
454
  "notes": '## Scenario\n\nThe standard closed-loop PID block diagram appears in every control systems textbook (Ogata, Franklin, \xC5str\xF6m) and every control system design spec sheet. Schematex renders it from a signal-flow description \u2014 not a generic flowchart \u2014 using proper summing junction symbols and automatic feedback routing.\n\n## Annotation key\n\n- `block("label") [role: ...]` \u2014 transfer function block; `role: controller` and `role: plant` affect visual styling\n- `sum(+r, -y)` \u2014 summing junction: adds the `+r` (reference) signal and subtracts the `-y` (output feedback)\n- `signal("label")` \u2014 named signal node\n- `G -> err` \u2014 the feedback path: plant output `y` routes back to the summing junction\n\n## How to read\n\nThe setpoint `r` enters the summing junction `err`, which subtracts the plant output `y` to compute the error signal. The PID controller `C(s)` processes the error and drives the plant `G(s)`. The plant output `y` is both the system output and the feedback signal. The loop is closed when `G -> err` feeds `y` back to the summing junction.'
444
455
  },
456
+ {
457
+ "slug": "bowtie-hot-work-fire",
458
+ "diagram": "bowtie",
459
+ "title": "Hot work \u2014 ignition of flammable atmosphere",
460
+ "description": "A bowtie with escalation factors on both wings \u2014 a preventative and a mitigative barrier are each degraded by a named condition with its own escalation-factor barrier, exercising the full element vocabulary.",
461
+ "standard": "CCPS / Energy Institute 2018",
462
+ "tags": [
463
+ "bowtie",
464
+ "risk",
465
+ "escalation-factor",
466
+ "hot-work",
467
+ "fire",
468
+ "barrier"
469
+ ],
470
+ "complexity": 3,
471
+ "featured": false,
472
+ "dsl": 'bowtie "Hot work \u2014 fire bowtie"\nhazard "Hot work near flammable materials"\ntopevent "Ignition of flammable atmosphere"\nthreat "Sparks / hot slag"\n prevent "Hot-work permit"\n prevent "Fire watch"\n escalation "Fire watch leaves post early"\n barrier "Post-work monitoring period (60 min)"\nthreat "Static discharge"\n prevent "Bonding + grounding"\n prevent "Antistatic PPE"\nconsequence "Flash fire"\n mitigate "Fixed fire suppression"\n escalation "Suppression isolated for maintenance"\n barrier "Impairment register + MoC"\nconsequence "Asset loss"\n mitigate "Fire-rated separation"\n mitigate "Business-continuity plan"',
473
+ "notes": '## What this shows\n\nThe complete element vocabulary, with **escalation factors on both wings** \u2014 because a mitigative barrier can be degraded just as a preventative one can. On the left, the "Fire watch" barrier is defeated if the watch leaves early, controlled by a mandatory post-work monitoring period. On the right, the "Fixed fire suppression" barrier is defeated when isolated for maintenance, controlled by an impairment register and management-of-change.\n\nThe left wing is taller than the right (its escalation drops deeper), so it sets the diagram height while the right wing stays centred about the knot. Each escalation hangs into the whitespace between bands on a muted *degrades* connector, never colliding with the next line.'
474
+ },
475
+ {
476
+ "slug": "bowtie-lpg-loss-of-containment",
477
+ "diagram": "bowtie",
478
+ "title": "LPG storage \u2014 loss of containment",
479
+ "description": "The canonical process-safety bowtie \u2014 three threats fan in through preventative barrier chains, three consequences fan out through mitigative chains, around the central loss-of-containment top event.",
480
+ "standard": "CCPS / Energy Institute 2018",
481
+ "tags": [
482
+ "bowtie",
483
+ "risk",
484
+ "process-safety",
485
+ "barrier",
486
+ "hazard",
487
+ "loss-of-containment"
488
+ ],
489
+ "complexity": 3,
490
+ "featured": true,
491
+ "dsl": 'bowtie "LPG storage \u2014 loss of containment"\nhazard "LPG stored under pressure"\ntopevent "Loss of containment"\nthreat "Corrosion of vessel wall"\n prevent "Corrosion-resistant coating"\n prevent "UT thickness inspection"\nthreat "Overpressure during filling"\n prevent "High-pressure trip (SIL 2)"\n prevent "Pressure relief valve"\nthreat "Mechanical impact (vehicle)"\n prevent "Bollards / vehicle barriers"\n prevent "Site speed limit + banksman"\nconsequence "Jet fire"\n mitigate "Gas detection + ESD"\n mitigate "Deluge / water spray"\nconsequence "Vapour cloud explosion"\n mitigate "Ignition-source control (ATEX)"\n mitigate "Blast-resistant control room"\nconsequence "Toxic / asphyxiation exposure"\n mitigate "Personal gas monitors"\n mitigate "Emergency evacuation plan"',
492
+ "notes": '## What this shows\n\nThe integrating picture of barrier-based risk management for one major-accident scenario. The **hazard** ("LPG stored under pressure") sits above the central **top event** \u2014 the moment control is lost. To the **left**, three credible **threats** each fan in through a chain of **preventative barriers** (grey, on the line) that stop them reaching the knot. To the **right**, three **consequences** each fan out through a chain of **mitigative barriers** that limit the damage if the top event occurs.\n\nThis is the shape a process-safety reviewer expects on an A3: defence-in-depth depth on both wings, the knot in the middle, the hazard above. **Correct by construction** \u2014 the engine would reject any threat or consequence drawn with no barrier (a Swiss-cheese cartoon), so every line you see genuinely passes through a control.'
493
+ },
494
+ {
495
+ "slug": "bowtie-runway-excursion",
496
+ "diagram": "bowtie",
497
+ "title": "Runway excursion (aviation SMS)",
498
+ "description": "A non-process-industry bowtie \u2014 the same threat / barrier / consequence grammar applied to an aviation safety-management scenario, showing the vocabulary travels across domains.",
499
+ "standard": "ICAO Doc 9859 + CCPS / EI 2018",
500
+ "tags": [
501
+ "bowtie",
502
+ "risk",
503
+ "aviation",
504
+ "SMS",
505
+ "ICAO",
506
+ "barrier"
507
+ ],
508
+ "complexity": 3,
509
+ "featured": false,
510
+ "dsl": 'bowtie "Runway excursion"\nhazard "Aircraft landing in adverse conditions"\ntopevent "Runway excursion on landing"\nthreat "Unstable approach"\n prevent "Stabilised-approach gate (go-around policy)"\n prevent "Approach monitoring + callouts"\nthreat "Contaminated runway"\n prevent "Runway condition reporting (RCR)"\n prevent "Landing performance assessment"\nthreat "Excessive landing speed"\n prevent "Speed / energy management SOP"\n prevent "Autobrake selection"\nconsequence "Hull damage"\n mitigate "Runway end safety area (RESA)"\n mitigate "Arrestor bed (EMAS)"\nconsequence "Injuries / fatalities"\n mitigate "Cabin-crew brace + evacuation"\n mitigate "Airport emergency response"',
511
+ "notes": "## What this shows\n\nThe bowtie is mandated well beyond process industries \u2014 ICAO's Safety Management Manual (Doc 9859) makes it a primary hazard-analysis tool for airlines. The grammar is identical: a **hazard** (landing in adverse conditions), a **top event** (the runway excursion), **threats** that could cause it through preventative barrier chains, and **consequences** limited by mitigative chains.\n\nIt reads the same to a non-specialist as a chemical-plant bowtie, which is exactly the point: one A3 puts the entire defence-in-depth story for a single scenario in front of a board or a regulator, regardless of industry."
512
+ },
513
+ {
514
+ "slug": "bowtie-working-at-height",
515
+ "diagram": "bowtie",
516
+ "title": "Working at height \u2014 fall from height",
517
+ "description": "A defence-in-depth bowtie with an escalation factor \u2014 a preventative barrier is degraded by a named condition, which is itself controlled by an escalation-factor barrier dropping below the line.",
518
+ "standard": "CCPS / Energy Institute 2018",
519
+ "tags": [
520
+ "bowtie",
521
+ "risk",
522
+ "escalation-factor",
523
+ "defence-in-depth",
524
+ "construction",
525
+ "safety"
526
+ ],
527
+ "complexity": 2,
528
+ "featured": true,
529
+ "dsl": 'bowtie "Working at height"\nhazard "Working at height"\ntopevent "Person falls from height"\nthreat "Guardrail removed for access"\n prevent "Permit-to-work system"\n prevent "Temporary edge protection"\n escalation "Edge protection not inspected"\n barrier "Pre-use inspection regime"\n prevent "Spotter / banksman"\nthreat "Fragile roof surface"\n prevent "Crawling boards + signage"\n prevent "Roof-access risk assessment"\nconsequence "Fatality"\n mitigate "Fall-arrest harness + lanyard"\n mitigate "Rescue plan + first aid"\nconsequence "Serious injury"\n mitigate "Safety netting below"\n mitigate "On-site medic + evacuation"',
530
+ "notes": '## What this shows\n\nTwo threats, two consequences, multi-barrier chains \u2014 and an **escalation factor**, the element that makes a bowtie an honest defence-in-depth model rather than a wish list. The "Temporary edge protection" barrier is degraded by a specific named condition ("Edge protection not inspected", amber), which drops vertically below the barrier on a muted *degrades* connector. That escalation factor is itself controlled by an **escalation-factor barrier** ("Pre-use inspection regime") one level deeper.\n\nReading order along each line is declaration order: the first barrier is the **outermost** (first line of defence, nearest the threat); the last is the **innermost** (nearest the knot). The escalation hangs into the whitespace below without disturbing the symmetry of the two threat lines.'
531
+ },
445
532
  {
446
533
  "slug": "bpmn-incident-response",
447
534
  "diagram": "bpmn",
@@ -2898,6 +2985,10 @@ var SYNTAX = {
2898
2985
  "faulttree": {
2899
2986
  "title": "Fault Tree Analysis",
2900
2987
  "content": '## 1. Your first diagram\n\nEvery document starts with the `faulttree` keyword (alias `fta`), an optional title, then a flat list of declarations wired by id:\n\n```\nfaulttree "Both pumps fail"\n analysis: cutsets, probability\n top T "Both redundant pumps fail" = AND(PA, PB)\n basic PA "Pump A fails" p: 0.01\n basic PB "Pump B fails" p: 0.01\n```\n\n`top` declares the single root event and the gate that produces it; `basic` declares a leaf component failure with a probability. The engine computes the minimal cut set `{PA, PB}` and P(top) = 1.0e-4. The DSL is **flat declaration + reference** (not nested by indentation) \u2014 a fault tree is a DAG, so a shared event is just referenced by id from several gates.\n\nHeader directives:\n\n- `analysis: cutsets, probability` \u2014 what to compute (also `pathsets`, `none`).\n- `prob: rare | mcub | exact` \u2014 the probability method (default `rare`, a conservative upper bound).\n- `layout: tb | bt` \u2014 top-down (default) or bottom-up.\n\n---\n\n## 2. Events\n\n```\ntop T "System fails" = OR(A, B)\ngate G1 "Sub-fault" = AND(A, B)\nbasic A "Component A fails" p: 0.01\nundeveloped EXT "External fire (not modelled)"\nhouse HX "Power on" state: 1\n```\n\n- **`top`** \u2014 the one undesired event being analysed (rectangle, emphasised border). Exactly one is required.\n- **`gate`** \u2014 an intermediate event that is itself a gate output (rectangle).\n- **`basic`** \u2014 a primary component failure, the leaf that carries `p:` (circle).\n- **`undeveloped`** \u2014 an event not developed further (diamond); may carry `p:`.\n- **`house`** \u2014 a normally-expected event forced `state: 0` or `state: 1` (house glyph) \u2014 switches branches of the tree on/off.\n\nProbabilities accept decimals or scientific notation (`p: 0.004` or `p: 1e-6`); `p:` and `prob:` are interchangeable. An event with no probability is treated symbolically (cut sets still computed; P(top) reported as n/a).\n\n---\n\n## 3. Gates\n\n```\ntop T1 = AND(A, B, C) # all inputs occur\ntop T2 = OR(A, B) # at least one input occurs\ntop T3 = XOR(A, B) # exactly one (treated as OR for cut sets)\ntop T4 = VOTING(2/3; A, B, C) # at least k of n\ngate G1 = INHIBIT(A) if COND # A occurs AND the condition holds\ngate G2 = PAND(A, B) order: A, B # A then B (order rendered, AND for cut sets)\n```\n\nGates are drawn **output-up, inputs-down** (the mirror of a `logic` gate): AND is a flat-bottomed dome, OR/XOR/VOTING a shield, INHIBIT a hexagon. The conditioning event of an `INHIBIT`/`PAND` renders as an ellipse to the side. A gate may reference another gate or any event \u2014 and the same basic event may feed several gates (a repeated event).\n\n---\n\n## 4. Computed cut sets & probability\n\nThis is the differentiator. With `analysis: cutsets`, the engine runs **MOCUS**: AND gates grow the order of a cut set, OR gates multiply the number of cut sets, then idempotence (`A\u2227A=A`) and absorption (`X \u2286 Y \u21D2 drop Y`) minimise the result.\n\n- Each **minimal cut set** is boxed in red; an **order-1 cut set is a single point of failure** (strongest red, `data-spof`).\n- A **repeated event** (one basic event under several gates) is handled by absorption \u2014 the case a naive expander gets wrong.\n- **P(top)** is computed from per-event probabilities: `rare` (\u03A3 cut-set probs, default), `mcub` (1 \u2212 \u220F(1\u2212P)), or `exact` (inclusion-exclusion, which correctly de-duplicates a shared event). The method is shown next to the top event and noted in `<desc>`.\n- A `house state: 0` can make the top event unsatisfiable \u2014 reported as "no cut sets."\n\n---\n\n## 5. Repeated events\n\n```\nfaulttree "Safety function fails"\n analysis: cutsets, probability\n prob: exact\n top T "Safety function fails" = OR(C1, C2)\n gate C1 "Channel 1" = AND(S1, L1)\n gate C2 "Channel 2" = AND(S2, L1)\n basic S1 "Sensor 1 fails" p: 0.05\n basic S2 "Sensor 2 fails" p: 0.05\n basic L1 "Shared logic solver fails" p: 0.05\n```\n\n`L1` feeds both channels \u2014 it is drawn once per reference with a shared-event mark, but the cut-set engine treats every instance as one Boolean variable. Cut sets are `{S1, L1}` and `{S2, L1}`; `prob: exact` subtracts the overlap (L1 counted once over the union), giving 0.004875 rather than the rare-event 0.005.\n\n---\n\n## 6. Transfers\n\n```\ngate OVP "Sustained over-pressure" = INHIBIT(PUMP) if HEATER\ntransfer OVP -> "OVP-detail"\n```\n\nA `transfer ID -> "name"` draws the transfer-out triangle below an event whose development lives elsewhere; a matching `transfer "name" = gate_expr` defines that named subtree and is spliced in for cut-set computation. v0.1 resolves transfers in-document.\n\n---\n\n## 7. Validation\n\nThe parser fails fast with readable errors so the cut-set math is meaningful:\n\n- exactly one `top` is required (zero or several is an error);\n- a gate referencing an undeclared id reports the id by name;\n- cycles are rejected (a fault tree is a DAG);\n- a probability outside `[0, 1]`, a `VOTING k/n` with `k > n` or `n \u2260 input count`, or an `if` condition on a non-INHIBIT/PAND gate are all reported in plain English.\n\n---\n\n## 8. Theming\n\n`default` uses the house palette \u2014 soft slate-blue event boxes, **green gates** ("logic proceeds"), **red cut-set boxes** (the computed risk), blue probability numerals, a yellow house. `monochrome` reproduces the NUREG-0492 black-and-white textbook look, where the dome/shield shape (not colour) carries the gate type. All strokes/fills come from `ReliabilityTokens`; every element carries `data-*` (`data-cutset`, `data-spof`, `data-prob`, `data-gate`) so the computed analysis is inspectable downstream.'
2988
+ },
2989
+ "bowtie": {
2990
+ "title": "Bowtie Risk Diagram",
2991
+ "content": '## 1. Your first diagram\n\nEvery document starts with the `bowtie` keyword, an optional title, then the hazard, the top event, and the two wings:\n\n```\nbowtie\ntopevent "Loss of containment"\nthreat "Corrosion"\n prevent "Inspection programme"\nconsequence "Release to atmosphere"\n mitigate "Gas detection + ESD"\n```\n\n`topevent` declares the single knot at the centre (mandatory, exactly one). Each `threat` starts a left-wing line; each `consequence` ends a right-wing line. A barrier under a `threat` is **preventative** (`prevent`); under a `consequence` it is **mitigative** (`mitigate`). The diagram is laid out symmetrically about the knot \u2014 threats fan in from the left, consequences fan out to the right.\n\nThe DSL is **indentation-structured** and mirrors the CCPS 7-step build methodology: identify the hazard \u2192 the top event \u2192 the threats \u2192 the consequences \u2192 the preventative barriers \u2192 the mitigative barriers \u2192 the escalation factors.\n\nHeader directives (any order):\n\n- `layout: symmetric | compact` \u2014 band model (default `symmetric`).\n- `legend: on | off | bottom | top` \u2014 the auto-derived colour legend (default on).\n\n---\n\n## 2. Hazard and top event\n\n```\nhazard "Working at height"\ntopevent "Person falls from height"\n```\n\n- **`hazard`** \u2014 the operation or material with the potential to cause harm: the *context* the bowtie is about (e.g. "Working at height", "Hydrocarbon under pressure"). Optional; renders as a header box above the knot with a tie-line down to it. At most one.\n- **`topevent`** \u2014 the moment control of the hazard is **lost** (e.g. "Loss of containment", "Person falls from height"). The knot of the bowtie, drawn as a green circle. **Mandatory, exactly one.**\n\nA hazard is a *thing/activity*, not a failure; the top event is the precise moment of *loss of control* \u2014 not a cause, and not yet a consequence.\n\n---\n\n## 3. Threats and consequences\n\n```\nthreat "Guardrail removed for access"\n prevent "Permit-to-work system"\n\nconsequence "Fatality"\n mitigate "Fall-arrest harness + lanyard"\n```\n\n- A **threat** is a credible cause that, *on its own*, could trigger the top event. Each threat is the start of one left-wing line, drawn as an orange box on the left edge.\n- A **consequence** is a credible outcome *of the top event* (not of the threat), drawn as a red box on the right edge.\n\nThreats and consequences may be declared in any interleaved order \u2014 the parser groups all left-wing blocks and all right-wing blocks regardless of sequence. A bowtie needs **at least one of each**: a one-wing diagram is a fault tree (see `faulttree`) or an event tree, not a bowtie.\n\n---\n\n## 4. Barriers (the controls in between)\n\n```\nthreat "Guardrail removed for access"\n prevent "Permit-to-work system"\n prevent "Temporary edge protection"\n prevent "Spotter / banksman"\n```\n\nA **barrier** is a control that interrupts the threat \u2192 top-event path (preventative) or reduces the consequence after the top event (mitigative). Each is a grey box *on the line*. Chains are free length (1..n) \u2014 the wing simply extends.\n\n**Barrier order is declaration order**: the first declared is the **outermost** (closest to the threat/consequence, the first line of defence); the last declared is the **innermost** (closest to the knot). This matches the left-to-right reading of a real bowtie. Each barrier carries `data-order` (0 = outermost) and `data-side` (`prevent` / `mitigate`) for downstream interactivity.\n\nWhen chains differ in length, barriers are **centre-anchored**: the innermost barriers align in a neat column near the knot, and the threat/consequence boxes are ragged by chain depth \u2014 reading as defence-in-depth.\n\n---\n\n## 5. Escalation factors\n\n```\nthreat "Corrosion"\n prevent "UT thickness inspection"\n escalation "Inspection interval too long"\n barrier "Risk-based inspection scheme"\n```\n\nAn **escalation factor** (or degradation factor) is a condition that *degrades a specific barrier\'s effectiveness* \u2014 e.g. "Edge protection not inspected", "Operator fatigue". It attaches to **one** barrier (not to the line) and drops vertically below it as an amber box, joined by a muted "degrades" connector.\n\nAn **escalation-factor barrier** is a control placed on the escalation factor itself \u2014 it protects the barrier from being degraded (e.g. a pre-use inspection regime). It nests one level deeper, under the escalation factor, and renders as a grey box below it.\n\nIndentation binds the nesting: `prevent`/`mitigate` at 2 spaces, `escalation` at 4, `barrier` at 6.\n\n---\n\n## 6. Correct by construction (the barrier rule set)\n\nBefore it draws a single shape, the engine validates the structural half of the CCPS/EI barrier rule set and **refuses to render** on failure \u2014 exactly as `prisma` refuses missing counts:\n\n- **Exactly one top event** \u2014 zero or several is an error.\n- **Every threat has \u2265 1 preventative barrier** \u2014 a bare threat is a Swiss-cheese cartoon, not a bowtie.\n- **Every consequence has \u2265 1 mitigative barrier** \u2014 the mirror rule.\n- **Every escalation factor is attached to a barrier** \u2014 it cannot float on a line or on the top event.\n- **At least one threat and one consequence** \u2014 a one-wing diagram is an FTA or an ETA.\n\nMessages name the offending element and the rule in plain English, e.g. *"Threat \'Corrosion\' has no preventative barrier \u2014 every threat must reach the top event through at least one barrier (CCPS/EI barrier rule). Add a `prevent` line under it."* This is what separates a real bowtie from a doodle. The engine does **not** judge whether a barrier is truly *effective* or *independent* \u2014 that is the analyst\'s qualitative judgement.\n\n---\n\n## 7. Bowtie vs fault tree\n\nA fully-developed bowtie *is* a fault tree glued to an event tree at the top event: the left wing read backwards is the fault tree whose top event is the bowtie\'s knot, and the right wing is the event tree that propagates it into consequences. Schematex keeps them as two engines because their use differs:\n\n- **`bowtie`** is qualitative and symmetric \u2014 the barrier inventory and the at-a-glance defence-in-depth story; no probability arithmetic.\n- **`faulttree`** is quantitative and Boolean \u2014 AND/OR gates, basic-event probabilities, minimal cut sets, a probability rollup.\n\nWhere you want the gate-level detail behind a single threat, draw a separate `faulttree`.\n\n---\n\n## 8. Theming\n\n`default` uses the recognised BowTieXP / bowtiemaster palette \u2014 **orange threats** (left), **grey barriers** on the line, a **green top-event disc** (centre knot), **red consequences** (right), **amber escalation factors** dropping below \u2014 mapped onto Schematex\'s semantic slots so it stays coherent with `prisma` / `pert` / `petri`. `monochrome` reproduces the regulator-print black-and-white look, where element distinction rides on shape/border + position (escalation factors get a dashed border, the knot a doubled ring) rather than colour. `dark` follows Catppuccin Mocha. All strokes/fills come from `BowtieTokens`; every element carries `data-*` (`data-role`, `data-side`, `data-line`, `data-order`, `data-barrier`) so the structure is inspectable downstream.'
2901
2992
  }
2902
2993
  };
2903
2994
 
@@ -3428,6 +3519,41 @@ var PROFILES = {
3428
3519
  "'VOTING k/n: n must equal the number of inputs' \u2014 make n match the listed inputs.",
3429
3520
  "If P(top) shows 'n/a', a basic event in a cut set is missing its `p:`."
3430
3521
  ]
3522
+ },
3523
+ bowtie: {
3524
+ type: "bowtie",
3525
+ header: 'bowtie "Title"',
3526
+ mode: "indentation-structured: hazard + topevent, then threat/consequence blocks with indented barrier chains",
3527
+ forms: [
3528
+ 'hazard "Working at height"',
3529
+ 'topevent "Person falls from height"',
3530
+ 'threat "Guardrail removed for access"',
3531
+ ' prevent "Permit-to-work system"',
3532
+ ' prevent "Temporary edge protection"',
3533
+ ' escalation "Edge protection not inspected"',
3534
+ ' barrier "Pre-use inspection regime"',
3535
+ 'consequence "Fatality"',
3536
+ ' mitigate "Fall-arrest harness"'
3537
+ ],
3538
+ prefer: [
3539
+ "Single-word keyword is `bowtie`. Declare exactly one `topevent` (the knot) and an optional `hazard` header.",
3540
+ "Each `threat` needs \u2265 1 indented `prevent` barrier; each `consequence` needs \u2265 1 indented `mitigate` barrier (the engine rejects a bare threat/consequence).",
3541
+ "Barrier order = declaration order (first = outermost, nearest the threat/consequence; last = innermost, nearest the knot).",
3542
+ "`escalation` nests (4 spaces) under the `prevent`/`mitigate` barrier it degrades; an escalation-factor `barrier` nests (6 spaces) under the escalation.",
3543
+ "Bowtie is qualitative \u2014 no probabilities. For Boolean gates + cut sets behind one threat, use a separate `faulttree`."
3544
+ ],
3545
+ avoid: [
3546
+ "Don't put a `prevent` before any `threat`, or a `mitigate` before any `consequence` \u2014 they bind to the most recent one.",
3547
+ "Don't leave a threat or consequence with no barrier \u2014 that is a Swiss-cheese cartoon, not a bowtie (it is rejected).",
3548
+ "Don't float an `escalation` on its own \u2014 it must follow a barrier line.",
3549
+ "Don't declare more than one `topevent` or more than one `hazard`."
3550
+ ],
3551
+ repair: [
3552
+ "'has no preventative barrier' / 'no mitigative barrier' \u2014 add a `prevent`/`mitigate` line under the threat/consequence.",
3553
+ "'not attached to a barrier' \u2014 move the `escalation` so it follows a `prevent`/`mitigate` line.",
3554
+ "'needs at least one threat/consequence' \u2014 a one-wing diagram is a fault tree or event tree; add the missing wing.",
3555
+ "'exactly one top event' \u2014 keep a single `topevent` line."
3556
+ ]
3431
3557
  }
3432
3558
  };
3433
3559
  function getGenerationProfile(type) {
@@ -3572,5 +3698,5 @@ function repairHint(type) {
3572
3698
  }
3573
3699
 
3574
3700
  export { DIAGRAM_REGISTRY, DIAGRAM_SINCE, getAllDiagramTypes, getDiagramMeta, getDiagramSince, getExamples, getSyntax, listDiagrams, renderDsl, resolveDiagramType, validateDsl };
3575
- //# sourceMappingURL=chunk-ZZHQBAC3.js.map
3576
- //# sourceMappingURL=chunk-ZZHQBAC3.js.map
3701
+ //# sourceMappingURL=chunk-3HZW6K5I.js.map
3702
+ //# sourceMappingURL=chunk-3HZW6K5I.js.map