koboyo 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/editor/assets/IconNote-CSELvWzx.js +1 -0
- package/assets/editor/assets/code-panel-BfsykjSz.js +43 -0
- package/assets/editor/assets/flow-layer-BC35drcK.js +1 -0
- package/assets/editor/assets/flow-panel-D_K9wgZi.js +1 -0
- package/assets/editor/assets/{index-DGJESAlV.css → index-CC2h28V_.css} +1 -1
- package/assets/editor/assets/{index-By5YsjJ8.js → index-DfNbwHl_.js} +7 -7
- package/assets/editor/assets/tool-catalog-ChSwaLIq.js +1 -0
- package/assets/editor/assets/{tool-drawer-GdbF-XpT.js → tool-drawer-CG7-cnML.js} +1 -1
- package/assets/editor/assets/tree-rq4RTGgw.js +1 -0
- package/assets/editor/index.html +4 -4
- package/dist/koboyo.js +285 -229
- package/package.json +5 -5
- package/skills/koboyo/SKILL.md +33 -1
- package/skills/koboyo/references/architecture.md +4 -4
- package/skills/koboyo/references/bpmn.md +1 -1
- package/skills/koboyo/references/chart.md +1 -1
- package/skills/koboyo/references/cycle.md +1 -1
- package/skills/koboyo/references/erd.md +1 -1
- package/skills/koboyo/references/flowchart.md +1 -1
- package/skills/koboyo/references/funnel.md +1 -1
- package/skills/koboyo/references/gantt.md +1 -1
- package/skills/koboyo/references/gitgraph.md +1 -1
- package/skills/koboyo/references/journey.md +1 -1
- package/skills/koboyo/references/matrix.md +1 -1
- package/skills/koboyo/references/mindmap.md +2 -2
- package/skills/koboyo/references/orgchart.md +1 -1
- package/skills/koboyo/references/pyramid.md +1 -1
- package/skills/koboyo/references/sankey.md +1 -1
- package/skills/koboyo/references/sequence.md +1 -1
- package/skills/koboyo/references/statemachine.md +1 -1
- package/skills/koboyo/references/timeline.md +1 -1
- package/skills/koboyo/references/venn.md +1 -1
- package/skills/koboyo/references/wireframe.md +1 -1
- package/assets/editor/assets/IconNote-C0uYQWp-.js +0 -1
- package/assets/editor/assets/code-panel-CVIEtmj2.js +0 -43
- package/assets/editor/assets/flow-layer-CGYUYmni.js +0 -1
- package/assets/editor/assets/flow-panel-BNLlwdYm.js +0 -1
- package/assets/editor/assets/tool-catalog-DOYGpvRD.js +0 -1
- package/assets/editor/assets/tree-BSe8fgqT.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koboyo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Render Koboyo diagram code to SVG and PNG on your own machine. No account needed.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"koboyo",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"vitest": "^4.1.10",
|
|
51
51
|
"zod": "^4.4.3",
|
|
52
52
|
"@koboyo/agent-tools": "0.0.0",
|
|
53
|
-
"@koboyo/compiler": "0.0.0",
|
|
54
53
|
"@koboyo/headless": "0.0.0",
|
|
55
|
-
"@koboyo/model": "0.0.0",
|
|
56
|
-
"@koboyo/local-editor": "0.0.0",
|
|
57
54
|
"@koboyo/language": "0.0.0",
|
|
58
|
-
"@koboyo/
|
|
55
|
+
"@koboyo/local-editor": "0.0.0",
|
|
56
|
+
"@koboyo/compiler": "0.0.0",
|
|
57
|
+
"@koboyo/renderer": "0.0.0",
|
|
58
|
+
"@koboyo/model": "0.0.0"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "node --import tsx scripts/build.mjs",
|
package/skills/koboyo/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: koboyo
|
|
|
3
3
|
description: "Draw diagrams as code and render them to SVG, PNG or HTML on this machine with the koboyo CLI: architecture and dependency maps, flowcharts, sequence diagrams, ERDs and class diagrams, state machines, mind maps, gantt charts, timelines and more. Use when the user asks to draw, diagram, visualize, map or explain a system, a codebase, a request flow, a data model or a process, or wants a picture for docs or a README; and to let the user edit a diagram by hand in a local editor and read their edits back."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
<!-- Generated by koboyo 0.
|
|
6
|
+
<!-- Generated by koboyo 0.2.0. `koboyo setup` rewrites this file. -->
|
|
7
7
|
|
|
8
8
|
# Koboyo diagrams
|
|
9
9
|
|
|
@@ -48,6 +48,9 @@ without drawing. Add `--json` to any command for one JSON result on stdout.
|
|
|
48
48
|
- A PNG: `-o docs/checkout.png` (`--width` sets its width in pixels).
|
|
49
49
|
- Existing Mermaid: `koboyo render flow.mmd` draws it directly, and
|
|
50
50
|
`koboyo convert flow.mmd` writes flow.kbd to keep working in Koboyo code.
|
|
51
|
+
- Keeping committed pictures current: `koboyo render docs/*.kbd --check` writes nothing
|
|
52
|
+
and exits 1 when an SVG no longer matches its code. Use it in CI, with the same options
|
|
53
|
+
as the render.
|
|
51
54
|
|
|
52
55
|
## Visualize a codebase
|
|
53
56
|
|
|
@@ -100,6 +103,12 @@ To bring the code in line with their edits, apply `changes` to the `.kbd`. Rewri
|
|
|
100
103
|
`.kbd` while the editor is open redraws the board, unless it has hand edits; then the
|
|
101
104
|
editor asks the person which to keep. Never write the `.kby` yourself.
|
|
102
105
|
|
|
106
|
+
When the person would rather sketch than describe, hand them a blank board: open a
|
|
107
|
+
`.kby` that does not exist yet (`koboyo open docs/sketch.kby --wait --json`, or
|
|
108
|
+
`open_editor({ path: "docs/sketch.kby" })`) and it is created empty. A `.kbd` is never
|
|
109
|
+
created empty; write its code first. What they draw comes back the same way, in `changes`
|
|
110
|
+
and the PNG, and stays in the `.kby`.
|
|
111
|
+
|
|
103
112
|
The person can pin comments on the drawing for you ("make this Postgres"). Treat each as a
|
|
104
113
|
request: do it in the `.kbd`, then answer it so they see it was handled, in the editor if
|
|
105
114
|
it is still open:
|
|
@@ -120,6 +129,27 @@ call it again with the same sessionId;
|
|
|
120
129
|
`read_drawing({ path })` reads the board as it is now, without waiting. Both list the open
|
|
121
130
|
comments; `reply_to_comment({ path, commentId, text, resolve })` answers one.
|
|
122
131
|
|
|
132
|
+
The server also draws on boards directly, with the hosted server's board tools taking a
|
|
133
|
+
`path` to a `.kby`: `create_diagram`, `read_canvas`, `draw_shapes`, `update_shapes`,
|
|
134
|
+
`connect_shapes`, `add_flow` and the rest. While the board is open in the editor, the
|
|
135
|
+
person watches each change land.
|
|
136
|
+
|
|
137
|
+
To get the person's feedback on something visual you built — a page, a screen, a chart:
|
|
138
|
+
|
|
139
|
+
1. Take a screenshot with your browser tool and save it in the project.
|
|
140
|
+
2. `add_image({ path: "review.kby", image: "shots/login.png" })` puts it on a board.
|
|
141
|
+
3. Optionally `annotate_image` the spots you want an opinion on, at pixel positions you
|
|
142
|
+
MEASURED (the element's bounding box times the device pixel ratio, or OCR boxes). Never
|
|
143
|
+
guess a position from looking at the picture.
|
|
144
|
+
4. `open_editor({ path: "review.kby", message: "Does the form read clearly?" })`, then
|
|
145
|
+
`wait_for_edits`.
|
|
146
|
+
5. Each comment pinned on the screenshot comes back with `image` { file, x, y }, and each
|
|
147
|
+
box, arrow or scribble they drew over it is in `imageMarks` with its `box` — all in the
|
|
148
|
+
screenshot's own pixels, so you can find the exact element they mean.
|
|
149
|
+
|
|
150
|
+
Drew two or three variants as frames? `offer_choices({ sessionId, question, options })`
|
|
151
|
+
asks the person to pick one; `wait_for_edits` returns it as `chosen`.
|
|
152
|
+
|
|
123
153
|
## MCP tools
|
|
124
154
|
|
|
125
155
|
If a `koboyo` MCP server is connected (`koboyo setup` adds it), its tools do the same work
|
|
@@ -139,6 +169,8 @@ koboyo save docs/architecture.kbd # upload it as a board and print its link
|
|
|
139
169
|
|
|
140
170
|
Saving the same file again updates the same board. `koboyo whoami` shows who is signed
|
|
141
171
|
in and `koboyo logout` signs out. The editor's **Save to cloud** button does the same.
|
|
172
|
+
Where no browser can open (an SSH session), `koboyo login` prints a code instead: tell
|
|
173
|
+
the user to enter it at the address it prints, on any device, and wait for it to finish.
|
|
142
174
|
Saving needs Koboyo Pro; without it the command says how to start a trial. Do not bring
|
|
143
175
|
it up unless the user asks to share.
|
|
144
176
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!-- Generated by koboyo 0.
|
|
1
|
+
<!-- Generated by koboyo 0.2.0. `koboyo setup` rewrites this file. -->
|
|
2
2
|
|
|
3
3
|
# Architecture diagrams
|
|
4
4
|
|
|
@@ -14,7 +14,7 @@ _Icons, colours, and layout are the compiler's job; you write the structure._
|
|
|
14
14
|
```koboyo
|
|
15
15
|
title: Image upload service
|
|
16
16
|
|
|
17
|
-
Client [
|
|
17
|
+
Client [monitor]
|
|
18
18
|
API [aws/api-gateway]
|
|
19
19
|
Resize [aws/lambda, green]
|
|
20
20
|
Bucket [aws/simple-storage-service, orange]
|
|
@@ -138,7 +138,7 @@ Oracle, Twitter, RSS -> Ingest -> Warehouse
|
|
|
138
138
|
Nodes may declare their attributes the first time they appear inside an edge:
|
|
139
139
|
|
|
140
140
|
```koboyo
|
|
141
|
-
Backend [server, blue] -> Client [
|
|
141
|
+
Backend [server, blue] -> Client [monitor]
|
|
142
142
|
Backend --> Cache [cylinder, red]: warm
|
|
143
143
|
```
|
|
144
144
|
|
|
@@ -167,7 +167,7 @@ title: Three-tier web app
|
|
|
167
167
|
direction: right
|
|
168
168
|
|
|
169
169
|
group Edge [gray] {
|
|
170
|
-
Browser [
|
|
170
|
+
Browser [app-window]
|
|
171
171
|
CDN [cloud, blue]
|
|
172
172
|
}
|
|
173
173
|
group Application [violet] {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!-- Generated by koboyo 0.
|
|
1
|
+
<!-- Generated by koboyo 0.2.0. `koboyo setup` rewrites this file. -->
|
|
2
2
|
|
|
3
3
|
# Mind maps
|
|
4
4
|
|
|
@@ -91,7 +91,7 @@ central: Machine learning
|
|
|
91
91
|
- Reinforcement [orange, icon: target]
|
|
92
92
|
- Policy
|
|
93
93
|
- Reward
|
|
94
|
-
- Tooling [violet, icon:
|
|
94
|
+
- Tooling [violet, icon: toolbox]
|
|
95
95
|
- Python
|
|
96
96
|
- Notebooks
|
|
97
97
|
```
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./createReactComponent-9UsI5fmM.js";var t=e(`outline`,`note`,`Note`,[[`path`,{d:`M13 20l7 -7`,key:`svg-0`}],[`path`,{d:`M13 20v-6a1 1 0 0 1 1 -1h6v-7a2 2 0 0 0 -2 -2h-12a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h7`,key:`svg-1`}]]);export{t};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{n as t,t as n}from"./jsx-runtime-2Zwg-L3c.js";import{Fn as r}from"./useScrollLock-B7mQdXyv.js";import{t as i}from"./tooltip-DgEojto1.js";import{a,o}from"./editor-B0tARd79.js";import{M as s,t as c}from"./reflow-Cv75wPSh.js";import{s as l}from"./style-BENGW2ZV.js";import{A as u,C as d,Zt as f,_ as p,ar as m,x as h,zt as g}from"./slides-D9bnXqtf.js";import{A as _,D as v,E as y,M as b,N as x,O as S,R as C,S as w,T,b as E,g as D,h as O,j as ee,k as te}from"./registry-DCgwH8wI.js";import{n as ne}from"./renderer-environment-DmWXvuT4.js";import{a as re,t as ie}from"./icon-sources-CZI1h18s.js";import{t as k}from"./icons-DzW1j-r3.js";import{o as ae,r as oe,t as se}from"./diagram-fingerprint-CsqZK4xZ.js";import{t as ce}from"./createReactComponent-9UsI5fmM.js";import{t as le}from"./IconAlertTriangle-CxPhYpe-.js";import{t as ue}from"./IconCode-hd05zxU4.js";import{t as de}from"./IconX-AlbPkO_g.js";import{n as fe,t as pe}from"./storage-CvDRYh5V.js";import{a as me}from"./chrome-C2RCq3SI.js";import{i as he,n as ge,r as _e,t as ve}from"./DialogRoot-mHGRFW9m.js";import{n as ye,t as be}from"./DialogTitle-CFhr-gP9.js";import{n as xe}from"./dialog-B32krrce.js";import{r as Se}from"./chrome-layout-B8YmHznO.js";import{t as Ce}from"./panel-shell-CG2aq4Ia.js";import{d as we,f as A,i as Te,p as Ee,r as De,t as Oe,u as ke}from"./layout-offthread-BwetpTFH.js";import{n as Ae,t as je}from"./export-DEFKKRRi.js";import{r as Me}from"./flows-GGbkNqs8.js";import{n as j}from"./icon-catalog-CbUlEKtK.js";var Ne=ce(`outline`,`book`,`Book`,[[`path`,{d:`M3 19a9 9 0 0 1 9 0a9 9 0 0 1 9 0`,key:`svg-0`}],[`path`,{d:`M3 6a9 9 0 0 1 9 0a9 9 0 0 1 9 0`,key:`svg-1`}],[`path`,{d:`M3 6l0 13`,key:`svg-2`}],[`path`,{d:`M12 6l0 13`,key:`svg-3`}],[`path`,{d:`M21 6l0 13`,key:`svg-4`}]]),M=e(t(),1);function N(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`node`}function P(e,t){let n=e,r=2;for(;t.has(n);)n=`${e}-${r}`,r+=1;return t.add(n),n}function Pe(e,t,n=0){let r=!1,i=0;for(let a=0;a<e.length;a+=1){let o=e[a];if(o===`"`){r=!r;continue}if(!r){if(o===`[`){i+=1;continue}if(o===`]`){i=Math.max(0,i-1);continue}if(i===0&&a>=n){for(let n=0;n<t.length;n+=1)if(e.startsWith(t[n],a))return{index:a,needle:n}}}}return null}function F(e,t,n=0){return Pe(e,[t],n)?.index??-1}function I(e){let t=F(e,`//`);return t===-1?e:e.slice(0,t)}function L(e,t){let n=[],r=0,i=0,a=!1;for(let o=0;o<e.length;o+=1){let s=e[o];s===`"`?a=!a:!a&&s===`[`?r+=1:!a&&s===`]`?r=Math.max(0,r-1):!a&&r===0&&s===t&&(n.push(e.slice(i,o)),i=o+1)}return n.push(e.slice(i)),n}function R(e){let t=e.trim();return t.length>=2&&t.startsWith(`"`)&&t.endsWith(`"`)?t.slice(1,-1).replace(/\\n/g,`
|
|
2
|
-
`):t}function z(e){return/\s|[:=,[\]{}]/.test(e)?`"${e.replace(/"/g,``)}"`:e}function B(e){let t=e.trimEnd();if(!t.endsWith(`]`))return{rest:e,attrs:null};let n=0,r=!1;for(let e=t.length-1;e>=0;--e){let i=t[e];if(i===`"`)r=!r;else if(!r&&i===`]`)n+=1;else if(!r&&i===`[`&&(--n,n===0))return{rest:t.slice(0,e),attrs:t.slice(e+1,t.length-1)}}return{rest:e,attrs:null}}var Fe={done:`done`,complete:`done`,active:`active`,doing:`active`,crit:`critical`,critical:`critical`,milestone:`milestone`};function Ie(e){let t=/^(\d+(?:\.\d+)?)\s*(d|day|days|w|week|weeks|h|hour|hours|m|min|mins|minute|minutes|s|sec|secs|second|seconds)?$/i.exec(e.trim());if(!t)return;let n=Number(t[1]),r=(t[2]??`d`).toLowerCase();return r.startsWith(`w`)?n*7:r.startsWith(`h`)?n/24:r===`m`||r.startsWith(`min`)?n/1440:r===`s`||r.startsWith(`sec`)?n/86400:n}function Le(e){let t=[],n=``,r=[],i=new Set,a=``,o=!1;return e.split(`
|
|
3
|
-
`).forEach((e,s)=>{let c=I(e).trim();if(c.length===0||c.toLowerCase()===`gantt`)return;let l=c.match(/^title\s*:\s*(.*)$/i);if(l){n=R(l[1].trim());return}let u=c.match(/^section\s+(.+)$/i);if(u){a=R(u[1].trim());return}let d=c.match(/^excludes\s*:\s*(.*)$/i);if(d){/weekends?/i.test(d[1])?o=!0:t.push({line:s+1,message:`only "excludes: weekends" is supported, not "${d[1].trim()}"`});return}let{attrs:f,rest:p}=B(c),m;for(let e of L(f??``,`,`)){let n=e.trim().toLowerCase();n&&(Fe[n]?m=Fe[n]:t.push({line:s+1,message:`unknown task attribute "${e.trim()}"`}))}let h=p.trim().match(/^[-*]\s+(.*)$/),g=(h?h[1]:p).trim();if(g.length===0)return;let _=g.indexOf(`:`),v=R((_===-1?g:g.slice(0,_)).trim());if(v.length===0)return;let y=_===-1?``:g.slice(_+1),b,x,S,C=[];for(let e of L(y,`,`)){let n=e.trim();if(!n)continue;let r=n.match(/^after\s+(.+)$/i);if(r){C.push(...r[1].trim().split(/\s+/).map(N));continue}let i=n.match(/^until\s+(.+)$/i);if(i){S=N(i[1].trim());continue}if(/^\d{4}-\d{2}-\d{2}$/.test(n)){b=n;continue}let a=Ie(n);if(a!==void 0){x=a;continue}t.push({line:s+1,message:`unknown schedule part "${n}" (expected a date, "after <task>", or a length like 5d)`})}r.push({id:P(N(v)||`t${r.length+1}`,i),label:v,section:a===``?void 0:a,start:b,after:C.length>0?C:void 0,days:x,until:S,status:m})}),{diagram:A({kind:`gantt`,title:n,tasks:r,skipWeekends:o}),diagnostics:t,iconUses:[]}}function Re(e,t,n){let r={};if(!e||e.trim()===``)return r;for(let i of L(e,`,`)){let e=i.trim();if(!e)continue;let a=F(e,`:`);if(a===-1){let i=e.toLowerCase();i===`highlight`?r.kind=`highlight`:i===`reverse`||i===`revert`?r.kind=`reverse`:n.push({line:t,message:`unknown commit attribute "${e}"`});continue}let o=e.slice(0,a).trim().toLowerCase(),s=R(e.slice(a+1));o===`tag`?r.tag=s:o===`label`?r.label=s:n.push({line:t,message:`unknown commit attribute "${o}"`})}return r}function ze(e){let t=[],n=``,r=[],i=[],a=`main`,o=new Map,s=new Set,c=e=>{r.includes(e)||r.push(e)};c(a);let l=(e,t,n={})=>{let{id:r,...c}=n,l=e.trim(),u=s.has(a)?void 0:o.get(a);s.add(a),i.push({id:r??(N(l)||`c${i.length+1}`),branch:a,label:l.length>0?l:void 0,tag:t.tag,kind:t.kind,branchFrom:u,...c})};return e.split(`
|
|
4
|
-
`).forEach((e,r)=>{let i=I(e).trim();if(i.length===0||i.toLowerCase()===`gitgraph`)return;let s=i.match(/^title\s*:\s*(.*)$/i);if(s){n=R(s[1].trim());return}let{attrs:u,rest:d}=B(i),f=Re(u,r+1,t),p=d.trim(),m=p.match(/^branch\s+(.+)$/i);if(m){let e=R(m[1].trim());e!==a&&o.set(e,a),a=e,c(a);return}let h=p.match(/^(?:checkout|switch)\s+(.+)$/i);if(h){a=R(h[1].trim()),c(a);return}let g=p.match(/^merge\s+(.+)$/i);if(g){let e=R(g[1].trim());if(e===a){t.push({line:r+1,message:`cannot merge "${e}" into itself — checkout another branch first`});return}c(e),l(f.label??`merge ${e}`,f,{mergeFrom:e});return}let _=p.match(/^cherry-?pick\s+(.+)$/i);if(_){let e=N(R(_[1].trim()));l(f.label??`pick ${e}`,f,{cherryPick:e,id:`pick-${e}`});return}let v=p.match(/^commit\b\s*(.*)$/i);if(v){l(f.label??v[1],f);return}t.push({line:r+1,message:`unknown git line "${p}" (expected commit, branch, checkout, merge or cherry-pick)`})}),{diagram:A({kind:`gitgraph`,title:n,lanes:r,commits:i}),diagnostics:t,iconUses:[]}}function Be(e){let t=[],n=``,r=[];return e.split(`
|
|
5
|
-
`).forEach((e,i)=>{let a=I(e).trim();if(a.length===0||a.toLowerCase()===`sankey`)return;let o=a.match(/^title\s*:\s*(.*)$/i);if(o){n=R(o[1].trim());return}let s=a.match(/^(.+?)\s*(?:->|=>)\s*(.+)$/),c=s?[s[1],...s[2].split(`:`)]:L(a,`,`).map(e=>e.trim());if(c.length<3){t.push({line:i+1,message:`expected "From -> To : value" but read "${a}"`});return}let l=Number(R(c[2].trim()));if(!Number.isFinite(l)||l<=0){t.push({line:i+1,message:`flow needs a positive value, got "${c[2].trim()}"`});return}r.push({from:R(c[0].trim()),to:R(c[1].trim()),value:l})}),{diagram:A({kind:`sankey`,title:n,flows:r}),diagnostics:t,iconUses:[]}}var V=te,Ve=x,He=C;function Ue(e){return Object.fromEntries(e.map(e=>[e,e]))}var H=Ue(ee),We={...Ue(_),square:`sharp`,round:`rounded`},Ge=Ue(T),Ke={...Ue(E),x:`cross`,o:`circle`,dot:`circle`},qe={full:`full`,half:`half`,"1/2":`half`,third:`third`,"1/3":`third`,"two-thirds":`twoThirds`,twothirds:`twoThirds`,"2/3":`twoThirds`},Je=Ee,Ye=new Set([`on`,`checked`,`true`]),Xe=new Set([`off`,`unchecked`,`false`]),Ze=new Map(O.map((e,t)=>[e,t])),Qe={white:`#ffffff`,black:`#1e1e1e`,silver:`#c0c0c0`,maroon:`#800000`,crimson:`#dc143c`,tomato:`#ff6347`,salmon:`#fa8072`,lightsalmon:`#ffa07a`,coral:`#ff7f50`,gold:`#ffd700`,khaki:`#f0e68c`,lavender:`#e6e6fa`,plum:`#dda0dd`,orchid:`#da70d6`,magenta:`#ff00ff`,fuchsia:`#ff00ff`,indigo:`#4b0082`,navy:`#000080`,royalblue:`#4169e1`,skyblue:`#87ceeb`,lightblue:`#add8e6`,lightskyblue:`#87cefa`,steelblue:`#4682b4`,lightcyan:`#e0ffff`,cyan:`#00ffff`,aqua:`#00ffff`,aquamarine:`#7fffd4`,turquoise:`#40e0d0`,mint:`#98ff98`,mintcream:`#f5fffa`,lightgreen:`#90ee90`,palegreen:`#98fb98`,seagreen:`#2e8b57`,forestgreen:`#228b22`,olive:`#808000`,lime:`#00ff00`,limegreen:`#32cd32`,lightyellow:`#ffffe0`,lemonchiffon:`#fffacd`,beige:`#f5f5dc`,ivory:`#fffff0`,tan:`#d2b48c`,wheat:`#f5deb3`,peachpuff:`#ffdab9`,brown:`#a52a2a`,chocolate:`#d2691e`,sienna:`#a0522d`,peru:`#cd853f`,lightpink:`#ffb6c1`,hotpink:`#ff69b4`,deeppink:`#ff1493`,rosybrown:`#bc8f8f`,lightgray:`#d3d3d3`,lightgrey:`#d3d3d3`,darkgray:`#a9a9a9`,darkgrey:`#a9a9a9`,dimgray:`#696969`,dimgrey:`#696969`,gainsboro:`#dcdcdc`,whitesmoke:`#f5f5f5`,slategray:`#708090`,slategrey:`#708090`,darkblue:`#00008b`,darkgreen:`#006400`,darkred:`#8b0000`,darkorange:`#ff8c00`,darkviolet:`#9400d3`,darkcyan:`#008b8b`,darkkhaki:`#bdb76b`,lightcoral:`#f08080`,lightseagreen:`#20b2aa`,lightsteelblue:`#b0c4de`,lightgoldenrodyellow:`#fafad2`,mediumpurple:`#9370db`,mediumseagreen:`#3cb371`,mediumblue:`#0000cd`,cornflowerblue:`#6495ed`,dodgerblue:`#1e90ff`,goldenrod:`#daa520`,thistle:`#d8bfd8`,violetred:`#d02090`,paleturquoise:`#afeeee`,powderblue:`#b0e0e6`},$e={blue:`#a5d8ff`,green:`#b2f2bb`,red:`#ffc9c9`,orange:`#ffd8a8`,violet:`#eebefa`,teal:`#96f2d7`,pink:`#fcc2d7`,yellow:`#ffec99`,gray:`#e9ecef`};function et(e){let t=(e>>16&255)/255,n=(e>>8&255)/255,r=(e&255)/255,i=Math.max(t,n,r),a=Math.min(t,n,r),o=i-a,s=0;o>0&&(s=i===t?(n-r)/o%6:i===n?(r-t)/o+2:(t-n)/o+4,s=(s*60+360)%360);let c=(i+a)/2,l=o===0?0:o/(1-Math.abs(2*c-1));return{hue:s,saturation:l}}var tt=/^(?:light|dark|medium|pale|deep|hot|dim|royal|sky|forest|sea|slate|steel)?(blue|green|red|orange|violet|purple|teal|pink|yellow|gray|grey)$/,nt={purple:`violet`,grey:`gray`};function rt(e){let t=e.trim().toLowerCase(),n=tt.exec(t);if(n)return nt[n[1]]??n[1];let r=Qe[t],i=/^#?([0-9a-f]{6})$/i.exec(r??t);if(!i)return null;let{hue:a,saturation:o}=et(parseInt(i[1],16));if(o<.12)return`gray`;let s=null,c=1/0;for(let[e,t]of Object.entries($e)){if(e===`gray`)continue;let n=et(parseInt(t.slice(1),16)).hue,r=Math.abs(a-n),i=Math.min(r,360-r);i<c&&(c=i,s=e)}return s}var it=new Set(j),at=new Set([`rectangle`,`box`,`ellipse`,`circle`,`diamond`,`cylinder`,`hexagon`,`triangle`,`pentagon`,`octagon`,`plus`,`cross`,`star`,`heart`,`cloud`,`arrow-up`,`arrow-down`,`arrow-left`,`arrow-right`]),ot=/^(tech|aws|gcp|azure)\/[a-z0-9-]+$/,st=new Set([`lucide`,`tech`,`aws`,`gcp`,`azure`,`emoji`,`mood`]);function ct(e,t,n){let r=e.toLowerCase();if(r===`flow`||r===`animated`){t.flow=!0;return}if(r===`invisible`||r===`hidden`){t.invisible=!0;return}if(r===`shadow`){t.shadow=!0;return}if(V[r]){t.color=V[r];return}if(Ve[r]){t.shape=Ve[r],at.has(r)||n.use({kind:`keyword`,written:e,ref:He(r),reading:`shape`});return}if(H[r]){t.fill=H[r];return}if(We[r]){t.corner=We[r];return}if(Ge[r]){t.frame=Ge[r],n.use({kind:`keyword`,written:e,ref:He(r),reading:`frame`});return}if(qe[r]){t.width=qe[r];return}if(Ye.has(r)){t.value=1;return}if(Xe.has(r)){t.value=0;return}let i=Ze.get(r);if(i!==void 0){t.value=i;return}let a=/^(\d+(?:\.\d+)?)%$/.exec(r);if(a){t.value=Number(a[1])/100;return}if(/^\d*\.\d+$/.test(r)||/^[01]$/.test(r)){t.value=Number(r);return}let o=rt(R(e));if(o){t.color=o;return}if(ot.test(r)){t.icon=He(r),n.use({kind:`icon`,written:e,ref:t.icon});return}if(it.has(r)){t.icon=r,n.use({kind:`icon`,written:e,ref:r});return}let s=n.push(`unknown attribute "${e}"`);n.use({kind:`unknown`,written:e,ref:He(r),diagnostic:s})}function U(e,t,n){let r={};if(!e||e.trim()===``)return r;let i=e=>{let r={line:t,message:e};return n.diagnostics.push(r),r},a={push:i,use:e=>{n.iconUses.push({...e,line:t})}};for(let t of L(e,`,`)){let e=t.trim();if(!e)continue;let n=F(e,`:`);if(n===-1){ct(e,r,a);continue}let o=e.slice(0,n).trim().toLowerCase(),s=R(e.slice(n+1)),c=s.toLowerCase();if(o===`icon`)r.icon=He(c),a.use({kind:`icon`,written:s,ref:r.icon});else if(st.has(o)){let e=c.trim();i(`"${o}:${e}" reads as a key: value pair. For the icon, write `+(ot.test(`${o}/${e}`)?`[${o}/${e}]`:`[icon: ${o}/${e}]`))}else if(o===`color`)r.color=V[c]??rt(s)??void 0,r.color||i(`unknown color "${s}"`);else if(o===`shape`)r.shape=Ve[c],r.shape||i(`unknown shape "${s}"`);else if(o===`fill`||o===`colormode`)r.fill=H[c],r.fill||i(`unknown fill "${s}" (pastel, bold, outline)`);else if(o===`corner`||o===`corners`)r.corner=We[c],r.corner||i(`unknown corner "${s}" (sharp, rounded)`);else if(o===`frame`)r.frame=Ge[c],r.frame||i(`unknown frame "${s}" (browser, phone, window)`);else if(o===`width`)r.width=qe[c],r.width||i(`unknown width "${s}"`);else if(o===`label`)r.label=s;else if(o===`labelcolor`||o===`textcolor`)r.labelColor=V[c]??rt(s)??void 0,r.labelColor||i(`unknown label color "${s}"`);else if(o===`group`)r.group=s;else if(o===`head`)r.head=Ke[c],r.head||i(`unknown head "${s}" (arrow, circle or cross)`);else if(o===`link`||o===`href`||o===`url`)r.link=m(s)??void 0,s&&!r.link&&i(`unsafe or invalid link "${s}"`);else if(o===`active`||o===`value`){let e=Number(c.replace(`%`,``));Number.isFinite(e)?r.value=c.endsWith(`%`)?e/100:e:i(`"${o}" expects a number`)}else if(o===`score`){let e=Number(c);Number.isFinite(e)?r.score=e:i(`"score" expects a number ${v.min}-${v.max}`)}else i(`unknown attribute key "${o}"`)}return r}function lt(e,t){let n=[],r={diagnostics:n,iconUses:[]},i=``,a=[],o=[],s={},c=t===`journey`,l=t===`timeline`,u=``,d,f=new Set,p=e=>{let t=e.match(/^"([^"]*)"\s*(?::\s*(.*))?$/);if(t)return{label:t[1].trim(),detail:t[2]?.trim()||void 0};let n=e.indexOf(`:`);return n<0?{label:R(e.trim())}:{label:R(e.slice(0,n).trim()),detail:e.slice(n+1).trim()||void 0}};return e.split(`
|
|
6
|
-
`).forEach((e,m)=>{let h=I(e),g=h.trim();if(g.length===0||g.toLowerCase()===t)return;let _=h.length-h.trimStart().length;if(l&&_>=2&&d){let e=g.match(/^[-*]\s+(.*)$/);if(e){let{rest:t}=B(e[1].trim()),n=R(t.trim());n.length>0&&(d.events||(d.events=d.detail?[d.detail]:[],d.detail=void 0),d.events.length<8&&d.events.push(n));return}}let v=g.match(/^(title|x|y)\s*:\s*(.*)$/i);if(v){let e=v[1].toLowerCase(),t=v[2].trim();if(e===`title`)i=R(t);else{let r=t.split(`|`).map(e=>R(e.trim()));r.length>=2?s[e]=r:n.push({line:m+1,message:`axis "${e}" needs two labels separated by | (e.g. x: Low | High)`})}return}let y=c||l?g.match(/^section\s+(.+)$/i):null;if(y){u=R(y[1].trim());return}let b=g.match(/^overlap\s+(.+?)\s*:\s*(.*)$/i);if(b){let e=b[1].split(/\s*[+&,]\s*/).map(e=>N(R(e.trim()))).filter(e=>e.length>0),t=R(b[2].trim());e.length>=2&&t.length>0?o.push({ids:e,label:t}):n.push({line:m+1,message:`overlap needs two set names and a label (overlap a + b: label)`});return}let x=g.match(/^[-*]\s+(.*)$/),{attrs:S,rest:C}=B(x?x[1].trim():g),{label:w,detail:T}=p(C.trim());if(w.length===0)return;let E=U(S,m+1,r),D=c&&T!==void 0&&/^\d+(\.\d+)?$/.test(T),O={id:P(N(w)||`i${a.length}`,f),label:w,detail:D?void 0:T,color:E.color,icon:E.icon,score:c?E.score??(D?Number(T):void 0):void 0,group:(c||l)&&u!==``?u:void 0};a.push(O),d=l?O:void 0}),{diagram:A({kind:`infographic`,variant:t,title:i,items:a,overlaps:o.length>0?o:void 0,axes:s.x||s.y?s:void 0}),diagnostics:n,iconUses:r.iconUses}}function ut(e){let t=[],n={diagnostics:t,iconUses:[]},r=``,i=``,a=[];e.split(`
|
|
7
|
-
`).forEach((e,t)=>{let o=I(e.replace(/\t/g,` `)),s=o.trim();if(s.length===0||s.toLowerCase()===`mindmap`)return;let c=s.match(/^(title|central|root|center)\s*:\s*(.*)$/i);if(c){let e=R(c[2].trim());c[1].toLowerCase()===`title`?r=e:i=e;return}let l=o.match(/^(\s*)[-*]\s+(.*)$/);if(l){let{attrs:e,rest:r}=B(l[2].trim()),i=R(r.trim());i.length>0&&a.push({indent:l[1].length,label:i,attrs:U(e,t+1,n)});return}i?a.push({indent:0,label:R(s),attrs:{}}):i=R(s)});let o=[],s=new Set,c=a.reduce((e,t)=>Math.min(e,t.indent),1/0),l=[];for(let e of a){if(e.indent<=c){let t=[];o.push({id:P(N(e.label)||`b${o.length}`,s),label:e.label,color:e.attrs.color,icon:e.attrs.icon,children:t}),l.length=0,l.push({indent:e.indent,children:t});continue}for(;l.length>1&&e.indent<=l[l.length-1].indent;)l.pop();let t=l[l.length-1];if(!t){let t=[];o.push({id:P(N(e.label)||`b${o.length}`,s),label:e.label,children:t}),l.push({indent:e.indent,children:t});continue}let n=[];t.children.push({label:e.label,icon:e.attrs.icon,children:n}),l.push({indent:e.indent,children:n})}return{diagram:A({kind:`mindmap`,title:r,central:i||r,branches:o}),diagnostics:t,iconUses:n.iconUses}}var dt=[...Object.keys(w),`mindmap`,`gitgraph`,`gantt`,`sankey`,...y],W=[`<-.->`,`<-->`,`<..>`,`-.->`,`<-.-`,`<->`,`-->`,`<--`,`<..`,`..>`,`<-`,`->`,`<>`,`>`,`<`],ft={"1:1":{value:`1:1`,swap:!1},"1:n":{value:`1:N`,swap:!1},"n:1":{value:`1:N`,swap:!0},"n:m":{value:`N:M`,swap:!1},"m:n":{value:`N:M`,swap:!1}},pt=[`1:1`,`1:N`,`N:1`,`N:M`],mt={"|o":`zeroOrOne`,"||":`one`,"}o":`zeroOrMany`,"}|":`oneOrMany`},ht={"o|":`zeroOrOne`,"||":`one`,"o{":`zeroOrMany`,"|{":`oneOrMany`};Object.fromEntries(Object.entries(mt).map(([e,t])=>[t,e])),Object.fromEntries(Object.entries(ht).map(([e,t])=>[t,e]));var gt={};for(let[e,t]of Object.entries(mt))for(let[n,r]of Object.entries(ht))for(let[i,a]of[[`--`,!0],[`..`,!1]])gt[`${e}${i}${n}`]={from:t,to:r,identifying:a};var _t=Object.keys(gt),vt=[`||--||`,`||--o{`,`|o--o{`,`||--|{`,`}|--o{`],yt={"<|--":{kind:`inheritance`,swap:!0},"--|>":{kind:`inheritance`,swap:!1},"<|..":{kind:`realization`,swap:!0},"..|>":{kind:`realization`,swap:!1},"--*":{kind:`composition`,swap:!0},"*--":{kind:`composition`,swap:!1},"--o":{kind:`aggregation`,swap:!0},"o--":{kind:`aggregation`,swap:!1},"..>":{kind:`dependency`,swap:!1},"<..":{kind:`dependency`,swap:!0}},bt=Object.keys(yt),xt=e=>e.includes(`.`)||e.includes(`--`),St=e=>e===`<-`||e===`<..`||e===`<--`||e===`<-.-`||e===`<`,Ct=e=>e===`<->`||e===`<..>`||e===`<-->`||e===`<-.->`||e===`<>`;function wt(e){return/^[<\-.*o]/.test(e)}function Tt(e){return wt(e)?e:` ${e} `}function Et(e){return wt(e)?e.length:e.length+2}function Dt(e,t,n=0){let r=Pe(e,t.map(Tt),n);return r?{index:r.index,token:t[r.needle]}:null}function Ot(e,t){let n=[],r=null,i=0;for(;i<e.length;){let a=Dt(e,t,i);if(!a)break;let o=e.slice(i,a.index);r===null?r=o:n[n.length-1].segment=o,n.push({token:a.token,segment:``}),i=a.index+Et(a.token)}return r===null?null:(n[n.length-1].segment=e.slice(i),{first:r,hops:n})}function kt(){return{diagnostics:[],iconUses:[],raw:{},family:null,title:``,direction:void 0,icons:void 0,kanban:!1,defaultFill:void 0,nodes:[],groups:[],edges:[],nodeByKey:new Map,groupByKey:new Map,usedIds:new Set,groupStack:[],actors:[],messages:[],frames:[],blockStack:[],activations:[],activationOpen:new Map,notes:[],legendEntries:[],inLegend:!1,entities:[],relations:[],currentEntity:null,erdGroupStack:[],classHeader:!1,screens:[],currentScreen:null}}function At(e){return e.groupStack[e.groupStack.length-1]??null}function G(e){return e.family??`architecture`}function jt(e,t,n,r){let i=(r??t).toLowerCase(),a=r?e.nodeByKey.get(i):e.nodeByKey.get(i)??e.nodeByKey.get(t.toLowerCase());if(a){let t=e.nodes.find(e=>e.id===a);return t&&(t.icon??=n.icon,t.shape??=n.shape,t.color??=n.color,t.fill??=n.fill,t.corner??=n.corner,t.labelColor??=n.labelColor,t.shadow||=n.shadow,t.link??=n.link,t.group??=n.group?Mt(e,n.group):At(e)??void 0,n.label&&(t.label=n.label)),a}let o=P(r||N(t),e.usedIds);return e.nodes.push({id:o,label:n.label??t,icon:n.icon,shape:n.shape,color:n.color,fill:n.fill,corner:n.corner,labelColor:n.labelColor,shadow:n.shadow,link:n.link,group:n.group?Mt(e,n.group):At(e)??void 0}),e.nodeByKey.set(i,o),(!r||!e.nodeByKey.has(t.toLowerCase()))&&e.nodeByKey.set(t.toLowerCase(),o),n.label&&!e.nodeByKey.has(n.label.toLowerCase())&&e.nodeByKey.set(n.label.toLowerCase(),o),o}function Mt(e,t){let n=t.toLowerCase(),r=e.groupByKey.get(n);if(r)return r;let i=P(N(t),e.usedIds);return e.groups.push({id:i,label:t}),e.groupByKey.set(n,i),i}function Nt(e,t,n,r){let i=Mt(e,t),a=e.groups.find(e=>e.id===i);return a&&(a.icon??=n.icon,a.color??=n.color,a.frame??=n.frame,r&&!a.parent&&r!==i&&(a.parent=r),n.label&&(a.label=n.label)),i}function Pt(e,t,n,r,i,a){let o=(n??t).toLowerCase(),s=e.nodeByKey.get(o)??e.nodeByKey.get(t.toLowerCase());if(s){let t=e.actors.find(e=>e.id===s);return t&&(r&&(t.label=r),t.icon??=i,t.link??=a),s}let c=P(n??N(t),e.usedIds);return e.actors.push({id:c,label:r??t,icon:i,link:a}),e.nodeByKey.set(o,c),e.nodeByKey.set(t.toLowerCase(),c),r&&!e.nodeByKey.has(r.toLowerCase())&&e.nodeByKey.set(r.toLowerCase(),c),c}function Ft(e,t,n){let{attrs:r,rest:i}=B(t.trim()),a=U(r,n,e),{id:o,name:s}=Rt(i);if(!s)return null;if(!(e.nodeByKey.get((o??s).toLowerCase())??e.nodeByKey.get(s.toLowerCase()))){let t=e.groupByKey.get(s.toLowerCase());if(t)return t}return jt(e,s,a,o)}function It(e,t,n){let{attrs:r,rest:i}=B(t.trim()),a=U(r,n,e),{id:o,name:s}=Rt(i);return s?Pt(e,s,o,a.label,a.icon,a.link):null}function Lt(e,t){let n=e.nodeByKey.get(t.toLowerCase());if(n)return n;let r=t.lastIndexOf(`.`);return r>0?e.nodeByKey.get(t.slice(0,r).trim().toLowerCase())??null:null}function Rt(e){let t=F(e,`=`);if(t===-1)return{name:R(e)};let n=e.slice(0,t).trim(),r=R(e.slice(t+1));return/^[A-Za-z0-9_-]+$/.test(n)?{id:n.toLowerCase(),name:r}:{name:R(e)}}var zt=[..._t,...bt,...W,...Object.keys(ft).flatMap(e=>[e,e.toUpperCase()])],Bt=[...W];function Vt(e,t){let n=F(e,`:`,t);for(;n!==-1&&(e[n+1]===`:`||e[n-1]===`:`);)n=F(e,`:`,e[n+1]===`:`?n+2:n+1);return n}function Ht(e,t,n){let r=G(e)===`erd`?zt:Bt,i=Dt(t,r);if(!i)return!1;let a=Vt(t,i.index+Et(i.token)),o=a===-1?void 0:t.slice(a+1).trim()||void 0,s={};if(o!==void 0&&G(e)!==`erd`){let t=B(o);t.attrs!==null&&(s=U(t.attrs,n,e),o=t.rest.trim()||void 0)}let c=Ot(a===-1?t:t.slice(0,a),r);if(!c)return!1;if(G(e)===`sequence`){let t=It(e,c.first,n),r=It(e,c.hops[0].segment,n);if(!t||!r)return e.diagnostics.push({line:n,message:`message needs both ends`,severity:`error`}),!0;c.hops.length>1&&e.diagnostics.push({line:n,message:`one message per line in sequence diagrams`});let i=c.hops[0].token,a=St(i);return e.messages.push({from:a?r:t,to:a?t:r,label:o??``,reply:xt(i)||void 0,bidirectional:Ct(i)||void 0}),!0}if(G(e)===`erd`){let t=R(c.first),r=c.hops[0],i=R(r.segment),a=Lt(e,t),s=Lt(e,i);if(!a||!s)return e.diagnostics.push({line:n,message:`relation references an undeclared table (${a?i:t})`,severity:`error`}),!0;let l=yt[r.token],u=gt[r.token],d=u||l?void 0:ft[r.token.toLowerCase()],f=l?l.swap:d?.swap;return c.hops.length>1&&e.diagnostics.push({line:n,message:`one relation per line in ERDs`}),e.relations.push({from:f?s:a,to:f?a:s,cardinality:d?.value,fromCard:u?.from,toCard:u?.to,identifying:u&&!u.identifying?!1:void 0,kind:l?.kind,label:o}),!0}let l=L(c.first,`,`).map(t=>Ft(e,t,n)).filter(e=>e!==null);for(let t of c.hops){let r=t.token,i=L(t.segment,`,`).map(t=>Ft(e,t,n)).filter(e=>e!==null);if(l.length===0||i.length===0)return e.diagnostics.push({line:n,message:`edge needs both ends`,severity:`error`}),!0;for(let t of l)for(let n of i)e.edges.push({from:St(r)?n:t,to:St(r)?t:n,label:o,dashed:xt(r)||void 0,bidirectional:Ct(r)||void 0,color:s.color,flow:s.flow||void 0,head:s.head,invisible:s.invisible||void 0,back:St(r)||void 0});l=i}return!0}var Ut={"+":`public`,"-":`private`,"#":`protected`,"~":`package`},Wt=new Set([`(`,`<`,`[`,`{`]),Gt=new Set([`)`,`>`,`]`,`}`]);function Kt(e){let t=[],n=0,r=!1,i=``;for(let a of e){if(a===`"`)r=!r;else if(!r&&Wt.has(a))n+=1;else if(!r&&Gt.has(a))n=Math.max(0,n-1);else if(!r&&n===0&&/\s/.test(a)){i&&t.push(i),i=``;continue}i+=a}return i&&t.push(i),t}function qt(e,t,n){if(e.currentEntity){let r=e.currentEntity,i=Kt(t.replace(/,$/,``));if(i.length===0)return!0;let a=R(i[0]);if(/^-{2,}$/.test(a)&&i.length===1)return r.methods??=[],!0;let o=/^([+\-#~])(.+)$/.exec(a),s=o?Ut[o[1]]:void 0,c=(o?o[2]:a).replace(/:$/,``),l,u;for(let t of i.slice(1)){let r=t.toLowerCase();r===`pk`||r===`fk`?u=r:l?e.classHeader?l=`${l} ${t}`:e.diagnostics.push({line:n,message:`extra field token "${t}"`}):l=R(t)}let d={name:c,type:l,key:u,visibility:s};return r.methods===void 0?(r.fields??=[]).push(d):r.methods.push(d),!0}let r=/^group\b([^{]*)\{$/i.exec(t),i=r?B(r[1].trim()):null;if(i&&R(i.rest)){let t=U(i.attrs,n,e);return e.erdGroupStack.push(Nt(e,R(i.rest),t,null)),!0}if(t.endsWith(`{`)||/\{\s*\}$/.test(t)){let r=/\{\s*\}$/.test(t),{attrs:i,rest:a}=B(t.replace(/\{\s*\}?$/,``).trim()),o=U(i,n,e),{id:s,name:c}=Rt(a);if(!c)return e.diagnostics.push({line:n,message:`table needs a name`,severity:`error`}),!0;let l=P(s??N(c),e.usedIds),u={id:l,label:o.label??c,color:o.color,fields:[],group:e.erdGroupStack[e.erdGroupStack.length-1]};return e.entities.push(u),e.nodeByKey.set((s??c).toLowerCase(),l),e.nodeByKey.set(c.toLowerCase(),l),r||(e.currentEntity=u),!0}return Ht(e,t,n)||e.diagnostics.push({line:n,message:`expected a table or relation`,severity:`error`}),!0}function Jt(e){let t=e.raw;t.kind=`erd`,t.entities=e.entities,t.relations=e.relations,t.groups=e.groups,t.variant=e.classHeader?`class`:void 0}function Yt(e,t,n){let r=/^(loop|alt|opt|par|break)\b(.*)\{$/.exec(t);if(r)return e.blockStack.push({kind:r[1],label:r[2].trim()||r[1],start:e.messages.length}),!0;let i=/^note\s+(over|left of|right of)\s+(.+?)\s*:\s*(.*)$/i.exec(t);if(i){let t=i[1].toLowerCase().startsWith(`over`)?`over`:i[1].toLowerCase().startsWith(`left`)?`left`:`right`,r=L(i[2],`,`).map(e=>e.trim()).filter(e=>e.length>0).map(t=>Pt(e,R(t)));return r.length===0?e.diagnostics.push({line:n,message:`note needs a lifeline`}):e.notes.push({text:i[3].trim(),actors:r,placement:t,after:e.messages.length-1}),!0}let a=/^(activate|deactivate)\s+(.+)$/i.exec(t);if(a){let t=Pt(e,R(a[2]));if(a[1].toLowerCase()===`activate`)if(e.activationOpen.has(t))e.diagnostics.push({line:n,message:`"${a[2]}" is already active`});else{let n=e.messages[e.messages.length-1],r=n&&(n.from===t||n.to===t);e.activationOpen.set(t,r?e.messages.length-1:e.messages.length)}else{let r=e.activationOpen.get(t);r===void 0?e.diagnostics.push({line:n,message:`deactivate without activate for "${a[2]}"`}):(e.activationOpen.delete(t),e.messages.length>r&&e.activations.push({actor:t,from:r,to:e.messages.length-1}))}return!0}if(Ht(e,t,n))return!0;let{attrs:o,rest:s}=B(t),c=U(o,n,e),{id:l,name:u}=Rt(s);return u&&Pt(e,u,l,c.label,c.icon,c.link),!0}function Xt(e){let t=e.raw;t.kind=`sequence`,t.actors=e.actors,t.messages=e.messages,t.frames=e.frames,t.activations=e.activations,t.notes=e.notes}function Zt(e,t,n){let r=/^screen\b(.*)\{$/i.exec(t);if(r){let{attrs:t,rest:i}=B(r[1].trim()),a=U(t,n,e);return e.currentScreen={name:R(i)||`Screen ${e.screens.length+1}`,frame:a.frame??`phone`,controls:[]},e.screens.push(e.currentScreen),!0}if(!e.currentScreen)return e.diagnostics.push({line:n,message:"expected `screen Name { … }`",severity:`error`}),!0;let i=e.currentScreen,{attrs:a,rest:o}=B(t),s=U(a,n,e),c=F(o,`:`),l=(c===-1?o:o.slice(0,c)).trim().toLowerCase(),u=c===-1?void 0:o.slice(c+1).trim()||void 0;return Je.has(l)?(i.controls??=[],i.controls.push({kind:l,label:s.label??u,width:s.width,value:s.value}),!0):(e.diagnostics.push({line:n,message:`unknown widget "${l}"`,severity:`error`}),!0)}function Qt(e){let t=e.raw;t.kind=`wireframe`,t.screens=e.screens}var $t={bar:`bar`,column:`bar`,xychart:`bar`,xy:`bar`,line:`line`,area:`area`,scatter:`scatter`,pie:`pie`,donut:`donut`,doughnut:`donut`,radar:`radar`,quadrant:`quadrant`},en=[...new Set(Object.values($t))],tn=new Set([`chart`,`pie`,`xychart`,`radar`,...Object.keys($t)]);function nn(e){let t=e.trim().toLowerCase().split(/\s+/),n=t[0];return n===`chart`?$t[t[1]??``]??`bar`:$t[n]??`bar`}function rn(e){return L(e,`,`).map(e=>R(e.trim())).filter(e=>e.length>0)}function an(e){let t=/^\[?\s*([-\d.]+)\s*,\s*([-\d.]+)\s*\]?$/.exec(e.trim());return t?[t[1],t[2]]:null}function on(e){let t=[],n=e.split(`
|
|
8
|
-
`),r=n.findIndex(e=>I(e).trim().length>0);if(r===-1)return{spec:null,diagnostics:t};let i=nn(I(n[r]).trim()),a,o,s,c,l,u,d=null,f=[],p=[],m=i===`quadrant`,h=[``,``,``,``],g=[];for(let e=r+1;e<n.length;e+=1){let r=I(n[e]).trim();if(!r)continue;let i=r.toLowerCase();if(i===`showvalues`||i===`values`||i===`showdata`){c=!0;continue}if(i===`stacked`){l=!0;continue}if(i===`horizontal`){u=!0;continue}let _=r.indexOf(`:`);if(_===-1){t.push({line:e+1,message:`chart rows are "label: values"; skipped "${r}"`});continue}let v=r.slice(0,_).trim(),y=v.toLowerCase(),b=r.slice(_+1).trim();if(y===`title`){a=R(b);continue}if(y===`x-axis`||y===`xaxis`||y===`x`){o=R(b);continue}if(y===`y-axis`||y===`yaxis`||y===`y`){s=R(b);continue}if(m){let n=/^quadrant-([1-4])$/.exec(y);if(n){h[Number(n[1])-1]=R(b);continue}let i=an(b);if(i){g.push([R(v),i[0],i[1]]);continue}t.push({line:e+1,message:`quadrant rows are "label: [x, y]"; skipped "${r}"`});continue}if(y===`categories`||y===`axis`||y===`labels`){d=rn(b);continue}let x=/^series\s+(.+)$/i.exec(v),S=R((x?x[1]:v).trim()),C=rn(b);if(C.length===0){t.push({line:e+1,message:`"${v}" has no numeric values`});continue}d||x?f.push({name:S,values:C}):p.push({label:S,values:C})}let _=m?[[``,`x`,`y`],...g]:cn(d,f,p);return _.length<2?(t.push({line:0,message:`chart has no data rows`,severity:`error`}),{spec:null,diagnostics:t}):{spec:{chartType:i,title:a,xTitle:o,yTitle:s,cells:_,showValues:c,stacked:l,horizontal:u,showLegend:m?void 0:sn(i,_,f.filter(e=>e.name).length)||void 0,quadrantLabels:m&&h.some(Boolean)?h:void 0},diagnostics:t}}function sn(e,t,n){return e===`pie`||e===`donut`?t.slice(1).some(e=>(e[0]??``).trim().length>0):e===`radar`?n>=1:n>=2}function cn(e,t,n){if(e&&t.length>0)return[[``,...t.map(e=>e.name||`Value`)],...e.map((e,n)=>[e,...t.map(e=>e.values[n]??``)])];if(t.length>0){let e=Math.max(...t.map(e=>e.values.length)),n=[``,...t.map(e=>e.name||`Value`)],r=[];for(let n=0;n<e;n+=1)r.push([`${n+1}`,...t.map(e=>e.values[n]??``)]);return[n,...r]}if(n.length>0){let e=Math.max(...n.map(e=>e.values.length));return[e<=1?[``,`Value`]:[``,...Array.from({length:e},(e,t)=>`Series ${t+1}`)],...n.map(t=>[t.label,...Array.from({length:e},(e,n)=>t.values[n]??``)])]}return[]}function ln(e){let t=Math.max(0,e.cells.length-1);if(e.chartType===`quadrant`)return`a quadrant chart · ${t} ${t===1?`point`:`points`}`;let n=Math.max(0,e.cells[0].length-1),r=n===1?`1 series`:`${n} series`;return`a ${e.chartType} chart · ${t} ${t===1?`row`:`rows`} · ${r}`}var un=new Set([...dt,...tn]),dn=new Set(y),fn=new Set([`[*]`,`start`,`begin`,`initial`]),pn=new Set([`end`,`final`,`stop`,`done`]);function mn(e,t){if(e===`flowchart`||e===`bpmn`||e===`orgchart`){t.shape??=`rectangle`;return}if(e!==`statemachine`)return;let n=t.id??``,r=(t.label??``).toLowerCase();fn.has(n)||fn.has(r)?(t.shape??=`circle`,t.fill??=`bold`,t.color??=`gray`):pn.has(n)||pn.has(r)?t.shape??=`double-circle`:t.shape??=`ellipse`}function hn(e,t,n){let r=w[t.toLowerCase()];if(r&&e.family===null&&e.nodes.length===0&&e.actors.length===0&&e.entities.length===0&&e.screens.length===0&&!e.title){e.family=r;let n=t.toLowerCase();return e.classHeader=n===`class`||n===`uml`,!0}if(e.inLegend&&!t.startsWith(`}`)){let r=F(t,`:`);return r===-1?(e.diagnostics.push({line:n,message:"legend rows are `swatch: meaning`",severity:`error`}),!0):(e.legendEntries.push({swatch:R(t.slice(0,r)),label:t.slice(r+1).trim()}),!0)}if(t.startsWith(`}`)){let r=t.slice(1).trim();if(e.inLegend)return e.inLegend=!1,!0;if(G(e)===`sequence`&&e.blockStack.length>0){let t=e.blockStack.pop();e.messages.length>t.start?e.frames.push({kind:t.kind,label:t.label,from:t.start,to:e.messages.length-1}):e.diagnostics.push({line:n,message:`empty ${t.kind} block`});let i=/^(else|and)\b(.*)\{$/.exec(r);return i?e.blockStack.push({kind:i[1]===`and`?`par`:`alt`,label:i[2].trim()||i[1],start:e.messages.length}):r&&e.diagnostics.push({line:n,message:`unexpected "${r}" after }`,severity:`error`}),!0}return e.currentEntity?(e.currentEntity=null,!0):e.erdGroupStack.length>0?(e.erdGroupStack.pop(),!0):e.currentScreen?(e.currentScreen=null,!0):e.groupStack.length>0?(e.groupStack.pop(),!0):(e.diagnostics.push({line:n,message:`unmatched }`,severity:`error`}),!0)}if(/^legend\b.*\{$/i.test(t))return e.inLegend=!0,!0;let i=/^direction\s+(right|down|left|up)$/i.exec(t);if(i&&!e.currentEntity&&!e.currentScreen)return e.direction=i[1].toLowerCase(),!0;if(/^kanban$/i.test(t)&&!e.currentEntity&&!e.currentScreen)return e.kanban=!0,!0;let a=/^title\s+(\S.*)$/i.exec(t);if(a&&!e.title&&!e.currentEntity&&!e.currentScreen)return e.title=R(a[1].trim()),!0;let o=/^(colorMode|styleMode|typeface|autoNumber)\b\s*:?\s*(.*)$/i.exec(t);if(o&&!e.currentEntity&&!e.currentScreen){let t=o[1].toLowerCase(),r=o[2].trim().toLowerCase();return t===`colormode`&&H[r]?e.defaultFill=H[r]:e.diagnostics.push({line:n,message:`${o[1]} isn't supported; skipped`}),!0}let s=/^(title|direction|icons)\s*:\s*(.+)$/i.exec(t);if(s&&!e.currentEntity&&!e.currentScreen){let t=s[1].toLowerCase(),r=s[2].trim();if(t===`title`)e.title=R(r);else if(t===`icons`){let t=r.toLowerCase();t===`inside`||t===`badge`||t===`hanging`?e.icons=t===`inside`?`inside`:`badge`:e.diagnostics.push({line:n,message:`icons "${r}" is not supported (badge, inside)`})}else{let t=r.toLowerCase();t===`down`||t===`right`||t===`up`||t===`left`?e.direction=t:e.diagnostics.push({line:n,message:`direction "${r}" is not supported (right, down, left, up)`})}return!0}return!1}function gn(e,t,n){let r=t.replace(/^group\b/i,``),i=r!==t,a=(i?/^(.*)\{$/:/^([^{]+)\{$/).exec(r);if(a){let{attrs:t,rest:r}=B(a[1].trim()),i=U(t,n,e),o=R(r)||`Group ${e.groups.length+1}`;return e.groupStack.push(Nt(e,o,i,At(e))),!0}let o=(i?/^([^{]*)\{(.*)\}$/:/^([^{]+)\{(.+)\}$/).exec(r);if(o){let{attrs:t,rest:r}=B(o[1].trim()),i=U(t,n,e),a=Nt(e,R(r)||`Group ${e.groups.length+1}`,i,At(e));for(let t of L(o[2],`,`)){let r=R(t);r&&_n(e,jt(e,r,{}),a,n)}return!0}if(Ht(e,t,n))return!0;let s=At(e),c=s?L(t,`,`):[t];for(let t of c){let r=t.trim();if(!r)continue;let{attrs:i,rest:a}=B(r),o=U(i,n,e),{id:c,name:l}=Rt(a);if(!l){e.diagnostics.push({line:n,message:`expected a node name`,severity:`error`});continue}let u=jt(e,l,o,c);s&&_n(e,u,s,n)}return!0}function _n(e,t,n,r){let i=e.nodes.find(e=>e.id===t);if(!i)return;let a=i.group;if(i.group=n,a===void 0||a===n)return;let o=t=>e.groups.find(e=>e.id===t)?.label??t;e.diagnostics.push({line:r,message:`"${i.label}" is already in group "${o(a)}" — one name is one node, so it moved to "${o(n)}". For a separate node with the same label, give it its own id: \`${N(o(n))}-${i.id} = ${i.label}\` (and use that id in its edges)`})}function vn(e){let t=G(e),n=e.raw;if(n.title=e.title,n.legend=e.legendEntries.length>0?e.legendEntries:void 0,t===`sequence`)Xt(e);else if(t===`erd`)Jt(e);else if(t===`wireframe`)Qt(e);else{n.kind=`graph`;let r=t===`flowchart`||t===`bpmn`||t===`orgchart`;n.direction=e.direction??(r?`down`:`right`),n.icons=e.icons,n.swimlanes=t===`bpmn`||void 0,n.kanban=e.kanban?!0:void 0,n.variant=t===`orgchart`?`orgchart`:t===`statemachine`?`statemachine`:void 0;for(let n of e.nodes)mn(t,n);if(e.defaultFill)for(let t of e.nodes)t.fill??=e.defaultFill;n.nodes=e.nodes,n.groups=e.groups,n.edges=e.edges;for(let t of e.groups){let n=e.nodes.some(e=>e.group===t.id),r=e.groups.some(e=>e.parent===t.id&&e.id!==t.id);!n&&!r&&e.diagnostics.push({line:0,message:`group "${t.label}" has no members`})}}return{diagram:A(n),diagnostics:e.diagnostics,iconUses:e.iconUses}}function yn(e){let t=e.split(`
|
|
9
|
-
`).map(e=>I(e).trim().toLowerCase()).find(e=>e.length>0);if(t===`mindmap`)return ut(e);if(t===`gitgraph`)return ze(e);if(t===`gantt`)return Le(e);if(t===`sankey`)return Be(e);let n=(t??``).split(/\s+/)[0];if(dn.has(n))return lt(e,n);if(tn.has(n)){let{spec:t,diagnostics:n}=on(e);return{diagram:A({kind:`graph`}),chart:t??void 0,diagnostics:n,iconUses:[]}}let r=kt(),i=e.split(`
|
|
10
|
-
`);for(let e=0;e<i.length;e+=1){let t=e+1,n=I(i[e]).trim();if(n&&!hn(r,n,t)){if(G(r)===`sequence`){Yt(r,n,t);continue}if(G(r)===`erd`){qt(r,n,t);continue}if(G(r)===`wireframe`){Zt(r,n,t);continue}gn(r,n,t)}}for(let e of r.blockStack)r.messages.length>e.start&&r.frames.push({kind:e.kind,label:e.label,from:e.start,to:r.messages.length-1}),r.diagnostics.push({line:i.length,message:`unclosed ${e.kind} block`,severity:`error`});for(let[e,t]of r.activationOpen)r.messages.length>t&&r.activations.push({actor:e,from:t,to:r.messages.length-1});return vn(r)}var bn={architecture:`architecture`,graph:`architecture`,flowchart:`flowchart`,flow:`flowchart`,bpmn:`flowchart`,sequence:`sequence`,erd:`erd`,wireframe:`flowchart`},xn={"<-->":`<-->`,"-->":`-->`,"<--":`<--`,"<>":`<->`,"--":`-->`,">":`->`,"<":`<-`,"-":`->`},Sn={"<>":`N:M`,">":`N:1`,"<":`1:N`,"-":`1:1`},Cn=/^[\w"][\w" -]*\s+[\w(),]+\s+(pk|fk)\s*$/i,wn=/^(loop|alt|opt|par|break)\b.*\{\s*$/i,Tn=/^(activate|deactivate)\s+\S/i,En=/\[[^\]]*\b(diamond|oval|circle|cylinder|hexagon|parallelogram|trapezoid|triangle|cloud|star|queue|callout|note|sticky)\b[^\]]*\]/i,Dn=[`<-->`,`<..>`,`<->`,`-->`,`<--`,`<..`,`..>`,`<-`,`->`,`<>`,`>`,`<`,`--`,`-`];function On(e){let t=0,n=-1;for(let r=0;r<e.length;r+=1){let i=e[r];if(i===`[`)t+=1;else if(i===`]`)t=Math.max(0,t-1);else if(i===`:`&&t===0){n=r;break}}let r=(n>=0?e.slice(0,n):e).trim(),i=e=>e.replace(/\s*\[[^\]]*\]\s*$/,``).trim();for(let e of Dn){let t=r.indexOf(` ${e} `);if(t>=0)return{src:i(r.slice(0,t)),dst:i(r.slice(t+e.length+2))}}return null}function kn(e){let t=0,n=0,r=0,i=0,a=0,o=new Set;for(let s of e){if(!s)continue;Cn.test(s)&&(t+=1),(wn.test(s)||Tn.test(s))&&(n+=1),En.test(s)&&(i+=1),/\{\s*$/.test(s)&&!wn.test(s)&&!s.startsWith(`}`)&&(a+=1);let e=On(s);e&&e.src&&e.dst&&(r+=1,o.add(e.src.toLowerCase()),o.add(e.dst.toLowerCase()),e.src.toLowerCase()===e.dst.toLowerCase()&&(n+=2))}return t>0?`erd`:n>0||r>=3&&i===0&&a===0&&o.size>0&&r/o.size>=1.3?`sequence`:e.some(e=>/icon:\s*(aws|gcp|azure|tech)[-/]/i.test(e))?`architecture`:`flowchart`}function An(e,t){let n=[...new Set([...Object.keys(t),...W])].sort((e,t)=>t.length-e.length),r=new Set,i=``,a=!1,o=0,s=0;for(;s<e.length;){let c=e[s];if(c===`"`){a=!a,i+=c,s+=1;continue}if(a){i+=c,s+=1;continue}if(c===`[`){o+=1,i+=c,s+=1;continue}if(c===`]`){o=Math.max(0,o-1),i+=c,s+=1;continue}if(o>0){i+=c,s+=1;continue}let l=!1;for(let a of n){if(!e.startsWith(a,s))continue;let n=t[a];if(n===void 0){i+=a,s+=a.length,l=!0;break}let o=s===0?` `:e[s-1],c=s+a.length>=e.length?` `:e[s+a.length];if(!(!/\s/.test(o)||!/\s/.test(c))){i+=n,r.add(a),s+=a.length,l=!0;break}}l||(i+=c,s+=1)}return{text:i,rewrote:r}}function jn(e,t,n){let{rest:r,attrs:i}=B(e.slice(0,e.lastIndexOf(`{`)).trimEnd());if(i===null)return e;let a=[];for(let e of L(i,`,`)){let r=e.trim();if(!r)continue;let i=r.indexOf(`:`),o=i===-1?null:r.slice(0,i).trim().toLowerCase();if(o===`color`||o===`label`){a.push(r);continue}let s=i===-1?r.toLowerCase():null;if(s&&(V[s]||rt(R(r)))){a.push(r);continue}n.push({line:t,message:o===`icon`?`table icons aren't supported; dropped "${r.slice(i+1).trim()}"`:`"${r}" isn't supported on tables; dropped`})}let o=r.trim();return a.length>0?`${o} [${a.join(`, `)}] {`:`${o} {`}function Mn(e){for(let t of L(e,`,`)){let e=t.trim(),n=e.indexOf(`:`);if(n!==-1&&e.slice(0,n).trim().toLowerCase()===`label`)return R(e.slice(n+1))}return R(e)}function Nn(e){let t=e.split(`
|
|
11
|
-
`),n=t.map(e=>I(e).trim()),r=bn[(n.find(Boolean)??``).toLowerCase()];if(r)return{code:e,family:r,diagnostics:[]};let i=kn(n),a=[],o=[i,``],s=!1;for(let e=0;e<t.length;e+=1){let n=o.length+1,r=t[e],c=I(r),l=r.slice(c.length),u=c.trim(),d=c.slice(0,c.length-c.trimStart().length);if(!u){o.push(r);continue}let f=/^(styleMode|typeface|autoNumber)\b/i.exec(u);if(f&&!s){a.push({line:n,message:`${f[1]} isn't supported; removed`}),o.push(`${d}// ${u} (not supported)${l}`);continue}if(/^colorMode\b/i.test(u)&&!s){o.push(`${d}${u.replace(/^colorMode\s*:?\s*/i,`colorMode `)}${l}`);continue}if(i===`erd`){if(s){u.startsWith(`}`)&&(s=!1),o.push(r);continue}if(u.endsWith(`{`)){o.push(`${d}${jn(u,n,a)}${l}`),s=!0;continue}let{text:e}=An(c,Sn);o.push(`${e}${l}`);continue}if(i===`sequence`){let e=/^(loop|alt|opt|par|break)\s*\[(.*)\]\s*\{$/i.exec(u);if(e){let t=Mn(e[2]);o.push(`${d}${e[1].toLowerCase()}${t?` ${t}`:``} {${l}`);continue}let t=/^\}\s*(else|and)\s*\[(.*)\]\s*\{$/i.exec(u);if(t){let e=Mn(t[2]);o.push(`${d}} ${t[1].toLowerCase()}${e?` ${e}`:``} {${l}`);continue}}let{text:p,rewrote:m}=An(c,xn);(m.has(`-`)||m.has(`--`))&&a.push({line:n,message:`plain lines render as arrows`}),o.push(`${p}${l}`)}return{code:o.join(`
|
|
12
|
-
`),family:i,diagnostics:a}}function Pn(e){let t=e.split(`
|
|
13
|
-
`).map(e=>I(e).trim()).filter(Boolean);if(t.length===0||un.has(t[0].toLowerCase().split(/\s+/)[0]))return!1;let n=!1;for(let e of t){if(/(^|\s)(-->|<--|<-->)(\s|$)/.test(e)){n=!0;continue}if(/->|\.\.>|<\.\./.test(e)||/(^|\s)<-(\s|$)/.test(e)||/(^|\s)(1:1|1:N|N:1|N:M|M:N)(\s|$)/i.test(e))return!1;/(^|\s)(>|<|<>|-)\s/.test(e)&&(n=!0),/^(colorMode|styleMode|typeface|autoNumber)\b/i.test(e)&&(n=!0),/\[[^\]]*icon\s*:[^\]]*\]\s*\{$/.test(e)&&(n=!0),/^(loop|alt|opt|par|break)\s*\[label\s*:/i.test(e)&&(n=!0)}return n}function Fn(e){let t=e.trim(),n=/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(t);return n&&(t=`#${n[1]}${n[1]}${n[2]}${n[2]}${n[3]}${n[3]}`),rt(t)}function In(e){let t=/fill:\s*([^,;]+)/i.exec(e),n=/stroke:\s*([^,;]+)/i.exec(e),r=t?.[1]??n?.[1];return!r||/none|transparent/i.test(r)?n&&n!==t?Fn(n[1]):null:Fn(r)}function K(e){if(/%%\{/.test(e))return e;let t=e.indexOf(`%%`);return t>=0?e.slice(0,t):e}function Ln(e){return!Number.isInteger(e)||e<1||e>1114111?``:String.fromCodePoint(e)}function q(e){let t=e.trim();t.length>=2&&/^["'].*["']$/.test(t)&&(t=t.slice(1,-1).trim());let n=t.startsWith("`")&&t.endsWith("`");return t=t.replace(/<br\s*\/?>/gi,` `).replace(/^`+|`+$/g,``),n&&(t=t.replace(/\*\*([^*]+)\*\*/g,`$1`).replace(/\*([^*]+)\*/g,`$1`).replace(/__([^_]+)__/g,`$1`).replace(/_([^_]+)_/g,`$1`)),t.replace(/\*\*/g,``).replace(/\\"/g,`"`).replace(/&?#x([0-9a-f]+);/gi,(e,t)=>Ln(parseInt(t,16))).replace(/&?#(\d+);/g,(e,t)=>Ln(Number(t))).replace(/\b(fa|fab|fas|far|fal|fad|fak):[a-z0-9-]+/gi,``).replace(/\s+/g,` `).trim()}function Rn(e){let t=[],n=``,r=!1;for(let i of e){let e=r?`${n} ${i.trim()}`:i;(e.match(/"/g)??[]).length%2==1?(n=e,r=!0):(t.push(e),n=``,r=!1)}return r&&t.push(n),t}function J(e){return/[:=[\]{}<>]|->|--|\/\//.test(e)?`"${e.replace(/"/g,``)}"`:e}function Y(e){return/[[\]{}]/.test(e)||/\/\//.test(e)?`"${e.replace(/"/g,``)}"`:e}function zn(e,t){if(!t||/^title:/m.test(e))return e;let n=e.split(`
|
|
14
|
-
`);return n.splice(1,0,`title: ${t}`),n.join(`
|
|
15
|
-
`)}function X(e){return e.join(`
|
|
16
|
-
`).replace(/\n{3,}/g,`
|
|
17
|
-
|
|
18
|
-
`).trimEnd()+`
|
|
19
|
-
`}function Bn(e){let t=e.replace(/%%\{[\s\S]*?\}%%/g,``),n,r=0,i=/^\s*---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(t);if(i){let e=/^\s*title:\s*(.+)$/m.exec(i[1]);e&&(n=q(e[1].trim())),t=t.slice(i[0].length),r=i[0].split(`
|
|
20
|
-
`).length-1}return{lines:t.split(`
|
|
21
|
-
`),title:n,dropped:r}}var Vn={TD:`down`,TB:`down`,BT:`up`,LR:`right`,RL:`left`},Hn=[{open:`(((`,close:`)))`,shape:`double-circle`},{open:`([`,close:`])`,shape:`ellipse`},{open:`[[`,close:`]]`,shape:`predefined-process`},{open:`[(`,close:`)]`,shape:`cylinder`},{open:`((`,close:`))`,shape:`circle`},{open:`{{`,close:`}}`,shape:`hexagon`},{open:`[/`,close:`/]`,shape:`parallelogram`},{open:`[\\`,close:`\\]`,shape:`parallelogram`},{open:`[/`,close:`\\]`,shape:`trapezoid`},{open:`[\\`,close:`/]`,shape:`trapezoid`},{open:`[`,close:`]`,shape:null},{open:`(`,close:`)`,shape:null},{open:`{`,close:`}`,shape:`diamond`},{open:`>`,close:`]`,shape:`chevron`}],Un={rect:`rectangle`,proc:`rectangle`,process:`rectangle`,rectangle:`rectangle`,rounded:`rectangle`,event:`rectangle`,"lin-rect":`rectangle`,"lin-proc":`rectangle`,"lined-process":`rectangle`,"lined-rectangle":`rectangle`,"shaded-process":`rectangle`,"div-rect":`rectangle`,"div-proc":`rectangle`,"divided-process":`rectangle`,"divided-rectangle":`rectangle`,"win-pane":`rectangle`,"internal-storage":`rectangle`,"window-pane":`rectangle`,text:`rectangle`,odd:`rectangle`,"tag-rect":`rectangle`,"tag-proc":`rectangle`,"tagged-process":`rectangle`,"tagged-rectangle":`rectangle`,"st-rect":`multi-process`,processes:`multi-process`,procs:`multi-process`,"stacked-rectangle":`multi-process`,fork:`fork-join`,join:`fork-join`,stadium:`ellipse`,pill:`ellipse`,terminal:`ellipse`,delay:`delay`,"half-rounded-rectangle":`delay`,hourglass:`ellipse`,collate:`ellipse`,display:`ellipse`,"curv-trap":`ellipse`,"curved-trapezoid":`ellipse`,"fr-rect":`predefined-process`,subproc:`predefined-process`,subprocess:`predefined-process`,subroutine:`predefined-process`,"framed-rectangle":`predefined-process`,diam:`diamond`,decision:`diamond`,diamond:`diamond`,question:`diamond`,cyl:`cylinder`,cylinder:`cylinder`,database:`cylinder`,db:`cylinder`,"lin-cyl":`cylinder`,"lined-cylinder":`cylinder`,disk:`cylinder`,"h-cyl":`cylinder`,"horizontal-cylinder":`cylinder`,das:`cylinder`,"bow-rect":`cylinder`,"bow-tie-rectangle":`cylinder`,"stored-data":`cylinder`,datastore:`cylinder`,"data-store":`cylinder`,"lean-r":`parallelogram`,"lean-right":`parallelogram`,"in-out":`parallelogram`,"lean-l":`parallelogram`,"lean-left":`parallelogram`,"out-in":`parallelogram`,flag:`parallelogram`,"paper-tape":`parallelogram`,"trap-b":`trapezoid`,"trapezoid-bottom":`trapezoid`,trapezoid:`trapezoid`,priority:`trapezoid`,"trap-t":`trapezoid`,"trapezoid-top":`trapezoid`,"inv-trapezoid":`trapezoid`,manual:`trapezoid`,doc:`document`,document:`document`,"lin-doc":`document`,"lined-document":`document`,"tag-doc":`document`,"tagged-document":`document`,docs:`multi-document`,documents:`multi-document`,"st-doc":`multi-document`,"stacked-document":`multi-document`,tri:`triangle`,triangle:`triangle`,extract:`triangle`,"flip-tri":`triangle`,"flipped-triangle":`triangle`,"manual-file":`triangle`,cloud:`cloud`,bang:`star`,bolt:`bolt`,"com-link":`bolt`,"lightning-bolt":`bolt`,brace:`note`,"brace-l":`note`,"brace-r":`note`,braces:`note`,comment:`note`,"notch-rect":`card`,card:`card`,"notched-rectangle":`card`,"notch-pent":`pentagon`,"loop-limit":`pentagon`,"notched-pentagon":`pentagon`,"sl-rect":`manual-input`,"manual-input":`manual-input`,"sloped-rectangle":`manual-input`,hex:`hexagon`,hexagon:`hexagon`,prepare:`hexagon`,circle:`circle`,circ:`circle`,"sm-circ":`circle`,"small-circle":`circle`,start:`circle`,"dbl-circ":`double-circle`,"double-circle":`double-circle`,"fr-circ":`double-circle`,"framed-circle":`double-circle`,stop:`octagon`,"f-circ":`circle`,junction:`circle`,"filled-circle":`circle`,"cross-circ":`circle`,summary:`circle`,"crossed-circle":`circle`,icon:`rectangle`,img:`rectangle`},Wn=/\s*((?:<|o|x)?(?:-\.+-*|-{2,}|={2,}|~{3,})(?:>|o|x)?)\s*(?:\|([^|]*)\|)?\s*/,Gn=new RegExp(Wn.source,`g`);function Kn(e,t){let n=/^classDef\s+(\S+)\s+(.+)$/i.exec(e);if(n){let e=In(n[2]);return e&&t.classColor.set(n[1],e),t.classAnim&&/animation/i.test(n[2])&&t.classAnim.add(n[1]),!0}let r=/^style\s+(\S+)\s+(.+)$/i.exec(e);if(r){let e=In(r[2]);return e&&t.styleColor.set(r[1],e),!0}let i=/^class\s+(.+?)\s+(\S+)$/i.exec(e);if(i){let e=t.keyOf??(e=>e);for(let n of i[1].split(`,`).map(e=>e.trim()).filter(Boolean))t.nodeClass.set(e(n),i[2]);return!0}return!1}function qn(e){let t=e.trim(),n=/[ox]$/.exec(t),r=/^~{3,}$/.test(t);return{dashed:t.includes(`.`),bidir:/^[<ox]/.test(t)&&/[>ox]$/.test(t),head:n?n[0]===`o`?`circle`:`cross`:null,invisible:r}}function Jn(e){return e.replace(/--\s+([^|]+?)\s+-->/g,`-->|$1|`).replace(/==\s+([^|]+?)\s+==>/g,`==>|$1|`).replace(/-\.\s+([^|]+?)\s+\.->/g,`-.->|$1|`).replace(/--\s+([^|]+?)\s+---/g,`---|$1|`).replace(/==\s+([^|]+?)\s+===/g,`===|$1|`).replace(/-\.\s+([^|]+?)\s+\.-/g,`-.-|$1|`)}function Yn(e){let t=[],n=0,r=``,i=``;for(let a of e)r?(i+=a,a===r&&(r=``)):a===`"`||a===`'`?(r=a,i+=a):a===`[`||a===`(`||a===`{`?(n+=1,i+=a):a===`]`||a===`)`||a===`}`?(n=Math.max(0,n-1),i+=a):a===`&`&&n===0?(t.push(i),i=``):i+=a;return t.push(i),t}function Xn(e,t,n,r){let i=e.trim();if(!i)return null;let a=/^([A-Za-z0-9_-]+)@\{(.+)\}$/.exec(i);if(a){let e=/shape:\s*"?([A-Za-z0-9-]+)"?/.exec(a[2]),i=/label:\s*("([^"]*)"|'([^']*)'|[^,}]+)/.exec(a[2]),o=/icon:\s*"?([^",}]+)"?/.exec(a[2]);if(!e&&!i&&!o)return null;let s=e?Un[e[1].toLowerCase()]??null:null,c=i?q(i[1]):null,l=o?Zn(o[1]):null;return Z(a[1],c,s,r,t,n,l)}i=i.replace(/:::[A-Za-z0-9_-]+\s*$/,``).trim();let o=i,s=null,c=null,l=null;for(let e of Hn){let t=i.indexOf(e.open);if(t>0&&i.endsWith(e.close)){o=i.slice(0,t).trim(),l=i.slice(t+e.open.length,i.length-e.close.length),s=q(l),c=e.shape;break}}if(o=o.replace(/^["']|["']$/g,``).trim(),!o)return null;let u=null,d=l?/\b(fa[bsrld]?|fak):([a-z0-9-]+)/i.exec(l):null;return d&&(u=Zn(`${d[1]}:${d[2]}`),s=s&&s.length>0?s:null),Z(o,s,c,r,t,n,u)}function Z(e,t,n,r,i,a,o=null){let s=i.get(e);return s?(t&&!s.label&&(s.label=t),n&&!s.shape&&(s.shape=n),o&&!s.icon&&(s.icon=o)):(i.set(e,{id:e,label:t,shape:n,group:r,icon:o}),a.push(e)),e}function Zn(e){let t=e.trim().replace(/^["']|["']$/g,``);return(t.includes(`:`)?t.slice(t.lastIndexOf(`:`)+1):t).replace(/^fa-/,``)}function Qn(e,t){let n=/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/i.exec(e);if(!n)return!1;let r=In(n[2]),i=/animation/i.test(n[2]);if(/^default$/i.test(n[1].trim()))return r&&(t.linkDefaultColor=r),i&&(t.linkDefaultAnim=!0),!0;for(let e of n[1].split(`,`).map(e=>Number(e.trim())))Number.isInteger(e)&&(r&&t.linkColor.set(e,r),i&&t.linkAnim.add(e));return!0}function $n(e,t){let n=/^subgraph\s+(.+)$/i.exec(e);if(!n)return!1;let r=/^(\S+)\s*\[(.+)\]$/.exec(n[1].trim()),i=q((r?r[2]:n[1]).trim()),a=t.groupStack[t.groupStack.length-1]??null;return t.groupStack.push(i),t.groups.includes(i)||(t.groups.push(i),t.groupParents.set(i,a)),!0}function er(e,t,n,r){let i=/^click\s+(\S+)\s+(.+)$/i.exec(e);if(!i)return!1;let a=i[2].trim().replace(/^href\s+/i,``),o=/^["']([^"']+)["']/.exec(a);return o?m(o[1])?(n.nodeLink.set(i[1],o[1]),!0):(r.push({line:t,message:`click link "${o[1]}" isn't imported (a node link needs a full URL)`}),!0):(r.push({line:t,message:`click callbacks aren't imported`}),!0)}function tr(e,t,n){let{nodes:r,order:i,edges:a}=t,o=[];for(let n of e.matchAll(/([A-Za-z0-9_-]+)@(?=(?:<|o|x)?[-=.])/g))t.edgeIds.add(n[1]),o.push(n[1]);let s=a.length,c=Jn(e.replace(/\b[A-Za-z0-9_-]+@(?=(?:<|o|x)?[-=.])/g,``));Gn.lastIndex=0;let l=[],u=0,d;for(;d=Gn.exec(c);)l.push({node:c.slice(u,d.index),link:{...qn(d[1]),label:(d[2]??``).trim()}}),u=Gn.lastIndex;l.push({node:c.slice(u)});let f=[];for(let e=0;e<l.length;e+=1){let t=Yn(l[e].node).map(e=>Xn(e,r,i,n)).filter(e=>e!==null);if(f.length>0&&t.length>0&&l[e-1].link){let n=l[e-1].link;for(let e of f)for(let r of t)a.push({src:e,dst:r,dashed:n.dashed,bidir:n.bidir,head:n.head,invisible:n.invisible,label:n.label})}t.length>0&&(f=t)}if(o.length>0&&a.length>s){let e=Array.from({length:a.length-s},(e,t)=>s+t);for(let n of o)t.edgeIndices.set(n,e)}}function nr(e){let{edges:t,nodeClass:n,classColor:r,linkColor:i,linkAnim:a}=e;for(let t of e.nodes.values()){let i=n.get(t.id);t.color=e.styleColor.get(t.id)??(i?r.get(i)??null:null),t.link=e.nodeLink.get(t.id)??null}for(let[i,a]of e.edgeIndices){let o=n.get(i),s=e.edgeAnimIds.has(i)||(o?e.classAnim.has(o):!1),c=o?r.get(o):void 0;for(let e of a)s&&(t[e].flow=!0),c&&(t[e].color=c)}for(let[e,n]of i)t[e]&&(t[e].color=n);for(let e of a)t[e]&&(t[e].flow=!0);let{linkDefaultColor:o,linkDefaultAnim:s}=e;(o||s)&&t.forEach((e,t)=>{o&&!i.has(t)&&(e.color??=o),s&&!a.has(t)&&(e.flow||=!0)})}function rr(e,t,n,r=`flowchart`){let i={nodes:new Map,order:[],edges:[],groups:[],groupStack:[],groupParents:new Map,edgeIds:new Set,classColor:new Map,classAnim:new Set,styleColor:new Map,nodeClass:new Map,edgeAnimIds:new Set,edgeIndices:new Map,linkColor:new Map,linkAnim:new Set,linkDefaultColor:null,linkDefaultAnim:!1,nodeLink:new Map},a=!1;for(let t=0;t<e.length;t+=1){let r=K(e[t]).trim();if(!r)continue;if(a){r.includes(`}`)&&(a=!1);continue}let o=/^acc(?:Title|Descr)\b\s*(\{)?/i.exec(r);if(o){o[1]&&!r.includes(`}`)&&(a=!0);continue}if(r.includes(`:::`))for(let e of r.matchAll(/([A-Za-z0-9_-]+)\s*(?:\[[^\]]*\]|\([^)]*\)|\{[^}]*\})?:::([A-Za-z0-9_-]+)/g))i.nodeClass.set(e[1],e[2]);let s=/^([A-Za-z0-9_-]+)\s*(?:@\{|\{|\[)/.exec(r);if(s&&i.edgeIds.has(s[1])){/animate|animation|\bfast\b|\bslow\b/i.test(r)&&i.edgeAnimIds.add(s[1]);continue}if(Kn(r,i)||Qn(r,i)||$n(r,i))continue;if(/^end$/i.test(r)){i.groupStack.pop();continue}if(/^direction\s+/i.test(r)||er(r,t+1,i,n))continue;let c=i.groupStack[i.groupStack.length-1]??null;if(!Wn.test(r)||/^[A-Za-z0-9_-]+@\{/.test(r)){Xn(r,i.nodes,i.order,c);continue}tr(r,i,c)}nr(i);let{nodes:o,order:s,edges:c,groups:l,groupParents:u}=i;return ar(r,t,o,s,c,l,u)}function ir(e,t,n){return rr(e,t,n,`bpmn`)}function ar(e,t,n,r,i,a,o){let s=[e];t&&t!==`down`&&e===`flowchart`&&s.push(`direction: ${t}`),t&&t!==`right`&&(e===`statemachine`||e===`architecture`)&&s.push(`direction: ${t}`),s.push(``);let c=(e,t)=>{let n=[];e.shape&&n.push(e.shape),e.color&&n.push(e.color),e.icon&&n.push(`icon: ${e.icon}`),e.link&&n.push(`link: ${e.link}`);let r=n.length>0?` [${n.join(`, `)}]`:``;return e.label!==null&&e.label!==e.id&&e.label!==``?`${t}${J(e.id)} = ${Y(e.label)}${r}`:n.length>0?`${t}${J(e.id)}${r}`:null},l=new Set;for(let e of i)l.add(e.src),l.add(e.dst);for(let e of r){let t=n.get(e);if(t.group)continue;let r=c(t,``);r?s.push(r):l.has(e)||s.push(J(t.id))}if(o){let e=new Map;for(let t of a){let n=o.get(t)??null,r=a.includes(n)?n:null,i=e.get(r)??[];i.push(t),e.set(r,i)}let t=(i,a)=>{s.push(`${a}group ${Y(i)} {`);for(let e of r){let t=n.get(e);t.group===i&&s.push(c(t,`${a} `)??`${a} ${J(e)}`)}for(let n of e.get(i)??[])t(n,`${a} `);s.push(`${a}}`)};for(let n of e.get(null)??[])t(n,``)}else for(let e of a){s.push(`group ${Y(e)} {`);for(let t of r){let r=n.get(t);r.group===e&&s.push(c(r,` `)??` ${J(t)}`)}s.push(`}`)}i.length>0&&s.push(``);for(let e of i){let t=e.bidir?e.dashed?`<-->`:`<->`:e.dashed?`-->`:`->`,n=[];e.color&&n.push(e.color),e.flow&&n.push(`flow`),e.invisible&&n.push(`invisible`),e.head&&n.push(`head: ${e.head}`);let r=n.length>0?` [${n.join(`, `)}]`:``,i=e.label?` : ${e.label}`:r?` :`:``;s.push(`${J(e.src)} ${t} ${J(e.dst)}${i}${r}`)}return X(s)}var or={cloud:{shape:`cloud`},database:{shape:`cylinder`},disk:{shape:`cylinder`},internet:{icon:`globe`},server:{icon:`server`}};function sr(e,t){let n=new Map,r=[],i=[],a=new Map,o=[],s=new Map,c=e=>{let t=or[e?.toLowerCase()]??{};return{shape:t.shape??null,iconAttr:t.icon?`[icon: ${t.icon}]`:``}};for(let t of e){let e=K(t).trim();if(!e||/^architecture/i.test(e))continue;let l=/^group\s+(\w+)\s*(?:\(([^)]*)\))?\s*\[([^\]]*)\]/i.exec(e);if(l){let e=l[1];a.set(e,q(l[3])),o.includes(e)||o.push(e);continue}let u=/^(?:service|junction)\s+(\w+)\s*(?:\(([^)]*)\))?\s*(?:\[([^\]]*)\])?\s*(?:in\s+(\w+))?/i.exec(e);if(u){let e=u[1],t=u[2]??``,i=u[3]?q(u[3]):e,a=u[4]??null,{shape:o}=c(t);Z(e,i,o,a,n,r),a&&s.set(e,a);continue}let d=/^(\w+)(?:\{group\})?(?::[LRTB])?\s*(<?-->?|--)\s*(?:[LRTB]:)?(\w+)(?:\{group\})?$/.exec(e);if(d){let e=d[1],t=d[3];Z(e,null,null,null,n,r),Z(t,null,null,null,n,r),i.push({src:e,dst:t,dashed:!1,bidir:d[2].startsWith(`<`),label:``})}}for(let[e,t]of s){let r=n.get(e);r&&(r.group=a.get(t)??t)}return ar(`architecture`,null,n,r,i,o.map(e=>a.get(e)??e))}var cr={person:`actor`,person_ext:`actor`,systemdb:`cylinder`,systemdb_ext:`cylinder`,containerdb:`cylinder`,containerdb_ext:`cylinder`,componentdb:`cylinder`,systemqueue:`queue`,systemqueue_ext:`queue`,containerqueue:`queue`,componentqueue:`queue`};function lr(e){let t=[],n=0,r=``,i=``;for(let a of e)r?(a===r&&(r=``),i+=a):a===`"`||a===`'`?(r=a,i+=a):a===`(`?(n+=1,i+=a):a===`)`?(--n,i+=a):a===`,`&&n===0?(t.push(i.trim()),i=``):i+=a;return i.trim()&&t.push(i.trim()),t}function ur(e,t){let n=new Map,r=[],i=[],a=[],o=[],s=``,c=0;for(let t=0;t<e.length;t+=1){let l=e[t],u=K(l).trim();if(!u||/^C4\w+/i.test(u)||/^Update\w+/i.test(u))continue;if(u===`}`){o.pop();continue}let d=/^title\s+(.+)$/i.exec(u);if(d){s=q(d[1]);continue}let f=/^(\w+)\s*\(([\s\S]*?)\)\s*(\{)?$/.exec(u);if(!f)continue;let p=f[1],m=lr(f[2]),h=p.toLowerCase();if(/boundary/i.test(p)){let e=q(m[1]??m[0]??`Boundary`);o.push(e),a.includes(e)||a.push(e);continue}if(/^(rel|birel)/i.test(p)){let e=q(m[0]),t=q(m[1]),n=q(m[2]??``);i.push({src:e,dst:t,dashed:!1,bidir:/^birel/i.test(p),label:n});continue}let g=q(m[0]),_=q(m[1]??m[0]),v=cr[h]??null;!c&&q(m[2]??``)&&(c=t+1),Z(g,_,v,o[o.length-1]??null,n,r)}return c&&t.push({line:c,message:`C4 descriptions aren't imported — each box keeps its name only`}),zn(ar(`architecture`,null,n,r,i,a),s)}function dr(e,t){let n=e=>/\*|n|\.\.\*|\.\.n|[2-9]/i.test(e),r=n(e),i=n(t);return!e&&!t?null:r&&i?`N:M`:!r&&i?`1:N`:r&&!i?`N:1`:`1:1`}function fr(e){let t=/^[+\-#~]/.exec(e.trim()),n=t?t[0]:``,r=e.trim().slice(n.length).replace(/[*$]\s*$/,``).replace(/~[^~]*~/g,``).trim();if(!r)return null;let i=/^([A-Za-z0-9_]+)\s*\([^)]*\)\s*(.*)$/.exec(r);if(i){let e=i[2].trim(),t=`${n}${i[1]}()`;return e?`${J(t)} ${z(e)}`:J(t)}let a=r.split(/\s+/).filter(Boolean);return a.length===0?null:a.length===1?J(`${n}${a[0]}`):`${J(`${n}${a[a.length-1]}`)} ${z(a.slice(0,-1).join(` `))}`}function pr(e,t,n=`erd`){let r=[n,``],i=[...e],a=[];for(let e of i)e.group&&!a.includes(e.group)&&a.push(e.group);let o=(e,t)=>{let n=e.label?`${J(e.id)} = ${Y(e.label)}`:J(e.id),i=e.methods&&e.methods.length>0?[...e.fields,`---`,...e.methods]:e.fields;if(i.length===0){r.push(`${t}${n} { }`);return}r.push(`${t}${n} {`);for(let e of i)r.push(`${t} ${e}`);r.push(`${t}}`)};for(let e of a){r.push(`group ${Y(e)} {`);for(let t of i)t.group===e&&o(t,` `);r.push(`}`)}for(let e of i)e.group||o(e,``);return t.length>0&&(r.push(``),r.push(...t)),X(r)}function mr(e){let t=/^([|o}{]+)(?:--|\.\.)([|o}{]+)$/.exec(e);if(!t)return{value:null,swap:!1};let n=/[}{]/.test(t[1]),r=/[}{]/.test(t[2]);return n&&r?{value:`N:M`,swap:!1}:!n&&r?{value:`1:N`,swap:!1}:n&&!r?{value:`1:N`,swap:!0}:{value:`1:1`,swap:!1}}function hr(e,t){let n=[],r=new Map,i=[],a=null,o=(e,t)=>{let i=r.get(e);return i?t&&!i.label&&(i.label=t):(i={id:e,label:t??null,fields:[]},n.push(i),r.set(e,i)),i};for(let n=0;n<e.length;n+=1){let r=K(e[n]).trim();if(!r||/^direction\b/i.test(r))continue;let s=/^(style|classDef|class)\b/i.exec(r);if(s){a||t.push({line:n+1,message:`'${s[1]}' is not imported — table colours don't carry over`});continue}if(r===`}`){a=null;continue}if(a){let e=r.replace(/"[^"]*"\s*$/,``).trim().split(/\s+/).filter(Boolean);if(e.length===0)continue;let t=e[0],n=e[1]??t,i=e.slice(2).map(e=>e.toLowerCase()),o=i.includes(`pk`)?` pk`:i.includes(`fk`)?` fk`:``;a.fields.push(`${J(n)} ${t}${o}`);continue}let c=/^([A-Za-z0-9_-]+)(?:\[("?)([^\]]+)\2\])?\s*\{$/.exec(r);if(c){a=o(c[1],c[3]?q(c[3]):null);continue}let l=gr(r);if(l){let e=gt[l.token]?l.token:(()=>{let{value:e,swap:t}=mr(l.token);return t&&([l.from,l.to]=[l.to,l.from]),e??`->`})();o(l.from),o(l.to),i.push(`${J(l.from)} ${e} ${J(l.to)}${l.label?` : ${l.label}`:``}`);continue}if(/^[A-Za-z0-9_-]+$/.test(r)){o(r);continue}t.push({line:n+1,message:`couldn't parse '${r}'`})}return pr(n,i)}function gr(e){let t=/^(\S+)\s+([|o}{]+(?:--|\.\.)[|o}{]+)\s+(\S+)(?:\s*:\s*(.+))?$/.exec(e);return t?{from:t[1],to:t[3],token:t[2],label:t[4]?t[4].trim():``}:null}function _r(e,t){let n=[],r=[],i=null;for(let t of e){let e=K(t).trim();if(!e)continue;if(e===`}`){i&&n.push(i),i=null;continue}let a=/^(\w*requirement|requirement|element|designConstraint)\s+([A-Za-z0-9_]+)\s*\{(.+)\}$/i.exec(e);if(a){let e={id:a[2],kind:/element/i.test(a[1])?`element`:`requirement`,text:``,fields:[]};for(let t of a[3].split(/[;,]/)){let n=/^\s*(\w+)\s*:\s*(.+?)\s*$/.exec(t);if(!n)continue;let r=n[1].toLowerCase(),i=q(n[2].trim());r===`text`||r===`name`?e.text=i:e.fields.push(`${r} ${z(i)}`)}n.push(e);continue}let o=/^(\w*requirement|requirement|element|designConstraint)\s+([A-Za-z0-9_]+)\s*\{$/i.exec(e);if(o){i={id:o[2],kind:/element/i.test(o[1])?`element`:`requirement`,text:``,fields:[]};continue}if(i){let t=/^(\w+)\s*:\s*(.+)$/.exec(e);if(t){let e=t[1].toLowerCase(),n=q(t[2].trim());e===`text`||e===`name`?i.text=n:i.fields.push(`${e} ${z(n)}`)}continue}let s=/^(\S+)\s*-\s*(\w+)\s*->\s*(\S+)$/.exec(e),c=/^(\S+)\s*<-\s*(\w+)\s*-\s*(\S+)$/.exec(e);s?r.push({from:J(s[1]),to:J(s[3]),label:s[2]}):c&&r.push({from:J(c[3]),to:J(c[1]),label:c[2]})}let a=new Set(n.map(e=>J(e.id)));for(let e of r)for(let t of[e.from,e.to])a.has(t)||(a.add(t),n.push({id:t,kind:`requirement`,text:``,fields:[]}));let o=[`erd`,``];for(let e of n){o.push(`${J(e.id)} {`),e.text&&o.push(` text ${z(e.text)}`);for(let t of e.fields)o.push(` ${t}`);o.push(`}`)}return r.length>0&&(o.push(``),o.push(...r.map(e=>`${e.from} -> ${e.to} : ${e.label}`))),X(o)}var vr=[`<|..`,`..|>`,`<|--`,`--|>`,`*--`,`--*`,`o--`,`--o`,`..>`,`<..`,`-->`,`<--`,`..`,`--`];function yr(e,t){let n=new Map,r=[],i=null,a=null,o=(e,t)=>{let r=e.replace(/^["']|["']$/g,``),i=n.get(r);return i?t&&(i.label=t):(i={id:r,label:t??r,fields:[],methods:[],group:a??void 0},n.set(r,i)),i},s=(e,t)=>{(t.includes(`(`)?e.methods:e.fields).push(t)};for(let c=0;c<e.length;c+=1){let l=K(e[c]).trim();if(!l||/^(direction|click|callback|link|note)\b/i.test(l))continue;let u=/^(cssClass|style|classDef)\b/i.exec(l);if(u){i||t.push({line:c+1,message:`'${u[1]}' is not imported — class colours don't carry over`});continue}let d=/^namespace\s+("?)([^"{]+)\1\s*\{?$/i.exec(l);if(d){a=d[2].trim();continue}if(l===`}`){i?i=null:a=null;continue}let f=i?null:/^<<(.+?)>>\s+(\S+)$/.exec(l);if(f){let e=n.get(J(f[2]));e&&e.fields.unshift(J(`«${f[1].trim()}»`));continue}if(i){let e=/^<<(.+)>>$/.exec(l);if(e){i.fields.push(J(`«${e[1].trim()}»`));continue}let t=fr(l);t&&s(i,t);continue}let p=/^class\s+([A-Za-z0-9_~"'.]+)(?:\["([^"]+)"\])?\s*(\{)?$/.exec(l);if(p){let e=o(p[1].replace(/~[^~]*~/g,``),p[2]);p[3]&&(i=e);continue}let m=/^([A-Za-z0-9_~"'.]+)\s*:\s*(.+)$/.exec(l);if(m&&!/[<|*o.>-]{2}/.test(l.split(`:`)[0])){let e=o(m[1].replace(/~[^~]*~/g,``)),t=/^<<(.+)>>$/.exec(m[2].trim());if(t)e.fields.push(J(`«${t[1].trim()}»`));else{let t=fr(m[2]);t&&s(e,t)}continue}let h=br(l);if(h){o(h.from),o(h.to);let e=yt[h.token]?h.token:dr(h.leftCard,h.rightCard)??`->`,t=h.label;r.push(`${J(h.from)} ${e} ${J(h.to)}${t?` : ${t}`:``}`);continue}t.push({line:c+1,message:`couldn't parse '${l}'`})}return pr([...n.values()].map(e=>({id:e.id,label:e.label===e.id?null:e.label,fields:e.fields,methods:e.methods,group:e.group})),r,`class`)}function br(e){let t=e.indexOf(`:`),n=t>=0?e.slice(0,t):e,r=t>=0?e.slice(t+1).trim():``;for(let e of vr){let t=n.indexOf(e);if(t<=0)continue;let i=n.slice(0,t).trim(),a=n.slice(t+e.length).trim(),o=``,s=``,c=/"([^"]*)"\s*$/.exec(i);c&&(o=c[1],i=i.slice(0,c.index).trim());let l=/^"([^"]*)"/.exec(a);l&&(s=l[1],a=a.slice(l[0].length).trim());let u=i.replace(/~[^~]*~/g,``).trim(),d=a.replace(/~[^~]*~/g,``).trim();if(u&&d)return{from:u,to:d,token:e,label:r,leftCard:o,rightCard:s}}return null}var xr=[{token:`<<-->>`,out:`<->`},{token:`<<->>`,out:`<->`},{token:`-->>`,out:`-->`},{token:`--x`,out:`-->`},{token:`--)`,out:`-->`},{token:`->>`,out:`->`},{token:`-->`,out:`-->`},{token:`-x`,out:`->`},{token:`-)`,out:`->`},{token:`->`,out:`->`}];function Sr(e){let t=e.indexOf(`:`),n=t>=0?e.slice(0,t):e,r=t>=0?e.slice(t+1).trim():``;for(let{token:e,out:t}of xr){let i=n.indexOf(e);if(i>0){let a=n.slice(0,i).trim().replace(/[+-]$/,``).trim(),o=n.slice(i+e.length).trim().replace(/^[+-]/,``).trim();if(a&&o)return{src:a,arrow:t,dst:o,text:r}}}return null}function Cr(e,t){let n=new Map;for(let r=0;r<e.length;r+=1){let i=K(e[r]).trim(),a=/^link\s+([^:]+):\s*(?:[^@]*@\s*)?(\S+)\s*$/i.exec(i);if(a){let e=a[1].trim();n.has(e)||n.set(e,a[2].trim());continue}let o=/^links\s+([^:]+):\s*(\{.*\})\s*$/i.exec(i);if(o){let e=o[1].trim(),i=[...o[2].matchAll(/"[^"]*"\s*:\s*"([^"]*)"/g)].map(e=>e[1]);if(i.length===0)continue;n.has(e)||n.set(e,i[0]),i.length>1&&t.push({line:r+1,message:`'${e}' has ${i.length} links; only the first is kept`})}}return n}function wr(e,t){let n=[`sequence`,``],r=Cr(e,t),i=e=>{let t=r.get(e.trim());return t?` [link: ${t}]`:``},a=0,o=[],s=!1,c=0,l=()=>` `.repeat(a);for(let r=0;r<e.length;r+=1){let u=K(e[r]).trim();if(!u)continue;if(/^autonumber\b/i.test(u)){s=!0;continue}if(/^(box|rect)\b/i.test(u)){o.push(`skip`),t.push({line:r+1,message:`'${u.split(/\s+/)[0]}' is not imported — its contents are kept`});continue}if(/^links?\s+[^:]+:/i.test(u))continue;if(/^properties\b/i.test(u)){t.push({line:r+1,message:`'properties' is not imported`});continue}if(/^destroy\s+(?!participant\b|actor\b)\S+/i.test(u)){t.push({line:r+1,message:`'destroy' is not imported — the lifeline runs to the end`});continue}let d=/^(?:create|destroy)\s+(?:participant|actor)\s+(.+)$/i.exec(u)??/^(?:participant|actor)\s+(.+)$/i.exec(u);if(d){let e=/^(.+?)\s+as\s+(.+)$/i.exec(d[1].trim());if(e){let t=e[1].trim(),r=i(t)||i(q(e[2]));n.push(`${l()}${t} = ${q(e[2])}${r}`)}else{let e=q(d[1].trim());n.push(`${l()}${e}${i(e)}`)}continue}let f=/^(loop|alt|opt|par|break|critical)\b\s*(.*)$/i.exec(u);if(f){let e=f[1].toLowerCase()===`critical`?`opt`:f[1].toLowerCase(),t=f[2].trim();n.push(`${l()}${e}${t?` ${t}`:``} {`),o.push(`emit`),a+=1;continue}let p=/^(else|and|option)\b\s*(.*)$/i.exec(u);if(p){a=Math.max(0,a-1);let e=p[1].toLowerCase()===`and`?`and`:`else`,t=p[2].trim();n.push(`${l()}} ${e}${t?` ${t}`:``} {`),a+=1;continue}if(/^end$/i.test(u)){if(o.pop()===`skip`)continue;a=Math.max(0,a-1),n.push(`${l()}}`);continue}let m=/^note\s+(over|left of|right of)\s+([^:]+):\s*(.*)$/i.exec(u);if(m){let e=m[1].toLowerCase(),t=m[2].split(`,`).map(e=>e.trim()).join(`, `);n.push(`${l()}note ${e} ${t} : ${m[3].trim()}`);continue}if(/^(activate|deactivate)\s+\S/i.test(u)){n.push(`${l()}${u}`);continue}let h=Sr(u);if(h){let e=s?`${c+=1}. ${h.text??``}`.trim():h.text,t=e?` : ${e}`:``;n.push(`${l()}${h.src} ${h.arrow} ${h.dst}${t}`);continue}t.push({line:r+1,message:`couldn't parse '${u}'`})}return X(n)}function Tr(e,t){let n=[`sequence`,``];for(let r=0;r<e.length;r+=1){let i=K(e[r]).trim();if(!i||/^zenuml$/i.test(i)||i===`{`||i===`}`)continue;let a=/^(?:@\w+\s+)?(?:participant\s+)?([A-Za-z0-9_]+)(?:\s+as\s+"?([^"]+)"?)?$/i.exec(i),o=/^([A-Za-z0-9_]+)\s*(->|=>|-->)\s*([A-Za-z0-9_]+)\s*:\s*(.+)$/.exec(i);if(o){let e=o[2]===`-->`?`-->`:`->`;n.push(`${o[1]} ${e} ${o[3]} : ${o[4].trim()}`);continue}if(/\b(if|else|while|for|forEach|opt|loop|par|try|catch|finally|return|new)\b/.test(i)){t.push({line:r+1,message:`ZenUML control '${i}' is simplified on import`});continue}a&&/^(participant|@)/i.test(i)&&n.push(a[2]?`${a[1]} = ${q(a[2])}`:a[1])}return X(n)}function Er(e,t){return e===null?t:`${N(e)}-${t}`}function Dr(e,t,n){let r=new Map,i=[],a=[],o=[],s=new Map,c=0,l=[],u=new Map,d=new Map,f=new Map,p=new Map,m=new Map,h=()=>l[l.length-1]?.title??null,g=e=>{let t=r.get(e);if(t)return t;let n={id:e,label:null,shape:null,group:h()};return r.set(e,n),i.push(e),n},_=(e,t,n)=>{o.includes(e)||(o.push(e),s.set(e,t)),l.push({title:e,parent:t,region:n})};for(let t=0;t<e.length;t+=1){let i=K(e[t]).trim();if(!i||/^direction\b/i.test(i)||(i.includes(`:::`)&&(i=i.replace(/([A-Za-z0-9_.-]+):::([A-Za-z0-9_-]+)/g,(e,t,n)=>(m.set(J(t),n),t))),Kn(i,{classColor:f,styleColor:p,nodeClass:m,keyOf:J})))continue;if(/^(note)\b/i.test(i)){let r=/^note\s+(?:(left|right)\s+of\s+)?([^:]+):\s*(.*)$/i.exec(i),o=r?J(r[2].trim()):null,s=r?r[3].trim():``;if(!r){let n=/^note\s+(?:(left|right)\s+of\s+)?(\S+)\s*$/i.exec(i);o=n?J(n[2].trim()):null;let r=[];for(;t+1<e.length&&!/^end note$/i.test(K(e[t+1]).trim());)t+=1,r.push(K(e[t]).trim());t+=1,s=r.filter(Boolean).join(` `)}if(o&&s){let e=J(`note-${o}-${c+=1}`);g(o);let t=g(e);t.label=s,t.shape=`note`,a.push({src:o,dst:e,dashed:!0,bidir:!1,label:``})}else n.push({line:t+1,message:`a state note with no text is dropped`});continue}if(/^end note$/i.test(i))continue;if(i===`--`){let e=l[l.length-1];if(!e)continue;let t;if(e.region)l.pop(),t=e.parent;else{t=e.title;let n=kr(t,1);o.push(n),s.set(n,t);for(let e of r.values())e.group===t&&(e.group=n);u.set(t,1)}let n=(u.get(t)??1)+1;u.set(t,n),_(kr(t,n),t,!0);continue}if(i===`}`){l.pop()?.region&&l.pop();continue}let v=/^state\s+(?:"([^"]+)"\s+as\s+)?([A-Za-z0-9_.-]+)\s*\{$/i.exec(i);if(v){let e=v[1]??v[2];d.set(J(v[2]),e),_(e,h(),!1);continue}let y=/^state\s+(.+)$/i.exec(i);if(y&&!i.includes(`-->`)){let e=y[1].trim(),t=/^"([^"]+)"\s+as\s+([A-Za-z0-9_.-]+)$/.exec(e);if(t){g(J(t[2])).label=t[1];continue}let n=/^([A-Za-z0-9_.-]+)\s+<<(choice|fork|join)>>$/.exec(e);if(n){g(J(n[1])).shape=n[2]===`choice`?`diamond`:`fork-join`;continue}g(J(e));continue}let b=/^([A-Za-z0-9_.-]+)\s*:\s*(.+)$/.exec(i);if(b&&!i.includes(`-->`)){g(J(b[1])).label=q(b[2]);continue}if(i.includes(`-->`)){let e=i.indexOf(`:`),t=e>=0?i.slice(0,e):i,n=e>=0?i.slice(e+1).trim():``,r=t.indexOf(`-->`),o=Or(t.slice(0,r).trim(),`src`,h(),g),s=Or(t.slice(r+3).trim(),`dst`,h(),g);o&&s&&a.push({src:o,dst:s,dashed:!1,bidir:!1,label:n});continue}n.push({line:t+1,message:`couldn't parse '${i}'`})}for(let[e,t]of d){let n=r.get(e);if(!(!n||n.label!==null||n.shape!==null)){r.delete(e),i.splice(i.indexOf(e),1);for(let n of a)n.src===e&&(n.src=J(t)),n.dst===e&&(n.dst=J(t))}}for(let e of r.values()){let t=m.get(e.id);e.color=p.get(e.id)??(t?f.get(t)??null:null)}return ar(`statemachine`,t,r,i,a,o,s)}function Or(e,t,n,r){if(e===`[*]`){let e=t===`src`?`start`:`end`,i=J(Er(n,e)),a=r(i);return a.label=e,a.shape=e===`start`?`circle`:`double-circle`,i}let i=J(e.replace(/^["']|["']$/g,``).trim());return i&&r(i),i}function kr(e,t){return`${e} ${t}`}function Ar(e,t,n){let r=``,i=[],a=null;for(let o of e){let e=K(o).trim();if(!e)continue;let s=/^title\s+(.+)$/i.exec(e);if(s){r=q(s[1]);continue}let c=/^section\s+(.+)$/i.exec(e);if(c){a={name:q(c[1]),tasks:[]},i.push(a);continue}n(e,e=>{a||(a={name:t,tasks:[]},i.push(a)),a.tasks.push(e)})}return{title:r,sections:i}}function jr(e,t){let{title:n,sections:r}=Ar(e,``,(e,t)=>{let n=/^(.+?)\s*:\s*(\d+(?:\.\d+)?)\s*(?::\s*(.*))?$/.exec(e);n&&t({label:q(n[1]),score:Number(n[2]),actors:n[3]?.trim()||void 0})}),i=[`journey`];n&&i.push(`title: ${n}`),i.push(``);for(let e of r){e.name&&i.push(`section ${e.name}`);for(let t of e.tasks){let e=t.label.replace(/:/g,` `).replace(/\s+/g,` `).trim(),n=t.actors?.replace(/:/g,` `).replace(/\s+/g,` `).trim();i.push(`- ${e}${n?`: ${n}`:``} [score: ${t.score}]`)}i.push(``)}return X(i)}function Mr(e,t){let n=e=>{let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);return t?Date.UTC(Number(t[1]),Number(t[2])-1,Number(t[3]))/864e5:void 0},r=n(e),i=n(t);return r===void 0||i===void 0?void 0:Math.round(i-r)}function Nr(e,t){let n=0,r=!1,{title:i,sections:a}=Ar(e,``,(e,i)=>{let a=/^(dateFormat|axisFormat|excludes|includes|todayMarker|tickInterval|weekday|weekend)\b/i.exec(e);if(a){let n=a[1].toLowerCase();if(n===`excludes`||n===`weekend`||n===`weekday`){/weekends?/i.test(e)?r=!0:t.push({line:1,message:`gantt "${e.trim()}" isn't supported — only weekends can be excluded, so those days still count`});return}n!==`dateformat`&&n!==`axisformat`&&n!==`tickinterval`&&t.push({line:1,message:`gantt "${a[1]}" isn't supported`});return}let o=e.indexOf(`:`);if(o===-1)return;let s={label:e.slice(0,o).trim(),after:[]};n+=1;for(let t of e.slice(o+1).split(`,`).map(e=>e.trim())){let e=t.toLowerCase();e===`done`||e===`active`||e===`milestone`?s.status=e:e===`crit`?s.status=`critical`:e.startsWith(`after `)?s.after.push(...t.slice(6).trim().split(/\s+/).map(N)):/^\d{4}-\d{2}-\d{2}$/.test(t)?s.start?s.end=t:s.start=t:/^\d+(\.\d+)?\s*(d|w|h|m|s|day|days|week|weeks|hour|hours|min|mins|minute|minutes|sec|secs|second|seconds)$/i.test(t)?s.length=t.replace(/\s+/g,``):/^until\s+/i.test(t)?s.until=t.slice(5).trim():/^[A-Za-z][\w-]*$/.test(t)&&(s.mermaidId=t)}i(s)}),o=new Map,s=new Set;for(let e of a)for(let t of e.tasks){let e=P(N(t.label),s);t.mermaidId&&o.set(t.mermaidId,e)}let c=[`gantt`];i&&c.push(`title: ${i}`),r&&c.push(`excludes: weekends`);for(let e of a){c.push(``),e.name&&c.push(`section ${e.name}`);for(let t of e.tasks){let e=[];if(t.after.length>0?e.push(`after ${t.after.map(e=>o.get(e)??e).join(` `)}`):t.start&&e.push(t.start),t.until)e.push(`until ${o.get(t.until)??N(t.until)}`);else if(t.length)e.push(t.length);else if(t.start&&t.end){let n=Mr(t.start,t.end);n!==void 0&&n>0&&e.push(`${n}d`)}let n=t.label.replace(/[[\]]/g,``).replace(/:/g,` `).replace(/\s+/g,` `).trim(),r=t.status?` [${t.status}]`:``;c.push(`- ${n}${e.length>0?`: ${e.join(`, `)}`:``}${r}`)}}return X(c)}function Pr(e,t){let n=[`chart pie`],r=[];for(let t of e){let e=K(t).trim();if(!e||/^showdata$/i.test(e))continue;let i=/^title\s+(.+)$/i.exec(e);if(i){n.push(`title: ${q(i[1])}`);continue}let a=/^("([^"]*)"|'([^']*)'|[^:]+)\s*:\s*([\d.]+)$/.exec(e);a&&r.push(`${q(a[1])} : ${a[4]}`)}return n.push(``,...r),X(n)}function Fr(e,t){let n=``,r=``,i=``,a={},o=[];for(let t of e){let e=K(t).trim();if(!e)continue;let s=/^title\s+(.+)$/i.exec(e);if(s){n=q(s[1]);continue}let c=/^x-axis\s+(.+)$/i.exec(e);if(c){r=q(c[1].trim());continue}let l=/^y-axis\s+(.+)$/i.exec(e);if(l){i=q(l[1].trim());continue}let u=/^quadrant-([1-4])\s+(.+)$/i.exec(e);if(u){a[Number(u[1])]=q(u[2]);continue}let d=/^(.+?):::?[A-Za-z0-9_-]*\s*:?\s*\[\s*([\d.]+)\s*,\s*([\d.]+)\s*\]/.exec(e)??/^(.+?)\s*:\s*\[\s*([\d.]+)\s*,\s*([\d.]+)\s*\]/.exec(e);d&&o.push({label:q(d[1].replace(/:::.*$/,``).trim()),x:d[2],y:d[3]})}let s=[`quadrant`];n&&s.push(`title: ${n}`),r&&s.push(`x-axis: ${r}`),i&&s.push(`y-axis: ${i}`);for(let e=1;e<=4;e+=1)a[e]&&s.push(`quadrant-${e}: ${a[e]}`);s.push(``);for(let e of o)s.push(`${e.label}: [${e.x}, ${e.y}]`);return X(s)}function Ir(e,t){let n=`Timeline`,r=[],i=null,a=null;for(let t of e){let e=K(t).trim();if(!e||/^timeline\b/i.test(e))continue;let o=/^title\s+(.+)$/i.exec(e);if(o){n=q(o[1]);continue}let s=/^section\s+(.+)$/i.exec(e);if(s){i={name:q(s[1]),periods:[]},r.push(i),a=null;continue}if(e.startsWith(`:`)&&a){a.events.push(...L(e,`:`).map(e=>q(e.trim())).filter(Boolean));continue}let c=L(e,`:`).map(e=>q(e.trim())).filter(Boolean);c.length!==0&&(i||(i={name:null,periods:[]},r.push(i)),a={period:c[0],events:c.slice(1)},i.periods.push(a))}let o=e=>e.includes(`:`)?`"${e}"`:e,s=[`timeline`,`title: ${n}`,``],c=r.some(e=>e.name!==null);for(let e of r){c&&s.push(`section ${e.name??`Events`}`);for(let t of e.periods){let e=o(t.period);if(t.events.length>1){s.push(`- ${e}`);for(let e of t.events)s.push(` - ${e}`)}else s.push(`- ${e}${t.events[0]?`: ${t.events[0]}`:``}`)}}return X(s)}function Lr(e){let t=[],n=``,r=!1;for(let i=0;i<e.length;i+=1){let a=e[i];r?a===`"`&&e[i+1]===`"`?(n+=`"`,i+=1):a===`"`?r=!1:n+=a:a===`"`?r=!0:a===`,`?(t.push(n.trim()),n=``):n+=a}return t.push(n.trim()),t}function Rr(e,t){let n=[`venn`],r=[],i=[],a=``,o=e=>{let t=/\[\s*"?([^"\]]*)"?\s*\]/.exec(e);return t?t[1].trim():null},s=e=>e.split(`,`).map(e=>N(q(e.trim().replace(/:\d+$/,``)))).filter(Boolean);for(let t of e){let e=K(t).trim();if(!e||/^venn(-beta)?$/i.test(e))continue;let n=/^title\s+(.+)$/i.exec(e);if(n){a=q(n[1].trim());continue}let c=/^set\s+([^[]+)(.*)$/i.exec(e);if(c){let e=N(q(c[1].trim().replace(/:\d+$/,``)));e&&r.push({id:e,label:o(c[2])??q(c[1].trim())});continue}let l=/^union\s+([^[]+)(.*)$/i.exec(e);if(l){let e=s(l[1]),t=o(l[2]);e.length>=2&&t&&i.push({ids:e,label:t});continue}let u=/^text\s+([^[]+)(.*)$/i.exec(e);if(u){let e=s(u[1]),t=o(u[2]);if(!t)continue;if(e.length===1){let n=r.find(t=>t.id===e[0]);n&&!n.detail&&(n.detail=t)}else e.length>=2&&!i.some(t=>t.ids.join()===e.join())&&i.push({ids:e,label:t});continue}}a&&n.push(`title: ${a}`),n.push(``);let c=e=>e.replace(/[:+&,]/g,` `).replace(/\s+/g,` `).trim(),l=new Map(r.map(e=>[e.id,c(e.label)]));for(let e of r){let t=l.get(e.id)??e.id;n.push(`- ${t}${e.detail?`: ${c(e.detail)}`:``}`)}for(let e of i){let t=e.ids.map(e=>l.get(e)).filter(e=>!!e);t.length<2||n.push(`overlap ${t.join(` + `)}: ${c(e.label)}`)}return X(n)}function zr(e,t){let n=[`sankey`],r=[],i=!0;for(let t of e){let e=t.trim();if(!e)continue;if(i&&/^sankey/i.test(e)){i=!1;continue}i=!1;let n=Lr(e);if(n.length<3||!n[0]||!n[1])continue;let a=Number(n[2]);if(!Number.isFinite(a)||a<=0)continue;let o=e=>e.replace(/->|=>/g,`-`).replace(/[:,]/g,` `).trim();r.push(`${o(n[0])} -> ${o(n[1])} : ${a}`)}return n.push(``,...r),X(n)}function Br(e){let t=/\[(.*)\]/.exec(e);return(t?t[1]:e).split(`,`).map(e=>q(e.trim())).filter(Boolean)}function Vr(e,t){let n=``,r=``,i=``,a=[],o=null,s=!1,c=[],l=!1,u=!1,d=/(-?\d+(?:\.\d+)?)\s*-->\s*(-?\d+(?:\.\d+)?)/;for(let t of e){let e=K(t).trim();if(!e||/^xychart/i.test(e))continue;if(/^horizontal$/i.test(e)){s=!0;continue}if(/^vertical$/i.test(e)){s=!1;continue}let f=/^title\s+(.+)$/i.exec(e);if(f){n=q(f[1]);continue}let p=/^x-axis\s+(.+)$/i.exec(e);if(p){if(p[1].includes(`[`))a=Br(p[1]);else{let e=d.exec(p[1]);e&&(o={min:Number(e[1]),max:Number(e[2])}),r=q(p[1].replace(d,``).trim())}continue}let m=/^y-axis\s+(.+)$/i.exec(e);if(m){i=q(m[1].replace(d,``).trim());continue}let h=/^bar\s+(.+)$/i.exec(e),g=/^line\s+(.+)$/i.exec(e);(h||g)&&(h?l=!0:u=!0,c.push({name:h?`Bar`:`Line`,values:Br((h??g)[1])}))}let f=l?`bar`:u?`line`:`bar`,p=[];for(let e of c)p.some(t=>t.values.join(`\0`)===e.values.join(`\0`))||p.push(e);if(c.length=0,c.push(...p),a.length===0&&c.length>0){let e=Math.max(...c.map(e=>e.values.length));if(o&&e>1){let{min:t,max:n}=o;a=Array.from({length:e},(r,i)=>{let a=t+(n-t)*i/(e-1);return String(Math.round(a*1e3)/1e3)})}else a=Array.from({length:e},(e,t)=>String(t+1))}let m=[`chart ${f}`];n&&m.push(`title: ${n}`),s&&m.push(`horizontal`),r&&m.push(`x-axis: ${r}`),i&&m.push(`y-axis: ${i}`),a.length>0&&m.push(`categories: ${a.join(`, `)}`),m.push(``);for(let e of c)m.push(`${e.name} : ${e.values.join(`, `)}`);return X(m)}function Hr(e,t){let n=``,r=[],i=[];for(let t of e){let e=K(t).trim();if(!e||/^radar/i.test(e))continue;let a=/^title\s+(.+)$/i.exec(e);if(a){n=q(a[1]);continue}let o=/^axis\s+(.+)$/i.exec(e);if(o){for(let e of o[1].split(`,`)){let t=/\["?([^"\]]+)"?\]/.exec(e);r.push(q(t?t[1]:e.trim()))}continue}let s=/^curve\s+([A-Za-z0-9_]+)\s*(?:\["?([^"\]]*)"?\])?\s*\{([^}]*)\}/i.exec(e);if(s){let e=q(s[2]||s[1]),t=s[3],n=t.includes(`:`)?t.split(`,`).map(e=>e.split(`:`)[1]?.trim()??``).filter(Boolean):t.split(`,`).map(e=>e.trim()).filter(Boolean);i.push({name:e,values:n})}}let a=[`chart radar`];n&&a.push(`title: ${n}`),r.length>0&&a.push(`categories: ${r.join(`, `)}`),a.push(``);for(let e of i)a.push(`${e.name} : ${e.values.join(`, `)}`);return X(a)}function Ur(e,t){let n=[`gitgraph`],r=[],i=0,a=e=>e.replace(/[[\]]/g,``).replace(/\s+/g,` `).trim(),o=e=>{let t=/tag:\s*"([^"]*)"/.exec(e),n=/type:\s*(\w+)/.exec(e),r=[];return t&&r.push(`tag: ${a(t[1])}`),n&&/highlight/i.test(n[1])?r.push(`highlight`):n&&/reverse/i.test(n[1])&&r.push(`reverse`),r.length>0?` [${r.join(`, `)}]`:``};for(let t of e){let e=K(t).trim();if(!e||/^gitGraph/i.test(e))continue;let n=/^commit\b(.*)$/i.exec(e);if(n){let e=/id:\s*"([^"]*)"/.exec(n[1]),t=e?a(e[1]):`commit ${i+=1}`;r.push(`commit ${t}${o(n[1])}`);continue}let s=/^branch\s+(\S+)/i.exec(e);if(s){r.push(`branch ${a(s[1])}`);continue}let c=/^(?:checkout|switch)\s+(\S+)/i.exec(e);if(c){r.push(`checkout ${a(c[1])}`);continue}let l=/^merge\s+(\S+)(.*)$/i.exec(e);if(l){r.push(`merge ${a(l[1])}${o(l[2])}`);continue}let u=/^cherry-pick\b(.*)$/i.exec(e);if(u){let e=/id:\s*"([^"]*)"/.exec(u[1]);e&&r.push(`cherry-pick ${N(a(e[1]))}${o(u[1])}`);continue}}return n.push(``,...r),X(n)}function Wr(e){let t=e.trim().replace(/:::[A-Za-z0-9_ -]+$/,``).trim(),n=[[`((`,`))`],[`))`,`((`],[`)`,`(`],[`[`,`]`],[`(`,`)`],[`{{`,`}}`]];if(/^[A-Za-z0-9_]*\s*([(){}[\]])/.exec(t))for(let[e,r]of n){let n=t.indexOf(e);if(n>=0&&t.endsWith(r))return q(t.slice(n+e.length,t.length-r.length))}return q(t)}function Gr(e,t){let n=[],r=``;for(let t of e){let e=K(t.replace(/\t/g,` `)),i=e.trim();if(!i||/^mindmap$/i.test(i)||/^::icon\(/i.test(i)||/^:::/.test(i))continue;let a=/^title\s+(.+)$/i.exec(i);if(a){r=q(a[1]);continue}let o=e.length-e.trimStart().length;n.push({indent:o,label:Wr(i)})}if(n.length===0)return X([`mindmap`,r?`central: ${r}`:``]);let i=n[0],a=n.slice(1),o=a.length>0?Math.min(...a.map(e=>e.indent)):i.indent+2,s=[`mindmap`,`central: ${i.label}`];r&&s.push(`title: ${r}`),s.push(``);let c=[];for(let e of a){for(;c.length>0&&e.indent<=c[c.length-1];)c.pop();let t=e.indent<=o?0:c.length;t===0&&(c.length=0),c.push(e.indent),s.push(`${` `.repeat(t)}- ${e.label}`)}return X(s)}function Kr(e,t){let n=[],r=``,i=/^([\s│┃|]*)[├└┣┗][─━-]+\s*(.*)$/;for(let t of e){let e=K(t.replace(/\t/g,` `)),a=e.trim();if(!a||/^tree(view)?(-beta)?$/i.test(a))continue;let o=/^title\s+(.+)$/i.exec(a);if(o){r=q(o[1]);continue}let s=i.exec(e),c=s?Math.round(s[1].replace(/[│┃|]/g,` `).length/4)*4+4:e.length-e.trimStart().length,l=(s?s[2]:a).trim();if(!l)continue;l=l.replace(/:::\S+/g,``).trim();let u=null,d=/^(.*?)\s*##\s*(.+)$/.exec(l);d&&(l=d[1].trim(),u=d[2].trim());let f=null,p=/icon\(\s*([^)]*)\s*\)/i.exec(l);if(p){l=l.replace(p[0],``).trim();let e=p[1].trim().toLowerCase();f=e&&e!==`none`?Zn(e):null}let m=q(l).trim();m&&n.push({indent:c,label:m,icon:f,detail:u})}if(n.length===0)return X([`flowchart`,r?`title: ${r}`:``]);let a=new Map,o=[],s=[],c=[];for(let e of n){for(;c.length>0&&e.indent<=c[c.length-1].indent;)c.pop();let t=c.length>0?c[c.length-1]:null,n=N(e.label.replace(/\/+$/,``)),r=t?`${t.id}-${n}`:n;for(;a.has(r);)r=`${r}-${o.length}`;let i=e.detail?`${e.label} (${e.detail})`:e.label;a.set(r,{id:r,label:i,shape:e.label.endsWith(`/`)?null:`document`,group:null,icon:e.icon}),o.push(r),t&&s.push({src:t.id,dst:r,dashed:!1,bidir:!1,label:``}),c.push({indent:e.indent,id:r})}let l=ar(`flowchart`,`right`,a,o,s,[]);if(!r)return l;let u=l.split(`
|
|
22
|
-
`),d=u.findIndex(e=>e.startsWith(`direction:`));return u.splice(d>=0?d+1:1,0,`title: ${r}`),X(u)}function qr(e,t){let n=`Packet`,r=[],i=0;for(let t of e){let e=K(t).trim();if(!e||/^packet/i.test(e))continue;let a=/^title\s+(.+)$/i.exec(e);if(a){n=q(a[1]);continue}let o=/^\+(\d+)\s*:\s*"?([^"]*)"?$/.exec(e);if(o){let e=Number(o[1]);r.push({range:`${i}-${i+e-1}`,label:q(o[2])}),i+=e;continue}let s=/^(\d+)(?:-(\d+))?\s*:\s*"?([^"]*)"?$/.exec(e);if(s){let e=Number(s[1]),t=s[2]?Number(s[2]):e;r.push({range:s[2]?`${e}-${t}`:`${e}`,label:q(s[3])}),i=t+1}}let a=[`flowchart`,`title: ${n}`,``];a.push(`group ${Y(n)} {`);let o=0;for(let e of r)a.push(` f${o+=1} = ${Y(`${e.range}: ${e.label}`)}`);return a.push(`}`),X(a)}function Jr(e,t){let n=[],r=null,i=null;for(let t of e){let e=K(t.replace(/\t/g,` `)),a=e.trim();if(!a||/^kanban$/i.test(a))continue;let o=e.length-e.trimStart().length;i===null&&(i=o);let s=a.replace(/@\{[^}]*\}\s*$/,``).trim(),c=/^[A-Za-z0-9_]*\["?([^"\]]+)"?\]$/.exec(s)??/^[A-Za-z0-9_]*\[([^\]]+)\]$/.exec(s),l=q(c?c[1]:s);o<=i?(r={title:l,items:[]},n.push(r)):r&&r.items.push(l)}let a=[`flowchart`,`kanban`,``],o=0;for(let e of n){a.push(`group ${Y(e.title)} {`);for(let t of e.items)a.push(` k${o+=1} = ${Y(t)}`);a.push(`}`)}return X(a)}function Yr(e){let t=e.trim().split(/\s+/)[0]??``,n=t.toLowerCase();if(/^c4(context|container|component|dynamic|deployment)$/i.test(t))return`c4`;switch(n){case`flowchart`:case`graph`:return`flowchart`;case`swimlane`:case`swimlane-beta`:return`swimlane`;case`sequencediagram`:return`sequence`;case`classdiagram`:case`classdiagram-v2`:return`class`;case`statediagram`:case`statediagram-v2`:return`state`;case`erdiagram`:return`er`;case`journey`:return`journey`;case`gantt`:return`gantt`;case`pie`:return`pie`;case`quadrantchart`:return`quadrant`;case`requirementdiagram`:return`requirement`;case`gitgraph`:return`git`;case`mindmap`:return`mindmap`;case`timeline`:return`timeline`;case`sankey`:case`sankey-beta`:return`sankey`;case`xychart`:case`xychart-beta`:return`xychart`;case`packet`:case`packet-beta`:return`packet`;case`kanban`:return`kanban`;case`architecture`:case`architecture-beta`:return`architecture`;case`radar`:case`radar-beta`:return`radar`;case`treeview`:case`treeview-beta`:return`treeview`;case`venn`:case`venn-beta`:return`venn`;case`zenuml`:return`zenuml`;default:return null}}function Xr(e){let{lines:t,title:n,dropped:r}=Bn(e),i=t.map(e=>K(e).trim()).find(Boolean)??``,a=t.findIndex(e=>K(e).trim()===i),o=Yr(i),s=[];if(!o){let t=i.split(/\s+/)[0]||`diagram`;return{code:e,family:null,diagnostics:[{line:r+a+1,message:`Mermaid ${t} diagrams aren't supported yet`}]}}let c=null;if(o===`flowchart`||o===`swimlane`){let e=/^(?:flowchart|graph|swimlane(?:-beta)?)\b\s*([A-Za-z]{2})?/i.exec(i);c=e&&e[1]?Vn[e[1].toUpperCase()]??null:null}if(o===`state`){let e=/\bdirection\s+([A-Za-z]{2})\b/i.exec(t.slice(a).join(`
|
|
23
|
-
`));c=e?Vn[e[1].toUpperCase()]??null:null}let l=Rn(t.slice(a+1)),u=!1;if(o===`flowchart`||o===`swimlane`){let e=i.replace(/^(?:flowchart|graph|swimlane(?:-beta)?)\b\s*([A-Za-z]{2})?/i,``).trim();e&&(l.unshift(e),u=!0)}o===`xychart`&&/\bhorizontal\b/i.test(i)&&(l.unshift(`horizontal`),u=!0);let d;switch(o){case`flowchart`:d=rr(l,c,s);break;case`swimlane`:d=ir(l,c,s);break;case`sequence`:d=wr(l,s);break;case`class`:d=yr(l,s);break;case`state`:d=Dr(l,c,s);break;case`er`:d=hr(l,s);break;case`journey`:d=jr(l,s);break;case`gantt`:d=Nr(l,s);break;case`pie`:d=Pr(l,s);break;case`quadrant`:d=Fr(l,s);break;case`requirement`:d=_r(l,s);break;case`git`:d=Ur(l,s);break;case`c4`:d=ur(l,s);break;case`mindmap`:d=Gr(l,s);break;case`timeline`:d=Ir(l,s);break;case`sankey`:d=zr(l,s);break;case`xychart`:d=Vr(l,s);break;case`packet`:d=qr(l,s);break;case`kanban`:d=Jr(l,s);break;case`architecture`:d=sr(l,s);break;case`radar`:d=Hr(l,s);break;case`treeview`:d=Kr(l,s);break;case`venn`:d=Rr(l,s);break;case`zenuml`:d=Tr(l,s);break;default:d=e}let f=r+a+ +!u;for(let e of s)e.line+=f;return{code:zn(d,n),family:o,diagnostics:s}}var Zr=/^(sequenceDiagram|classDiagram|stateDiagram(-v2)?|erDiagram|gantt|journey|gitGraph|quadrantChart|requirementDiagram|C4(Context|Container|Component|Dynamic|Deployment)|timeline|sankey(-beta)?|xychart(-beta)?|packet(-beta)?|kanban|architecture-beta|radar(-beta)?|treeview(-beta)?|venn(-beta)?|swimlane(-beta)?|zenuml|mindmap|pie)\b/;function Qr(e){return un.has(e)&&Zr.test(e)}function $r(e){return e.slice(1).map(e=>K(e).trim()).some(e=>/^[-*]\s+\S/.test(e)||/^(title|central)\s*:/i.test(e)||/\S\s*->\s*\S/.test(e))}function ei(e){let t=e.split(`
|
|
24
|
-
`).map(e=>K(e).trim()).filter(Boolean);if(t[0]===`---`){let e=t.indexOf(`---`,1);e!==-1&&(t=t.slice(e+1))}let n=t[0];if(!n)return!1;if(/^(flowchart|graph)\s+(TD|TB|BT|LR|RL)\b/i.test(n))return!0;let r=n.split(/\s+/)[0].toLowerCase();return un.has(r)?Zr.test(n)&&!Zr.test(r)?!0:Qr(r)?!$r(t):!1:Zr.test(n)?!0:/-->\||->>|-->>|-\.->|==>|\|\|--|o\{|\{\{|<\|--/.test(e)}var ti={eraser:`eraser.io`,mermaid:`Mermaid`};function ni(e){return ei(e)?`mermaid`:Pn(e)?`eraser`:null}function ri(e,t){return{language:t,...t===`mermaid`?Xr(e):Nn(e)}}function ii(e){let t=ni(e);if(!t)return{source:e,converted:null};let n=ri(e,t);return{source:n.code,converted:n}}function ai(e){let t=f(e);return t?{x:t.x+t.width+160,y:t.y}:null}function oi(e){return{async resolve(t){let n=await e.resolveIcon(t).catch(()=>null);return n?n.source===`lucide`?n.name:`${n.source}/${n.name}`:null},async names(){let t=await Promise.all(ie.filter(e=>!re(e)).map(async t=>(await e.loadAssetIndex(t).catch(()=>[])).map(e=>`${t}/${e[1]}`)));return[...j,...t.flat()]}}}var si=e(r(),1),ci=[...pt,...vt],li=new Set(Object.keys(w).filter(e=>!D.includes(e))),ui=[...dt.filter(e=>!li.has(e)),`chart`],di=[`title`,`direction`,`icons`],fi=[`right`,`down`,`left`,`up`],pi=[`badge`,`inside`],mi=[`group`,`screen`,`note`,`legend`,`loop`,`alt`,`else`,`opt`,`par`,`and`,`break`,`activate`,`deactivate`,`central`],hi=[`icon`,`color`,`shape`,`fill`,`colorMode`,`corner`,`frame`,`label`,`labelColor`,`group`,`link`,`head`,`width`,`value`,`score`],gi=[`full`,`half`,`third`,`two-thirds`],_i=new Set([...Object.keys(w),`mindmap`,...y,`chart`,...di,...mi,...en]),vi=[`drawnicons`,`aws`,`gcp`,`azure`,`tech`,`mood`,`emoji`],yi={drawnicons:`Library`,aws:`AWS`,gcp:`GCP`,azure:`Azure`,tech:`Tech`,mood:`Mood`,emoji:`Emoji`},bi=[`server`,`database`,`user`,`cloud`,`queue`,`globe`,`lock`,`mail`];function Q(e,t,n){return e.map(e=>({label:e,detail:t,insert:n?n(e):void 0}))}var xi=vi.map(e=>({label:`${e}/`,detail:`${yi[e]} icons`,insert:`${e}/`}));function Si(e){let t=Q(e?j:bi,`icon`);return[...xi,...t]}function Ci(e,t,n,r,i,a){let o=a?.entries(e);if(!o)return{from:n,to:r,query:i,options:[]};let s=t.toLowerCase(),c=[],l=[];for(let t of o){let n={label:`${e}/${t.slug}`,detail:t.name,iconUrl:a?.iconUrl(e,t.slug)},r=t.slug.toLowerCase(),i=t.name.toLowerCase();!s||r.startsWith(s)||i.startsWith(s)?c.push(n):(r.includes(s)||i.includes(s))&&l.push(n)}return{from:n,to:r,query:i,options:[...c,...l].slice(0,80)}}var wi={color:Q(S,`colour`),labelcolor:Q(S,`colour`),textcolor:Q(S,`colour`),shape:Q(b,`shape`),fill:Q(ee,`fill`),colormode:Q(ee,`fill`),corner:Q(_,`corner`),corners:Q(_,`corner`),frame:Q(T,`frame`),head:Q(E,`head`),width:Q(gi,`width`)};function Ti(e,t){return e===`icon`?Si(t):wi[e]??null}function Ei(e){return[...Q(hi,`key`,e=>`${e}: `),...Q(S,`colour`),...Q(b,`shape`),...Q(ee,`fill`),...Q(_,`corner`),...Q([`shadow`,`flow`,`invisible`],`flag`),...Q(T,`frame`),...xi,...Q(e?j:bi,`icon`)]}function Di(e){for(let t of e.split(`
|
|
25
|
-
`)){let e=t.trim();if(!e||e.startsWith(`//`))continue;let n=e.toLowerCase().split(/\s+/)[0];return w[n]||(n===`chart`||dt.includes(n)?n:`architecture`)}return`architecture`}var Oi=new RegExp(W.map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).concat(`,`,`=`).join(`|`));function ki(e){let t=new Set;for(let n of e.split(`
|
|
26
|
-
`)){let e=n.replace(/\/\/.*$/,``).trim();if(!e)continue;let r=e.toLowerCase().split(/\s+/)[0];if(!_i.has(r)){e=e.replace(/\[[^\]]*\]/g,``).replace(/:.*/,``);for(let n of e.split(Oi)){let e=n.trim();e&&/[A-Za-z]/.test(e)&&e.length<=40&&t.add(e)}}}return[...t]}function Ai(e,t){if(!t)return e;let n=t.toLowerCase(),r=[],i=[];for(let t of e){let e=t.label.toLowerCase();e.startsWith(n)?r.push(t):e.includes(n)&&i.push(t)}return[...r,...i]}function ji(e,t,n,r){let i=Ai(r,n).slice(0,80);return i.length===0?null:{from:e,to:t,query:n,options:i}}function Mi(e,t,n){let r=e.lastIndexOf(`
|
|
27
|
-
`,t-1)+1,i=e.slice(r,t);if(/^\s*direction\s*:\s*\w*$/i.test(i)){let e=/\w*$/.exec(i)?.[0]??``;return ji(t-e.length,t,e,Q(fi,`direction`))}if(/^\s*icons\s*:\s*\w*$/i.test(i)){let e=/\w*$/.exec(i)?.[0]??``;return ji(t-e.length,t,e,Q(pi,`icons`))}let a=i.lastIndexOf(`[`);if(a>i.lastIndexOf(`]`)){let e=i.slice(a+1).split(`,`).pop()??``,r=e.match(/([a-zA-Z][\w-]*)\s*:\s*([\w/-]*)$/),o=r?r[1].toLowerCase():null,s=r?r[2]:/[\w/-]*$/.exec(e)?.[0]??``,c=t-s.length,l=/^([a-z]+)\/(.*)$/.exec(s);if(l&&vi.includes(l[1]))return Ci(l[1],l[2],c,t,s,n);if(o){let e=Ti(o,s);if(e)return ji(c,t,s,e)}return ji(c,t,s,Ei(s))}let o=/[\w/-]*$/.exec(i)?.[0]??``,c=t-o.length,l=i.replace(/^\s+/,``),u=!/\s/.test(l),d=Di(e),f=ki(e);if(u){let e=[...Q(ui,`family`),...Q(di,`directive`,e=>`${e}: `)];return d===`wireframe`?(e.push(Q([`screen`],`block`)[0]),e.push(...Q(s,`control`,e=>`${e}: `))):d===`sequence`?e.push(...Q([`note`,`loop`,`alt`,`opt`,`par`,`break`,`activate`,`deactivate`],`block`)):d===`erd`?e.push(...Q(ci,`cardinality`,e=>`${e} `)):d===`mindmap`?e.push(...Q([`central`],`directive`,()=>`central: `)):d===`gitgraph`?e.push(...Q([`commit`,`branch`,`checkout`,`merge`,`cherry-pick`],`block`,e=>e===`commit`?e:`${e} `)):d===`gantt`?(e.push(Q([`section`],`block`,e=>`${e} `)[0]),e.push(Q([`excludes`],`directive`,()=>`excludes: weekends`)[0])):d===`journey`||d===`timeline`?e.push(Q([`section`],`block`,e=>`${e} `)[0]):d===`venn`?e.push(Q([`overlap`],`block`,e=>`${e} `)[0]):d===`sankey`||d===`chart`||e.push(...Q([`group`,`legend`],`block`)),e.push(...Q(f,`node`)),ji(c,t,o,e)}return ji(c,t,o,[...Q(W,`connector`,e=>`${e} `),...Q(d===`erd`?ci:[],`cardinality`,e=>`${e} `),...Q(f,`node`)])}var Ni=new Set([...dt,...tn,`quadrant-1`,`quadrant-2`,`quadrant-3`,`quadrant-4`,`group`,`screen`,`note`,`loop`,`alt`,`opt`,`par`,`break`,`and`,`else`,`activate`,`deactivate`,`legend`,`title`,`direction`,`icons`,`kanban`,`central`,`root`,`center`,`categories`,`x-axis`,`y-axis`,`stacked`,`horizontal`,`section`,`overlap`,`excludes`,`commit`,`branch`,`checkout`,`switch`,`merge`,`cherry-pick`]),Pi=new Set([...W,...bt,..._t]);function Fi(e){return Pi.has(e)||e.toLowerCase()in ft}function Ii(e,t){for(let n of t.split(/(\[[^\]]*\])/g))if(n){if(n.startsWith(`[`)&&n.endsWith(`]`)){e.push({kind:`attribute`,text:n});continue}for(let t of n.split(/(\s+)/))t&&e.push({kind:Fi(t)?`connector`:`plain`,text:t})}}function Li(e,t){let n=-1;for(let e=0;e<t.length-1;e+=1)if(t[e]===`/`&&t[e+1]===`/`){let r=e===0?` `:t[e-1];if(/\s/.test(r)){n=e;break}}let r=n>=0?t.slice(0,n):t,i=n>=0?t.slice(n):``,a=r.match(/^(\s*)([A-Za-z][\w-]*)([\s\S]*)$/);a&&Ni.has(a[2].toLowerCase())?(a[1]&&e.push({kind:`plain`,text:a[1]}),e.push({kind:`keyword`,text:a[2]}),Ii(e,a[3])):Ii(e,r),i&&e.push({kind:`comment`,text:i})}function Ri(e){let t=[];for(let n of e.split(`
|
|
28
|
-
`))Li(t,n),t.push({kind:`plain`,text:`
|
|
29
|
-
`});return t}var $=n(),zi={plain:null,keyword:`text-violet-600 dark:text-violet-400`,connector:`text-sky-600 dark:text-sky-400`,attribute:`text-amber-700 dark:text-amber-300`,comment:`text-[var(--chrome-fg-400)] italic`};function Bi(e){return(0,$.jsx)($.Fragment,{children:Ri(e.code).map((e,t)=>{let n=zi[e.kind];return n?(0,$.jsx)(`span`,{className:n,children:e.text},t):(0,$.jsx)(M.Fragment,{children:e.text},t)})})}var Vi=[`aws`,`gcp`,`azure`,`tech`];function Hi(){let[e,t]=(0,M.useState)(0),n=(0,M.useRef)(!0);(0,M.useEffect)(()=>(n.current=!0,()=>{n.current=!1}),[]);let r=(0,M.useCallback)(e=>{k().cachedAssetIndex(e)||k().loadAssetIndex(e).then(()=>{n.current&&t(e=>e+1)}).catch(()=>void 0)},[]);return(0,M.useEffect)(()=>{for(let e of Vi)r(e)},[r]),{snapshot:(0,M.useMemo)(()=>({entries(e){let t=k().cachedAssetIndex(e);return t?t.map(e=>({name:e[0],slug:e[1],keywords:e[2]})):(r(e),null)},iconUrl(e,t){return k().assetIconUrl(e,t)}}),[r]),iconsVersion:e}}function Ui(e){return e.filter(e=>e.severity===`error`)}function Wi(e){return e===1?`1 error — that line will be skipped`:`${e} errors — those lines will be skipped`}function Gi(e,t){if(!Number.isInteger(t)||t<1)return null;let n=0;for(let r=1;r<t;r++){let t=e.indexOf(`
|
|
30
|
-
`,n);if(t===-1)return null;n=t+1}let r=e.indexOf(`
|
|
31
|
-
`,n);return{start:n,end:r===-1?e.length:r}}var Ki=`'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace`,qi=12,Ji=20,Yi=12,Xi=60,Zi={margin:0,border:0,padding:Yi,fontFamily:Ki,fontSize:qi,lineHeight:`${Ji}px`,fontVariantLigatures:`none`,fontFeatureSettings:`"liga" 0, "calt" 0`,tabSize:2,whiteSpace:`pre`,overflowWrap:`normal`,wordBreak:`normal`},Qi=0;function $i(){let e=typeof document<`u`?document.fonts:void 0;if(!e)return!0;try{return e.check(`${qi}px 'JetBrains Mono'`)}catch{return!0}}function ea(){if(Qi)return Qi;let e=document.createElement(`canvas`).getContext(`2d`);if(!e)return qi*.6;e.font=`${qi}px ${Ki}`;let t=e.measureText(`M`).width||qi*.6;return $i()&&(Qi=t),t}function ta(e,t){let n=e.value,r=n.lastIndexOf(`
|
|
32
|
-
`,t-1)+1,i=n.slice(0,t).split(`
|
|
33
|
-
`).length-1,a=t-r,o=e.getBoundingClientRect();return{left:o.left+Yi+a*ea()-e.scrollLeft,top:o.top+Yi+(i+1)*Ji-e.scrollTop}}function na(e){let t=(0,M.useRef)(null),n=(0,M.useRef)(null),r=(0,M.useRef)(``),i=(0,M.useRef)(0),a=(0,M.useRef)(null),o=(0,M.useRef)(()=>void 0),[s,c]=(0,M.useState)(null),l=(0,M.useRef)(null),{snapshot:u,iconsVersion:d}=Hi();(0,M.useEffect)(()=>{o.current(!1)},[d]),(0,M.useLayoutEffect)(()=>{if(a.current!=null&&t.current){let e=a.current;t.current.selectionStart=e,t.current.selectionEnd=e,a.current=null}f()});function f(){let e=t.current,i=n.current;if(!e||!i)return!1;let a=`translate(${-e.scrollLeft}px, ${-e.scrollTop}px)`;return a===r.current?!1:(r.current=a,i.style.transform=a,!0)}function p(){f()&&c(e=>{let n=t.current;if(!e||!n)return e;let r=ta(n,n.selectionStart);return r.left===e.left&&r.top===e.top?e:{...e,...r}})}function m(){cancelAnimationFrame(i.current),i.current=requestAnimationFrame(()=>{p(),document.activeElement===t.current&&m()})}(0,M.useEffect)(()=>()=>cancelAnimationFrame(i.current),[]),(0,M.useImperativeHandle)(e.handleRef,()=>({revealLine(e){let n=t.current;if(!n)return;let r=Gi(n.value,e);if(!r)return;n.focus({preventScroll:!0}),n.setSelectionRange(r.start,r.end);let i=Yi+(e-1)*Ji,a=i+Ji;(i<n.scrollTop||a>n.scrollTop+n.clientHeight)&&(n.scrollTop=Math.max(0,i-n.clientHeight/2)),n.scrollLeft=0,c(null),f()}}));function h(e){let n=t.current;if(!n)return;let r=n.selectionStart;if(r!==n.selectionEnd){c(null);return}let i=Mi(n.value,r,u),a=n.value.slice(0,r),o=i!=null&&i.options.length===1&&i.options[0].label.toLowerCase()===i.query.toLowerCase(),s=e||i!=null&&!o&&(i.query.length>=1||a.endsWith(`[`));if(!i||!s){c(null);return}let l=ta(n,r);c({from:i.from,to:i.to,options:i.options.slice(0,Xi),index:0,left:l.left,top:l.top})}function g(n){let r=t.current;if(!r)return;let i=r.selectionStart,o=r.value,s=Mi(o,i,u),l=s?s.from:i,d=n.insert??n.label,f=o.slice(0,l)+d+o.slice(i);a.current=l+d.length,c(null),e.onChange(f),requestAnimationFrame(()=>h(!1))}o.current=h;function _(t){if(t.stopPropagation(),t.key===`Enter`&&(t.metaKey||t.ctrlKey)){t.preventDefault(),c(null),e.onGenerate();return}if(t.key===` `&&t.ctrlKey||t.key===`Escape`&&s){if(t.key===`Escape`){t.preventDefault(),c(null);return}t.preventDefault(),h(!0);return}if(s){if(t.key===`ArrowDown`){t.preventDefault(),c({...s,index:(s.index+1)%s.options.length});return}if(t.key===`ArrowUp`){t.preventDefault(),c({...s,index:(s.index-1+s.options.length)%s.options.length});return}(t.key===`Enter`||t.key===`Tab`)&&(t.preventDefault(),g(s.options[s.index]))}}return(0,M.useEffect)(()=>{if(!s)return;let e=t.current;if(!e)return;let n=ta(e,e.selectionStart);(n.left!==s.left||n.top!==s.top)&&c({...s,left:n.left,top:n.top})},[e.value,s]),(0,M.useLayoutEffect)(()=>{let e=l.current;if(!s||!e)return;e.style.left=`8px`;let t=e.getBoundingClientRect(),n=Math.max(8,Math.min(s.left,window.innerWidth-t.width-8)),r=s.top+t.height<=window.innerHeight-8?s.top:Math.max(8,s.top-t.height-Ji);e.style.left=`${n}px`,e.style.top=`${r}px`},[s]),(0,$.jsxs)(`div`,{className:`relative overflow-hidden ${e.className??``}`,children:[(0,$.jsx)(`pre`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 overflow-hidden text-[var(--chrome-fg-900)]`,style:{margin:0},children:(0,$.jsx)(`code`,{ref:n,style:{...Zi,display:`block`},children:(0,$.jsx)(Bi,{code:e.value})})}),(0,$.jsx)(`textarea`,{ref:t,value:e.value,spellCheck:!1,wrap:`off`,autoCapitalize:`off`,autoCorrect:`off`,"data-testid":`code-input`,placeholder:e.placeholder,onChange:t=>{e.onChange(t.target.value),requestAnimationFrame(()=>h(!1))},onKeyDown:_,onScroll:p,onFocus:m,onBlur:()=>c(null),onClick:()=>c(null),className:`absolute inset-0 resize-none bg-transparent text-transparent caret-[var(--chrome-fg-900)] outline-none`,style:Zi}),s&&(0,si.createPortal)((0,$.jsx)(`ul`,{ref:l,className:`fixed z-50 max-h-56 min-w-44 max-w-80 overflow-y-auto rounded-lg bg-[var(--chrome-popup)] py-1 shadow-lg ring-1 ring-[var(--chrome-ring)]`,style:{left:s.left,top:s.top,fontFamily:Ki,fontSize:12},role:`listbox`,onPointerDown:e=>e.preventDefault(),children:s.options.map((e,t)=>(0,$.jsxs)(`li`,{role:`option`,"aria-selected":t===s.index,onPointerDown:t=>{t.preventDefault(),g(e)},onPointerEnter:()=>c(e=>e&&{...e,index:t}),className:`flex cursor-pointer items-center gap-2.5 px-2.5 py-1 ${t===s.index?`bg-[var(--chrome-hover)] text-[var(--chrome-fg-900)]`:`text-[var(--chrome-fg-700)]`}`,children:[e.iconUrl&&(0,$.jsx)(`img`,{src:e.iconUrl,alt:``,loading:`lazy`,className:`h-4 w-4 shrink-0 object-contain`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.label}),(0,$.jsx)(`span`,{className:`ml-auto shrink-0 truncate text-[10px] text-[var(--chrome-fg-400)]`,children:e.detail})]},`${e.label}-${t}`))}),document.body)]})}function ra(e,t){if(!e)return null;let n=t.get(e.shapeId);return n?{...e,shapeId:n}:e}function ia(e){let t=new Map,n=new Map,r=new Map;return e.forEach((e,i)=>{t.set(e.id,`s${i+1}`),e.groupId&&!n.has(e.groupId)&&n.set(e.groupId,`g${n.size+1}`),e.lockId&&!r.has(e.lockId)&&r.set(e.lockId,`l${r.size+1}`)}),e.map(e=>{let i={...e,id:t.get(e.id)};return i.groupId&&=n.get(i.groupId),i.lockId&&=r.get(i.lockId),i.type===`arrow`&&(i.startBinding=ra(i.startBinding,t),i.endBinding=ra(i.endBinding,t)),i.type===`figure`&&i.flows&&(i.flows=g(i.flows,e=>t.get(e)??e)),i.type===`polygon`&&i.band&&(i.band={...i.band,from:t.get(i.band.from)??i.band.from,to:t.get(i.band.to)??i.band.to}),i})}var aa=3,oa=4,sa=new Set([`emoji`,`mood`]),ca=[...Object.keys(V),...Object.keys(Ve),...Object.keys(H),...Object.keys(Ge),...Object.keys(We),`flow`,`shadow`,`invisible`];async function la(e,t){let n=new Map,r=e=>{let r=n.get(e);return r||(r=t.resolve(e),n.set(e,r)),r},i=null,a=()=>(i??=t.names(),i),o=new Map,s=[];for(let t of e.iconUses){if(!t.ref)continue;let e=await ua(t,await r(t.ref),a);e&&(t.kind===`unknown`?o.set(t.diagnostic,e):s.push(e))}let c=[...e.diagnostics.map(e=>o.get(e)??e),...s],l=e=>e>0?e:1/0;return c.map((e,t)=>({diagnostic:e,index:t})).sort((e,t)=>l(e.diagnostic.line)-l(t.diagnostic.line)||e.index-t.index).map(e=>e.diagnostic)}async function ua(e,t,n){if(e.kind===`icon`){if(t)return null;let r=ma(e.ref,await n(),[]);return fa(e.line,`unknown icon "${e.written}"`,r)}if(e.kind===`keyword`){if(!t)return null;let n=e.reading===`shape`?`drawn as a shape`:`read as a frame`;return fa(e.line,`"${e.written}" is ${n} here. For the icon, write [icon: ${e.written}]`,[])}if(t)return{line:e.line,message:`unknown attribute "${e.written}". For the icon, write [${da(t)}]`,severity:`warning`,suggestions:[t]};let r=ma(e.ref,await n(),ca);return fa(e.line,e.diagnostic.message,r)}function da(e){let t=e.includes(`/`)?e.slice(0,e.indexOf(`/`)):null;return t&&![`tech`,`aws`,`gcp`,`azure`].includes(t)?`icon: ${e}`:e}function fa(e,t,n){return n.length===0?{line:e,message:t,severity:`warning`}:{line:e,message:`${t} (did you mean: ${n.join(`, `)}?)`,severity:`warning`,suggestions:n}}function pa(e){return e.toLowerCase().replace(/[^a-z0-9]/g,``)}function ma(e,t,n){let r=e.search(/[:/]/),i=r>0?e.slice(0,r):null,a=pa(i?e.slice(r+1):e);if(a.length===0)return[];let o=i?t.filter(e=>e.startsWith(`${i}/`)):[...n,...t.filter(e=>!sa.has(e.split(`/`)[0]))],s=[];for(let e of o){let t=ha(a,pa(e.slice(e.indexOf(`/`)+1)));t!==null&&s.push({name:e,score:t})}s.sort((t,n)=>t.score-n.score||Math.abs(t.name.length-e.length)-Math.abs(n.name.length-e.length)||t.name.localeCompare(n.name));let c=s[0]?.score??0,l=new Set,u=[];for(let{name:e,score:t}of s)if(t>=oa&&c<oa||(l.has(e)||(l.add(e),u.push(e)),u.length===aa))break;return u}function ha(e,t){if(t.length===0)return null;if(t===e)return 0;if(e.length>=3&&t.startsWith(e))return 1;let n=Math.min(3,Math.max(1,Math.floor(e.length/3))),r=Math.abs(t.length-e.length)>n?n+1:ga(e,t);return r<=n?.5+r:e.length>=4&&t.includes(e)?2:t.length>=3&&e.startsWith(t)?oa:null}function ga(e,t){let n=[],r=Array.from({length:t.length+1},(e,t)=>t);for(let i=1;i<=e.length;i+=1){let a=[i];for(let o=1;o<=t.length;o+=1){let s=e[i-1]===t[o-1]?0:1,c=Math.min(r[o]+1,a[o-1]+1,r[o-1]+s);i>1&&o>1&&e[i-1]===t[o-2]&&e[i-2]===t[o-1]&&(c=Math.min(c,n[o-2]+1)),a.push(c)}n=r,r=a}return r[t.length]}function _a(e,t,n){return{...ae(t,{fontFamily:n?.fontFamily??l,color:n?.color??`#1e1e1e`,opacity:n?.opacity??1},e.chartType),horizontal:e.horizontal,stacked:e.stacked,cells:e.cells,showValues:e.showValues,showLegend:e.showLegend,showTitles:!!(e.title||e.xTitle||e.yTitle),title:e.title,xTitle:e.xTitle,yTitle:e.yTitle,quadrantLabels:e.quadrantLabels}}function va(e){if(e.layout!==void 0)return e.layout;let{environment:t}=e;return(e,n,r)=>Te(e,n,t,r)}var ya={x:0,y:0};function ba(e){return e||void 0}function xa(e,t){return t===`stable`?ia(e):e}function Sa(e,t){return t.environment?la(e,oi(t.environment.icons)):Promise.resolve(e.diagnostics)}async function Ca(e,t){let n=t.origin??ya,r=va(t),i=await Sa(e,t);if(e.chart){let[r]=xa([_a(e.chart,n)],t.ids);return{status:`ok`,kind:`chart`,shapes:[r],bounds:{x:r.x,y:r.y,width:r.width,height:r.height},primary:r,title:ba(e.chart.title),diagnostics:i}}if(ke(e.diagram))return{status:`empty`,diagnostics:i};let a=await r(e.diagram,n,{frame:t.frame});if(!a)return{status:`empty`,diagnostics:i};let o=xa(c(a.shapes),t.ids);return{status:`ok`,kind:`diagram`,shapes:o,bounds:a.bounds,primary:De(o),title:ba(e.diagram.title),diagnostics:i}}function wa(e){let{source:t,converted:n}=ii(e),r=yn(t);return{source:t,converted:n,parsed:r,diagnostics:[...n?.diagnostics??[],...r.diagnostics]}}async function Ta(e,t){if(Ui(e.diagnostics).length>0&&!t.allowErrors)return{status:`gated`};let n=await Ca(e.parsed,{origin:t.origin,layout:t.layout}),r=t.icons?await la({diagnostics:e.diagnostics,iconUses:e.parsed.iconUses},t.icons):e.diagnostics;if(n.status===`empty`)return{status:`empty`,diagnostics:r};n.primary&&oe(n.primary,e.source,n.shapes);let i=n.kind===`chart`?e.parsed.chart:void 0;return{status:`built`,shapes:n.shapes,primary:n.primary,label:i?n.primary.title||`Chart`:n.primary?.label||`Diagram`,bounds:n.bounds,summary:i?ln(i):we(e.parsed.diagram),diagnostics:r}}function Ea(e,t){switch(t.type){case`load`:return{code:t.code,linked:t.linked,diagnostics:[],result:null,errorGate:!1};case`edit`:return{...e,code:t.code};case`report`:return{...e,diagnostics:t.diagnostics??e.diagnostics,result:t.result===void 0?e.result:t.result};case`gate`:return{...e,diagnostics:[],errorGate:!0};case`ungate`:return e.errorGate?{...e,errorGate:!1}:e;case`link`:return{...e,linked:t.linked}}}var Da=96,Oa=`// Describe a diagram as code.
|
|
34
|
-
// Full syntax guide at koboyo.com/docs
|
|
35
|
-
title: My pipeline
|
|
36
|
-
|
|
37
|
-
API Gateway [aws/api-gateway]
|
|
38
|
-
Resize fn [aws/lambda, green]
|
|
39
|
-
Postgres [cylinder, blue]
|
|
40
|
-
|
|
41
|
-
API Gateway -> Resize fn: upload
|
|
42
|
-
Resize fn --> Postgres: async write
|
|
43
|
-
`;function ka(){return pe.getString(fe.diagramCode)??Oa}function Aa(e,t,n){let r=ai(e);if(r)return r;let i=d({x:n.width/2,y:n.height/2},t);return{x:i.x-400,y:i.y-250}}function ja(e){let{containerRef:t}=e,{store:n,viewportAnimation:r,history:s}=a(),l=ne(),{beginTransaction:d,endTransaction:f}=s,m=o(e=>e.rightPanel===`code`),g=o(e=>e.selectedIds),{addMany:_,removeShapes:v,setCodeOpen:y,setViewport:b}=n.getState(),[x,S]=(0,M.useReducer)(Ea,void 0,()=>({code:ka(),diagnostics:[],result:null,errorGate:!1,linked:null})),{code:C,diagnostics:w,result:T,errorGate:E,linked:D}=x,[O,ee]=(0,M.useState)(!1),te=(0,M.useRef)(null),[re,ie]=(0,M.useState)(null),[k,ae]=(0,M.useState)(`next`);(0,M.useEffect)(()=>{D||pe.setString(fe.diagramCode,C)},[C,D]);let oe=(0,M.useRef)(D);oe.current=D;let ce=(0,M.useRef)(C);ce.current=C,(0,M.useEffect)(()=>{if(!m||g.size!==1)return;let e=[...g][0];if(oe.current?.frameId===e)return;let t=n.getState().shapes,r=u(t,e);if(!r||r.type!==`figure`&&r.type!==`chart`||typeof r.code!=`string`||!r.code.trim())return;let i=oe.current;if(i){let e=u(t,i.frameId);if(e&&(e.type===`figure`||e.type===`chart`)&&e.code!==ce.current)return}S({type:`load`,code:r.code,linked:{frameId:r.id,label:(r.type===`chart`?r.title:r.label)||(r.type===`chart`?`Chart`:`Diagram`),stale:se(t,r)}})},[m,g,n]);let we=(0,M.useRef)(null),A=o(e=>e.codeSeed),Te=(0,M.useRef)(null);(0,M.useEffect)(()=>{if(!m)return;let e=A===null?null:n.getState().codeSeed;e!==null&&(n.getState().setCodeSeed(null),Te.current=e,S({type:`load`,code:e,linked:null}));let t=we.current;!t||Te.current===null||Te.current!==C||(Te.current=null,t())},[m,A,C,n]);let Ee=(0,M.useDeferredValue)(C),De=(0,M.useMemo)(()=>yn(ii(Ee).source).diagnostics,[Ee]),ke=Ui(De).length,Me=E&&ke>0,j=Me?De:w;(0,M.useEffect)(()=>{ke===0&&S({type:`ungate`})},[ke]);let N=Se()===`docked`;if(!m)return null;function P(){S({type:`load`,code:ka(),linked:null})}let Pe=()=>{let e=t.current,n=e?.clientWidth??window.innerWidth,r=e?.clientHeight??window.innerHeight;return{width:Math.max(1,n-(N?360:0)),height:r}};function F(e){r.animate(n.getState().viewport,h(e,Pe(),Da),b)}let I=ni(C);function L(){if(!I)return;let e=ri(C,I);S({type:`edit`,code:e.code}),S({type:`report`,diagnostics:e.diagnostics,result:e.code===C?null:`Converted from ${ti[I]}.`})}function R(e,t){return t.type===`figure`?[t,...p(e,t)]:[t]}async function z(e){let t=n.getState();if(!t.viewMode){if(e.target){if(se(t.shapes,e.target)&&!e.force){let n=l.theme.palette(),[r,i]=await Promise.all([Ae(R(t.shapes,e.target),l,{padding:20,background:n.bg,palette:n}),Ae(c(e.shapes),l,{padding:20,background:n.bg,palette:n})]);ae(`next`),ie({current:je(r),next:je(i)});return}let n=Ma(t.shapes,e.target,e.shapes,e.primary);d(),v(new Set(R(t.shapes,e.target).map(e=>e.id))),_(n),f()}else _(e.shapes);e.primary?(S({type:`link`,linked:{frameId:e.primary.id,label:e.label,stale:!1}}),n.getState().setSelectedIds(new Set([e.primary.id]))):e.target&&S({type:`link`,linked:null}),F(e.bounds),S({type:`report`,result:`${e.target?`Updated`:`Added`} ${e.summary}.`}),N||y(!1)}}async function B(e={}){if(!(O||n.getState().viewMode)){ee(!0),S({type:`report`,result:null});try{let t=wa(C);t.converted&&t.converted.code!==C&&S({type:`edit`,code:t.converted.code});let r=n.getState(),i=D?u(r.shapes,D.frameId):void 0,a=i&&(i.type===`figure`||i.type===`chart`)?i:void 0,o=await Ta(t,{origin:a?{x:a.x,y:a.y}:Aa(r.shapes,r.viewport,Pe()),layout:Oe,allowErrors:Me||!!e.skipErrors,icons:oi(l.icons)});if(o.status===`gated`){S({type:`gate`});return}if(S({type:`ungate`}),D&&!a&&S({type:`link`,linked:null}),S({type:`report`,diagnostics:o.diagnostics}),o.status===`empty`){S({type:`report`,result:`Nothing to draw yet. Add a node or an edge.`});return}await z({target:a,shapes:o.shapes,primary:o.primary,label:o.label,bounds:o.bounds,summary:o.summary,force:e.force??!1})}catch(e){S({type:`report`,diagnostics:[],result:xe(e,`Couldn't draw this. Check the code and try again.`)})}finally{ee(!1)}}}return we.current=B,(0,$.jsxs)(Ce,{width:360,testId:`code-panel`,ariaLabel:`Diagram as code`,onDismiss:()=>y(!1),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between py-2 pl-4 pr-2`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[14px] text-[var(--chrome-fg-900)]`,children:[(0,$.jsx)(ue,{size:15,stroke:1.75}),`Diagram as code`]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,$.jsx)(i,{label:`Syntax guide`,side:`bottom`,children:(0,$.jsx)(`a`,{href:`/docs`,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`Syntax guide`,"data-testid":`code-docs-link`,className:me,children:(0,$.jsx)(Ne,{size:16,stroke:1.75})})}),(0,$.jsx)(i,{label:`Hide code panel`,side:`bottom`,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":`Hide code panel`,"data-testid":`code-close`,onClick:()=>y(!1),className:me,children:(0,$.jsx)(de,{size:16,stroke:1.75})})})]})]}),(0,$.jsx)(`div`,{className:`mx-3 h-px bg-[var(--chrome-divider)]`}),D&&(0,$.jsxs)(`div`,{"data-testid":`code-linked-chip`,"data-stale":D.stale?`true`:`false`,className:`mx-3 mt-2 flex items-start justify-between gap-2 rounded-lg px-2.5 py-1.5 text-[12px] ${D.stale?`bg-amber-50 text-amber-800`:`bg-[var(--chrome-hover)] text-[var(--chrome-fg-700)]`}`,children:[(0,$.jsx)(`span`,{className:`text-pretty`,children:D.stale?`“${D.label}” was edited on the canvas. Updating from this code replaces those edits.`:`Editing “${D.label}”. Generating replaces it.`}),(0,$.jsx)(i,{label:`Back to the draft`,side:`bottom`,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":`Stop editing this diagram`,"data-testid":`code-unlink`,onClick:P,className:`shrink-0 rounded-md p-0.5 transition-[background-color,scale] active:scale-[0.96] ${D.stale?`hover:bg-amber-100`:`hover:bg-[var(--chrome-rest)]`}`,children:(0,$.jsx)(de,{size:14,stroke:1.75})})})]}),I&&(0,$.jsxs)(`div`,{"data-testid":`code-foreign-hint`,className:`mx-3 mt-2 flex items-center justify-between gap-2 rounded-lg bg-amber-50 px-2.5 py-1.5 text-[12px] text-amber-800`,children:[(0,$.jsxs)(`span`,{className:`min-w-0`,children:[`Looks like `,ti[I],`.`]}),(0,$.jsx)(`button`,{type:`button`,"data-testid":`code-foreign-convert`,onClick:L,className:`shrink-0 whitespace-nowrap rounded-md px-1.5 py-0.5 text-amber-900 underline decoration-amber-400 transition-[background-color,scale] hover:bg-amber-100 active:scale-[0.96]`,children:`Convert now`})]}),(0,$.jsx)(na,{handleRef:te,value:C,onChange:e=>S({type:`edit`,code:e}),onGenerate:()=>void B(),placeholder:`API -> Worker: job`,className:`m-3 flex-1 rounded-lg text-[12px] leading-relaxed ring-1 ring-[var(--chrome-ring)] focus-within:ring-black/25`}),(j.length>0||T)&&(0,$.jsxs)(`div`,{className:`mx-3 mb-2 flex max-h-32 flex-col gap-1 overflow-y-auto`,children:[T&&(0,$.jsx)(`div`,{"data-testid":`code-result`,className:`text-pretty text-[12px] text-[var(--chrome-fg-600)]`,children:T}),j.map((e,t)=>(0,$.jsxs)(`button`,{type:`button`,"data-testid":`code-diagnostic`,"data-severity":e.severity??`warning`,disabled:e.line<=0,onClick:()=>te.current?.revealLine(e.line),className:`-mx-1 rounded px-1 text-left text-pretty text-[12px] leading-snug tabular-nums transition-colors enabled:hover:bg-[var(--chrome-hover)] ${e.severity===`error`?`text-red-600`:`text-amber-700`}`,children:[e.line>0?`Line ${e.line}: `:``,e.message]},`${e.line}-${t}`))]}),(0,$.jsxs)(`div`,{className:`border-t border-[var(--chrome-ring)] p-3`,children:[Me&&(0,$.jsxs)(`div`,{role:`status`,"data-testid":`code-error-gate`,className:`mb-2 flex items-start gap-1.5 rounded-lg bg-red-50 px-2.5 py-1.5 text-[12px] text-[var(--chrome-danger)] dark:bg-red-500/10`,children:[(0,$.jsx)(le,{size:14,stroke:1.75,className:`mt-px shrink-0`}),(0,$.jsx)(`span`,{className:`text-pretty tabular-nums`,children:Wi(ke)})]}),(0,$.jsx)(`button`,{type:`button`,"data-testid":`code-generate`,disabled:O||C.trim().length===0,onClick:()=>void B(),className:`w-full rounded-lg bg-[var(--chrome-accent)] px-3 py-2 text-[13px] text-white transition-[background-color,scale] hover:bg-[var(--chrome-accent-hover)] active:scale-[0.96] disabled:bg-[var(--chrome-rest)] disabled:active:scale-100`,children:O?`Generating…`:Me?`Apply anyway`:D?`Update diagram`:I?`Convert ${ti[I]} & generate`:`Generate diagram`}),(0,$.jsx)(`p`,{className:`mt-1.5 text-center text-[11px] text-[var(--chrome-fg-400)]`,children:`⌘↵ generates · the code stays for tweaking`})]}),re&&(0,$.jsx)(ve,{open:!0,onOpenChange:e=>!e&&ie(null),children:(0,$.jsxs)(ge,{children:[(0,$.jsx)(he,{className:`fixed inset-0 z-40 bg-gray-900/25`}),(0,$.jsxs)(_e,{"data-overlay":!0,"data-testid":`code-replace-dialog`,className:`fixed left-1/2 top-1/2 z-50 flex max-h-[92dvh] w-[min(860px,94vw)] -translate-x-1/2 -translate-y-1/2 flex-col rounded-2xl bg-[var(--chrome-popup)] p-5 shadow-[0_24px_70px_rgba(0,0,0,0.22)] outline-none ring-1 ring-[var(--chrome-ring)]`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(be,{className:`text-[15px] font-medium text-[var(--chrome-fg-900)]`,children:`Replace your edits?`}),(0,$.jsx)(`p`,{className:`mt-1 text-[13px] leading-snug text-[var(--chrome-fg-600)]`,children:`This diagram was edited on the canvas after its code was generated. Compare both, then keep your edits or replace them with the code.`})]}),(0,$.jsx)(ye,{"aria-label":`Close`,className:`-mr-1 -mt-1 shrink-0 rounded-lg p-1 text-[var(--chrome-fg-500)] outline-none transition-colors hover:bg-[var(--chrome-hover)]`,children:(0,$.jsx)(de,{size:16,stroke:1.75})})]}),(0,$.jsx)(`div`,{role:`tablist`,className:`mt-4 inline-flex self-start rounded-lg bg-[var(--chrome-rest)] p-0.5 text-[12.5px]`,children:[{key:`next`,label:`Code version`},{key:`current`,label:`Already on Canvas`}].map(e=>(0,$.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":k===e.key,onClick:()=>ae(e.key),className:`rounded-md px-3 py-1 transition-colors ${k===e.key?`bg-[var(--chrome-popup)] text-[var(--chrome-fg-900)] shadow-sm`:`text-[var(--chrome-fg-500)] hover:text-[var(--chrome-fg-800)]`}`,children:e.label},e.key))}),(0,$.jsxs)(`div`,{className:`mt-3 flex min-h-0 flex-1 items-center justify-center overflow-auto rounded-xl bg-[var(--canvas-bg)] p-4 ring-1 ring-[var(--chrome-ring)] [min-height:clamp(260px,56vh,520px)]`,children:[(0,$.jsx)(`img`,{src:re.current,alt:`Your edits`,className:`max-h-full max-w-full object-contain ${k===`current`?``:`hidden`}`}),(0,$.jsx)(`img`,{src:re.next,alt:`Code version`,className:`max-h-full max-w-full object-contain ${k===`next`?``:`hidden`}`})]}),(0,$.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-3`,children:[(0,$.jsx)(`p`,{className:`text-[12px] text-[var(--chrome-fg-500)]`,children:k===`current`?`What you have on the canvas.`:`Rebuilt from the code. You can undo this.`}),k===`current`?(0,$.jsx)(ye,{className:`rounded-lg bg-[var(--chrome-rest)] px-3.5 py-2 text-[13px] text-[var(--chrome-fg-800)] outline-none ring-1 ring-[var(--chrome-ring)] transition-[background-color,scale] hover:bg-[var(--chrome-hover)] active:scale-[0.96]`,children:`Keep my edits`}):(0,$.jsx)(`button`,{type:`button`,"data-testid":`code-confirm-replace`,onClick:()=>{ie(null),B({force:!0,skipErrors:!0})},className:`rounded-lg bg-[var(--chrome-accent)] px-3.5 py-2 text-[13px] text-white outline-none transition-[background-color,scale] hover:bg-[var(--chrome-accent-hover)] active:scale-[0.96]`,children:`Apply my Code Changes`})]})]})]})})]})}function Ma(e,t,n,r){if(t.type!==`figure`||!t.flows?.length||r?.type!==`figure`)return n;let{flows:i}=Me(e,t,n,r);return n.map(e=>e===r?{...r,flows:i}:e)}export{ja as CodePanel};
|