@legionworks/facet 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-APACHE +202 -0
- package/LICENSE-MIT +23 -0
- package/README.md +158 -0
- package/dist/gallery/chunk-4g8rem85.css +656 -0
- package/dist/gallery/chunk-c6s9k9ty.js +5970 -0
- package/dist/gallery/frame/artifact.css +8424 -0
- package/dist/gallery/frame/chunks/abnfDiagram-N423BO3Z-jj74szbm.js +155 -0
- package/dist/gallery/frame/chunks/architecture-TIHT7OUA-cvdjn7dt.js +10 -0
- package/dist/gallery/frame/chunks/architectureDiagram-T3A2C74G-n4z77eg6.js +8675 -0
- package/dist/gallery/frame/chunks/blockDiagram-VBNYF7ZC-7xsqzrd1.js +3529 -0
- package/dist/gallery/frame/chunks/c4Diagram-5PPSVZJV-z2zjs7wx.js +2413 -0
- package/dist/gallery/frame/chunks/classDiagram-JCYQIIEL-ve8rngqp.js +47 -0
- package/dist/gallery/frame/chunks/classDiagram-v2-OCEON4UE-8cfaxb8z.js +47 -0
- package/dist/gallery/frame/chunks/cose-bilkent-JH36ORCC-sn92qexx.js +4822 -0
- package/dist/gallery/frame/chunks/cynefin-VYW2F7L2-tqjv913d.js +10 -0
- package/dist/gallery/frame/chunks/cynefinDiagram-MW4NZA55-c1c0dj12.js +500 -0
- package/dist/gallery/frame/chunks/dagre-VZM6K2ZE-7tyg4yt2.js +476 -0
- package/dist/gallery/frame/chunks/diagram-7IWD3JNH-y4eng9sc.js +526 -0
- package/dist/gallery/frame/chunks/diagram-B4RE2ZJO-rn3p7j5h.js +673 -0
- package/dist/gallery/frame/chunks/diagram-LBJQPF4R-w4a2cm9q.js +255 -0
- package/dist/gallery/frame/chunks/diagram-Q27KOJAE-aqc2v7wy.js +575 -0
- package/dist/gallery/frame/chunks/diagram-UB23O5K3-xncy8nyd.js +355 -0
- package/dist/gallery/frame/chunks/ebnfDiagram-BXEA7PRR-acwgxz16.js +175 -0
- package/dist/gallery/frame/chunks/erDiagram-JOGREHBK-mzp5nswt.js +1332 -0
- package/dist/gallery/frame/chunks/eventmodeling-45OFAUF4-sg07qr0c.js +10 -0
- package/dist/gallery/frame/chunks/flowDiagram-UKHOOZJN-2e5ygs44.js +29 -0
- package/dist/gallery/frame/chunks/ganttDiagram-PKOTCBZU-p2hhh7hr.js +2620 -0
- package/dist/gallery/frame/chunks/gitGraph-TEB2WS4Q-j6kw0naa.js +10 -0
- package/dist/gallery/frame/chunks/gitGraphDiagram-DS77QQ5N-4z9z8wjm.js +1347 -0
- package/dist/gallery/frame/chunks/info-DKCQHKI2-mpt80jd3.js +10 -0
- package/dist/gallery/frame/chunks/infoDiagram-6WML65LV-5rqm3mgg.js +65 -0
- package/dist/gallery/frame/chunks/ishikawaDiagram-WSZJBQD7-b51z96jy.js +975 -0
- package/dist/gallery/frame/chunks/journeyDiagram-NVQOT4AX-9jbfp0pk.js +1272 -0
- package/dist/gallery/frame/chunks/kanban-definition-27J2QSJJ-4x0vx4se.js +1116 -0
- package/dist/gallery/frame/chunks/katex-xfgk95tv.js +14034 -0
- package/dist/gallery/frame/chunks/markdown-1s5vwkf2.js +9 -0
- package/dist/gallery/frame/chunks/markdown-2h6bwsms.js +3239 -0
- package/dist/gallery/frame/chunks/markdown-2x113yh8.js +107 -0
- package/dist/gallery/frame/chunks/markdown-30b7rwmp.js +1943 -0
- package/dist/gallery/frame/chunks/markdown-356bfj4g.js +2031 -0
- package/dist/gallery/frame/chunks/markdown-44n9ea69.js +2406 -0
- package/dist/gallery/frame/chunks/markdown-56enrf2r.js +39 -0
- package/dist/gallery/frame/chunks/markdown-5avymm8t.js +725 -0
- package/dist/gallery/frame/chunks/markdown-6r4svars.js +33 -0
- package/dist/gallery/frame/chunks/markdown-6zz8efx2.js +24 -0
- package/dist/gallery/frame/chunks/markdown-7jp6prnb.js +19 -0
- package/dist/gallery/frame/chunks/markdown-809k7q41.js +55 -0
- package/dist/gallery/frame/chunks/markdown-82xmzhzd.js +1076 -0
- package/dist/gallery/frame/chunks/markdown-92n37gd4.js +7627 -0
- package/dist/gallery/frame/chunks/markdown-ag2sssf8.js +36 -0
- package/dist/gallery/frame/chunks/markdown-b4s7ntq2.js +19 -0
- package/dist/gallery/frame/chunks/markdown-c9k0fvp1.js +100 -0
- package/dist/gallery/frame/chunks/markdown-ceefymn8.js +125 -0
- package/dist/gallery/frame/chunks/markdown-d1wfbs70.js +243 -0
- package/dist/gallery/frame/chunks/markdown-dy5sgjhc.js +11022 -0
- package/dist/gallery/frame/chunks/markdown-dz3z5w30.js +30868 -0
- package/dist/gallery/frame/chunks/markdown-eg6ngz7y.js +30340 -0
- package/dist/gallery/frame/chunks/markdown-ff5wvb43.js +1149 -0
- package/dist/gallery/frame/chunks/markdown-ffg06nfz.js +86 -0
- package/dist/gallery/frame/chunks/markdown-fvfncadf.js +472 -0
- package/dist/gallery/frame/chunks/markdown-gvyszqpv.js +19 -0
- package/dist/gallery/frame/chunks/markdown-gx1p0ew0.js +88 -0
- package/dist/gallery/frame/chunks/markdown-gxye5frz.js +65 -0
- package/dist/gallery/frame/chunks/markdown-h7pzv34e.js +105 -0
- package/dist/gallery/frame/chunks/markdown-hab789t9.js +47 -0
- package/dist/gallery/frame/chunks/markdown-hjp6sj8t.js +125 -0
- package/dist/gallery/frame/chunks/markdown-jka64qgp.js +1993 -0
- package/dist/gallery/frame/chunks/markdown-k8xkn8mw.js +56 -0
- package/dist/gallery/frame/chunks/markdown-m7frq8x8.js +112 -0
- package/dist/gallery/frame/chunks/markdown-p740v4qm.js +36 -0
- package/dist/gallery/frame/chunks/markdown-pxfeh231.js +57 -0
- package/dist/gallery/frame/chunks/markdown-pzgd8z3s.js +87 -0
- package/dist/gallery/frame/chunks/markdown-qx3cngz2.js +1673 -0
- package/dist/gallery/frame/chunks/markdown-rawhfvvc.js +85 -0
- package/dist/gallery/frame/chunks/markdown-rd8w0ng9.js +49 -0
- package/dist/gallery/frame/chunks/markdown-rm2yxfjj.js +2773 -0
- package/dist/gallery/frame/chunks/markdown-s1jatrnk.js +993 -0
- package/dist/gallery/frame/chunks/markdown-sgfg5vvq.js +59 -0
- package/dist/gallery/frame/chunks/markdown-t4ethv9d.js +409 -0
- package/dist/gallery/frame/chunks/markdown-tnmabqvz.js +36 -0
- package/dist/gallery/frame/chunks/markdown-tvdpppw8.js +5292 -0
- package/dist/gallery/frame/chunks/markdown-v0x27twr.js +22 -0
- package/dist/gallery/frame/chunks/markdown-v14td68x.js +36 -0
- package/dist/gallery/frame/chunks/markdown-w6sgd54z.js +36 -0
- package/dist/gallery/frame/chunks/markdown-xw8dsk8b.js +2125 -0
- package/dist/gallery/frame/chunks/markdown-y18mve73.js +85 -0
- package/dist/gallery/frame/chunks/markdown-yengsms5.js +427 -0
- package/dist/gallery/frame/chunks/markdown-z1wc0v0d.js +1826 -0
- package/dist/gallery/frame/chunks/markdown-zazx9h4n.js +329 -0
- package/dist/gallery/frame/chunks/mermaid-de7p4v0x.js +30 -0
- package/dist/gallery/frame/chunks/mindmap-definition-FAOFIHXS-ra44cbem.js +1216 -0
- package/dist/gallery/frame/chunks/packet-7NZHBO7P-xppm5913.js +10 -0
- package/dist/gallery/frame/chunks/pegDiagram-VL7TDLO6-a2a4wg03.js +163 -0
- package/dist/gallery/frame/chunks/pie-RZYD4A2V-hnbxk152.js +10 -0
- package/dist/gallery/frame/chunks/pieDiagram-7S7Q4E2Y-f1vxjtmx.js +311 -0
- package/dist/gallery/frame/chunks/quadrantDiagram-CIZ2JOQS-ywafa6kh.js +1390 -0
- package/dist/gallery/frame/chunks/radar-I7S5WNFK-ewqd27se.js +10 -0
- package/dist/gallery/frame/chunks/railroad-3IZDKUUU-5hy4bdx3.js +10 -0
- package/dist/gallery/frame/chunks/railroad-abnf-AHOZXSZD-bh5sxz0d.js +10 -0
- package/dist/gallery/frame/chunks/railroad-ebnf-EBAXGLYW-6b9c3zeh.js +10 -0
- package/dist/gallery/frame/chunks/railroad-peg-LSFZ7HO6-avc8v39s.js +10 -0
- package/dist/gallery/frame/chunks/railroadDiagram-AXF67PYL-qc61wax4.js +131 -0
- package/dist/gallery/frame/chunks/requirementDiagram-LRYGKXZP-9bs4786c.js +1295 -0
- package/dist/gallery/frame/chunks/sankeyDiagram-W5VNT64P-awt1em8b.js +1339 -0
- package/dist/gallery/frame/chunks/sequenceDiagram-SI44F4Z6-qaf9mz3t.js +4324 -0
- package/dist/gallery/frame/chunks/sizeCapture-X5ZJPWSS-9fq685xd.js +64 -0
- package/dist/gallery/frame/chunks/stateDiagram-OKZ733FA-vx7a7hh0.js +456 -0
- package/dist/gallery/frame/chunks/stateDiagram-v2-UEYNNEHI-x4m6ws5t.js +46 -0
- package/dist/gallery/frame/chunks/swimlanes-SLNWSIFB-e4mxm1gh.js +8287 -0
- package/dist/gallery/frame/chunks/swimlanesDiagram-ULZ7WXOC-0h93e2qq.js +42 -0
- package/dist/gallery/frame/chunks/timeline-definition-Z64GVDOM-wp0bhbzg.js +1549 -0
- package/dist/gallery/frame/chunks/treeView-QDETBFTQ-hcx7n0vt.js +10 -0
- package/dist/gallery/frame/chunks/treemap-6X3UGDF4-av02skdw.js +10 -0
- package/dist/gallery/frame/chunks/vennDiagram-T6HMQDX7-pmvk1p7n.js +2566 -0
- package/dist/gallery/frame/chunks/wardley-OPB4EBWU-njsp6e40.js +10 -0
- package/dist/gallery/frame/chunks/wardleyDiagram-T6FBY63Y-eggmnv4z.js +979 -0
- package/dist/gallery/frame/chunks/xychartDiagram-ELKLHX3M-q40tnpe5.js +1954 -0
- package/dist/gallery/frame/frame.css +183 -0
- package/dist/gallery/frame/runtime/chart.js +42744 -0
- package/dist/gallery/frame/runtime/html.js +14 -0
- package/dist/gallery/frame/runtime/markdown.js +1403 -0
- package/dist/gallery/frame/runtime/mermaid.js +32 -0
- package/dist/gallery/frame/runtime/svg.js +14 -0
- package/dist/gallery/frame/runtime/tsx.js +52 -0
- package/dist/gallery/index.html +104 -0
- package/docs/reference/cli.md +163 -0
- package/docs/reference/export.md +106 -0
- package/docs/reference/html.md +215 -0
- package/docs/reference/http.md +85 -0
- package/docs/reference/mcp.md +78 -0
- package/docs/reference/security.md +119 -0
- package/docs/reference/storage.md +93 -0
- package/docs/reference/tsx.md +101 -0
- package/docs/reference/validation.md +212 -0
- package/package.json +89 -0
- package/scripts/build-gallery.ts +127 -0
- package/scripts/launch-netns.sh +67 -0
- package/skills/facet/SKILL.md +100 -0
- package/src/cli/client.ts +311 -0
- package/src/cli/commands/create.ts +49 -0
- package/src/cli/commands/doctor.ts +249 -0
- package/src/cli/commands/export.ts +179 -0
- package/src/cli/commands/instantiate.ts +35 -0
- package/src/cli/commands/list.ts +49 -0
- package/src/cli/commands/open.ts +75 -0
- package/src/cli/commands/pin.ts +39 -0
- package/src/cli/commands/promote.ts +49 -0
- package/src/cli/commands/publish.ts +122 -0
- package/src/cli/commands/read-back.ts +56 -0
- package/src/cli/commands/status.ts +114 -0
- package/src/cli/commands/watch.ts +146 -0
- package/src/cli/main.ts +522 -0
- package/src/cli/output.ts +106 -0
- package/src/cli/parser.ts +376 -0
- package/src/cli/presenter.ts +212 -0
- package/src/cli/service-metadata.ts +134 -0
- package/src/cli/spawn-service.ts +326 -0
- package/src/css.d.ts +4 -0
- package/src/gallery-web/app.ts +1581 -0
- package/src/gallery-web/export-menu.ts +121 -0
- package/src/gallery-web/export.ts +112 -0
- package/src/gallery-web/favicon.ts +54 -0
- package/src/gallery-web/frame/entries/chart.ts +6 -0
- package/src/gallery-web/frame/entries/html.ts +6 -0
- package/src/gallery-web/frame/entries/markdown.ts +6 -0
- package/src/gallery-web/frame/entries/mermaid.ts +6 -0
- package/src/gallery-web/frame/entries/svg.ts +6 -0
- package/src/gallery-web/frame/entries/tsx.ts +6 -0
- package/src/gallery-web/frame/frame-payload.ts +91 -0
- package/src/gallery-web/frame/renderer-validation.ts +13 -0
- package/src/gallery-web/frame/renderers/chart.ts +182 -0
- package/src/gallery-web/frame/renderers/dompurify-shim.ts +112 -0
- package/src/gallery-web/frame/renderers/html.ts +48 -0
- package/src/gallery-web/frame/renderers/markdown.ts +81 -0
- package/src/gallery-web/frame/renderers/mermaid.ts +120 -0
- package/src/gallery-web/frame/renderers/registry.ts +260 -0
- package/src/gallery-web/frame/renderers/svg.ts +393 -0
- package/src/gallery-web/frame/renderers/tsx.ts +61 -0
- package/src/gallery-web/frame/runtime.ts +501 -0
- package/src/gallery-web/frame/styles/artifact.css +8424 -0
- package/src/gallery-web/frame/styles/frame.css +183 -0
- package/src/gallery-web/frame/styles/html-source.css +23 -0
- package/src/gallery-web/frame/view-box.ts +33 -0
- package/src/gallery-web/frame-html.ts +72 -0
- package/src/gallery-web/index.html +104 -0
- package/src/gallery-web/session.ts +107 -0
- package/src/gallery-web/sse-client.ts +212 -0
- package/src/gallery-web/styles/app.css +420 -0
- package/src/gallery-web/styles/tokens.css +112 -0
- package/src/gallery-web/styles/verdict.css +186 -0
- package/src/gallery-web/swap.ts +64 -0
- package/src/gallery-web/theme.ts +40 -0
- package/src/gallery-web/view-state.ts +93 -0
- package/src/harness-adapters/claude-code/README.md +10 -0
- package/src/harness-adapters/claude-code/facet.sh +4 -0
- package/src/harness-adapters/codex/README.md +10 -0
- package/src/harness-adapters/codex/facet.sh +4 -0
- package/src/harness-adapters/mcp/README.md +13 -0
- package/src/harness-adapters/mcp/cli-bridge.ts +216 -0
- package/src/harness-adapters/mcp/main.ts +15 -0
- package/src/harness-adapters/mcp/server.ts +164 -0
- package/src/harness-adapters/mcp/tool-schemas.ts +53 -0
- package/src/harness-adapters/opencode/README.md +10 -0
- package/src/harness-adapters/opencode/facet.sh +4 -0
- package/src/runtime/compiled-entrypoints.ts +69 -0
- package/src/service/dispatcher.ts +717 -0
- package/src/service/export.ts +218 -0
- package/src/service/http-utils.ts +55 -0
- package/src/service/lexical/expectations.ts +210 -0
- package/src/service/lifecycle/idle-controller.ts +125 -0
- package/src/service/lifecycle/orphan-cleanup.ts +128 -0
- package/src/service/lifecycle/process-lock.ts +235 -0
- package/src/service/main.ts +136 -0
- package/src/service/process.ts +240 -0
- package/src/service/router-guards.ts +239 -0
- package/src/service/router.ts +627 -0
- package/src/service/security/auth.ts +168 -0
- package/src/service/security/host-origin.ts +138 -0
- package/src/service/security/http-guards.ts +13 -0
- package/src/service/security/leases.ts +182 -0
- package/src/service/security/token-store.ts +138 -0
- package/src/service/server.ts +356 -0
- package/src/service/store/database.ts +61 -0
- package/src/service/store/evidence-retention.ts +234 -0
- package/src/service/store/migrations.ts +167 -0
- package/src/service/store/repository-lifecycle.ts +121 -0
- package/src/service/store/repository.ts +732 -0
- package/src/service/store/schema.ts +218 -0
- package/src/service/stored-verdict.ts +97 -0
- package/src/service/stream.ts +301 -0
- package/src/service/verdict-enrichment.ts +45 -0
- package/src/shared/build/frame-bundle-plugins.ts +61 -0
- package/src/shared/build-mode.ts +28 -0
- package/src/shared/config/evidence-read.ts +98 -0
- package/src/shared/config/limits.ts +56 -0
- package/src/shared/config/paths.ts +96 -0
- package/src/shared/contracts/artifact-types.ts +2 -0
- package/src/shared/contracts/artifact.ts +98 -0
- package/src/shared/contracts/commands/_shared.ts +59 -0
- package/src/shared/contracts/commands/guards.ts +86 -0
- package/src/shared/contracts/commands/index.ts +204 -0
- package/src/shared/contracts/commands/names.ts +35 -0
- package/src/shared/contracts/commands/requests.ts +149 -0
- package/src/shared/contracts/commands/results.ts +200 -0
- package/src/shared/contracts/envelope.ts +140 -0
- package/src/shared/contracts/events.ts +41 -0
- package/src/shared/contracts/observed-counts.ts +19 -0
- package/src/shared/contracts/renderers.ts +6 -0
- package/src/shared/contracts/validation.ts +296 -0
- package/src/shared/errors/facet-error.ts +127 -0
- package/src/shared/errors/store-error.ts +68 -0
- package/src/shared/evidence-image.ts +37 -0
- package/src/shared/export.ts +31 -0
- package/src/shared/html/policy.ts +108 -0
- package/src/shared/html/style-vocabulary.ts +352 -0
- package/src/shared/logging/logger.ts +108 -0
- package/src/shared/logging/redact.ts +49 -0
- package/src/shared/security/frozen-csp.ts +13 -0
- package/src/shared/storage-version.ts +2 -0
- package/src/shared/tsx/execution.ts +29 -0
- package/src/shared/tsx/import-policy.ts +94 -0
- package/src/shared/util/dir-permissions.ts +94 -0
- package/src/shared/util/mermaid-nodes.ts +230 -0
- package/src/shared/util/process.ts +67 -0
- package/src/shared/util/time.ts +21 -0
- package/src/shared/version.ts +3 -0
- package/src/validation/sandbox/limits.ts +41 -0
- package/src/validation/sandbox/netns.ts +177 -0
- package/src/validation/tier0/chart.ts +177 -0
- package/src/validation/tier0/dom-shim.ts +54 -0
- package/src/validation/tier0/html.ts +408 -0
- package/src/validation/tier0/markdown.ts +285 -0
- package/src/validation/tier0/mermaid.ts +98 -0
- package/src/validation/tier0/runner.ts +504 -0
- package/src/validation/tier0/svg.ts +321 -0
- package/src/validation/tier0/tsx/allowlist-resolver.ts +77 -0
- package/src/validation/tier0/tsx/ast-policy-capabilities.ts +238 -0
- package/src/validation/tier0/tsx/ast-policy-shared.ts +71 -0
- package/src/validation/tier0/tsx/ast-policy.ts +181 -0
- package/src/validation/tier0/tsx/compiler.ts +156 -0
- package/src/validation/tier0/worker-dispatch.ts +211 -0
- package/src/validation/tier0/worker-entry.ts +96 -0
- package/src/validation/tier0/worker-input.ts +75 -0
- package/src/validation/tier1/browser-process.ts +147 -0
- package/src/validation/tier1/cdp-pipe.ts +281 -0
- package/src/validation/tier1/entries/chart.ts +5 -0
- package/src/validation/tier1/entries/html.ts +6 -0
- package/src/validation/tier1/entries/markdown.ts +5 -0
- package/src/validation/tier1/entries/mermaid.ts +5 -0
- package/src/validation/tier1/entries/svg.ts +5 -0
- package/src/validation/tier1/entries/tsx.ts +5 -0
- package/src/validation/tier1/frame-target.ts +162 -0
- package/src/validation/tier1/harness-entry.ts +261 -0
- package/src/validation/tier1/harness.ts +215 -0
- package/src/validation/tier1/isolated-probe.ts +94 -0
- package/src/validation/tier1/launcher.ts +177 -0
- package/src/validation/tier1/limits.ts +80 -0
- package/src/validation/tier1/nonce.ts +17 -0
- package/src/validation/tier1/protocol-probe.ts +519 -0
- package/src/validation/tier1/runner.ts +1122 -0
- package/src/validation/tier1/verdict.ts +246 -0
- package/src/validation/tier1/webp.ts +69 -0
- package/templates/README.md +88 -0
- package/templates/bar-compare.vl.json +63 -0
- package/templates/capacity-report.tsx +102 -0
- package/templates/decision-record.md +24 -0
- package/templates/deployment-state.mmd +40 -0
- package/templates/exemplar.md +91 -0
- package/templates/facet-story.tsx +799 -0
- package/templates/fleet-dashboard.html +141 -0
- package/templates/html-release-ledger.html +91 -0
- package/templates/html-status-report.html +114 -0
- package/templates/incident-console.tsx +147 -0
- package/templates/legion-boundaries.mmd +23 -0
- package/templates/legion-flow.mmd +15 -0
- package/templates/legion-sequence.mmd +14 -0
- package/templates/legion-state.mmd +7 -0
- package/templates/metric-card.svg +29 -0
- package/templates/observability-map.svg +101 -0
- package/templates/pipeline-audit.md +108 -0
- package/templates/release-metrics.vl.json +98 -0
- package/templates/service-topology.mmd +47 -0
- package/templates/status-report.md +32 -0
- package/templates/system-map.svg +53 -0
- package/templates/timeseries.vl.json +71 -0
- package/templates/tsx-interactive-counter.tsx +19 -0
- package/templates/tsx-status-report.tsx +31 -0
|
@@ -0,0 +1,725 @@
|
|
|
1
|
+
import {
|
|
2
|
+
selectSvgElement
|
|
3
|
+
} from "./markdown-6zz8efx2.js";
|
|
4
|
+
import {
|
|
5
|
+
clear,
|
|
6
|
+
configureSvgSize,
|
|
7
|
+
getConfig,
|
|
8
|
+
getConfig2,
|
|
9
|
+
getThemeVariables3,
|
|
10
|
+
sanitizeText
|
|
11
|
+
} from "./markdown-92n37gd4.js";
|
|
12
|
+
import {
|
|
13
|
+
log
|
|
14
|
+
} from "./markdown-xw8dsk8b.js";
|
|
15
|
+
import {
|
|
16
|
+
__name
|
|
17
|
+
} from "./markdown-1s5vwkf2.js";
|
|
18
|
+
|
|
19
|
+
// node_modules/mermaid/dist/chunks/mermaid.core/chunk-6Q2QTUOP.mjs
|
|
20
|
+
var diagramTitle = "";
|
|
21
|
+
var accTitle = "";
|
|
22
|
+
var accDescription = "";
|
|
23
|
+
var rules = [];
|
|
24
|
+
var ruleMap = /* @__PURE__ */ new Map;
|
|
25
|
+
var sanitizeText2 = /* @__PURE__ */ __name((text) => {
|
|
26
|
+
return sanitizeText(text, getConfig2());
|
|
27
|
+
}, "sanitizeText");
|
|
28
|
+
var sanitizeAstNode = /* @__PURE__ */ __name((node) => {
|
|
29
|
+
switch (node.type) {
|
|
30
|
+
case "terminal":
|
|
31
|
+
return { ...node, value: sanitizeText2(node.value) };
|
|
32
|
+
case "nonterminal":
|
|
33
|
+
return { ...node, name: sanitizeText2(node.name) };
|
|
34
|
+
case "sequence":
|
|
35
|
+
return { ...node, elements: node.elements.map(sanitizeAstNode) };
|
|
36
|
+
case "choice":
|
|
37
|
+
return { ...node, alternatives: node.alternatives.map(sanitizeAstNode) };
|
|
38
|
+
case "optional":
|
|
39
|
+
return { ...node, element: sanitizeAstNode(node.element) };
|
|
40
|
+
case "repetition":
|
|
41
|
+
return {
|
|
42
|
+
...node,
|
|
43
|
+
element: sanitizeAstNode(node.element),
|
|
44
|
+
separator: node.separator ? sanitizeAstNode(node.separator) : undefined
|
|
45
|
+
};
|
|
46
|
+
case "special":
|
|
47
|
+
return { ...node, text: sanitizeText2(node.text) };
|
|
48
|
+
}
|
|
49
|
+
}, "sanitizeAstNode");
|
|
50
|
+
var clear2 = /* @__PURE__ */ __name(() => {
|
|
51
|
+
diagramTitle = "";
|
|
52
|
+
accTitle = "";
|
|
53
|
+
accDescription = "";
|
|
54
|
+
rules.length = 0;
|
|
55
|
+
ruleMap.clear();
|
|
56
|
+
clear();
|
|
57
|
+
log.debug("[Railroad] Database cleared");
|
|
58
|
+
}, "clear");
|
|
59
|
+
var setTitle = /* @__PURE__ */ __name((text) => {
|
|
60
|
+
diagramTitle = sanitizeText2(text);
|
|
61
|
+
log.debug("[Railroad] Title set:", text);
|
|
62
|
+
}, "setTitle");
|
|
63
|
+
var getTitle = /* @__PURE__ */ __name(() => {
|
|
64
|
+
return diagramTitle;
|
|
65
|
+
}, "getTitle");
|
|
66
|
+
var addRule = /* @__PURE__ */ __name((rule) => {
|
|
67
|
+
const sanitizedRule = {
|
|
68
|
+
...rule,
|
|
69
|
+
name: sanitizeText2(rule.name),
|
|
70
|
+
definition: sanitizeAstNode(rule.definition),
|
|
71
|
+
comment: rule.comment ? sanitizeText2(rule.comment) : undefined
|
|
72
|
+
};
|
|
73
|
+
log.debug("[Railroad] Adding rule:", sanitizedRule.name);
|
|
74
|
+
if (ruleMap.has(sanitizedRule.name)) {
|
|
75
|
+
log.warn(`[Railroad] Rule '${sanitizedRule.name}' is already defined. Overwriting.`);
|
|
76
|
+
}
|
|
77
|
+
rules.push(sanitizedRule);
|
|
78
|
+
ruleMap.set(sanitizedRule.name, sanitizedRule);
|
|
79
|
+
}, "addRule");
|
|
80
|
+
var getRules = /* @__PURE__ */ __name(() => {
|
|
81
|
+
return rules;
|
|
82
|
+
}, "getRules");
|
|
83
|
+
var getRule = /* @__PURE__ */ __name((name) => {
|
|
84
|
+
return ruleMap.get(name);
|
|
85
|
+
}, "getRule");
|
|
86
|
+
var setAccTitle = /* @__PURE__ */ __name((text) => {
|
|
87
|
+
accTitle = sanitizeText2(text).replace(/^\s+/g, "");
|
|
88
|
+
log.debug("[Railroad] Accessibility title set:", text);
|
|
89
|
+
}, "setAccTitle");
|
|
90
|
+
var getAccTitle = /* @__PURE__ */ __name(() => {
|
|
91
|
+
return accTitle;
|
|
92
|
+
}, "getAccTitle");
|
|
93
|
+
var setAccDescription = /* @__PURE__ */ __name((text) => {
|
|
94
|
+
accDescription = sanitizeText2(text).replace(/\n\s+/g, `
|
|
95
|
+
`);
|
|
96
|
+
log.debug("[Railroad] Accessibility description set:", text);
|
|
97
|
+
}, "setAccDescription");
|
|
98
|
+
var getAccDescription = /* @__PURE__ */ __name(() => {
|
|
99
|
+
return accDescription;
|
|
100
|
+
}, "getAccDescription");
|
|
101
|
+
var setDiagramTitle = setTitle;
|
|
102
|
+
var getDiagramTitle = getTitle;
|
|
103
|
+
var db = {
|
|
104
|
+
clear: clear2,
|
|
105
|
+
setTitle,
|
|
106
|
+
getTitle,
|
|
107
|
+
addRule,
|
|
108
|
+
getRules,
|
|
109
|
+
getRule,
|
|
110
|
+
setAccTitle,
|
|
111
|
+
getAccTitle,
|
|
112
|
+
setAccDescription,
|
|
113
|
+
getAccDescription,
|
|
114
|
+
setDiagramTitle,
|
|
115
|
+
getDiagramTitle
|
|
116
|
+
};
|
|
117
|
+
var DEFAULT_RAILROAD_CONFIG = {
|
|
118
|
+
compactMode: false,
|
|
119
|
+
padding: 10,
|
|
120
|
+
verticalSeparation: 8,
|
|
121
|
+
horizontalSeparation: 10,
|
|
122
|
+
arcRadius: 10,
|
|
123
|
+
fontSize: 14,
|
|
124
|
+
fontFamily: "monospace",
|
|
125
|
+
terminalFill: "#FFFFC0",
|
|
126
|
+
terminalStroke: "#000000",
|
|
127
|
+
terminalTextColor: "#000000",
|
|
128
|
+
nonTerminalFill: "#FFFFFF",
|
|
129
|
+
nonTerminalStroke: "#000000",
|
|
130
|
+
nonTerminalTextColor: "#000000",
|
|
131
|
+
lineColor: "#000000",
|
|
132
|
+
strokeWidth: 2,
|
|
133
|
+
markerFill: "#000000",
|
|
134
|
+
commentFill: "#E8E8E8",
|
|
135
|
+
commentStroke: "#888888",
|
|
136
|
+
commentTextColor: "#666666",
|
|
137
|
+
specialFill: "#F0E0FF",
|
|
138
|
+
specialStroke: "#8800CC",
|
|
139
|
+
ruleNameColor: "#000066",
|
|
140
|
+
showMarkers: true,
|
|
141
|
+
markerRadius: 5
|
|
142
|
+
};
|
|
143
|
+
var COLOR_VALUE_PATTERN = /^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$|^(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch)\([\d\s%+,./-]+\)$|^[a-z]+$/i;
|
|
144
|
+
var FONT_FAMILY_PATTERN = /^[\w "',.-]+$/;
|
|
145
|
+
var RAILROAD_STYLE_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
146
|
+
"compactMode",
|
|
147
|
+
"padding",
|
|
148
|
+
"verticalSeparation",
|
|
149
|
+
"horizontalSeparation",
|
|
150
|
+
"arcRadius",
|
|
151
|
+
"fontSize",
|
|
152
|
+
"fontFamily",
|
|
153
|
+
"terminalFill",
|
|
154
|
+
"terminalStroke",
|
|
155
|
+
"terminalTextColor",
|
|
156
|
+
"nonTerminalFill",
|
|
157
|
+
"nonTerminalStroke",
|
|
158
|
+
"nonTerminalTextColor",
|
|
159
|
+
"lineColor",
|
|
160
|
+
"strokeWidth",
|
|
161
|
+
"markerFill",
|
|
162
|
+
"commentFill",
|
|
163
|
+
"commentStroke",
|
|
164
|
+
"commentTextColor",
|
|
165
|
+
"specialFill",
|
|
166
|
+
"specialStroke",
|
|
167
|
+
"ruleNameColor",
|
|
168
|
+
"showMarkers",
|
|
169
|
+
"markerRadius"
|
|
170
|
+
]);
|
|
171
|
+
var isRailroadStyleOptions = /* @__PURE__ */ __name((options) => {
|
|
172
|
+
if (!options) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return Object.keys(options).every((key) => key === "railroad" || RAILROAD_STYLE_OPTION_KEYS.has(key));
|
|
176
|
+
}, "isRailroadStyleOptions");
|
|
177
|
+
var extractRailroadOverrides = /* @__PURE__ */ __name((options) => {
|
|
178
|
+
if (!options) {
|
|
179
|
+
return {};
|
|
180
|
+
}
|
|
181
|
+
if ("railroad" in options && options.railroad) {
|
|
182
|
+
return options.railroad;
|
|
183
|
+
}
|
|
184
|
+
return isRailroadStyleOptions(options) ? options : {};
|
|
185
|
+
}, "extractRailroadOverrides");
|
|
186
|
+
var extractThemeOverrides = /* @__PURE__ */ __name((options) => {
|
|
187
|
+
if (!options || isRailroadStyleOptions(options)) {
|
|
188
|
+
return {};
|
|
189
|
+
}
|
|
190
|
+
const {
|
|
191
|
+
railroad: _railroad,
|
|
192
|
+
svgId: _svgId,
|
|
193
|
+
theme: _theme,
|
|
194
|
+
look: _look,
|
|
195
|
+
...themeOverrides
|
|
196
|
+
} = options;
|
|
197
|
+
return themeOverrides;
|
|
198
|
+
}, "extractThemeOverrides");
|
|
199
|
+
var sanitizeColorValue = /* @__PURE__ */ __name((value, fallback) => {
|
|
200
|
+
if (typeof value !== "string") {
|
|
201
|
+
return fallback;
|
|
202
|
+
}
|
|
203
|
+
const normalized = value.trim();
|
|
204
|
+
return COLOR_VALUE_PATTERN.test(normalized) ? normalized : fallback;
|
|
205
|
+
}, "sanitizeColorValue");
|
|
206
|
+
var sanitizeFontFamilyValue = /* @__PURE__ */ __name((value, fallback) => {
|
|
207
|
+
if (typeof value !== "string") {
|
|
208
|
+
return fallback;
|
|
209
|
+
}
|
|
210
|
+
const normalized = value.trim();
|
|
211
|
+
return FONT_FAMILY_PATTERN.test(normalized) ? normalized : fallback;
|
|
212
|
+
}, "sanitizeFontFamilyValue");
|
|
213
|
+
var sanitizeNumberValue = /* @__PURE__ */ __name((value, fallback) => {
|
|
214
|
+
const parsed = typeof value === "number" ? value : typeof value === "string" ? Number.parseFloat(value) : Number.NaN;
|
|
215
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;
|
|
216
|
+
}, "sanitizeNumberValue");
|
|
217
|
+
var parseThemeFontSize = /* @__PURE__ */ __name((value) => {
|
|
218
|
+
const parsed = typeof value === "number" ? value : typeof value === "string" ? Number.parseFloat(value) : Number.NaN;
|
|
219
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
|
|
220
|
+
}, "parseThemeFontSize");
|
|
221
|
+
var buildThemeDefaults = /* @__PURE__ */ __name((themeVariables) => {
|
|
222
|
+
const fontFamily = sanitizeFontFamilyValue(themeVariables.fontFamily, DEFAULT_RAILROAD_CONFIG.fontFamily);
|
|
223
|
+
const fontSize = parseThemeFontSize(themeVariables.fontSize) ?? DEFAULT_RAILROAD_CONFIG.fontSize;
|
|
224
|
+
return {
|
|
225
|
+
...DEFAULT_RAILROAD_CONFIG,
|
|
226
|
+
fontFamily,
|
|
227
|
+
fontSize,
|
|
228
|
+
terminalFill: sanitizeColorValue(themeVariables.secondBkg ?? themeVariables.secondaryColor, DEFAULT_RAILROAD_CONFIG.terminalFill),
|
|
229
|
+
terminalStroke: sanitizeColorValue(themeVariables.secondaryBorderColor ?? themeVariables.lineColor, DEFAULT_RAILROAD_CONFIG.terminalStroke),
|
|
230
|
+
terminalTextColor: sanitizeColorValue(themeVariables.secondaryTextColor ?? themeVariables.textColor, DEFAULT_RAILROAD_CONFIG.terminalTextColor),
|
|
231
|
+
nonTerminalFill: sanitizeColorValue(themeVariables.mainBkg ?? themeVariables.background, DEFAULT_RAILROAD_CONFIG.nonTerminalFill),
|
|
232
|
+
nonTerminalStroke: sanitizeColorValue(themeVariables.primaryBorderColor ?? themeVariables.lineColor, DEFAULT_RAILROAD_CONFIG.nonTerminalStroke),
|
|
233
|
+
nonTerminalTextColor: sanitizeColorValue(themeVariables.primaryTextColor ?? themeVariables.textColor, DEFAULT_RAILROAD_CONFIG.nonTerminalTextColor),
|
|
234
|
+
lineColor: sanitizeColorValue(themeVariables.lineColor, DEFAULT_RAILROAD_CONFIG.lineColor),
|
|
235
|
+
markerFill: sanitizeColorValue(themeVariables.lineColor, DEFAULT_RAILROAD_CONFIG.markerFill),
|
|
236
|
+
commentFill: sanitizeColorValue(themeVariables.labelBackground ?? themeVariables.tertiaryColor, DEFAULT_RAILROAD_CONFIG.commentFill),
|
|
237
|
+
commentStroke: sanitizeColorValue(themeVariables.tertiaryBorderColor ?? themeVariables.lineColor, DEFAULT_RAILROAD_CONFIG.commentStroke),
|
|
238
|
+
commentTextColor: sanitizeColorValue(themeVariables.tertiaryTextColor ?? themeVariables.textColor, DEFAULT_RAILROAD_CONFIG.commentTextColor),
|
|
239
|
+
specialFill: sanitizeColorValue(themeVariables.tertiaryColor ?? themeVariables.secondaryColor, DEFAULT_RAILROAD_CONFIG.specialFill),
|
|
240
|
+
specialStroke: sanitizeColorValue(themeVariables.tertiaryBorderColor ?? themeVariables.secondaryBorderColor, DEFAULT_RAILROAD_CONFIG.specialStroke),
|
|
241
|
+
ruleNameColor: sanitizeColorValue(themeVariables.titleColor ?? themeVariables.textColor, DEFAULT_RAILROAD_CONFIG.ruleNameColor)
|
|
242
|
+
};
|
|
243
|
+
}, "buildThemeDefaults");
|
|
244
|
+
var buildRailroadStyleOptions = /* @__PURE__ */ __name((options) => {
|
|
245
|
+
const currentConfig = getConfig();
|
|
246
|
+
const themeVariables = {
|
|
247
|
+
...getThemeVariables3(),
|
|
248
|
+
...currentConfig.themeVariables ?? {},
|
|
249
|
+
...extractThemeOverrides(options)
|
|
250
|
+
};
|
|
251
|
+
const themeDefaults = buildThemeDefaults(themeVariables);
|
|
252
|
+
const railroadOptions = {
|
|
253
|
+
...currentConfig.railroad ?? {},
|
|
254
|
+
...extractRailroadOverrides(options)
|
|
255
|
+
};
|
|
256
|
+
return {
|
|
257
|
+
compactMode: railroadOptions.compactMode ?? themeDefaults.compactMode,
|
|
258
|
+
padding: sanitizeNumberValue(railroadOptions.padding, themeDefaults.padding),
|
|
259
|
+
verticalSeparation: sanitizeNumberValue(railroadOptions.verticalSeparation, themeDefaults.verticalSeparation),
|
|
260
|
+
horizontalSeparation: sanitizeNumberValue(railroadOptions.horizontalSeparation, themeDefaults.horizontalSeparation),
|
|
261
|
+
arcRadius: sanitizeNumberValue(railroadOptions.arcRadius, themeDefaults.arcRadius),
|
|
262
|
+
fontSize: sanitizeNumberValue(railroadOptions.fontSize, themeDefaults.fontSize),
|
|
263
|
+
fontFamily: sanitizeFontFamilyValue(railroadOptions.fontFamily, themeDefaults.fontFamily),
|
|
264
|
+
terminalFill: sanitizeColorValue(railroadOptions.terminalFill, themeDefaults.terminalFill),
|
|
265
|
+
terminalStroke: sanitizeColorValue(railroadOptions.terminalStroke, themeDefaults.terminalStroke),
|
|
266
|
+
terminalTextColor: sanitizeColorValue(railroadOptions.terminalTextColor, themeDefaults.terminalTextColor),
|
|
267
|
+
nonTerminalFill: sanitizeColorValue(railroadOptions.nonTerminalFill, themeDefaults.nonTerminalFill),
|
|
268
|
+
nonTerminalStroke: sanitizeColorValue(railroadOptions.nonTerminalStroke, themeDefaults.nonTerminalStroke),
|
|
269
|
+
nonTerminalTextColor: sanitizeColorValue(railroadOptions.nonTerminalTextColor, themeDefaults.nonTerminalTextColor),
|
|
270
|
+
lineColor: sanitizeColorValue(railroadOptions.lineColor, themeDefaults.lineColor),
|
|
271
|
+
strokeWidth: sanitizeNumberValue(railroadOptions.strokeWidth, themeDefaults.strokeWidth),
|
|
272
|
+
markerFill: sanitizeColorValue(railroadOptions.markerFill, themeDefaults.markerFill),
|
|
273
|
+
commentFill: sanitizeColorValue(railroadOptions.commentFill, themeDefaults.commentFill),
|
|
274
|
+
commentStroke: sanitizeColorValue(railroadOptions.commentStroke, themeDefaults.commentStroke),
|
|
275
|
+
commentTextColor: sanitizeColorValue(railroadOptions.commentTextColor, themeDefaults.commentTextColor),
|
|
276
|
+
specialFill: sanitizeColorValue(railroadOptions.specialFill, themeDefaults.specialFill),
|
|
277
|
+
specialStroke: sanitizeColorValue(railroadOptions.specialStroke, themeDefaults.specialStroke),
|
|
278
|
+
ruleNameColor: sanitizeColorValue(railroadOptions.ruleNameColor, themeDefaults.ruleNameColor),
|
|
279
|
+
showMarkers: railroadOptions.showMarkers ?? themeDefaults.showMarkers,
|
|
280
|
+
markerRadius: sanitizeNumberValue(railroadOptions.markerRadius, themeDefaults.markerRadius)
|
|
281
|
+
};
|
|
282
|
+
}, "buildRailroadStyleOptions");
|
|
283
|
+
var getStyles = /* @__PURE__ */ __name((options) => {
|
|
284
|
+
const {
|
|
285
|
+
fontFamily,
|
|
286
|
+
fontSize,
|
|
287
|
+
terminalFill,
|
|
288
|
+
terminalStroke,
|
|
289
|
+
terminalTextColor,
|
|
290
|
+
nonTerminalFill,
|
|
291
|
+
nonTerminalStroke,
|
|
292
|
+
nonTerminalTextColor,
|
|
293
|
+
lineColor,
|
|
294
|
+
strokeWidth,
|
|
295
|
+
markerFill,
|
|
296
|
+
commentFill,
|
|
297
|
+
commentStroke,
|
|
298
|
+
commentTextColor,
|
|
299
|
+
specialFill,
|
|
300
|
+
specialStroke,
|
|
301
|
+
ruleNameColor
|
|
302
|
+
} = buildRailroadStyleOptions(options);
|
|
303
|
+
return `
|
|
304
|
+
.railroad-diagram {
|
|
305
|
+
font-family: ${fontFamily};
|
|
306
|
+
font-size: ${fontSize}px;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
.railroad-terminal rect {
|
|
310
|
+
fill: ${terminalFill};
|
|
311
|
+
stroke: ${terminalStroke};
|
|
312
|
+
stroke-width: ${strokeWidth}px;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
.railroad-terminal text {
|
|
316
|
+
fill: ${terminalTextColor};
|
|
317
|
+
font-family: ${fontFamily};
|
|
318
|
+
font-size: ${fontSize}px;
|
|
319
|
+
text-anchor: middle;
|
|
320
|
+
dominant-baseline: middle;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
.railroad-nonterminal rect {
|
|
324
|
+
fill: ${nonTerminalFill};
|
|
325
|
+
stroke: ${nonTerminalStroke};
|
|
326
|
+
stroke-width: ${strokeWidth}px;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.railroad-nonterminal text {
|
|
330
|
+
fill: ${nonTerminalTextColor};
|
|
331
|
+
font-family: ${fontFamily};
|
|
332
|
+
font-size: ${fontSize}px;
|
|
333
|
+
text-anchor: middle;
|
|
334
|
+
dominant-baseline: middle;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
.railroad-line {
|
|
338
|
+
stroke: ${lineColor};
|
|
339
|
+
stroke-width: ${strokeWidth}px;
|
|
340
|
+
fill: none;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
.railroad-start circle,
|
|
344
|
+
.railroad-end circle {
|
|
345
|
+
fill: ${markerFill};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
.railroad-comment ellipse {
|
|
349
|
+
fill: ${commentFill};
|
|
350
|
+
stroke: ${commentStroke};
|
|
351
|
+
stroke-width: ${strokeWidth}px;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
.railroad-comment text {
|
|
355
|
+
fill: ${commentTextColor};
|
|
356
|
+
font-style: italic;
|
|
357
|
+
font-family: ${fontFamily};
|
|
358
|
+
font-size: ${fontSize}px;
|
|
359
|
+
text-anchor: middle;
|
|
360
|
+
dominant-baseline: middle;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
.railroad-special rect {
|
|
364
|
+
fill: ${specialFill};
|
|
365
|
+
stroke: ${specialStroke};
|
|
366
|
+
stroke-width: ${strokeWidth}px;
|
|
367
|
+
stroke-dasharray: 5,3;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
.railroad-special text {
|
|
371
|
+
fill: ${nonTerminalTextColor};
|
|
372
|
+
font-family: ${fontFamily};
|
|
373
|
+
font-size: ${fontSize}px;
|
|
374
|
+
text-anchor: middle;
|
|
375
|
+
dominant-baseline: middle;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
.railroad-rule-name {
|
|
379
|
+
font-weight: bold;
|
|
380
|
+
fill: ${ruleNameColor};
|
|
381
|
+
font-family: ${fontFamily};
|
|
382
|
+
font-size: ${fontSize}px;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
.railroad-group {
|
|
386
|
+
/* Grouping container, no specific styles */
|
|
387
|
+
}
|
|
388
|
+
`;
|
|
389
|
+
}, "getStyles");
|
|
390
|
+
var PathBuilder = class {
|
|
391
|
+
constructor() {
|
|
392
|
+
this.d = "";
|
|
393
|
+
}
|
|
394
|
+
static {
|
|
395
|
+
__name(this, "PathBuilder");
|
|
396
|
+
}
|
|
397
|
+
moveTo(x, y) {
|
|
398
|
+
this.d += `M ${x} ${y} `;
|
|
399
|
+
return this;
|
|
400
|
+
}
|
|
401
|
+
lineTo(x, y) {
|
|
402
|
+
this.d += `L ${x} ${y} `;
|
|
403
|
+
return this;
|
|
404
|
+
}
|
|
405
|
+
horizontalTo(x) {
|
|
406
|
+
this.d += `H ${x} `;
|
|
407
|
+
return this;
|
|
408
|
+
}
|
|
409
|
+
verticalTo(y) {
|
|
410
|
+
this.d += `V ${y} `;
|
|
411
|
+
return this;
|
|
412
|
+
}
|
|
413
|
+
arcTo(rx, ry, rotation, largeArc, sweep, x, y) {
|
|
414
|
+
this.d += `A ${rx} ${ry} ${rotation} ${largeArc ? 1 : 0} ${sweep ? 1 : 0} ${x} ${y} `;
|
|
415
|
+
return this;
|
|
416
|
+
}
|
|
417
|
+
build() {
|
|
418
|
+
return this.d.trim();
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
var RailroadRenderer = class {
|
|
422
|
+
constructor(svg, config = buildRailroadStyleOptions()) {
|
|
423
|
+
this.textCache = /* @__PURE__ */ new Map;
|
|
424
|
+
this.svg = svg;
|
|
425
|
+
this.config = config;
|
|
426
|
+
}
|
|
427
|
+
static {
|
|
428
|
+
__name(this, "RailroadRenderer");
|
|
429
|
+
}
|
|
430
|
+
measureText(text) {
|
|
431
|
+
if (this.textCache.has(text)) {
|
|
432
|
+
return this.textCache.get(text);
|
|
433
|
+
}
|
|
434
|
+
const tempText = this.svg.append("text").attr("font-family", this.config.fontFamily).attr("font-size", this.config.fontSize).text(text);
|
|
435
|
+
const bbox = tempText.node().getBBox();
|
|
436
|
+
const dimensions = { width: bbox.width, height: bbox.height };
|
|
437
|
+
tempText.remove();
|
|
438
|
+
this.textCache.set(text, dimensions);
|
|
439
|
+
return dimensions;
|
|
440
|
+
}
|
|
441
|
+
renderTerminal(parent, value) {
|
|
442
|
+
const textDim = this.measureText(value);
|
|
443
|
+
const width = textDim.width + this.config.padding * 2;
|
|
444
|
+
const height = textDim.height + this.config.padding * 2;
|
|
445
|
+
const group = parent.append("g").attr("class", "railroad-terminal");
|
|
446
|
+
group.append("rect").attr("x", 0).attr("y", 0).attr("width", width).attr("height", height).attr("rx", 10).attr("ry", 10);
|
|
447
|
+
group.append("text").attr("x", width / 2).attr("y", height / 2).text(value);
|
|
448
|
+
return {
|
|
449
|
+
element: group.node(),
|
|
450
|
+
dimensions: {
|
|
451
|
+
width,
|
|
452
|
+
height,
|
|
453
|
+
up: height / 2,
|
|
454
|
+
down: height / 2
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
renderNonTerminal(parent, name) {
|
|
459
|
+
const textDim = this.measureText(name);
|
|
460
|
+
const width = textDim.width + this.config.padding * 2;
|
|
461
|
+
const height = textDim.height + this.config.padding * 2;
|
|
462
|
+
const group = parent.append("g").attr("class", "railroad-nonterminal");
|
|
463
|
+
group.append("rect").attr("x", 0).attr("y", 0).attr("width", width).attr("height", height);
|
|
464
|
+
group.append("text").attr("x", width / 2).attr("y", height / 2).text(name);
|
|
465
|
+
return {
|
|
466
|
+
element: group.node(),
|
|
467
|
+
dimensions: {
|
|
468
|
+
width,
|
|
469
|
+
height,
|
|
470
|
+
up: height / 2,
|
|
471
|
+
down: height / 2
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
renderSequence(parent, elements) {
|
|
476
|
+
const rendered = elements.map((e) => this.renderExpression(parent, e));
|
|
477
|
+
let totalWidth = 0;
|
|
478
|
+
let maxUp = 0;
|
|
479
|
+
let maxDown = 0;
|
|
480
|
+
for (const r of rendered) {
|
|
481
|
+
totalWidth += r.dimensions.width;
|
|
482
|
+
maxUp = Math.max(maxUp, r.dimensions.up);
|
|
483
|
+
maxDown = Math.max(maxDown, r.dimensions.down);
|
|
484
|
+
}
|
|
485
|
+
totalWidth += (rendered.length - 1) * this.config.horizontalSeparation;
|
|
486
|
+
const group = parent.append("g").attr("class", "railroad-sequence");
|
|
487
|
+
let x = 0;
|
|
488
|
+
for (let i = 0;i < rendered.length; i++) {
|
|
489
|
+
const r = rendered[i];
|
|
490
|
+
const y = maxUp - r.dimensions.up;
|
|
491
|
+
const elem = group.node().appendChild(r.element);
|
|
492
|
+
elem.setAttribute("transform", `translate(${x}, ${y})`);
|
|
493
|
+
if (i < rendered.length - 1) {
|
|
494
|
+
const lineX1 = x + r.dimensions.width;
|
|
495
|
+
const lineX2 = lineX1 + this.config.horizontalSeparation;
|
|
496
|
+
const lineY = maxUp;
|
|
497
|
+
group.append("path").attr("class", "railroad-line").attr("d", new PathBuilder().moveTo(lineX1, lineY).lineTo(lineX2, lineY).build());
|
|
498
|
+
}
|
|
499
|
+
x += r.dimensions.width + this.config.horizontalSeparation;
|
|
500
|
+
}
|
|
501
|
+
return {
|
|
502
|
+
element: group.node(),
|
|
503
|
+
dimensions: {
|
|
504
|
+
width: totalWidth,
|
|
505
|
+
height: maxUp + maxDown,
|
|
506
|
+
up: maxUp,
|
|
507
|
+
down: maxDown
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
renderChoice(parent, alternatives) {
|
|
512
|
+
const rendered = alternatives.map((a) => this.renderExpression(parent, a));
|
|
513
|
+
let maxWidth = 0;
|
|
514
|
+
let totalHeight = 0;
|
|
515
|
+
for (const r of rendered) {
|
|
516
|
+
maxWidth = Math.max(maxWidth, r.dimensions.width);
|
|
517
|
+
totalHeight += r.dimensions.height;
|
|
518
|
+
}
|
|
519
|
+
totalHeight += (rendered.length - 1) * this.config.verticalSeparation;
|
|
520
|
+
const arcRadius = this.config.arcRadius;
|
|
521
|
+
const arcWidth = arcRadius * 4;
|
|
522
|
+
const totalWidth = maxWidth + arcWidth;
|
|
523
|
+
const group = parent.append("g").attr("class", "railroad-choice");
|
|
524
|
+
let y = 0;
|
|
525
|
+
const centerY = totalHeight / 2;
|
|
526
|
+
for (const r of rendered) {
|
|
527
|
+
const elemY = y;
|
|
528
|
+
const elemCenterY = elemY + r.dimensions.up;
|
|
529
|
+
const elemX = arcRadius * 2 + (maxWidth - r.dimensions.width) / 2;
|
|
530
|
+
const elem = group.node().appendChild(r.element);
|
|
531
|
+
elem.setAttribute("transform", `translate(${elemX}, ${elemY})`);
|
|
532
|
+
const leftPath = new PathBuilder;
|
|
533
|
+
const isBelowCenter = elemCenterY > centerY;
|
|
534
|
+
if (elemCenterY === centerY) {
|
|
535
|
+
leftPath.moveTo(0, centerY).lineTo(elemX, elemCenterY);
|
|
536
|
+
} else {
|
|
537
|
+
leftPath.moveTo(0, centerY).arcTo(arcRadius, arcRadius, 0, false, isBelowCenter, arcRadius, centerY + (isBelowCenter ? arcRadius : -arcRadius)).lineTo(arcRadius, elemCenterY - (isBelowCenter ? arcRadius : -arcRadius)).arcTo(arcRadius, arcRadius, 0, false, !isBelowCenter, arcRadius * 2, elemCenterY).lineTo(elemX, elemCenterY);
|
|
538
|
+
}
|
|
539
|
+
group.append("path").attr("class", "railroad-line").attr("d", leftPath.build());
|
|
540
|
+
const rightPath = new PathBuilder;
|
|
541
|
+
const rightStart = elemX + r.dimensions.width;
|
|
542
|
+
const rightLaneX = totalWidth - arcRadius * 2;
|
|
543
|
+
if (elemCenterY === centerY) {
|
|
544
|
+
rightPath.moveTo(rightStart, elemCenterY).lineTo(totalWidth, centerY);
|
|
545
|
+
} else {
|
|
546
|
+
rightPath.moveTo(rightStart, elemCenterY).lineTo(rightLaneX, elemCenterY).arcTo(arcRadius, arcRadius, 0, false, !isBelowCenter, totalWidth - arcRadius, elemCenterY + (isBelowCenter ? -arcRadius : arcRadius)).lineTo(totalWidth - arcRadius, centerY + (isBelowCenter ? arcRadius : -arcRadius)).arcTo(arcRadius, arcRadius, 0, false, isBelowCenter, totalWidth, centerY);
|
|
547
|
+
}
|
|
548
|
+
group.append("path").attr("class", "railroad-line").attr("d", rightPath.build());
|
|
549
|
+
y += r.dimensions.height + this.config.verticalSeparation;
|
|
550
|
+
}
|
|
551
|
+
return {
|
|
552
|
+
element: group.node(),
|
|
553
|
+
dimensions: {
|
|
554
|
+
width: totalWidth,
|
|
555
|
+
height: totalHeight,
|
|
556
|
+
up: centerY,
|
|
557
|
+
down: totalHeight - centerY
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
renderOptional(parent, element) {
|
|
562
|
+
const inner = this.renderExpression(parent, element);
|
|
563
|
+
const arcRadius = this.config.arcRadius;
|
|
564
|
+
const arcHeight = arcRadius * 2;
|
|
565
|
+
const totalWidth = inner.dimensions.width + arcRadius * 4;
|
|
566
|
+
const totalHeight = inner.dimensions.height + arcHeight;
|
|
567
|
+
const group = parent.append("g").attr("class", "railroad-optional");
|
|
568
|
+
const elemX = arcRadius * 2;
|
|
569
|
+
const elemY = arcHeight;
|
|
570
|
+
const elem = group.node().appendChild(inner.element);
|
|
571
|
+
elem.setAttribute("transform", `translate(${elemX}, ${elemY})`);
|
|
572
|
+
const centerY = elemY + inner.dimensions.up;
|
|
573
|
+
const lowerPath = new PathBuilder().moveTo(0, centerY).lineTo(arcRadius * 2, centerY);
|
|
574
|
+
group.append("path").attr("class", "railroad-line").attr("d", lowerPath.build());
|
|
575
|
+
const lowerPath2 = new PathBuilder().moveTo(elemX + inner.dimensions.width, centerY).lineTo(totalWidth, centerY);
|
|
576
|
+
group.append("path").attr("class", "railroad-line").attr("d", lowerPath2.build());
|
|
577
|
+
const bypassPath = new PathBuilder().moveTo(0, centerY).arcTo(arcRadius, arcRadius, 0, false, false, arcRadius, centerY - arcRadius).lineTo(arcRadius, arcRadius).arcTo(arcRadius, arcRadius, 0, false, true, arcRadius * 2, 0).lineTo(totalWidth - arcRadius * 2, 0).arcTo(arcRadius, arcRadius, 0, false, true, totalWidth - arcRadius, arcRadius).lineTo(totalWidth - arcRadius, centerY - arcRadius).arcTo(arcRadius, arcRadius, 0, false, false, totalWidth, centerY);
|
|
578
|
+
group.append("path").attr("class", "railroad-line").attr("d", bypassPath.build());
|
|
579
|
+
return {
|
|
580
|
+
element: group.node(),
|
|
581
|
+
dimensions: {
|
|
582
|
+
width: totalWidth,
|
|
583
|
+
height: totalHeight,
|
|
584
|
+
up: centerY,
|
|
585
|
+
down: totalHeight - centerY
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
renderRepetition(parent, element, min) {
|
|
590
|
+
const inner = this.renderExpression(parent, element);
|
|
591
|
+
const arcRadius = this.config.arcRadius;
|
|
592
|
+
const arcHeight = arcRadius * 2;
|
|
593
|
+
const totalWidth = inner.dimensions.width + arcRadius * 4;
|
|
594
|
+
const hasBypass = min === 0;
|
|
595
|
+
const totalHeight = inner.dimensions.height + arcHeight + (hasBypass ? arcHeight : 0);
|
|
596
|
+
const group = parent.append("g").attr("class", "railroad-repetition");
|
|
597
|
+
const elemX = arcRadius * 2;
|
|
598
|
+
const elemY = hasBypass ? arcHeight : 0;
|
|
599
|
+
const elem = group.node().appendChild(inner.element);
|
|
600
|
+
elem.setAttribute("transform", `translate(${elemX}, ${elemY})`);
|
|
601
|
+
const centerY = elemY + inner.dimensions.up;
|
|
602
|
+
group.append("path").attr("class", "railroad-line").attr("d", new PathBuilder().moveTo(0, centerY).lineTo(arcRadius * 2, centerY).build());
|
|
603
|
+
group.append("path").attr("class", "railroad-line").attr("d", new PathBuilder().moveTo(elemX + inner.dimensions.width, centerY).lineTo(totalWidth, centerY).build());
|
|
604
|
+
const loopY = elemY + inner.dimensions.height + arcRadius;
|
|
605
|
+
const loopPath = new PathBuilder().moveTo(elemX + inner.dimensions.width, centerY).arcTo(arcRadius, arcRadius, 0, false, true, elemX + inner.dimensions.width + arcRadius, centerY + arcRadius).lineTo(elemX + inner.dimensions.width + arcRadius, loopY).arcTo(arcRadius, arcRadius, 0, false, true, elemX + inner.dimensions.width, loopY + arcRadius).lineTo(arcRadius * 2, loopY + arcRadius).arcTo(arcRadius, arcRadius, 0, false, true, arcRadius, loopY).lineTo(arcRadius, centerY + arcRadius).arcTo(arcRadius, arcRadius, 0, false, true, arcRadius * 2, centerY);
|
|
606
|
+
group.append("path").attr("class", "railroad-line").attr("d", loopPath.build());
|
|
607
|
+
if (hasBypass) {
|
|
608
|
+
const bypassPath = new PathBuilder().moveTo(0, centerY).arcTo(arcRadius, arcRadius, 0, false, false, arcRadius, centerY - arcRadius).lineTo(arcRadius, arcRadius).arcTo(arcRadius, arcRadius, 0, false, true, arcRadius * 2, 0).lineTo(totalWidth - arcRadius * 2, 0).arcTo(arcRadius, arcRadius, 0, false, true, totalWidth - arcRadius, arcRadius).lineTo(totalWidth - arcRadius, centerY - arcRadius).arcTo(arcRadius, arcRadius, 0, false, false, totalWidth, centerY);
|
|
609
|
+
group.append("path").attr("class", "railroad-line").attr("d", bypassPath.build());
|
|
610
|
+
}
|
|
611
|
+
return {
|
|
612
|
+
element: group.node(),
|
|
613
|
+
dimensions: {
|
|
614
|
+
width: totalWidth,
|
|
615
|
+
height: totalHeight,
|
|
616
|
+
up: centerY,
|
|
617
|
+
down: totalHeight - centerY
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
renderSpecial(parent, text) {
|
|
622
|
+
const textDim = this.measureText("? " + text + " ?");
|
|
623
|
+
const width = textDim.width + this.config.padding * 2;
|
|
624
|
+
const height = textDim.height + this.config.padding * 2;
|
|
625
|
+
const group = parent.append("g").attr("class", "railroad-special");
|
|
626
|
+
group.append("rect").attr("x", 0).attr("y", 0).attr("width", width).attr("height", height);
|
|
627
|
+
group.append("text").attr("x", width / 2).attr("y", height / 2).text("? " + text + " ?");
|
|
628
|
+
return {
|
|
629
|
+
element: group.node(),
|
|
630
|
+
dimensions: {
|
|
631
|
+
width,
|
|
632
|
+
height,
|
|
633
|
+
up: height / 2,
|
|
634
|
+
down: height / 2
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
renderExpression(parent, node) {
|
|
639
|
+
switch (node.type) {
|
|
640
|
+
case "terminal":
|
|
641
|
+
return this.renderTerminal(parent, node.value);
|
|
642
|
+
case "nonterminal":
|
|
643
|
+
return this.renderNonTerminal(parent, node.name);
|
|
644
|
+
case "sequence":
|
|
645
|
+
return this.renderSequence(parent, node.elements);
|
|
646
|
+
case "choice":
|
|
647
|
+
return this.renderChoice(parent, node.alternatives);
|
|
648
|
+
case "optional":
|
|
649
|
+
return this.renderOptional(parent, node.element);
|
|
650
|
+
case "repetition":
|
|
651
|
+
return this.renderRepetition(parent, node.element, node.min);
|
|
652
|
+
case "special":
|
|
653
|
+
return this.renderSpecial(parent, node.text);
|
|
654
|
+
default:
|
|
655
|
+
throw new Error(`Unknown node type: ${node.type}`);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
renderRule(rule, y) {
|
|
659
|
+
const group = this.svg.append("g").attr("class", "railroad-rule").attr("transform", `translate(0, ${y})`);
|
|
660
|
+
const ruleName = rule.name + " =";
|
|
661
|
+
const nameWidth = this.measureText(ruleName).width + 20;
|
|
662
|
+
const definitionX = nameWidth + 20;
|
|
663
|
+
const defGroup = group.append("g");
|
|
664
|
+
const result = this.renderExpression(defGroup, rule.definition);
|
|
665
|
+
const baselineY = Math.max(20, result.dimensions.up);
|
|
666
|
+
const definitionY = baselineY - result.dimensions.up;
|
|
667
|
+
defGroup.attr("transform", `translate(${definitionX}, ${definitionY})`);
|
|
668
|
+
const nameGroup = group.append("g").attr("class", "railroad-rule-name-group");
|
|
669
|
+
nameGroup.append("text").attr("class", "railroad-rule-name").attr("x", 0).attr("y", baselineY).text(ruleName);
|
|
670
|
+
const startMarker = group.append("g").attr("class", "railroad-start");
|
|
671
|
+
startMarker.append("circle").attr("cx", nameWidth).attr("cy", baselineY).attr("r", this.config.markerRadius);
|
|
672
|
+
const endMarker = group.append("g").attr("class", "railroad-end");
|
|
673
|
+
endMarker.append("circle").attr("cx", definitionX + result.dimensions.width + 10).attr("cy", baselineY).attr("r", this.config.markerRadius);
|
|
674
|
+
group.append("path").attr("class", "railroad-line").attr("d", new PathBuilder().moveTo(nameWidth + this.config.markerRadius, baselineY).lineTo(definitionX, baselineY).build());
|
|
675
|
+
group.append("path").attr("class", "railroad-line").attr("d", new PathBuilder().moveTo(definitionX + result.dimensions.width, baselineY).lineTo(definitionX + result.dimensions.width + 10 - this.config.markerRadius, baselineY).build());
|
|
676
|
+
return {
|
|
677
|
+
height: Math.max(40, definitionY + result.dimensions.height + this.config.padding * 2),
|
|
678
|
+
width: definitionX + result.dimensions.width + 10 + this.config.markerRadius
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
renderDiagram(rules2) {
|
|
682
|
+
let y = this.config.padding;
|
|
683
|
+
let maxWidth = 0;
|
|
684
|
+
for (const rule of rules2) {
|
|
685
|
+
const result = this.renderRule(rule, y);
|
|
686
|
+
y += result.height + this.config.verticalSeparation;
|
|
687
|
+
maxWidth = Math.max(maxWidth, result.width);
|
|
688
|
+
}
|
|
689
|
+
return {
|
|
690
|
+
width: maxWidth + this.config.padding * 2,
|
|
691
|
+
height: y + this.config.padding
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
var configureRailroadSvgSize = /* @__PURE__ */ __name((svg, dimensions, useMaxWidth) => {
|
|
696
|
+
configureSvgSize(svg, dimensions.height, dimensions.width, useMaxWidth);
|
|
697
|
+
svg.attr("viewBox", `0 0 ${dimensions.width} ${dimensions.height}`);
|
|
698
|
+
}, "configureRailroadSvgSize");
|
|
699
|
+
var draw = /* @__PURE__ */ __name((text, id, _version) => {
|
|
700
|
+
log.debug(`[Railroad] Rendering diagram
|
|
701
|
+
` + text);
|
|
702
|
+
try {
|
|
703
|
+
const svg = selectSvgElement(id);
|
|
704
|
+
svg.attr("class", "railroad-diagram");
|
|
705
|
+
const railroadConfig = getConfig().railroad;
|
|
706
|
+
const useMaxWidth = railroadConfig?.useMaxWidth ?? true;
|
|
707
|
+
const rules2 = db.getRules();
|
|
708
|
+
log.debug(`[Railroad] Rendering ${rules2.length} rules`);
|
|
709
|
+
if (rules2.length === 0) {
|
|
710
|
+
log.warn("[Railroad] No rules to render");
|
|
711
|
+
configureRailroadSvgSize(svg, { height: 100, width: 200 }, useMaxWidth);
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
const renderer2 = new RailroadRenderer(svg, buildRailroadStyleOptions());
|
|
715
|
+
const dimensions = renderer2.renderDiagram(rules2);
|
|
716
|
+
configureRailroadSvgSize(svg, dimensions, useMaxWidth);
|
|
717
|
+
log.debug("[Railroad] Render complete");
|
|
718
|
+
} catch (error) {
|
|
719
|
+
log.error("[Railroad] Render error:", error);
|
|
720
|
+
throw error;
|
|
721
|
+
}
|
|
722
|
+
}, "draw");
|
|
723
|
+
var renderer = { draw };
|
|
724
|
+
|
|
725
|
+
export { db, getStyles, renderer };
|