From 297215b68ac62bf9c3b61ebb28fbe11d49fa82a8 Mon Sep 17 00:00:00 2001 From: Tomasz Cichocinski Date: Thu, 5 Nov 2026 11:30:44 +0100 Subject: [PATCH] explain-pr-as-video: a narrated video that walks a reviewer through a PR's decisions --- CHANGELOG.md | 1 + README.md | 4 +- skills/explain-pr-as-video/SKILL.md | 147 +++++ skills/explain-pr-as-video/agents/openai.yaml | 4 + skills/explain-pr-as-video/assets/logo.png | Bin 0 -> 15338 bytes .../explain-pr-as-video/assets/pele.LICENSE | 40 ++ skills/explain-pr-as-video/assets/pele.js | 150 +++++ skills/explain-pr-as-video/assets/runtime.js | 557 ++++++++++++++++++ skills/explain-pr-as-video/assets/theme.css | 294 +++++++++ skills/explain-pr-as-video/references/deck.md | 180 ++++++ .../explain-pr-as-video/references/share.md | 13 + skills/explain-pr-as-video/scripts/ab.mjs | 268 +++++++++ skills/explain-pr-as-video/scripts/render.mjs | 206 +++++++ skills/jam/SKILL.md | 1 + 14 files changed, 1864 insertions(+), 1 deletion(-) create mode 100644 skills/explain-pr-as-video/SKILL.md create mode 100644 skills/explain-pr-as-video/agents/openai.yaml create mode 100644 skills/explain-pr-as-video/assets/logo.png create mode 100644 skills/explain-pr-as-video/assets/pele.LICENSE create mode 100644 skills/explain-pr-as-video/assets/pele.js create mode 100644 skills/explain-pr-as-video/assets/runtime.js create mode 100644 skills/explain-pr-as-video/assets/theme.css create mode 100644 skills/explain-pr-as-video/references/deck.md create mode 100644 skills/explain-pr-as-video/references/share.md create mode 100644 skills/explain-pr-as-video/scripts/ab.mjs create mode 100644 skills/explain-pr-as-video/scripts/render.mjs diff --git a/CHANGELOG.md b/CHANGELOG.md index 258809d..81836dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Added `add-voiceover`: voice a spoken script line by line and lay each line under its moment in any video, with a WebVTT subtitle file. The agent asks which voice to use: ElevenLabs (`eleven_v4`), Kokoro (free, local, a one-time 340 MB download), the OS voice, or the team's own command. A video with its own sound keeps it under the narration, lowered together with it only if the mix would clip. The script runs on Node 22 or later with nothing to install. No Jam account needed. - Added `record-terminal-proof`: record a terminal run with asciinema and render a GIF for the pull request, plus an MP4 when needed. No Jam account needed. - `scripts/check.mjs` counts Jam mentions in an unbranded skill in prose only, so a "With Jam" line can show the command. +- Added `explain-pr-as-video`: a narrated video that teaches a reviewer a pull request, from an animated HTML deck rendered to MP4 with a browser preview, voiced through `add-voiceover`. - `server.json` follows Jam MCP 1.27.1, the version production serves. - `jam-fix` hands a narrated walkthrough that asks for several changes to `jam-to-tasks`, when installed, instead of diagnosing it as one bug. - Added `jam-to-tasks`: turn a narrated Jam into a numbered list of every change asked for, each tied to its moment, frame and quote, then work through the list. diff --git a/README.md b/README.md index 3697b96..0685e00 100644 --- a/README.md +++ b/README.md @@ -61,15 +61,17 @@ These need no Jam account. With the Jam CLI, a video can become a Jam link to co - [record-demo](./skills/record-demo/SKILL.md): "Record a demo of this feature." Plays the flow in a browser at human pace and renders a narrated 1440p video, with the camera moving only where the script says. - [add-voiceover](./skills/add-voiceover/SKILL.md): "Add a voiceover to this video." Writes a script for the ear, voices it line by line and lays each line on the moment it describes, with a subtitle file. +- [explain-pr-as-video](./skills/explain-pr-as-video/SKILL.md): "Explain this PR as a video." Walks a reviewer through the decisions in a pull request, each with what was rejected and what it costs, as a narrated video drawn from an animated HTML deck. - [record-terminal-proof](./skills/record-terminal-proof/SKILL.md): "Record proof that the migration ran." Records the commands and renders a GIF that plays inline on the pull request. ## Requirements -- A free [Jam](https://jam.dev?utm_source=github&utm_medium=readme&utm_campaign=skills) account, for every skill except the three video skills. +- A free [Jam](https://jam.dev?utm_source=github&utm_medium=readme&utm_campaign=skills) account, for every skill except the four video skills. - The [Jam CLI](https://jam.dev/cli). Say "set up jam" and `jam-setup` walks you through it. A skill signs in when it needs to. `jam`, `jam-fix` and `jam-to-e2e` can read a Jam through Jam MCP instead, the Model Context Protocol (MCP) server the plugin connects. - For `video-to-jam`: ffmpeg and a local transcriber such as Whisper. - For `record-demo`: agent-browser 0.38.1 or later, ffmpeg and Node 22 or later, with no npm packages. Its narration comes from `add-voiceover`. - For `add-voiceover`: ffmpeg and Node 22 or later, with no npm packages. An ElevenLabs key or the free Kokoro model (Python 3 and uv) gives a natural voice; without either, it uses the macOS voice. +- For `explain-pr-as-video`: ffmpeg, Chrome and Node 22 or later, with no npm packages. Its narration comes from `add-voiceover`. - For `record-terminal-proof`: asciinema 3 and agg. On Windows, use WSL. - In CI or a cloud agent: a [personal access token](https://jam.dev/docs/personal-access-tokens) in `JAM_TOKEN`. - For `jam-proof`: recording a web page needs only Chrome. Recording a window or the whole screen needs macOS or Linux (X11). diff --git a/skills/explain-pr-as-video/SKILL.md b/skills/explain-pr-as-video/SKILL.md new file mode 100644 index 0000000..eb96d6f --- /dev/null +++ b/skills/explain-pr-as-video/SKILL.md @@ -0,0 +1,147 @@ +--- +name: explain-pr-as-video +description: "Make a narrated video that walks a reviewer through the decisions in a pull request: the problem, the shape of the system, each decision with its rejected alternatives and its costs, the facts checked for it, what is proven, and the calls only the reviewer can make. Built as an animated HTML deck, voiced line by line, rendered to MP4 with a browser preview. Use when the user asks for a PR video, a review video, a video walkthrough or explainer of a pull request, a stack of PRs, a branch or a diff, or wants to help reviewers understand a big change." +--- + +# Explain a PR as a video + +The video teaches; it does not sell. Code review is mostly judging decisions: was this the right choice, and is its trade-off acceptable? So the video is built around the PR's decisions, each told like an architecture decision record: what forced it, what was chosen, what was rejected and why, and what it costs. Everything with a factual answer is checked before the reviewer sees it. What is left for the reviewer is judgment, and the video ends by asking for it: one decision at a time, approve or push back. + +Needs Node 22+, `ffmpeg`, Chrome or Chromium (`CHROME_PATH` if it is not found), the Inter and JetBrains Mono fonts (without them the fallbacks wrap text differently, so check the stills on the machine that renders), and the `add-voiceover` skill installed next to this one for the voice. Scripts are in this skill's folder: `scripts/render.mjs`, `assets/runtime.js`, `assets/theme.css`, `assets/pele.js` (Pele, MIT, draws Mermaid; license in `assets/pele.LICENSE`), `assets/logo.png`. + +## 1. Learn the change before writing a word + +Read the PR body, the linked issue, the whole diff and the CI state. Note with `path:line` for each fact: + +- **The one thing**: what changed and why it matters, in one line, and the one sentence the reviewer should remember after the video, in their words. Everything else serves it. +- **The symptom**: what went wrong for a person or a program, with any real number from the PR or issue. Never invent a figure. +- **The shape**: the 3 to 5 parts the change runs through (processes, services, modules) and the one boundary or flow it changes. +- **The decisions**: 2 to 4 choices the PR makes that a reasonable engineer could have made differently. For each: the context that forced it, the decision in active voice, the alternatives rejected and why (from the PR, the issue, code comments; say so when no reason is given), and the consequences, the downside included. A change with no real alternative is not a decision; it gets a line, not a scene. +- **Proof**: what was verified and how, CI per platform as of today, and what the PR says is not verified. +- **Doubts about each decision, settled.** Every doubt with a factual answer is yours to settle: does anything depend on the old behavior, what can this value contain, does the alert still fire. Each answer is a finding with its `path:line`, attached to the decision it informs. Look hardest for consequences the PR does not mention. +- **The reviewer's calls**: for each decision, the trade-off in one sentence the reviewer can approve or push back on, with the findings that inform it. Never ask the reviewer something you could have checked. + +- **One name per thing.** Pick one word for each part and concept (`recorder`, not "daemon" in one scene and "recorder" in the next) and use it in the voice, on screen and in the text map. + +- **A worked example.** One real datum (a click, a field, a request) that you can follow through every part of the change, with the real field and event names from the diff. It becomes the spine of the video. + +Do not confuse proposed, merged and released. Do not present tests or refactors as features. + +### A stack of PRs + +Make one video for the whole stack, not one per PR. Read every PR body, the ADRs they link and the head of the stack; a body often carries its own diagram blocks and review map, so reuse their names and order. The home stage is the system diagram with a chip per PR on the part it touches. Then follow the worked example through the PRs in order, give the 2 or 3 decisions that cut across the stack a scene each, and end with the calls and the reading and deploy order. Aim for 4 to 5 minutes for a large stack. + +## 2. Write the script for the ear + +**Who is listening:** an engineer on the team who knows the codebase but not this change. Talk to them like a teammate walking them through it at their desk: casual, direct, no lecture. Name modules, files and commands without defining them; explain only what this PR adds or what a teammate could not know (a monitor, an incident number, a decision made in the issue). Recap the shape in a few quick lines, as a refresher, not a tutorial. + +Make a work folder outside the repo. Write `lines.json`, one spoken line per entry, grouped by scene: + +```json +[ + {"scene": "why", "cue": "err", "say": "An agent starts a recording, and Chrome sends no picture."}, + {"scene": "shape", "cue": "ready", "say": "It answers the CLI with one line of JSON. The ready line."}, + {"scene": "shape", "cue": "lost", "say": "Before this change, whatever the recorder knew stopped here.", "pause": 0.4} +] +``` + +- `scene` groups lines; keep each scene's lines together. `cue` names the line so the deck can react to it. `pause` adds seconds of silence before a line. +- Default arc, 6 to 8 scenes: **why** (the symptom) → **shape** (build the system diagram one part per line) → one scene per **decision**: what it does on the diagram, then chosen, rejected and why, the cost, and what you checked → a short scene for changes that are not decisions → **proof** (verified, CI per platform, not verified) → **your call** (one approve-or-push-back line per decision, then the reading order). Fold scenes for a small PR. +- **The hook**: the first line shows the failure itself, or the moment that needs the change, never the repo name or "this PR". Frame 0 is the thumbnail, so the first scene has something on screen at time zero. +- Casual spoken English: contractions ("it's", "doesn't"), short sentences mixed with longer ones, natural openers ("Okay, so", "Here's the catch", "So, your call"). Present tense, one idea per line, 6 to 20 words. Say numbers and symbols as spoken: "exit code thirteen", "record dot ts". +- No pitch: no "robust", "seamless", "great work", no closing thanks. State limits as plainly as wins. +- The screen never repeats the spoken sentence word for word. The voice explains; the screen shows the picture, the name or the number it is about. +- Budget about 2.7 words per second of video. Aim for 90 to 180 seconds; a 700-line PR fits in about 450 words. Count with `jq -r '.[].say' lines.json | wc -w`. + +Voice it once to get each line's length (the add-voiceover skill picks the voice; its default order is the team's command, ElevenLabs, then Kokoro): + +```bash +python3 /../add-voiceover/scripts/voiceover.py lines.json voiceover +``` + +To draft without spending ElevenLabs credits, run it with `env -u ELEVENLABS_API_KEY` so the free local Kokoro voice is used. Voice the final cut with the user's voice, or with a conversational ElevenLabs voice so it sounds like a person talking, not a voiceover. + +## 3. Build the deck + +Copy `assets/runtime.js`, `assets/theme.css`, `assets/pele.js` and `assets/logo.png` into the work folder and write `deck.html`. Read `references/deck.md` before the first scene: it has the page skeleton, every component, and the animation attributes. The essentials: + +- One `
` per scene id. The title feeds the chapter rail at the bottom. +- `data-in="cue"` makes an element enter when that line starts (`cue+0.6` for later, `@0.2` for seconds into the scene). `data-anim` picks the entrance: `rise`, `fade`, `pop`, `left`, `wipe`, `draw` for SVG wires, `type` for terminal text, `count` for numbers. +- `data-focus="cueA cueB"` lights an element while one of those lines is spoken and dims the scene's other `data-focus` elements. At the end of each scene the focus lets go and the whole picture holds before the cut. This is the pointer that follows the voice: use it on every scene with more than two parts. +- **Draw with the primitives, not by hand.** Messages between parts are a `pre.lanes` sequence diagram, and a sequence diagram from a PR body usually pastes straight in. Time (windows, latency, retries) goes on a `.track` with a playhead. A page is a `.browser`, and rows landing in a table are `table.rows`. The worked example rides the wires as a `.token`. `references/deck.md` has each one. +- **Pick the shape of each line, then its picture.** Most lines are one of a few shapes: a flow through the system, before and after, one choice out of several, a number that lands, a wrong idea struck through, steps in order, a real log or screenshot with the detail circled. Similar lines get different pictures; each line gets the one that shows it. +- **One home stage.** The shape diagram is home. Each decision scene returns to it and moves into the part the decision changes, so the viewer never loses where they are. Keep the decision card (`.adr`) the same in every decision scene: it is the reviewer's form, and the same form makes decisions easy to compare. +- Build diagrams up. Draw the system on the shape scene one part per line, then copy that diagram into each change scene and add only what the change adds. Each scene redraws the last and adds one idea. +- Show code only as evidence for a spoken claim: 2 to 4 short hunks in the whole video, each at most 4 lines, never a whole file. +- Avoid what looks generated: bullet slides, three cards in a row, side-by-side panels standing in for a picture, a whole diagram dropped on at once, every scene entering the same way, titles that keep moving after they land. +- Label anything made up for illustration, such as a sample log, as an illustration. + +**Branding.** `theme.css` and `logo.png` carry the default brand. For another one, add a stylesheet after `theme.css` that sets the `:root` tokens (colors, `--font`, `--mono`) and replace `logo.png`. + +## 4. Check the frames, then render + +```bash +node /scripts/render.mjs deck.html voiceover/lines.json --stills +``` + +This writes `timeline.js` and `timed.json`, prints any deck problems (unknown cues, text that overflows, content in the rail's area), and writes `stills/NN-.png`, each scene once it has fully built. `--at ` renders one frame mid-scene, to check a camera move or a focus state. The automatic check skips diagrams inside a camera stage, so read every still as an image: + +1. Describe each still in one sentence as a stranger would, naming every object. Anything you would have to explain ("the green line is the new reason") is a problem. +2. Cover the words: do the stills alone, in order, tell the story? +3. Write each problem as `scene · where · problem → change`, ranked: **P0** breaks the read (wrong, clipped, unreadable, overlapping), **P1** weakens it (crowding, two focal points, a scene that looks like the last), **P2** polish. Fix every P0, then the P1s worth it, and re-run. + +Stills only show where each scene ends. Check the motion too, with 12 frames per scene on one sheet: + +```bash +ffmpeg -v error -ss -t -i voiceover/voiced.mp4 -vf "fps=12/,scale=640:-1,tile=4x3" -frames:v 1 motion-.png +``` + +Look for a token that parks on a label, a dimmed panel that turns into a grey block, and a before-diagram that vanishes too fast to read. + +When you can start a sub-agent, give it `lines.json`, the stills, the motion sheets and your fact notes, and ask for P0 and P1 lines in that format, with a score. Ask two different models if you can: in practice they catch different mistakes, one the overstated claims, the other the facts slightly off. Fix what holds up, then ask again. + +Then render and mix the voice: + +```bash +node /scripts/render.mjs deck.html voiceover/lines.json +python3 /../add-voiceover/scripts/voiceover.py timed.json voiceover --video video.mp4 +``` + +The render takes about half the video's length on a laptop. The second voiceover pass reuses every voiced line from the first, so it only mixes. Output: `voiceover/voiced.mp4`, plus `voiceover/voiceover.vtt` for players that show subtitles. + +Check sync: take a frame 1.5 seconds after a few lines' `at` in `voiceover/lines.json` and confirm it shows what the line names: + +```bash +ffmpeg -v error -ss -i voiceover/voiced.mp4 -frames:v 1 check.png +``` + +Opening `deck.html` in a browser plays the deck with the narration and a scrubber: space plays, arrows jump 5 seconds. + +## A/B test the whole video or a scene + +Copy the work folder once per variant (`a/`, `b/`) and change one thing in each copy: a scene's lines or section, or the voice (`KOKORO_VOICE`, `ELEVENLABS_VOICE_ID`). Voice, render and mix every copy as in step 4, then: + +```bash +node /scripts/ab.mjs compare a b +``` + +Give the user `compare.html`. It plays any scene of any variant, the number keys switch variant at the same point in the scene, and blind mode hides which variant is which. Once they pick a variant per scene, or one for the whole video, they copy `picks.json` from the page. A scene marked "cut" is dropped. Then: + +```bash +node /scripts/ab.mjs merge picks.json merged +``` + +`merged/` holds the picked scenes' lines and sections on top of the first variant's deck, plus every voiced line, so voicing it again only voices what changed. Run step 4 there. + +## 5. Share it with a text map + +The video never carries anything the reviewer must act on that the text lacks. Write a short description to go with it: one line per scene with its time, the findings with their evidence, the reading order with `path:line` links pinned to the head commit, and the open calls. Give the user the MP4 path and that text, and tell them in two lines what you only looked at rather than checked (the voice is measured for sync, not heard) and the weakest scene. Do not post to the PR unless the user asks. + +With Jam: upload the MP4 with that text as a shareable recording, as `references/share.md` shows, and return its link. + +## When it goes wrong + +- **`Chrome not found`**: set `CHROME_PATH` to a Chrome or Chromium binary. +- **A line warns it starts late**: an earlier line is too long for its scene; shorten it. +- **An element never appears**: its cue name has a typo; the `--stills` run prints `cue "x" is not a line in scene y`. +- **Motion that works in the browser is frozen in the video**: it uses a CSS transition or animation. Every motion must come from the data attributes, which the renderer drives frame by frame. diff --git a/skills/explain-pr-as-video/agents/openai.yaml b/skills/explain-pr-as-video/agents/openai.yaml new file mode 100644 index 0000000..3bc2116 --- /dev/null +++ b/skills/explain-pr-as-video/agents/openai.yaml @@ -0,0 +1,4 @@ +interface: + display_name: "Explain PR as Video" + short_description: "Teach a reviewer a pull request in a narrated video" + default_prompt: "Use $explain-pr-as-video to make a narrated video that teaches a reviewer this pull request." diff --git a/skills/explain-pr-as-video/assets/logo.png b/skills/explain-pr-as-video/assets/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..6814a9d4aaec91b9cf3a51850015e68fe34b2193 GIT binary patch literal 15338 zcmYMbbySqy_dYyBH!}j#skD?x_b^h@3=LA!-5rucqadhs!_YO9NJ%Q)-O@;Ryz_j1 z-?iR9?lo)n$@|>rTzl`cuN|$fDo=<N)0cl9tXVBq`(zL|5%QZpGw&!cu1;4f^!HMha|tM4-N?#)jv#SQ3=(tdzSMK zLFSsbq!CwrW*!x7Ar?(?x6HroUzzCcxZ?l*NMgi&`6vDEAa1jwf_e78n}@8GGa6Yo z((U0)8#=nIF{{6F^KMp^L!`~`mGkG`{IQZP&?m6%z9Xo4Ot%%p2lvF7Q3Mu!4ZQSL z-hCDHMpPyL*jF{~XQ;-`8@!85LPBy;>yh`1tT29AHV~@~L4I`?5#^`!a<#>D3J&O; zS=1L>x|*N9zgplyPRvuEMBJa#fbhbBo1H`%_md6NnWOR3-nx2K>EZAa@$hkAncc06 zQl{&N%LB|z2pL}pi}Y$-oO0U$sYU!nqXni~ji($G7V$!-+2dEr{oR?t^P}ffQNWj~ zJIV{D4U^N=nQ~Bs-ptpfNZX$)qYT)3w3fmlN(T1C3N;OK(1Hmd-;gmOp=@iN=wwne zVDC_(0qszrY<#XmDGHvalkrp55;ps#K_*feL)|u3Meh)#VMIC3j(IlM>`s1=LZILY zAPcj;W!YD|X-cr`>!{_>2kTU7&0mtuP@Wp~Vyd_!D|=_{?#C zHLU_piFzR~ToWwKVc_U_p))%vq!1X`X1oRhV}9g?M1)HZCT=pnVaLn+g{|)V@0)cO z9v!Pkk@B}LFDh_EukDO6<bLTVvFAaUAgckA@tYo|%a0OP@ zIBt_>hsHfSbIeZ-xA)L@zkfipYLl8cE0>&ptF4%6i`y3};ZT)ttwubj25XRx7PSW4 z)DjRAzf*ZOpZX342)wZzDGIf9Dn%|uuF4d;4++dv&ok!DQk2D%^CJ9w7(e>MpShCJ z(UvVUYCAFYOj1Fx*JPoj*1DBOrF`(uT7*54A;TFW&4RkRjrrdZ*q!{2^KX!Ia5h&v zyu5IjYz<+~*oJ!+-&?x05WN$ShQZ`BXyoSm@~ZY@2P0y!cuN48Pzu#um}--2d=z}# z&c>#nD8GZ1TW?BTHnaJ40$1~_iGJFQ$QAye~4}Ike8(CvyIt|fTjKC)kt>3);^`|0^DZJifEY@QBvAd75 z%IX>f_U&$Xz1rkeM-ids>iB%9UPt;G{rR6R)%Jh#t%Um$P$(&lU=`N4&%Y^~3Awo3 zy`x#?(Qq6a*FJR>2dyNouK5vzH5@_GI852~$c=go^&|m$0&3-K$;=niP$*-k2Tjpt z01>MVKI0aU^ur`o+q-ZzW8+K^Si|S|xHXoX=ayD=$G$|Uy~q!0xH}j$dfZt+-5mvI z3ur=OePwa#ZJ?fU(NNIG4BzmKJe!atd?uOU@q$T{bMz~+P5)wi21dJ(e-M*cw?rWc zg`Pay`EGCAT@|Oiz!<~Uythzna3`#ng4#(1CQ0^HQ!IuH3;us8H5ksHXFUAD?LJmk zR&I42LJcQMp)4&nJmQfNBLT_90zEH3<`t3JnEvX8e{agn#DqttIw6O11G@cSWYbo) zKKgOZzKU4z+v@;0JTFQjO;Rm`GBZwWZJ$Cw3WA^W>67iqHKpikG-?S>*6&&zj5p-v ztiq9Wq)Pb1|5}I=}Xm?MNeQBwQ;@%D2~Vi&WBCpswM(B7Wyz$prff^Uu((yxeo)QI^c#< ze07p~H^go`(|e`SgqF51JVu>N;&O+W0!k_>Rs0g8A~XOy$@n3Tg4HOPuWT!FnmYTR zEJD~3nc2EL`kEsXrpM`bP(^R%p8yGaPGjIom*|A!0SWyFIMsS^ISzrD9mBA{fH;_7 za?pmZzc2?)PfH51ZRDQ?Hpy!|2B|4xM3$WDmU=&h_?k3G;;OEq9A3f_g#E0X!=@&i zqhA+rQyL`fBW-4WT=MbcusHadbOv5xM={WAgG>+ApOp+g>gwwWvj)`MGA?-?_-Vbr zz4=W*7a?3O-9S<81d>27n2@+;0e|g9c?{eNH#iMnU-n`jk>oMl$64NegP(z=kBaH4 zZ*vWDmyj2%BXcjN3g|<3be)e(1)v|pH87ip-z_8>9=mQ5X*7&FwK{IuMXH6n+zLGs zA|KC1?mm$~gRYw{g-qzaAv+HVE6G4*^qQFDZLCj!ZIKJ+krQsD7+GmsH9R{Viy~*b zI=7uMz{v%Fy9oB)AlJ?YdIVM!!MgKC=mq4{)4l7jkF{8`A!H2%JHAc>WKebYwozv7e zA8{M$pEiAcud&nhE?$z(7wT162tc=dFp~;>g{2xCWVDc8d%F_x4cTOxGAPsx++q7f zZB%{K=KO-kh`rO*5rN?!S}oN7cFrtZkqo3N2}(N#>PT&3T1?qA^977|+YXq)!%I>U zeM88$=3SD5rjM)1B;|(MDJ>}soP@i%xGKxCIer)Ysh8reeP8G1Ic^~3dC;en$rGm# zoa@6nEAaZINt{tCaQ`mbn6lnvIFXq$QlX`_RfJjILOsQlX?SQSE5}uBB8ya@t*v;4 zzwi_QF>ad*O7Fa+R*AfzE5CT@I|}&dwm)fg^LJ9;B6lJM|6gQT@T)lP{@h$i5u3Kp zR7(Hh2PaSauT+{jgl)G99)tZupQkSP>QP-p(fFTCQ+d|1IX01GB&A>wV-gWjX4;Ce zxIMP!XBT5Q%`EYz2BwPWcWWa+ri8zhW9OR{_d7C|Q(#|JDJc;+aI@+&|5jvDv-RJA zo6GYmz0QeOuAxX;$j)IWe>Cok@R2ee=d{bqLdaYM3E1UzXnJ(IW*=tK%)pF8`xsO& zsrS3|GX{q&o1cF;H7K*p6Ud*sR9zvUYVk$G36b&Nv+n0OEViTD5&D;)HLM5srO zkjo$v)s$;uGp(JR{;B&S`yghYj-G(r!O7{}6qQ=V=x6^knEq-Pl}$izm*_mm?ICBssKE?die|TY9*b z_^I|kvcPY|#q)=PoKISNRVv#}X=j3K*__tGs(t^?S6NwQ78|G<5>++TZ&5(z*0rli zXUok;5k;d>m^L7P5YA3pMSZWsCkfnj9YV%%-F|VHkeF4Q8iQj-??s4wh!ve&KMv~i?!}@hrxP|nWH>Q)KL~Gr+LY~MA&-r9G zjSZ`*^HX8h|Q zcT$S{QxxVjp_(@eW=u2*A72|N&PoVKW}oI9b&K5?eys1TOI)w^C1Wk6S2{)~D1BYE z)?hU3@LRu7(~zqjhnb!(x6S&WWb`vtKIvndROZnlISGg!tW3gC`rmQ z>;i!?)?1HA9)Xo`s}8C;3iL(z77bkpay%&QJ0ArNrfUuNf z+Wm>q&zjmOGWA~Z)381!!vjxl2ZHSD?skn7i+SP7sASjOG?Ix`QX@IjMNveXBu+M) zp%|%A3gf17uPYm4vv^&1id7lfI)&GBsEAX%gd{=shnUyl>ZMZmVSN#w2jsopxc7>p zt6xAHs$-AW=(0b=z78j%fBY(o%iar65?Op}zQl^BdaZu?mJ(93>}#YZ$`_)^jX;;< z8~%N)NX{CbS7POAM69NyK#!#!W46N(!(%`|vl@=BlwAVBk;M)8Zg6_AB8-TYh_Tf1-nxzh z)r9-$GB(J2fJJKh6~afvO4wNHgV36z?&AS&8q-@-t+Jh8vhOCsfGJEG6?Zv@y~hKU zTr)vaP6NB)vhQw$|7}_T3NeoGYD^%F*5$FpY7H!l;XBJHRP|1lBW9H36+{J<) zo}%6~ny_VMY>VyENUzy=oub|p;2jzzpoS$eTMt)zUFe#@u8?``JECLc#uxI8NIUVU zuGS@Y&h0Q87X`!k;}Vp8|5x;4MpT5v8TuvXb+3kUOEp=V5kU?{?D}vbiSs75VCf!> zk|`(mHwtN7vbX#3C>ePq_%Z#j7T;{lJ31_N$gWeH*-i+FGbx6Xjz=YS4OyBvs{MFi zabGSv;<=N-u@Rf`Xv{*LceeU#3W>I2l}4dI-v!>WNrJ>1D~z~Waw1MUyQMod5C0+$GCK~+sV?VJDO^ITuLI@^FK##z5GJllW7?`u^ zY5UdZ!-|H^Cd0dxUw0AdNuPO0qQrAR+y#o|4seit%^UIza;5KVbd_6eCZVvMTgdYe zs;$0=S`@Uk{4+|aMF%Ag)8M4aF^40<7%41uv{gQQpWRR$+?hZH%z*d1G($+|#p~mi zS#tn$$nZ3Eg8Etzy{4iyX97CzNiQHqB-1}AW?%C5c?^522XdV^se|O%dNh#Kq9t*m zlku}d+b5zHLsxM|#w-eHzM{Gdud6>dG|em(|F3S%!L=EnCuO)3eKFo?`ksKCX>=~; zZa^)YB!(PIU3s@WXx1;kWcBPwMn#rKUM#`=m6#Q(pMtYr=*VR@yON)t5@K+RxsxtH z3?;_MaHcby2xVp)?TB&`S&ZONhzr*y!@3Gz4`x4I7B zsN*ExTvgBZNF*4z>4HD3fR38{+sy_EbiN97+`fE&eWy+6_-{KHsm(?ur}ocw;*hY; zYUr8fKJrUh!(z1AAlzPRYQHh`@5Q5&Z$MV28 z3EkGXUY#vqdnDWY!4nW5V=6ionek)0i_cyobtwC>X^K(*K zEcI}Y!1WhC*GbK*AmOWwM=dro0uI(lbzU5L9hqI!-bkuc^CO_!5p@+-5zLlwY8>zC z0^t#9CndPAyYTl1%G~mWFy+8mg%!R1I!|R>PKv0!2v{6WZN9`+NFIt*NBAAX;VLLHqHwRlFN?dar z-54gj{T4gUhd(@YOdsA`FP_O7vDVz7*v+W)E^jp zj%wzep|(YiTs!UU>;=!!70}D?c6{d9RmDv&Wc73M@#gES>E&z5EC9AS7N_x3YQi2w zjOrKaz+K@N2`}dC_(Di6E@TUOuLLquhCVqoP)NtnPFE*I4+!Z<4Y(UW2tcM<`&xE2 z0|&+AYOfBKSPQVw75Hcm8>c1=^&Zs!?)beQO)#dBQ;z@^Bvr;2FJ8&&7jBf6(hTTC zp(F|M#o`wswFGPKjggmU%PVz+#c1dXV3?%n(RWny>0CU`cr|71Fkk^Zp@CjUYHdS9 zd?2g}I7O|+7w2+)%nDgE2e60iS&u9~X?s0quf|R;OoNT<2+29HlF(Y_ok=A#b9p&u7)Z1J*))uJL?_5MwQ#!sWgk`9`DS49ZUvy^#Jg`C1_O%2{q!D=5mINa+~9G8;Q!*-c+}^ z@P$BN;z-%UW8lyJpCX>ANmOOU!EZhEdN0J7J?`&Z)zp0`q#3)uX&|DAeGU=~^!`k1 ze5;N?L?&2c{$HV=?z_8qYBg=Gz@J|e0y*_B9rsyOm|G`mqO{d1P>si2Pl4P9UK^iOo5g+VZ*NZYwls>@!C)Nwx4~1MhB?Z&$(5FcVmxr z`Jth`+-X63Tsl4*^|H9$DcAV2EZUFt9^m~_aS-L)tH@s zN$C_3-H%z(cvaU4q8(+Y>;_oa5II>EYII|>M6Ms4SRHhyma8sB$q zx@m8BNOD&xq_xNS0y^5Hplj+&kqfP9Wa|nyeq$ju#dG6wZ~zYwCQR$ zlUjMlJ2u@Xilv==A&BbjD~EP4bNrql4K_H`0-(KCy{?&lD3o_xp>tmV%Yawi!tU$M z0GI{aWB90=5h^2dF74!}i9piPf5H!PDS9h9MwqmJg}oREazZ56)cOP3A3zb3nU z?Hj@Do{^t%*u=D0dG11r!p5dg$cCt zP>(Nrt`3#xH{B>v-?adE*RyQBN~{vy*8*_kqHv?{Y>vk!}p%ZZ%q85qy4c99^kbVdO=m+e%PVs=$aB33A*{%pj(a} zh%#+BJlG_WoP-q8bWM*W#Mn{8zwrYzlS8eU!a$tTu% z@ym7@coQD{g40S?7k_Zun{dGB(EHJ6g7c;FEobxSa5D zG{*bZSnDmW{gJ=VyKqc15S6#MIkq`1=5o{tKo})@f7srG)DMe_1N43K*kjk$*_Jsg zZRKl$_v!w!d1Z{@d#S-U)^{W8*j-dS_c!1!g1kYPH$xMBKW!AqsATym%oG2MwI=i2 zLYVbtZq^8bh#uR(%RBoqIS{PI1d}LJdmQt=PT|l=>?@z%+J4#QhfSZsD zru7P=CwBbYkNDPlE{sGk{&>jZthnDQ3_Y!QF?*zXuYW1I7yZTmtBJAUHC9q={@{W$ zK~6O2d9ZE7+gXsEA_7DGCY-WMkHml4Ze#4jZy#RU4;0eelWHBV57v2(ItnFJv4JQ9 z;fhx_1=RI)<8VDC^mt!&<&7U-e7j%0LD5&kX$ELkZ%+QUFO@7p;=sX-0(8nQn?B|W zvQnz)5LghG8z}cRmO7@_Kb^I+;M9{jspOp!)nor(H)!Re;V0I?@!F%p!;vs;VYoUa zdP!(PzTI!D$|vQ>x8Aft{wMFEIce8&>^3YvyMh?02y*aX&eF!cFDzKb8YJD%2XlT+ zF%kx2mxO+{ zQu+W0>8&otZtGeeIqq0)S7Y>XN<7y}wEWRQnQ#T(kiibt*g+tMlXRh*aOQKaFJU-{ z#B(JMEOp8yV>|ND<|kGISK8ozJOr`aiW1)ymF)G{LT@~k5i0;AiY zO(m}W#l?Z16x>3?osg?6W&o9(7G*0;*!!7&X2zKBgVfMUph_>`JAf=nsp4V=M?*yP z3Zmi5fenVy|N8bM6Xy=_O&}HEYQKH*~5@m%*Q+9y3)h?(UgQe7R z*m?lprMDoAeO1xxj;ZTa8VTl!egBCtXcAW$V}z#e&V^$n=+H~T_t4RuS6@)T%@gxy zQNEoL!Fic6!v}nBy6b<^PQo!2#ONiz#w-w=3`C5u@f3Ry%FEl7+uFwF%sHWuW`r2KcgyVdPPL?VnjRw%YVQz%!Cp2&!9DOVuam zeT3N(1B98IN-weFh@%fLTv-j1PwA*RM;{J_RGMx^+ISp zkOX{-JxS-2@sc1%191f~?&I+@0g*Znwey{KEKk?I&(ucN|dTtj6-0e z+oTNk@s@D!PGFhbOl#pP0$NOuJ-bV$dzU&n_XzpV)WA+q%Dw-Fv!4Y zteW0S>Rn&V64N%#EiSTD4Ye`WG14$2SI<|!xTXxYK0`{_g~hVIM?qaGF?SFqLsV}AHVmGlcGjQ6M#@gwj=hjweFy^)vL&3-Ob!09V|7%l&r{(=Zh3U zk#-&UGS{`jvmY7!tUQE)Ylc*i>((aKlRAf5=+=sbR1~Q9xXzPwCWKAVBlCNb_6)lu zC-HWtfPkRlv@4ET%HXz#QC}E+bP2{t7^gV^6>IG9G?bu_&U<8!n3+-|VPe82e#vDH zupKRMDM*G-u41`eP)Mgb^?1LafiUE0ii2C>zybBNI~_N>qc! zlo#zYVfYK6c_5AshnKvM*^GdHju1*fjsHp|-VS}Ij#K;~g-sFGxME=e-i)-JHyvqRz7VBXCXa*~yJ4{=c;KG&!BXw1nXd&X z_)wRCyTHS6pf!;f^k34|(;CX!dS4QvmtYvUa3pSaW|CcDfO}>Z!iwJ(UKTpEe?j3u z2Sezd7zz{M>+d|%@-oRrg;9u^y5d$>5-#?N?o5?b%BDRq*9G0~1Pf*Mv15&5{C3u8 zRe&F(oMl5e+k4c~3WxBb02M9ZbBPgl=*(TK9wxX42dP*>l%u`UV*Ee6-#=>6f|-*+ zNqIyg!}R{cYmSWt?~-;cGn9;;=RA;`V+~9oj_!m~kCdYGE;!j-Pp2ag=on=G5Wi>S zKvQBd1%}dif|4#(C6Q_YNBB%JL{1pmx>D6gl>(4tz7US4jRfatqVy3u)FlcVQ7 zhtWSo{0Jmp6!2q>b0*e%dI%U$S4c~2-JHHHwOGlre7F-Z;JFtYrh0(ScuxC&ck{e# zWEZ`@g6^xxUxXbEMBN2(>U%x@xZ4=InOX&6PM1|vfF^KK(#L5v| z9jUkP$w27+#S;FP1Kq(5iXN^0e*;iAgu1@oMp)b&*~ZNb?X5o3SuZC&t; zNVL60Igih!h!Htr0joFJj$bbJn;ua%{8-ynun7_Eqn<~%@i8)$c^b1szm|xcM0}FC zSYb8vbA!r{Ynl!f+%EXkC!u;H`n?-v`|Il4<`^JpUOsK#7An-os^MEws!iu$kTQTz zO!qu;RHm>y`9(|y@4A7RFHUBAeV4qq<)6K6l-le^K5mN4)$FT8<8@)%%j!4nn5tms zo>8e0c}E~=3_OSpgxK_i^47s(6b;i4zTJD)C`+b4k4oVyTZK$Gey?Ge^?@htQ8XTr zy&O(nxz5|``_3_)l9c@8z26I#Q?voc87S9Yda|NPQx(J;3?DYs>FKsB_PREb zj&*WByZB~1C#QWOJnAKT7mw1??6nr#>9rTdBZ?V0gkidxM?sXLe!_<$iv$;9{7 zp{#>3logF8Z71*OTKQ4%mRnM^e(%!7ruyX*e`h2d= zRR#sh5$m;dn}wbpje)N2`B}zSg~gy%G}nH=Lf33nO%W20vI<_M@nxof_qkI=8|+0v zH5WRR=n6HJN6FKEqf7I{G5E1{s4!7le2_;1{NujTQIg?)73G~E%LI)ue}(T;J<{ zpyv%R;thEdy`he#QK2+aEL#{S4e>NGAk!_YSBb@=qEDVgJS@;luv61DnUuWFimVvu zCA=EwkZwn6)kS+qE5HyC7Nlbvg1OjuzuqBPJp6PvU&{14JOoI}6rhPF3$M+Y<#;z8 zy*I>wB2Xf za}c3rX=f4k$K-Y0=H12R@39}%r;n+*AHjFpw~jx!^{aj+_Yi&wWaSxXP8R>prr0#_ zhDIEhvFN`T{~}KTIJEHa?_6yM9u-E+nFcGyv(TOM6Pde(;_}4e1mZYMinql34I@tv ziHFnFQwgYBsq*F*+M? z+4m~YcbB}17j73mdUGa5-ar0@%WLQ5RJ7Xd=2tQ~+B<(rIV#h#Uq$ltR=-t%Sn8p? za75j#T}4Ge6W7@P!m|@A8OUyUMayx`o<=M%MVf%gS+85)u3`4^u&rVP3u_z?b%OFA zsm@n51e21O$3!xyd^v-;_GUsS2_Y(+ zlEX2NiX}WKafTC2d(KxVVe>>LG@8Hlm`5ZG;~Mv@Mn6Yq>p5mSmS|r|iy6eZ^WYVX zzog>K+{@+Y629s*3H-E+!0E=+ThVWKA`D}N5ah&3rxV$~Er~-BeG&s1aw{S|X)>fc zIOGWrcto$uxOeLjd9T93h|G)qqZE{y%%oPd2nD8SJfNeGyPkigx!tkg{F<H>>%ug3x=#@&xszMZe!ewfCvc z)#K586K^W^mD?8#Z{xD+iq+ukj$f9?Y?d@O-NfIBajLT~A>A5EPB&g~Myy*tm1Wlc zn<9B8Ur~Wy7`Uq`W|PWg+{M8vgBQ^?8}Fze>2a!)qKR3IX$oEziKepd=y`b6R4$ul zIhGf3X^YX*p>H1O5AJ4JQwRE%HX^cB_bm(yg&2DDfEv$CJ88X7w-U;mAJzo*Z;s8Q z`R{|ti)XkO5?%C6iEaLTLSi_#7*GF%PFEP(V-EbOd5Uzgtw)g&LpyRkP6-$|{r4)S zG9~L$O~TpCGp7x(Lb2_sz8uueE9>p+U75@?Ck#fgK8godKZ=FobW9Xe}xWP)mR^xOtN%sjDHNu8J4Ukk@j3$(2iQ%{>d7GG?ac+9f(mOibm z(ASTAe4&Ila=;rmobid@xSeS%H2+{nwLek^M$p8T55Zw_B6lsl-oy>2opZ`A)&o2EM>!53tR#v+ zk#3H##pM)~k;_KVAU?uk(>gTN8a%`38iFr1A3CL=B=Bqd;6s}3iDu$+qg>v_-P>4F zJ)k9SQ8Em{B93ru)YkkRA*I|NwEm>TrBuc!S)Q=oTjs+~S`M(Y`8u}yScJCVLODKJ z;I;BL$$HlGq%GAeJ-tNeJrm$$8y_8!8+@NguWL+sszFo`s(Ug%>XOSZG60yhFVX<5B1wbt@e zZ|ijRvMKxE4o!dXr!@v_e`yu7+GC#U*oz;N|e$l6=(Zk|uw82#871!1e z(R&;_OYO0bt~)IiEgOcAIsVrN0wFE}_DXc;sEgssT6+JC+&xUM+auG*Bec~IT@s9^6IyH?jbHB1@P*X&i@k_@f&cu~j>k`-HT{K% ztHL6ajPbwnQUOY}7{zbGJ@3_$tRD&#r#Y-!2KiqQP&Q8TbB7R2%pP9Eo|%q2=%Y@) zpv3nIe5KK|$wAj)tKakNQ{_Rm_!UA`fLgTe2i%o*#Lu8Ta8;OMl~FTO3Rj}UZJ2Vy zI*3l#xMjY^c01QsU)=Kcrv0f#UGQc%siFQ4weDsde$M*9>=AZyEn%9<$b&;!pm#c1 ziIF-kW@%&w|Lpq_o9k6MOW#N*n2mUqqHP)Ed;Kp9<$Gcjsfxbwy8{m#|KM}qiFgW^ zaL#$F{Sh*8uAhqL`#egoK7g$eBG!GGl9D!2Dt(X3dJ=nvjVMy*R`znRAzS)r5H-cI zPkEHBQ-+v#=kWN`8}_&Vao5Df-R3+ex={4yt?%}g;K8i_tlCfQ^Dm8!mmnA=alse8 zJk9@DyQ|;0?~XIiTy4t#=_w>}NlL#iGN)E0g5x9CYVl=pFMC*I4}}qNYqF~rf~y_B zjz1dBHB$ZMcKrxIF^|Z(1)Fw`s|Oq`u0f_}rQ3{{RyWG*)Y3g#;KkxKpEqjAwY)Q_ z@~q%#x%yK0nry=FG#>x9!m3=el7r{jwLq9S8RI_#OvaEVRygm?`Pw7#?C0O0gR{;K zV0RR6z^Z;6MeosE9eEm;jT>2TLSGRqJTY-IpP(aRr#rCy%eFwG-3Fu|n|Uv+eZT!- zEcvqCUF$`*htlI;AVHma%~#jV!lPY@ww2rJymhs|$(p5c-phd||IZHS3dR6Ru1r_8 zY6*(Fw9^Kls66b3!M7P7dJtkxX$cm64Qh-|i!Ry5hp&A~Nad=GiRlFj-H#S;$moR* zsHB4~F;vn8RZuj0CMb#7hr6XKuiv@d*^{JlIGLB1%(ah|VwO_~XO$M5$0z}BPTbZe z8P8}XlDnGaK<~yMXUonh*kHj_NtBs*uq&UZ86;Qr`|yE%i%PmjLPl3ruU*N#@M_ad z#CFpd?A!6SZexc};Zk;@u4v~-N4Y0+#p*`<+4{Ue7LsoT|wZS=8Tv# z#uCc+k-DJ%aM*zS>`8u~Nhf*lx--Rs7W{vPPThKLj9o=g$C+>#e_Jtc6Z4&|Bui3gP^;{rn*@IwFJPX?WONncTxc;$8Oe5O$f!Wl-Nilv&jK zO=oq{TsIRcik8kXeOKg!Yj#oxj zxatqH&S`*q~ir^g#TscsxCTeYWS#XBFyyrz@JU6|;Zue)Uu;M5oh zBx1ingaV%OX%upr^iU3fzXWq7xp(na?{Tj1ssE96XVRfe7dFDL(o1b*mt=ax!QG!Y z>uU^a@v|PqjI5oQ2|D!)mkrh)%C0_l+n&Bs>@64>ik?`k^VR&|%8%aAl~h-l_hRX4 zIq|~?2+bNrh1NS!KUk~Z$0z6Z`8o0i&wI#Tzsc}F5_L}F)gS+&ul7sJVInMs>oc^V_o-EB5^xLAb6^oGO~Jlr97){xsJij^ zv=IZt8JLvtw$G39`x54gy*CcZDvzA*#2dzy1|+pAZ2!*UE?;}yjWdf|#6KIFnWXj+ zcj|mM)W%m8H9glJJryd;NyH_>#1z9*zc}i5R<~U|Kb@Zc7uuirmAXw;p@SX+U!P`( z1y#N>V^_b7mf@qWI0Ot|HW>zukU|l+9J?r*{<9{zJ2BOv0OY)9wr1}6F9U z>LLkRj-@;ckmNyCBQy$os2ob4ZjgxkZ!#lq^Mz~-@L{NtQZOO#5n?8$apIZxs7lJL z>8KQ@>ghlwcCiEgT^&=iH9B3x%j&oEPrFZTC~9nSev zK$|?FaJU`G|I#S1vAL(~=O*K80aVmVrZ`}54`lQh*MG;9X{!&GE$WG=sFb`aoyjc> z5nMdqohYoVR7EY9IECVPQrid2a z-xJZG=J6)}3yK&i!4zZbudbE^Ld(igfx^UASPjMgEY5g@6WdTr)ICW{Uf}@Mlo^;1 zgq69SUD%1bqa>0!4;qCM62*dgfk;|ZDvAz`fm;BA1N=$Krh(DtKI0Ip2Why5OXeTA z7`%dm;n?R|1ws|d6vud0-Y7q|y)chTB3-U~B%Z(jK~Dyn4sYUyLSb3%B_%7?Rc|RJ zdsd_%mvFDlniXf9&J=d710W`H6Aq673G4mCt#_)lot#(M)IG6-;8X~g<4?`Z;Da?% z&3?^4g>B09Fa$81z9qZIeDlWWOrVT(@$hO}SVFZxg8obesvmAoKkq1`_NjBuiJaT$ z)?jkY;;CIBE@M}sp$9L|I`p0fCaXsdu}^@r;Uf@!1wM$2|K%Ad|8in1M7j6=o&Ul! z&{0QYy?_Q>NQQ>3ow#yhCl9ljesA9V*<`2%QB9;T)pk9|x`N}@);v9Phx<8{UGtjzq4ru_$_A70fheeP~i@36yZLZ#Fw zY9ERc=WOY)Z3+#iH;!Jp=#oCG`G&>SY?SFxW8grnKt=(DrjV+ZRYY#*)Bbm`HViIO zlqQ{q4G@ejp*VL@sKfxMtHuP?2pdeomoGb0%K9<(Gbmb2HD}tc|DzoakK}yNbPp|calDmB1h6mvQ-MF6ndhw z%o?_o7{fEj7d)V(Fv)Cs{0v?QcE)P6u<*J0_`Ks*!JdLGnG8lrBnYBP!IuQLVN$Lz zB+iD72sxxSx0bxVl=HX-h;W|JSL<-(RhQ?Q1Qg_2%?fpxPn}6JGj+ zRT+QWk|J$!rH+-q46AB}O%|WUo&kF$Nd*WM03m{#9kuZC){Eg!sfrlIfwoVGYrEKV z-r7gN**;wI`~DLDT=+a4#owb8wq!J6D{nyCm9w`!WnpAOL^5VZK-L25XRxrN5_mm& zEdajKo|B_Vt+oY8CZG8CoGci?8kW7ELccxnrtv3yXm0pRj$VRC@uB*0&uK6{0-2%B ztY3JcLSw@)NK~Au!;2q`;CIU``X=VG))k?OrOHc?lSCRtWmUiBW|eOH-4T;BiGbg` zt)YL`s@=@vet|dMDw0g&em2+qYY(84G5h)_dm!dOwtPQDq*=p6oGO-z&m$Qx8&xLo TkfacmiVIMDs|u}zn1=p;kP=3u literal 0 HcmV?d00001 diff --git a/skills/explain-pr-as-video/assets/pele.LICENSE b/skills/explain-pr-as-video/assets/pele.LICENSE new file mode 100644 index 0000000..fd6f9c8 --- /dev/null +++ b/skills/explain-pr-as-video/assets/pele.LICENSE @@ -0,0 +1,40 @@ +MIT License + +Copyright (c) 2026 kepano + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +--- + +The reset icon of the zoom controls is "rotate-ccw" from Lucide v1.14.0 +(https://lucide.dev), under the ISC License: + +Copyright (c) 2026 Lucide Icons and Contributors + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/skills/explain-pr-as-video/assets/pele.js b/skills/explain-pr-as-video/assets/pele.js new file mode 100644 index 0000000..d35f91e --- /dev/null +++ b/skills/explain-pr-as-video/assets/pele.js @@ -0,0 +1,150 @@ +/*! Pele 1.13.0 | MIT License | https://github.com/obsidianmd/pele */ +"use strict";var pele=(()=>{var ja=Object.defineProperty;var J1=Object.getOwnPropertyDescriptor;var ew=Object.getOwnPropertyNames;var tw=Object.prototype.hasOwnProperty;var nw=(e,t,n)=>t in e?ja(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var rw=(e,t)=>{for(var n in t)ja(e,n,{get:t[n],enumerable:!0})},sw=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ew(t))!tw.call(e,i)&&i!==n&&ja(e,i,{get:()=>t[i],enumerable:!(r=J1(t,i))||r.enumerable});return e};var iw=e=>sw(ja({},"__esModule",{value:!0}),e);var fe=(e,t,n)=>nw(e,typeof t!="symbol"?t+"":t,n);var OL={};rw(OL,{PeleError:()=>Qe,detectType:()=>Um,enableZoom:()=>Dm,forgetTextWidths:()=>nc,mount:()=>O_,parse:()=>Gm,register:()=>wu,registered:()=>M_,render:()=>Ym,supports:()=>L_});var ow=[["flowchart","flowchart-elk",/^\s*flowchart-elk/],["mindmap","mindmap",/^\s*mindmap/],["architecture","architecture",/^\s*architecture/],["agentflow","agentflow",/^\s*agentflow-beta\b/],["c4","c4",/^\s*(?:C4Context|C4Container|C4Component|C4Dynamic|C4Deployment)/],["kanban","kanban",/^\s*kanban/],["class","classDiagram",/^\s*classDiagram/],["er","er",/^\s*erDiagram/],["gantt","gantt",/^\s*gantt/],["info","info",/^\s*info/],["pie","pie",/^\s*pie/],["requirement","requirement",/^\s*requirement(Diagram)?/],["sequence","sequence",/^\s*sequenceDiagram/],["swimlane","swimlane",/^\s*swimlane-beta\b/],["flowchart","flowchart-v2",/^\s*(graph|flowchart)/],["timeline","timeline",/^\s*timeline/],["gitGraph","gitGraph",/^\s*gitGraph/],["state","stateDiagram",/^\s*stateDiagram/],["journey","journey",/^\s*journey/],["quadrantChart","quadrantChart",/^\s*quadrantChart/],["sankey","sankey",/^\s*sankey(-beta)?/],["packet","packet",/^\s*packet(-beta)?/],["xychart","xychart",/^\s*xychart(-beta)?/],["block","block",/^\s*block(-beta)?/],["eventmodeling","eventmodeling",/^\s*eventmodeling/],["treeView","treeView",/^\s*treeView-beta/],["radar","radar",/^\s*radar-beta/],["ishikawa","ishikawa",/^\s*ishikawa(-beta)?\b/i],["treemap","treemap",/^\s*treemap/],["railroad","railroad",/^\s*railroad-beta/i],["railroad","railroadEbnf",/^\s*railroad-ebnf-beta/i],["railroad","railroadAbnf",/^\s*railroad-abnf-beta/i],["railroad","railroadPeg",/^\s*railroad-peg-beta/i],["venn","venn",/^\s*venn-beta/],["wardley","wardley",/^\s*wardley-beta/i],["cynefin","cynefin",/^\s*cynefin-beta(?:[\s:]|$)/],["usecase","usecase",/^\s*usecase-beta(?:\s|$)/]];function nu(e){for(let[t,n,r]of ow)if(r.test(e))return{type:t,mermaidType:n};return null}var Qe=class extends Error{constructor(n,r="syntax",i={}){super(n);fe(this,"code");fe(this,"type");fe(this,"mermaidType");fe(this,"line");fe(this,"column");fe(this,"snippet");this.name="PeleError",this.code=r,this.type=i.type??null,this.mermaidType=i.mermaidType??null,this.line=i.line??0,this.column=i.column??0,this.snippet=i.snippet??""}};function ds(e,t,n){return Array.from(e.matchAll(t),r=>[r.index,r.index+r[0].length,n])}function aw(e,t){let n=0;for(let[r,i,s]of e){let a=r-n;if(t=0;n--)t=aw(e[n],t);return t}var Ri;function em(e,t){let n=Ri;Ri=e;try{return t()}finally{Ri=n}}function ls(e,t){return Ri!==void 0&&e===Ri.parsed?Ri.find(t):[e,t]}function cr(e,t){let n=e.trimEnd().length;n>0&&t>=n?([e,t]=ls(e,n-1),t++):[e,t]=ls(e,t);let r=1,i=0;for(let c=e.indexOf(` +`);c!==-1&&c0&&e<=1114111&&(e<55296||e>57343)?String.fromCodePoint(e):t}var dw=/&(?:#(\d+)|#[xX]([0-9a-fA-F]+)|(\w+));/g,nm="fl°",rm="¶ß";function uw(e){let t="",n=0,r=e.indexOf(nm);for(;r!==-1;){let i=e.indexOf("¶",r+2);if(i===-1)break;if(e[i+1]==="ß"){let s=e[r+2]==="°";t+=e.slice(n,r)+(s?"&#":"&")+e.slice(r+(s?3:2),i)+";",n=i+2}r=e.indexOf(nm,i+1)}return n===0?e:t+e.slice(n)}var fw=/fl°°?(\w+)¶ß/g;function xo(e){return e.includes(rm)?e.replace(fw,"#$1;"):e}function bt(e){return e.includes(rm)&&(e=uw(e)),e.includes("&")&&(e=e.replace(dw,(t,n,r,i)=>n?tm(Number(n),t):r?tm(parseInt(r,16),t):lw(i)??t)),e}var Ao,So=new Map;function sm(e,t){let n=Ao,r=So;Ao=e,So=new Map;try{return t()}finally{Ao=n,So=r}}function Ti(e){if(Ao===void 0)return"";let t=So.get(e);return t===void 0&&(t=Ao(e)??"",So.set(e,t)),t}var wr,Mi=new Map;function om(e,t){let n=wr,r=Mi;wr=e,Mi=new Map;try{return t()}finally{wr=n,Mi=r}}function am(){return wr!==void 0}function im(e){return Number.isFinite(e)&&e>0}function cm(e,t){if(wr===void 0)return;let n=t+` +`+e;if(Mi.has(n))return Mi.get(n);let r=wr(e,t)??void 0,i=r&&im(r.width)&&im(r.height)&&typeof("svg"in r?r.svg:r.html)=="string"?r:void 0;return Mi.set(n,i),i}function lm(e){if(wr===void 0)return e();let t=wr;wr=void 0;try{return e()}finally{wr=t}}var us=class{constructor(t){fe(this,"message",t)}},fm=64;function qa(e,t,n){t==="__proto__"?Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0}):e[t]=n}var iu=class{constructor(t){fe(this,"lines");fe(this,"i",0);this.lines=(t.includes("\r")?t.replace(/\r\n?/g,` +`):t).split(` +`)}skipBlank(){for(;this.i'"%@`]/;function wo(e){return e===" "||e===" "||e===` +`||e==="\r"}function ru(e){let t=e[0],n,r;if(t==='"'||t==="'"){let s=1;for(;;){if(s>=e.length)return null;let a=e[s];if(t==='"'&&a==="\\")s+=2;else if(a===t){if(t==='"'||e[s+1]!=="'")break;s+=2}else s++}for(n=s+1,r=n;wo(e[r]);)r++;if(e[r]!==":")return null}else{if(t===void 0||yw.test(t)||t==="-"&&(e.length<2||wo(e[1])||e[1]===":"||e[1]==="#"))return null;for(r=1;r"9"))return t;if(hw.test(t)||bw.test(t))return Number(t);if(pw.test(t)||mw.test(t)||gw.test(t)){let r=t[0]==="-",i=Number(r||t[0]==="+"?t.slice(1):t);return r?-i:i}return/^[-+]?\.(?:inf|Inf|INF)$/.test(t)?t[0]==="-"?-1/0:1/0:/^\.(?:nan|NaN|NAN)$/.test(t)?NaN:t}var dm={0:"\0",a:"\x07",b:"\b",t:" ",n:` +`,v:"\v",f:"\f",r:"\r",e:"\x1B"," ":" ",'"':'"',"/":"/","\\":"\\",N:"…",_:" ",L:"\u2028",P:"\u2029"};function _o(e){if(!e.includes(` +`))return e;let t=e.split(` +`),n=t.length-1;for(let r=0;r<=n;r++){let i=t[r],s=0,a=i.length;if(r>0)for(;ss&&(i.charCodeAt(a-1)===32||i.charCodeAt(a-1)===9);)a--;t[r]=i.slice(s,a)}return t.join(` +`).replace(/\n+/g,r=>r.length===1?" ":` +`.repeat(r.length-1))}function Ew(e){if(!e.includes("\\"))return _o(e);let t="",n=_o(e.replace(/\\\n[ \t]*/g,""));for(let r=0;rfm)throw new Error("YAML: nesting is too deep");t=Ws(e,t,!1);let i=e[t];if(i==="{"){let a={};t++;let o=!0;for(;;){if(t=Ws(e,t,!1),t>=e.length)throw new us("YAML: unexpected end of the stream within a flow collection");if(e[t]==="}")return[a,t+1];um(e[t],o);let c;[c,t]=Ci(e,t,":,}",r+1),t=Ws(e,t,!1);let l=null;e[t]===":"&&([l,t]=Ci(e,t+1,",}",r+1)),qa(a,String(c),l),t=Ws(e,t,!1),o=e[t]===",",o&&t++}}if(i==="["){let a=[];t++;let o=!0;for(;;){if(t=Ws(e,t,!1),t>=e.length)throw new us("YAML: unexpected end of the stream within a flow collection");if(e[t]==="]")return[a,t+1];um(e[t],o);let c;[c,t]=Ci(e,t,",]",r+1),a.push(c),t=Ws(e,t,!1),o=e[t]===",",o&&t++}}if(i==='"'){let a=t+1;for(;a=e.length)throw new us("YAML: unexpected end of the stream within a double quoted scalar");return[Ew(e.slice(t+1,a)),a+1]}if(i==="'"){let a=t+1;for(;a=e.length)throw new us("YAML: unexpected end of the stream within a single quoted scalar");return[_o(e.slice(t+1,a)).replace(/''/g,"'"),a+1]}let s=t;for(;s=e.length||/[\s,[\]{}]/.test(e[s+1])))break;if(a==="#"&&s>t&&/\s/.test(e[s-1])){let o=e.indexOf(` +`,s);return[ou(_o(e.slice(t,s).trim())),o===-1?e.length:o]}s++}return[ou(_o(e.slice(t,s).trim())),s]}function Ro(e){let t="";for(let n=0;n",i=t.includes("-")?"-":t.includes("+")?"+":"",s=/[1-9]/.exec(t),a=s?n+Number(s[0]):-1,o=[];for(;e.i0&&o[o.length-1]==="";)o.pop(),c++;let l;if(r){l="";for(let u=0;u0){let d=o[u-1];h===""?l+=` +`:d!==""&&(l+=/^[ \t]/.test(d)||/^[ \t]/.test(h)?` +`:" ")}l+=h}}else l=o.join(` +`);return o.length===0?i==="+"?` +`.repeat(c):"":i==="-"?l:i==="+"?l+` +`.repeat(c+1):l+` +`}function su(e,t,n){let r=t[0];if((r==="|"||r===">")&&/^[|>][-+0-9]*\s*(?:#.*)?$/.test(t))return xw(e,t,n);if(r==="{"||r==="["||r==='"'||r==="'"){let s=e.i,a=t,o=0,c=1;for(;;)try{let[l,u]=Ci(a,0,""),h=0;for(let m=a.indexOf(` +`);m!==-1&&m=e.lines.length)throw new Error(l.message);let u=e.lines.slice(s+o,s+o+c);a+=` +`+u.join(` +`),o+=u.length,c*=2}}let i=Ro(t).trim();for(;e.i=e.lines.length||e.lines[o].length-e.lines[o].trimStart().length<=n)break;i+=` +`.repeat(o-e.i),e.i=o;continue}if(s.length-s.trimStart().length<=n)break;let a=Ro(s).trim();i+=(i.endsWith(` +`)?"":" ")+a,e.i++}return ou(i)}function Qa(e,t,n=0){if(n>fm)throw new Error("YAML: nesting is too deep");if(e.skipBlank(),e.i>=e.lines.length)return null;let r=e.indent();if(r=e.lines.length||e.indent()!==r));){let o=e.lines[e.i].slice(r);if(o!=="-"&&!o.startsWith("- "))break;let c=o.slice(1),l=c.length-c.trimStart().length+1,u=Ro(c).trim();u===""?(e.i++,a.push(Qa(e,r+1,n+1))):ru(u)!==null?(e.lines[e.i]=" ".repeat(r+l)+c.trimStart(),a.push(Qa(e,r+l,n+1))):(e.i++,a.push(su(e,c.trim(),r)))}return a}if(ru(i)===null)return e.i++,su(e,i.trim(),r-1);let s={};for(;e.i=e.lines.length));){let a=e.indent();if(ar)throw new Error("YAML: bad indentation of a mapping entry");let o=e.lines[e.i].slice(r),c=ru(o);if(!c)throw new Error("YAML: can not read a block mapping entry");let l=String(Ci(c.key,0,"")[0]),u=o.slice(c.length);if(e.i++,Ro(u).trim()==="")if(e.skipBlank(),e.ir||m&&h===r?Qa(e,m?r:r+1,n+1):null)}else qa(s,l,null);else qa(s,l,su(e,u.trim(),r))}return s}function lr(e){let t=e.trim();if(t[0]==="{"||t[0]==="[")try{let[i,s]=Ci(t,0,"");if(Ws(t,s,!1)===t.length)return i}catch(i){throw i instanceof us?new Error(i.message):i}let n=new iu(e),r=Qa(n,0);if(n.skipBlank(),n.i=9&&e<=13:e===160||e===5760||e>=8192&&e<=8202||e===8232||e===8233||e===8239||e===8287||e===12288||e===65279}function Xn(e){return e===32||e===9}function Us(e){return e===10||e===13||e===8232||e===8233}function xt(e){return e>=48&&e<=57}function Vr(e){return e>=65&&e<=90||e>=97&&e<=122}function Za(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function ot(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===95}var Aw=/^\s*%%(?!{)[^\n]+\n?/gm,Ni=/%{2}{\s*(?:(\w+)\s*:|(\w+))\s*(?:(\w+)|((?:(?!}%{2}).|\r?\n)*))?\s*(?:}%{2})?/gi,Sw=/<(\w+)([^>]*)>/g,ww=/="([^"]*)"/g,_w=new Set(["__proto__","constructor","prototype"]);function pm(e,t,n){return n?.push(ds(e,t,0)),e.replace(t,"")}function lu(e,t){e.includes("%%")&&(e=pm(e,Aw,t));let n=e.trimStart();return t?.push([[0,e.length-n.length,0]]),n}function du(e){return e.includes("\r")?e.replace(/\r\n?/g,` +`):e}function Ja(e){return e===` +`||e==="\r"}function au(e){return e!==void 0&&/\s/.test(e)}function Rw(e){let t=0;for(;t{if(!Ja(e[h])||!e.startsWith(i,h+1))return-1;let d=-1;for(let m=h+1+i.length;mr[0];h=e.lastIndexOf(a,h-1))if(s(h)!==-1){o=h;break}if(o===-1)return;let c=r[0];for(let h of r)h0?l-1:0;for(let h=e.indexOf(a,u);h!==-1&&h<=o;h=e.indexOf(a,h+1)){if(h"):-1;r>0&&(n=n.slice(0,r+1).replace(Sw,(c,l,u)=>"<"+l+u.replace(ww,"='$1'")+">")+n.slice(r+1));let i={},s,a=0,o=n.includes("---")?Rw(n):void 0;if(o){let c=o.indent?o.body.split(` +`).map(u=>u.startsWith(o.indent)?u.slice(o.indent.length):u).join(` +`):o.body,l;try{l=lr(c)}catch(u){throw new Qe(`Front matter is not valid YAML. ${u.message}`,"syntax")}if(jr(l)&&(l.title&&(s=String(l.title)),jr(l.config)&&ec(i,l.config),l.displayMode)){let u=jr(i.gantt)?i.gantt:i.gantt={};u.displayMode=String(l.displayMode)}for(let u=n.indexOf(` +`);u!==-1&&ul&&(r?.push([u,u+1,0]),s+=e.slice(a,u),a=u+1)}i=o>=e.length?-1:e.indexOf(t,o+1)}return a===0?e:s+e.slice(a)}function uu(e,t){if(!e.includes("#"))return e;e=hm(hm(e,"style",t),"classDef",t);let n=mm(t);return e.replace(Mw,(r,i)=>{let s=r.substring(1,r.length-1),a=(Cw.test(s)?"fl°°":"fl°")+s+"¶ß";return n?.push([i,i+r.length,a.length]),a})}var gm="7q7q9vfgfgopij5b9999atg87q997q7qfgfgfgfgfgfgfgfgfgfg7q7qg8g8g8fgs7ijijk2k2ijgzlmk27qdwijfgn5k2lmijlmk2ijgzk2ijq8ijijgz7q7q7qd1fg99fgfgdwfgfg7qfgfg6666dw66n5fgfgfgfg99dw7qfgdwk2dwdwdw9a789ag8",bm="7q99d6fgfgopk26m9999atg87q997q7qfgfgfgfgfgfgfgfgfgfg9999g8g8g8gzr3k2k2k2k2ijgzlmk27qfgk2gzn5k2lmijlmk2ijgzk2ijq8ijijgz997q99g8fg99fggzfggzfg99gzgz7q7qfg7qopgzgzgzgzatfg99gzfglmfgfgdwat7satg8";var xm=1.2;function ym(e){let t=new Uint16Array(95);for(let n=0;n<95;n++)t[n]=parseInt(e.substr(n*2,2),36);return t}var Nw,Iw;function kw(e){return e>=4352&&e<=4447||e>=11904&&e<=42191||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65072&&e<=65103||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=55296&&e<=56319}function $w(e){return e===173||e>=768&&e<=879||e>=8203&&e<=8207||e>=56320&&e<=57343||e>=65024&&e<=65039||e===65279}var Lw={width(e,t,n){let r=(n&4)!==0,i=n&24?t/xm:t,s=n&1?Iw??=ym(bm):Nw??=ym(gm),a=0;for(let o=0;o=Dw&&d.clear(),d.set(a,m))),m}}}var fu=new Map;function ct(e="sans-serif",t="monospace"){let n=e+` +`+t,r=fu.get(n);return r||(r=Pw(e,t)??Lw,fu.set(n,r)),r}function nc(){fu.clear()}var Fw=/[&<>"\x00-\x08\x0b\x0c\x0e-\x1f\x7f\ud800-\udfff\ufffe\uffff]/u,Bw=/[&<>"]|[\x00-\x08\x0b\x0c\x0e-\x1f\x7f\ud800-\udfff\ufffe\uffff]+/gu,Ww={"&":"&","<":"<",">":">",'"':"""},rc=/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f\ud800-\udfff\ufffe\uffff]/u;function rt(e){return Fw.test(e)?e.replace(Bw,t=>Ww[t]??""):e}function Ue(e){return rt(bt(e))}var hu=[];for(let e=0;e<100;e++)hu.push(e===0?"":e%10===0?"."+e/10:"."+(e<10?"0"+e:e));function f(e){let t=Math.round(e*100);if(t===0)return"0";if(t>0){if(t<1e11){let n=Math.floor(t/100);return n+hu[t-n*100]}}else if(t>-1e11){let n=-t,r=Math.floor(n/100);return"-"+r+hu[n-r*100]}return String(t/100)}function Ne(e,t,n,r,i){let s=e.lines;if(s.length===0)return"";let a=e.lineHeight,o=e.heights,c=e.size*.35,l=n-e.height/2,u=s.length===1&&s[0].length===1?s[0][0]:void 0;if(u&&u.icon===void 0&&u.math===void 0&&u.style===0)return`${rt(u.text)}`;let h=Xr(e),d=r,m;r=qn(r,h);let p="",y="";for(let E=0;E`}else if(v.icon!==void 0){let G=e.size*1.1,K=i?.(v.icon)??"";y+=`${K}`}else v.text!==""&&(p+=`${rt(v.text)}`);O+=v.width}}else{for(let O=0;O${rt(v.text)}`}b.length===0&&(p+=` `)}l+=S}return`${p}${y}`}var Uw=/ fill="([^"]*)"/,Gw=/ stroke="([^"]*)"/,Yw=/ style="([^"]*)"/,Hw=/(?:^|;)\s*fill:([^;]*)/,Kw=/(?:^|;)\s*opacity:([^;]*)/;function zw(e){let t=Yw.exec(e)?.[1]??"",n=(Hw.exec(t)?.[1]??Uw.exec(e)?.[1]??"").trim();if(n==="none")return{attrs:"",halo:Gw.exec(e)?.[1]??"none"};let r=Kw.exec(t)?.[1].trim();return{attrs:(n===""?"":` color="${n}"`)+(r?` opacity="${r}"`:"")}}function Vw(e,t,n,r){return"svg"in e?`${e.svg}`:`
${e.html}
`}var Am=' font-weight="var(--_w)"',Sm=' font-style="italic"',jw=' text-decoration="underline"',wm=' font-family="var(--_fm)"',Xw=' baseline-shift="sub" font-size="smaller"',qw=' baseline-shift="super" font-size="smaller"';function _r(e){return(e&1?Am:"")+(e&2?Sm:"")+(e&4?wm:"")+(e&32?jw:"")+(e&8?Xw:e&16?qw:"")}function Xr(e){let t=7,n=!1;for(let r of e.lines)for(let i of r)i.icon!==void 0||i.text===""||(t&=i.style,n=!0);return n?t:0}function qn(e,t){return e+(t&1&&!e.includes(' font-weight="')?Am:"")+(t&2&&!e.includes(' font-style="')?Sm:"")+(t&4&&!e.includes(' font-family="')?wm:"")}var _m=new Set("black blue blueviolet brown crimson darkblue darkcyan darkgreen darkmagenta darkolivegreen darkorchid darkred darkslateblue darkslategray darkviolet dimgray firebrick forestgreen green indigo maroon mediumblue mediumslateblue mediumvioletred midnightblue navy olive purple rebeccapurple royalblue saddlebrown seagreen sienna slateblue steelblue teal".split(" ")),Rm=new Set("aliceblue antiquewhite aqua aquamarine azure beige bisque blanchedalmond burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk cyan darkgoldenrod darkgray darkkhaki darkorange darksalmon darkseagreen darkturquoise deeppink deepskyblue dodgerblue floralwhite fuchsia gainsboro ghostwhite gold goldenrod gray greenyellow honeydew hotpink indianred ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightpink lightsalmon lightseagreen lightskyblue lightslategray lightsteelblue lightyellow lime limegreen linen magenta mediumaquamarine mediumorchid mediumpurple mediumseagreen mediumspringgreen mediumturquoise mintcream mistyrose moccasin navajowhite oldlace olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue red rosybrown salmon sandybrown seashell silver skyblue slategray snow springgreen tan thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen".split(" ")),sc="var(--pele-fg-on-light,#1f1f1f)",ic="var(--pele-fg-on-dark,#fff)",mu=/[";]fill:([^;"]*)/,Qw=/[";](?:fill-)?opacity:([^;"]*)/g,Tm=/^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i,Zw=/^(rgba?|hsla?)\(([^()]*)\)$/i,Mm=/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?(%|deg|grad|rad|turn)?$/i,pu=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,gu=(e,t,n)=>.2126*pu(e)+.7152*pu(t)+.0722*pu(n),Jw=e=>Math.min(Math.max(e,0),1),e_=Math.sqrt(1.05*(gu(31/255,31/255,31/255)+.05))-.05;function Mo(e,t){let n=Mm.exec(e);return!n||n[1]&&n[1]!=="%"?NaN:Jw(parseFloat(e)/(n[1]?100:t))}function t_(e){let t=Mm.exec(e);if(!t||t[1]==="%")return NaN;let n=t[1]?.toLowerCase(),r=parseFloat(e);return n==="turn"?r*360:n==="rad"?r*180/Math.PI:n==="grad"?r*.9:r}function n_(e,t){let n=e.includes(","),[r,i,s]=n?[e]:e.split("/");if(s!==void 0)return;let a=r.trim().split(n?/\s*,\s*/:/\s+/);if(n?a.length<3||a.length>4:a.length!==3)return;if(i!==void 0&&a.push(i.trim()),!n)return a.map(c=>c==="none"?"0":c);let o=a.slice(t?1:0,3).filter(c=>c.endsWith("%")).length;return o===(t?2:3)||!t&&o===0?a:void 0}function Cm(e){let t=e.trim().toLowerCase(),n=t.replace("grey","gray");return Tm.test(t)||_m.has(n)||Rm.has(n)||t==="transparent"||t==="currentcolor"}function Nm(e){let t=e.trim().toLowerCase(),n=t.replace("grey","gray");if(_m.has(n))return[0,1];if(Rm.has(n))return[1,1];if(Tm.test(t)){let l=t.length<6?t.slice(1).replace(/./g,"$&$&"):t.slice(1),u=h=>parseInt(l.slice(2*h,2*h+2),16)/255;return[gu(u(0),u(1),u(2)),l.length===8?u(3):1]}let r=Zw.exec(t),i=r?.[1].startsWith("hsl")??!1,s=r&&n_(r[2],i);if(!s)return;let a=s.length===4?Mo(s[3],1):1,o;if(!i)o=s.slice(0,3).map(l=>Mo(l,255));else{let l=(t_(s[0])%360+360)%360/30,u=Mo(s[1],100),h=Mo(s[2],100),d=u*Math.min(h,1-h);o=[0,8,4].map(m=>{let p=(m+l)%12;return h-d*Math.max(-1,Math.min(p-3,9-p,1))})}let c=gu(o[0],o[1],o[2]);return Number.isNaN(c+a)?void 0:[c,a]}function Im(e){let t=1;for(let[,n]of e.matchAll(Qw))t*=Mo(n.trim(),1);return t}var To=new Map;function dr(e,t=""){let n=`${e}\0${t}`;if(To.has(n))return To.get(n);To.size>1e3&&To.clear();let r=r_(e,t);return To.set(n,r),r}function r_(e,t){let n=mu.exec(e),r=n&&!mu.test(t)?Nm(n[1]):void 0;if(r&&r[1]*Im(e)>=.5)return r[0]>e_?sc:ic}function Mn(e){let t=mu.exec(e)?.[1].trim().toLowerCase();if(!t||t==="none"||t==="transparent")return!1;let n=Im(e);return(Nm(t)?.[1]??1)*(Number.isNaN(n)?1:n)>0}function vt(e,t){let n=dr(e.shape,e.text)??t;return n?` fill="${n}"`:""}var s_={pie:{prefix:"pie",first:1},gitGraph:{prefix:"git",first:0},timeline:{prefix:"cScale",first:0},radar:{prefix:"cScale",first:0},treemap:{prefix:"cScale",first:0},mindmap:{prefix:"cScale",first:1},venn:{prefix:"venn",first:1,repeat:!0}},Co=8,i_=/^[\w\s#%.,+\-/()]{1,200}$/,o_=/([\w-]*)\s*\(/g,a_=/var\(\s*([\w-]*)/gi,c_=new Set(["rgb","rgba","hsl","hsla","hwb","lab","lch","oklab","oklch","color","color-mix","light-dark","var"]),km=e=>jr(e)?e:{};function l_(e){if(typeof e!="string")return;let t=e.trim();if(!i_.test(t))return;if(!t.includes("("))return Cm(t)?t:void 0;let n=0;for(let r of t)if(r==="(")n++;else if(r===")"&&--n<0)return;if(n===0){for(let[,r]of t.matchAll(o_))if(!c_.has(r.toLowerCase()))return;for(let[,r]of t.matchAll(a_))if(!r.startsWith("--pele-"))return;return t}}function d_(e){let t=[],n=0,r=0;for(let i=0;ii.trim())}function u_(e,t){if(e==="xychart"){let i=km(t.xyChart).plotColorPalette;return typeof i=="string"?{list:d_(i),repeat:!0}:void 0}let n=s_[e];if(n===void 0)return;let r=[];for(let i=0;ii!=null&&i!=="")),{list:r,repeat:n.repeat===!0}}var bu={style:"",inks:[]};function $m(e,t){let n=u_(e,km(t.themeVariables));if(n===void 0||n.list.length===0)return bu;let{list:r,repeat:i}=n,s="",a=[];for(let o=0;o=r.length);o++){let c=l_(r[o%r.length]);c!==void 0&&(s+=`;--pele-series-${o+1}:${c}`,a[o]=dr(`;fill:${c}`))}return s===""?bu:{style:rt(s),inks:a}}var No=bu;function Lm(e,t){let n=No;No=e;try{return t()}finally{No=n}}var Om=()=>No.style;function fs(e){let t=No.inks[(e%Co+Co)%Co];return t?` fill="${t}"`:""}function Gs(e){return e.ownerDocument?.defaultView??globalThis}function yu(e,t){let n=e.clientWidth-(parseFloat(t.paddingLeft)||0)-(parseFloat(t.paddingRight)||0);return n>0?n:0}function f_(e,t,n,r,i){let s=t.width/n,a=t.height/n,o=(c,l,u)=>l>=u?Math.min(Math.max(c,u-l),0):Math.min(Math.max(c,0),u-l);return{x:o(r,s,e.width),y:o(i,a,e.height),width:s,height:a}}var Ii=1.25,oc=48,h_=4,p_="--_bg:var(--pele-bg,#fff);--_fg:var(--pele-fg,#1f1f1f);--_b:var(--pele-border,#8a8a8a);position:absolute;top:var(--pele-zoom-top,8px);right:var(--pele-zoom-right,8px);bottom:var(--pele-zoom-bottom,auto);left:var(--pele-zoom-left,auto);display:flex;flex-direction:column;gap:2px;padding:2px;width:auto;max-width:none;border:1px solid var(--_b);border-radius:var(--pele-radius,4px);background:var(--_bg);color:var(--_fg);line-height:0",m_="appearance:none;display:grid;place-items:center;width:24px;height:24px;margin:0;padding:0;border:0;border-radius:calc(var(--pele-radius,4px) - 1px);background:transparent;color:inherit;font:inherit;cursor:var(--pele-zoom-cursor,pointer)",g_={zoomIn:"M5 12h14M12 5v14",zoomOut:"M5 12h14",reset:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8M3 3v5h5"},b_={zoomIn:"Zoom in",zoomOut:"Zoom out",reset:"Reset zoom"};function Dm(e,t={}){return Eu(e,t,!0)}function Eu(e,t,n){let r=null,i={width:0,height:0},s={width:0,height:0},a={width:0,height:0},o=!1,c="",l={width:"",height:"",maxWidth:"",margin:"",display:""},u=null,h=0,d=0,m=0,p=0,y=()=>Gs(e),E=()=>i.width>0&&s.width>0?s.width/i.width:1,b=()=>Math.max(E(),t.maxScale??3),S=()=>r!==null&&i.width>0&&(t.always===!0||E()<.999),x=()=>{if(!r||h!==0)return;let ce=r.getBoundingClientRect();s={width:ce.width,height:ce.height},a={width:Math.max(s.width,e.clientWidth),height:Math.max(s.height,e.clientHeight)},o=a.width>s.width+1||a.height>s.height+1,o||(a=s);let pe=y().getComputedStyle(e);c=["Top","Right","Bottom","Left"].map(V=>`${-(parseFloat(pe.getPropertyValue(`padding-${V.toLowerCase()}`))||0)}px`).join(" ")},I,L={},O=!1,v=()=>{if(t.controls===!1)return;let ce=S();if(!I){if(!ce)return;let V=e.ownerDocument;I=V.createElement("div"),I.className="pele pele-zoom",I.setAttribute("style",p_);let X={zoomIn:()=>H((h||E())*Ii*Ii),zoomOut:()=>H((h||E())/(Ii*Ii)),reset:()=>C()};for(let le of["zoomIn","zoomOut","reset"]){let de=V.createElement("button"),Se=t.labels?.[le]??b_[le];de.type="button",de.className=`pele-zoom-${le==="zoomIn"?"in":le==="zoomOut"?"out":"reset"}`,de.setAttribute("style",m_),de.setAttribute("aria-label",Se),de.title=Se,de.innerHTML=``,de.addEventListener("click",X[le]),L[le]=de,I.append(de)}}ce&&!O&&y().getComputedStyle(e).position==="static"&&(e.style.position="relative",O=!0),ce&&I.parentNode!==e&&e.append(I),I.hidden=!ce,I.style.display=ce?"flex":"none";let pe=(V,X)=>{V&&(V.disabled=X,V.style.opacity=X?"0.35":"",V.style.cursor=X?"default":"var(--pele-zoom-cursor,pointer)")};pe(L.zoomIn,(h||E())>=b()*.999),pe(L.zoomOut,h===0),L.reset&&(L.reset.style.display=h===0?"none":"grid")},G=ce=>I!==void 0&&ce.target instanceof y().Node&&I.contains(ce.target),K=()=>{r&&(oe(),r.style.width=l.width,r.style.height=l.height,r.style.maxWidth=l.maxWidth,r.style.margin=l.margin,r.style.display=l.display)},C=()=>{r&&(K(),h=0,r.setAttribute("viewBox",`0 0 ${i.width} ${i.height}`),r.style.cursor="",r.style.userSelect="",x(),r.style.touchAction=S()?"pan-y":"",S()?r.setAttribute("tabindex","0"):r.removeAttribute("tabindex"),ue(S()),v(),Z())},Z=()=>{if(!r||!I||I.hidden)return;let ce=I.getBoundingClientRect(),pe=[...r.querySelectorAll("text")].some(Me=>{let Ce=Me.getBoundingClientRect();return Ce.right>ce.left&&Ce.leftce.top&&Ce.top=V.width/2)return;let le=e.getBoundingClientRect(),de=e.offsetWidth>0?le.width/e.offsetWidth:1,Se=parseFloat(y().getComputedStyle(e).paddingRight)||0,_e=le.left+(e.clientLeft+e.clientWidth-Se)*de,xe=[r.style.maxWidth,r.style.marginRight];r.style.maxWidth=`${(X-V.left)/de}px`,r.style.marginRight=`${Math.max(_e-X,0)/de}px`,u={before:xe,after:[r.style.maxWidth,r.style.marginRight]},r.getBoundingClientRect().right>X+1&&oe(),x()},oe=()=>{!r||!u||(r.style.maxWidth===u.after[0]&&(r.style.maxWidth=u.before[0]),r.style.marginRight===u.after[1]&&(r.style.marginRight=u.before[1]),u=null)},H=(ce,pe,V)=>{if(!r||(h===0&&x(),!S()))return;let X=h||E(),le=Math.min(Math.max(ce,E()),b());if(le<=E()*1.001){C();return}let de=r.getBoundingClientRect(),Se=pe??de.left+de.width/2,_e=V??de.top+de.height/2,xe=(h?d:0)+(Se-de.left)/X,Me=(h?m:0)+(_e-de.top)/X;h=le;let Ce=de;o&&(r.style.maxWidth="none",r.style.margin=c,r.style.display="block",r.style.width=`${a.width}px`,r.style.height=`${a.height}px`,Ce=r.getBoundingClientRect()),z(xe-(Se-Ce.left)/h,Me-(_e-Ce.top)/h),r.style.cursor="grab",r.style.userSelect="none",r.style.touchAction="none",v()},z=(ce,pe)=>{if(!r)return;let V=f_(i,a,h,ce,pe);d=V.x,m=V.y,r.setAttribute("viewBox",`${d} ${m} ${V.width} ${V.height}`)},M=(ce,pe)=>{h!==0&&z(d-ce/h,m-pe/h)},T=()=>{$();let ce=e.clientWidth+e.clientHeight;ce!==p&&(p=ce,C())},R,_,$=()=>{if(!n)return;let ce=y();ce!==_&&(R?.disconnect(),_=ce,R=ce.ResizeObserver?new ce.ResizeObserver(T):void 0,R?.observe(e))},g=()=>{$(),h!==0?K():oe();let ce=e.firstElementChild;if(r=ce&&ce.localName==="svg"?ce:null,h=0,!r){I?.remove(),ue(!1);return}i={width:Number(r.getAttribute("width"))||0,height:Number(r.getAttribute("height"))||0},l={width:r.style.width,height:r.style.height,maxWidth:r.style.maxWidth,margin:r.style.margin,display:r.style.display},C()},N=new Map,w=!1,A=0,D=0,U=()=>{let[ce,pe]=[...N.values()];return{distance:Math.hypot(ce.x-pe.x,ce.y-pe.y),x:(ce.x+pe.x)/2,y:(ce.y+pe.y)/2}},B=()=>{w=!1},F=ce=>{!S()||G(ce)||ce.pointerType==="mouse"&&ce.button!==0||(N.set(ce.pointerId,{x:ce.clientX,y:ce.clientY}),A=0,N.size===2&&(D=U().distance),(N.size===2||h!==0)&&(e.setPointerCapture?.(ce.pointerId),r&&(r.style.cursor="grabbing")))},W=ce=>{let pe=N.get(ce.pointerId);if(pe){if(N.size===2){let V=U();N.set(ce.pointerId,{x:ce.clientX,y:ce.clientY});let X=U();D>0&&X.distance>0&&H((h||E())*(X.distance/V.distance),X.x,X.y),M(X.x-V.x,X.y-V.y),w=!0;return}N.set(ce.pointerId,{x:ce.clientX,y:ce.clientY}),h!==0&&(A+=Math.abs(ce.clientX-pe.x)+Math.abs(ce.clientY-pe.y),A>4&&(w=!0),M(ce.clientX-pe.x,ce.clientY-pe.y))}},j=ce=>{N.delete(ce.pointerId)&&(D=0,N.size===0&&r&&h!==0&&(r.style.cursor="grab"))},Q=ce=>{!w||ce.detail===0||(w=!1,ce.preventDefault(),ce.stopPropagation())},Y=ce=>{if(!(ce.ctrlKey||ce.metaKey)||!S())return;ce.preventDefault(),h===0&&x();let pe=Math.min(Math.max(-ce.deltaY,-24),24);H((h||E())*2**(pe*.02),ce.clientX,ce.clientY)},ne=ce=>{!S()||G(ce)||(ce.preventDefault(),h!==0?C():H(Math.max(1,E()*2),ce.clientX,ce.clientY))},q=ce=>{if(!S()||G(ce)||ce.ctrlKey||ce.metaKey||ce.altKey)return;let pe=ce.key;if(pe==="+"||pe==="=")H((h||E())*Ii);else if(pe==="-")H((h||E())/Ii);else{if(h===0)return;if(pe==="0"||pe==="Escape")C();else if(pe==="ArrowLeft")M(oc,0);else if(pe==="ArrowRight")M(-oc,0);else if(pe==="ArrowUp")M(0,oc);else if(pe==="ArrowDown")M(0,-oc);else return}ce.preventDefault()},k=ce=>{if(!r||ce.target!==r)return;let pe=!0;try{pe=r.matches(":focus-visible")}catch{}r.style.outline=pe?"":"none"},J=0,te=ce=>{S()&&(ce.preventDefault(),h===0&&x(),J=h||E())},se=ce=>{if(J===0)return;ce.preventDefault();let{scale:pe,clientX:V,clientY:X}=ce;H(J*pe,V,X)},re=()=>{J=0},P=[["pointerdown",B,{capture:!0}],["pointerdown",F],["pointermove",W],["pointerup",j],["pointercancel",j],["click",Q,{capture:!0}],["dblclick",ne],["keydown",q],["focusin",k]];for(let[ce,pe,V]of P)e.addEventListener(ce,pe,V);let ee=[["wheel",Y,{passive:!1}],["gesturestart",te,{passive:!1}],["gesturechange",se,{passive:!1}],["gestureend",re,{passive:!1}]],ae=!1;function ue(ce){if(ce!==ae){ae=ce;for(let[pe,V,X]of ee)ce?e.addEventListener(pe,V,X):e.removeEventListener(pe,V,X);ce||(J=0)}}return p=e.clientWidth+e.clientHeight,g(),{get scale(){return h||E()},get fit(){return E()},zoomBy(ce){H((h||E())*ce)},zoomTo(ce){H(ce)},reset:C,refresh:g,resized:T,destroy(){C(),oe(),r&&(r.style.touchAction="",r.removeAttribute("tabindex")),I?.remove(),O&&(e.style.position=""),R?.disconnect(),ue(!1);for(let[ce,pe,V]of P)e.removeEventListener(ce,pe,V)}}}function xu(e,t){let n=t?Gs(t).getComputedStyle(t):e;return{family:n.getPropertyValue("--pele-font").trim()||e.fontFamily||void 0,mono:n.getPropertyValue("--pele-font-mono").trim()||void 0}}function y_(e){return[...new Set([e.ownerDocument?.fonts,globalThis.document?.fonts])].filter(n=>n!==void 0)}var Au=new WeakMap;function E_(e){let t=Au.get(e);return t||(t=e.ready.then(()=>{Au.delete(e),nc()}),Au.set(e,t)),t}var Su=new WeakMap;function x_(e,t){Promise.all(e.map(E_)).then(()=>{let n=t.deref();n&&Su.get(n)?.()})}var ac=new WeakMap,A_=0,S_=Math.random().toString(36).slice(2,7),w_="position:relative;height:1.3em;margin-top:-1.3em;line-height:1.3;font-size:0.8em;color:var(--pele-error,#e45756);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;",__="margin:0;font-size:0.8em;font-family:var(--pele-font-mono,monospace);color:var(--pele-error,#e45756);white-space:pre-wrap;";function R_(e){return e instanceof Error?e.message:String(e)}function T_(e){let t=e.split(` +`).filter(n=>n.trim()!=="");return t.length>1?`${t[0]} ${t[t.length-1]}`:t[0]??""}function vm(e,t,n,r={}){ac.get(t)?.destroy();let i=n,s=r,a,o,c=!1,l,u,h,d=`pele-${S_}-${++A_}`,m={},p,y=-1,E=!1,b=!1,S=!1,x=(A,D)=>{let{onRender:U,onError:B,sanitize:F,...W}=s,j={...W,idPrefix:W.idPrefix??d,fontFamily:W.fontFamily??m.family,fontFamilyMono:W.fontFamilyMono??m.mono,maxWidth:void 0};D&&(u=e.render(a,j),p=void 0);let Q=s.maxWidth??yu(t,A);return y=Q,Q>0&&Q{s.sanitize?t.replaceChildren(s.sanitize(A)):t.innerHTML=A},L,O=()=>{let A=h?t.firstElementChild:null;if(A?.style&&(A.style.opacity=l===void 0?"":"0.4"),l===void 0){L?.remove(),L=void 0;return}let D=t.ownerDocument;if(!D)return;L??=D.createElement("div"),L.className="pele pele-error";let U=R_(l);A?(L.textContent=T_(U),L.title=U,L.setAttribute("style",w_),L.parentNode!==t&&t.append(L)):(L.textContent=U,L.removeAttribute("title"),L.setAttribute("style",__),t.replaceChildren(L))},v=A=>{l=A,O(),s.onError?.(A)},G=()=>{if(b||S)return;let A=y_(t).filter(D=>D.status==="loading");A.length!==0&&(b=!0,x_(A,new WeakRef(w)))},K=()=>{b=!1,E=!0,T()},C=(A,D=!A)=>{let U=Gs(t).getComputedStyle(t),B=t.firstElementChild??null,F={fonts:m,natural:u,adapts:p,drawnFor:y,stale:E},W;try{if(A&&(m=xu(U,B),E=t.isConnected===!1),W=x(U,A),D&&W.svg===h?.svg){A&&(o=a),c&&l!==void 0&&(l=void 0,O());return}I(W.svg)}catch(j){throw{fonts:m,natural:u,adapts:p,drawnFor:y,stale:E}=F,j}if(A&&(o=a),A&&!B&&t.firstElementChild){let j=xu(U,t.firstElementChild);if(j.family!==m.family||j.mono!==m.mono){let Q={fonts:m,natural:u,adapts:p,drawnFor:y};m=j;try{let Y=x(U,!0);I(Y.svg),W=Y}catch{({fonts:m,natural:u,adapts:p,drawnFor:y}=Q)}}}h=W,c&&(l=void 0),O(),Z?.refresh(),G(),s.onRender?.(W)},Z,oe=!1,H=()=>{let A=s.zoom??"auto";A!==oe&&(Z?.destroy(),oe=A,Z=A===!1?void 0:Eu(t,typeof A=="object"?A:{always:A===!0},!1))},z=()=>t.isConnected===!1||!(t.clientWidth>0),M=()=>t.isConnected!==!1&&!(t.clientWidth>0),T=()=>{if(S||(N(),!a||z()))return;let A=Gs(t).getComputedStyle(t),D=xu(A,t.firstElementChild??null);try{if(E||D.family!==m.family||D.mono!==m.mono)C(!0,!0);else if(p!==!1&&s.maxWidth===void 0){let U=yu(t,A);U!==y&&U!==h?.width&&C(!1)}}catch(U){E=!1,c&&(l=U),a!==o&&(a=o,c=!1),O(),s.onError?.(U)}Z?.resized(),G()},R,_,$,g=()=>{$!==void 0&&R?.cancelAnimationFrame($),$=void 0},N=()=>{let A=Gs(t);A!==R&&(_?.disconnect(),g(),R=A,_=A.ResizeObserver?new A.ResizeObserver(()=>{if($===void 0){if(!A.requestAnimationFrame)return T();$=A.requestAnimationFrame(()=>{$=void 0,T()})}}):void 0,_?.observe(t))},w={get result(){return h},get source(){return i},get error(){return l},get zoom(){return Z},update(A,D=s){let U=!c||A!==i||D.limit!==s.limit||D.maxEdges!==s.maxEdges||D.config!==s.config;i=A,s=D;let B=a;if(U)try{B=e.parse(A,D)}catch(W){c=!1,v(W),H();return}let F=h;if(a=B,c=!0,M()){E=!0,H();return}try{C(!0)}catch(W){if(h!==F)throw H(),W;a=o,c=!1,v(W)}H()},refresh:T,destroy(){S=!0,_?.disconnect(),_=void 0,g(),R=void 0,Z?.destroy(),Su.delete(w),ac.get(t)===w&&ac.delete(t)}};Su.set(w,K);try{a=e.parse(n,r),c=!0,C(!0)}catch(A){if(h)throw A;a=o,c=!1,v(A)}return H(),N(),ac.set(t,w),w}var cc=new Map;function wu(...e){for(let t of e)cc.set(t.type,t)}function M_(e){return cc.has(e)}var C_=5e4,N_=4e6,I_=5e3;function Pm(e){try{return e()}catch(t){throw t instanceof RangeError?new Qe("Diagram is nested too deeply.","limit"):t}}function Fm(e,t){try{return t()}catch(n){if(n instanceof RangeError)throw new Qe("Diagram is nested too deeply.","limit",e);if(n instanceof Qe){n.type??=e.type,n.mermaidType??=e.mermaidType;let r=xo(n.message);r!==n.message&&(n.stack=n.stack?.replace(n.message,()=>r),n.message=r),n.snippet=xo(n.snippet)}throw n}}var Bm=new WeakMap;function Wm(e,t=C_,n=I_,r){if(e.length>t)throw new Qe(`Diagram source is longer than the limit of ${t} characters.`,"limit");let i=tc(e),s=nu(i.text);if(s===null)throw new Qe("No diagram type detected for the given text.","unsupported-diagram");let a=cc.get(s.type);if(a===void 0)throw new Qe(`Diagram type "${s.type}" is not supported yet.`,"unsupported-diagram",s);let o=r?{...r,...i.config}:i.config,c=a.keepComments===!0,l=uu(c?i.withComments:i.text)+` +`,u=Fm(s,()=>em({parsed:l,find:k_(e,c)},()=>a.parse(l,o,i.title,i.lineOffset,{maxEdges:n})));return{...s,diagram:a,model:u,config:o}}function k_(e,t){let n,r="";return i=>{if(n===void 0){n=[];let s=tc(e,n);uu(t?s.withComments:lu(s.withComments,n),n),r=du(e)+` +`}return[r,zr(n,i)]}}function $_(e,t){if(typeof e=="string")return Wm(e,t.limit,t.maxEdges,t.config);let n=Bm.get(e);if(n===void 0)throw new TypeError("render() takes diagram text or a model that parse() returned.");return n}function Um(e){return nu(tc(e).text)?.type??null}function L_(e){try{let t=Um(e);return t!==null&&cc.has(t)}catch{return!1}}function Gm(e,t={}){return Pm(()=>{let n=Wm(e,t.limit,t.maxEdges,t.config),r=n.model;return Object.defineProperty(r,"mermaidType",{value:n.mermaidType,enumerable:!0}),Bm.set(r,n),r})}function Ym(e,t={}){return Pm(()=>{let{type:n,mermaidType:r,diagram:i,model:s,config:a}=$_(e,t),o=a[i.section??n],c=typeof o=="object"&&o!==null&&!Array.isArray(o)&&o.useMaxWidth===!1,l=t.responsive??!c,u=t.icons,h=u&&(p=>u(bt(p))),d=Fm({type:n,mermaidType:r},()=>Lm($m(n,a),()=>om(i.math?t.math:void 0,()=>sm(h,()=>i.render(s,a,{...t,responsive:l,icons:h}))))),m=t.outputLimit??N_;if(d.svg.length>m)throw new Qe(`Diagram output is longer than the limit of ${m} characters.`,"limit",{type:n,mermaidType:r});for(let p of d.links)p.id=bt(p.id);return{type:n,mermaidType:r,...d}})}function O_(e,t,n={}){return vm({parse:Gm,render:Ym},e,t,n)}var Io="about:blank",D_=/^([^\w]*)(javascript|data|vbscript)/im,Hm=/&#(\w+)(^\w|;)?/g,Km=/&(newline|tab);/gi,_u=/[\u0000-\u001F\u007F-\u009F -‍\uD800-\uDFFF\uFFFE\uFFFF]/gimu,v_=/^.+(:|:)/gim,zm=/(\\|%5[cC])((%(6[eE]|72|74))|[nrt])/g;function Vm(e){try{return decodeURIComponent(e)}catch{return e}}function Ru(e,t){let n=t?Vm(e.trim()):e.trim(),r,i=0;do{if(++i>32)return;n=n.replace(_u,"").replace(Hm,(s,a)=>String.fromCharCode(a)).replace(Km,"").replace(_u,"").replace(zm,"").trim(),t&&(n=Vm(n)),r=n.match(_u)||n.match(Hm)||n.match(Km)||n.match(zm)}while(r&&r.length>0);return n}function ki(e){if(!e)return Io;let t=Ru(e,!0),n=Ru(e,!1);if(!t||!n)return Io;if(t[0]==="."||t[0]==="/")return n;let r=t.trimStart().match(v_);if(!r)return n;let i=r[0].toLowerCase().trim();if(D_.test(i))return Io;let s=n.trimStart().replace(/\\/g,"/");if(i==="mailto:"||i.includes("://"))return s;if(i==="http:"||i==="https:"){let a;try{a=new URL(s)}catch{return Io}return a.protocol=a.protocol.toLowerCase(),a.hostname=a.hostname.toLowerCase(),a.toString()}return s}function Qn(e){return ki(bt(e))}var P_=["http","https","mailto","tel"],F_=["http","https"],B_=/^([a-z][a-z0-9+.-]*):/i,W_=/^[\\/]{2}/;function jm(e,t){if(W_.test(e))return!1;let n=B_.exec(e);return!n||t.includes(n[1].toLowerCase())}function Xm(e,t){let n=Ru(e,!0);return n!==void 0&&jm(e,t)&&jm(n,t)?e:void 0}function ko(e,t){return t.links===!1?void 0:Xm(e,t.linkSchemes??P_)}function qm(e,t){return t.images===!1?void 0:Xm(e,t.imageSchemes??F_)}var U_=new RegExp(rc.source,"gu");function $i(e,t){let n=ki(e);if(n===Io||ko(n,t)===void 0)return!1;let r=e.replace(U_,"").replace(/[\t\n\r]/g,"").replace(/^[\x00-\x20]+/,"");return ko(r,t)!==void 0}function Zn(e,t,n,r,i,s=""){let a=ko(t,i);return a===void 0?e:(r.push({id:n,href:a,internal:!1}),`${e}`)}function qr(e){let t=e.linkRel??"noopener";return t?` rel="${rt(t)}"`:""}var G_=[["rect","proc","process","rectangle","squareRect"],["rounded","event","roundedRect"],["stadium","terminal","pill"],["fr-rect","subprocess","subproc","framed-rectangle","subroutine"],["cyl","db","database","cylinder"],["datastore","data-store"],["folder","directory"],["bucket"],["console"],["browser"],["person"],["circle","circ"],["bang"],["cloud"],["diam","decision","diamond","question"],["hex","hexagon","prepare"],["lean-r","lean-right","in-out","lean_right"],["lean-l","lean-left","out-in","lean_left"],["trap-b","priority","trapezoid-bottom","trapezoid"],["trap-t","manual","trapezoid-top","inv-trapezoid","inv_trapezoid"],["dbl-circ","double-circle","doublecircle"],["text"],["notch-rect","card","notched-rectangle"],["lin-rect","lined-rectangle","lined-process","lin-proc","shaded-process"],["sm-circ","start","small-circle","stateStart"],["fr-circ","stop","framed-circle","stateEnd"],["fork","join","forkJoin"],["hourglass","collate"],["brace","comment","brace-l"],["brace-r"],["braces"],["bolt","com-link","lightning-bolt"],["doc","document"],["delay","half-rounded-rectangle"],["h-cyl","das","horizontal-cylinder"],["lin-cyl","disk","lined-cylinder"],["curv-trap","curved-trapezoid","display"],["div-rect","div-proc","divided-rectangle","divided-process"],["tri","extract","triangle"],["win-pane","internal-storage","window-pane"],["f-circ","junction","filled-circle"],["notch-pent","loop-limit","notched-pentagon"],["flip-tri","manual-file","flipped-triangle"],["sl-rect","manual-input","sloped-rectangle"],["docs","documents","st-doc","stacked-document"],["st-rect","procs","processes","stacked-rectangle"],["bow-rect","stored-data","bow-tie-rectangle"],["cross-circ","summary","crossed-circle"],["tag-doc","tagged-document"],["tag-rect","tagged-rectangle","tag-proc","tagged-process"],["flag","paper-tape"],["odd","rect_left_inv_arrow"],["lin-doc","lined-document"]],Y_=["state","choice","note","composite","rectWithTitle","labelRect","block_arrow","collapsedGroup","iconSquare","iconCircle","icon","iconRounded","imageSquare","anchor","kanbanItem","mindmapCircle","defaultMindmapNode","classBox","erBox","requirementBox","usecaseActor","usecaseActorHollow","usecaseActorAwesome","usecaseActorIcon","usecaseBusiness","usecaseEllipse","usecaseJsonTable"],H_=new Map([["square","rect"],["round","rounded"],["ellipse","ellipse"],["hexagon","hex"],["diamond","diam"]]),lc=new Map;for(let e of G_)for(let t of e)lc.set(t,e[0]);for(let e of Y_)lc.set(e,e);function dc(e){return lc.has(e)}function uc(e){return e===void 0?"rect":H_.get(e)??lc.get(e)??"rect"}var K_=new Map([["task","roundedRect"],["tool","subroutine"],["input","lean-right"],["decision","diamond"],["refdoc","lin-doc"],["action","hexagon"],["round","rect"]]),z_=new Set(["doc","stadium","terminal","circle","trapezoid","inv_trapezoid","inv-trapezoid","doublecircle","double-circle","typeDeclaration","procs","lean_left","lean-left","in-out","cylinder","ellipse","odd","tag-rect","tagged-rectangle","delay","half-rounded-rectangle","lin-rect","lined-rectangle","win-pane","window-pane","curv-trap","curved-trapezoid"]),V_=new Set(["roundedRect","subroutine","subprocess","subproc","framed-rectangle","lean-right","diamond","lin-doc","lined-document","hexagon","hex","connector","collapsedGroup"]),$o="roundedRect";function Li(e){return e&&(K_.get(e)??e)}function Qm(e){return dc(e)||e==="constructor"}function Zm(e,t){for(let n of e)n.isGroup||((!n.shape||n.shape==="squareRect"||n.shape==="rect")&&(n.shape=$o),z_.has(n.shape)?(t.emitError("SHAPE_REMOVED",`shape "${n.shape}" was removed in v0.8.1, using "${$o}"`,{nodeId:n.id}),n.shape=$o):V_.has(n.shape)||(t.emitWarning("SHAPE_UNSUPPORTED",`shape "${n.shape}" is not supported, using "${$o}"`,{nodeId:n.id}),n.shape=$o))}var j_=new Set(["shape","view","icon","img","form","pos","w","h","class","style","labelType"]),X_=new Set(["subroutine","subprocess","subproc","framed-rectangle","tool"]);function q_(e){return X_.has(e.type)}function Tu(e){return e==="markdown"||e==="string"||e==="text"?e:"markdown"}function Jm(e){return e.startsWith('"')&&e.endsWith('"')?e.substring(1,e.length-1):e}function Mu(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Q_(e){let t=i=>Array.isArray(i)?[]:Mu(i)?{}:i,n=t(e),r=[[e,n]];for(;r.length>0;){let[i,s]=r.pop();if(Array.isArray(i))for(let a of i){let o=t(a);s.push(o),typeof a=="object"&&a!==null&&r.push([a,o])}else if(Mu(i))for(let a of Object.keys(i)){if(a==="__proto__"||a==="constructor"||a==="prototype")continue;let o=i[a],c=t(o);s[a]=c,typeof o=="object"&&o!==null&&r.push([o,c])}}return n}function fc(e,t){return Object.assign(e??{},t)}var Z_=/:\s*[>|][\d+-]*\s*$/,J_=/,([\t ]*)$/;function eR(e){let t=!1,n=!1,r=0,i,s=[];for(let a of e.split(` +`)){if(i!==void 0){let u=a.length-a.trimStart().length;if(a.trim()===""||u>i){s.push(a);continue}i=void 0}let o=-1;for(let u=0;u0){s.push(a);continue}let c=o>=0?a.slice(0,o):a,l=o>=0?a.slice(o):"";if(Z_.test(c)){i=a.length-a.trimStart().length,s.push(a);continue}s.push(c.replace(J_,"$1")+l)}return s.join(` +`)}function tR(e,t){if(e==="arrow_point"&&t==="normal")return"sequence";if(e==="arrow_cross"&&t==="normal")return"failure";if(e==="arrow_open"&&t==="dotted")return"reference"}function nR(e){let t=e.trim(),n=t.slice(0,-1),r="arrow_open";switch(t.slice(-1)){case"x":r="arrow_cross";break;case">":r="arrow_point";break;case"-":case".":n=t;break}let i="normal",s=n.length-1,a=0;for(let o=0;o0&&(i="dotted",s=a),{type:r,stroke:i,length:s}}function eg(e){if(!e)return;let t={},n=!1;for(let r of Object.keys(e))j_.has(r)||(t[r]=e[r],n=!0);return n?t:void 0}var hc=class{constructor(t={}){fe(this,"type","agentflow");fe(this,"direction");fe(this,"nodes",new Map);fe(this,"edges",[]);fe(this,"subgraphs",[]);fe(this,"connectors",new Map);fe(this,"classes",new Map);fe(this,"tooltips",new Map);fe(this,"defaultEdgeStyle");fe(this,"defaultInterpolate");fe(this,"mappings",[]);fe(this,"diagnostics",[]);fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"lineOffset");fe(this,"subgraphLookup",new Map);fe(this,"globalNodes",new Set);fe(this,"members",new Set);fe(this,"edgeById",new Map);fe(this,"pairCount",new Map);fe(this,"subCount",0);fe(this,"bareMappings",new Set);fe(this,"firstMapping",new Map);fe(this,"reported",new Map);fe(this,"options");this.options=t,this.lineOffset=t.lineOffset??0}metadata(t,n,r){let i=n.includes(` +`),s;try{s=lr(i?n+` +`:`{ +`+n+` +}`)}catch(a){let o=i?eR(n):n,c;if(o!==n)try{c=lr(o+` +`)}catch{c=void 0}if(c===void 0){let{line:l,column:u}=this.errorAt(r),h=r?` (${l}:${u})`:"";throw new Qe(`Metadata of "${t}" is not valid YAML. ${a.message}${h}`,"syntax",{type:"agentflow",line:l,column:u})}s=c}return Q_(s??{})}errorAt(t){if(t===void 0)return{line:0,column:0};let n=this.options.source;if(n===void 0)return{line:t.first_line+this.lineOffset,column:t.first_column+1};let r=0;for(let a=1;a10?10:r.length,r.edgeSemantic&&(s.edgeSemantic=r.edgeSemantic));let o=t+"\0"+n,c=this.pairCount.get(o)??0;i&&!this.edgeById.has(i)?(s.id=i,s.isUserDefinedId=!0):s.id=`L_${t}_${n}_${c===0?0:c+1}`;let l=this.options.maxEdges;if(l!==void 0&&this.edges.length>=l)throw new Qe(`Edge limit exceeded. The limit is ${l}.`,"limit",{type:"agentflow"});this.edges.push(s),this.pairCount.set(o,c+1),this.edgeById.has(s.id)||this.edgeById.set(s.id,s)}addLink(t,n,r){let i=typeof r?.id=="string"?r.id.replace("@",""):void 0,s=t[t.length-1],a=n[0];for(let o of t)for(let c of n)this.addSingleLink(o,c,r,o===s&&c===a?i:void 0)}updateLinkInterpolate(t,n){for(let r of t)r==="default"?this.defaultInterpolate=n:this.edgeAt(r).interpolate=n}updateLink(t,n){for(let r of t){if(r==="default"){this.defaultEdgeStyle=n;continue}let i=this.edgeAt(r);i.style=n,n.length>0&&!n.some(s=>s?.startsWith("fill"))&&n.push("fill:none")}}edgeAt(t){let n=this.edges[Number(t)];if(n===void 0)throw new Qe(`The index ${t} for linkStyle is out of bounds. Valid indices for linkStyle are between 0 and ${this.edges.length-1}. (Help: Ensure that the index is within the range of existing edges.)`,"semantic",{type:"agentflow"});return n}addClass(t,n){let r=n.join().replace(/\\,/g,"§§§").replace(/,/g,";").replace(/§§§/g,",").split(";");for(let i of t.split(",")){let s=this.classes.get(i);s===void 0&&(s={id:i,styles:[],textStyles:[]},this.classes.set(i,s));for(let a of r)a.includes("color")&&s.textStyles.push(a.replace("fill","bgFill")),s.styles.push(a)}}setDirection(t){let n=t.trim();n.includes("<")&&(n="RL"),n.includes("^")&&(n="BT"),n.includes(">")&&(n="LR"),n.includes("v")&&(n="TB"),n==="TD"&&(n="TB"),this.direction=n}setClass(t,n){for(let r of t.split(","))this.nodes.get(r)?.classes.push(n),this.edgeById.get(r)?.classes.push(n),this.subgraphLookup.get(r)?.classes.push(n)}setTooltip(t,n){if(n!==void 0)for(let r of t.split(","))this.tooltips.set(r,n)}setLink(t,n,r){let i=n.trim();for(let s of t.split(",")){let a=this.nodes.get(s);a!==void 0&&(a.link=i?Qn(i):void 0,a.linkTarget=r)}this.setClass(t,"clickable")}setClickEvent(t,n,r){this.setClass(t,"clickable")}setAccTitle(t){this.accTitle=t.replace(/^\s+/g,"")}setAccDescription(t){this.accDescr=t.replace(/\n\s+/g,` +`)}addSubGraph(t,n,r,i){let s=t?.text?.trim(),a=r?.text||"";t!==void 0&&t===r&&/\s/.test(a)&&(s=void 0);let o=new Set,c=[],l;for(let p of n)if(typeof p=="string")p.trim()!==""&&!o.has(p)&&(o.add(p),c.push(p));else if(Array.isArray(p))for(let y of p)y.trim()!==""&&!o.has(y)&&(o.add(y),c.push(y));else l=p.value;l??=this.options.inheritDir?this.direction??this.options.direction:void 0,s??="subGraph"+this.subCount,this.subCount++;let u=this.members,h=c.filter(p=>p!==s&&!this.globalNodes.has(p)&&!u.has(p));for(let p of h)u.add(p);let d=this.subgraphLookup.get(s);if(d){for(let p of h)d.nodes.push(p);return a.trim()&&(d.title=a.trim()),l&&(d.dir=l),s}let m={id:s,nodes:h,title:a.trim(),classes:[],dir:l,labelType:Tu(r?.type),type:"flow"};return this.subgraphs.push(m),this.subgraphLookup.set(s,m),s}addGlobal(t){let n=!1,r=i=>{let s=i.trim();s!==""&&(this.globalNodes.add(s),this.members.delete(s)&&(n=!0))};for(let i of t)if(typeof i=="string")r(i);else if(Array.isArray(i))for(let s of i)r(s);if(n)for(let i of this.subgraphs)i.nodes=i.nodes.filter(s=>!this.globalNodes.has(s))}addConnector(t,n){let r=t?.text?.trim();if(!r)return"";let i=n?.text?.trim()??"",s=this.connectors.get(r);if(s)i.length>0&&(s.text=i);else{let a={id:r,labelType:"text",styles:[],classes:[],isConnector:!0,text:i.length>0?i:r};this.connectors.set(r,a),this.nodes.set(r,a)}return r}destructLink(t,n){let r=nR(t);return n&&(n.includes(".")?"dotted":"normal")!==r.stroke?{type:"INVALID",stroke:"INVALID"}:{...r,edgeSemantic:tR(r.type,r.stroke)}}subgraph(t){return this.subgraphLookup.get(t)}vertexKind(t){if(q_(t))return"tool";let n=Li(t.type);return n==="hexagon"||n==="hex"?"action":n==="lean-right"||n==="lean_right"?"input":n==="lin-doc"||n==="lined-document"?"refdoc":n==="diamond"?"decision":"task"}semanticModel(){let t=[],n=[];for(let[a,o]of this.nodes){if(this.subgraphLookup.has(a))continue;let c=eg(o.metadata);if(o.isConnector){let h={id:a};o.text!==void 0&&o.text!==a&&(h.title=o.text),c&&(h.metadata=c),n.push(h);continue}let l={id:a};o.text!==void 0&&(l.label=o.text);let u=Li(o.type);u!==void 0&&(l.shape=u),l.vertexKind=this.vertexKind(o),c&&(l.metadata=c),t.push(l)}let r=this.edges.map(a=>{let o={start:a.start,end:a.end};return a.id!==void 0&&(o.id=a.id),a.text.length>0&&(o.label=a.text),a.type!==void 0&&(o.type=a.type),a.stroke!==void 0&&(o.stroke=a.stroke),a.edgeSemantic!==void 0&&(o.edgeSemantic=a.edgeSemantic),a.length!==void 0&&(o.length=a.length),a.metadata&&Object.keys(a.metadata).length>0&&(o.metadata={...a.metadata}),o}),i=this.subgraphs.map(a=>{let o={id:a.id,nodes:[...a.nodes],type:a.type,title:a.title};a.dir!==void 0&&(o.direction=a.dir);let c=eg(a.metadata);return c&&(o.metadata=c),o}),s={vertices:t,edges:r,subGraphs:i,connectors:n,diagnostics:this.diagnostics};return this.direction!==void 0&&(s.direction=this.direction),s}position(t){let n=t?.first_line??0,r=t?.first_column??0;return{startLine:n+this.lineOffset,startColumn:r,endLine:(t?.last_line??n)+this.lineOffset,endColumn:t?.last_column??r,startIndex:0,endIndex:0}}pushMapping(t,n,r){let i={id:t,type:n,position:r};return this.mappings.push(i),this.firstMapping.has(t)||this.firstMapping.set(t,i),i}addVertexMapping(t,n,r,i){if(!t)return;let s=this.pushMapping(t,"vertex",this.position(i));r==null&&this.bareMappings.add(s)}extendVertexMapping(t,n){if(!t||!n)return;let r=this.position(n);for(let i=this.mappings.length-1;i>=0;i--){let s=this.mappings[i];if(s.type!=="vertex"||s.id!==t)continue;this.bareMappings.delete(s)&&(s.type="attachment");let a=s.position;(r.endLine>a.endLine||r.endLine===a.endLine&&r.endColumn>a.endColumn)&&(a.endLine=r.endLine,a.endColumn=r.endColumn);return}this.pushMapping(t,"attachment",r)}addEdgeMapping(t,n,r,i){let s=Array.isArray(n)?n.filter(a=>typeof a=="string"&&a!==""):[];this.pushMapping(s.length>0?s.join(">"):"edge","edge",this.position(i))}blockMapping(t,n,r,i){if(!t)return;let s=this.position(r),a=i?this.position(i):s;this.pushMapping(t,n,{startLine:s.startLine,startColumn:s.startColumn,endLine:a.endLine,endColumn:a.endColumn,startIndex:0,endIndex:0})}addSubgraphMapping(t,n,r,i){let s=typeof t=="string"?t:t?.text;this.blockMapping(s??"","subgraph",r,i)}addConnectorMapping(t,n,r,i){this.blockMapping(t?.text?.trim()??"","connector",r,i)}emit(t,n,r,i){let s=i?.nodeId??i?.edgeId,a={id:t,severity:n,message:r};i?.nodeId?a.nodeId=i.nodeId:i?.edgeId&&(a.edgeId=i.edgeId);let o=s?this.firstMapping.get(s):void 0;o&&(a.position=o.position);let c=s??"",l=this.reported.get(c);if(l===void 0)this.reported.set(c,[a]);else{for(let u of l)if(u.id===t&&u.severity===n&&u.message===r&&u.nodeId===a.nodeId&&u.edgeId===a.edgeId)return;l.push(a)}this.diagnostics.push(a),this.options.log?.(n,`agentflow[${t}]: ${r}`)}emitWarning(t,n,r){this.emit(t,"warning",n,r)}emitError(t,n,r){this.emit(t,"error",n,r)}};var rR="4q 0 b 0 5 0 6 m 2 u 2 cp 5 b f 4 8 0 2 0 3m 4 2 1 3 3 9 0 2 2 2 0 2 j 2 2a 2 3u 9 4d a 11 3 0 8 12 21 q 6 2 1a 16 10 1 2 2q 2 0 g 1 8 1 b 2 3 0 h 0 2 t u 2g c 0 p w a 1 5 0 6 l 5 0 a 0 4 0 o o 20 0 2 a 2g 1h 4 0 j 0 8 9 g 6 2 6 6 7 3 1 3 l 2 6 2 0 4 3 4 0 h 0 e 1 2 2 f 1 k 5 5 1 3 l 2 6 2 1 2 1 2 1 w 3 2 0 k 2 h 8 2 2 2 l 2 6 2 1 2 4 4 0 j 0 g 1 10 7 3 1 3 l 2 6 2 1 2 4 4 0 v 1 2 2 g 0 i 0 2 5 4 2 2 3 4 1 2 0 2 1 4 1 4 2 4 b n 0 1h 7 2 2 2 m 2 9 2 4 4 0 r 1 7 1 10 7 2 2 2 m 2 9 2 4 4 0 x 0 2 1 g 1 j 7 2 2 2 14 3 0 h 0 i 1 p 5 6 h 4 n 2 8 2 0 3 6 1n 1b 2 1 d 6 1n 1 2 0 3 1 2 0 3 0 7 3 2 6 2 2 2 0 2 0 3 1 2 3 2 1 a 0 3 4 2 0 m 3 x 0 1s 7 2 z s 4 38 16 l 0 h 5 5 3 4 0 4 1 8 2 5 c d 0 i 11 2 0 6 0 3 16 2 98 2 3 3 6 2 0 2 3 3 14 2 3 3 w 2 3 3 6 2 0 2 3 3 e 2 1k 2 3 3 1u 12 f h 2c d h7 3 g 2 p 6 22 m c 2 3 f h f h f c 2 2 g 1f 10 0 5 0 1w 2f 9 14 2 0 6 1x b s 1g t 3 4 c 17 m 6 1l m a 1g 2b 0 2m 1a i 6 1k t e 1 b 17 r z 16 2 b z 30 3 2 3 4 1 a 5b 1t 7p 3 5 3 11 3 5 3 7 2 0 2 0 2 0 2 u 3 1g 2 6 2 0 4 2 2 6 4 3 3 5 5 c 6 2 2 6 39 0 e 0 h c 2u 0 5 0 3 9 2 0 4 4 7 0 2 0 2 0 2 3 2 a 3 3 6 4 5 0 1h 1 22k 1a 2 1a 2 3o 7 3 4 1 d 11 2 0 6 0 3 1j 8 0 h m a 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 29 0 d2 1 17 4 6 1 5 2d 7 2 2 2h 2 3 6 14 4 2l i q 1i f e9 52t 23 g5o 1g wc 1w 19 3 7g 4 f b 1 l 1a h o 9 1x 1e 8 3 2u 3 3 2 3 d a 26 9 2 2 2 3 2 m u 1f f 1d 1r 5 4 0 f r b m q s 8 1a t 0 1d 14 o 2 2 7 l m 4 0 6 1b 2 0 4 1 3 4 3 0 2 0 p 2 3 a 8 2 d 5 3 5 3 5 a 6 2 6 42 y u 8mb d m 5 1c 6it a5 3 2x 13 6 d 4 6 0 2 9 2 c 2 4 2 0 2 1 2 1 2 2z y a2 j 1r 3 1h 15 b 39 4 2 3q 11 p 7 p c 2g 4 5 3 5 3 5 3 2",sR;function iR(){let e=rR.split(" "),t=new Uint16Array(e.length),n=0;for(let r=0;r65500)return!1;let t=sR??=iR(),n=0,r=(t.length>>1)-1;for(;n<=r;){let i=n+r>>1;if(et[i*2+1])n=i+1;else return!0}return!1}var Cu=["$end","INVALID","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","SHAPE_DATA","CALLBACKNAME","CALLBACKARGS","MD_STR","STR","STYLE","DEFAULT","LINKSTYLE","INTERPOLATE","CLASSDEF","CLASS","HREF","CLICK","GRAPH","flow","connector","global","end","LINK_TARGET","NODIR","DIR","direction_tb","direction_bt","direction_rl","direction_lr","direction_td","LINK_ID","NUM","BRKT","STYLE_SEPARATOR","COLON","AMP","SEMI","COMMA","MULT","LINK","START_LINK","EDGE_TEXT","-)","TEXT","(-","STADIUMEND","STADIUMSTART","SUBROUTINEEND","SUBROUTINESTART","VERTEX_WITH_PROPS_START","TAGEND","CYLINDEREND","CYLINDERSTART","DOUBLECIRCLEEND","DOUBLECIRCLESTART","TRAPEND","INVTRAPEND","TRAPSTART","INVTRAPSTART","TAGSTART","UP","SEP","DOWN","COMMENT","NODE_STRING","MINUS","UNICODE_TEXT","PIPE","PE","PS","SQE","SQS","DIAMOND_STOP","DIAMOND_START","NEWLINE","SPACE","EOF"];var tg=new Uint8Array(128);for(let e of"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"#$%&'*+.`?\\_/")tg[e.charCodeAt(0)]=1;var oR=/accTitle\s*:\s*/y,aR=/accDescr\s*:\s*/y,cR=/accDescr\s*\{\s*/y,lR=/call\s+/y,dR=/click\s+/y,uR=/(?:\r?\n)*\s*\n/y,fR=/\s*(?:LR|RL|TB|BT|TD|BR)\b/y,hR=/\s*[<>^]/y,pR=/\s*v\b/y,mR=[/.*direction\s+TB[^\n]*/y,/.*direction\s+BT[^\n]*/y,/.*direction\s+RL[^\n]*/y,/.*direction\s+LR[^\n]*/y,/.*direction\s+TD[^\n]*/y],Nu=/[\n\r\u2028\u2029]/g,gR=/\(\s*\)/y,bR=/\n\s*/g;function ng(e){let t=e.length,n=[],r=[],i=[],s=[],a=[],o=0,c=0,l=1,u=0,h=!0,d=e.indexOf("direction"),m=e.indexOf("@"),p=-1,y=0,E=0,b=-1,S=-1,x=-1,I=-1,L=-1,O=-1,v=-1,G=F=>{let W=-1;for(let j=c;j{n.push(F),r.push(e.slice(c,W)),i.push(c),s.push(l,u),G(W),s.push(l,u)},C=(F,W)=>{n.push(F),r.push(e.slice(c,W)),i.push(c),s.push(l,u),u+=W-c,c=W,s.push(l,u)},Z=(F,W)=>{n.push(F),r.push(e.slice(c,W)),i.push(c),s.push(l,u);for(let j=c;j{n.push(F),r.push(W),i.push(c),s.push(l,u),G(j),s.push(l,u)},H=F=>{a.push(o),o=F},z=()=>{a.length>0&&(o=a.pop())},M=(F,W)=>(F.lastIndex=W,F.test(e)?F.lastIndex:-1),T=F=>e.startsWith(F,c)&&!ot(e.charCodeAt(c+F.length)),R=F=>{if(F>=S&&F<=x)return x;let W=F;for(;W{if(F>=I&&F<=L)return L;let W=F;for(;W{let W=R(F);if(W===v||e.charCodeAt(W)!==45||e.charCodeAt(W+1)!==45)return-1;let j=W+2;for(;e.charCodeAt(j)===45;)j++;let Q=e.charCodeAt(j);return Q===120||Q===62?R(j+1):(v=W,-1)},g=()=>{let F=R(c);if(F===O||e.charCodeAt(F)!==45)return!1;let W=e.charCodeAt(F+1),j=F+2;if(W===45){for(;e.charCodeAt(j)===45;)j++;let Q=e.charCodeAt(j);return Q===120||Q===62?K(42,R(j+1)):(H(10),K(43,R(F+2))),!0}if(W===46){for(;e.charCodeAt(j)===46;)j++;if(e.charCodeAt(j)===45)return K(42,R(j+1)),!0}return O=F,!1},N=F=>{if(e.charCodeAt(F)!==37||e.charCodeAt(F+1)!==37||e.charCodeAt(F+2)===123)return-1;let W=e.indexOf(` +`,F+2);return W===-1?t:W},w=()=>{e.charCodeAt(c+1)===96?(H(2),G(c+2)):(H(1),G(c+1))},A=F=>{let W=e.charCodeAt(c+1);return F===40?(W===45?(H(8),C(47,c+2)):W===91?(H(7),C(49,c+2)):W===40&&e.charCodeAt(c+2)===40?(H(7),C(57,c+3)):(H(7),C(72,c+1)),!0):F===91?(W===91?(H(7),C(51,c+2)):W===40?(H(7),C(55,c+2)):W===47?(H(9),C(60,c+2)):W===92?(H(9),C(61,c+2)):(H(7),C(74,c+1)),!0):F===124?(H(7),C(70,c+1),!0):F===123?(H(7),C(76,c+1),!0):!1},D=()=>{let F=c;for(;F{let W=F;for(;W{let W;switch(F){case 97:if(e.startsWith("acc",c)){if((W=M(oR,c))>=0)return H(3),K(2,W),!0;if((W=M(aR,c))>=0)return H(4),K(4,W),!0;if((W=M(cR,c))>=0)return H(5),G(W),!0}if(T("agentflow-beta"))return h&&(h=!1,H(6)),C(20,c+14),!0;break;case 64:if(e.charCodeAt(c+1)===123)return H(14),oe(7,"",c+2),!0;break;case 99:if((W=M(lR,c))>=0)return H(12),G(W),!0;if(T("classDef"))return C(16,c+8),!0;if(T("class"))return C(17,c+5),!0;if((W=M(dR,c))>=0)return H(11),G(W),!0;if(T("connector"))return C(22,c+9),!0;break;case 34:return w(),!0;case 115:if(T("style"))return C(12,c+5),!0;break;case 100:if(T("default"))return C(13,c+7),!0;break;case 108:if(T("linkStyle"))return C(14,c+9),!0;break;case 105:if(T("interpolate"))return C(15,c+11),!0;break;case 104:if(e.startsWith("href",c)&&qe(e.charCodeAt(c+4)))return K(18,c+5),!0;break;case 102:if(T("flow"))return C(21,c+4),!0;break;case 103:if(T("global"))return C(23,U(c+6)),!0;break;case 101:if(T("end"))return C(24,U(c+3)),!0;break;case 95:if(T("_self"))return C(25,c+5),!0;if(T("_blank"))return C(25,c+6),!0;if(T("_parent"))return C(25,c+7),!0;if(T("_top"))return C(25,c+4),!0;break}if(d!==-1&&c>=y&&(d=0)return K(28+j,W),!0;y=p}if(m!==-1&&F!==34&&!qe(F)){if(c>=E){m=m;Q--){if(e.charCodeAt(Q)!==64)continue;let Y=e.charCodeAt(Q+1);if(Y!==123&&Y!==34){b=Q;break}}}if(b>c)return C(33,b+1),!0}if(F>=48&&F<=57){let j=c+1;for(;j57)break;j++}return C(34,j),!0}switch(F){case 35:return C(35,c+1),!0;case 58:return e.charCodeAt(c+1)===58&&e.charCodeAt(c+2)===58?C(36,c+3):C(37,c+1),!0;case 38:return C(38,c+1),!0;case 59:return C(39,c+1),!0;case 44:return C(40,c+1),!0;case 42:return C(41,c+1),!0;case 60:return C(62,c+1),!0;case 45:return g()||D()||C(68,c+1),!0;case 40:return A(F);case 91:return e.charCodeAt(c+1)===124?(C(52,c+2),!0):A(F);case 124:case 123:return A(F);case 62:return H(7),C(53,c+1),!0;case 94:return C(63,c+1),!0;case 92:return e.charCodeAt(c+1)===124?(C(64,c+2),!0):D();case 118:return ot(e.charCodeAt(c+1))?D():(C(65,c+1),!0);case 37:return(W=N(c))>=0?(K(66,W),!0):D()}if(qe(F)){if(g())return!0;if((F===32||F===9)&&(W=N(_(c)))>=0)return K(66,W),!0;for(W=c;;){let j=e.charCodeAt(W);if(j===10)W++;else if(j===13&&e.charCodeAt(W+1)===10)W+=2;else break}return W>c?K(77,W):K(78,c+1),!0}return F<128?D():Oi(F)?(C(69,c+1),!0):!1};e:for(;;){if(c>=t){let j=-1;switch(o){case 0:j=79;break;case 3:j=3;break;case 4:j=5;break;case 5:j=6;break;case 11:j=19;break;case 12:j=8;break;case 13:j=9;break}j!==-1&&C(j,t);break}let F=e.charCodeAt(c),W=!0;switch(o){case 0:W=B(F);break;case 1:if(F===34)e.charCodeAt(c+1)===96?(H(2),G(c+2)):(z(),G(c+1));else{let j=e.indexOf('"',c);K(11,j===-1?t:j)}break;case 2:if(F===96)e.charCodeAt(c+1)===34?(z(),G(c+2)):W=!1;else if(F===34)w();else{let j=c+1;for(;j=0?(z(),K(26,j)):(j=M(fR,c))>=0||(j=M(hR,c))>=0||(j=M(pR,c))>=0?(z(),K(27,j)):W=A(F);break}case 7:{let j=e.charCodeAt(c+1);switch(F){case 34:w();break;case 40:case 91:case 123:A(F);break;case 93:z(),j===41?C(48,c+2):j===93?C(50,c+2):C(73,c+1);break;case 41:z(),j===93?C(54,c+2):j===41&&e.charCodeAt(c+2)===41?C(56,c+3):C(71,c+1);break;case 124:z(),C(70,c+1);break;case 125:z(),C(75,c+1);break;case 37:{let Q=N(c);Q>=0?G(Q):W=!1;break}default:{let Q=c+1;for(;Q=0)G(Q);else if((F===45||F===47||F===41)&&j===41)z(),C(45,c+2);else if(F===40||F===91||F===123)A(F);else if(F===41||F===93||F===125)W=!1;else{let Y=c+1;for(;Y=0?G(Q):W=!1;break}default:{if((F===63||F===61)&&j===93){z(),C(58,c+2);break}let Q=c+1;for(;Q=0){z(),K(42,j);break}if(F===45&&e.charCodeAt(c+1)===45){W=!1;break}let Q=c+1;for(;Q=0)break;Q++}Z(44,Q);break}case 11:if(F===34)w();else if(qe(F))z(),G(c+1);else{let j=c+1;for(;j=0?G(j):(H(13),G(c+1))}else{let j=e.indexOf("(",c);j===-1&&(j=t),K(8,j)}break;case 13:if(F===41)z(),G(c+1);else{let j=e.indexOf(")",c);j===-1&&(j=t),K(9,j)}break;case 14:if(F===34)H(15),C(7,c+1);else if(F===125)z(),G(c+1);else if(F===94)W=!1;else{let j=c+1;for(;j"),j)}break}if(!W)return n.push(1),r.push(""),i.push(c),s.push(l,u,l,u),{types:n,texts:r,starts:i,locs:s};continue e}return n.push(0),r.push(""),i.push(t),s.push(l,u,l,u),{types:n,texts:r,starts:i,locs:s}}var pc=new Uint8Array(80);for(let e of[34,67,65,68,13,40,37,38,35,41,69])pc[e]=1;var ku=new Uint8Array(80);for(let e of[34,69,67,27,65,68,40,37,38,35,41])ku[e]=1;var $u=new Uint8Array(80);for(let e of[34,67,78,68,38,69,37,41,35,12,14,16,17,19,20,27,21,22,23,24,65,63,43])$u[e]=1;var Lu=new Uint8Array(80);for(let e of[34,67,37,78,35,12])Lu[e]=1;var mc=new Uint8Array(80);for(let e of[77,39,79,66])mc[e]=1;var rg="'UNICODE_TEXT', 'TEXT', 'TAGSTART'",Iu="'COMMENT', 'SEMI', 'NEWLINE', 'EOF'",og=new Uint8Array(80);for(let e of[66,77,78,79])og[e]=1;var Lo=[],sg=/}[^\S\n]*\n/g;function ag(e,t,n=!1){let r=!n&&e.includes("}")?e.replace(sg,`} +`):e,{types:i,texts:s,starts:a,locs:o}=ng(r),c=0,l,u=0,h=0,d=w=>{let A=i[c],D=a[c];if(A===79||A===0){let B=c;for(;B>0&&og[i[B-1]];)B--;D=r.slice(0,a[B]).trimEnd().length}let U=r===e?D:zr([ds(e,sg,2)],D);throw A===1?ft("agentflow",e,U,"",!0):ft("agentflow",e,U,`Expecting ${w}, got '${Cu[A]}'`)},m=(w,A)=>({first_line:o[4*w],first_column:o[4*w+1],last_line:o[4*A+2],last_column:o[4*A+3]}),p=(w,A="")=>(i[c]!==w&&d(`'${Cu[w]}'${A?", "+A:""}`),s[c++]),y=()=>{mc[i[c]]===0&&d(Iu),c++},E=()=>{pc[i[c]]===0&&d("'NODE_STRING'");let w=s[c++];for(;pc[i[c]]===1;)w+=s[c++];return w},b=()=>{ku[i[c]]===0&&d("'NODE_STRING'");let w=s[c++];for(;ku[i[c]]===1;)w+=s[c++];return w},S=()=>{let w=i[c],A;if(w===11)A="string";else if(w===10)A="markdown";else if(w===46||w===62||w===53||w===69)A="text";else return d(`${rg}, 'TAGEND', 'STR', 'MD_STR'`);let D=s[c++];for(;;){let U=i[c];if(U!==46&&U!==62&&U!==53&&U!==69)break;D+=s[c++]}return{text:D,type:A}},x=w=>{p(w,rg)},I=()=>{let w=i[c],A;if(w===11)A="string";else if(w===10)A="markdown";else if(w===44||w===69)A="text";else return d("'EDGE_TEXT', 'STR', 'MD_STR'");let D=s[c++];for(;i[c]===44||i[c]===69;)D+=s[c++];return{text:D,type:A}},L=()=>{let w=i[c],A;if(w===11)A="text";else if(w===10)A="markdown";else if($u[w]===1)A="text";else return d("'NODE_STRING', 'STR', 'MD_STR'");let D=s[c++];for(;$u[i[c]]===1;)D+=s[c++];return{text:D,type:A}},O=()=>{u=c;let w=s[c++];for(;i[c]===7;)w+=s[c++];return h=c-1,w},v=(w,A,D,U)=>{let B=m(D,U);t.addVertex(w,void 0,void 0,void 0,void 0,void 0,void 0,A,B),t.extendVertexMapping(w,B)},G=(w,A)=>{A.data!==void 0&&t.addVertex(w,void 0,void 0,void 0,void 0,void 0,void 0,A.data,m(A.dataFrom,A.dataTo))},K=()=>{let w=c,A=E(),D,U,B;switch(i[c]){case 74:c++,D=S(),x(73),U="square";break;case 57:c++,D=S(),x(56),U="doublecircle";break;case 72:c++,i[c]===72?(c++,D=S(),x(71),p(71),U="circle"):(D=S(),x(71),U="round");break;case 47:c++,D=S(),x(45),U="ellipse";break;case 49:c++,D=S(),x(48),U="stadium";break;case 51:c++,D=S(),x(50),U="subroutine";break;case 52:{c++;let F=p(67);p(37);let W=p(67);p(70),D=S(),x(73),U="rect",B={[F]:W};break}case 55:c++,D=S(),x(54),U="cylinder";break;case 76:c++,i[c]===76?(c++,D=S(),x(75),p(75),U="hexagon"):(D=S(),x(75),U="diamond");break;case 53:c++,D=S(),x(73),U="odd";break;case 60:c++,D=S(),i[c]===59?(c++,U="lean_right"):(x(58),U="trapezoid");break;case 61:c++,D=S(),i[c]===58?(c++,U="lean_left"):(x(59),U="inv_trapezoid");break}return B!==void 0?t.addVertex(A,D,U,void 0,void 0,void 0,B):U!==void 0?t.addVertex(A,D,U):t.addVertex(A),t.addVertexMapping(A,D,U,m(w,c-1)),A},C=()=>{let w=K();return i[c]===36&&(c++,t.setClass(w,E())),w},Z=()=>{let w=[C()];for(l=void 0;;){let D=i[c]===7?O():void 0,U=u,B=h;if(i[c]!==78)return l=D,w;do c++;while(i[c]===78);if(i[c]!==38)return D!==void 0&&d("'AMP'"),w;c++,i[c]!==78&&d("'SPACE'");do c++;while(i[c]===78);let F=C();D!==void 0&&v(w[w.length-1],D,U,B),w.push(F)}},oe=()=>{let w;if(i[c]===33&&(w=s[c++]),i[c]===42){let A=t.destructLink(s[c++]);return w!==void 0&&(A.id=w),i[c]===70&&(c++,A.text=S(),x(70),i[c]===78&&c++),A}if(i[c]===43){let A=s[c++],D=I(),U=p(42,"'EDGE_TEXT'"),B=t.destructLink(U,A);return B.text=D,w!==void 0&&(B.id=w),B}return d("'LINK', 'START_LINK'")},H=()=>{let w=c,A=Z();l!==void 0&&v(A[A.length-1],l,u,h);let D=A;for(;;){let U=i[c];if(U!==42&&U!==43&&U!==33)return D;let B=oe(),F=Z();l!==void 0&&v(F[F.length-1],l,u,h),t.addLink(A,F,B),t.addEdgeMapping(A,F,B,m(w,c-1)),D=F.concat(D),A=F}},z=()=>{Lu[i[c]]===0&&d("'NODE_STRING', 'NUM', 'COLON', 'BRKT'");let w=s[c++];for(;Lu[i[c]]===1;)w+=s[c++];return w},M=()=>{let w=[z()];for(;i[c]===40;)c++,w.push(z());return w},T=()=>{c++,p(78);let w;if(i[c]===13)w=[s[c++]];else for(w=[p(34,"'DEFAULT'")];i[c]===40;)c++,w.push(p(34));if(p(78),i[c]!==15){t.updateLink(w,M());return}c++,p(78);let A=b();if(i[c]===78){c++;let D=M();t.updateLinkInterpolate(w,A),t.updateLink(w,D)}else t.updateLinkInterpolate(w,A)},R=(w,A)=>{if(i[c]!==78){t.setLink(w,A);return}if(c++,i[c]===25){t.setLink(w,A,s[c++]);return}let D=p(11,"'LINK_TARGET'");i[c]===78?(c++,t.setLink(w,A,p(25))):t.setLink(w,A),t.setTooltip(w,D)},_=()=>{let w=s[c++];switch(i[c]){case 8:{let A=s[c++],D=i[c]===9,U=D?s[c++]:void 0,B;i[c]===78&&(c++,B=p(11)),D?t.setClickEvent(w,A,U):t.setClickEvent(w,A),B!==void 0&&t.setTooltip(w,B);return}case 18:c++,R(w,p(11));return;case 11:R(w,s[c++]);return;default:{let A=b();if(i[c]===78){c++;let D=p(11);t.setClickEvent(w,A),t.setTooltip(w,D)}else t.setClickEvent(w,A)}}},$=w=>{p(78,Iu);let A=L(),D={text:"",type:"text"};i[c]===74&&(c++,D=S(),x(73));let U=i[c]===7?O():void 0;return mc[i[c]]===0&&d(`${Iu}, 'SHAPE_DATA'`),{global:!1,at:w,id:A,title:D,data:U,dataFrom:u,dataTo:h,list:[],collect:!1}},g=()=>{let w=i[c];switch(w){case 12:{c++,p(78);let A=E();return p(78),t.addVertex(A,void 0,void 0,M()),y(),Lo}case 14:return T(),y(),Lo;case 16:{c++,p(78);let A=E();return p(78),t.addClass(A,M()),y(),Lo}case 17:{c++,p(78);let A=E();return p(78),t.setClass(A,E()),y(),Lo}case 19:return _(),y(),Lo;case 22:{let A=$(c++),D=c++,U=t.addConnector(A.id,A.title);return G(U,A),t.addConnectorMapping(A.id,A.title,m(A.at,A.at),m(D,D)),U}case 28:case 29:case 30:case 31:case 32:return c++,{stmt:"dir",value:yR[w-28]};case 2:{c++;let A=p(3).trim();return t.setAccTitle(A),A}case 4:{c++;let A=p(5).trim();return t.setAccDescription(A),A}case 6:{let A=s[c++].trim();return t.setAccDescription(A),A}default:{pc[w]===0&&d(ig);let A=H();return y(),A}}},N=()=>{let w=[],A=[],D=!1;for(;;){let U=i[c];if(U===0)break;if(U===24){let B=w.pop();if(B===void 0)break;let F=c++;if(B.global){t.addGlobal(A),A=B.list,D=B.collect;continue}let W=t.addSubGraph(B.id,A,B.title,"flow");G(W,B),t.addSubgraphMapping(B.id,B.title,m(B.at,B.at),m(F,F)),A=B.list,D=B.collect,D&&A.push(W)}else if(U===39||U===77||U===78||U===79)D&&A.push(s[c]),c++;else if(U===66)c++;else if(U===21||U===23){let B=c++,F;U===23||mc[i[c]]===1?(F={global:U===23,at:B,id:void 0,title:void 0,data:void 0,dataFrom:0,dataTo:0,list:A,collect:D},y()):(F=$(B),F.list=A,F.collect=D,c++),w.push(F),A=[],D=!0}else{let B=g();D&&(!Array.isArray(B)||B.length>0)&&A.push(B)}}w.length>0&&d("'end'")};for(;i[c]===78||i[c]===77||i[c]===66;)c++;if(p(20,"'SPACE', 'NEWLINE', 'COMMENT'"),i[c]===26)c++,t.setDirection("TB");else{let w=p(27,"'NODIR'"),A=i[c];if(A===78){do c++;while(i[c]===78);A=i[c],A!==77&&d("'NEWLINE', 'SPACE'")}else A!==39&&A!==77&&A!==66&&d("'COMMENT', 'SEMI', 'NEWLINE', 'SPACE'");c++,t.setDirection(w)}N(),i[c]!==0&&d(ig)}var yR=["TB","BT","RL","LR","TD"],ig="'COMMENT', 'SEMI', 'NEWLINE', 'SPACE', 'EOF', 'flow', 'global', 'connector', 'acc_title', 'acc_descr', 'acc_descr_multiline_value', 'STYLE', 'LINKSTYLE', 'CLASSDEF', 'CLASS', 'CLICK', 'NODE_STRING'";function Ys(e,t,n=0){return{w:e,h:t,kind:n,pin:0,hint:NaN,key:NaN,span:0,x:0,y:0,rank:0}}function Hs(e,t,n=1,r=0,i=0){return{tail:e,head:t,minlen:n,labelW:r,labelH:i,tailDx:0,headDx:0,tailFixed:!1,headFixed:!1,reversed:!1,points:[],labelX:0,labelY:0}}var ER=24,cg=2e4,vu=16,lg=8,xR=.125,dg=3,AR=18,SR=10,wR=14,_R=2,RR=28,ug=12,TR=12,MR=8,CR=4,fg=.5,Rr=.5,Pu=1,NR=12,hg=24,IR=40,pg=400,Di=16,Ou=new Float64Array(2*Di+2),Du=new Float64Array(2*Di+2);function vi(e){return e===1||e===2}function mg(e,t,n,r){for(let i=t+1;i=t&&(r[e[o]]>a||r[e[o]]===a&&e[o]>s);)e[o+1]=e[o],o--;e[o+1]=s}}function kR(e,t,n,r,i,s){let a=(u,h)=>n[u]r[h]:r[u]=u&&a(m,e[p]);)e[p+1]=e[p],p--;e[p+1]=m}let c=e,l=s;for(let u=8;u0){let ie=new Set;for(let me of t){let Te=Math.min(me.tail,me.head),ye=Math.max(me.tail,me.head),we=Te*r+ye;if(me.labelW>0||ie.has(we)){s=2;break}ie.add(we)}}Do(e,t),vo(e,t,s);let a=new Int32Array(i),o=0;for(let ie=0;ie1&&(o+=a[ie]-1)}let c=new Uint8Array(i);if(o>cg){let ie=[];for(let me=0;me1&&ie.push(me);ie.sort((me,Te)=>a[Te]-a[me]||me-Te);for(let me of ie){if(o<=cg)break;c[me]=1,o-=a[me]-1}}let l=r+o,u=new Float64Array(l),h=new Float64Array(l),d=new Uint8Array(l),m=new Int32Array(l),p=0;for(let ie=0;iep&&(p=me.rank)}let y=0;for(let ie=0;ie0&&e[ie].kind===0&&(v=!0);let G=v?new Uint8Array(y):void 0,K=v?new Uint8Array(y):void 0,C=new Int32Array(i).fill(-1),Z=new Int32Array(i).fill(-1),oe=new Float64Array(l).fill(NaN);for(let ie=0;ie0&&(Be=he+(Re-he>>1),s===2&&Re-he>=4?(Be&1)===1&&(Be+=ye.reversed?1:-1):s===2&&(Be&1)===0&&(Be+=ye.reversed?1:-1));let ge=we;Re-he>1&&(I[Te]=ie),C[Te]=me,G&&!(ye.reversed?ye.headFixed:ye.tailFixed)&&(G[me]=ye.reversed?2:1);for(let Le=he+1;Le{let Ie=0;for(;we>=0;we=me[we])Ie++;return Ie},ye=(we,Ie)=>{let ve=Te(we),Pe=Te(Ie);for(;ve>Pe;ve--)we=me[we];for(;Pe>ve;Pe--)Ie=me[Ie];for(;we!==Ie;)we=me[we],Ie=me[Ie];return we};for(let we=0;we0;){let Ie=ye.pop();if(!Te[Ie]){Te[Ie]=1,g[me[m[Ie]]++]=Ie;for(let ve=M[Ie+1]-1;ve>=M[Ie];ve--){let Pe=b[R[ve]];Te[Pe]||ye.push(Pe)}}}}let w=(ie,me)=>{let Te=$[ie],ye=$[ie+1];if(ye-Te<2)return!1;for(let ve=Te;veIe.set(ve,Pe)),we.sort((ve,Pe)=>me(ve)-me(Pe)||Ie.get(ve)-Ie.get(Pe)),g.set(we,Te),!0};for(let ie=0;ie<=p;ie++)w(ie,me=>oe[me]);let A=!1;for(let ie=0;ieTe.set(we,Ie));let ye=we=>weye(we)-ye(Ie)||Te.get(we)-Te.get(Ie)),g.set(me,$[ie])}let D=new Uint8Array(p+1),U=ie=>ie{for(let ie=0;ie<=p;ie++){let me=$[ie];for(let Te=me,ye=$[ie+1];Te0&&p>0&&([W,j]=GR(F,e),B()),n.orderOnly){let ie=gg(F,n);for(let me=0;me=0)for(let ve=I[me],Pe=ve+a[me]-1;ve{let Te=!1;for(let ye=$[ie];ye<$[ie+1];ye++){let we=d[g[ye]];if(we===me)Te=!0;else if(we!==1)return!1}return Te},se=te(0,3)?s:0,re=te(p,4)?s:0,P=new Float64Array(p+1);for(let ie=0;ieP[m[E[ie]]]&&(P[m[E[ie]]]=me)}let ee=new Float64Array(p+1),ae=new Float64Array(p+1),ue=ie=>(ie=p-re?n.portSep:n.rankSep)/s,ce=new Float64Array(p+1);for(let ie=0;ied[ie]===1&&pe[m[ie]]&&!n.tracks?(ae[m[ie]]-ee[m[ie]])/4:0,X=n.tracks?AR:RR,le=n.tracks?SR:ug,de=n.tracks?wR:ug,Se=new Int32Array(p+1);if(k){let ie=new Float64Array(p+1);for(let Te=0;Te_R*ie[k.rank[Te]]?1:0);let me=new Float64Array(p+1);BR(k,J,!n.tracks,ie,me);for(let Te=0;Te0?ce[Te]+=Math.max(0,2*X+(J[Te]-1)*le-ie[Te]):me[Te]>0&&(ce[Te]+=Math.max(0,Math.min(dg*n.rankSep,me[Te])-ie[Te]))}let _e=0;for(let ie=0;ie<=p;ie++){let me=0;for(let Te=$[ie];Te<$[ie+1];Te++)h[g[Te]]>me&&(me=h[g[Te]]);ee[ie]=_e,ae[ie]=_e+me,_e+=me+ce[ie]}let xe=_e,Me=(ie,me=k.track[ie])=>{let Te=k.rank[ie],ye=ae[Te],we=ee[Se[Te]],Ie=n.tracks?J[Te]:k.levels[ie],ve=Ie>1?Math.min(de,(we-ye-2*X)/(Ie-1)):0;return(ye+we)/2+(me-(Ie-1)/2)*ve},Ce=1/0,ke=-1/0;for(let ie=0;ieke&&(ke=Q[ie]+me)}let be=new Uint8Array(p+1),Ae=new Uint8Array(p+1);for(let ie=0;ieT[ie]&&(be[m[ie]]=1),M[ie+1]>M[ie]&&(Ae[m[ie]]=1));for(let ie=0;ieq[ie])for(let Pe=q[ie];Pe=0&&(n.tracks||k.wide[Pe]===1)){let Re=Me(Pe);we.push(k.from[Pe]-Ce,Re,k.to[Pe]-Ce,Re)}else k.track[Pe]>0&&we.push(k.from[Pe]-Ce,Me(Pe,k.track[Pe]-1));let he=k.lower[Pe];he<0||(we.push(Q[he]-Ce,ee[m[he]]+V(he)),ae[m[he]]>ee[m[he]]&&we.push(Q[he]-Ce,ae[m[he]]-V(he)))}else if(Ie>=0)for(let Pe=Ie,he=Ie+a[ie]-1;PeBe&&we.push(Re,ge-V(Pe))}if(we.push(ye.x+(me.reversed?me.tailDx:me.headDx),ye.y-ye.h/2),me.reversed)for(let Pe=0,he=we.length-2;Pe=0?(me.labelX=Q[ve]-Ce,me.labelY=(ee[m[ve]]+ae[m[ve]])/2):me.labelW>0&&(me.labelX=(we[0]+we[we.length-2])/2,me.labelY=(we[1]+we[we.length-1])/2)}return{width:ke-Ce,height:xe}}function Do(e,t){let n=e.length,r=t.length,i=new Int32Array(n+1);for(let l=0;l0;){let u=c[c.length-1];if(o[u]d[v]&&(d[v]=d[I]+o[O]),--m[v]===0&&(p[y++]=v)}}for(let x=0;x<8;x++){let I=!1;for(let L=y-1;L>=0;L--){let O=p[L],v=l[O+1]-l[O],G=c[O+1]-c[O];if(v===0&&G===0)continue;let K=-1/0,C=1/0;for(let oe=l[O];oev&&C!==1/0?Z=C:v>G&&K!==-1/0&&(Z=K),Z!==d[O]&&(d[O]=Z,I=!0)}if(!I)break}let E=1/0,b=-1/0,S=!1;for(let x=0;xb&&(b=d[x]))}E===1/0&&(E=0,b=0);for(let x=0;xu[l[p]]-u[l[y]]||p-y);let h=p=>{let y=0;a[0]=0;for(let E=1;E1);if(r/dp?.5:1)),r/dy?0:1)),d===0)return 0;let m=Math.min(vu,r/d);for(let p=1;p0&&Gu[z]===2||u[z]===1&&!(s!==void 0&&s[h[z]]===1),K=(z,M)=>{let T=M===0?m[z]:p[z];return[M===0?n[T]+y[z]:n[T]+E[z],T{let M=L[h[z]],T=M+v[z],R=_=>d[_]/2+d[z]/2+(u[_]===0?i.nodeSep/2+a/2:u[_]===u[z]?a:a/2);return[T>M?n[O[T-1]]+R(O[T-1]):-1/0,T+1{let g=(M[1]!==T[1]?M[1]N>=R&&N<=_)??Math.max(R,Math.min(_,g[0]))},oe=new Uint8Array(o),H=[];for(let z=1;z_&&(_=N),w<$&&($=w)}if(_<=$){let g=Z(n[H[0]],K(I[x[T]],0),K(S[b[R]],1),_,$);for(let N of H)n[N]=g;continue}for(let g of H){let[N,w]=C(g);N>w||(n[g]=Z(n[g],K(Oo(e,s,I[x[g]],0),0),K(Oo(e,s,S[b[g]],1),1),N,w))}}}function vR(e,t,n,r,i,s,a){let{real:o,W:c,EF:l,ET:u,EFD:h,ETD:d,succStart:m,succE:p,predStart:y,predE:E,pos:b}=e,S=(I,L,O,v,G)=>{if(s[L][O]<2)return 0;I=Oo(e,a,I,L);let K=L===0?l[I]:u[I],C=L===0?n[K]+h[I]:n[K]+d[I];if(G&&Math.abs(C-n[O])<=v/2+Rr)return Math.max(-v/2,Math.min(v/2,C-n[O]));let Z=C,oe=0;K=2&&(oe=Math.max(0,Math.min(t[K].span,c[K])),oe>0&&(Z=n[K]));let H=Math.max(n[O]-v/2,Z-oe/2),z=Math.min(n[O]+v/2,Z+oe/2);if(H>z+Rr){let T=Math.max(0,v/2-IR);return Math.max(-T,Math.min(T,C-n[O]))}let M=(n[O]*oe+Z*v)/(oe+v);return Math.max(H,Math.min(z,M))-n[O]},x=[];for(let I=0;Ib[v[H]]-b[v[z]]||H-z),x.push({v:I,side:O,span:L,ids:C,room:Z,all:oe})}}for(let I=0,L=!0;L&&I<6;I++){L=!1;for(let{v:O,side:v,span:G,ids:K,room:C,all:Z}of x){let oe=v===0?i:r,H=v===0?d:h,z=0,M=-G/2;for(let T=0;T<=Z.length;T++){let R=T=0&&oe[Z[g]]!==0;g--)_++;let $=R?H[Z[T]]-vu:G/2;if(_>0){let g=[],N=[],w=0;for(let U=0;U<_;U++){U>0&&(w+=C[z+U]),g.push(S(K[z+U],v,O,G,I>0)-w),N.push(1);let B=U>0&&C[z+U]===0;for(;g.length>1&&(B||g[g.length-2]/N[N.length-2]>g[g.length-1]/N[N.length-1]);){B=!1;let F=g.pop(),W=N.pop();g[g.length-1]+=F,N[N.length-1]+=W}}let A=w,D=0;w=0;for(let U=0;U0&&(w+=C[z+D]),Math.abs(H[K[z+D]]-B-w)>.01&&(L=!0),H[K[z+D]]=B+w}z+=_}R&&(M=H[Z[T]]+vu)}}}}function PR(e,t,n,r){let{n:i,KIND:s,RANK:a,EF:o,ET:c,EFD:l,ETD:u,layerStart:h,order:d,pos:m}=e,p=C=>n!==void 0&&s[C]===1&&n[a[C]]===1,y=[],E=[],b=[],S=[];for(let C=0;Ct[E[C]]+S[C]-t[y[C]]-b[C],I=new Int32Array(i),L=[];for(let C=0;C{let oe=I[C],H=I[Z];if(oe!==H){L[oe].lengthMath.abs(x(C))-Math.abs(x(Z))||C-Z);let G=C=>yg(e,r,C),K=(C,Z)=>{for(let oe of L[C]){let H=h[a[oe]],z=h[a[oe]+1],M=H+m[oe];if(M>H&&I[d[M-1]]!==C&&t[oe]+Z-t[d[M-1]]hg||I[y[C]]===I[E[C]])continue;let oe=I[y[C]],H=I[E[C]],z=L[oe].length<=L[H].length?oe:H;for(let M of[z,z===oe?H:oe]){let T=M===oe?Z:-Z;if(!(Math.abs(Z)>NR&&!L[M].every(R=>s[R]===1))&&K(M,T)){for(let R of L[M])t[R]+=T;O(y[C],E[C]);break}}}}function FR(e){let{maxRank:t,KIND:n,layerStart:r,order:i}=e,s=new Uint8Array(t+1),a=!1;for(let o=1;or[o];for(let l=r[o];c&&lC>=m[Z]-Rr&&C<=p[Z]+Rr?1:0,E=(C,Z)=>Math.abs(s[C]-s[Z])m[C]b(C,Z)&&!E(C,Z),x=(C,Z)=>b(C,Z)||y(a[C],Z)+y(s[Z],C)+y(a[Z],C)+y(s[C],Z)>0,I=(C,Z)=>y(a[C],Z)+y(s[Z],C),L=C=>{let Z=C.map((H,z)=>z).sort((H,z)=>m[C[H]]-m[C[z]]),oe=[];for(let H=0;H{C.sort((D,U)=>p[U]-m[U]-(p[D]-m[D])||m[D]-m[U]||D-U);let Z=C.length,oe=[],H=C.map((D,U)=>U),z=D=>{for(;H[D]!==D;)D=H[D]=H[H[D]];return D},M=Z<=pg,T=M?L(C):[],R=M?C.map(()=>[]):[];for(let D=0;DU);if(M){let D=new Int32Array(Z),U=[];for(let F=0;F=B&&(B=c[C[F]]+1);if(M){$.clear();for(let F of R[D])$.add(c[C[F]]);for(;$.has(B);)B++}else{for(;g[B]?.some(F=>S(U,F));)B++;(g[B]??=[]).push(U)}c[U]=B,B>=N&&(N=B+1)}let w=new Int32Array(Z).fill(N),A=new Int32Array(Z).fill(-1);for(let D=0;D{let H=Pi(a[C]-s[C],Z);for(let z=0;z<=Di;z++){let M=z/Di,T=1-M;oe[2*z]=s[C]+(a[C]-s[C])*M*M*(3-2*M),oe[2*z+1]=Z*(3*H*M*T*T+3*(1-H)*M*M*T+M*M*M)}},G=(C,Z,oe)=>{let H=oe*oe*1.000000001;for(let z=0;z<=Di;z++){let M=C[2*z],T=C[2*z+1];for(let R=0;R{let z=Math.max(oe/2,oe-2*TR);return v(C,z,Ou),v(Z,z,Du),G(Ou,Du,H)||G(Du,Ou,H)};for(let[C,Z]of d){if(!n){t[C]=O(Z);continue}if(Z.length>pg)continue;let oe=Z.filter(g=>u[g]===1);O(oe);let H=new Set(oe.filter(g=>l[g]>1)),z=L(Z);for(let g=0;gT){for(let g of Z)(p[g]-m[g])*fg>i[C]&&(i[C]=(p[g]-m[g])*fg);continue}let _=Z.filter(g=>H.has(g)||u[g]!==1&&R.has(g));O(_);let $=0;for(let g of _)l[g]>$&&($=l[g]);t[C]=$}}function WR(e,t,n,r,i,s,a){let{maxRank:o,EF:c,ET:l,EFD:u,ETD:h,succStart:d,succE:m,predStart:p,predE:y,layerStart:E,order:b}=e,S=new Float64Array(t.length),x=new Float64Array(t.length),I=new Float64Array(t.length);for(let O=0;Ox[C]-x[Z]||I[C]-I[Z]||C-Z);for(let C=0;Ce.pos[oe]-e.pos[H]);for(let oe=0;oev&&s[C-1];)C--;for(;Z+1T&&t[w]-o[w]/2{for(let V=ue+1;Vpe[X]-pe[le]),!0;return!1};for(let ae=0;ae{let P=0;for(let ee=0;ee=de&&c[K[X+Ce-de]]===Me&&H[Ce]>xe;)H[Ce+1]=H[Ce],Ce--;H[Ce+1]=xe}else if(Se<=12)for(let _e=de+1;_e=de&&H[Me]>xe;)H[Me+1]=H[Me],Me--;H[Me+1]=xe}else H.subarray(de,ue).sort()}if(ue<2)continue;let ce=1;for(;ce1;)(V&1)===0&&(P+=oe[V+1]),V>>=1,oe[V]++}}return P},M=z(),T=new Float64Array(n),R=new Int32Array(L),_=new Int32Array(L),$=I?I.length:0,g=new Int32Array($);for(let P=0;P<$;P++)for(let ee=P;ee>=0;ee=I[ee])g[P]++;let N=new Float64Array($),w=new Int32Array($),A=new Int32Array($),D=(P,ee)=>{let ae=p[P],ue=p[P+1];for(let le=ae;le=0;de=I[de])N[de]=0,w[de]=0;for(let le=ae;le=0;Se=I[Se])w[Se]===0&&(A[Se]=le),N[Se]+=ee[de],w[Se]++}let ce=le=>le>=n?N[le-n]/w[le-n]:ee[le],pe=le=>le>=n?A[le-n]:ae+E[le],V=(le,de)=>{let Se=le,_e=de,xe=x[le],Me=x[de],Ce=xe<0?0:g[xe],ke=Me<0?0:g[Me];for(;Ce>ke;Ce--)Se=n+xe,xe=I[xe];for(;ke>Ce;ke--)_e=n+Me,Me=I[Me];for(;xe!==Me;)Se=n+xe,xe=I[xe],_e=n+Me,Me=I[Me];return ce(Se)-ce(_e)||pe(Se)-pe(_e)},X=Array.from(y.subarray(ae,ue)).sort(V);y.set(X,ae);for(let le=ae;le{let ae=P?d:u,ue=P?m:h,ce=P?a:o,pe=P?c:l;for(let V=1;V<=i;V++){let X=P?V:i-V;if(S[X])continue;let le=p[X],de=p[X+1],Se=0;for(let xe=le;xe0&&(Ae+=pe[ue[ie]]/s[me])}T[Me]=Ae/(be-ke),R[Se++]=Me}if(x){D(X,T);continue}if(Se<2)continue;kR(R,Se,T,E,ee,_);let _e=0;for(let xe=le;xe{let P=0;for(let ee=0;ee<=i;ee++)for(let ae=p[ee];ae=r))for(let ue=ae+1;ue{for(let P=0;P<=i;P++)for(let ee=p[P];eeP{let ae=ee?a[P]:o[P];return b&&s[ae]>0?E[ae]+(ee?c[P]:l[P])/s[ae]:E[ae]},q=(P,ee)=>{let ae=0;for(let ue=d[P];uene(m[pe],!0)&&ae++}for(let ue=u[P];uene(h[pe],!1)&&ae++}return ae},k=()=>{for(let P=0;P<8;P++){let ee=!1;for(let ae=0;ae<=i;ae++){if(S[ae])continue;let ue=p[ae];for(let ce=ue;ce+1=q(pe,V)||(y[ce]=V,y[ce+1]=pe,E[V]=ce-ue,E[pe]=ce+1-ue,ee=!0)}}if(!ee)break}},J=y.slice(),te=n<=600,se=B,re=1/0;for(let P=0;P<(te?2:1);P++){P>0&&(y.set(J),Q());let ee=F,ae=J.slice();for(let ce=0,pe=0;pe<4&&ce=2);let V=z();if(V0){Q(),k();let ce=z();ceU||j()>=re)&&y.set(B),[U,M]}function yg(e,t,n){return e.W[n]/2+(e.KIND[n]===0?t.nodeSep:t.edgeSep)/2}function gg(e,t){let{n,maxRank:r,W:i,KIND:s,EF:a,ET:o,EFD:c,ETD:l,succStart:u,succE:h,predStart:d,predE:m,layerStart:p,order:y,pos:E}=e,b=a.length,S=new Float64Array(n);for(let A=0;A1&&mg(h,u[A],u[A+1],x);for(let A=0;A1&&mg(m,d[A],d[A+1],x);let I=new Uint8Array(b);for(let A=1;A<=r;A++){let D=p[A]-p[A-1],U=p[A],B=p[A+1],F=0,W=U;for(let j=U;j=0?E[Y]:D;if(Y>=0||j===B-1){for(let q=W;q<=j;q++){let k=y[q],J=vi(s[k]);for(let te=d[k];te=0&&re<=r?p[re+1]-p[re]-1:0,ee=-1;for(let ae=U?se-1:te;U?ae>=te:ae>1),X=ce+(pe>>1);for(let le=0;le<2&&!(le===1&&V===X);le++){let de=F[le===0!==U?V:X],Se=W[de],_e=U?P-E[Se]:E[Se];v[ue]===ue&&ee<_e&&I[de]===0&&(v[Se]=ue,v[ue]=O[ue]=O[Se],G[ue]=G[Se]+Q[de]-j[de],ee=_e)}}}let Y=0;for(let k=0;k<=r;k++){let J=p[k],te=p[k+1];for(let se=J+1;seR[re]&&(R[re]=R[J]+Z[se]),--oe[re]===0&&(T[ne++]=re)}}for(let k=ne-1;k>=0;k--){let J=T[k],te=1/0;for(let se=H[J];seR[J]&&(R[J]=te)}let q=new Float64Array(n);for(let k=0;kU&&(U=B[F]+W)}g.push(D),N.push(U),U-D<$&&($=U-D,_=A)}for(let A=0;A<4;A++){let D=(A&1)===0?g[_]-g[A]:N[_]-N[A];if(D!==0){let U=L[A];for(let B=0;BU&&(W=D,D=U,U=W),B>F&&(W=B,B=F,F=W),D>B&&(W=D,D=B,B=W),U>F&&(W=U,U=F,F=W),U>B&&(W=U,U=B,B=W),w[A]=(U+B)/2}return w}function ln(e){return e==="BT"||e==="LR"||e==="RL"?e:"TB"}var YR=4e4,HR=400,KR=500,zR=1.5,VR=4;function Eg(e,t,n,r){let i=[];for(let o of e)i.push(o.x,o.y,o.w,o.h);let s=[];for(let o of t)s.push(o.labelX,o.labelY);let a=[];for(let o of n){a.push(o.x,o.y);for(let c of o.ports)a.push(c.px,c.py)}return{nodes:i,routes:t.map(o=>o.route),labels:s,levels:a,total:r}}function xg(e,t,n,r){t.forEach((s,a)=>{s.x=e.nodes[4*a],s.y=e.nodes[4*a+1],s.w=e.nodes[4*a+2],s.h=e.nodes[4*a+3]}),n.forEach((s,a)=>{s.route=e.routes[a],s.labelX=e.labels[2*a],s.labelY=e.labels[2*a+1]});let i=0;for(let s of r){s.x=e.levels[i++],s.y=e.levels[i++];for(let a of s.ports)a.px=e.levels[i++],a.py=e.levels[i++]}return e.total}var Ag=24,Fi=.5,Fu=3,Bu=2,jR=Math.max(3,Fu,Bu+1),bc=.62,XR=128;function qR(e){return e.tracks?1:e.straight?2:0}function yc(e,t,n=0){let r=0;for(let M of t)M.src!==M.dst&&M.route.length>3&&(r+=(M.route.length/3-1)*jR);let i=new Float64Array(r),s=new Float64Array(r),a=new Float64Array(r),o=new Float64Array(r),c=new Float64Array(r),l=new Float64Array(r),u=new Int32Array(r),h=new Uint8Array(r),d=0,m=1/0,p=-1/0,y=NaN,E=NaN,b=NaN,S=NaN,x=(M,T,R,_,$,g)=>{let N=d-1;R===b&&_===S&&(g===_&&E===_||$===R&&y===R)&&u[N]===M&&h[N]===T&&(R-y)*($-R)+(_-E)*(g-_)>0&&(d--,R=y,_=E),y=R,E=_,b=$,S=g,h[d]=T,i[d]=Math.min(R,$),a[d]=Math.max(R,$),s[d]=R<=$?_:g,o[d]=R<=$?g:_,c[d]=Math.min(_,g),l[d]=Math.max(_,g),c[d]p&&(p=l[d]),u[d++]=M};for(let M=0;MMath.abs(R[A]-R[A-3])<.01||Math.abs(R[A+1]-R[A-2])<.01,$=A=>Math.abs(R[A]-R[A-3])+Math.abs(R[A+1]-R[A-2]),g=A=>n===0&&A>0&&A=.01&&$(A+3)>=.01&&Math.abs(R[A]-R[A-3])<.01!=Math.abs(R[A+3]-R[A])<.01,N=R[0],w=R[1];for(let A=3;Am?Math.round(Math.sqrt(d)):1,L=p>m?I/(p-m):0,O=M=>Math.min(I-1,Math.floor((M-m)*L)),v=new Int32Array(d),G=new Int32Array(I+1);for(let M=0;MMath.abs(M[T]-M[R])=3&&oe(T,_,$,$-3);)$-=3;Z.set([T[0],T[1],T[R],T[R+1],T[$],T[$+1],T[_],T[_+1]],M*8)}let H=(M,T,R,_)=>{let $=M*8+(T===1?0:4),g=Z[$],N=Z[$+1],w=Z[$+2]-g,A=Z[$+3]-N,D=w*w+A*A,U=D>0?Math.max(0,Math.min(1,((R-g)*w+(_-N)*A)/D)):0;return Math.hypot(R-g-U*w,_-N-U*A)XR)C.subarray(G[M],T).sort((R,_)=>i[R]-i[_]||R-_);else for(let R=G[M]+1;RG[M]&&i[C[$-1]]>i[_];$--)C[$]=C[$-1];C[$]=_}for(let R=G[M];Ra[_])break;if(l[A]l[_]||u[_]===u[A]||!N&&v[A]!==M)continue;let D=$*(s[A]-s[_])-g*(i[A]-i[_]),U=$*(o[A]-s[_])-g*(a[A]-i[_]);if(D>0==U>0)continue;let B=a[A]-i[A],F=o[A]-s[A],W=B*(s[_]-s[A])-F*(i[_]-i[A]),j=B*(o[_]-s[A])-F*(a[_]-i[A]);if(W>0==j>0)continue;let Q=t[u[_]],Y=t[u[A]],ne=W/(W-j),q=i[_]+ne*$,k=s[_]+ne*g,J=(te,se,re)=>(h[_]&se)!==0&&(h[A]&re)!==0||Math.abs(q-e[te].x){let i=new Set;for(let s=e[r].parent;s>=0&&!i.has(s);s=e[s].parent)i.add(s);return i};for(let[r,i]of t){if(r<0||i<0||r===i)continue;let s=n(r),a=n(i);for(let o of s)a.has(o)||(e[o].dir=void 0);for(let o of a)s.has(o)||(e[o].dir=void 0)}}function Tr(e,t,n,r){for(let i of e)i.x+=n,i.y+=r;for(let i of t){for(let s=0;s{let _={id:T,dir:R,items:[],edges:[],ports:[],portOf:new Map,routes:new Map,x:0,y:0};return s.set(T,_),_},c=o(-1,n),l=[];for(let T=0;T=0&&R{for(let R=T;R_!==T),e[T].parent=-1,c.items.push(T),d[T]=1,h[T]=0,e[T].isGroup){let _=a.length,$=o(T,e[T].dir??n);$.items=l[T],a.push($),m(_)}}for(let T=a.length-1;T>0;T--){let R=a[T],_=1/0;for(let $ of R.items)e[$].seq<_&&(_=e[$].seq);_!==1/0&&(e[R.id].seq=_)}for(let T of a)T.items.sort((R,_)=>e[R].seq-e[_].seq||R-_);let p=0;for(let T of t){let R=T.src,_=T.dst,$=0;for(;h[R]>h[_];$++)R=e[R].parent;for(;h[_]>h[R];$++)_=e[_].parent;for(;R!==_&&e[R].parent!==e[_].parent;$+=2)R=e[R].parent,_=e[_].parent;R!==_&&(p+$>YR?(T.src=R,T.dst=_):p+=$)}let y=[],E=[];for(let T=0;Th[$];)g.push(_),_=e[_].parent;for(;h[$]>h[_];)N.push($),$=e[$].parent;if(_===$){E.push(T);continue}for(;e[_].parent!==e[$].parent;)g.push(_),N.push($),_=e[_].parent,$=e[$].parent;s.get(e[_].parent).edges.push({e:T,a:_,b:$});for(let[w,A]of[[g,!0],[N,!1]])for(let D of w){let U=s.get(e[D].parent),B={e:T,inner:D,out:A,side:0,hint:NaN,px:0,py:0,route:[]};U.ports.push(B),U.portOf.set(T*2+(A?0:1),B)}}let b=new Int32Array(i),S=(T,R,_)=>(_?R.src:R.dst)!==T,x=(T,R)=>{let _=T.dir==="TB"||T.dir==="BT",$=Ec(T.dir),g=[],N=[];T.items.forEach((U,B)=>{b[U]=B;let F=e[U],W=R?Ys(_?F.w:F.h,_?F.h:F.w):Ys(0,0);W.span=F.isGroup?Math.min(F.span,W.w-2*F.padX):F.span,W.key=O?L[U]:NaN,g.push(W)});let w=(U,B,F)=>e[U].isGroup&&S(U,t[B],F),A=(U,B,F)=>{if(!R||!e[U].isGroup||!S(U,t[B],F))return 0;let W=s.get(U).portOf.get(B*2+(F?0:1));return _?W.px-e[U].w/2:W.py-e[U].h/2};for(let U of T.edges){let B=t[U.e],F=Hs(b[U.a],b[U.b],B.minlen);R&&(F.labelW=_?B.labelW:B.labelH,F.labelH=_?B.labelH:B.labelW,F.tailDx=A(U.a,U.e,!0),F.headDx=A(U.b,U.e,!1),F.tailFixed=w(U.a,U.e,!0),F.headFixed=w(U.b,U.e,!1)),N.push(F)}let D=new Int32Array(T.ports.length).fill(-1);return T.ports.forEach((U,B)=>{if(U.side===$||U.side===Po($)){let F=g.length,W=Ys(0,0,U.side===$?3:4);W.key=O?L[U.out?t[U.e].dst:t[U.e].src]:NaN,W.hint=Number.isNaN(U.hint)&&O&&G?G(T,U):U.hint,g.push(W),D[B]=F;let j=U.out?Hs(b[U.inner],F):Hs(F,b[U.inner]);U.out?(j.tailDx=A(U.inner,U.e,!0),j.tailFixed=w(U.inner,U.e,!0)):(j.headDx=A(U.inner,U.e,!1),j.headFixed=w(U.inner,U.e,!1)),N.push(j)}else g[b[U.inner]].pin=U.side===0||U.side===3?-1:1}),{lnodes:g,ledges:N,dummies:D}},I=p>1&&p<=HR&&t.length<=KR,L=new Float64Array(i).fill(NaN),O=!1,v=0,G,K=a.length>1&&I;for(let T of a)T.dir!==n&&(K=!1);if(K){let T=n==="TB"||n==="BT",R=new Int32Array(i).fill(-1),_=new Int32Array(i).fill(-1),$=[],g=[],N=[];for(let W=0;W=0?_[j]:-1:(R[W]=$.length,$.push(Ys(T?e[W].w:e[W].h,T?e[W].h:e[W].w)),g.push(j>=0?_[j]:-1))}let w=[],A=new Int32Array(t.length).fill(-1);t.forEach((W,j)=>{W.src===W.dst||R[W.src]<0||R[W.dst]<0||(A[j]=w.length,w.push(Hs(R[W.src],R[W.dst],W.minlen,T?W.labelW:W.labelH,T?W.labelH:W.labelW)))});let D=gc($,w,{...r,groups:{of:Int32Array.from(g),parent:Int32Array.from(N)},orderOnly:!0});v=Math.min(D.crossings??0,D.declared??0);let U=new Float64Array(i),B=new Int32Array(i),F=new Int32Array(i).fill(-1);for(let W=0;W=0;j=e[j].parent)U[j]+=L[W],B[j]++,F[j]=Math.max(F[j],$[R[W]].rank)}for(let W=0;W0&&(L[W]=U[W]/B[W]);G=(W,j)=>{let Q=A[j.e];if(Q<0||W.id<0||!j.out||j.side!==Po(Ec(W.dir)))return NaN;let Y=w[Q].points,ne=L[t[j.e].src],q=0;for(let k=0;k{if(!I)return{lnodes:R,ledges:_,size:gc(R,_,r)};let $=[];for(let w of R)$.push(w.w,w.h,w.kind,w.pin,w.hint,w.key,w.span);for(let w of _)$.push(w.tail,w.head,w.minlen,w.labelW,w.labelH,w.tailDx,w.headDx,+w.tailFixed,+w.headFixed);let g=C.get(T.id);g||C.set(T.id,g=[]);for(let w of g){let A=w.given.length===$.length;for(let D=0;A&&D<$.length;D++)A=Object.is(w.given[D],$[D]);if(A)return w}let N={given:$,lnodes:R,ledges:_,size:gc(R,_,r)};return g.push(N),N},oe={width:0,height:0},H=()=>{for(let R of a){for(let w of R.ports)e[w.inner].isGroup&&S(w.inner,t[w.e],w.out)&&(s.get(w.inner).portOf.get(w.e*2+(w.out?0:1)).side=w.side);if(R.edges.length===0)continue;let _=!1;for(let w of R.edges){let A=t[w.e];(e[w.a].isGroup&&A.src!==w.a||e[w.b].isGroup&&A.dst!==w.b)&&(_=!0)}if(!_)continue;let{lnodes:$,ledges:g}=x(R,!1);Do($,g),vo($,g,1);let N=Ec(R.dir);R.edges.forEach((w,A)=>{let D=t[w.e],U=!g[A].reversed;e[w.a].isGroup&&D.src!==w.a&&(s.get(w.a).portOf.get(w.e*2).side=U?Po(N):N),e[w.b].isGroup&&D.dst!==w.b&&(s.get(w.b).portOf.get(w.e*2+1).side=U?N:Po(N))})}for(let R=a.length-1;R>=0;R--){let _=a[R],$=_.id>=0?e[_.id]:void 0,g=_.dir==="TB"||_.dir==="BT",N=_.dir==="BT"||_.dir==="RL",w=x(_,!0),{lnodes:A,ledges:D,size:U}=Z(_,w.lnodes,w.ledges),B=w.dummies,F=g?U.width:U.height,W=g?U.height:U.width,j=$?$.padX:0,Q=$?$.padTop:0,Y=Math.max(F+2*j,$?$.minW:0),ne=W+Q+($?$.padBottom:0),q=(Y-F)/2,k=Q,J=(ee,ae)=>q+(g?ee:N?U.height-ae:ae),te=(ee,ae)=>k+(g?N?U.height-ae:ae:ee),se=g?0:1,re=ee=>{let ae=[];for(let ue=0;ue{e[ee].x=J(A[ae].x,A[ae].y),e[ee].y=te(A[ae].x,A[ae].y)}),_.edges.forEach((ee,ae)=>{let ue=D[ae];_.routes.set(ee.e,re(ue.points));let ce=t[ee.e];ce.labelW>0&&(ce.labelX=J(ue.labelX,ue.labelY),ce.labelY=te(ue.labelX,ue.labelY))});let P=_.edges.length;_.ports.forEach((ee,ae)=>{let ue=e[ee.inner];if(B[ae]>=0){let de=re(D[P++].points),Se=ee.out?de.length-3:0,_e=de[Se],xe=de[Se+1];ee.side===0?xe=0:ee.side===2?xe=ne:ee.side===3?_e=0:_e=Y,ee.out?de.push(_e,xe,se):de.unshift(_e,xe,se),ee.px=_e,ee.py=xe,ee.route=de;return}let ce=ue.x,pe=ue.y;if(ue.isGroup&&S(ee.inner,t[ee.e],ee.out)){let de=s.get(ee.inner).portOf.get(ee.e*2+(ee.out?0:1));ce+=de.px-ue.w/2,pe+=de.py-ue.h/2}else ee.side===0?pe-=ue.h/2:ee.side===2?pe+=ue.h/2:ee.side===3?ce-=ue.w/2:ce+=ue.w/2;let V=ce,X=pe;ee.side===0?X=0:ee.side===2?X=ne:ee.side===3?V=0:V=Y;let le=ee.side===0||ee.side===2?0:1;ee.px=V,ee.py=X,ee.route=ee.out?[ce,pe,le,V,X,le]:[V,X,le,ce,pe,le]}),$?($.w=Y,$.h=ne):oe={width:Y,height:ne}}for(let R of a){let _=R.x,$=R.y;for(let g of R.items){let N=e[g];if(N.x+=_,N.y+=$,N.isGroup){let w=s.get(g);w.x=N.x-N.w/2,w.y=N.y-N.h/2}}}let T=(R,_,$,g)=>{for(let N=0;N<_.length;N+=3){let w=_[N]+$,A=_[N+1]+g,D=R.length;D>=3&&Math.abs(R[D-3]-w)<.01&&Math.abs(R[D-2]-A)<.01||R.push(w,A,_[N+2])}};for(let R of a)for(let _ of R.edges){let $=t[_.e],g=[],N=[];for(let A=$.src;e[A].parent!==R.id;A=e[A].parent)N.push(s.get(e[A].parent));for(let A of N)T(g,A.portOf.get(_.e*2).route,A.x,A.y);T(g,R.routes.get(_.e),R.x,R.y);let w=[];for(let A=$.dst;e[A].parent!==R.id;A=e[A].parent)w.push(s.get(e[A].parent));for(let A=w.length-1;A>=0;A--)T(g,w[A].portOf.get(_.e*2+1).route,w[A].x,w[A].y);$.route=g,$.labelW>0&&($.labelX+=R.x,$.labelY+=R.y)}},z=qR(r);O=K,H();let M=-1;if(K&&(M=yc(e,t,z),M>v*zR+VR)){let T=Eg(e,t,a,oe);O=!1,H();let R=yc(e,t,z);R>=M?(O=!0,oe=xg(T,e,t,a)):M=R}if(O===K&&I){let T=!1;for(let R of a){if(R.id<0)continue;let _=e[R.id],$=R.dir==="TB"||R.dir==="BT",g=Po(Ec(R.dir)),N=[];for(let w of R.ports){if(w.side!==g)continue;let A=t[w.e].route,D=R.x+w.px,U=R.y+w.py,B=-1;for(let j=0;j=0&&W=A.length||(w.hint=A[W+F]-($?_.x-_.w/2:_.y-_.h/2),N.push([$?w.px:w.py,w.hint]))}N.sort((w,A)=>w[0]-A[0]);for(let w=1;wN[w][1]&&(T=!0)}if(T){let R=M>=0?M:yc(e,t,z),_=R>0?Eg(e,t,a,oe):void 0;_&&(H(),yc(e,t,z)>=R&&(oe=xg(_,e,t,a)))}}for(let T of E){let R=t[T],_=e[R.src],$=e[R.dst];R.route=[_.x,_.y,0,$.x,$.y,0],R.labelX=(_.x+$.x)/2,R.labelY=(_.y+$.y)/2}for(let T of y){let R=t[T],_=e[R.src];R.labelX=_.x+_.w/2+28+R.labelW/2,R.labelY=_.y}return oe}function ur(e,t){for(let n=0;ns&&m=6)return h;d>u+.5&&(u=d,l=h)}return l}function Ac(e,t,n,r){let i=t>0?r.get(Math.round(e.y-e.h/2)):void 0;if(i===void 0)return!1;let s=e.x-e.w/2;for(let a of i)if(a>s&&a=0&&c<8;u=s[u].parent)c++;let l=`color-mix(in srgb,var(--_a) ${f(100*(1-.5**c))}%,var(--_bg))`;return``+Ne(e,t,n,` fill="none" stroke="${l}" stroke-width="5" stroke-linejoin="round"`,o)+Ne(e,t,n,r,o)+""}var Lt=8,QR=12,wc=.62,Fo=6;function _c(){let e=new Map;return{add(t,n,r){let i=Rt(r);n>=0&&i>0&&i+Fo>(e.get(t*4+n)??0)&&e.set(t*4+n,i+Fo)},of:(t,n)=>n>=0?e.get(t*4+n)??0:0}}function Cn(e,t,n,r,i=n>0?n+Fo:0,s=r>0?r+Fo:0){let a=t==="linear",o=t==="step"||t==="stepBefore"||t==="stepAfter",c=[],l=[],u=[],h=(g,N,w,A)=>Math.abs(g-w)<.01&&Math.abs(N-A)<.01;for(let g=0;g=0&&Math.abs(N-c[D])>=.01&&Math.abs(w-l[D])>=.01){let U=c[D],B=l[D],F=t==="stepBefore"?B:t==="stepAfter"?w:(B+w)/2,W=t==="stepBefore"?U:t==="stepAfter"?N:(U+N)/2,j=A===0?[U,F,N,F]:[W,B,W,w];for(let Q=0;Q<4;Q+=2)h(j[Q],j[Q+1],U,B)||h(j[Q],j[Q+1],N,w)||(c.push(j[Q]),l.push(j[Q+1]),u.push(A))}c.push(N),l.push(w),u.push(A)}let d=c.length-1,m=g=>Math.abs(c[g]-c[g-1])<.01||Math.abs(l[g]-l[g-1])<.01,p=g=>a||m(g),y=(g,N,w)=>{if(!p(Math.max(g,N)))return w===0?[0,Math.sign(l[N]-l[g])||1]:[Math.sign(c[N]-c[g])||1,0];let A=c[N]-c[g],D=l[N]-l[g],U=Math.hypot(A,D)||1;return[A/U,D/U]},[E,b]=y(0,1,u[1]),[S,x]=y(d-1,d,u[d]),I=c[0],L=l[0],O=c[d],v=l[d];c[0]+=E*n,l[0]+=b*n,c[d]-=S*r,l[d]-=x*r;let G=g=>Math.abs(c[g]-c[g-1])+Math.abs(l[g]-l[g-1]),K=g=>!a&&g>0&&g=.01&&G(g+1)>=.01&&Math.abs(c[g]-c[g-1])<.01!=Math.abs(c[g+1]-c[g])<.01,C=(g,N,w)=>Math.abs(c[g]-c[g-1])*Math.abs(N)+Math.abs(l[g]-l[g-1])*Math.abs(w),Z=(g,N,w)=>{let A=Math.min(Math.max(0,g-Fo-N),w/4);return A+Math.min(g-N-A,(w-A)/4)},oe=s>r&&(!p(d)||K(d-1))?Z(s,r,C(d,S,x)):0,H=i>n&&(!p(1)||K(1))?Z(i,n,C(1,E,b)):0;oe>=1&&(c.splice(d,0,c[d]-S*oe),l.splice(d,0,l[d]-x*oe),u.splice(d,0,u[d]),d++),H>=1&&(c.splice(1,0,c[0]+E*H),l.splice(1,0,l[0]+b*H),u.splice(1,0,u[1]),d++);let z=[],M=g=>(z.push(tT(g)),f(g));z.push(77,2);let T=`M${M(c[0])},${M(l[0])}`,R=c[0],_=l[0],$=(g,N)=>{h(g,N,R,_)||(z.push(76,2),T+=`L${M(g)},${M(N)}`,R=g,_=N)};for(let g=1;g<=d;g++){let N=c[g],w=l[g];if(!p(g)){let j=u[g]===0,Q=j?w-_:N-R,Y=Math.abs(Q)*Pi(j?N-R:w-_,Q),ne=j?0:Math.sign(Q)*Y,q=j?Math.sign(Q)*Y:0;z.push(67,6),T+=`C${M(R+ne)},${M(_+q)} ${M(N-ne)},${M(w-q)} ${M(N)},${M(w)}`,R=N,_=w;continue}if(!K(g)){if(g0)continue;$(N,w);continue}let A=K(g-1)?G(g)/2:G(g),D=K(g+1)?G(g+1)/2:G(g+1);o&&(A=D=Math.min(QR,A,D));let[U,B]=y(g-1,g,u[g]),[F,W]=y(g,g+1,u[g+1]);$(N-U*A,w-B*A),R=N+F*D,_=w+W*D,o?(z.push(81,4),T+=`Q${M(N)},${M(w)} ${M(R)},${M(_)}`):(z.push(67,6),T+=`C${M(N-U*A*(1-wc))},${M(w-B*A*(1-wc))} ${M(N+F*D*(1-wc))},${M(w+W*D*(1-wc))} ${M(R)},${M(_)}`)}return{d:T,tokens:z,sx:I,sy:L,sdx:-E,sdy:-b,ex:O,ey:v,edx:S,edy:x}}function Rt(e){return e==="arrow_point"?Lt-1:e==="arrow_circle"?Lt:e==="arrow_cross"?4:0}function _t(e,t,n,r,i,s,a="none"){let o=-i,c=r;if(e==="arrow_point"){let l=t-r*Lt,u=n-i*Lt,h=Lt*.42;return``}if(e==="arrow_circle")return``;if(e==="arrow_cross"){let l=t-r*4,u=n-i*4,h=3.5,d=(r+o)*h,m=(i+c)*h,p=(r-o)*h,y=(i-c)*h;return``}return""}var ZR=Array.from({length:23},(e,t)=>+`1e${t}`);function JR(e){return Sg(eT(e))}function eT(e){let t=[],n=-1;for(let r=0;r=65&&i<=90&&i!==69)n=t.length+1,t.push(i,0),r++;else if(i===45||i===46||i>=48&&i<=57){let s=i===45?r+1:r,a=0,o=-1;for(let l=e.charCodeAt(s);l>=48&&l<=57||l===46&&o<0;l=e.charCodeAt(++s))l===46?o=0:(a=a*10+l-48,o>=0&&o++);let c;if((e.charCodeAt(s)|32)===101||a>Number.MAX_SAFE_INTEGER||o>22){for(let l=e.charCodeAt(s);l===46||l===101||l===69||l>=48&&l<=57||(l===45||l===43)&&(e.charCodeAt(s-1)|32)===101;l=e.charCodeAt(++s));c=Number(e.slice(r,s))}else c=o>0?a/ZR[o]:a,i===45&&(c=-c);n>=0&&(t.push(c),t[n]++),r=s}else r++}return t}function tT(e){let t=Math.round(e*100);return t===0?0:t/100}function Sg(e){let t=[],n=0,r=0;for(let i=0;i0&&t.push(NaN,NaN),n=e[l],r=e[l+1],t.push(n,r)}return t}function nT(e,t,n,r,i,s,a,o,c){let l=(t-o)/2,u=(n-c)/2;if(r===0||i===0||l===0&&u===0){e.push(o,c);return}let h=Math.max(1,Math.sqrt(l*l/(r*r)+u*u/(i*i)));r*=h,i*=h;let d=(s===a?-1:1)*Math.sqrt(Math.max(0,(r*r*i*i-r*r*u*u-i*i*l*l)/(r*r*u*u+i*i*l*l))),m=d*r*u/i+(t+o)/2,p=-d*i*l/r+(n+c)/2,y=Math.atan2((n-p)/i,(t-m)/r),E=Math.atan2((c-p)/i,(o-m)/r)-y;a&&E<0?E+=2*Math.PI:!a&&E>0&&(E-=2*Math.PI);for(let b=1;b<=8;b++)e.push(m+r*Math.cos(y+E*b/8),p+i*Math.sin(y+E*b/8))}function rT(e,t,n,r,i,s,a,o){let c=0,l=1;for(let u=0;u<4;u++){let h=u===0?-n:u===1?n:u===2?-r:r,d=u===0?e-i:u===1?a-e:u===2?t-s:o-t;h===0?d<0&&(l=-1):h<0?c=Math.max(c,d/h):l=Math.min(l,d/h)}return cr&&c>r||oi&&l>i)&&rT(a,o,c-a,l-o,t,n,r,i))return!0}return!1}function Bo(e,t,n,r){if(n.length===0)return;let i=r?Sg(r):JR(e),s=1/0,a=1/0,o=-1/0,c=-1/0;for(let h=0;ho&&(o=d),mc&&(c=m)}let l,u=1/0;for(let h of n){let[d,m,p,y]=h.box;if(op-.5||cy-.5)continue;let E=sT(i,d+.5,m+.5,p-.5,y-.5);for(let S=0;Sd+.5&&t[S]m+.5&&t[S+1]p||ay)return"";let b=(p-d)*(y-m);bn.includes(u)?new RegExp(`[";]${u}:([^;"]+);`).exec(n)?.[1].trim():void 0,s=i("stroke");if(s==="none"||s==="transparent")return"";let a=r?"2.5":i("stroke-width"),o="",c="";a!==void 0&&/^[\d.]+(?:px)?$/.test(a)?parseFloat(a)!==1&&(o=` stroke-width="${f(parseFloat(a)+Wu)}"`):a!==void 0&&(c+=`stroke-width:calc(${a} + ${Wu}px);`);for(let u of["opacity","stroke-opacity"]){let h=i(u);h!==void 0&&(c+=`${u}:${h};`)}let l=``+t.replace(/ class="pele-marker"/g,"");return o||c?`${l}`:l}function Cr(e,t,n,r="",i=!1){return Go(e.d,_t(t,e.sx,e.sy,e.sdx,e.sdy,"var(--_bg)","var(--_bg)")+_t(n,e.ex,e.ey,e.edx,e.edy,"var(--_bg)","var(--_bg)"),r,i)}function Dn(e){return e?`${e}`:""}function dn(e,t,n,r,i,s){let a=t.width+8,o=t.height;return``+Ne(t,n,r,i,s)+""}function Rc(e,t,n,r,i,s,a,o){let c=(i?t:n)/2,l=Math.min(c-4,8+r*6),u=s+r*8,h=Math.hypot(u,l)||1,d=(y,E)=>i?`${f(e.x+E)},${f(e.y+n/2+y)}`:`${f(e.x+t/2+y)},${f(e.y+E)}`,m=u/h*a,p=l/h*a;return i?(o.labelX=e.x,o.labelY=e.y+n/2+u+4+o.labelH/2):(o.labelX=e.x+t/2+u+4+o.labelW/2,o.labelY=e.y),{d:`M${d(0,-l)}C${d(u,-l*2)} ${d(u,l*2)} ${d(m,l+p)}`,sx:i?e.x-l:e.x+t/2,sy:i?e.y+n/2:e.y-l,sdx:i?0:-1,sdy:i?-1:0,ex:i?e.x+l:e.x+t/2,ey:i?e.y+n/2:e.y+l,edx:i?-l/h:-u/h,edy:i?-u/h:-l/h}}var Tg="--_bg:var(--pele-bg,#fff);--_fg:var(--pele-fg,#1f1f1f);--_m:var(--pele-muted,#6e6e6e);--_l:var(--pele-line,#1f1f1f);--_s:var(--pele-surface,#f3f3f3);--_a:var(--pele-surface-alt,#e6e6e6);--_b:var(--pele-border,#8a8a8a);--_c:var(--pele-accent,#5b7bd5);color:var(--_fg)",fr="var(--_fm)",Mg="var(--pele-radius,4px)",ht=' style="rx:var(--_r)"',iT=/[";]fill:/,vn=e=>iT.test(e);function At(e){let t=e.indexOf(' style="');return t<0?e+ht:`${e.slice(0,t+8)}rx:var(--_r);${e.slice(t+8)}`}var Yo="var(--pele-critical,#e45756)",wg=String.raw`(?:"[^"'\\\n<>{}();:@]*"|'[^"'\\\n<>{}();:@]*'|[\p{L}\p{N}_-][\p{L}\p{N}_ .-]*)`,oT=new RegExp(String.raw`^\s*${wg}(?:\s*,\s*${wg})*\s*$`,"u");function _g(e,t){return e&&oT.test(e)?e:t}function Cg(e,t,n){return`;--_fm:var(--pele-font-mono,${_g(n,"monospace")});font:${e}px sans-serif;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;font-family:var(--pele-font,${_g(t,"sans-serif")})`}var aT=new Set(["fill","fill-opacity","stroke","stroke-width","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-opacity","opacity","rx","ry"]),cT=new Set(["color","font-size","font-family","font-weight","font-style","text-decoration","letter-spacing","word-spacing","opacity"]),lT=/url\s*\(|expression\s*\(|javascript:|[<>{};\\]|@import|image-set|\/\*/i,Rg={shape:"",line:"",text:"",stroke:void 0,bold:!1,italic:!1,fontSize:void 0};function Ct(e){if(e.length===0)return Rg;let t=new Map,n=new Map;for(let l of e){let u=l.indexOf(":");if(u<=0)continue;let h=l.slice(0,u).trim().toLowerCase(),d=l.slice(u+1).replace(/!important/gi,"").trim();d===""||lT.test(d)||rc.test(d)||(aT.has(h)&&t.set(h,d),cT.has(h)&&n.set(h==="color"?"fill":h,d))}if(t.size===0&&n.size===0)return Rg;let r="",i="";for(let[l,u]of t)r+=`${l}:${u};`,l!=="fill"&&l!=="fill-opacity"&&(i+=`${l}:${u};`);let s="";for(let[l,u]of n)s+=`${l}:${u};`;let a=n.get("font-weight"),o=n.get("font-size"),c=o&&/^[\d.]+(px)?$/.test(o)?parseFloat(o):void 0;return{shape:r?` style="${rt(r)}"`:"",line:i?` style="${rt(i)}"`:"",text:s?` style="${rt(s)}"`:"",stroke:t.get("stroke"),bold:a==="bold"||a==="bolder"||Number(a)>=600,italic:n.get("font-style")==="italic",fontSize:c!==void 0&&c>0&&c<=200?c:void 0}}var dT=/[^\w-]+/g;function It(e){let t=e.replace(dT," ").trim();return t===""?"":" "+t}var uT=["#4c78a8","#f58518","#54a24b","#e45756","#72b7b2","#eeca3b","#b279a2","#9d755d"];function Et(e){let t=(e%8+8)%8;return`var(--pele-series-${t+1},${uT[t]})`}var fT=[["tw","title"],["hw","heading"],["w","bold"]],hT=/var\(--_(r|tw|hw|w)\)/g;function at(e,t,n,r,i,s,a){let o=rt(i.idPrefix??"pele"),c="",l="";s.accTitle&&(c+=`${Ue(s.accTitle)}`,l+=` aria-labelledby="${o}-title"`),s.accDescr&&(c+=`${Ue(s.accDescr)}`,l+=` aria-describedby="${o}-desc"`);let u=i.responsive===!1?"":"max-width:100%;height:auto;",h=new Set;for(let[,m]of a.matchAll(hT))if(h.add(m),h.size===4)break;let d=h.has("r")?`;--_r:${Mg}`:"";for(let[m,p]of fT)h.has(m)&&(d+=`;--_${m}:var(--pele-${p}-weight,bold)`);return``+c+a+""}var Tt=18,Mt=12,Wi=12,Gn=(e,t,n)=>(n?t:e)-2*Wi,Ho=e=>(t,n,r)=>r?0:t-2*e(n)-2*Wi;function Nc(e,t,n){let r=Math.min(1,Math.abs(e)/t);return n*(1-Math.sqrt(1-r*r))}var Ks=(e,t,n,r)=>n&1?Nc(r,t/2,e/2):Nc(r,e/2,t/2),zs=(e,t,n)=>(n?t:e)*.6,Ng=(e,t,n,r)=>n&1?0:Nc(r,e/2,Math.min(12,Math.max(6,e/14))),Vs=(e,t)=>()=>({w:e,h:t,dy:0});function Ig(e,t,n){let r=Math.max(1.6*e+40,80),i=(t+10)/(1-(e+8)/r),s=i/2-10-t/2;return{w:r,h:i,dy:n?-s:s}}function Bi(e,t){return``}var Tc=(e,t,n)=>n&1?t/8:0,Ko=(e,t)=>({w:Math.max(e+2*Tt,2*Tt+12),h:t+2*Mt,dy:0});function Nn(e,t){let n="";for(let r=0;r`}function xn(e,t,n,r=""){return``}var kg={rect:{size:Ko,span:Gn,draw:(e,t,n)=>xn(e,t,At(n))},rounded:{size:Ko,span:Gn,draw:(e,t,n)=>xn(e,t,n,` rx="${f(Math.min(12,t/2))}"`)},stadium:{inset:(e,t,n,r)=>n&1?Nc(r,t/2,t/2):0,span:(e,t,n)=>n?t*.6:e-t,size:(e,t)=>{let n=t+2*Mt;return{w:e+n*.5+2*Tt-8,h:n,dy:0}},draw:(e,t,n)=>xn(e,t,n,` rx="${f(t/2)}"`)},"fr-rect":{span:Gn,size:(e,t)=>({w:e+2*Tt+16,h:t+2*Mt,dy:0}),draw:(e,t,n,r)=>{let i=e/2-8;return xn(e,t,At(n))+``}},cyl:{inset:Ng,span:(e,t,n)=>n?t-2*Wi-12:e*.6,size:(e,t)=>{let n=Math.max(e+2*Tt,56),r=Math.min(12,Math.max(6,n/14));return{w:n,h:t+2*Mt+2*r,dy:r/2}},draw:(e,t,n,r)=>{let i=e/2,s=Math.min(12,Math.max(6,e/14)),a=-t/2+s,o=t/2-s;return``}},circle:{inset:Ks,span:zs,size:(e,t)=>{let n=Math.max(Math.sqrt(e*e+t*t)+16,44);return{w:n,h:n,dy:0}},draw:(e,t,n)=>``},"dbl-circ":{inset:Ks,span:zs,size:(e,t)=>{let n=Math.max(Math.sqrt(e*e+t*t)+26,54);return{w:n,h:n,dy:0}},draw:(e,t,n,r)=>``},ellipse:{inset:Ks,span:zs,size:(e,t)=>({w:e*1.3+2*Tt,h:t*1.2+2*Mt,dy:0}),draw:(e,t,n)=>``},diam:{inset:(e,t,n,r)=>n&1?Math.abs(r)*e/t:Math.abs(r)*t/e,span:(e,t,n)=>(n?t:e)*.6,size:(e,t)=>{let n=e+16,r=t+8;return{w:n+1.6*r,h:n/1.6+r,dy:0}},draw:(e,t,n)=>Nn([0,-t/2,e/2,0,0,t/2,-e/2,0],n)},hex:{inset:(e,t,n,r)=>n&1?Math.abs(r)/2:0,span:(e,t,n)=>n?t*.5:e-t/2-Wi,size:(e,t)=>{let n=t+2*Mt;return{w:e+2*Tt+n/2,h:n,dy:0}},draw:(e,t,n)=>{let r=t/4;return Nn([-e/2+r,-t/2,e/2-r,-t/2,e/2,0,e/2-r,t/2,-e/2+r,t/2,-e/2,0],n)}},odd:{inset:(e,t,n)=>n===3?t/4:0,span:Ho(()=>0),size:(e,t)=>{let n=t+2*Mt;return{w:e+2*Tt+n/4,h:n,dy:0}},draw:(e,t,n)=>{let r=t/4;return Nn([-e/2,-t/2,e/2,-t/2,e/2,t/2,-e/2,t/2,-e/2+r,0],n)}},"lean-r":{inset:Tc,span:Ho(e=>e/4),size:(e,t)=>{let n=t+2*Mt;return{w:e+2*Tt+n/2,h:n,dy:0}},draw:(e,t,n)=>{let r=t/4;return Nn([-e/2+r,-t/2,e/2,-t/2,e/2-r,t/2,-e/2,t/2],n)}},"lean-l":{inset:Tc,span:Ho(e=>e/4),size:(e,t)=>{let n=t+2*Mt;return{w:e+2*Tt+n/2,h:n,dy:0}},draw:(e,t,n)=>{let r=t/4;return Nn([-e/2,-t/2,e/2-r,-t/2,e/2,t/2,-e/2+r,t/2],n)}},"trap-b":{inset:Tc,span:Ho(e=>e/4),size:(e,t)=>{let n=t+2*Mt;return{w:e+2*Tt+n/2,h:n,dy:0}},draw:(e,t,n)=>{let r=t/4;return Nn([-e/2+r,-t/2,e/2-r,-t/2,e/2,t/2,-e/2,t/2],n)}},"trap-t":{inset:Tc,span:Ho(e=>e/4),size:(e,t)=>{let n=t+2*Mt;return{w:e+2*Tt+n/2,h:n,dy:0}},draw:(e,t,n)=>{let r=t/4;return Nn([-e/2,-t/2,e/2,-t/2,e/2-r,t/2,-e/2+r,t/2],n)}},text:{bare:!0,span:Gn,size:(e,t)=>({w:e+8,h:t+8,dy:0}),draw:(e,t)=>xn(e,t,' fill="none" stroke="none"')},"sm-circ":{noLabel:!0,inset:Ks,span:zs,size:Vs(14,14),draw:(e,t,n)=>``},"f-circ":{noLabel:!0,inset:Ks,span:zs,size:Vs(14,14),draw:(e,t,n,r)=>``},"fr-circ":{noLabel:!0,inset:Ks,span:zs,size:Vs(18,18),draw:(e,t,n,r)=>``},fork:{noLabel:!0,span:(e,t,n)=>(n?t:e)-8,size:Vs(72,8),draw:(e,t,n,r)=>xn(e,t,` fill="var(--_l)"${r}`,' rx="2"')},"notch-rect":{size:Ko,span:Gn,draw:(e,t,n)=>Nn([-e/2+10,-t/2,e/2,-t/2,e/2,t/2,-e/2,t/2,-e/2,-t/2+10],n)},"lin-rect":{span:Gn,size:(e,t)=>({w:e+2*Tt+8,h:t+2*Mt,dy:0}),draw:(e,t,n,r)=>xn(e,t,At(n))+``},"div-rect":{span:Gn,size:(e,t)=>({w:e+2*Tt,h:t+2*Mt+8,dy:4}),draw:(e,t,n,r)=>xn(e,t,At(n))+``},"win-pane":{span:Gn,size:(e,t)=>({w:e+2*Tt+8,h:t+2*Mt+8,dy:4}),draw:(e,t,n,r)=>xn(e,t,At(n))+``},tri:{inset:(e,t,n)=>n&1?e/4:0,size:(e,t)=>Ig(e,t,!1),draw:(e,t,n)=>Nn([0,-t/2,e/2,t/2,-e/2,t/2],n)},"flip-tri":{inset:(e,t,n)=>n&1?e/4:0,size:(e,t)=>Ig(e,t,!0),draw:(e,t,n)=>Nn([-e/2,-t/2,e/2,-t/2,0,t/2],n)},"sl-rect":{inset:(e,t,n)=>n===0?5:0,size:(e,t)=>({w:e+2*Tt,h:t+2*Mt+10,dy:5}),draw:(e,t,n)=>Nn([-e/2,-t/2+10,e/2,-t/2,e/2,t/2,-e/2,t/2],n)},"notch-pent":{span:Gn,size:(e,t)=>({w:e+2*Tt,h:t+2*Mt,dy:0}),draw:(e,t,n)=>Nn([-e/2+10,-t/2,e/2-10,-t/2,e/2,-t/2+10,e/2,t/2,-e/2,t/2,-e/2,-t/2+10],n)},hourglass:{noLabel:!0,inset:(e,t,n)=>n&1?e/2:0,size:Vs(32,40),draw:(e,t,n)=>Nn([-e/2,-t/2,e/2,-t/2,-e/2,t/2,e/2,t/2],n)},delay:{size:(e,t)=>{let n=t+2*Mt;return{w:e+2*Tt+n/4,h:n,dy:0}},draw:(e,t,n)=>{let r=t/2;return``}},"h-cyl":{size:(e,t)=>{let n=t+2*Mt,r=Math.min(12,n/4);return{w:e+2*Tt+2*r,h:n,dy:0}},draw:(e,t,n,r)=>{let i=t/2,s=Math.min(12,t/4),a=-e/2+s,o=e/2-s;return``}},"cross-circ":{noLabel:!0,inset:Ks,span:zs,size:Vs(44,44),draw:(e,t,n,r)=>{let i=e/2,s=i*Math.SQRT1_2;return``}},"st-rect":{span:(e,t,n)=>(n?t:e)-2*Wi-8,size:(e,t)=>({w:e+2*Tt+8,h:t+2*Mt+8,dy:4}),draw:(e,t,n)=>{let r=e-8,i=t-8,s="";for(let a=0;a<3;a++){let o=-e/2+(2-a)*4,c=-t/2+a*4;s+=``}return s}},doc:{inset:(e,t,n)=>n===2?10:0,size:(e,t)=>({w:e+2*Tt,h:t+2*Mt+10,dy:-5}),draw:(e,t,n)=>Cc(e,t,n)},flag:{inset:(e,t,n)=>n&1?0:8,size:(e,t)=>({w:e+2*Tt,h:t+2*Mt+16,dy:0}),draw:(e,t,n)=>{let r=e/2,i=t/2-8,s=e/4;return``}},datastore:{size:Ko,span:Gn,draw:(e,t,n,r)=>xn(e,t,n.replace('stroke="var(--_b)"','stroke="none"'))+``},folder:{size:(e,t)=>({w:Math.max(e+2*Tt,64),h:t+2*Mt+8,dy:4}),draw:(e,t,n)=>{let r=e/2,i=t/2,s=Math.min(e*.4,48);return Bi(`M${f(-r)},${f(-i)}H${f(-r+s)}L${f(-r+s+8)},${f(-i+8)}H${f(r)}V${f(i)}H${f(-r)}Z`,n)}},bucket:{size:(e,t)=>({w:e+2*Tt+20,h:t+2*Mt+10,dy:3}),inset:(e,t,n)=>n&1?t/12:0,draw:(e,t,n,r)=>{let i=e/2,s=t/2,a=5,o=t/6;return Bi(`M${f(-i)},${f(-s+a)}A${f(i)},${f(a)} 0 0 1 ${f(i)},${f(-s+a)}L${f(i-o)},${f(s-a)}A${f(i-o)},${f(a)} 0 0 1 ${f(-i+o)},${f(s-a)}Z`,n)+``}},console:{span:Gn,size:(e,t)=>({w:Math.max(e+2*Tt,72),h:t+2*Mt+12,dy:6}),draw:(e,t,n,r)=>xn(e,t,At(n))+``},browser:{span:Gn,size:(e,t)=>({w:Math.max(e+2*Tt,72),h:t+2*Mt+12,dy:6}),draw:(e,t,n,r)=>{let i="";for(let s=0;s<3;s++)i+=``;return xn(e,t,At(n))+``+i}},person:{size:(e,t)=>({w:Math.max(e+2*Tt,56),h:t+2*Mt+26,dy:13}),draw:(e,t,n)=>{let r=-t/2;return``}},bang:{size:(e,t)=>({w:e+2*Tt+28,h:t+2*Mt+24,dy:0}),inset:()=>3,draw:(e,t,n)=>{let i=[];for(let s=0;s<28;s++){let a=Math.PI*s/14-Math.PI/2,o=s%2===0?1:.82;i.push(Math.cos(a)*(e/2)*o,Math.sin(a)*(t/2)*o)}return Nn(i,n)}},cloud:{size:(e,t)=>({w:e+2*Tt+32,h:t+2*Mt+24,dy:0}),inset:(e,t,n)=>n&1?2:1,draw:(e,t,n)=>{let r=e/2,i=t/2,s=i*.55;return Bi(`M${f(-r+s)},${f(i)}A${f(s)},${f(s)} 0 0 1 ${f(-r+s*.6)},${f(-i*.1)}A${f(r*.42)},${f(i*.7)} 0 0 1 ${f(-r*.1)},${f(-i*.72)}A${f(r*.4)},${f(i*.62)} 0 0 1 ${f(r*.62)},${f(-i*.42)}A${f(s*1.05)},${f(s*1.05)} 0 0 1 ${f(r-s)},${f(i)}Z`,n)}},brace:{bare:!0,size:(e,t)=>({w:e+2*Tt+12,h:t+2*Mt,dy:0}),draw:(e,t,n,r)=>xn(e,t,' fill="none" stroke="none"')+Mc(-e/2+12,t,-1,r)},"brace-r":{bare:!0,size:(e,t)=>({w:e+2*Tt+12,h:t+2*Mt,dy:0}),draw:(e,t,n,r)=>xn(e,t,' fill="none" stroke="none"')+Mc(e/2-12,t,1,r)},braces:{bare:!0,size:(e,t)=>({w:e+2*Tt+24,h:t+2*Mt,dy:0}),draw:(e,t,n,r)=>xn(e,t,' fill="none" stroke="none"')+Mc(-e/2+12,t,-1,r)+Mc(e/2-12,t,1,r)},bolt:{noLabel:!0,size:Vs(36,56),inset:(e,t,n)=>n&1?e/4:0,draw:(e,t,n)=>Nn([e*.15,-t/2,-e/2,t*.08,-e*.05,t*.08,-e*.15,t/2,e/2,-t*.08,e*.05,-t*.08],n)},"lin-cyl":{inset:Ng,span:(e,t,n)=>n?t-2*Wi-20:e*.6,size:(e,t)=>{let n=Math.max(e+2*Tt,56),r=Math.min(12,Math.max(6,n/14));return{w:n,h:t+2*Mt+2*r+8,dy:r/2+4}},draw:(e,t,n,r)=>{let i=e/2,s=Math.min(12,Math.max(6,e/14)),a=-t/2+s,o=t/2-s,c=l=>`M${f(-i)},${f(l)}A${f(i)},${f(s)} 0 0 0 ${f(i)},${f(l)}`;return Bi(`M${f(-i)},${f(a)}A${f(i)},${f(s)} 0 0 1 ${f(i)},${f(a)}V${f(o)}A${f(i)},${f(s)} 0 0 1 ${f(-i)},${f(o)}Z`,n)+``}},"curv-trap":{size:(e,t)=>{let n=t+2*Mt;return{w:e+2*Tt+n*.6,h:n,dy:0}},draw:(e,t,n)=>{let r=e/2,i=t/2,s=t*.3;return Bi(`M${f(-r+s)},${f(-i)}H${f(r-s)}A${f(s)},${f(i)} 0 0 1 ${f(r-s)},${f(i)}H${f(-r+s)}L${f(-r)},0Z`,n)}},docs:{size:(e,t)=>({w:e+2*Tt+8,h:t+2*Mt+18,dy:-1}),inset:(e,t,n)=>n===2?10:0,draw:(e,t,n)=>{let r="";for(let i=0;i<3;i++)r+=`${Cc(e-8,t-8,n)}`;return r}},"bow-rect":{size:(e,t)=>{let n=t+2*Mt;return{w:e+2*Tt+n*.4,h:n,dy:0}},inset:(e,t,n)=>n===1?t*.2:0,draw:(e,t,n)=>{let r=e/2,i=t/2,s=t*.2;return Bi(`M${f(-r+s)},${f(-i)}H${f(r)}A${f(s)},${f(i)} 0 0 0 ${f(r)},${f(i)}H${f(-r+s)}A${f(s)},${f(i)} 0 0 1 ${f(-r+s)},${f(-i)}Z`,n)}},"tag-rect":{size:Ko,span:Gn,draw:(e,t,n,r)=>xn(e,t,At(n))+``},"tag-doc":{size:(e,t)=>({w:e+2*Tt,h:t+2*Mt+10,dy:-5}),inset:(e,t,n)=>n===2?10:0,draw:(e,t,n,r)=>Cc(e,t,n)+``},"lin-doc":{size:(e,t)=>({w:e+2*Tt+8,h:t+2*Mt+10,dy:-5}),inset:(e,t,n)=>n===2?10:0,draw:(e,t,n,r)=>Cc(e,t,n)+``},collapsedGroup:{size:(e,t)=>({w:e+2*Tt+8,h:t+2*Mt+8,dy:-2}),draw:(e,t,n)=>``}};function Mc(e,t,n,r){let i=t/2,s=6*n;return``}function Cc(e,t,n){let r=e/2,i=-t/2,s=t/2-10,a=e/4;return``}var Uu=kg.rect,Ui=new Map(Object.entries(kg));function ps(e,t,n){return(Ui.get(e)??Uu).size(t,n)}function hr(e,t,n,r,i){return(Ui.get(e)??Uu).draw(t,n,r,i)}function Qr(e,t,n,r,i=0){return Ui.get(e)?.inset?.(t,n,r,i)??0}function $g(e,t,n,r){return Math.max(0,Ui.get(e)?.span?.(t,n,r)??0)}function Lg(e){return Ui.get(e)?.noLabel!==!0}function Gi(e){return(Ui.get(e)??Uu).bare!==!0}function Jn(e,t,n){let r=e[t]-n.x,i=e[t+1]-n.y;return Math.abs(Math.abs(i)-n.h/2)<.5?i<0?0:2:Math.abs(Math.abs(r)-n.w/2)<.5?r<0?3:1:-1}function js(e,t,n,r){if(r.isGroup)return;let i=Jn(e,t,r);if(i===0||i===2){let s=Qr(n.shape,n.w,n.h,i,e[t]-r.x)+(r.h-n.h)/2;e[t+1]+=i===0?s:-s}else if(i>=0){let s=Qr(n.shape,n.w,n.h,i,e[t+1]-r.y)+(r.w-n.w)/2;e[t]+=i===3?s:-s}}var pT=1.5,Fg=1.3,mT=/|\\n|\n/gi,Og=/<\/?([a-zA-Z][\w-]*)(?:\s[^<>]*)?\/?>/y,Dg=/(fa[bklrs]?):fa-([\w-]+)/g,gT=/[<\\\n*_]|fa[bklrs]?:fa-/,bT=new Map([["b",1],["strong",1],["i",2],["em",2],["cite",2],["dfn",2],["var",2],["code",4],["kbd",4],["samp",4],["tt",4],["sub",8],["sup",16],["u",32],["ins",32]]),yT=24,ET=new Set("a abbr address article aside audio b bdi bdo big blockquote body br button caption center cite code col colgroup data dd del details dfn dialog div dl dt em embed fieldset figcaption figure font footer form h1 h2 h3 h4 h5 h6 head header hr html i iframe img input ins kbd label legend li link main map mark meta meter nav noscript object ol optgroup option output p picture pre progress q rp rt ruby s samp script section select small source span strike strong style sub summary sup table tbody td template textarea tfoot th thead time title tr track tt u ul var video wbr".split(" ")),Hu="\\u2e80-\\u9fff\\uf900-\\ufaff\\uff00-\\uff60",vg="、。,.:;!?)]}」』】〕〉》〙〗ー…‥・ゝゞぁぃぅぇぉっゃゅょゎァィゥェォッャュョヮ,.:;!?)\\]}",xT="([{「『【〔〈《〘〖([{",AT=new RegExp(`[${Hu}]`),Ic="\\u200b\\u00ad",ST=new RegExp(`[${Ic}]`),wT=new RegExp(`\\s*(?:[${xT}]*[${Hu}][${vg}]*|[^\\s${Hu}${Ic}]+[${Ic}]*[${vg}]*|[${Ic}]+)\\s*|\\s+`,"g"),Bg=57344,_T=6400,RT=/\$\$(.+?)\$\$/g,Wg=/[\ue000-\uf8ff]/,TT=/([\ue000-\uf8ff])/,zo,MT={lines:[],widths:[],width:0,height:0,size:0,lineHeight:0};function CT(e){let t=e.split(` +`),n=1/0;for(let r of t){if(r.trim()==="")continue;let i=r.length-r.trimStart().length;ir.slice(Math.min(n,r.length-r.trimStart().length))).join(` +`)}function kc(e){return e!==void 0&&e.icon===void 0&&e.math===void 0}function Gu(e,t,n){if(t!==""){if(zo!==void 0&&Wg.test(t)){let r=zo,i=t.split(TT);for(let s=0;s{NT(e,o,s|(i.shifts[i.shifts.length-1]??0)),o=""};for(;c0?t[c-1]:" ",b=c+p{let u=a[a.length-1];if(kc(u)){let h=u.text.trimEnd();if(l&&u.text.endsWith("­")&&(h=h.slice(0,-1)+"-"),h!==u.text){u.text=h;let d=t.width(h,n,u.style);o+=d-u.width,u.width=d}}i.push(a),s.push(o),a=[],o=0};for(let l of e){if(l.icon!==void 0||l.math){let y=l.math?l.math.width:n*1.25;o>0&&o+y>r&&c(),a.push({...l,width:y}),o+=y;continue}let u=l.text.match(wT)??[],h=l.text.includes("­"),d=h?u.length:0,m=new Float64Array(d),p=new Float64Array(d+1);for(let y=d-1;y>=0;y--){let E=u[y].endsWith("­"),b=u[y].trimEnd();m[y]=t.width(E?b.slice(0,-1):b,n,l.style),p[y]=E?y===d-1?l===e[e.length-1]?m[y]:1/0:m[y]+p[y+1]:m[y]}for(let y=0;y0&&!S&&(c(E.trimStart()===E),E=E.trimStart());let x=a[a.length-1];if(kc(x)&&x.style===l.style){if(x.text+=E,b>0||E.trimEnd()!==E){let I=x.width;x.width=t.width(x.text,n,x.style),o+=x.width-I}}else{let I=t.width(E,n,l.style);a.push({text:E,style:l.style,width:I}),o+=I}}}(a.length>0||i.length===0)&&c()}function Ge(e,t,n,r,i,s=0){if(e===void 0||e==="")return MT;let a=Math.round(r*pT);if(am()&&e.includes("$$")&&!Wg.test(e)){let o={tex:[],math:[]},c=e.replace(RT,(l,u)=>o.tex.length===_T?l:(o.tex.push(u),String.fromCharCode(Bg+o.tex.length-1)));if(o.tex.length>0){for(let l of o.tex)o.math.push(cm(bt(l),r));return Pg(c,t,n,r,i,s,a,o)}}if(!gT.test(e)&&!e.includes("&")&&!e.includes("fl")){let o=e.trim(),c=n.width(o,r,s);if(c<=i||!(o.includes(" ")||AT.test(o)||ST.test(o)))return{lines:[[{text:o,style:s,width:c}]],widths:[c],width:c,height:a,size:r,lineHeight:a};let l=[],u=[];Ug([{text:o,style:s,width:c}],n,r,i,l,u);let h=0;for(let m of u)m>h&&(h=m);let d=l.length>1?Math.round(r*Fg):a;return{lines:l,widths:u,width:h,height:l.length*d,size:r,lineHeight:d}}return Pg(e,t,n,r,i,s,a)}function Pg(e,t,n,r,i,s,a,o){let c=zo;zo=o;try{let l=$T(e,t,n,r,i,s,a);return o?Vo(l):l}finally{zo=c}}function $T(e,t,n,r,i,s,a){let o=t?CT(e.replace(/\r\n?/g,` +`)).trim():e.trim(),c=[],l=[],u=0,h={style:s,shifts:[]};for(let m of o.split(mT)){let p=[];IT(p,m.trim(),t,s,h);let y=kT(p,n,r);y>i?Ug(p,n,r,i,c,l):(c.push(p),l.push(y))}for(let m of l)m>u&&(u=m);let d=c.length>1?Math.round(r*Fg):a;return{lines:c,widths:l,width:u,height:c.length*d,size:r,lineHeight:d}}function Vo(e){let t;for(let r=0;re.lineHeight)),t&&(t[r]=i)}if(t===void 0)return e.heights===void 0?e:{...e,heights:void 0,height:e.lines.length*e.lineHeight};let n=0;for(let r of t)n+=r;return{...e,heights:t,height:n}}function Yi(e){for(let t of e)if(t.math)return!0;return!1}function Nr(e,t){let n=e.heights;if(!n)return(t+.5)*e.lineHeight;let r=0;for(let i=0;i0)||i.width<=s)return i;let a=Math.min(n,t),o=t;i=r(o,!0);for(let c=0;c<3&&i.width>s&&o>a;c++)o=Math.max(a,o-(i.width-s)),i=r(o,!0);return i}function kt(e){let t=e.maxWidth;return t!==void 0&&t>0?Math.max(80,t-2*(e.padding??8)):4e3}function gs(e,t,n,r=0){let i=e.maxWidth;return i===void 0||!(i>0)?t:Math.max(Math.min(n,t),Math.min(t,i-r))}var LT=640;function Pt(e,t){let n=t(!1),r=e.maxWidth;if(e.autoDirection===!1||r===void 0||!(r>0)||n.width<=r)return n;let i=e.directionBreakpoint;if(r>=(i!==void 0&&i>0?i:LT))return n;let s=t(!0);return s.width0)||n.width<=r)return n;let i=t(!0);return i.widthMath.max(1,e-Gg),DT=(e,t)=>{let n=Gg+e%OT(t);return t>0?n%t:n};function Yg(e,t,n,r){let i=n.size;for(let s of e){if(s.isGroup||s.shape==="collapsedGroup"){s.colorIndex=DT(n.get(s.id)??i++,r);continue}let a=t(s.id);a&&Xs.has(a)&&(s.kind=a)}}function Hg(e,t,n){let r=[],i=[],s=e.subgraphs,a=b=>{let S=[];for(let x of b){let I=e.classes.get(x);I?.styles&&(S=[...S,...I.styles].map(L=>L.trim())),I?.textStyles&&(S=[...S,...I.textStyles].map(L=>L.trim()))}return S},o=new Set,c=new Map,l=new Set;for(let b of s){if(b.metadata?.view!=="collapsed"||o.has(b.id))continue;let S=[b.id];for(;S.length>0;){let x=e.subgraph(S.pop())?.nodes;if(x!==void 0)for(let I of x)I===b.id||o.has(I)||(o.add(I),c.set(I,b.id),l.has(I)||S.push(I))}l.add(b.id)}let u=new Map;for(let b of o){let S=[b],x=c.get(b);for(;;){let I=u.get(x),L=I??c.get(x);if(L===void 0||(I===void 0&&S.push(x),x=L,I!==void 0))break}for(let I of S)u.set(I,x)}let h=new Map;s.forEach((b,S)=>h.set(b.id,S));let d=new Map,m=(b,S,x)=>{let I=h.get(b);if(I===void 0||I=0;b--){let S=s[b];if(!o.has(S.id))for(let x of S.nodes){if(m(x,S.id,b)){e.emitWarning("CONTAINMENT_VIOLATION",`Container "${S.id}" cannot contain "${x}" because "${x}" already contains it. The nesting that would close the loop is dropped.`,{nodeId:x});continue}d.set(x,S.id)}}let p=new Map;for(let b=s.length-1;b>=0;b--){let S=s[b];if(o.has(S.id))continue;let x=S.metadata?.view==="collapsed",I={id:S.id,label:S.title,labelType:S.labelType,parentId:d.get(S.id),cssStyles:[],cssCompiledStyles:a(S.classes),cssClasses:S.classes.join(" "),shape:x?"collapsedGroup":"flowGroup",dir:S.dir,isGroup:!x,metadata:x?{...S.metadata,containerType:S.type}:S.metadata};r.push(I),p.set(S.id,I)}for(let b of e.nodes.values()){if(o.has(b.id))continue;let S=p.get(b.id);if(S){S.cssStyles=b.styles,S.cssCompiledStyles=a(b.classes),S.cssClasses=b.classes.join(" ");continue}let x=Li(b.type),I={id:b.id,label:b.text,labelType:b.labelType,parentId:d.get(b.id),cssStyles:b.styles,cssCompiledStyles:a(["default","node",...b.classes]),cssClasses:"default "+b.classes.join(" "),dir:b.dir,link:b.link,linkTarget:b.linkTarget,tooltip:e.tooltips.get(b.id),metadata:b.metadata,isGroup:!1,shape:x==="square"||x===void 0?"squareRect":x};r.push(I),p.set(b.id,I)}e.edges.forEach((b,S)=>{let x=u.get(b.start)??b.start,I=u.get(b.end)??b.end;if(x===I&&b.start!==b.end)return;let L=[...e.defaultEdgeStyle??[]];b.style&&L.push(...b.style);let O=b.type==="arrow_open"?"none":b.type==="arrow_cross"||b.type==="arrow_point"?b.type:"arrow_point";i.push({id:b.id||`L_${x}_${I}_${S}`,isUserDefinedId:b.isUserDefinedId,start:x,end:I,type:b.type??"normal",label:b.text,labelType:b.labelType,thickness:b.stroke,pattern:b.stroke,minlen:b.length,classes:"edge-thickness-normal edge-pattern-solid flowchart-link",arrowTypeStart:"none",arrowTypeEnd:O,cssCompiledStyles:a(b.classes),style:L,animate:b.animate,animation:b.animation,curve:b.interpolate||e.defaultInterpolate||n,metadata:b.metadata})}),Zm(r,e);let y=new Map;for(let b of s){let S=d.get(b.id);if(S===void 0)continue;let x=y.get(S);x?x.push(b.id):y.set(S,[b.id])}let E=new Map;for(let b of s){if(d.get(b.id)!==void 0)continue;let S=[b.id];for(;S.length>0;){let x=S.pop();if(E.has(x))continue;E.set(x,E.size);let I=y.get(x);if(I)for(let L=I.length-1;L>=0;L--)S.push(I[L])}}return Yg(r,b=>{if(e.connectors.has(b))return"connector";let S=e.nodes.get(b);return S?e.vertexKind(S):void 0},E,t),{nodes:r,edges:i}}var vT=8,PT=40,FT=16,BT=48,jo=20,Ku=26,$c=14,zu="collapsed",WT={TB:2,RL:3,BT:0,LR:1},Kg=new WeakMap;function Xu(e,t){let n=Kg.get(e);if(n===void 0){let r=t.flowchart?.curve;n=Hg(e,vT,typeof r=="string"?r:void 0),Kg.set(e,n)}return n}function Lc(e,t,n){let r=e.agentflow?.[t];return typeof r=="number"&&r>0?Math.min(r,2e3):n}function Vu(e,t,n){let r=Et(e);return` fill="${r}"${vn(n.shape)?"":` fill-opacity="${t}"`} stroke="${r}"`}function Vg(e,t,n){return Pn(e.direction)?Pt(n,r=>zg(e,t,n,r)):zg(e,t,n,!1)}function zg(e,t,n,r){let i=Xu(e,t),s=n.fontSize??16,a=Math.round(s*.875),o=n.measurer??ct(n.fontFamily,n.fontFamilyMono),c=Lc(t,"wrappingWidth",120),l=Lc(t,"minNodeWidth",120),u=n.padding??8,h=n.icons,d=new Map,m=[],p=[];i.nodes.forEach((ne,q)=>d.set(ne.id,q));for(let ne of i.nodes){let q=ne.cssStyles.length>0?ne.cssCompiledStyles.concat(ne.cssStyles):ne.cssCompiledStyles,k=Ct(q),J=(k.bold?1:0)|(k.italic?2:0),te=ne.labelType==="markdown",se=k.fontSize??s,re,P;if(ne.isGroup){let ee=Ge(ne.label,te,o,se,4e3,J);re={node:ne,style:k,label:ee,shape:"group",w:0,h:0,dy:0,loops:0},P=Bt(0,0),P.isGroup=!0,P.dir=ne.dir?ln(ne.dir):void 0,P.padX=jo,P.padTop=ee.height>0?ee.height+16:jo,P.padBottom=jo,P.minW=ee.width+2*jo-12}else if(ne.shape==="collapsedGroup"){let ee=Ge(ne.label,te,o,se,c,J),ae=Math.max(ee.width,l)+2*Tt,ue=ee.height+2*Mt+$c;re={node:ne,style:k,label:ee,shape:zu,w:ae,h:ue,dy:-$c/2,loops:0},P=Bt(ae,ue)}else{let ee=uc(ne.shape),ae=Ge(ne.label,te,o,se,c,J),ue=ps(ee,ee==="diam"?ae.width:Math.max(ae.width,l),ae.height);re={node:ne,style:k,label:ae,shape:ee,w:ue.w,h:ue.h,dy:ue.dy,loops:0},P=Bt(ue.w,ue.h)}P.seq=m.length,m.push(re),p.push(P)}i.nodes.forEach((ne,q)=>{p[q].parent=ne.parentId!==void 0?d.get(ne.parentId)??-1:-1}),xc(p,i.edges.map(ne=>[d.get(ne.start)??-1,d.get(ne.end)??-1]));let y=r?"TB":ln(e.direction),E=ne=>{let q;for(let k=p[ne].parent,J=0;k>=0&&q===void 0&&J<1e4;k=p[k].parent,J++)q=p[k].dir;return q??y},b=ne=>{let q=E(ne);return q==="LR"||q==="RL"},S=new Int32Array(p.length).fill(-1);for(let ne=0;ne=0&&S[k]<0&&q.length<=p.length;)q.push(k),k=p[k].parent;let J=k>=0?S[k]+1:0;for(let te=q.length-1;te>=0;te--)S[q[te]]=J++}let x=(ne,q)=>{let k=q;for(let J=S[q];J>S[ne];J--)k=p[k].parent;return k===ne&&q!==ne},I=[],L=[],O=[],v=[];for(let ne of i.edges){let q=d.get(ne.start),k=d.get(ne.end);if(q===void 0||k===void 0)continue;let J=Ge(ne.label,ne.labelType==="markdown",o,a,c);if(x(q,k)||x(k,q)){v.push({edge:ne,label:J,src:q,dst:k});continue}q===k&&(m[q].loops++,b(q)?p[q].h+=2*(Ku+(J.height>0?J.height+8:0)):p[q].w+=2*(Ku+(J.width>0?J.width+12:0))),O.push(ne),L.push(J),I.push({src:q,dst:k,minlen:ne.minlen??1,labelW:J.width>0?J.width+12:0,labelH:J.height>0?J.height+4:0,route:[],labelX:0,labelY:0})}let G=On(p,I,y,{nodeSep:Lc(t,"nodeSpacing",PT),edgeSep:FT,rankSep:Lc(t,"rankSpacing",BT),portSep:20}),K=Ge(e.title,!1,o,s,4e3,1),C=K.height>0?K.height+12:0,Z=Math.max(G.width,K.width),oe=u+(Z-G.width)/2,H=u+C;Tr(p,I,oe,H);let z=Math.ceil(Z+2*u),M=Math.ceil(G.height+C+2*u),T=[],R=[],_=[],$=[],g=v.length*p.length<2e6;for(let{edge:ne,src:q,dst:k}of v){let J=x(k,q),te=J?k:q,se=J?q:k,re=p[te],P=p[se],ee=WT[re.dir??E(te)],ae=J?ee:ee+2&3,ue=X=>{let le=(X&1)===0,de=X===0||X===3?-1:1,Se=le?P.x:P.x+de*P.w/2,_e=le?P.y+de*P.h/2:P.y,xe=le?P.x:re.x+de*re.w/2,Me=le?re.y+de*re.h/2:P.y,Ce=le?0:1;return J?[Se,_e,Ce,xe,Me,Ce]:[xe,Me,Ce,Se,_e,Ce]},ce=X=>{for(let le=0;leMath.min(X[0],X[3])-1&&de.x-de.w/2Math.min(X[1],X[4])-1&&de.y-de.h/2`+Ne(q.label,de,se-k.h/2+8+q.label.height/2,` class="pele-cluster-label"${vt(q.style,"var(--_m)")}${q.style.text}`,h)+"";continue}let ee=q.w,ae=q.h,ue="",ce;if(q.shape===zu){let de=Et(J.colorIndex??Xs.size),Se=ae/2-$c-2,_e=Se+($c+2)/2;ce=``}else{let de=Xs.get(J.kind??"task")??1;ue=` pele-kind-${J.kind??"task"}`,ce=hr(q.shape,ee,ae,Vu(de,"0.14",q.style)+q.style.shape,` stroke="${Et(de)}"`+q.style.line)}let pe=q.shape===zu||Gi(q.shape)?vt(q.style):"",V=Ne(q.label,0,q.dy,` class="pele-label"${pe}${q.style.text}`,h);if(/ internal-link(?: |$)/.test(re+" ")&&J.label&&n.links!==!1){let de=bt(J.label),Se=$i(de,n),_e=rt(de);V=`${V}`,T.push({id:J.id,href:de,internal:!0})}let le=ce+V;J.tooltip&&(le=`${Ue(J.tooltip)}`+le),J.link&&(le=Zn(le,J.link,J.id,T,n,J.linkTarget?` target="${rt(J.linkTarget)}"`:"")),D+=`${le}`}let B="",F="",W="",j=(ne,q,k,J,te)=>{let se=ne.style.length>0||ne.cssCompiledStyles.length>0?Ct(ne.cssCompiledStyles.concat(ne.style)):void 0,re=ne.arrowTypeEnd,P=Mr(k.d,[k.ex,k.ey],U,se?.line,k.tokens),ee=P||(se?.stroke?rt(se.stroke):"var(--_l)"),ae=ne.thickness==="dotted"?"reference":re==="arrow_cross"?"failure":"sequence",ue=It(ne.classes.replace(/edge-thickness-normal|edge-pattern-solid|flowchart-link/g,""));P===""&&(B+=Cr(k,"none",re,se?.line)),F+=``+_t(re,k.ex,k.ey,k.edx,k.edy,ee)+"",q.width>0&&(W+=dn(ne.id,q,J,te,se?.text??"",h))},Q=new Map;for(let ne=0;nej(ne.edge,ne.label,R[q],_[2*q],_[2*q+1])),{svg:at("agentflow",z,M,s,n,e,Ne(K,z/2,u+K.height/2,' class="pele-title" font-weight="var(--_tw)"')+(A?`${A}`:"")+Dn(B)+(F?`${F}`:"")+(W?`${W}`:"")+`${D}`),width:z,height:M,links:T}}function ju(e,t){return`M${f(e-1.75)},${f(t)}a1.75,1.75 0 1 0 3.5,0a1.75,1.75 0 1 0 -3.5,0Z`}var jg={type:"agentflow",keepComments:!0,parse(e,t,n,r,i){let s=t.flowchart??{},a=new hc({inheritDir:s.inheritDir===!0,direction:typeof t.direction=="string"?t.direction:void 0,lineOffset:r,source:e,maxEdges:i.maxEdges});return n&&(a.title=n),ag(e,a),Xu(a,t),a},render:Vg};function kr(e){throw new Qe(e,"semantic",{type:"architecture"})}var Oc=class{constructor(){fe(this,"type","architecture");fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"nodes",new Map);fe(this,"groups",new Map);fe(this,"edges",[]);fe(this,"layoutHints",[]);fe(this,"registered",new Map)}register(t,n,r){this.registered.has(n)&&kr(`The ${t} id [${n}] is already in use by another ${this.registered.get(n)}`),r!==void 0&&(n===r&&kr(`The ${t} [${n}] cannot be placed within itself`),this.registered.has(r)||kr(`The ${t} [${n}]'s parent does not exist. Please make sure the parent is created before this ${t}`),this.registered.get(r)==="node"&&kr(`The ${t} [${n}]'s parent is not a group`)),this.registered.set(n,t==="group"?"group":"node")}addService({id:t,icon:n,iconText:r,title:i,in:s}){this.register("service",t,s),this.nodes.set(t,{id:t,type:"service",icon:n,iconText:r,title:i,in:s})}addJunction({id:t,in:n}){this.register("junction",t,n),this.nodes.set(t,{id:t,type:"junction",in:n})}addGroup({id:t,icon:n,title:r,in:i}){this.register("group",t,i),this.groups.set(t,{id:t,icon:n,title:r,in:i})}addEdge({lhsId:t,rhsId:n,lhsDir:r,rhsDir:i,lhsInto:s,rhsInto:a,lhsGroup:o,rhsGroup:c,title:l}){let u=[["left",t,o],["right",n,c]];for(let[d,m]of u)this.registered.has(m)||kr(`The ${d}-hand id [${m}] does not yet exist. Please create the service/group before declaring an edge to it.`);for(let[d,m]of u)this.nodes.has(m)||kr(`The ${d}-hand id [${m}] is a group. Add {group} to a service inside it instead.`);let h=this.nodes.get(t).in;if(h!==void 0&&h===this.nodes.get(n).in)for(let[d,m,p]of u)p&&kr(`The ${d}-hand id [${m}] is modified to traverse the group boundary, but the edge does not pass through two groups.`);this.edges.push({lhsId:t,lhsDir:r,lhsInto:s,lhsGroup:o,rhsId:n,rhsDir:i,rhsInto:a,rhsGroup:c,title:l})}addLayoutHint(t){t.members.length<2&&kr(`An align directive requires at least two members; got ${t.members.length}`);let n=new Set;for(let r of t.members)this.registered.get(r)!=="node"&&kr(`align ${t.direction} references [${r}], which is not a service or junction`),n.has(r)&&kr(`align ${t.direction} lists [${r}] more than once`),n.add(r);this.layoutHints.push(t)}};function Xg(e,t){e.accDescr&&(t.accDescr=e.accDescr.replace(/\n\s+/g,` +`)),e.accTitle&&(t.accTitle=e.accTitle.replace(/^\s+/g,"")),e.title&&(t.title=e.title);for(let n of e.groups)t.addGroup(n);for(let n of e.services)t.addService(n);for(let n of e.junctions)t.addJunction(n);for(let n of e.edges)t.addEdge(n);for(let n of e.alignments)t.addLayoutHint({direction:n.direction,members:[...n.members]})}var qg=new WeakMap;function UT(e){let t=e.map((i,s)=>s),n=[];for(let i=0;i<128;i++){let s=String.fromCharCode(i);n.push(t.filter(a=>{let{pattern:o,first:c}=e[a];return typeof o=="string"?o[0]===s:c===void 0||c.includes(s)}))}let r={starting:n,every:t,longer:e.map(i=>i.longer?.map(s=>e.indexOf(s)))};return qg.set(e,r),r}function Yt(e,t,n){let r=[],i=[],s=[],a=new Uint8Array(t.length),{starting:o,every:c,longer:l}=qg.get(t)??UT(t),u=[],h=e.length,d=(p,y)=>{if(a[p])return-1;let E=t[p];if(E.match!==void 0)return E.match(e,y,r[r.length-1]??-1);if(E.scanner!==void 0)return(u[p]??=E.scanner())(e,y,r[r.length-1]??-1);let b=E.pattern;return typeof b=="string"?e.startsWith(b,y)?y+b.length:-1:(b.lastIndex=y,b.test(e)?b.lastIndex:(E.opener!==void 0&&(E.opener.lastIndex=y,E.opener.test(e)&&(a[p]=1)),-1))},m=0;e:for(;mE){b=x,E=I;break}}t[b].hidden||(r.push(b),i.push(m),s.push(E)),m=E;continue e}throw ft(n,e,m,"",!0)}return r.push(-1),i.push(h),s.push(h),{kinds:r,starts:i,ends:s,src:e}}var sn={name:"ACC_DESCR",pattern:/[\t ]*accDescr(?:[\t ]*:([^\n\r]*?(?=%%)|[^\n\r]*)|\s*{([^}]*)})/y,first:" a"},Xt={name:"ACC_TITLE",pattern:/[\t ]*accTitle[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)/y,first:" a"},pr={name:"TITLE",pattern:/[\t ]*title(?:[\t ][^\n\r]*?(?=%%)|[\t ][^\n\r]*|)/y,first:" t"};function er(e){return{...pr,pattern:new RegExp(String.raw`[\t ]*title(?:[\t ][^\n\r]*?(?=%%)|[\t ][^\n\r]*|(?!${e}))`,"y")}}var Fn={name:"STRING",pattern:/"([^"\\]|\\.)*"|'([^'\\]|\\.)*'/y,first:`"'`},Sn={name:"NEWLINE",pattern:/\r?\n/y,first:`\r +`},wn={name:"WHITESPACE",pattern:/[\t ]+/y,hidden:!0,first:" "},Ht={name:"YAML",pattern:/---[\t ]*\r?\n(?:[\S\s]*?\r?\n)?---(?:\r?\n|(?!\S))/y,hidden:!0,opener:/---[\t ]*\r?\n/y,first:"-"},Qt={name:"DIRECTIVE",pattern:/[\t ]*%%{[\S\s]*?}%%(?:\r?\n|(?!\S))/y,hidden:!0,opener:/[\t ]*%%{/y,first:" %"},Zt={name:"SINGLE_LINE_COMMENT",pattern:/[\t ]*%%[^\n\r]*/y,first:" %",hidden:!0};function Jt(e){return{name:e,pattern:new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"(?:(?=%%)|(?!\\S))","y"),first:e[0]}}var GT=/accDescr(?:[\t ]*:([^\n\r]*)|\s*{([^}]*)})/,YT=/accTitle[\t ]*:([^\n\r]*)/,HT=/title([\t ][^\n\r]*|)/;function qu(e){return e.trim().replace(/[\t ]{2,}/gm," ")}function Kt(e){return qu(HT.exec(e)[1])}function zt(e){return qu(YT.exec(e)[1])}function Vt(e){let t=GT.exec(e);return t[1]!==void 0?qu(t[1]):t[2].replace(/^\s*/gm,"").replace(/\s+$/gm,"").replace(/[\t ]{2,}/gm," ").replace(/[\n\r]{2,}/gm,` +`)}var KT=new Map([["b","\b"],["f","\f"],["n",` +`],["r","\r"],["t"," "],["v","\v"],["0","\0"]]);function un(e){if(!e.includes("\\"))return e.slice(1,-1);let t="";for(let n=1;n0&&r.slice(i[o-1],s[o-1]).trim()==="";)o--;o>0&&(a=s[o-1])}throw ft(this.diagram,r,a,`Expecting ${t} but found ${n}.`)}};var Zg={name:"ID",pattern:/[\w]([-\w]*\w)?/y};function bs(e){return{name:e,pattern:e,longer:[Zg]}}var Qg=[bs("architecture-beta"),bs("junction"),bs("service"),bs("column"),bs("group"),bs("align"),bs("row"),{name:"--",pattern:"--",longer:[Ht]},bs("in"),{name:":",pattern:":"},{name:"-",pattern:"-",longer:[Ht]},{name:"ARROW_DIRECTION",pattern:/L|R|T|B/y},{name:"ARROW_GROUP",pattern:/\{group\}/y},{name:"ARROW_INTO",pattern:/<|>/y},sn,Xt,er(String.raw`[-\w]*\w`),Fn,Zg,Sn,wn,Ht,Qt,Zt,{name:"ARCH_ICON",pattern:/\([\w-:]+\)/y},{name:"ARCH_TITLE",pattern:/\[(?:"([^"\\]|\\.)*"|'([^'\\]|\\.)*'|[^\[\]\r\n]+)\]/y}];function Qu(e){let t=e.slice(1,-1).trim();return(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))&&(t=t.slice(1,-1).replace(/\\"/g,'"').replace(/\\'/g,"'")),t.trim()}function Jg(e){let t=new Ut(Yt(e,Qg,"architecture"),Qg,"architecture"),n={$type:"Architecture",groups:[],services:[],junctions:[],edges:[],alignments:[]},r=s=>t.kinds[t.i]===s,i=()=>{if(t.kind!==-1)for(t.kind!==19&&t.fail("a line break or the end of input");t.kind===19;)t.i++};for(;t.kind===19;)t.i++;for(t.expect(0);t.kind!==-1;){switch(t.kind){case 19:t.i++;continue;case 14:n.accDescr=Vt(t.take());break;case 15:n.accTitle=zt(t.take());break;case 16:n.title=Kt(t.take());break;case 4:{t.i++;let s={$type:"Group",id:t.expect(18)};r(24)&&(s.icon=t.take().slice(1,-1)),r(25)&&(s.title=Qu(t.take())),t.accept(8)&&(s.in=t.expect(18)),n.groups.push(s);break}case 2:{t.i++;let s={$type:"Service",id:t.expect(18)};r(17)?s.iconText=un(t.take()):r(24)&&(s.icon=t.take().slice(1,-1)),r(25)&&(s.title=Qu(t.take())),t.accept(8)&&(s.in=t.expect(18)),n.services.push(s);break}case 1:{t.i++;let s={$type:"Junction",id:t.expect(18)};t.accept(8)&&(s.in=t.expect(18)),n.junctions.push(s);break}case 18:{let s=t.take(),a=t.accept(12);t.expect(9);let o=t.expect(11),c=t.accept(13),l;t.accept(7)||(r(10)||t.fail("'--' or '-'"),t.i++,l=Qu(t.expect(25)),t.expect(10));let u=t.accept(13),h=t.expect(11);t.expect(9);let d=t.expect(18),m=t.accept(12);n.edges.push({$type:"Edge",lhsId:s,lhsGroup:a,lhsDir:o,lhsInto:c,title:l,rhsInto:u,rhsDir:h,rhsId:d,rhsGroup:m});break}case 5:{t.i++,!r(6)&&!r(3)&&t.fail("'row' or 'column'");let s=t.take(),a=[t.expect(18),t.expect(18)];for(;r(18);)a.push(t.take());n.alignments.push({$type:"Alignment",direction:s,members:a});break}default:t.fail("a group, a service, a junction, an edge, an alignment, a title, or a line break")}i()}return n}var zT=new Map([["database","M4 6a8 3 0 1 0 16 0a8 3 0 1 0-16 0M4 6v12a8 3 0 0 0 16 0V6M4 12a8 3 0 0 0 16 0"],["server","M3 4h18v7H3zM3 13h18v7H3zM7 7.5h.01M7 16.5h.01M11 7.5h6M11 16.5h6"],["disk","M5 3h14v18H5zM12 6.5a4 4 0 1 0 0 8a4 4 0 1 0 0-8M12 10.5h.01M8 18h3"],["internet","M3 12a9 9 0 1 0 18 0a9 9 0 1 0-18 0M3 12h18M12 3a13 13 0 0 0 0 18M12 3a13 13 0 0 1 0 18"],["cloud","M7 18a4 4 0 0 1-.5-7.97A6 6 0 0 1 18 9.5a4.25 4.25 0 0 1-.5 8.5z"]]);function eb(e){let t=zT.get(e);return t===void 0?"":``}var Xo=[-1,1,0,0],Dc=[0,0,-1,1];function qo(e){return e==="L"?0:e==="R"?1:e==="T"?2:3}var tb=64,vc=2**25,nb=2**26;function rb(e,t,n,r){let i=e.length,s=t.length,a=s,o=new Map,c=new Map,l=new Int32Array(i+s).fill(a),u=new Int32Array(s+1),h=[];for(let Y=0;Y<=s;Y++)h.push([]);t.forEach((Y,ne)=>{c.set(Y.id,ne);let q=Y.in===void 0?void 0:c.get(Y.in);q!==void 0&&q!==ne?(l[i+ne]=q,u[ne]=u[q]+1):u[ne]=1}),e.forEach((Y,ne)=>{o.set(Y.id,ne);let q=Y.in===void 0?void 0:c.get(Y.in);q!==void 0&&(l[ne]=q),h[l[ne]].push(ne)});for(let Y=0;Y{if(Y===ne)return;let te=Y,se=ne,re=l[Y],P=l[ne];for(;re!==P;)u[re]>=u[P]?(te=i+re,re=l[te]):(se=i+P,P=l[se]);let ee=d.length;d.push(Y),m.push(ne),p.push(q),y.push(k),E.push(te),b.push(se),(J[te]??=[]).push(ee),(J[se]??=[]).push(ee)};for(let Y of r){let ne=Y.direction==="row";for(let q=1;q{M=0,T=0;for(let q=Y;q!==ne;q=i+l[q])M+=L[q],T+=O[q]},_=(Y,ne,q)=>{if(L[Y]=ne,O[Y]=q,K[Y]=1,C.push(Y),v[Y]*G[Y]>tb){oe.push(Y);return}for(let k=q;kL[Y]{if(q*k>tb){for(let J=z;J{let se=`${Y},${ne},${q},${k},${J},${te}`,re=H.get(se)??0;for(;;){let P=g(Y+re*J,ne+re*te,q,k);if(P<0)break;re=J>0?L[P]+v[P]-Y:J<0?Y+q-L[P]:te>0?O[P]+G[P]-ne:ne+k-O[P]}return H.set(se,re),re},w=(Y,ne)=>{let q=E[ne]===Y,k=q?b[ne]:E[ne];if(K[k])return;let J=q?p[ne]:y[ne],te=q?y[ne]:p[ne];R(q?d[ne]:m[ne],Y);let se=M,re=T;R(q?m[ne]:d[ne],k);let P=Xo[J],ee=Dc[J],ae=0,ue=0,ce=Xo[J]+Xo[te]===0&&Dc[J]+Dc[te]===0;J===te?(P=Xo[J]===0?1:0,ee=1-P):ce||(ae=-Xo[te],ue=-Dc[te]);let pe,V;if(P!==0?(pe=P>0?L[Y]+v[Y]:L[Y]-v[k],V=O[Y]+re+ue-T):(V=ee>0?O[Y]+G[Y]:O[Y]-G[k],pe=L[Y]+se+ae-M),ce){let X=x[k];if(X!==void 0&&X.length>1){let Me=[];for(let Ce of X){let ke=b[Ce]===k,be=ke?E[Ce]:b[Ce];if(!K[be]||(ke?p[Ce]:y[Ce])!==J||(ke?y[Ce]:p[Ce])!==te)continue;R(ke?d[Ce]:m[Ce],be);let Ae=P!==0?O[be]+T:L[be]+M;R(ke?m[Ce]:d[Ce],k),Me.push(Ae-(P!==0?T:M))}Me.length>1&&(Me.sort((Ce,ke)=>Ce-ke),P!==0?V=Me[Me.length-1>>1]:pe=Me[Me.length-1>>1])}let le=P===0?1:0,de=1-le,Se=N(pe,V,v[k],G[k],le,de),_e=Se===0?0:N(pe,V,v[k],G[k],-le,-de),xe=Se<=_e?Se:-_e;pe+=le*xe,V+=de*xe}else{let X=N(pe,V,v[k],G[k],P,ee);pe+=P*X,V+=ee*X}_(k,pe,V)},A=Y=>{let ne=h[Y];if(ne.length===0)return;C.length=0;let q=[];for(let X of ne){if(K[X])continue;z=C.length,q.push(z),Z.clear(),oe.length=0,H.clear(),_(X,0,0);let le=z,de=z,Se=0;for(;;){if(le=C.length)break;let _e=x[C[de]];if(_e===void 0||Se>=_e.length){de++,Se=0;continue}w(C[de],_e[Se++])}}q.push(C.length);let k=q.length-1,J=new Array(k),te=new Array(k),se=new Array(k),re=new Array(k),P=0,ee=0;for(let X=0;X0&&ue+se[X]>ae&&(ce+=pe,ue=0,pe=0);for(let le=q[X];le=0;Y--)A(Y);A(a);let D=new Int32Array(s),U=new Int32Array(s),B=new Int32Array(s),F=new Uint8Array(s);for(let Y=0;Yr-i))t.has(n)||t.set(n,t.size);return t}function ab(e,t,n,r,i){return`${i?.(e)??eb(e)}`}function qT(e,t,n,r){let i=e.lines.length>n;if(!i&&e.width<=t)return e;let s=r.width("…",e.size,0),a=[],o=[],c=0;for(let l=0;l({...d})),h=e.widths[l];if(h>t||i&&l===n-1)for(;;){let d=u[u.length-1];if(d===void 0){u.push({text:"…",style:0,width:s}),h=s;break}let m=h-d.width;if(d.icon===void 0&&m+s>1;m+r.width(d.text.slice(0,b),e.size,d.style)+s<=t?p=b:y=b-1}let E=p>0?d.text.charCodeAt(p-1):0;E>=55296&&E<=56319&&p--,d.text=d.text.slice(0,p).trimEnd()+"…",d.width=r.width(d.text,e.size,d.style),h=m+d.width;break}u.pop(),h=m}a.push(u),o.push(h),c=Math.max(c,h)}return{...e,lines:a,widths:o,width:c,height:a.length*e.lineHeight}}function QT(e,t){let{x:n,y:r,dx:i,dy:s}=e,{x:a,y:o,dx:c,dy:l}=t,u=n+i*In,h=r+s*In,d=a+c*In,m=o+l*In;if(i*c+s*l===0){let b=i!==0?a:n,S=i!==0?r:o;return(b-n)*i+(S-r)*s>0&&(b-a)*c+(S-o)*l>0?[n,r,b,S,a,o]:i!==0?[n,r,u,h,u,m,d,m,a,o]:[n,r,u,h,d,h,d,m,a,o]}let p=i!==0,y=p?o-r:a-n;if(i===-c&&s===-l){if((a-n)*i+(o-r)*s>0){if(Math.abs(y)<.5)return[n,r,a,o];if(p){let L=i>0?e.x1:t.x1,O=i>0?t.x0:e.x0,v=L0?e.y1:t.y1,x=s>0?t.y0:e.y0,I=S=1){if(p){let S=i>0?Math.max(n,a)+In:Math.min(n,a)-In;return[n,r,S,r,S,o,a,o]}let b=s>0?Math.max(r,o)+In:Math.min(r,o)-In;return[n,r,n,b,a,b,a,o]}if(p){let b=e.y1+In<=t.y0?(e.y1+t.y0)/2:t.y1+In<=e.y0?(t.y1+e.y0)/2:Math.max(e.y1,t.y1)+In;return[n,r,u,r,u,b,d,b,d,o,a,o]}let E=e.x1+In<=t.x0?(e.x1+t.x0)/2:t.x1+In<=e.x0?(t.x1+e.x0)/2:Math.max(e.x1,t.x1)+In;return[n,r,n,h,E,h,E,m,a,m,a,o]}function ZT(e){let t=[e[0],e[1]];for(let n=2;n=4&&(a&&Math.abs(t[s-4]-t[s-2])<.01||o&&Math.abs(t[s-3]-t[s-1])<.01)?(t[s-2]=r,t[s-1]=i):t.push(r,i))}return t}function JT(e,t,n){let r=e.length/2,i=new Array(r),s=new Array(r);for(let c=0;c{let h=Math.hypot(i[l]-i[c],s[l]-s[c]),d=Math.min(u,Math.max(0,h-1));h>0&&d>0&&(i[c]+=(i[l]-i[c])/h*d,s[c]+=(s[l]-s[c])/h*d)};a(0,1,t),a(r-1,r-2,n);let o=`M${f(i[0])},${f(s[0])}`;for(let c=1;ce2(e,t,n,r))}function e2(e,t,n,r){let i=Zu(t,"iconSize",48,8,512),s=Zu(t,"fontSize",n.fontSize??16,4,128),a=Math.min(Zu(t,"padding",20,0,256),r?12:1/0),o=Math.round(s*.875),c=n.measurer??ct(n.fontFamily,n.fontFamilyMono),l=n.padding??8,u=n.icons,h=i/2,d=[...e.nodes.values()],m=[...e.groups.values()],p=d.length,y=m.length,E=rb(d,m,e.edges,e.layoutHints),b=new Map;d.forEach((ge,Le)=>b.set(ge.id,Le));let S=new Array(p),x=new Float64Array(p),I=new Float64Array(p),L=r?Math.max(i,64):Math.max(i*2.25,96);for(let ge=0;ge0?sb+Fe.height:0)}let O=[],v=[];for(let ge=0;ge0&&Fe>0?6:0),ne[ge]=Math.max(Le.height,Fe)}for(let ge=y-1;ge>=0;ge--){let Le=a+F[ge],Fe=a+W[ge],Ve=(ne[ge]>0?Math.max(a,ne[ge]+12):a)+j[ge],Oe=a+Q[ge];if(Y[ge]>0){let Je=Le+Fe;for(let $e=A[ge];$e<=D[ge];$e++)Je+=oe[$e]+($eJe&&(Fe+=Math.ceil(Y[ge]+20-Je))}F[ge]=Le,W[ge]=Fe,j[ge]=Ve,Q[ge]=Oe,q[A[ge]]=Math.max(q[A[ge]],Le),k[D[ge]]=Math.max(k[D[ge]],Fe),J[U[ge]]=Math.max(J[U[ge]],Ve),te[B[ge]]=Math.max(te[B[ge]],Oe);let je=E.groupParent[ge];je<0||(A[je]===A[ge]&&(F[je]=Math.max(F[je],Le)),D[je]===D[ge]&&(W[je]=Math.max(W[je],Fe)),U[je]===U[ge]&&(j[je]=Math.max(j[je],Ve)),B[je]===B[ge]&&(Q[je]=Math.max(Q[je],Oe)))}let re=new Float64Array(C),P=new Float64Array(Z),ee=0;for(let ge=0;gere[A[ge]]-F[ge],le=ge=>re[D[ge]]+oe[D[ge]]+W[ge],de=ge=>P[U[ge]]-j[ge],Se=ge=>P[B[ge]]+H[B[ge]]+Q[ge],_e=ge=>re[R[ge]]+oe[R[ge]]/2,xe=(ge,Le,Fe)=>{let Ve=jT[Le],Oe=XT[Le],je=_e(ge),Je=P[_[ge]],$e={x:je,y:Je+h,dx:Ve,dy:Oe,x0:je-x[ge]/2,y0:Je,x1:je+x[ge]/2,y1:Je+I[ge],gap:0,wire:!1};d[ge].type==="junction"?($e.x0=$e.x1=je,$e.y0=$e.y1=$e.y,$e.gap=ib):Ve!==0?$e.x=je+Ve*h:$e.y=Oe<0?Je:Je+I[ge]+(S[ge].height>0?2:0);let Ze=Fe?E.nodeParent[ge]:-1;return Ze>=0&&($e.x0=X(Ze),$e.x1=le(Ze),$e.y0=de(Ze),$e.y1=Se(Ze),$e.gap=0,$e.wire=d[ge].type==="junction",Ve!==0?$e.x=Ve<0?$e.x0:$e.x1:$e.y=Oe<0?$e.y0:$e.y1),$e},Me="",Ce="",ke=[],be=Rt("arrow_point");for(let ge=0;ge<$;ge++){let Le=e.edges[ge],Fe=N[ge*2],Ve=N[ge*2+1];if(Fe<0||Ve<0)continue;let Oe=xe(Fe,qo(Le.lhsDir),Le.lhsGroup),je=xe(Ve,qo(Le.rhsDir),Le.rhsGroup);Oe.x===je.x&&Oe.y===je.y&&Oe.dx===je.dx&&(Oe.x-=8*Math.abs(Oe.dy),Oe.y-=8*Math.abs(Oe.dx),je.x+=8*Math.abs(Oe.dy),je.y+=8*Math.abs(Oe.dx));let Je=QT(Oe,je);Oe.wire&&Je.unshift(_e(Fe),P[_[Fe]]+h),je.wire&&Je.push(_e(Ve),P[_[Ve]]+h);let $e=ZT(Je);if($e.length<4)continue;let Ze=Ue(`${Le.lhsId}-${Le.rhsId}`);Me+=``+(Le.lhsInto?_t("arrow_point",Oe.x+Oe.dx*Oe.gap,Oe.y+Oe.dy*Oe.gap,-Oe.dx,-Oe.dy,"var(--_l)"):"")+(Le.rhsInto?_t("arrow_point",je.x+je.dx*je.gap,je.y+je.dy*je.gap,-je.dx,-je.dy,"var(--_l)"):"")+"";let tt=-1,mt=-1,dt=-1,Ee=-1,We=g[ge];for(let De=0;De<$e.length;De+=2)ue=Math.min(ue,$e[De]-4),pe=Math.max(pe,$e[De]+4),ce=Math.min(ce,$e[De+1]-4),V=Math.max(V,$e[De+1]+4);for(let De=0;De+3<$e.length;De+=2){let Xe=Math.abs($e[De+1]-$e[De+3])<.01,ze=Math.abs($e[De]-$e[De+2])+Math.abs($e[De+1]-$e[De+3]);Xe||ke.push($e[De],Math.min($e[De+1],$e[De+3]),Math.max($e[De+1],$e[De+3])),ze>mt&&(tt=De,mt=ze),Xe&&ze>Ee&&(dt=De,Ee=ze)}if(We.width>0){let De=Ee>=We.width+8?dt:tt,Xe=($e[De]+$e[De+2])/2,ze=($e[De+1]+$e[De+3])/2,et=We.width+8,Ye=Math.abs($e[De]-$e[De+2])<.01;for(let He of[Oe,je])Xe+et/2<=He.x0||Xe-et/2>=He.x1||ze+We.height/2<=He.y0||ze-We.height/2>=He.y1||(Ye?Xe=Xe>=(He.x0+He.x1)/2?He.x1+et/2+4:He.x0-et/2-4:ze=ze>=(He.y0+He.y1)/2?He.y1+We.height/2+4:He.y0-We.height/2-4);ue=Math.min(ue,Xe-et/2),pe=Math.max(pe,Xe+et/2),ce=Math.min(ce,ze-We.height/2),V=Math.max(V,ze+We.height/2),Ce+=dn(`${Le.lhsId}-${Le.rhsId}`,We,Xe,ze,"",u)}}let Ae="";for(let ge=0;ge0){let $e=Ve+ne[ge]+12,Ze=[];for(let Ee=0;EeVe&&ke[Ee]>Fe&&ke[Ee]Ee-We),Ze.push(Fe+Oe-4);let tt=Fe+10;for(let Ee of Ze){if(Ee-6-tt>=Y[ge])break;tt=Math.max(tt,Ee+6)}tt+Y[ge]>Fe+Oe-4&&(tt=Fe+10);let mt=Ve+6+ne[ge]/2,dt=tt;Le.icon&&(Je+=ab(Le.icon,tt,mt-se/2,se,u),dt+=se+6),Je+=Ne(je,dt+je.width/2,mt,' class="pele-cluster-label" fill="var(--_m)"',u)}Ae+=``+Je+""}let ie="",me=i*.5,Te=Math.max(6,Math.round(s*.75));for(let ge=0;ge`;continue}let Ve="";if(Le.icon)Ve=ab(Le.icon,-me/2,(i-me)/2,me,u);else if(Le.iconText){let Oe=Ge(Le.iconText,!1,c,Te,i-8),je=Math.max(1,Math.floor((i-4)/(Oe.lineHeight||1)));Ve=Ne(qT(Oe,i-8,je,c),0,h,` class="pele-icon-text" font-size="${Te}"`,u)}ie+=``+Ve+Ne(S[ge],0,i+sb+S[ge].height/2,' class="pele-label"',u)+""}let ye=Ge(e.title,!1,c,s,r?kt(n):4e3,1),we=ye.height>0?ye.height+12:0,Ie=Math.ceil(Math.max(pe-ue,ye.width)+2*l),ve=Math.ceil(V-ce+we+2*l),Pe=Math.round((Ie-(pe-ue))/2-ue),he=Math.round(l+we-ce),Re=(Ae?`${Ae}`:"")+(Me?`${Me}`:"")+(Ce?`${Ce}`:"")+(ie?`${ie}`:"");return{svg:at("architecture",Ie,ve,s,n,e,Ne(ye,Ie/2,l+ye.height/2,' class="pele-title" font-weight="var(--_tw)"')+(Re?`${Re}`:"")),width:Ie,height:ve,links:[]}}var lb={type:"architecture",parse(e,t,n){let r=new Oc;return n&&(r.title=n),Xg(Jg(e),r),r},render:cb};var db=1e5;function t2(e){switch(e){case"[]":return"square";case"()":return"round";case"(())":return"circle";case">]":return"rect_left_inv_arrow";case"{}":return"diamond";case"{{}}":return"hexagon";case"([])":return"stadium";case"[[]]":return"subroutine";case"[()]":return"cylinder";case"((()))":return"doublecircle";case"[//]":return"lean_right";case"[\\\\]":return"lean_left";case"[/\\]":return"trapezoid";case"[\\/]":return"inv_trapezoid";case"<[]>":return"block_arrow";default:return"na"}}function n2(e){switch(e.trim().slice(-1)){case"x":return"arrow_cross";case"o":return"arrow_circle";case">":return"arrow_point";default:return""}}function r2(e){switch(e.trim().charAt(0)){case"x":return"arrow_cross";case"o":return"arrow_circle";case"<":return"arrow_point";default:return"arrow_open"}}function s2(e){return e.includes("==")?"thick":"normal"}function i2(e){return e.includes(".-")?"dotted":"solid"}function ub(e,t){let n=e.flat(),r=-1;for(let i of n)if(i.type==="column-setting"){r=i.columns??-1;break}return{list:n,at:0,parent:t,children:[],columns:r}}var Pc=class{constructor(t={}){fe(this,"type","block");fe(this,"title");fe(this,"root",{id:"root",type:"composite",children:[],columns:-1});fe(this,"blocks",[]);fe(this,"edges",[]);fe(this,"classes",new Map);fe(this,"byId",new Map);fe(this,"typeStr2Type",t2);fe(this,"edgeStrToEdgeData",n2);fe(this,"edgeStrToEdgeStartData",r2);fe(this,"edgeStrToThickness",s2);fe(this,"edgeStrToPattern",i2);fe(this,"warn");fe(this,"pending",new Set);fe(this,"edgeCount",new Map);fe(this,"ids",0);fe(this,"colors",0);fe(this,"spaces",0);this.warn=t.warn}generateId(){return"id-"+ ++this.ids}addStyleClass(t,n=""){let r=this.classes.get(t);r||(r={id:t,styles:[],textStyles:[]},this.classes.set(t,r));for(let i of n.split(",")){let s=i.indexOf(";"),a=(s===-1?i:i.slice(0,s)+i.slice(s+1)).trim();i.includes("color")&&r.textStyles.push(a.replace("fill","bgFill").replace("color","fill")),r.styles.push(a)}}addStyle2Node(t,n=""){this.named(t).styles=n.split(",")}setCssClass(t,n){for(let r of t.split(","))(this.named(r.trim()).classes??=[]).push(n)}named(t){let n=this.byId.get(t);return n===void 0&&(n={id:t,type:"na",children:[]},this.byId.set(t,n),this.pending.add(t)),n}setHierarchy(t){let n=[ub(t,this.root)];for(;n.length>0;){let r=n[n.length-1];if(r.at===r.list.length){r.parent.children=r.children,n.pop();continue}let i=r.list[r.at++];switch(r.columns>0&&i.type!=="column-setting"&&typeof i.widthInColumns=="number"&&i.widthInColumns>r.columns&&this.warn?.(`Block ${i.id} width ${i.widthInColumns} exceeds configured column width ${r.columns}`),i.type){case"classDef":this.addStyleClass(i.id,i.css);continue;case"applyClass":this.setCssClass(i.id,i.styleClass??"");continue;case"applyStyles":i.stylesStr&&this.addStyle2Node(i.id,i.stylesStr);continue;case"column-setting":r.parent.columns=i.columns??-1;continue;case"edge":{let c=(this.edgeCount.get(i.id)??0)+1;this.edgeCount.set(i.id,c),i.id=c+"-"+i.id,this.edges.push(i);continue}}i.id??=this.generateId(),i.label||(i.label=i.type==="composite"?"":i.id);let s=this.byId.get(i.id),a=s===void 0||this.pending.delete(i.id);a?(s&&(i.classes=s.classes,i.styles=s.styles),i.type==="composite"&&(i.colorIndex=this.colors++),this.byId.set(i.id,i)):(i.type!=="na"&&(s.type=i.type),i.label!==i.id&&(s.label=i.label));let o=i.children;if(i.children=[],i.type==="space"){let c=i.width??1;if(!(c<=db-this.spaces))throw new Qe(`A block diagram can hold at most ${db} space blocks.`,"limit",{type:"block"});this.spaces+=Math.max(c,0);for(let l=0;l0&&n.push(ub(o,i))}this.blocks=this.root.children??[]}};var Ju=["$end","INVALID","BLOCK_DIAGRAM_KEY","id-block","COLUMNS","MD_STR","STR","SPACE_BLOCK","DEFAULT","LINKSTYLE","INTERPOLATE","classDef","DEFAULT_CLASSDEF_ID","CLASSDEF_ID","CLASSDEF_STYLEOPTS","class","CLASSENTITY_IDS","STYLECLASS","style","STYLE_ENTITY_IDS","STYLE_DEFINITION_DATA","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","end","NODE_DSTART","NODE_DEND","BLOCK_ARROW_START","BLOCK_ARROW_END","DIR","NODE_ID","LINK","START_LINK","LINK_LABEL","SIZE","EOF"];var o2=["right","left","x","y","up","down"],fb=new Uint8Array(128);for(let e of[9,10,11,12,13,32,40,41,45,58,60,61,62,91,123,125])fb[e]=1;function hb(e){let t=e.length,n=[],r=[],i=[],s=[],a=0,o=0,c=(K,C,Z)=>(n.push(K),r.push(C),i.push(o),o=Z,!0),l=(K,C)=>c(K,e.slice(o,C),C),u=K=>{s.push(a),a=K},h=()=>{s.length>0&&(a=s.pop())},d=K=>{for(;K{for(;K57)break;K++}return K},p=K=>{for(;Ke.startsWith(K,o)&&!ot(e.charCodeAt(o+K.length)),E=()=>(e.charCodeAt(o+1)===96?(u(2),o+=2):(u(1),o++),!0),b=K=>{if(e.charCodeAt(K)!==46)return-1;do K++;while(e.charCodeAt(K)===46);if(e.charCodeAt(K)!==45)return-1;let C=e.charCodeAt(K+1);return C===120||C===111||C===62?K+2:K+1},S=K=>{let C=e.charCodeAt(K);(C===120||C===111||C===60)&&K++;let Z=e.charCodeAt(K);if(Z===46)return b(K);if(Z!==45&&Z!==61)return-1;let oe=K+1;for(;e.charCodeAt(oe)===Z;)oe++;if(oe-K===1)return Z===45?b(oe):-1;let H=e.charCodeAt(oe);return H===120||H===111||H===62?oe+1:oe-K>=3?oe:-1},x=()=>{let K=S(o);if(K>=0)return l(33,d(K));let C=e.charCodeAt(o)===60?o+1:o,Z=e.charCodeAt(C),oe=e.charCodeAt(C+1);return Z===45&&(oe===45||oe===46)||Z===61&&oe===61?(u(6),l(34,d(C+2))):!1},I=K=>{let C=e.indexOf(` +`,o);return C===-1&&(C=t),h(),l(K,C)},L=(K,C)=>{let Z=p(o);if(Z===o)return!1;for(;e.charCodeAt(Z)===44;){let oe=d(Z+1),H=p(oe);if(H===oe)break;Z=H}return a=C,l(K,Z)},O=K=>{if(qe(K))return o=d(o+1),!0;let C;switch(K){case 98:if(e.startsWith("block",o)){if(y("block-beta"))return l(2,o+10);if(e.charCodeAt(o+5)===58)return l(3,o+6);if(!ot(e.charCodeAt(o+5)))return l(2,o+5)}break;case 99:if(e.startsWith("columns",o)){if(C=d(o+7),C>o+7){if(e.startsWith("auto",C)&&!ot(e.charCodeAt(C+4)))return c(4,"-1",C+4);let Z=m(C);if(Z>C)return c(4,e.slice(C,Z),Z)}}else if(e.startsWith("class",o)){let Z=e.startsWith("Def",o+5),oe=Z?o+8:o+5;if(C=d(oe),C>oe)return u(Z?7:9),l(Z?11:15,C)}break;case 34:return E();case 115:if(e.startsWith("space",o)){if(e.charCodeAt(o+5)===58){let Z=m(o+6);if(Z>o+6)return c(7,e.slice(o+6,Z),Z)}if(!ot(e.charCodeAt(o+5)))return c(7,"1",o+5)}else if(e.startsWith("style",o)&&(C=d(o+5),C>o+5))return u(11),l(18,C);break;case 100:if(y("default"))return l(8,o+7);break;case 108:if(y("linkStyle"))return l(9,o+9);break;case 105:if(y("interpolate"))return l(10,o+11);break;case 97:if(e.startsWith("accTitle",o)){if(C=d(o+8),e.charCodeAt(C)===58)return u(13),l(21,d(C+1))}else if(e.startsWith("accDescr",o)){C=d(o+8);let Z=e.charCodeAt(C);if(Z===58)return u(14),l(23,d(C+1));if(Z===123)return u(15),o=d(C+1),!0}break;case 101:if(y("end"))return l(26,d(o+3));break;case 45:return e.charCodeAt(o+1)===41?(u(3),l(27,o+2)):x();case 61:return x();case 60:return e.charCodeAt(o+1)===91?(u(4),l(29,o+2)):x();case 40:{let Z=e.charCodeAt(o+1),oe=Z===45||Z===91?2:Z===40?e.charCodeAt(o+2)===40?3:2:1;return u(3),l(27,o+oe)}case 41:case 123:return u(3),l(27,e.charCodeAt(o+1)===K?o+2:o+1);case 62:return u(3),l(27,o+1);case 91:{let Z=e.charCodeAt(o+1);return u(3),l(27,Z===91||Z===124||Z===40||Z===92||Z===47?o+2:o+1)}case 58:{let Z=m(o+1);return Z>o+1?c(36,e.slice(o+1,Z),Z):!1}}for(C=o;Co&&l(32,C)},v=K=>{let C=e.charCodeAt(o+1),Z=0;switch(K){case 34:return E();case 40:Z=C===45?2:C===40?e.charCodeAt(o+2)===40?3:2:1;break;case 41:Z=C===41?e.charCodeAt(o+2)===41?3:2:C===93?2:1;break;case 125:Z=C===125?2:1;break;case 45:Z=C===41?2:0;break;case 93:Z=C===93||C===41||C===62?2:1;break;case 92:case 47:Z=C===93?2:0;break}return Z===0?!1:(h(),l(28,o+Z))},G=K=>{if(K===41)return h(),h(),c(30,"]>",d(o+1));let C=d(K===44?o+1:o);for(let Z of o2)if(e.startsWith(Z,C)){let oe=d(C+Z.length);return c(31,e.slice(K===44?C:o,oe),oe)}return!1};for(;;){if(o>=t){let Z=-1;switch(a){case 0:Z=37;break;case 1:Z=6;break;case 8:Z=14;break;case 10:Z=17;break;case 12:Z=20;break;case 13:Z=22;break;case 14:Z=24;break;case 15:Z=25;break}o=t,Z!==-1&&c(Z,"",t);break}let K=e.charCodeAt(o),C=!0;switch(a){case 0:C=O(K);break;case 1:if(K===34)h(),o++;else{let Z=e.indexOf('"',o);l(6,Z===-1?t:Z)}break;case 2:if(K===96)C=e.charCodeAt(o+1)===34,C&&(h(),o+=2);else if(K===34)C=!1;else{let Z=o+1;for(;Z=0,C&&(h(),l(33,d(Z)))}break;case 7:{let Z=12,oe=e.startsWith("DEFAULT",o)?o+7:o,H=d(oe);(oe===o||H===oe)&&(Z=13,oe=p(o),H=d(oe)),C=oe>o&&H>oe,C&&(a=8,l(Z,H));break}case 8:I(14);break;case 9:C=L(16,10);break;case 10:I(17);break;case 11:C=L(19,12);break;case 12:I(20);break;case 13:I(22);break;case 14:I(24);break;case 15:if(K===125)h(),o++;else{let Z=e.indexOf("}",o);l(25,Z===-1?t:Z)}break}if(!C)return n.push(1),r.push(""),i.push(o),{types:n,texts:r,starts:i}}return n.push(0),r.push(""),i.push(t),{types:n,texts:r,starts:i}}var Qo="'NODE_ID', 'COLUMNS', 'SPACE_BLOCK', 'BLOCK_DIAGRAM_KEY', 'id-block', 'classDef', 'class', 'style'";function pb(e){let t=e[e.length-1];return Array.isArray(t)?(e.pop(),e.concat(t)):e}function mb(e,t){let{types:n,texts:r,starts:i}=hb(e),s=0,a=d=>{let m=n[s];throw m===1?ft("block",e,i[s],"",!0):ft("block",e,i[s],`Expecting ${d}, got '${Ju[m]}'`)},o=d=>(n[s]!==d&&a(`'${Ju[d]}'`),r[s++]),c=()=>{let d=o(32);if(n[s]===27){let m=r[s++],p=o(6);return{id:d,label:p,typeStr:m+o(28)}}if(n[s]===29){let m=r[s++],p=o(6),y=[o(31)];for(;n[s]===31;)y.push(r[s++]);return{id:d,label:p,typeStr:m+o(30),directions:y}}return{id:d}},l=()=>{let d=c(),m=n[s]===36?parseInt(r[s++],10):1,p={id:d.id,label:d.label,type:t.typeStr2Type(d.typeStr),directions:d.directions,widthInColumns:m},y;for(;n[s]===33||n[s]===34;){let E="";n[s++]===34&&(o(35),E=o(6),o(33));let b=r[s-1],S=c(),x=t.edgeStrToEdgeData(b),I=t.edgeStrToEdgeStartData(b),L=t.edgeStrToThickness(b),O=t.edgeStrToPattern(b);y??=[{id:p.id,label:p.label,type:p.type,directions:p.directions}],p={id:S.id,label:S.label,type:t.typeStr2Type(S.typeStr),directions:S.directions},y.push({id:y[y.length-1].id+"-"+S.id,start:y[y.length-1].id,end:S.id,label:E,type:"edge",thickness:L,pattern:O,directions:S.directions,arrowTypeEnd:x,arrowTypeStart:I},p)}return y??p};o(2);let u=[],h=[];for(;;)switch(n[s]){case 32:h.push(l());break;case 4:h.push({type:"column-setting",columns:parseInt(r[s++],10)});break;case 7:{let d=parseInt(r[s++],10);h.push({id:t.generateId(),type:"space",label:"",width:d,children:[]});break}case 2:s++,u.push({list:h,header:void 0}),h=[];break;case 3:s++,n[s]!==32&&a("'NODE_ID'"),u.push({list:h,header:l()}),h=[];break;case 26:{let d=u.pop();if(d===void 0||h.length===0)return a(Qo);s++;let m=t.generateId(),p=pb(h);h=d.list,h.push(d.header===void 0?{id:m,type:"composite",label:"",children:p}:{...d.header,type:"composite",children:p});break}case 11:{s++;let d=o(13).trim();h.push({type:"classDef",id:d,css:o(14).trim()});break}case 15:{s++;let d=o(16).trim();h.push({type:"applyClass",id:d,styleClass:o(17).trim()});break}case 18:{s++;let d=o(19).trim();h.push({type:"applyStyles",id:d,stylesStr:o(20).trim()});break}case 37:u.length>0&&a(Qo+", 'end'"),h.length===0&&a(Qo),t.setHierarchy(pb(h));return;default:a(h.length===0?Qo:Qo+(u.length>0?", 'end'":", 'EOF'"))}}function yn(e,t,n,r){return lm(()=>Ge(e,!1,t,n,r,1))}function Fc(e,t,n,r,i,s,a){let o=yn(e,t,n,4e3);if(o.height===0)return{width:i,height:s,content:a};let c=o.height+12,l=Math.max(i,Math.ceil(o.width+2*r));return{width:l,height:Math.ceil(s+c),content:Ne(o,l/2,r+o.height/2,' class="pele-title" font-weight="var(--_tw)"')+`${a}`}}var $r=1,Lr=2,Or=4,Dr=8,qs=7,Bc=20,Es=12;function gb(e){let t=0;if(e)for(let n of e)switch(n.trim()){case"right":t|=$r;break;case"left":t|=Lr;break;case"up":t|=Or;break;case"down":t|=Dr;break;case"x":t|=$r|Lr;break;case"y":t|=Or|Dr;break}return t}var ys=(e,t)=>e&t?1:0;function Zo(e){return e!==0&&(e&(Or|Dr))===0?"x":e!==0&&(e&($r|Lr))===0?"y":""}function ef(e,t,n){let r=Zo(e),i=ys(e,Lr)-ys(e,$r),s=ys(e,Or)-ys(e,Dr);if(r==="x"){let a=Math.max(n+8,14)+2*qs,o=Math.min(a/2,Bc);return{w:Math.max(t+12,16)+o*(e===($r|Lr)?2:1),h:a,dx:i*o/2,dy:0}}if(r==="y"){let a=Math.max(t+16,14)+2*qs,o=Math.min(a/2,Bc);return{w:a,h:Math.max(n+8,16)+o*(e===(Or|Dr)?2:1),dx:0,dy:s*o/2}}return{w:Math.max(t+16,24)+Es*(ys(e,Lr)+ys(e,$r)),h:Math.max(n+8,24)+Es*(ys(e,Or)+ys(e,Dr)),dx:i*Es/2,dy:s*Es/2}}function bb(e,t,n,r){let i=Zo(e),s=t/2,a=n/2,o;if(i==="x"){let l=Math.min(a,Bc),u=a-qs,h=e&Lr?-s+l:-s,d=e&$r?s-l:s;o=[h,-u,d,-u],e&$r&&o.push(d,-a,s,0,d,a),o.push(d,u,h,u),e&Lr&&o.push(h,a,-s,0,h,-a)}else if(i==="y"){let l=Math.min(s,Bc),u=s-qs,h=e&Or?-a+l:-a,d=e&Dr?a-l:a;o=[u,h,u,d],e&Dr&&o.push(s,d,0,a,-s,d),o.push(-u,d,-u,h),e&Or&&o.push(-s,h,0,-a,s,h)}else{let l=e&Lr?-s+Es:-s,u=e&$r?s-Es:s,h=e&Or?-a+Es:-a,d=e&Dr?a-Es:a,m=(l+u)/2,p=(h+d)/2,y=Math.min(10,(u-l)/2),E=Math.min(10,(d-h)/2);o=[l,h],e&Or&&o.push(m-y,h,m,-a,m+y,h),o.push(u,h),e&$r&&o.push(u,p-E,s,p,u,p+E),o.push(u,d),e&Dr&&o.push(m+y,d,m,a,m-y,d),o.push(l,d),e&Lr&&o.push(l,p+E,-s,p,l,p-E)}let c="";for(let l=0;l`}var a2=1e3;function c2(e,t){if(e===0||!Number.isInteger(e))throw new Qe("Columns must be an integer !== 0.","semantic",{type:"block"});if(t<0||!Number.isInteger(t))throw new Qe("Position must be a non-negative integer."+t,"semantic",{type:"block"});return e<0?{px:t,py:0}:{px:t%e,py:Math.floor(t/e)}}function l2(e,t,n){let r=e.columns,i=[],s=0,a=0,o=0,c=0;for(let u of e.children){let{px:h,py:d}=c2(r,s),m=u.span>=1?Math.min(u.span,a2):1;if(r>0&&m>r-h&&(m=r-h),u.span=m,u.col=h,u.row=d,s+=m,h+m>a&&(a=h+m),d===i.length&&i.push(0),u.children.length===0?i[d]=-1:i[d]>=0&&u.nh>i[d]&&(i[d]=u.nh),u.space)continue;let p=(u.nw-t*(m-1))/m;p>o&&(o=p),u.nh>c&&(c=u.nh)}let l=(i.length-1)*t+Wc(e.rowGaps);for(let u=0;u0){let b=0;for(let S=0;S0?l/h:0,m=h>0?0:l/o,p=e.x-e.w/2+n,y=e.y-e.h/2+n+e.head,E=0;for(let b of e.children){for(;E=0;r--){let i=n[r];i.children.length>0&&l2(i,t,r===0?0:t)}e.w=e.nw,e.h=e.nh,e.x=e.w/2,e.y=e.h/2;for(let r=0;r0&&d2(i,t,r===0?0:t)}return{width:e.w,height:e.h}}var u2=12,Eb=200,f2=8,xb=' fill="var(--_s)" stroke="var(--_b)"',h2=' stroke="var(--_b)"',Ab=[],p2=[],m2=[],zi=[],g2=["default"],Sb=2e6,tf=4,b2=new Map([["square","rect"],["round","rounded"],["circle","circle"],["doublecircle","dbl-circ"],["diamond","diam"],["hexagon","hex"],["stadium","stadium"],["subroutine","fr-rect"],["cylinder","cyl"],["rect_left_inv_arrow","odd"],["lean_right","lean-r"],["lean_left","lean-l"],["trapezoid","trap-b"],["inv_trapezoid","trap-t"]]),wb=new Set(["circle","dbl-circ","diam"]),y2=new Set(["stadium","hex","odd","lean-r","lean-l","trap-b","trap-t"]);function Uc(e){return e.kind===0&&(e.shape==="circle"||e.shape==="dbl-circ")}function Hi(e,t,n){let r=e.bw/2,i=e.bh/2,s=Math.abs(t-e.x),a=i;return Uc(e)?a=Math.sqrt(Math.max(r*r-s*s,0)):e.kind===0&&e.shape==="diam"?a=i*Math.max(1-s/r,0):e.kind===0?a=i-Qr(e.shape,e.bw,e.bh,n>0?2:0):e.kind===1&&Zo(e.mask)==="x"&&(a=i-qs),e.y+n*a}function Ki(e,t,n){let r=e.bw/2,i=e.bh/2,s=Math.abs(t-e.y),a=r;return Uc(e)?a=Math.sqrt(Math.max(i*i-s*s,0)):e.kind===0&&e.shape==="diam"?a=r*Math.max(1-s/i,0):e.kind===0?a=r-Qr(e.shape,e.bw,e.bh,n>0?1:3):e.kind===1&&Zo(e.mask)==="y"&&(a=r-qs),e.x+n*a}function _b(e,t,n,r){let i=t-e.x,s=n-e.y,a=e.bw/2,o=e.bh/2,c;Uc(e)?c=a/(Math.hypot(i,s)||1):e.kind===0&&e.shape==="diam"?c=1/(Math.abs(i)/a+Math.abs(s)/o||1):c=Math.min(i===0?1/0:a/Math.abs(i),s===0?1/0:o/Math.abs(s)),c===1/0&&(c=0),r.push(e.x+i*c,e.y+s*c)}function E2(e,t,n,r,i){let s=i.x-i.bw/2+1,a=i.x+i.bw/2-1,o=i.y-i.bh/2+1,c=i.y+i.bh/2-1;if(ea&&n>a||tc&&r>c)return!1;if(e===n||t===r)return!0;let l=n-e,u=r-t,h=(m,p)=>Math.sign(l*(p-t)-u*(m-e)),d=h(s,o);return d===0||h(a,o)!==d||h(a,c)!==d||h(s,c)!==d}function nf(e,t,n,r){let i=0;for(let s of r)if(!(s===t||s===n)){for(let a=0;a+36,b=y-p>6;if(E&&b){let oe=e.bw*e.bh<=t.bw*t.bh?e:t,H=oe===e?t:e,z=oe.y-oe.bh/2-(H.y-H.bh/2),M=H.y+H.bh/2-(oe.y+oe.bh/2),T=oe.x-oe.bw/2-(H.x-H.bw/2),R=H.x+H.bw/2-(oe.x+oe.bw/2),_=Math.min(z,M,T,R),$;return _===M?$=[oe.x,Hi(oe,oe.x,1),oe.x,H.y+H.bh/2]:_===z?$=[oe.x,Hi(oe,oe.x,-1),oe.x,H.y-H.bh/2]:_===R?$=[Ki(oe,oe.y,1),oe.y,H.x+H.bw/2,oe.y]:$=[Ki(oe,oe.y,-1),oe.y,H.x-H.bw/2,oe.y],oe===e?$:[$[2],$[3],$[0],$[1]]}if(E){let oe=Math.min(6,(m-d)/2),H=Math.min(Math.max((d+m)/2+n,d+oe),m-oe),z=t.y>e.y?1:-1;return[H,Hi(e,H,z),H,Hi(t,H,-z)]}if(b){let oe=Math.min(6,(y-p)/2),H=Math.min(Math.max((p+y)/2+n,p+oe),y-oe),z=t.x>e.x?1:-1;return[Ki(e,H,z),H,Ki(t,H,-z),H]}let S=t.x>e.x?1:-1,x=t.y>e.y?1:-1,I=[Ki(e,e.y,S),e.y,t.x,e.y,t.x,Hi(t,t.x,-x)],L=[e.x,Hi(e,e.x,x),e.x,t.y,Ki(t,t.y,-S),t.y],O=Math.abs(t.x-e.x)>=Math.abs(t.y-e.y),v=O?I:L;if(r===void 0)return v;let G=nf(v,e,t,r);if(G===0)return v;let K=O?L:I,C=nf(K,e,t,r);if(Cu){let y=u/(t+n);t*=y,n*=y}t=Math.min(t,u),n=Math.min(n,m);let p=`M${f(i+c*t)},${f(s+l*t)}`;if(r===6){let y=Math.max(0,Math.min(f2,u-t,m-n));p+=`L${f(e[2]-c*y)},${f(e[3]-l*y)}Q${f(e[2])},${f(e[3])} ${f(e[2]+h*y)},${f(e[3]+d*y)}`}return p+=`L${f(a-h*n)},${f(o-d*n)}`,{d:p,sx:i,sy:s,sdx:-c,sdy:-l,ex:a,ey:o,edx:h,edy:d}}function rf(e,t){let n=e.bw/2,r=e.bh/2,i=Math.max(1,Math.min(10+5*(t-1),n,r));if(Uc(e)){let s=e.x+n*Math.SQRT1_2,a=e.y-n*Math.SQRT1_2,o=2*Math.asin(Math.min(1,i/(2*n))),c=l=>Math.atan2(e.y-n*Math.sin(l)-a,e.x+n*Math.cos(l)-s);return[s,a,i,c(Math.PI/4+o),c(Math.PI/4-o)]}if(e.kind===0&&e.shape==="diam"){let s=Math.atan2(r,n);return[e.x+n/2,e.y-r/2,i,s+Math.PI,s]}return[e.x+n,e.y-r,i,Math.PI,Math.PI/2]}function S2(e,t,n,r){let[i,s,a,o,c]=rf(e,t),l=o+n/a,u=c-r/a,h=(u-l)%(2*Math.PI);h<=0&&(h+=2*Math.PI);let d=i+a*Math.cos(l),m=s+a*Math.sin(l),p=i+a*Math.cos(u),y=s+a*Math.sin(u),E=i+a*Math.cos(o),b=s+a*Math.sin(o),S=i+a*Math.cos(c),x=s+a*Math.sin(c),I=Math.hypot(E-d,b-m),L=Math.hypot(S-p,x-y);return{d:`M${f(d)},${f(m)}A${f(a)},${f(a)} 0 ${h>Math.PI?1:0} 1 ${f(p)},${f(y)}`,sx:E,sy:b,sdx:I>0?(E-d)/I:Math.sin(o),sdy:I>0?(b-m)/I:-Math.cos(o),ex:S,ey:x,edx:L>0?(S-p)/L:-Math.sin(c),edy:L>0?(x-y)/L:Math.cos(c)}}var w2=[.5,.3,.7,.15,.85];function Rb(e,t,n,r,i,s,a){if(a===void 0)return!1;for(let o of a)if(o!==i&&o!==s&&Math.abs(e-o.x)<(n+o.bw)/2&&Math.abs(t-o.y)<(r+o.bh)/2)return!0;return!1}function _2(e,t,n,r,i,s,a){if(a===void 0)return .5;for(let o of w2){let c=e[t]+(e[t+2]-e[t])*o,l=e[t+1]+(e[t+3]-e[t+1])*o;if(!Rb(c,l,n,r,i,s,a))return o}return .5}function R2(e,t,n,r,i,s){let a=n[e[0]][0]===n[e[0]][2],o=-1/0,c=1/0,l=-tf,u=!1;for(let m=0;mc-o-2*Lt)return l-(c-o-2*Lt);let h=[],d=(o+c-l)/2;for(let m of e){let{label:p,lx:y,ly:E}=t[m],b=a?p.height:p.width+8,S=d+b/2;if(Rb(a?y:S,a?S:E,p.width+8,p.height,r,i,s))return 0;h.push(S),d+=b+tf}return e.forEach((m,p)=>{a?t[m].ly=h[p]:t[m].lx=h[p]}),0}function T2(e,t,n,r,i,s){let a=new Set;for(let d=t;d!==void 0;d=e[d.index])a.add(d);let o,c=n;for(;c!==void 0&&!a.has(c);)o=c,c=e[c.index];if(c===void 0||o===void 0||c===t)return!1;let l=t;for(;e[l.index]!==c;)l=e[l.index];let u;if(r){if(l.row===o.row)return!1;u=Math.max(l.row,o.row)-1,c.rowGaps===zi&&(c.rowGaps=[])}else{let[d,m]=l.colM2(e,t,n,r))}function M2(e,t,n,r){let i=n.fontSize??16,s=Math.round(i*.875),a=n.measurer??ct(n.fontFamily,n.fontFamilyMono),o=n.padding??8,c=n.icons,l=t.block?.padding,u=Math.min(typeof l=="number"&&l>=0?Math.min(l,200):u2,r?6:1/0),h=r?80:Eb,d=re=>{let P=[],ee=ae=>{for(let ue of ae)for(let ce of ue.split(";"))P.push(ce)};for(let ae of re.classes&&re.classes.length>0?re.classes:g2){let ue=e.classes.get(ae);ue&&ee(ue.styles)}return re.styles&&ee(re.styles),Ct(P)},m=(re,P)=>{let ee=re.type,ae=ee==="space"?Ct(Ab):d(re),ue=(ae.bold?1:0)|(ae.italic?2:0),ce=ae.fontSize??i,pe=0,V="",X,le=0,de=0,Se=0,_e=0,xe=0,Me=0;if(ee==="space")pe=3,X=Ge(void 0,!1,a,ce,h);else if(ee==="composite")pe=2,X=Ge(re.label,!1,a,ce,r?kt(n):4e3,ue),Se=X.height>0?X.height+4:0,le=X.width+2*u,de=Se+2*u;else if(ee==="block_arrow"){pe=1,X=Ge(re.label,!1,a,ce,h,ue);let Ce=!0;for(let be of X.lines)for(let Ae of be)(Ae.icon!==void 0||Ae.text.trim()!=="")&&(Ce=!1);_e=gb(re.directions);let ke=Ce?ef(_e,0,0):ef(_e,X.width,X.height);le=ke.w,de=ke.h,xe=ke.dx,Me=ke.dy}else{V=b2.get(ee??"")??"rect",X=Ge(re.label,!1,a,ce,h,ue);let Ce=ps(V,X.width,X.height);le=Ce.w,de=V==="cyl"?Math.max(Ce.h,X.height+40):Ce.h,Me=Ce.dy}return{children:[],columns:pe===2?re.columns??-1:-1,span:pe===3?1:re.widthInColumns??1,space:pe===3,head:Se,nw:le,nh:de,col:0,row:0,cols:0,heights:m2,rowGaps:zi,colGaps:zi,x:0,y:0,w:0,h:0,block:re,kind:pe,index:P,shape:V,label:X,style:ae,mask:_e,dx:xe,dy:Me,bw:0,bh:0}},p=m(e.root,0);p.nw=0,p.nh=0;let y=[p],E=[],b=new Map;for(let re=0;rere.nw),L=()=>{for(let P of y)P.nw=I[P.index];let re=yb(p,u);S.length=0,x.length=0;for(let P of y)P.kind===0&&wb.has(P.shape)?(P.bw=P.nw,P.bh=P.nh):P.kind===1?(P.bw=P.span>1?P.w:P.nw,P.bh=P.nh):(P.bw=P.w,P.bh=P.kind===0&&y2.has(P.shape)?P.nh:P.h),P.kind===0&&P.shape==="cyl"&&(P.dy=Math.min(12,Math.max(6,P.bw/14))/2),P.kind===0||P.kind===1?S.push(P):P.head>0&&x.push({x:P.x,y:P.y-P.h/2+(P.head+u)/2+2,bw:P.label.width,bh:P.label.height});return re},O=L(),v=new Map,G=new Set,K=[],C=[];for(let re of e.edges){let P=b.get(re.start??""),ee=b.get(re.end??"");if(P===void 0||ee===void 0)continue;let ae=Math.min(P.index,ee.index)*y.length+Math.max(P.index,ee.index);v.set(ae,(v.get(ae)??0)+1),re.label&&G.add(ae),K.push([P,ee]),C.push(re)}let Z=C.length*S.length<=Sb?S:void 0,oe=[],H=new Map,z=[],M=()=>{let re=new Map;oe.length=0,H.clear();for(let P=0;Pxe?2:0,ke=V.width>0?_2(X,Ce,V.width+8,V.height,ee,ae,Z):.5;if(le=X[Ce]+(X[Ce+2]-X[Ce])*ke,de=X[Ce+1]+(X[Ce+3]-X[Ce+1])*ke,V.width>0&&ce>1){z[P]=X.slice(Ce,Ce+4);let be=H.get(ue);be?be.push(P):H.set(ue,[P])}}oe.push({edge:C[P],points:X,loop:ee===ae?pe+1:0,label:V,lx:le,ly:de})}},T=re=>{M();let P=Z&&[...Z,...x],ee=new Map,ae=!1;for(let ue of H.values()){if(ue.length<2)continue;let[ce,pe]=K[ue[0]],V=R2(ue,oe,z,ce,pe,P),X=z[ue[0]][0]===z[ue[0]][2];re&&V>0&&(X||!r)&&T2(E,ce,pe,X,Math.ceil(V),ee)&&(ae=!0)}return ae},R=()=>{let re=0;for(let P=0;P0&&ue.label.width>0&&V>0&&X>0&&(re+=V*X)}}return re},_=0,$=0,g=0,N=0,w=(re,P,ee,ae)=>{re-ee/2<_&&(_=re-ee/2),re+ee/2>g&&(g=re+ee/2),P-ae/2<$&&($=P-ae/2),P+ae/2>N&&(N=P+ae/2)},A=()=>{_=0,$=0,g=O.width,N=O.height;for(let re=0;re0){let[ee,ae,ue]=rf(K[re][0],P.loop);w(ee,ae,2*ue+2,2*ue+2)}P.label.width>0&&w(P.lx,P.ly,P.label.width+8,P.label.height)}return g-_};if(T(C.length*C.length<=Sb)){let re=R(),P=A(),ee=!0;for(let ce=0;ce<3&ⅇce++)O=L(),ee=T(ce<2);let ae=A(),ue=n.maxWidth!==void 0&&n.maxWidth>0?n.maxWidth:1/0;if(R()>re-1||ae>P&&Math.ceil(ae+2*o)>ue){for(let ce of y)ce.rowGaps=zi,ce.colGaps=zi;O=L(),T(!1)}}A();let D=yn(e.title,a,i,r?kt(n):4e3),U=D.height>0?D.height+12:0,B=Math.max(g-_,D.width),F=o-_+(B-(g-_))/2,W=o+U-$;for(let re of y)re.x+=F,re.y+=W;let j=Math.ceil(B+2*o),Q=Math.ceil(N-$+U+2*o),Y="",ne="",q=[];for(let re=1;re`+Ne(P.label,P.x,pe+(P.head+u)/2+2,` class="pele-cluster-label"${vt(P.style,"var(--_m)")}${P.style.text}`,c)+"";continue}let ue=P.kind===1,ce=P.label;if(P.span>1&&P.label.width>0&&P.label.lines.length>1&&P.bw>P.nw&&(ue||!wb.has(P.shape))){let pe=(P.style.bold?1:0)|(P.style.italic?2:0),V=P.label.width+(P.bw-P.nw);ce=Ge(P.block.label,!1,a,P.label.size,V,pe)}ne+=``+(ue?bb(P.mask,P.bw,P.bh,xb+P.style.shape):hr(P.shape,P.bw,P.bh,xb+P.style.shape,h2+P.style.line))+Ne(ce,P.dx,P.dy,` class="pele-label"${ue||Gi(P.shape)?vt(P.style):""}${P.style.text}`,c)+""}let k="",J="",te="";for(let re=0;re0)V=S2(K[re][0],ae,Rt(ce),Rt(pe));else{for(let de=0;de`+_t(ce,V.sx,V.sy,V.sdx,V.sdy,X||"var(--_l)")+_t(pe,V.ex,V.ey,V.edx,V.edy,X||"var(--_l)")+"",ue.width>0){let de=oe[re].lx+F,Se=oe[re].ly+W;te+=dn(P.id,ue,de,Se,"",c)}}return{svg:at("block",j,Q,i,n,e,Ne(D,j/2,o+D.height/2,' class="pele-title" font-weight="var(--_tw)"')+(Y?`${Y}`:"")+Dn(k)+(J?`${J}`:"")+`${ne}`+(te?`${te}`:"")),width:j,height:Q,links:[]}}var Mb={type:"block",math:!0,parse(e,t,n){let r=new Pc;return r.title=n,mb(e,r),r},render:Tb};var C2=new Set(["label","type","descr","techn","sprite","tags","link","bgColor","fontColor","borderColor","shadowing","shape","legendText","legendSprite"]),N2=new Set(["label","descr","techn","sprite","tags","link","textColor","lineColor"]);function Jo(e,t){let{key:n,value:r}=t;"from"in e&&(n==="offsetX"||n==="offsetY")?e[n]=parseInt(r):("from"in e?N2:C2).has(n)?e[n]=r:(e.extra??=new Map).set(n,r)}function jt(e,t,n){n!==void 0&&(typeof n=="string"?e[t]=n:Jo(e,n))}function Vi(e,t,n){n===void 0?e[t]??="":jt(e,t,n)}function Cb(e,t){e.labelAttr=void 0,typeof t=="object"?(e.label="",e.labelAttr=t,Jo(e,t)):e.label=t??""}var Gc=class{constructor(){fe(this,"type","c4");fe(this,"c4Type");fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"shapes",[]);fe(this,"boundaries",[{alias:"global",label:"global",type:"global",parent:void 0}]);fe(this,"rels",[]);fe(this,"shapeInRow",4);fe(this,"boundaryInRow",2);fe(this,"shapeIndex",new Map);fe(this,"boundaryIndex",new Map);fe(this,"relIndex",new Map);fe(this,"current",this.boundaries[0]);fe(this,"stack",[])}setC4Type(t){this.c4Type=t}setTitle(t){this.title=t}setAccDescription(t){this.accDescr=t.replace(/\n\s+/g,` +`)}element(t,n,r,i){let s=typeof r=="string"?n.get(r):void 0;return s===void 0&&(s={alias:"",label:"",parent:void 0},t.push(s),typeof r=="string"?(s.alias=r,n.set(r,s)):(s.aliasAttr=r,Jo(s,r))),Cb(s,i),s}addPersonOrSystem(t,n){let r=this.element(this.shapes,this.shapeIndex,n[0],n[1]);Vi(r,"descr",n[2]),this.finishShape(r,t,n,3)}addContainer(t,n){let r=this.element(this.shapes,this.shapeIndex,n[0],n[1]);Vi(r,"techn",n[2]),Vi(r,"descr",n[3]),this.finishShape(r,t,n,4)}addComponent(t,n){this.addContainer(t,n)}finishShape(t,n,r,i){jt(t,"sprite",r[i]),jt(t,"tags",r[i+1]),jt(t,"link",r[i+2]),t.kind=n,t.parent=this.current}boundary(t,n){let r=this.element(this.boundaries,this.boundaryIndex,t[0],t[1]);return t[2]===void 0?r.type=n:jt(r,"type",t[2]),r}open(t){t.parent=this.current,this.stack.push(this.current),this.current=t}addPersonOrSystemBoundary(t,n="system"){let r=this.boundary(t,n);jt(r,"tags",t[3]),jt(r,"link",t[4]),this.open(r)}addContainerBoundary(t){this.addPersonOrSystemBoundary(t,"container")}addDeploymentNode(t,n){let r=this.boundary(n,"node");Vi(r,"descr",n[3]),jt(r,"sprite",n[4]),jt(r,"tags",n[5]),jt(r,"link",n[6]),r.nodeType=t,this.open(r)}popBoundaryParseStack(){this.current=this.stack.pop()??this.boundaries[0]}addRel(t,n){let r=n[0],i=n[1];if(r===void 0||i===void 0||n[2]===void 0)return;let s=typeof r=="string"&&typeof i=="string",a=s?this.relIndex.get(r)?.get(i):void 0;if(a===void 0){if(a={type:t,from:"",to:"",label:""},this.rels.push(a),s){let o=this.relIndex.get(r);o===void 0&&this.relIndex.set(r,o=new Map),o.set(i,a)}typeof r=="string"?a.from=r:a.fromAttr=r,typeof i=="string"?a.to=i:a.toAttr=i}a.type=t,Cb(a,n[2]),Vi(a,"techn",n[3]),Vi(a,"descr",n[4]),jt(a,"sprite",n[5]),jt(a,"tags",n[6]),jt(a,"link",n[7])}getC4Shape(t){return this.shapeIndex.get(t)??this.boundaryIndex.get(t)}updateElStyle(t,n){let r=typeof n[0]=="string"?this.getC4Shape(n[0]):void 0;r!==void 0&&(jt(r,"bgColor",n[1]),jt(r,"fontColor",n[2]),jt(r,"borderColor",n[3]),jt(r,"shadowing",n[4]),jt(r,"shape",n[5]),jt(r,"sprite",n[6]),jt(r,"techn",n[7]),jt(r,"legendText",n[8]),jt(r,"legendSprite",n[9]))}updateRelStyle(t,n){let r=n[0],i=n[1],s=typeof r=="string"&&typeof i=="string"?this.relIndex.get(r)?.get(i):void 0;if(s===void 0)return;jt(s,"textColor",n[2]),jt(s,"lineColor",n[3]);let a=n[4],o=n[5];typeof a=="string"?s.offsetX=parseInt(a):a!==void 0&&Jo(s,a),typeof o=="string"?s.offsetY=parseInt(o):o!==void 0&&Jo(s,o)}updateLayoutConfig(t,n){let r=a=>a===void 0?NaN:parseInt(typeof a=="string"?a:a.value),i=r(n[0]),s=r(n[1]);i>=1&&(this.shapeInRow=i),s>=1&&(this.boundaryInRow=s)}};var sf=["$end","INVALID","direction_tb","direction_bt","direction_rl","direction_lr","title","accDescription","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","NEWLINE","C4_CONTEXT","C4_CONTAINER","C4_COMPONENT","C4_DYNAMIC","C4_DEPLOYMENT","PERSON","PERSON_EXT","SYSTEM","SYSTEM_DB","SYSTEM_QUEUE","SYSTEM_EXT","SYSTEM_EXT_DB","SYSTEM_EXT_QUEUE","CONTAINER","CONTAINER_DB","CONTAINER_QUEUE","CONTAINER_EXT","CONTAINER_EXT_DB","CONTAINER_EXT_QUEUE","COMPONENT","COMPONENT_DB","COMPONENT_QUEUE","COMPONENT_EXT","COMPONENT_EXT_DB","COMPONENT_EXT_QUEUE","ENTERPRISE_BOUNDARY","SYSTEM_BOUNDARY","BOUNDARY","CONTAINER_BOUNDARY","NODE","NODE_L","NODE_R","REL","BIREL","REL_U","REL_D","REL_L","REL_R","REL_B","REL_INDEX","UPDATE_EL_STYLE","UPDATE_REL_STYLE","UPDATE_LAYOUT_CONFIG","EOF_IN_STRUCT","ATTRIBUTE_EMPTY","STR","STR_KEY","STR_VALUE","LBRACE","RBRACE","EOF"];var I2=new Map([["C4Context",14],["C4Container",15],["C4Component",16],["C4Dynamic",17],["C4Deployment",18],["Person",19],["Person_Ext",20],["System",21],["SystemDb",22],["SystemQueue",23],["System_Ext",24],["SystemDb_Ext",25],["SystemQueue_Ext",26],["Container",27],["ContainerDb",28],["ContainerQueue",29],["Container_Ext",30],["ContainerDb_Ext",31],["ContainerQueue_Ext",32],["Component",33],["ComponentDb",34],["ComponentQueue",35],["Component_Ext",36],["ComponentDb_Ext",37],["ComponentQueue_Ext",38],["Enterprise_Boundary",39],["System_Boundary",40],["Boundary",41],["Container_Boundary",42],["Deployment_Node",43],["Node",43],["Node_L",44],["Node_R",45],["Rel",46],["BiRel",47],["Rel_Up",48],["Rel_U",48],["Rel_Down",49],["Rel_D",49],["Rel_Left",50],["Rel_L",50],["Rel_Right",51],["Rel_R",51],["Rel_Back",52],["RelIndex",53],["UpdateElementStyle",54],["UpdateRelStyle",55],["UpdateLayoutConfig",56]]),of=[/.*direction\s+TB[^\n]*/y,/.*direction\s+BT[^\n]*/y,/.*direction\s+RL[^\n]*/y,/.*direction\s+LR[^\n]*/y],af=/[\n\r\u2028\u2029]/g,cf=/title[^\S\r\n]*(?=[\r\n]|$)\s*/y;function Nb(e){let t=e.length,n=[],r=[],i=[],s=0,a=9,o=0,c=!1,l=-2,u=-1,h=0,d=(E,b,S)=>{n.push(E),r.push(b),i.push(S),o=S},m=E=>{for(;E{let S=e.indexOf(E,b);return S===-1?t:S},y=(E,b)=>{let S=o+E.length;if(!e.startsWith(E,o)||!qe(e.charCodeAt(S)))return!1;let x=++S;for(;S=t&&(c=!0);let E=e.charCodeAt(o);if(s===0){if(o>=t){d(64,t,t);continue}if(l!==-1&&o>=h&&(l18&&(s=1),d(S,o,b);continue}}d(1,o,o);break}if(s===1){if(o>=t)d(57,t,t);else if(E===40){let b=o+1;for(;e.charCodeAt(b)===32;)b++;e.charCodeAt(b)===44?d(58,o,b+1):o++,s=2}else if(E===41)o++,s=0;else{d(1,o,o);break}continue}if(s===2){if(o>=t)continue;if(E===41)o++,s=0;else if(E===44)e.charCodeAt(o+1)===44?d(58,o,o+2):o++;else{let b=o;for(;e.charCodeAt(b)===32;)b++;let S=e.charCodeAt(b);S===34?e.charCodeAt(b+1)===34?d(58,o,b+2):(o=b+1,s=3):S===36?(o=b+1,s=4):d(59,o,p(",",o))}continue}if(s===3){E===34?(o++,s=2):d(59,o,p('"',o));continue}if(s===4){d(60,o,p("=",o)),s=5;continue}if(s===5){if(o>=t)continue;let b=o+1;if(E===61)for(;e.charCodeAt(b)===32;)b++;if(E!==61||e.charCodeAt(b)!==34){d(1,o,o);break}o=b+1,s=6;continue}if(s===6){if(o>=t)continue;E===34?(o++,s=2):d(61,o,p('"',o));continue}if(s===7){d(a,o,p(` +`,o)),s=0;continue}E===125?(o++,s=0):d(12,o,p("}",o))}return{types:n,starts:r,ends:i}}var lf=["person","external_person","system","system_db","system_queue","external_system","external_system_db","external_system_queue","container","container_db","container_queue","external_container","external_container_db","external_container_queue","component","component_db","component_queue","external_component","external_component_db","external_component_queue"],k2=["rel","birel","rel_u","rel_d","rel_l","rel_r","rel_b","rel"],$2=["node","nodeL","nodeR"],L2="'direction_tb', 'direction_bt', 'direction_rl', 'direction_lr', 'C4_CONTEXT', 'C4_CONTAINER', 'C4_COMPONENT', 'C4_DYNAMIC', 'C4_DEPLOYMENT'",O2="'STR', 'STR_KEY', 'ATTRIBUTE', 'ATTRIBUTE_EMPTY'";function D2(e){return e===6||e===7||e===8||e===10||e===12}function Ib(e){return e>=19&&e<=56}function kb(e,t){let{types:n,starts:r,ends:i}=Nb(e),s=0,a=y=>e.slice(r[y],i[y]),o=y=>{let E=n[s];throw E===1?ft("c4",e,r[s],"",!0):ft("c4",e,r[s],`Expecting ${y}, got '${sf[E]}'`)},c=y=>{n[s]!==y&&o(`'${sf[y]}'`),s++},l=()=>{let y=[];for(;;){let E=n[s];if(E===59)y.push(a(s++).trim());else if(E===58)y.push(""),s++;else if(E===60)s++,n[s]!==61&&o("'STR_VALUE'"),y.push({key:a(s-1).trim(),value:a(s).trim()}),s++;else break}return y.length===0&&o(O2),y},u=y=>{y===6?t.setTitle(a(s++).substring(6)):y===7?t.setAccDescription(a(s++).substring(15)):y===12?t.setAccDescription(a(s++).trim()):(s++,y===8?(n[s]!==9&&o("'acc_title_value'"),t.setTitle(a(s++).trim())):(n[s]!==11&&o("'acc_descr_value'"),t.setAccDescription(a(s++).trim())))},h=y=>{s++;let E=l();if(y<=26)t.addPersonOrSystem(lf[y-19],E);else if(y<=32)t.addContainer(lf[y-19],E);else if(y<=38)t.addComponent(lf[y-19],E);else{if(y<=45)return y===39?E.splice(2,0,"ENTERPRISE"):y===40?E.splice(2,0,"SYSTEM"):y===42&&E.splice(2,0,"CONTAINER"),y>=43?t.addDeploymentNode($2[y-43],E):y===42?t.addContainerBoundary(E):t.addPersonOrSystemBoundary(E),n[s]===62?(s++,c(13)):n[s]===13?(s++,c(62),n[s]===13&&s++):o("'NEWLINE', 'LBRACE'"),!0;y<=53?(y===53&&E.splice(0,1),t.addRel(k2[y-46],E)):y===54?t.updateElStyle("update_el_style",E):y===55?t.updateRelStyle("update_rel_style",E):t.updateLayoutConfig("update_layout_config",E)}return!1},d=n[s];(d<14||d>18)&&o(L2),s++,c(13);let m=0,p=0;for(;;){let y=n[s];if(p===3||p===4){if(y===13){s++,p=2;continue}if(p===3&&Ib(y)){p=1;continue}}else if(Ib(y)){h(y)?(m++,p=1):p=4;continue}else if(D2(y)&&p!==1){u(y),p=3;continue}else p!==2&&o("'title', 'accDescription', 'acc_title', 'acc_descr', 'acc_descr_multiline_value', 'PERSON', 'REL'");if(m>0)y!==63&&o("'NEWLINE', 'RBRACE'"),s++,t.popBoundaryParseStack(),m--,p=4;else{y!==64&&o("'NEWLINE', 'EOF'"),s++,c(0),t.setC4Type(a(0));return}}}var df=/\s/;function Qs(e,t,n,r,i=0){let s=[];for(let l of e.split(` +`)){let u=Array.from(l);u.length===0&&s.push("");let h=0;for(;ht.width(u.slice(h,h+S).join(""),n,i)<=r,m=1;for(;m0;S--)if(df.test(u[h+S])){y=S+1;break}}let b=u.slice(h,h+y).join("");for(s.push(E&&b.trimEnd()||b),h+=y;E&&ht.width(l,n,i)),o=0;for(let l of a)o=Math.max(o,l);let c=Math.round(n*1.5);return{lines:s.map((l,u)=>[{text:l,style:i,width:a[u]}]),widths:a,width:o,height:s.length*c,size:n,lineHeight:c}}function Zs(e,t,n){if(e.width<=n)return e;let r=[],i=[];for(let o=0;o{r.push(c),i.push(l),c=[],l=0};for(let h of e.lines[o]){if(h.icon!==void 0||h.math){c.length&&l+h.width>n&&u(),c.push(h),l+=h.width;continue}for(let d of Array.from(h.text)){let m=c[c.length-1],p=m&&m.icon===void 0&&m.math===void 0&&m.style===h.style,E=t.width(p?m.text+d:d,e.size,h.style)-(p?m.width:0);c.length&&l+E>n&&(u(),m=void 0,E=t.width(d,e.size,h.style)),m&&m.icon===void 0&&m.math===void 0&&m.style===h.style?(m.text+=d,m.width+=E):c.push({text:d,style:h.style,width:E}),l+=E}}(c.length||!e.lines[o].length)&&u()}let s=0;for(let o of i)s=Math.max(s,o);let a={...e,lines:r,widths:i,width:s,height:r.length*e.lineHeight};return e.heights?Vo(a):a}function Zr(e,t,n,r){let i=Xr(e),s="h.icon!==void 0)){let h=e.widths[o];a+=Ne({...e,lines:[c],widths:[h],width:h,height:e.lineHeight},t+h/2,l,r);continue}let u="";for(let h of c){let d=_r(h.style&~i);u+=d?`${rt(h.text)}`:rt(h.text)}u!==""&&(a+=`${s} x="${f(t)}" y="${f(l+e.size*.35)}" text-anchor="start" xml:space="preserve">${u}`)}return a}var ji=28,ei=20,Ob=7,v2=8,P2=30,ta=88,Yc=160,zc=8,na=26,ff=e=>Math.min(12,Math.max(6,e/14)),hf=e=>Math.min(12,e/4);function Js(e,t,n,r,i,s,a,o){let c=0,l=1;if(a===0){if(in)return 1/0}else{let u=(e-i)/a,h=(n-i)/a;c=Math.max(c,Math.min(u,h)),l=Math.min(l,Math.max(u,h))}if(o===0){if(sr)return 1/0}else{let u=(t-s)/o,h=(r-s)/o;c=Math.max(c,Math.min(u,h)),l=Math.min(l,Math.max(u,h))}return c<=l?c:1/0}function ea(e,t,n,r,i,s,a,o){let c=a/n,l=o/r,u=(i-e)/n,h=(s-t)/r,d=c*c+l*l,m=2*(c*u+l*h),p=u*u+h*h-1,y=m*m-4*d*p;if(d===0||y<0)return 1/0;let E=(-m-Math.sqrt(y))/(2*d);return E>=0&&E<=1?E:p<=0?0:1/0}function Yn(e,t,n,r,i){let{x:s,y:a,w:o,h:c}=e,l=r-t,u=i-n;if(e.form==="person")return Math.min(Js(s,a+na,s+o,a+c,t,n,l,u),ea(s+o/2,a+14,13,13,t,n,l,u));if(e.form==="cyl"){let h=ff(o);return Math.min(Js(s,a+h,s+o,a+c-h,t,n,l,u),ea(s+o/2,a+h,o/2,h,t,n,l,u),ea(s+o/2,a+c-h,o/2,h,t,n,l,u))}if(e.form==="h-cyl"){let h=hf(c);return Math.min(Js(s+h,a,s+o-h,a+c,t,n,l,u),ea(s+h,a+c/2,h,c/2,t,n,l,u),ea(s+o-h,a+c/2,h,c/2,t,n,l,u))}return Js(s,a,s+o,a+c,t,n,l,u)}function pf(e,t,n,r,i){for(let s=2;s=t.x+t.w&&e.y+e.h>=t.y+t.h}function F2(e,t,n){let r=e.x+e.w/2,i=e.y+e.h/2,s=t.x+t.w/2,a=t.y+t.h/2,o=Hc(e,t);if(o||Hc(t,e)){let L=o?e:t,O=o?t:e,v=O.x+O.w/2,G=O.y+O.h/2,K=O.x-L.x,C=L.x+L.w-O.x-O.w,Z=O.y-L.y,oe=L.y+L.h-O.y-O.h,H=Math.min(K,C,Z,oe),z=H===K?L.x:H===C?L.x+L.w:v,M=H===K||H===C?G:H===oe?L.y+L.h:L.y,T=Math.min(Yn(O,z,M,v,G),1),R=z+(v-z)*T,_=M+(G-M)*T;return o?[z,M,R,_]:[R,_,z,M]}let c=r,l=i,u=s,h=a,d=Math.max(e.x,t.x),m=Math.min(e.x+e.w,t.x+t.w),p=Math.max(e.y,t.y),y=Math.min(e.y+e.h,t.y+t.h);d{for(let u=0;us)return!0;return!1};return!o(t?this.upright:this.level,uf)&&!o(this.frames[t?0:1],B2)}crossings(t){let n=0;for(let r=2;ra&&c[l]s&&n++}return n}frame(t){this.frames[0].push(t.x,t.y,t.y+t.h,t.x+t.w,t.y,t.y+t.h),this.frames[1].push(t.y,t.x,t.x+t.w,t.y+t.h,t.x,t.x+t.w)}take(t){for(let n=2;ns)continue;let u=!0;for(let h=0;h=e+uf&&a<=t-uf&&n.push(a)}return n}function U2(e,t,n,r,i,s){let a=e.x+e.w/2,o=e.y+e.h/2,c=t.x+t.w/2,l=t.y+t.h/2,u,h=(y,E,b)=>{if(!Db(y,n,e,t))return;for(let x=2;xa,E=Math.sign(l-o),b=y?[1,0]:[0,1],S=Lb(y?e.x+e.w:t.x+t.w,y?t.x:e.x);e:for(let x of r.ports(e,b[0],o+E*e.h/4,e.y+8,e.y+e.h-8))for(let I of r.ports(t,b[1],l-E*t.h/4,t.y+8,t.y+t.h-8))for(let L of S){let O=L+(a-L)*Math.min(Yn(e,L,x,a,x),1),v=L+(c-L)*Math.min(Yn(t,L,I,c,I),1),G=u;if(h([O,x,L,x,L,I,v,I],!0,b),u!==G)break e}}if(e.y+e.h<=t.y||t.y+t.h<=e.y){let y=l>o,E=Math.sign(c-a),b=y?[3,2]:[2,3],S=Lb(y?e.y+e.h:t.y+t.h,y?t.y:e.y);e:for(let x of r.ports(e,b[0],a+E*e.w/4,e.x+8,e.x+e.w-8))for(let I of r.ports(t,b[1],c-E*t.w/4,t.x+8,t.x+t.w-8))for(let L of S){let O=L+(o-L)*Math.min(Yn(e,x,L,x,o),1),v=L+(l-L)*Math.min(Yn(t,I,L,I,l),1),G=u;if(h([x,O,x,L,I,L,I,v],!1,b),u!==G)break e}}if(!u)return;let{points:d,upright:m,sides:p}=u;return r.take(d),r.claim(e,p[0],m?d[1]:d[0]),r.claim(t,p[1],m?d[7]:d[6]),vb(d,2,i,s,{room:m?ta:Yc})}function Pb(e,t,n,r,i,s,a){if(e===t){let E=Math.min(e.h/2-4,10),b=Math.hypot(ji,E),S=e.x+e.w,x=e.y+e.h/2,I=ji/b,L=E/b;return{d:`M${f(S+I*s)},${f(x-E-L*s)}C${f(S+ji)},${f(x-E*2)} ${f(S+ji)},${f(x+E*2)} ${f(S+I*a)},${f(x+E+L*a)}`,sx:S,sy:x-E,sdx:-I,sdy:L,ex:S,ey:x+E,edx:-I,edy:-L,x0:S+ji+4,y0:x,x1:S+ji+4,y1:x,nx:1,ny:0,lean:0,room:64,points:[]}}let[o,c,l,u]=F2(e,t,n),h=o===l,d=!1;if(r&&!Hc(e,t)&&!Hc(t,e))for(let E of r)E!==e&&E!==t&&Js(E.x,E.y,E.x+E.w,E.y+E.h,o,c,l-o,u-c)<=1&&(d=!0);if(r&&d&&!h&&c!==u){let E=U2(e,t,r,i,s,a);if(E)return E;i.squeezed++}if(r&&d&&(h||c===u)){let E=A=>{let D=A?-1/0:1/0,U=B=>{let F=h?B.x:B.y;D=A?Math.max(D,F+(h?B.w:B.h)):Math.min(D,F)};U(e),U(t);for(let B of r)B!==e&&B!==t&&Js(B.x,B.y,B.x+B.w,B.y+B.h,o,c,l-o,u-c)<=1&&U(B);return D},b=h?Math.min(e.y,t.y):Math.min(e.x,t.x),S=h?Math.max(e.y+e.h,t.y+t.h):Math.max(e.x+e.w,t.x+t.w),x=(A,D)=>{for(let U of r){if(U===e||U===t)continue;let B=h?U.yb:U.xb,F=h?U.x:U.y,W=F+(h?U.w:U.h);if(B&&(A?W>D:F{let D=E(A),U=A?1:-1,B=h?A?1:0:A?3:2,F=h?i.ports(e,B,L+G*e.h/4,e.y+8,e.y+e.h-8)[0]:i.ports(e,B,I+G*e.w/4,e.x+8,e.x+e.w-8)[0],W=h?i.ports(t,B,v-G*t.h/4,t.y+8,t.y+t.h-8)[0]:i.ports(t,B,O-G*t.w/4,t.x+8,t.x+t.w-8)[0],j=Y=>{if(h){let k=Y+(I-Y)*Math.min(Yn(e,Y,F,I,F),1),J=Y+(O-Y)*Math.min(Yn(t,Y,W,O,W),1);return[k,F,Y,F,Y,W,J,W]}let ne=Y+(L-Y)*Math.min(Yn(e,F,Y,F,L),1),q=Y+(v-Y)*Math.min(Yn(t,W,Y,W,v),1);return[F,ne,F,Y,W,Y,W,q]},Q=j(D+U*ei);for(let Y=0;Y<=4;Y++){let ne=D+U*(ei+Y*Ob),q=j(ne);if(Db(q,r,e,t)&&(Q=q,i.free(h,ne,F,W)))return{points:Q,side:B,p0:F,p1:W,step:Y}}return{points:Q,side:B,p0:F,p1:W,step:5}},C=h?u>c:li.crossings(A.points)*8+A.step,T=oe&&!Z||z&&M(z)4&&i.squeezed++,i.take(R),i.claim(e,_,$),i.claim(t,_,g),vb(R,2,s,a,h?{nx:w,lean:P2,room:ta}:{room:Yc})}let m=Math.hypot(l-o,u-c)||1,p=(l-o)/m,y=(u-c)/m;return(h||c===u)&&i.take([o,c,l,u]),{d:`M${f(o+p*s)},${f(c+y*s)}L${f(l-p*a)},${f(u-y*a)}`,sx:o,sy:c,sdx:-p,sdy:-y,ex:l,ey:u,edx:p,edy:y,x0:o,y0:c,x1:l,y1:u,nx:n?-y:0,ny:n?p:0,lean:0,room:Math.abs(p)>Math.abs(y)?ta:Yc,points:[o,c,l,u]}}var gf=216,G2=64,Fb=14,Y2=12,H2=ta+zc+3*Lt,K2=88,Bb=ei+8,Vc=48,Xi=16,jc=10,mf=new Map([["person","person"],["box","rect"],["rounded","rect"],["component","rect"],["cylinder","cyl"],["database","cyl"],["db","cyl"],["queue","h-cyl"],["pipe","h-cyl"]]);function z2(e){let t=mf.get((e.shape??"").toLowerCase())??mf.get((e.sprite??"").toLowerCase());if(t)return t;if(e.tags)for(let r of e.tags.split(",")){let i=mf.get(r.trim().toLowerCase());if(i)return i}let n=e.kind;return n.endsWith("person")?"person":n.endsWith("_db")?"cyl":n.endsWith("_queue")?"h-cyl":"rect"}function V2(e,t,n,r,i=gf){let s=z2(e),a=s==="h-cyl"?36:0,o=s==="person"?na:s==="cyl"?24:0,c=i-2*Fb-a,l=[Ge("«"+e.kind.replace(/_/g," ")+"»",!1,t,r-1,c),Ge(e.label,!1,t,n,c,1),Ge(e.techn?`[${e.techn}]`:void 0,!1,t,r,c),Ge(e.descr,!1,t,r,c)],u=0,h=l[3].height>0?4:0;for(let d of l)u=Math.max(u,d.width),h+=d.height;return{shape:e,form:s,labels:l,textH:h,x:0,y:0,w:Math.max(i,u+2*Fb+a),h:Math.max(G2,h+2*Y2+o)}}function Wb(e,t,n,r,i){let s=0,a=0;for(let o=0;o0?a-r:0]}function Ub(e,t,n,r,i,s){let a=i===void 0?Bb:12,o=new Map;for(let y of e.boundaries){let E=i===void 0?4e3:Math.max(80,i-2*Xi-2*Bb*2),b=y.parent?[Ge(y.label,!1,t,n,E,1),Ge(y.type?`[${y.type}]`:void 0,!1,t,r,E),Ge(y.descr,!1,t,r,E)]:[],S=0,x=0;for(let I of b)S+=I.height,x=Math.max(x,I.width);o.set(y,{boundary:y,kids:[],nodes:[],labels:b,head:S>0?S+jc+6+ei:a,headW:x,headX:Xi,x:0,y:0,w:0,h:0,form:"rect"})}let c=o.get(e.boundaries[0]);for(let y of o.values()){let E=y.boundary.parent;E&&o.get(E)?.kids.push(y)}let l=[c],u=new Map([[c.boundary,0]]);for(let y=0;y=0;y--){let E=l[y],b=i===void 0?H2:s,S=(K,C,Z)=>{if(i===void 0)return C;let oe=1;for(let H of K)oe=Math.max(oe,H.w);return Math.max(1,Math.min(C,Math.floor((i+Z-2*a)/(oe+Z))))},[x,I]=Wb(E.nodes,S(E.nodes,h,b),b,K2,!0),[L,O]=Wb(E.kids,S(E.kids,d,Vc),Vc,Vc,!1),v=I>0&&O>0?Vc:0,G=E===c?0:a;m.set(E,I+v),E.w=Math.max(x,L,E.headW+2*Xi-2*G)+2*G,E.h=(G&&E.head)+I+v+O+G}let p=new Map;for(let y of l){let E=y.x+(y===c?0:a),b=y.y+(y===c?0:y.head);for(let S of y.nodes)S.x+=E,S.y+=b,p.set(S.shape,S);for(let S of y.kids)S.x+=E,S.y+=b+m.get(y);y!==c&&p.set(y.boundary,y)}return{order:l,boxes:p}}var j2=7,qc=36,bf=24,Gb=2e3,Xc=8,X2=[.5,.4,.6,.3,.7,.2,.8],q2=2e6;function ra(e,t,n){let r=[];return e&&r.push("fill:"+e),t&&r.push("stroke:"+t),n&&r.push("color:"+n),Ct(r)}function yf(e,t,n,r,i){return t?Zn(e,ki(t.includes("¶ß")?t.replace(/\ufb02\u00b0\u00b0?/g,"#").replace(/\u00b6\u00df/g,";"):t),n,r,i):e}function Yb(e,t,n){return An(n,r=>{if(!r)return Ef(e,t,n,!1)[0];let[i,s]=Ef(e,t,n,!0,qc);for(let a=qc+bf;s>0&&a<=qc+3*bf;a+=bf){let[o,c]=Ef(e,t,n,!0,a);c{m=Math.min(m,B),p=Math.min(p,F),y=Math.max(y,W),E=Math.max(E,j)},S=[],x=new Map;for(let B of e.rels){let F=B.fromAttr?void 0:e.getC4Shape(B.from),W=B.toAttr?void 0:e.getC4Shape(B.to),j=F&&h.get(F),Q=W&&h.get(W);if(!j||!Q)throw new Qe(`C4 rel "${B.from}" -> "${B.to}" references an unknown shape or boundary`,"semantic",{type:"c4"});S.push(j,Q);let Y=x.get(j);Y||x.set(j,Y=new Set),Y.add(Q)}let I=[],L=[];for(let B of u)for(let F of B.nodes)I.push(F),L.push(F.x+Xc,F.y+Xc,F.x+F.w-Xc,F.y+F.h-Xc);let O=e.rels.length*(I.length+u.length+3*e.rels.length)<=q2,v=(B,F,W,j)=>{let Q=0;for(let Y=0;Y0&&(Q+=ne*q)}return Q},G=B=>B?Math.max(-Gb,Math.min(Gb,B)):0,K="",C="",Z=Rt("arrow_point"),oe=[];for(let B of u){if(B===d)continue;let F=ra(B.boundary.bgColor,void 0,void 0).shape;Mn(F)&&oe.push({box:[B.x,B.y,B.x+B.w,B.y+B.h],shape:F})}let H=new Kc;for(let B of u)B!==d&&H.frame(B);let z=e.rels.map((B,F)=>{let W=S[F*2],j=S[F*2+1],Q=ra(void 0,B.lineColor,void 0),Y=B.type==="birel"||B.type==="rel_b",ne=B.type!=="rel_b",q=W!==j&&x.get(j)?.has(W)===!0,k=Pb(W,j,q?j2:0,O?I:void 0,H,Y?Z:0,ne?Z:0);b(Math.min(k.x0,k.x1),Math.min(k.y0,k.y1),Math.max(k.x0,k.x1),Math.max(k.y0,k.y1)),Y&&O&&L.push(k.sx-Lt,k.sy-Lt,k.sx+Lt,k.sy+Lt),ne&&O&&L.push(k.ex-Lt,k.ey-Lt,k.ex+Lt,k.ey+Lt);let J=Mr(k.d,[k.sx,k.sy,k.ex,k.ey],oe,Q.line),te=J||(Q.stroke?rt(Q.stroke):"var(--_l)");return J===""&&(K+=Cr(k,Y?"arrow_point":"none",ne?"arrow_point":"none",Q.line)),C+=``+(Y?_t("arrow_point",k.sx,k.sy,k.sdx,k.sdy,te):"")+(ne?_t("arrow_point",k.ex,k.ey,k.edx,k.edy,te):"")+"",k});for(let B of u){if(!O||B.headW===0)continue;let F=B.y+jc,W=B.y+B.head-ei,j=1/0;for(let Q of[Xi,(B.w-B.headW)/2,B.w-Xi-B.headW]){let Y=0;for(let ne of z)pf(ne.points,B.x+Q-4,F,B.x+Q+B.headW+4,W)&&Y++;if(Y{let W=z[F],j=B.from+"-"+B.to,Q=ra(void 0,void 0,B.textColor),Y=(e.c4Type==="C4Dynamic"?F+1+": ":"")+B.label,ne=Ge(Y,!1,o,a,W.room),q=Ge(B.techn?`[${B.techn}]`:void 0,!1,o,a,W.room,2),k=Math.max(ne.width,q.width)+zc,J=ne.height+q.height;if(J===0)return;let te=Math.abs(W.nx)*(k/2)+Math.abs(W.ny)*(J/2)+2,se=W.lean?Math.max(0,Math.min(W.lean,te-14)):te,re=W.nx*se+(r?0:G(B.offsetX)),P=W.ny*se+(r?0:G(B.offsetY)),ee=.5;if(O){let ce=1/0,pe=re!==W.nx*se||P!==W.ny*se;for(let V=0;V<(pe?2:1)&&ce>0;V++){let X=V?W.nx*se:re,le=V?W.ny*se:P;for(let de of X2){let Se=W.x0+(W.x1-W.x0)*de+X,_e=W.y0+(W.y1-W.y0)*de+le,xe=v(Se-k/2,_e-J/2,Se+k/2,_e+J/2);if(xe`+(B.descr?`${Ue(B.descr)}`:"")+``+yf(Ne(ne,ae,ue+ne.height/2,Q.text)+Ne(q,ae,ue+ne.height+q.height/2,` class="pele-c4-techn" fill="var(--_m)"${Q.text}`),B.link,j,l,n)+""});let T="",R="";for(let B of u){if(B!==d){let F=B.boundary,W=ra(F.bgColor,F.borderColor,F.fontColor),j=B.x+B.headX,Q=B.y+jc,Y=vt(W)+W.text,ne=vt(W,"var(--_m)")+W.text,q=Zr(B.labels[0],j,Q,` class="pele-cluster-label" font-weight="var(--_hw)"${Y}`);Q+=B.labels[0].height,q+=Zr(B.labels[1],j,Q,` class="pele-c4-type" font-size="${a}"${ne}`),Q+=B.labels[1].height,q+=Zr(B.labels[2],j,Q,` class="pele-c4-descr" font-size="${a}"${ne}`),T+=``+yf(q,F.link,F.alias,l,n)+""}for(let F of B.nodes){let W=F.shape,j=W.kind.startsWith("external"),Q=ra(W.bgColor,W.borderColor,W.fontColor),Y=' stroke="var(--_b)"'+(j?' stroke-dasharray="4 3"':""),{w:ne,h:q,form:k,labels:J}=F,te=k==="h-cyl"?-hf(q)/2:0,se=k==="person"?na/2:k==="cyl"?ff(ne)/2:0,re=vt(Q)+Q.text,P=vt(Q,"var(--_m)")+Q.text,ee=se-F.textH/2,ae=Ne(J[0],te,ee+J[0].height/2,` class="pele-c4-type" font-size="${a-1}"${P}`);ee+=J[0].height,ae+=Ne(J[1],te,ee+J[1].height/2,` class="pele-label" font-weight="var(--_hw)"${re}`),ee+=J[1].height,ae+=Ne(J[2],te,ee+J[2].height/2,` class="pele-c4-techn" font-size="${a}"${P}`),ee+=J[2].height+4,ae+=Ne(J[3],te,ee+J[3].height/2,` class="pele-c4-descr" font-size="${a}"${re}`),R+=``+yf(hr(k,ne,q,` fill="var(${j?"--_bg":"--_s"})"${Y}${Q.shape}`,Y+Q.line)+ae,W.link,W.alias,l,n)+""}}let _=Ge(e.title,!1,o,s,r?kt(n):4e3,1),$=_.height>0?_.height+12:0,g=Math.max(y-m,_.width),N=Math.ceil(g+2*c),w=Math.ceil(E-p+$+2*c),A=c-m+(g-(y-m))/2,D=c+$-p;return[{svg:at("c4",N,w,s,n,e,Ne(_,N/2,c+_.height/2,' class="pele-title" font-weight="var(--_tw)"')+``+(T?`${T}`:"")+Dn(K)+(C?`${C}`:"")+(R?`${R}`:"")+(M?`${M}`:"")+""),width:N,height:w,links:l},H.squeezed]}var Hb={type:"c4",parse(e,t,n){let r=new Gc;return n&&(r.title=n),kb(e,r),r},render:Yb};function xf(e){let t=0;for(let n=e.indexOf("~");n!==-1;n=e.indexOf("~",n+1))t++;return t}function Q2(e){let t=xf(e);if(t<=1)return e;let n=t%2!==0&&e.startsWith("~"),r=e.split(""),i=[];for(let s=n?1:0;s";return r.join("")}function xs(e){if(!e.includes("~"))return e;let t=e.split(/(,)/),n=[];for(let r=0;r0&&r+1r&&t.charCodeAt(s)!==41;)s--;let a=s-1;for(;a>r&&t.charCodeAt(a)!==40;)a--;if(a>r){let o=t[r],c=Kb(o)&&a>r+1;c&&(this.visibility=o),this.id=t.slice(c?r+1:r,a),this.parameters=t.slice(a+1,s).trim();let l=s+1,u="";if(l=48&&t<=57?J2+e:e).className}var Qc=class{constructor(){fe(this,"type","class");fe(this,"lineType",Z2);fe(this,"relationType",qi);fe(this,"direction","TB");fe(this,"classes",new Map);fe(this,"relations",[]);fe(this,"notes",new Map);fe(this,"namespaces",new Map);fe(this,"interfaces",[]);fe(this,"styleClasses",new Map);fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"namespaceStack",[]);fe(this,"withCssClass",new Map)}addClass(t){let{className:n,type:r}=As(t);if(this.classes.has(n))return;let i={id:n,type:r,label:n,cssClasses:"default",methods:[],members:[],annotations:[],styles:[]};this.classes.set(n,i),this.tag(i,"default")}tag(t,n){let r=this.withCssClass.get(n);r?r.add(t):this.withCssClass.set(n,new Set([t]))}ensure(t){return this.addClass(t),this.classes.get(As(t).className)}setClassLabel(t,n){this.ensure(t).label=n}addRelation(t){let{type1:n,type2:r}=t.relation;n===qi.LOLLIPOP&&r==="none"?(this.addClass(t.id2),t.id1=this.addInterface(t.id1,t.id2)):r===qi.LOLLIPOP&&n==="none"?(this.addClass(t.id1),t.id2=this.addInterface(t.id2,t.id1)):(this.addClass(t.id1),this.addClass(t.id2)),t.id1=As(t.id1).className,t.id2=As(t.id2).className,t.relationTitle1=t.relationTitle1.trim(),t.relationTitle2=t.relationTitle2.trim(),this.relations.push(t)}addInterface(t,n){let r=`interface${this.interfaces.length}`;return this.interfaces.push({id:r,label:t,classId:n}),r}addAnnotation(t,n){this.ensure(t).annotations.push(n)}addMember(t,n){let r=this.ensure(t);if(typeof n!="string")return;let i=n.trim();if(i.startsWith("<<")&&i.endsWith(">>"))r.annotations.push(i.substring(2,i.length-2));else if(i.indexOf(")")>0){let s=new sa(i,"method");(s.memberType==="method"?r.methods:r.members).push(s)}else i&&r.members.push(new sa(i,"attribute"))}addMembers(t,n){if(Array.isArray(n)){n.reverse();for(let r of n)this.addMember(t,r)}}addNote(t,n){let r=this.notes.size,i=`note${r}`;return this.notes.set(i,{id:i,class:n,text:t,index:r}),i}cleanupLabel(t){return(t.startsWith(":")?t.substring(1):t).trim()}setCssClass(t,n){for(let r of t.split(",")){let i=this.classes.get(zb(r));if(i!==void 0){i.cssClasses+=" "+n;for(let s of n.split(" "))this.tag(i,s)}}}defineClass(t,n){for(let r of t){let i=this.styleClasses.get(r);if(i===void 0&&(i={id:r,styles:[],textStyles:[]},this.styleClasses.set(r,i)),!n)continue;for(let o of n)o.includes("color")&&i.textStyles.push(o.replace("fill","bgFill")),i.styles.push(o);let s=this.withCssClass.get(r);if(s===void 0)continue;let a=n.flatMap(o=>o.split(","));for(let o of s)for(let c of a)o.styles.push(c)}}setTooltip(t,n){if(n!==void 0)for(let r of t.split(",")){let i=this.classes.get(As(r).className);i&&(i.tooltip=n)}}setLink(t,n,r){let i=bt(n).trim();for(let s of t.split(",")){let a=this.classes.get(zb(s));a&&(a.link=i?ki(i):void 0,a.linkTarget=typeof r=="string"?r:"_blank")}this.setCssClass(t,"clickable")}setClickEvent(t,n,r){for(let i of t.split(",")){let s=this.classes.get(As(i).className);s&&(s.haveCallback=!0)}this.setCssClass(t,"clickable")}setDirection(t){this.direction=t}setAccTitle(t){this.accTitle=t.replace(/^\s+/g,"")}setAccDescription(t){this.accDescr=t.replace(/\n\s+/g,` +`)}addNamespace(t,n){let r=this.namespaceStack[this.namespaceStack.length-1],i=r?`${r}.${t}`:t;this.namespaceStack.push(i);let s=this.namespaces.get(i);if(s)return s.explicit=!0,n&&(s.label=n),i;let a=r||void 0,o=r?r.length+1:0;for(;;){let c=i.indexOf(".",o),l=c===-1,u=l?i:i.slice(0,c),h=this.namespaces.get(u);if(h===void 0){let m=i.slice(o,l?i.length:c);h={id:u,label:l&&n?n:m,classes:new Map,notes:new Map,children:new Map,parent:a,explicit:l},this.namespaces.set(u,h)}else l&&(h.explicit=!0);let d=a?this.namespaces.get(a):void 0;if(d&&(d.children.has(u)||d.children.set(u,h),h.parent??=a),l)return i;a=u,o=c+1}}popNamespace(){this.namespaceStack.pop()}addClassesToNamespace(t,n,r){let i=this.namespaces.get(t);if(i!==void 0){for(let s of n){let{className:a}=As(s),o=this.classes.get(a);o!==void 0&&(o.parent=t,i.classes.set(a,o))}for(let s of r){let a=this.notes.get(s);a!==void 0&&(a.parent=t,i.notes.set(s,a))}}}setCssStyle(t,n){let r=this.classes.get(t);if(!(!n||!r))for(let i of n)for(let s of i.split(","))r.styles.push(s)}};var Af=["$end","INVALID","CLASS_DIAGRAM","NEWLINE","EOF","SQS","STR","SQE","DOT","GENERICTYPE","LABEL","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","STRUCT_START","STRUCT_STOP","NAMESPACE","STYLE_SEPARATOR","ANNOTATION_START","ANNOTATION_END","CLASS","MEMBER","NOTE_FOR","NOTE","CLASSDEF","ALPHA","COMMA","direction_tb","direction_bt","direction_rl","direction_lr","AGGREGATION","EXTENSION","COMPOSITION","DEPENDENCY","LOLLIPOP","LINE","DOTTED_LINE","CALLBACK","LINK","LINK_TARGET","CLICK","CALLBACK_NAME","CALLBACK_ARGS","HREF","STYLE","CSSCLASS","COLON","BRKT","PCT","MINUS","UNICODE_TEXT","BQUOTE_STR","EDGE_STATE","EOF_IN_STRUCT","OPEN_IN_STRUCT","PLUS","EQUALS","PUNCTUATION"];var eM=[4,6,4,9,44,45,12,14,15,4,56,4,56],tM=[/.*direction\s+TB[^\n]*/y,/.*direction\s+BT[^\n]*/y,/.*direction\s+RL[^\n]*/y,/.*direction\s+LR[^\n]*/y],Sf=/[\n\r\u2028\u2029]/g;function Vb(e){let t=e.length,n=[],r=[],i=[],s=[],a=0,o=0,c=e.indexOf("direction"),l=-1,u=0,h=(O,v,G)=>(n.push(O),r.push(e.slice(v,G)),i.push(v),o=G,!0),d=O=>{s.push(a),a=O},m=()=>{s.length>0&&(a=s.pop())},p=O=>e.startsWith(O,o)&&!ot(e.charCodeAt(o+O.length)),y=O=>{for(;O{let v=e.indexOf(O,o);return v===-1?t:v},b=O=>{let v=o,G=-1;for(let K=e.charCodeAt(v);v{switch(O){case 99:if(p("cssClass"))return h(48,o,o+8);if(p("callback"))return h(40,o,o+8);if(p("click"))return h(43,o,o+5);break;case 108:if(p("link"))return h(41,o,o+4);break;case 110:if(p("note for"))return h(24,o,o+8);if(p("note"))return h(25,o,o+4);break;case 60:if(e.charCodeAt(o+1)===60)return h(20,o,o+2);break;case 62:if(e.charCodeAt(o+1)===62)return h(21,o,o+2);break;case 104:if(p("href"))return h(46,o,o+4);break}return!1},x=O=>{if(S(O))return!0;let v=e.charCodeAt(o+1);switch(O){case 34:return d(1),o++,!0;case 126:return d(3),o++,!0;case 96:return d(2),o++,!0;case 95:if(p("_self"))return h(42,o,o+5);if(p("_blank"))return h(42,o,o+6);if(p("_parent"))return h(42,o,o+7);if(p("_top"))return h(42,o,o+4);break;case 60:return v===124?h(34,o,o+2):h(36,o,o+1);case 124:return v===62&&h(34,o,o+2);case 62:return h(36,o,o+1);case 42:return h(35,o,o+1);case 111:if(!ot(v))return h(33,o,o+1);break;case 40:return v===41&&h(37,o,o+2);case 45:return v===45?h(38,o,o+2):h(52,o,o+1);case 46:return v===46?h(39,o,o+2):h(8,o,o+1);case 58:{let G=o+1;for(;Go+1?h(10,o,G):v===58&&e.charCodeAt(o+2)===58&&h(19,o,o+3)}case 43:return h(58,o,o+1);case 37:return h(51,o,o+1);case 61:return h(59,o,o+1);case 91:return h(5,o,o+1);case 93:return h(7,o,o+1);case 33:case 35:case 36:case 38:case 39:case 44:case 63:case 92:case 47:return h(60,o,o+1)}if(ot(O)){let G=o+1;for(;ot(e.charCodeAt(G));)G++;return h(27,o,G)}return Oi(O)&&h(53,o,o+1)},I=()=>{if(c===-1||o=l))return!1;for(let O=0;O<4;O++){let v=tM[O];if(v.lastIndex=o,v.test(e))return h(29+O,o,v.lastIndex)}return u=l,!1},L=O=>{if(I())return!0;if(qe(O))return b(!1),!0;switch(O){case 37:if(e.charCodeAt(o+1)===37){let v=E(` +`);for(;v=t){n.push(eM[a]),r.push(""),i.push(t);break}let O=e.charCodeAt(o),v=!0;switch(a){case 0:v=L(O);break;case 9:qe(O)?b(!0):O===125?(m(),m(),h(17,o,o+1)):O===123?(d(10),h(16,o,o+1)):v=x(O);break;case 10:if(O===34)d(1),o++;else if(O===125)m(),h(17,o,o+1);else if(O===91&&e.startsWith("*]",o+1))h(55,o,o+3);else if(O===123)h(57,o,o+1);else if(O===10)o++;else{let G=o+1;for(;G{let v=n[s];throw v===1?ft("class",e,i[s],"",!0):ft("class",e,i[s],`Expecting ${O}, got '${Af[v]}'`)},o=O=>(n[s]!==O&&a(`'${Af[O]}'`),r[s++]),c=()=>(Zc[n[s]]===0&&a("'UNICODE_TEXT', 'NUM', 'ALPHA', 'MINUS'"),r[s++]),l=O=>{let v="";for(;;){if(n[s]===54){v+=r[s++];break}Zc[n[s]]===0&&a(nM),v+=r[s++];let G=n[s];if(G===8)v+=".",s++;else if(Zc[G]===0&&G!==54)break}return O&&n[s]===9&&(v+="~"+r[s++]+"~"),v},u=()=>{s++;let O=o(6);return o(7),O},h=()=>{n[s]!==23&&a("'STRUCT_STOP', 'MEMBER'");let O=[];for(;n[s]===23;)O.push(r[s++]);return o(17),O.reverse()},d=()=>{s++;let O=l(!0);switch(t.addClass(O),n[s]===5&&t.setClassLabel(O,u()),n[s]){case 19:{s++;let v=c();t.setCssClass(O,v),n[s]===16&&(s++,t.addMembers(O,h()));break}case 16:s++,n[s]===17?s++:t.addMembers(O,h());break;case 20:{s++;let v=c();o(21),t.addAnnotation(O,v),n[s]===16&&(s++,n[s]===17?s++:t.addMembers(O,h()));break}}return O},m=()=>{if(n[s++]===25)return t.addNote(o(6));let O=l(!0);return t.addNote(o(6),O)},p=()=>{let O=[];for(;;){s++;let v=l(!1),G=n[s]===5?t.addNamespace(v,u()):t.addNamespace(v);o(16),n[s]===3&&s++,O.push({id:G,classes:[],notes:[]});let K=!0;for(;K;){let C=O[O.length-1],Z=n[s];if(Z===18)break;for(Z===22?C.classes.push(d()):Z===25||Z===24?C.notes.push(m()):a("'NAMESPACE', 'CLASS', 'NOTE_FOR', 'NOTE'");;){if(n[s]===3){let H=n[s+1];if(H===18||H===22||H===25||H===24){s++;break}s++}o(17);let oe=O.pop();if(t.addClassesToNamespace(oe.id,oe.classes,oe.notes),t.popNamespace(),O.length===0){K=!1;break}}}if(O.length===0)return}},y=()=>{let O=ti[n[s]];return O===0?"none":(s++,O-1)},E=()=>{let O=l(!0),v=n[s];if(v===10){t.addMember(O,t.cleanupLabel(r[s++]));return}let G="none";if(v===6)G=r[s++],v=n[s];else if(ti[v]===0&&v!==38&&v!==39)return;let K=y();v=n[s],v!==38&&v!==39&&a("'AGGREGATION', 'EXTENSION', 'COMPOSITION', 'DEPENDENCY', 'LOLLIPOP', 'LINE', 'DOTTED_LINE'"),s++;let C=y(),Z=n[s]===6?r[s++]:"none",oe=l(!0),H={id1:O,id2:oe,relation:{type1:K,type2:C,lineType:v===38?0:1},relationTitle1:G,relationTitle2:Z};n[s]===10&&(H.title=t.cleanupLabel(r[s++])),t.addRelation(H)},b=()=>{let O=[];for(;;){wf[n[s]]===0&&a("'ALPHA', 'NUM', 'COLON', 'UNIT', 'SPACE', 'BRKT', 'STYLE', 'PCT', 'LABEL'");let v=r[s++];for(;wf[n[s]]===1;)v+=r[s++];if(O.push(v),n[s]!==28)return O;s++}},S=O=>{n[s]===6&&t.setTooltip(O,r[s++])},x=O=>{let v=o(6),G=n[s]===6?r[s++]:void 0;n[s]===42?t.setLink(O,v,r[s++]):t.setLink(O,v),G!==void 0&&t.setTooltip(O,G)},I=()=>{let O=n[s];switch(O){case 53:case 27:case 52:case 54:E();return;case 18:p();return;case 22:d();return;case 23:s++;return;case 20:{s++;let v=c();o(21),t.addAnnotation(l(!0),v);return}case 40:{s++;let v=l(!0);t.setClickEvent(v,o(6)),S(v);return}case 41:s++,x(l(!0));return;case 43:{s++;let v=l(!0);if(n[s]===46){s++,x(v);return}let G=o(44);n[s]===45?t.setClickEvent(v,G,r[s++]):t.setClickEvent(v,G),S(v);return}case 47:{s++;let v=o(27);t.setCssStyle(v,b());return}case 48:{s++;let v=o(6);t.setCssClass(v,o(27));return}case 25:case 24:m();return;case 26:{s++;let v=[o(27)];for(;n[s]===28;)s++,v.push(o(27));t.defineClass(v,b());return}case 29:case 30:case 31:case 32:s++,t.setDirection(O===29?"TB":O===30?"BT":O===31?"RL":"LR");return;case 11:s++,t.setAccTitle(o(12).trim());return;case 13:s++,t.setAccDescription(o(14).trim());return;case 15:t.setAccDescription(r[s++].trim());return}a("'acc_title', 'acc_descr', 'acc_descr_multiline_value', 'NAMESPACE', 'ANNOTATION_START', 'CLASS', 'MEMBER', 'NOTE_FOR', 'NOTE', 'CLASSDEF', 'direction_tb', 'CALLBACK', 'LINK', 'CLICK', 'STYLE', 'CSSCLASS', 'ALPHA', 'MINUS', 'BQUOTE_STR'")},L=n[s]===2;for(L&&(s++,o(3));I(),!(n[s]!==3||(s++,n[s]===4||n[s]===0)););L&&o(4),o(0)}function Xb(e,t,n,r){let i=Int32Array.from(e,(b,S)=>S),s=b=>{for(;i[b]!==b;)i[b]=i[i[b]],b=i[b];return b},a=(b,S)=>{i[s(b)]=s(S)};for(let b=0;b=0&&a(b,e[b].parent);for(let b of t)a(b.src,b.dst);let o=new Map,c=(b,S,x,I=0,L=0)=>{b.left=Math.min(b.left,S-I/2),b.top=Math.min(b.top,x-L/2),b.right=Math.max(b.right,S+I/2),b.bottom=Math.max(b.bottom,x+L/2)};for(let b=0;b0&&c(S,b.labelX,b.labelY,b.labelW,b.labelH)}let l=0,u=0,h=0,d=0,m=1/0,p=-1/0,y=[];for(let b of o.values()){let S=b.right-b.left,x=b.bottom-b.top;l>0&&l+S>n&&(u+=h+r,l=0,h=0),y.push(l-b.left,u-b.top),m=Math.min(m,b.left),p=Math.max(p,b.right),d=Math.max(d,l+S),h=Math.max(h,x),l+=S+r}if(d>=p-m)return;let E=0;for(let b of o.values())Tr(b.nodes,b.edges,y[E++],y[E++]);return{width:d,height:u+h}}var rM=["aggregation","extension","composition","dependency","lollipop"];function qb(e){return typeof e=="number"&&rM[e]||"none"}function Qb(e,t=!0){let n=[],r=[],i=new Map,s=new Map,a=new Map,o=new Map,c=d=>{if(t||d===void 0)return d;let m=[],p=d,y;for(;p;){if(o.has(p)){y=o.get(p);break}let E=e.namespaces.get(p);if(E===void 0)break;if(E.explicit){y=p;break}m.push(p),p=E.parent}for(let E of m)o.set(E,y);return y},l=d=>d===void 0?-1:i.get(d)??-1;for(let d of e.namespaces.values())!t&&!d.explicit||(i.set(d.id,n.length),n.push({id:d.id,label:t?d.label:d.id,isGroup:!0,shape:"rect",parentId:t?d.parent:void 0,parent:-1}));for(let d of n)d.parent=l(d.parentId);let u=0;for(let d of e.classes.values()){let m=c(d.parent);s.set(d.id,n.length),n.push({id:d.id,label:d.label,isGroup:!1,shape:"classBox",parentId:m,parent:l(m),classNode:d,colorIndex:u++})}for(let d of e.notes.values()){let m=c(d.parent),p=d.class===void 0?void 0:s.get(d.class);p!==void 0&&r.push({id:`edgeNote${d.index}`,start:d.id,end:n[p].id,source:n.length,target:p,label:void 0,arrowTypeStart:"none",arrowTypeEnd:"none",startLabelRight:"",endLabelLeft:"",pattern:"dotted",classes:"relation"}),n.push({id:d.id,label:d.text,isGroup:!1,shape:"note",parentId:m,parent:l(m)})}for(let d of e.interfaces){let m=s.get(d.classId);a.set(d.id,n.length),n.push({id:d.id,label:d.label,isGroup:!1,shape:"interface",parentId:void 0,parent:m===void 0?-1:n[m].parent})}let h=0;for(let d of e.relations){h++;let{type1:m,type2:p}=d.relation,y=m===qi.LOLLIPOP&&p==="none"?a:s,E=y===s&&p===qi.LOLLIPOP&&m==="none"?a:s;r.push({id:`id_${d.id1}_${d.id2}_${h}`,start:d.id1,end:d.id2,source:y.get(d.id1)??-1,target:E.get(d.id2)??-1,label:d.title,arrowTypeStart:qb(m),arrowTypeEnd:qb(p),startLabelRight:d.relationTitle1==="none"?"":d.relationTitle1,endLabelLeft:d.relationTitle2==="none"?"":d.relationTitle2,pattern:d.relation.lineType===1?"dashed":"solid",classes:"relation"})}return{nodes:n,edges:r}}var Rf=12,oa=16,ia=6,Jc=5;function Tf(e){switch(e){case"extension":return Rf;case"composition":case"aggregation":return oa;case"lollipop":return 2*Jc;case"dependency":return Rt("arrow_point")}return 0}function Mf(e,t,n,r,i,s){let a=-i,o=r;switch(e){case"extension":{let c=t-r*Rf,l=n-i*Rf;return``}case"composition":case"aggregation":{let c=t-r*oa/2,l=n-i*oa/2,u=ia-1;return``}case"lollipop":return``;case"dependency":return _t("arrow_point",t,n,r,i,s)}return""}var Zb=40,sM=16,Jb=56,ni=20,Cf=26,Nf=12,el=8,ey=6,iM=10,oM=64,tl=8,If="var(--_l)",aM=new Set(["_self","_blank","_parent","_top"]);function kf(e,t,n){let r=e[t];return typeof r=="number"&&r>0?Math.min(r,2e3):n}var nl=[],rl=[];function ty(e,t,n,r){let i=bt(e.getDisplayDetails().displayText).trim(),s=(e.classifier==="*"?2:0)|(r?4:0);return{text:i,width:t.width(i,n,s),classifier:e.classifier}}function ny(e,t,n){let r=i=>An(n,s=>cM(e,t,n,i,s));return Pn(e.direction)?Pt(n,r):r(!1)}function cM(e,t,n,r,i){let s=t.class??{},a=Qb(e,s.hierarchicalNamespaces!==!1),o=s.hideEmptyMembersBox===!0,c=Array.isArray(n.monospace)&&n.monospace.includes("members"),l=be=>c&&!/[";]font-family:/.test(be.text),u=n.fontSize??16,h=Math.round(u*.875),d=Math.round(u*.8),m=Math.round(d*1.4),p=n.measurer??ct(n.fontFamily,n.fontFamilyMono),y=n.padding??8,E=(be,Ae)=>{if(!be.includes("$$"))return;let ie=Ge(be,!1,p,Ae,4e3);return ie.lines.some(Yi)?ie:void 0},b=be=>be?E(be,d)?.width??p.width(bt(be),d,0):0,S=r?"TB":ln(e.direction),x=new Map,I=new Map,L=new Map,O=be=>{let Ae=x.get(be);if(Ae===void 0){let ie=Ct([be]);Ae=ie.shape===""&&ie.text===""?"":be.slice(0,be.indexOf(":")).trim().toLowerCase(),x.set(be,Ae)}Ae!==""&&L.set(Ae,be)},v=be=>{L.clear();let Ae=I.get(be.cssClasses);if(Ae===void 0){for(let ie of be.cssClasses.split(" ")){let me=e.styleClasses.get(ie);if(me)for(let Te of me.styles)for(let ye of Te.split(","))O(ye)}Ae=[...L],I.set(be.cssClasses,Ae)}else for(let[ie,me]of Ae)L.set(ie,me);for(let ie of be.styles)O(ie);return Ct(L.size===0?rl:[...L.values()])},G=new Int32Array(a.nodes.length);for(let be of a.nodes)be.parent>=0&&G[be.parent]++;let K=new Uint8Array(a.nodes.length);for(let be of a.edges){if(be.source<0||be.target<0)continue;let Ae=a.nodes[be.source].parent,ie=a.nodes[be.target].parent;if(Ae!==ie){for(let me=Ae;me>=0&&K[me]===0;me=a.nodes[me].parent)K[me]=1;for(let me=ie;me>=0&&K[me]===0;me=a.nodes[me].parent)K[me]=1}}let C=[],Z=[];a.nodes.forEach((be,Ae)=>{let ie,me;if(be.isGroup){let Te=Ge(be.label,!1,p,u,4e3);ie=oe(be,Te,0,0,u),G[Ae]>0?(me=Bt(0,0),me.isGroup=!0,me.padX=ni,me.padTop=Te.height>0?Te.height+16:ni,me.padBottom=ni,me.minW=Te.width+2*ni-12+(K[Ae]===1&&!i?Math.min(Te.width+24,240):0)):(ie.w=Math.max(Te.width+2*ni,80),ie.h=Te.height+2*ni,me=Bt(ie.w,ie.h))}else if(be.classNode)ie=H(be,be.classNode),me=Bt(ie.w,ie.h);else if(be.shape==="note"){let Te=Ge(be.label,!0,p,h,260);ie=oe(be,Te,Math.max(Te.width+2*Nf,40),Te.height+2*el,h),me=Bt(ie.w,ie.h)}else{let Te=Ge(be.label,!1,p,h,200);ie=oe(be,Te,Math.max(Te.width,12)+4,Math.max(Te.height,12),h),me=Bt(ie.w,ie.h)}me.parent=be.parent,me.seq=Ae,C.push(ie),Z.push(me)});function oe(be,Ae,ie,me,Te){return{node:be,style:Ct(rl),label:Ae,w:ie,h:me,loops:0,annotations:rl,attributes:nl,methods:nl,titleH:0,attributesH:0,fontSize:Te}}function H(be,Ae){let ie=v(Ae),me=ie.fontSize??u,Te=Math.round(me*.875),ye=Math.round(Te*1.5),we=Ae.type?"<"+xs(Ae.type).replace(//g,">")+">":"",Ie=Ge(Ae.label+we,!1,p,me,4e3,1|(ie.italic?2:0)),ve=Ae.annotations.length>0?Ae.annotations.map(Oe=>E(`«${Oe.trim()}»`,d)??`«${bt(Oe).trim()}»`):rl,Pe=Ae.members.length>0?Ae.members.map(Oe=>ty(Oe,p,Te,l(ie))):nl,he=Ae.methods.length>0?Ae.methods.map(Oe=>ty(Oe,p,Te,l(ie))):nl,Re=Ie.width,Be=0;for(let Oe of ve)Re=Math.max(Re,typeof Oe=="string"?p.width(Oe,d,0):Oe.width),Be+=typeof Oe=="string"?m:Math.max(m,Oe.height);for(let Oe of Pe)Re=Math.max(Re,Oe.width);for(let Oe of he)Re=Math.max(Re,Oe.width);let ge=!(o&&Pe.length===0&&he.length===0),Le=Oe=>ge?Oe>0?2*ey+Oe*ye:iM:0,Fe=2*el+Be+Math.max(Ie.height,Math.round(me*1.5)),Ve=Le(Pe.length);return{node:be,style:ie,label:Ie,w:Math.max(Re+2*Nf,oM),h:Fe+Ve+Le(he.length),loops:0,annotations:ve,attributes:Pe,methods:he,titleH:Fe,attributesH:Ve,fontSize:me}}let z=[],M=[],T=[],R=[],_=[],$=new Float64Array(C.length*4),g=(be,Ae,ie)=>{$[be*4+Ae]++,ie>$[be*4+Ae+1]&&($[be*4+Ae+1]=ie)};for(let be of a.edges){if(be.source<0||be.target<0)continue;let Ae=Ge(be.label,!0,p,h,200),ie=b(be.startLabelRight),me=b(be.endLabelLeft);be.source===be.target?(C[be.source].loops++,Z[be.source].w+=2*(Cf+(Ae.width>0?Ae.width+12:0))):(g(be.source,0,ie),g(be.target,2,me)),R.push(ie),_.push(me),M.push(be),T.push(Ae),z.push({src:be.source,dst:be.target,minlen:1,labelW:Ae.width>0?Ae.width+12:0,labelH:Ae.height>0?Ae.height+4:0,route:[],labelX:0,labelY:0})}if(S==="TB"||S==="BT")for(let be=0;be1&&(Ae=Math.max(Ae,(me-1)*(Te>0?Te+24:14)+24))}Ae=Math.min(Ae,480),Ae>C[be].w&&(Z[be].w+=Ae-C[be].w,C[be].w=Ae)}let N=!1;for(let be=0;be0||_[be]>0;let w=0;if(S==="TB"||S==="BT"){let be=Ae=>Ae?Math.max(m,E(Ae,d)?.height??0):0;for(let Ae of M)w=Math.max(w,be(Ae.startLabelRight)+be(Ae.endLabelLeft)-2*m)}let A=On(Z,z,S,{nodeSep:kf(s,"nodeSpacing",Zb),edgeSep:sM,rankSep:kf(s,"rankSpacing",N?Jb+16:Jb)+w,portSep:20,apart:!0}),D=new Map,U=[],B=(be,Ae,ie,me,Te)=>{let ye=be.route,we=Z[ie],Ie=Jn(ye,Ae,we);if(Ie<0)return;let ve=(we.w-C[ie].w)/2;Ie===1?ye[Ae]-=ve:Ie===3&&(ye[Ae]+=ve);let Pe=Ie&1,he=ye[(Ae===0?3:Ae-3)+Pe],Re=he-ye[Ae+Pe],Be={route:ye,at:Ae,toward:he,order:Te,room:me,side:Ie,after:Pe?Re>0:Re>=0},ge=ie*4+Ie,Le=D.get(ge);return Le?Le.push(Be):D.set(ge,[Be]),Be},F=[],W=[];for(let be=0;be=6;F.push(ie?B(Ae,0,Ae.src,R[be],be):void 0),W.push(ie?B(Ae,Ae.route.length-3,Ae.dst,_[be],be):void 0)}let j=(be,Ae,ie)=>{for(let me=Z[be].parent,Te=0;me>=0&&Te<1e4;me=Z[me].parent,Te++){let ye=Z[me],we=Math.abs(Ae-ye.x),Ie=Math.abs(ie-ye.y);if(Math.abs(Ie-ye.h/2)<.5&&we<=ye.w/2+.5||Math.abs(we-ye.w/2)<.5&&Ie<=ye.h/2+.5)return!0}return!1},Q=[];for(let[be,Ae]of D){if(Ae.length<2)continue;let ie=be>>2,me=be&1,Te=me?C[ie].h:C[ie].w;Ae.sort((ve,Pe)=>ve.toward-Pe.toward||ve.order-Pe.order);let ye=0;for(let ve=0;ve+10&&Pe.after&&(Re+=me?m+6:Pe.room),he.room>0&&!he.after&&(Re+=me?m+6:he.room),Q[ve]=Re,ye+=Re}let we=Math.min(1,(Te-24)/ye);if(we<=0)continue;let Ie=(me?Z[ie].y:Z[ie].x)-ye*we/2;for(let ve=0;ve=0&&Le=0&&Math.abs(Pe[Be+me]-Ie)<=24)for(let Le=Be;Le!==ge+Re;Le+=Re)Pe[Le+me]=Ie;Pe[he+me]=Ie,Ie+=Q[ve]*we}}let Y=(be,Ae,ie,me)=>{if(Ae===void 0||ie<=0)return;let Te=Ae.side&1,ye=me?0:be.length-3,we=ye+1-Te,Ie=Math.abs(be[(me?3:ye-3)+1-Te]-be[we]),ve=Math.min(Te?ie+10:m+6,Ie*.35);if(ve<4)return;let Pe=[be[ye],be[ye+1],be[ye+2]];Pe[1-Te]+=(Ae.side===0||Ae.side===3?-1:1)*ve,be.splice(me?3:ye,0,Pe[0],Pe[1],Pe[2])};for(let be=0;be{if(!Ae)return;let Ie=E(Ae,d),ve=Ie?Math.max(m,Ie.height):m,Pe=me,he=Te;ye&1?(Pe+=(ye===3?-1:1)*(5+ie/2),he+=(we?1:-1)*(7+ve/2)):(Pe+=(we?1:-1)*(9+ie/2),he+=(ye===0?-1:1)*(3+ve/2)),U.push({text:bt(Ae),math:Ie,x:Pe,y:he,w:ie,h:ve,parent:be}),ne=Math.min(ne,Pe-ie/2),k=Math.max(k,Pe+ie/2),q=Math.min(q,he-ve/2),J=Math.max(J,he+ve/2)},se=new Map,re=new Int32Array(z.length);for(let be=0;be=6){let Te=me.length-3,ye=F[be],we=W[be];te(Ae.src,ie.startLabelRight,R[be],me[0],me[1],ye?ye.side:2,ye?ye.after:!0),te(Ae.dst,ie.endLabelLeft,_[be],me[Te],me[Te+1],we?we.side:0,we?we.after:!0)}}let P=n.maxWidth;if(P!==void 0&&P>0&&k-ne+2*y>P){let be=U.map(ie=>({...Bt(ie.w,ie.h,ie.parent),x:ie.x,y:ie.y})),Ae=Xb(Z.concat(be),z,Math.max(1,P-2*y),kf(s,"nodeSpacing",Zb));Ae&&(U.forEach((ie,me)=>{ie.x=be[me].x,ie.y=be[me].y}),ne=q=0,k=Ae.width,J=Ae.height)}let ee=y-ne,ae=y-q,ue=Math.ceil(k-ne+2*y),ce=Math.ceil(J-q+2*y),pe=[],V=new Map;if(a.nodes.length>0&&a.nodes[0].isGroup)for(let be of z)ur(V,be.route);let X="",le="",de="";for(let be=0;be`+(ge?"":Ne(Ae.label,he+ee,Re,Be))+"";continue}let Pe=` transform="translate(${f(Te)},${f(ye)})"`;if(me.classNode)de+=Se(Ae,me.classNode,we,Pe);else if(me.shape==="note"){let he=Ie/2,Re=-ve/2;de+=``+Ne(Ae.label,0,0,` class="pele-label" font-size="${h}"`,n.icons)+""}else de+=``+Ne(Ae.label,0,0,` class="pele-label" font-size="${h}"`,n.icons)+""}function Se(be,Ae,ie,me){let{w:Te,h:ye,style:we}=be,Ie=-Te/2,ve=-ye/2,Pe=Math.round(be.fontSize*.875),he=Math.round(Pe*1.5),Re=``,Be=vt(we),ge=ve+be.titleH,Le=ge+be.attributesH;if(ye>be.titleH){let je=we.stroke?` style="stroke:${rt(we.stroke)}"`:"";Re+=``}let Fe=ve+el;for(let je of be.annotations)if(typeof je=="string")Re+=`${rt(je)}`,Fe+=m;else{let Je=Math.max(m,je.height);Re+=Ne(je,0,Fe+Je/2,` class="pele-annotation" font-size="${d}"${Be||' fill="var(--_m)"'}`,n.icons),Fe+=Je}let Ve=be.fontSize===u?"":` font-size="${f(be.fontSize)}"`;Re+=Ne(be.label,0,(Fe+ge-el)/2,` class="pele-label"${Ve} font-weight="var(--_hw)"${Be}${we.text}`,n.icons);let Oe=(je,Je,$e)=>{let Ze="",tt=$e+ey+he/2+Pe*.35;for(let mt of je){let dt=mt.classifier==="$"?` pele-static"${we.text?we.text.slice(0,-1)+'text-decoration:underline"':' style="text-decoration:underline"'}`:mt.classifier==="*"?` pele-abstract" font-style="italic"${we.text}`:`"${we.text}`;Ze+=`${rt(mt.text)}`,tt+=he}return Ze};return(be.attributes.length>0||be.methods.length>0)&&(Re+=`${Oe(be.attributes,"attribute",ge)}${Oe(be.methods,"method",Le)}`),Ae.tooltip&&(Re=`${Ue(Ae.tooltip)}`+Re),Ae.link&&(Re=Zn(Re,Ae.link,Ae.id,pe,n,Ae.linkTarget&&aM.has(Ae.linkTarget)?` target="${Ae.linkTarget}"`:"")),`${Re}`}let _e="",xe="";for(let be=0;be`+Mf(Te,ve.sx,ve.sy,ve.sdx,ve.sdy,If)+Mf(ye,ve.ex,ve.ey,ve.edx,ve.edy,If)+"",me.width>0){let he=Ae.labelX+ee,Re=Ae.labelY+ae;xe+=dn(ie.id,me,he,Re,"",n.icons)}}let Me="";for(let be of U)Me+=be.math?Ne(be.math,be.x+ee,be.y+ae,' class="pele-cardinality"',n.icons):`${rt(be.text)}`;let Ce=Fc(e.title,p,u,y,ue,ce,(X?`${X}`:"")+(_e?`${_e}`:"")+(le?`${le}`:"")+(xe?`${xe}`:"")+(Me?`${Me}`:"")+`${de}`);return{svg:at("class",Ce.width,Ce.height,u,n,e,Ce.content),width:Ce.width,height:Ce.height,links:pe}}var ry={type:"class",math:!0,parse(e,t,n){let r=new Qc;return n&&(r.title=n),jb(e,r),r},render:ny};var $f=class{constructor(){fe(this,"domains",new Map);fe(this,"transitions",[])}setDomains(t){if(t)for(let n of t){let r=n.domain;this.domains.set(r,{name:r,items:(n.items??[]).map(i=>({label:i.label}))})}}setTransitions(t){t&&(this.transitions=t.filter(n=>n.from!==n.to).map(n=>({from:n.from,to:n.to,label:n.label||void 0})))}};function sy(e,t){let n=new $f;return n.setDomains(e.domains),n.setTransitions(e.transitions),{type:"cynefin",title:e.title||t,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,` +`):void 0,domains:n.domains,transitions:n.transitions}}var iy=[{name:"cynefin-beta:",pattern:"cynefin-beta:"},Jt("cynefin-beta"),{name:"-->",pattern:"-->"},{name:":",pattern:":"},{name:"DOMAIN_NAME",pattern:/complex|complicated|clear|chaotic|confusion/y},sn,Xt,pr,Fn,Sn,wn,Ht,Qt,Zt];function oy(e){let t=new Ut(Yt(e,iy,"cynefin"),iy,"cynefin"),n={$type:"Cynefin",domains:[],transitions:[]},r=()=>{for(;t.kinds[t.i]===9;)t.i++},i=()=>{t.kind!==-1&&(t.kind!==9&&t.fail("a line break or the end of input"),r())};for(r(),t.kind!==1&&t.kind!==0&&t.fail("'cynefin-beta'"),t.i++;t.kind!==-1;)switch(t.kind){case 9:t.i++;break;case 5:n.accDescr=Vt(t.take()),i();break;case 6:n.accTitle=zt(t.take()),i();break;case 7:n.title=Kt(t.take()),i();break;case 4:{let s=t.take();if(t.accept(2)){let o={$type:"Transition",from:s,to:t.expect(4)};t.accept(3)&&(o.label=un(t.expect(8))),i(),n.transitions.push(o);break}let a={$type:"DomainBlock",domain:s,items:[]};for(r();t.kinds[t.i]===8;)a.items.push({$type:"DomainItem",label:un(t.take())}),r();n.domains.push(a);break}default:t.fail("a domain, a transition, a title, or a line break")}return n}function ay(e){let t=e+1831565813|0;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function lM(e){let t=0;for(let n=0;n=2;n-=6)t+=`C${f(e[n+2])},${f(e[n+3])} ${f(e[n])},${f(e[n+1])} ${f(e[n-2])},${f(e[n-1])}`;return t}function ca(e){return`M${f(e[0])},${f(e[1])}${Qi(e)}`}function uy(e,t,n,r){let i=`${f(n)},${f(r)}`;return`M${f(e-n)},${f(t)}A${i} 0 1,1 ${f(e+n)},${f(t)}A${i} 0 1,1 ${f(e-n)},${f(t)}Z`}var Of=[["complex",0,0,0],["complicated",1,0,1],["chaotic",0,1,3],["clear",1,1,2]],dM=4,uM=new Map([["complex",["Complex","Probe → Sense → Respond","Emergent Practices"]],["complicated",["Complicated","Sense → Analyse → Respond","Good Practices"]],["clear",["Clear","Sense → Categorise → Respond","Best Practices"]],["chaotic",["Chaotic","Act → Sense → Respond","Novel Practices"]],["confusion",["Confusion","","Disorder"]]]),fy=3,hy=200,fM=10,hM=4,il=6,py=10,my=20,ol=10;function al(e,t,n,r,i){let s=e.cynefin?.[t];return typeof s=="number"&&s>=r&&s<=i?s:n}function gy(e,t,n){let r=n.fontSize??16,i=Math.round(r*.8125),s=Math.round(r*.875),a=n.measurer??ct(n.fontFamily,n.fontFamilyMono),o=n.padding??8,c=n.icons,l=t.cynefin?.showDomainDescriptions!==!1,u=al(t,"boundaryAmplitude",8,0,50),h=cy(al(t,"seed",0,-1e15,1e15),n.idPrefix??"pele"),d=Math.round(s*1.5),m=(k,J)=>{let te=Ge(k,!1,a,s,hy);return{text:k,label:te,w:te.width+2*fM,h:Math.max(te.height,d)+2*hM,overflow:J}},p=k=>{let J=uM.get(k),te=Ge(J[0],!1,a,r,4e3,1),se=[];if(l)for(let ce of[J[1],J[2]])ce&&se.push(Ge(ce,!1,a,i,4e3,2));let re=e.domains.get(k)?.items??[],P=k==="confusion"&&re.length>fy?fy:re.length,ee=[];for(let ce=0;ce0&&(ue+=py-il);for(let ce of ee)ae=Math.max(ae,ce.w),ue+=il+ce.h;return{name:k,title:te,subtitles:se,badges:ee,w:ae,h:ue,cx:0,cy:0}},y=Of.map(([k])=>p(k)),E=p("confusion"),b=Math.max(88,E.w*.71+8),S=Math.max(64,E.h*.71+6),x=al(t,"width",640,100,1e4)/2,I=al(t,"height",440,100,1e4)/2;for(let k of y)x=Math.max(x,k.w+2*my),I=Math.max(I,k.h+2*my);for(let k of y){let J=(x-k.w)/2,te=(I-k.h)/2;if((J/(b+ol))**2+(te/(S+ol))**2>=1)continue;let se=k.w+2*(b+ol),re=k.h+2*(S+ol);se*I<=x*re?x=Math.max(x,se):I=Math.max(I,re)}let L=Ge(e.title,!1,a,r,4e3,1),O=L.height>0?L.height+12:0,v=2*x,G=2*I,K=o,C=o+O,Z=K+x,oe=C+I,H=K+v,z=C+G,M=sl(C,oe,Z,h,u,{...ly,segments:4,pinEnd:!0}),T=sl(K,Z,oe,h+100,u,{...Lf,segments:4,pinEnd:!0}),R=sl(Z,H,oe,h+200,u,{...Lf,segments:4,pinStart:!0}),_=dy(Z,oe,z,v*.03),$=(k,J)=>J?`${f(k[k.length-2])},${f(k[k.length-1])}`:`${f(k[0])},${f(k[1])}`,g=new Map([["complex",`M${f(K)},${f(C)}L${$(M,!1)}${Qi(M)}${aa(T)}Z`],["complicated",`M${$(M,!1)}L${f(H)},${f(C)}L${$(R,!0)}${aa(R)}${aa(M)}Z`],["chaotic",`M${$(T,!1)}${Qi(T)}${Qi(_)}L${f(K)},${f(z)}Z`],["clear",`M${$(R,!1)}${Qi(R)}L${f(H)},${f(z)}L${$(_,!0)}${aa(_)}Z`]]),N="";for(let[k,,,J]of Of)N+=``;let w=``,A=uy(Z,oe,b,S),D=``,U=k=>{let J=k.cy-k.h/2,te=Ne(k.title,k.cx,J+k.title.height/2,' class="pele-label" font-weight="var(--_hw)"');J+=k.title.height;for(let se of k.subtitles)te+=Ne(se,k.cx,J+se.height/2,` class="pele-cynefin-subtitle" font-size="${i}" font-style="italic" fill="var(--_m)"`),J+=se.height;J+=py-il;for(let se of k.badges)J+=il,te+=``+Ne(se.label,k.cx,J+se.h/2,` class="pele-label" font-size="${s}"${se.overflow?' fill="var(--_m)"':""}`,c)+"",J+=se.h;return`${te}`},B=new Map,F="";Of.forEach(([k,J,te],se)=>{let re=y[se];re.cx=K+x*(J+.5),re.cy=C+I*(te+.5),B.set(k,re),F+=U(re)}),E.cx=Z,E.cy=oe,B.set("confusion",E),F+=U(E);let W=(k,J,te)=>k===E?((J-Z)/(b+4))**2+((te-oe)/(S+4))**2<=1:Math.abs(J-k.cx)<=k.w/2+8&&Math.abs(te-k.cy)<=k.h/2+8,j="",Q=new Map;for(let k of e.transitions){let J=B.get(k.from),te=B.get(k.to);if(!J||!te||J===te)continue;let se=k.from=0?1:-1,V=-ee/ae*pe,X=P/ae*pe,de=(J!==E&&te!==E&&Math.abs(P)>1&&Math.abs(ee)>1?2*(Math.hypot(b*V,S*X)+16):ae*.15)+re*56,Se=ue+V*de,_e=ce+X*de,xe=Le=>{let Fe=1-Le;return[Fe*Fe*J.cx+2*Fe*Le*Se+Le*Le*te.cx,Fe*Fe*J.cy+2*Fe*Le*_e+Le*Le*te.cy]},Me=(Le,Fe,Ve,Oe)=>{for(let je=0;je<16;je++){let Je=(Fe+Ve)/2;W(Le,...xe(Je))===Oe?Fe=Je:Ve=Je}return(Fe+Ve)/2},Ce=48,ke=1;for(;ke<=Ce&&W(J,...xe(ke/Ce));)ke++;if(ke>Ce)continue;let be=Me(J,(ke-1)/Ce,ke/Ce,!0);for(;ke<=Ce&&!W(te,...xe(ke/Ce));)ke++;let Ae=ke>Ce?1:Me(te,(ke-1)/Ce,ke/Ce,!1),[ie,me]=xe(be),[Te,ye]=xe(Ae),we=(Le,Fe,Ve)=>(1-be)*(1-Ae)*Le+((1-be)*Ae+be*(1-Ae))*Fe+be*Ae*Ve,Ie=we(J.cx,Se,te.cx),ve=we(J.cy,_e,te.cy),Pe=Math.hypot(Te-Ie,ye-ve)||1,he=(Te-Ie)/Pe,Re=(ye-ve)/Pe,Be=_t("arrow_point",Te,ye,he,Re,"var(--_l)");Te-=he*Rt("arrow_point"),ye-=Re*Rt("arrow_point");let ge="";if(k.label){let Le=Ge(k.label,!1,a,i,hy),[Fe,Ve]=xe((be+Ae)/2),Oe=Math.abs(V)*Le.width/2+Math.abs(X)*Le.height/2+6,je=Le.width/2+4,Je=Math.min(Math.max(Fe+V*Oe,K+je),Math.max(H-je,K+je));ge=Ne(Le,Je,Ve+X*Oe,` class="pele-edge-label" font-size="${i}"`,c)}j+=``+Be+ge+""}let Y=Math.ceil(Math.max(v,L.width)+2*o),ne=Math.ceil(G+O+2*o),q=Ne(L,K+v/2,o+L.height/2,' class="pele-title" font-weight="var(--_tw)"')+`${N}`+w+D+F+(j?`${j}`:"");return{svg:at("cynefin",Y,ne,r,n,e,q),width:Y,height:ne,links:[]}}var by={type:"cynefin",parse:(e,t,n)=>sy(oy(e),n),render:gy};function pM(e){return e==="markdown"||e==="string"||e==="text"?e:"markdown"}var cl=class{constructor(){fe(this,"type","er");fe(this,"direction","TB");fe(this,"entities",new Map);fe(this,"relationships",[]);fe(this,"classes",new Map);fe(this,"subgraphs",[]);fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"subgraphLookup",new Map);fe(this,"claimed",new Set)}addEntity(t,n=""){let r=this.entities.get(t);return r===void 0?(r={id:`entity-${t}-${this.entities.size}`,label:t,alias:n,attributes:[],cssClasses:"default",cssStyles:[]},this.entities.set(t,r)):!r.alias&&n&&(r.alias=n),r}addAttributes(t,n){let r=this.addEntity(t);for(let i=n.length-1;i>=0;i--){let s=n[i];s.keys??=[],s.comment??="",r.attributes.push(s)}}addRelationship(t,n,r,i){let s=this.subgraphLookup.has(t)?t:this.addEntity(t).id,a=this.subgraphLookup.has(r)?r:this.addEntity(r).id;this.relationships.push({entityA:s,roleA:n,entityB:a,relSpec:i})}setDirection(t){this.direction=t}addCssStyles(t,n){if(n)for(let r of t){let i=this.entities.get(r);if(i)for(let a of n)i.cssStyles.push(a);let s=this.subgraphLookup.get(r);if(s)for(let a of n)s.cssStyles.push(a)}}addClass(t,n){for(let r of t){let i=this.classes.get(r);if(i===void 0&&(i={id:r,styles:[],textStyles:[]},this.classes.set(r,i)),!!n)for(let s of n)s.includes("color")&&i.textStyles.push(s.replace("fill","bgFill")),i.styles.push(s)}}setClass(t,n){for(let r of t){let i=this.entities.get(r);if(i)for(let a of n)i.cssClasses+=" "+a;let s=this.subgraphLookup.get(r);if(s)for(let a of n)s.classes.push(a)}}addSubGraph(t,n,r){let i=t.text.trim(),s=new Set,a=[],o;for(let l of n.flat()){if(typeof l!="string"){l?.stmt==="dir"&&(o=l.value);continue}let u=l.trim();u===""||s.has(u)||(s.add(u),this.claimed.has(l)||a.push(l))}for(let l of a)this.claimed.add(l);let c={id:i,nodes:a,title:(r.text||"").trim(),classes:[],cssStyles:[],dir:o,labelType:pM(r.type)};return this.subgraphs.push(c),this.subgraphLookup.set(i,c),i}setAccTitle(t){this.accTitle=t.replace(/^\s+/g,"")}setAccDescription(t){this.accDescr=t.replace(/\n\s+/g,` +`)}};var Df=["$end","INVALID","ER_DIAGRAM","EOF","NEWLINE","COLON","STYLE_SEPARATOR","BLOCK_START","BLOCK_STOP","SQS","SQE","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","END","SUBGRAPH","direction_tb","direction_bt","direction_rl","direction_lr","CLASSDEF","UNICODE_TEXT","STYLE_TEXT","COMMA","CLASS","STYLE","SEMI","NUM","BRKT","ENTITY_NAME","DECIMAL_NUM","ENTITY_ONE","ATTRIBUTE_WORD","ATTRIBUTE_KEY","COMMENT","ZERO_OR_ONE","ZERO_OR_MORE","ONE_OR_MORE","ONLY_ONE","MD_PARENT","NON_IDENTIFYING","IDENTIFYING","WORD","CHAR"];var la=1,ll=2,Ff=4,da=8,mr=new Uint8Array(128);for(let e=0;e<128;e++){let t=e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===95,n=t&&(e<48||e>57);t&&(mr[e]|=la|ll|da),n&&(mr[e]|=Ff)}for(let e of"-*")mr[e.charCodeAt(0)]|=la|ll|da;mr[46]|=la|da;mr[42]|=Ff;for(let e of"[](),")mr[e.charCodeAt(0)]|=da;var mM=/accTitle\s*:\s*/iy,gM=/accDescr\s*:\s*/iy,bM=/accDescr\s*\{\s*/iy,yM=[/.*direction\s+TB[^\n]*/iy,/.*direction\s+BT[^\n]*/iy,/.*direction\s+RL[^\n]*/iy,/.*direction\s+LR[^\n]*/iy],vf=/direction/gi,Pf=/[\n\r\u2028\u2029]/g;function yy(e,t){return e<128?(mr[e]&t)!==0:e>=192||e===181}function Ey(e){let t=e.length,n=[],r=[],i=[],s=0,a=0,o=-2,c=0,l=-1,u=-2,h=-1,d=-1,m=-1,p=(H,z,M)=>{n.push(H),r.push(e.slice(z,M)),i.push(z),a=M},y=(H,z)=>(H.lastIndex=z,H.test(e)?H.lastIndex:-1),E=H=>{for(let z=0;z122||(T|32)!==M))return!1}return!0},b=H=>E(H)&&!ot(e.charCodeAt(a+H.length)),S=H=>{let z=e.charCodeAt(H);return z>=65&&z<=90?z+32:z},x=H=>(Pf.lastIndex=H,Pf.test(e)?Pf.lastIndex-1:t),I=H=>{for(;xt(e.charCodeAt(H));)H++;return H},L=()=>{if(o===-1||o=l))return!1;for(let H=0;H<4;H++){let z=y(yM[H],a);if(z>=0)return p(18+H,a,z),!0}return c=l,!1},O=()=>{let H=e.indexOf('"',a+1);if(H===-1){p(45,a,a+1);return}let z=H>a+1;for(let M=a+1;z&&M{let z=e.charCodeAt(a+1);if(z===43&&(H===49||H===48)){p(H===49?39:38,a,a+2);return}let M=I(a+1);if(e.charCodeAt(M)===46&&xt(e.charCodeAt(M+1))){p(32,a,I(M+2));return}if(H===49){if(qe(z)){let T=a+2;for(;qe(e.charCodeAt(T));)T++;let R=e.charCodeAt(T);if(ot(R)||R===34||R===39){p(40,a,a+1);return}}else if(z===45||z===46){let T=e.charCodeAt(a+2);if(T===45||T===46){p(40,a,a+1);return}}if(!ot(z)){p(33,a,a+1);return}}p(29,a,M)},G=H=>{let z=e.charCodeAt(a+1);switch(H){case 101:if(b("erdiagram"))p(2,a,a+9);else if(b("end")){let M=a+3;for(;qe(e.charCodeAt(M));)M++;p(16,a,M)}else return!1;return!0;case 115:if(b("style"))s=6,p(27,a,a+5);else if(b("subgraph"))p(17,a,a+8);else return!1;return!0;case 99:if(b("classdef"))s=6,p(22,a,a+8);else if(b("class"))p(26,a,a+5);else return!1;return!0;case 111:if(b("one or zero"))p(37,a,a+11);else if(b("one or more")||b("one or many"))p(39,a,a+11);else if(b("one"))p(40,a,a+3);else if(b("only one"))p(40,a,a+8);else if(z===124)p(37,a,a+2);else if(z===123)p(38,a,a+2);else if(b("optionally to"))p(42,a,a+13);else return!1;return!0;case 122:if(b("zero or one"))p(37,a,a+11);else if(b("zero or more")||b("zero or many"))p(38,a,a+12);else return!1;return!0;case 109:if(E("many(0)"))p(38,a,a+7);else if(E("many(1)"))p(39,a,a+7);else if(b("many"))p(38,a,a+4);else return!1;return!0;case 116:return b("to")?(p(43,a,a+2),!0):!1;case 117:return z!==46&&z!==45&&z!==124?!1:(p(41,a,a+1),!0);case 124:if(S(a+1)===111&&!ot(e.charCodeAt(a+2)))p(37,a,a+2);else if(z===124)p(40,a,a+2);else if(z===123)p(39,a,a+2);else return!1;return!0;case 125:if(S(a+1)===111&&!ot(e.charCodeAt(a+2)))p(38,a,a+2);else if(z===124)p(39,a,a+2);else return!1;return!0;case 46:return z!==46&&z!==45?!1:(p(42,a,a+2),!0);case 45:if(z===45)p(43,a,a+2);else if(z===46)p(42,a,a+2);else return!1;return!0}return!1},K=H=>{let z;if((H===97||H===65)&&E("acc")){if((z=y(mM,a))>=0){s=3,p(11,a,z);return}if((z=y(gM,a))>=0){s=4,p(13,a,z);return}if((z=y(bM,a))>=0){s=5,a=z;return}}if(!L()){switch(H){case 32:case 9:case 13:z=a+1;for(let M=e.charCodeAt(z);M===32||M===9||M===13;M=e.charCodeAt(z))z++;a=z;return;case 10:for(z=a+1;e.charCodeAt(z)===10;)z++;p(4,a,z);return;case 34:O();return;case 123:s=1,p(7,a,a+1);return;case 35:p(30,a,a+1);return;case 44:p(25,a,a+1);return;case 58:e.charCodeAt(a+1)===58&&e.charCodeAt(a+2)===58?p(6,a,a+3):p(5,a,a+1);return;case 91:p(9,a,a+1);return;case 93:p(10,a,a+1);return}if(xt(H)){v(H);return}if(!G(H>=65&&H<=90?H+32:H)){if(H>=128||(mr[H]&la)!==0){z=a+1;for(let M=e.charCodeAt(z);M>=128||(mr[M]&la)!==0;M=e.charCodeAt(z))z++;p(23,a,z);return}p(45,a,a+1)}}},C=()=>{if(u===-1||u=m||(h{if(qe(H)){for(a++;qe(e.charCodeAt(a));)a++;return}let z=H|32;if((z===112||z===102||z===117)&&(e.charCodeAt(a+1)|32)===107&&!ot(e.charCodeAt(a+2))){p(35,a,a+2);return}if(!C()){if(yy(H,Ff)){let M=a+1;for(;M=128||(mr[H]&ll)!==0){z=a+1;for(let M=e.charCodeAt(z);M>=128||(mr[M]&ll)!==0;M=e.charCodeAt(z))z++;p(24,a,z)}else return n.push(1),r.push(""),i.push(a),{types:n,texts:r,starts:i};break}}let oe=s===0?3:s===3?12:s===4?14:s===5?15:-1;return oe!==-1&&(n.push(oe),r.push(""),i.push(t)),n.push(0),r.push(""),i.push(t),{types:n,texts:r,starts:i}}var Bf=new Map([[37,"ZERO_OR_ONE"],[38,"ZERO_OR_MORE"],[39,"ONE_OR_MORE"],[40,"ONLY_ONE"],[41,"MD_PARENT"]]),EM=["TB","BT","RL","LR"],xy="'UNICODE_TEXT', 'NUM', 'ENTITY_NAME', 'DECIMAL_NUM', 'ENTITY_ONE'",xM="'ZERO_OR_ONE', 'ZERO_OR_MORE', 'ONE_OR_MORE', 'ONLY_ONE', 'MD_PARENT'",dl="'EOF', 'NEWLINE', 'title', 'acc_title', 'acc_descr', 'acc_descr_multiline_value', 'SUBGRAPH', 'direction_tb', 'direction_bt', 'direction_rl', 'direction_lr', 'CLASSDEF', 'CLASS', 'STYLE', "+xy;function Ay(e,t){let{types:n,texts:r,starts:i}=Ey(e),s=0,a=v=>{let G=n[s];throw G===1?ft("er",e,i[s],"",!0):ft("er",e,i[s],`Expecting ${v}, got '${G===45?r[s]:Df[G]}'`)},o=v=>(n[s]!==v&&a(`'${Df[v]}'`),r[s++]),c=()=>{let v=n[s];v!==4&&v!==28&&v!==3&&a("'EOF', 'NEWLINE', 'SEMI'"),s++},l=v=>v===23||v===31||v===29||v===32||v===33,u=()=>{let v=n[s];l(v)||a(xy);let G=r[s++];return v===31?G.slice(1,-1):G},h=()=>{let v=[];for(;;){let G=n[s];if(G!==23&&G!==24&&a("'UNICODE_TEXT', 'STYLE_TEXT'"),v.push(r[s++]),n[s]!==25)return v;s++}},d=v=>v===24||v===29||v===5||v===30,m=()=>{let v=[];for(;;){d(n[s])||a("'STYLE_TEXT', 'COLON', 'NUM', 'BRKT'");let G=r[s++];for(;d(n[s]);)G+=r[s++];if(v.push(G),n[s]!==25)return v;s++}},p=()=>{let v=Bf.get(n[s++]),G=n[s];G!==43&&G!==42&&a("'NON_IDENTIFYING', 'IDENTIFYING'");let K=G===43?"IDENTIFYING":"NON_IDENTIFYING";s++;let C=Bf.get(n[s]);return C===void 0?a(xM):(s++,{cardA:C,relType:K,cardB:v})},y=()=>{let v=n[s];v!==44&&v!==31&&v!==23&&a("'UNICODE_TEXT', 'ENTITY_NAME', 'WORD'");let G=r[s++];return v===23?G:G.slice(1,-1)},E=v=>n[s]===45&&r[s]===v,b=()=>{let v=[];do{let G=o(34);E("?")&&(G+=r[s++]),n[s]!==34&&a(G.endsWith("?")?"'ATTRIBUTE_WORD'":"'ATTRIBUTE_WORD', '?'");let K={type:G,name:r[s++]};if(n[s]===35){let C=[r[s++]];for(;E(",");)s++,C.push(o(35));K.keys=C}n[s]===36&&(K.comment=r[s++].slice(1,-1)),v.push(K)}while(n[s]!==8);return v.reverse()},S=()=>{if(n[s]!==7)return;if(s++,n[s]===8){s++;return}let v=b();return s++,v},x=()=>{let v=u(),G=n[s];if(G===9){s++;let Z=u();o(10);let oe;n[s]===6&&(s++,oe=h());let H=S();return t.addEntity(v,Z),H&&t.addAttributes(v,H),oe&&t.setClass([v],oe),[v]}let K;if(G===6&&(s++,K=h(),G=n[s]),Bf.has(G)){let Z=p(),oe=u(),H;n[s]===6&&(s++,H=h()),o(5);let z=y();return t.addEntity(v),t.addEntity(oe),t.addRelationship(v,z,oe,Z),K&&t.setClass([v],K),H&&t.setClass([oe],H),[v,oe]}let C=S();return t.addEntity(v),C&&t.addAttributes(v,C),K&&t.setClass([v],K),[v]};o(2);let I=[{id:"",title:"",list:[]}],L=I[0],O=!1;for(;;){let v=n[s];switch(v){case 4:s++;break;case 3:s++,O&&a(`'END', ${dl}`);return;case 16:{O||a(dl),s++;let G=t.addSubGraph({text:L.id},L.list,{text:L.title});I.pop(),L=I[I.length-1],O=I.length>1,O&&L.list.push(G);break}case 17:{s++;let G=u(),K=G;if(n[s]===9){for(s++,K=u();l(n[s]);)K+=" "+u();o(10)}c(),L={id:G,title:K,list:[]},I.push(L),O=!0;break}case 11:{s++;let G=o(12).trim();t.setAccTitle(G),O&&L.list.push(G);break}case 13:{s++;let G=o(14).trim();t.setAccDescription(G),O&&L.list.push(G);break}case 15:{let G=r[s++].trim();t.setAccDescription(G),O&&L.list.push(G);break}case 18:case 19:case 20:case 21:{s++;let G=EM[v-18];O?L.list.push({stmt:"dir",value:G}):t.setDirection(G);break}case 22:{let G=r[s++],K=h(),C=m();c(),t.addClass(K,C),O&&L.list.push(G);break}case 26:{let G=r[s++],K=h();t.setClass(K,h()),O&&L.list.push(G);break}case 27:{let G=r[s++],K=h(),C=m();c(),t.addCssStyles(K,C),O&&L.list.push(G);break}default:{l(v)||a(O?`'END', ${dl}`:dl);let G=x();if(O)for(let K of G)L.list.push(K)}}}}var AM=[];function Sy(e){let t=[],n=[],r=e.subgraphs,i=c=>{let l=[];for(let u of c){let h=e.classes.get(u);if(h!==void 0){for(let d of h.styles)l.push(d.trim());for(let d of h.textStyles)l.push(d.trim())}}return l},s=new Map,a=new Set;for(let c=r.length-1;c>=0;c--){let l=r[c];a.add(l.id);for(let u of l.nodes)s.set(u,l.id)}for(let c=r.length-1;c>=0;c--){let l=r[c];t.push({id:l.id,label:l.title,alias:"",attributes:AM,isGroup:!0,parentId:s.get(l.id),cssStyles:l.cssStyles,cssCompiledStyles:i(l.classes),cssClasses:l.classes.join(" "),dir:l.dir,labelType:l.labelType})}let o=new Map;for(let[c,l]of e.entities){if(a.has(c)){o.set(l.id,c);continue}t.push({id:l.id,label:l.label,alias:l.alias,attributes:l.attributes,isGroup:!1,parentId:s.get(c),cssStyles:l.cssStyles,cssCompiledStyles:i(l.cssClasses.split(" ")),cssClasses:l.cssClasses,dir:void 0,labelType:"markdown"})}return e.relationships.forEach((c,l)=>{n.push({id:`id_${c.entityA}_${c.entityB}_${l}`,start:o.get(c.entityA)??c.entityA,end:o.get(c.entityB)??c.entityB,label:c.roleA,arrowTypeStart:c.relSpec.cardB.toLowerCase(),arrowTypeEnd:c.relSpec.cardA.toLowerCase(),pattern:c.relSpec.relType==="IDENTIFYING"?"solid":"dashed"})}),{nodes:t,edges:n}}var vr=18,wy=5,_y=6,Wf=10,Ry=3.5;function ri(e,t,n,r,i){let s=(u,h)=>f(t-r*u-i*h)+","+f(n-i*u+r*h),a=u=>`M${s(u,-wy)}L${s(u,wy)}`,o=`M${s(0,-_y)}L${s(Wf,0)}L${s(0,_y)}`,c=u=>``,l=u=>``;switch(e){case"only_one":return l(a(6)+a(10));case"zero_or_one":return l(a(6))+c(13.5);case"one_or_more":return l(o+a(Wf+3.5));case"zero_or_more":return l(o)+c(Wf+Ry+.5);case"md_parent":return``}return""}var SM=48,wM=20,_M=64,ua=20,fa=28,RM=38,Ty=96,My=18,TM=12,MM=9,Uf=12,Cy=16,Gf=9,CM=260,Yf=1e6,NM=[],IM=18,kM=14,Ny=' fill="var(--_s)" stroke="var(--_b)"';function Iy(e,t,n){let r=e.er?.[t];return typeof r=="number"&&r>0?Math.min(r,2e3):n}function ul(e,t,n,r,i,s=0){let a=e.lines;if(a.length===0)return"";let o=a.length===1&&a[0].length===1?a[0][0]:void 0;if(o&&o.icon===void 0&&o.math===void 0&&o.style===s&&!(s&&o.text.includes(" ")))return`${rt(o.text)}`;let c=Xr(e),l=e.size*.35,u=n-l-e.lineHeight/2,h="",d="";for(let m=0;m${i?.(x.icon)??""}`}else if(x.text!==""){let I=E||!S?` x="${f(b)}" y="${f(n)}"`:"";h+=`${rt(x.text)}`,S=!0}b+=x.width}}return`${h}${d}`}function Hf(e){let t=xs(e);return t===e?e:t.replace(//g,">")}function Ly(e,t,n){return Pn(e.direction)?Pt(n,r=>ky(e,t,n,r)):ky(e,t,n,!1)}function ky(e,t,n,r){let i=Sy(e),s=Array.isArray(n.monospace)&&n.monospace.includes("attributes"),a=n.fontSize??16,o=Math.round(a*.875),c=n.measurer??ct(n.fontFamily,n.fontFamilyMono),l=n.padding??8,u=n.icons,h=new Map,d=[],m=[];i.nodes.forEach((A,D)=>h.set(A.id,D));let p=[],y=[],E=[],b=new Map,S=[];for(let A of i.edges){let D=h.get(A.start),U=h.get(A.end);if(D===void 0||U===void 0)continue;let B=Ge(A.label,!0,c,o,200),F;if(D===U){F={label:B,band:0,at:0};let W=b.get(D);W?W.push(F):b.set(D,[F])}S.push(F),E.push(A),y.push(B),p.push({src:D,dst:U,minlen:1,labelW:B.width>0?B.width+12:0,labelH:B.height>0?B.height+4:0,route:[],labelX:0,labelY:0})}let x=A=>{let D=A;for(let U=0;U0?D.cssCompiledStyles.concat(D.cssStyles):D.cssCompiledStyles),B=(U.bold?1:0)|(U.italic?2:0),F=s&&!/[";]font-family:/.test(U.text)?4:0,W=U.fontSize??a,j=U.fontSize??o,Q=U.fontSize??Math.round(a*.75),Y=D.isGroup?Ge(D.label,!0,c,W,4e3,B):Ge(D.alias||D.label,!0,c,W,240,B),ne=b.get(A)??NM,q=ne.length>0&&!D.isGroup&&x(A),k={node:D,style:U,label:Y,w:0,h:0,headH:0,rows:[],cols:[],rowSize:j,keySize:Q,mono:F,below:q},J=0,te=0;for(let P of ne)P.band=Math.max(RM,q?P.label.width+12:P.label.height+6),te+=P.band,J=Math.max(J,q?P.label.height:P.label.width);let se=Math.max(Ty,q?te+8:0),re;if(D.isGroup)re=Bt(0,0),re.isGroup=!0,re.dir=D.dir?ln(D.dir):void 0,re.padX=ua,re.padTop=k.label.height>0?k.label.height+16:ua,re.padBottom=ua,re.minW=Math.max(k.label.width+2*ua-12,Ty);else{let P=Math.max(Y.height,Math.round(W*1.5));if(D.attributes.length===0)k.w=Math.max(Y.width+2*My,se),k.h=Math.max(P+2*TM,q?0:te+8);else{let ae=Math.round(j*1.5),ue=[0,0,0,0];for(let le of D.attributes){let de=[Ge(Hf(le.type),!0,c,j,Yf,B|F),Ge(Hf(le.name),!0,c,j,Yf,B|F),Ge(le.keys.join(", "),!1,c,Q,Yf,B|F),Ge(Hf(le.comment),!0,c,j,CM,B)],Se=ae;for(let _e=0;_e<4;_e++)de[_e].width>ue[_e]&&(ue[_e]=de[_e].width),de[_e].height>Se&&(Se=de[_e].height);k.rows.push({cells:de,h:Se+Gf}),k.h+=Se+Gf}let ce=0,pe=0;for(let le of ue)le!==0&&(pe+=le+(ce>0?Cy:0),ce++);k.w=Math.max(pe+2*Uf,Y.width+2*My,se);let V=ce>0?(k.w-pe-2*Uf)/ce:0,X=Uf;for(let le of ue)k.cols.push(X),le>0&&(X+=le+V+Cy);k.headH=P+2*MM,k.h+=k.headH}let ee=ne.length>0?2*(vr+fa*.75+10+J):0;re=q?Bt(k.w,k.h+ee):Bt(k.w+ee,k.h)}re.seq=d.length,d.push(k),m.push(re)}i.nodes.forEach((A,D)=>{m[D].parent=A.parentId!==void 0?h.get(A.parentId)??-1:-1});let I=On(m,p,r?"TB":ln(e.direction),{nodeSep:Iy(t,"nodeSpacing",SM),edgeSep:wM,rankSep:Iy(t,"rankSpacing",_M),portSep:24});LM(p,m,d);let L=I.width;for(let[A,D]of b){let U=m[A];if(!U.isGroup)continue;let B=0;for(let F of D)B=Math.max(B,F.label.width);L=Math.max(L,U.x+U.w/2+vr+fa*.75+10+B)}let O=yn(e.title,c,a,4e3),v=O.height>0?O.height+12:0,G=Math.max(L,O.width),K=l+(G-L)/2,C=l+v;Tr(m,p,K,C);let Z=Math.ceil(G+2*l),oe=Math.ceil(I.height+v+2*l),H=[],z=new Map,M=!1;for(let A of m)A.isGroup&&(M=!0);if(M)for(let A of p)ur(z,A.route);let T="",R=[],_="";for(let A=0;A`+Ne(D.label,ae,ee+8+D.label.height/2,` class="pele-cluster-label"${vt(D.style,"var(--_m)")}${D.style.text}`,u)+"";continue}let W=D.w,j=D.h,Q=-W/2,Y=-j/2,ne=D.style.text,q=vt(D.style),k=q||' fill="var(--_m)"',J=`x="${f(Q)}" y="${f(Y)}" width="${f(W)}" height="${f(j)}"`,te=Ne(D.label,0,D.rows.length>0?Y+D.headH/2:0,` class="pele-label"${q}${ne}`,u),se=bt(B.alias||B.label);if(/ internal-link(?: |$)/.test(F+" ")&&te!==""&&n.links!==!1){let P=$i(se,n),ee=rt(se);te=`${te}`,H.push({id:B.label,href:se,internal:!0})}let re;if(D.rows.length===0)re=``+te;else{let P=Math.round(D.rowSize*1.5),ee=D.style.stroke?rt(D.style.stroke):"var(--_b)",ae="",ue="",ce=Y+D.headH;for(let le=0;le`:ae+=``}let Se=ce+Gf/2+P/2+D.rowSize*.35,[_e,xe,Me,Ce]=de.cells;ue+=ul(_e,Q+D.cols[0],Se,` class="pele-er-type"${k}${ne}`,u,D.mono)+ul(xe,Q+D.cols[1],Se,` class="pele-er-name"${q}${ne}`,u,D.mono)+ul(Me,Q+D.cols[2],Se,` class="pele-er-keys" font-size="${D.keySize}"${k}${ne}`,u,D.mono)+ul(Ce,Q+D.cols[3],Se,` class="pele-er-comment"${k}${ne}`,u),ce+=de.h}let pe=f(Y+D.headH),V=dr(D.style.shape),X=V===sc?ic:V===ic?sc:"var(--_bg)";re=`${ae}`+te+`${ue}`}_+=`${re}`}for(let[A,D]of b){let U=d[A],B=0;for(let j of D)B+=j.band;let F=Math.min(1,Math.max((U.below?U.w:U.h)-8,0)/B),W=-B*F/2;for(let j of D)j.band*=F,j.at=W+j.band/2,W+=j.band}let $="",g="",N="";for(let A=0;A0?`M${f(P.sx)},${f(P.sy)}L${P.d.slice(1)}L${f(P.ex)},${f(P.ey)}`:P.d,W=ri(U.arrowTypeStart,P.sx,P.sy,P.sdx,P.sdy),j=ri(U.arrowTypeEnd,P.ex,P.ey,P.edx,P.edy)}let Y=Bo(F,[],R),ne=Y&&Wo(Y);ne===""&&(g+=Go(F,W+j)),Y&&ne&&(W=Uo(W,Y),j=Uo(j,Y));let q=U.pattern==="dashed";if($+=``+W+j+"",B.width>0){let k=D.labelX,J=D.labelY;N+=dn(U.id,B,k,J,"",u)}}return{svg:at("er",Z,oe,a,n,e,Ne(O,Z/2,l+O.height/2,' class="pele-title" font-weight="var(--_tw)"')+(T?`${T}`:"")+Dn(g)+($?`${$}`:"")+(N?`${N}`:"")+`${_}`),width:Z,height:oe,links:H}}function $M(e){let t=e.slice(0,3);for(let n=3;nMath.abs(t[r+s]-e[n+s])<.01&&Math.abs(e[n+s]-e[n+3+s])<.01;n+3{let l=t[s],u=a[o]-l.x,h=a[o+1]-l.y,d;if(Math.abs(Math.abs(h)-l.h/2)<.5)d=h<0?0:2;else if(Math.abs(Math.abs(u)-l.w/2)<.5)d=u<0?3:1;else return;let m=s*4+d,p={route:a,at:o,toward:a[c+(d&1?1:0)]},y=r.get(m);y?y.push(p):r.set(m,[p])};for(let s of e){let a=s.route.length-3;s.src===s.dst||a<3||(i(s.src,s.route,0,3),i(s.dst,s.route,a,a-3))}for(let[s,a]of r){if(a.length<2)continue;let o=s>>2,c=(s&1)===1,l=t[o].isGroup?t[o]:n[o],u=c?l.h:l.w,h=Math.max(Math.min(IM,(u-2*kM)/(a.length-1)),0),d=c?t[o].y:t[o].x;a.sort((m,p)=>m.toward-p.toward);for(let m=0;mt?e.slice(t+1,n):t===-1&&e.length>=2?e.slice(1,-1):"").replace(/\r/g,"").split(` +`);for(;i.length>0&&i[0].trim()==="";)i.shift();for(;i.length>0&&i[i.length-1].trim()==="";)i.pop();let s=1/0;for(let a of i)a.trim()!==""&&(s=Math.min(s,a.length-a.trimStart().length));return i.map(a=>a.slice(Math.min(s,a.length)).trimEnd()).join(` +`)}function Dy(e,t){let n=new Set;for(let h of e.frames){if(n.has(h.name)){let d=cr(e.$source,h.$offset).line;throw new Qe(`Duplicate event modeling frame ID "${h.name}" on line ${d}`,"semantic",{type:"eventmodeling",line:d})}n.add(h.name)}let r=new Map;for(let h of e.dataEntities)r.has(h.name)||r.set(h.name,h.dataBlockValue);let i=new Map,s=new Map,a=(h,d)=>{let m=vM(h),p=d===void 0?m:`${m} ${d}`,y=i.get(p);if(!y){let[E,b,S]=DM.get(m),x=E;d!==void 0&&(x=s.get(m)??E+1,s.set(m,x+1)),y={index:x,label:d===void 0?b:S+d,group:m,namespace:d},i.set(p,y)}return y},o=[],c=new Map,l=[];e.frames.forEach((h,d)=>{let m=h.entityIdentifier.split("."),p=m.length===2?m[0]:void 0,y=OM.get(h.modelEntityType)??"event",E=h.dataInlineValue===void 0?void 0:Kf(h.dataInlineValue);if(h.dataReference){let S=r.get(h.dataReference.$refText);S!==void 0&&(E=Kf(S))}let b={id:h.name,kind:y,entity:h.entityIdentifier,name:m.length===2?m[1]:h.entityIdentifier,namespace:p,reset:h.$type==="EmResetFrame",lane:a(y,p),data:E,dataType:h.dataType};if(o.push(b),c.set(b.id,b),h.sourceFrames.length>0){let S=new Set(h.sourceFrames.map(x=>x.$refText));for(let x of o)S.has(x.id)&&l.push({source:x,target:b})}else if(d>0&&!b.reset){for(let S=d-1;S>=0;S--)if(o[S].lane!==b.lane){l.push({source:o[S],target:b});break}}});let u=h=>h.map(d=>d.entityIdentifier.$refText);return{type:"eventmodeling",title:e.title&&Kt(e.title)||t,accTitle:e.accTitle?zt(e.accTitle).replace(/^\s+/g,""):void 0,accDescr:e.accDescr?Vt(e.accDescr).replace(/\n\s+/g,` +`):void 0,boxes:o,lanes:[...i.values()].sort((h,d)=>h.index-d.index),relations:l,notes:e.noteEntities.map(h=>({frame:h.sourceFrame.$refText,text:Kf(h.dataBlockValue),dataType:h.dataType})),specifications:e.gwtEntities.map(h=>({frame:h.sourceFrame.$refText,given:u(h.givenStatements),when:u(h.whenStatements),then:u(h.thenStatements)})),entities:e.modelEntities.map(h=>h.name)}}var zf=/[\t ]*accDescr(?:[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)|\s*({))/y;function PM(){let e=!1;return(t,n)=>{zf.lastIndex=n;let r=zf.exec(t);if(r===null)return-1;let i=zf.lastIndex;if(r[1]===void 0)return i;if(e)return-1;let s=t.indexOf("}",i);return e=s===-1,s+1||-1}}function Zi(e="ACC_DESCR"){return{...sn,name:e,scanner:PM}}var jf={name:"EM_ID",pattern:/[_a-zA-Z][\w_]*/y},Ji=e=>({name:e,pattern:e,longer:[jf]}),ha=e=>({name:e,pattern:e}),FM=["resetframe","readmodel","processor","timeframe","command","entity","event","jsobj","figma","given","json","salt","html","text","data","note","when","then","rmo","cmd","evt","pcr","uri"],Xf=[{...Jt("eventmodeling"),longer:[jf]},...FM.map(Ji),ha("->>"),Ji("gwt"),Ji("ui"),Ji("md"),Ji("tf"),ha("[["),ha("]]"),Ji("rf"),ha("`"),ha("."),jf,{name:"EM_FID",pattern:/\d{1,3}/y},{name:"EM_DATA_INLINE",pattern:/\{(.*)\}|"(.*)"|'(.*)'/y},{name:"EM_DATA_BLOCK",pattern:/\{[\t ]*\r?\n(?:[\S\s]*?\r?\n)?\}(?:\r?\n|(?!\S))/y},Zi("EM_ACC_DESCR"),{...Xt,name:"EM_ACC_TITLE"},{...er(String.raw`\w`),name:"EM_TITLE"},{name:"EM_WS",pattern:/\s+/y,hidden:!0},{...Ht,name:"EM_YAML"},{...Qt,name:"EM_DIRECTIVE"},{...Zt,name:"EM_SINGLE_LINE_COMMENT"},{name:"EM_ML_COMMENT",pattern:/\/\*[\s\S]*?\*\//y,hidden:!0},{name:"EM_SL_COMMENT",pattern:/\/\/[^\n\r]*/y,hidden:!0}],en=e=>Xf.findIndex(t=>t.name===e),fl=e=>new Set(e.map(en)),Ot={keyword:0,arrow:en("->>"),open:en("[["),close:en("]]"),tick:en("`"),dot:en("."),id:en("EM_ID"),frameId:en("EM_FID"),inline:en("EM_DATA_INLINE"),block:en("EM_DATA_BLOCK"),accDescr:en("EM_ACC_DESCR"),accTitle:en("EM_ACC_TITLE"),title:en("EM_TITLE"),entity:en("entity"),data:en("data"),note:en("note"),gwt:en("gwt"),given:en("given"),when:en("when"),then:en("then")},vy=fl(["tf","timeframe"]),BM=fl(["rf","resetframe"]),Vf=fl(["rmo","readmodel","ui","cmd","command","evt","event","pcr","processor"]),WM=fl(["json","jsobj","figma","salt","uri","md","html","text"]);function Py(e){let t=new Ut(Yt(e,Xf,"eventmodeling"),Xf,"eventmodeling"),n={$type:"EventModel",modelEntities:[],frames:[],dataEntities:[],noteEntities:[],gwtEntities:[],$source:e},r=c=>t.kinds[t.i]===c,i=(c,l)=>c.has(t.kinds[t.i])?t.take():t.fail(l),s=()=>{let c=t.expect(Ot.id);for(;t.accept(Ot.dot);)c+="."+t.expect(Ot.id);return c},a=()=>{if(!t.accept(Ot.tick))return;let c=i(WM,"a data type");return t.expect(Ot.tick),c},o=()=>{let c=[];do i(Vf,"an entity type"),c.push({$type:"EmGwtStatement",entityIdentifier:{$refText:t.expect(Ot.id)}});while(Vf.has(t.kinds[t.i]));return c};for(t.expect(Ot.keyword);!r(-1);){let c=t.kinds[t.i];if(c===Ot.accDescr)n.accDescr=t.take();else if(c===Ot.accTitle)n.accTitle=t.take();else if(c===Ot.title)n.title=t.take();else if(c===Ot.entity)t.i++,n.modelEntities.push({$type:"EmModelEntity",name:s()});else if(vy.has(c)||BM.has(c)){let l={$type:vy.has(c)?"EmTimeFrame":"EmResetFrame",name:"",modelEntityType:"",entityIdentifier:"",sourceFrames:[],$offset:t.tokens.starts[t.i]};for(t.i++,l.name=t.expect(Ot.frameId),l.modelEntityType=i(Vf,"an entity type"),l.entityIdentifier=s();t.accept(Ot.arrow);)l.sourceFrames.push({$refText:t.expect(Ot.frameId)});if(t.accept(Ot.open)&&(l.dataReference={$refText:t.expect(Ot.id)},t.expect(Ot.close)),r(Ot.tick)||r(Ot.inline)){let u=a();u!==void 0&&(l.dataType=u),l.dataInlineValue=t.expect(Ot.inline)}n.frames.push(l)}else if(c===Ot.data){t.i++;let l={$type:"EmDataEntity",name:t.expect(Ot.id),dataBlockValue:""},u=a();u!==void 0&&(l.dataType=u),l.dataBlockValue=t.expect(Ot.block),n.dataEntities.push(l)}else if(c===Ot.note){t.i++;let l={$type:"EmNoteEntity",sourceFrame:{$refText:t.expect(Ot.frameId)},dataBlockValue:""},u=a();u!==void 0&&(l.dataType=u),l.dataBlockValue=t.expect(Ot.block),n.noteEntities.push(l)}else if(c===Ot.gwt){t.i++;let l={$type:"EmGwt",sourceFrame:{$refText:t.expect(Ot.frameId)},givenStatements:[],whenStatements:[],thenStatements:[]};t.expect(Ot.given),l.givenStatements=o(),t.accept(Ot.when)&&(l.whenStatements=o()),t.expect(Ot.then),l.thenStatements=o(),n.gwtEntities.push(l)}else t.fail("a frame, an entity, a data block, a note, or a specification")}return n}var Gy=new Map([["command",0],["event",1],["readmodel",2],["processor",6]]),fn=12,Hn=10,UM=96,Fy=16,GM=80,hl=12,By=8,YM=48,Wy=80,Yy=8;function qf(e,t){let n=[];for(let r of bt(e).split(` +`)){let i=r.length<=t?void 0:Array.from(r);if(i===void 0||i.length<=t){n.push(r);continue}for(let s=0;s${rt(e[a])}`);return s===""?"":`${s}`}function Hy(e,t,n){return Pt(n,r=>HM(e,t,n,r))}function HM(e,t,n,r){if(r)return VM(e,n);let i=n.fontSize??16,s=Math.round(i*.875),a=Math.round(i*.8125),o=Math.round(i*.75),c=Math.round(o*1.4),l=Math.round(a*1.5),u=n.measurer??ct(n.fontFamily,n.fontFamilyMono),h=n.padding??8,d=(w,A,D)=>{let U=0;for(let B of w)U=Math.max(U,u.width(B,A,D));return U},m=new Map,p=0;for(let w of e.lanes){let A=Ge(w.label,!1,u,a,4e3,1);p=Math.max(p,A.width),m.set(w,{lane:w,label:A,right:-1/0,y:0,h:0})}p+=2*hl;let y=[],E=new Map,b;for(let w of e.boxes){let A=m.get(w.lane),D=Ge(w.name,!1,u,s,4e3,1),U=w.data?qf(w.data,YM):[],B=Math.max(UM,Math.max(D.width,d(U,o,4))+2*fn),F=2*Hn+D.height+(U.length>0?6+U.length*c:0),W=0;if(b){let Q=b.x+Math.max(b.w/2,b.w-GM);W=b.box.lane===w.lane?A.right+Fy:Math.max(Q,A.right+Fy)}let j={box:w,name:D,data:U,x:W,y:0,w:B,h:F};A.right=W+B,A.h=Math.max(A.h,F),y.push(j),E.set(w,j),b=j}let S=0;for(let w of y)S=Math.max(S,w.x+w.w);let x=p+S+hl,I=Ge(e.title,!1,u,i,4e3,1),L=I.height>0?I.height+12:0,O=h,v=h+L,G=v,K="";for(let w of m.values())w.y=G,w.h+=2*hl,K+=``+Ne(w.label,O+hl+w.label.width/2,G+w.h/2,` class="pele-cluster-label" font-size="${a}" font-weight="var(--_hw)" fill="var(--_m)"`)+"",G+=w.h+By;let C=m.size>0?G-By:v,Z="";for(let w of y){let A=m.get(w.box.lane);w.x+=O+p,w.y=A.y+(A.h-w.h)/2;let D=Gy.get(w.box.kind),U=`x="${f(w.x)}" y="${f(w.y)}" width="${f(w.w)}" height="${f(w.h)}"`,B=D===void 0?``:``,F=w.y+Hn+w.name.height/2,W=Ne(w.name,w.x+w.w/2,F,` class="pele-label" font-size="${s}" font-weight="var(--_hw)"`)+pl(w.data,w.x+fn,w.y+Hn+w.name.height+6+c/2+o*.35,c,` class="pele-em-data" font-family="${fr}" font-size="${o}"`);Z+=`${B}${W}`}let oe="",H=Rt("arrow_point");for(let w of e.relations){let A=E.get(w.source),D=E.get(w.target);if(!A||!D||A===D)continue;let U,B;if(A.box.lane===D.box.lane){let F=D.x>=A.x,W=F?A.x+A.w:A.x,j=F?D.x:D.x+D.w,Q=A.y+A.h/2,Y=D.y+D.h/2,ne=j>=W?1:-1;U=`M${f(W)},${f(Q)}L${f(j-ne*H)},${f(Y)}`,B=_t("arrow_point",j,Y,ne,0,"var(--_l)")}else{let F=D.y>A.y,W=Math.max(A.x,D.x),j=Math.min(A.x+A.w,D.x+D.w),Q=re=>Math.min(24,re/4),Y=j-W>=16?(W+j)/2:D.x>A.x?A.x+A.w-Q(A.w):A.x+Q(A.w),ne=j-W>=16?Y:D.x>A.x?D.x+Q(D.w):D.x+D.w-Q(D.w),q=F?A.y+A.h:A.y,k=F?D.y:D.y+D.h,J=F?1:-1,te=k-J*H,se=(q+te)/2;U=Y===ne?`M${f(Y)},${f(q)}V${f(te)}`:`M${f(Y)},${f(q)}C${f(Y)},${f(se)} ${f(ne)},${f(se)} ${f(ne)},${f(te)}`,B=_t("arrow_point",ne,k,0,J,"var(--_l)")}oe+=`${B}`}let z=new Map;for(let w of e.boxes)z.set(w.id,w.name);let M="",T=0,R=(w,A,D,U)=>{let B=Ge(`${A} · ${D}${z.has(D)?" "+z.get(D):""}`,!1,u,a,4e3,1),F=Math.max(B.width,d(U,a,0))+2*fn,W=2*Hn+B.height+U.length*l,j=C+(M===""&&m.size===0?0:Yy);M+=``+Ne(B,O+fn+B.width/2,j+Hn+B.height/2,` font-size="${a}" font-weight="var(--_hw)"`)+pl(U,O+fn,j+Hn+B.height+l/2+a*.35,l,` font-size="${a}"`)+"",C=j+W,T=Math.max(T,F)};for(let w of e.notes)R("note","Note",w.frame,qf(w.text,Wy));for(let w of e.specifications){let A=[`Given ${w.given.join(", ")}`];w.when.length>0&&A.push(`When ${w.when.join(", ")}`),A.push(`Then ${w.then.join(", ")}`),R("specification","Given / When / Then",w.frame,A.flatMap(D=>qf(D,Wy)))}let _=Math.max(m.size>0?x:0,T,I.width),$=Math.ceil(_+2*h),g=Math.ceil(C+h),N=Ne(I,$/2,h+I.height/2,' class="pele-title" font-weight="var(--_tw)"')+K+oe+Z+M;return{svg:at("eventmodeling",$,g,i,n,e,N),width:$,height:g,links:[]}}var Uy=8,KM=120,zM=20;function VM(e,t){let n=t.fontSize??16,r=Math.round(n*.875),i=Math.round(n*.75),s=t.padding??8,a=t.measurer??ct(t.fontFamily,t.fontFamilyMono),o=Math.max(160,(t.maxWidth??320)-2*s),c=new Map(e.boxes.map((z,M)=>[z,M])),l=new Map,u=new Set;for(let z of e.relations){let M=c.get(z.source),T=c.get(z.target);if(M===void 0||T===void 0||M===T)continue;if(Math.abs(M-T)<2){u.add(e.boxes[Math.max(M,T)]);continue}let R=l.get(z.target);R?(R[0]=Math.min(R[0],M),R[1]=Math.max(R[1],M)):l.set(z.target,[Math.min(M,T),Math.max(M,T)])}let h=new Map,d=[];for(let[z,[M,T]]of[...l].sort((R,_)=>R[1][0]-_[1][0])){let R=d.findIndex(_=>_Qs(bt(z),a,M,y,T);e.boxes.forEach((z,M)=>{let T=u.has(z)?y-zM:y,R=Zs(Ge(z.lane.label,!1,a,r,T,1),a,T),_=Ge(z.name,!1,a,r,y-36,1),$=z.data?G(z.data,i,4):void 0,g=Math.max(p,R.width+2*fn,_.width+2*fn+36,($?.width??0)+2*fn),N=R.height+12,w=2*Hn+_.height+($?$.height+6:0),A=Gy.get(z.kind),D=b+N,U=`x="${f(s)}" y="${f(D)}" width="${f(g)}" height="${f(w)}"`;I+=``+Zr(R,s+fn,b,` class="pele-cluster-label" font-size="${r}" font-weight="var(--_hw)" fill="var(--_m)"`)+``+(A===void 0?"":``)+Ne(_,s+fn+_.width/2,D+Hn+_.height/2,` class="pele-label" font-size="${r}" font-weight="var(--_hw)"`)+`${rt(z.id)}`+($?pl($.lines.map(B=>B.map(F=>F.text).join("")),s+fn,D+Hn+_.height+6+$.lineHeight/2+i*.35,$.lineHeight,` class="pele-em-data" font-family="${fr}" font-size="${i}"`):"")+"",v.set(z,{y:D,h:w,w:g,index:M,lane:R.width}),x=Math.max(x,g+m),S=D+w,b=S+28});for(let z of e.relations){let M=v.get(z.source),T=v.get(z.target);if(!M||!T||M===T)continue;let R=T.y>M.y,_=R?1:-1,$=R?M.y+M.h:M.y,g=R?T.y:T.y+T.h,N,w;if(Math.abs(M.index-T.index)===1){let A=s+Math.max(Math.min(M.w,T.w)/2,fn+(R?T:M).lane+16);N=`M${f(A)},${f($)}V${f(g-_*Rt("arrow_point"))}`,w=_t("arrow_point",A,g,0,_,"var(--_l)")}else{let A=s+x-m+12+Uy*(h.get(z.target)??0),D=M.y+M.h/2-5,U=T.y+T.h/2+5;N=`M${f(s+M.w)},${f(D)}H${f(A)}V${f(U)}H${f(s+T.w+Rt("arrow_point"))}`,w=_t("arrow_point",s+T.w,U,-1,0,"var(--_l)")}L+=`${w}`}let K=new Map(e.boxes.map(z=>[z.id,z.name])),C=(z,M,T,R)=>{let _=Ge(`${M} · ${T}${K.has(T)?" "+K.get(T):""}`,!1,a,r,y,1),$=G(R,r),g=Math.max(p,_.width+2*fn,$.width+2*fn),N=2*Hn+_.height+$.height;O+=``+Ne(_,s+fn+_.width/2,b+Hn+_.height/2,` font-size="${r}" font-weight="var(--_hw)"`)+pl($.lines.map(w=>w.map(A=>A.text).join("")),s+fn,b+Hn+_.height+$.lineHeight/2+r*.35,$.lineHeight,` font-size="${r}"`)+"",S=b+N,b=S+Yy,x=Math.max(x,g)};for(let z of e.notes)C("note","Note",z.frame,z.text);for(let z of e.specifications){let M=[`Given ${z.given.join(", ")}`];z.when.length&&M.push(`When ${z.when.join(", ")}`),M.push(`Then ${z.then.join(", ")}`),C("specification","Given / When / Then",z.frame,M.join(` +`))}let Z=Math.ceil(x+2*s),oe=Math.ceil(S+s),H=Ne(E,Z/2,s+E.height/2,' class="pele-title" font-weight="var(--_tw)"')+L+I+O;return{svg:at("eventmodeling",Z,oe,n,t,e,H),width:Z,height:oe,links:[]}}var Ky={type:"eventmodeling",keepComments:!0,parse:(e,t,n)=>Dy(Py(e),n),render:Hy};function Qf(e){return e==="markdown"||e==="string"||e==="text"?e:"markdown"}function zy(e){return e.startsWith('"')&&e.endsWith('"')?e.substring(1,e.length-1):e}function jM(e,t){let n=0;for(let r=0;r":r="arrow_point",t.startsWith("<")&&(r="double_"+r,n=n.slice(1));break;case"o":r="arrow_circle",t.startsWith("o")&&(r="double_"+r,n=n.slice(1));break}let i="normal",s=n.length-1;n.startsWith("=")&&(i="thick"),n.startsWith("~")&&(i="invisible");let a=jM(".",n);return a&&(i="dotted",s=a),{type:r,stroke:i,length:s}}var ml=class{constructor(t={}){fe(this,"type","flowchart");fe(this,"direction");fe(this,"nodes",new Map);fe(this,"edges",[]);fe(this,"subgraphs",[]);fe(this,"classes",new Map);fe(this,"tooltips",new Map);fe(this,"defaultEdgeStyle");fe(this,"defaultInterpolate");fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"subgraphLookup",new Map);fe(this,"members",new Set);fe(this,"edgeById",new Map);fe(this,"pairCount",new Map);fe(this,"subCount",0);fe(this,"options");this.options=t}addVertex(t,n,r,i,s,a,o,c){if(!t||t.trim().length===0)return;let l;if(c!==void 0){let p=c.includes(` +`)?c+` +`:`{ +`+c+` +}`,y;try{y=lr(p)}catch(E){throw new Qe(`Metadata of "${t}" is not valid YAML. ${E.message}`,"syntax",{type:"flowchart"})}l=y!==null&&typeof y=="object"&&!Array.isArray(y)?y:void 0}let u=this.subgraphLookup.get(t);if(u&&l){u.metadata={...u.metadata,...l};return}let h=this.edgeById.get(t);if(h){l?.animate!==void 0&&(h.animate=l.animate),l?.animation!==void 0&&(h.animation=l.animation),l?.curve!==void 0&&(h.interpolate=l.curve);return}let d=this.nodes.get(t);if(d===void 0&&(n===void 0&&r===void 0&&i!==void 0&&i!==null&&this.options.warn?.(`Style applied to unknown node "${t}". This may indicate a typo. The node will be created automatically.`),d={id:t,labelType:"text",styles:[],classes:[]},this.nodes.set(t,d)),n!==void 0?(d.labelType=n.type,d.text=zy(n.text.trim())):d.text===void 0&&(d.text=t),r!==void 0&&(d.type=r),i!=null)for(let p of i)d.styles.push(p);if(s!=null)for(let p of s)d.classes.push(p);if(a!==void 0&&(d.dir=a),d.props===void 0?d.props=o??{}:o!==void 0&&Object.assign(d.props,o),l===void 0)return;if(l.shape){let p=String(l.shape);if(p!==p.toLowerCase()||p.includes("_"))throw new Qe(`No such shape: ${p}. Shape names should be lowercase.`,"semantic",{type:"flowchart"});if(!dc(p))throw new Qe(`No such shape: ${p}.`,"semantic",{type:"flowchart"});d.type=p}let m=typeof l.label=="string"?l.label:void 0;l.label&&(d.text=String(l.label),d.labelType=Qf(l.labelType)),l.icon&&(d.icon=String(l.icon),!m?.trim()&&d.text===t&&(d.text="")),l.form&&(d.form=String(l.form)),l.pos&&(d.pos=String(l.pos)),l.img&&(d.img=String(l.img),!m?.trim()&&d.text===t&&(d.text="")),l.constraint&&(d.constraint=String(l.constraint)),l.w&&(d.assetWidth=Number(l.w)),l.h&&(d.assetHeight=Number(l.h))}addSingleLink(t,n,r,i){let s={start:t,end:n,type:void 0,text:"",labelType:"text",classes:[],isUserDefinedId:!1,interpolate:this.defaultInterpolate},a=r?.text;a!==void 0&&(s.text=zy(a.text.trim()),s.labelType=Qf(a.type)),r!==void 0&&(s.type=r.type,s.stroke=r.stroke,s.length=r.length>10?10:r.length);let o=t+"\0"+n,c=this.pairCount.get(o)??0;i&&!this.edgeById.has(i)?(s.id=i,s.isUserDefinedId=!0):s.id=`L_${t}_${n}_${c===0?0:c+1}`;let l=this.options.maxEdges;if(l!==void 0&&this.edges.length>=l)throw new Qe(`Edge limit exceeded. The limit is ${l}.`,"limit",{type:"flowchart"});this.edges.push(s),this.pairCount.set(o,c+1),this.edgeById.has(s.id)||this.edgeById.set(s.id,s)}addLink(t,n,r){let i=typeof r?.id=="string"?r.id.replace("@",""):void 0,s=t[t.length-1],a=n[0];for(let o of t)for(let c of n)this.addSingleLink(o,c,r,o===s&&c===a?i:void 0)}updateLinkInterpolate(t,n){for(let r of t)r==="default"?this.defaultInterpolate=n:this.edgeAt(r).interpolate=n}updateLink(t,n){for(let r of t){if(r==="default"){this.defaultEdgeStyle=n;continue}let i=this.edgeAt(r);i.style=n,n.length>0&&!n.some(s=>s?.startsWith("fill"))&&n.push("fill:none")}}edgeAt(t){let n=this.edges[Number(t)];if(n===void 0)throw new Qe(`The index ${t} for linkStyle is out of bounds. Valid indices for linkStyle are between 0 and ${this.edges.length-1}. (Help: Ensure that the index is within the range of existing edges.)`,"semantic",{type:"flowchart"});return n}addClass(t,n){let r=n.join().replace(/\\,/g,"§§§").replace(/,/g,";").replace(/§§§/g,",").split(";");for(let i of t.split(",")){let s=this.classes.get(i);s===void 0&&(s={id:i,styles:[],textStyles:[]},this.classes.set(i,s));for(let a of r)a.includes("color")&&s.textStyles.push(a.replace("fill","bgFill")),s.styles.push(a)}}setDirection(t){let n=t.trim();n.includes("<")&&(n="RL"),n.includes("^")&&(n="BT"),n.includes(">")&&(n="LR"),n.includes("v")&&(n="TB"),n==="TD"&&(n="TB"),this.direction=n}setClass(t,n){for(let r of t.split(","))this.nodes.get(r)?.classes.push(n),this.edgeById.get(r)?.classes.push(n),this.subgraphLookup.get(r)?.classes.push(n)}setTooltip(t,n){if(n!==void 0)for(let r of t.split(","))this.tooltips.set(r,n)}setLink(t,n,r){let i=n.trim();for(let s of t.split(",")){let a=this.nodes.get(s);a!==void 0&&(a.link=i?Qn(i):void 0,a.linkTarget=r)}this.setClass(t,"clickable")}setClickEvent(t,n,r){this.setClass(t,"clickable")}setAccTitle(t){this.accTitle=t.replace(/^\s+/g,"")}setAccDescription(t){this.accDescr=t.replace(/\n\s+/g,` +`)}addSubGraph(t,n,r){let i=t?.text.trim(),s=r?.text??"";t!==void 0&&t===r&&/\s/.test(s)&&(i=void 0);let a=new Set,o=[],c;for(let d of n)if(typeof d=="string")d.trim()!==""&&!a.has(d)&&(a.add(d),o.push(d));else if(Array.isArray(d))for(let m of d)m.trim()!==""&&!a.has(m)&&(a.add(m),o.push(m));else c=d.value;c??=this.options.inheritDir?this.direction??this.options.direction:void 0,i??="subGraph"+this.subCount,s=s||"",this.subCount++;let l={id:i,nodes:o,title:s.trim(),classes:[],dir:c,labelType:Qf(r?.type)},u=this.members;l.nodes=o.filter(d=>!u.has(d)&&d!==i);for(let d of l.nodes)u.add(d);let h=this.subgraphLookup.get(i);if(h)for(let d of l.nodes)h.nodes.push(d);else this.subgraphs.push(l);return this.subgraphLookup.set(i,h??l),i}exists(t,n){for(let r of t)if(r.nodes.includes(n))return!0;return!1}makeUniq(t,n){let r=new Set;for(let i of n)for(let s of i.nodes)r.add(s);return{nodes:t.nodes.filter(i=>!r.has(i))}}destructLink(t,n){let r=qM(t);if(!n)return r;let i=XM(n);if(i.stroke!==r.stroke)return{type:"INVALID",stroke:"INVALID"};if(i.type==="arrow_open")i.type=r.type;else{if(i.type!==r.type)return{type:"INVALID",stroke:"INVALID"};i.type="double_"+i.type}return i.type==="double_arrow"&&(i.type="double_arrow_point"),i.length=r.length,i}subgraph(t){return this.subgraphLookup.get(t)}};var Zf=["$end","INVALID","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","SHAPE_DATA","CALLBACKNAME","CALLBACKARGS","MD_STR","STR","STYLE","DEFAULT","LINKSTYLE","INTERPOLATE","CLASSDEF","CLASS","HREF","CLICK","GRAPH","subgraph","end","LINK_TARGET","NODIR","DIR","direction_tb","direction_bt","direction_rl","direction_lr","direction_td","LINK_ID","NUM","BRKT","STYLE_SEPARATOR","COLON","AMP","SEMI","COMMA","MULT","LINK","START_LINK","EDGE_TEXT","-)","TEXT","(-","STADIUMEND","STADIUMSTART","SUBROUTINEEND","SUBROUTINESTART","VERTEX_WITH_PROPS_START","TAGEND","CYLINDEREND","CYLINDERSTART","DOUBLECIRCLEEND","DOUBLECIRCLESTART","TRAPEND","INVTRAPEND","TRAPSTART","INVTRAPSTART","TAGSTART","UP","SEP","DOWN","NODE_STRING","MINUS","UNICODE_TEXT","PIPE","PE","PS","SQE","SQS","DIAMOND_STOP","DIAMOND_START","NEWLINE","SPACE","EOF"];var qy=new Uint8Array(128);for(let e of"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"#$%&'*+.`?\\_/")qy[e.charCodeAt(0)]=1;var QM=/accTitle\s*:\s*/y,ZM=/accDescr\s*:\s*/y,JM=/accDescr\s*\{\s*/y,eC=/call\s+/y,tC=/click\s+/y,nC=/(?:\r?\n)*\s*\n/y,rC=/\s*(?:LR|RL|TB|BT|TD|BR)\b/y,sC=/\s*[<>^]/y,iC=/\s*v\b/y,oC=[/.*direction\s+TB[^\n]*/y,/.*direction\s+BT[^\n]*/y,/.*direction\s+RL[^\n]*/y,/.*direction\s+LR[^\n]*/y,/.*direction\s+TD[^\n]*/y],Jf=/[\n\r\u2028\u2029]/g,Vy=/\s*[xo<]?--+[-xo>]\s*/y,aC=/\s*[xo<]?--\s*/y,jy=/\s*[xo<]?==+[=xo>]\s*/y,cC=/\s*[xo<]?==\s*/y,eh=/\s*[xo<]?-?\.+-[xo>]?\s*/y,lC=/\s*[xo<]?-\.\s*/y,Xy=/\s*~~~+\s*/y,dC=/(?:\r?\n)+/y,uC=/[^\S\n\r]+/y,fC=/\(\s*\)/y,hC=/\n\s*/g;function Qy(e){let t=e.length,n=[],r=[],i=[],s=[],a=0,o=0,c=!0,l=e.indexOf("direction"),u=e.indexOf("@"),h=-1,d=0,m=0,p=-1,y=-1,E=-1,b=(T,R,_)=>{n.push(T),r.push(e.slice(R,_)),i.push(R),o=_},S=T=>{s.push(a),a=T},x=()=>{s.length>0&&(a=s.pop())},I=(T,R)=>(T.lastIndex=R,T.test(e)?T.lastIndex:-1),L=T=>e.startsWith(T,o)&&!ot(e.charCodeAt(o+T.length)),O=T=>{let R=T;if(T>=y&&T<=E)R=E;else if(qe(e.charCodeAt(T))){for(;R{let R=T;if(T>=y&&T<=E)R=E;else if(qe(e.charCodeAt(T))){for(;R{e.charCodeAt(o+1)===96?(S(2),o+=2):(S(1),o++)},K=()=>{if(!v(o))return!1;let T=I(Xy,o);return T<0?!1:(b(40,o,T),!0)},C=T=>{let R=e.charCodeAt(o+1);return T===40?(R===45?(S(8),b(45,o,o+2)):R===91?(S(7),b(47,o,o+2)):R===40&&e.charCodeAt(o+2)===40?(S(7),b(55,o,o+3)):(S(7),b(69,o,o+1)),!0):T===91?(R===91?(S(7),b(49,o,o+2)):R===40?(S(7),b(53,o,o+2)):R===47?(S(9),b(58,o,o+2)):R===92?(S(9),b(59,o,o+2)):(S(7),b(71,o,o+1)),!0):T===124?(S(7),b(67,o,o+1),!0):T===123?(S(7),b(73,o,o+1),!0):!1},Z=T=>{c&&(c=!1,S(6)),b(20,o,o+T)},oe=()=>{let T=o;for(;T{let R=O(o),_;if(R===45){if((_=I(Vy,o))>=0)return b(40,o,_),!0;if((_=I(aC,o))>=0)return S(10),b(41,o,_),!0;if((_=I(eh,o))>=0)return b(40,o,_),!0;if((_=I(lC,o))>=0)return S(12),b(41,o,_),!0}else if(R===61){if((_=I(jy,o))>=0)return b(40,o,_),!0;if((_=I(cC,o))>=0)return S(11),b(41,o,_),!0}else if(R===46&&(_=I(eh,o))>=0)return b(40,o,_),!0;return T!==45&&T!==61&&T!==46&&K()},z=T=>{let R;switch(T){case 97:if(e.startsWith("acc",o)){if((R=I(QM,o))>=0)return S(3),b(2,o,R),!0;if((R=I(ZM,o))>=0)return S(4),b(4,o,R),!0;if((R=I(JM,o))>=0)return S(5),o=R,!0}break;case 64:if(e.charCodeAt(o+1)===123)return S(16),n.push(7),r.push(""),i.push(o),o+=2,!0;break;case 99:if((R=I(eC,o))>=0)return S(14),o=R,!0;if(L("classDef"))return b(16,o,o+8),!0;if(L("class"))return b(17,o,o+5),!0;if((R=I(tC,o))>=0)return S(13),o=R,!0;break;case 34:return G(),!0;case 115:if(L("style"))return b(12,o,o+5),!0;if(L("swimlane-beta"))return Z(13),!0;if(L("subgraph"))return b(21,o,o+8),!0;break;case 100:if(L("default"))return b(13,o,o+7),!0;break;case 108:if(L("linkStyle"))return b(14,o,o+9),!0;break;case 105:if(L("interpolate"))return b(15,o,o+11),!0;break;case 104:if(e.startsWith("href",o)&&qe(e.charCodeAt(o+4)))return b(18,o,o+5),!0;break;case 102:if(L("flowchart-elk"))return Z(13),!0;if(L("flowchart"))return Z(9),!0;break;case 103:if(L("graph"))return Z(5),!0;break;case 101:if(L("end")){for(R=o+3;R=d&&(l=0)return b(26+_,o,R),!0;d=h}if(u!==-1&&T!==34&&!qe(T)){if(o>=m){u=u;$--){if(e.charCodeAt($)!==64)continue;let g=e.charCodeAt($+1);if(g!==123&&g!==34){p=$;break}}}if(p>o)return b(31,o,p+1),!0}if(T>=48&&T<=57){let _=o+1;for(;_57)break;_++}return b(32,o,_),!0}switch(T){case 35:return b(33,o,o+1),!0;case 58:return e.charCodeAt(o+1)===58&&e.charCodeAt(o+2)===58?b(34,o,o+3):b(35,o,o+1),!0;case 38:return b(36,o,o+1),!0;case 59:return b(37,o,o+1),!0;case 44:return b(38,o,o+1),!0;case 42:return b(39,o,o+1),!0;case 120:case 111:return H(T)||oe();case 60:return H(T)||b(60,o,o+1),!0;case 45:return H(T)||oe()||b(65,o,o+1),!0;case 61:return H(T);case 46:return H(T)||oe();case 126:return K();case 40:return C(T);case 91:return e.charCodeAt(o+1)===124?(b(50,o,o+2),!0):C(T);case 124:case 123:return C(T);case 62:return S(7),b(51,o,o+1),!0;case 94:return b(61,o,o+1),!0;case 92:return e.charCodeAt(o+1)===124?(b(62,o,o+2),!0):oe();case 118:return ot(e.charCodeAt(o+1))?oe():(b(63,o,o+1),!0)}return qe(T)?H(T)?!0:(R=I(dC,o))>=0?(b(74,o,R),!0):(R=I(uC,o))>=0?(b(75,o,R),!0):!1:T<128?oe():Oi(T)?(b(66,o,o+1),!0):!1},M=(T,R,_,$)=>{if(T===34)return G(),!0;let g=O(o);if(g===_||g===$){let w=I(R,o);if(w>=0)return x(),b(40,o,w),!0}if(T===_&&(_!==45||e.charCodeAt(o+1)===45))return!1;let N=o+1;for(;N=0)break}N++}return b(42,o,N),!0};e:for(;;){if(o>=t){let _=-1;switch(a){case 0:_=76;break;case 3:_=3;break;case 4:_=5;break;case 5:_=6;break;case 13:_=19;break;case 14:_=8;break;case 15:_=9;break}_!==-1&&b(_,t,t);break}let T=e.charCodeAt(o),R=!0;switch(a){case 0:R=z(T);break;case 1:if(T===34)e.charCodeAt(o+1)===96?(S(2),o+=2):(x(),o++);else{let _=e.indexOf('"',o);b(11,o,_===-1?t:_)}break;case 2:if(T===96)e.charCodeAt(o+1)===34?(x(),o+=2):R=!1;else if(T===34)G();else{let _=o+1;for(;_=0?(x(),b(24,o,_)):(_=I(rC,o))>=0||(_=I(sC,o))>=0||(_=I(iC,o))>=0?(x(),b(25,o,_)):R=K()||C(T);break}case 7:{let _=e.charCodeAt(o+1);switch(T){case 34:G();break;case 40:case 91:case 123:C(T);break;case 93:x(),_===41?b(46,o,o+2):_===93?b(48,o,o+2):b(70,o,o+1);break;case 41:x(),_===93?b(52,o,o+2):_===41&&e.charCodeAt(o+2)===41?b(54,o,o+3):b(68,o,o+1);break;case 124:x(),b(67,o,o+1);break;case 125:x(),b(72,o,o+1);break;default:{if((T===126||qe(T))&&K())break;let $=o+1;for(;$=0)break;$++}b(44,o,$)}}break}case 9:{let _=e.charCodeAt(o+1);if(T===34){G();break}if((T===126||qe(T))&&K())break;switch(T){case 40:_===45||_===91||_===40&&e.charCodeAt(o+2)===40?C(T):_===93?(x(),b(56,o,o+2)):C(T);break;case 91:case 123:C(T);break;case 92:_===93?(x(),b(56,o,o+2)):b(44,o,o+1);break;case 47:_===93?(x(),b(57,o,o+2)):b(44,o,o+1);break;case 93:case 41:_===93?(x(),b(56,o,o+2)):R=!1;break;case 125:R=!1;break;default:{if((T===63||T===61)&&_===93){x(),b(56,o,o+2);break}let $=o+1;for(;$=0?o=_:(S(15),o++)}else{let _=e.indexOf("(",o);_===-1&&(_=t),b(8,o,_)}break;case 15:if(T===41)x(),o++;else{let _=e.indexOf(")",o);_===-1&&(_=t),b(9,o,_)}break;case 16:if(T===34)S(17),b(7,o,o+1);else if(T===125)x(),o++;else if(T===94)R=!1;else{let _=o+1;for(;_")),i.push(o),o=_}break}if(!R)return n.push(1),r.push(""),i.push(o),{types:n,texts:r,starts:i};continue e}return n.push(0),r.push(""),i.push(t),{types:n,texts:r,starts:i}}var gl=new Uint8Array(77);for(let e of[32,64,63,65,13,38,35,36,33,39,66])gl[e]=1;var th=new Uint8Array(77);for(let e of[32,66,64,25,63,65,38,35,36,33,39])th[e]=1;var nh=new Uint8Array(77);for(let e of[32,64,75,65,36,66,35,39,33,12,14,16,17,19,20,25,21,22,63,61,41])nh[e]=1;var rh=new Uint8Array(77);for(let e of[32,64,35,75,33,12])rh[e]=1;var Zy="'UNICODE_TEXT', 'TEXT', 'TAGSTART'",pa=[],Jy=/}\s*\n/g;function tE(e,t){let n=e.includes("}")?e.replace(Jy,`} +`):e,{types:r,texts:i,starts:s}=Qy(n),a=0,o,c=M=>{let T=r[a],R=n===e?s[a]:zr([ds(e,Jy,2)],s[a]);throw T===1?ft("flowchart",e,R,"",!0):ft("flowchart",e,R,`Expecting ${M}, got '${Zf[T]}'`)},l=(M,T="")=>(r[a]!==M&&c(`'${Zf[M]}'${T?", "+T:""}`),i[a++]),u=()=>{let M=r[a];M!==74&&M!==37&&M!==76&&c("'SEMI', 'NEWLINE', 'EOF'"),a++},h=()=>{gl[r[a]]===0&&c("'NODE_STRING'");let M=i[a++];for(;gl[r[a]]===1;)M+=i[a++];return M},d=()=>{th[r[a]]===0&&c("'NODE_STRING'");let M=i[a++];for(;th[r[a]]===1;)M+=i[a++];return M},m=()=>{let M=r[a],T;if(M===11)T="string";else if(M===10)T="markdown";else if(M===44||M===60||M===51||M===66)T="text";else return c(`${Zy}, 'TAGEND', 'STR', 'MD_STR'`);let R=i[a++];for(;;){let _=r[a];if(_!==44&&_!==60&&_!==51&&_!==66)break;R+=i[a++]}return{text:R,type:T}},p=M=>{l(M,Zy)},y=()=>{let M=r[a],T;if(M===11)T="string";else if(M===10)T="markdown";else if(M===42||M===66)T="text";else return c("'EDGE_TEXT', 'STR', 'MD_STR'");let R=i[a++];for(;r[a]===42||r[a]===66;)R+=i[a++];return{text:R,type:T}},E=()=>{let M=r[a],T;if(M===11)T="text";else if(M===10)T="markdown";else if(nh[M]===1)T="text";else return c("'NODE_STRING', 'STR', 'MD_STR'");let R=i[a++];for(;nh[r[a]]===1;)R+=i[a++];return{text:R,type:T}},b=()=>{let M=i[a++];for(;r[a]===7;)M+=i[a++];return M},S=()=>{let M=h(),T;switch(r[a]){case 71:a++,T=m(),p(70),t.addVertex(M,T,"square");break;case 55:a++,T=m(),p(54),t.addVertex(M,T,"doublecircle");break;case 69:a++,r[a]===69?(a++,T=m(),p(68),l(68),t.addVertex(M,T,"circle")):(T=m(),p(68),t.addVertex(M,T,"round"));break;case 45:a++,T=m(),p(43),t.addVertex(M,T,"ellipse");break;case 47:a++,T=m(),p(46),t.addVertex(M,T,"stadium");break;case 49:a++,T=m(),p(48),t.addVertex(M,T,"subroutine");break;case 50:{a++;let R=l(64);l(35);let _=l(64);l(67),T=m(),p(70),t.addVertex(M,T,"rect",void 0,void 0,void 0,{[R]:_});break}case 53:a++,T=m(),p(52),t.addVertex(M,T,"cylinder");break;case 73:a++,r[a]===73?(a++,T=m(),p(72),l(72),t.addVertex(M,T,"hexagon")):(T=m(),p(72),t.addVertex(M,T,"diamond"));break;case 51:a++,T=m(),p(70),t.addVertex(M,T,"odd");break;case 58:a++,T=m(),r[a]===57?(a++,t.addVertex(M,T,"lean_right")):(p(56),t.addVertex(M,T,"trapezoid"));break;case 59:a++,T=m(),r[a]===56?(a++,t.addVertex(M,T,"lean_left")):(p(57),t.addVertex(M,T,"inv_trapezoid"));break;default:t.addVertex(M)}return M},x=()=>{let M=S();return r[a]===34&&(a++,t.setClass(M,h())),M},I=()=>{let M=[x()];for(o=void 0;;){let T=r[a]===7?b():void 0;if(r[a]!==75)return o=T,M;do a++;while(r[a]===75);if(r[a]!==36)return T!==void 0&&c("'AMP'"),M;a++,r[a]!==75&&c("'SPACE'");do a++;while(r[a]===75);let R=x();T!==void 0&&t.addVertex(M[M.length-1],void 0,void 0,void 0,void 0,void 0,void 0,T),M.push(R)}},L=()=>{let M;if(r[a]===31&&(M=i[a++]),r[a]===40){let T=t.destructLink(i[a++]);return M!==void 0&&(T.id=M),r[a]===67&&(a++,T.text=m(),p(67),r[a]===75&&a++),T}if(r[a]===41){let T=i[a++],R=y(),_=l(40,"'EDGE_TEXT'"),$=t.destructLink(_,T);return $.text=R,M!==void 0&&($.id=M),$}return c("'LINK', 'START_LINK'")},O=M=>{let T=I();o!==void 0&&t.addVertex(T[T.length-1],void 0,void 0,void 0,void 0,void 0,void 0,o);let R=T;for(;;){let _=r[a];if(_!==40&&_!==41&&_!==31)return R;let $=L(),g=I();o!==void 0&&t.addVertex(g[g.length-1],void 0,void 0,void 0,void 0,void 0,void 0,o),t.addLink(T,g,$),M&&(R=g.concat(R)),T=g}},v=()=>{rh[r[a]]===0&&c("'NODE_STRING', 'NUM', 'COLON', 'BRKT'");let M=i[a++];for(;rh[r[a]]===1;)M+=i[a++];return M},G=()=>{let M=[v()];for(;r[a]===38;)a++,M.push(v());return M},K=()=>{a++,l(75);let M;if(r[a]===13)M=[i[a++]];else for(M=[l(32,"'DEFAULT'")];r[a]===38;)a++,M.push(l(32));if(l(75),r[a]!==15){t.updateLink(M,G());return}a++,l(75);let T=d();if(r[a]===75){a++;let R=G();t.updateLinkInterpolate(M,T),t.updateLink(M,R)}else t.updateLinkInterpolate(M,T)},C=(M,T)=>{if(r[a]!==75){t.setLink(M,T);return}if(a++,r[a]===23){t.setLink(M,T,i[a++]);return}let R=l(11,"'LINK_TARGET'");r[a]===75?(a++,t.setLink(M,T,l(23))):t.setLink(M,T),t.setTooltip(M,R)},Z=()=>{let M=i[a++];switch(r[a]){case 8:{let T=i[a++],R=r[a]===9,_=R?i[a++]:void 0,$;r[a]===75&&(a++,$=l(11)),R?t.setClickEvent(M,T,_):t.setClickEvent(M,T),$!==void 0&&t.setTooltip(M,$);return}case 18:a++,C(M,l(11));return;case 11:C(M,i[a++]);return;default:{let T=d();if(r[a]===75){a++;let R=l(11);t.setClickEvent(M,T),t.setTooltip(M,R)}else t.setClickEvent(M,T)}}},oe=()=>{a++;let M=r[a];if(M===74||M===37||M===76)return a++,{id:void 0,title:void 0,list:[],collect:!1};l(75,"'SEMI', 'NEWLINE', 'EOF'");let T=E(),R=T;return r[a]===71&&(a++,R=m(),p(70)),M=r[a],M!==74&&M!==37&&M!==76&&c("'SEMI', 'NEWLINE', 'EOF', 'SQS'"),a++,{id:T,title:R,list:[],collect:!1}},H=M=>{let T=r[a];switch(T){case 12:{a++,l(75);let R=h();return l(75),t.addVertex(R,void 0,void 0,G()),u(),pa}case 14:return K(),u(),pa;case 16:{a++,l(75);let R=h();return l(75),t.addClass(R,G()),u(),pa}case 17:{a++,l(75);let R=h();return l(75),t.setClass(R,h()),u(),pa}case 19:return Z(),u(),pa;case 26:case 27:case 28:case 29:case 30:return a++,{stmt:"dir",value:pC[T-26]};case 2:{a++;let R=l(3).trim();return t.setAccTitle(R),R}case 4:{a++;let R=l(5).trim();return t.setAccDescription(R),R}case 6:{let R=i[a++].trim();return t.setAccDescription(R),R}default:{gl[T]===0&&c(eE);let R=O(M);return u(),R}}},z=()=>{let M=[],T=[],R=!1;for(;;){let _=r[a];if(_===0)break;if(_===22){let $=M.pop();if($===void 0)break;a++;let g=t.addSubGraph($.id,T,$.title);T=$.list,R=$.collect,R&&T.push(g)}else if(_===37||_===74||_===75||_===76)R&&T.push(i[a]),a++;else if(_===21){let $=oe();$.list=T,$.collect=R,M.push($),T=[],R=!0}else{let $=H(R);R&&(!Array.isArray($)||$.length>0)&&T.push($)}}M.length>0&&c("'end'")};for(;r[a]===75||r[a]===74;)a++;if(l(20,"'SPACE', 'NEWLINE'"),r[a]===24)a++,t.setDirection("TB");else{let M=l(25,"'NODIR'"),T=r[a];if(T===75){do a++;while(r[a]===75);T=r[a],T!==74&&c("'NEWLINE', 'SPACE'")}else T!==37&&T!==74&&c("'SEMI', 'NEWLINE', 'SPACE'");a++,t.setDirection(M)}z(),r[a]!==0&&c(eE)}var pC=["TB","BT","RL","LR","TD"],eE="'SEMI', 'NEWLINE', 'SPACE', 'EOF', 'subgraph', 'acc_title', 'acc_descr', 'acc_descr_multiline_value', 'STYLE', 'LINKSTYLE', 'CLASSDEF', 'CLASS', 'CLICK', 'NODE_STRING'";function mC(e){if(e.img)return"imageSquare";if(e.icon)return e.form==="circle"?"iconCircle":e.form==="square"?"iconSquare":e.form==="rounded"?"iconRounded":"icon";switch(e.type){case"square":case void 0:return"squareRect";case"round":return"roundedRect";default:return e.type}}function gC(e){switch(e){case"arrow_point":case"arrow_circle":case"arrow_cross":return["none",e];case"double_arrow_point":case"double_arrow_circle":case"double_arrow_cross":{let t=e.replace("double_","");return[t,t]}}return["none","arrow_point"]}function nE(e,t){let n=[],r=[],i=e.subgraphs,s=x=>{let I=[];for(let L of x){let O=e.classes.get(L);if(O!==void 0){for(let v of O.styles)I.push(v.trim());for(let v of O.textStyles)I.push(v.trim())}}return I},a=new Map;for(let x of i)for(let I of x.nodes)e.subgraph(I)&&a.set(I,x.id);let o=new Map,c=new Map;for(let x of i){let I=a.get(x.id);if(I===void 0)continue;let L=c.get(I);L?L.push(x.id):c.set(I,[x.id])}let l=0;for(let x of i){if(a.has(x.id))continue;let I=[x.id];for(;I.length>0;){let L=I.pop();if(o.has(L))continue;o.set(L,l++);let O=c.get(L);if(O)for(let v=O.length-1;v>=0;v--)I.push(O[v])}}let u=x=>e.subgraph(x)?.metadata?.view==="collapsed",h=!1;for(let x of i)x.metadata?.view==="collapsed"&&(h=!0);let d=new Map,m=x=>{let I=[],L=new Set,O=x;for(;O!==void 0&&!d.has(O)&&!L.has(O);)L.add(O),I.push(O),O=a.get(O);let v=O!==void 0?d.get(O):void 0;for(let G=I.length-1;G>=0;G--)v===void 0&&u(I[G])&&(v=I[G]),d.set(I[G],v);return v},p=new Set,y=new Map;for(let x of h?i:[]){let I=m(x.id);if(I!==void 0){x.id!==I&&(p.add(x.id),y.set(x.id,I));for(let L of x.nodes)L!==I&&(p.add(L),y.set(L,I))}}let E=new Map,b=new Set;for(let x=i.length-1;x>=0;x--){let I=i[x];if(!p.has(I.id)){I.nodes.length>0&&b.add(I.id);for(let L of I.nodes)E.set(L,I.id)}}let S=new Map;for(let x=i.length-1;x>=0;x--){let I=i[x];if(p.has(I.id))continue;let L=I.metadata?.view==="collapsed",O={id:I.id,label:I.title,labelType:I.labelType,parentId:E.get(I.id),cssStyles:[],cssCompiledStyles:s(I.classes),cssClasses:I.classes.join(" "),shape:L?"collapsedGroup":"rect",dir:I.dir,isGroup:!L,colorIndex:o.get(I.id)};L||(O.metadata=I.metadata),n.push(O),S.set(I.id,O)}for(let x of e.nodes.values()){if(p.has(x.id))continue;let I=S.get(x.id);if(I){I.cssStyles=x.styles,I.cssCompiledStyles=s(x.classes),I.cssClasses=x.classes.join(" ");continue}let L=b.has(x.id),O={id:x.id,label:x.text,labelType:x.labelType,parentId:E.get(x.id),cssStyles:x.styles,cssCompiledStyles:s(["default","node",...x.classes]),cssClasses:"default "+x.classes.join(" "),dir:x.dir,link:x.link,linkTarget:x.linkTarget,tooltip:e.tooltips.get(x.id),icon:x.icon,pos:x.pos,img:x.img,assetWidth:x.assetWidth,assetHeight:x.assetHeight,constraint:x.constraint,isGroup:L,shape:L?"rect":mC(x)};n.push(O)}return e.edges.forEach((x,I)=>{let L=y.get(x.start)??x.start,O=y.get(x.end)??x.end;if(L===O&&(y.has(x.start)||y.has(x.end)))return;let[v,G]=gC(x.type),K=[...e.defaultEdgeStyle??[]];x.style&&K.push(...x.style);let C=x.stroke==="invisible"||x.type==="arrow_open";r.push({id:x.id||`L_${L}_${O}_${I}`,isUserDefinedId:x.isUserDefinedId,start:L,end:O,type:x.type??"normal",label:x.text,labelType:x.labelType,thickness:x.stroke,pattern:x.stroke,minlen:x.length,classes:x.stroke==="invisible"?"":"edge-thickness-normal edge-pattern-solid flowchart-link",arrowTypeStart:C?"none":v,arrowTypeEnd:C?"none":G,cssCompiledStyles:s(x.classes),style:K,animate:x.animate,animation:x.animation,curve:x.interpolate||e.defaultInterpolate||t})}),{nodes:n,edges:r}}var bC=40,yC=16,EC=48,rE=20,sh=26,ih=' fill="var(--_s)" stroke="var(--_b)"',xC=' stroke="var(--_b)"';function oh(e,t,n){let r=e[t];return typeof r=="number"&&r>0?Math.min(r,2e3):n}function ma(e,t){return e!==void 0&&e>0&&e<=4e3?e:t}function bl(e,t,n,r){let i=s=>An(n,a=>AC(e,t,n,r,s,a));return Pn(e.direction)?Pt(n,i):i(!1)}function AC(e,t,n,r,i,s){let a=s?12:rE,o=r?t[r.type]:void 0,c=typeof o=="object"&&o!==null&&!Array.isArray(o)?o:t.flowchart??{},l=nE(e,typeof c.curve=="string"?c.curve:void 0);r?.prepare(l);let u=n.fontSize??16,h=Math.round(u*.875),d=n.measurer??ct(n.fontFamily,n.fontFamilyMono),m=Math.min(oh(c,"wrappingWidth",200),r&&s?100:1/0),p=n.padding??8,y=n.icons,E=new Map,b=[],S=[];l.nodes.forEach((Q,Y)=>E.set(Q.id,Y));for(let Q of l.nodes){let Y=Ct(Q.cssStyles.length>0?Q.cssCompiledStyles.concat(Q.cssStyles):Q.cssCompiledStyles),ne=(Y.bold?1:0)|(Y.italic?2:0),q=Q.labelType==="markdown",k=Y.fontSize??u,J,te;if(Q.isGroup){let se=Ge(Q.label,q,d,k,r&&s?Math.max(80,kt(n)/2):4e3,ne);J={node:Q,style:Y,label:se,shape:"group",w:0,h:0,dy:0,loops:0},te=Bt(0,0),te.isGroup=!0,te.dir=Q.dir?ln(Q.dir):void 0,te.padX=a,te.padTop=se.height>0?se.height+16:rE,te.padBottom=a,te.minW=se.width+2*a-12}else{let se=uc(Q.shape),re=Q.img||Q.icon||Lg(se)?Q.label:void 0,P=Ge(re,q,d,k,m,ne),ee,ae,ue=0;if(Q.img||Q.icon){let ce=Q.img?80:48,pe=ma(Q.assetWidth,ce),V=ma(Q.assetHeight,ce);ee=Math.max(pe,P.width+8),ae=V+(P.height>0?P.height+6:0),ue=Q.pos==="t"?-V/2:V/2,P.height===0&&(ue=0)}else{let ce=ps(se,P.width,P.height);ee=ce.w,ae=ce.h,ue=ce.dy}J={node:Q,style:Y,label:P,shape:se,w:ee,h:ae,dy:ue,loops:0},te=Bt(ee,ae)}te.seq=b.length,b.push(J),S.push(te)}l.nodes.forEach((Q,Y)=>{S[Y].parent=Q.parentId!==void 0?E.get(Q.parentId)??-1:-1}),xc(S,l.edges.map(Q=>[E.get(Q.start)??-1,E.get(Q.end)??-1]));let x=i?"TB":ln(e.direction),I=Q=>{let Y;for(let ne=S[Q].parent,q=0;ne>=0&&Y===void 0&&q<1e4;ne=S[ne].parent,q++)Y=S[ne].dir;return Y??=x,Y==="LR"||Y==="RL"};b.forEach((Q,Y)=>{Q.node.isGroup?S[Y].span=1/0:!Q.node.img&&!Q.node.icon&&(S[Y].span=$g(Q.shape,Q.w,Q.h,I(Y)))});let L=[],O=[],v=[];for(let Q of l.edges){let Y=E.get(Q.start),ne=E.get(Q.end);if(Y===void 0||ne===void 0)continue;let q=Ge(Q.label,Q.labelType==="markdown",d,h,m);Y===ne&&(b[Y].loops++,I(Y)?S[Y].h+=2*(sh+(q.height>0?q.height+8:0)):S[Y].w+=2*(sh+(q.width>0?q.width+12:0))),v.push(Q),O.push(q),L.push({src:Y,dst:ne,minlen:Q.minlen??1,labelW:q.width>0?q.width+12:0,labelH:q.height>0?q.height+4:0,route:[],labelX:0,labelY:0})}let G={nodeSep:oh(c,"nodeSpacing",bC)*(s?.5:1),edgeSep:yC,rankSep:oh(c,"rankSpacing",EC)*(s?.75:1),portSep:20,tracks:typeof c.curve=="string"&&/^step/.test(c.curve),straight:c.curve==="linear",headRoom:Rt("arrow_point")},K=r?r.layout(S,L,x,G,s):On(S,L,x,G),C=yn(e.title,d,u,s?kt(n):4e3),Z=C.height>0?C.height+12:0,oe=Math.max(K.width,C.width),H=p+(oe-K.width)/2,z=p+Z;Tr(S,L,H,z);let M=Math.ceil(oe+2*p),T=Math.ceil(K.height+Z+2*p),R=[],_=new Map,$=!1;for(let Q of S)Q.isGroup&&($=!0);if($)for(let Q of L)ur(_,Q.route);let g="",N="",w="",A=[];for(let Q=0;Q`+(le?"":Ne(Y.label,V,X,de,y))+"";continue}let re=Y.w,P=Y.h,ee,ae="";if(q.img){let V=ma(q.assetWidth,80),X=ma(q.assetHeight,80),le=Y.label.height>0?q.pos==="t"?P/2-X:-P/2:-X/2,de=qm(Qn(q.img),n);ee=de===void 0?"":``}else if(q.icon){let V=ma(q.assetHeight,48),X=Y.label.height>0?q.pos==="t"?P/2-V:-P/2:-V/2,le=q.shape==="icon"?"":q.shape==="iconCircle"?``:``,de=V*.6;ee=le+`${y?.(q.icon)??""}`}else ee=hr(Y.shape,re,P,ih+Y.style.shape,xC+Y.style.line),Gi(Y.shape)&&(ae=vt(Y.style));let ue=Ne(Y.label,0,Y.dy,` class="pele-label"${ae}${Y.style.text}`,y);if(/ internal-link(?: |$)/.test(te+" ")&&q.label&&n.links!==!1){let V=bt(q.label),X=$i(V,n),le=rt(V);ue=`${ue}`,R.push({id:q.id,href:V,internal:!0})}let pe=ee+ue;q.tooltip&&(pe=`${Ue(q.tooltip)}`+pe),q.link&&(pe=Zn(pe,q.link,q.id,R,n,q.linkTarget?` target="${rt(q.linkTarget)}"`:"")),w+=`${pe}`}let D=_c();for(let Q=0;Q0||ne.cssCompiledStyles.length>0?Ct(ne.cssCompiledStyles.concat(ne.style)):void 0;if(ne.thickness!=="invisible"){let J=ne.arrowTypeStart,te=ne.arrowTypeEnd,se;if(Y.src===Y.dst){let ue=b[Y.src],ce=W.get(Y.src)??0;W.set(Y.src,ce+1),se=Rc(S[Y.src],ue.w,ue.h,ce,I(Y.src),sh,Rt(te),Y)}else{let ue=Y.route.slice(),ce=D.of(Y.src,Jn(ue,0,S[Y.src])),pe=D.of(Y.dst,Jn(ue,ue.length-3,S[Y.dst]));js(ue,0,b[Y.src],S[Y.src]),js(ue,ue.length-3,b[Y.dst],S[Y.dst]),se=Cn(ue,ne.curve,Rt(J),Rt(te),ce,pe)}let re=Mr(se.d,[se.sx,se.sy,se.ex,se.ey],A,k?.line,se.tokens),P=re||(k?.stroke&&ne.thickness!=="invisible"?rt(k.stroke):"var(--_l)"),ee="";ne.thickness==="thick"?ee+=' stroke-width="2.5"':ne.thickness==="dotted"&&(ee+=' stroke-dasharray="3 4"');let ae=It(ne.classes.replace(/edge-thickness-normal|edge-pattern-solid|flowchart-link/g,""));re===""&&(U+=Cr(se,J,te,k?.line,ne.thickness==="thick")),B+=``+_t(J,se.sx,se.sy,se.sdx,se.sdy,P)+_t(te,se.ex,se.ey,se.edx,se.edy,P)+""}if(q.width>0){let J=Y.labelX,te=Y.labelY;F+=dn(ne.id,q,J,te,k?.text??"",y)}}return{svg:at(r?.type??"flowchart",M,T,u,n,e,Ne(C,M/2,p+C.height/2,' class="pele-title" font-weight="var(--_tw)"')+(g?`${g}`:"")+Dn(U)+(B?`${B}`:"")+(N?`${N}`:"")+(F?`${F}`:"")+`${w}`),width:M,height:T,links:R}}var yl={type:"flowchart",math:!0,parse(e,t,n,r,i){let s=t.flowchart??{},a=new ml({inheritDir:s.inheritDir===!0,maxEdges:i.maxEdges});return n&&(a.title=n),tE(e,a),a},render:bl};var si=["January","February","March","April","May","June","July","August","September","October","November","December"],Jr=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function eo(e){return!Number.isNaN(e.getTime())}function Kn(e,t){let n=String(e);return n.length>=t?n:"0".repeat(t-n.length)+n}function fE(e){let t=["th","st","nd","rd"],n=e%100;return e+(t[(n-20)%10]||t[n]||t[0])}function ah(e){let t=-Math.round(e.getTimezoneOffset()/15)*15;return t===0?0:t}function sE(e){let t=ah(e),n=Math.abs(t);return(t>=0?"+":"-")+Kn(Math.floor(n/60),2)+":"+Kn(n%60,2)}function hE(e){return e.getDay()||7}function Pr(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function SC(e){let t=new Date(e.getFullYear(),e.getMonth()+1,0);return t.setHours(23,59,59,999),t.getDate()}function iE(e,t){let n=new Date(e);return n.setDate(1),t(n),n.setDate(Math.min(e.getDate(),SC(n))),n}function xl(e,t,n){switch(n){case"M":return iE(e,r=>r.setMonth(e.getMonth()+t));case"y":return iE(e,r=>r.setFullYear(e.getFullYear()+t));case"d":return Pr(e,Math.round(t));case"w":return Pr(e,Math.round(7*t));case"h":return new Date(e.getTime()+t*36e5);case"m":return new Date(e.getTime()+t*6e4);case"s":return new Date(e.getTime()+t*1e3);default:return new Date(e.getTime()+t)}}function pE(e){return Pr(e,4-hE(e))}function oE(e){let t=pE(e),n=new Date(t.getFullYear(),0,1),r=hE(n),i=Pr(n,4-r+(r>4?7:0)),s=(ah(i)-ah(t))*6e4,a=(t.getTime()-i.getTime()-s)/6048e5;return(a<0?Math.ceil(a)||0:Math.floor(a))+1}var wC=/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,_C=/\[([^\]]+)]|YYYY|YY|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,RC="YYYY-MM-DDTHH:mm:ssZ";function ch(e,t){if(!eo(e))return"Invalid Date";let n=t||RC;if(n==="YYYY-MM-DD")return lh(e);let r=!1,i=n.replace(wC,a=>{switch(a){case"Q":return String(Math.ceil((e.getMonth()+1)/3));case"Do":return"["+fE(e.getDate())+"]";case"GGGG":return String(pE(e).getFullYear());case"W":return String(oE(e));case"WW":return Kn(oE(e),2);case"k":return String(e.getHours()||24);case"kk":return Kn(e.getHours()||24,2);case"X":return String(Math.floor(e.getTime()/1e3));case"x":return String(e.getTime());case"gggg":case"wo":case"w":case"ww":case"z":case"zzz":return r=!0,a;default:return a}});if(r)return;let s=e.getHours();return i.replace(_C,(a,o)=>{if(o)return o;switch(a){case"YY":return String(e.getFullYear()).slice(-2);case"YYYY":return Kn(e.getFullYear(),4);case"M":return String(e.getMonth()+1);case"MM":return Kn(e.getMonth()+1,2);case"MMM":return si[e.getMonth()].slice(0,3);case"MMMM":return si[e.getMonth()];case"D":return String(e.getDate());case"DD":return Kn(e.getDate(),2);case"d":return String(e.getDay());case"dd":return Jr[e.getDay()].slice(0,2);case"ddd":return Jr[e.getDay()].slice(0,3);case"dddd":return Jr[e.getDay()];case"H":return String(s);case"HH":return Kn(s,2);case"h":return String(s%12||12);case"hh":return Kn(s%12||12,2);case"a":return s<12?"am":"pm";case"A":return s<12?"AM":"PM";case"m":return String(e.getMinutes());case"mm":return Kn(e.getMinutes(),2);case"s":return String(e.getSeconds());case"ss":return Kn(e.getSeconds(),2);case"SSS":return Kn(e.getMilliseconds(),3);case"Z":return sE(e);default:return sE(e).replace(":","")}})}function lh(e){let t=e.getFullYear(),n=e.getMonth()+1,r=e.getDate();return(t>=1e3&&t<=9999?t:Kn(t,4))+(n<10?"-0":"-")+n+(r<10?"-0":"-")+r}var TC=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|Q|YYYY|YY?|ww?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,MC=/\[[^\]]+]/g,aE=/\d/,ga=/\d\d/,CC=/\d{3}/,NC=/\d{4}/,gr=/\d\d?/,IC=/[+-]?\d+/,cE=/[+-]\d\d:?(\d\d)?|Z/,ba=/\d*[^-_:/,()\s\d]+/;function _n(e){return(t,n)=>(t[e]=+n,!0)}var lE=(e,t)=>{if(t==="Z")return e.offset=0,!0;let n=t.match(/([+-]|\d\d)/g),r=+n[1]*60+(+n[2]||0);return e.offset=r===0?0:n[0]==="+"?-r:r,!0};function dE(e){return(t,n)=>{let r=e.indexOf(n)+1;return r<1?!1:(t.month=r%12||r,!0)}}var kC=new Map([["A",{re:ba,read:(e,t)=>(e.afternoon=t==="PM",!0)}],["a",{re:ba,read:(e,t)=>(e.afternoon=t==="pm",!0)}],["Q",{re:aE,read:(e,t)=>(e.month=(+t-1)*3+1,!0)}],["S",{re:aE,read:(e,t)=>(e.milliseconds=+t*100,!0)}],["SS",{re:ga,read:(e,t)=>(e.milliseconds=+t*10,!0)}],["SSS",{re:CC,read:(e,t)=>(e.milliseconds=+t,!0)}],["s",{re:gr,read:_n("seconds")}],["ss",{re:gr,read:_n("seconds")}],["m",{re:gr,read:_n("minutes")}],["mm",{re:gr,read:_n("minutes")}],["H",{re:gr,read:_n("hours")}],["h",{re:gr,read:_n("hours")}],["HH",{re:gr,read:_n("hours")}],["hh",{re:gr,read:_n("hours")}],["D",{re:gr,read:_n("day")}],["DD",{re:ga,read:_n("day")}],["Do",{re:ba,read:(e,t)=>{let n=t.match(/\d+/);if(!n)return!1;e.day=+n[0],e.dayGiven=!0;for(let r=1;r<=31;r++)fE(r)===t&&(e.day=r);return!0}}],["w",{re:gr,read:_n("week")}],["ww",{re:ga,read:_n("week")}],["M",{re:gr,read:_n("month")}],["MM",{re:ga,read:_n("month")}],["MMM",{re:ba,read:dE(si.map(e=>e.slice(0,3)))}],["MMMM",{re:ba,read:dE(si)}],["Y",{re:IC,read:_n("year")}],["YY",{re:ga,read:(e,t)=>(e.year=+t+(+t>68?1900:2e3),!0)}],["YYYY",{re:NC,read:_n("year")}],["Z",{re:cE,read:lE}],["ZZ",{re:cE,read:lE}]]),uE,El=null;function $C(e){if(e===uE)return El;if(uE=e,El=null,/[Ll]/.test(e.replace(MC,"")))return null;let t=e.match(TC);return t?(El=t.map(n=>kC.get(n)??n.replace(/^\[|\]$/g,"")),El):null}function LC(e,t,n){if(t==="x"||t==="X")return new Date((t==="X"?1e3:1)*Number(e));let r=$C(t);if(!r)return;let i={},s=e,a=0;for(let p of r){if(typeof p=="string"){a+=p.length;continue}let y=p.re.exec(s.slice(a));if(!y||!p.read(i,y[0]))return;s=s.replace(y[0],"")}i.afternoon!==void 0&&i.hours!==void 0&&(i.afternoon?i.hours<12&&(i.hours+=12):i.hours===12&&(i.hours=0));let o=i.dayGiven||i.day?i.day:!i.year&&!i.month?n.getDate():1,c=i.year||n.getFullYear(),l=0;i.year&&!i.month||(l=i.month>0?i.month-1:n.getMonth());let u=i.hours||0,h=i.minutes||0,d=i.seconds||0,m=i.milliseconds||0;if(i.offset!==void 0)return new Date(Date.UTC(c,l,o,u,h,d,m+i.offset*6e4));if(!i.week)return new Date(c,l,o,u,h,d,m)}function mE(e,t,n){let r=LC(e,t,n);return r&&eo(r)&&ch(r,t)===e?r:void 0}var OC=/^[YMDHhmsSZXx\-/.:, T]*$/,DC=/^\s*(active|done|crit|milestone|vert)\s*$/,vC=/^after\s+([\d\w- ]+)/,PC=/^until\s+([\d\w- ]+)/,FC=/^(\d+(?:\.\d+)?)([Mdhmswy]|ms)$/,BC=/[\s,]+/,WC=/^\d+$/,UC=new Set(Jr.map(e=>e.toLowerCase())),GC=4e8,YC=400,HC=200,KC=400;function dh(e){let t=e===void 0?NaN:+e;return Number.isFinite(t)?t:Date.now()}function zC(e){let t=FC.exec(e.trim());return t?[Number.parseFloat(t[1]),t[2]]:[NaN,"ms"]}function gE(e,t){let n=new Set(e);for(let r of t.toLowerCase().split(BC))r!==""&&n.add(r);return[...n]}var Al=class{constructor(t={}){fe(this,"type","gantt");fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"dateFormat","");fe(this,"axisFormat","");fe(this,"tickInterval");fe(this,"todayMarker","");fe(this,"includes",[]);fe(this,"excludes",[]);fe(this,"inclusiveEndDates",!1);fe(this,"topAxis",!1);fe(this,"displayMode","");fe(this,"weekday");fe(this,"weekend","saturday");fe(this,"sections",[]);fe(this,"links",new Map);fe(this,"tasks",[]);fe(this,"byId",new Map);fe(this,"currentSection","");fe(this,"taskCount",0);fe(this,"lastOrder",0);fe(this,"lastTaskId");fe(this,"options");fe(this,"now",0);fe(this,"work",0);fe(this,"includeSet",new Set);fe(this,"excludeSet",new Set);fe(this,"excludedDays",[]);fe(this,"datedTokens",!1);this.options=t}setDateFormat(t){this.dateFormat=t}enableInclusiveEndDates(){this.inclusiveEndDates=!0}TopAxis(){this.topAxis=!0}setAxisFormat(t){this.axisFormat=t}setTickInterval(t){this.tickInterval=t}setTodayMarker(t){this.todayMarker=t}setIncludes(t){this.includes=gE(this.includes,t)}setExcludes(t){this.excludes=gE(this.excludes,t)}setWeekday(t){this.weekday=t}setWeekend(t){this.weekend=t}setDiagramTitle(t){this.title=t}setAccTitle(t){this.accTitle=t.replace(/^\s+/g,"")}setAccDescription(t){this.accDescr=t.replace(/\n\s+/g,` +`)}addSection(t){this.currentSection=t,this.sections.push(t)}addTask(t,n){let r=(n.startsWith(":")?n.slice(1):n).split(","),i={id:"",task:t,section:this.currentSection,startTime:void 0,endTime:void 0,renderEndTime:null,manualEndTime:!1,processed:!1,active:!1,done:!1,crit:!1,milestone:!1,vert:!1,order:-1,classes:[],prevTaskId:this.lastTaskId,raw:{data:n,start:void 0,end:""}},s;for(;r.length>0&&(s=DC.exec(r[0]))!==null;)i[s[1]]=!0,r.shift();if(r.length===0)throw new Qe(`Task "${t.trim()}" needs a duration or an end date.`,"semantic",{type:"gantt"});if(r.length>3)throw new Qe(`Task "${t.trim()}" has too many fields. A task takes an id, a start, and an end or duration.`,"semantic",{type:"gantt"});for(let a=0;a1&&(i.raw.start=r[r.length-2]),i.raw.end=r[r.length-1],i.vert||(i.order=this.lastOrder++),this.tasks.push(i),this.lastTaskId=i.id,this.byId.set(i.id,i)}setLink(t,n){let r=Qn(n);for(let i of t.split(","))this.byId.has(i)&&this.links.set(i,r);this.setClass(t,"clickable")}setClickEvent(t,n,r){this.setClass(t,"clickable")}setClass(t,n){for(let r of t.split(","))this.byId.get(r)?.classes.push(n)}getTasks(t){this.now=dh(t),this.work=0,this.includeSet=new Set(this.includes),this.excludeSet=new Set(this.excludes);let n=this.weekend==="friday"?5:this.weekend==="saturday"?6:NaN,r=this.excludeSet.has("weekends");this.excludedDays=Jr.map((s,a)=>{let o=a||7;return r&&(o===n||o===n+1)||this.excludeSet.has(s.toLowerCase())}),this.datedTokens=this.includes.length>0||!OC.test(this.dateFormat.trim());for(let s of this.excludes)s!=="weekends"&&!UC.has(s)&&(this.datedTokens=!0);for(let s of this.tasks)s.startTime=s.endTime=void 0,s.renderEndTime=null,s.processed=s.manualEndTime=!1;let i=this.compileTasks();for(let s=0;!i&&s<10;s++)i=this.compileTasks();return this.tasks}isInvalidDate(t){let n=this.excludedDays[t.getDay()];if(!this.datedTokens)return n;let r=this.dateFormat.trim(),i=lh(t),s=i;this.spend(HC),r!=="YYYY-MM-DD"&&(this.spend(KC+r.length*8),s=ch(t,r));let a=o=>o.has(i)||s!==void 0&&o.has(s);return a(this.includeSet)?!1:n||a(this.excludeSet)}spend(t){if(this.work+=t,this.work>GC)throw new Qe("The gantt chart takes too much work to schedule.","limit",{type:"gantt"})}parse(t,n){return this.spend((n.length+1)*(t.length+1)),mE(t,n,new Date(this.now))}today(){let t=new Date(this.now);return t.setHours(0,0,0,0),t}warn(t){this.options.warn&&this.options.warn(t())}compileTasks(){let t=!0;for(let n of this.tasks)this.compileTask(n),t=t&&n.processed;return t}compileTask(t){let n=t.raw.start;if(n===void 0){let r=t.prevTaskId===void 0?void 0:this.byId.get(t.prevTaskId);t.startTime=r?r.endTime:this.today()}else{let r=this.getStartDate(n);r&&(t.startTime=r)}t.startTime&&(t.endTime=this.getEndDate(t.startTime,t.raw.end),t.endTime&&(t.processed=!0,t.manualEndTime=this.parse(t.raw.end,"YYYY-MM-DD")!==void 0,this.checkTaskDates(t)))}references(t,n){let r=[],i;for(let s of n.split(" ")){if(s==="")continue;let a=this.byId.get(s);a?r.push(a):(i??=[]).push(s)}if(i){let s=i;this.warn(()=>`Gantt: "${t}" refers to task ids that do not exist: ${s.join(", ")}.`)}return r}getStartDate(t){let n=t.trim(),r=this.dateFormat.trim();if((r==="x"||r==="X")&&WC.test(n))return this.checked(new Date(Number(n)),n);let i=vC.exec(n);if(i!==null){let o=this.references("after",i[1]),c;for(let l of o)(!c||l.endTime>c.endTime)&&(c=l);return c?c.endTime:this.today()}let s=this.parse(n,r);if(s)return s;let a=new Date(n);if(!eo(a)||a.getFullYear()<-1e4||a.getFullYear()>1e4)throw new Qe("Invalid date:"+n,"semantic",{type:"gantt"});return a}checked(t,n){if(!eo(t))throw new Qe("Invalid date:"+n,"semantic",{type:"gantt"});return t}getEndDate(t,n){let r=n.trim(),i=PC.exec(r);if(i!==null){let u=this.references("until",i[1]),h;for(let d of u)(!h||d.startTime`Gantt: "${r}" is neither a date in the "${s}" format nor a duration such as "3d", so the task gets no duration.`),new Date(t);let l=xl(t,o,c);return eo(l)?l:new Date(t)}checkTaskDates(t){if(this.excludes.length===0||t.manualEndTime)return;let n=Pr(t.startTime,1),r=new Date(t.endTime),i=+Pr(r,1e4),s=!1,a=null;for(;+n<=+r;){if(this.spend(YC),s||(a=+r),s=this.isInvalidDate(n),s&&(r.setDate(r.getDate()+1),+r>i))throw new Qe("Failed to find a valid date that was not excluded by `excludes` after 10,000 iterations.","semantic",{type:"gantt"});n.setDate(n.getDate()+1)}t.endTime=r,t.renderEndTime=a===null?null:new Date(a)}};var bE=["$end","INVALID","open_directive","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","NL","href","callbackname","callbackargs","click","gantt","dateFormat","inclusiveEndDates","topAxis","axisFormat","tickInterval","includes","excludes","todayMarker","weekday_monday","weekday_tuesday","weekday_wednesday","weekday_thursday","weekday_friday","weekday_saturday","weekday_sunday","weekend_friday","weekend_saturday","date","title","accDescription","section","taskTxt","taskData",":","EOF"];var VC=/accTitle\s*:\s*/iy,jC=/accDescr\s*:\s*/iy,XC=/accDescr\s*\{\s*/iy,qC=/href\s+"/iy,QC=/call\s+/iy,ZC=/click\s+/iy,JC=/\(\s*\)/y,uh=/weekday\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday)\b/iy,eN=["monday","tuesday","wednesday","thursday","friday","saturday","sunday"],fh=/weekend\s+(?:(friday)|saturday)\b/iy,tN=/\d\d\d\d-\d\d-\d\d\b/y,nN=/title[^\S\r\n]*(?=[\r\n]|$)/iy,rN=new Map([[97,[[/axisFormat\s[^#\n;]+/iy,17],[/accDescription\s[^#\n;]+/iy,33]]],[103,[[/gantt\b/iy,13]]],[100,[[/dateFormat\s[^#\n;]+/iy,14]]],[105,[[/inclusiveEndDates\b/iy,15],[/includes\s[^#\n;]+/iy,19]]],[116,[[/topAxis\b/iy,16],[/tickInterval\s[^#\n;]+/iy,18],[/todayMarker\s[^\n;]+/iy,21],[/title[^\S\r\n][^\n]+/iy,32]]],[101,[[/excludes\s[^#\n;]+/iy,20]]],[115,[[/section\s[^\n]+/iy,34]]]]);function yE(e){let t=e.length,n=[],r=[],i=[],s=0,a=0,o=(h,d,m)=>{n.push(h),r.push(e.slice(d,m)),i.push(d),a=m},c=h=>(h.lastIndex=a,h.test(e)?h.lastIndex:-1),l=(h,d)=>{let m=e.indexOf(h,d);return m===-1?t:m},u=h=>{let d;switch(h|32){case 97:if((d=c(VC))>=0)return s=1,o(3,a,d),!0;if((d=c(jC))>=0)return s=2,o(5,a,d),!0;if((d=c(XC))>=0)return s=3,a=d,!0;break;case 104:if((d=c(qC))>=0)return s=4,a=d,!0;break;case 99:if((d=c(QC))>=0)return s=5,a=d,!0;if((d=c(ZC))>=0)return s=7,a=d,!0;break;case 116:if((d=c(nN))>=0)return a=d,!0;break;case 119:{uh.lastIndex=a;let p=uh.exec(e);if(p)return o(22+eN.indexOf(p[1].toLowerCase()),a,uh.lastIndex),!0;if(fh.lastIndex=a,p=fh.exec(e),p)return o(p[1]!==void 0?29:30,a,fh.lastIndex),!0;break}}let m=rN.get(h|32);if(m){for(let[p,y]of m)if((d=c(p))>=0)return o(y,a,d),!0}return!1};for(;;){if(a>=t){let d=38;switch(s){case 1:d=4;break;case 2:d=6;break;case 3:d=7;break;case 4:d=9;break;case 5:d=10;break;case 6:d=11;break;case 7:d=12;break}o(d,t,t);break}let h=e.charCodeAt(a);switch(s){case 0:{let d=e.charCodeAt(a+1);if(h===37)if(d!==37){let m=l(` +`,a+1);for(;e.charCodeAt(m)===10;)m++;a=m}else{if(e.charCodeAt(a+2)===123)return o(2,a,a+3),o(1,a,a),{types:n,texts:r,starts:i};a=l(` +`,a+2)}else if(h===10){let m=a+1;for(;e.charCodeAt(m)===10;)m++;o(8,a,m)}else if(qe(h))for(a++;a=48&&h<=57&&c(tN)>=0)o(31,a,a+10);else if(h!==58){let m=a+1;for(;ma+1?36:37,a,m)}}break}case 1:case 2:{let d=s===1?4:6;s=0,o(d,a,l(` +`,a));break}case 3:h===125?(s=0,a++):o(7,a,l("}",a));break;case 4:h===34?(s=0,a++):o(9,a,l('"',a));break;case 5:if(h===40){let d=c(JC);d>=0?(s=0,a=d):(s=6,a++)}else o(10,a,l("(",a));break;case 6:h===41?(s=0,a++):o(11,a,l(")",a));break;case 7:if(qe(h))s=0,a++;else{let d=a+1;for(;d{let l=n[s];throw ft("gantt",e,i[s],`Expecting ${c}, got '${l===0?"1":bE[l]}'`)},o=(c="")=>{Sl[n[s]]!==1&&a(EE+c)};for(n[s]!==13&&a("'gantt'"),s++;;){let c=n[s],l=r[s];switch(Sl[c]!==1&&a(EE),s++,c){case 38:if(n[s]===0)return;o();break;case 8:break;case 14:o(),t.setDateFormat(l.slice(11));break;case 15:o(),t.enableInclusiveEndDates();break;case 16:o(),t.TopAxis();break;case 17:o(),t.setAxisFormat(l.slice(11));break;case 18:o(),t.setTickInterval(l.slice(13));break;case 20:o(),t.setExcludes(l.slice(9));break;case 19:o(),t.setIncludes(l.slice(9));break;case 21:o(),t.setTodayMarker(l.slice(12));break;case 29:o(),t.setWeekend("friday");break;case 30:o(),t.setWeekend("saturday");break;case 32:o(),t.setDiagramTitle(l.slice(6));break;case 3:{n[s]!==4&&a("'acc_title_value'");let u=r[s++];o(),t.setAccTitle(u.trim());break}case 5:{n[s]!==6&&a("'acc_descr_value'");let u=r[s++];o(),t.setAccDescription(u.trim());break}case 7:o(),t.setAccDescription(l.trim());break;case 34:o(),t.addSection(l.slice(8));break;case 35:{n[s]!==36&&a("'taskData'");let u=r[s++];o(),t.addTask(l,u);break}case 12:{let u,h=null,d;n[s]===10?(u=r[s++],n[s]===11&&(h=r[s++]),n[s]===9?(d=r[s++],o()):o(h===null?", 'callbackargs', 'href'":", 'href'")):n[s]===9?(d=r[s++],n[s]===10?(u=r[s++],n[s]===11?(h=r[s++],o()):o(", 'callbackargs'")):o(", 'callbackname'")):a("'callbackname', 'href'"),u!==void 0&&t.setClickEvent(l,u,h),d!==void 0&&t.setLink(l,d);break}default:o(),t.setWeekday(sN[c-22])}}}var es=1e3,ts=60*es,ii=60*ts,oi=24*ii,xa=7*oi,ph=30*oi,Rl=365*oi;function wl(e){e.setHours(0,0,0,0)}function Ml(e){return{floor(t){t.setDate(t.getDate()-(t.getDay()+7-e)%7),wl(t)},offset:(t,n)=>t.setDate(t.getDate()+n*7),cycle:1/0,ms:xa}}var ya={millisecond:{floor:()=>{},offset:(e,t)=>e.setTime(+e+t),cycle:1/0,ms:1},second:{floor:e=>e.setTime(+e-e.getMilliseconds()),offset:(e,t)=>e.setTime(+e+t*es),field:e=>e.getUTCSeconds(),cycle:60,ms:es},minute:{floor:e=>e.setTime(+e-e.getMilliseconds()-e.getSeconds()*es),offset:(e,t)=>e.setTime(+e+t*ts),field:e=>e.getMinutes(),cycle:60,ms:ts},hour:{floor:e=>e.setTime(+e-e.getMilliseconds()-e.getSeconds()*es-e.getMinutes()*ts),offset:(e,t)=>e.setTime(+e+t*ii),field:e=>e.getHours(),cycle:24,ms:ii},day:{floor:wl,offset:(e,t)=>e.setDate(e.getDate()+t),field:e=>e.getDate()-1,cycle:31,ms:oi},month:{floor(e){e.setDate(1),wl(e)},offset:(e,t)=>e.setMonth(e.getMonth()+t),field:e=>e.getMonth(),cycle:12,ms:ph},year:{floor(e){e.setMonth(0,1),wl(e)},offset:(e,t)=>e.setFullYear(e.getFullYear()+t),cycle:1/0,ms:Rl}};function Tl(e,t,n){return Math.floor((+t-+e-(t.getTimezoneOffset()-e.getTimezoneOffset())*ts)/n)}function iN(e,t){return(e%t+t)%t}function _l(e,t,n){let r=e==="week"?Ml(n):ya[e];if(t<=1)return r;if(e==="millisecond")return{...r,floor:a=>a.setTime(Math.floor(+a/t)*t),offset:(a,o)=>a.setTime(+a+o*t)};if(e==="year")return{...r,floor(a){a.setFullYear(Math.floor(a.getFullYear()/t)*t),r.floor(a)},offset:(a,o)=>a.setFullYear(a.getFullYear()+o*t)};if(e==="week"){let a=new Date(0);return r.floor(a),{...r,floor(o){r.floor(o),r.offset(o,-iN(Tl(a,o,xa),t))},offset:(o,c)=>r.offset(o,c*t)}}let i=r.field,s=a=>i(a)%t===0;return{...r,floor(a){for(r.floor(a);Number.isFinite(+a)&&!s(a);r.floor(a))a.setTime(+a-1)},offset(a,o){for(let c=0;ca;){if(s.length>=r)return;a=+i,s.push(a),e.offset(i,1),e.floor(i)}return s}function AE(e,t,n){let r=(t-e)/Math.max(0,n),i=Math.floor(Math.log10(r)),s=r/Math.pow(10,i),a=s>=Math.sqrt(50)?10:s>=Math.sqrt(10)?5:s>=Math.SQRT2?2:1;return Math.pow(10,i)*a}var to=[["second",1,es],["second",5,5*es],["second",15,15*es],["second",30,30*es],["minute",1,ts],["minute",5,5*ts],["minute",15,15*ts],["minute",30,30*ts],["hour",1,ii],["hour",3,3*ii],["hour",6,6*ii],["hour",12,12*ii],["day",1,oi],["day",2,2*oi],["week",1,xa],["month",1,ph],["month",3,3*ph],["year",1,Rl]];function _E(e,t,n){let r=(t-e)/n,i=0;for(;ii))return wE(c,n,r,i)}function hn(e,t,n){let r=e<0?"-":"",i=String(r?-e:e);return r+(i.length=4||n===0?e:new Date(+e-1),t);return n>=4||n===0||(t.offset(r,1),t.floor(r)),r}var cN=new Map([["-",""],["_"," "],["0","0"]]);function Ea(e,t){let n="",r=0,i=e.length;for(let s=0;s=12?"PM":"AM";case"q":return String(1+Math.floor(t.getMonth()/3));case"Q":return String(+t);case"s":return String(Math.floor(+t/1e3));case"S":return hn(t.getSeconds(),n,2);case"u":return String(t.getDay()||7);case"U":return hn(SE(t,0),n,2);case"V":{let r=hh(t),i=Ss(r,ya.year),s=Ss(i,Ml(4));return hn(Tl(s,r,xa)+(i.getDay()===4?1:0),n,2)}case"w":return String(t.getDay());case"W":return hn(SE(t,1),n,2);case"x":return Ea("%-m/%-d/%Y",t);case"X":return Ea("%-I:%M:%S %p",t);case"y":return hn(t.getFullYear()%100,n,2);case"Y":return hn(t.getFullYear()%1e4,n,4);case"Z":{let r=t.getTimezoneOffset(),i=Math.abs(r);return(r>0?"-":"+")+hn(Math.floor(i/60),"0",2)+hn(i%60,"0",2)}case"%":return"%";default:return e}}var dN=800,uN=240,no=8,fN=//gi;function Fr(e,t,n,r){let i=e.gantt?.[t];return typeof i=="number"&&Number.isFinite(i)?Math.min(r,Math.max(n,i)):void 0}function mh(e,t){let n=e.gantt?.[t];return typeof n=="string"?n:void 0}function hN(e,t){return e.gantt?.[t]===!0}function TE(e,t,n){let r=Ge(e.replace(fN," "),!1,t,n,4e3);return r.lines.length<=1?r:{...r,lines:[r.lines[0]],widths:[r.widths[0]],width:r.widths[0],height:r.lineHeight}}function Cl(e){return Number.isFinite(+e.startTime)&&Number.isFinite(+e.endTime)}function pN(e,t,n){let r=e.filter(Cl).sort((a,o)=>+a.startTime-+o.startTime||a.order-o.order),i=[];for(let a of r){let o=+a.startTime,c=0;for(;c!ye.vert),S=E.filter(ye=>ye.vert&&Cl(ye)),x=new Map;for(let ye of b)x.has(ye.section)||x.set(ye.section,x.size);let I=new Map,L=[];if(p){let ye=new Map;for(let we of b){let Ie=ye.get(we.section);Ie?Ie.push(we):ye.set(we.section,[we])}for(let[we,Ie]of ye){let ve=pN(Ie,L.length,I);for(let Pe=0;Pe0?C.height+16:0;if(!K){let ye=Math.ceil(Math.max(C.width,1)+2*s),we=Math.ceil(Math.max(C.height,1)+2*s),Ie=Ne(C,ye/2,s+C.height/2,' class="pele-title" font-weight="var(--_tw)"');return{svg:at("gantt",ye,we,r,n,e,Ie),width:ye,height:we,links:[]}}let oe=new Map,H=0;for(let ye of x.keys()){let we=Ge(ye,!1,i,c,180);oe.set(ye,we),H=Math.max(H,we.width)}let z=e.axisFormat||(e.dateFormat==="D"?"%d":mh(t,"axisFormat")??"%Y-%m-%d"),M=ye=>Ea(z,new Date(ye)),T=Math.max(i.width(M(v),l,0),i.width(M(G),l,0)),R=s+(Fr(t,"leftPadding",0,2e3)??Math.max(H>0?H+24:0,T/2)),_=Fr(t,"rightPadding",0,2e3)??Math.max(16,T/2),$=gs(n,Fr(t,"useWidth",100,2e4)??dN,280),g=Math.max(uN,$-R-_-s),N=R+g,w=G>v?g/(G-v):0,A=ye=>w===0?R+g/2:R+(ye-v)*w,D=Math.round(l*1.75),U=Fr(t,"topPadding",0,2e3),B=Fr(t,"gridLineStartPadding",0,2e3),F=s+Z+(y?D:0),W=Math.max(F,U??0),j=U!==void 0&&B!==void 0?Math.max(0,Math.min(U-B,W-F)):0,Q=Math.max(O,1)*d,Y=W+Q,ne=[],q=N+_;for(let ye of b){let we=TE(ye.task,i,o),Ie=I.get(ye);if(!Cl(ye)){let Be=R+no+we.width/2;q=Math.max(q,Be+we.width/2),ne.push({task:ye,label:we,row:Ie,x0:NaN,x1:NaN,labelX:Be,inside:!1});continue}let ve=A(+ye.startTime),Pe=Math.max(A(+(ye.renderEndTime??ye.endTime)),ve+(ye.milestone?0:2));if(ye.milestone){let Be=ve+(A(+ye.endTime)-ve)/2;ve=Be-u/2,Pe=Be+u/2}let he=!ye.milestone&&we.width+2*no<=Pe-ve,Re=(ve+Pe)/2;if(!he){let Be=Pe+no+we.width<=N+_,ge=ve-no-we.width>=R;Re=Be||!ge?Pe+no+we.width/2:ve-no-we.width/2,q=Math.max(q,Re+we.width/2)}ne.push({task:ye,label:we,row:Ie,x0:ve,x1:Pe,labelX:Re,inside:he})}let k=e.tickInterval||mh(t,"tickInterval")||"",J=e.weekday??mh(t,"weekday")??"sunday",te=Math.max(2,Math.min(10,Math.floor(g/(T+24)))),se=RE(k,J,v,G,Math.ceil(g/3))??_E(v,G,te),re="",P="",ee="",ae=-1/0,ue="",ce=Y+D/2+2,pe=W-j-D/2-2;for(let ye of se){let we=A(ye);re+=`M${f(we)},${f(W-j)}V${f(Y)}`;let Ie=M(ye),ve=i.width(Ie,l,0);if(we-ve/2${rt(Ie)}`;P+=`+we.startTime-+Ie.startTime)){let we=A(+ye.startTime),Ie=TE(ye.task,i,o),ve=Math.max(s+Ie.width/2,we),Pe=0;for(;Pe`,X+=Ne(Ie,ve,de+Pe*Se+Se/2,` class="pele-vert-label" data-id="${Ue(ye.id)}"`)}let _e=Math.ceil(Math.max(q,s+C.width)+s),xe=Math.ceil(Y+D+(le.length>0?4+le.length*Se:0)+s),Me="",Ce="";for(let ye=0;ye1||we!=="")&&(Me+=``);let Re=oe.get(we);Ce+=Ne(Re,s+8+Re.width/2,Pe+he/2,` class="pele-section-label" data-id="${Ue(we)}"`,n.icons),ye=Ie}let ke="";if((e.excludes.length>0||e.includes.length>0)&&+xl(new Date(v),6,"y")>G){let ye,we,Ie=()=>{if(!ye||!we)return;let ve=new Date(ye);ve.setHours(0,0,0,0);let Pe=new Date(we);Pe.setHours(23,59,59,999);let he=Math.max(R,A(+ve)),Re=Math.min(N,A(+Pe));Re>he&&(ke+=``),ye=we=void 0};for(let ve=new Date(v);+ve<=G;ve=Pr(ve,1))e.isInvalidDate(ve)?(ye??=ve,we=ve):Ie();Ie()}let be=[],Ae="";for(let ye of ne){let we=ye.task,Ie=W+ye.row*d+d/2,ve=we.active?"active":we.done?"done":"",Pe="pele-task";ve&&(Pe+=" pele-"+ve),we.crit&&(Pe+=" pele-crit"),we.milestone&&(Pe+=" pele-milestone"),we.classes.includes("clickable")&&(Pe+=" pele-clickable");let he="",Re="";if(Number.isNaN(ye.x0))Pe+=" pele-unscheduled",Re=' fill="var(--_m)"';else{let Le=we.crit?Yo:"var(--_c)",Fe=ve==="done"?'fill="var(--_a)"':ve==="active"?`fill="${Le}" fill-opacity="0.25"`:`fill="${Le}"`,Ve=`stroke="${ve==="done"&&!we.crit?"var(--_b)":Le}"`;if(we.milestone){let Oe=(ye.x0+ye.x1)/2,je=u/2;he=``}else he=``;ye.inside?Re=ve===""?' fill="var(--_bg)"':"":ve==="done"&&(Re=' fill="var(--_m)"')}let Be=he+Ne(ye.label,ye.labelX,Ie,` class="pele-label"${Re}`),ge=e.links.get(we.id);ge!==void 0&&(Be=Zn(Be,ge,we.id,be,n)),Ae+=`${Be}`}let ie="";if(e.todayMarker!=="off"&&a>=v&&a<=G&&G>v){let ye=A(a),we=W-j,Ie=e.todayMarker?Ct(e.todayMarker.split(",")).line:"";ie=``+(Ie?"":``)+""}let me=`M${f(R)},${f(Y)}H${f(N)}`+(y?`M${f(R)},${f(W-j)}H${f(N)}`:""),Te=Ne(C,_e/2,s+C.height/2,' class="pele-title" font-weight="var(--_tw)"')+(Me?`${Me}`:"")+(ke?`${ke}`:"")+``+(V?`${V}`:"")+ie+`${Ae}${P}${ee}`+(X?`${X}`:"");return{svg:at("gantt",_e,xe,r,n,e,Te),width:_e,height:xe,links:be}}var CE={type:"gantt",parse(e,t,n){let r=new Al;n&&(r.title=n);let i=t.gantt?.displayMode;return typeof i=="string"&&(r.displayMode=i),xE(e,r),r},render:ME};var tn={NORMAL:0,REVERSE:1,HIGHLIGHT:2,MERGE:3,CHERRY_PICK:4};function Bn(e){throw new Qe(e,"semantic",{type:"gitGraph"})}function NE(e){return e==="REVERSE"?tn.REVERSE:e==="HIGHLIGHT"?tn.HIGHLIGHT:tn.NORMAL}function mN(e,t){e.dir&&t.setDirection(e.dir);for(let n of e.statements)gN(n,t)}function gN(e,t){switch(e.$type){case"Commit":t.commit({id:e.id,msg:e.message??"",type:e.type!==void 0?NE(e.type):tn.NORMAL,tags:e.tags??void 0});break;case"Branch":t.branch({name:e.name,order:e.order??0});break;case"Merge":t.merge({branch:e.branch,id:e.id??"",type:e.type!==void 0?NE(e.type):void 0,tags:e.tags??void 0});break;case"Checkout":t.checkout(e.branch);break;case"CherryPicking":t.cherryPick({id:e.id,targetId:"",tags:e.tags?.length===0?void 0:e.tags,parent:e.parent});break}}function IE(e,t,n){let r=t.gitGraph,i=typeof r?.mainBranchName=="string"?r.mainBranchName:"main",s=typeof r?.mainBranchOrder=="number"?r.mainBranchOrder:0,a=new Map,o=new Map([[i,null]]),c=new Map([[i,s]]),l=[],u=null,h=i,d="LR",m=0,p=()=>{for(let S=m+1;;S+=2654435761){let x=`${m}-${(Math.imul(S,2654435761)>>>0).toString(16).padStart(8,"0").slice(0,7)}`;if(!a.has(x))return x}},y=S=>{u=S,a.set(S.id,S),o.set(h,S.id)},E=S=>{o.has(S)||Bn(`Trying to checkout branch which is not yet created. (Help try using "branch ${S}")`),h=S;let x=o.get(S);u=x?a.get(x)??null:null};mN(e,{setDirection(S){d=S},commit({msg:S,id:x,type:I,tags:L}){let O={id:x||p(),message:S,seq:m++,type:I??tn.NORMAL,tags:L?[...L]:[],parents:u===null?[]:[u.id],branch:h};a.has(O.id)&&l.push(`Commit ID ${O.id} already exists`),y(O)},branch({name:S,order:x}){o.has(S)&&Bn(`Trying to create an existing branch. (Help: Either use a new name if you want create a new branch or try using "checkout ${S}")`),o.set(S,u!==null?u.id:null),c.set(S,x),E(S)},merge({branch:S,id:x,type:I,tags:L}){let O=o.get(h),v=o.get(S),G=O?a.get(O):void 0,K=v?a.get(v):void 0;G&&K&&G.branch===S&&Bn(`Cannot merge branch '${S}' into itself.`),h===S&&Bn('Incorrect usage of "merge". Cannot merge a branch to itself'),G===void 0&&Bn(`Incorrect usage of "merge". Current branch (${h})has no commits`),o.has(S)||Bn(`Incorrect usage of "merge". Branch to be merged (${S}) does not exist`),K===void 0&&Bn(`Incorrect usage of "merge". Branch to be merged (${S}) has no commits`),G===K&&Bn('Incorrect usage of "merge". Both branches have same head'),x&&a.has(x)&&Bn(`Incorrect usage of "merge". Commit with id:${x} already exists, use different custom id`),y({id:x||p(),message:`merged branch ${S} into ${h}`,seq:m++,parents:u===null?[]:[u.id,v||""],branch:h,type:tn.MERGE,customType:I,customId:!!x,tags:L?[...L]:[]})},cherryPick({id:S,targetId:x,tags:I,parent:L}){let O=S?a.get(S):void 0;if(O===void 0&&Bn('Incorrect usage of "cherryPick". Source commit id should exist and provided'),L&&!O.parents.includes(L)&&Bn("Invalid operation: The specified parent commit is not an immediate parent of the cherry-picked commit."),O.type===tn.MERGE&&!L&&Bn("Incorrect usage of cherry-pick: If the source commit is a merge commit, an immediate parent commit must be specified."),x&&a.has(x))return;O.branch===h&&Bn('Incorrect usage of "cherryPick". Source commit is already on current branch');let v=o.get(h);(!v||!a.has(v))&&Bn(`Incorrect usage of "cherry-pick". Current branch (${h})has no commits`),y({id:p(),message:`cherry-picked ${O.message} into ${h}`,seq:m++,parents:u===null?[]:[u.id,O.id],branch:h,type:tn.CHERRY_PICK,tags:I?I.filter(Boolean):[`cherry-pick:${O.id}${O.type===tn.MERGE?`|parent:${L}`:""}`]})},checkout:E});let b=[...c].map(([S,x],I)=>({name:S,order:x??parseFloat(`0.${I}`)})).sort((S,x)=>S.order-x.order).map(S=>S.name);return{type:"gitGraph",title:e.title||n,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,` +`):void 0,direction:d,commits:a,branches:o,lanes:b,currentBranch:h,head:u,warnings:l}}var $E={name:"REFERENCE",pattern:/\w([-\./\w]*[-\w])?/y},LE=[$E];function tr(e){return{name:e,pattern:e,longer:LE}}var kE=[tr("cherry-pick"),{name:"gitGraph:",pattern:"gitGraph:"},tr("HIGHLIGHT"),{...Jt("gitGraph"),longer:LE},tr("checkout"),tr("REVERSE"),{name:"parent:",pattern:"parent:"},tr("commit"),tr("NORMAL"),tr("branch"),{name:"order:",pattern:"order:"},tr("switch"),{name:"type:",pattern:"type:"},tr("merge"),{name:"msg:",pattern:"msg:"},{name:"tag:",pattern:"tag:"},{name:"id:",pattern:"id:"},tr("LR"),tr("TB"),tr("BT"),{name:":",pattern:":"},{...sn,opener:/[\t ]*accDescr\s*{/y},Xt,er(String.raw`[-./\w]*[-\w]`),{name:"INT",pattern:/0|[1-9][0-9]*(?!\.)/y},Fn,Sn,wn,Ht,Qt,Zt,$E];function OE(e){let t=new Ut(Yt(e,kE,"gitGraph"),kE,"gitGraph"),n={$type:"GitGraph",statements:[]},r=()=>{if(t.kind!==-1)for(t.kind!==26&&t.fail("a line break or the end of input");t.kind===26;)t.i++},i=()=>t.kind===31?t.take():t.kind===25?un(t.take()):t.fail("a branch name"),s=()=>un(t.expect(25)),a=()=>(t.kind!==8&&t.kind!==5&&t.kind!==2&&t.fail("NORMAL, REVERSE, or HIGHLIGHT"),t.take());for(;t.kind===26;)t.i++;if(!t.accept(1)){t.expect(3);let o=t.kinds[t.i+1];(t.kind===17||t.kind===18||t.kind===19)&&o===20?(n.$type="Direction",n.dir=t.take(),t.i++):t.accept(20)}for(;t.kind!==-1;)switch(t.kind){case 26:t.i++;break;case 21:n.accDescr=Vt(t.take()),r();break;case 22:n.accTitle=zt(t.take()),r();break;case 23:n.title=Kt(t.take()),r();break;case 7:{t.i++;let o={$type:"Commit",tags:[]};for(;;)if(t.accept(16))o.id=s();else if(t.accept(15))o.tags.push(s());else if(t.accept(12))o.type=a();else if(t.accept(14)||t.kinds[t.i]===25)o.message=s();else break;r(),n.statements.push(o);break}case 9:{t.i++;let o={$type:"Branch",name:i()};t.accept(10)&&(o.order=parseInt(t.expect(24))),r(),n.statements.push(o);break}case 13:{t.i++;let o={$type:"Merge",branch:i(),tags:[]};for(;;)if(t.accept(16))o.id=s();else if(t.accept(15))o.tags.push(s());else if(t.accept(12))o.type=a();else break;r(),n.statements.push(o);break}case 4:case 11:{t.i++;let o={$type:"Checkout",branch:i()};r(),n.statements.push(o);break}case 0:{t.i++;let o={$type:"CherryPicking",tags:[]};for(;;)if(t.accept(16))o.id=s();else if(t.accept(15))o.tags.push(s());else if(t.accept(6))o.parent=s();else break;r(),n.statements.push(o);break}default:t.fail("a statement, a title, or a line break")}return n}var bN=/<(?!br\s*\/?>)/gi,yN=/:fa-/g,EN=/|fl°°?\w+¶ß|&#?\w+;|[\ud800-\udbff][\udc00-\udfff]|[\s\S]/gi;function br(e,t,n,r,i=0){let s=e;return s!==void 0&&(s.includes("<")&&(s=s.replace(bN,"<")),s.includes(":fa-")&&(s=s.replace(yN,":fa-"))),Ge(s,!1,t,n,r,i)}function Wn(e,t,n,r,i=0){let s=br(e,t,n,r,i);if(e===void 0||s.width<=r)return s;let a="",o=0;for(let c of e.match(EN)??[]){if(c.trim()===""||c.length>2&&c[0]==="<")o=0;else{let l=t.width(c.length>2?"x":c,n,i);o>0&&o+l>r&&(a+=` +`,o=0),o+=l}a+=c}return br(a,t,n,r,i)}var nn=7,xN=44,AN=44,Nl=36,Il=8,ai=20,Aa=20,Sa=7,DE=6,gh=Math.SQRT1_2,vE=["normal","reverse","highlight","merge","cherry-pick"];function kl(e,t,n){let r=e.gitGraph?.[t];return typeof r=="boolean"?r:n}function PE(e){return Sa+4+e.width+6}function SN(e,t,n,r){let i=`cx="${f(t)}" cy="${f(n)}"`;if(e===tn.HIGHLIGHT)return``;if(e===tn.MERGE)return``;let s=``;return e===tn.REVERSE?s+``:e===tn.CHERRY_PICK?s+``:s}function BE(e,t,n){return e.direction!=="LR"?FE(e,t,n,e.direction):Pt(n,r=>FE(e,t,n,r?"TB":"LR"))}function FE(e,t,n,r){let i=n.fontSize??16,s=Math.round(i*.75),a=n.measurer??ct(n.fontFamily,n.fontFamilyMono),o=n.padding??8,c=kl(t,"showBranches",!0),l=kl(t,"showCommitLabel",!0),u=kl(t,"rotateCommitLabel",!0),h=kl(t,"parallelCommits",!1),d=r!=="LR",m=r==="BT",p=new Map;e.lanes.forEach((k,J)=>p.set(k,J));let y=e.lanes.length,E=Math.round(i*.875),b=e.lanes.map(k=>br(c?k:"",a,E,4e3)),S=[],x=new Map;for(let k of[...e.commits.values()].sort((J,te)=>J.seq-te.seq)){let J=l&&k.type!==tn.CHERRY_PICK&&(k.type!==tn.MERGE||k.customId===!0),te=[];for(let re of k.tags){let P=br(re,a,s,4e3);P.lines.length>0&&te.push(P)}let se={commit:k,index:S.length,lane:p.get(k.branch)??0,m:0,label:J?br(k.id,a,s,4e3):void 0,tags:te};S.push(se),x.set(k.id,se)}let I=new Float64Array(S.length),L=new Float64Array(S.length),O=new Float64Array(y).fill(nn),v=new Float64Array(y).fill(nn);S.forEach((k,J)=>{let{label:te,tags:se}=k,re=0,P=0;for(let V of se){let X=PE(V);d?(re=Math.max(re,V.height),P+=X+4):(re=Math.max(re,X),P+=V.height+3)}let ee=0,ae=0;te!==void 0&&te.lines.length>0&&(u?ae=3+gh*(te.width+te.height):(ee=d?te.height:te.width,ae=6+(d?te.width:te.height))),I[J]=Math.max(nn,re/2,ee/2),L[J]=re/2;let ue=nn+(se.length>0?DE+P:0),ce=nn+ae,pe=k.lane;O[pe]=Math.max(O[pe],d?ce:ue),v[pe]=Math.max(v[pe],d?ue:ce)});let G=new Float64Array(S.length);d||S.forEach((k,J)=>{if(L[J]!==0)for(let te of k.commit.parents){let se=x.get(te);se!==void 0&&se.laneMath.max(xN,I[k]+I[J]+Il,G[J]>0?I[k]+Nl+G[J]:0);S.forEach((k,J)=>{if(!h){k.m=J===0?0:S[J-1].m+K(J-1,J);return}let te=0;for(let se of k.commit.parents){let re=x.get(se);re===void 0||re.index>=J||(te=Math.max(te,re.m+K(re.index,J)))}k.m=te});let C=0;for(let k of S)C=Math.max(C,k.m);let Z=new Float64Array(y);for(let k=0;k0&&(Z[k]=Z[k-1]+Math.max(AN,v[k-1]+O[k]+Il))}let oe=(k,J)=>d?J:k,H=(k,J)=>d?m?-k:k:J,z=(k,J)=>`${f(oe(k,J))},${f(H(k,J))}`,M=1/0,T=1/0,R=-1/0,_=-1/0,$=(k,J,te,se)=>{kR&&(R=te),se>_&&(_=se)},g="";if(c)for(let k=0;k`,J.lines.length>0&&($(ae-re/2,ue-P/2,ae+re/2,ue+P/2),g+=``+Ne(J,ae,ue,' class="pele-label"'+(fs(k)||' fill="var(--_bg)"'))),g+=""}let N=Array.from({length:y},()=>[]);for(let k of S)N[k.lane].push(k.m);if(h)for(let k of N)k.sort((J,te)=>J-te);let w=(k,J,te)=>{let se=N[k],re=0,P=se.length;for(;re>1;se[ee]<=J?re=ee+1:P=ee}return re`;continue}let ue=re>0&&J.type===tn.MERGE,ce=re>0&&!ue,pe=`M${z(ae,ee)}`;if(se<=ae){let V=(ae+se)/2;pe+=`C${z(V,ee)} ${z(V,te)} ${z(se,te)}`}else if(!ue&&!w(k.lane,ae,se)){let V=Math.min(Nl,se-ae);pe+=`C${z(ae+V/2,ee)} ${z(ae+V/2,te)} ${z(ae+V,te)}L${z(se,te)}`}else{let V=P.laneae?se-G[k.index]:se,X=Math.min(Nl,V-ae),le=ee;(!ue||w(P.lane,ae,se))&&(le=ee>te?te+v[k.lane]+Il/2:te-O[k.lane]-Il/2,X=Math.min(Nl,(V-ae)/2),pe+=`C${z(ae+X/2,ee)} ${z(ae+X/2,le)} ${z(ae+X,le)}`),pe+=`L${z(V-X,le)}C${z(V-X/2,le)} ${z(V-X/2,te)} ${z(V,te)}`,V`}}let U="";for(let k of S){let{commit:J,label:te,tags:se}=k,re=oe(k.m,Z[k.lane]),P=H(k.m,Z[k.lane]),ee=J.customType??J.type;$(re-nn-1,P-nn-1,re+nn+1,P+nn+1);let ue=J.type${Ue(J.message)}`:"";if(ue+=SN(ee,re,P,Et(k.lane)),te!==void 0&&te.lines.length>0){let V=te.width,X=te.height,le=(de,Se)=>``;if(u){let de=gh*X/2,Se=d?re-nn-3-de:re+3,_e=d?P:P+nn+3+de,xe=gh*V+de;$(Se-xe,m?_e-xe:_e-de,Se+de,m?_e+de:_e+xe),ue+=``+le(Se-V/2,_e)+Ne(te,Se-V/2,_e,"")+""}else{let de=d?re-nn-6-V/2:re,Se=d?P:P+nn+6+X/2;$(de-V/2,Se-X/2,de+V/2,Se+X/2),ue+=`${le(de,Se)}${Ne(te,de,Se,"")}`}}let ce=nn+DE;for(let V=d?0:se.length-1;V>=0&&V`+Ne(X,Se+Sa+4+X.width/2,_e,' fill="var(--_fg)"')+""}let pe=J.type===tn.MERGE&&ee!==tn.MERGE?" pele-commit-merge":"";U+=`${ue}`}M>R&&$(0,0,0,0);let B=Ge(e.title,!1,a,i,4e3,1),F=B.height>0?B.height+16:0,W=Math.max(R-M,B.width),j=Math.ceil(W+2*o),Q=Math.ceil(_-T+F+2*o),Y=o-M+(W-(R-M))/2,ne=o+F-T,q=Ne(B,j/2,o+B.height/2,' class="pele-title" font-weight="var(--_tw)"')+``+(g?`${g}`:"")+(A||D?`${A}${D}`:"")+(U?`${U}`:"")+"";return{svg:at("gitGraph",j,Q,i,n,e,q),width:j,height:Q,links:[]}}var WE={type:"gitGraph",parse:(e,t,n)=>IE(OE(e),t,n),render:BE};function UE(e,t){return{type:"info",title:e.title||t,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,` +`):void 0}}var GE=[Jt("showInfo"),Jt("info"),sn,Xt,pr,Sn,wn,Ht,Qt,Zt];function YE(e){let t=new Ut(Yt(e,GE,"info"),GE,"info"),n={$type:"Info"};for(;t.kind===5;)t.i++;for(t.expect(1);t.kind===5;)t.i++;if(t.accept(0))for(;t.kind===5;)t.i++;for(;t.kind!==-1;){let r=t.kind;if(r===2?n.accDescr=Vt(t.take()):r===3?n.accTitle=zt(t.take()):r===4?n.title=Kt(t.take()):t.fail("a title or the end of input"),t.kind===-1)break;for(t.kind!==5&&t.fail("a line break or the end of input");t.kind===5;)t.i++}return n}var HE="1.13.0";function KE(e,t,n){let r=n.fontSize??16,i=n.measurer??ct(n.fontFamily,n.fontFamilyMono),s=n.padding??8,a=Ge(e.title,!1,i,r,4e3,1),o=a.height>0?a.height+8:0,c=Ge(`Pele v${HE}`,!1,i,r,4e3),l=Math.ceil(Math.max(a.width,c.width)+2*s),u=Math.ceil(o+c.height+2*s),h=Ne(a,l/2,s+a.height/2,' class="pele-title" font-weight="var(--_tw)"')+Ne(c,l/2,s+o+c.height/2,' class="pele-version" fill="var(--_m)"');return{svg:at("info",l,u,r,n,e,h),width:l,height:u,links:[]}}var zE={type:"info",parse:(e,t,n)=>UE(YE(e),n),render:KE};var $l=class{constructor(){fe(this,"type","ishikawa");fe(this,"title");fe(this,"root");fe(this,"stack",[]);fe(this,"baseLevel")}addNode(t,n){let r={text:n,children:[]};if(!this.root){this.root=r,this.stack=[{level:0,node:r}];return}this.baseLevel??=t;let i=Math.max(t-this.baseLevel+1,1),s=this.stack;for(;s.length>1&&s[s.length-1].level>=i;)s.pop();s[s.length-1].node.children.push(r),s.push({level:i,node:r})}};var VE=["$end","EOF","SPACELINE","NL","ISHIKAWA","SPACELIST","TEXT"];function _N(e,t){let n="ishikawa-beta",r=0;for(;r<13;){let i=e.charCodeAt(t+r),s=n.charCodeAt(r);if(i!==s&&(i+32!==s||i<65||i>90))break;r++}return r===13&&!ot(e.charCodeAt(t+13))?13:r>=8&&!ot(e.charCodeAt(t+8))?8:0}function jE(e){let t=[],n=[],r=[],i=e.length,s=0;for(;s0?(c=4,l=s+u):(c=6,l=e.indexOf(` +`,s),l===-1&&(l=i))}else o>s?(c=2,l=o+1):o===s?(c=3,l=s+1):(c=5,l=a);t.push(c),n.push(s),r.push(l),s=l}return t.push(1,0),n.push(i,i),r.push(i,i),{types:t,starts:n,ends:r}}var bh="'SPACELINE', 'NL', 'EOF'";function XE(e,t){let{types:n,starts:r,ends:i}=jE(e),s=0,a=o=>{throw ft("ishikawa",e,r[s],`Expecting ${o}, got '${VE[n[s]]}'`)};if(n[s]===2){for(s++;n[s]===2||n[s]===3;)s++;n[s]!==4&&a("'SPACELINE', 'NL', 'ISHIKAWA'")}else n[s]!==4&&a("'SPACELINE', 'ISHIKAWA'");for(s++,n[s]===3&&s++;;){let o=n[s];if(o===6||o===5&&n[s+1]===6){let c=o===6?s:s+1;s=c+1,n[s]!==2&&n[s]!==3&&n[s]!==1&&a(bh),t.addNode(o===6?0:i[c-1]-r[c-1],e.slice(r[c],i[c]).trim())}else o===2||o===5?(s++,n[s]!==2&&n[s]!==3&&n[s]!==1&&a(o===5?`${bh}, 'TEXT'`:bh)):a("'SPACELINE', 'SPACELIST', 'TEXT'");for(s++;n[s]===3||n[s]===1;)s++;if(n[s]===0)return}}var Ol=.5,Ll=Math.hypot(Ol,1),RN=14,TN=6,MN=8,qE=22,CN=18,yh=5,NN=26,QE=34,IN=28,kN=10,$N=5;function LN(e,t,n,r,i){let s=Ge(e.text,!1,n,r,180),a=Math.round(i*1.5),o=[],c=[],l=[],u=(p,y,E)=>{let b=p.length;for(let S=b-1;S>=0;S--)l.push({node:p[t?b-1-S:S],depth:y,parent:E,slot:S,bone:-1})};for(u(e.children,2,-1);l.length>0;){let p=l.pop();if(p.bone!==-1){c.push(p.bone);continue}let y=o.length;o.push({label:Ge(p.node.text,!1,n,i,200),depth:p.depth,parent:p.parent,slot:p.slot,kids:p.node.children.length,rise:0,at:0,textEnd:0}),p.depth%2===0?c.push(y):(p.bone=y,l.push(p)),u(p.node.children,p.depth+1,y)}let h=RN;for(let p of c){let y=Math.max(o[p].label.height,a)+TN;o[p].rise=h+y/2,h+=y}let d=s.width+2*kN,m=d/2;for(let p of o){let y=p.parent===-1?void 0:o[p.parent];p.depth%2===0?(p.at=y?y.at:0,p.textEnd=p.at-(p.kids>0?(p.kids+1)*qE:CN)-yh):(p.at=y.at-(y.kids-p.slot)*qE,p.textEnd=p.at-yh),m=Math.max(m,p.label.width-p.textEnd)}return{node:e,label:s,boxW:d,boxH:s.height+2*$N,bones:o,rise:h+MN,reach:m}}function ZE(e,t,n){return Pt(n,r=>ON(e,t,n,r))}function ON(e,t,n,r){let i=n.fontSize??16,s=Math.round(i*.875),a=n.measurer??ct(n.fontFamily,n.fontFamilyMono),o=n.padding??8;if(r)return DN(e,n);let c=e.root,l=Ge(e.title,!1,a,i,4e3,1),u=l.height>0?l.height+12:0,h="",d=0,m=0,p=0,y=0;if(c){let O=Ge(c.text,!1,a,i,200,1),v=Math.max(O.height+24,48),G=O.width+24+v/2,K=c.children.map((M,T)=>LN(M,T%2===0,a,i,s));for(let M of K)M.rise=Math.max(M.rise,v/2+14);let C=[],Z=-QE;for(let M=0;M0){let T=0;for(let R=0;R<2;R++){let _=K[M-2+R],$=K[M+R];_&&(T=Math.max(T,_.reach+($?$.boxW/2:0)))}Z-=T+NN}C.push(Z,Z)}let oe=K.length>0?Z-IN:-QE;m=G,d=oe,p=-v/2,y=v/2;let H="";K.forEach((M,T)=>{let R=T%2===0?-1:1,_=C[T],$=(B,F)=>_+B-F*Ol,g=$(0,M.rise),N=R*M.rise,w=Lt-1,A=`M${f(_-Ol/Ll*w)},${f(R*w/Ll)}L${f(g)},${f(N)}`,D="";for(let B of M.bones){let F=R*B.rise;if(B.depth%2===0)A+=`M${f($(B.at,B.rise))},${f(F)}H${f($(B.textEnd+yh,B.rise))}`;else{let j=M.bones[B.parent].rise;A+=`M${f($(B.at,j))},${f(R*j)}L${f($(B.at,B.rise))},${f(F)}`}let W=$(B.textEnd,B.rise);D+=Ne(B.label,W-B.label.width/2,F,B.depth>2?' fill="var(--_m)"':""),d=Math.min(d,W-B.label.width)}let U=N+R*(M.boxH/2);d=Math.min(d,g-M.boxW/2),m=Math.max(m,g+M.boxW/2),p=Math.min(p,U-M.boxH/2),y=Math.max(y,U+M.boxH/2),H+=``+_t("arrow_point",_,0,Ol/Ll,-R/Ll,"var(--_l)")+``+Ne(M.label,g,U,' class="pele-label"')+(D?`${D}`:"")+""});let z=v/2;h=``+_t("arrow_point",0,0,1,0,"var(--_l)")+H+``+Ne(O,12+O.width/2,0,' class="pele-label" font-weight="var(--_hw)"')+""}let E=Math.max(m-d,l.width),b=Math.ceil(E+2*o),S=Math.ceil(y-p+u+2*o),x=o+(E-(m-d))/2-d,I=o+u-p;return{svg:at("ishikawa",b,S,i,n,{},Ne(l,b/2,o+l.height/2,' class="pele-title" font-weight="var(--_tw)"')+(h?`${h}`:"")),width:b,height:S,links:[]}}function DN(e,t){let n=t.fontSize??16,r=Math.round(n*.875),i=t.measurer??ct(t.fontFamily,t.fontFamilyMono),s=t.padding??8,a=Math.max(140,(t.maxWidth??320)-2*s),o=Ge(e.title,!1,i,n,kt(t),1),c=[],l=e.root?[{node:e.root,depth:0,parent:-1}]:[],u=0;for(;l.length;){let x=l.pop(),I=c.length;c.push({...x,x:0,y:0,w:0,h:0}),u=Math.max(u,x.depth);for(let L=x.node.children.length-1;L>=0;L--)l.push({node:x.node.children[L],depth:x.depth+1,parent:I})}let h=Math.min(20,Math.max(2,(a-120)/Math.max(1,u))),d=s+(o.height?o.height+12:0),m=o.width,p="",y="";for(let x of c){x.x=s+x.depth*h;let I=Math.max(60,a-x.depth*h-20);x.label=Zs(Ge(x.node.text,!1,i,x.depth<2?n:r,I,x.depth<2?1:0),i,I),x.w=x.label.width+20,x.h=x.label.height+12,x.y=d,d+=x.h+12,m=Math.max(m,x.x-s+x.w);let L=x.depth<2;if(p+=``+(L?``:"")+Ne(x.label,x.x+x.w/2,x.y+x.h/2,` class="pele-label"${x.depth<2?' font-weight="var(--_hw)"':""}${x.depth>1?` font-size="${r}"`:""}`)+"",x.parent>=0){let O=c[x.parent],v=O.x+h/2;y+=``}}let E=Math.ceil(m+2*s),b=Math.ceil(Math.max(s+o.height,d-12)+s),S=Ne(o,E/2,s+o.height/2,' class="pele-title" font-weight="var(--_tw)"')+y+p;return{svg:at("ishikawa",E,b,n,t,{},S),width:E,height:b,links:[]}}var JE={type:"ishikawa",parse(e,t,n){let r=new $l;return r.title=n,XE(e,r),r},render:ZE};function vl(e){let t=new Set;for(let n of e)for(let r of n.people)t.add(r);return[...t].sort()}var Dl=class{constructor(){fe(this,"type","journey");fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"sections",[]);fe(this,"tasks",[]);fe(this,"currentSection","")}setDiagramTitle(t){this.title=t}setAccTitle(t){this.accTitle=t.replace(/^\s+/g,"")}setAccDescription(t){this.accDescr=t.replace(/\n\s+/g,` +`)}addSection(t){this.currentSection=t,this.sections.push(t)}addTask(t,n){let r=n.substring(1).split(":"),i=r.length===1?[]:r[1].split(",").map(s=>s.trim());this.tasks.push({task:t,score:Number(r[0]),people:i,section:this.currentSection})}getActors(){return vl(this.tasks)}};function wa(e,t){let n=e.indexOf(` +`,t);return n===-1?e.length:n}function nr(e,t,n){for(let r=0;r{n.types.push(l),n.texts.push(e.slice(u,h)),n.starts.push(u)};if(o===58){a=Eh(e,a+1);let l=wa(e,a);return c(i?r+2:r,t,a),c(i?r+3:r+1,a,l),l}if(!i||o!==123)return t;for(a=Eh(e,a+1);e.charCodeAt(a)!==125;){let l=e.indexOf("}",a);if(l===-1&&(l=s),c(r+4,a,l),a===s)return s;a=l}return a+1}var e0=["$end","EOF","INVALID","NEWLINE","journey","title","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","section","taskName","taskData",":"];function Bl(e,t,n){let r=e.length,i=t;for(;i{n.push(c),r.push(e.slice(a,l)),i.push(a),a=l};for(;a=Pl(e,a),!(a>=t);){let c=e.charCodeAt(a),l=a+1;if(c===10){for(;e.charCodeAt(l)===10;)l++;o(3,l);continue}if(nr(e,a,"journey")&&!ot(e.charCodeAt(a+7))){o(4,a+7);continue}if(nr(e,a,"title")){for(l=a+5;e.charCodeAt(l)!==10&&qe(e.charCodeAt(l));)l++;if(l===t||e.charCodeAt(l)===10){a=l;continue}let u=e.charCodeAt(a+5);if(u!==13&&qe(u)&&(l=Bl(e,a+6,!1),l>a+6)){o(5,l);continue}}if(l=Fl(e,a,s,6),l!==a){a=l;continue}if(nr(e,a,"section")&&qe(e.charCodeAt(a+7))&&(l=Bl(e,a+8,!0),l>a+8)){o(11,l);continue}c===58?(l=Bl(e,a+1,!1),o(l>a+1?13:14,l>a+1?l:a+1)):c===59?o(2,a+1):o(12,Bl(e,a+1,!0))}return(i.length===0||i[i.length-1]{let c=n[a]===0?"1":e0[n[a]];throw ft("journey",e,i[a],`Expecting ${o}, got '${c}'`)};n[0]!==4&&s(0,"'journey'");for(let a=1;;a++){let o=r[a];switch(n[a]){case 3:break;case 5:t.setDiagramTitle(o.substring(6));break;case 6:t.setAccTitle(r[++a].trim());break;case 8:t.setAccDescription(r[++a].trim());break;case 10:t.setAccDescription(o.trim());break;case 11:t.addSection(o.substring(8));break;case 12:n[++a]!==13&&s(a,"'taskData'"),t.addTask(o,r[a]);break;case 1:return;default:s(a,vN)}}}var Ul=10,ws=8,PN=124,FN=200,Wl=12,r0=6,xh=24,Ah=26,ro=11,Br=5,BN=13,WN=20,UN='',GN={happy:"M-5,2A6,6 0 0 0 5,2",neutral:"M-4.5,4.5H4.5",sad:"M-5,6.5A6,6 0 0 1 5,6.5"};function s0(e,t,n){return`${UN}`}function i0(e,t,n){return Pt(n,r=>YN(e,t,n,r))}function YN(e,t,n,r){let i=n.fontSize??16,s=Math.round(i*.875),a=Math.round(i*.75),o=n.measurer??ct(n.fontFamily,n.fontFamilyMono),c=n.padding??8;if(r)return HN(e,n);let l=e.tasks,u=l.length,h=vl(l).filter(j=>j!==""),d=new Map;h.forEach((j,Q)=>d.set(j,Q));let m=PN,p=l.map(j=>br(j.task,o,s,m)),y=0;for(let j of p)y=Math.max(y,j.width);y>m&&(m=Math.min(Math.ceil(y),FN),p=l.map(j=>Wn(j.task,o,s,m)));let E=m+2*Ul,b=E+Wl,S=u>0?u*b-Wl:0,x=Math.round(s*1.5),I=Math.max(S,240),L=[],O=0,v=0,G=0;for(let j of h){let Q=Wn(j,o,s,I-2*Br-6),Y=2*Br+6+Q.width;G>0&&G+Y>I&&(G=0,v+=4);let ne=G>0?L[L.length-1].y:v,q=Math.max(Q.height,x);L.push({name:j,label:Q,x:G,y:ne,h:q}),G+=Y,O=Math.max(O,G),v=Math.max(v,ne+q),G+=WN}let K=u>0?xh+S:0,C=Wn(e.title,o,i,Math.max(K,320),1),Z=C.height>0?C.height+16:0,oe=Math.max(K,C.width,u>0?xh+O:0),H=c+(oe-K)/2+xh,z=c+Z,M=[],T=0;for(let j=0;j0?2*Br+6:0,$=R+_+2*ws,g=z+(T>0?T+r0:0),N=g+$+ro+16,w=N+4*Ah,A=H+S,D="",U=z;if(u>0){let j="",Q="";for(let J=5;J>=1;J--){let te=N+(5-J)*Ah;j+=`M${f(H-6)},${f(te)}H${f(A)}`,Q+=`${J}`}D+=`${Q}`;let Y="",ne="",q="",k=[];l.forEach((J,te)=>{let se=H+te*b,re=se+E/2,P=J.score,ee=Number.isNaN(P)?3:Math.min(5,Math.max(1,P)),ae=N+(5-ee)*Ah;Y+=`${te===0?"M":"L"}${f(re)},${f(ae)}`,ne+=`M${f(re)},${f(g+$)}V${f(ae-ro)}`,q+=s0(re,ae,P>3?"happy":P<3?"sad":"neutral");let ue="",ce=J.people.filter(V=>V!==""),pe=Math.min(BN,(E-2*Ul-2*Br)/Math.max(ce.length-1,1));ce.forEach((V,X)=>{ue+=`${Ue(V)}`}),k.push(``+Ne(p[te],re,g+ws+R/2,` font-size="${s}"`)+ue+"")}),D+=``+(u>1?``:"")+q;for(let J of M){let te=k.slice(J.start,J.start+J.count).join("");if(!J.label){D+=te;continue}let se=H+J.start*b,re=J.count*b-Wl;D+=``+Ne(J.label,se+re/2,z+T/2,` font-size="${s}" font-weight="var(--_hw)"`)+te+""}if(U=w+ro,L.length>0){let J=H+(S-O)/2,te=U+16,se="";for(let re of L){let P=te+re.y+re.h/2;se+=``+Ne(re.label,J+re.x+2*Br+6+re.label.width/2,P,"")+""}D+=`${se}`,U=te+v}}let B=Math.ceil(oe+2*c),F=Math.ceil(Math.max(U,c)+c),W=Ne(C,c+oe/2,c+C.height/2,' class="pele-title" font-weight="var(--_tw)"')+D;return{svg:at("journey",B,F,i,n,e,W),width:B,height:F,links:[]}}function HN(e,t){let n=t.fontSize??16,r=Math.round(n*.875),i=t.measurer??ct(t.fontFamily,t.fontFamilyMono),s=t.padding??8,a=Math.max(140,(t.maxWidth??320)-2*s),o=Wn(e.title,i,n,a,1),c=vl(e.tasks).filter(b=>b!==""),l=new Map(c.map((b,S)=>[b,S])),u=s+(o.height?o.height+16:0),h,d="",m=o.width;e.tasks.forEach((b,S)=>{if(b.section!==h){h=b.section;let C=Wn(h,i,n,a-16,1);C.height&&(d+=Ne(C,s+8+C.width/2,u+C.height/2,' class="pele-cluster-label" font-weight="var(--_hw)"'),m=Math.max(m,C.width+16),u+=C.height+8)}let x=Wn(b.task,i,r,a-72),I=b.people.filter(C=>C!=="").map(C=>({name:C,label:Wn(C,i,r,a-44)})),L=Math.max(x.height,42),O=2*ws+L;for(let C of I)O+=Math.max(16,C.label.height)+4;let v=Math.max(a,x.width+72);d+=``,d+=Ne(x,s+Ul+x.width/2,u+ws+x.height/2,' class="pele-label"');let G=s+v-28;d+=s0(G,u+ws+ro,b.score>3?"happy":b.score<3?"sad":"neutral"),Number.isNaN(b.score)||(d+=`${f(Math.min(5,Math.max(1,b.score)))}`);let K=u+ws+L+4;for(let C of I){let Z=Math.max(16,C.label.height);d+=``+Ne(C.label,s+28+C.label.width/2,K+Z/2,` class="pele-journey-actor" font-size="${r}"`),K+=Z+4}d+="",u+=O,S+1`),u+=16,m=Math.max(m,v)});let p=Math.ceil(m+2*s),y=Math.ceil(Math.max(s+o.height,u-(e.tasks.length?16:0))+s),E=Ne(o,p/2,s+o.height/2,' class="pele-title" font-weight="var(--_tw)"')+d;return{svg:at("journey",p,y,n,t,e,E),width:p,height:y,links:[]}}var o0={type:"journey",parse(e,t,n){let r=new Dl;return r.title=n,n0(e,r),r},render:i0};var KN=["1","INVALID","SPACELINE","NL","EOF","","SPACELIST","ICON","CLASS","NODE_DSTART","NODE_ID","NODE_DESCR","NODE_DEND","SHAPE_DATA"];function a0(e,t){return e===5?t?"KANBAN":"MINDMAP":KN[e]}var _s={DEFAULT:0,NO_BORDER:0,ROUNDED_RECT:1,RECT:2,CIRCLE:3,CLOUD:4,BANG:5,HEXAGON:6};function Gl(e,t){switch(e){case"[":return _s.RECT;case"(":return t===")"?_s.ROUNDED_RECT:_s.CLOUD;case"((":return _s.CIRCLE;case")":return _s.CLOUD;case"))":return _s.BANG;case"{{":return _s.HEXAGON;default:return _s.DEFAULT}}var zN=/\s+/y,Sh=/.+/y,VN=/[^([\n){}]+/y,jN=/[^([\n){}@]+/y,XN=/[^)\](}]+/y,qN=/[^`"]+/y,QN=/[^}^"]+/y,ZN=/\n\s*/g;function c0(e,t,n){for(let r=0;r{r.push(y),i.push(E),s.push(l),l=b},d=(y,E,b)=>{h(y,e.slice(l,E),E),c=b},m=(y,E)=>(y.lastIndex=E,y.test(e)?y.lastIndex:-1),p=y=>{let E=e.indexOf(y,l);return E===-1?n:E};for(;l=160?Math.max(m(zN,l),l):l;if(t&&y===64&&E===123)h(13,"",l+2),c=6;else if(e.charCodeAt(S)===37&&e.charCodeAt(S+1)===37)d(2,m(Sh,S),0);else if(S>l)u=S?d(6,S,0):(b=e.lastIndexOf(` +`,S-1))>l?d(2,b+1,0):d(3,l+1,0);else if(c0(e,l,a)&&!ot(e.charCodeAt(l+a.length)))d(5,l+a.length,0);else if(y===58&&E===58&&e.charCodeAt(l+2)===58)l+=3,c=1;else if(y===58&&E===58&&c0(e,l+2,"icon")&&e.charCodeAt(l+6)===40)l+=7,c=2;else if(y===45&&E===41||y===40&&(E===45||E===40)||(y===41||y===123)&&E===y)d(9,l+2,3);else if(y===41||y===40||y===91)d(9,l+1,3);else if((b=m(o,l))!==-1)d(10,b,0);else break}else if(c===3)y===34?(c=E===96?5:4,l+=E===96?2:1):y===41||y===40?d(12,E===y||y===40&&E===45?l+2:l+1,0):y===93?d(12,l+1,0):y===125&&E===125||y===45&&E===41?d(12,l+2,0):d(11,m(y===125?Sh:XN,l),3);else if(c===4)y===34?(l++,c=3):d(11,p('"'),4);else if(c===5)if(y===96&&E===34)l+=2,c=3;else if((b=m(qN,l))!==-1)d(11,b,5);else break;else if(c===1)if((b=m(Sh,l))!==-1)d(8,b,0);else if(y===10)l++,c=0;else break;else if(c===2)y===41?(l++,c=0):d(7,p(")"),2);else if(c===6)if(y===34)d(13,l+1,7);else if(y===125)l++,c=0;else if((b=m(QN,l))!==-1)d(13,b,6);else break;else y===34?d(13,l+1,6):(b=p('"'),h(13,e.slice(l,b).replace(ZN,"
"),b))}return l{let m=i[c];throw m===1?ft(r,e,a[c],"",!0):ft(r,e,a[c],`Expecting ${d}, got '${a0(m,n)}'`)},u=`'${a0(5,n)}'`;if(i[c]===2){for(c++;i[c]===2||i[c]===3;)c++;i[c]!==5&&l(`'SPACELINE', 'NL', ${u}`)}else i[c]!==5&&l(`'SPACELINE', ${u}`);c++;let h="'SPACELINE', 'NL', 'SPACELIST', 'ICON', 'CLASS', 'NODE_DSTART', 'NODE_ID'";for(i[c]===3&&(c++,h="'SPACELINE', 'SPACELIST', 'ICON', 'CLASS', 'NODE_DSTART', 'NODE_ID'");;){let d=i[c],m=0,p=d===6;if(p&&(m=s[c++].length,d=i[c]),d===10||d===9){let y,E,b=0;if(d===10&&(y=s[c++]),i[c]===9){let S=s[c++];i[c]!==11&&l("'NODE_DESCR'"),E=s[c++],i[c]!==12&&l("'NODE_DEND'");let x=s[c++];!so(i[c])&&i[c]!==13&&l(ci+o),b=t.getType(S,x)}else!so(i[c])&&i[c]!==13&&l(ci+", 'NODE_DSTART'"+o),E=y;if(i[c]===13){let S=s[c++];for(;i[c]===13;)S+=s[c++];so(i[c])||l(ci+o),t.addNode(m,y??E,E,b,S)}else t.addNode(m,y??E,E,b)}else if(d===7||d===8){let y=s[c++];so(i[c])||l(ci),t.decorateNode(d===7?{icon:y}:{class:y})}else p?so(d)||l(ci+", 'ICON', 'CLASS', 'NODE_DSTART', 'NODE_ID'"):d===2?so(i[++c])||l(ci):l(h);for(c++;i[c]===3||i[c]===4;)c++;if(i[c]===0)return;l0[i[c]]===0&&l(ci+", 'SPACELIST', 'ICON', 'CLASS', 'NODE_DSTART', 'NODE_ID'")}}var Hl=class{constructor(){fe(this,"type","kanban");fe(this,"title");fe(this,"sections",[]);fe(this,"getType",Gl);fe(this,"last");fe(this,"sectionLevel",0);fe(this,"misplaced")}addNode(t,n,r,i,s){let a={id:n,level:t,label:r};if(s!==void 0){let c=s.includes(` +`)?s+` +`:`{ +`+s+` +}`,l;try{l=lr(c)}catch(u){throw new Qe(`Metadata of "${a.id}" is not valid YAML. ${u.message}`,"syntax",{type:"kanban"})}if(l!==null&&typeof l=="object"&&!Array.isArray(l)){let u=l.shape?String(l.shape):"";if(u!==u.toLowerCase()||u.includes("_"))throw new Qe(`No such shape: ${u}. Shape names should be lowercase.`,"semantic",{type:"kanban"});l.label&&(a.label=String(l.label)),l.icon&&(a.icon=String(l.icon)),l.assigned&&(a.assigned=String(l.assigned)),l.ticket&&(a.ticket=String(l.ticket)),l.priority&&(a.priority=String(l.priority))}}if(this.misplaced)throw new Qe(`Items without section detected, found section ("${this.misplaced.label}")`,"semantic",{type:"kanban"});let o=this.sections;if(o.length===0&&(this.sectionLevel=t),this.last=a,t===this.sectionLevel){let c=a;c.items=[],o.push(c)}else o[o.length-1].items.push(a),t${i?.(e)??""}`}var Wr=12,Ur=8,yr=10,_h=8,JN=4,Ra=6,eI=new Map([["very high",`stroke="${Yo}"`],["high",`stroke="${Yo}" opacity="0.5"`],["low",'stroke="var(--_m)" opacity="0.5"'],["very low",'stroke="var(--_m)"']]);function Kl(e,t,n,r,i,s=0){let a=Ge(e,t,n,r,i,s);if(a.width<=i)return a;let o=[],c=[],l=0,u=[],h=0,d=()=>{o.push(u),c.push(h),l=Math.max(l,h),u=[],h=0};for(let p=0;p0&&h+y.width>i&&d(),u.push(y),h+=y.width;continue}let E="",b=h;for(let S of y.text){let x=n.width(S,r,y.style);h>0&&h+x>i&&(E&&u.push({text:E,style:y.style,width:h-b}),d(),E="",b=0),E+=S,h+=x}E&&u.push({text:E,style:y.style,width:h-b})}d()}let m={...a,lines:o,widths:c,width:l,height:o.length*a.lineHeight};return a.heights?Vo(m):m}function Ta(e,t,n,r,i,s=!1){let a="";for(let o=0;o${rt(c[0].text)}
`;else{let u=e.widths[o];a+=Ne(Ir(e,o),t+(s?-u:u)/2,l,r,i)}}return a}var io=e=>!!e&&Ti(e)!=="";function u0(e,t,n){let r=n.fontSize??16,i=Math.round(r*.875),s=Math.round(r*1.5),a=Math.round(i*1.5),o=n.measurer??ct(n.fontFamily,n.fontFamilyMono),c=n.padding??8,l=n.icons,u=t.kanban??{},h=u.sectionWidth,d=i*1.25,m=0,p=(W,j,Q)=>{if(!(!W||!W.includes("$$")))for(let Y of Ge(W,!0,o,j,1/0).lines)for(let ne of Y)ne.math&&(m=Math.max(m,ne.math.width+Q))};for(let W of e.sections){let j=o.width(String(W.items.length),i,0);p(W.label,r,2*Ur+8+j+12+(io(W.icon)?d+Ra:0));for(let Q of W.items){let Y=2*(Ur+yr);p(Q.label,i,Y+(io(Q.icon)?d+Ra:0)),p(Q.ticket,i,Y),p(Q.assigned,i,Y)}}let y=Math.max(typeof h=="number"&&h>0?Math.min(Math.max(h,80),2e3):200,Math.ceil(m)),E=n.maxWidth!==void 0&&n.maxWidth>0?n.maxWidth-2*c:1/0,b=e.sections.length,S=b*(y+Wr)-Wr<=E,x=S?Math.max(b,1):Math.max(1,Math.floor((E+Wr)/(y+Wr))),I=S?y:Math.max(Math.min(y,E),Math.min(Math.floor((E+Wr)/x)-Wr,y*2),Math.ceil(m)),L=typeof u.ticketBaseUrl=="string"?u.ticketBaseUrl:"",O=I-2*Ur,v=O-2*yr,G=[],K=e.sections,C=[],Z=[],oe=[],H=s,z=[];for(let W of K){let j=o.width(String(W.items.length),i,0),Q=j+12+(io(W.icon)?d+Ra:0),Y=Kl(W.label,!0,o,r,O-8-Q,1);H=Math.max(H,Y.height),Z.push(j),C.push(Y);let ne=[],q=0;for(let k of W.items){let J=Kl(k.label,!0,o,i,v-(io(k.icon)?d+Ra:0)),te=Kl(k.ticket,!1,o,i,v),se=Kl(k.assigned,!1,o,i,v),re=te.width+se.width+8>v?te.height+se.height:Math.max(te.height,se.height),P=2*yr+Math.max(J.height,a)+(re?JN+re:0);ne.push({item:k,label:J,ticket:te,assigned:se,meta:re,height:P}),q+=P+_h}oe.push(ne),z.push(q)}H+=2*Ur;let M=[],T=[];for(let W=0,j=0;W0?T[T.length-1]+M[M.length-1]:0,_=yn(e.title,o,r,kt(n)),$=_.height>0?_.height+16:0,g=Math.max(Math.min(K.length,x)*(I+Wr)-Wr,0),N=Math.max(g,_.width),w=c+(N-g)/2,A=I-Ur-4,D="";for(let W=0;W`+Ta(C[W],Ur+4,Ur,' class="pele-cluster-label" font-weight="var(--_hw)"',l)+`${j.items.length}`;io(j.icon)&&(Y+=_a(j.icon,A-Z[W]-Ra-d,Ur+(s-d)/2,d,l));let ne=H;for(let q of oe[W]){let k=q.item,J=(k.priority??"").trim().toLowerCase(),te=eI.get(J),se=``;te!==void 0&&(se+=``),se+=Ta(q.label,yr,yr,' class="pele-label"',l),io(k.icon)&&(se+=_a(k.icon,O-yr-d,yr+(a-d)/2,d,l));let re=q.height-yr;if(k.ticket){let P=re-q.meta,ee=L?ko(Qn(L.replace("#TICKET#",()=>k.ticket)),n):void 0;ee===void 0?se+=Ta(q.ticket,yr,P,' class="pele-ticket" fill="var(--_m)"',l):(se+=``+Ta(q.ticket,yr,P,' class="pele-ticket" fill="var(--_c)"',l)+"",G.push({id:k.id,href:ee,internal:!1}))}k.assigned&&(se+=Ta(q.assigned,O-yr,re-q.assigned.height,' class="pele-assigned" fill="var(--_m)"',l,!0)),Y+=`${se}`,ne+=q.height+_h}D+=`${Y}`}let U=Math.ceil(N+2*c),B=Math.ceil(R+$+2*c),F=Ne(_,U/2,c+_.height/2,' class="pele-title" font-weight="var(--_tw)"')+D;return{svg:at("kanban",U,B,r,n,{},F),width:U,height:B,links:G}}var f0={type:"kanban",math:!0,parse(e,t,n){let r=new Hl;return r.title=n,d0(e,r),r},render:u0};var tI=11,zl=class{constructor(){fe(this,"type","mindmap");fe(this,"title");fe(this,"nodes",[]);fe(this,"getType",Gl);fe(this,"baseLevel",0);fe(this,"open",[])}addNode(t,n,r,i){let s=this.nodes.length===0;s&&(this.baseLevel=t),t-=this.baseLevel;let a=this.open,o=a.length;for(;o>0&&a[o-1].level>=t;)o--;let c=a[o-1];if(!c&&!s)throw new Qe(`There can be only one root. No parent could be found for ("${r}")`,"semantic",{type:"mindmap"});let l={id:this.nodes.length,nodeId:n,level:t,descr:r,type:i,children:[],isRoot:s};c&&(l.section=c.isRoot?c.children.length%tI:c.section,c.children.push(l)),a.length=o,a.push(l),this.nodes.push(l)}decorateNode(t){let n=this.nodes[this.nodes.length-1];!t||!n||(t.icon&&(n.icon=t.icon),t.class&&(n.class=t.class))}};function h0(e,t){Yl(e,t,!1)}var nI=["","rounded","rect","circle","cloud","bang","hex"],p0="stadium",rI=36,sI=8,iI=18,oI=52,m0=28,g0=6,aI=12,cI=.22,Rh=6,Th=28,b0=12,y0=8,E0=10;function lI(e,t,n,r){if(e.lines.length<2)return Ne(e,t+e.width/2,n,' class="pele-label"',r);let i="",s=n-e.height/2;for(let a=0;adI(e,t,n,r))}function dI(e,t,n,r){let i=n.fontSize??16,s=n.measurer??ct(n.fontFamily,n.fontFamilyMono),a=n.padding??8,o=n.icons,c=t.mindmap?.maxNodeWidth,l=typeof c=="number"&&c>0?Math.min(c,2e3):200,u=i*1.25,h=e.nodes,d=h.length,m=new Int32Array(d),p=new Int32Array(d);for(let q=0;q0?n.maxWidth-2*a:1/0,E=new Array(d),b=new Array(d),S=new Float64Array(d),x=new Float64Array(d),I=new Float64Array(d),L=new Float64Array(d),O=new Uint8Array(d);for(let q=0;q0?Rh:0):0),re=Math.max(te.height,Math.round(i*1.5)),P=nI[k.type]||(q===0?p0:"");if(r&&q===0&&P!=="rect"&&P!=="rounded"&&(P=p0),b[q]=P,P===""){let ee=k.children.length>0;S[q]=se+2*(ee?aI:g0),x[q]=re+(ee?6:0),L[q]=x[q]/2}else{let ee=ps(P,se,re);S[q]=ee.w,x[q]=ee.h,I[q]=ee.dy,L[q]=ee.h/2}}let v=new Float64Array(d),G=new Float64Array(d),K=new Float64Array(d),C=new Float64Array(d),Z=0,oe=(q,k,J,te)=>{let se=0,re=0;for(let ae=k;ae0||ae+10?Math.max(te,iI):te,se+=v[ue]+re}Z=se-re;let P=q[k].id,ee=q[J-1].id;return(G[P]+K[P]+L[P]+G[ee]+K[ee]+L[ee])/2};for(let q=d-1;q>0;q--){let k=h[q].children;if(k.length===0){v[q]=x[q];continue}let J=oe(k,0,k.length,sI)-L[q],te=Math.min(0,J);v[q]=Math.max(Z,J+x[q])-te,K[q]=J-te,C[q]=-te}let H=new Float64Array(d),z=new Float64Array(d),M=new Float64Array(d),T=new Int8Array(d),R=new Float64Array(d);if(r){let q=0;for(let k=0;k0&&m[k]===0&&(q+=E0),H[k]=p[k]*Th+S[k]/2,z[k]=q,q+=x[k]+E0}else if(d>0){let q=h[0].children,k=q.length,J=0;for(let P of q)J+=v[P.id];let te=k,se=1/0,re=0;for(let P=1;P0&&(z[P]=M[P]+K[P]);for(let ee of h[P].children){let ae=ee.id;P>0&&(T[ae]=T[P],M[ae]=M[P]+C[P]+G[ae]),H[ae]=H[P]+T[ae]*(S[P]/2+(P>0?rI:oI)+S[ae]/2)}}}let _=0,$=0,g=0,N=0,w="",A="",D="",U="",B=q=>{D!==""&&(w+=`${A}${D}`,A=D="")};for(let q=1;q<=d;q++){let k=q%d,J=h[k],te=b[k],se=E[k],re=H[k],P=z[k];if(_=Math.min(_,re-S[k]/2),$=Math.max($,re+S[k]/2),g=Math.min(g,P),N=Math.max(N,P+x[k]),(k===0||m[k]===0)&&B(h[q-1].section),k>0&&r){m[k]===0&&(U=Et(J.section??0));let V=m[k],X=V===0?Math.min(Math.max(b0,x[0]/2),Th-y0):b0,le=H[V]-S[V]/2+Math.min(X,S[V]/2),de=R[V]||z[V]+x[V],_e=re-S[k]/2+(te?Qr(te,S[k],x[k],3):0),xe=P+L[k],Me=Math.max(0,Math.min(y0,_e-le,xe-de));R[V]=xe-Me,A+=``}else if(k>0){m[k]===0&&(U=Et(J.section??0));let V=m[k],X=T[k],le=X>0?1:3,de=H[V]+X*(S[V]/2-(b[V]?Qr(b[V],S[V],x[V],le):0)),Se=z[V]+L[V],xe=re-X*S[k]/2+(te?X*Qr(te,S[k],x[k],4-le):0),Me=P+L[k],Ce=f((de+xe)/2);A+=``}let ee=!te&&J.children.length>0,ae=` fill="${U}" fill-opacity="${cI}" stroke="${U}"`,ue="";te?ue=k>0?hr(te,S[k],x[k],ae,` stroke="${U}"`):hr(te,S[k],x[k],' fill="var(--_s)" stroke="var(--_b)"',' stroke="var(--_b)"'):ee&&(ue=``);let ce=0;J.icon&&O[k]&&(ce=(u+(se.width>0?Rh:0))/2,ue+=_a(J.icon,-ce-se.width/2,I[k]-u/2,u,o));let pe=`0?"":" pele-root"}${It(J.class??"")}" data-id="${Ue(J.nodeId)}" transform="translate(${f(re)},${f(P+x[k]/2)})">`+ue+(r&&!te?lI(se,ce-se.width/2,I[k],o):Ne(se,ce,I[k],' class="pele-label"',o))+"";k>0?D+=pe:w+=pe}let F=yn(e.title,s,i,kt(n)),W=F.height>0?F.height+16:0,j=Math.max($-_,F.width),Q=Math.ceil(j+2*a),Y=Math.ceil(N-g+W+2*a),ne=Ne(F,Q/2,a+F.height/2,' class="pele-title" font-weight="var(--_tw)"')+`${w}`;return{svg:at("mindmap",Q,Y,i,n,{},ne),width:Q,height:Y,links:[]}}var A0={type:"mindmap",math:!0,parse(e,t,n){let r=new zl;return r.title=n,h0(e,r),r},render:x0};var uI=1e4;function oo(e,t,n,r,i){let s=e.packet?.[t];return typeof s=="number"&&s>=r?Math.min(s,i):n}function Mh(e){return new Qe(e,"semantic",{type:"packet"})}function S0(e,t,n){let r=Math.floor(oo(t,"bitsPerRow",32,1,4096)),i=[],s=-1,a=[],o=1;for(let c of e.blocks){let{start:l,end:u,bits:h}=c;if(l!==void 0&&u!==void 0&&u0&&i.push(a),{type:"packet",title:e.title||n,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,` +`):void 0,bitsPerRow:r,rows:i}}var w0=[{name:"packet-beta",pattern:"packet-beta"},Jt("packet"),{name:"-",pattern:"-",longer:[Ht]},{name:"+",pattern:"+"},{name:":",pattern:":"},sn,Xt,pr,{name:"INT",pattern:/0|[1-9][0-9]*(?!\.)/y},Fn,Sn,wn,Ht,Qt,Zt];function _0(e){let t=new Ut(Yt(e,w0,"packet"),w0,"packet"),n={$type:"Packet",blocks:[]},r=()=>{if(t.kind!==-1)for(t.kind!==10&&t.fail("a line break or the end of input");t.kind===10;)t.i++};for(;t.kind===10;)t.i++;for(t.accept(0)||t.expect(1);t.kind!==-1;)switch(t.kind){case 10:t.i++;break;case 5:n.accDescr=Vt(t.take()),r();break;case 6:n.accTitle=zt(t.take()),r();break;case 7:n.title=Kt(t.take()),r();break;case 8:case 3:{let i={$type:"PacketBlock",label:""};t.accept(3)?i.bits=Number(t.expect(8)):(i.start=Number(t.take()),t.accept(2)&&(i.end=Number(t.expect(8)))),t.expect(4),i.label=un(t.expect(9)),n.blocks.push(i),r();break}default:t.fail("a field, a title, or a line break")}return n}function Ma(e,t,n,r,i,s=0){if(e===""||t<=0)return;let a=i.width(e,n,s);if(a<=t)return{text:e,size:n,width:a};let o=Math.max(r,Math.floor(n*t/a));for(;o>=r;){if(a=i.width(e,o,s),a<=t)return{text:e,size:o,width:a};o--}let c=Array.from(e),l=0,u=c.length-1;for(;l>1;i.width(c.slice(0,d).join("").trimEnd()+"…",r,s)<=t?l=d:u=d-1}if(l===0)return;let h=c.slice(0,l).join("").trimEnd()+"…";return a=i.width(h,r,s),a<=t?{text:h,size:r,width:a}:void 0}function R0(e,t,n){return Pt(n,r=>fI(e,t,n,r))}function fI(e,t,n,r){let i=n.fontSize??16,s=Math.round(i*.875),a=Math.round(i*.625),o=n.measurer??ct(n.fontFamily,n.fontFamilyMono),c=n.padding??8,l=t.packet??{},u=oo(t,"rowHeight",32,1,400),h=oo(t,"bitWidth",32,1,400),d=oo(t,"paddingX",5,0,400),m=oo(t,"paddingY",5,0,400),p=l.showBits!==!1,y=l.bitOrder==="descending",E=e.bitsPerRow,b=e.rows;if(r){let $=Math.max(1,Math.floor(((n.maxWidth??320)-2*c)/Math.min(h,18)));E=Math.min(E,Math.max(8,2**Math.floor(Math.log2($))));let g=e.rows[e.rows.length-1],N=g?.[g.length-1]?.end??0;Math.ceil((N+1)/E)>1e4&&(E=e.bitsPerRow),h=Math.min(h,Math.max(18,((n.maxWidth??320)-2*c)/E));let w=D=>D.bits===D.end-D.start,A=[];for(let D of e.rows)for(let U of D){let B=A[A.length-1];B&&w(B)&&w(U)&&B.label===U.label&&U.start===B.end+1&&U.start%e.bitsPerRow===0?(B.end=U.end,B.bits=B.end-B.start):A.push({...U})}b=[];for(let D of A)for(let U=D.start;U<=D.end;){let B=Math.min(D.end,(Math.floor(U/E)+1)*E-1),F=Math.floor(U/E);(b[F]??(b[F]=[])).push({...D,start:U,end:B}),U=B+1}}let S=new Map;if(r)for(let $ of b)for(let g of $){let N=Math.max(1,(g.end-g.start+1)*h-Math.min(d,h-1)-6),w=Qs(bt(g.label).trim(),o,s,N);S.set(g,w)}let x=p?a+4:0,I=b.map($=>{let g=u;if(r)for(let N of $)g=Math.max(g,S.get(N).height+10);return g}),L=[],O=0;for(let $ of I)L.push(O),O+=x+$+m;b.length&&(O-=m);let v=Math.min(d,h-1),G=b.length>0?E*h-v:0,K=Ge(e.title,!1,o,i,r?kt(n):4e3,1),C=K.height>0?K.height+(O>0?12:0):0,Z=new Map,oe=($,g)=>{let N=Z.get($);return N||Z.set($,N=new Map),N.has(g)||N.set(g,Ma(bt($).trim(),g,s,Math.round(i*.5),o)),N.get(g)},H=c+Math.max(0,(K.width-G)/2),z="",M="";b.forEach(($,g)=>{let N=c+L[g]+x,w=I[g];for(let A of $){let D=A.end-A.start+1,U=A.start%E,B=H+(y?E-U-D:U)*h,F=D*h-v,W=r?void 0:oe(A.label,F-6);if(z+=``+(r?Ne(S.get(A),B+F/2,N+w/2,""):W&&W.size<=w?`${rt(W.text)}`:"")+"",!p)continue;let j=y?A.end:A.start,Q=y?A.start:A.end;D===1?M+=`${j}`:M+=`${j}${Q}`}});let T=Math.ceil(Math.max(G,K.width)+2*c),R=Math.ceil(O+C+2*c),_=(z?`${z}`:"")+(M?`${M}`:"")+Ne(K,T/2,R-c-K.height/2,' class="pele-title" font-weight="var(--_tw)"');return{svg:at("packet",T,R,i,n,e,_),width:T,height:R,links:[]}}var T0={type:"packet",parse:(e,t,n)=>S0(_0(e),t,n),render:R0};function M0(e,t){let n=new Map;for(let{label:r,value:i}of e.sections){if(i<0)throw new Qe(`"${r}" has invalid value: ${i}. Negative values are not allowed in pie charts. All slice values must be >= 0.`,"semantic",{type:"pie"});n.has(r)||n.set(r,i)}return{type:"pie",title:e.title||t,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,` +`):void 0,showData:e.showData,sections:n}}function C0(e,t){let n=t;for(let r=e.charCodeAt(n);r>=48&&r<=57;r=e.charCodeAt(n))n++;return n}function hI(){let e=0,t=0,n=-1;return(r,i)=>{let s=r.charCodeAt(i)===45?i+1:i;if((s=t)&&(e=s,t=C0(r,s),n=-1,t>s&&r.charCodeAt(t)===46)){let a=C0(r,t+1),o=a-t-1;o>0&&r.charCodeAt(a)!==46?n=a:o>1&&(n=a-1)}return t===s?-1:n>=0?n:r.charCodeAt(s)===48?r.charCodeAt(s+1)===46?-1:s+1:r.charCodeAt(t)!==46?t:t-1>s?t-1:-1}}var N0=[Jt("showData"),Jt("pie"),{name:":",pattern:":"},{name:"NUMBER_PIE",pattern:/(?:-?[0-9]+\.[0-9]+(?!\.))|(?:-?(0|[1-9][0-9]*)(?!\.))/y,scanner:hI,first:"-0123456789"},sn,Xt,pr,Fn,Sn,wn,Ht,Qt,Zt];function I0(e){let t=new Ut(Yt(e,N0,"pie"),N0,"pie"),n={$type:"Pie",showData:!1,sections:[]},r=()=>{if(t.kind!==-1)for(t.kind!==8&&t.fail("a line break or the end of input");t.kind===8;)t.i++};for(;t.kind===8;)t.i++;for(t.expect(1),n.showData=t.accept(0);t.kind!==-1;)switch(t.kind){case 8:t.i++;break;case 4:n.accDescr=Vt(t.take()),r();break;case 5:n.accTitle=zt(t.take()),r();break;case 6:n.title=Kt(t.take()),r();break;case 7:{let i=un(t.take());t.expect(2);let s=Number(t.expect(3));n.sections.push({$type:"PieSection",label:i,value:s}),r();break}default:t.fail("a section, a title, or a line break")}return n}var pI=120,Ca=12,Ch=26,Nh=32,k0=28;function Ih(e,t){return e.pie?.[t]}function ao(e,t){return`${f(Math.sin(e)*t)},${f(-Math.cos(e)*t)}`}function mI(e,t,n,r){if(t-e>=Math.PI*2-1e-9){let s=(a,o)=>`M0,${f(-a)}A${f(a)},${f(a)} 0 1 ${o} 0,${f(a)}A${f(a)},${f(a)} 0 1 ${o} 0,${f(-a)}Z`;return s(n,1)+(r>0?s(r,0):"")}let i=t-e>Math.PI?1:0;return r<=0?`M0,0L${ao(e,n)}A${f(n)},${f(n)} 0 ${i} 1 ${ao(t,n)}Z`:`M${ao(e,n)}A${f(n)},${f(n)} 0 ${i} 1 ${ao(t,n)}L${ao(t,r)}A${f(r)},${f(r)} 0 ${i} 0 ${ao(e,r)}Z`}function $0(e,t,n){return ms(n,pI*2,140,(r,i)=>gI(e,t,n,r/2,i))}function gI(e,t,n,r,i){let s=n.fontSize??16,a=Math.round(s*.875),o=n.measurer??ct(n.fontFamily,n.fontFamilyMono),c=n.padding??8,l=Ih(t,"textPosition"),u=typeof l=="number"&&l>=0&&l<=1?l:.75,h=Ih(t,"donutHole"),d=typeof h=="number"&&h>0&&h<=.9?h*r:0,m=String(Ih(t,"legendPosition")??"right"),p=i&&(m==="left"||m==="right")?"bottom":m,y=[...e.sections],E=0;for(let[,Q]of y)E+=Q;let b=y.map(([Q,Y])=>Ge(e.showData?`${Q} [${Y}]`:Q,!1,o,a,4e3)),S=0;for(let Q of b)S=Math.max(S,Q.width);S+=b.length>0?Ca+8:0;let x=b.length*Ch,I=Ge(e.title,!1,o,s,kt(n),1),L=I.height>0?I.height+16:0,O=y.map(([,Q])=>{let Y=E>0?Q/E:0;return Y*100>=1&&(Y*100).toFixed(0)!=="0"?Y:0}),v=O.map(Q=>Q===0||Q>=.5?!1:2*r*u*Math.sin(Q*Math.PI)0?Nh+S:0,H=Math.max(H,x)):C&&(oe=Math.max(oe,S),H+=x>0?20+x:0),oe=Math.max(oe,I.width);let z=c+(K==="left"?S+Nh+Z/2:K==="right"?Z/2:oe/2),M=c+L,T=M+(p==="top"?x+20+Z/2:C?Z/2:H/2),R="",_="",$="",g=0,N=r+k0/2,w=[],A=(Q,Y,ne)=>w.every(q=>Math.abs(Q-q.x)>=(ne+q.width)/2+2||Math.abs(Y-q.y)>=a+2);y.forEach(([Q],Y)=>{let ne=O[Y];if(ne===0)return;let q=g+ne*Math.PI*2;R+=``;let k=(g+q)/2,J=(ne*100).toFixed(0)+"%";if(v[Y]){let te=o.width(J,a,0),se=k;for(let ee=0;ee<360&&!A(Math.sin(se)*N,-Math.cos(se)*N,te);ee++)se+=2/N;let re=Math.sin(se)*N,P=-Math.cos(se)*N;w.push({x:re,y:P,width:te}),$+=`${J}`}else{let te=r*u;_+=`${J}`}g=q}),R===""&&(R=``);let D="",U,B;K==="right"?(U=z+Z/2+Nh,B=M+(H-x)/2):K==="left"?(U=c,B=M+(H-x)/2):K==="center"?(U=z-S/2,B=T-x/2):(U=c+(oe-S)/2,B=p==="top"?M:M+Z+20),b.forEach((Q,Y)=>{let ne=B+Y*Ch+Ch/2;D+=``+Ne(Q,U+Ca+8+Q.width/2,ne,"")+""});let F=Math.ceil(oe+2*c),W=Math.ceil(H+L+2*c),j=Ne(I,F/2,c+I.height/2,' class="pele-title" font-weight="var(--_tw)"')+`${R}`+(_?`${_}`:"")+($?`${$}`:"")+(D?`${D}`:"");return{svg:at("pie",F,W,s,n,e,j),width:F,height:W,links:[]}}var L0={type:"pie",parse:(e,t,n)=>M0(I0(e),n),render:$0};var bI=/^\d+$/,O0=/^#?([\dA-Fa-f]{6}|[\dA-Fa-f]{3})$/,yI=/^\d+px$/;function Vl(e,t,n){return new Qe(`value for ${e} ${t} is invalid, please use a valid ${n}`,"semantic",{type:"quadrantChart"})}function EI(e){let t=e.trim(),n=t.indexOf(":");if(n===-1)return[t,"undefined"];let r=t.slice(n+1).trimStart(),i=r.indexOf(":");return[t.slice(0,n).trimEnd(),i===-1?r:r.slice(0,i).trimEnd()]}function D0(e){let t={};for(let n of e){let[r,i]=EI(n);if(r==="radius"){if(!bI.test(i))throw Vl(r,i,"number");t.radius=parseInt(i)}else if(r==="color"){if(!O0.test(i))throw Vl(r,i,"hex code");t.color=i}else if(r==="stroke-color"){if(!O0.test(i))throw Vl(r,i,"hex code");t.strokeColor=i}else if(r==="stroke-width"){if(!yI.test(i))throw Vl(r,i,"number of pixels (eg. 10px)");t.strokeWidth=i}else throw new Qe(`style named ${r} is not supported.`,"semantic",{type:"quadrantChart"})}return t}function ns(e){return{text:e.text.trim(),type:e.type}}var jl=class{constructor(){fe(this,"type","quadrantChart");fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"quadrants",[void 0,void 0,void 0,void 0]);fe(this,"xAxisLeft");fe(this,"xAxisRight");fe(this,"yAxisBottom");fe(this,"yAxisTop");fe(this,"points",[]);fe(this,"classes",new Map)}setQuadrant1Text(t){this.quadrants[0]=ns(t)}setQuadrant2Text(t){this.quadrants[1]=ns(t)}setQuadrant3Text(t){this.quadrants[2]=ns(t)}setQuadrant4Text(t){this.quadrants[3]=ns(t)}setXAxisLeftText(t){this.xAxisLeft=ns(t)}setXAxisRightText(t){this.xAxisRight=ns(t)}setYAxisBottomText(t){this.yAxisBottom=ns(t)}setYAxisTopText(t){this.yAxisTop=ns(t)}addPoint(t,n,r,i,s){this.points.push({x:Number(r),y:Number(i),text:ns(t),className:n,...D0(s)})}addClass(t,n){this.classes.set(t,D0(n))}setDiagramTitle(t){this.title=t}setAccTitle(t){this.accTitle=t.replace(/^\s+/g,"")}setAccDescription(t){this.accDescr=t.replace(/\n\s+/g,` +`)}};function pn(e,t,n){for(let r=0;r=97&&s<=122&&i===s-32))return!1}return!0}var kh=["$end","INVALID","NEWLINE","title","title_value","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","X-AXIS","Y-AXIS","AXIS-TEXT-DELIMITER","QUADRANT_1","QUADRANT_2","QUADRANT_3","QUADRANT_4","CLASSDEF","MD_STR","STR","class_name","point_start","point_x","point_y","QUADRANT","ALPHA","UNICODE_TEXT","COLON","PLUS","COMMA","EQUALS","MULT","BRKT","UNDERSCORE","DOT","AMP","MINUS","NUM","SPACE","SEMI","PUNCTUATION","EOF"];var $h=[41,4,6,8,9,19],Lh=new Uint8Array(128);for(let[e,t]of[[":",27],["+",28],[",",29],["=",30],["*",31],["#",32],["_",33],[".",34],["&",35],["-",36],[" \v\f",38],[";",39],["!$%'`?\\/",40]])for(let n=0;n{n.push(v),r.push(e.slice(G,K)),i.push(G),o=K},b=v=>{s.push(a),a=v},S=()=>{s.length>0&&(a=s.pop())},x=v=>{let G=e.indexOf(` +`,v);return G===-1?t:G},I=v=>{for(;e.charCodeAt(v)===32;)v++;return v},L=v=>{for(;v{let G=e.charCodeAt(v);if(G===49)return v+1;if(G!==48)return-1;let K=v+1;if(K=l)&&(c=o,l=I(o)),C=l);let Z=e.charCodeAt(C),oe=Z|32,H=0,z=0;if(oe===120&&pn(e,C,"x-axis"))H=10,z=C+6;else if(oe===121&&pn(e,C,"y-axis"))H=11,z=C+6;else if(Z===45){if(C=h)for(u=C,h=C;e.charCodeAt(h)===45;)h++;h-C>=2&&e.charCodeAt(h)===62&&(H=12,z=h+1)}else if(oe===113&&pn(e,C,"quadrant")){let M=e.charCodeAt(C+9);e.charCodeAt(C+8)===45&&M>=49&&M<=52?(H=13+M-49,z=C+10):pn(e,C+8,"chart")&&(H=24,z=C+13)}if(H!==0){E(H,o,I(z));continue}if(K===99&&pn(e,o,"classdef")&&!ot(e.charCodeAt(o+8))){E(17,o,o+8);continue}if(v===34){G===96?(o+=2,b(6)):(o++,b(5));continue}if(v===58&&G===58&&e.charCodeAt(o+2)===58){o+=3,b(7);continue}if(v===58||qe(v)){let M=o;if(v!==58&&((o=m)&&(d=o,m=L(o)),M=m),e.charCodeAt(M)===58&&((M+1=y)&&(p=M+1,y=L(M+1)),e.charCodeAt(y)===91)){E(21,o,L(y+1)),b(8);continue}}if(Vr(v)){let M=o+1;for(;Vr(e.charCodeAt(M));)M++;E(25,o,M);continue}if(v>=128){let M=o+1;for(;e.charCodeAt(M)>=128;)M++;E(26,o,M);continue}if(xt(v)){let M=o+1;for(;xt(e.charCodeAt(M));)M++;E(37,o,M);continue}if(Lh[v]!==0){E(Lh[v],o,o+1);continue}break}return o{let d=n[s];throw d===1?ft("quadrantChart",e,i[s],"",!0):ft("quadrantChart",e,i[s],`Expecting ${h}, got '${kh[d]}'`)},o=h=>(n[s]!==h&&a(`'${kh[h]}'`),r[s++]),c=h=>h===19||h===18||P0[h]===1,l=()=>{let h=n[s];c(h)||a(AI);let d=r[s++];for(;P0[n[s]]===1||n[s]===38||n[s]===36;)d+=r[s++];return{text:d,type:h===18?"markdown":"text"}},u=()=>{let h=[];for(;;){Oh[n[s]]===0&&a("'ALPHA', 'NUM', 'COLON', 'SPACE', 'BRKT', 'MINUS'");let d=r[s++];for(;Oh[n[s]]===1;)d+=r[s++];if(h.push(d.trim()),n[s]!==29)return h;s++}};for(;B0[n[s]]===1||n[s]===38;)s++;for(o(24);n[s]!==0;){for(;n[s]===38;)s++;let h=n[s];switch(h){case 17:{s++,o(38),F0[n[s]]===0&&a("'ALPHA', 'NUM', 'UNICODE_TEXT'");let d=r[s++];for(;F0[n[s]]===1;)d+=r[s++];o(38),t.addClass(d,u());break}case 10:case 11:{s++;let d=l(),m;n[s]===12&&(s++,c(n[s])?m=l():d.text+=" ⟶ "),h===10?(t.setXAxisLeftText(d),m&&t.setXAxisRightText(m)):(t.setYAxisBottomText(d),m&&t.setYAxisTopText(m));break}case 13:case 14:case 15:case 16:s++,t[xI[h-13]](l());break;case 3:s++,t.setDiagramTitle(o(4).trim());break;case 5:s++,t.setAccTitle(o(6).trim());break;case 7:s++,t.setAccDescription(o(8).trim());break;case 9:t.setAccDescription(r[s++].trim());break;default:if(c(h)){let d=l(),m=n[s]===20?r[s++]:"";o(21);let p=o(22),y=o(23);t.addPoint(d,m,p,y,Oh[n[s]]===1?u():[])}}B0[n[s]]===0&&a("'NEWLINE', 'SEMI', 'EOF'"),s++}}var U0=4,SI=300;function ql(e,t){return e.quadrantChart?.[t]}function rs(e,t,n,r){let i=ql(e,t);return typeof i=="number"&&i>=0?Math.min(i,r):n}function Na(e,t,n){let r=ql(e,t);return typeof r=="number"&&Number.isFinite(r)?Math.min(72,Math.max(4,r)):n}function G0(e){return e.startsWith("#")?e:"#"+e}function Y0(e,t,n){let r=n.fontSize??16,i=Na(t,"titleFontSize",r),s=Na(t,"quadrantLabelFontSize",r),a=Na(t,"xAxisLabelFontSize",Math.round(r*.875)),o=Na(t,"yAxisLabelFontSize",Math.round(r*.875)),c=Na(t,"pointLabelFontSize",Math.round(r*.75)),l=(P,ee)=>P===ee?"":` font-size="${P}"`,u=n.measurer??ct(n.fontFamily,n.fontFamilyMono),h=Math.round(Math.max(100,rs(t,"chartWidth",500,4e3))),d=Math.round(gs(n,h,280)),m=Math.round(Math.max(100,rs(t,"chartHeight",500,4e3))*d/h),p=rs(t,"quadrantPadding",n.padding??8,200),y=rs(t,"xAxisLabelPadding",5,200),E=rs(t,"yAxisLabelPadding",5,200),b=e.points.length>0,S=(P,ee,ae)=>Ge(P?.text,P?.type==="markdown",u,ee,Math.max(ae,40)),x=Ge(e.title,!1,u,i,Math.max(d-2*p,40),1),I=rs(t,"titlePadding",10,200),L=x.height>0?x.height+I:0,O=!!(e.xAxisLeft?.text||e.xAxisRight?.text),v=!!(e.yAxisBottom?.text||e.yAxisTop?.text),G=b||ql(t,"xAxisPosition")==="bottom",K=ql(t,"yAxisPosition")==="right",C=d-2*p,Z=S(e.xAxisLeft,a,e.xAxisRight?C/2-16:C),oe=S(e.xAxisRight,a,C/2-16),H=Math.max(Z.height,oe.height),z=O?H+y:0,M=m-2*p-L-z,T=S(e.yAxisBottom,o,e.yAxisTop?M/2-16:M),R=S(e.yAxisTop,o,M/2-16),_=Math.max(T.height,R.height),$=v?_+E:0,g=p+(K?0:$),N=p+L+(G?0:z),w=Math.max(0,C-$),A=Math.max(0,M),D=Math.max(0,(w-U0)/2),U=Math.max(0,(A-U0)/2),B=[g+D,N,g+w-D,N+A,g,N+U,g+w,N+A-U],F=(P,ee,ae,ue,ce)=>{for(let pe=P;pe=B[pe+2]||B[pe+1]>=B[pe+3])&&eeB[pe]&&aeB[pe+1])return!1;return!0},W=rs(t,"quadrantTextTopPadding",5,200),j="";for(let P=0;P<4;P++){let ee=P===0||P===3?g+w-D:g,ae=P<2?N:N+A-U,ue=S(e.quadrants[P],s,D-16),ce=ee+D/2,pe=b?ae+W+ue.height/2:ae+U/2;B.push(ce-ue.width/2,pe-ue.height/2,ce+ue.width/2,pe+ue.height/2),j+=``+Ne(ue,ce,pe,` class="pele-label"${l(s,r)} fill="var(--_fg)" stroke="none"`)+""}let Q="";if(O){let P=G?N+A+y+H/2:N-y-H/2;Q+=Ne(Z,oe.height>0?g+w/4:g+Z.width/2,P,"")+Ne(oe,g+w*3/4,P,"")}if(v){let P=K?g+w+E+_/2:g-E-_/2,ee=(ae,ue)=>ae.height>0?`${Ne(ae,0,0,"")}`:"";Q+=ee(T,R.height>0?N+A*3/4:N+A-T.width/2)+ee(R,N+A/4)}let Y=rs(t,"pointRadius",5,200),ne=rs(t,"pointTextPadding",5,200),q=Et(0),k=[],J=[];for(let P of e.points){if(!(P.x>=0&&P.x<=1&&P.y>=0&&P.y<=1))continue;let ee=e.classes.get(P.className),ae=Math.min(P.radius??ee?.radius??Y,2e3),ue=P.color??ee?.color,ce=P.strokeColor??ee?.strokeColor,pe=P.strokeWidth??ee?.strokeWidth,V=[];ue&&V.push("fill:"+G0(ue)),pe&&(ce&&V.push("stroke:"+G0(ce)),V.push("stroke-width:"+pe));let X=g+P.x*w,le=N+(1-P.y)*A;k.push({cx:X,cy:le,reach:ae+(pe?Math.min(parseInt(pe),400)/2:0),text:S(P.text,c,w)}),J.push(``)}let te=k.length<=SI;if(te)for(let{cx:P,cy:ee,reach:ae}of k)B.push(P-ae,ee-ae,P+ae,ee+ae);let se="";for(let{cx:P,cy:ee,reach:ae,text:ue}of k){let ce=ue.width/2,pe=ue.size*.6+(ue.height-ue.lineHeight)/2,V=ae+ne,X=Math.min(V,Math.max(0,(D-ue.width)/2)),le=8+4*(Pg+w||ie-peN+A)continue;let me=!te||F(Ce<10?0:8,Ae-ce,ie-pe,Ae+ce,ie+pe);if((!Me||me)&&(_e=Ae,xe=ie,Me=!0),me)break}te&&B.push(_e-ce,xe-pe,_e+ce,xe+pe),se+=Ne(ue,_e,xe,' class="pele-label"')}let re=Ne(x,d/2,I/2+x.height/2,` class="pele-title"${l(i,r)} font-weight="var(--_tw)"`)+`${j}`+(Q?`${Q}`:"")+(k.length>0?`${J.reverse().join("")}${se}`:"");return{svg:at("quadrantChart",d,m,r,n,e,re),width:d,height:m,links:[]}}var H0={type:"quadrantChart",parse(e,t,n){let r=new jl;return r.title=n,W0(e,r),r},render:Y0};var K0=32;function z0(e){return new Qe(e,"semantic",{type:"radar"})}function V0(e,t){let n=e.axes.map(s=>({name:s.name,label:s.label??s.name})),r=e.curves.map(s=>{let a;if(s.entries[0].axis===void 0)a=s.entries.map(o=>o.value);else{if(n.length===0)throw z0("Axes must be populated before curves for reference entries");let o=new Map;for(let c of s.entries)c.axis!==void 0&&!o.has(c.axis.$refText)&&o.set(c.axis.$refText,c.value);a=n.map(c=>{let l=o.get(c.name);if(l===void 0)throw z0("Missing entry for axis "+c.label);return l})}return{name:s.name,label:s.label??s.name,entries:a}}),i={showLegend:!0,ticks:5,max:null,min:0,graticule:"circle"};for(let s of e.options)s.name==="showLegend"?i.showLegend=s.value:s.name==="graticule"?i.graticule=s.value:i[s.name]=s.value;return i.ticks>K0&&(i.ticks=K0),{type:"radar",title:e.title||t,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,` +`):void 0,axes:n,curves:r,options:i}}var Ph=0,Ql=0;function j0(e,t){let n=t;for(let r=e.charCodeAt(n);r>=48&&r<=57;r=e.charCodeAt(n))n++;return n}function wI(e,t){(t=Ql)&&(Ph=t,Ql=j0(e,t));let n=Ql;if(n===t)return-1;let r=e.charCodeAt(n)===46;if(r){let i=j0(e,n+1),s=i-n-1;if(s>0&&e.charCodeAt(i)!==46)return i;if(s>1)return i-1}return e.charCodeAt(t)===48?t+1:r?n-1>t?n-1:-1:n}var Dh=sn.pattern,vh=/[\t ]*accDescr\s*{/y,Zl=-2;function _I(e,t){return vh.lastIndex=t,vh.test(e)&&(Zl===-2&&(Zl=e.lastIndexOf("}")),vh.lastIndex>Zl)?-1:(Dh.lastIndex=t,Dh.test(e)?Dh.lastIndex:-1)}var Fh={name:"ID",pattern:/[\w]([-\w]*\w)?/y},X0=/[-\w]*\w/y;function q0(e,t){return(n,r,i)=>{if(e.lastIndex=r,!e.test(n))return-1;let s=e.lastIndex;return i===t?s:(X0.lastIndex=s,X0.test(n)?-1:s)}}var li=e=>({name:e,pattern:e,longer:[Fh]}),di=e=>({name:e,pattern:e}),Q0=[di("radar-beta:"),{...Jt("radar-beta"),longer:[Fh]},li("showLegend"),li("graticule"),li("curve"),li("ticks"),li("axis"),li("max"),li("min"),di(":"),di(","),di("["),di("]"),di("{"),di("}"),{name:"GRATICULE",pattern:/circle|polygon/y,match:q0(/circle|polygon/y,3)},{name:"BOOLEAN",pattern:/true|false/y,match:q0(/true|false/y,2)},{...sn,match:_I},Xt,er(String.raw`[-\w]*\w`),{name:"NUMBER",pattern:/(?:[0-9]+\.[0-9]+(?!\.))|(?:0|[1-9][0-9]*(?!\.))/y,match:wI},Fn,Fh,Sn,wn,Ht,Qt,Zt];function RI(e){return Ph=Ql=0,Zl=-2,Yt(e,Q0,"radar")}function Z0(e){let t=new Ut(RI(e),Q0,"radar"),n={$type:"Radar",axes:[],curves:[],options:[]},r=()=>{for(;t.kind===23;)t.i++},i=()=>{t.kind!==-1&&(t.kind!==23&&t.fail("a line break or the end of input"),r())},s=()=>{if(!t.accept(11))return;let h=un(t.expect(21));return t.expect(12),h},a=h=>{if(!h)return{$type:"Entry",value:Number(t.expect(20))};let d={$refText:t.expect(22)};return t.accept(9),{$type:"Entry",axis:d,value:Number(t.expect(20))}},o=()=>{let h=t.expect(22),d=s(),m={$type:"Curve",name:h,entries:[]};d!==void 0&&(m.label=d),t.expect(13),r(),t.kind!==20&&t.kind!==22&&t.fail("a number or an axis name");let p=t.kind===22;for(m.entries.push(a(p));t.accept(10);)r(),m.entries.push(a(p));return r(),t.expect(14),m},c=()=>{let h={$type:"Axis",name:t.expect(22)},d=s();return d!==void 0&&(h.label=d),h},l=()=>{let h=t.kind,d=t.take(),m;return h===2?m=t.expect(16)==="true":h===3?m=t.expect(15):m=Number(t.expect(20)),{$type:"Option",name:d,value:m}},u=()=>t.kind===2||t.kind===5||t.kind===7||t.kind===8||t.kind===3;for(r(),t.accept(0)||(t.expect(1),t.accept(9)),r();t.kind!==-1;)switch(t.kind){case 23:t.i++;break;case 17:n.accDescr=Vt(t.take()),i();break;case 18:n.accTitle=zt(t.take()),i();break;case 19:n.title=Kt(t.take()),i();break;case 6:t.i++;do n.axes.push(c());while(t.accept(10));break;case 4:t.i++;do n.curves.push(o());while(t.accept(10));break;default:for(u()||t.fail("an axis, a curve, an option, a title, or a line break"),n.options.push(l());t.accept(10);)u()||t.fail("an option"),n.options.push(l())}return n}var co=12,Bh=26,J0=24;function ss(e,t,n,r,i){let s=e.radar?.[t];return typeof s=="number"&&s>=r?Math.min(s,i):n}function TI(e,t,n,r){let i=Math.min(Math.max(e,t),n),s=r*(i-t);return Number.isFinite(s)?s/(n-t):r*((i-t)/(n-t))}function MI(e,t){let n=e.length,r=`M${f(e[0].x)},${f(e[0].y)}`;for(let i=0;iCI(e,t,n,i,ss(t,"height",320,1,4e3)*i/r,s))}function CI(e,t,n,r,i,s){let a=n.fontSize??16,o=Math.round(a*.875),c=n.measurer??ct(n.fontFamily,n.fontFamilyMono),l=n.padding??8,u=ss(t,"axisScaleFactor",1,0,10),h=ss(t,"axisLabelFactor",1.05,0,10),d=ss(t,"curveTension",.17,0,1),m=Math.min(r,i)/2,{axes:p,curves:y}=e,{ticks:E,graticule:b,min:S}=e.options,x=p.length,I=p.map((F,W)=>{let j=2*Math.PI*W/x-Math.PI/2;return{x:Math.cos(j),y:Math.sin(j)}}),L=e.options.max;if(L===null){L=-1/0;for(let F of y)for(let W of F.entries)W>L&&(L=W)}let O=-r/2-ss(t,"marginLeft",16,0,2e3),v=r/2+ss(t,"marginRight",16,0,2e3),G=-i/2-ss(t,"marginTop",16,0,2e3),K=i/2+ss(t,"marginBottom",16,0,2e3),C="";for(let F=0;F`:C+=``}let Z="",oe="";I.forEach((F,W)=>{let j=m*u;Z+=`M0,0L${f(F.x*j)},${f(F.y*j)}`;let Q=Ge(p[W].label,!1,c,o,4e3),Y=m*h+6,ne=F.x*Y+(F.x>.01?Q.width/2:F.x<-.01?-Q.width/2:0),q=F.y*Y+(F.y>.01?Q.height/2:F.y<-.01?-Q.height/2:0);oe+=`${Ne(Q,ne,q,"")}`,O=Math.min(O,ne-Q.width/2),v=Math.max(v,ne+Q.width/2),G=Math.min(G,q-Q.height/2),K=Math.max(K,q+Q.height/2)});let H="";y.forEach((F,W)=>{if(F.entries.length!==x)return;let j=F.entries.map((ne,q)=>{let k=TI(ne,S,L,m),J=Number.isFinite(k)?k:0;return{x:I[q].x*J,y:I[q].y*J}}),Q=Et(W),Y=` class="pele-curve" data-id="${Ue(F.name)}" fill="${Q}" stroke="${Q}"`;H+=b==="circle"?``:``});let z=e.options.showLegend?y.map(F=>Ge(F.label,!1,c,o,4e3)):[],M=0;for(let F of z)M=Math.max(M,F.width);let T=z.length*Bh,R=s?-(co+8+M)/2:v+J0,_=s?K+J0/2:-T/2;z.length>0&&s?(O=Math.min(O,R),v=Math.max(v,-R),K=_+T):z.length>0&&(v=R+co+8+M,G=Math.min(G,-T/2),K=Math.max(K,T/2));let $="";z.forEach((F,W)=>{let j=_+W*Bh+Bh/2,Q=Et(W);$+=``+Ne(F,R+co+8+F.width/2,j,"")+""});let g=Ge(e.title,!1,c,a,kt(n),1),N=g.height>0?g.height+8:0,w=Math.max(v-O,g.width),A=Math.ceil(w+2*l),D=Math.ceil(K-G+N+2*l),U=`translate(${f(l+(w-(v-O))/2-O)},${f(l+N-G)})`,B=Ne(g,A/2,l+g.height/2,' class="pele-title" font-weight="var(--_tw)"')+``+(C?`${C}`:"")+(Z?``:"")+(H?`${H}`:"")+(oe?`${oe}`:"")+($?`${$}`:"")+"";return{svg:at("radar",A,D,a,n,e,B),width:A,height:D,links:[]}}var nx={type:"radar",parse:(e,t,n)=>V0(Z0(e),n),render:tx};function Wh(e){return e===32||e>=9&&e<=13||e>127&&/\s/.test(String.fromCharCode(e))}function NI(){let e=1/0;return(t,n)=>{if(!t.startsWith("accDescr",n))return-1;let r=t.length,i=n+8;for(;i=e)return-1;let s=t.indexOf("}",i+1);return s===-1&&(e=i),s+1||-1}}var Uh="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function Rs(e){return{name:"TITLE",pattern:new RegExp(String.raw`title(?:[\t ][^\n\r]*?(?=%%)|[\t ][^\n\r]*|(?!${e}))`,"y"),first:"t"}}var Ts={name:"ACC_TITLE",pattern:/accTitle[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)/y,first:"a"},Ms={name:"ACC_DESCR",pattern:/accDescr(?:[\t ]*:([^\n\r]*?(?=%%)|[^\n\r]*)|\s*{([^}]*)})/y,first:"a",scanner:NI};function St(e,t){return{name:e,pattern:e,longer:t}}function Cs(e,t){return{...Jt(e),longer:[t]}}function lo(e){return{name:e,pattern:/[A-Z_a-z][\w-]*/y,first:Uh+"_"}}function uo(e){return{name:e,pattern:/"([^"\\]|\\.)*"|'([^'\\]|\\.)*'/y,first:`"'`}}function Ns(e){return[{name:e+"_WHITESPACE",pattern:/[\t \r\n]+/y,hidden:!0,first:` \r +`},{...Ht,name:e+"_YAML",first:"-"},{...Qt,name:e+"_DIRECTIVE",first:" %"},{...Zt,name:e+"_SINGLE_LINE_COMMENT",first:" %"}]}function is(e){if(!e.includes("\\"))return e.slice(1,-1);let t=e.length-1,n="";for(let r=1;r({type:"terminal",value:e}),ks=e=>({type:"nonterminal",name:e}),ui=e=>({type:"special",text:e}),Gr=e=>({type:"optional",element:e}),as=(e,t,n=1/0)=>({type:"repetition",element:e,min:t,max:n});function $s(e){return e.length===1?e[0]:{type:"sequence",elements:e}}function Ls(e){return e.length===1?e[0]:{type:"choice",alternatives:e}}function Os(e,t){return e.rules.map(n=>({name:n.name,definition:Yh(n.definition,Jl,t)}))}function Yh(e,t,n){let r=[e],i=[t(e)],s=[[]];for(;;){let a=r.length-1,o=s[a];if(o.lengtht.slice(1,-1),t=>{let n=t.expect(11);t.expect(1);let r=II(t);return t.expect(2),{$type:"AbnfRule",name:n,definition:r}})}function kI(e,t){switch(e.$type){case"AbnfAlternation":return Ls(t);case"AbnfConcatenation":return $s(t);case"AbnfElement":{let n=e.repeat;if(!n)return t[0];let r=n.indexOf("*"),i=r===-1,s=r>0||i?parseInt(n,10):0,a=i?s:rOs(e,kI);function $I(e,t){if(e.charCodeAt(t)!==63)return-1;let n=!1;for(let r=t+1;r$I},fx=Ns("EBNF"),hx={name:"EBNF_ISO_COMMENT",pattern:/\(\*[\s\S]*?\*\)/y,hidden:!0,first:"(",opener:/\(\*/y},mx=[Cs("railroad-ebnf-beta",dx),St("::="),St("="),St(";"),St("|"),St(","),St("(",[hx]),St(")"),St("["),St("]"),St("{"),St("}"),St("?",[ux]),St("*"),St("+"),St("-",[fx[1]]),Rs(String.raw`[\w-]`),Ts,Ms,dx,uo("EBNF_STRING"),ux,...fx,{name:"EBNF_BLOCK_COMMENT",pattern:/\/\*[\s\S]*?\*\//y,hidden:!0,first:"/",opener:/\/\*/y},hx];function px(e,t,n,r){let i={$type:"EbnfSequence",elements:[]};return t.alternatives.push(i),{choice:t,sequence:i,term:void 0,node:e,close:n,except:r}}var LI=["EbnfGroup","EbnfOptional","EbnfRepetition"];function OI(e){let t=[],n=px(void 0,{$type:"EbnfChoice",alternatives:[]},-2,!1),r=!1;for(;;){let i,s=e.kind;switch(s){case 20:i={$type:"EbnfTerminal",value:is(e.take())};break;case 19:i={$type:"EbnfNonTerminal",name:e.take()};break;case 21:i={$type:"EbnfSpecial",text:e.take().slice(1,-1).trim()};break;case 6:case 8:case 10:{e.i++;let a={$type:"EbnfChoice",alternatives:[]};t.push(n),n=px({$type:LI[s-6>>1],element:a},a,s+1,r),r=!1;continue}default:e.fail("a terminal, a name, or an opening bracket")}for(;;){r?(n.term.postfixes.push({$type:"EbnfExceptionPostfix",except:i}),r=!1):(n.term={$type:"EbnfTerm",base:i,postfixes:[]},n.sequence.elements.push(n.term));let a=n.term.postfixes;for(;;){let c=e.kind;if(c===12)a.push({$type:"EbnfOptionalPostfix",operator:e.take()});else if(c===13)a.push({$type:"EbnfZeroOrMorePostfix",operator:e.take()});else if(c===14)a.push({$type:"EbnfOneOrMorePostfix",operator:e.take()});else break}let o=e.kind;if(o===n.close){e.i++,i=n.node,r=n.except,n=t.pop();continue}if(o===15)e.i++,r=!0;else if(o===5)e.i++;else if(o===4)e.i++,n.sequence={$type:"EbnfSequence",elements:[]},n.choice.alternatives.push(n.sequence);else if(o!==20&&o!==19&&o!==21&&o!==6&&o!==8&&o!==10){if(t.length===0)return n.choice;e.fail(`token of type '${mx[n.close].name}'`)}break}}}function gx(e){return Is(e,mx,"RailroadEbnf",16,is,t=>{let n=t.expect(19);t.accept(2)||t.expect(1);let r={$type:"EbnfRule",name:n,definition:OI(t)};return t.expect(3),r})}function DI(e,t){switch(e.$type){case"EbnfChoice":return Ls(t);case"EbnfSequence":return $s(t);case"EbnfTerm":{let n=t[0],r=1;for(let i of e.postfixes)i.$type==="EbnfOptionalPostfix"?n=Gr(n):i.$type==="EbnfExceptionPostfix"?n={type:"sequence",elements:[n,os("-"),t[r++]]}:n=as(n,i.$type==="EbnfOneOrMorePostfix"?1:0);return n}case"EbnfTerminal":return os(e.value);case"EbnfNonTerminal":return ks(e.name);case"EbnfSpecial":return ui(e.text);case"EbnfGroup":return t[0];case"EbnfOptional":return Gr(t[0]);case"EbnfRepetition":return as(t[0],0)}}var bx=e=>Os(e,DI);var zh=lo("RR_ID"),Ds=e=>St(e,[zh]),vI=[Cs("railroad-beta",zh),Ds("nonterminal"),Ds("zeroOrMore"),Ds("oneOrMore"),Ds("sequence"),Ds("optional"),Ds("terminal"),Ds("special"),Ds("choice"),St("="),St(";"),St("("),St(","),St(")"),Rs(String.raw`[\w-]`),Ts,Ms,zh,uo("RR_STRING"),...Ns("RR"),{name:"RR_BLOCK_COMMENT",pattern:/\/\*[\s\S]*?\*\//y,hidden:!0,first:"/",opener:/\/\*/y}];function Hh(e){e.i++,e.expect(11);let t=is(e.expect(18));return e.expect(13),t}function Kh(e){return{$type:e,element:void 0}}function PI(e){let t=[];for(;;){let n;switch(e.kind){case 6:n={$type:"RailroadTerminalExpr",value:Hh(e)};break;case 1:n={$type:"RailroadNonTerminalExpr",name:Hh(e)};break;case 7:n={$type:"RailroadSpecialExpr",text:Hh(e)};break;case 4:n={$type:"RailroadSequenceExpr",elements:[]};break;case 8:n={$type:"RailroadChoiceExpr",alternatives:[]};break;case 5:n=Kh("RailroadOptionalExpr");break;case 3:n=Kh("RailroadOneOrMoreExpr");break;case 2:n=Kh("RailroadZeroOrMoreExpr");break;default:e.fail("an expression")}if("elements"in n||"alternatives"in n||"element"in n){e.i++,e.expect(11),t.push(n);continue}for(;;){let r=t[t.length-1];if(r===void 0)return n;if("element"in r)r.element=n;else if(("elements"in r?r.elements:r.alternatives).push(n),e.accept(12))break;e.expect(13),t.pop(),n=r}}}function yx(e){return Is(e,vI,"Railroad",14,is,t=>{let n=t.expect(17);t.expect(9);let r=PI(t);return t.expect(10),{$type:"RailroadRule",name:n,definition:r}})}function FI(e,t){switch(e.$type){case"RailroadTerminalExpr":return os(e.value);case"RailroadNonTerminalExpr":return ks(e.name);case"RailroadSpecialExpr":return ui(e.text);case"RailroadSequenceExpr":return $s(t);case"RailroadChoiceExpr":return Ls(t);case"RailroadOptionalExpr":return Gr(t[0]);default:return as(t[0],e.$type==="RailroadOneOrMoreExpr"?1:0)}}var Ex=e=>Os(e,FI);var xx=lo("PEG_ID"),BI=[Cs("railroad-peg-beta",xx),St("<-"),St(";"),St("/"),St("&"),St("!"),St("?"),St("*"),St("+"),St("("),St(")"),St("."),Rs(String.raw`[\w-]`),Ts,Ms,xx,uo("PEG_STRING"),...Ns("PEG"),{name:"PEG_LINE_COMMENT",pattern:/#[^\n\r]*/y,hidden:!0,first:"#"}];function Ax(e,t,n){let r={$type:"PegSequence",elements:[]};return t.alternatives.push(r),{choice:t,sequence:r,node:e,operator:n}}function WI(e){let t=[],n=Ax(void 0,{$type:"PegOrderedChoice",alternatives:[]},void 0);for(;;){let r=e.kind===4||e.kind===5?e.take():void 0,i;switch(e.kind){case 16:i={$type:"PegLiteral",value:is(e.take())};break;case 15:i={$type:"PegIdentifier",name:e.take()};break;case 11:i={$type:"PegAny",dot:e.take()};break;case 9:{e.i++;let a={$type:"PegOrderedChoice",alternatives:[]};t.push(n),n=Ax({$type:"PegGroup",element:a},a,r);continue}default:e.fail("a literal, a name, a dot, or an opening parenthesis")}for(;;){let a={$type:"PegSuffix",primary:i};(e.kind===6||e.kind===7||e.kind===8)&&(a.operator=e.take()),n.sequence.elements.push(r===void 0?{$type:"PegPrefix",suffix:a}:{$type:"PegPrefix",operator:r,suffix:a});let o=e.kind;if(o===10&&t.length>0){e.i++,i=n.node,r=n.operator,n=t.pop();continue}if(o===3)e.i++,n.sequence={$type:"PegSequence",elements:[]},n.choice.alternatives.push(n.sequence);else if(o!==4&&o!==5&&o!==16&&o!==15&&o!==11&&o!==9){if(t.length===0)return n.choice;e.fail("token of type ')'")}break}}}function Sx(e){return Is(e,BI,"RailroadPeg",12,is,t=>{let n=t.expect(15);t.expect(1);let r={$type:"PegRule",name:n,definition:WI(t)};return t.expect(2),r})}function UI(e){switch(e.type){case"terminal":return`"${e.value}"`;case"nonterminal":return e.name;case"special":return e.text;default:return"(...)"}}function GI(e,t){let n=t[0];switch(e.$type){case"PegOrderedChoice":return Ls(t);case"PegSequence":return $s(t);case"PegPrefix":return e.operator?ui(e.operator+UI(n)):n;case"PegSuffix":return e.operator?e.operator==="?"?Gr(n):as(n,e.operator==="+"?1:0):n;case"PegLiteral":return os(e.value);case"PegIdentifier":return ks(e.name);case"PegAny":return ui(e.dot);case"PegGroup":return n}}var wx=e=>Os(e,GI);var Vh=class{constructor(){fe(this,"type","railroad");fe(this,"notation","railroad");fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"rules",[]);fe(this,"byName",new Map)}setTitle(t){this.title=t}setAccTitle(t){this.accTitle=t.replace(/^\s+/g,"")}setAccDescription(t){this.accDescr=t.replace(/\n\s+/g,` +`)}addRule(t){this.rules.push(t),this.byName.set(t.name,t)}getRule(t){return this.byName.get(t)}},YI=/^\s*railroad-(ebnf-|abnf-|peg-)?beta/i;function HI(e){let t=YI.exec(e);if(t===null)return;let n=t[1]?.toLowerCase();return n==="ebnf-"?"ebnf":n==="abnf-"?"abnf":n==="peg-"?"peg":"railroad"}function KI(e,t){switch(t){case"ebnf":{let n=gx(e);return[n,bx(n)]}case"abnf":{let n=cx(e);return[n,lx(n)]}case"peg":{let n=Sx(e);return[n,wx(n)]}default:{let n=yx(e);return[n,Ex(n)]}}}function zI(e,t,n){let[r,i]=KI(t,n);e.notation=n,r.accDescr&&e.setAccDescription(r.accDescr),r.accTitle&&e.setAccTitle(r.accTitle),r.title&&e.setTitle(r.title);for(let s of i)e.addRule(s)}function _x(e,t){let n=HI(e);if(n===void 0)throw new Qe("No railroad diagram keyword found.","syntax",{type:"railroad"});let r=new Vh;return t&&(r.title=t),zI(r,e,n),r}var jh=12,VI=6,jI=18,nd=12,Er=7;function fi(e,t,n,r){let i=e.railroad?.[t];return typeof i=="number"&&i>=0?Math.min(i,r):n}var XI=/[\n\r\t]/g;function td(e){return(e.includes("¶ß")?bt(e.replace(/&/g,"&")):e).replace(XI,n=>n===` +`?"\\n":n==="\r"?"\\r":"\\t")}function ed(e,t){for(let n=t,r=e.length-1;nNumber.isFinite(r)?String(r):"∞";return e===t?n(e)+"×":t===1/0?"≥"+n(e)+"×":e===0?"≤"+n(t)+"×":n(e)+"–"+n(t)+"×"}function Tx(e,t,n,r){return Math.max(e+t.down+r.sep+n.up,2*r.arc)}function Rx(e,t){let n=Math.max(e.up+t.sep,2*t.arc);return{kind:5,width:e.width+4*t.arc,up:n,down:e.down,kids:[e],text:"",id:"",reach:n}}function QI(e,t,n=1/0){let r=new Map,i=[[e,n]];for(let s=0;n!==1/0&&s{let o=r.get(s)??1/0;switch(s.type){case"terminal":{let c=td(s.value);return Xh(0,/^ +$/.test(c)?"␣".repeat(c.length):c,"",4,t)}case"nonterminal":return Xh(1,td(s.name),s.name,0,t);case"special":return Xh(2,"? "+td(s.text)+" ?","",2,t);case"sequence":{let c=Math.max(0,a.length-1)*t.gap,l=0,u=0;for(let S of a)c+=S.width,l=Math.max(l,S.up),u=Math.max(u,S.down);let h={kind:3,width:c,up:l,down:u,kids:a,text:"",id:"",reach:0};if(c<=o||a.length<2)return h;let d=[],m=[],p=0,y=()=>{let S=0,x=0;for(let I of m)S=Math.max(S,I.up),x=Math.max(x,I.down);d.push({kind:3,width:p,up:S,down:x,kids:m,text:"",id:"",reach:0}),m=[],p=0};for(let S of a)m.length&&p+t.gap+S.width>Math.max(40,o-6*t.arc)&&y(),p+=(m.length?t.gap:0)+S.width,m.push(S);if(y(),d.length<2)return h;let E=0,b=0;for(let S=0;S0&&(l=Tx(l,a[h-1],a[h],t));let u=a[a.length-1];return{kind:4,width:c+4*t.arc,up:a.length>0?a[0].up:0,down:u?l+u.down:0,kids:a,text:"",id:"",reach:0}}case"optional":return Rx(a[0],t);case"repetition":{let{min:c,max:l}=s,u=a[0];if(c===1&&l===1)return u;let h=qI(c,l),d=Math.max(u.down+t.sep,2*t.arc),m=h===""?0:qh(t.measurer.width(h,nd,0)),p={kind:6,width:Math.max(u.width,m)+2*t.arc,up:u.up,down:d+(h===""?Er/2+1:nd+6),kids:[u],text:h,id:"",reach:d};return c===0?Rx(p,t):p}}})}function Mx(e,t,n){return An(n,r=>ZI(e,t,n,r))}function ZI(e,t,n,r){let i=n.fontSize??16,s=fi(t,"fontSize",0,200),a=s||Math.round(i*.875),o=s||i,c=fi(t,"padding",-1,200),l=Math.round(a*1.5),u={measurer:n.measurer??ct(n.fontFamily,n.fontFamilyMono),size:a,padding:c<0?12:c,height:qh(l+(c<0?9:2*c)),gap:Math.min(fi(t,"horizontalSeparation",16,500),r?12:1/0),sep:fi(t,"verticalSeparation",10,500),arc:Math.min(fi(t,"arcRadius",10,200),r?6:1/0)},h=t.railroad?.showMarkers===!1?0:fi(t,"markerRadius",4,50),d=fi(t,"strokeWidth",0,20),m=d>0?` stroke-width="${f(d)}"`:"",p=n.padding??8,{arc:y}=u,E=f(y),b=(U,B,F)=>`a${E},${E} 0 0 ${U} ${B}${E},${F}${E}`,S=b(1,"",""),x=b(0,"",""),I=b(0,"","-"),L=b(1,"","-"),O=b(0,"-",""),v=b(0,"-","-"),G=Ge(e.title,!1,u.measurer,i,r?kt(n):4e3,1),K=G.height>0?G.height+16:0,C=Math.round(o*1.5),Z=a*.35,oe=u.height/2,H="",z="",M="",T=(U,B,F)=>{F>U&&(H+=`M${f(U)},${f(B)}H${f(F)}`)},R=(U,B,F)=>{let W=[U],j=[B,F];for(;W.length>0;){let Q=W.pop(),Y=j.pop(),ne=j.pop(),q=Q.kids,k=ne+Q.width;switch(Q.kind){case 3:{let J=k;for(let te=q.length-1;te>=0;te--)J-=q[te].width,W.push(q[te]),j.push(J,Y),te>0&&T(J-u.gap,Y,J),J-=u.gap;break}case 7:{let J=ne+2*y,te=W.length,se=0;T(ne,Y,J);for(let re=0;re0&&(P=Tx(P,q[ee-1],ae,u));let ue=Y+P,ce=ne+2*y+(J-ae.width)/2,pe=ee===q.length-1;ee===0?(T(ne,Y,ce),T(ce+ae.width,Y,k)):H+=(pe?`M${f(ne)},${f(Y)}${S}V${f(ue-y)}`:`M${f(te)},${f(ue-y)}`)+x+(ce>te+y?`H${f(ce)}`:"")+`M${f(ce+ae.width)},${f(ue)}`+(ce>te+y?`H${f(se-y)}`:"")+I+(pe?`V${f(Y+y)}${L}`:""),W.push(ae),j.push(ue,ce)}ed(W,re),ed(j,2*re);break}case 5:{let J=q[0],te=ne+2*y;T(ne,Y,te),T(te+J.width,Y,k),H+=`M${f(ne)},${f(Y)}${I}V${f(Y-Q.reach+y)}${L}H${f(k-2*y)}${S}V${f(Y-y)}${x}`,W.push(J),j.push(te,Y);break}case 6:{let J=q[0],te=ne+(Q.width-J.width)/2,se=Y+Q.reach,re=ne+Q.width/2;T(ne,Y,te),T(te+J.width,Y,k),H+=`M${f(ne+y)},${f(Y)}${O}V${f(se-y)}${x}H${f(k-y)}${I}V${f(Y+y)}${v}`,z+=`M${f(re-Er/2)},${f(se)}l${Er},${-Er/2}v${Er}z`,Q.text!==""&&(M+=`${rt(Q.text)}`),W.push(J),j.push(te,Y);break}default:{let J=Q.text,te=J.startsWith(" ")||J.endsWith(" ")||J.includes(" ")?' xml:space="preserve"':"",se=`${se} rx="${f(oe)}" fill="var(--_s)" stroke="var(--_b)"${m}/>${re} font-family="${fr}">${rt(J)}`:Q.kind===1?M+=`${se} fill="var(--_bg)" stroke="var(--_b)"${m}${ht}/>${re}>${rt(J)}`:M+=`${se} fill="var(--_bg)" stroke="var(--_b)" stroke-dasharray="4 3"${m}${ht}/>${re} font-style="italic">? ${rt(J.slice(2,-2))} ?`}}}},_="",$=G.width,g=p+K,N=p+G.height;for(let U of e.rules){let B=QI(U.definition,u,r?Math.max(80,(n.maxWidth??320)-2*p-4*h-2*jh-1):1/0),F=td(U.name),W=g+C+VI+B.up,j=p+2*h,Q=j+jh,Y=Q+B.width+jh;H="",z="",M="",T(j,W,Q),T(Q+B.width,W,Y),R(B,Q,W);let ne=h>0?``:"";_+=`${rt(F)}`+(z?``:"")+ne+M+"",$=Math.max($,Y+2*h-p,u.measurer.width(F,o,1)),N=W+B.down,g=N+u.sep+jI}let w=Math.ceil($+2*p),A=Math.ceil(N+p),D=Ne(G,w/2,p+G.height/2,' class="pele-title" font-weight="var(--_tw)"')+(_?`${_}`:"");return{svg:at("railroad",w,A,i,n,e,D),width:w,height:A,links:[]}}var Cx={type:"railroad",parse:(e,t,n)=>_x(e,n),render:Mx};var hi={REQUIREMENT:"Requirement",FUNCTIONAL_REQUIREMENT:"Functional Requirement",INTERFACE_REQUIREMENT:"Interface Requirement",PERFORMANCE_REQUIREMENT:"Performance Requirement",PHYSICAL_REQUIREMENT:"Physical Requirement",DESIGN_CONSTRAINT:"Design Constraint"},sd={LOW_RISK:"Low",MED_RISK:"Medium",HIGH_RISK:"High"},Ia={VERIFY_ANALYSIS:"Analysis",VERIFY_DEMONSTRATION:"Demonstration",VERIFY_INSPECTION:"Inspection",VERIFY_TEST:"Test"},Yr={CONTAINS:"contains",COPIES:"copies",DERIVES:"derives",SATISFIES:"satisfies",VERIFIES:"verifies",REFINES:"refines",TRACES:"traces"},JI=1e6,rd=class{constructor(){fe(this,"type","requirement");fe(this,"direction","TB");fe(this,"requirements",new Map);fe(this,"elements",new Map);fe(this,"relations",[]);fe(this,"classes",new Map);fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"newId","");fe(this,"newText","");fe(this,"newRisk","");fe(this,"newVerifyMethod","");fe(this,"newElementType","");fe(this,"newDocRef","");fe(this,"styleCopies",0)}copy(t,n){if(this.styleCopies+=n.length,this.styleCopies>JI)throw new Qe("Requirement diagram applies too many style declarations.","limit",{type:"requirement"});for(let r of n)t.push(r)}setDirection(t){this.direction=t}addRequirement(t,n){let r=this.requirements.get(t);return r===void 0&&(r={name:t,type:n,requirementId:this.newId,text:this.newText,risk:this.newRisk,verifyMethod:this.newVerifyMethod,cssStyles:[],classes:["default"]},this.requirements.set(t,r)),this.newId=this.newText=this.newRisk=this.newVerifyMethod="",r}setNewReqId(t){this.newId=t}setNewReqText(t){this.newText=t}setNewReqRisk(t){this.newRisk=t}setNewReqVerifyMethod(t){this.newVerifyMethod=t}addElement(t){let n=this.elements.get(t);return n===void 0&&(n={name:t,type:this.newElementType,docRef:this.newDocRef,cssStyles:[],classes:["default"]},this.elements.set(t,n)),this.newElementType=this.newDocRef="",n}setNewElementType(t){this.newElementType=t}setNewElementDocRef(t){this.newDocRef=t}addRelationship(t,n,r){this.relations.push({type:t,src:n,dst:r})}node(t){return this.requirements.get(t)??this.elements.get(t)}setCssStyle(t,n){for(let r of t){let i=this.node(r);if(!n||!i)return;for(let s of n)this.copy(i.cssStyles,s.includes(",")?s.split(","):[s])}}setClass(t,n){for(let r of t){let i=this.node(r);if(i)for(let s of n){i.classes.push(s);let a=this.classes.get(s)?.styles;a&&this.copy(i.cssStyles,a)}}}defineClass(t,n){for(let r of t){let i=this.classes.get(r);i===void 0&&(i={id:r,styles:[],textStyles:[]},this.classes.set(r,i));for(let a of n)a.includes("color")&&i.textStyles.push(a.replace("fill","bgFill")),i.styles.push(a);let s=n.flatMap(a=>a.split(","));for(let a of this.requirements.values())a.classes.includes(r)&&this.copy(a.cssStyles,s);for(let a of this.elements.values())a.classes.includes(r)&&this.copy(a.cssStyles,s)}}setAccTitle(t){this.accTitle=t.replace(/^\s+/g,"")}setAccDescription(t){this.accDescr=t.replace(/\n\s+/g,` +`)}};var Qh=["$end","INVALID","title","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","direction_tb","direction_bt","direction_rl","direction_lr","NEWLINE","EOF","RD","STRUCT_START","STRUCT_STOP","STYLE_SEPARATOR","COLONSEP","ID","TEXT","RISK","VERIFYMTHD","REQUIREMENT","FUNCTIONAL_REQUIREMENT","INTERFACE_REQUIREMENT","PERFORMANCE_REQUIREMENT","PHYSICAL_REQUIREMENT","DESIGN_CONSTRAINT","LOW_RISK","MED_RISK","HIGH_RISK","VERIFY_ANALYSIS","VERIFY_DEMONSTRATION","VERIFY_INSPECTION","VERIFY_TEST","ELEMENT","CONTAINS","COPIES","DERIVES","SATISFIES","VERIFIES","REFINES","TRACES","TYPE","DOCREF","STYLE","CLASSDEF","CLASS","ALPHA","COLON","SEMICOLON","PERCENT","MINUS","BRKT","END_ARROW_L","END_ARROW_R","LINE","qString","unqString","COMMA"],Nx=new Map([["requirementdiagram",14],["id",19],["text",20],["risk",21],["verifymethod",22],["requirement",23],["functionalrequirement",24],["interfacerequirement",25],["performancerequirement",26],["physicalrequirement",27],["designconstraint",28],["low",29],["medium",30],["high",31],["analysis",32],["demonstration",33],["inspection",34],["test",35],["element",36],["contains",37],["copies",38],["derives",39],["satisfies",40],["verifies",41],["refines",42],["traces",43],["type",44],["docref",45],["style",46],["classdef",47],["class",48]]);var tk=/accTitle\s*:\s*/iy,nk=/accDescr\s*:\s*/iy,rk=/accDescr\s*\{\s*/iy,id=/direction\s+(?:(TB)|(BT)|(RL)|LR)/gi,Zh=/[\n\r\u2028\u2029]/g,sk=22,Ix=new Uint8Array(128);for(let e of`:,\r +{<>-=`)Ix[e.charCodeAt(0)]=1;function kx(e){let t=e.length,n=[],r=[],i=[],s=[],a=0,o=0,c=[[],[],[],[]],l=[[],[],[],[]],u=[0,0,0,0],h=!1,d=-1;id.lastIndex=0;for(let O=id.exec(e);O!==null;O=id.exec(e)){let v=O[1]!==void 0?0:O[2]!==void 0?1:O[3]!==void 0?2:3;c[v].push(O.index),l[v].push(id.lastIndex),h=!0}let m=(O,v,G)=>{n.push(O),r.push(e.slice(v,G)),i.push(v),o=G},p=O=>{s.push(a),a=O},y=()=>{s.length>0&&(a=s.pop())},E=(O,v)=>(O.lastIndex=v,O.test(e)?O.lastIndex:-1),b=O=>{let v=e.indexOf(` +`,O);return v===-1?t:v},S=()=>{if(d=0&&c[O][v]>=o)return m(8+O,o,b(l[O][v])),!0}return!1},x=O=>{let v=O|32;if(v===116&&e.slice(o+1,o+5).toLowerCase()==="itle"&&qe(e.charCodeAt(o+5))){let G=o+6;for(;Go+6)return m(2,o,G),!0}if(v===97&&(e.charCodeAt(o+1)|32)===99&&(e.charCodeAt(o+2)|32)===99){let G;if((G=E(tk,o))>=0)return p(3),m(3,o,G),!0;if((G=E(nk,o))>=0)return p(4),m(5,o,G),!0;if((G=E(rk,o))>=0)return p(5),o=G,!0}if(h&&!Us(O)&&S())return!0;if(O===10||O===13&&e.charCodeAt(o+1)===10){let G=o;for(;G{if(ot(O)){let v=o+1;for(;v{let I=n[s];if(I===1)throw ft("requirement",e,i[s],"",!0);for(let O=S;O>=b;O--)x.unshift(O);let L=x.map(O=>`'${Qh[O]}'`).join(", ");throw ft("requirement",e,i[s],`Expecting ${L}, got '${Qh[I]}'`)},l=b=>(n[s]!==b&&c(b),r[s++]),u=(b,S)=>{let x=n[s];return(xS)&&c(b,S),s++,ik[x-23]},h=()=>{let b=n[s];return b!==59&&b!==58&&c(58,59),r[s++]},d=()=>{let b=n[s];if(b===3)s++,t.setAccTitle(l(4).trim());else if(b===5)s++,t.setAccDescription(l(6).trim());else if(b===7)t.setAccDescription(r[s++].trim());else return!1;return!0},m=()=>{let b=[];for(;;){let S=n[s];if(S!==49&&S!==59&&S!==58&&c(58,59,49),b.push(r[s++]),n[s]!==60)return b;s++}},p=()=>{let b=[];for(;;){$x(n[s])||c(49,51,53,54);let S=r[s++];for(;$x(n[s]);)S+=r[s++];if(b.push(S),n[s]!==60)return b;s++}},y=()=>{let b;return n[s]===17?(s++,b=m(),l(15)):n[s]===15?s++:c(15,15,17),l(12),b},E=b=>{for(a.length=0,o.length=0;;){let S=n[s];if(S===16){s++;break}if(S===12){s++;continue}(b?S<19||S>22:S!==44&&S!==45)&&(b&&c(19,22,12,16),c(44,45,12,16)),s++,l(18),o.push(S===21?u(29,31):S===22?u(32,35):h()),a.push(S),l(12)}for(let S=a.length-1;S>=0;S--){let x=o[S];switch(a[S]){case 19:t.setNewReqId(x);break;case 20:t.setNewReqText(x);break;case 21:t.setNewReqRisk(x);break;case 22:t.setNewReqVerifyMethod(x);break;case 44:t.setNewElementType(x);break;default:t.setNewElementDocRef(x)}}};for(;d();)n[s]===12&&s++;for(n[s]!==14&&c(14,14,3,5,7),s++,l(12);;){let b=n[s];if(b===13)return;if(b===12)s++;else{if(d())continue;if(b>=8&&b<=11)s++,t.setDirection(b===8?"TB":b===9?"BT":b===10?"RL":"LR");else if(b>=23&&b<=28){let S=u(23,28),x=h(),I=y();E(!0),t.addRequirement(x,S),I&&t.setClass([x],I)}else if(b===36){s++;let S=h(),x=y();E(!1),t.addElement(S),x&&t.setClass([S],x)}else if(b===46){s++;let S=m();t.setCssStyle(S,p())}else if(b===47){s++;let S=m();t.defineClass(S,p())}else if(b===48){s++;let S=m();t.setClass(S,m())}else if(b===59||b===58){let S=r[s++],x=n[s];if(x===17)s++,t.setClass([S],m());else if(x===55||x===57){s++;let I=u(37,43);l(x===57?56:57);let L=h();x===57?t.addRelationship(I,S,L):t.addRelationship(I,L,S)}else c(17,17,55,57)}else c(12,13,3,5,7,8,9,10,11,23,24,25,26,27,28,36,47,48,46,59,58)}}}function Ox(e){let t=[];for(let i of e.requirements.values())t.push({id:i.name,requirement:i,element:void 0,cssStyles:i.cssStyles,cssClasses:i.classes.join(" ")});for(let i of e.elements.values())t.push({id:i.name,requirement:void 0,element:i,cssStyles:i.cssStyles,cssClasses:i.classes.join(" ")});let n=i=>e.requirements.has(i)||e.elements.has(i)?i:void 0,r=e.relations.map((i,s)=>({id:`${i.src}-${i.dst}-${s}`,start:n(i.src),end:n(i.dst),type:i.type,contains:i.type===Yr.CONTAINS}));return{nodes:t,edges:r,direction:e.direction}}var ok=40,ak=16,ck=56,od=14,ka=10,Jh=2,Dx=12,lk=120,dk=280,uk=240,ep=26,Bx=6,vx=9,ad=4.5,fk=28,hk=14;function cd(e,t,n){if(t===0||e.lines.length===0)return e;let r=0,i=[],s=e.lines.map(a=>{let o=0,c=a.map(l=>{let u=l.style|t,h=l.icon!==void 0||l.math?l.width:n.width(l.text,e.size,u);return o+=h,{...l,style:u,width:h}});return i.push(o),o>r&&(r=o),c});return{...e,lines:s,widths:i,width:r}}function Px(e,t,n,r){let i=Xr(e),s="",a="";for(let o=0;o${rt(d.text)}`,h=!1)}return(s===""?"":`${s}`)+a}function pk(e,t,n,r){let i=Bx,s=e-n*i,a=t-r*i;return``}function mk(e,t,n,r){let i=e-n*vx,s=t-r*vx;return``}function gk(e,t,n){let r=new Map;for(let i of t){let s=i.route;if(!(i.src===i.dst||s.length<6))for(let a of[0,s.length-3]){let o=a===0?i.src:i.dst,c=e[o],l=s[a]-c.x,u=s[a+1]-c.y,h=a===0?3:a-3,d;if(Math.abs(Math.abs(u)-c.h/2)<.5)d=u<0?0:2;else if(Math.abs(Math.abs(l)-c.w/2)<.5)d=l<0?3:1;else continue;let m=o*4+d,p={route:s,at:a,toward:s[d%2===0?h:h+1]},y=r.get(m);y?y.push(p):r.set(m,[p])}}for(let[i,s]of r){if(s.length<2)continue;let a=i>>2,o=i%2===1,c=(o?n[a].h:n[a].w)-2*hk,l=Math.max(0,Math.min(fk,c/(s.length-1)));s.sort((u,h)=>u.toward-h.toward);for(let u=0;uFx(e,t,n,r)):Fx(e,t,n,!1)}function Fx(e,t,n,r){let i=Ox(e),s=n.fontSize??16,a=Math.round(s*.875),o=n.measurer??ct(n.fontFamily,n.fontFamilyMono),c=n.padding??8,l=new Map,u=[],h=[];for(let z of i.nodes){let M=Ct(z.cssStyles),T=(M.bold?1:0)|(M.italic?2:0),R=M.fontSize??s,_=M.fontSize??a,$=z.requirement,g=z.element,N=cd(Ge(`«${$?$.type:"Element"}»`,!1,o,_,4e3),T,o),w=cd(Ge(z.id,!0,o,R,dk),T|1,o),A=$?[["ID",$.requirementId],["Text",$.text],["Risk",$.risk],["Verification",$.verifyMethod]]:[["Type",g.type],["Doc Ref",g.docRef]],D=[],U=0,B=0,F=0;for(let[Y,ne]of A){if(!ne)continue;let q=cd(Ge(Y,!1,o,_,4e3),T,o),k=cd(Ge(ne,!0,o,_,uk),T,o),J=Math.max(q.height,k.height);D.push({key:q,value:k,height:J}),U=Math.max(U,q.width),B=Math.max(B,k.width),F+=J+Jh}D.length>0&&(F+=2*ka-Jh);let W=2*ka+N.height+w.height,j=Math.max(lk,Math.max(N.width,w.width)+2*od,D.length>0?U+Dx+B+2*od:0);l.has(z.id)||l.set(z.id,u.length);let Q=Bt(j,W+F);Q.seq=u.length,u.push({node:z,style:M,kind:N,name:w,rows:D,keyWidth:U,headHeight:W,w:j,h:W+F}),h.push(Q)}let d=r?"TB":ln(i.direction),m=d==="LR"||d==="RL",p=[],y=[],E=[];for(let z of i.edges){let M=z.start===void 0?void 0:l.get(z.start),T=z.end===void 0?void 0:l.get(z.end);if(M===void 0||T===void 0)continue;let R=Ge(`«${z.type}»`,!1,o,a,4e3);M===T&&(m?h[M].h+=2*(ep+R.height+8):h[M].w+=2*(ep+R.width+12)),E.push(z),y.push(R),p.push({src:M,dst:T,minlen:1,labelW:R.width+12,labelH:R.height+4,route:[],labelX:0,labelY:0})}let b=On(h,p,d,{nodeSep:ok,edgeSep:ak,rankSep:ck,portSep:20});gk(h,p,u);let S=yn(e.title,o,s,4e3),x=S.height>0?S.height+12:0,I=Math.max(b.width,S.width),L=c+(I-b.width)/2,O=c+x,v=Math.ceil(I+2*c),G=Math.ceil(b.height+x+2*c),K="";for(let z=0;z`+Ne(M.kind,0,w+ka+M.kind.height/2,` class="pele-stereotype" font-size="${M.kind.size}"${g}${_.text}`)+Ne(M.name,0,w+ka+M.kind.height+M.name.height/2,` class="pele-label" font-size="${M.name.size}" font-weight="var(--_hw)"${$}${_.text}`);if(M.rows.length>0){let D=w+M.headHeight;A+=``;let U=D+ka,B="";for(let F of M.rows)B+=Px(F.key,N+od,U,` class="pele-field"${g}${_.text}`)+Px(F.value,N+od+M.keyWidth+Dx,U,` class="pele-value"${$}${_.text}`),U+=F.height+Jh;A+=`${B}`}K+=`${A}`}let C="",Z="",oe=new Map;for(let z=0;zm?`${f(A+ne)},${f(D+w.h/2+Y)}`:`${f(A+w.w/2+Y)},${f(D+ne)}`,Q=W/.75;$={d:`M${j(_,-F)}C${j(Q,-F)} ${j(Q,F)} ${j(0,F)}`,sx:m?A-F:A+w.w/2,sy:m?D+w.h/2:D-F,sdx:m?0:-1,sdy:m?-1:0,ex:m?A+F:A+w.w/2,ey:m?D+w.h/2:D+F,edx:m?0:-1,edy:m?-1:0},m?(g=A,N=D+w.h/2+W+4+M.labelH/2):(g=A+w.w/2+W+4+M.labelW/2,N=D)}else{let w=M.route.slice();for(let A=0;A`+(T.contains?pk($.sx,$.sy,$.sdx,$.sdy):mk($.ex,$.ey,$.edx,$.edy))+"",Z+=dn(T.id,R,g,N,"")}return{svg:at("requirement",v,G,s,n,e,Ne(S,v/2,c+S.height/2,' class="pele-title" font-weight="var(--_tw)"')+(C?`${C}`:"")+(Z?`${Z}`:"")+`${K}`),width:v,height:G,links:[]}}var Ux={type:"requirement",math:!0,parse(e,t,n){let r=new rd;return n&&(r.title=n),Lx(e,r),r},render:Wx};var ld=class{constructor(){fe(this,"type","sankey");fe(this,"nodes",[]);fe(this,"links",[]);fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"lookup",new Map)}findOrCreateNode(t){let n=this.lookup.get(t);return n===void 0&&(n={id:t,index:this.nodes.length},this.lookup.set(t,n),this.nodes.push(n)),n}addLink(t,n,r){this.links.push({source:t,target:n,value:r})}};var dd=["$end","STUCK","SANKEY","NEWLINE","COMMA","DQUOTE","NON_ESCAPED_TEXT","ESCAPED_TEXT","EOF"];function Gx(e){return e>=32&&e<=126&&e!==34&&e!==44||e>=160&&e<=55295||e>=57344&&e<=65533||e>=65536&&e<=1114111}function Yx(e){let t=e.length,n=[],r=[],i=[],s=[],a=0,o=0,c=(u,h,d)=>{n.push(u),r.push(e.slice(h,d)),i.push(h),o=d},l=u=>e.slice(o,o+u.length).toLowerCase()===u&&!ot(e.charCodeAt(o+u.length));for(;o0&&(a=s.pop()),c(5,o,o+1);continue}for(;d65535?2:1;else if(m===34&&e.charCodeAt(d+1)===34)d+=2;else break}c(7,o,d)}else{if(a===0&&(u|32)===115){let m=l("sankey-beta")?11:l("sankey")?6:0;if(m>0){s.push(a),a=1,c(2,o,o+m);continue}}if(u===10||u===13&&e.charCodeAt(o+1)===10){c(3,o,u===10?o+1:o+2);continue}if(u===44){c(4,o,o+1);continue}if(u===34){s.push(a),a=2,c(5,o,o+1);continue}for(;d65535?2:1}c(6,o,d)}if(d===h)return c(1,o,o),{types:n,texts:r,starts:i}}return c(a===2?7:8,t,t),c(0,t,t),{types:n,texts:r,starts:i}}var Hx=/[\n\r]+/g,bk=/[\x00-\x08\x0b\x0c\x0e-\x1f\ud800-\udfff\ufffe\uffff]/u;function tp(e){return e===10||e===13?!1:e<128?e===32||e===9||e===11||e===12:e===160||e===5760||e>=8192&&e<=8202||e===8232||e===8233||e===8239||e===8287||e===12288||e===65279}function yk(e,t){let n=e.length;for(;n>0&&tp(e.charCodeAt(n-1));)n--;let r="",i=0,s=!1;for(let a=0;a{let p=[];n!==e&&np(n,p);let y=d>0&&d>=e.length?zr(p,e.length-1)+1:zr(p,d);return ft("sankey",n,y,m)},c=d=>{let m=r[a],p=m===1?dd[r[a-1]]:dd[m];throw o(s[a],`Expecting ${d}, got '${p}'`)},l=(d,m="")=>{r[a]!==d&&c(`'${dd[d]}'${m}`),a++},u=()=>{if(r[a]===6)return i[a++];r[a]!==5&&c("'DQUOTE', 'NON_ESCAPED_TEXT'"),a++,r[a]!==7&&c("'ESCAPED_TEXT'");let d=i[a++];return l(5),d},h=()=>{let d=s[a],m=u().trim().replaceAll('""','"');if(bk.test(bt(m)))throw o(d,"Invalid XML character in node name");return m};for(l(2),l(3);;){let d=h();l(4,", 'NEWLINE', 'EOF'");let m=h();l(4,", 'NEWLINE', 'EOF'");let p=s[a],y=parseFloat(u());if(!Number.isFinite(y))throw o(p,"Expecting a number");let E=t.findOrCreateNode(d),b=t.findOrCreateNode(m);if(t.addLink(E,b,y),r[a]!==3)break;a++}r[a]===8&&a++,r[a]!==0&&c("'NEWLINE', 'EOF'")}var Ek=6;function rp(e,t){if(e.length>8){e.sort(t);return}for(let n=1;n=0&&t(e[i],r)>0;)e[i+1]=e[i],i--;e[i+1]=r}}function zx(e,t){let n=e.nodes.length,r=e.links.map(R=>({source:R.source.index,target:R.target.index,value:Number.isFinite(R.value)&&R.value>0?R.value:0,thickness:0,sourceY:0,targetY:0})),i=[],s=[];for(let R=0;R{i[R.source].push(_),s[R.target].push(_)});let a=new Int32Array(n),o=new Int32Array(n),c=[];for(let R=0;R0){R=r[$].source;break}}throw new Qe(`Sankey diagrams cannot have circular links, and "${e.nodes[R].id}" is part of one.`,"semantic",{type:"sankey"})}let l=1;for(let R=0;Rl&&(l=a[R]+1);let u=new Int32Array(n);for(let R=n-1;R>=0;R--){let _=c[R];for(let $ of i[_])u[_]h&&(h=R.value);let d=h>0?1/h:0,m=[],p=new Float64Array(n),y=[];for(let R=0;R1?(t.width-t.nodeWidth)/(l-1):0;for(let R=0;R0){_=l;for(let A of i[R])a[r[A].target]-1<_&&(_=a[r[A].target]-1)}}else _=i[R].length>0?a[R]:l-1;let $=0,g=0,N=0,w=0;for(let A of s[R])$+=r[A].value*d,N+=r[A].value;for(let A of i[R])g+=r[A].value*d,w+=r[A].value;p[R]=Math.max($,g),m.push({layer:_,value:Math.max(N,w),x:_*E,y:0,height:0}),y[_].push(R)}let b=1;for(let R of y)R.length>b&&(b=R.length);let S=b>1?Math.min(t.nodePadding,t.height/(b-1)):t.nodePadding,x=1/0;for(let R of y){let _=0;for(let $ of R)_+=p[$];_>0&&(x=Math.min(x,(t.height-(R.length-1)*S)/_))}(!Number.isFinite(x)||x<0)&&(x=0);let I=Math.max(0,t.labelHeight-S),L=R=>{for(let _ of y){let $=(_.length-1)*S;for(let g of _)$+=Math.max(p[g]*R,I);if($>t.height+1e-6)return!1}return!0};if(I>0&&!L(x))if(L(0)){let R=0;for(let _=0;_<40;_++){let $=(R+x)/2;L($)?R=$:x=$}x=R}else I=0;let O=new Float64Array(n);for(let R of r)R.thickness=R.value*d*x;for(let R of y){let _=0;for(let g of R)m[g].height=p[g]*x,O[g]=Math.max(0,I-m[g].height)/2,m[g].y=_+O[g],_+=m[g].height+2*O[g]+S;let $=(t.height-_+S)/(R.length+1);R.forEach((g,N)=>m[g].y+=$*(N+1))}let v=R=>m[R].y+m[R].height/2,G=new Float64Array(r.length),K=new Float64Array(r.length),C=(R,_)=>v(r[R].target)-v(r[_].target)||R-_,Z=(R,_)=>v(r[R].source)-v(r[_].source)||R-_,oe=(R,_)=>v(R)-v(_)||R-_,H=R=>{let _=0;rp(i[R],C);for(let $ of i[R])G[$]=_+r[$].thickness/2,_+=r[$].thickness},z=R=>{let _=0;rp(s[R],Z);for(let $ of s[R])K[$]=_+r[$].thickness/2,_+=r[$].thickness},M=()=>{for(let R=0;R{for(let N of R){let w=$?s[N]:i[N];if(w.length===0)continue;$?z(N):H(N);let A=0,D=0,U=0;for(let F of w){let W=$?m[r[F].source].y+G[F]-K[F]:m[r[F].target].y+K[F]-G[F];A+=W*r[F].thickness,D+=r[F].thickness,U+=v($?r[F].source:r[F].target)-m[N].height/2}let B=D>0?A/D:U/w.length;m[N].y+=(B-m[N].y)*_}rp(R,oe);let g=0;for(let N of R)m[N].y-O[N]=0;N--){let w=R[N];m[w].y+m[w].height+O[w]>g&&(m[w].y=g-m[w].height-O[w]),g=m[w].y-O[w]-S}};M();for(let R=0;R=0;$--)T(y[$],_,!1);M();for(let $=1;$>>0).toString(36)+(n>>>0).toString(36)}function Qx(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ud(e,t,n,r,i){let s=e[t];return typeof s=="number"&&s>=r?Math.min(s,i):n}function jx(e,t){let n=e[t];return typeof n=="string"||typeof n=="number"&&Number.isFinite(n)?String(n):""}function Xx(e){return Math.abs(e)<1e15?Math.round(e*100)/100:e}function qx(e){return typeof e=="string"?Ct([`fill:${e}`]).shape:""}function Zx(e,t,n){let r=Qx(t.sankey)?t.sankey:{},i=ud(r,"width",600,1,1e4);return ms(n,i,160,s=>wk(e,r,n,s,i))}function wk(e,t,n,r,i){let s=n.fontSize??16,a=Math.round(s*.625),o=Math.max(a,Math.round(s*.875*Math.min(1,r/i))),c=n.measurer??ct(n.fontFamily,n.fontFamilyMono),l=n.padding??8,u=ud(t,"height",400,1,1e4),h=Math.min(ud(t,"nodeWidth",10,1,200),r),d=t.showValues!==!1,m=bt(jx(t,"prefix")),p=bt(jx(t,"suffix")),y=t.labelStyle==="outlined",E=t.nodeAlignment==="left"||t.nodeAlignment==="right"||t.nodeAlignment==="center"?t.nodeAlignment:"justify",b=typeof t.linkColor=="string"?t.linkColor:"gradient",S=te=>zx(e,{width:r,height:u,nodeWidth:h,nodePadding:ud(t,"nodePadding",12,0,200)+(d?xk:0),labelHeight:te*1.15,alignment:E}),x=S(o),I=new Map,L=1;for(let te of x.nodes){let se=(I.get(te.layer)??0)+1;I.set(te.layer,se),se>L&&(L=se)}let O=Math.max(a,Math.round(u/L/Ak));OC.get(e.nodes[te].id)??"",oe=te=>/^ style="fill:(.*);"$/.exec(Z(te))?.[1]??Et(te),H=0,z=0;v.forEach(te=>{te.value>z&&(z=te.value,H=te.layer)});let M=0,T=r,R=0,_=u,$=v.map((te,se)=>{let re=bt(e.nodes[se].id),P=d?`${m}${Xx(te.value)}${p}`:"",ee=c.width(P?`${re} ${P}`:re,o,0),ae=y?te.layer>=H:te.x{let re=e.nodes[se].id,P=bt(re),ee=Math.max(te.height,1);w+=``;let ae=$[se],ue=(Se,_e)=>(g.get(Math.floor(_e/K))??[]).some(xe=>xe!==ae&&Math.abs(xe.y-_e)xe.left-Hr);if(v.length<=Vx&&ue(ae.left,ae.y))e:for(let Se of[0,-K,K])for(let _e of[ae.after,!ae.after]){let xe=_e?te.x+h+Hr:te.x-Hr-ae.width,Me=ae.y+Se;if(ue(xe,Me)||xeT||Me-o*.75_||v.some((ke,be)=>be!==se&&xeke.x-Hr&&Me-o*.75ke.y))continue;let Ce=Math.max(0,te.y-Me,Me-te.y-te.height);if(!v.some((ke,be)=>be!==se&&ke.x===te.x&&Math.max(0,ke.y-Me,Me-ke.y-ke.height)<=Ce)){ae.left=xe,ae.y=Me,ae.after=_e;break e}}let{value:ce,after:pe,y:V}=ae,X=pe?te.x+h+Hr:te.x-Hr,le=` x="${f(X)}" y="${f(V+o*.35)}" text-anchor="${pe?"start":"end"}"`,de=rt(P)+(ce?` ${rt(ce)}`:"");N+=``+(y?`${rt(P)}${ce?" "+rt(ce):""}`:"")+`${de}`});let A=b==="gradient"||b==="source"||b==="target"?"":qx(b),D=n.idPrefix??"",U=b==="gradient"&&/^[\w-]+$/.test(D),B=new Map,F="";for(let te of G){let se=b==="target"?te.target:te.source,re=Math.max(te.thickness,1)/2,P=v[te.source].x+h,ee=v[te.target].x,ae=`fill="${Et(se)}"${A||Z(se)}`;if(U){let V=`x1="${f(P)}" x2="${f(ee)}">`,X=`${D}-sankey-${Sk(V)}`;B.set(X,``),ae=`fill="url(#${X}) ${oe(te.source)}"`}let ue=f((P+ee)/2),ce=Ue(e.nodes[te.source].id),pe=Ue(e.nodes[te.target].id);F+=`${ce} → ${pe}: ${rt(m)}${Xx(te.value)}${rt(p)}`}let W=Ge(e.title,!1,c,s,kt(n),1),j=W.height>0?W.height+12:0,Q=Math.max(T-M,W.width),Y=l-M+(Q-(T-M))/2,ne=l+j-R,q=Math.ceil(Q+2*l),k=Math.ceil(_-R+j+2*l);return{svg:at("sankey",q,k,s,n,e,Ne(W,q/2,l+W.height/2,' class="pele-title" font-weight="var(--_tw)"')+``+(B.size>0?`${[...B.values()].join("")}`:"")+`${F}${w}${N}`),width:q,height:k,links:[]}}var Jx={type:"sankey",parse(e,t,n){let r=new ld;return n&&(r.title=n),Kx(np(e),r,e),r},render:Zx};var _k="aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey darkturquoise darkviolet deeppink deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green greenyellow grey honeydew hotpink indianred indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon lightseagreen lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime limegreen linen magenta maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple rebeccapurple red rosybrown royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue slategray slategrey snow springgreen steelblue tan teal thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen transparent currentcolor inherit initial unset revert accentcolor accentcolortext activetext buttonborder buttonface buttontext canvas canvastext field fieldtext graytext highlight highlighttext linktext mark marktext selecteditem selecteditemtext visitedtext activeborder activecaption appworkspace background buttonhighlight buttonshadow captiontext inactiveborder inactivecaption inactivecaptiontext infobackground infotext menu menutext scrollbar threeddarkshadow threedface threedhighlight threedlightshadow threedshadow window windowframe windowtext",eA,Rk=/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?(%|deg|grad|rad|turn)?$/i;function tA(e){if(e.toLowerCase()==="none")return 4;let t=Rk.exec(e);return t?t[1]===void 0?1:t[1]==="%"?2:3:0}function Tk(e,t){let n=tA(e);return n===1||n===2||t&&n===4}function Mk(e){let t=e.startsWith("hsl"),n=e.indexOf("("),r=e.slice(0,n);if(r!=="rgb"&&r!=="rgba"&&r!=="hsl"&&r!=="hsla"||e.length>120||e.indexOf(")")!==e.length-1)return!1;let i=e.slice(n+1,-1).trim(),s,a,o=i.includes(",");if(o)s=i.split(",").map(l=>l.trim()),s.length===4&&(a=s.pop());else{let l=i.split("/");if(l.length>2)return!1;s=l[0].trim().split(/\s+/),l.length===2&&(a=l[1].trim())}if(s.length!==3||a!==void 0&&!Tk(a,!o))return!1;let c=s.map(tA);if(o)return t?(c[0]===1||c[0]===3)&&c[1]===2&&c[2]===2:(c[0]===1||c[0]===2)&&c[1]===c[0]&&c[2]===c[0];for(let l=0;l<3;l++){let u=c[l];if(!(u===1||u===4||(t&&l===0?u===3:u===2)))return!1}return!0}function nA(e){return e.includes("(")?Mk(e):(eA??=new Set(_k.split(" ")),eA.has(e.toLowerCase()))}var Ck=/^:?wrap:/,Nk=/^:?nowrap:/,Ik=/^:?(?:no)?wrap:/,kk=/^(?:rgba?|hsla?)\s*\(/,rA=/[\r\u2028\u2029]/,$k=/^\w*/;function $a(e){throw new Qe(e,"semantic",{type:"sequence"})}function sA(e){let t=e.trim(),n=Ck.test(t)?!0:Nk.test(t)?!1:void 0;return{text:(n===void 0?t:t.replace(Ik,"")).trim(),wrap:n}}function Lk(e){let t=kk.exec(e);if(t){let r=e.lastIndexOf(")");if(r>=t[0].length)return rA.test(e.slice(t[0].length))?void 0:[e.slice(0,r+1),e.slice(r+1)]}if(rA.test(e))return;let n=$k.exec(e)[0];return[n,e.slice(n.length)]}function iA(e){return typeof e=="string"?[...e].map((t,n)=>[String(n),t]):e!==null&&typeof e=="object"?Object.entries(e):[]}var fd=class{constructor(t={}){fe(this,"type","sequence");fe(this,"actors",new Map);fe(this,"createdActors",new Map);fe(this,"destroyedActors",new Map);fe(this,"boxes",[]);fe(this,"messages",[]);fe(this,"notes",[]);fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"prevActor");fe(this,"currentBox");fe(this,"lastCreated");fe(this,"lastDestroyed");fe(this,"wrapEnabled");fe(this,"sequenceWrap");fe(this,"active",new Map);this.wrapEnabled=t.wrap,this.sequenceWrap=t.sequenceWrap??!1}autoWrap(){return this.wrapEnabled??this.sequenceWrap}setAccTitle(t){this.accTitle=t.replace(/^\s+/g,"")}setAccDescription(t){this.accDescr=t.replace(/\n\s+/g,` +`)}setDiagramTitle(t){this.title=t}parseMessage(t){return sA(t)}parseBoxData(t){let n=Lk(t),r=n?.[0]?n[0].trim():"transparent",i=n?.[1]?n[1].trim():void 0;if(nA(r)||(r="transparent",i=t.trim()),i===void 0)return{text:void 0,color:r,wrap:void 0};let{text:s,wrap:a}=sA(i);return{text:s||void 0,color:r,wrap:a}}addBox(t){this.currentBox={name:t.text,wrap:t.wrap??this.autoWrap(),fill:t.color,actorKeys:[]},this.boxes.push(this.currentBox)}addActor(t,n,r,i,s){let a=this.currentBox,o;if(s!==void 0){let h;try{h=lr(s.includes(` +`)?s+` +`:`{ +`+s+` +}`)}catch(d){throw new Qe(`Config of participant "${t}" is not valid YAML. ${d.message}`,"syntax",{type:"sequence"})}h!==null&&typeof h=="object"&&!Array.isArray(h)&&(o=h)}let c=o&&Object.prototype.hasOwnProperty.call(o,"type")?o.type:void 0,l=o&&Object.prototype.hasOwnProperty.call(o,"alias")?o.alias:void 0;c!=null&&(i=String(c)),l&&(!r||r.text===n)&&(r={text:String(l),wrap:r?.wrap,type:i});let u=this.actors.get(t);if(!(u&&(this.currentBox&&u.box&&this.currentBox!==u.box&&$a(`A same participant should only be defined in one Box: ${u.name} can't be in '${u.box.name}' and in '${this.currentBox.name}' at the same time.`),a=u.box?u.box:this.currentBox,u.box=a,n===u.name&&r==null))){if((r?.text==null||i==null)&&(r={text:n,type:i}),this.actors.set(t,{box:a,name:n,description:r.text,wrap:r.wrap??this.autoWrap(),prevActor:this.prevActor,links:new Map,properties:new Map,type:i??"participant"}),this.prevActor){let h=this.actors.get(this.prevActor);h&&(h.nextActor=t)}this.currentBox&&this.currentBox.actorKeys.push(t),this.prevActor=t}}addMessage(t,n,r,i){this.messages.push({id:String(this.messages.length),from:t,to:n,message:r.text,wrap:r.wrap??this.autoWrap(),answer:i})}addSignal(t,n,r,i,s=!1,a){if(i===18){let o=t?this.active.get(t)??0:0;o<1&&$a(`Trying to inactivate an inactive participant (${t})`),this.active.set(t,o-1)}else i===17&&t&&this.active.set(t,(this.active.get(t)??0)+1);return this.messages.push({id:String(this.messages.length),from:t,to:n,message:r?.text??"",wrap:r?.wrap??this.autoWrap(),type:i,activate:s,centralConnection:a??0}),!0}addNote(t,n,r){let i=r.wrap??this.autoWrap(),s={actor:t,placement:n,message:r.text,wrap:i},a=typeof t=="string"?[t,t]:t;this.notes.push(s),this.messages.push({id:String(this.messages.length),from:a[0],to:a[1],message:r.text,wrap:i,type:2,placement:n})}addLinks(t,n){let r=this.actors.get(t);if(r)try{let i=JSON.parse(n.text);for(let[s,a]of iA(i))r.links.set(s,a)}catch{return}}addALink(t,n){let r=this.actors.get(t);if(!r)return;let i=n.text.indexOf("@");r.links.set(n.text.slice(0,i-1).trim(),n.text.slice(i+1).trim())}addProperties(t,n){let r=this.actors.get(t);if(r)try{let i=JSON.parse(n.text);for(let[s,a]of iA(i))r.properties.set(s,a)}catch{return}}addDetails(t,n){let r=this.actors.get(t);r&&(r.details=n.text)}apply(t){let n=[],r=[],i=t;for(;;){i!==void 0&&(Array.isArray(i)?(n.push(i),r.push(0)):typeof i!="string"&&this.applyOne(i));let s=n.length-1;if(s<0)return;let a=n[s];r[s]=9&&e<=13,r=0;`/\\+()<->: +,;`.includes(t)||(r|=1),`+<->: +,;`.includes(t)||(r|=2),`<>: +,;@`.includes(t)||(r|=8|(n?0:4)),`# +;`.includes(t)||(r|=16),!`/\\+()<>: +,;-`.includes(t)&&!n&&(r|=32),oA[e]=r}function aA(e){let t=e.length,n=[],r=[],i=[],s=[],a=0,o=0,c=-1,l=(_,$,g)=>{n.push(_),r.push(e.slice($,g)),i.push($),o=g},u=(_,$,g,N)=>{n.push(_),r.push(N),i.push($),o=g},h=_=>{s.push(a),a=_},d=()=>{s.length>0&&(a=s.pop())},m=_=>(c<_&&(c=e.indexOf(` +`,_),c===-1&&(c=t)),c),p=(_,$)=>{let g=e.charCodeAt(_);return g<128?(oA[g]&$)!==0:$===4||$===32?!qe(g):!0},y=(_,$)=>{for(let g=0;g<$.length;g++){let N=$.charCodeAt(g),w=e.charCodeAt(_+g);if(N>=97&&N<=122?(w|32)!==N:w!==N)return!1}return!0},E=_=>y(o,_)&&!ot(e.charCodeAt(o+_.length)),b=_=>{for(;_{let _=o;for(;_{for(;_{l(_,o,o+$),h(g)},L=(_,$,g=-1)=>E(_)?(l($,o,o+_.length),g>=0&&h(g),!0):!1,O=(_,$)=>{if(!y(o,_))return!1;let g=o+_.length,N=e.charCodeAt(g);if(N!==32&&N!==9)return!1;for(;N===32||N===9;)N=e.charCodeAt(++g);return g>=t||!p(g,32)?!1:(l($,o,o+_.length),!0)},v=_=>{let $=e.charCodeAt(_),g=e.charCodeAt(_+1);if($===45){if(g===120||g===88||g===41||g===92||g===47||g===45)return!0;let N=e.charCodeAt(_+2);return g===124&&(N===92||N===47)}return $===47||$===92?(g===124||g===$)&&e.charCodeAt(_+2)===45:$===40&&g===41},G=()=>{let _=o+1;for(;_=t||!p($,2))break;for($++;${let _=o;for(;xt(e.charCodeAt(_));)_++;let $=_>o;if(e.charCodeAt(_)===46&&xt(e.charCodeAt(_+1))){let N=xt(e.charCodeAt(_+2))?_+3:_+2,w=e.charCodeAt(N);if(w===32||w===10)return l(10,o,N),!0}let g=e.charCodeAt(_);return $&&(g===32||g===10)?(l(10,o,_),!0):!1},C=()=>{let _=e.charCodeAt(o+1),$=e.charCodeAt(o+2);if(_===62)l($===62?55:53,o,o+($===62?3:2));else if(_===120||_===88)l(59,o,o+2);else if(_===41)l(61,o,o+2);else if(_===124&&$===92)l(63,o,o+3);else if(_===124&&$===47)l(64,o,o+3);else if(_===92&&$===92)l(65,o,o+3);else if(_===47&&$===47)l(66,o,o+3);else if(_===45){let g=e.charCodeAt(o+3);$===62?l(g===62?57:54,o,o+(g===62?4:3)):$===120||$===88?l(60,o,o+3):$===41?l(62,o,o+3):$===124&&g===92?l(67,o,o+4):$===124&&g===47?l(68,o,o+4):$===92&&g===92?l(69,o,o+4):$===47&&g===47?l(70,o,o+4):l(46,o,o+1)}else l(46,o,o+1)},Z=_=>{let $=e.charCodeAt(o+1);if($!==124&&$!==_||e.charCodeAt(o+2)!==45)return!1;let g=e.charCodeAt(o+3)===45,N=_===47,w;return $===124?g?w=N?75:76:w=N?71:72:g?w=N?77:78:w=N?73:74,l(w,o,o+(g?4:3)),!0},oe=()=>{if(!y(o,"title"))return!1;let _=o+5,$=e.charCodeAt(_)===58;$&&_++;let g=_;for(;g{let _=y(o,"accdescr");if(!_&&!y(o,"acctitle"))return!1;let $=b(o+8),g=e.charCodeAt($);return g===58?(l(_?18:16,o,b($+1)),h(_?6:5),!0):_&&g===123?(o=b($+1),h(7),!0):!1},z=_=>{switch(_|32){case 97:return L("actor",34,1)||L("alt",24,3)||L("and",30,3)||L("activate",12,1)||H()||L("autonumber",9);case 98:return L("box",6,3)||L("break",28,3);case 99:return L("create",5)||L("critical",27,3);case 100:return L("destroy",35,1)||O("details",41)||L("deactivate",13,1);case 101:return L("else",31,3)||L("end",8);case 108:return L("loop",21,3)||L("left of",43)||O("links",38)||O("link",39);case 110:return L("note",36);case 111:return L("opt",23,3)||L("option",29,3)||L("over",37)||L("off",11);case 112:return L("participant",32,1)||L("par",25,3)||L("par_over",26,3)||O("properties",40);case 114:return L("rect",22,3)||L("right of",44);case 115:return L("sequencediagram",4);case 116:return oe();default:return!1}},M=()=>{let _=e.charCodeAt(o);if(_===10){let $=o+1;for(;e.charCodeAt($)===10;)$++;l(3,o,$);return}if(qe(_)){o=b(o+1);return}if(_===35||_===37&&e.charCodeAt(o+1)!==123){o=m(o);return}if(!((xt(_)||_===46)&&K())&&!(_<128&&(_|32)>=97&&(_|32)<=122&&z(_)))if(_===44)l(42,o,o+1);else if(_===59)l(3,o,o+1);else if(p(o,1))G();else if(_===45)C();else if(_===60&&e.startsWith("<<->>",o))l(56,o,o+5);else if(_===60&&e.startsWith("<<-->>",o))l(58,o,o+6);else{if((_===47||_===92)&&Z(_))return;_===58?l(52,o,x(o+1)):_===43?l(45,o,o+1):_===40&&e.charCodeAt(o+1)===41?l(47,o,o+2):l(2,o,o+1)}},T=()=>{if(S())return!0;let _=e.charCodeAt(o);if(_===35)return o=m(o),!0;if(_===64&&e.charCodeAt(o+1)===123)return I(49,2,4),!0;let $=o;for(;$o){let N=b($);if(e.charCodeAt(N)===64&&e.charCodeAt(N+1)===123)return l(48,o,$),!0;if(N>$&&y(N,"as")&&qe(e.charCodeAt(N+2)))return l(48,o,$),h(2),!0}let g=$;for(;go){let N=e.charCodeAt(g),w=g;if(go&&e.charCodeAt(w)!==35;)w--;if(w>o)return u(48,o,w,e.slice(o,w).trim()),d(),!0}if(e.charCodeAt(g)===60)return l(2,o,m(o)),d(),!0;if(_!==10){let N=m(o);return u(2,o,N,e.slice(o,N).trim()),d(),!0}return!1},R=()=>{switch(a){case 0:return M(),!0;case 1:return T();case 2:return S()?!0:e.charCodeAt(o)===35?(o=m(o),!0):(d(),d(),E("as")?I(33,2,3):l(3,o,o),!0);case 3:return S()?!0:e.charCodeAt(o)===35?(o=m(o),!0):(l(7,o,x(o)),d(),!0);case 4:if(e.charCodeAt(o)!==125){let _=e.indexOf("}",o);return _===-1&&(_=t),l(50,o,_),!0}else{let _=b(o+1),$=_>o+1&&y(_,"as")&&qe(e.charCodeAt(_+2));return l(51,o,o+1),d(),$?h(2):d(),!0}case 5:case 6:return l(a===5?17:19,o,m(o)),d(),!0;default:if(e.charCodeAt(o)===125)o++,d();else{let _=e.indexOf("}",o);_===-1&&(_=t),l(20,o,_)}return!0}};for(;o{let I=n[s];throw I===1?ft("sequence",e,i[s],"",!0):ft("sequence",e,i[s],`Expecting ${x}, got '${sp[I]}'`)},o=x=>(n[s]!==x&&a(`'${sp[x]}'`),r[s++]),c=()=>{let x=n[s];return x!==48&&x!==39&&a("'ACTOR'"),{type:"addParticipant",actor:r[s++]}},l=()=>t.parseMessage(o(52).trim().substring(1)),u=()=>{let x=n[s++];if(x===35){let L=c();return o(3),L.type="destroyParticipant",L}let I=c();if(n[s]===49&&n[s-1]===48){s++;let L=o(50);o(51),I.config=L.trim()}if(I.draw=x===32?"participant":"actor",n[s]===33){s++;let L=o(7);o(3),I.description=t.parseMessage(L)}else n[s]===3?s++:a("'AS', 'NEWLINE'");return I},h=x=>{let I=!1;n[s]===47&&(I=!0,s++);let L=Wt[n[s]];L<0&&a(Ok),s++;let O=n[s];(O===47||!I&&(O===45||O===46))&&s++;let v=c(),G=l(),K={type:"addMessage",from:x.actor,to:v.actor,signalType:L,msg:G},C=[x,v,K];if(I){let Z=O===47;K.activate=Z,K.centralConnection=Z?61:60,Z&&C.push({type:"centralConnection",signalType:59,actor:v.actor}),C.push({type:"centralConnectionReverse",signalType:60,actor:x.actor})}else O===45?(K.activate=!0,C.push({type:"activeStart",signalType:17,actor:v.actor})):O===46?C.push({type:"activeEnd",signalType:18,actor:x.actor}):O===47&&(K.activate=!0,K.centralConnection=59,C.push({type:"centralConnection",signalType:59,actor:v.actor}));return C},d=x=>{s++;let I=c();return[I,{type:x,actor:I.actor,text:l()}]},m=()=>{s++;let x=n[s];if(x===37){s++;let O=c(),v=O,G=[O.actor,O.actor];if(n[s]===42){s++;let K=c();v=[O,K],G=[O.actor,K.actor]}return[v,{type:"addNote",placement:2,actor:G,text:l()}]}x!==43&&x!==44&&a("'over', 'left_of', 'right_of'"),s++;let I=c(),L=x===43?0:1;return[I,{type:"addNote",placement:L,actor:I.actor,text:l()}]},p=()=>{s++;let x={type:"sequenceIndex",sequenceVisible:!0,signalType:26};return n[s]===10?(x.sequenceIndex=Number(r[s++]),x.sequenceIndexStep=n[s]===10?Number(r[s++]):1):n[s]===11&&(s++,x.sequenceVisible=!1),n[s]!==3&&a("'NEWLINE', 'NUM', 'off'"),s++,x},y=(x,I,L,O)=>{let v=x.list,G=x.sections;if(G)for(let K=G.length-2;K>=0;K-=2){let C={type:I,signalType:O};C[L]=t.parseMessage(G[K+1]),v=G[K].concat([C,v])}return v},E=x=>{let I=x.text,L=x.list;switch(x.kind){case 1:L[0]={type:"boxStart",boxData:t.parseBoxData(I)},L.push({type:"boxEnd",boxText:I});break;case 2:L[0]={type:"loopStart",loopText:t.parseMessage(I),signalType:10},L.push({type:"loopEnd",loopText:I,signalType:11});break;case 3:L[0]={type:"rectStart",color:t.parseMessage(I),signalType:22},L.push({type:"rectEnd",color:t.parseMessage(I),signalType:23});break;case 4:L[0]={type:"optStart",optText:t.parseMessage(I),signalType:15},L.push({type:"optEnd",optText:t.parseMessage(I),signalType:16});break;case 5:L[0]={type:"breakStart",breakText:t.parseMessage(I),signalType:30},L.push({type:"breakEnd",optText:t.parseMessage(I),signalType:31});break;case 6:L=y(x,"else","altText",13),L[0]={type:"altStart",altText:t.parseMessage(I),signalType:12},L.push({type:"altEnd",signalType:14});break;case 7:L=y(x,"and","parText",20),L[0]={type:"parStart",parText:t.parseMessage(I),signalType:x.startType},L.push({type:"parEnd",signalType:21});break;default:L=y(x,"option","optionText",28),L[0]={type:"criticalStart",criticalText:t.parseMessage(I),signalType:27},L.push({type:"criticalEnd",signalType:29})}return L};for(;n[s]===3;)s++;o(4);let b=[],S={kind:0,text:"",startType:0,list:[],sections:void 0};for(;;){let x=n[s],I=S.list;if(S.kind===1){if(x===32||x===34||x===35)I.push(u());else if(x===3)I.push([]),s++;else if(x===8){s++;let L=E(S);S=b.pop(),S.list.push(L)}else a("'end', 'NEWLINE', 'participant', 'participant_actor', 'destroy'");continue}switch(x){case 3:case 2:I.push([]),s++;break;case 32:case 34:case 35:I.push(u());break;case 5:{s++;let L=n[s];L!==32&&L!==34&&L!==35&&a("'participant', 'participant_actor', 'destroy'");let O=u();O.type="createParticipant",I.push(O);break}case 48:I.push(h(c())),o(3);break;case 39:{let L=n[s+1];I.push(L===48||L===39?d("addALink"):h(c())),o(3);break}case 38:I.push(d("addLinks")),o(3);break;case 40:I.push(d("addProperties")),o(3);break;case 41:I.push(d("addDetails")),o(3);break;case 36:I.push(m()),o(3);break;case 9:I.push(p());break;case 12:case 13:{s++;let L=c();o(3),I.push(x===12?{type:"activeStart",signalType:17,actor:L.actor}:{type:"activeEnd",signalType:18,actor:L.actor});break}case 14:case 15:{let L=r[s++].substring(x===14?6:7);t.setDiagramTitle(L),I.push(L);break}case 16:{s++;let L=o(17).trim();t.setAccTitle(L),I.push(L);break}case 18:{s++;let L=o(19).trim();t.setAccDescription(L),I.push(L);break}case 20:{let L=r[s++].trim();t.setAccDescription(L),I.push(L);break}case 21:case 22:case 23:case 28:case 24:case 25:case 26:case 27:case 6:{s++;let L=o(7);b.push(S),S={kind:Kr[x],text:L,startType:x===26?32:19,list:[[]],sections:void 0};break}case 31:case 30:case 29:{S.kind!==(x===31?6:x===30?7:8)&&a("'end'"),s++;let O=o(7);(S.sections??=[]).push(I,O),S.list=[];break}case 8:{S.kind===0&&a("'NEWLINE', 'EOF'"),s++;let L=E(S);S=b.pop(),S.list.push(L);break}case 0:S.kind!==0&&a("'end'"),t.apply(I);return;default:a("'NEWLINE', 'ACTOR', 'participant', 'note', 'end'")}}}var Dk=16,vk=10,lA=34,dA=4,mi=5,pi=6,cs=' fill="var(--_s)" stroke="var(--_b)"',fo=' fill="none" stroke="var(--_b)"',Pk=new Set(["participant","actor","boundary","control","entity","database","collections","queue"]),Fk=new Set(["actor","boundary","control","entity","database"]);function uA(e){return Pk.has(e)?e:"participant"}function La(e){return Fk.has(e)}function fA(e,t,n,r,i=Dk){if(La(e))return{w:Math.max(40,t.width+8),h:lA+(t.height>0?dA+t.height:0)};let s=e==="collections"?mi:e==="queue"?2*pi:0;return{w:Math.max(n,t.width+2*i)+s,h:Math.max(r,t.height+2*vk)+(e==="collections"?mi:0)}}function Bk(e,t,n){let r=f(t),i=s=>f(n+s);switch(e){case"actor":return``;case"boundary":return``;case"control":return``;case"entity":return``;default:{let s=f(t-14),a=f(t+14);return``}}}function hA(e,t,n,r,i,s,a=""){let{w:o,h:c}=r,l=' class="pele-label"';if(La(e))return Bk(e,t,n)+Ne(i,t,n+lA+dA+i.height/2,l+a,s);let u=t-o/2;if(e==="collections"){let h=o-mi,d=c-mi,m=``,p=``;return m+p+Ne(i,u+h/2,n+mi+d/2,l,s)}if(e==="queue"){let h=f(u+pi),d=f(u+o-pi),m=f(n+c),p=f(c/2);return``+Ne(i,t-pi/2,n+c/2,l,s)}return``+Ne(i,t,n+c/2,l,s)}var ap=[];function mn(e,t,n,r=1,i=!1){ap[e]={dotted:t,head:n,atStart:r!==1,atEnd:r!==0,bottom:i}}mn(0,!1,1);mn(1,!0,1);mn(3,!1,2);mn(4,!0,2);mn(5,!1,0);mn(6,!0,0);mn(24,!1,3);mn(25,!0,3);mn(33,!1,1,2);mn(34,!0,1,2);for(let e of[!1,!0]){let t=e?10:0;mn(41+t,e,4),mn(42+t,e,4,1,!0),mn(43+t,e,5),mn(44+t,e,5,1,!0),mn(45+t,e,4,0),mn(46+t,e,4,0,!0),mn(47+t,e,5,0),mn(48+t,e,5,0,!0)}var Wk=new Map([[10,"loop"],[12,"alt"],[15,"opt"],[19,"par"],[32,"par"],[27,"critical"],[30,"break"],[22,"rect"]]),Uk=12,ip=28,pA=22,rr=10,mA=4,Gk=14,ho=10,Yk=16,Hk=20,Kk=10,hd=20,gA=240,pd=16,po=4,bA=' stroke-dasharray="4 4"';function op(e){return e!==void 0&&ap[e]!==void 0}function zk(e,t){let n=new Array(e.length),r=new Array(e.length),i=1,s=1,a=!1;for(let o=0;o=0&&r<=2e3?r:n}function EA(e,t,n,r,i,s){let a=f(e-n*Lt);return i?``:``}function md(e,t,n,r,i,s){switch(e){case 1:return _t("arrow_point",t,n,r,0,s);case 2:return _t("arrow_cross",t,n,r,0,s);case 3:return``;case 4:return EA(t,n,r,i,!1,s);case 5:return EA(t,n,r,i,!0,s);default:return""}}function Vk(e){return e===1?Lt-1:e===2?4:0}function xA(e,t,n){return An(n,r=>AA(e,t,n,r))}function AA(e,t,n,r,i=0,s=!0){let a=t.sequence??{},o=n.fontSize??16,c=Math.round(o*.875),l=Math.round(o*.75),u=n.measurer??ct(n.fontFamily,n.fontFamilyMono),h=Array.isArray(n.monospace)&&n.monospace.includes("messages"),d=h?{width:(Ee,We,De)=>u.width(Ee,We,De|4)}:u,m=n.icons,p=n.padding??8,y=a.mirrorActors!==!1,E=a.rightAngles===!0,b=Math.min(gi(a,"actorMargin",40),r?8:1/0),S=Math.min(gi(a,"width",64),r?48:1/0),x=gi(a,"height",Math.round(o*1.5)+20),I=Math.min(gi(a,"width",160),r?Math.max(32,((n.maxWidth??320)-2*p)/Math.max(1,e.actors.size)-b-24):1/0),L=Math.max(4,14+gi(a,"messageMargin",35)-35),O=Math.min(gi(a,"noteMargin",10),r?6:1/0),v=Math.min(gi(a,"boxMargin",10),r?6:1/0),G=a.messageAlign==="left"?-1:a.messageAlign==="right"?1:0,K=r?6:Uk,C=r?8:Yk,Z=r?12:Hk,oe=r?6:Kk,H=e.messages,z=H.length,M=zk(H,a.showSequenceNumbers===!0),T=(Ee,We,De,Xe=I,ze=u)=>{let et=Ge(Ee,!1,ze,We,r||De?Xe:1/0);return r?Zs(et,ze,Math.max(120,Xe)):et},R=(Ee,We,De=I)=>T(Ee,c,We,De,d),_;if(a.hideUnusedParticipants===!0){_=new Set;for(let Ee of H)_.add(Ee.from).add(Ee.to)}let $=new Int32Array(z+1);$[z]=-1;for(let Ee=z-1;Ee>=0;Ee--)$[Ee]=op(H[Ee].type)?Ee:$[Ee+1];let g=[],N=new Map;for(let[Ee,We]of e.actors){if(_&&!_.has(Ee))continue;let De=uA(We.type),Xe=T(We.description,o,We.wrap),ze=e.createdActors.get(Ee),et=e.destroyedActors.get(Ee),Ye=ze===void 0?-1:$[Math.min(ze,z)];Ye>=0&&H[Ye].to!==Ee&&(Ye=-1);let He=et===void 0?-1:$[Math.min(et,z)];He>=0&&H[He].to!==Ee&&H[He].from!==Ee&&(He=-1),N.set(Ee,g.length),g.push({id:Ee,actor:We,kind:De,label:Xe,size:fA(De,Xe,S,x,r?8:void 0),x:0,createAt:Ye,destroyAt:He,top:0,lifeStart:0,lifeEnd:-1,activations:[]})}let w=g.length-1,A=new Map,D=(Ee,We,De)=>{if(Ee<0||We>w)return;let Xe=Ee*g.length+We;(A.get(Xe)??0)M.shown[Ee]?Math.max(pd,u.width(String(M.index[Ee]),l,0)+8):0,B=new Array(z),F=new Array(z),W=(Ee,We)=>{let De=F[Ee];if(!De){if(We===I)return B[Ee].label;F[Ee]=De=new Map([[I,B[Ee].label]])}let Xe=De.get(We);return Xe||De.set(We,Xe=R(H[Ee].message,!0,We)),Xe};for(let Ee=0;Ee1&&Y.push([De,Xe,We])}Y.sort((Ee,We)=>Ee[1]-Ee[0]-(We[1]-We[0])||Ee[0]-We[0]);for(let[Ee,We,De]of Y){let Xe=0;for(let et=Ee;et=De)continue;let ze=(De-Xe)/(We-Ee);for(let et=Ee;et{for(let Ee=1;Ee<=w;Ee++)g[Ee].x=g[Ee-1].x+Q[Ee-1]};ne();for(let Ee of j){let We=g[Ee.last].x+g[Ee.last].size.w/2-(g[Ee.first].x-g[Ee.first].size.w/2);Ee.grow=Math.max(0,(Ee.title.width-We)/2),Ee.grow!==0&&(Ee.first>0&&(Q[Ee.first-1]+=Ee.grow),Ee.last{Eek&&(k=We)},te=Ee=>[g[Ee.first].x-g[Ee.first].size.w/2-v-Ee.grow,g[Ee.last].x+g[Ee.last].size.w/2+v+Ee.grow],se=new Array(z),re=()=>{ne(),q=1/0,k=-1/0;for(let De of g)J(De.x-De.size.w/2,De.x+De.size.w/2);for(let De of j)J(...te(De));let Ee=[],We=()=>w<0?[0,120]:[g[0].x-Z,g[w].x+Z];for(let De=0;DeHe.x1&&([He.x0,He.x1]=We()),He.kind!=="rect"){He.tabW=u.width(He.kind,l,1)+14;for(let it=0;itst&&(He.x1+=pt.width-st),it===0?He.title=pt:He.dividerLabels.push(pt)}}J(He.x0,He.x1);let nt=Ee[Ee.length-1];nt&&(nt.x0=Math.min(nt.x0,He.x0-oe),nt.x1=Math.max(nt.x1,He.x1+oe))}else if(Ye){let He=g[Ye.a],nt=g[Ye.b],it,wt;if(Ye.kind===2){if(Xe.placement===0)Ye.x=He.x-ho-Ye.w;else if(Xe.placement===1)Ye.x=He.x+ho;else if(Ye.a===Ye.b)Ye.x=He.x-Ye.w/2;else{let st=Math.min(He.x,nt.x)-C,pt=Math.max(He.x,nt.x)+C;(r||Xe.wrap)&&(Ye.label=T(Xe.message,c,!0,Math.max(I,pt-st-2*O))),Ye.w=Math.max(pt-st,Ye.label.width+2*O),Ye.x=(st+pt-Ye.w)/2}it=Ye.x,wt=Ye.x+Ye.w}else Ye.kind===1?(it=He.x,wt=He.x+rr+ip+8+Ye.label.width+U(De)):(it=Math.min(He.x,nt.x),wt=Math.max(He.x,nt.x),(r||Xe.wrap)&&(Ye.label=W(De,Math.max(I,wt-it-2*K-rr))),nt.createAt===De&&(nt.x>He.x?wt+=nt.size.w/2:it-=nt.size.w/2));J(it,wt);let ut=Ee[Ee.length-1];ut&&(ut.x0=Math.min(ut.x0,it-Z),ut.x1=Math.max(ut.x1,wt+Z))}}};re();let P=!1,ee=!1;if(r&&n.maxWidth!==void 0){let Ee=Math.floor(n.maxWidth)-Math.ceil(k-q+2*p)-i,We=new Int32Array(g.length),De=new Array(Q.length).fill(0),Xe=[],ze=0;for(let He=0;Ee>0&&He0?1:0,Ye+=We[He];if(Ye>0){let He=Q.slice(),nt=gt=>{for(let yt=0;ytB[yt].label.lines.length)},it=gt=>gt.reduce((yt,Nt)=>yt+Nt,0),wt=gt=>We[gt]*Ee/Ye,ut=nt(wt),st=it(De),pt=gt=>De[gt]*(Ee-.01)/st;if(s&&Ye>1&&st>0&&Q.some((gt,yt)=>pt(yt)>wt(yt))){let gt=ut;ut=nt(pt),ee=it(ut)yt<=gt[Nt]),ee||(ut=nt(wt))}P=it(ut)0?v+(ae>0?ae+4:0):0,ce=0;for(let Ee of g)Ee.createAt<0&&(ce=Math.max(ce,Ee.size.h));let pe=ue+ce;for(let Ee of g)Ee.top=pe-Ee.size.h,Ee.lifeStart=pe;let V=g.map(Ee=>Ee.x),X=(Ee,We)=>{let De=0,Xe=V.length;for(;De>1;V[ze]<=Ee?De=ze+1:Xe=ze}return De{if(Ee)return de.has(Ee)||de.set(Ee,dr(Ct([`fill:${Ee}`]).shape)),de.get(Ee)},_e=Ee=>{let We=Se(Ee);return We?` fill="${We}"`:""},xe=(Ee,We)=>{for(let De=le.length-1;De>=0;De--)if(le[De].kind==="rect")return le[De].fill;for(let De of j){let[Xe,ze]=te(De);if(Ee>=Xe&&We<=ze)return De.box.fill}},Me=(Ee,We)=>_e(xe(Ee,We)),Ce=(Ee,We,De,Xe=!1)=>{if(Ee.width===0)return"";let ze=We-Ee.width/2,et=X(ze,ze+Ee.width),Ye=et?``:"",He=et?"":Me(ze,ze+Ee.width);return Ye+Ne(Ee,We,De,Xe?` class="pele-frame-label"${He||' fill="var(--_m)"'} stroke="none"`:He,m)},ke=(Ee,We=0)=>Ee.activations.length+We>0?Ee.x-rr/2:Ee.x,be=(Ee,We=0)=>{let De=Ee.activations.length+We;return De>0?Ee.x+rr/2+(De-1)*mA:Ee.x},Ae=[],ie=[],me="",Te="",ye="",we="",Ie="",ve="",Pe=(Ee,We)=>{let De=Ee.activations.pop(),Xe=Math.max(We,De+Gk),ze=Ee.x-rr/2+Ee.activations.length*mA;return J(ze,ze+rr),ie.push(``),Xe},he=(Ee,We)=>{let De=Ee.x,Xe=We+16;return Ee.lifeEnd=Xe,ve+=``,Xe+6},Re=(Ee,We,De)=>{let Xe=Ee.actor.properties.get("class");return``+hA(Ee.kind,Ee.x,We,Ee.size,Ee.label,m,La(Ee.kind)?_e(Ee.actor.box?.fill):"")+""},Be=(Ee,We,De,Xe)=>`${rt(String(M.index[Ee]))}`,ge=pe+6;for(let Ee=0;Ee0&&(ge=Math.max(ge,Pe(g[et],ge)))}else if(ze&&ze.dividers[0]===Ee)le.push(ze),ze.kind==="rect"?(ze.top=ge+8,ge=ze.top):(ze.top=ge+12,ge=ze.top+Math.max(hd,ze.title.height+2));else if(ze){le.pop();let et=ge+12,Ye=f(ze.x0),He=f(ze.x1-ze.x0);if(ze.kind==="rect"){let nt=ze.fill?Ct([`fill:${ze.fill}`]).shape:"";Ae.push(``)}else{let nt=``;for(let it=0;it`+Ce(ut,ze.x0+8+ut.width/2,wt+2+ut.height/2,!0)}nt+=`${ze.kind}`+Ce(ze.title,ze.x0+ze.tabW+8+ze.title.width/2,ze.top+Math.max(hd,ze.title.height)/2,!0),me+=`${nt}`}ge=et}else if(De===13||De===20||De===28){let et=le[le.length-1];if(et){let Ye=et.dividerLabels[et.dividerY.length];et.dividerY.push(ge+12),ge+=12+(Ye.height>0?Ye.height:0)}}else if(Xe&&Xe.kind===2){let et=g[Xe.a],Ye=Xe.label.height+2*Math.max(4,O-4),He=ge+10,nt=Xe.x;We.placement===1?nt+=be(et)-et.x:We.placement===0&&(nt+=ke(et)-et.x),J(nt,nt+Xe.w),we+=``+Ne(Xe.label,nt+Xe.w/2,He+Ye/2,' class="pele-label" stroke="none" fill="var(--_fg)"',m)+"",ge=He+Ye}else if(Xe){let et=ap[De],Ye=g[Xe.a],He=g[Xe.b],nt=Xe.label,it=U(Ee),wt=0;for(let $t=Ee+1;$t``,En=et.atStart&&!et.atEnd,Sr=Vk(et.head),an="",cn;if(Xe.kind===1){let $t=ge+L+Math.max(0,(nt.height-pA)/2),qt=$t+pA,Ln=yt?Ye.x+po:be(Ye),Tn=gt?Ye.x+po:be(Ye,wt),or=Math.max(Ln,Tn)+ip+it/2;Nt=Se(xe(Ye.x,or)),Ft=Nt??Ft,yt&&(an+=jn(Ye.x,$t)),gt&&(an+=jn(Ye.x,qt)),it>0&&(an+=Be(Ee,En?Tn:Ln,En?qt:$t,it),En?Tn+=it/2:Ln+=it/2);let Jd=(et.atStart?md(et.head,Ln,$t,-1,ut,Ft):"")+(et.atEnd?md(et.head,Tn,qt,-1,-ut,Ft):""),Va=f(Ln+(et.atStart?Sr:0)),ar=f(Tn+(et.atEnd?Sr:0));an=``+Jd+an,J(Ye.x,or+8+nt.width),nt.width>0&&(ye+=`${Ne(nt,or+8+nt.width/2,($t+qt)/2,Me(or+8,or+8+nt.width),m)}`),cn=Math.max(qt,($t+qt)/2+nt.height/2)}else{let $t=He.x>Ye.x?1:-1,qt=He.createAt===Ee;Nt=Se(xe(Math.min(Ye.x,He.x),Math.max(Ye.x,He.x))),Ft=Nt??Ft,cn=ge+L+Math.max(nt.height>0?nt.height+2:6,qt?He.size.h/2-L+6:0);let Ln=$t>0?be(Ye):ke(Ye),Tn=$t>0?ke(He,wt):be(He,wt);if(qt&&(He.top=cn-He.size.h/2,He.lifeStart=He.top+He.size.h,Tn=He.x-$t*(La(He.kind)?18:He.size.w/2+1)),yt&&(an+=jn(Ye.x,cn),Ln=Ye.x+$t*po),gt&&(an+=jn(He.x,cn),Tn=He.x-$t*po),it>0)if(En){let ar=gt?Tn-$t*(it/2+2):Tn;an+=Be(Ee,ar,cn,it),Tn=ar-$t*it/2}else{let ar=yt?Ln+$t*(it/2+2):Ln;an+=Be(Ee,ar,cn,it),Ln=ar+$t*it/2}let or=(et.atStart?md(et.head,Ln,cn,-$t,ut*$t,Ft):"")+(et.atEnd?md(et.head,Tn,cn,$t,ut*$t,Ft):""),Jd=Ln+(et.atStart?$t*Sr:0),Va=Tn-(et.atEnd?$t*Sr:0);if(an=``+or+an,nt.width>0){let ar=Math.min(Ln,Tn),eu=Math.max(Ln,Tn),tu=G<0?ar+K+nt.width/2:G>0?eu-K-nt.width/2:(ar+eu)/2;J(tu-nt.width/2,tu+nt.width/2),ye+=`${Ce(nt,tu,cn-4-nt.height/2)}`}qt&&(ge=cn+He.size.h/2-6)}Te+=`${an}`,ge=Math.max(ge,cn),Ye.destroyAt===Ee&&(ge=Math.max(ge,he(Ye,cn))),He.destroyAt===Ee&&He!==Ye&&(ge=Math.max(ge,he(He,cn)))}}ge+=20;for(let Ee of g)for(;Ee.activations.length>0;)Pe(Ee,ge);let Le=ge;if(y){let Ee=0;for(let We of g)We.lifeEnd>=0||(Ee=Math.max(Ee,We.size.h),Ie+=Re(We,ge,!0));Le=ge+Ee}let Fe="";for(let Ee of g){Ie+=Re(Ee,Ee.top,!1);let We=Ee.lifeEnd>=0?Ee.lifeEnd:ge;We>Ee.lifeStart&&(Fe+=``)}let Ve="";for(let Ee of j){let[We,De]=te(Ee),Xe=Ee.box.fill==="transparent"?"":Ct([`fill:${Ee.box.fill}`]).shape;Ve+=``+Ne(Ee.title,(We+De)/2,v/2+2+Ee.title.height/2,` class="pele-cluster-label"${_e(Ee.box.fill)||' fill="var(--_m)"'}`,m)+""}j.length>0&&(Le+=v);let Oe=0,je="",Je=kt(n),$e=yn(e.title,u,o,r?Je:1/0),Ze=r?Zs($e,u,Math.max(120,Je)):$e;if(q>k&&J(0,Math.max(Ze.width,40)),Ze.width>0){let Ee=(q+k)/2;J(Ee-Ze.width/2,Ee+Ze.width/2),Oe=-Ze.height-12,je=Ne(Ze,Ee,Oe+Ze.height/2,' class="pele-title" font-weight="var(--_tw)"',m)}let tt=Math.ceil(k-q+2*p);if(P&&tt>n.maxWidth)return AA(e,t,n,r,ee?i:i>0?1/0:tt-Math.floor(n.maxWidth),!1);let mt=Math.ceil(Le-Oe+2*p);return{svg:at("sequence",tt,mt,o,n,e,``+je+(Ve?`${Ve}`:"")+(Ae.length>0?`${Ae.reverse().join("")}`:"")+(Fe?`${Fe}`:"")+(ie.length>0?`${ie.reverse().join("")}`:"")+(me?`${me}`:"")+(Te?`${Te}`:"")+(ve?`${ve}`:"")+(ye?`${ye}`:"")+(we?`${we}`:"")+(Ie?`${Ie}`:"")+""),width:tt,height:mt,links:[]}}var SA={type:"sequence",math:!0,parse(e,t,n){let r=t.sequence??{},i=new fd({wrap:typeof t.wrap=="boolean"?t.wrap:void 0,sequenceWrap:r.wrap===!0});return n&&i.setDiagramTitle(n),cA(e,i),i},render:xA};function jk(e){let t="TB";for(let n of e)typeof n!="string"&&n.stmt==="dir"&&(t=n.value);return t}function wA(e,t,n){let r=[],i=[],s=new Map,a=new Map,o=new Map,c=0,l=0,u=m=>{if(!m.id||m.id===""||m.id==="")return;if(m.cssClasses){let y;for(let E of m.cssClasses.split(" ")){let b=n.get(E);if(b){y??=m.cssCompiledStyles.slice();for(let S of b.styles)y.push(S)}}y&&(m.cssCompiledStyles=y)}let p=s.get(m.id);if(p){let y=m.parentId??p.parentId;Object.assign(p,m),y!==void 0&&(p.parentId=y)}else s.set(m.id,m),r.push(m)},h=(m,p,y)=>{let E=p.id;if(E==="root")return;let b=t.get(E),S=b?.classes?.join(" ")??"",x=b?.styles??[],I=a.get(E);if(!I){let H="rect";p.start===!0?H="stateStart":p.start===!1&&(H="stateEnd"),p.type!=="default"&&(H=p.type),I={shape:H,description:E,cssClasses:`${S} statediagram-state`,cssStyles:x,type:void 0,dir:void 0,colorIndex:void 0},a.set(E,I)}if(p.description&&(Array.isArray(I.description)?(I.shape="rectWithTitle",I.description=I.description.concat(p.description)):I.description.length>0?(I.shape="rectWithTitle",I.description=I.description===E?[p.description].flat():[I.description,p.description].flat()):(I.shape="rect",I.description=Array.isArray(p.description)?p.description.slice():p.description)),I.description.length===1&&I.shape==="rectWithTitle"&&(I.shape=I.type==="group"?"roundedWithTitle":"rect"),!I.type&&p.doc){if(I.type="group",I.dir=jk(p.doc),I.shape=p.type==="divider"?"divider":"roundedWithTitle",I.shape==="divider"&&m?.id!==void 0&&o.has(m.id))I.colorIndex=o.get(m.id);else{let H=l++;I.colorIndex=S.trim()!==""||x.length>0?void 0:H}o.set(E,I.colorIndex),I.cssClasses=`${I.cssClasses} statediagram-cluster ${y?"statediagram-cluster-alt":""}`}let L=I.description,O={id:E,shape:I.shape,label:Array.isArray(L)?L[0]:L,description:Array.isArray(L)?L.slice(1):[],cssClasses:I.cssClasses,cssCompiledStyles:[],cssStyles:I.cssStyles,type:I.type,isGroup:I.type==="group",dir:I.dir,colorIndex:I.colorIndex};O.shape==="divider"&&(O.label=""),m&&m.id!=="root"&&(O.parentId=m.id);let v=p.note;if(!v){u(O);return}let G=(H,z,M,T)=>({id:H,shape:z,label:v.text,description:[],cssClasses:M,cssCompiledStyles:[],cssStyles:[],type:T?"group":"node",isGroup:T,dir:void 0,position:v.position}),K=G(`${E}----note-${c++}`,"note","statediagram-note",!1);K.parentId=`${E}----parent`,K.noteFor=E,u(G(K.parentId,"noteGroup",I.cssClasses,!0)),u(K),u(O);let C=v.position==="left of",Z=C?K.id:E,oe=C?E:K.id;i.push({id:`${Z}-${oe}`,start:Z,end:oe,label:"",classes:"transition note-edge",pattern:"dashed"})},d=[{item:void 0,doc:e,at:0,alt:!0}];for(;d.length>0;){let m=d[d.length-1];if(m.at>=m.doc.length){d.pop();continue}let p=m.doc[m.at++];typeof p!="string"&&(p.stmt==="state"?(h(m.item,p,m.alt),p.doc&&d.push({item:p,doc:p.doc,at:0,alt:!m.alt})):p.stmt==="relation"&&(h(m.item,p.state1,m.alt),h(m.item,p.state2,m.alt),i.push({id:`edge${c++}`,start:p.state1.id,end:p.state2.id,label:p.description??"",classes:"transition"})))}for(let m of r)if(m.isGroup&&m.description.length>0)throw new Qe(`Group nodes can only have label. Remove the additional description for node [${m.id}]`,"semantic",{type:"state"});return{nodes:r,edges:i}}var gd=class{constructor(){fe(this,"type","state");fe(this,"rootDoc",[]);fe(this,"states",new Map);fe(this,"relations",[]);fe(this,"classes",new Map);fe(this,"links",new Map);fe(this,"graph",{nodes:[],edges:[]});fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"dividerCount",0)}get direction(){let t="TB";for(let n of this.rootDoc)typeof n!="string"&&n.stmt==="dir"&&(t=n.value);return t}setRootDoc(t){this.rootDoc=t,this.translate(),this.extract(t)}extract(t){this.states=new Map,this.relations=[],this.classes=new Map;let n=Array.isArray(t)?t:t.doc;for(let r of n)if(typeof r!="string")switch(r.stmt){case"state":this.addState(r.id.trim(),r.type,r.doc,r.description,r.note);break;case"relation":this.addRelation(r.state1,r.state2,r.description);break;case"classDef":this.addStyleClass(r.id.trim(),r.classes);break;case"style":{let i=r.styleClass.split(",").map(s=>s.replace(/;/g,"").trim());for(let s of this.named(r.id.trim()))s.styles=i.slice();break}case"applyClass":this.setCssClass(r.id.trim(),r.styleClass);break;case"click":this.addLink(typeof r.id=="string"?r.id:r.id.id,r.url,r.tooltip);break}this.graph=wA(n,this.states,this.classes)}translate(){let t=[["root",{stmt:"root",id:"root",doc:this.rootDoc},!0]];for(;t.length>0;){let[n,r,i]=t.pop();if(typeof r=="string")continue;if(r.stmt==="relation"){t.push([n,r.state2,!1],[n,r.state1,!0]);continue}if(r.stmt==="state")r.id==="[*]"?(r.id=n+(i?"_start":"_end"),r.start=i):r.id=r.id.trim();else if(r.stmt!=="root")continue;if(!r.doc)continue;let s=[],a=[];for(let o of r.doc)typeof o!="string"&&o.stmt==="state"&&o.type==="divider"&&!o.doc?(s.push({...o,doc:a}),a=[]):a.push(o);s.length>0&&(a.length>0&&s.push({stmt:"state",id:this.getDividerId(),type:"divider",doc:a}),r.doc=s);for(let o=r.doc.length-1;o>=0;o--)t.push([r.id,r.doc[o],!0])}}addState(t,n="default",r,i,s,a){let o=t.trim(),c=this.states.get(o);if(c?(c.doc||(c.doc=r),c.type||(c.type=n)):(c={stmt:"state",id:o,descriptions:[],type:n,doc:r,note:s,classes:[],styles:[],textStyles:[]},this.states.set(o,c)),i)for(let l of Array.isArray(i)?i:[i])this.addDescription(o,l.trim());if(s&&(c.note=s),a)for(let l of a)this.setCssClass(o,l.trim())}getState(t){return this.states.get(t)}addLink(t,n,r){this.links.set(t,{url:n,tooltip:r})}addRelation(t,n,r=""){for(let i of[t,n])this.addState(i.id,i.type,i.doc,i.description,i.note,i.classes);this.relations.push({id1:t.id.trim(),id2:n.id.trim(),relationTitle:r})}addDescription(t,n){this.states.get(t)?.descriptions?.push(n.startsWith(":")?n.replace(":","").trim():n)}getDividerId(){return`divider-id-${++this.dividerCount}`}addStyleClass(t,n=""){let r=this.classes.get(t);if(r||(r={id:t,styles:[],textStyles:[]},this.classes.set(t,r)),!!n)for(let i of n.split(",")){let s=i.replace(";","").trim();i.includes("color")&&r.textStyles.push(s.replace("fill","bgFill").replace("color","fill")),r.styles.push(s)}}setCssClass(t,n){for(let r of this.named(t))r.classes?.push(n)}getDirection(){for(let t of this.rootDoc)if(typeof t!="string"&&t.stmt==="dir")return t.value;return"TB"}setDirection(t){for(let n of this.rootDoc)if(typeof n!="string"&&n.stmt==="dir"){n.value=t;return}this.rootDoc.unshift({stmt:"dir",value:t})}trimColon(t){return t.startsWith(":")?t.slice(1).trim():t.trim()}setAccTitle(t){this.accTitle=t.replace(/^\s+/g,"")}setAccDescription(t){this.accDescr=t.replace(/\n\s+/g,` +`)}named(t){let n=[];for(let r of t.split(",")){let i=this.states.get(r);i||(this.addState(r),i=this.states.get(r.trim())),i&&n.push(i)}return n}};var cp=["$end","INVALID","NL","SD","DESCR","-->","HIDE_EMPTY","scale","WIDTH","COMPOSIT_STATE","STRUCT_START","STRUCT_STOP","STATE_DESCR","AS","ID","FORK","JOIN","CHOICE","CONCURRENT","note","NOTE_TEXT","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","CLICK","STRING","HREF","classDef","CLASSDEF_ID","DEFAULT_CLASSDEF_ID","CLASSDEF_STYLEOPTS","DEFAULT","style","STYLE_IDS","STYLEDEF_STYLEOPTS","class","CLASSENTITY_IDS","STYLECLASS","direction_tb","direction_bt","direction_rl","direction_lr","EDGE_STATE","STYLE_SEPARATOR","left_of","right_of","INVALID"];var Xk=/direction/gi,qk=/<<(?:fork|join|choice)>>|\[\[(?:fork|join|choice)\]\]/gi,Qk=/[\n\r\u2028\u2029]/g,Zk=/%%/g,Jk=/\{/g;function Oa(e,t){let n=0,r=-2;return i=>{if(r===-2||ir){e.lastIndex=i;let s=e.exec(t);r=s?s.index:-1,n=i}return r}}function _A(e){let t=e.length,n=[],r=[],i=[],s=[],a=0,o=0,c,l=Oa(Xk,e),u=Oa(qk,e),h=Oa(Qk,e),d=Oa(Zk,e),m=Oa(Jk,e),p=-1,y=-1,E=[-1,-1,-1,-1],b=[0,0,0,0],S=-1,x=-1,I=[-1,-1,-1,-1,-1,-1],L=(_,$,g)=>{n.push(_),r.push(e.slice($,g)),i.push($),o=g},O=(_,$,g,N)=>{n.push(_),r.push($),i.push(g),o=N},v=_=>{s.push(a),a=_},G=()=>{s.length>0&&(a=s.pop())},K=(_,$)=>{for(let g=0;g<_.length;g++){let N=_.charCodeAt(g),w=e.charCodeAt($+g);if(w!==N&&!(N>=97&&N<=122&&w===N-32))return!1}return!0},C=_=>{let $=_;for(;${let $=_;for(;${let $=e.indexOf(` +`,_);return $===-1?t:$},H=_=>{let $=h(_);return $===-1?t:$},z=_=>{if(_y){let $=l(_),g=$===-1?t:H(_);p=_,y=g,E[0]=E[1]=E[2]=E[3]=-1;for(let N=$;N!==-1&&N=_)return $;return-1},M=_=>{if(_x){let $=u(_),g=$===-1?t:H(_);S=_,x=g,I.fill(-1);for(let N=$;N!==-1&&N=_)return $;return-1},T=(_,$)=>{let g=d(_);return g===-1||g+2>$?(L(14,_,$),!0):g===_?(o=$,!1):(L(14,_,g),!0)},R=_=>(n.push(_),r.push(""),i.push(o),{types:n,texts:r,starts:i,error:c});for(;;){if(o>=t){switch(a){case 0:L(2,t,t);break;case 6:L(22,t,t);break;case 7:L(24,t,t);break;case 8:L(25,t,t);break;case 10:L(32,t,t);break;case 12:L(39,t,t);break;case 14:L(36,t,t);break;case 3:L(12,t,t);break;case 18:L(20,t,t);break;case 4:case 19:L(14,t,t);break}return R(0)}let _=e.charCodeAt(o);switch(a){case 0:case 1:{let $=a===0,g=_|32;if($){if(g===99&&K("click",o)&&!ot(e.charCodeAt(o+5))){L(26,o,o+5);continue}if(g===104&&K("href",o)&&!ot(e.charCodeAt(o+4))){L(28,o,o+4);continue}if(_===34){let A=e.indexOf('"',o+1);if(A!==-1){L(27,o,A+1);continue}}if(g===100&&K("default",o)&&!ot(e.charCodeAt(o+7))){L(33,o,o+7);continue}let w=z(o);if(w!==-1){L(40+w,o,oe(b[w]));continue}if(_===10){let A=o+1;for(;e.charCodeAt(A)===10;)A++;L(2,o,A);continue}if(qe(_)){o=C(o);continue}}else if(_!==10&&qe(_)){let w=o+1;for(;wo+5){L(7,o,w),v(5);continue}}if(K("style",o)){let w=C(o+5);if(w>o+5){L(34,o,w),v(13);continue}}if(K("state",o)){let w=C(o+5);if(w>o+5){o=w,v(2);continue}if($&&K("diagram",o+5)){let A=K("-v2",o+12)?o+15:o+12;if(w=C(A),w>A){L(3,o,w);continue}}}}else if(g===99){if(K("class",o)){let w=K("def",o+5),A=w?o+8:o+5,D=C(A);if(D>A){L(w?29:37,o,D),v(w?9:11);continue}}}else if(g===97&&$&&(K("acctitle",o)||K("accdescr",o))){let w=(e.charCodeAt(o+3)|32)===116,A=C(o+8),D=e.charCodeAt(A);if(D===58){L(w?21:23,o,C(A+1)),v(w?6:7);continue}if(D===123&&!w){o=C(A+1),v(8);continue}}if($){if(_===123){L(10,o,o+1),v(1);continue}}else{let w=z(o);if(w!==-1){L(40+w,o,oe(b[w]));continue}if(_===125){L(11,o,o+1),G();continue}if(_===10){o++;continue}}if(g===110&&K("note",o)){let w=C(o+4);if(w>o+4){L(19,o,w),v(15);continue}}if($&&g===104&&K("hide empty description",o)&&!ot(e.charCodeAt(o+22))){L(6,o,o+22);continue}if(_===91&&e.charCodeAt(o+1)===42&&e.charCodeAt(o+2)===93){L(44,o,o+3);continue}let N=o;for(;No){T(o,N);continue}if(_===58){for(N=o+1;N=t||A===58||A===10||A===59)break;N++}N++}if(N>o+1){O(4,e.slice(o,N).trim(),o,N);continue}if(e.charCodeAt(o+1)===58&&e.charCodeAt(o+2)===58){L(45,o,o+3);continue}}else if(_===45&&e.charCodeAt(o+1)===45){if(e.charCodeAt(o+2)===62){L(5,o,o+3);continue}if(!$){L(18,o,o+2);continue}}if(!$)return R(1);L(48,o,o+1);continue}case 2:{if(_!==10&&qe(_)){let w=o+1;for(;wg+2){L(13,o,w),v(4);continue}}if(_===10){o++,G();continue}if(_===123){L(10,o,o+1),G(),v(1);continue}if(ot(_)){let w=Z(o),A=C(w);if(A>w&&ot(e.charCodeAt(A))){let D=m(A+1);if(D!==-1&&D=48&&_<=57){let g=o+1;for(;g=48&&e.charCodeAt(g)<=57;)g++;L(8,o,g);continue}let $=C(o);if($>o&&K("width",$)&&!ot(e.charCodeAt($+5))){o=$+5,G();continue}return R(1)}case 6:L(22,o,oe(o)),G();continue;case 7:L(24,o,oe(o)),G();continue;case 8:{if(_===125){o++,G();continue}let $=e.indexOf("}",o);L(25,o,$===-1?t:$);continue}case 9:{let $=K("default",o)&&C(o+7)>o+7,g=$?o+7:Z(o),N=C(g);if(g===o||N===g)return R(1);L($?31:30,o,N),G(),v(10);continue}case 10:L(32,o,oe(o)),G();continue;case 11:{let $=Z(o);if($===o)return R(1);for(;e.charCodeAt($)===44;){let g=C($+1),N=Z(g);if(N===g)break;$=N}L(38,o,$),G(),v(12);continue}case 12:L(39,o,oe(o)),G();continue;case 13:{let $=o;for(;$$+1){O(20,e.slice(o+2,w).trim(),o,w),G();continue}}let g=e.indexOf(` +`,o),N=-1;for(;g!==-1&&(N=C(g),!(K("end note",N)&&!ot(e.charCodeAt(N+8))));)g=e.indexOf(` +`,N);if(g===-1)return R(1);O(20,e.slice(o,N).trim(),o,N+8),G();continue}case 18:{let $=C(o);if(K("as",$)){L(13,o,C($+2)),G(),v(19);continue}if(_===34){o++;continue}let g=e.indexOf('"',o);L(20,o,g===-1?t:g);continue}case 19:T(o,oe(o))&&G();continue}}}var e$=["TB","BT","RL","LR"],bd="'NL', 'ID', 'HIDE_EMPTY', 'scale', 'COMPOSIT_STATE', 'STATE_DESCR', 'FORK', 'JOIN', 'CHOICE', 'CONCURRENT', 'note', 'acc_title', 'acc_descr', 'acc_descr_multiline_value', 'CLICK', 'classDef', 'style', 'class', 'direction_tb', 'direction_bt', 'direction_rl', 'direction_lr', 'EDGE_STATE'";function RA(e,t){let{types:n,texts:r,starts:i,error:s}=_A(e),a=0,o=p=>{let y=n[a];throw y===1?s!==void 0?new Qe(s,"syntax",{type:"state",...cr(e,i[a])}):ft("state",e,i[a],"",!0):ft("state",e,i[a],`Expecting ${p}, got '${cp[y]}'`)},c=p=>(n[a]!==p&&o(`'${cp[p]}'`),r[a++]),l=()=>{let p=n[a];p!==14&&p!==44&&o("'ID', 'EDGE_STATE'");let y=r[a++].trim();return n[a]!==45?{stmt:"state",id:y,type:"default",description:""}:(a++,{stmt:"state",id:y,classes:[c(14).trim()],type:"default",description:""})};for(;n[a]===2;)a++;n[a]!==3&&o("'NL', 'SD'"),a++;let u=[],h=[],d=p=>{p!=="nl"&&u.push(p)},m=(p,y)=>{a++;let E=[];u.push({stmt:"state",id:p,type:"default",description:y,doc:E}),h.push(u),u=E};for(;;){let p=n[a];switch(p){case 2:a++;break;case 14:case 44:{let y=l();if(n[a]===4)y.description=t.trimColon(r[a++]),d(y);else if(n[a]===5){a++;let E=l();n[a]===4?d({stmt:"relation",state1:y,state2:E,description:t.trimColon(r[a++])}):d({stmt:"relation",state1:y,state2:E})}else d(y);break}case 6:d(r[a++]);break;case 7:a++,c(8),d(r[a-2]);break;case 9:n[a+1]===10?m(r[a++],""):d(r[a++]);break;case 12:{let y=r[a++];c(13);let E=c(14);if(n[a]===10)m(E,y);else if(E.includes(":")){let b=E.split(":");d({stmt:"state",id:b[0],type:"default",description:[y.trim(),b[1]]})}else d({stmt:"state",id:E,type:"default",description:y.trim()});break}case 15:d({stmt:"state",id:r[a++],type:"fork"});break;case 16:d({stmt:"state",id:r[a++],type:"join"});break;case 17:d({stmt:"state",id:r[a++],type:"choice"});break;case 18:a++,d({stmt:"state",id:t.getDividerId(),type:"divider"});break;case 19:{let y=r[a++];if(n[a]===46||n[a]===47){let E=r[a++].trim(),b=c(14).trim();d({stmt:"state",id:b,note:{position:E,text:c(20).trim()}})}else n[a]!==20&&o("'NOTE_TEXT', 'left_of', 'right_of'"),a++,c(13),c(14),d(y);break}case 40:case 41:case 42:case 43:{let y=e$[p-40];a++,t.setDirection(y),d({stmt:"dir",value:y});break}case 21:{a++;let y=c(22).trim();t.setAccTitle(y),d(y);break}case 23:{a++;let y=c(24).trim();t.setAccDescription(y),d(y);break}case 25:{let y=r[a++].trim();t.setAccDescription(y),d(y);break}case 26:{a++;let y=l(),E,b="";n[a]===28?(a++,E=c(27)):(n[a]!==27&&o("'STRING', 'HREF'"),E=r[a++],b=c(27)),c(2),d({stmt:"click",id:y,url:E,tooltip:b});break}case 29:{a++;let y=c(30).trim();d({stmt:"classDef",id:y,classes:c(32).trim()});break}case 34:{a++;let y=c(35).trim();d({stmt:"style",id:y,styleClass:c(36).trim()});break}case 37:{a++;let y=c(38).trim();d({stmt:"applyClass",id:y,styleClass:c(39).trim()});break}case 11:h.length===0&&o(`'$end', ${bd}`),a++,u=h.pop();break;case 0:return h.length>0&&o(`'STRUCT_STOP', ${bd}`),t.setRootDoc(u),u;default:o(h.length>0?`'STRUCT_STOP', ${bd}`:`'$end', ${bd}`)}}}var t$=40,n$=16,r$=44,mo=16,lp=10,s$=16,TA=10,dp=26,MA=8,i$=320,up=10,CA=8,NA=' fill="var(--_s)" stroke="var(--_b)"',yd=' fill="none" stroke="var(--_b)"',o$=/(?:^| )statediagram-(?:state|cluster-alt|cluster|note)(?= |$)/g;var a$=new Map([["rectWithTitle",1],["stateStart",2],["stateEnd",3],["choice",4],["fork",5],["join",6],["note",7],["divider",10]]),c$=["pele-node pele-state","pele-node pele-state","pele-node pele-state-start","pele-node pele-state-end","pele-node pele-state-choice","pele-node pele-state-fork","pele-node pele-state-join","pele-note","pele-cluster pele-state-composite"];function IA(e){return e==="TB"||e==="BT"}function fp(e,t,n){let r=e.state?.[t];return typeof r=="number"&&r>0?Math.min(r,2e3):n}function kA(e){let t=0,n=e.length;for(;tt&&e.charCodeAt(n-1)===34;)n--;return e.slice(t,n)}function $A(e,t,n){return en?n:e}function Ed(e,t,n,r,i){return``}function xd(e,t,n,r){let i=Bt(0,0);return i.isGroup=!0,i.dir=e,i.padX=t,i.padTop=n,i.padBottom=r,i}function OA(e,t,n){return Pn(e.direction)?Pt(n,r=>LA(e,t,n,r)):LA(e,t,n,!1)}function LA(e,t,n,r){let i=e.graph,s=t.flowchart?.curve,a=n.fontSize??16,o=Math.round(a*.875),c=n.measurer??ct(n.fontFamily,n.fontFamilyMono),l=fp(t,"wrappingWidth",200),u=n.padding??8,h=n.icons,d=r?"TB":ln(e.direction),m=Ge(void 0,!1,c,a,0),p=(V,X,le,de=0)=>Ge(V,!0,c,X,le,de),y=new Map,E=[],b=[],S=(V,X,le)=>(E.push({node:V,kind:X,style:void 0,label:m,lines:[],w:0,h:0,titleH:0}),le&&b.push(le),E.length-1);for(let V of i.nodes){if(V.shape==="noteGroup")continue;let X=V.isGroup?V.shape==="divider"?9:8:a$.get(V.shape)??0;y.set(V.id,S(V,X,void 0))}let x=E.length,I=[];for(let V=0;V{for(;deln(E[V].node.dir),v=V=>IA(I[V]===-1?d:O(I[V])),G=new Int32Array(x),K=new Uint8Array(x),C=new Array(x).fill(1/0),Z=0,oe=new Int32Array(2*x);for(let V of i.edges){let X=y.get(V.start),le=y.get(V.end);if(!(X===void 0||le===void 0)){if(V.pattern==="dashed"){K[E[X].kind===7?le:X]=1;continue}G[X]=Math.max(G[X],++oe[2*X]),G[le]=Math.max(G[le],++oe[2*le+1]),C[X]===1/0&&(C[X]=Z++),C[le]===1/0&&(C[le]=Z++)}}for(let V=0;V0?le.cssCompiledStyles.concat(le.cssStyles):le.cssCompiledStyles),Se=(de.bold?1:0)|(de.italic?2:0),_e=de.fontSize??a;X.style=de;let xe;switch(X.kind){case 8:X.label=p(le.label,_e,4e3,Se),X.titleH=X.label.height>0?X.label.height+12:0,xe=xd(O(V),mo,X.titleH+mo,mo),xe.minW=X.label.width+2*mo;break;case 9:xe=xd(O(V),lp,lp,lp);break;case 2:X.w=X.h=14;break;case 3:X.w=X.h=18;break;case 4:X.w=X.h=30;break;case 5:case 6:{let Me=$A(40*G[V]+16,72,320);X.w=v(V)?Me:CA,X.h=v(V)?CA:Me;break}case 10:break;case 7:X.label=p(le.label,o,Math.max(l,i$)),X.w=X.label.width+24,X.h=X.label.height+16;break;default:{X.label=p(le.label,_e,l,Se);let Me=X.label.width,Ce=X.label.height+2*TA;if(X.kind===1){Ce+=14;for(let ke of le.description){let be=p(ke===""?" ":ke,o,l,Se);X.lines.push(be),be.width>Me&&(Me=be.width),Ce+=be.height}}X.w=Math.max(Me+2*s$,56),X.h=Ce}}xe??=Bt(X.w,X.h),(X.kind===0||X.kind===1)&&(xe.span=(v(V)?X.w:X.h)-24),b.push(xe)}let H=[],z=[],M=[],T=new Int32Array(x),R=new Float64Array(x),_=new Float64Array(x),$=new Map,g=(V,X)=>{if(!b[V].isGroup)return!1;for(let le=I[X];le!==-1;le=I[le])if(le===V)return!0;return!1},N=(V,X)=>($.set(H.length,V),C.push(X?-1:1/0),S(void 0,10,Bt(0,0,V)));for(let V of i.edges){let X=y.get(V.start),le=y.get(V.end);if(X===void 0||le===void 0)continue;let de=p(V.label,o,l),Se=de.width>0?de.width+12:0;X===le?(T[X]++,R[X]=Math.max(R[X],Se),_[X]+=de.height):g(X,le)?X=N(X,!0):g(le,X)&&(le=N(le,!1)),M.push(V),z.push(de),H.push({src:X,dst:le,minlen:1,labelW:Se,labelH:de.height>0?de.height+4:0,route:[],labelX:0,labelY:0})}for(let V=0;V0){let Se=dp+(T[V]-1)*8;le=v(V)?Se+R[V]:Se*.75+4+_[V],X.isGroup||(v(V)?(X.w+=2*le,X.h=Math.max(X.h,_[V])):(X.h+=2*le,X.w=Math.max(X.w,R[V])),le=0)}if(!K[V]&&le===0){X.parent=I[V];continue}let de=v(V)?xd("LR",le,0,0):xd("TB",0,le,le);de.parent=I[V],C.push(C[V]),b[V].parent=S(void 0,10,de)}for(let V=0;V=0?V[Me].push(xe):X.push(xe)}let le=xe=>E[xe].kind===2?0:1,de=(xe,Me)=>le(xe)-le(Me)||(C[xe]===C[Me]?0:C[xe]0;){let xe=_e.pop();b[xe].seq=Se++;let Me=V[xe].sort(de);for(let Ce=Me.length-1;Ce>=0;Ce--)_e.push(Me[Ce])}}let w=On(b,H,d,{nodeSep:fp(t,"nodeSpacing",t$),edgeSep:n$,rankSep:fp(t,"rankSpacing",r$),portSep:20,tracks:s==="step"||s==="stepBefore"||s==="stepAfter",straight:s==="linear",headRoom:Rt("arrow_point")}),A=Math.ceil(w.width+2*u),D=Math.ceil(w.height+2*u),U=[],B=new Map;for(let V of H){let X=V.route;for(let le=3;le=0?F[X].push(V):W.push(V)}let j=W.slice();for(let V=0;V{let _e=V.filter(Ce=>E[Ce].kind===9);if(_e.length<2)return;let xe=(Ce,ke)=>ke?b[Ce].x-b[Ce].w/2:b[Ce].y-b[Ce].h/2,Me=(Ce,ke)=>ke?b[Ce].x+b[Ce].w/2:b[Ce].y+b[Ce].h/2;for(let Ce of[!0,!1]){let ke=_e.slice().sort((Ae,ie)=>xe(Ae,Ce)-xe(ie,Ce)||Ae-ie),be=!0;for(let Ae=1;Aexe(ke[Ae],Ce)+.5&&(be=!1);if(be){for(let Ae=1;Ae`}return}}for(let Ce of _e){let ke=b[Ce];ne+=Ed(ke.x-ke.w/2+u,ke.y-ke.h/2+u,ke.w,ke.h,` class="pele-divider" rx="${up}"`)}};J(j,u/2,u/2,A-u/2,D-u/2);for(let V of W){let X=E[V],le=X.node,de=X.style;if(le===void 0||de===void 0||X.kind>=9)continue;let Se=b[V],_e=Se.x+u,xe=Se.y+u,Me=X.w,Ce=X.h,ke=vt(de),be=` class="pele-label"${ke}${de.text}`,Ae;switch(X.kind){case 8:{let Te=_e-Se.w/2,ye=xe-Se.h/2;Mn(de.shape)&&Y.push({box:[Te,ye,Te+Se.w,ye+Se.h],shape:de.shape}),Ae=Ed(Te,ye,Se.w,Se.h,` rx="${up}" fill="var(--_a)"${vn(de.shape)?"":' fill-opacity="0.5"'} stroke="var(--_b)"${de.shape}`),X.titleH>0&&(Ae+=``+Ne(X.label,l$(Se,X.label.width,B)+u,ye+X.titleH/2,` class="pele-cluster-label"${ke}${de.text}`,h)),J(F[V],Te,ye+X.titleH,Te+Se.w,ye+Se.h);break}case 2:Ae=``;break;case 3:Ae=``;break;case 4:Ae=``;break;case 5:case 6:Ae=Ed(-Me/2,-Ce/2,Me,Ce,` rx="2" fill="var(--_l)"${de.shape}`);break;case 7:{let Te=f(Me/2),ye=f(Ce/2),we=f(Me/2-MA),Ie=f(MA-Ce/2);Ae=``+Ne(X.label,0,0,` class="pele-label" font-size="${o}" fill="var(--_m)"`,h);break}default:{if(Ae=Ed(-Me/2,-Ce/2,Me,Ce,` rx="${f(Math.min(up,Ce/2))}"${NA}${de.shape}`),X.kind===0){Ae+=Ne(X.label,0,0,be,h);break}let Te=TA-Ce/2+X.label.height;Ae+=``+Ne(X.label,0,Te-X.label.height/2,be,h),Te+=14;for(let ye of X.lines)Ae+=Ne(ye,0,Te+ye.height/2,` class="pele-state-description" font-size="${o}"${ke}${de.text}`,h),Te+=ye.height}}let ie=e.links.get(le.id);if(ie){let Te=bt(kA(ie.tooltip));Te&&(Ae=`${rt(Te)}`+Ae),Ae=Zn(Ae,Qn(kA(ie.url)),le.id,U,n,' target="_blank"')}let me=`${Ae}`:X.kind===7?k+=`${me} transform="translate(${f(_e)},${f(xe)})">${Ae}`:q+=`${me} transform="translate(${f(_e)},${f(xe)})">${Ae}`}let te=(V,X,le)=>{let de=b[le];if(de.isGroup)return;let Se=E[le],_e=Se.kind===5||Se.kind===6,xe=X===0?3:X-3;for(let Me of[1,0]){let Ce=Me?de.h:de.w,ke=Me?Se.h:Se.w,be=Me?Se.w:Se.h,Ae=(Me?de.y:de.x)+u,ie=(Me?de.x:de.y)+u,me=V[X+Me]-Ae;if(!(Math.abs(Math.abs(me)-Ce/2)>=.5)){V[X+Me]-=Math.sign(me)*(Ce-ke)/2,_e&&be>ke&&(V[X+1-Me]=$A(V[xe+1-Me],ie-be/2+6,ie+be/2-6));return}}},se=_c();for(let V=0;Vke.x+u+(ie?ye+Fe:-Ve),he=(Fe,Ve)=>ke.y+u+(ie?Ve:ye+Fe),Re=(Fe,Ve)=>`${f(Pe(Fe,Ve))},${f(he(Fe,Ve))}`;xe={d:`M${Re(0,-we)}C${Re(Ie,-2*we)} ${Re(Ie,2*we)} ${Re(Ie*ve,we+we*ve)}`,sx:0,sy:0,sdx:0,sdy:0,ex:Pe(0,we),ey:he(0,we),edx:Pe(-Ie,-we)-Pe(0,0),edy:he(-Ie,-we)-he(0,0)};let Be=Math.hypot(xe.edx,xe.edy)||1;xe.edx/=Be,xe.edy/=Be;let ge=dp+(T[X.src]-1)*8,Le=ue[X.src]+de.height/2;ue[X.src]+=de.height,X.labelX=ie?ke.x+ye+ge+4+X.labelW/2:ke.x,X.labelY=ie?ke.y-_[X.src]/2+Le:ke.y+ye+ge*.75+4+Le}else{let ke=X.route.slice(),be=se.of(X.src,Jn(ke,0,b[X.src])),Ae=se.of(X.dst,Jn(ke,ke.length-3,b[X.dst]));for(let me=0;me=6){let me=b[ie],Te=E[X.src].kind===10,ye=Te?0:ke.length-3,we=(me.dir==="TB"||me.dir==="LR")===Te,Ie=IA(me.dir)?[ke[ye],me.y+u+(we?E[ie].titleH-me.h/2:me.h/2),0]:[me.x+u+(we?-me.w/2:me.w/2),ke[ye+1],1];ke=Te?Ie.concat(ke):ke.concat(Ie)}xe=Cn(ke,typeof s=="string"?s:void 0,0,Rt(_e),be,Ae)}let Me=Mr(xe.d,[xe.ex,xe.ey],Y,"",xe.tokens);Me===""&&(re+=Cr(xe,"none",_e));let Ce=Se?`pele-note-edge" stroke="${Me||"var(--_b)"}" stroke-dasharray="3 4`:Me?`pele-transition" stroke="${Me}`:"pele-transition";if(P+=``+_t(_e,xe.ex,xe.ey,xe.edx,xe.edy,Me||"var(--_l)")+"",de.width>0){let ke=X.labelX+u,be=X.labelY+u;ee+=dn(le.id,de,ke,be,"",h)}}let ce=Fc(e.title,c,a,u,A,D,(Q?`${Q}`:"")+(ne?`${ne}`:"")+Dn(re)+(P?`${P}`:"")+(ee?`${ee}`:"")+`${q}${k}`);return{svg:at("state",ce.width,ce.height,a,n,e,ce.content),width:ce.width,height:ce.height,links:U}}function l$(e,t,n){let r=n.get(Math.round(e.y-e.h/2));if(r===void 0||t===0)return e.x;let i=e.x-e.w/2,s=t/2,a=e.x,o=-1;for(let c of[e.x,i+mo+s,i+e.w-mo-s]){let l=1/0;for(let u of r)u>i&&u=6)return c;l>o+.5&&(o=l,a=c)}return a}var DA={type:"state",math:!0,parse(e,t,n){let r=new gd;return n&&(r.title=n),RA(e,r),r},render:OA};var d$=34,u$=24,f$=8,h$=2e4,vA=1e4,hp=2e6,PA=4,p$=3,FA=8,pp=20,BA=20,WA=14,m$=3;function GA(e,t,n,r,i=u$){let s=e.length;if(s===0)return{width:0,height:0};let a=n==="LR"||n==="RL",o=n==="BT"||n==="RL",c=[];for(let H=s-1;H>=0;H--)e[H].parent<0&&e[H].isGroup&&c.push(H);let l=Math.max(1,c.length),u=new Int32Array(s).fill(-1);c.forEach((H,z)=>u[H]=z);let h=new Uint8Array(s);for(let H=0;H=0&&(h[e[H].parent]=1);let d=new Float64Array(l).fill(i),m=i,p=H=>{let z=H,M=i;for(let R=0;e[z].parent>=0&&Rd[T]&&(d[T]=M),M>m&&(m=M),T},y=new Int32Array(s).fill(-1),E=[];for(let H=0;H=0||(!e[H].isGroup||!h[H])&&(y[H]=E.length,E.push(H));let b=H=>a?H.w:H.h,S=H=>a?H.h:H.w,x=E.map(H=>Ys(S(e[H]),b(e[H]))),I=[],L=[],O=1;{let H=new Set;for(let z=0;z0||H.has(_))&&(O=2),H.add(_),I.push(Hs(T,R,M.minlen,a?M.labelH:M.labelW,a?M.labelW:M.labelH)),L.push(z)}}Do(x,I),vo(x,I,O);let v=I.length,G=Int32Array.from(E,p),K=(H,z)=>{let M=d.map((he,Re)=>z[Re]?Math.max(he,BA):he),T=new Uint8Array(l),R=0,_=new Int32Array(v);for(let he=0;heh$,g=E.length+($?0:R),N=new Int32Array(g),w=new Int32Array(g),A=new Float64Array(g),D=new Float64Array(g),U=new Uint8Array(g),B=0;for(let he=0;heB&&(B=N[he]);let F=new Int32Array(v).fill(-1),W=new Int32Array(v).fill(-1),j=[];{let he=E.length;for(let Re=0;Re0&&(Oe=Fe+(Ve-Fe>>1),O===2&&(Oe&1)===0&&Oe--),F[Re]=he;let je=ge;for(let Je=Fe+1;Je{he.sort((Re,Be)=>w[Re]-w[Be]||te[Re]-te[Be]||Re-Be);for(let Re=0;Re0;he++){let Re=(he&1)===0;for(let Be=1;Be<=B;Be++){let ge=k[Re?Be:B-Be],Le=Re?Q:Y,Fe=Re?ne:q;for(let Ve of ge){let Oe=0,je=Le[Ve+1]-Le[Ve];for(let Je=Le[Ve];Je0?Oe/je:J[Ve]}se(ge)}}let re=(he,Re)=>U[he]||U[Re]?r.edgeSep:r.nodeSep,P=(he,Re)=>{let Be=0;for(;Be{let ge=A[he[Re]];for(let Le=Re;Le0?d$:0;for(let he=0;heue&&(ue=Re.padTop)}for(let he of k)P(he,(Re,Be,ge)=>{let Le=ee(he,Be,ge);Le>ae[w[he[Be]]]&&(ae[w[he[Be]]]=Le)});let ce=new Float64Array(l+1);for(let he=0;he{let ge=w[he[Re]],Le=(ce[ge]+M[ge]+(ce[ge+1]-M[ge])-ee(he,Re,Be))/2;for(let Fe=Re;Fe<=Be;Fe++)pe[he[Fe]]=Le+A[he[Fe]]/2,Fe{let ge=w[he[Re]],Le=ce[ge]+M[ge];for(let Ve=Re;Ve<=Be;Ve++){let Oe=he[Ve];pe[Oe]=Math.max(V[Oe],Le+A[Oe]/2),Ve=Re;Ve--){let Oe=he[Ve];pe[Oe]=Math.min(pe[Oe],Fe-A[Oe]/2),Ve>Re&&(Fe=pe[Oe]-A[Oe]/2-re(he[Ve-1],Oe))}};for(let he of k)P(he,X);for(let he=0;he<4&&B>0;he++){let Re=(he&1)===0;for(let Be=1;Be<=B;Be++){let ge=k[Re?Be:B-Be],Le=Re?Q:Y,Fe=Re?ne:q;for(let Ve of ge){let Oe=0,je=0;for(let Je=Le[Ve];Je0?Oe/je:pe[Ve]}P(ge,le)}}let de=new Float64Array(B+1),Se=new Float64Array(B+1),_e=new Float64Array(B+1).fill(r.rankSep/O);if(H.some(he=>he===1)){let he=r.rankSep/O;_e.fill(he/m$);for(let Re=0;ReO)continue;let Ve=Math.min(he,(Be.labelH+2*pp-Math.min(D[ge],D[Le])/2)/_[Re]);for(let Oe=N[ge];Oe_e[Oe]&&(_e[Oe]=Ve);continue}let Fe=F[Re];if(Fe<0||_[Re]<=O*Be.minlen){for(let Ve=N[ge];Ve=.5)&&(_e[N[Oe]]=he)}}}let xe=ue+m;for(let he=0;he<=B;he++){let Re=0;for(let Be of k[he])D[Be]>Re&&(Re=D[Be]);de[he]=xe,Se[he]=xe+Re,xe+=Re+(he===B?0:_e[he])}let Me=xe+m,Ce=ce[l],ke=he=>o?ue+Me-he:he,be=(he,Re)=>a?ke(Re):he,Ae=(he,Re)=>a?he:ke(Re),ie=a?1:0;for(let he=0;he=0||y[he]>=0)continue;let Re=0;for(let Be=e[he].parent;Be>=0&&Reme[Re]-me[he]||he-Re);let ye=new Float64Array(s*4);for(let he=0;he{Re.x-Re.w/2ye[he*4+2]&&(ye[he*4+2]=Re.x+Re.w/2),Re.y+Re.h/2>ye[he*4+3]&&(ye[he*4+3]=Re.y+Re.h/2)};for(let he of E)e[he].parent>=0&&u[e[he].parent]<0&&we(e[he].parent,e[he]);for(let he of Te){let Re=e[he];if(ye[he*4]===1/0)continue;let Be=Math.max(ye[he*4+2]-ye[he*4]+2*Re.padX,Re.minW);Re.x=(ye[he*4]+ye[he*4+2])/2,Re.w=Be,Re.y=(ye[he*4+1]-Re.padTop+ye[he*4+3]+Re.padBottom)/2,Re.h=ye[he*4+3]-ye[he*4+1]+Re.padTop+Re.padBottom,Re.parent>=0&&u[Re.parent]<0&&we(Re.parent,Re)}for(let he of t)he.route=[];for(let he=0;he=0)for(let Je=Ve;Jede[N[Je]]&&Fe.push(pe[Je],Se[N[Je]]);Fe.push(pe[Le],de[N[Le]]+(Se[N[Le]]-de[N[Le]]-D[Le])/2);let Oe=[];for(let Je=0;Je=0){let Je=(de[N[je]]+Se[N[je]])/2;Be.labelX=be(pe[je],Je),Be.labelY=Ae(pe[je],Je)}else Be.labelX=(Oe[0]+Oe[Oe.length-3])/2,Be.labelY=(Oe[1]+Oe[Oe.length-2])/2}for(let he of t){if(he.route.length>0||he.src===he.dst)continue;let Re=e[he.src],Be=e[he.dst],[ge,Le]=UA(Re,Be),[Fe,Ve]=UA(Be,Re),Oe=Math.abs(Fe-ge)>Math.abs(Ve-Le)?1:0;he.route=[ge,Le,Oe,Fe,Ve,Oe],he.labelX=(ge+Fe)/2,he.labelY=(Le+Ve)/2}let Ie=new Uint8Array(v),ve=t.reduce((he,Re)=>he+Re.route.length/3,0),Pe=v*(E.length+t.length+ve);if(Pe<=hp){let he=Oe=>(de[N[Oe]]+Se[N[Oe]])/2,Re=t.map(Oe=>[a?Oe.labelY:Oe.labelX,ke(a?Oe.labelX:Oe.labelY)]),Be=(Oe,je,Je,$e,Ze,tt,mt,dt)=>Je>Ze-mt/2&&Oett-dt/2&&je{for(let dt=0;dt0&&Ee.src!==Ee.dst&&Be(Oe,je,Je,$e,Re[dt][0],Re[dt][1],a?Ee.labelH:Ee.labelW,a?Ee.labelW:Ee.labelH))return!1}return!0},Le=(Oe,je,Je,$e,Ze)=>{let tt=0;for(let mt=0;mtOe&&Math.min(dt[Ee-3],dt[Ee])je&&Math.min(dt[Ee-2],dt[Ee+1])<$e){tt++;break}}return tt},Fe=(Oe,je,Je)=>{let $e=0;for(let Ze=0;Ze{let tt=Math.abs(Je-Oe)<.5,mt=tt?Math.min(je,$e):Math.min(Oe,Je),dt=tt?Math.max(je,$e):Math.max(Oe,Je),Ee=tt?Oe:je;for(let We=0;We=PA||Math.abs(Ye-Ee)>=PA)continue;let He=Xe[ze-3+(tt?1:0)],nt=Xe[ze+(tt?1:0)];if(Math.min(dt,Math.max(He,nt))-Math.max(mt,Math.min(He,nt))>1)return!0}}return!1};for(let Oe=0;Oe{for(let st=2;st0){let st=je.labelW,pt=je.labelH;for(let gt=2;gt0?FtCe||Nt-pt/2<0||Nt+pt/2>Me||!ge(yt-st/2,Nt-pt/2,yt+st/2,Nt+pt/2,-1,-1,Je))continue;let Sr=be(yt,Nt),an=Ae(yt,Nt);Le(Sr-$e.labelW/2,an-$e.labelH/2,Sr+$e.labelW/2,an+$e.labelH/2,Je)>0||(nt=yt,it=Nt,wt=En)}if(wt<0)return!1}let ut=[Ye[0],Ye[1]];for(let st=2;st2?pp:0,Ft=st+2Nt+Ft+1&&(Nt&&ut.push(Ye[st-2]+pt/yt*Nt,Ye[st-1]+gt/yt*Nt),Ft&&ut.push(Ye[st]-pt/yt*Ft,Ye[st+1]-gt/yt*Ft)),ut.push(Ye[st],Ye[st+1])}$e.route=[];for(let st=0;st0&&($e.labelX=be(nt,it),$e.labelY=Ae(nt,it),Re[Je]=[nt,it]),Ie[Oe]=1,!0};if(ze([mt+De*A[Ze]/2,Ee,dt,Ee,dt,We-Xe*D[tt]/2],2)||ze([mt,Ee+Xe*D[Ze]/2,mt,We,dt-De*A[tt]/2,We],2)||Pe>hp/FA)continue;let et=[];for(let Ye of w[Ze]Ye.cost-He.cost);for(let Ye of et)if(ze(Ye.pts,1)){T[Ye.lane]=1;break}}}return{width:a?Me:Ce,height:a?Ce:Me,routed:Ie,margins:T,work:Pe}},C=new Uint8Array(v),Z=new Uint8Array(l),oe=K(C,Z);for(let H=0;HM&oe.routed[T]);if(z.every((M,T)=>M===C[T])&&oe.margins.every((M,T)=>M===Z[T]))break;C=z,Z=oe.margins,oe=K(C,Z)}return C.some((H,z)=>H&&!oe.routed[z])&&(oe=K(new Uint8Array(v),new Uint8Array(l))),{width:oe.width,height:oe.height}}function UA(e,t){let n=t.x-e.x,r=t.y-e.y,i=Math.max(e.w/2,.5),s=Math.max(e.h/2,.5);if(Math.abs(n)`+(l&&d?`${d}`:d)+""}function y$(e,t){let n=e.x-e.w/2,r=e.y-e.h/2;return t==="LR"||t==="RL"?[n,r,n+e.padTop,r+e.h]:[n,r,n+e.w,r+e.padTop]}var E$={type:"swimlane",prepare:g$,layout:(e,t,n,r,i)=>GA(e,t,n,r,i?12:void 0),drawGroup:b$,filledBox:y$},HA={type:"swimlane",math:!0,parse:yl.parse,render:(e,t,n)=>bl(e,t,n,E$)};var Ad=class{constructor(){fe(this,"type","timeline");fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"direction","LR");fe(this,"sections",[]);fe(this,"periods",[]);fe(this,"currentSection","")}getCommonDb(){return this}setDiagramTitle(t){this.title=t}setAccTitle(t){this.accTitle=t.replace(/^\s+/g,"")}setAccDescription(t){this.accDescr=t.replace(/\n\s+/g,` +`)}setDirection(t){this.direction=t}addSection(t){this.currentSection=t,this.sections.push(t)}addTask(t,n,r){this.periods.push({text:t,events:r?[r]:[],section:this.currentSection,sectionIndex:this.sections.length-1})}addEvent(t){let n=this.periods[this.periods.length-1];if(!n)throw new Qe("An event needs a time period before it.","semantic",{type:"timeline"});n.events.push(t)}};var KA=["$end","EOF","INVALID","NEWLINE","timeline","timeline_lr","timeline_td","title","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","section","period","event"];function zA(e){let t=e.length,n=[],r=[],i=[],s={types:n,texts:r,starts:i},a=0,o=(c,l)=>{n.push(c),r.push(e.slice(a,l)),i.push(a),a=l};for(;a=Pl(e,a),!(a>=t);){let c=e.charCodeAt(a),l=a+1;if(c===10){for(;e.charCodeAt(l)===10;)l++;o(3,l);continue}if(nr(e,a,"timeline")){for(l=a+8;e.charCodeAt(l)===32||e.charCodeAt(l)===9;)l++;let u=nr(e,l,"lr");if(l>a+8&&(u||nr(e,l,"td"))&&!ot(e.charCodeAt(l+2))){o(u?5:6,l+2);continue}if(!ot(e.charCodeAt(a+8))){o(4,a+8);continue}}if(nr(e,a,"title")){for(l=a+5;e.charCodeAt(l)!==10&&qe(e.charCodeAt(l));)l++;if(l===t||e.charCodeAt(l)===10){a=l;continue}let u=e.charCodeAt(a+5);if(u!==13&&qe(u)){o(7,wa(e,a+6));continue}}if(l=Fl(e,a,s,8),l!==a){a=l;continue}if(nr(e,a,"section")&&qe(e.charCodeAt(a+7))){for(l=a+8;la+8){o(13,l);continue}}if(c!==58){l=a+1;for(let u=e.charCodeAt(l);la+2){o(15,l);continue}}o(2,a+1)}return(i.length===0||i[i.length-1]{let l=n[o]===0?"1":KA[n[o]];throw ft("timeline",e,i[o],`Expecting ${c}, got '${l}'`)},a=n[0];a!==4&&a!==5&&a!==6&&s(0,"'timeline', 'timeline_lr', 'timeline_td'"),a!==4&&t.setDirection(a===5?"LR":"TD");for(let o=1;;o++){let c=r[o];switch(n[o]){case 3:break;case 7:t.getCommonDb().setDiagramTitle(c.substring(6));break;case 8:t.getCommonDb().setAccTitle(r[++o].trim());break;case 10:t.getCommonDb().setAccDescription(r[++o].trim());break;case 12:t.getCommonDb().setAccDescription(c.trim());break;case 13:t.addSection(c.substring(8));break;case 14:t.addTask(c,0,"");break;case 15:t.addEvent(c.substring(2));break;case 1:return;default:s(o,x$)}}}var Sd=12,jA=8,A$=152,S$=216,w$=264,bi=20,go=20,wd=14,Da=8,mp=8,_d=12,_$=' fill="var(--_bg)"',XA=' fill="none" stroke="var(--_b)"';function gp(e,t,n,r,i){return``}function QA(e,t,n){return e.direction==="TD"?qA(e,t,n,!0):Pt(n,r=>qA(e,t,n,r))}function qA(e,t,n,r){let i=n.fontSize??16,s=Math.round(i*.875),a=n.measurer??ct(n.fontFamily,n.fontFamilyMono),o=n.padding??8,c=t.timeline?.disableMulticolor!==!0,l=e.periods,u=e.sections.length>0,h=e.sections.map((se,re)=>({section:re,periods:[]})),d={section:-1,periods:[]};l.forEach((se,re)=>(h[se.sectionIndex]??d).periods.push(re)),d.periods.length>0&&h.unshift(d);let m=r&&n.maxWidth!==void 0&&n.maxWidth>0?n.maxWidth-2*o:1/0,p=go+wd*2+4*Sd,y=Math.min(A$,Math.max(80,Math.round((m-p)*.38))),E=Math.min(w$,Math.max(110,m-p-y)),b=y,S=()=>r?E:b,x=l.map(se=>br(se.text,a,i,b)),I=l.map(se=>se.events.map(re=>br(re,a,s,S()))),L=0;for(let se of x)L=Math.max(L,se.width);if(!r)for(let se of I)for(let re of se)L=Math.max(L,re.width);let O=L>b;if(r)for(let se of I)for(let re of se)O||=re.width>E;O&&(b=Math.min(Math.max(Math.ceil(L),y),m===1/0?S$:y),x=l.map(se=>Wn(se.text,a,i,b)),I=l.map(se=>se.events.map(re=>Wn(re,a,s,S()))));let v=Math.round(i*1.5),G=b+2*Sd,K=S()+2*Sd,C=se=>Math.max(se.height,v)+2*jA,Z=se=>Math.max(se.height,Math.round(s*1.5))+2*jA,oe=(se,re)=>se.section>=0?se.section:u?void 0:c?re:0,H=(se,re)=>{let P=oe(se,re);return P===void 0?"var(--_m)":Et(P)},z=se=>(se===void 0?"":fs(se))||_$,M=!1;for(let se of I)se.length>0&&(M=!0);let T=0;for(let se of h)T+=Math.max(se.periods.length,1);let R=G+bi,_=l.length>0,$=r?G+(M?go+wd*2+K:_?go+_d:0):T>0?T*R-bi+(_?_d+Lt:0):0,g=Wn(e.title,a,i,Math.max($,320),1),N=g.height>0?g.height+16:0,w=Math.max($,g.width),A=o+(w-$)/2,D=o+N,U=(se,re)=>Wn(e.sections[se.section],a,i,re-2*Sd,1),B=(se,re,P,ee,ae,ue)=>gp(P,ee,ae,ue,` fill="${Et(se.section)}"`)+Ne(re,P+ae/2,ee+ue/2,' font-weight="var(--_hw)"'+z(se.section)),F=(se,re,P,ee,ae,ue)=>gp(ee,ae,G,ue,` fill="${P}"`)+Ne(x[se],ee+G/2,ae+ue/2,z(oe(re,se))),W=(se,re,P,ee,ae)=>''+gp(P,ee,K,ae,` fill="${re}" fill-opacity="0.16"`)+Ne(se,P+K/2,ee+ae/2,` font-size="${s}"`)+"",j=(se,re,P)=>``,Q=se=>se.section>=0?``:"",Y=se=>``,ne="",q;if(r){let se=A+G+go,re=se+wd,P=re+wd,ee=D;for(let ae of h){if(ne+=Q(ae),ae.section>=0){let ue=U(ae,$),ce=C(ue);ne+=B(ae,ue,A,ee,$,ce),ee+=ce+mp+4}for(let ue of ae.periods){let ce=H(ae,ue),pe=C(x[ue]),V=I[ue].length>0?Z(I[ue][0]):pe,X=ee+Math.max(pe,V)/2,le=`M${f(A+G)},${f(X)}H${f(se)}`,de="",Se=X-V/2,_e=X;for(let xe of I[ue]){let Me=Z(xe);_e=Se+Me/2,le+=`M${f(re)},${f(_e)}H${f(P)}`,de+=W(xe,ce,P,Se,Me),Se+=Me+Da}de&&(le+=`M${f(se)},${f(X)}H${f(re)}V${f(_e)}`),ne+=Y(ue)+F(ue,ae,ce,A,X-pe/2,pe)+``+j(se,X,ce)+de+"",ee=Math.max(X+pe/2,Se-Da)+bi}ae.periods.length===0&&(ee+=bi-mp-4),ae.section>=0&&(ne+="")}if(h.length>0&&(ee-=bi),_){let ae=ee+_d+Lt;ne=``+_t("arrow_point",se,ae,0,1,"var(--_l)")+ne,ee=ae}q=ee+o}else{let se=0,re=h.map(V=>{if(V.section<0)return;let X=U(V,Math.max(V.periods.length,1)*R-bi);return se=Math.max(se,C(X)),X}),P=0;for(let V of x)P=Math.max(P,C(V));let ee=D+(u?se+mp:0),ae=ee+P+(P>0?go:0),ue=ae+go,ce=_?ae+_d:D+se,pe=0;if(h.forEach((V,X)=>{let le=Math.max(V.periods.length,1),de=A+pe*R;ne+=Q(V);let Se=re[X];Se&&(ne+=B(V,Se,de,D,le*R-bi,se)),V.periods.forEach((_e,xe)=>{let Me=H(V,_e),Ce=de+xe*R,ke=Ce+G/2,be=`M${f(ke)},${f(ee+P)}V${f(I[_e].length>0?ue:ae)}`,Ae="",ie=ue;for(let me of I[_e]){let Te=Z(me);ie>ue&&(be+=`M${f(ke)},${f(ie-Da)}V${f(ie)}`),Ae+=W(me,Me,Ce,ie,Te),ie+=Te+Da}ce=Math.max(ce,ie-Da),ne+=Y(_e)+F(_e,V,Me,Ce,ee,P)+``+j(ke,ae,Me)+Ae+""}),V.section>=0&&(ne+=""),pe+=le}),_){let V=A+$;ne=``+_t("arrow_point",V,ae,1,0,"var(--_l)")+ne}q=ce+o}let k=Math.ceil(w+2*o),J=Math.ceil(Math.max(q,o*2)),te=Ne(g,k/2,o+g.height/2,' class="pele-title" font-weight="var(--_tw)"')+ne;return{svg:at("timeline",k,J,i,n,e,te),width:k,height:J,links:[]}}var ZA={type:"timeline",parse(e,t,n){let r=new Ad;return r.title=n,VA(e,r),r},render:QA};var bp=/[─━│┃└┗├┣]/,tS=/[└┗├┣]/,R$=/[─━]/,JA=/^[\s│┃]+$/,T$=/^[\s─━│┃└┗├┣]+$/,M$=/^\s*(title[\t ]|accTitle[\t ]*:|accDescr[\t ]*[:{])/,C$=/^\s*%%/,N$=" ";function I$(e){return e.some(t=>bp.test(t))}function k$(e){for(let t of e){let n=tS.exec(t);if(n?.index&&n.index>0)return n.index}return 4}function nS(e,t){return e.replace(/\bline\s+(\d+)\b/gi,(n,r)=>{let i=t.get(parseInt(r,10));return i?`line ${i}`:n})}function yp(e,t){let n=0;for(let r=1;ru.trim()===""||C$.test(u)||M$.test(u),a=[];for(let u=i+1;u{c.push(u),t.set(c.length,h+1),d&&n.set(c.length,d)};for(let u=0;u<=i;u++)l(r[u],u);for(let u=i+1;u$$(h,y+Math.max(S-b.length,0)))}else{if(T$.test(d))continue;bp.test(d)?l(h,u):/^\s+/.test(d)?eS(e,u,"Unexpected indentation without box-drawing characters. In box-drawing format, use ├── or └── prefixes for indented nodes."):l(h,u)}}return{text:c.join(` +`),lineMap:t,columns:n}}function L$(e,t){if(e.startsWith("##",t)||e.startsWith("icon(",t))return!0;if(!e.startsWith(":::",t))return!1;let n=t+3;for(;Xn(e.charCodeAt(n));)n++;let r=e.charCodeAt(n);return r>=65&&r<=90||r>=97&&r<=122||r===95}function O$(e,t){let n=e.charCodeAt(t);if(Xn(n)||n===10||n===13||n===34||n===39||e.startsWith(":::",t)||e.startsWith("icon(",t)||e.startsWith("##",t))return-1;let r=e.length,i=t+1;for(;i0&&Xn(e.charCodeAt(t-1));)t--;return t===e.length?e:e.slice(0,t)}function Ep(e,t){switch(e){case"INDENTATION":return t?.length||0;case"QUOTED_NAME":return t.substring(1,t.length-1);case"BARE_NAME":return oS(t);case"CLASS_ANNOTATION":return t.trim().substring(3).trim();case"ICON_ANNOTATION":{let n=t.trim();return n.substring(5,n.length-1)}case"DESC_ANNOTATION":return t.trim().substring(2).trim();default:return}}function aS(e){let t=new Ut(Yt(e,iS,"treeView"),iS,"treeView"),n={$type:"TreeView",nodes:[]};for(t.expect(0);;)if(t.kind===1)n.accDescr=Vt(t.take());else if(t.kind===2)n.accTitle=zt(t.take());else if(t.kind===3)n.title=Kt(t.take());else break;for(;t.kind!==-1;){let r={$type:"TreeNode",name:""};if(t.kind===7&&(r.indent=t.take().length),t.kind===8){let i=t.take();r.name=i.substring(1,i.length-1)}else t.kind===12?r.name=oS(t.take()):t.fail("a name");for(;;)if(t.kind===4)r.classAnnotation=Ep("CLASS_ANNOTATION",t.take());else if(t.kind===5)r.iconAnnotation=Ep("ICON_ANNOTATION",t.take());else if(t.kind===6)r.descAnnotation=Ep("DESC_ANNOTATION",t.take());else break;n.nodes.push(r)}return n}var xp=class{constructor(){fe(this,"count",1);fe(this,"root",{id:0,level:-1,name:"/",nodeType:"directory",children:[]});fe(this,"stack",[this.root])}addNode(t,n,r,i,s,a){let o=this.stack;for(;t<=o[o.length-1].level;)o.pop();let c={id:this.count++,level:t,name:n,nodeType:r,icon:s,cssClass:i,description:a,children:[]};o[o.length-1].children.push(c),o.push(c)}};function D$(e,t){for(let n of e.nodes){let r=typeof n.indent=="number"?n.indent:0,i=n.name,s=i.endsWith("/");s&&(i=i.slice(0,-1));let a=n.iconAnnotation;t.addNode(r,i,s?"directory":"file",n.classAnnotation||void 0,a!==void 0?a||"none":void 0,n.descAnnotation||void 0)}}function cS(e){let{text:t,lineMap:n,columns:r}=rS(e);try{return aS(t)}catch(i){if(!(i instanceof Qe)||t===e)throw i;let s=n.get(i.line);if(s===void 0)throw i;let a=i.column>0?r.get(i.line)?.(i.column-1)??i.column-1:0,o=cr(e,yp(e,s)+a),c=i.message.includes(` +`)?i.message.indexOf(` +`):i.message.length,l=i.message.slice(c),u=nS(i.message.slice(0,c),new Map([[i.line,o.line]]))+(i.snippet?l.replace(i.snippet,()=>o.snippet):l);throw new Qe(u,i.code,{type:i.type,line:o.line,column:i.column>0?o.column:0,snippet:i.snippet?o.snippet:""})}}function lS(e,t){let n=new xp;return D$(e,n),{type:"treeView",title:e.title||t,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,` +`):void 0,root:n.root,count:n.count}}var va="mermaid-treeview",Rd=new Map([["folder","M3 6.5A1.5 1.5 0 0 1 4.5 5h4.6l2.4 2.5h8A1.5 1.5 0 0 1 21 9v9a1.5 1.5 0 0 1-1.5 1.5h-15A1.5 1.5 0 0 1 3 18z"],["file","M6.5 3h7L19 8.5v11a1.5 1.5 0 0 1-1.5 1.5h-11A1.5 1.5 0 0 1 5 19.5v-15A1.5 1.5 0 0 1 6.5 3zM13.5 3v5.5H19"]]);function Ap(e,t){if(e===void 0||!Object.prototype.hasOwnProperty.call(e,t))return;let n=e[t];return typeof n=="string"?n:void 0}function v$(e,t){let n=Ap(t?.filenameIcons,e);if(n)return n;let r=e.lastIndexOf(".");if(r>0){let i=e.substring(r).toLowerCase();return Ap(t?.extensionIcons,i)??Ap(t?.extensionIcons,i.slice(1))}}function dS(e,t){return e.includes(":")?e:Rd.has(e)||!t?`${va}:${e}`:`${t}:${e}`}function Sp(e,t){if(e.icon!=="none"){if(e.icon)return dS(e.icon,t.defaultIconPack);if(t.showIcons){if(e.nodeType==="file"){let n=v$(e.name,t);if(n==="none")return;if(n)return dS(n,t.defaultIconPack)}return`${va}:${e.nodeType==="directory"?"folder":"file"}`}}}function uS(e){let t=r=>typeof r=="object"&&r!==null&&!Array.isArray(r)?r:void 0,n=t(e.treeView)??{};return{showIcons:!!n.showIcons,defaultIconPack:typeof n.defaultIconPack=="string"?n.defaultIconPack:"",filenameIcons:t(n.filenameIcons),extensionIcons:t(n.extensionIcons)}}var P$=6,F$=16,B$=7,W$=4,Td=4;function Md(e,t,n,r,i){let s=e.treeView?.[t];return typeof s=="number"&&s>=r&&s<=i?s:n}function U$(e){return{paddingX:Md(e,"paddingX",5,0,100),paddingY:Md(e,"paddingY",2,0,100),rowIndent:Md(e,"rowIndent",15,0,400),lineThickness:Md(e,"lineThickness",1,.25,12)}}function fS(e,t,n){return An(n,r=>G$(e,t,n,r))}function G$(e,t,n,r){let i=n.fontSize??16,s=n.measurer??ct(n.fontFamily,n.fontFamilyMono),a=n.padding??8,o=uS(t),c=Array.isArray(n.monospace)&&n.monospace.includes("files"),l=c?` font-family="${fr}"`:"",{paddingX:u,paddingY:h,rowIndent:d,lineThickness:m}=U$(t),p=0,y=e.root.children.map(A=>[A,0]);for(let A=0;r&&A0?x.height+12:0,L=A=>A.some(D=>Sp(D,o)!==void 0),O=[],v=new Map,G=[],K=(A,D)=>{let U=L(A);for(let B=A.length-1;B>=0;B--)G.push([A[B],D,U])};K(e.root.children,0);let C=0,Z=!1,oe=0;for(;G.length>0;){let[A,D,U]=G.pop(),B=D*E,F=bt(A.name),W=B+(U?S+P$:0),j=Math.max(40,(n.maxWidth??320)-2*a-2*Td-W),Q=(A.nodeType==="directory"?1:0)|(c?4:0),Y=r?Qs(F,s,i,j,Q):void 0,ne=r&&A.description?Qs(bt(A.description),s,i,j,2):void 0,q=Y?Y.width:s.width(F,i,Q);W+q>C&&(C=W+q);let k=A.cssClass!==void 0&&A.cssClass.split(/\s+/).includes("highlight");k&&(Z=!0);let J=r?Math.max(b,(Y?.height??0)+(ne?.height??0)+2*h):b,te=oe+(r?h+Math.max(S,Y?.height??0)/2:J/2),se={node:A,x:B,cy:te,icon:Sp(A,o),text:F,labelX:W,highlighted:k,label:Y,description:ne,top:oe,height:J};oe+=J,O.push(se),v.set(A,se),K(A.children,D+1)}let H=C+F$,z=C;for(let A of O){let D=A.node.description;if(!D)continue;let U=A.description?A.description.width:s.width(bt(D),i,2);z=Math.max(z,(r?A.labelX:H)+U)}z=Math.max(z,x.width);let M=a+(Z?Td:0),T=a+I,R=Math.ceil(z+2*M),_=Math.ceil(T+oe+a),$="";for(let A of O){let D=A.node.children;if(D.length===0)continue;let U=M+A.x+B$,B=Math.max(U,M+A.x+E-u),F=T+v.get(D[D.length-1]).cy,W=Math.min(W$,B-U),j=`M${f(U)},${f(T+A.top+A.height-2)}V${f(F-W)}`;W>0&&(j+=`Q${f(U)},${f(F)} ${f(U+W)},${f(F)}H${f(B)}`);for(let Q=0;QU;Q++)j+=`M${f(U)},${f(T+v.get(D[Q]).cy)}H${f(B)}`;$+=``}let g=i*.35,N="";for(let A of O){let D=A.node,U=T+A.cy,B=D.nodeType==="directory",F="";if(A.highlighted){let W=M+A.x-Td;F+=``}if(A.icon!==void 0){let W=A.icon.startsWith(va+":")?A.icon.slice(va.length+1):"",j=Rd.get(W)??Rd.get(B?"folder":"file"),Q=n.icons?.(A.icon)??``;F+=`${Q}`}A.label?F+=Zr(A.label,M+A.labelX,T+A.top+h,` class="pele-label"${B?' font-weight="var(--_hw)"':""}${l}`):A.text!==""&&(F+=`${rt(A.text)}`),A.description?F+=Zr(A.description,M+A.labelX,T+A.top+h+(A.label?.height??0),' class="pele-tree-description" font-style="italic" fill="var(--_m)"'):D.description&&(F+=`${rt(bt(D.description))}`),N+=`${F}`}let w=Ne(x,R/2,a+x.height/2,' class="pele-title" font-weight="var(--_tw)"')+($?`${$}`:"")+N;return{svg:at("treeView",R,_,i,n,e,w),width:R,height:_,links:[]}}var hS={type:"treeView",parse:(e,t,n)=>lS(cS(e),n),render:fS};function Y$(e){let t=[],n=[];for(let r of e){let i=r.type==="Leaf",s={name:r.name,children:i?void 0:[]};for(s.classSelector=r.classSelector,r.cssCompiledStyles&&(s.cssCompiledStyles=r.cssCompiledStyles),i&&r.value!==void 0&&(s.value=r.value);n.length>0&&n[n.length-1].level>=r.level;)n.pop();n.length===0?t.push(s):n[n.length-1].node.children.push(s),i||n.push({node:s,level:r.level})}return t}function pS(e,t){let n=new Map;for(let i of e.TreemapRows){if(i.$type!=="ClassDefStatement")continue;let s=n.get(i.className);s||n.set(i.className,s=[]);let a=(i.styleText??"").replace(/\\,/g,"§§§").replace(/,/g,";").replace(/§§§/g,",");for(let o of a.split(";"))s.push(o)}let r=[];for(let i of e.TreemapRows){if(i.$type!=="TreemapRow")continue;let s=i.item,a=s.classSelector?n.get(s.classSelector):void 0;r.push({level:i.indent??0,name:s.name,type:s.$type,value:s.$type==="Leaf"?s.value:void 0,classSelector:s.classSelector,cssCompiledStyles:a&&a.length>0?a:void 0})}return{type:"treemap",title:e.title||t,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,` +`):void 0,roots:Y$(r),classes:n}}var mS=[sn,Xt,er(String.raw`\w`),{name:"TREEMAP_KEYWORD",pattern:/treemap-beta|treemap/y},{name:"CLASS_DEF",pattern:/classDef\s+([a-zA-Z_][a-zA-Z0-9_]+)(?:\s+([^;\r\n]*))?(?:;)?/y},{name:"STYLE_SEPARATOR",pattern:/:::/y},{name:"SEPARATOR",pattern:/:/y},{name:"COMMA",pattern:/,/y},{name:"INDENTATION",pattern:/[ \t]{1,}/y},{name:"WS",pattern:/[ \t]+/y,hidden:!0},{name:"ML_COMMENT",pattern:/\%\%[^\n]*/y,hidden:!0},{name:"NL",pattern:/\r?\n/y,hidden:!0},{name:"ID2",pattern:/[a-zA-Z_][a-zA-Z0-9_]*/y},{name:"NUMBER2",pattern:/[0-9_\.\,]+/y},{name:"STRING2",pattern:/"[^"]*"|'[^']*'/y}],H$=/classDef\s+([A-Z_a-z]\w+)(?:\s+([^\n\r;]*))?;?/;function gS(e){let t=new Ut(Yt(e,mS,"treemap"),mS,"treemap"),n=t.kinds,r={$type:"Treemap",TreemapRows:[]},i=()=>t.accept(5)?t.expect(12):void 0;for(t.expect(3);t.kind!==-1;){let s=t.kind;if(s===0){r.accDescr=Vt(t.take());continue}if(s===1){r.accTitle=zt(t.take());continue}if(s===2){r.title=Kt(t.take());continue}s!==8&&s!==14&&s!==4&&t.fail("a node, a class definition, or a title");let a=s===8?t.take().length:void 0;if(t.kind===4){let d=H$.exec(t.take()),m={$type:"ClassDefStatement",className:d[1]};d[2]&&(m.styleText=d[2]),a!==void 0&&(m.indent=a),r.TreemapRows.push(m);continue}let o=t.expect(14).slice(1,-1),c=n[t.i]===8?t.i+1:t.i,l;n[c]===6||n[c]===7?(t.i=c+1,t.accept(8),l={$type:"Leaf",name:o,value:parseFloat(t.expect(13).replace(/,/g,""))}):l={$type:"Section",name:o};let u=i();u!==void 0&&(l.classSelector=u);let h={$type:"TreemapRow",item:l};a!==void 0&&(h.indent=a),r.TreemapRows.push(h)}return r}var bS=/^(?:.?[<>=^])?([-+( ])?(\$)?0?\d*(,)?(?:\.(\d+))?(~)?([a-zA-Z%])?$/;function yS(e){let t="";for(let n=e.length;n>0;n-=3)t=e.slice(Math.max(0,n-3),n)+(t?","+t:"");return t}function ES(e){let t=bS.exec(e==="$0,0"?"$,":e)??bS.exec(","),n=t[1]==="+",r=t[3]!==void 0,i=t[4]===void 0?void 0:Math.min(Number(t[4]),20),s=t[6]??"";return a=>{let o=Math.abs(a),c,l="";if(s==="f"?c=o.toFixed(i??6):s==="%"?(c=(o*100).toFixed(i??6),l="%"):s==="d"?c=Math.round(o).toFixed(0):s==="e"?c=o.toExponential(i??6):c=String(Number(o.toPrecision(Math.max(1,i??12)))),t[5]&&c.includes(".")&&!c.includes("e")&&(c=c.replace(/\.?0+$/,"")),r&&!c.includes("e")){let u=c.indexOf(".");c=u===-1?yS(c):yS(c.slice(0,u))+c.slice(u)}return(a<0?"-":n?"+":"")+(t[2]??"")+c+l}}function xS(e,t,n){let r=e.children===void 0&&Number.isFinite(e.value)&&e.value>0?e.value:0;return{node:e,parent:t,series:n,value:r,children:[],headed:!1,header:0,x:0,y:0,w:0,h:0}}var Cd=(e,t,n)=>e>=t?Math.min(e,n):t;function K$(e,t,n,r,i,s,a){let o=t,c=0;for(;cm)break;m=x,h=S,p++}let y=h/u,E=0;for(let b=c;b=s?n:n+E,L=i>=s?r+E:r,O=i>=s?y:x,v=i>=s?x:y,G=Math.round(I+O-a/2)>Math.round(I+a/2)?a/2:0,K=Math.round(L+v-a/2)>Math.round(L+a/2)?a/2:0;S.x=Math.round(I+G),S.y=Math.round(L+K),S.w=Math.round(I+O-G)-S.x,S.h=Math.round(L+v-K)-S.y,E+=x,o-=S.value}i>=s?(n+=y,i-=y):(r+=y,s-=y),c=p}}function AS(e,t,n,r){let i=e.map((d,m)=>xS(d,void 0,m)),s=i.slice();for(let d=0;d=0;d--){let m=s[d];m.parent&&(m.parent.value+=m.value)}let{gap:a,header:o,short:c,side:l}=r,u=[],h=(d,m,p,y,E)=>{let b=d.filter(x=>x.value>0).sort((x,I)=>I.value-x.value),S=0;for(let x of b)S+=x.value;if(!(b.length===0||!Number.isFinite(S))){y=Math.max(0,y),E=Math.max(0,E),y>0&&E>0&&K$(b,S,m-a/2,p-a/2,y+a,E+a,a);for(let x of b){let I=Cd(x.x,m,m+y),L=Cd(x.y,p,p+E);x.w=Cd(x.x+x.w,I,m+y)-I,x.h=Cd(x.y+x.h,L,p+E)-L,x.x=I,x.y=L,u.push(x)}}};h(i,0,0,t,n);for(let d=0;d=12?o:c;m.headed=m.w>Math.max(24,2*l)&&m.h-p-l>=8,m.header=m.headed?p:0,m.headed?h(m.children,m.x+l,m.y+p,m.w-2*l,m.h-p-l):h(m.children,m.x,m.y,m.w,m.h)}return u}var wp=28,z$=18,_p=6,yi=1.25,SS=e=>rt(bt(e).trim()).trim();function V$(e){let t=0,n=e.slice();for(;n.length>0;){let r=n.pop();r.children!==void 0?n.push(...r.children):Number.isFinite(r.value)&&r.value>0&&t++}return t}function wS(e,t){let n=Math.min(t.w,t.h)/4;return n<4?At(e).replace("rx:var(--_r)",`rx:min(var(--_r),${f(n)}px)`):At(e)}function Nd(e,t,n,r,i){let s=e.treemap?.[t];return typeof s=="number"&&s>=r?Math.min(s,i):n}function _S(e,t,n){let r=n.fontSize??16,i=Math.round(r*.875),s=Math.round(r*.75),a=Math.round(r*.5625),o=n.measurer??ct(n.fontFamily,n.fontFamilyMono),c=t.treemap??{},l=n.padding??Nd(t,"diagramPadding",8,0,2e3),u=Math.round(gs(n,Nd(t,"nodeWidth",64,1,400)*10,200,2*l)),h=Math.round(Nd(t,"nodeHeight",40,1,400)*10),d=c.showValues!==!1,m=ES(typeof c.valueFormat=="string"?c.valueFormat:","),p=Math.min(1,Math.max(0,Math.log10(u*h/Math.max(1,V$(e.roots))/800))),y=AS(e.roots,u,h,{gap:Nd(t,"padding",Math.round(2+2*p),0,200),header:wp,short:z$,side:Math.round(3+3*p)}),E=Ge(e.title,!1,o,r,kt(n),1),b=E.height>0?E.height+8:0,S=l+Math.max(0,(E.width-u)/2),x=l+b,I="",L="";for(let K of y){let C=K.node,Z=Ct(C.cssCompiledStyles??[]),oe=Et(K.series),H=S+K.x,z=x+K.y,M=bt(C.name).trim(),T=d?m(K.value):"",R=`data-id="${Ue(C.name)}">`,_=SS(C.name),$=_===""?[]:[_];for(let Y=K.parent;Y!==void 0&&!Y.headed;Y=Y.parent){let ne=SS(Y.node.name);ne!==""&&$.unshift(ne)}let g=$.join(" › "),N=Y=>g===""||Y===M&&g===_?"":`${g}`,w=`0&&re-P-12>=3*te,ae=te*yi${rt(ae.text)}`),ee&&se*yi<=wp&&(Y+=`${rt(T)}`)}let q=/[";]fill:/.test(Z.shape)?"":' fill-opacity="0.12"',k=K.headed?`${w}${wS(`${q} stroke="${oe}"${Z.shape}`,K)}/>`:``;I+=``;continue}let B="",F=K.w-8,W=A??a,j=A===void 0?Math.min(r,Math.floor((K.h-4)/yi)):A*yi<=K.h-4?A:0,Q=j>=W?Ma(M,F,j,W,o,D):void 0;if(Q){let Y=f(H+K.w/2),ne=z+K.h/2,q=A??Math.max(a,Math.round(Q.size*.8)),k=(Q.size+q)*yi;if(T&&k<=K.h-4&&o.width(T,q,D)<=F){let J=ne-k/2+Q.size*yi/2,te=ne+k/2-q*yi/2;B=`${rt(Q.text)}${rt(T)}`}else B=`${rt(Q.text)}`}L+=`${B}`}let O=Math.ceil(Math.max(u,E.width)+2*l),v=Math.ceil(h+b+2*l),G=Ne(E,O/2,l+E.height/2,' class="pele-title" font-weight="var(--_tw)"')+(I?`${I}`:"")+(L?`${L}`:"");return{svg:at("treemap",O,v,r,n,e,G),width:O,height:v,links:[]}}var RS={type:"treemap",parse:(e,t,n)=>pS(gS(e),n),render:_S};var Rp="EOF USECASE ACTOR SYSTEM_BOUNDARY END DIRECTION TD TB BT LR RL NOTE FOR JSON CLASS_DEF CLASS STYLE INCLUDE EXTEND TRUE FALSE IDENTIFIER NUMBER AT COMMA COLON HASH_COLOR CSS_IDENTIFIER CSS_ESCAPED_COMMA DASH DOT PERCENT CSS_PUNCTUATION LABEL_PUNCTUATION LABEL_SYMBOL PLAIN_STRING MARKDOWN_STRING UNCLOSED_MARKDOWN_STRING COMMENT NEWLINE ACC_DESCR_BLOCK ACC_TITLE_LINE ACC_DESCR_LINE JSON_DECLARATION_START JSON_OBJECT_LITERAL UNCLOSED_JSON_OBJECT_LITERAL GENERALIZATION DEPENDENCY_ARROW STEREOTYPE_START STEREOTYPE_END STEREOTYPE_TEXT UNCLOSED_STEREOTYPE_TEXT CLASS_SEPARATOR FORWARD_SOLID BACKWARD_SOLID FORWARD_CIRCLE BACKWARD_CIRCLE FORWARD_CROSS BACKWARD_CROSS MARKERLESS_SOLID METADATA_START LBRACE RBRACE LBRACKET RBRACKET LPAREN RPAREN".split(" ");var Pa=1,CS=2,vs=new Uint8Array(128);for(let e=48;e<=57;e++)vs[e]=Pa;for(let e=65;e<=90;e++)vs[e]=vs[e+32]=Pa;vs[95]=Pa;for(let e of"!#$&*+/=?^|~")vs[e.charCodeAt(0)]=CS;var TS=[0,12,5,14,3,9,2,2,2,2,2,4,3,4,8,5,5,7,6,4,5];function Id(e){return e<128&&(vs[e]&Pa)!==0}function Tp(e,t,n){for(let r=0;r${e.charAt(t)}<- at offset: ${s}, skipped ${a-s} characters. at line ${r}, column ${i} [${s},${a})`,"syntax",{type:"usecase",line:r,column:i})}function IS(e){let t=[],n=[],r=[],i=e.length,s=0,a=!0,o=!1;for(;sm){for(;Xn(e.charCodeAt(d));)d++;if(e.charCodeAt(d)===64){for(d++;Xn(e.charCodeAt(d));)d++;if(e.charCodeAt(d)===123){t.push(43),n.push(s),r.push(d),s=d;let p=0,y=!1,E=!1,b=d;for(;b=i)break;if(e.charCodeAt(s)===62&&e.charCodeAt(s+1)===62)l=49,u=s+2;else{let d=s,m=!1;for(;ds+1?26:32}else if(c===92)e.charCodeAt(u)===44?(l=28,u++):l=33;else if(c<127&&c>32)l=(vs[c]&CS)!==0?32:33;else for(l=34;u=32&&d<127||d===9||d===10||d===13)break;u++}t.push(l),n.push(s),r.push(u),s=u,a=h}for(let c=0;c<3;c++)t.push(0),n.push(i),r.push(i);return{types:t,starts:n,ends:r}}function kS(){return{type:"usecase",actors:new Map,useCases:new Map,systemBoundaries:new Map,relationships:[],notes:new Map,jsonNodes:new Map,classDefs:new Map,direction:"LR",title:void 0,accTitle:"",accDescr:"",accDescription:"",source:"",headerSpan:[0,0],statements:[]}}function $S(){return{elements:[],boundaries:[],jsons:[],relationships:[],notes:[],metadata:[],classes:[],styles:[],classDefs:[],direction:void 0,accTitle:"",accDescription:""}}function Mp(e,t){if(t.length===0)return;let n=new Set(e);for(let r of t)n.has(r)||(n.add(r),e.push(r))}function q$(e){let t=new Set(["actor","usecase","boundary","edge"]);for(let{key:n,value:r}of e)if(n==="icon")t.clear(),t.add("actor");else if(n==="animate"||n==="animation")t.clear(),t.add("edge");else if(n==="type")t.clear(),r==="rect"||r==="package"?t.add("boundary"):(r==="normal"||r==="hollow"||r==="awesome")&&t.add("actor");else if(n==="business")t.delete("boundary"),t.delete("edge");else return;return t.size===1?[...t][0]:void 0}function LS(e,t,n,r,i){let s=kS(),{actors:a,useCases:o,systemBoundaries:c}=s,l=new Map,u=new Map,h=new Map,d=new Map,m=new Map,p=g=>kd(e,g[0],g[1]),y=(g,N)=>{let[w,A]=Ei(e,N[0]);return new Qe(g,"semantic",{type:"usecase",line:w,column:A})},E=(g,N)=>{throw y(`${g} at ${p(N)}`,N)},b=(g,N,w,A,D)=>{let U=B=>B===void 0?"":` (label "${B}")`;throw y(`${g} at ${p(N)}${U(A)}; previous declaration at ${p(w)}${U(D)}`,N)},S=(g,N,w)=>E(`Metadata property '${w.key}' is invalid for ${N} '${g}'`,w.keySpan),x=(g,N)=>{let w=m.get(g);(w===void 0||N[...g].sort((N,w)=>(m.get(N.id)??0)-(m.get(w.id)??0)),L=(g,N)=>{l.set(g.id,{kind:N,span:g.span,generated:g.generated,label:g.label.text})},O=(g,N)=>{let w=l.get(g.id);if(!w)return;let A=g.generated?g.label.text:void 0,D=w.generated?w.label:void 0;w.kind!==N&&b(`ID '${g.id}' is declared as both ${w.kind} and ${N}`,g.span,w.span,A,D),(w.generated||g.generated)&&b(`Generated ID '${g.id}' collides with another declaration`,g.span,w.span,A,D)},v=(g,N,w)=>{let A=l.get(g);A&&b(`ID '${g}' is declared more than once (${A.kind} and ${N})`,w,A.span,void 0,A.generated?A.label:void 0),l.set(g,{kind:N,span:w,generated:!1})},G=(g,N,w)=>{let{key:A,value:D}=N,U=B=>{!w&&B!==void 0&&B!==D&&b(`Actor '${g.id}' has conflicting ${A} metadata`,N.keySpan,g.span)};A==="type"&&(D==="normal"||D==="hollow"||D==="awesome")?(U(g.actorType),g.actorType=D):A==="icon"&&typeof D=="string"?(U(g.icon),g.icon=D):A==="business"&&typeof D=="boolean"?(U(g.business),g.business=D):S(g.id,"actor",N)},K=(g,N,w)=>{for(let A of N??[])g.kind==="actor"?G(g,A,w):A.key==="business"&&typeof A.value=="boolean"?(!w&&g.business!==void 0&&g.business!==A.value&&b(`Use case '${g.id}' has conflicting business metadata`,A.keySpan,g.span),g.business=A.value):S(g.id,"usecase",A)},C=g=>{let N;if(g.kind==="actor"){o.delete(g.id);let w={id:g.id,label:g.label.text,labelType:g.label.type,business:g.business??!1,classes:[...g.classes],type:g.icon?"icon":g.actorType??"normal",styles:a.get(g.id)?.styles??[]};g.icon&&(w.icon=g.icon),a.set(g.id,w),N=w}else a.delete(g.id),N={id:g.id,label:g.label.text,labelType:g.label.type,business:g.business??!1,classes:[...g.classes],shape:g.shape??"ellipse",styles:o.get(g.id)?.styles??[]},o.set(g.id,N);g.stereotype&&(N.stereotype=g.stereotype),g.parent?.id&&(N.parentId=g.parent.id)},Z=g=>{O(g,g.kind);let N=g.parent?.id?g.parent:void 0,w=u.get(g.id);if(!w){let A={kind:g.kind,id:g.id,label:g.label,span:g.span,generated:g.generated,classes:[...g.classes],parent:N,shape:g.shape,stereotype:g.stereotype,stereotypeSpan:g.stereotype?g.span:void 0};K(A,g.metadata,!1),u.set(g.id,A),L(g,g.kind);return}(w.label.text!==g.label.text||w.label.type!==g.label.type)&&b(`ID '${g.id}' has conflicting labels`,g.span,w.span),g.shape&&w.shape&&g.shape!==w.shape&&b(`Use case '${g.id}' has conflicting shapes`,g.span,w.span),N&&w.parent?.id&&N.id!==w.parent.id&&b(`Element '${g.id}' belongs to more than one system boundary`,N.span,w.parent.span),g.stereotype&&w.stereotype&&g.stereotype!==w.stereotype&&b(`Element '${g.id}' has conflicting stereotypes`,g.span,w.stereotypeSpan??w.span),w.shape??=g.shape,w.parent??=g.parent,w.stereotype??=g.stereotype,w.stereotypeSpan??=g.stereotype?g.span:void 0,Mp(w.classes,g.classes),K(w,g.metadata,!1)},oe=g=>{O(g,"boundary");let N=h.get(g.id);if(N){(N.label.text!==g.label.text||N.label.type!==g.label.type)&&b(`Boundary '${g.id}' has conflicting titles`,g.span,N.span),Mp(N.classes,g.classes);return}h.set(g.id,{...g,classes:[...g.classes],members:[]}),L(g,"boundary")},H=g=>{g.classed&&!g.declares&&E(`Relationship endpoint '${g.id}' uses ::: without declaring the node`,g.span);let N=l.get(g.id);return N?N.kind:(u.set(g.id,{...g,kind:"usecase",shape:"ellipse",classes:[]}),L(g,"usecase"),x(g.id,g.span[0]),"usecase")},z=(g,N)=>{let w=l.get(g)?.kind;return(w==="actor"?a.get(g):w==="usecase"?o.get(g):w==="boundary"?c.get(g):w==="json"?s.jsonNodes.get(g):d.get(g))??E(`Class/style target '${g}' is unresolved or anonymous`,N)},M=[];for(let{source:g,target:N}of t.relationships)x(g.id,g.span[0]),x(N.id,N.span[0]);for(let g of t.elements)x(g.id,g.span[0]),M.push({offset:g.span[0],run:()=>Z(g)});for(let g of t.boundaries)x(g.id,g.span[0]),M.push({offset:g.span[0],run:()=>oe(g)});for(let g of t.jsons)x(g.id,g.span[0]),M.push({offset:g.span[0],run:()=>v(g.id,"json",g.span)});for(let{id:g,idSpan:N}of t.relationships)g&&N&&M.push({offset:N[0],run:()=>v(g,"edge",N)});M.sort((g,N)=>g.offset-N.offset);for(let g of M)g.run();for(let g of I(u.values()))C(g);for(let g of I(h.values()))c.set(g.id,{id:g.id,label:g.label.text,labelType:g.label.type,type:"rect",members:[],classes:[],styles:[]});for(let g of I(t.jsons))s.jsonNodes.set(g.id,{id:g.id,value:g.value,propertyOrder:g.propertyOrder,classes:[...g.classes],styles:[]});let T=0;for(let g of t.relationships){let{source:N,target:w,type:A}=g,D=H(N),U=H(w),B=j=>j==="actor"||j==="usecase"||j==="json";B(D)||b(`Relationship source '${N.id}' cannot be ${D}`,N.span,l.get(N.id).span),B(U)||b(`Relationship target '${w.id}' cannot be ${U}`,w.span,l.get(w.id).span),(A==="include"||A==="extend")&&(D!=="usecase"||U!=="usecase")&&E(`${A} relationship requires use-case endpoints`,g.span),A==="generalization"&&(D==="json"||D!==U)&&E("Generalization requires actor-to-actor or use-case-to-use-case endpoints",g.span),A==="association"&&(D==="json"||U==="json")&&g.arrowType>2&&E(`JSON relationship '${N.id}' to '${w.id}' permits only point, reversed-point, or markerless solid association`,g.span);let F=g.id??`edge-${T++}`,W={id:F,explicitId:!!g.id,source:N.id,target:w.id,type:A,arrowType:g.arrowType,minlen:g.minlen,classes:[],styles:[],animate:!1};g.label&&(W.label=g.label.text,W.labelType=g.label.type),s.relationships.push(W),d.set(F,W)}let R=new Map(a),_=new Map(o);a.clear(),o.clear();for(let g of I(u.values())){let N=R.get(g.id),w=_.get(g.id);N?a.set(g.id,N):w?o.set(g.id,w):C(g)}for(let{target:g,span:N,properties:w,statement:A}of t.metadata){let D=l.get(g);if(!D){let W=q$(w);return E(`Metadata target '${g}' is unresolved${W?` (metadata implies ${W})`:""}`,N)}let U=D.kind;U==="actor"||U==="usecase"?K(u.get(g),w,!0):U==="edge"&&(A.kind="edgeMetadata",A.edges=[{id:g,span:A.span,idSpan:N,metadata:A.metadata}],delete A.nodes);let B=h.get(g),F=d.get(g);for(let W of U==="actor"||U==="usecase"?[]:w){let{key:j,value:Q}=W;U==="boundary"&&B&&j==="type"&&(Q==="rect"||Q==="package")?B.type=Q:U==="edge"&&F&&j==="animate"&&typeof Q=="boolean"?F.animate=Q:U==="edge"&&F&&j==="animation"&&(Q==="fast"||Q==="slow")?(F.animation=Q,F.animate=!0):S(g,U,W)}}for(let g of s.relationships)g.animation&&(g.animate=!0);for(let g of u.values())g.kind==="actor"?(g.icon&&g.actorType&&g.actorType!=="normal"&&E(`Actor '${g.id}' cannot combine icon with type '${g.actorType}'`,g.span),g.business&&(g.icon||g.actorType==="awesome")&&E(`Business actor '${g.id}' must use normal or hollow geometry`,g.span)):g.shape==="rect"&&g.business&&E(`Rectangular use case '${g.id}' cannot be a business use case`,g.span),C(g);for(let g of[...t.elements].sort((N,w)=>N.span[0]-w.span[0])){if(!g.parent?.id)continue;let N=h.get(g.parent.id).members;N.includes(g.id)||N.push(g.id)}for(let g of h.values()){let N=c.get(g.id);N.type=g.type??"rect",N.members=g.members,N.classes=[...g.classes]}let $=0;for(let g of t.notes){let N=l.get(g.target);if(!N)return E(`Note target '${g.target}' is unresolved`,g.span);N.kind!=="actor"&&N.kind!=="usecase"&&b(`Note target '${g.target}' must be an actor or use case, not ${N.kind}`,g.span,N.span);let w=`note-${$++}`;s.notes.set(w,{id:w,target:g.target,label:g.label.text,labelType:g.label.type})}for(let g of t.classDefs)for(let N of g.ids)s.classDefs.set(N,{id:N,styles:[...g.styles]});for(let g of t.classes)for(let N of g.targets)Mp(z(N.id,N.span).classes,g.classes);for(let g of t.styles)z(g.target,g.span).styles.push(...g.styles);return s.direction=t.direction??s.direction,s.title=i,s.accTitle=t.accTitle,s.accDescription=t.accDescription,s.accDescr=t.accDescription.replace(/\n\s+/g,` +`),s.source=e,s.headerSpan=n,s.statements=r,s}var Rn=class extends Error{constructor(n){super("Invalid JSON token");fe(this,"offset",n)}};function OS(e){let t=new Map,n=[],r=[],i=e.length,s=0,a="",o=0,c=()=>{for(;s{s++;let m="";for(;s{for(let m=0;m{if(e.charCodeAt(s)===45&&s++,e.charCodeAt(s)===48)s++;else if(xt(e.charCodeAt(s)))for(;xt(e.charCodeAt(s));)s++;else throw new Rn(s);if(e.charCodeAt(s)===46){if(s++,!xt(e.charCodeAt(s)))throw new Rn(s);for(;xt(e.charCodeAt(s));)s++}if((e.charCodeAt(s)|32)===101){if(s++,(e.charCodeAt(s)===43||e.charCodeAt(s)===45)&&s++,!xt(e.charCodeAt(s)))throw new Rn(s);for(;xt(e.charCodeAt(s));)s++}};for(c();;)if(o===0){c();let d=e.charCodeAt(s);if(o=2,d===123){s++;let m=[];t.set(a,m),n.push(a),c(),e.charCodeAt(s)===125?s++:(r.push({object:!0,pointer:a,keys:m,ranges:new Map,key:"",from:0,index:0}),o=1)}else if(d===91)s++,c(),e.charCodeAt(s)===93?s++:(r.push({object:!1,pointer:a,keys:[],ranges:new Map,key:"",from:0,index:0}),a+="/0",o=0);else if(d===34)l(!1);else if(d===116)u("true");else if(d===102)u("false");else if(d===110)u("null");else if(d===45||xt(d))h();else throw new Rn(s)}else if(o===1){let d=r[r.length-1];if(e.charCodeAt(s)!==34)throw new Rn(s);let m=l(!0),p=d.ranges.get(m);if(p===void 0)d.keys.push(m);else for(let y=p[0];y ${e} <-- but found --> '${rn(Ke)}' <--`)}function on(e){return lt[Ke]!==e&&e1(Rp[e]),Ke++}function sr(e){let t=e.split("|").map((n,r)=>` ${r+1}. [${n}]`);Fd(`Expecting: one of these possible Token sequences: +${t.join(` +`)} +but found: '${rn(Ke)}'`)}function PS(){let e=Pd.split("|"),t=e.flatMap(i=>["NEWLINE","IDENTIFIER","PLAIN_STRING","RBRACE"].map(s=>`${i}, METADATA_START, ${s}`)),n=`STEREOTYPE_START|CLASS_SEPARATOR|IDENTIFIER|${vd}|NEWLINE|EOF`.split("|"),r=e.flatMap((i,s)=>(s===0?["LPAREN","LBRACKET",...n]:n).map(a=>`${i}, ${a}`));return[XS,...t,...r,...t].join("|")}function FS(e){return e>=1&&e<=21}function BS(e){return e>=1&&e<=34}function Ai(){QS=$n[Ke-1],lt[Ke]===39?Ke++:lt[Ke]!==0&&sr("NEWLINE|EOF")}function Wa(e){let t=lt[e]===36?2:lt[e]===35?1:0;return[bn[e]+t,$n[e]-t]}function $p(e){let t=Wa(e);return{text:kn.slice(t[0],t[1]),type:lt[e]===36?"markdown":"text",span:t}}function t1(e){return e.replace(/\W/g,"_")}function Ba(){let e=lt[Ke];if(e===35||e===36)return $p(Ke++);BS(e)||sr(Z$);let t=Ke;for(;BS(lt[Ke]);)Ke++;let n=[bn[t],$n[Ke-1]];return{text:kn.slice(n[0],n[1]),type:"text",span:n}}function xi(e){return e===21||e===35}function WS(){let e=Ke;xi(lt[Ke])||sr("IDENTIFIER|PLAIN_STRING"),Ke++,on(25);let t=Ke,n=lt[Ke];!xi(n)&&n!==19&&n!==20&&sr("IDENTIFIER|PLAIN_STRING|TRUE|FALSE"),Ke++;let r=Wa(e),i=Wa(t);return{key:kn.slice(r[0],r[1]),value:n===19?!0:n===20?!1:kn.slice(i[0],i[1]),span:[bn[e],$n[t]],keySpan:r,valueSpan:i}}function eL(){let e=lt[Ke],t=lt[Ke+1],n=lt[Ke+2];return e===24?xi(t)||t===39&&(n===39||xi(n)):e!==39?!1:t===24||xi(t)||t===39&&(n===39||n===24||xi(n))}function Op(){on(60);let e=[];for(;lt[Ke]===39;)Ke++;if(xi(lt[Ke])){for(e.push(WS());eL();){if(lt[Ke]===24)Ke++;else{for(;lt[Ke]===39;)Ke++;lt[Ke]===24&&Ke++}for(;lt[Ke]===39;)Ke++;e.push(WS())}for(lt[Ke]===24&&Ke++;lt[Ke]===39;)Ke++}return on(62),e}function Dp(e){return e.map(({key:t,span:n,keySpan:r,valueSpan:i})=>({key:t,span:n,keySpan:r,valueSpan:i}))}function vp(e,t){do{Ke++;let n=on(21);e.push(rn(n)),t.push(zn(n))}while(lt[Ke]===24)}function n1(e){let t=Ke,n=lt[Ke],r={id:"",label:void 0,span:Wa(t),generated:n!==21,classes:[],classSpans:[],explicit:!1,nodeSpan:[0,0]};if(n===21){Ke++,r.id=rn(t);let i=lt[Ke];i===65||e&&i===63?(Ke++,r.label=Ba(),on(i===65?66:64),r.shape=i===65?"ellipse":"rect"):r.label=$p(t)}else n===35||n===36?(Ke++,r.label=$p(t),r.id=t1(r.label.text)):sr(Pd);return r}function Dd(e){let t=Ke,n=n1(!e);if(e&&(n.shape=void 0),lt[Ke]===60&&(n.metadata=Op()),lt[Ke]===48){Ke++;let r=on(50);on(49),n.stereotype=rn(r).trim(),n.stereotypeSpan=zn(r)}return lt[Ke]===52&&vp(n.classes,n.classSpans),n.explicit=!!(n.shape||n.metadata||n.stereotype),n.nodeSpan=[bn[t],$n[Ke-1]],n}function Pp(e,t){return{id:e.id,kind:t,label:e.label,span:e.span,generated:e.generated,parent:Od,shape:e.shape,metadata:e.metadata,stereotype:e.stereotype,classes:e.classes}}function US(e,t){return{id:e.id,label:e.label,span:e.span,generated:e.generated,declares:t,classed:e.classes.length>0}}function Fp(e,t){let n={id:e.id,span:e.nodeSpan,idSpan:e.span,labelSpan:e.label.span};return t&&(n.defines=!0),e.stereotypeSpan&&(n.stereotypeSpan=e.stereotypeSpan),e.metadata&&(n.metadata=Dp(e.metadata)),e.classSpans.length>0&&(n.classSpans=e.classSpans),n}function Np(e){if(lt[Ke]<1||lt[Ke]>36)return!1;for(let t=Ke+1;;t++){let n=lt[t];if(n===59||(Ar[n]&e)!==0)return!0;if(n<1||n>36)return!1}}function Fa(e){let t=$n[e]-bn[e]-(lt[e]===59?0:1);return Math.max(1,t-1)}function r1(){let e=Ke,t={type:"association",arrowType:0,minlen:1,target:void 0,span:[0,0]};lt[Ke]===21&<[Ke+1]===23&&(t.explicitId=rn(Ke),t.explicitIdSpan=zn(Ke),Ke+=2);let n=Ke,r=lt[Ke++];if(r===47)on(25),lt[Ke]!==17&<[Ke]!==18&&sr("INCLUDE|EXTEND"),t.type=lt[Ke]===17?"include":"extend",t.label={text:t.type,type:"text",span:zn(Ke)},Ke++;else if(r===46)t.type="generalization";else if(r===53)t.minlen=Fa(n);else if(r===54)t.arrowType=1,$n[n]-bn[n]===3&&Np(0)?(t.label=Ba(),t.minlen=Fa(on(59))):t.minlen=Fa(n);else if(r===59)if(t.arrowType=2,$n[n]-bn[n]===2&&Np(VS)){t.label=Ba();let i=lt[Ke];i===53?t.arrowType=0:i===55?t.arrowType=3:i===57?t.arrowType=4:i!==59&&sr("FORWARD_SOLID|MARKERLESS_SOLID|FORWARD_CIRCLE|FORWARD_CROSS"),(t.arrowType===0||t.arrowType===2)&&(t.minlen=Fa(Ke)),Ke++}else t.minlen=Fa(n);else r===55?t.arrowType=3:r===57?t.arrowType=4:r===56||r===58?(t.arrowType=r===56?5:6,Np(0)&&(t.label=Ba(),on(59))):(Ke--,sr(vd));return t.target=Dd(!1),t.span=[bn[e],$n[Ke-1]],t}function xr(e){return{kind:e,span:[0,0]}}function s1(e,t,n,r){let i=n.target;i.explicit&&gn.elements.push(Pp(i,"usecase")),gn.relationships.push({source:US(e,t),target:US(i,i.explicit),span:n.span,id:n.explicitId,idSpan:n.explicitIdSpan,type:n.type,arrowType:n.arrowType,label:n.label,minlen:n.minlen}),r.push(Fp(i,i.explicit));let s=xr("edge");return s.nodes=r,s.edges=[{id:n.explicitId??`edge-${ZS++}`,span:s.span}],n.explicitIdSpan&&(s.edges[0].idSpan=n.explicitIdSpan),n.label&&(s.edges[0].labelSpan=n.label.span),s}function i1(e){let t=xr("node");return t.nodes=e,t}function o1(e){Ke++;let t=[Dd(!0)],n;if(lt[Ke]===24)do Ke++,t.push(Dd(!0));while(lt[Ke]===24);else e&&(Ar[lt[Ke]]&Lp)!==0&&(n=r1());Ai();for(let i of t)gn.elements.push(Pp(i,"actor"));let r=t.map(i=>Fp(i,!0));return n?s1(t[0],!0,n,r):i1(r)}function a1(e){let t=Dd(!1),n=e&&(Ar[lt[Ke]]&Lp)!==0?r1():void 0;Ai(),n||(t.explicit=!0,t.shape??="ellipse"),t.explicit&&gn.elements.push(Pp(t,"usecase"));let r=[Fp(t,t.explicit)];return n?s1(t,t.explicit,n,r):i1(r)}function tL(){Ke++;let e=n1(!0),t={id:e.id,label:e.label,span:e.span,generated:e.generated,classes:e.classes},n=lt[Ke]===60?Op():void 0;lt[Ke]===52&&vp(e.classes,e.classSpans),Ai(),gn.boundaries.push(t),Od=t;let r=[];for(;(Ar[lt[Ke]]&zS)!==0;)r.push(c1(!1));Od=void 0;let i=on(4);Ai();let s=xr("group");return s.group=t.id,s.idSpan=t.span,s.titleSpan=t.label.span,s.endSpan=zn(i),s.classSpans=e.classSpans,r.length>0&&(s.children=r),n&&(s.metadata=Dp(n),gn.metadata.push({target:t.id,span:t.span,properties:n,statement:s})),s}function GS(){let e=Ke,t=lt[Ke];for(FS(t)||t===27?Ke++:t===59?(Ke++,FS(lt[Ke])||e1("WORD"),Ke++):sr("WORD|CSS_IDENTIFIER|MARKERLESS_SOLID"),on(25),(Ar[lt[Ke]]&kp)===0&&Fd(`Expecting: expecting at least one iteration which starts with one of these possible Token sequences:: + <[${qS.replaceAll("|","] ,[")}]> +but found: '${rn(Ke)}'`);(Ar[lt[Ke]]&kp)!==0;)Ke++;return kn.slice(bn[e],$n[Ke-1]).replaceAll("\\,",",")}function YS(){let e=[GS()];for(;lt[Ke]===24;)Ke++,e.push(GS());return e}function Ip(){let e=[on(21)];for(;lt[Ke]===24;)Ke++,e.push(on(21));return e}function $d(e){let t=Wa(e);return{id:rn(e),span:t,idSpan:t}}function nL(){let e=Ke,t=lt[Ke],n;if(t===41||t===42||t===40){Ke++;let r=rn(e);t===40?gn.accDescription=r.slice(r.indexOf("{")+1,r.lastIndexOf("}")).trim():t===42?gn.accDescription=r.slice(r.indexOf(":")+1).trim():gn.accTitle=r.slice(r.indexOf(":")+1).trim(),n=xr(t===41?"accTitle":"accDescr")}else if(t===5){Ke++;let r=lt[Ke];(r<6||r>10)&&sr("TD|TB|BT|LR|RL"),gn.direction=r===6?"TB":rn(Ke),Ke++,n=xr("direction")}else{if(t===2)return o1(!0);if(t===3)return tL();if(t===11){Ke++,on(12);let r=on(21),i=Ba();gn.notes.push({target:rn(r),span:zn(r),label:i}),n=xr("note"),n.ref=`note-${JS++}`,n.refSpan=i.span,n.nodes=[$d(r)]}else if(t===43){Ke++;let r=on(44),i=[],s=[];lt[Ke]===52&&vp(i,s);let a=bn[e]+4;for(;kn.charCodeAt(a)===32||kn.charCodeAt(a)===9;)a++;let o=a;for(;/\w/.test(kn.charAt(o));)o++;let c={id:kn.slice(a,o),value:{},propertyOrder:new Map,span:[a,o],classes:i};gn.jsons.push(c),Ld.push([c,r]),n=xr("json"),n.nodes=[{id:c.id,span:c.span,idSpan:c.span,defines:!0,classSpans:s}],n.classSpans=s}else if(t===14){Ke++;let r=Ip();gn.classDefs.push({ids:r.map(rn),styles:YS()}),n=xr("classDef"),n.ref=rn(r[0]),n.refSpan=zn(r[0])}else if(t===15){Ke++;let r=Ip(),i=Ip();gn.classes.push({targets:r.map(s=>({id:rn(s),span:zn(s)})),classes:i.map(rn)}),n=xr("classAssign"),n.ref=rn(i[0]),n.refSpan=zn(i[0]),n.nodes=r.map($d)}else if(t===16){Ke++;let r=on(21);gn.styles.push({target:rn(r),span:zn(r),styles:YS()}),n=xr("style"),n.nodes=[$d(r)]}else{let r=lt[Ke+1];if(r===60){(Ar[lt[Ke+2]]&jS)===0&&sr(PS()),Ke++;let i=$d(e);t!==21&&(i.id=t1(kn.slice(i.span[0],i.span[1])));let s=Op();n=xr("metadata"),n.nodes=[i],n.metadata=Dp(s),gn.metadata.push({target:i.id,span:i.span,properties:s,statement:n})}else return(!((Ar[r]&KS)!==0||t===21&&(r===65||r===63))||t===21&&J$.has(rn(e).toLowerCase()))&&sr(PS()),a1(!0)}}return Ai(),n}function c1(e){let t=Ke,n=lt[Ke];if(n===39)return Ke++,{kind:"blank",span:zn(t)};if(n===38)return Ke++,Ai(),{kind:"comment",span:zn(t)};let r=e?nL():n===2?o1(!1):a1(!1);if(r.span=[bn[t],QS],r.edges)for(let i of r.edges)i.span=r.span;return r}function l1(e,t){kn=e,{types:lt,starts:bn,ends:$n}=IS(e),Ke=0,gn=$S(),Od=void 0,Ld=[],ZS=0,JS=0;try{let n=on(1);Ai();let r=[];for(;(Ar[lt[Ke]]&HS)!==0;)r.push(c1(!0));lt[Ke]!==0&&Fd(`Redundant input, expecting EOF but found: ${rn(Ke)}`);for(let[i,s]of Ld){let a=vS(rn(s),()=>Ei(e,bn[s]));i.value=a.value,i.propertyOrder=a.propertyOrder}return LS(e,gn,zn(n),r,t)}finally{kn="",lt=bn=$n=Ld=[]}}var rL={normal:"usecaseActor",hollow:"usecaseActorHollow",awesome:"usecaseActorAwesome",icon:"usecaseActorIcon"},Bp=[["none","arrow_point"],["arrow_point","none"],["none","none"],["none","arrow_circle"],["none","arrow_cross"],["arrow_circle","none"],["arrow_cross","none"]];function d1(e){return typeof e=="string"?e:e===null?"null":String(e)}function sL(e){let t=[],n=[[e.value,"",""]],r=[];for(;n.length>0;){let[i,s,a]=n.pop();if(r.length=0,Array.isArray(i))i.length===0?t.push({key:s,accessibleKey:s,value:"[]"}):i.every(o=>o===null||typeof o!="object")?i.forEach((o,c)=>t.push({key:c===0?s:"",accessibleKey:s,value:d1(o)})):i.forEach((o,c)=>r.push([o,`${s}[${c}]`,`${a}/${c}`]));else if(i!==null&&typeof i=="object"){let o=i,c=e.propertyOrder.get(a)??Object.keys(o);c.length===0&&t.push({key:s,accessibleKey:s,value:"{}"});for(let l of c)r.push([Object.prototype.hasOwnProperty.call(o,l)?o[l]:void 0,s?`${s}.${l}`:l,`${a}/${l.replaceAll("~","~0").replaceAll("/","~1")}`])}else t.push({key:s,accessibleKey:s,value:d1(i)});for(let o=r.length-1;o>=0;o--)n.push(r[o])}return t}function Ua(...e){return e.filter(Boolean).join(" ")}function iL(e){return e.type==="generalization"?["none","extension"]:e.type!=="association"?Bp[0]:Bp[e.arrowType]??Bp[2]}function u1(e){let t=[],n=[],r=i=>{let s=new Map;for(let a of["default",...i]){let o=e.classDefs.get(a);if(o)for(let c of o.styles){let l=c.trim(),u=l.indexOf(":"),h=(u===-1?l:l.slice(0,u)).trim();h&&s.set(h,l)}}return[...s.values()]};for(let i of e.actors.values())t.push({id:i.id,label:i.label,labelType:i.labelType,shape:rL[i.type],isGroup:!1,padding:10,cssClasses:Ua("default","usecase-actor",`usecase-actor-${i.type}`,i.business&&"usecase-business",...i.classes),cssStyles:[...i.styles],cssCompiledStyles:r(i.classes),actorType:i.type,business:i.business,icon:i.icon||void 0,stereotype:i.stereotype||void 0,parentId:i.parentId||void 0});for(let i of e.useCases.values()){let s=i.shape==="ellipse";t.push({id:i.id,label:i.label,labelType:i.labelType,shape:s?i.business?"usecaseBusiness":"usecaseEllipse":"rect",isGroup:!1,padding:s?20:10,cssClasses:Ua("default","usecase-element",`usecase-${i.shape}`,i.business&&"usecase-business",...i.classes),cssStyles:[...i.styles],cssCompiledStyles:r(i.classes),business:i.business,stereotype:i.stereotype||void 0,parentId:i.parentId||void 0})}for(let i of e.notes.values())t.push({id:i.id,label:i.label,labelType:i.labelType,shape:"note",isGroup:!1,padding:10,cssClasses:"default usecase-note",cssStyles:[],cssCompiledStyles:r([]),noteTarget:i.target});for(let i of e.jsonNodes.values())t.push({id:i.id,label:i.id,labelType:"text",shape:"usecaseJsonTable",isGroup:!1,padding:10,cssClasses:Ua("default","usecase-json-table",...i.classes),cssStyles:[...i.styles],cssCompiledStyles:r(i.classes),jsonRows:sL(i)});for(let i of e.systemBoundaries.values())t.push({id:i.id,label:i.label,labelType:i.labelType,shape:"usecaseSystemBoundary",isGroup:!0,padding:20,cssClasses:Ua("default","system-boundary",`system-boundary-${i.type}`,...i.classes),cssStyles:[...i.styles],cssCompiledStyles:r(i.classes),boundaryType:i.type});for(let i of e.relationships){let s=i.type==="include"||i.type==="extend",[a,o]=iL(i),c=i.animate||i.animation!==void 0,l={id:i.id,start:i.source,end:i.target,relationshipType:i.type,pattern:s?"dotted":"solid",arrowTypeStart:a,arrowTypeEnd:o,classes:Ua("default","relationship",`relationship-${i.type}`,...i.classes,c&&`edge-animation-${i.animation??"fast"}`),style:[...i.styles],cssCompiledStyles:r(i.classes),animate:i.animate,animation:i.animation,minlen:i.minlen,explicitId:i.explicitId,internal:!1};s?(l.label=i.type,l.labelType="text"):i.type==="association"&&(i.label&&(l.label=i.label),i.labelType&&(l.labelType=i.labelType)),n.push(l)}for(let i of e.notes.values())n.push({id:`${i.id}-edge`,start:i.id,end:i.target,relationshipType:"note",pattern:"dotted",arrowTypeStart:"none",arrowTypeEnd:"none",classes:"default relationship relationship-note",style:[],cssCompiledStyles:r([]),animate:!1,minlen:1,explicitId:!1,internal:!0});return{nodes:t,edges:n}}var oL=32,aL=16,cL=72,Bd=20,Wp=26,Hp=40,Ya=60,f1=6,Up=6,Ga=10,Gp=8,Wd=9,Yd=12,lL=14,Ha=' fill="var(--_s)" stroke="var(--_b)"';function h1(e,t,n){let r=e.usecase?.[t];return typeof r=="number"&&r>0?Math.min(r,2e3):n}function dL(e){return e.replace(/[&<>\\]/g,t=>`&#${t.charCodeAt(0)};`)}function Ps(e,t,n,r,i,s=0){return Ge(e&&!t?dL(e):e,t,n,r,i,s)}function Yp(e,t,n,r){let i=n===1||n===2?1:-1,s=n===1||n===3,a=(s?e.w:e.h)/2,o=0;if(e.kind===0)s?(a=Hp/2+3,o=(Ya-e.h)/2):a+=2;else if(e.kind===1){let c=(s?e.h:e.w)/2;a*=Math.sqrt(Math.max(1-(r/c)**2,0))}return s?[t.x+i*a,t.y+o+r]:[t.x+r,t.y+i*a]}function m1(e,t){let n=t===1||t===3;if(e.kind===0)return n?Ya*.5:Hp*.6;let r=n?e.h:e.w;return e.kind===1?r*.6:r-16}function uL(e,t,n){let r=new Map,i=(s,a,o,c)=>{let l=t[s];if(l.isGroup)return;let u=a[o]-l.x,h=a[o+1]-l.y,d;if(Math.abs(Math.abs(h)-l.h/2)<.5)d=h<0?0:2;else if(Math.abs(Math.abs(u)-l.w/2)<.5)d=u<0?3:1;else return;let m=s*4+d,p={route:a,at:o,toward:a[c+(d&1?1:0)]},y=r.get(m);y?y.push(p):r.set(m,[p])};for(let s of e){let a=s.route.length-3;s.src===s.dst||a<3||(i(s.src,s.route,0,3),i(s.dst,s.route,a,a-3))}for(let[s,a]of r){let o=s>>2,c=s&3,l=n[o],u=a.length>1?Math.min(lL,m1(l,c)/(a.length-1)):0;a.sort((h,d)=>h.toward-d.toward);for(let h=0;h`}function Ud(e){return e==="extension"?Yd:Rt(e)}function Gd(e,t,n,r,i,s,a){return e==="extension"?fL(t,n,r,i,s):_t(e,t,n,r,i,s,a)}function hL(e,t){let n=e.node,r=e.style.shape,i=` fill="none" stroke="var(--_b)"${e.style.line}`,s=-21,a=9,o;return n.actorType==="hollow"?(a=8,o=``):n.actorType==="awesome"?o=``:n.actorType==="icon"?(s=-14,a=12,o=`${t?.(n.icon??"")??""}`):o=``,n.business&&(o+=``),o}function g1(e,t,n){return Pn(e.direction)?Pt(n,r=>p1(e,t,n,r)):p1(e,t,n,!1)}function p1(e,t,n,r){let i=u1(e),s=n.fontSize??16,a=Math.round(s*.875),o=Math.round(s*.8125),c=n.measurer??ct(n.fontFamily,n.fontFamilyMono),l=n.padding??8,u=n.icons,h=r?"TB":ln(e.direction),d=h==="LR"||h==="RL",m=new Map,p=[],y=[];i.nodes.forEach((g,N)=>m.set(g.id,N));for(let g of i.nodes){let N=Ct(g.cssStyles.length>0?g.cssCompiledStyles.concat(g.cssStyles):g.cssCompiledStyles),w=(N.bold?1:0)|(N.italic?2:0),A=N.fontSize??s,D=g.labelType==="markdown",U=Ps(g.stereotype&&`«${g.stereotype}»`,!1,c,o,200,w),B={node:g,kind:2,style:N,label:U,stereotype:U,w:0,h:0,rows:[],keyW:0,headH:0,loops:0},F;if(g.isGroup){B.kind=4,B.label=Ps(g.label,D,c,A,4e3,w);let W=B.label.height;F=Bt(0,0),F.isGroup=!0,F.padX=Bd,F.padBottom=Bd,F.padTop=g.boundaryType==="package"?W+2*Up+16:W>0?W+16:Bd,F.minW=B.label.width+2*Bd}else{if(g.jsonRows){B.kind=3,B.label=Ps(g.label,!1,c,A,4e3,w|1);let W=0;for(let j of g.jsonRows){let Q=Ps(j.key,!1,c,a,4e3,w),Y=Ps(j.value,!1,c,a,260,w);B.rows.push([Q,Y]),B.keyW=Math.max(B.keyW,Q.width),W=Math.max(W,Y.width),B.h+=Math.max(Q.height,Y.height,Math.round(a*1.5))+Gp}B.keyW>0&&(B.keyW+=2*Ga),B.headH=Math.max(B.label.height,Math.round(A*1.5))+Gp,B.w=Math.max(B.label.width+2*Ga,B.rows.length>0?B.keyW+W+2*Ga:0,72),B.h+=B.headH}else if(g.actorType)B.kind=0,B.label=Ps(g.label,D,c,A,140,w),B.w=Math.max(Hp,B.label.width,U.width),B.h=Ya+f1+U.height+B.label.height;else{B.label=Ps(g.label,D,c,g.shape==="note"?a:A,180,w);let W=Math.max(B.label.width,U.width),j=B.label.height+U.height;g.shape==="usecaseEllipse"||g.shape==="usecaseBusiness"?(B.kind=1,B.w=Math.max(W+2*g.padding+(g.business?16:4),88),B.h=Math.max(j+28,48)):g.shape==="note"?(B.w=W+2*g.padding+6,B.h=j+18):(B.w=Math.max(W+2*g.padding+12,80),B.h=Math.max(j+24,44))}F=Bt(B.w,B.h)}F.seq=p.length,p.push(B),y.push(F)}i.nodes.forEach((g,N)=>{y[N].parent=g.parentId!==void 0?m.get(g.parentId)??-1:-1});let E=[],b=[],S=[];for(let g of i.edges){let N=m.get(g.start),w=m.get(g.end);if(N===void 0||w===void 0)continue;let A=g.relationshipType==="include"||g.relationshipType==="extend",D=Ps(A?`«${g.label}»`:g.label,g.labelType==="markdown",c,a,200);N===w&&(p[N].loops++,d?y[N].h+=2*(Wp+(D.height>0?D.height+8:0)):y[N].w+=2*(Wp+(D.width>0?D.width+12:0))),S.push(g),b.push(D),E.push({src:N,dst:w,minlen:g.minlen,labelW:D.width>0?D.width+12:0,labelH:D.height>0?D.height+4:0,route:[],labelX:0,labelY:0})}let x=On(y,E,h,{nodeSep:h1(t,"nodeSpacing",oL),edgeSep:aL,rankSep:h1(t,"rankSpacing",cL),portSep:20}),I=yn(e.title,c,s,4e3),L=I.height>0?I.height+12:0,O=Math.max(x.width,I.width),v=l+(O-x.width)/2,G=l+L;Tr(y,E,v,G);let K=Math.ceil(O+2*l),C=Math.ceil(x.height+L+2*l),Z=new Map;for(let g of E)ur(Z,g.route);uL(E,y,p);let oe="",H=[],z="";for(let g=0;g`+Ne(N.label,k+P/2,J+ee/2,se,u)}else re=``+Ne(N.label,pL(w,N.label.width,Z),J+8+N.label.height/2,se,u);oe+=`${re}`;continue}let ne,q;if(N.kind===0){q="pele-actor";let k=-Y/2,J=k+Ya+f1+N.stereotype.height/2;ne=`${hL(N,u)}`+Ne(N.stereotype,0,J,` class="pele-stereotype" font-size="${o}" fill="var(--_m)"`,u)+Ne(N.label,0,Y/2-N.label.height/2,` class="pele-label"${B}`,u)}else if(N.kind===3){q="pele-json";let k=-Q/2,J=-Y/2+N.headH,te="",se=`M${f(k)},${f(J)}H${f(k+Q)}`;N.keyW>0&&(se+=`M${f(k+N.keyW)},${f(J)}V${f(Y/2)}`);for(let[re,P]of N.rows){let ee=Math.max(re.height,P.height,Math.round(a*1.5))+Gp;te+=Ne(re,k+Ga+re.width/2,J+ee/2,` class="pele-json-key"${j}`,u)+mL(P,k+N.keyW+Ga,J+ee/2,` class="pele-json-value"${W}${B}`,u),J+=ee}ne=``+Ne(N.label,0,-Y/2+N.headH/2,` class="pele-label" font-weight="var(--_hw)"${W}${B}`,u)+`${te}`}else{let k=N.stereotype.height/2,J;if(N.kind===1){if(q="pele-usecase",J=``,A.business){let te=Q/2-15,se=Q/2-5,re=P=>Y/2*Math.sqrt(1-(P/(Q/2))**2);J+=``}}else if(A.shape==="note"){q="pele-note";let te=Q/2,se=Y/2;J=``}else q="pele-usecase",J=``;ne=J+Ne(N.stereotype,0,-N.label.height/2,` class="pele-stereotype" font-size="${o}"${j}`,u)+Ne(N.label,0,k,` class="pele-label"${A.shape==="note"?` font-size="${a}"`:""}${W}${B}`,u)}z+=`${ne}`}let M="",T="",R="",_=new Map;for(let g=0;g0||w.cssCompiledStyles.length>0?Ct(w.cssCompiledStyles.concat(w.style)):void 0,U=w.arrowTypeStart,B=w.arrowTypeEnd,F;if(N.src===N.dst){let q=y[N.src],k=p[N.src],J=_.get(N.src)??0;_.set(N.src,J+1);let te=d?2:1,se=Math.min(m1(k,te)/2,8+J*6),re=Wp+J*8,[P,ee]=Yp(k,q,te,-se),[ae,ue]=Yp(k,q,te,se),ce=Math.hypot(re,se)||1,pe=d?se/ce:re/ce,V=d?re/ce:se/ce,X=Ud(U),le=Ud(B),de=(Ce,ke,be,Ae)=>d?`${f(Ce+be*se*(Ae?1:0))},${f(ke+Ae)}`:`${f(Ce+Ae)},${f(ke+be*se*(Ae?1:0))}`,Se=d?P-pe*X:P+pe*X,_e=d?ee+V*X:ee-V*X,xe=ae+pe*le,Me=ue+V*le;F={d:`M${f(Se)},${f(_e)}C${de(P,ee,-1,re)} ${de(ae,ue,1,re)} ${f(xe)},${f(Me)}`,sx:P,sy:ee,sdx:d?pe:-pe,sdy:d?-V:V,ex:ae,ey:ue,edx:-pe,edy:-V},d?(N.labelX=q.x,N.labelY=Math.max(ee,ue)+re*.75+6+A.height/2):(N.labelX=Math.max(P,ae)+re*.75+8+A.width/2,N.labelY=q.y)}else{if(N.route.length<6)continue;F=Cn(N.route,void 0,Ud(U),Ud(B))}let W=Bo(F.d,[F.sx,F.sy,F.ex,F.ey],H,F.tokens),j=W&&Wo(W,D?.line),Q=j||(D?.stroke?rt(D.stroke):"var(--_l)");if(j===""){let q="var(--_bg)";M+=Go(F.d,Gd(U,F.sx,F.sy,F.sdx,F.sdy,q,q)+Gd(B,F.ex,F.ey,F.edx,F.edy,q,q),D?.line)}let Y=w.internal?"2 3":w.pattern==="dotted"?"5 4":w.animate?"9 5":"",ne=Gd(U,F.sx,F.sy,F.sdx,F.sdy,Q)+Gd(B,F.ex,F.ey,F.edx,F.edy,Q);if(T+=``+(W&&j?Uo(ne,W):ne)+"",A.width>0){let q=N.labelX,k=N.labelY,J=w.relationshipType==="include"||w.relationshipType==="extend";R+=dn(w.id,A,q,k,(J?' fill="var(--_m)"':"")+(D?.text??""),u)}}return{svg:at("usecase",K,C,s,n,e,Ne(I,K/2,l+I.height/2,' class="pele-title" font-weight="var(--_tw)"')+(oe?`${oe}`:"")+Dn(M)+(T?`${T}`:"")+(R?`${R}`:"")+`${z}`),width:K,height:C,links:[]}}function pL(e,t,n){let r=n.get(Math.round(e.y-e.h/2));if(t===0||r===void 0)return e.x;let i=e.x-e.w/2+6,s=e.x+e.w/2-6,a=r.filter(d=>d>i&&dd-m);a.push(s);let o=t/2+6,c=e.x,l=1/0,u=0,h=i;for(let d of a){if(d-h>=2*o){let m=Math.min(Math.max(e.x,h+o),d-o);Math.abs(m-e.x)u&&(u=d-h,c=(h+d)/2);h=d}return c}function mL(e,t,n,r,i){if(e.lines.length<2)return Ne(e,t+e.width/2,n,r,i);let s="";for(let a=0;al1(e,n),render:g1};function Fs(e){let t=e.trim();return t.length>=2&&t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function Kp(e){return e.map(Fs).sort()}var Hd=class{constructor(){fe(this,"type","venn");fe(this,"title");fe(this,"subsets",[]);fe(this,"textNodes",[]);fe(this,"styles",[]);fe(this,"known",new Set);fe(this,"current");fe(this,"indent",!1)}setDiagramTitle(t){this.title=t}addSubsetData(t,n,r){let i=Kp(t);this.current=i,i.length===1&&this.known.add(i[0]),this.subsets.push({sets:i,size:r??10/t.length**2,label:n?Fs(n):void 0})}addTextData(t,n,r){this.textNodes.push({sets:Kp(t),id:Fs(n),label:r?Fs(r):void 0})}addStyleData(t,n){let r=new Map;for(let[i,s]of n)r.set(i,s&&Fs(s));this.styles.push({targets:Kp(t),styles:r})}validateUnionIdentifiers(t){let n=t.map(Fs).filter(r=>!this.known.has(r));if(n.length>0)throw new Qe(`unknown set identifier: ${n.join(", ")}`,"semantic",{type:"venn"})}getCurrentSets(){return this.current}getIndentMode(){return this.indent}setIndentMode(t){this.indent=t}};var zp=["$end","INVALID","EOF","NEWLINE","VENN","TITLE","SET","UNION","TEXT","INDENT_TEXT","STYLE","BRACKET_LABEL","NUMERIC","HEXCOLOR","RGBCOLOR","RGBACOLOR","IDENTIFIER","STRING","COMMA","COLON"],gL=[["venn-beta",4],["set",6],["union",7],["text",8],["style",10]],Kd=class{constructor(t,n){fe(this,"src",t);fe(this,"host",n);fe(this,"text","");fe(this,"start",0);fe(this,"at",0);fe(this,"lineStart",!1);fe(this,"ended",!1)}word(t,n){let r=this.src;for(let i=0;i90))return!1}return!0}keyword(t,n){return this.word(t,n)&&!ot(this.src.charCodeAt(t+n.length))}color(t,n){let r=this.src,i=t+1;for(let s=0;s=n)return this.ended?0:(this.ended=!0,2);let i=t.charCodeAt(r);if(i===37&&t.charCodeAt(r+1)===37&&t.charCodeAt(r+2)!==123){this.at=this.lineEnd(r+2);continue}if(this.lineStart&&this.word(r,"title")&&this.afterLineFeed(r)&&t.slice(r+5,this.lineEnd(r+5)).trim()===""){let s=this.lineEnd(r+5);for(;t.charCodeAt(s)===10||t.charCodeAt(s)===13;)s++;this.at=s;continue}if(this.lineStart){if(i===32||i===9){let s=r+1;for(;t.charCodeAt(s)===32||t.charCodeAt(s)===9;)s++;if(this.at=s,this.keyword(s,"text")&&this.host.getIndentMode())return this.at=s+4,this.lineStart=!1,this.text=t.slice(r,s),9;continue}i!==10&&i!==13&&(this.host.setIndentMode(!1),this.lineStart=!1)}if(i===10||i===13){for(r++;t.charCodeAt(r)===10||t.charCodeAt(r)===13;)r++;return this.lineStart=!0,this.token(3,r)}if(i===37&&t.charCodeAt(r+1)===37){this.at=this.lineEnd(r);continue}if(i===32||i===9){for(r++;t.charCodeAt(r)===32||t.charCodeAt(r)===9;)r++;this.at=r;continue}if((i|32)>=97&&(i|32)<=122||i===95){let s=t.charCodeAt(r+5);if(this.word(r,"title")&&qe(s)&&s!==10&&s!==13){let a=r+6;for(;ar+6)return this.token(5,a)}for(let[a,o]of gL)if(this.keyword(r,a)&&t.charCodeAt(r+a.length)!==45)return this.token(o,r+a.length);if(this.word(r,"rgb")){let a=(t.charCodeAt(r+3)|32)===97,o=r+(a?4:3),c=t.charCodeAt(o)===40?this.color(o,a?4:3):-1;if(c!==-1)return this.token(a?15:14,c)}for(r++;ot(t.charCodeAt(r))||t.charCodeAt(r)===45;)r++;return this.token(16,r)}if(i===91){if(t.charCodeAt(r+1)===34){let a=t.indexOf('"',r+2);return a===-1||t.charCodeAt(a+1)!==93?1:(this.at=a+2,this.text=t.slice(r+2,a),11)}let s=r+1;for(;ss){if(t.charCodeAt(r)===46&&xt(t.charCodeAt(r+1)))for(r+=2;xt(t.charCodeAt(r));)r++}else if(t.charCodeAt(r)===46&&xt(t.charCodeAt(r+1)))for(r+=2;xt(t.charCodeAt(r));)r++;else return 1;return this.token(12,r)}if(i===35){let s=r+1;for(;s=r+4?this.token(13,s):1}if(i===34){let s=t.indexOf('"',r+1);return s===-1?1:this.token(17,s+1)}return i===44?this.token(18,r+1):i===58?this.token(19,r+1):1}}token(t,n){return this.text=this.src.slice(this.at,n),this.at=n,t}};var bL="'EOF', 'NEWLINE', 'TITLE', 'SET', 'UNION', 'TEXT', 'INDENT_TEXT', 'STYLE'",yL="'NUMERIC', 'IDENTIFIER', 'STRING', 'HEXCOLOR', 'RGBCOLOR', 'RGBACOLOR'";function y1(e,t){let n=new Kd(e,t),r=-1,i=()=>r===-1?r=n.next():r,s=m=>{throw i()===1?ft("venn",e,n.start,"",!0):ft("venn",e,n.start,`Expecting ${m}, got '${zp[r]}'`)},a=()=>(r=-1,n.text),o=m=>(i()!==m&&s(`'${zp[m]}'`),a()),c=()=>(i()!==16&&r!==17&&s("'IDENTIFIER', 'STRING'"),a()),l=()=>{let m=[c()];for(;i()===18;)a(),m.push(c());return m},u=(m,p)=>{let y=i()===11?a():void 0,E;if(i()===19&&(a(),E=parseFloat(o(12))),p){if(m.length<2)throw new Qe("union requires multiple identifiers","semantic",{type:"venn"});t.validateUnionIdentifiers(m)}t.addSubsetData(m,y,E),t.setIndentMode(!0)},h=m=>{let p=i();p!==16&&p!==17&&p!==12&&s("'NUMERIC', 'IDENTIFIER', 'STRING'");let y=a(),E=p!==12&&i()===11?a():void 0;t.addTextData(m(),y,E)},d=()=>{let m=l(),p=[];for(;;){let y=o(16);o(19);let E;if(i()===17)E=a();else{let b=[];for(;i()===16||r>=12&&r<=15;)b.push(a());b.length===0&&s(yL),E=b.join(" ")}if(p.push([y,E]),i()!==18)break;a()}t.addStyleData(m,p)};for(;i()===3;)a();for(o(4);;){let m=i();if(m===2)return;if((m<3||m>10||m===4)&&s(bL),a(),m===5)t.setDiagramTitle(n.text.slice(6));else if(m===6)u([c()],!1);else if(m===7)u(l(),!0);else if(m===8){let p=l();h(()=>p)}else m===9?h(()=>{let p=t.getCurrentSets();if(!p)throw new Qe("text requires set","semantic",{type:"venn"});return p}):m===10&&d()}}var zd=Math.PI*2;function EL(e){let t=new Set,n=new Map;for(let i of e)t.add(JSON.stringify([...i.sets].sort())),i.sets.length===1&&n.set(i.sets[0],i.size);let r=[];for(let i of e){if(i.sets.length<3)continue;let s=[...i.sets].sort();for(let a=0;a0?[...e,...r]:e}function xL(e,t,n){if(n>=e+t)return 0;let r=Math.min(e,t);if(n<=Math.abs(e-t))return Math.PI*r*r;let i=e*e*Math.acos((n*n+e*e-t*t)/(2*n*e)),s=t*t*Math.acos((n*n+t*t-e*e)/(2*n*t)),a=.5*Math.sqrt(Math.max((-n+e+t)*(n+e-t)*(n-e+t)*(n+e+t),0));return i+s-a}function AL(e,t,n){let r=Math.abs(e-t),i=e+t;if(!(n>0))return i;if(n>=Math.PI*Math.min(e,t)**2)return r;for(let s=0;s<48;s++){let a=(r+i)/2;xL(e,t,a)>n?r=a:i=a}return(r+i)/2}function E1(e,t,n,r,i,s){let a=1/0;for(let o of t){let c=e[o],l=r-c.x,u=i-c.y,h=c.r-Math.sqrt(l*l+u*u);if(h{let E=E1(e,t,n,p,y,l-a*1e-9);if(!(E>l-a*1e-9))return!1;let b=Math.hypot(p-r,y-i);return E>l+a*1e-9||ba*1e-6;p++){let y=!1;for(let E=0;E<8;E++){let b=E*zd/8;h(o+Math.cos(b)*m,c+Math.sin(b)*m)&&(y=!0)}y||(m/=2)}return{x:o,y:c,margin:l}}function x1(e){let t=new Map;for(let E of e)for(let b of E.sets)t.has(b)||t.set(b,10);for(let E of e)E.sets.length===1&&t.set(E.sets[0],E.size);let n=new Map,r=[],i=0;for(let E of t.values())Number.isFinite(E)&&E>i&&(i=E);i===0&&(i=10);let s=Math.sqrt(i/Math.PI);for(let[E,b]of t){n.set(E,r.length);let S=Number.isFinite(b)&&b>0?Math.sqrt(b/Math.PI):0;r.push({id:E,x:0,y:0,r:Math.max(S,s*.3)})}let a=r.length;if(a<2)return r;let o=new Map;for(let E of EL(e)){if(E.sets.length!==2)continue;let b=n.get(E.sets[0]),S=n.get(E.sets[1]);b!==S&&o.set(Math.min(b,S)*a+Math.max(b,S),E.size)}let c=new Map;for(let[E,b]of o)c.set(E,AL(r[Math.floor(E/a)].r,r[E%a].r,b));let l=s*.15,u=(E,b)=>c.get(E*a+b)??r[E].r+r[b].r+l;if(a===2)return r[1].x=u(0,1),r;if(a===3){let E=u(0,1),b=u(0,2),S=u(1,2),x=e.some(I=>new Set(I.sets).size===3);for(let I=0;I<40;I++){let L=E>0?(E*E+b*b-S*S)/(2*E):0;if(r[1].x=E,r[2].x=Math.max(-b,Math.min(b,L)),r[2].y=Math.sqrt(Math.max(b*b-L*L,0)),!x||Vd(r,[0,1,2],[]).margin>s*.12)break;E*=.94,b*=.94,S*=.94}return r}let h=0;for(let E of r)h+=2*E.r+l;let d=Math.min(300,Math.floor(3e6/(a*a)));if(a<=64){let E=h/zd;r.forEach((b,S)=>{let x=S*zd/a-Math.PI/2;b.x=Math.cos(x)*E,b.y=Math.sin(x)*E})}else{let E=Math.ceil(Math.sqrt(a)),b=2*s+l;r.forEach((S,x)=>{S.x=x%E*b,S.y=Math.floor(x/E)*b})}let m=new Float64Array(a),p=new Float64Array(a),y=new Int32Array(a);for(let E=0;E=I)continue;v<1e-9&&(L=Math.cos(b+S),O=Math.sin(b+S),v=1);let G=(v-(x??I))/2/v;m[b]+=L*G,p[b]+=O*G,m[S]-=L*G,p[S]-=O*G,y[b]++,y[S]++}for(let b=0;b`M${t(c.x-c.r)},${t(c.y)}A${t(c.r)},${t(c.r)} 0 1 1 ${t(c.x+c.r)},${t(c.y)}A${t(c.r)},${t(c.r)} 0 1 1 ${t(c.x-c.r)},${t(c.y)}Z`;if(e.length===1)return n(e[0]);let r=(c,l,u,h)=>{for(let d of e)if(d!==u&&d!==h&&Math.hypot(c-d.x,l-d.y)>d.r*(1+1e-9))return!1;return!0},i=[];for(let c=0;c=u.r+h.r||d<=Math.abs(u.r-h.r)||d===0)continue;let m=(u.r*u.r-h.r*h.r+d*d)/(2*d),p=Math.sqrt(Math.max(u.r*u.r-m*m,0)),y=u.x+(h.x-u.x)*m/d,E=u.y+(h.y-u.y)*m/d;for(let b of[1,-1]){let S=y+b*p*(h.y-u.y)/d,x=E-b*p*(h.x-u.x)/d;r(S,x,u,h)&&i.push({x:S,y:x,a:u,b:h})}}if(i.length<2){let c=e[0];for(let l of e)l.rl.r*(1+1e-9))return"";return n(c)}let s=0,a=0;for(let c of i)s+=c.x/i.length,a+=c.y/i.length;i.sort((c,l)=>Math.atan2(c.y-a,c.x-s)-Math.atan2(l.y-a,l.x-s));let o="";for(let c=0;cMath.PI?1:0)}h===void 0?o+=`L${t(u.x)},${t(u.y)}`:o+=`A${t(h.r)},${t(h.r)} 0 ${d} 1 ${t(u.x)},${t(u.y)}`}return o+"Z"}var SL=100,wL=1.6,S1=Ct([]);function Vp(e){return e.length===1?e[0]:JSON.stringify(e)}function w1(e,t,n){let r=n.fontSize??16,i=Math.round(r*.875),s=Math.round(r*.8125),a=n.measurer??ct(n.fontFamily,n.fontFamilyMono),o=n.padding??8,c=x1(e.subsets),l=new Map;c.forEach((g,N)=>l.set(g.id,N));let u=new Map;for(let{targets:g,styles:N}of e.styles){let w=Vp(g),A=u.get(w);A||u.set(w,A=new Map);for(let[D,U]of N)A.set(D,U)}let h=g=>{let N=u.get(g);if(!N)return S1;let w=[];for(let[A,D]of N)w.push(`${A}:${D}`);return Ct(w)},d=c.map(()=>[]);for(let g=0;gl.get(q)),D=new Set(A),U=A[0];for(let q of A)c[q].r!D.has(q)),Q=Vd(c,A,j),Y=j.length>0&&Q.marginy&&(y=g.r);let E=y>0?SL/y:1,b=1;for(let g of p.values()){if(g.spot.margin<=0)continue;let N=0,w=0;for(let D of g.lines)N=Math.max(N,D.label.width),w+=D.label.height;let A=Math.hypot(N,w)/2+4;b=Math.max(b,Math.min(A/(g.spot.margin*E),wL))}E*=b;for(let g of p.values()){let N=Math.max(g.spot.margin*E*1.8,72);for(let w of g.lines)w.label.width>N&&(w.label=Ge(w.raw,!1,a,w.size,N,w.base))}let S=1/0,x=1/0,I=-1/0,L=-1/0;for(let g of c)S=Math.min(S,(g.x-g.r)*E),x=Math.min(x,(g.y-g.r)*E),I=Math.max(I,(g.x+g.r)*E),L=Math.max(L,(g.y+g.r)*E);for(let g of p.values()){let N=0,w=0;for(let A of g.lines)N=Math.max(N,A.label.width),w+=A.label.height;S=Math.min(S,g.spot.x*E-N/2),I=Math.max(I,g.spot.x*E+N/2),x=Math.min(x,g.spot.y*E-w/2),L=Math.max(L,g.spot.y*E+w/2)}c.length===0&&(S=x=I=L=0);let O=Ge(e.title&&Fs(e.title),!1,a,r,4e3,1),v=O.height>0?O.height+12:0,G=Math.max(I-S,O.width),K=o+(G-(I-S))/2-S,C=o+v-x,Z=Math.ceil(G+2*o),oe=Math.ceil(L-x+v+2*o),H=c.map(g=>({id:g.id,x:g.x*E+K,y:g.y*E+C,r:g.r*E})),z="";H.forEach((g,N)=>{let w=Et(N),A=p.get(g.id)?.style??S1;z+=``});let M=[...p.values()].filter(g=>g.sets.length>1&&g.style.shape!==""),T=g=>{if(g.across)return"";let N=g.sets.length===1&&/[";]fill-opacity:/.test(g.style.shape)?g.style.shape:"";for(let w of M)w.sets.every(A=>g.sets.includes(A))&&(N=w.style.shape);return N},R="",_="";for(let g of p.values()){let N=Ue(g.sets.join("|"));if(g.sets.length>1&&g.style.shape!==""){let F=A1(g.inside.map(W=>H[W]),f);F!==""&&(R+=``)}let w=0;for(let F of g.lines)w+=F.label.height;if(w===0)continue;let A=g.spot.x*E+K,D=g.spot.y*E+C-w/2,U=T(g),B="";for(let F of g.lines){let W=F.id===void 0?g.style.text:h(F.id).text,j=dr(U,W),Q=F.id===void 0?` class="pele-label"${F.size===r?"":` font-size="${F.size}"`}${j?` fill="${j}"`:""}${W}`:` class="pele-venn-text" data-id="${Ue(F.id)}" font-size="${s}" fill="${j??"var(--_m)"}"${W}`;B+=Ne(F.label,A,D+F.label.height/2,Q),D+=F.label.height}_+=`${B}`}return{svg:at("venn",Z,oe,r,n,{},Ne(O,Z/2,o+O.height/2,' class="pele-title" font-weight="var(--_tw)"')+`${z}`+(R?`${R}`:"")+(_?`${_}`:"")),width:Z,height:oe,links:[]}}var _1={type:"venn",parse(e,t,n){let r=new Hd;return n&&(r.title=n),y1(e,r),r},render:w1};var jd=class{constructor(){fe(this,"nodes",new Map);fe(this,"labels");fe(this,"links",[]);fe(this,"trends",new Map);fe(this,"pipelines",new Map);fe(this,"annotations",[]);fe(this,"notes",[]);fe(this,"accelerators",[]);fe(this,"deaccelerators",[]);fe(this,"annotationsBox");fe(this,"axes",{});fe(this,"size")}addNode(t){let n=this.nodes.get(t.id)??{id:t.id,label:t.label};this.nodes.set(t.id,{...n,...t,className:t.className??n.className,labelOffsetX:t.labelOffsetX??n.labelOffsetX,labelOffsetY:t.labelOffsetY??n.labelOffsetY}),this.labels=void 0}addLink(t){this.links.push(t)}addTrend(t){this.trends.set(t.nodeId,t)}startPipeline(t){this.pipelines.set(t,{nodeId:t,componentIds:[]});let n=this.nodes.get(t);n&&(n.isPipelineParent=!0)}addPipelineComponent(t,n){this.pipelines.get(t)?.componentIds.push(n);let r=this.nodes.get(n);r&&(r.inPipeline=!0)}addAnnotation(t){this.annotations.push(t)}addNote(t){this.notes.push(t)}addAccelerator(t){this.accelerators.push(t)}addDeaccelerator(t){this.deaccelerators.push(t)}setAnnotationsBox(t,n){this.annotationsBox={x:t,y:n}}setAxes(t){this.axes={...this.axes,...t}}setSize(t,n){this.size={width:t,height:n}}getNode(t){return this.nodes.get(t)}resolveNodeId(t){if(this.nodes.has(t))return t;if(!this.labels){this.labels=new Map;for(let[n,r]of this.nodes)this.labels.has(r.label)||this.labels.set(r.label,n)}return this.labels.get(t)??t}build(){let t=[];for(let n of this.nodes.values()){if(typeof n.x!="number"||typeof n.y!="number")throw new Qe(`Node "${n.label}" is missing coordinates`,"semantic",{type:"wardley"});t.push(n)}return{nodes:t,links:[...this.links],trends:[...this.trends.values()],pipelines:[...this.pipelines.values()],annotations:[...this.annotations],notes:[...this.notes],accelerators:[...this.accelerators],deaccelerators:[...this.deaccelerators],annotationsBox:this.annotationsBox,axes:{...this.axes},size:this.size}}};function Xd(e,t){let n=e<=1?e*100:e;if(n<0||n>100)throw new Qe(`${t} must be between 0-1 (decimal) or 0-100 (percentage). Received: ${e}`,"semantic",{type:"wardley"});return n}function wi(e,t,n){return{x:Xd(t,`${n} evolution`),y:Xd(e,`${n} visibility`)}}function R1(e){return e==="+<>"?"bidirectional":e==="+<"?"backward":e==="+>"?"forward":void 0}function _L(e){if(!e?.startsWith("+"))return{};let t=e.indexOf("'",2),n=e[1]==="'"&&t!==-1?e.slice(2,t):void 0;return e.includes("<>")?{flow:"bidirectional",label:n}:e.includes("<")?{flow:"backward",label:n}:e.includes(">")?{flow:"forward",label:n}:{label:n}}function T1(e){return e?[(e.negX?-1:1)*e.offsetX,(e.negY?-1:1)*e.offsetY]:[void 0,void 0]}function RL(e,t){e.size&&t.setSize(e.size.width,e.size.height),e.evolution&&t.setAxes({stages:e.evolution.stages.map(n=>n.secondName?`${n.name.trim()} / ${n.secondName.trim()}`:n.name.trim()),stageBoundaries:e.evolution.stages.filter(n=>n.boundary!==void 0).map(n=>n.boundary)});for(let n of e.anchors){let r=wi(n.visibility,n.evolution,`Anchor "${n.name}"`);t.addNode({id:n.name,label:n.name,x:r.x,y:r.y,className:"anchor"})}for(let n of e.components){let r=wi(n.visibility,n.evolution,`Component "${n.name}"`),[i,s]=T1(n.label);t.addNode({id:n.name,label:n.name,x:r.x,y:r.y,className:"component",labelOffsetX:i,labelOffsetY:s,inertia:n.inertia,sourceStrategy:n.decorator?.strategy})}for(let n of e.notes){let r=wi(n.visibility,n.evolution,`Note "${n.text}"`);t.addNote({text:n.text,x:r.x,y:r.y})}for(let n of e.pipelines){let r=t.getNode(n.parent);if(!r||typeof r.y!="number")throw new Qe(`Pipeline "${n.parent}" must reference an existing component with coordinates.`,"semantic",{type:"wardley"});let i=r.y;t.startPipeline(n.parent);for(let s of n.components){let a=`${n.parent}_${s.name}`,[o,c]=T1(s.label),l=Xd(s.evolution,`Pipeline component "${s.name}" evolution`);t.addNode({id:a,label:s.name,x:l,y:i,className:"pipeline-component",labelOffsetX:o,labelOffsetY:c,inertia:void 0,sourceStrategy:void 0}),t.addPipelineComponent(n.parent,a)}}for(let n of e.links){let r=!!n.arrow&&(n.arrow.includes("-.->")||n.arrow.includes(".-.")),i=_L(n.arrow),s=R1(n.fromPort)??R1(n.toPort)??i.flow;t.addLink({source:t.resolveNodeId(n.from),target:t.resolveNodeId(n.to),dashed:r,label:i.label??n.linkLabel,flow:s})}for(let n of e.evolves){let r=t.getNode(n.component);r?.y!==void 0&&t.addTrend({nodeId:n.component,targetX:Xd(n.target,`Evolve target for "${n.component}"`),targetY:r.y})}if(e.annotations.length>0){let n=wi(e.annotations[0].x,e.annotations[0].y,"Annotations box");t.setAnnotationsBox(n.x,n.y)}for(let n of e.annotation){let r=wi(n.x,n.y,`Annotation ${n.number}`);t.addAnnotation({number:n.number,coordinates:[{x:r.x,y:r.y}],text:n.text})}for(let n of e.accelerators){let r=wi(n.x,n.y,`Accelerator "${n.name}"`);t.addAccelerator({name:n.name,x:r.x,y:r.y})}for(let n of e.deaccelerators){let r=wi(n.x,n.y,`Deaccelerator "${n.name}"`);t.addDeaccelerator({name:n.name,x:r.x,y:r.y})}}function M1(e,t){let n=new jd;return RL(e,n),{type:"wardley",title:e.title||t,accTitle:e.accTitle?e.accTitle.replace(/^\s+/g,""):void 0,accDescr:e.accDescr?e.accDescr.replace(/\n\s+/g,` +`):void 0,...n.build()}}function C1(e,t){let n=t;for(let r=e.charCodeAt(n);r>=48&&r<=57;r=e.charCodeAt(n))n++;return n}function TL(){let e=0,t=0;return(n,r)=>{if((r=t)&&(e=r,t=C1(n,r)),t===r||n.charCodeAt(t)!==46)return-1;let i=C1(n,t+1);return i>t+1?i:-1}}var N1={name:"ARROW",pattern:/->/y,first:"-"},I1={name:"LINK_ARROW",pattern:/-->|-\.->|>|\+'[^']*'<>|\+'[^']*'<|\+'[^']*'>/y,first:"->+"},Un=(e,t)=>({name:e,pattern:new RegExp(t,"y"),first:t[0]}),k1=[{name:"[",pattern:"["},{name:",",pattern:","},{name:"]",pattern:"]"},{name:"@",pattern:"@"},{name:"/",pattern:"/"},{name:"(",pattern:"("},{name:")",pattern:")"},{name:"-",pattern:"-",longer:[N1,I1,Ht]},{name:"{",pattern:"{"},{name:"}",pattern:"}"},{name:"WARDLEY_NUMBER",pattern:/[0-9]+\.[0-9]+/y,first:"0123456789",scanner:TL},N1,{name:"LINK_PORT",pattern:/\+<>|\+>|\+))*(?:[ \t]+[A-Za-z(](?:[A-Za-z0-9_()&]|-(?!>))*)*/y,first:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"},{name:"WS",pattern:/[ \t]+/y,hidden:!0,first:" "},Zi(),Xt,pr,{name:"INT",pattern:/0|[1-9][0-9]*(?!\.)/y,first:"0123456789"},Fn,{name:"ID",pattern:/[\w]([-\w]*\w)?/y,first:"_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"},Sn,wn,Ht,Qt,Zt];function $1(e){let t=new Ut(Yt(e,k1,"wardley"),k1,"wardley"),n={$type:"Wardley",anchors:[],components:[],links:[],evolves:[],pipelines:[],notes:[],annotations:[],annotation:[],accelerators:[],deaccelerators:[]},r=m=>t.kinds[t.i]===m,i=()=>r(36)||r(37)||r(30),s=()=>r(36)?un(t.take()):r(37)||r(30)?t.take():t.fail("a name"),a=()=>Number(t.expect(10)),o=()=>parseInt(t.expect(35)),c=()=>r(10)?Number(t.take()):parseInt(t.expect(35)),l=()=>{if(!r(-1))for(r(38)||t.fail("a line break or the end of input");r(38);)t.i++},u=m=>{t.expect(0);let p=m();t.expect(1);let y=m();return t.expect(2),[p,y]},h=()=>{t.expect(21),t.expect(0);let m=t.accept(7),p=o();t.expect(1);let y=t.accept(7),E=o();return t.expect(2),{$type:"Label",negX:m,offsetX:p,negY:y,offsetY:E}},d=()=>{let m={$type:"EvolutionStage",name:s()};return t.accept(3)&&(m.boundary=a()),t.accept(4)&&(m.secondName=s()),m};for(;r(38);)t.i++;for(t.expect(16);!r(-1);)switch(t.kind){case 38:t.i++;break;case 32:n.accDescr=Vt(t.take()),l();break;case 33:n.accTitle=zt(t.take()),l();break;case 34:n.title=Kt(t.take()),l();break;case 17:{t.i++;let[m,p]=u(o);l(),n.size={$type:"Size",width:m,height:p};break}case 18:{t.i++;let m=[d()];for(t.expect(11),m.push(d());t.accept(11);)m.push(d());l(),n.evolution={$type:"Evolution",stages:m};break}case 19:{t.i++;let m=s(),[p,y]=u(a);l(),n.anchors.push({$type:"Anchor",name:m,visibility:p,evolution:y});break}case 20:{t.i++;let m={$type:"Component",name:s(),visibility:0,evolution:0,inertia:!1};[m.visibility,m.evolution]=u(a),r(21)&&(m.label=h()),r(5)&&t.kinds[t.i+1]===15&&(t.i++,m.decorator={$type:"Decorator",strategy:t.take()},t.expect(6)),t.accept(22)?m.inertia=!0:t.accept(5)&&(t.expect(22),t.expect(6),m.inertia=!0),l(),n.components.push(m);break}case 23:{t.i++;let m=s(),p=a();l(),n.evolves.push({$type:"Evolve",component:m,target:p});break}case 24:{t.i++;let m=s();for(t.expect(8),t.expect(38);r(38);)t.i++;let p=[];do{t.expect(20);let y={$type:"PipelineComponent",name:s(),evolution:0};t.expect(0),y.evolution=a(),t.expect(2),r(21)&&(y.label=h()),l(),p.push(y)}while(r(20));t.expect(9),l(),n.pipelines.push({$type:"Pipeline",parent:m,components:p});break}case 25:{t.i++;let m=un(t.expect(36)),[p,y]=u(a);l(),n.notes.push({$type:"Note",text:m,visibility:p,evolution:y});break}case 26:{t.i++;let[m,p]=u(c);l(),n.annotations.push({$type:"Annotations",x:m,y:p});break}case 27:{t.i++;let m=o();t.expect(1);let[p,y]=u(c),E=un(t.expect(36));l(),n.annotation.push({$type:"Annotation",number:m,x:p,y,text:E});break}case 28:case 29:{let m=t.kind===29;t.i++;let p=s(),[y,E]=u(a);l(),m?n.deaccelerators.push({$type:"Deaccelerator",name:p,x:y,y:E}):n.accelerators.push({$type:"Accelerator",name:p,x:y,y:E});break}default:{i()||t.fail("a statement");let m={$type:"Link",from:s(),to:""};r(12)&&(m.fromPort=t.take()),(r(13)||r(11))&&(m.arrow=t.take()),m.to=s(),r(12)&&(m.toPort=t.take()),r(14)&&(m.linkLabel=t.take().substring(1).trim()),l(),n.links.push(m)}}return n}var ML=["Genesis","Custom Built","Product","Commodity"],CL=48,Gt=6,_i=10,NL=8,qd=15,Ka=60,IL=30,L1=20,jp="var(--_c)",Vn="var(--_l)";function kL(e,t,n,r,i){let s=e["wardley-beta"]?.[t];return typeof s=="number"&&s>=r&&s<=i?s:n}function bo(e,t,n){return en?n:e}function O1(e,t,n,r){let i=Xr(e),s="",a=n;for(let o of e.lines){let c=!0;for(let l of o){if(l.icon!==void 0)continue;let u=_r(l.style&~i);s+=`${rt(l.text)}`,c=!1}a+=e.lineHeight}return s===""?"":`${s}`}function D1(e,t,n,r){let i=typeof t=="number"&&Number.isFinite(t)?t:kL(e,n,r,1,1e6);return bo(i,200,1e4)-2*CL}function v1(e,t,n){let r=D1(t,e.size?.width,"width",900);return ms(n,r,160,(i,s)=>$L(e,t,n,i,r,s))}function $L(e,t,n,r,i,s){let a=n.fontSize??16,o=Math.round(a*.8125),c=Math.round(a*.6875),l=n.measurer??ct(n.fontFamily,n.fontFamilyMono),u=n.padding??8,h=D1(t,e.size?.height,"height",600)*Math.max(.75,r/i),d=t["wardley-beta"]?.showGrid===!0,m=0,p=0,y=r,E=h,b=(V,X,le,de)=>{Vy&&(y=le),de>E&&(E=de)},S=(V,X,le,de)=>(b(X-V.width/2,le-V.height/2,X+V.width/2,le+V.height/2),Ne(V,X,le,de,n.icons)),x=(V,X,le,de)=>(b(X,le-V.size,X+V.width,le-V.size+V.height+4),O1(V,X,le,de)),I=(V,X,le=s?Math.max(64,Math.min(120,r/2)):4e3,de=0)=>Ge(V,!1,l,X,le,de),L=V=>V/100*r,O=V=>h-V/100*h,v=e.axes.stages&&e.axes.stages.length>0?e.axes.stages:ML,G=e.axes.stageBoundaries,K=G!==void 0&&G.length===v.length,C="",Z="",oe=h,H=0;if(v.forEach((V,X)=>{let le=K?H:X/v.length,de=K?bo(G[X],0,1):(X+1)/v.length;H=de,X>0&&(C+=``);let Se=I(V,o,Math.max(48,Math.abs(de-le)*r-12));Z+=S(Se,(le+de)/2*r,h+8+Se.height/2,` class="pele-wardley-stage-label" font-size="${o}" fill="var(--_m)"`),oe=Math.max(oe,h+8+Se.height)}),d)for(let V=1;V<4;V++)C+=``;C+=``;let z=I(e.axes.xLabel??"Evolution",o),M=I(e.axes.yLabel??"Visibility",o),T=` class="pele-wardley-axis-label" font-size="${o}" font-weight="var(--_hw)"`,R=S(z,r/2,oe+6+z.height/2,T)+Ne(M,-16,h/2,`${T} transform="rotate(-90 -16 ${f(h/2)})"`);b(-16-M.height/2,0,0,0);let _=oe+6+z.height+10,$=new Map;for(let V of e.nodes)$.set(V.id,{x:L(V.x),y:O(V.y),node:V});let g="",N=new Map;for(let V of e.pipelines){N.set(V.nodeId,new Set(V.componentIds));let X=[];for(let Me of V.componentIds){let Ce=$.get(Me);Ce&&X.push(Ce)}if(X.length===0)continue;X.sort((Me,Ce)=>Me.x-Ce.x);let le=X[0].x,de=X[X.length-1].x,Se=X[0].y,_e=Se-2*Gt,xe=$.get(V.nodeId);xe&&(xe.x=(le+de)/2,xe.y=_e-_i/6),b(le-qd,_e,de+qd,_e+4*Gt),g+=``+(X.length>1?``:"")+""}let w=new Map,A=(V,X,le)=>{let de=V.node;if(de.className==="anchor"){let Se=w.get(de);return Se||w.set(de,Se=I(de.label,o,s?Math.max(64,r/2):4e3,1)),1/Math.hypot(X/(Se.width/2+5),le/(o*.8))}return de.isPipelineParent?_i/Math.SQRT2:de.sourceStrategy?2*Gt:Gt},D=new Map,U=(V,X,le)=>{Math.abs(X)<.25||Math.abs(le)<.25||D.set(V,(D.get(V)??0)|(X>0?le<0?1:2:le<0?4:8))},B="";for(let V of e.links){let X=$.get(V.source),le=$.get(V.target);if(!X||!le||X===le||N.get(V.target)?.has(V.source))continue;let de=le.x-X.x,Se=le.y-X.y,_e=Math.hypot(de,Se);if(_e<.01)continue;let xe=de/_e,Me=Se/_e,Ce=A(X,xe,Me),ke=A(le,xe,Me);if(Ce+ke>=_e)continue;U(X,xe,Me),U(le,-xe,-Me);let be=X.x+xe*Ce,Ae=X.y+Me*Ce,ie=le.x-xe*ke,me=le.y-Me*ke,Te="";(V.flow==="forward"||V.flow==="bidirectional")&&(Te+=_t("arrow_point",ie,me,xe,Me,Vn),ie-=xe*Rt("arrow_point"),me-=Me*Rt("arrow_point")),(V.flow==="backward"||V.flow==="bidirectional")&&(Te+=_t("arrow_point",be,Ae,-xe,-Me,Vn),be+=xe*Rt("arrow_point"),Ae+=Me*Rt("arrow_point"));let ye="";if(V.label){let we=I(V.label,c+1,200),Ie=xe>=0?1:-1,ve=Me*Ie,Pe=-xe*Ie,he=5+Math.abs(ve)*we.width/2+Math.abs(Pe)*we.height/2;ye=S(we,(X.x+le.x)/2+ve*he,(X.y+le.y)/2+Pe*he,` class="pele-edge-label" font-size="${c+1}" fill="var(--_m)"`)}B+=``+Te+ye+""}let F="";for(let V of e.trends){let X=$.get(V.nodeId);if(!X)continue;let le=L(V.targetX),de=O(V.targetY),Se=le-X.x,_e=de-X.y,xe=Math.hypot(Se,_e),Me="",Ce=xe>0?A(X,Se/xe,_e/xe):0;if(xe>Ce+Gt+4){let ke=Se/xe,be=_e/xe,Ae=le-ke*(Gt+2),ie=de-be*(Gt+2);Me=``+_t("arrow_point",Ae,ie,ke,be,jp)}b(le-Gt,de-Gt,le+Gt,de+Gt),F+=`${Me}`}let W="",j=1.2*Gt,Q=.7*Gt;for(let V of $.values()){let X=V.node,{x:le,y:de}=V,Se=X.className==="anchor",_e=X.sourceStrategy,xe="";if(_e){let be=_e==="outsource"?"var(--_m)":_e==="buy"?"var(--_a)":_e==="build"?"var(--_s)":"var(--_bg)";xe+=``}if(_e==="market"){let be=j*Math.cos(Math.PI/6),Ae=de+j*Math.sin(Math.PI/6);xe+=``;for(let[ie,me]of[[le,de-j],[le-be,Ae],[le+be,Ae]])xe+=``}else X.isPipelineParent?xe+=``:Se||(xe+=``);if(X.inertia===!0){let be=(X.isPipelineParent?_i/2:Gt)+10+(_e?Gt+4:0);xe+=``}let Me=X.labelOffsetX===void 0?void 0:bo(X.labelOffsetX,-5e3,5e3),Ce=X.labelOffsetY===void 0?void 0:bo(X.labelOffsetY,-5e3,5e3),ke;if(Se){let be=w.get(X)??I(X.label,o,s?Math.max(64,r/2):4e3,1);ke=S(be,le+(Me??0),de+(Ce??-3),` class="pele-label" font-size="${o}" font-weight="var(--_hw)"`)}else{let be=I(X.label,o),Ae=` class="pele-label" font-size="${o}"`,ie=NL+(_e?10:0);if(Me!==void 0||Ce!==void 0)ke=x(be,le+(Me??ie),de+(Ce??-ie),Ae);else if(X.inPipeline)ke=S(be,le,de+2*Gt+4+be.height/2,Ae);else{let me=D.get(V)??0,Te=(me&1)===0?1:(me&2)===0?2:(me&4)===0?4:(me&8)===0?8:1,ye=Te===1||Te===2,we=Te===1||Te===4;ke=x(be,ye?le+ie:le-ie-be.width,we?de-ie:de+ie+o*.75,Ae)}}b(le-2*Gt,de-2*Gt,le+2*Gt+20,de+2*Gt),W+=`${xe}${ke}`}let Y="";for(let V of e.annotations){let X=I(String(V.number),c,4e3,1),le="";for(let de of V.coordinates){let Se=L(de.x),_e=O(de.y),xe=Math.max(10,X.width/2+4);b(Se-xe,_e-xe,Se+xe,_e+xe),le+=``+Ne(X,Se,_e,` font-size="${c}" font-weight="var(--_hw)"`)}Y+=`${le}`}let ne=e.annotations.filter(V=>V.text).sort((V,X)=>V.number-X.number);if(ne.length>0){let V=ne.map(Ce=>I(`${Ce.number}. ${Ce.text}`,o,s?Math.max(80,r-20):320)),X=0,le=0;for(let Ce of V)X=Math.max(X,Ce.width),le+=Ce.height;X+=20,le+=14;let de=e.annotationsBox,Se=de?bo(L(de.x),0,Math.max(0,r-X)):0,_e=de?bo(O(de.y),0,Math.max(0,h-le)):_;b(Se,_e,Se+X,_e+le);let xe="",Me=_e+7;for(let Ce of V)xe+=O1(Ce,Se+10,Me+Ce.lineHeight/2+o*.35,` font-size="${o}"`),Me+=Ce.height;Y+=`${xe}`}let q="";for(let V of e.notes)q+=x(I(V.text,o,Math.min(360,r*.6),1),L(V.x),O(V.y),` class="pele-wardley-note" font-size="${o}" font-weight="var(--_hw)"`);let k="",J=(V,X,le,de)=>{let Se=L(X),_e=O(le),xe=IL/2,Me=de?Se+Ka:Se,Ce=de?Se:Se+Ka,ke=de?Se+Ka-L1:Se+L1,be=`M${f(Ce)},${f(_e-xe)}H${f(ke)}V${f(_e-xe-8)}L${f(Me)},${f(_e)}L${f(ke)},${f(_e+xe+8)}V${f(_e+xe)}H${f(Ce)}Z`;b(Se,_e-xe-8,Se+Ka,_e+xe+8),k+=``+S(I(V,c+1,160,1),Se+Ka/2,_e+xe+8+12,` font-size="${c+1}" font-weight="var(--_hw)"`)+""};for(let V of e.accelerators)J(V.name,V.x,V.y,!0);for(let V of e.deaccelerators)J(V.name,V.x,V.y,!1);let te=Ge(e.title,!1,l,a,s?Math.max(80,r):4e3,1),se=te.height>0?te.height+12:0,re=Math.min(m,r/2-te.width/2),P=Math.max(y,r/2+te.width/2),ee=u-re,ae=u+se-p,ue=Math.ceil(P-re+2*u),ce=Math.ceil(E-p+se+2*u),pe=Ne(te,ee+r/2,u+te.height/2,' class="pele-title" font-weight="var(--_tw)"')+`${C}`+Z+R+g+(B?`${B}`:"")+(F?`${F}`:"")+W+Y+q+k+"";return{svg:at("wardley",ue,ce,a,n,e,pe),width:ue,height:ce,links:[]}}var P1={type:"wardley",section:"wardley-beta",parse:(e,t,n)=>M1($1(e),n),render:v1};var Qd=class{constructor(){fe(this,"type","xychart");fe(this,"title");fe(this,"accTitle");fe(this,"accDescr");fe(this,"orientation");fe(this,"xAxis",{type:"band",title:"",categories:[]});fe(this,"yAxis",{type:"linear",title:"",min:1/0,max:-1/0});fe(this,"hasSetXAxis",!1);fe(this,"hasSetYAxis",!1);fe(this,"plots",[])}setOrientation(t){this.orientation=t==="horizontal"?"horizontal":"vertical"}setXAxisTitle(t){this.xAxis.title=t.text.trim()}setXAxisRangeData(t,n){this.xAxis={type:"linear",title:this.xAxis.title,min:t,max:n},this.hasSetXAxis=!0}setXAxisBand(t){this.xAxis={type:"band",title:this.xAxis.title,categories:t.map(n=>n.text.trim())},this.hasSetXAxis=!0}setYAxisTitle(t){this.yAxis.title=t.text.trim()}setYAxisRangeData(t,n){this.yAxis={type:"linear",title:this.yAxis.title,min:t,max:n},this.hasSetYAxis=!0}plotData(t){if(t.length===0)return[];this.hasSetXAxis||this.setXAxisRangeData(1,t.length);let n=this.xAxis;if(n.type==="band"&&t.length>n.categories.length&&(t=t.slice(0,n.categories.length)),!this.hasSetYAxis){let{min:i,max:s}=this.yAxis;for(let a of t)as&&(s=a);this.yAxis={type:"linear",title:this.yAxis.title,min:i,max:s}}if(n.type==="band")return n.categories.map((i,s)=>[i,t[s]]);if(t.length===1)return[[`${n.min}`,t[0]]];let r=(n.max-n.min)/(t.length-1);return t.map((i,s)=>[`${n.min+s*r}`,i])}addPlot(t,n,r){let i={type:t,title:n.text.trim(),data:this.plotData(r.map(s=>s.value))};t==="line"&&r.some(s=>s.label.trim()!=="")&&(i.pointLabels=r.map(s=>s.label.trim())),this.plots.push(i)}setLineData(t,n){this.addPlot("line",t,n)}setBarData(t,n){this.addPlot("bar",t,n)}setDiagramTitle(t){this.title=t}setAccTitle(t){this.accTitle=t.replace(/^\s+/g,"")}setAccDescription(t){this.accDescr=t.replace(/\n\s+/g,` +`)}};var Xp=["$end","INVALID","NEWLINE","title","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","XYCHART","CHART_ORIENTATION","X_AXIS","Y_AXIS","ARROW_DELIMITER","LINE","BAR","NUMBER_WITH_DECIMAL","SQUARE_BRACES_START","SQUARE_BRACES_END","STR","ALPHA","COLON","PLUS","COMMA","EQUALS","MULT","BRKT","UNDERSCORE","DOT","AMP","MINUS","NUM","SEMI","EOF"];var F1=[33,33,33,33,33,19,5,7,8],B1="`)"+" ".repeat(36)+'{ this.pushstate(md_string); }\n(?:(?!`").)+'+" ".repeat(18)+"{ return md_str; }\n(?:`",qp=new Uint8Array(128);for(let[e,t]of[[":",21],["+",22],[",",23],["=",24],["*",25],["#",26],["_",27],[".",28],["&",29],["-",30],[";",32]])qp[e.charCodeAt(0)]=t;function W1(e){let t=e.length,n=[],r=[],i=[],s=[],a=0,o=0,c=(y,E,b)=>{n.push(y),r.push(e.slice(E,b)),i.push(E),o=b},l=y=>{s.push(a),a=y},u=()=>{s.length>0&&(a=s.pop())},h=y=>{let E=e.indexOf(` +`,y);return E===-1?t:E},d=y=>{for(;y{for(;xt(e.charCodeAt(y));)y++;return y},p=y=>pn(e,o,y)&&!ot(e.charCodeAt(o+y.length));for(;o{let m=n[s];throw m===1?ft("xychart",e,i[s],"",!0):ft("xychart",e,i[s],`Expecting ${d}, got '${Xp[m]}'`)},o=d=>(n[s]!==d&&a(`'${Xp[d]}'`),r[s++]),c=d=>d===19||U1[d]===1,l=()=>{c(n[s])||a("'STR', 'ALPHA', 'NUM'");let d=r[s++];if(n[s-1]!==19)for(;U1[n[s]]===1;)d+=r[s++];return{text:d,type:"text"}},u=()=>{let d=Number(o(16));return o(13),[d,Number(o(16))]},h=()=>{let d=[];for(o(17);;){let m=Number(o(16));if(d.push({value:m,label:n[s]===19?r[s++]:""}),n[s]!==23)break;s++}return o(18),d};for(;;)if(G1[n[s]]===1)s++;else{if(n[s]!==9)break;n[++s]===10&&t.setOrientation(r[s++])}for(;n[s]!==0;){let d=n[s++];switch(d){case 3:t.setDiagramTitle(l().text.trim());break;case 11:case 12:{let m=c(n[s])?l():void 0;if(d===11&&n[s]===17){let p=[];do s++,p.push(l());while(n[s]===23);o(18),t.setXAxisBand(p)}else if(n[s]===16||m===void 0){let[p,y]=u();d===11?t.setXAxisRangeData(p,y):t.setYAxisRangeData(p,y)}d===11?t.setXAxisTitle(m??{type:"text",text:""}):t.setYAxisTitle(m??{type:"text",text:""});break}case 14:case 15:{let m=n[s]===17?{text:"",type:"text"}:l(),p=h();d===14?t.setLineData(m,p):t.setBarData(m,p);break}case 4:t.setAccTitle(o(5).trim());break;case 6:t.setAccDescription(o(7).trim());break;case 8:t.setAccDescription(r[s-1].trim());break;default:s--,a("'title', 'X_AXIS', 'Y_AXIS', 'LINE', 'BAR', 'acc_title', 'acc_descr', 'acc_descr_multiline_value'")}for(;G1[n[s]]===1;)s++}}function Qp(e,t){let n=e/Math.max(t,1),r=Math.floor(Math.log10(n)),i=n/10**r,s=i>=7.07?10:i>=3.16?5:i>=1.41?2:1;return r<0?-(10**-r)/s:s*10**r}function za(e,t){return e>0?t/e:t*-e}function yo(e,t){return e>0?t*e:t/-e}function Zp(e,t,n){let r=Math.round(za(n,e));yo(n,r)t&&i--;let s=[];for(let a=r;a<=i&&s.length<100;a++)s.push(yo(n,a));return s}var K1=4,Eo=12,z1=26,V1=24,j1=1e300;function Jp(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{}}function ir(e,t,n=!0){let r=e[t];return typeof r=="boolean"?r:n}function X1(e,t){return typeof e=="number"&&e>0?Math.round(Math.min(Math.max(e,100),4e3)):t}function Bs(e){return typeof e=="number"&&isFinite(e)?Math.min(Math.max(e,-j1),j1):void 0}function LL(e){let t=0;for(let n of e)t=Math.max(t,n.label.width);return t}function Zd(e,t,n,r){let i=e.lines.length===1?e.lines[0]:void 0;return i&&i.length===1&&i[0].icon===void 0&&i[0].style===0?`${rt(i[0].text)}`:Ne(e,t+(r==="start"?e.width/2:r==="end"?-e.width/2:0),n,"")}function q1(e,t,n){if(e.plots.length===0)throw new Qe("No Plot to render, please provide a plot with some data","semantic",{type:"xychart"});let r=Jp(t.xyChart),i=n.fontSize??16,s=Math.round(i*.875),a=Math.round(i*.75),o=n.measurer??ct(n.fontFamily,n.fontFamilyMono),c=n.padding??8,l=X1(r.width,700),u=gs(n,l,240),h=Math.round(X1(r.height,500)*Math.max(.6,u/l)),d=(e.orientation??r.chartOrientation)==="horizontal",m=ir(r,"showDataLabel",!1),p=e.xAxis,y=e.plots,E=($e,Ze,tt)=>Ge($e,!1,o,Ze,tt),b=E("0",s,4e3).height,S=E("0",a,4e3).height,x=Ge(ir(r,"showTitle")?e.title:void 0,!1,o,i,u-2*c,1),I=x.height>0?x.height+12:0,L=[],O=0;ir(r,"showLegend")&&y.forEach(($e,Ze)=>{if($e.title==="")return;let tt=E($e.title,s,u*.3);L.push({index:Ze,label:tt}),O=Math.max(O,tt.width+Eo+8)});let v=L.length>0?O+V1:0,G=y.filter($e=>$e.type==="bar").length,K=Bs(e.yAxis.min)??1/0,C=Bs(e.yAxis.max)??-1/0,Z=e.hasSetYAxis&&isFinite(K)&&isFinite(C)&&K!==C;if(!Z){K=1/0,C=-1/0;for(let $e of y)for(let[,Ze]of $e.data){let tt=Bs(Ze);tt!==void 0&&(ttC&&(C=tt))}K>C&&(K=C=0),G>0&&(K=Math.min(K,0),C=Math.max(C,0)),K===C&&(K===0?C=1:(K-=Math.abs(K)/2,C+=Math.abs(C)/2))}let oe=($e,Ze)=>{let tt=Qp(Math.abs(C-K),Math.max(2,Math.min(10,Math.floor($e/Ze))));return Z||(K=yo(tt,Math.floor(za(tt,K)+1e-9)),C=yo(tt,Math.ceil(za(tt,C)-1e-9))),Zp(Math.min(K,C),Math.max(K,C),tt).map(mt=>({at:(mt-K)/(C-K),label:E(String(mt),s,4e3)}))},H=1;if(p.type==="band")H=Math.max(p.categories.length,1);else for(let $e of y)H=Math.max(H,$e.data.length);let z=1/H,M=p.type==="band"||G>0?z/2:0,T=Bs(p.type==="linear"?p.min:void 0),R=Bs(p.type==="linear"?p.max:void 0),_=T!==void 0&&R!==void 0&&T!==R,$=($e,Ze)=>p.type==="band"?($e+.5)*z:M+(Ze>1?$e/(Ze-1):_?0:.5)*(1-2*M),g=Jp(r.xAxis),N=Jp(r.yAxis),w=d?g:N,A=d?N:g,D=E(ir(w,"showTitle")?d?p.title:e.yAxis.title:void 0,s,h*.8),U=E(ir(A,"showTitle")?d?e.yAxis.title:p.title:void 0,s,u*.8),B=ir(w,"showTick")?K1:0,F=ir(A,"showTick")?K1:0,W=ir(w,"showLabel"),j=ir(A,"showLabel"),Q=d?u*.3:Math.max(48,(u-2*c-64-v)*z-8),Y=p.type==="band"&&ir(g,"showLabel")?p.categories.map($e=>E($e,s,Q)):[],ne=0,q=0;for(let $e of Y)ne=Math.max(ne,$e.width),q=Math.max(q,$e.height);let k=$e=>{let Ze=[];if(p.type==="band"){let tt=Y.length===0?8:d?q:ne+12,mt=Math.max(1,Math.ceil(tt/($e*z)));for(let dt=0;dt0?se+4:0)+(U.height>0?U.height+4:0),P=d?0:J>0||m?S+4:W?b/2:0,ee=c+I+P,ae=Math.max(1,h-c-re-ee),ue=ee+ae,ce=d?k(ae):oe(ae,56),pe=W?LL(ce):0,V=c+(D.height>0?D.height+6:0)+(pe>0?pe+6:0)+B,X=Math.max(J>0?J+12:0,te>0?te+8:0),le=d?Math.min(u*.25,X):0,de=Math.max(1,u-c-V-v-le),Se=d?oe(de,80):k(de);if(j&&v+le===0){let $e=0;for(let Ze of Se)$e=Math.max($e,Ze.at*de+Ze.label.width/2-de);de=Math.max(1,de-$e)}let _e=V+de,xe=($e,Ze)=>d?V+Ze*de:V+$e*de,Me=($e,Ze)=>d?ee+$e*ae:ue-Ze*ae,Ce=$e=>($e-K)/(C-K),ke=$e=>Math.min(Math.max($e,0),1),be=$e=>d?`M${f(xe(0,$e))},${f(ee)}V${f(ue)}`:`M${f(V)},${f(Me(0,$e))}H${f(_e)}`,Ae="";for(let $e of d?Se:ce)Ae+=be($e.at);let ie="",me="";ir(w,"showAxisLine")&&(ie+=`M${f(V)},${f(ee)}V${f(ue)}`),ir(A,"showAxisLine")&&(ie+=`M${f(V)},${f(ue)}H${f(_e)}`);for(let $e of ce){let Ze=d?ee+$e.at*ae:ue-$e.at*ae;B&&(ie+=`M${f(V)},${f(Ze)}h${-B}`),W&&(me+=Zd($e.label,V-B-6,Ze,"end"))}for(let $e of Se){let Ze=V+$e.at*de;F&&(ie+=`M${f(Ze)},${f(ue)}v${F}`),j&&(me+=Zd($e.label,Ze,ue+F+4+$e.label.height/2,"middle"))}let Te=(d?ae:de)*z,we=Te*.7/Math.max(G,1),Ie=G>1?Math.min(2,we*.2):0,ve=ke(Ce(0));G>0&&ve>0&&ve<1&&(ie+=be(ve));let Pe="",he="",Re="",Be="",ge=0;y.forEach(($e,Ze)=>{let tt=Et(Ze),mt=$e.title?` data-id="${Ue($e.title)}"`:"",dt=p.type==="band"?Math.min($e.data.length,H):$e.data.length;if($e.type==="bar"){let et=(ge++-(G-1)/2)*we-(we-Ie)/2,Ye="";for(let He=0;He`,!m)continue;let Ft=String(nt),jn=o.width(Ft,a,0),En=wt>=ve?1:-1,Sr=pt+yt/2,an=gt+Nt/2,cn="middle";if(d){if(Nt0?pt+yt:pt)+En*6,cn=En>0?"start":"end"}else{if(jn+2>Te/G)continue;an=(En>0?gt:gt+Nt)-En*(S/2+2)}Re+=`${Ft}`}Pe+=`${Ye}`;return}let Ee="",We="",De=!1,Xe=0,ze=NaN;for(let et=0;et=0&&nt<=1;if(ze!==ze)it&&(Ee+=`M${f(xe(He,nt))},${f(Me(He,nt))}`),De=it;else{let pt=nt-ze,gt=0,yt=1;if(pt!==0){let Nt=-ze/pt,Ft=(1-ze)/pt;gt=Math.max(gt,Math.min(Nt,Ft)),yt=Math.min(yt,Math.max(Nt,Ft))}else it||(gt=2);if(gt<=yt){let Nt=Xe+(He-Xe)*gt,Ft=ze+pt*gt,jn=Xe+(He-Xe)*yt,En=ze+pt*yt;(!De||gt>0)&&(Ee+=`M${f(xe(Nt,Ft))},${f(Me(Nt,Ft))}`),Ee+=`L${f(xe(jn,En))},${f(Me(jn,En))}`}De=it}if(Xe=He,ze=nt,!it)continue;let wt=xe(He,nt),ut=Me(He,nt);Te>=12&&(We+=``);let st=E($e.pointLabels?.[et],a,4e3);if(st.height>0){let pt=st.width/2;Be+=d?Zd(st,wt+10,ut,"start"):Zd(st,Math.max(Math.min(wt,_e-pt),V+pt),ut-6-st.height/2,"middle")}}he+=``+(Ee?``:"")+We+""});let Le="";D.height>0&&(Le+=`${Ne(D,0,0,"")}`),Le+=Ne(U,V+de/2,h-c-U.height/2,"");let Fe="",Ve=0;for(let $e of L)Ve+=Math.max(z1,$e.label.height+6);let Oe=ee+Math.max(0,(ae-Ve)/2),je=_e+le+V1;for(let{index:$e,label:Ze}of L){let tt=Math.max(z1,Ze.height+6);if(Oe+tt>h)break;let mt=Oe+tt/2,dt=Et($e);Fe+=``+(y[$e].type==="bar"?``:``)+Ne(Ze,je+Eo+8+Ze.width/2,mt,"")+"",Oe+=tt}let Je=Ne(x,u/2,c+x.height/2,' class="pele-title" font-weight="var(--_tw)"')+(Ae?``:"")+`${Pe}${he}`+(ie?``:"")+(me?`${me}`:"")+(Le?`${Le}`:"")+(Re?`${Re}`:"")+(Be?`${Be}`:"")+(Fe?`${Fe}`:"");return{svg:at("xychart",u,h,i,n,e,Je),width:u,height:h,links:[]}}var Q1={type:"xychart",section:"xyChart",parse(e,t,n){let r=new Qd;return r.title=n,H1(e,r),r},render:q1};var Z1=[yl,L0,Oy,A0,f0,ZA,o0,ry,H0,Q1,DA,CE,lb,Ux,Jx,T0,nx,RS,zE,SA,WE,Hb,Mb,Cx,jg,hS,by,P1,Ky,b1,_1,JE,HA];wu(...Z1);return iw(OL);})(); diff --git a/skills/explain-pr-as-video/assets/runtime.js b/skills/explain-pr-as-video/assets/runtime.js new file mode 100644 index 0000000..8d15b36 --- /dev/null +++ b/skills/explain-pr-as-video/assets/runtime.js @@ -0,0 +1,557 @@ +// Deck runtime: turns window.TIMELINE (written by render.mjs) into a pure function of time. +// Every visual state is computed from t in seek(t), so the renderer can capture any frame in any order. +// CSS transitions and animations never render; animate with the data attributes below instead. +// +//
one scene per voiced scene id +// data-in="cue" | "cue+0.4" | "@1.2" when the element enters: a cue's first word, plus an offset, +// or seconds after the scene starts (default "@0.2") +// data-anim="rise|fade|pop|left|wipe|draw|type|count|none" how it enters (default rise) +// data-dur="0.6" enter length in seconds +// data-count="20" target number for data-anim="count" +// data-out="cue" fades out when that cue starts +// data-focus="cueA cueB" lit while one of those cues is spoken; while any element in the +// scene is lit, the scene's other data-focus elements dim +// data-camera="cue:scale,x,y; cue2:..." on a scene's .stage: eases the camera there when the cue starts +// data-to="cue:left,top[,width]; ..." moves an absolutely placed element to a new place on a cue +// data-travel="pathId" a .token rides that SVG path from data-in for data-dur seconds, +// then parks at its end (path and token share a positioned parent) +// data-strike="cue" strikes the element through when the cue starts +// data-link="#from -> #to" on an SVG path: drawn from the right edge of #from to the left edge +// of #to (or the reverse when #to is on the left), wherever layout put them +// class="wire stream" once drawn, dashes keep flowing along the wire +// marker-end="url(#arrow)" on a wire any marker-end becomes the chevron in the wire's color, with a source dot +// data-on="wireId" on a .tag the tag becomes a pill centered on that wire +//
                 any Mermaid diagram, drawn by Pele; see layoutMermaid below
+//   
                   a sequence diagram laid out from text; see layoutLanes below
+//   .track data-span="0 24"               a time axis: children with data-t="2" (and data-t2="7" for a span)
+//                                         are placed along it; data-sweep="cue:0; cue2:12" on a child moves it
+//                                         along the axis between those cues, at an even speed
+(() => {
+  const T = window.TIMELINE;
+  const RENDER = new URLSearchParams(location.search).has("render");
+  const clamp = (x) => (x < 0 ? 0 : x > 1 ? 1 : x);
+  const out3 = (p) => 1 - (1 - p) ** 3;
+  const inOut = (p) => (p < 0.5 ? 4 * p ** 3 : 1 - (-2 * p + 2) ** 3 / 2);
+  const back = (p) => 1 + 2.2 * (p - 1) ** 3 + 1.2 * (p - 1) ** 2;
+  const problems = [];
+  const sceneEls = [...document.querySelectorAll(".scene")];
+
+  // 
 holds one statement per line, the grammar PR bodies use for
+  // diagrams, plus cues:
+  //   node: Service worker @cue                       a lane, left to right in order
+  //   arrow: Offscreen -> Service worker "VOICE PIECE" @cue ~outcue .new   one row each, top to bottom
+  //   frame: loop "[each 5 s piece]" 2-4 @cue        a box around arrows 2 to 4 (1-based)
+  //   token: "aria-label" 3 @cue                      a chip that rides arrow 3 when the cue starts
+  //   gap @cue                                         an empty row
+  // Anything after " | " (a path:line) is ignored. Arrows get ids 
-a for data-travel.
+  const esc = (x) => x.replace(/[&<>"]/g, (c) => `&#${c.charCodeAt(0)};`);
+  function layoutLanes(pre) {
+    const id = pre.id || `lanes${Math.random().toString(36).slice(2, 7)}`;
+    const W = pre.clientWidth || 1640, H = pre.clientHeight || 600;
+    const nodes = [], rows = [], frames = [], tokens = [];
+    for (let line of pre.textContent.split("\n")) {
+      line = line.replace(/\s+\|\s+\S+$/, "").trim();
+      const at = line.match(/\s@([\w+.@-]+)/)?.[1], out = line.match(/\s~([\w+.-]+)/)?.[1];
+      const cls = [...line.matchAll(/\s\.([\w-]+)/g)].map((m) => m[1]).join(" ");
+      const label = line.match(/"([^"]*)"/)?.[1] ?? ""; // labels cannot contain double quotes; use ' instead
+      let m;
+      if ((m = line.match(/^node:\s*(.+?)(\s+[@~.]|$)/))) nodes.push({ name: m[1].trim(), at, cls });
+      else if ((m = line.match(/^arrow:\s*(.+?)\s*->\s*(.+?)(\s+["@~.]|$)/))) rows.push({ from: m[1].trim(), to: m[2].trim(), label, at, out, cls });
+      else if (/^gap\b/.test(line)) rows.push({ gap: true });
+      else if ((m = line.match(/^frame:\s*(\w+)\s*"[^"]*"\s*(\d+)-(\d+)/))) frames.push({ kind: m[1], label, a: +m[2], b: +m[3], at, out });
+      else if ((m = line.match(/^token:\s*"[^"]*"\s*(\d+)/))) tokens.push({ label, n: +m[1], at, cls });
+    }
+    const x = (name) => {
+      const i = nodes.findIndex((n) => n.name === name);
+      if (i < 0) problems.push(`lanes ${id}: arrow names unknown node "${name}"`);
+      return (W * (Math.max(i, 0) + 0.5)) / nodes.length;
+    };
+    const headH = 92, top = headH + 70, step = Math.min(96, (H - top - 30) / Math.max(rows.length - 0.5, 1));
+    if (step < 62) problems.push(`lanes ${id}: ${rows.length} rows need about ${Math.ceil(top + 62 * rows.length)}px of height; give it more or split it`);
+    const colW = Math.min(W / nodes.length - 36, 380);
+    const attr = (o) => `${o.at ? ` data-in="${o.at}"` : ""}${o.out ? ` data-out="${o.out}"` : ""}`;
+    let svg = "", html = "", under = "";
+    nodes.forEach((n, i) => {
+      const cx = (W * (i + 0.5)) / nodes.length;
+      html += `

${esc(n.name)}

`; + svg += ``; + }); + const n0 = (k) => rows.slice(0, k).length; + rows.forEach((r, k) => { + if (r.gap) return; + const y = top + k * step, x1 = x(r.from), x2 = x(r.to), aid = `${id}-a${k + 1}`; + const d = x1 === x2 ? `M${x1} ${y - 22} h64 v34 h-56` : `M${x1 + Math.sign(x2 - x1) * 6} ${y} H${x2 - Math.sign(x2 - x1) * 10}`; + svg += ``; + const lx = x1 === x2 ? x1 + 84 : (x1 + x2) / 2; + html += `
${esc(r.label)}
`; + }); + for (const f of frames) { + const y1 = top + (f.a - 1) * step - step * 0.55, y2 = top + (f.b - 1) * step + step * 0.45; + under += `
${esc(f.kind)} ${esc(f.label)}
`; + } + for (const tk of tokens) { + html += `
${esc(tk.label)}
`; + } + const div = document.createElement("div"); + div.className = `lanes ${pre.className.replace("lanes", "")}`.trim(); + div.id = id; + div.style.cssText = pre.style.cssText; + for (const k of ["in", "out", "focus", "anim"]) if (pre.dataset[k]) div.dataset[k] = pre.dataset[k]; + div.innerHTML = ` + + + ${svg}${html}`; + div.insertAdjacentHTML("afterbegin", under); // frames sit under the wires + pre.replaceWith(div); + } + //
 is a Mermaid diagram, drawn by Pele (pele.js, loaded before this file).
+  // Cues ride along as Mermaid comments, so the source still renders anywhere Mermaid does:
+  //   %% R: in=chose focus=chose class=new          a node, by its Mermaid id (class: new, risk, ghost)
+  //   %% R->T: in=chose+0.8 class=new out=api       an edge (class: new, risk, mute); its path gets the id
+  //                                                 "rt-R-T", for a token's data-travel
+  function layoutMermaid(pre) {
+    if (!window.pele) return problems.push("a pre.mermaid needs 
+
+
+
+
+```
+
+The content area is x 140 to 1780 and y 130 to 960. The chapter rail sits below 960. Keep titles to one line, about 40 characters.
+
+## Timing attributes
+
+| Attribute | Meaning |
+| --- | --- |
+| `data-in="cue"` | Enter when the line with that `cue` starts. `cue+0.6` or `cue-0.3` shifts it. `@1.2` is seconds after the scene starts. Default `@0.2`. |
+| `data-anim` | `rise` (default), `fade`, `pop`, `left`, `wipe`, `draw` (SVG paths and lines stroke in; arrowheads land at the end), `type` (types the text, for terminal lines), `count` (counts the first number up to `data-count`), `none` (no entrance, for elements already on screen). |
+| `data-dur="0.6"` | Entrance length in seconds. `type` defaults to the text's length. |
+| `data-out="cue"` | Fades out when that line starts. |
+| `data-focus="a b"` | Lit while line `a` or `b` is spoken. While a line lights something, every other `data-focus` element in the scene dims. After the scene's last line the focus releases. |
+| `data-camera="cue:scale,x,y; cue2:1,0,0"` | On a `.stage`: eases the view to that zoom and offset when the line starts. Return to `1,0,0` before the scene ends. |
+
+Time the entrance a beat after the word that names the thing: `data-in="cue+1.2"` when the noun comes mid-line. Check with `render.mjs --at `.
+
+## Color keeps one meaning
+
+The theme has three states, and color means nothing else:
+
+| State | Looks | Use for |
+| --- | --- | --- |
+| default | ink on white, hairline border | what exists and stays as it is |
+| `.new` | solid lime | what this change adds or chose |
+| `.risk` | accent border or text | what goes wrong, or a risk left over |
+| `.mute` (`.ghost` on boxes) | grey, dashed | the old way, the road not taken |
+
+A title's `` gets a lilac marker: emphasis on the key words, not a fourth meaning. Never set a color, background or fill in the deck; `--stills` reports any inline color. Keep the accent rare: the problem in the why scene, the cost of each decision, the gap in the proof. Focus uses the same lilac: what the voice is on gets a flush lilac halo (a card, a box, a node) or a lilac fill (a decision column) and full ink, and the rest of the scene dims. It never competes with the accent.
+
+## Components (theme.css)
+
+- Type: `.kicker` (chapter eyebrow), `.title` (`.xl` for a hero; `em` for the one phrase that is the problem), `.label` (small caps heading inside a card), `.lede`, `.small`, `code` (only for things you would type or grep).
+- Layout: `.row`, `.col`, `.grow`, `.mt`, `.abs` (position with inline `left`/`top`).
+- `.card` with `h3` and `p`, in any state. `.chip` and `.step` (a box in a flow, with `.arrow` between) take the same states. `.num` is a numbered square. `ul.checks` lists verified facts with a check mark.
+- `.adr`: a decision as one card with a column per part: `div.chose`, `div.rejected`, `div.cost`, `div.checked` (a `ul` of findings, each with its `path:line` in a `code`). Each opens with a `.label`. Put `data-focus` on the column and `data-in` on a `div` around its body, so the four labels show from the start and each body arrives on the line that says it.
+- `.term`: a terminal; children `div.cmd` (prompt), `.err`, `.ok`, `.dim`. Use `data-anim="type"` on `.cmd` lines.
+- `.code`: a code card; `div.file` header, `div.ln` lines with `.add`, `.del`, `.hl`; spans `.c`, `.k`, `.s`.
+- Diagrams, inside `
`: `.box` (process or module; `.new`, `.risk`, `.ghost`), `.zone` with a `span` label, `.boundary` (a dashed divider; inline `left`, `top`, `height`), `.packet` (a JSON message; spans `.k`, `.s`, `.n`, `.err`), `.tag` (a label; `.new`, `.risk`, `.mute`), `.cross` (where something is lost). Wires go in `` as `path.wire` (`.new`, `.risk`, `.mute`) with `marker-end="url(#arrow)"`. +- A `.box` is a node card. In a system diagram give each one a kind and an icon: `…
Service worker

Routing

once, at start
`. The icon is a 24-grid outline icon pasted inline (Lucide, ISC, fits); keep only its `viewBox` and child elements, and the theme strokes it. The kind (`.eb`) says what sort of thing it is, so the title can stay a short name. One kind word per real thing: the same process gets the same kind in every scene. + +## A decision scene + +Title the scene with the decision in active voice. Above, the smallest picture that shows what the decision does, usually the shape diagram again. Below, the `.adr` card: + +```html +
+
ChosenFail with exit 13 and the details. Stop there.
+
RejectedFall back to screen capture on its own. The issue leaves that to the caller.
+
CostAn unattended agent recovers by itself.
+
We checked
  • No fallback exists in codescreencast.ts:279
+
+``` + +Arrowheads need no ``: the runtime gives every wire with a `marker-end` a chevron in the wire's color and a dot where it leaves its source. + +Label a wire with a pill on it, not text floating near it: `
on
` sits on the middle of the wire's longest straight run. Keep pill text to a word or a short value, so the pill fits the gap between two boxes. Leave columns about 170 px apart where wires carry pills. + +## A diagram from Mermaid + +Draw any box-and-wire picture (a system, a flow, states) as Mermaid in a `
` inside the `.stage`; Pele (`pele.js`) lays it out and the runtime animates it. Write cues as Mermaid comments, so the same source still renders on GitHub:
+
+```html
+
+flowchart LR
+  R["`**Routing**
+  once, at start`"] -- on --> T["`**Text path**
+  new renderer`"]
+  T -- mode --> O["`**Offscreen**
+  older build`"]
+%% R: in=chose focus=chose
+%% T: in=chose+0.8 focus="chose old" class=new
+%% O: in=old out=api focus=old class=risk
+%% R->T: in=chose+0.8 class=new
+%% T->O: in=old out=api
+
+
mode: pieces
+``` + +- A node's first line in `**bold**` is its name, the next line its `.sub`. +- `%% :` and `%% ->:` take `in`, `out`, `focus`, `anim`, `dur` and `class` (nodes `new`, `risk`, `ghost`; edges `new`, `risk`, `mute`). An edge draws itself and its label pill fades in after it. +- An edge's path id is `
--`, for a token's `data-travel`.
+- Mermaid's own `:::class`, `classDef` and `style` set colors; leave them out and use `class=` in a cue comment, so color keeps its meaning.
+- Prefer it to placing `.box`es by hand. Place by hand only what Mermaid cannot say: a box that changes text mid-scene, a note pinned to a node.
+
+## A sequence diagram from text
+
+For anything that is messages between parts (processes, services, workers), write a `
` instead of placing boxes. It reads a small `node:` / `arrow:` grammar, so a sequence diagram already written in a PR description usually pastes in and only needs cues:
+
+```html
+
+
+node: Recorder .new
+node: Worker
+node: Transcribe API .new
+node: Answer API
+arrow: Worker -> Recorder "START" @start .new
+arrow: Recorder -> Worker "AUDIO PIECE" @piece .new
+arrow: Worker -> Transcribe API "AUDIO" @tx .new
+arrow: Transcribe API -> Worker "TEXT" @tx+0.9 .new
+gap
+arrow: Worker -> Answer API "TEXT + VOICE" @answer .new
+frame: loop "[each 5 s piece]" 2-4 @piece+0.6
+token: "5 s audio" 3 @tx+0.1
+
+
+``` + +- `node:` adds a lane, left to right. `arrow: A -> B "LABEL"` adds a row, top to bottom; `A -> A` loops back. `gap` leaves a row empty. `frame: loop "[label]" 2-4` boxes arrows 2 to 4. `token: "label" 3` sends a chip along arrow 3. +- Each statement takes `@cue` (enter, with offsets like `@tx+0.9`), `~cue` (leave) and classes (`.new`, `.risk`, `.mute`). A trailing `| path:line` is ignored. Labels cannot contain `"`. +- Before and after on one stage: two `pre.lanes` in the same place, the first with `data-out="flag"`, the second with `data-in="flag" data-anim="fade"`. Lanes in the same position cross-fade, so a renamed or replaced part reads as a change, not a new picture. +- Keep it to 4 or 5 lanes and about 8 rows; `--stills` says when the rows need more height. + +## Time, pages and tables + +- **Time** goes on a track. `.track[data-span="0 14"]` holds `.tk-row` rows (a `b` label on the left), and any child with `data-t="2"` sits at 2 s; add `data-t2="7"` for a span. Inside it, `.tk-dot` (`.new`, `.risk`, `.mute`), `.tk-note`, `.tk-mark` (above the axis), `.tk-tick` (below) and `.tk-span` (a window or a bar). A `.playhead` with `data-sweep="cueA:0; cueB:7.5"` moves to that time as each cue starts, at an even speed, so the voice and the clock agree. Use it for windows, timeouts, retries and latency races. +- **A page** is `.browser` (absolutely placed) with `.bar` (the URL) and `.page` holding `h5`, `.field` (label text plus an `i` for the value), `.btn`, `.txt` and cards. Use it for the worked example's starting point; say on screen that the page is an illustration. +- **Rows that land** are a `table.rows` with a `caption`; give each `tr` a `data-in` so rows arrive as the voice names them. `tr.new` marks what the change adds, and `tr.mute` what it does not cover. + +## Motion that carries meaning + +- `data-travel=""` on a `.token` (inside the same positioned parent as the SVG): the token rides the path from `data-in` for `data-dur` seconds and parks at its end. Lanes arrows have ids `-a`. Use it for the one real datum the video follows: a click, a field's text, a request. +- `data-link="#from -> #to"` on an SVG `path` instead of `d`: the runtime draws the wire from the right edge of one element to the left edge of the other, wherever layout put them. Prefer it over hand-written coordinates for anything that points at text (a field, a button, a log line): a caption added later moves the text, and a hand-drawn wire then points at the wrong line. +- `data-to="cue:left,top[,width]; cue2:…"` on an absolutely placed element: it moves there on the cue. Use it so a part changes place or size instead of being redrawn. +- `data-strike="cue"`: a line sweeps through the element; for what is dropped or rejected. +- `class="wire stream"`: once drawn, the dashes keep flowing; for a continuous stream (a capture, a live socket), not for a one-off call. + +## A diagram that builds up + +```html +
+ + + +

CLI

what the agent runs
+

recorder

background process
+
spawns
+
+``` + +In the next scene, copy the same boxes and wires with `data-anim="none"` and give only the new parts an entrance. + +## Checklist before the full render + +- `render.mjs --stills` prints no problems. +- Every still reads at phone size: nothing overlaps, no text is cut, one highlighted phrase per title. +- Every scene with three or more parts uses `data-focus`, so the eye follows the voice. +- Motion was checked mid-flight, not only in the end-of-scene stills: `--at` frames during each token's ride and each move. +- Every colored element is `.new`, `.risk` or `.mute` for the reason the table above gives. +- Illustrative content (sample logs, example values) says so on screen. diff --git a/skills/explain-pr-as-video/references/share.md b/skills/explain-pr-as-video/references/share.md new file mode 100644 index 0000000..c2e9f22 --- /dev/null +++ b/skills/explain-pr-as-video/references/share.md @@ -0,0 +1,13 @@ +# Share the video as a Jam + +A Jam is a shareable jam.dev recording. Needs the Jam CLI signed in (`jam auth status`); if it is not, ask the user to run `jam auth login`. + +Write the payload with the text map from step 5 as the description, then create the Jam: + +```bash +jq -n --arg vp "$PWD/voiceover/voiced.mp4" --arg url "" --arg title "PR #: " --rawfile desc description.md \ + '{kind:"video", videoPath:$vp, url:$url, title:$title, description:$desc, micEnabled:true, screenDimensions:{width:1920,height:1080}}' > jam.json +jam create jam @jam.json --json | jq -r .url +``` + +`micEnabled` makes Jam transcribe the narration, so the Jam is searchable by what the video says. Return the link to the user; post it on the PR only when they ask. diff --git a/skills/explain-pr-as-video/scripts/ab.mjs b/skills/explain-pr-as-video/scripts/ab.mjs new file mode 100644 index 0000000..ab8ffcc --- /dev/null +++ b/skills/explain-pr-as-video/scripts/ab.mjs @@ -0,0 +1,268 @@ +#!/usr/bin/env node +// Compare rendered variants of a video, scene by scene, then build one deck from the scenes you picked. +// +// usage: node ab.mjs compare <variant-dir> <variant-dir>... [--out compare.html] +// node ab.mjs merge <picks.json> <out-dir> +// +// A variant is a work folder after a full render: deck.html, lines.json, timeline.js and voiceover/voiced.mp4. +// compare writes a page that plays any scene of any variant, switches variant mid-scene with the number keys, +// hides which is which in blind mode, and gives back picks.json. merge takes each scene's lines and +// <section> from the variant picked for it, on top of the first variant's deck, and copies the voiced +// lines so the merged script only voices what is new. +import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs"; +import { basename, dirname, join, relative, resolve } from "node:path"; +import { parseArgs } from "node:util"; + +const { values: opt, positionals: [mode, ...rest] } = parseArgs({ + allowPositionals: true, + options: { out: { type: "string", default: "compare.html" } }, +}); +const fail = (msg) => (console.error(msg), process.exit(2)); +const read = (file) => (existsSync(file) ? readFileSync(file, "utf8") : fail(`missing ${file}`)); +const sectionRe = /<section\b[^>]*\bdata-scene="([^"]+)"[\s\S]*?<\/section>/g; +const sections = (html) => new Map([...html.matchAll(sectionRe)].map((m) => [m[1], m[0]])); + +function variant(dir) { + dir = resolve(dir); + const timeline = JSON.parse(read(join(dir, "timeline.js")).replace(/^window\.TIMELINE = /, "").replace(/;\s*$/, "")); + const video = ["voiceover/voiced.mp4", "video.mp4"].map((f) => join(dir, f)).find(existsSync); + if (!video?.endsWith("voiced.mp4")) console.error(`${dir}: no voiceover/voiced.mp4, comparing ${video ? "the silent render" : "nothing"}`); + const lines = JSON.parse(read(join(dir, "lines.json"))); + return { name: basename(dir), dir, video, timeline, lines }; +} + +// Scene order: the first variant's, with any scene only another variant has placed after its predecessor there. +function sceneOrder(variants) { + const order = variants[0].timeline.scenes.map((s) => s.id); + for (const v of variants.slice(1)) { + let prev = -1; + for (const { id } of v.timeline.scenes) { + if (!order.includes(id)) order.splice(prev + 1, 0, id); + prev = order.indexOf(id); + } + } + return order; +} + +if (mode === "compare") { + if (rest.length < 2) fail("usage: node ab.mjs compare <variant-dir> <variant-dir>... [--out compare.html]"); + const out = resolve(opt.out); + const variants = rest.map(variant); + const data = { + variants: variants.map((v) => ({ + name: v.name, + dir: v.dir, + src: relative(dirname(out), v.video ?? ""), + duration: v.timeline.duration, + scenes: Object.fromEntries(v.timeline.scenes.map((s) => [s.id, { start: s.start, end: s.end, say: v.lines.filter((l) => l.scene === s.id).map((l) => l.say).join(" ") }])), + })), + order: sceneOrder(variants), + }; + writeFileSync(out, page(data)); + console.log(out); +} else if (mode === "merge") { + if (rest.length !== 2) fail("usage: node ab.mjs merge <picks.json> <out-dir>"); + const picks = JSON.parse(read(rest[0])); + const out = resolve(rest[1]); + const variants = picks.variants.map(variant); + const byName = new Map(variants.map((v) => [v.name, v])); + const base = variants[0]; + const baseDeck = read(join(base.dir, "deck.html")); + const decks = new Map(variants.map((v) => [v.name, v === base ? baseDeck : read(join(v.dir, "deck.html"))])); + + const lines = [], parts = []; + for (const id of sceneOrder(variants)) { + const pick = picks.scenes[id] === undefined ? (picks.whole ?? base.name) : picks.scenes[id]; + if (pick === null) continue; // the scene was cut + const v = byName.get(pick) ?? fail(`scene ${id}: no variant "${pick}"`); + const section = sections(decks.get(pick)).get(id) ?? fail(`scene ${id}: ${pick}/deck.html has no section for it`); + lines.push(...v.lines.filter((l) => l.scene === id).map(({ wav, seconds, at, ...l }) => l)); + parts.push(section); + } + + // The first variant's deck with its scenes swapped for the picked ones. Deck-only styles of other picked + // variants are appended; they share one page, so scope a variant's new CSS by its scene: [data-scene=why] .x + const used = new Set([picks.whole, ...Object.values(picks.scenes)].filter(Boolean)); + const styles = [...used].filter((n) => n !== base.name).flatMap((n) => decks.get(n).match(/<style>[\s\S]*?<\/style>/g) ?? []) + .filter((s) => !baseDeck.includes(s)); + const first = baseDeck.search(sectionRe); + let deck = baseDeck.replace(sectionRe, ""); + deck = deck.slice(0, first) + parts.join("\n\n ") + deck.slice(first); + deck = deck.replace("</head>", `${styles.join("\n")}\n</head>`); + + const generated = new Set(["deck.html", "lines.json", "timed.json", "timeline.js", "video.mp4", "stills", "sync", "voiceover", "compare.html"]); + mkdirSync(out, { recursive: true }); + for (const f of readdirSync(base.dir)) if (!generated.has(f)) cpSync(join(base.dir, f), join(out, f), { recursive: true }); + writeFileSync(join(out, "deck.html"), deck); + writeFileSync(join(out, "lines.json"), JSON.stringify(lines, null, 1)); + mkdirSync(join(out, "voiceover"), { recursive: true }); + for (const v of variants) { + const vo = join(v.dir, "voiceover"); + if (existsSync(vo)) for (const f of readdirSync(vo)) if (f.endsWith(".wav") && f !== "narration.wav") cpSync(join(vo, f), join(out, "voiceover", f)); + } + console.error(`merged ${parts.length} scenes, ${lines.length} lines into ${out}; voice, then render as usual`); + console.log(out); +} else { + fail("usage: node ab.mjs compare <variant-dir>... | node ab.mjs merge <picks.json> <out-dir>"); +} + +function page(data) { + return `<!doctype html> +<html lang="en"> +<head> +<meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1"> +<title>Compare variants + + + +
+
+ +
Pick a scenespace play/pause · 1–9 switch variant at the same point · ↑↓ scene
+
+ Whole video: + +
+ +
then: node ab.mjs merge picks.json merged
+
+
+
+ + + +`; +} diff --git a/skills/explain-pr-as-video/scripts/render.mjs b/skills/explain-pr-as-video/scripts/render.mjs new file mode 100644 index 0000000..19c9637 --- /dev/null +++ b/skills/explain-pr-as-video/scripts/render.mjs @@ -0,0 +1,206 @@ +#!/usr/bin/env node +// Render an HTML deck to a silent MP4, timed by voiced lines. +// +// usage: node render.mjs [--stills] [--at ] [--fps 30] [--jobs 4] +// +// is the lines.json add-voiceover writes after voicing: each line has "say", +// "seconds", a "scene" id and, optionally, a "cue" name and a "pause" in seconds before it. +// The script spaces the lines out, then writes, next to the deck: +// timeline.js the timing the deck's runtime reads, in the render and in the browser +// timed.json the same lines with "at" set, for add-voiceover's second pass with --video +// video.mp4 the silent render, 1920x1080 +// --stills writes stills/NN-.png, one per scene once it has fully built, instead of the video. +// --at writes one frame at that second to stills/at-.png. +// +// Needs Node 22+, ffmpeg and Chrome or Chromium (CHROME_PATH overrides the search). No npm packages. +import { spawn } from "node:child_process"; +import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { availableParallelism, tmpdir } from "node:os"; +import { dirname, join, resolve } from "node:path"; +import { pathToFileURL } from "node:url"; +import { parseArgs } from "node:util"; + +const { values: opt, positionals } = parseArgs({ + allowPositionals: true, + options: { + stills: { type: "boolean" }, + at: { type: "string" }, + fps: { type: "string", default: "30" }, + jobs: { type: "string", default: String(Math.max(1, Math.min(4, availableParallelism() >> 1))) }, + }, +}); +if (positionals.length !== 2) { + console.error("usage: node render.mjs [--stills] [--at ] [--fps 30] [--jobs 4]"); + process.exit(2); +} +const deck = resolve(positionals[0]); +const work = dirname(deck); +const fps = Number(opt.fps); +const W = 1920, H = 1080; +const LEAD = 0.8, GAP = 0.45, SCENE_GAP = 1.4, TAIL = 2.2; // seconds of air around the voice + +// Space the lines: a breath between lines, a longer one between scenes, plus any "pause" a line asks for. +const lines = JSON.parse(readFileSync(positionals[1], "utf8")); +let t = LEAD; +lines.forEach((line, i) => { + if (typeof line.seconds !== "number" || !line.scene) { + console.error(`line ${i + 1} needs "scene" and "seconds"; voice the lines with add-voiceover first`); + process.exit(2); + } + if (i && line.scene !== lines[i - 1].scene) t += SCENE_GAP; + t += line.pause ?? 0; + line.at = Math.round(t * 1000) / 1000; + t += line.seconds + GAP; +}); +const duration = Math.ceil((t - GAP + TAIL) * 10) / 10; +const scenes = []; +for (const line of lines) { + const last = scenes.at(-1); + if (last?.id === line.scene) continue; + if (scenes.some((s) => s.id === line.scene)) { + console.error(`scene "${line.scene}" comes back after another scene; keep each scene's lines together`); + process.exit(2); + } + scenes.push({ id: line.scene, start: last ? Math.max(0, line.at - SCENE_GAP / 2 - 0.15) : 0 }); +} +scenes.forEach((s, i) => (s.end = scenes[i + 1]?.start ?? duration)); +const timeline = { + duration, + scenes, + lines: lines.map(({ say, scene, cue, at, seconds }) => ({ say, scene, cue, at, seconds })), +}; +writeFileSync(join(work, "timeline.js"), `window.TIMELINE = ${JSON.stringify(timeline, null, 1)};\n`); +writeFileSync(join(work, "timed.json"), JSON.stringify(lines, null, 1)); +console.error(`timeline: ${scenes.length} scenes, ${lines.length} lines, ${duration} s`); + +// Chrome over --remote-debugging-pipe: JSON messages separated by NUL on fds 3 (in) and 4 (out). +function findChrome() { + const candidates = [ + process.env.CHROME_PATH, + "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", + "/Applications/Chromium.app/Contents/MacOS/Chromium", + "/usr/bin/google-chrome", + "/usr/bin/google-chrome-stable", + "/usr/bin/chromium", + "/usr/bin/chromium-browser", + `${process.env.PROGRAMFILES}\\Google\\Chrome\\Application\\chrome.exe`, + `${process.env.LOCALAPPDATA}\\Google\\Chrome\\Application\\chrome.exe`, + ]; + return candidates.find((p) => p && existsSync(p)) ?? (console.error("Chrome not found; set CHROME_PATH"), process.exit(2)); +} + +const profile = mkdtempSync(join(tmpdir(), "explain-pr-as-video-")); +const chrome = spawn(findChrome(), [ + "--headless=new", "--remote-debugging-pipe", `--user-data-dir=${profile}`, "--no-first-run", + "--hide-scrollbars", "--mute-audio", "--allow-file-access-from-files", "--force-color-profile=srgb", + "--force-device-scale-factor=1", `--window-size=${W},${H}`, "--font-render-hinting=none", "about:blank", +], { stdio: ["ignore", "ignore", "ignore", "pipe", "pipe"] }); +const pending = new Map(); +let nextId = 0, buffer = ""; +chrome.stdio[4].on("data", (chunk) => { + buffer += chunk; + let end; + while ((end = buffer.indexOf("\0")) >= 0) { + const msg = JSON.parse(buffer.slice(0, end)); + buffer = buffer.slice(end + 1); + const wait = pending.get(msg.id); + if (!wait) continue; + pending.delete(msg.id); + msg.error ? wait.reject(new Error(`${wait.method}: ${msg.error.message}`)) : wait.resolve(msg.result); + } +}); +const send = (method, params = {}, sessionId) => + new Promise((res, rej) => { + const id = ++nextId; + pending.set(id, { resolve: res, reject: rej, method }); + chrome.stdio[3].write(JSON.stringify({ id, method, params, sessionId }) + "\0"); + }); +const cleanup = () => { + chrome.kill("SIGKILL"); + try { + rmSync(profile, { recursive: true, force: true, maxRetries: 5 }); + } catch {} // Chrome may still be writing its profile; the OS temp dir clears it later +}; +process.on("exit", cleanup); + +async function openPage() { + const { targetId } = await send("Target.createTarget", { url: "about:blank" }); + const { sessionId } = await send("Target.attachToTarget", { targetId, flatten: true }); + const page = (method, params) => send(method, params, sessionId); + await page("Emulation.setDeviceMetricsOverride", { width: W, height: H, deviceScaleFactor: 1, mobile: false }); + await page("Page.enable"); + const url = pathToFileURL(deck); + url.searchParams.set("render", "1"); + await page("Page.navigate", { url: url.href }); + const evaluate = async (expression) => { + const r = await page("Runtime.evaluate", { expression, awaitPromise: true, returnByValue: true }); + if (r.exceptionDetails) throw new Error(`deck: ${r.exceptionDetails.exception?.description ?? r.exceptionDetails.text}`); + return r.result.value; + }; + for (let i = 0; !(await evaluate("document.readyState === 'complete' && !!window.deck?.ready")); i++) { + if (i > 100) throw new Error("the deck never loaded window.deck; check that it includes runtime.js"); + await new Promise((r) => setTimeout(r, 100)); + } + await evaluate("document.fonts.ready.then(() => window.deck.problems())").then((problems) => { + for (const p of problems) console.error(`deck: ${p}`); + }); + const shot = async (seconds, format = "jpeg") => { + await evaluate(`window.deck.seek(${seconds})`); + const { data } = await page("Page.captureScreenshot", { format, quality: format === "jpeg" ? 92 : undefined, optimizeForSpeed: true }); + return Buffer.from(data, "base64"); + }; + return { shot, evaluate }; +} + +function ffmpeg(args) { + const proc = spawn("ffmpeg", ["-v", "error", "-y", ...args], { stdio: ["pipe", "inherit", "inherit"] }); + const done = new Promise((res, rej) => proc.on("close", (code) => (code ? rej(new Error(`ffmpeg exited ${code}`)) : res()))); + return { stdin: proc.stdin, done }; +} + +if (opt.stills || opt.at) { + const stills = join(work, "stills"); + mkdirSync(stills, { recursive: true }); + const { shot } = await openPage(); + const targets = opt.at + ? [[`at-${opt.at}`, Number(opt.at)]] + : scenes.map((s, i) => [`${String(i).padStart(2, "0")}-${s.id}`, s.end - 0.4]); + for (const [name, at] of targets) { + writeFileSync(join(stills, `${name}.png`), await shot(at, "png")); + console.log(join(stills, `${name}.png`)); + } + process.exit(0); +} + +// Split the frames into contiguous chunks, one tab and one encoder each, then join the parts. +const frames = Math.ceil(duration * fps); +const jobs = Math.max(1, Math.min(Number(opt.jobs), Math.ceil(frames / (fps * 5)))); +const parts = Array.from({ length: jobs }, (_, j) => ({ + from: Math.floor((frames * j) / jobs), + to: Math.floor((frames * (j + 1)) / jobs), + file: join(profile, `part-${j}.mp4`), +})); +let done = 0; +const started = Date.now(); +await Promise.all( + parts.map(async (part) => { + const { shot } = await openPage(); + const enc = ffmpeg(["-f", "image2pipe", "-framerate", String(fps), "-c:v", "mjpeg", "-i", "-", + "-c:v", "libx264", "-preset", "medium", "-crf", "16", "-pix_fmt", "yuv420p", "-r", String(fps), part.file]); + for (let f = part.from; f < part.to; f++) { + if (!enc.stdin.write(await shot(f / fps))) await new Promise((r) => enc.stdin.once("drain", r)); + if (++done % (fps * 10) === 0) console.error(`frames ${done}/${frames} (${Math.round((Date.now() - started) / 1000)} s)`); + } + enc.stdin.end(); + await enc.done; + }), +); +const list = join(profile, "parts.txt"); +writeFileSync(list, parts.map((p) => `file '${p.file}'`).join("\n")); +const out = join(work, "video.mp4"); +const join_ = ffmpeg(["-f", "concat", "-safe", "0", "-i", list, "-c", "copy", "-movflags", "+faststart", out]); +join_.stdin.end(); +await join_.done; +console.error(`rendered ${frames} frames in ${Math.round((Date.now() - started) / 1000)} s`); +console.log(out); +process.exit(0); diff --git a/skills/jam/SKILL.md b/skills/jam/SKILL.md index 2968a63..b2a9a26 100644 --- a/skills/jam/SKILL.md +++ b/skills/jam/SKILL.md @@ -26,6 +26,7 @@ before you start. | Jam set up for this agent: the CLI, sign-in, Jam MCP, the skills | `jam-setup` | | a polished, narrated demo video of a feature | `record-demo` | | a spoken voiceover on a video | `add-voiceover` | +| a narrated video that walks a reviewer through a pull request | `explain-pr-as-video` | | a terminal run recorded as a GIF for the pull request | `record-terminal-proof` | Several asks in one request ("fix it and file a ticket"): run the skills in