@zuilib/text-editor 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -3
- package/README.md +61 -35
- package/dist/chunk-3KAABUZQ.js +2 -0
- package/dist/chunk-5J4TV6XA.js +2 -0
- package/dist/chunk-6JQG6QDN.js +16 -0
- package/dist/chunk-6LHJXZZ2.js +2 -0
- package/dist/chunk-N6OUUWQO.js +5 -0
- package/dist/comments.js +1 -1
- package/dist/drawing.js +1 -1
- package/dist/index.js +1 -1
- package/dist/lexical.js +1 -1
- package/dist/markdown.js +1 -1
- package/dist/mentions.js +1 -1
- package/dist/styles.css +215 -6
- package/dist/tailwind.css +7 -0
- package/package.json +19 -33
- package/dist/chunk-3TZVOXWX.js +0 -16
- package/dist/chunk-C7VEINKX.js +0 -2
- package/dist/chunk-R5PL4Q7X.js +0 -5
- package/dist/chunk-SDICQI2B.js +0 -2
- package/dist/chunk-XP3MZRCW.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,37 @@
|
|
|
1
1
|
# Changelog — @zuilib/text-editor
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.13.0 — Unreleased
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
### Breaking
|
|
6
|
+
|
|
7
|
+
- Lexical and `@zuilib/tokens` are now regular dependencies, so consumers
|
|
8
|
+
install only `@zuilib/text-editor`; React and React DOM remain peers.
|
|
9
|
+
Lexical is pinned to 0.35.0. The new `tailwind.css` entry owns token styles
|
|
10
|
+
and source registration, while `styles.css` includes tokens and editor
|
|
11
|
+
chrome for hosts without Tailwind.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- **Small screens and touch.** `.zui-text-editor` is now an inline-size
|
|
16
|
+
container (and so a stacking context), and the layout follows the
|
|
17
|
+
editor's own width: below 40rem the toolbar scrolls sideways with a
|
|
18
|
+
hidden scrollbar and scroll snapping instead of overflowing, the outline
|
|
19
|
+
becomes a collapsible strip above the document, each table scrolls
|
|
20
|
+
horizontally inside its own box with a 6rem column minimum, headings
|
|
21
|
+
step down, and any drawing wider than its pane scales to fit (aspect
|
|
22
|
+
preserved). Link, mention and comment panels stay inside the pane
|
|
23
|
+
(`useFloatingClamp`, internal) and the mention list caps at `50dvh`.
|
|
24
|
+
On coarse pointers buttons, tools and rail handles get 44px targets,
|
|
25
|
+
the hover-only fold chevrons and table rail handles are visible, and a
|
|
26
|
+
tap on a table rail pins the `+` / `−` handle where the finger was (a
|
|
27
|
+
second tap acts). A finger on an idle drawing scrolls the page; the
|
|
28
|
+
canvas captures touches once tapped (focused). Editable text renders at
|
|
29
|
+
16px or more on phones so iOS does not zoom on focus. Desktop geometry
|
|
30
|
+
is unchanged.
|
|
31
|
+
|
|
32
|
+
## 0.12.0 — 2026-09-01
|
|
33
|
+
|
|
34
|
+
This entry carries everything since 0.11.1: the library-wide naming overhaul (clean break; only the
|
|
7
35
|
persisted drawing format migrates), the extension API and first-party plugins,
|
|
8
36
|
and the controlled-`value` rewrite. Features new in this release are described
|
|
9
37
|
under their final names.
|
package/README.md
CHANGED
|
@@ -41,32 +41,27 @@ frontmatter as `---` blocks. Feature history: [CHANGELOG](./CHANGELOG.md).
|
|
|
41
41
|
## Installation
|
|
42
42
|
|
|
43
43
|
```bash
|
|
44
|
-
pnpm add @zuilib/text-editor
|
|
45
|
-
lexical @lexical/react @lexical/markdown @lexical/rich-text \
|
|
46
|
-
@lexical/code @lexical/list @lexical/link @lexical/table @lexical/utils
|
|
44
|
+
pnpm add @zuilib/text-editor
|
|
47
45
|
```
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
Lexical and ZUI tokens are regular dependencies. React and React DOM remain
|
|
48
|
+
peers so the editor shares the application's React runtime. Tailwind v4 is
|
|
49
|
+
optional; when the app uses it, the package-owned entry registers the editor's
|
|
50
|
+
document typography classes:
|
|
53
51
|
|
|
54
52
|
```css
|
|
55
53
|
@import "tailwindcss";
|
|
56
|
-
@import "@zuilib/
|
|
57
|
-
@source "../node_modules/@zuilib/text-editor/dist";
|
|
58
|
-
@import "@zuilib/text-editor/styles.css";
|
|
54
|
+
@import "@zuilib/text-editor/tailwind.css";
|
|
59
55
|
```
|
|
60
56
|
|
|
61
|
-
Without Tailwind,
|
|
62
|
-
document block classes yourself; the
|
|
57
|
+
Without Tailwind, import `@zuilib/text-editor/styles.css`; it includes the
|
|
58
|
+
tokens and editor chrome. Style the document block classes yourself; the list is on the
|
|
63
59
|
[Theming](https://zuilib.com/docs/text-editor/theming#block-classes) page.
|
|
64
60
|
|
|
65
61
|
## Quick start
|
|
66
62
|
|
|
67
63
|
```tsx
|
|
68
64
|
import { useState } from 'react'
|
|
69
|
-
import '@zuilib/tokens/styles.css'
|
|
70
65
|
import '@zuilib/text-editor/styles.css'
|
|
71
66
|
import { MarkdownEditor } from '@zuilib/text-editor'
|
|
72
67
|
|
|
@@ -304,7 +299,9 @@ clicked.
|
|
|
304
299
|
`items` has `format`, `block`, `insert` and `history` (undo / redo, only
|
|
305
300
|
in this function form). Buttons made with `ToolbarButton` take part in the
|
|
306
301
|
toolbar's arrow-key navigation (`data-toolbar-item`); other elements you
|
|
307
|
-
put in the toolbar keep their own focus handling.
|
|
302
|
+
put in the toolbar keep their own focus handling. In an editor narrower
|
|
303
|
+
than 40rem the toolbar scrolls sideways instead of wrapping (see [Small
|
|
304
|
+
screens and touch](#small-screens-and-touch)).
|
|
308
305
|
|
|
309
306
|
### Placing your own toolbar (compound components)
|
|
310
307
|
|
|
@@ -486,9 +483,43 @@ indented by level, click to scroll, current section highlighted. Not part
|
|
|
486
483
|
of the document — pure UI. Available in `edit-rich` and `view`.
|
|
487
484
|
|
|
488
485
|
`collapsible` (default on) shows a chevron in the gutter of each heading on
|
|
489
|
-
hover
|
|
490
|
-
or higher level). Folding never
|
|
491
|
-
|
|
486
|
+
hover (always visible on touch screens); clicking collapses the section
|
|
487
|
+
(until the next heading of the same or higher level). Folding never
|
|
488
|
+
changes the markdown; fold state resets on remount; a folded section
|
|
489
|
+
auto-expands if the cursor enters it.
|
|
490
|
+
|
|
491
|
+
## Small screens and touch
|
|
492
|
+
|
|
493
|
+
The editor lays out against its **own width**, not the viewport:
|
|
494
|
+
`.zui-text-editor` and `.zui-text-editor-main` are CSS inline-size
|
|
495
|
+
containers (which also makes the root a stacking context, so the sticky
|
|
496
|
+
toolbar's `z-index` never escapes the editor). Nothing changes above a
|
|
497
|
+
pane width of 40rem; below it:
|
|
498
|
+
|
|
499
|
+
- the toolbar scrolls sideways (hidden scrollbar, scroll snapping) rather
|
|
500
|
+
than wrapping or overflowing — button order is part of the UI;
|
|
501
|
+
- the outline becomes a collapsible strip above the document instead of a
|
|
502
|
+
220px side column;
|
|
503
|
+
- each table is its own horizontal scroll container with a 6rem column
|
|
504
|
+
minimum, so a wide table scrolls inside the pane and never widens it;
|
|
505
|
+
- headings step down (h1 `2rem`, h2 `1.625rem`, h3 `1.375rem`);
|
|
506
|
+
- a drawing wider than the pane scales down to fit, aspect preserved
|
|
507
|
+
(it is still edited at full resolution).
|
|
508
|
+
|
|
509
|
+
Link, mention and comment panels are clamped inside the pane; the mention
|
|
510
|
+
list is capped at `50dvh` so it clears a soft keyboard. On coarse pointers
|
|
511
|
+
(`@media (pointer: coarse)`) toolbar buttons, drawing tools, outline
|
|
512
|
+
entries and the table rail handles get 44px targets, the hover-revealed
|
|
513
|
+
fold chevrons and rail handles are visible by default, and a tap on a
|
|
514
|
+
table rail pins the `+` / `−` handle where the finger was (a second tap
|
|
515
|
+
acts; sliding along the rail moves it). A finger on an idle drawing
|
|
516
|
+
scrolls the page; once the canvas is tapped (focused) touches draw and
|
|
517
|
+
drag. Below a 40rem *viewport* the editable surface renders at 16px or
|
|
518
|
+
more so iOS does not zoom on focus.
|
|
519
|
+
|
|
520
|
+
Custom toolbar content: anything that pops out of `MarkdownEditor.Toolbar`
|
|
521
|
+
(a menu, a select) should render in a portal — below 40rem the toolbar is
|
|
522
|
+
a scroll container and clips its overflow.
|
|
492
523
|
|
|
493
524
|
## Extending
|
|
494
525
|
|
|
@@ -684,7 +715,7 @@ and `is-resolved` when every id on them is resolved; the colour reads
|
|
|
684
715
|
`editor.update` / `read`: `$getMarkNodes()`, `$getCommentIds()`,
|
|
685
716
|
`$removeComment(id)`, `$plainTextOffset(node)`, plus
|
|
686
717
|
`formatCommentMarker`, `parseCommentIds`, `ADD_COMMENT_COMMAND` and
|
|
687
|
-
`COMMENTS_THEME`.
|
|
718
|
+
`COMMENTS_THEME`. `@lexical/mark` installs with the editor.
|
|
688
719
|
|
|
689
720
|
### Images
|
|
690
721
|
|
|
@@ -753,8 +784,8 @@ go. Plain-text pastes and pastes into an input are untouched.
|
|
|
753
784
|
| `tables`, `links`, `images` | `false` flattens cells to paragraphs, keeps link text only, drops images |
|
|
754
785
|
| `transform` | `(html) => html` runs on the cleaned HTML before conversion |
|
|
755
786
|
|
|
756
|
-
`normalizePastedHtml(html, options)` is the pure function behind it.
|
|
757
|
-
|
|
787
|
+
`normalizePastedHtml(html, options)` is the pure function behind it.
|
|
788
|
+
`@lexical/html` and `@lexical/clipboard` install with the editor.
|
|
758
789
|
|
|
759
790
|
## For AI agents / programmatic authoring
|
|
760
791
|
|
|
@@ -806,7 +837,8 @@ Lexical type. Plugin authors composing at the Lexical level import
|
|
|
806
837
|
| `CodeGrammar`, `CodeRule`, `CodeToken`, `CodeTokenType` | Code highlighting types |
|
|
807
838
|
| `registerCodeLanguage`, `hasCodeLanguage`, `resolveCodeLanguage`, `getCodeLanguages`, `tokenizeCode` | Code language registry and lexer |
|
|
808
839
|
| `BUILTIN_CODE_LANGUAGES`, `CODE_TOKEN_TYPES`, `PLAIN_LANGUAGE` | Code highlighting constants |
|
|
809
|
-
| `@zuilib/text-editor/styles.css` |
|
|
840
|
+
| `@zuilib/text-editor/styles.css` | Tokens + editor chrome for hosts without Tailwind |
|
|
841
|
+
| `@zuilib/text-editor/tailwind.css` | Tokens, editor chrome and package source registration for Tailwind v4 hosts |
|
|
810
842
|
|
|
811
843
|
The default entry additionally re-exports the pure drawing-data API (below)
|
|
812
844
|
and the plugin components (`MentionsPlugin`, `CommentsPlugin`,
|
|
@@ -891,20 +923,15 @@ elsewhere), and `labels.count` formats it. The visible count is not a
|
|
|
891
923
|
live region; a hidden status announces `labels.limitExceeded(max)` /
|
|
892
924
|
`labels.limitRestored(max)` only when the document crosses the limit.
|
|
893
925
|
|
|
894
|
-
Load
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
custom properties (`--primary`, `--popover`, `--border`, …) and falls back
|
|
900
|
-
to its own defaults when they are unset. Document content (headings,
|
|
901
|
-
lists, code blocks) is styled with Tailwind utility classes, so a Tailwind
|
|
902
|
-
v4 host must scan this package for them to be generated:
|
|
926
|
+
Load one editor CSS entry in the app layout. `styles.css` includes the token
|
|
927
|
+
values and authored editor chrome for hosts without Tailwind. A Tailwind v4
|
|
928
|
+
host imports Tailwind itself and then `tailwind.css`, which includes those
|
|
929
|
+
same styles and registers the package source. Dark mode follows the ZUI
|
|
930
|
+
convention: a `dark` class on `<html>`.
|
|
903
931
|
|
|
904
932
|
```css
|
|
905
|
-
@import "
|
|
906
|
-
@
|
|
907
|
-
@import "@zuilib/text-editor/styles.css";
|
|
933
|
+
@import "tailwindcss";
|
|
934
|
+
@import "@zuilib/text-editor/tailwind.css";
|
|
908
935
|
```
|
|
909
936
|
|
|
910
937
|
## Architecture notes (for extenders)
|
|
@@ -942,8 +969,7 @@ v4 host must scan this package for them to be generated:
|
|
|
942
969
|
## Related packages
|
|
943
970
|
|
|
944
971
|
- `@zuilib/tokens` — design tokens and base styles
|
|
945
|
-
- `@zuilib/
|
|
946
|
-
- `@zuilib/form` — react-hook-form wiring
|
|
972
|
+
- `@zuilib/primitives` — the UI primitives (Button, Input, …) and the react-hook-form wiring (`form`, `form-field`)
|
|
947
973
|
|
|
948
974
|
## Build & release (maintainers)
|
|
949
975
|
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{b as Y,c as ne}from"./chunk-5VRVC56Y.js";import{a as j,b as ee,c as te}from"./chunk-6LHJXZZ2.js";import{useCallback as re,useEffect as p,useId as me,useMemo as z,useRef as y,useState as h}from"react";import{useLexicalComposerContext as fe}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as pe}from"@lexical/react/useLexicalEditable";import{$createTextNode as oe,$getNodeByKey as ye,$getSelection as ce,$isRangeSelection as ue,$isTextNode as ge,COMMAND_PRIORITY_EDITOR as ie,COMMAND_PRIORITY_HIGH as x,SELECTION_CHANGE_COMMAND as Me,KEY_ARROW_DOWN_COMMAND as Re,KEY_ARROW_UP_COMMAND as Ne,KEY_ENTER_COMMAND as Ce,KEY_ESCAPE_COMMAND as Ee,KEY_TAB_COMMAND as he,createCommand as xe}from"lexical";import{mergeRegister as se}from"@lexical/utils";import{Fragment as Oe,jsx as v,jsxs as ae}from"react/jsx-runtime";var ve={suggestions:l=>`Suggestions for ${l}`,noResults:"No matches",loading:"Searching"},$e=xe("INSERT_MENTION_COMMAND"),Ae=40;function le(l){return l.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Te(l,a,s){let u=l.slice(0,a);for(let m of s){let c=new RegExp(`(?:^|[\\s(\\[])(${le(m)})([^\\s${le(m)}]{0,${Ae}})$`).exec(u);if(!c)continue;let r=c.index+c[0].length-c[1].length-c[2].length;return{trigger:m,query:c[2],from:r}}return null}function _e(l){let a=ce();if(!ue(a)||!a.isCollapsed())return null;let s=a.anchor.getNode();if(!ge(s)||ne(s)||s.hasFormat("code")||s.getMode()!=="normal")return null;let u=Te(s.getTextContent(),a.anchor.offset,l);return u?{...u,key:s.getKey()}:null}function Ie({trigger:l="@",search:a,render:s,triggers:u,maxItems:m=8,labels:T,onSelect:c}){let[r]=fe(),H=pe(),_=z(()=>({...ve,...T}),[T]),g=z(()=>u??(a?[{trigger:l,search:a,render:s}]:[]),[u,l,a,s]),M=z(()=>g.map(e=>e.trigger),[g]),R=me(),[i,$]=h(null),[N,I]=h([]),[B,A]=h(!1),[C,O]=h(0),[b,U]=h(null),F=y(null);j(F,b);let S=y(null),D=y(i);D.current=i;let L=y(N);L.current=N;let G=y(C);G.current=C;let W=y(c);W.current=c,p(()=>{if(!H||M.length===0){$(null);return}let e=()=>{let t=r.getEditorState().read(()=>_e(M)),o=t?`${t.key}:${t.from}:${t.trigger}:${t.query}`:null;t&&S.current===o||(o!==null&&(S.current=null),$(n=>n&&t&&n.key===t.key&&n.from===t.from&&n.trigger===t.trigger&&n.query===t.query?n:t))};return e(),se(r.registerUpdateListener(e),r.registerCommand(Me,()=>(e(),!1),ie))},[r,H,M]);let q=i?.query??null,P=i?.trigger??null;p(()=>{if(P===null||q===null){I([]),A(!1);return}let e=g.find(o=>o.trigger===P);if(!e)return;let t=!0;return A(!0),e.search(q).then(o=>{t&&(I(o.slice(0,m)),O(0),A(!1))}).catch(()=>{t&&(I([]),A(!1))}),()=>{t=!1}},[g,P,q,m]),p(()=>{if(!i){U(null);return}U(ee(r,te(r,i.key)))},[r,i]);let w=re(()=>{let e=D.current;e&&(S.current=`${e.key}:${e.from}:${e.trigger}:${e.query}`),$(null)},[]),k=re(e=>{let t=D.current;if(!t)return;let o=g.find(n=>n.trigger===t.trigger);r.update(()=>{let n=ye(t.key);if(!ge(n))return;let d=n.getTextContent(),f=t.from+t.trigger.length+t.query.length,X=d.slice(t.from,f);if(X!==t.trigger+t.query)return;let J=n.splitText(t.from,f).find(de=>de.getTextContent()===X);if(!J)return;let V=Y(e.id,e.name,t.trigger);J.replace(V);let Z=oe(" ");V.insertAfter(Z),Z.select(1,1)}),$(null),o&&W.current?.(e,t.trigger)},[r,g]),E=i!==null;p(()=>{if(!E)return;let e=o=>n=>{let d=L.current.length;return d===0?!1:(n?.preventDefault(),O(f=>(f+o+d)%d),!0)},t=o=>{let n=L.current[G.current];return n?(o?.preventDefault(),k(n),!0):!1};return se(r.registerCommand(Re,e(1),x),r.registerCommand(Ne,e(-1),x),r.registerCommand(Ce,t,x),r.registerCommand(he,t,x),r.registerCommand(Ee,o=>(o?.preventDefault(),w(),!0),x))},[r,E,k,w]),p(()=>r.registerCommand($e,({id:e,name:t,trigger:o})=>{let n=ce();if(!ue(n))return!1;let d=Y(e,t,o??M[0]??"@"),f=oe(" ");return n.insertNodes([d,f]),!0},ie),[r,M]);let K=E&&N[C]?`${R}-${C}`:null;if(p(()=>{let e=r.getRootElement();if(e&&E)return e.setAttribute("aria-controls",R),K?e.setAttribute("aria-activedescendant",K):e.removeAttribute("aria-activedescendant"),()=>{e.removeAttribute("aria-controls"),e.removeAttribute("aria-activedescendant")}},[r,E,R,K]),!i||b===null)return null;let Q=g.find(e=>e.trigger===i.trigger)?.render;return ae("div",{ref:F,className:"zui-text-editor-mentions",style:b,"data-slot":"mentions",children:[v("div",{role:"listbox",id:R,"aria-label":_.suggestions(i.trigger),"aria-busy":B||void 0,children:N.map((e,t)=>{let o=t===C;return v("div",{id:`${R}-${t}`,role:"option","aria-selected":o,className:`zui-text-editor-mention-option${o?" is-active":""}`,onMouseDown:n=>n.preventDefault(),onMouseMove:()=>O(t),onClick:()=>k(e),children:Q?Q(e,{active:o,query:i.query,trigger:i.trigger}):ae(Oe,{children:[v("span",{className:"zui-text-editor-mention-name",children:e.name}),e.hint&&v("span",{className:"zui-text-editor-mention-hint",children:e.hint})]})},e.id)})}),N.length===0&&v("div",{className:"zui-text-editor-mention-empty",role:"status",children:B?_.loading:_.noResults})]})}export{ve as a,$e as b,Te as c,Ie as d};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{d as A,f as U,g as q}from"./chunk-A7MCBSAZ.js";import{a as x,b as E,c as S}from"./chunk-6LHJXZZ2.js";import{useCallback as Y,useEffect as y,useMemo as oe,useRef as f,useState as L}from"react";import{useLexicalComposerContext as ne}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as re}from"@lexical/react/useLexicalEditable";import{$getSelection as T,$isRangeSelection as M,$isTextNode as I,COMMAND_PRIORITY_EDITOR as F,COMMAND_PRIORITY_HIGH as se,KEY_DOWN_COMMAND as ae,SELECTION_CHANGE_COMMAND as le,createCommand as ie}from"lexical";import{$createMarkNode as Q,$getMarkIDs as de,$isMarkNode as G,$wrapSelectionInMarkNode as ce,MarkNode as me}from"@lexical/mark";import{$findMatchingParent as ue,mergeRegister as W,registerNestedElementResolver as fe}from"@lexical/utils";import{Fragment as J,jsx as g,jsxs as p}from"react/jsx-runtime";var ge={add:"Add comment",comments:"Comments",resolve:"Resolve",reopen:"Reopen",remove:"Delete comment",resolved:"Resolved",unknown:t=>`Comment ${t}`},Ae={mark:"zui-comment",markOverlap:"zui-comment-overlap"},pe=ie("ADD_COMMENT_COMMAND");function ve(){let t=typeof crypto<"u"?crypto:void 0;return t&&typeof t.randomUUID=="function"?t.randomUUID():`c-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function Ce(t){return(t.metaKey||t.ctrlKey)&&t.shiftKey&&!t.altKey&&t.key.toLowerCase()==="m"}function ye(t){let n=T();if(!M(n)||n.isCollapsed())return null;let i=n.getTextContent();if(i.trim()==="")return null;let[r]=n.isBackward()?[n.focus]:[n.anchor],a=q(r.getNode())+(I(r.getNode())?r.offset:0);ce(n,n.isBackward(),t,o=>Q(o));let c=A().filter(o=>o.hasID(t)),m=c[c.length-1]?.getLastDescendant();return I(m)&&m.select(m.getTextContentSize(),m.getTextContentSize()),{id:t,quote:i,range:{start:a,end:a+i.length},resolved:!1}}function be(){let t=T();if(!M(t)||!t.isCollapsed())return[];let n=t.anchor.getNode();if(I(n)){let r=de(n,t.anchor.offset);if(r&&r.length>0)return r;let a=n.getPreviousSibling();if(t.anchor.offset===0&&G(a))return a.getIDs()}let i=ue(n,G);return i?i.getIDs():[]}function j(t,n){let i=new Set(n.filter(r=>r.resolved).map(r=>r.id));t.getEditorState().read(()=>{for(let r of A()){let a=t.getElementByKey(r.getKey());if(!a)continue;let c=r.getIDs();a.classList.add("zui-comment"),a.setAttribute("data-slot","comment"),a.setAttribute("data-comment-ids",c.join(",")),a.classList.toggle("is-resolved",c.length>0&&c.every(m=>i.has(m)))}})}function Me({comments:t,onAdd:n,onResolve:i,onDelete:r,createId:a=ve,labels:c,renderComment:m}){let[o]=ne(),w=re(),u=oe(()=>({...ge,...c}),[c]),[D,V]=L(null),[b,X]=L([]),[N,$]=L(null),O=f(n);O.current=n;let z=f(i);z.current=i;let _=f(r);_.current=r;let P=f(a);P.current=a;let K=f(t);K.current=t;let R=f(null),H=f(null),B=f(null);x(H,D),x(R,N);let C=Y(()=>{let e=ye(P.current());return e&&O.current?.(e),e!==null},[]),Z=Y(()=>{let e=!1;return o.update(()=>{e=C()},{discrete:!0}),e},[o,C]);y(()=>fe(o,me,e=>Q(e.getIDs()),(e,l)=>{for(let d of e.getIDs())l.addID(d)}),[o]),y(()=>W(o.registerCommand(pe,()=>C(),F),o.registerCommand(ae,e=>{if(!Ce(e))return!1;if(e.preventDefault(),C())return!0;let l=R.current?.querySelector("button");return l?(l.focus(),!0):!1},se)),[o,C]),y(()=>{let e=()=>{let{hasRange:l,ids:d,key:v}=o.getEditorState().read(()=>{let s=T(),h=M(s)&&!s.isCollapsed()&&s.getTextContent().trim()!=="",k=M(s)?s.anchor.getNode().getKey():null;return{hasRange:h,ids:be(),key:k}});B.current=v,V(w&&l?E(o,S(o,v),"above"):null),X(s=>s.length===d.length&&s.every((h,k)=>h===d[k])?s:d)};return e(),W(o.registerUpdateListener(e),o.registerCommand(le,()=>(e(),!1),F))},[o,w]),y(()=>{if(b.length===0){$(null);return}$(E(o,S(o,B.current),"below"))},[o,b]),y(()=>(j(o,t),o.registerUpdateListener(()=>j(o,K.current))),[o,t]);let ee=e=>{let l=t.find(d=>d.id===e);z.current?.(e,!(l?.resolved??!1))},te=e=>{o.update(()=>{U(e)}),_.current?.(e)};return p(J,{children:[D&&g("div",{ref:H,className:"zui-text-editor-comment-add",style:D,"data-slot":"comment-add",children:p("button",{type:"button",className:"zui-text-editor-toolbar-button",title:u.add,onMouseDown:e=>e.preventDefault(),onClick:()=>Z(),children:[p("svg",{viewBox:"0 0 20 20",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[g("path",{d:"M3 5.5A1.5 1.5 0 0 1 4.5 4h11A1.5 1.5 0 0 1 17 5.5v7a1.5 1.5 0 0 1-1.5 1.5H8l-4 3v-3h.5A1.5 1.5 0 0 1 3 12.5z"}),g("path",{d:"M10 7v5M7.5 9.5h5"})]}),g("span",{children:u.add})]})}),N&&b.length>0&&g("div",{ref:R,className:"zui-text-editor-comments",style:N,role:"group","aria-label":u.comments,"data-slot":"comments",onKeyDown:e=>{e.key==="Escape"&&(e.preventDefault(),o.getRootElement()?.focus({preventScroll:!0}),o.focus())},children:b.map(e=>{let l=t.find(s=>s.id===e)??{id:e,quote:"",resolved:!1},d=t.some(s=>s.id===e),v={resolve:()=>ee(e),remove:()=>te(e)};return g("div",{className:`zui-text-editor-comment${l.resolved?" is-resolved":""}`,"data-comment-id":e,children:m?m(l,v):p(J,{children:[p("div",{className:"zui-text-editor-comment-quote",children:[d?l.quote:u.unknown(e),l.resolved&&p("span",{className:"zui-text-editor-comment-state",children:[" ",u.resolved]})]}),p("div",{className:"zui-text-editor-comment-actions",children:[d&&g("button",{type:"button",className:"zui-text-editor-toolbar-button",onMouseDown:s=>s.preventDefault(),onClick:v.resolve,children:l.resolved?u.reopen:u.resolve}),g("button",{type:"button",className:"zui-text-editor-toolbar-button",onMouseDown:s=>s.preventDefault(),onClick:v.remove,children:u.remove})]})]})},e)})})]})}export{ge as a,Ae as b,pe as c,Me as d};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{k as Le,o as Hn,p as Wn,t as Gn,u as Kn,w as ae}from"./chunk-N5JWZ2VW.js";import{a as zn,e as K,r as ze,s as Fn,t as He,u as Yn}from"./chunk-LDVPFZCN.js";var de=["rect","ellipse","diamond","note","cylinder","cloud","queue","actor"],ue=["arrow","line"],bi=[...de,...ue,"text"];function A(t){return de.includes(t)}function R(t){return ue.includes(t)}var Jn=320,Si=80,We=5e3,qn=1e5,Mi=2e3,Pi=/^(#[0-9a-f]{3,8}|(rgba?|hsla?|oklch|oklab)\([\w.,%\s/+-]*\)|[a-z]+)$/i;function Vn(t){return typeof t=="string"&&t.length<=64&&Pi.test(t)}var I=15,H=11,et=1.35,nt={version:3,canvasHeight:Jn,shapes:[]},Dt=["#1e1e1e","#e03131","#2f9e44","#1971c2","#f08c00","#7048e8"],Qn=["transparent","#ffc9c9","#b2f2bb","#a5d8ff","#ffec99","#d0bfff"],Un=0;function Ke(){return Un+=1,`s${Date.now().toString(36)}${Un.toString(36)}`}var Ye={top:[.5,0],right:[1,.5],bottom:[.5,1],left:[0,.5]};function Y(t){return JSON.stringify(t)}function ye(t){try{return qe(JSON.parse(t))}catch{return nt}}var Xn=!1;function Di(t){Xn||(Xn=!0,console.warn(t))}function ki(t){if(!$t(t))return t;let{w:e,h:n,...o}=t;return{...o,width:e,height:n}}function qe(t,e=Di){if(!$t(t)||t.version!==2&&t.version!==3||!Array.isArray(t.shapes))return nt;let n=t.version===2?t.shapes.map(ki):t.shapes;n.length>We&&(e(`Drawing has ${n.length} shapes; keeping the first ${We}`),n=n.slice(0,We));let o=n.flatMap(s=>{let l=Ei(s);return l?[l]:[]}),i=new Set(o.map(s=>s.id)),r=Fe(t.canvasHeight,NaN),a=Fe(t.canvasWidth,NaN);return{version:3,canvasHeight:Number.isFinite(r)&&r>=Si?r:Jn,...Number.isFinite(a)&&a>=120?{canvasWidth:a}:{},...ae(t.width)?{width:t.width}:{},...se(t.title)?{title:se(t.title)}:{},...se(t.description)?{description:se(t.description)}:{},shapes:o.map(s=>{if(!R(s.type))return s;let l=Zn(s.startBinding,i,o),c=Zn(s.endBinding,i,o);return l===s.startBinding&&c===s.endBinding?s:{...s,startBinding:l,endBinding:c}})}}function Zn(t,e,n){if(!t||!e.has(t.id))return;let o=n.find(i=>i.id===t.id);return o&&A(o.type)?t:void 0}function $t(t){return typeof t=="object"&&t!==null}function Fe(t,e){return typeof t=="number"&&Number.isFinite(t)?t:e}function le(t){return typeof t=="string"&&t!==""?t:void 0}function se(t){let e=le(t)?.trim();return e?e.slice(0,Mi):void 0}function ce(t){return Math.min(qn,Math.max(-qn,t))}function jn(t){if(!$t(t)||typeof t.id!="string"||!t.id)return;let e={id:t.id},n=t.fixedPoint;return Array.isArray(n)&&n.length===2&&typeof n[0]=="number"&&typeof n[1]=="number"&&(e.fixedPoint=[Ge(n[0]),Ge(n[1])]),t.mode==="inside"&&(e.mode="inside"),e}function Ge(t){return Math.min(1,Math.max(0,t))}function Ei(t){if(!$t(t))return null;let e=t.type;if(typeof t.id!="string"||!t.id||typeof e!="string"||!bi.includes(e)||typeof t.x!="number"||typeof t.y!="number"||typeof t.width!="number"||typeof t.height!="number"||![t.x,t.y,t.width,t.height].every(Number.isFinite))return null;let n={id:t.id,type:e,x:ce(t.x),y:ce(t.y),width:ce(t.width),height:ce(t.height),stroke:Vn(t.stroke)?t.stroke:Dt[0],fill:Vn(t.fill)?t.fill:"transparent",strokeWidth:Math.min(100,Math.max(0,Fe(t.strokeWidth,2)))},o=le(t.text);if(o!==void 0&&(n.text=o),A(n.type)){let i=le(t.label),r=le(t.footer);i!==void 0&&(n.label=i),r!==void 0&&(n.footer=r),n.width<0&&(n.x+=n.width,n.width=-n.width),n.height<0&&(n.y+=n.height,n.height=-n.height)}if(R(n.type)){let i=jn(t.startBinding),r=jn(t.endBinding);if(i&&(n.startBinding=i),r&&(n.endBinding=r),n.type==="arrow"&&t.bidirectional===!0&&(n.bidirectional=!0),t.routing==="elbow"&&(n.routing="elbow"),typeof t.elbow=="number"&&Number.isFinite(t.elbow)&&(n.elbow=Ge(t.elbow)),Array.isArray(t.waypoints)){let a=t.waypoints.flatMap(s=>$t(s)&&typeof s.x=="number"&&typeof s.y=="number"&&Number.isFinite(s.x)&&Number.isFinite(s.y)?[{x:s.x,y:s.y}]:[]);a.length&&(n.waypoints=a)}}return n}var pe={up:{x:0,y:-1},right:{x:1,y:0},down:{x:0,y:1},left:{x:-1,y:0}};function to(t){return t==="up"?"down":t==="down"?"up":t==="left"?"right":"left"}function eo(t){return t==="left"||t==="right"}function Ve(t,e){let n=e.x-t.x,o=e.y-t.y;return Math.abs(n)>=Math.abs(o)?n>=0?"right":"left":o>=0?"down":"up"}function k(t){return{x:Math.min(t.x,t.x+t.width),y:Math.min(t.y,t.y+t.height),w:Math.abs(t.width),h:Math.abs(t.height)}}function no(t){if(R(t.type)||t.width>=0&&t.height>=0)return t;let e=k(t);return{...t,x:e.x,y:e.y,width:e.w,height:e.h}}function oo(t){return{x:t.x+t.w/2,y:t.y+t.h/2}}function io(t){return oo(k(t))}function fe(t,e){return{x:t.x-e,y:t.y-e,w:t.w+e*2,h:t.h+e*2}}function Ue(t,e,n=0){return e.x>=t.x-n&&e.x<=t.x+t.w+n&&e.y>=t.y-n&&e.y<=t.y+t.h+n}function Xe(t,e){return e.x>t.x&&e.x<t.x+t.w&&e.y>t.y&&e.y<t.y+t.h}function ro(t,e){return t.x>=e.x&&t.y>=e.y&&t.x+t.w<=e.x+e.w&&t.y+t.h<=e.y+e.h}function Lt(t){if(!t.length)return{x:0,y:0,w:0,h:0};let e=1/0,n=1/0,o=-1/0,i=-1/0;for(let r of t)e=Math.min(e,r.x),n=Math.min(n,r.y),o=Math.max(o,r.x+r.w),i=Math.max(i,r.y+r.h);return{x:e,y:n,w:o-e,h:i-n}}function kt(t,e){return Math.abs(t.x-e.x)+Math.abs(t.y-e.y)}function ut(t,e=40){let n=oo(t);return Array.from({length:e},(o,i)=>{let r=i*2*Math.PI/e;return{x:n.x+t.w/2*Math.cos(r),y:n.y+t.h/2*Math.sin(r)}})}function Ze(t){return[{x:t.x,y:t.y},{x:t.x+t.w,y:t.y},{x:t.x+t.w,y:t.y+t.h},{x:t.x,y:t.y+t.h}]}function he(t,e){let n=!1;for(let o=0,i=e.length-1;o<e.length;i=o++){let r=e[o],a=e[i];r.y>t.y!=a.y>t.y&&t.x<(a.x-r.x)*(t.y-r.y)/(a.y-r.y)+r.x&&(n=!n)}return n}function xe(t,e){let n=1/0;for(let o=0;o<e.length;o++)n=Math.min(n,Ri(t,e[o],e[(o+1)%e.length]));return n}function Ri(t,e,n){let o=n.x-e.x,i=n.y-e.y,r=o*o+i*i,a=r===0?0:Math.max(0,Math.min(1,((t.x-e.x)*o+(t.y-e.y)*i)/r));return Math.hypot(t.x-(e.x+o*a),t.y-(e.y+i*a))}function je(t,e,n,o=1e-6){let i=null;for(let r=0;r<n.length;r++){let a=n[r],s=n[(r+1)%n.length],l=s.x-a.x,c=s.y-a.y,u=e.x*c-e.y*l;if(Math.abs(u)<1e-9)continue;let x=a.x-t.x,y=a.y-t.y,m=(x*c-y*l)/u,g=(x*e.y-y*e.x)/u;m>=o&&g>=-1e-9&&g<=1+1e-9&&(i===null||m<i)&&(i=m)}return i}function ot(t,e,n){let o=n*.6,i=Math.max(1,Math.floor(e/o)),r=[];for(let a of t.split(`
|
|
3
|
+
`)){if(a.length<=i){r.push(a);continue}let s="";for(let l of a.split(" ")){for(;l.length>i;)s&&(r.push(s),s=""),r.push(l.slice(0,i)),l=l.slice(i);s?s.length+1+l.length<=i?s+=` ${l}`:(r.push(s),s=l):s=l}r.push(s)}return r}function X(t,e=I){let n=t.split(`
|
|
4
|
+
`),o=n.reduce((i,r)=>Math.max(i,r.length),0);return{w:Math.max(20,o*e*.6),h:n.length*e*et}}var xt=8;function zt(t,e,n=e){return{x:t.x+e,y:t.y+n,w:Math.max(t.w-e*2,20),h:Math.max(t.h-n*2,10)}}function Ti(t){let e=(1-Math.SQRT1_2)/2;return zt(t,t.w*e,t.h*e)}var Et=t=>Math.min(18,t.w/4,t.h/4),Rt=t=>Math.min(t.h*.14,18),Tt=t=>Math.min(t.w*.12,18),Ht=.62;function ge(t,e,n,o,i,r,a=12){return Array.from({length:a+1},(s,l)=>{let c=i+(r-i)*l/a;return{x:t+n*Math.cos(c),y:e+o*Math.sin(c)}})}var gt={rect:{type:"rect",label:"Rectangle",defaultSize:{w:160,h:90},textSlots:["label","text","footer"],outline:t=>Ze(k(t)),textArea:t=>zt(k(t),xt)},ellipse:{type:"ellipse",label:"Ellipse",defaultSize:{w:160,h:90},textSlots:["label","text","footer"],outline:t=>ut(k(t)),textArea:t=>zt(Ti(k(t)),2)},diamond:{type:"diamond",label:"Diamond",defaultSize:{w:170,h:100},textSlots:["label","text","footer"],outline:t=>{let e=k(t);return[{x:e.x+e.w/2,y:e.y},{x:e.x+e.w,y:e.y+e.h/2},{x:e.x+e.w/2,y:e.y+e.h},{x:e.x,y:e.y+e.h/2}]},textArea:t=>{let e=k(t);return zt(e,e.w/4,e.h/4)}},note:{type:"note",label:"Note",defaultSize:{w:160,h:110},textSlots:["label","text","footer"],defaultFill:"#ffec99",outline:t=>{let e=k(t),n=Et(e);return[{x:e.x,y:e.y},{x:e.x+e.w,y:e.y},{x:e.x+e.w,y:e.y+e.h-n},{x:e.x+e.w-n,y:e.y+e.h},{x:e.x,y:e.y+e.h}]},textArea:t=>{let e=k(t),n=Et(e);return{x:e.x+xt,y:e.y+xt,w:Math.max(e.w-xt*2,20),h:Math.max(e.h-xt*2-n/2,10)}}},cylinder:{type:"cylinder",label:"Database",defaultSize:{w:140,h:110},textSlots:["label","text","footer"],outline:t=>{let e=k(t),n=Rt(e),o=e.x+e.w/2;return[...ge(o,e.y+n,e.w/2,n,Math.PI,2*Math.PI),...ge(o,e.y+e.h-n,e.w/2,n,0,Math.PI)]},textArea:t=>{let e=k(t),n=Rt(e);return{x:e.x+xt,y:e.y+n*2+4,w:Math.max(e.w-xt*2,20),h:Math.max(e.h-n*3-8,10)}}},cloud:{type:"cloud",label:"Cloud",defaultSize:{w:180,h:110},textSlots:["label","text","footer"],outline:t=>ut(k(t)),textArea:t=>{let e=k(t);return zt(e,e.w*.17,e.h*.2)}},queue:{type:"queue",label:"Queue",defaultSize:{w:180,h:80},textSlots:["label","text","footer"],outline:t=>{let e=k(t),n=Tt(e),o=e.y+e.h/2;return[...ge(e.x+e.w-n,o,n,e.h/2,-Math.PI/2,Math.PI/2),...ge(e.x+n,o,n,e.h/2,Math.PI/2,3*Math.PI/2)]},textArea:t=>{let e=k(t),n=Tt(e);return{x:e.x+n+4,y:e.y+6,w:Math.max(e.w-n*3-8,20),h:Math.max(e.h-12,10)}}},actor:{type:"actor",label:"Actor",defaultSize:{w:90,h:120},textSlots:["text"],outline:t=>Ze(k(t)),textArea:t=>{let e=k(t),n=e.y+e.h*Ht;return{x:e.x-20,y:n,w:e.w+40,h:Math.max(e.y+e.h-n,10)}}}};function me(t){return gt[t.type]??null}var uo=6,Ni=10,Ci=.55;function Gt(t){let e=me(t);if(e)return e.outline(t);let n=k(t);return[{x:n.x,y:n.y},{x:n.x+n.w,y:n.y},{x:n.x+n.w,y:n.y+n.h},{x:n.x,y:n.y+n.h}]}function vi(t,e,n=0){let o=Gt(t);return he(e,o)?!0:n>0&&xe(e,o)<=n}function Wt(t,e,n,o=Ni){let i=null,r=1/0;for(let a=t.length-1;a>=0;a--){let s=t[a];if(s.id===n||!A(s.type)||!vi(s,e,o))continue;let l=k(s),c=l.w*l.h;c<r&&(i=s,r=c)}return i}function mt(t,e){let n=k(t),[o,i]=e?.fixedPoint??[.5,.5];return{x:n.x+n.w*o,y:n.y+n.h*i}}function Oi(t,e){let n=k(t);if(n.w<1||n.h<1)return;let o=Math.min(1,Math.max(0,(e.x-n.x)/n.w)),i=Math.min(1,Math.max(0,(e.y-n.y)/n.h)),r=(1-Ci)/2;if(o>r&&o<1-r&&i>r&&i<1-r)return;let a=[[o*n.w,"fx",0],[(1-o)*n.w,"fx",1],[i*n.h,"fy",0],[(1-i)*n.h,"fy",1]];a.sort((u,x)=>u[0]-x[0]);let[,s,l]=a[0],c=s==="fx"?[l,i]:[o,l];return[ao(c[0]),ao(c[1])]}function ao(t){return Math.round(t*1e3)/1e3}function Ii(t){let e=t?.fixedPoint;if(!e)return null;let[n,o]=e;return o<=0?n<=0||n>=1?null:"up":o>=1?n<=0||n>=1?null:"down":n<=0?"left":n>=1?"right":null}function Ft(t,e,n){let o=Ii(e);if(o)return o;let i=k(t),r=io(t),a=(n.x-r.x)/Math.max(i.w,1),s=(n.y-r.y)/Math.max(i.h,1);return Math.abs(a)>=Math.abs(s)?a>=0?"right":"left":s>=0?"down":"up"}function so(t,e,n,o=uo){let i=mt(t,e);if(e?.mode==="inside")return i;let r=n.x-i.x,a=n.y-i.y,s=Math.hypot(r,a);if(s<1)return i;let l=r/s,c=a/s,u=Gt(t),m=!(xe(i,u)<.5)&&he(i,u)?je(i,{x:l,y:c},u)??0:0;return{x:i.x+l*(m+o),y:i.y+c*(m+o)}}function co(t,e,n,o=uo){let i=mt(t,e);if(e?.mode==="inside")return i;let r=pe[n],a=Gt(t),c=!(xe(i,a)<.5)&&he(i,a)?je(i,r,a)??0:0;return{x:i.x+r.x*(c+o),y:i.y+r.y*(c+o)}}function be(t){let e=new Map(t.map(n=>[n.id,n]));return t.map(n=>{if(!R(n.type)||!n.startBinding&&!n.endBinding)return n;let o=lo(e,n.startBinding),i=lo(e,n.endBinding);if(!o&&!i)return{...n,startBinding:void 0,endBinding:void 0};let r={x:n.x,y:n.y},a={x:n.x+n.width,y:n.y+n.height},s=n.waypoints,l=s?.length?s[0]:i?mt(i,n.endBinding):a,c=s?.length?s[s.length-1]:o?mt(o,n.startBinding):r,u=n.routing==="elbow"&&!s?.length,x=o?u?co(o,n.startBinding,Ft(o,n.startBinding,l)):so(o,n.startBinding,l):r,y=i?u?co(i,n.endBinding,Ft(i,n.endBinding,c)):so(i,n.endBinding,c):a,m={...n,x:x.x,y:x.y,width:y.x-x.x,height:y.y-x.y,startBinding:o?n.startBinding:void 0,endBinding:i?n.endBinding:void 0};return _i(n,m)?n:m})}function lo(t,e){if(!e)return;let n=t.get(e.id);return n&&A(n.type)?n:void 0}function _i(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height&&t.startBinding===e.startBinding&&t.endBinding===e.endBinding}function yo(t,e){let n={x:t.x,y:t.y},o={x:t.x+t.width,y:t.y+t.height},i=Wt(e,n,t.id),r=Wt(e,o,t.id);return i&&r&&i.id===r.id?t:{...t,startBinding:i?we(i,n):void 0,endBinding:r?we(r,o):void 0}}function we(t,e){let n=Oi(t,e);return n?{id:t.id,fixedPoint:n}:{id:t.id}}var Se=" ",Ai=Dt[0],Je="transparent";function po(t,e={}){let n=t.shapes.filter(c=>A(c.type)),o=new Set(n.map(c=>c.id)),i=t.shapes.filter(c=>R(c.type)&&c.startBinding!==void 0&&o.has(c.startBinding.id)&&c.endBinding!==void 0&&o.has(c.endBinding.id)),r=t.shapes.filter(c=>c.type==="text"),a=$i(n),s=c=>a.get(c)??c;return`${[`flowchart ${e.direction??Bi(i)}`,...n.map(c=>Se+Hi(c,s(c.id))),...i.map(c=>Se+Wi(c,s)),...n.flatMap(c=>{let u=Fi(c,s(c.id));return u?[Se+u]:[]}),...r.map(c=>`${Se}%% note: ${(c.text??"").replace(/\s*\n\s*/g," ")}`)].join(`
|
|
5
|
+
`)}
|
|
6
|
+
`}function Bi(t){return t.length===0||t.filter(n=>Math.abs(n.width)>=Math.abs(n.height)).length*2>=t.length?"LR":"TD"}function $i(t){let e=new Map,n=new Set;for(let o of t){let i=Li(o.id),r=i;for(let a=2;n.has(r);a+=1)r=`${i}_${a}`;n.add(r),e.set(o.id,r)}return e}function Li(t){let e=t.replace(/[^A-Za-z0-9_]/g,"_");return e===""||/^[0-9]/.test(e)?`n_${e}`:e}var zi={rect:["[","]"],ellipse:["([","])"],diamond:["{","}"],note:["[","]"],cylinder:["[(",")]"],cloud:["((","))"],queue:["[[","]]"],actor:["((","))"]};function Hi(t,e){let[n,o]=zi[t.type],i=[t.label,t.text,t.footer].filter(a=>a!==void 0&&a!==""),r=i.length?i.map(fo).join("<br/>"):t.id;return`${e}${n}"${r}"${o}`}function Wi(t,e){let n=e(t.startBinding?.id??""),o=e(t.endBinding?.id??""),i=t.type==="line"?"---":t.bidirectional?"<-->":"-->",r=t.text?`|${fo(t.text).replace(/\|/g,"#124;")}|`:"";return`${n} ${i}${r} ${o}`}function Fi(t,e){let n=[];return t.fill!==Je&&n.push(`fill:${t.fill}`),t.stroke!==Ai&&n.push(`stroke:${t.stroke}`),n.length===0?null:(t.fill===Je&&n.unshift(`fill:${Je}`),`style ${e} ${n.join(",")}`)}function fo(t){return t.replace(/"/g,"#quot;").replace(/</g,"#lt;").replace(/>/g,"#gt;").replace(/\r?\n/g,"<br/>")}var Z={plain:{stroke:"transparent",fill:"#f1f3f5"},black:{stroke:"#1e1e1e",fill:"#1e1e1e"},gray:{stroke:"#1e1e1e",fill:"transparent"},red:{stroke:"#e03131",fill:"#ffc9c9"},green:{stroke:"#2f9e44",fill:"#b2f2bb"},blue:{stroke:"#1971c2",fill:"#a5d8ff"},orange:{stroke:"#f08c00",fill:"#ffec99"},purple:{stroke:"#7048e8",fill:"#d0bfff"}},bo=Object.keys(Z),Gi=260,Ki=6,Yi=90,ho=40,Me=32,qi=32,Vi=120,tn="#1e1e1e",en=2;function Ui(t){return Kt(t)&&Array.isArray(t.boxes)}function So(t){try{let e=JSON.parse(t);return Ui(e)?Xi(ar(e)):nt}catch{return nt}}function Xi(t){let e=rr(t.boxes),n=new Map(e.map(d=>[d.id,d.type??"rect"])),o=new Map(e.map(d=>[d.id,Zi(d,n.get(d.id))])),i=new Set(n.keys()),r=(t.connectors??[]).filter(d=>i.has(at(d.from))&&i.has(at(d.to))&&at(d.from)!==at(d.to)),a=Ji(e,o,r,t.direction??"right"),s=e.map(d=>er(d,n.get(d.id),o.get(d.id),a.get(d.id))),l=new Map(s.map(d=>[d.id,ir(d)])),c=new Set(i),u=d=>{let f=c.size+1;for(;c.has(`${d}${f}`);)f+=1;let P=`${d}${f}`;return c.add(P),P},x=r.map(d=>nr(d,l,u("c"))),y=(t.texts??[]).map(d=>or(d,u("t"))),m=be([...s,...x,...y]),g=m.reduce((d,f)=>{let P=k(f);return Math.max(d,P.y+P.h)},0);return qe({version:3,...t.canvasWidth!==void 0?{canvasWidth:t.canvasWidth}:{},canvasHeight:t.canvasHeight??Math.max(Vi,Math.ceil(g+qi)),...t.width!==void 0?{width:t.width}:{},shapes:m})}function Zi(t,e){let n=gt[e],o={id:"",type:e,x:0,y:0,width:n.defaultSize.w,height:n.defaultSize.h,stroke:"",fill:"",strokeWidth:0},i=n.textArea(o),r=i.w/n.defaultSize.w,a=i.h/n.defaultSize.h,s=t.w!==void 0?Math.max(20,t.w*r):Gi,l=n.textSlots.flatMap(x=>{let y=ji(t,x,s);return y?[y]:[]}),c=l.reduce((x,y)=>Math.max(x,y.w),0),u=l.reduce((x,y)=>x+y.h,0)+Math.max(0,l.length-1)*Ki;return{w:t.w??Math.max(n.defaultSize.w,Math.ceil(c/r)),h:t.h??Math.max(n.defaultSize.h,Math.ceil(u/a))}}function ji(t,e,n){let o=t[e];if(!o)return null;let i=e==="text"?I:H;return X(ot(o,n,i).join(`
|
|
7
|
+
`),i)}function Ji(t,e,n,o){let i=new Map,r=t.filter(f=>f.x===void 0||f.y===void 0),a=new Set(r.map(f=>f.id)),s=n.map(f=>({from:at(f.from),to:at(f.to)})).filter(f=>f.from!==f.to&&a.has(f.from)&&a.has(f.to)),l=tr(r.map(f=>f.id),Qi(r.map(f=>f.id),s)),c=[];for(let f of r){let P=l.get(f.id)??0;(c[P]??(c[P]=[])).push(f.id)}let u=o==="right"?"w":"h",x=o==="right"?"h":"w",y=c.map(f=>f.reduce((P,S)=>Math.max(P,e.get(S)[u]),0)),m=c.map(f=>f.reduce((P,S)=>P+e.get(S)[x],0)+Math.max(0,f.length-1)*ho),g=m.reduce((f,P)=>Math.max(f,P),0),d=Me;c.forEach((f,P)=>{let S=Me+(g-m[P])/2;for(let F of f){let _=e.get(F),ct=Math.round(d+(y[P]-_[u])/2),_t=Math.round(S);i.set(F,o==="right"?{x:ct,y:_t}:{x:_t,y:ct}),S+=_[x]+ho}d+=y[P]+Yi});for(let f of t){let P=i.get(f.id)??{x:Me,y:Me};i.set(f.id,{x:f.x??P.x,y:f.y??P.y})}return i}function Qi(t,e){let n=new Map;for(let a of e)(n.get(a.from)??n.set(a.from,[]).get(a.from)).push(a);let o=new Map,i=[],r=a=>{o.set(a,"visiting");for(let s of n.get(a)??[]){let l=o.get(s.to);l!=="visiting"&&(i.push(s),l===void 0&&r(s.to))}o.set(a,"done")};for(let a of t)o.has(a)||r(a);return i}function tr(t,e){let n=new Map;for(let r of e)(n.get(r.to)??n.set(r.to,[]).get(r.to)).push(r.from);let o=new Map,i=r=>{let a=o.get(r);if(a!==void 0)return a;let s=(n.get(r)??[]).reduce((l,c)=>Math.max(l,i(c)+1),0);return o.set(r,s),s};for(let r of t)i(r);return o}function er(t,e,n,o){let i=t.color?Z[t.color]:void 0,r=t.fill??i?.fill??gt[e].defaultFill??"transparent";return{id:t.id,type:e,x:o.x,y:o.y,width:n.w,height:n.h,stroke:t.stroke??i?.stroke??tn,fill:r,strokeWidth:en,...t.text?{text:t.text}:{},...t.label?{label:t.label}:{},...t.footer?{footer:t.footer}:{}}}function nr(t,e,n){let o=t.type??"arrow",i=e.get(at(t.from)),r=e.get(at(t.to));return{id:t.id??n,type:o,x:i.x,y:i.y,width:r.x-i.x,height:r.y-i.y,stroke:t.stroke??(t.color?Z[t.color].stroke:tn),fill:"transparent",strokeWidth:en,startBinding:xo(t.from),endBinding:xo(t.to),...t.text?{text:t.text}:{},...o==="arrow"&&t.bidirectional?{bidirectional:!0}:{},...t.routing==="elbow"?{routing:"elbow"}:{}}}function or(t,e){let n=X(t.text);return{id:t.id??e,type:"text",x:t.x,y:t.y,width:n.w,height:n.h,stroke:t.stroke??(t.color?Z[t.color].stroke:tn),fill:"transparent",strokeWidth:en,text:t.text}}function at(t){return typeof t=="string"?t:t.id}function xo(t){return typeof t=="string"||!t.side?{id:at(t)}:{id:t.id,fixedPoint:Ye[t.side]}}function ir(t){let e=k(t);return{x:e.x+e.w/2,y:e.y+e.h/2}}function rr(t){let e=new Set;return t.filter(n=>e.has(n.id)?!1:(e.add(n.id),!0))}function ar(t){let e=t,n=e.boxes.flatMap(s=>{let l=sr(s);return l?[l]:[]}),o=Array.isArray(e.connectors)?e.connectors.flatMap(s=>{let l=cr(s);return l?[l]:[]}):[],i=Array.isArray(e.texts)?e.texts.flatMap(s=>{let l=lr(s);return l?[l]:[]}):[],r=wt(e.canvasWidth),a=wt(e.canvasHeight);return{direction:e.direction==="down"?"down":"right",...r!==void 0?{canvasWidth:r}:{},...a!==void 0?{canvasHeight:a}:{},...ae(e.width)?{width:e.width}:{},boxes:n,connectors:o,texts:i}}function sr(t){return!Kt(t)||!W(t.id)||t.type!==void 0&&!(typeof t.type=="string"&&A(t.type))?null:on({id:t.id,type:t.type,label:W(t.label)?t.label:void 0,text:W(t.text)?t.text:void 0,footer:W(t.footer)?t.footer:void 0,x:wt(t.x),y:wt(t.y),w:mo(t.w),h:mo(t.h),color:nn(t.color),stroke:W(t.stroke)?t.stroke:void 0,fill:W(t.fill)?t.fill:void 0})}function cr(t){if(!Kt(t))return null;let e=go(t.from),n=go(t.to);return!e||!n||t.type!==void 0&&!(typeof t.type=="string"&&R(t.type))?null:on({id:W(t.id)?t.id:void 0,type:t.type,from:e,to:n,text:W(t.text)?t.text:void 0,bidirectional:t.bidirectional===!0?!0:void 0,routing:t.routing==="elbow"?"elbow":void 0,color:nn(t.color),stroke:W(t.stroke)?t.stroke:void 0})}function go(t){if(W(t))return t;if(!Kt(t)||!W(t.id))return null;let e=t.side;return typeof e=="string"&&e in Ye?{id:t.id,side:e}:{id:t.id}}function lr(t){if(!Kt(t)||!W(t.text))return null;let e=wt(t.x),n=wt(t.y);return e===void 0||n===void 0?null:on({id:W(t.id)?t.id:void 0,x:e,y:n,text:t.text,color:nn(t.color),stroke:W(t.stroke)?t.stroke:void 0})}function Kt(t){return typeof t=="object"&&t!==null}function W(t){return typeof t=="string"&&t!==""}function wt(t){return typeof t=="number"&&Number.isFinite(t)?t:void 0}function mo(t){let e=wt(t);return e!==void 0&&e>0?e:void 0}function nn(t){return typeof t=="string"&&bo.includes(t)?t:void 0}function on(t){return Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0))}var Qe={enum:bo,description:"Named color preset: outline plus, for boxes, a matching fill. `plain` has no outline and a light fill, `black` is a dark card with light text, `gray` is a dark outline on transparent (the default); the rest pair a colored outline with its pastel fill."},wo={oneOf:[{type:"string",description:"Id of a box. The connector attaches to its outline, aimed at the other end"},{type:"object",required:["id"],additionalProperties:!1,properties:{id:{type:"string",description:"Id of a box"},side:{enum:["top","right","bottom","left"],description:"Pin the endpoint to the middle of this side of the box instead of auto-aiming"}}}],description:"Box a connector end attaches to: a bare box id, or {id, side} to pick the attach edge"},wa={$schema:"http://json-schema.org/draft-07/schema#",title:"DrawingSkeleton",description:"Compact intent description of a diagram. Boxes are sized from their text and laid out automatically along the connector flow; connectors are drawn between box outlines. Only say what is on the canvas \u2014 geometry is derived",type:"object",required:["boxes"],additionalProperties:!1,properties:{direction:{enum:["right","down"],description:'Auto-layout flow direction. Boxes connected a\u2192b are placed in successive ranks along this axis ("right" = columns left to right, "down" = rows top to bottom). Default "right"'},canvasWidth:{type:"number",minimum:120,description:"Logical canvas width in px. Omit for a fluid canvas in CSS pixels"},canvasHeight:{type:"number",minimum:80,description:"Canvas height in px. Omit to fit the content"},width:{enum:["full","text","content"],description:'Block width: "text" aligns the drawing with the text column (same as "full" unless the app sets a text measure); "content" fits the drawing to its shapes and left-aligns it with the text; omit to span the editor'},boxes:{type:"array",items:{$ref:"#/definitions/box"},description:"Card-like shapes carrying up to three text slots. Order is the render order and the stacking order within a layout rank"},connectors:{type:"array",items:{$ref:"#/definitions/connector"},description:"Arrows and lines between boxes. Connectors whose from/to id does not match a box are dropped"},texts:{type:"array",items:{$ref:"#/definitions/text"},description:"Free-floating annotations not attached to any box. Prefer box slots (label/text/footer) when the text belongs to a box"}},definitions:{box:{type:"object",required:["id"],additionalProperties:!1,properties:{id:{type:"string",description:"Unique within the drawing; connectors reference it"},type:{enum:de,description:'Shape: rect (default), ellipse, diamond (decision), note (sticky note, yellow by default), cylinder (database), cloud (external system), queue (message queue), actor (stick figure; only the "text" slot renders, below the figure)'},label:{type:"string",description:"Small bold heading at the top of the box"},text:{type:"string",description:'Main content, centered. Wraps automatically; "\\n" forces a line break'},footer:{type:"string",description:"Small dim line at the bottom of the box"},x:{type:"number",description:"Top-left x in px. Omit (with y) to let the layout place the box"},y:{type:"number",description:"Top-left y in px. Omit (with x) to let the layout place the box"},w:{type:"number",exclusiveMinimum:0,description:"Width in px. Omit to size from the text (never smaller than the type default)"},h:{type:"number",exclusiveMinimum:0,description:"Height in px. Omit to size from the text (never smaller than the type default)"},color:Qe,stroke:{type:"string",description:"CSS color of the outline and text; overrides the preset"},fill:{type:"string",description:'CSS color of the interior ("transparent" for none); overrides the preset'}}},connector:{type:"object",required:["from","to"],additionalProperties:!1,properties:{id:{type:"string",description:"Optional; generated when omitted"},type:{enum:ue,description:'arrow (default; arrowhead at "to") or line (no arrowheads)'},from:wo,to:wo,text:{type:"string",description:"Label rendered at the middle of the connector"},bidirectional:{type:"boolean",description:"Arrow only: arrowheads on both ends"},routing:{enum:["straight","elbow"],description:"straight (default) draws a direct line; elbow draws a right-angled path routed around the boxes"},color:Qe,stroke:{type:"string",description:"CSS color of the line and label; overrides the preset"}}},text:{type:"object",required:["x","y","text"],additionalProperties:!1,properties:{id:{type:"string",description:"Optional; generated when omitted"},x:{type:"number",description:"Top-left x of the first line, in px"},y:{type:"number",description:"Top-left y of the first line, in px"},text:{type:"string",description:'Content; "\\n" forces a line break'},color:Qe,stroke:{type:"string",description:"CSS color of the text; overrides the preset"}}}}};import{$applyNodeReplacement as Kr,DecoratorNode as Yr}from"lexical";import{useCallback as O,useEffect as Oe,useMemo as Pn,useRef as z,useState as V,useContext as _r}from"react";import{$getNodeByKey as Ar}from"lexical";import{useLexicalComposerContext as Br}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as $r}from"@lexical/react/useLexicalEditable";var Mo=28,Do=14,dr=60,ur=1;function ko(t,e){let n=new Map(e.map(S=>[S.id,S])),o=t.startBinding?n.get(t.startBinding.id):void 0,i=t.endBinding?n.get(t.endBinding.id):void 0,r={x:t.x,y:t.y},a={x:t.x+t.width,y:t.y+t.height},s=i?mt(i,t.endBinding):a,l=o?mt(o,t.startBinding):r,c=o?Ft(o,t.startBinding,s):Ve(r,a),u=i?Ft(i,t.endBinding,l):Ve(a,r),x=o?Po(r,c,Mo):r,y=i?Po(a,u,Mo):a,m=Lt([Pe(x),Pe(y)]),g=fe(m,dr),d=e.filter(S=>A(S.type)).map(S=>fe(k(S),Do)).filter(S=>yr(S,g)).filter(S=>!Ue(S,x)&&!Ue(S,y)),f=pr(x,y,c,u,d)??(eo(c)?[x,{x:y.x,y:x.y},y]:[x,{x:x.x,y:y.y},y]),P=xr([r,x,...f,y,a]);return t.elbow!==void 0&&P.length===4&&(P=gr(P,t.elbow,d)),P}function Po(t,e,n){let o=pe[e];return{x:t.x+o.x*n,y:t.y+o.y*n}}function Pe(t){return{x:t.x,y:t.y,w:0,h:0}}function yr(t,e){return t.x<=e.x+e.w&&t.x+t.w>=e.x&&t.y<=e.y+e.h&&t.y+t.h>=e.y}function pr(t,e,n,o,i){let r=new Set([t.x,e.x,(t.x+e.x)/2]),a=new Set([t.y,e.y,(t.y+e.y)/2]);for(let d of i)r.add(d.x),r.add(d.x+d.w),a.add(d.y),a.add(d.y+d.h);let s=fe(Lt([Pe(t),Pe(e),...i]),Do);r.add(s.x),r.add(s.x+s.w),a.add(s.y),a.add(s.y+s.h);let l=[...r].sort((d,f)=>d-f),c=[...a].sort((d,f)=>d-f),u=c.map((d,f)=>l.map((P,S)=>({x:P,y:d,col:S,row:f,g:1/0,f:1/0,closed:!1,visited:!1,parent:null,dir:null}))),x=u[c.indexOf(t.y)][l.indexOf(t.x)],y=u[c.indexOf(e.y)][l.indexOf(e.x)];if(x===y)return[t];let m=Math.max(1e4,kt(t,e)**2),g=new rn;for(x.g=0,x.f=kt(x,y),x.visited=!0,g.push(x);g.size;){let d=g.pop();if(d.closed)continue;if(d===y)return hr(d);d.closed=!0;let f=d.dir??n;for(let[P,S]of fr(u,d)){if(S.closed||P===to(f)||S===y&&P===o)continue;let F={x:(d.x+S.x)/2,y:(d.y+S.y)/2};if(i.some(ct=>Xe(ct,F)))continue;let _=d.g+kt(d,S)+(P!==f?m:0);(!S.visited||_<S.g)&&(S.visited=!0,S.parent=d,S.dir=P,S.g=_,S.f=_+kt(S,y),g.push(S))}}return null}function fr(t,e){let n=[];return e.row>0&&n.push(["up",t[e.row-1][e.col]]),e.col<t[0].length-1&&n.push(["right",t[e.row][e.col+1]]),e.row<t.length-1&&n.push(["down",t[e.row+1][e.col]]),e.col>0&&n.push(["left",t[e.row][e.col-1]]),n}function hr(t){let e=[];for(let n=t;n;n=n.parent)e.push({x:n.x,y:n.y});return e.reverse()}var rn=class{constructor(){this.items=[]}get size(){return this.items.length}push(e){let n=this.items;n.push(e);let o=n.length-1;for(;o>0;){let i=o-1>>1;if(n[i].f<=n[o].f)break;[n[i],n[o]]=[n[o],n[i]],o=i}}pop(){let e=this.items,n=e[0],o=e.pop();if(e.length){e[0]=o;let i=0;for(;;){let r=i*2+1,a=r+1,s=i;if(r<e.length&&e[r].f<e[s].f&&(s=r),a<e.length&&e[a].f<e[s].f&&(s=a),s===i)break;[e[s],e[i]]=[e[i],e[s]],i=s}}return n}};function xr(t){let e=[];for(let o of t){let i=e[e.length-1];i&&kt(i,o)<ur||e.push(o)}let n=[];for(let o=0;o<e.length;o++){let i=n[n.length-1],r=e[o+1],a=e[o];if(i&&r){let s=Math.abs(i.x-a.x)<.01&&Math.abs(a.x-r.x)<.01,l=Math.abs(i.y-a.y)<.01&&Math.abs(a.y-r.y)<.01;if(s||l)continue}n.push(a)}return n}function gr(t,e,n){let[o,i,r,a]=t,s=Math.abs(i.y-r.y)<.01&&Math.abs(i.x-r.x)>.01,l=Math.abs(i.x-r.x)<.01&&Math.abs(i.y-r.y)>.01,c=Math.min(.95,Math.max(.05,e)),u;if(l){let x=o.x+(a.x-o.x)*c;u=[o,{x,y:i.y},{x,y:r.y},a]}else if(s){let x=o.y+(a.y-o.y)*c;u=[o,{x:i.x,y:x},{x:r.x,y:x},a]}else return t;for(let x=0;x<u.length-1;x++){let y={x:(u[x].x+u[x+1].x)/2,y:(u[x].y+u[x+1].y)/2};if(n.some(m=>Xe(m,y)))return t}return u}function an(t,e=[]){let n={x:t.x,y:t.y},o={x:t.x+t.width,y:t.y+t.height};return t.waypoints?.length?[n,...t.waypoints,o]:t.routing==="elbow"?ko(t,e):[n,o]}function sn(t,e=6){if(t.length<2)return"";if(t.length===2)return`M ${v(t[0].x)} ${v(t[0].y)} L ${v(t[1].x)} ${v(t[1].y)}`;let n=`M ${v(t[0].x)} ${v(t[0].y)}`;for(let i=1;i<t.length-1;i++){let r=t[i-1],a=t[i],s=t[i+1],l=Math.hypot(a.x-r.x,a.y-r.y),c=Math.hypot(s.x-a.x,s.y-a.y),u=Math.min(e,l/2,c/2);if(u<.5){n+=` L ${v(a.x)} ${v(a.y)}`;continue}let x={x:a.x-(a.x-r.x)/l*u,y:a.y-(a.y-r.y)/l*u},y={x:a.x+(s.x-a.x)/c*u,y:a.y+(s.y-a.y)/c*u};n+=` L ${v(x.x)} ${v(x.y)} Q ${v(a.x)} ${v(a.y)} ${v(y.x)} ${v(y.y)}`}let o=t[t.length-1];return`${n} L ${v(o.x)} ${v(o.y)}`}function v(t){return Number.isInteger(t)?String(t):t.toFixed(2)}function Yt(t,e,n){let o=n?1:-1;for(let i=e+o;i>=0&&i<t.length;i+=o){let r=t[e].x-t[i].x,a=t[e].y-t[i].y;if(Math.abs(r)>.01||Math.abs(a)>.01)return Math.atan2(a,r)}return 0}function De(t,e,n){let o=Math.PI/7;return[{x:t.x-n*Math.cos(e-o),y:t.y-n*Math.sin(e-o)},t,{x:t.x-n*Math.cos(e+o),y:t.y-n*Math.sin(e+o)}]}function Eo(t,e,n){let[o,i,r]=De(t,e,n);return`M ${v(o.x)} ${v(o.y)} L ${v(i.x)} ${v(i.y)} L ${v(r.x)} ${v(r.y)}`}function cn(t){let e=0;for(let n=1;n<t.length;n++)e+=Math.hypot(t[n].x-t[n-1].x,t[n].y-t[n-1].y);return e}function Ro(t,e){if(t.type!=="arrow"||e.length<2)return[];let n=cn(e);if(n<1)return[];let o=Math.min(14,4+n/4),i=e.length-1,r=[Eo(e[i],Yt(e,i,!1),o)];return t.bidirectional&&r.push(Eo(e[0],Yt(e,0,!0),o)),r}function ke(t){if(t.length===0)return{x:0,y:0};if(t.length===1)return t[0];let e=t[Math.floor((t.length-1)/2)],n=t[Math.ceil((t.length+1)/2)-1];return{x:(e.x+n.x)/2,y:(e.y+n.y)/2}}import{jsx as T,jsxs as qt}from"react/jsx-runtime";var Vt={select:T("path",{d:"M4.5 2.5l12 6.5-5.4 1.4L8.5 16.5z",fill:"currentColor",stroke:"none"}),rect:T("rect",{x:"3",y:"4.5",width:"14",height:"11",rx:"2"}),ellipse:T("ellipse",{cx:"10",cy:"10",rx:"7",ry:"5.5"}),diamond:T("path",{d:"M10 3l7 7-7 7-7-7z"}),note:T("path",{d:"M4 3.5h12v9l-3.5 3.5H4z M12.5 16v-3.5H16"}),cylinder:qt("g",{children:[T("ellipse",{cx:"10",cy:"5.5",rx:"6",ry:"2.5"}),T("path",{d:"M4 5.5v9c0 1.4 2.7 2.5 6 2.5s6-1.1 6-2.5v-9"})]}),cloud:T("path",{d:"M6 15.5a3 3 0 0 1-.5-5.95A4.5 4.5 0 0 1 14 8.3a3.6 3.6 0 0 1 .5 7.2z"}),queue:qt("g",{children:[T("path",{d:"M5.5 5.5h9M5.5 14.5h9M5.5 5.5a2.2 4.5 0 0 0 0 9"}),T("ellipse",{cx:"14.5",cy:"10",rx:"2.2",ry:"4.5"})]}),actor:qt("g",{children:[T("circle",{cx:"10",cy:"5",r:"2.2"}),T("path",{d:"M10 7.2v5M6.5 9.2h7M10 12.2l-3 4.6M10 12.2l3 4.6"})]}),arrow:T("path",{d:"M4 16L16 4M9 4h7v7"}),line:T("path",{d:"M4 16L16 4"}),text:T("path",{d:"M4 5V3.5h12V5M10 3.5V16.5M7 16.5h6"})},j={more:qt("g",{children:[T("rect",{x:"3",y:"3",width:"5.5",height:"5.5",rx:"1.2"}),T("circle",{cx:"14.25",cy:"5.75",r:"2.75"}),T("path",{d:"M5.75 11.5l2.75 5h-5.5z"}),T("path",{d:"M11.5 12h5.5v5h-5.5z"})]}),straight:T("path",{d:"M4 16L16 4"}),elbow:T("path",{d:"M4 16v-6h12V4"}),oneWay:T("path",{d:"M3 10h13M12 5.5L16.5 10L12 14.5"}),twoWay:T("path",{d:"M3.5 10h13M8 5.5L3.5 10L8 14.5M12 5.5L16.5 10L12 14.5"}),trash:T("path",{d:"M4 6h12M8 6V4h4v2M6 6l1 10h6l1-10M8.5 9v4M11.5 9v4"}),mermaid:qt("g",{children:[T("rect",{x:"3",y:"3.5",width:"5",height:"4",rx:"1"}),T("rect",{x:"12",y:"3.5",width:"5",height:"4",rx:"1"}),T("rect",{x:"7.5",y:"12.5",width:"5",height:"4",rx:"1"}),T("path",{d:"M5.5 7.5v2.5h9V7.5M10 10v2.5"})]}),check:T("path",{d:"M4 10.5l4 4 8-9"}),grip:T("path",{d:"M7 7h.01M7 10h.01M7 13h.01M10 7h.01M10 10h.01M10 13h.01M13 7h.01M13 10h.01M13 13h.01",strokeWidth:"2.2"})};function yt({children:t,size:e=16}){return T("svg",{viewBox:"0 0 20 20",width:e,height:e,fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t})}var Ee=8,Ut=3;function ln(t,e){return{x:Math.min(t.x,e.x),y:Math.min(t.y,e.y),w:Math.abs(e.x-t.x),h:Math.abs(e.y-t.y)}}function To(t,e,n){return t.filter(o=>{if(R(o.type)){let i=n.get(o.id)??[];return i.length>0&&i.every(r=>r.x>=e.x&&r.x<=e.x+e.w&&r.y>=e.y&&r.y<=e.y+e.h)}return ro(k(o),e)}).map(o=>o.id)}function dn(t,e,n){switch(e.mode){case"marquee":return t;case"draw":return t.map(o=>o.id===e.id?{...o,w:n.x-o.x,h:n.y-o.y}:o);case"move":{let o=n.x-e.origin.x,i=n.y-e.origin.y;return t.map(r=>{let a=e.origs.get(r.id);return a?{...r,x:a.x+o,y:a.y+i,waypoints:a.waypoints?.map(s=>({x:s.x+o,y:s.y+i}))}:r})}case"resize":{let o=e.orig,i=o.x+o.width,r=o.y+o.height,a=e.corner==="nw"||e.corner==="sw"?n.x:o.x,s=e.corner==="nw"||e.corner==="ne"?n.y:o.y,l=e.corner==="ne"||e.corner==="se"?n.x:i,c=e.corner==="sw"||e.corner==="se"?n.y:r;return t.map(u=>u.id===e.id?{...u,x:a,y:s,width:l-a,height:c-s}:u)}case"endpoint":{let o=e.orig;return t.map(i=>i.id!==e.id?i:e.end==="start"?{...i,x:n.x,y:n.y,width:o.x+o.width-n.x,height:o.y+o.height-n.y}:{...i,width:n.x-o.x,height:n.y-o.y})}case"elbow":{let o=e.vertical?e.d.x-e.a.x:e.d.y-e.a.y;if(Math.abs(o)<1)return t;let i=e.vertical?(n.x-e.a.x)/o:(n.y-e.a.y)/o,r=Math.round(Math.min(.95,Math.max(.05,i))*1e3)/1e3;return t.map(a=>a.id===e.id?{...a,elbow:r}:a)}case"waypoint":return t.map(o=>{if(o.id!==e.id||!o.waypoints)return o;let i=o.waypoints;if(e.index<0||e.index>=i.length)return o;let r=e.index===0?{x:o.x,y:o.y}:i[e.index-1],a=e.index===i.length-1?{x:o.x+o.width,y:o.y+o.height}:i[e.index+1],s=n.x,l=n.y;Math.abs(s-r.x)<Ee?s=r.x:Math.abs(s-a.x)<Ee&&(s=a.x),Math.abs(l-r.y)<Ee?l=r.y:Math.abs(l-a.y)<Ee&&(l=a.y);let c=[...i];return c[e.index]={x:s,y:l},{...o,waypoints:c}})}}function un(t,e,n){let o=e.has(n)?e:new Set([n]);return new Map(t.filter(i=>o.has(i.id)).map(i=>[i.id,i]))}import{jsx as J,jsxs as yn}from"react/jsx-runtime";var mr=Object.keys(Z);function wr({name:t,active:e,onClick:n}){let o=Z[t],i=K().drawing.color(t);return J("button",{type:"button",title:i,"aria-label":i,"aria-pressed":e,className:`zui-drawing-swatch ${e?"is-active":""}`,style:{backgroundColor:o.fill,borderColor:o.stroke},onClick:n})}function Xt({label:t,active:e,onClick:n,children:o,className:i}){return J("button",{type:"button",title:t,"aria-label":t,"aria-pressed":e,className:`zui-drawing-tool ${e?"is-active":""} ${i??""}`,onClick:n,children:J(yt,{children:o})})}function No({selection:t,stroke:e,fill:n,onColor:o,onRouting:i,onDirection:r,onDelete:a}){let s=t.filter(g=>R(g.type)),l=t.filter(g=>g.type==="arrow"),c=s.length>0&&s.every(g=>g.routing==="elbow"),u=s.length>0&&s.every(g=>g.routing!=="elbow"),x=l.length>0&&l.every(g=>g.bidirectional),y=l.length>0&&l.every(g=>!g.bidirectional),m=K().drawing;return yn("div",{className:"zui-drawing-props",onPointerDown:g=>g.stopPropagation(),children:[J("div",{className:"zui-drawing-props-group",role:"radiogroup","aria-label":m.colors,children:mr.map(g=>J(wr,{name:g,active:Z[g].stroke===e&&Z[g].fill===n,onClick:()=>o(g)},g))}),s.length>0&&yn("div",{className:"zui-drawing-props-group","aria-label":m.connectorRouting,children:[J(Xt,{label:m.straight,active:u,onClick:()=>i(!1),children:j.straight}),J(Xt,{label:m.elbow,active:c,onClick:()=>i(!0),children:j.elbow})]}),l.length>0&&yn("div",{className:"zui-drawing-props-group","aria-label":m.arrowDirection,children:[J(Xt,{label:m.oneWay,active:y,onClick:()=>r(!1),children:j.oneWay}),J(Xt,{label:m.twoWay,active:x,onClick:()=>r(!0),children:j.twoWay})]}),t.length>0&&J("div",{className:"zui-drawing-props-group",children:J(Xt,{label:t.length>1?m.deleteShapes(t.length):m.deleteShape,className:"zui-drawing-tool-danger",onClick:a,children:j.trash})})]})}import{jsx as B,jsxs as pn}from"react/jsx-runtime";var Zt=7;function Re({x:t,y:e,cursor:n,square:o,onPointerDown:i,title:r}){let a={className:"zui-drawing-handle",strokeWidth:1.5,style:{cursor:n},onPointerDown:i};return o?B("rect",{...a,x:t-Zt/2,y:e-Zt/2,width:Zt,height:Zt,rx:2,children:r&&B("title",{children:r})}):B("circle",{...a,cx:t,cy:e,r:Zt/2+.5,children:r&&B("title",{children:r})})}function Co({shape:t,points:e,onHandlePointerDown:n,onWaypointAdd:o,onWaypointRemove:i}){let r=K().drawing;if(R(t.type)){let u=t.waypoints??[],x=t.routing==="elbow"&&!u.length&&e.length===4,y=x?{x:(e[1].x+e[2].x)/2,y:(e[1].y+e[2].y)/2}:null,m=x&&Math.abs(e[1].x-e[2].x)<.01,g=e.slice(0,-1).flatMap((d,f)=>{let P=e[f+1];return Math.hypot(P.x-d.x,P.y-d.y)<28?[]:x&&f===1?[]:[{index:f,x:(d.x+P.x)/2,y:(d.y+P.y)/2}]});return pn("g",{className:"zui-drawing-selection",children:[g.map(({index:d,x:f,y:P})=>B("circle",{className:"zui-drawing-handle zui-drawing-ghost",cx:f,cy:P,r:4.5,strokeWidth:1.5,strokeDasharray:"2 2",style:{cursor:"copy"},onPointerDown:S=>o(S,t.id,d,{x:f,y:P}),children:B("title",{children:"Drag to add a bend"})},`ghost-${d}`)),u.map((d,f)=>B("g",{onDoubleClick:P=>{P.stopPropagation(),i(t.id,f)},children:B(Re,{x:d.x,y:d.y,square:!0,cursor:"move",title:r.waypoint,onPointerDown:P=>n(P,{mode:"waypoint",id:t.id,index:f})})},`wp-${f}`)),y&&B(Re,{x:y.x,y:y.y,square:!0,cursor:m?"ew-resize":"ns-resize",title:r.elbowHandle,onPointerDown:d=>n(d,{mode:"elbow",id:t.id,a:e[0],d:e[3],vertical:m})}),["start","end"].map(d=>{let f=d==="start"?e[0]:e[e.length-1];return B(Re,{x:f.x,y:f.y,cursor:"crosshair",onPointerDown:P=>n(P,{mode:"endpoint",id:t.id,end:d,orig:t})},d)})]})}let a=k(t),s=5,l=[{corner:"nw",x:a.x-s,y:a.y-s},{corner:"ne",x:a.x+a.w+s,y:a.y-s},{corner:"sw",x:a.x-s,y:a.y+a.h+s},{corner:"se",x:a.x+a.w+s,y:a.y+a.h+s}],c=t.type!=="text";return pn("g",{className:"zui-drawing-selection",children:[B(vo,{rect:a,pad:s}),c&&l.map(({corner:u,x,y})=>B(Re,{x,y,square:!0,cursor:u==="nw"||u==="se"?"nwse-resize":"nesw-resize",onPointerDown:m=>n(m,{mode:"resize",id:t.id,corner:u,orig:t})},u))]})}function vo({rect:t,pad:e}){return B("rect",{x:t.x-e,y:t.y-e,width:t.w+e*2,height:t.h+e*2,rx:6,fill:"none",stroke:"currentColor",strokeWidth:1,strokeDasharray:"5 4",pointerEvents:"none"})}function Oo({shapes:t,paths:e}){if(!t.length)return null;let n=t.map(o=>{if(!R(o.type))return k(o);let i=e.get(o.id)??[],r=i.map(c=>c.x),a=i.map(c=>c.y),s=Math.min(...r),l=Math.min(...a);return{x:s,y:l,w:Math.max(...r)-s,h:Math.max(...a)-l}});return pn("g",{className:"zui-drawing-selection",pointerEvents:"none",children:[n.map((o,i)=>B("rect",{x:o.x-3,y:o.y-3,width:o.w+6,height:o.h+6,rx:4,fill:"none",stroke:"currentColor",strokeWidth:1,opacity:.45},t[i].id)),B(vo,{rect:Lt(n),pad:8})]})}function Io({rect:t}){return B("rect",{className:"zui-drawing-selection",x:t.x,y:t.y,width:t.w,height:t.h,rx:3,fill:"currentColor",fillOpacity:.08,stroke:"currentColor",strokeWidth:1,pointerEvents:"none"})}import{jsx as q,jsxs as Te}from"react/jsx-runtime";var D=t=>Number.isInteger(t)?String(t):t.toFixed(2);function _o({shape:t,stroke:e}){let n=k(t),o=t.fill;switch(t.type){case"rect":return q("rect",{...e,x:n.x,y:n.y,width:n.w,height:n.h,rx:Math.min(8,n.w/4,n.h/4),fill:o});case"ellipse":return q("ellipse",{...e,cx:n.x+n.w/2,cy:n.y+n.h/2,rx:n.w/2,ry:n.h/2,fill:o});case"diamond":return q("polygon",{...e,points:`${D(n.x+n.w/2)},${D(n.y)} ${D(n.x+n.w)},${D(n.y+n.h/2)} ${D(n.x+n.w/2)},${D(n.y+n.h)} ${D(n.x)},${D(n.y+n.h/2)}`,fill:o});case"note":{let i=Et(n),r=n.x+n.w,a=n.y+n.h;return Te("g",{children:[q("path",{...e,d:`M ${D(n.x)} ${D(n.y)} H ${D(r)} V ${D(a-i)} L ${D(r-i)} ${D(a)} H ${D(n.x)} Z`,fill:o}),q("path",{...e,d:`M ${D(r-i)} ${D(a)} V ${D(a-i)} H ${D(r)}`,fill:"rgba(0,0,0,0.08)"})]})}case"cylinder":{let i=Rt(n),r=n.w/2,a=n.x+r;return Te("g",{children:[q("path",{...e,d:`M ${D(n.x)} ${D(n.y+i)} V ${D(n.y+n.h-i)} A ${D(r)} ${D(i)} 0 0 0 ${D(n.x+n.w)} ${D(n.y+n.h-i)} V ${D(n.y+i)}`,fill:o}),q("ellipse",{...e,cx:a,cy:n.y+i,rx:r,ry:i,fill:o})]})}case"cloud":{let i=(r,a)=>`${D(n.x+r*n.w)} ${D(n.y+a*n.h)}`;return q("path",{...e,d:`M ${i(.22,.86)} C ${i(.04,.88)} ${i(0,.58)} ${i(.16,.5)} C ${i(.08,.26)} ${i(.3,.12)} ${i(.42,.28)} C ${i(.5,.02)} ${i(.76,.04)} ${i(.78,.3)} C ${i(.98,.26)} ${i(1.04,.56)} ${i(.88,.64)} C ${i(1,.8)} ${i(.9,.9)} ${i(.76,.86)} Z`,fill:o})}case"queue":{let i=Tt(n),r=n.h/2;return Te("g",{children:[q("path",{...e,d:`M ${D(n.x+i)} ${D(n.y)} H ${D(n.x+n.w-i)} V ${D(n.y+n.h)} H ${D(n.x+i)} A ${D(i)} ${D(r)} 0 0 1 ${D(n.x+i)} ${D(n.y)} Z`,fill:o}),q("ellipse",{...e,cx:n.x+n.w-i,cy:n.y+r,rx:i,ry:r,fill:o})]})}case"actor":{let i=n.h*Ht,r=n.x+n.w/2,a=Math.max(4,Math.min(i*.16,n.w*.2)),s=n.y+a*2,l=n.y+i*.62,c=s+i*.12,u=Math.min(n.w*.32,i*.3);return Te("g",{children:[q("circle",{...e,cx:r,cy:n.y+a,r:a,fill:o}),q("path",{...e,fill:"none",d:`M ${D(r)} ${D(s)} V ${D(l)} M ${D(r-u)} ${D(c)} H ${D(r+u)} M ${D(r)} ${D(l)} L ${D(r-u)} ${D(n.y+i)} M ${D(r)} ${D(l)} L ${D(r+u)} ${D(n.y+i)}`})]})}default:return null}}function fn(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return e>>>0}function Bo(t){let e=t>>>0;return()=>{e=e+1831565813|0;let n=Math.imul(e^e>>>15,1|e);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}function $o(t){return Math.min(4,Math.max(1,t*.03))}function Lo(t){let e=Bo(t^2654435769),n=e()*Math.PI*2,o=2+e();return{x:Math.cos(n)*o,y:Math.sin(n)*o}}function br(t,e,n){let o=Bo(t),i=(g,d)=>g+Math.floor(o()*d),r=n?i(2,2):1.5+o(),a=n?i(5,3):3+o()*2,s=n?i(2,2):1+o(),l=o()*Math.PI*2,c=o()*Math.PI*2,u=o()*Math.PI*2,x=e*(.55+o()*.15),y=e*.3,m=Math.PI*2;return{offset:g=>x*Math.sin(m*r*g+l)+y*Math.sin(m*a*g+c),pressure:g=>1+.3*Math.sin(m*s*g+u)}}function Sr(t,e){let n=e?[...t,t[0]]:[...t],o=[],i=0;for(let l=1;l<n.length;l++){let c=Math.hypot(n[l].x-n[l-1].x,n[l].y-n[l-1].y);o.push(c),i+=c}if(i===0)return{points:[n[0]],ts:[0]};let r=[],a=[],s=0;for(let l=1;l<n.length;l++){let c=n[l-1],u=n[l],x=o[l-1],y=Math.max(1,Math.round(x/5));for(let m=0;m<y;m++){let g=m/y;r.push({x:c.x+(u.x-c.x)*g,y:c.y+(u.y-c.y)*g}),a.push((s+x*g)/i)}s+=x}return e||(r.push(n[n.length-1]),a.push(1)),{points:r,ts:a}}function Mr(t,e,n){let o=t.length,i=t[n?(e-1+o)%o:Math.max(0,e-1)],r=t[n?(e+1)%o:Math.min(o-1,e+1)],a=r.x-i.x,s=r.y-i.y,l=Math.hypot(a,s)||1;return{x:-s/l,y:a/l}}var Ao=t=>Number.isInteger(t)?String(t):t.toFixed(2),Nt=t=>t.map((e,n)=>`${n===0?"M":"L"} ${Ao(e.x)} ${Ao(e.y)}`).join(" ");function Ct(t,e){if(t.length<2)return{ring:"",center:""};let{closed:n,seed:o,width:i,amplitude:r}=e,a=br(o,r,n),{points:s,ts:l}=Sr(t,n);if(s.length<2)return{ring:"",center:""};let c=[],u=[],x=[];for(let y=0;y<s.length;y++){let m=l[y],g=Mr(s,y,n),d=a.offset(m),f={x:s[y].x+g.x*d,y:s[y].y+g.y*d},P=n?1:.55+.45*Math.min(1,m/.1,(1-m)/.1),S=i*a.pressure(m)*P/2;c.push(f),u.push({x:f.x+g.x*S,y:f.y+g.y*S}),x.push({x:f.x-g.x*S,y:f.y-g.y*S})}return n?{ring:`${Nt(u)} Z ${Nt([...x].reverse())} Z`,center:`${Nt(c)} Z`}:{ring:`${Nt(u)} ${Nt([...x].reverse()).replace(/^M/,"L")} Z`,center:Nt(c)}}function zo(t,e,n=4){let o=Math.min(e,t.w/2,t.h/2);if(o<=0)return[{x:t.x,y:t.y},{x:t.x+t.w,y:t.y},{x:t.x+t.w,y:t.y+t.h},{x:t.x,y:t.y+t.h}];let i=[[t.x+t.w-o,t.y+o,-Math.PI/2],[t.x+t.w-o,t.y+t.h-o,0],[t.x+o,t.y+t.h-o,Math.PI/2],[t.x+o,t.y+o,Math.PI]],r=[];for(let[a,s,l]of i)for(let c=0;c<=n;c++){let u=l+Math.PI/2*(c/n);r.push({x:a+o*Math.cos(u),y:s+o*Math.sin(u)})}return r}function Ho(t,e=6,n=4){if(t.length<3)return[...t];let o=[t[0]];for(let i=1;i<t.length-1;i++){let r=t[i-1],a=t[i],s=t[i+1],l=Math.hypot(a.x-r.x,a.y-r.y),c=Math.hypot(s.x-a.x,s.y-a.y),u=Math.min(e,l/2,c/2);if(u<.5){o.push(a);continue}let x={x:a.x-(a.x-r.x)/l*u,y:a.y-(a.y-r.y)/l*u},y={x:a.x+(s.x-a.x)/c*u,y:a.y+(s.y-a.y)/c*u};for(let m=0;m<=n;m++){let g=m/n,d=1-g;o.push({x:d*d*x.x+2*d*g*a.x+g*g*y.x,y:d*d*x.y+2*d*g*a.y+g*g*y.y})}}return o.push(t[t.length-1]),o}function Wo(t,e,n,o,i=10){let r=[];for(let a=1;a<=i;a++){let s=a/i,l=1-s;r.push({x:l*l*l*t.x+3*l*l*s*e.x+3*l*s*s*n.x+s*s*s*o.x,y:l*l*l*t.y+3*l*l*s*e.y+3*l*s*s*n.y+s*s*s*o.y})}return r}function hn(t,e,n,o,i,r,a=12){return Array.from({length:a+1},(s,l)=>{let c=i+(r-i)*l/a;return{x:t+n*Math.cos(c),y:e+o*Math.sin(c)}})}import{jsx as pt,jsxs as vt}from"react/jsx-runtime";var Ne=t=>Number.isInteger(t)?String(t):t.toFixed(2);function Fo(t){let e=1/0,n=1/0,o=-1/0,i=-1/0;for(let r of t)r.x<e&&(e=r.x),r.x>o&&(o=r.x),r.y<n&&(n=r.y),r.y>i&&(i=r.y);return{w:o-e,h:i-n}}function Go({shape:t}){let e=k(t),n=fn(t.id),o=t.strokeWidth,i=Lo(n),r=`translate(${Ne(i.x)} ${Ne(i.y)})`,a=c=>$o(Math.min(Fo(c).w,Fo(c).h)),s=(c,u,x=t.fill)=>{let y=Ct(c,{closed:!0,seed:n+u,width:o,amplitude:a(c)});return vt("g",{children:[pt("path",{d:y.center,fill:x,stroke:"none",transform:r}),pt("path",{d:y.ring,fill:t.stroke,fillRule:"evenodd",stroke:"none"})]})},l=(c,u,x=o)=>pt("path",{d:Ct(c,{closed:!1,seed:n+u,width:x,amplitude:a(c)}).ring,fill:t.stroke,stroke:"none"});switch(t.type){case"rect":return s(zo(e,Math.min(8,e.w/4,e.h/4)),0);case"ellipse":return s(ut(e,64),0);case"diamond":return s([{x:e.x+e.w/2,y:e.y},{x:e.x+e.w,y:e.y+e.h/2},{x:e.x+e.w/2,y:e.y+e.h},{x:e.x,y:e.y+e.h/2}],0);case"note":{let c=Et(e),u=e.x+e.w,x=e.y+e.h,y=[{x:e.x,y:e.y},{x:u,y:e.y},{x:u,y:x-c},{x:u-c,y:x},{x:e.x,y:x}],m=[{x:u-c,y:x},{x:u-c,y:x-c},{x:u,y:x-c}];return vt("g",{children:[s(y,0),pt("path",{d:`M ${m.map(g=>`${Ne(g.x)} ${Ne(g.y)}`).join(" L ")} Z`,fill:"rgba(0,0,0,0.08)",stroke:"none"}),l(m,1)]})}case"cylinder":{let c=Rt(e),u=e.w/2,x=e.x+u,y=[{x:e.x,y:e.y+c},{x:e.x,y:e.y+e.h-c},...hn(x,e.y+e.h-c,u,c,Math.PI,0,16),{x:e.x+e.w,y:e.y+c}],m=Ct(y,{closed:!1,seed:n+0,width:o,amplitude:a(y)});return vt("g",{children:[pt("path",{d:`${m.center} Z`,fill:t.fill,stroke:"none",transform:r}),pt("path",{d:m.ring,fill:t.stroke,stroke:"none"}),s(ut({x:e.x,y:e.y,w:e.w,h:c*2},48),1)]})}case"cloud":{let c=(g,d)=>({x:e.x+g*e.w,y:e.y+d*e.h}),u=c(.22,.86),x=[[c(.04,.88),c(0,.58),c(.16,.5)],[c(.08,.26),c(.3,.12),c(.42,.28)],[c(.5,.02),c(.76,.04),c(.78,.3)],[c(.98,.26),c(1.04,.56),c(.88,.64)],[c(1,.8),c(.9,.9),c(.76,.86)]],y=[u],m=u;for(let[g,d,f]of x)y.push(...Wo(m,g,d,f,8)),m=f;return s(y,0)}case"queue":{let c=Tt(e),u=e.h/2,x=[{x:e.x+c,y:e.y},{x:e.x+e.w-c,y:e.y},{x:e.x+e.w-c,y:e.y+e.h},{x:e.x+c,y:e.y+e.h},...hn(e.x+c,e.y+u,c,u,Math.PI/2,3*Math.PI/2,16).slice(1,-1)];return vt("g",{children:[s(x,0),s(ut({x:e.x+e.w-c*2,y:e.y,w:c*2,h:e.h},48),1)]})}case"actor":{let c=e.h*Ht,u=e.x+e.w/2,x=Math.max(4,Math.min(c*.16,e.w*.2)),y=e.y+x*2,m=e.y+c*.62,g=y+c*.12,d=Math.min(e.w*.32,c*.3);return vt("g",{children:[s(ut({x:u-x,y:e.y,w:x*2,h:x*2},32),0),l([{x:u,y},{x:u,y:m}],1),l([{x:u-d,y:g},{x:u+d,y:g}],2),l([{x:u-d,y:e.y+c},{x:u,y:m},{x:u+d,y:e.y+c}],3)]})}default:return null}}function Ko({shape:t,points:e}){if(e.length<2)return null;let n=fn(t.id),o=cn(e),i=Math.min(3,Math.max(.8,o*.015)),r=t.strokeWidth,a=Ct(Ho(e),{closed:!1,seed:n,width:r,amplitude:i}),s=[];if(t.type==="arrow"&&o>=1){let l=Math.min(14,4+o/4),c=e.length-1;s.push(De(e[c],Yt(e,c,!1),l)),t.bidirectional&&s.push(De(e[0],Yt(e,0,!0),l))}return vt("g",{fill:t.stroke,stroke:"none",children:[pt("path",{d:a.ring}),s.map((l,c)=>pt("path",{d:Ct(l,{closed:!1,seed:n+1+c,width:r*1.15,amplitude:.8}).ring},c))]})}import{Fragment as Er,jsx as $,jsxs as jt}from"react/jsx-runtime";import{createElement as gn}from"react";var st=12,mn=160;function ve(t){let e=me(t);return{area:e?e.textArea(t):k(t),slots:e?e.textSlots:["label","text","footer"]}}function wn(t,e){let{area:n,slots:o}=ve(t),i=(e-n.y)/Math.max(n.h,1);return i<.3&&o.includes("label")?"label":i>.7&&o.includes("footer")?"footer":o.includes("text")?"text":o[0]}var Ce={userSelect:"none"};function Pr(t){let e=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t);if(!e)return 1;let n=e[1].length===3?e[1].replace(/./g,a=>a+a):e[1],[o,i,r]=[0,2,4].map(a=>parseInt(n.slice(a,a+2),16)/255);return .2126*o+.7152*i+.0722*r}function bn(t){return t.stroke==="transparent"||t.stroke==="none"?"#1e1e1e":Pr(t.fill)<.35?"#ffffff":t.stroke}var xn={userSelect:"none",pointerEvents:"none"};function Dr({shape:t,hideField:e,showHints:n}){let{area:o,slots:i}=ve(t),r=o.x+o.w/2,a=Math.max(o.w,20),s=n&&o.h>=56&&o.w>=44,l=ot(t.text??"",a,I),c=ot(t.label??"",a,H),u=ot(t.footer??"",a,H),x=I*et,y=H*et,m=o.y+o.h/2-(l.length-1)*x/2+I*.35,g={fill:bn(t),textAnchor:"middle"};return jt("g",{children:[i.includes("label")&&e!=="label"&&(t.label?c.map((d,f)=>gn("text",{...g,key:f,x:r,y:o.y+H+f*y,fontSize:H,fontWeight:600,letterSpacing:.3,opacity:.85,style:Ce},d)):s&&$("text",{...g,x:r,y:o.y+H,fontSize:H,opacity:.3,style:xn,children:"Label"})),i.includes("text")&&e!=="text"&&(t.text?l.map((d,f)=>gn("text",{...g,key:f,x:r,y:m+f*x,fontSize:I,style:Ce},d)):s&&$("text",{...g,x:r,y:m,fontSize:I,opacity:.3,style:xn,children:"Text"})),i.includes("footer")&&e!=="footer"&&(t.footer?u.map((d,f)=>gn("text",{...g,key:f,x:r,y:o.y+o.h-3-(u.length-1-f)*y,fontSize:H,opacity:.65,style:Ce},d)):s&&$("text",{...g,x:r,y:o.y+o.h-3,fontSize:H,opacity:.3,style:xn,children:"Footer"}))]})}function kr({shape:t,points:e}){let n=t.text??"",o=ot(n,mn,st),i=X(o.join(`
|
|
8
|
+
`),st),{x:r,y:a}=ke(e),s=st*et,l=a-(o.length-1)*s/2+st*.35;return jt("g",{children:[$("rect",{x:r-i.w/2-5,y:a-i.h/2-3,width:i.w+10,height:i.h+6,rx:5,className:"zui-drawing-label-plate",opacity:.94}),o.map((c,u)=>$("text",{x:r,y:l+u*s,fill:t.stroke,fontSize:st,textAnchor:"middle",style:Ce,children:c},u))]})}function Yo({shape:t,points:e,hideField:n,showHints:o,ink:i=!1}){let r={stroke:t.stroke,strokeWidth:t.strokeWidth,strokeLinecap:"round",strokeLinejoin:"round"};if(A(t.type))return jt("g",{children:[i?$(Go,{shape:t}):$(_o,{shape:t,stroke:r}),$(Dr,{shape:t,hideField:n,showHints:o})]});if(R(t.type)){let a=e??[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y+t.height}];return jt("g",{children:[i?$(Ko,{shape:t,points:a}):jt(Er,{children:[$("path",{...r,d:sn(a),fill:"none"}),Ro(t,a).map((s,l)=>$("path",{...r,d:s,fill:"none"},l))]}),t.text&&n!=="text"&&$(kr,{shape:t,points:a})]})}return $("text",{x:t.x,y:t.y+I,fill:t.stroke,fontSize:I,style:{userSelect:"none",whiteSpace:"pre"},children:(t.text??"").split(`
|
|
9
|
+
`).map((a,s)=>$("tspan",{x:t.x,dy:s===0?0:I*et,children:a},s))})}function qo({shape:t,points:e}){if(R(t.type)&&e)return $("path",{d:sn(e),fill:"none",stroke:"transparent",strokeWidth:16});let n=k(t);return $("rect",{x:n.x-2,y:n.y-2,width:Math.max(n.w,8)+4,height:Math.max(n.h,8)+4,fill:"transparent",stroke:"none"})}import{useEffect as Rr,useRef as Vo,useState as Tr}from"react";import{jsx as Nr}from"react/jsx-runtime";function Uo({shape:t,field:e,points:n,onCommit:o}){let i=t[e]??"",[r,a]=Tr(i),s=Vo(null),l=Vo(r);l.current=r,Rr(()=>{let y=s.current;if(!y)return;y.focus(),y.select();let m=d=>{if(d.stopPropagation(),(d.key==="Home"||d.key==="End")&&!d.shiftKey&&!d.metaKey&&!d.ctrlKey){d.preventDefault();let f=y.value,P=d.key==="Home"?y.selectionStart:y.selectionEnd,S=d.key==="Home"?f.lastIndexOf(`
|
|
10
|
+
`,P-1)+1:(f.indexOf(`
|
|
11
|
+
`,P)+1||f.length+1)-1;y.setSelectionRange(S,S);return}d.key==="Enter"&&!d.shiftKey?(d.preventDefault(),o(t.id,e,l.current)):d.key==="Escape"&&(d.preventDefault(),o(t.id,e,i))},g=d=>d.stopPropagation();return y.addEventListener("keydown",m),y.addEventListener("keyup",g),y.addEventListener("keypress",g),()=>{y.removeEventListener("keydown",m),y.removeEventListener("keyup",g),y.removeEventListener("keypress",g)}},[]);let c={color:bn(t),fontFamily:"var(--zui-drawing-font)",lineHeight:et};if(t.type==="text"){let y=X(r||" ");Object.assign(c,{left:t.x,top:t.y,fontSize:I,width:Math.max(80,y.w+20),height:y.h+2,whiteSpace:"pre-wrap"})}else if(R(t.type)){let y=ot(r,mn,st),m=X(y.join(`
|
|
12
|
+
`)||" ",st),g=Math.max(70,m.w+16),d=m.h+4,f=ke(n??[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y+t.height}]);Object.assign(c,{left:f.x-g/2,top:f.y-d/2,width:g,height:d,fontSize:st,textAlign:"center",whiteSpace:"pre-wrap"})}else{let{area:y}=ve(t),m=e==="text"?I:H,g=Math.max(y.w,40),f=ot(r,g,m).length*m*et+2,P=e==="label"?y.y-1:e==="footer"?y.y+y.h-f+1:y.y+y.h/2-f/2;Object.assign(c,{left:y.x,top:P,width:g,height:f,fontSize:m,fontWeight:e==="label"?600:void 0,letterSpacing:e==="label"?.3:void 0,opacity:e==="text"?1:e==="label"?.85:.65,textAlign:"center",whiteSpace:"pre-wrap"})}let u=K().drawing,x=e==="label"?u.labelPlaceholder:e==="footer"?u.footerPlaceholder:u.textPlaceholder;return Nr("textarea",{ref:s,className:"zui-drawing-text-input",style:c,value:r,placeholder:x,spellCheck:!1,onChange:y=>a(y.target.value),onBlur:()=>o(t.id,e,r),onPointerDown:y=>y.stopPropagation()})}import{useEffect as Cr,useRef as vr,useState as Sn}from"react";import{Fragment as Ir,jsx as Q,jsxs as Ot}from"react/jsx-runtime";var Or=[{tool:"select",label:"select"},{tool:"rect",label:"rect"},{tool:"ellipse",label:"ellipse"},{tool:"diamond",label:"diamond"},{tool:"arrow",label:"arrow"},{tool:"line",label:"line"},{tool:"text",label:"text"}],Xo=["note","cylinder","cloud","queue","actor"];function Mn({label:t,active:e,onClick:n,children:o,className:i,pressed:r}){return Q("button",{type:"button",title:t,"aria-label":t,"aria-pressed":r??e,className:`zui-drawing-tool ${e?"is-active":""} ${i??""}`,onClick:n,[He]:"",children:Q(yt,{children:o})})}function Zo({tool:t,onToolChange:e,width:n,onWidthChange:o,onCopyMermaid:i,properties:r}){let[a,s]=Sn(!1),[l,c]=Sn("note"),[u,x]=Sn(!1),y=vr(null),m=Yn(),g=K(),d=g.drawing;Cr(()=>{if(!a)return;let S=_=>{y.current?.contains(_.target)||s(!1)},F=_=>{_.key==="Escape"&&s(!1)};return document.addEventListener("pointerdown",S),document.addEventListener("keydown",F),()=>{document.removeEventListener("pointerdown",S),document.removeEventListener("keydown",F)}},[a]);let f=Xo.includes(t),P=f?Vt[t]:Vt[l];return Ot(Ir,{children:[Ot("div",{className:"zui-drawing-toolbar-group",role:"toolbar","aria-label":d.tools,...m,children:[Or.map(({tool:S,label:F})=>Q(Mn,{label:d[F],active:t===S,onClick:()=>e(S),children:Vt[S]},S)),Ot("div",{className:"zui-drawing-more",ref:y,children:[Ot("button",{type:"button",title:d.moreShapes,"aria-label":d.moreShapes,"aria-haspopup":"menu","aria-expanded":a,className:`zui-drawing-tool zui-drawing-tool-more ${f?"is-active":""}`,onClick:()=>s(S=>!S),[He]:"",children:[Q(yt,{children:P}),Q("span",{className:"zui-drawing-caret","aria-hidden":"true"})]}),a&&Q("div",{className:"zui-drawing-popover",role:"menu",children:Xo.map(S=>Ot("button",{type:"button",role:"menuitemradio","aria-checked":t===S,className:`zui-drawing-popover-item ${t===S?"is-active":""}`,onClick:()=>{c(S),e(S),s(!1)},children:[Q(yt,{size:18,children:Vt[S]}),Q("span",{children:d[S]})]},S))})]})]}),r,Ot("div",{className:"zui-drawing-toolbar-group zui-drawing-toolbar-group-end",children:[Q(Mn,{label:u?d.copiedMermaid:d.copyMermaid,className:u?"is-success":"",onClick:()=>{i().then(S=>{S&&(x(!0),setTimeout(()=>x(!1),1600))})},children:u?j.check:j.mermaid}),Q("span",{className:"zui-drawing-toolbar-divider"}),Gn.map(({preset:S,label:F,icon:_,width:ct})=>Q(Mn,{label:g.layout[F],active:Kn(n)===S,onClick:()=>o(ct),children:_},S))]})]})}import{jsx as L,jsxs as Ie}from"react/jsx-runtime";var Lr=120,zr=1200,Hr={full:"",text:"is-text-width",content:"is-content-width"},Wr=240,Fr=40,bt=new Set;function jo(t,e){let n=0;for(let o of t)if(R(o.type))for(let i of e.get(o.id)??[])n=Math.max(n,i.x);else{let i=k(o);n=Math.max(n,i.x+i.w)}return Math.max(Wr,Math.ceil(n+Fr))}function Jo(t){let e=new Map;for(let n of t)R(n.type)&&e.set(n.id,an(n,t));return e}function Dn({nodeKey:t,data:e}){let[n]=Br(),o=$r(),[i,r]=V(e.shapes),[a,s]=V(e.canvasHeight),[l,c]=V(e.width??"full"),u=_r(zn)?.drawingStyle==="ink",x=K().drawing,[y,m]=V("select"),[g,d]=V(bt),[f,P]=V(null),[S,F]=V(Dt[0]),[_,ct]=V(Qn[0]),[_t,Rn]=V(null),[_e,Tn]=V(null),[Nn,Cn]=V(1),Qt=z(null),te=z(null),tt=z(null),ee=z(null),Ae=z(null),St=z(null),ne=z(Y(e)),G=z(i);G.current=i;let Be=z(a);Be.current=a;let vn=z(l);vn.current=l;let At=z(g);At.current=g;let lt=Pn(()=>Jo(i),[i]),oe=e.canvasWidth,On=z(null),[In,ni]=V(null);Oe(()=>{let p=On.current;if(!p||typeof ResizeObserver>"u")return;let h=()=>ni(p.clientWidth||null);h();let b=new ResizeObserver(h);return b.observe(p),()=>b.disconnect()},[]);let _n=Pn(()=>jo(e.shapes,Jo(e.shapes)),[e.shapes]),oi=In!==null&&_n>In?_n:null,U=oe??(l==="content"?jo(i,lt):oi);Oe(()=>{let p=Y(e);p!==ne.current&&(ne.current=p,r(e.shapes),s(e.canvasHeight),c(e.width??"full"),d(bt),P(null))},[e]),Oe(()=>{let p=te.current;if(!U||!p||typeof ResizeObserver>"u"){Cn(1);return}let h=()=>{let w=p.getBoundingClientRect();Cn(w.width>0?w.width/U:1)};h();let b=new ResizeObserver(h);return b.observe(p),()=>b.disconnect()},[U]);let Bt=O((p,h)=>{let b=h?.width??vn.current,w=h?.width===void 0&&e.width!==void 0,M={version:3,...oe?{canvasWidth:oe}:{},canvasHeight:h?.height??Be.current,...b!=="full"||w?{width:b}:{},...e.title?{title:e.title}:{},...e.description?{description:e.description}:{},shapes:p},E=Y(M);E!==ne.current&&(ne.current=E,n.update(()=>{let N=Ar(t);kn(N)&&N.setData(M)}))},[n,t,oe,e.width,e.title,e.description]),C=O((p,h)=>{r(b=>{let w=be(p(b));return h?.commit&&Bt(w),w})},[Bt]),it=O(p=>{let h=te.current;if(!h)return{x:0,y:0};let b=h.getScreenCTM();if(!b){let M=h.getBoundingClientRect();return{x:p.clientX-M.left,y:p.clientY-M.top}}let w=b.inverse();return{x:w.a*p.clientX+w.c*p.clientY+w.e,y:w.b*p.clientX+w.d*p.clientY+w.f}},[]),ht=Pn(()=>i.filter(p=>g.has(p.id)),[i,g]),Mt=ht.length===1?ht[0]:null,rt=O((p,h)=>{P({id:p,field:h}),d(new Set([p]))},[]),ie=p=>{te.current?.setPointerCapture(p.pointerId)},ii=O(p=>{if(!o||f||p.button!==0)return;let h=it(p);if(ie(p),y==="select"){p.shiftKey||d(bt),tt.current={mode:"marquee",origin:h,current:h,additive:p.shiftKey};return}if(y==="text"){let E=Ke(),N=X("");C(dt=>[...dt,{id:E,type:"text",x:h.x,y:h.y-I/2,width:N.w,height:N.h,stroke:S,fill:"transparent",strokeWidth:2,text:""}]),m("select"),d(new Set([E])),ee.current=E;return}let b=Ke(),w=A(y)?gt[y]:null,M=w?_==="transparent"&&w.defaultFill?w.defaultFill:_:"transparent";tt.current={mode:"draw",id:b,origin:h},d(bt),C(E=>[...E,{id:b,type:y,x:h.x,y:h.y,width:0,height:0,stroke:S,fill:M,strokeWidth:2}])},[o,f,it,y,S,_,C,rt]),ri=O((p,h)=>{if(!o||y!=="select"||f||p.button!==0)return;p.stopPropagation();let b=it(p);ie(p);let w=At.current;if(p.shiftKey){if(w.has(h.id)){let dt=new Set(w);dt.delete(h.id),d(dt);return}let N=new Set(w).add(h.id);d(N),tt.current={mode:"move",clickedId:h.id,origin:b,origs:un(G.current,N,h.id),wasSelected:!1};return}let M=w.size===1&&w.has(h.id),E=w.has(h.id)?w:new Set([h.id]);w.has(h.id)||d(E),tt.current={mode:"move",clickedId:h.id,origin:b,origs:un(G.current,E,h.id),wasSelected:M}},[o,y,f,it]),ai=O((p,h)=>{if(!(!o||p.button!==0)&&(p.stopPropagation(),ie(p),tt.current=h,h.mode==="endpoint")){let b=h.end==="start"?"startBinding":"endBinding";C(w=>w.map(M=>M.id===h.id?{...M,[b]:void 0}:M))}},[o,C]),An=O(()=>{St.current=null;let p=Ae.current,h=tt.current;if(!(!p||!h)){if(h.mode==="marquee"){h.current=p,Tn({origin:h.origin,current:p});return}if(C(b=>dn(b,h,p)),h.mode==="endpoint"||h.mode==="draw"&&R(G.current.find(b=>b.id===h.id)?.type??"")){let b=Wt(G.current,p,h.id);Rn(w=>w===(b?.id??null)?w:b?.id??null)}}},[C]),si=O(p=>{tt.current&&(Ae.current=it(p),St.current===null&&(St.current=requestAnimationFrame(An)))},[it,An]),Bn=O(p=>{let h=tt.current;if(tt.current=null,St.current!==null&&(cancelAnimationFrame(St.current),St.current=null),Ae.current=null,Rn(null),ee.current){let w=ee.current;ee.current=null,rt(w,"text");return}if(!h)return;let b=it(p);if(h.mode==="marquee"){Tn(null);let w=ln(h.origin,b);if(w.w<Ut&&w.h<Ut)return;let M=To(G.current,w,lt);d(E=>h.additive?new Set([...E,...M]):new Set(M));return}if(h.mode==="move"&&h.wasSelected){let w=Math.abs(b.x-h.origin.x)>Ut||Math.abs(b.y-h.origin.y)>Ut,M=G.current.find(E=>E.id===h.clickedId);if(!w&&M){C(E=>dn(E,h,h.origin)),M.type==="text"||R(M.type)?rt(M.id,"text"):rt(M.id,wn(M,h.origin.y));return}}if(h.mode==="draw"){let w=G.current.find(M=>M.id===h.id);if(w&&Math.abs(w.width)<4&&Math.abs(w.height)<4){if(w&&A(w.type)){let M=gt[w.type].defaultSize;C(E=>E.map(N=>N.id===h.id?{...N,x:N.x-M.w/2,y:N.y-M.h/2,w:M.w,h:M.h}:N),{commit:!0}),m("select"),d(new Set([h.id]))}else C(M=>M.filter(E=>E.id!==h.id));return}w&&R(w.type)&&C(M=>M.map(E=>E.id===h.id?yo(E,M):E)),m("select"),d(new Set([h.id]))}h.mode==="endpoint"&&C(w=>w.map(M=>{if(M.id!==h.id)return M;let E=h.end==="start"?{x:M.x,y:M.y}:{x:M.x+M.width,y:M.y+M.height},N=Wt(w,E,M.id),dt=h.end==="start"?M.endBinding:M.startBinding;if(N&&N.id===dt?.id)return M;let wi=h.end==="start"?"startBinding":"endBinding";return{...M,[wi]:N?we(N,E):void 0}})),C(w=>w.map(no),{commit:!0})},[it,lt,C,rt]),$e=O(()=>{let p=At.current;p.size&&(P(null),d(bt),C(h=>h.filter(b=>!p.has(b.id)&&!(b.startBinding&&p.has(b.startBinding.id))&&!(b.endBinding&&p.has(b.endBinding.id))),{commit:!0}))},[C]),$n=z(f);$n.current=f,Oe(()=>{let p=Qt.current;if(!p||!o)return;let h=b=>{if($n.current)return;let w=At.current;if((b.key==="Delete"||b.key==="Backspace")&&w.size)b.preventDefault(),b.stopPropagation(),$e();else if(b.key==="Enter"&&w.size===1){let[M]=w,E=G.current.find(N=>N.id===M);E&&(b.preventDefault(),b.stopPropagation(),rt(E.id,"text"))}else b.key==="a"&&(b.metaKey||b.ctrlKey)&&!b.shiftKey&&!b.altKey?(b.preventDefault(),b.stopPropagation(),d(new Set(G.current.map(M=>M.id)))):b.key==="Escape"&&(b.stopPropagation(),d(bt),m("select"))};return p.addEventListener("keydown",h),()=>p.removeEventListener("keydown",h)},[o,$e,rt]);let Pt=O(p=>{let h=At.current;h.size&&C(b=>b.map(w=>h.has(w.id)?p(w):w),{commit:!0})},[C]),ci=O(p=>{let h=Z[p];F(h.stroke),ct(h.fill),Pt(b=>A(b.type)?{...b,stroke:h.stroke,fill:h.fill}:{...b,stroke:h.stroke==="transparent"?Dt[0]:h.stroke})},[Pt]),li=O(p=>Pt(h=>R(h.type)?{...h,routing:p?"elbow":void 0,elbow:void 0,waypoints:void 0}:h),[Pt]),di=O(p=>Pt(h=>h.type==="arrow"?{...h,bidirectional:p||void 0}:h),[Pt]),ui=O(p=>{c(p),Bt(G.current,{width:p})},[Bt]),yi=O((p,h,b,w)=>{!o||p.button!==0||(p.stopPropagation(),ie(p),C(M=>M.map(E=>{if(E.id!==h||!R(E.type))return E;let N=an(E,M).slice(1,-1),dt=[...N.slice(0,b),w,...N.slice(b)];return{...E,waypoints:dt,routing:void 0,elbow:void 0}})),tt.current={mode:"waypoint",id:h,index:b})},[o,C]),pi=O((p,h)=>{C(b=>b.map(w=>{if(w.id!==p||!w.waypoints)return w;let M=w.waypoints.filter((E,N)=>N!==h);return{...w,waypoints:M.length?M:void 0}}),{commit:!0})},[C]),fi=O((p,h,b)=>{P(null),Qt.current?.focus({preventScroll:!0}),C(w=>w.flatMap(M=>M.id!==p?[M]:M.type==="text"?b.trim()===""?[]:[{...M,text:b,...X(b)}]:[{...M,[h]:b.trim()===""?void 0:b}]),{commit:!0})},[C]),hi=O(async()=>{let p={version:3,canvasHeight:Be.current,shapes:G.current};try{return await navigator.clipboard.writeText(po(p)),!0}catch{return!1}},[]),re=i.find(p=>p.id===f?.id)??null,Ln=_t?i.find(p=>p.id===_t):null,xi=Mt?.stroke??ht[0]?.stroke??S,gi=Mt?.fill??ht[0]?.fill??_,mi=y==="select"?"default":y==="text"?"text":"crosshair";return Ie("div",{ref:Qt,className:`zui-drawing-canvas ${Hr[l]} ${o?"is-editable":""} ${u?"is-ink":""}`,tabIndex:o?0:void 0,onFocus:()=>n.dispatchCommand(ze,t),onBlur:p=>{Qt.current?.contains(p.relatedTarget)||n.dispatchCommand(ze,null)},children:[o&&L("div",{className:"zui-drawing-toolbar",onPointerDown:p=>p.stopPropagation(),children:L(Zo,{tool:y,onToolChange:p=>{m(p),p!=="select"&&d(bt)},width:l,onWidthChange:ui,onCopyMermaid:hi,properties:L("div",{className:"zui-drawing-props-host",children:L(No,{selection:ht,stroke:xi,fill:gi,onColor:ci,onRouting:li,onDirection:di,onDelete:$e})})})}),Ie("div",{ref:On,className:"zui-drawing-stage",children:[Ie("svg",{ref:te,className:"zui-drawing-surface",role:"img","aria-label":e.title??x.canvas,"aria-description":e.description,style:{height:U?void 0:a,width:U??void 0,maxWidth:"100%",aspectRatio:U?`${U} / ${a}`:void 0,cursor:mi},viewBox:U?`0 0 ${U} ${a}`:void 0,preserveAspectRatio:"xMinYMin meet",onPointerDown:ii,onPointerMove:si,onPointerUp:Bn,onPointerCancel:Bn,onDoubleClick:p=>{if(!o)return;let b=p.target.closest("[data-shape-id]")?.getAttribute("data-shape-id"),w=b?i.find(M=>M.id===b):null;w&&(w.type==="text"||R(w.type)?rt(w.id,"text"):rt(w.id,wn(w,it(p).y)))},children:[i.map(p=>Ie("g",{"data-shape-id":p.id,className:`zui-drawing-shape ${g.has(p.id)?"is-selected":""}`,style:{cursor:o&&y==="select"?"move":void 0},onPointerDown:h=>ri(h,p),children:[L(qo,{shape:p,points:lt.get(p.id)}),p.id===f?.id&&p.type==="text"?null:L(Yo,{shape:p,ink:u,points:lt.get(p.id),hideField:p.id===f?.id?f.field:null,showHints:o&&y==="select"&&Mt?.id===p.id&&p.id!==f?.id})]},p.id)),Ln&&L("polygon",{className:"zui-drawing-selection zui-drawing-bind-target",points:Gt(Ln).map(p=>`${p.x},${p.y}`).join(" "),fill:"currentColor",fillOpacity:.06,stroke:"currentColor",strokeWidth:2,strokeLinejoin:"round",pointerEvents:"none"}),Mt&&o&&!f&&L(Co,{shape:Mt,points:lt.get(Mt.id)??[],onHandlePointerDown:ai,onWaypointAdd:yi,onWaypointRemove:pi}),ht.length>1&&o&&L(Oo,{shapes:ht,paths:lt}),_e&&L(Io,{rect:ln(_e.origin,_e.current)})]}),o&&i.length===0&&L("div",{className:"zui-drawing-empty","aria-hidden":"true",children:"Pick a shape above, then click or drag on the canvas"}),re&&f&&L("div",{className:"zui-drawing-overlay",style:{transform:`scale(${Nn})`,width:U??void 0,height:U?a:void 0},children:L(Uo,{shape:re,field:f.field,points:lt.get(re.id),onCommit:fi},`${re.id}:${f.field}`)}),o&&L(Gr,{height:a,scale:Nn,onChange:s,onCommit:p=>Bt(G.current,{height:p})})]})]})}function Gr({height:t,scale:e,onChange:n,onCommit:o}){let i=z(null),r=z(t);r.current=t;let a=l=>Math.round(Math.min(zr,Math.max(Lr,l))),s=K().drawing.resize;return L("div",{className:"zui-drawing-resize",title:s,role:"separator","aria-orientation":"horizontal",onPointerDown:l=>{l.preventDefault(),l.stopPropagation(),l.currentTarget.setPointerCapture(l.pointerId),i.current={startY:l.clientY,orig:t}},onPointerMove:l=>{let c=i.current;c&&n(a(c.orig+(l.clientY-c.startY)/Math.max(e,.05)))},onPointerUp:()=>{i.current&&(i.current=null,o(r.current))},children:L(yt,{size:14,children:j.grip})})}import{jsx as Ur}from"react/jsx-runtime";var qr=64,Jt=new Map;function Vr(t){let e=Jt.get(t);if(e)return e;let n=ye(t);if(Jt.size>=qr){let o=Jt.keys().next().value;o!==void 0&&Jt.delete(o)}return Jt.set(t,n),n}var ft=class t extends Yr{static getType(){return"drawing"}static clone(e){return new t(e.__data,e.__key)}constructor(e,n){super(n),this.__data=e}static importJSON(e){return It(e.data)}exportJSON(){return{data:this.__data,type:"drawing",version:1}}createDOM(e){let n=document.createElement("div"),o=e.theme.drawing;return n.className=typeof o=="string"?o:"zui-drawing",n}updateDOM(){return!1}exportDOM(){let e=document.createElement("pre");return e.setAttribute("data-drawing",this.__data),{element:e}}static importDOM(){return{pre:e=>e.hasAttribute("data-drawing")?{conversion:n=>({node:It(Y(ye(n.getAttribute("data-drawing")??"")))}),priority:2}:null}}getData(){return Vr(this.getLatest().__data)}setData(e){let n=this.getWritable();n.__data=Y(e)}getBlockWidth(){return this.getData().width??"full"}setBlockWidth(e){let{width:n,...o}=this.getData();this.setData(e==="full"?o:{...o,width:e})}isInline(){return!1}decorate(e,n){return Ur(Dn,{nodeKey:this.getKey(),data:this.getData()})}};function It(t=Y(nt)){return Kr(new ft(t))}function kn(t){return t instanceof ft}var Qo=/^```\s*$/,ti={dependencies:[ft],export:t=>kn(t)?`\`\`\`drawing
|
|
13
|
+
${t.getLatest().__data}
|
|
14
|
+
\`\`\``:null,regExpStart:/^```drawing\s*$/,regExpEnd:Qo,replace:(t,e,n,o,i,r)=>{if(!r||e!=null||i==null)return!1;let a=ye(i.join(`
|
|
15
|
+
`).trim());t.append(It(Y(a)))},type:"multiline-element"},ei={dependencies:[ft],export:()=>null,regExpStart:/^```diagram\s*$/,regExpEnd:Qo,replace:(t,e,n,o,i,r)=>{if(!r||e!=null||i==null)return!1;let a=So(i.join(`
|
|
16
|
+
`).trim());t.append(It(Y(a)))},type:"multiline-element"};import{useEffect as Xr}from"react";import{useLexicalComposerContext as Zr}from"@lexical/react/LexicalComposerContext";import{COMMAND_PRIORITY_EDITOR as jr}from"lexical";import{$insertNodeToNearestRoot as Jr}from"@lexical/utils";function En(){let[t]=Zr();return Xr(()=>t.registerCommand(Fn,e=>{let n=e?.width,o=n===void 0?nt:{version:3,canvasHeight:nt.canvasHeight,width:n,shapes:[]};return Jr(It(Y(o))),!0},jr),[t]),null}import{jsx as ea}from"react/jsx-runtime";var Qr=[...Hn,ft],ta=[Le,ti,ei,...Wn.filter(t=>t!==Le)],yc={nodes:Qr,transformers:ta,plugins:ea(En,{})};export{de as a,ue as b,bi as c,A as d,nt as e,Dt as f,Qn as g,Ye as h,Y as i,ye as j,qe as k,gt as l,Wt as m,we as n,po as o,Z as p,Ui as q,So as r,Xi as s,wa as t,ft as u,It as v,kn as w,ti as x,ei as y,En as z,Qr as A,ta as B,yc as C};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{useEffect as r,useLayoutEffect as i}from"react";var u=typeof window>"u"?r:i,c=4;function f(o,e,t){return Math.max(0,Math.min(o,t-e-c))}function m(o,e){u(()=>{let t=o.current,n=t?.offsetParent;if(!t||e===null||!(n instanceof HTMLElement))return;let l=f(t.offsetLeft,t.offsetWidth,n.clientWidth);l!==t.offsetLeft&&(t.style.insetInlineStart=`${l}px`)},[o,e])}function d(o,e,t="below"){let n=o.getRootElement()?.parentElement;if(!n||!e)return null;let l=n.getBoundingClientRect();return{top:t==="below"?e.bottom-l.top+n.scrollTop+4:e.top-l.top+n.scrollTop-4,insetInlineStart:Math.max(0,e.left-l.left+n.scrollLeft),...t==="above"?{transform:"translateY(-100%)"}:{}}}function s(){if(typeof window>"u")return null;let o=window.getSelection();if(!o||o.rangeCount===0)return null;let e=o.getRangeAt(0);if(typeof e.getBoundingClientRect!="function")return null;let t=e.getBoundingClientRect();if(t.width===0&&t.height===0){let n=e.startContainer,l=n instanceof Element?n:n.parentElement;return l?l.getBoundingClientRect():null}return t}function g(o,e){let t=s();if(t)return t;if(e===null)return null;let n=o.getElementByKey(e);return n?n.getBoundingClientRect():null}export{m as a,d as b,g as c};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{b as Te,c as rt,f as Re,q as ae,r as Et,s as Tt,t as kt,u as St}from"./chunk-N5JWZ2VW.js";import{a as Lt}from"./chunk-6LHJXZZ2.js";import{b as le,c as ct,d as dt,e as se,f as mt,g as ft,h as pt,i as gt,j as ht,k as yt,l as bt,m as xt,n as Ct,o as Rt,p as Pt,q as ue,r as ce,s as Le,t as ke,u as Se,v as we}from"./chunk-AGTPMKLK.js";import{a as lt,b as _,d as st,e as w,g as at,h as ut,n as K,u as wt}from"./chunk-LDVPFZCN.js";import{b as it,c as O}from"./chunk-YFFSTMIR.js";var Pe=globalThis;Pe.Prism?Pe.Prism.manual=!0:Pe.Prism={manual:!0};var yo=String.raw`[A-Za-z_$][\w$]*`,bo=String.raw`\s+`,xo=/^[A-Z][A-Z\d_]+$/,Co=/^[A-Z]/,vt=new WeakMap;function Eo(e){return new RegExp(`${e}|`).exec("").length-1}function To(e){let t=vt.get(e);if(t)return t;let o=[...e.rules,"whitespace","identifier"],r=o.map(c=>c==="whitespace"?bo:c==="identifier"?e.identifier??yo:c.match),n=[],i=1;for(let c of r)n.push(i),i+=1+Eo(c);let l=new RegExp(r.map(c=>`(${c})`).join("|"),e.caseInsensitive?"yi":"y"),s=new Map,u=(c,m)=>{for(let p of c??[])s.set(e.caseInsensitive?p.toLowerCase():p,m)};u(e.builtins,"builtin"),u(e.types,"type"),u(e.constants,"constant"),u(e.keywords,"keyword");let a={regex:l,groupStarts:n,rules:o,words:s};return vt.set(e,a),a}function Ro(e,t){let o=t;for(;e[o]===" "||e[o]===" ";)o++;return e[o]==="("}function Lo(e,t,o,r,n){let i=o.get(t.caseInsensitive?e.toLowerCase():e);if(i)return i;if(t.capitalizedIsType){if(xo.test(e))return"constant";if(Co.test(e))return"type"}return t.callIsFunction&&Ro(r,n)?"function":"text"}function ko(e,t){let{groupStarts:o,rules:r}=t;for(let n=0;n<o.length;n++)if(e[o[n]]!==void 0)return r[n];throw new Error("zui code lexer: no alternative matched")}function de(e,t){let o=To(t),r=[],n=(u,a)=>{let c=r[r.length-1];c&&c.type===u?r[r.length-1]={type:u,text:c.text+a}:r.push({type:u,text:a})},i=0,l=0,s=u=>{u>l&&n("text",e.slice(l,u))};for(;i<e.length;){o.regex.lastIndex=i;let u=o.regex.exec(e);if(u===null||u[0].length===0){i+=1;continue}let a=u[0],c=i+a.length,m=ko(u,o),p;m==="whitespace"?p="text":m==="identifier"?p=Lo(a,t,o.words,e,c):p=m.type,p!=="text"&&(s(i),n(p,a),l=c),i=c}return s(e.length),r}import{$createLineBreakNode as So,$createTabNode as wo,$nodesOfType as Po}from"lexical";import{$createCodeHighlightNode as vo,CodeNode as Nt,registerCodeHighlighting as No}from"@lexical/code";import{mergeRegister as zo}from"@lexical/utils";var Mo=2e5;function zt(e,t){return e.length>Mo?rt:Re(t)}var Mt={defaultLanguage:Te,tokenize(e,t){return de(e,zt(e,t)).map(o=>o.type==="text"?o.text:{type:o.type,alias:"",content:o.text})},$tokenize(e,t){let o=e.getTextContent(),r=[];for(let{type:n,text:i}of de(o,zt(o,t))){let l=n==="text"?void 0:n;for(let s of i.split(/(\n|\t)/))s===`
|
|
3
|
+
`?r.push(So()):s===" "?r.push(wo()):s.length>0&&r.push(vo(s,l))}return r}};function Io(e){let o=globalThis.Prism?.languages;return!o||Object.prototype.hasOwnProperty.call(o,e)?!1:(o[e]={},!0)}function ve(e){let t=zo(e.registerNodeTransform(Nt,o=>{let r=o.getLanguage();r&&Io(r)&&o.markDirty()}),No(e,Mt));return e.update(()=>{for(let o of Po(Nt))o.markDirty()},{tag:["history-merge","skip-dom-selection"]}),t}var Ne=["comment","string","number","keyword","builtin","type","function","property","variable","constant","operator","punctuation","tag","attr","regex","meta","inserted","deleted"];import{useEffect as It,useRef as $t}from"react";import{useLexicalComposerContext as $o}from"@lexical/react/LexicalComposerContext";import{$convertFromMarkdownString as Ao,$convertToMarkdownString as Bo}from"@lexical/markdown";import{$createRangeSelection as Oo,$getRoot as Ko,$getSelection as Do,$isElementNode as ze,$isRangeSelection as Ho,$isTextNode as At,$setSelection as _o}from"lexical";var Me="initial-load",Fo=8,Go=1e3;function Uo(e,t){if(t.size>0)return!0;for(let o of e.values())if(o)return!0;return!1}var Ie=class{constructor(t=Fo,o=Go,r=()=>Date.now()){this.capacity=t;this.staleMs=o;this.now=r;this.entries=[]}push(t){let o=this.entries.findIndex(r=>r.value===t);o!==-1&&this.entries.splice(o,1),this.entries.push({value:t,at:this.now()}),this.entries.length>this.capacity&&this.entries.shift()}isEcho(t){let o=this.entries.length;if(o===0)return!1;if(this.entries[o-1].value===t)return!0;let r=this.now();return this.entries.some(n=>n.value===t&&r-n.at<=this.staleMs)}get last(){let t=this.entries.length;return t===0?null:this.entries[t-1].value}};function Wo(e){let t=[],o=e;for(;o!==null;){let r=o.getParent();if(r===null)break;t.unshift(o.getIndexWithinParent()),o=r}return t}function Bt(e){return{path:Wo(e.getNode()),offset:e.offset,type:e.type}}function Ot(e){let t=Ko();for(let r of e.path){if(!ze(t))return null;let n=t.getChildAtIndex(r);if(n===null)return null;t=n}let o=At(t)?t.getTextContentSize():ze(t)?t.getChildrenSize():0;return e.type==="text"&&!At(t)||e.type==="element"&&!ze(t)?null:[t,Math.min(e.offset,o)]}function Yo(e,t){let o=Do(),r=Ho(o)?{anchor:Bt(o.anchor),focus:Bt(o.focus)}:null;if(Ao(e,t),r===null)return;let n=Ot(r.anchor),i=Ot(r.focus);if(n===null||i===null)return;let l=Oo();l.anchor.set(n[0].getKey(),n[1],r.anchor.type),l.focus.set(i[0].getKey(),i[1],r.focus.type),_o(l)}function Vo(e,t,o){let r=e.getRootElement(),n=r!==null&&typeof document<"u"&&document.activeElement===r;e.update(()=>Yo(t,o),{tag:n?[Me]:[Me,"skip-dom-selection"]})}function $e({markdown:e,onValueChange:t,transformers:o}){let[r]=$o(),n=$t(new Ie),i=$t(t);return i.current=t,It(()=>{e===void 0||n.current.isEcho(e)||(n.current.push(e),Vo(r,e,o))},[r,e]),It(()=>r.registerUpdateListener(({editorState:l,dirtyElements:s,dirtyLeaves:u,tags:a})=>{Uo(s,u)&&(a.has(Me)||l.read(()=>{let c=Bo(o);c!==n.current.last&&(n.current.push(c),i.current?.(c))}))}),[r]),null}var Ae={ltr:"text-start",rtl:"text-end",placeholder:"text-muted-foreground opacity-50",paragraph:"zui-paragraph mb-2",heading:{h1:"zui-heading zui-heading-1 text-4xl font-bold mb-4",h2:"zui-heading zui-heading-2 text-3xl font-bold mb-3",h3:"zui-heading zui-heading-3 text-2xl font-bold mb-2",h4:"zui-heading zui-heading-4 text-xl font-bold mb-2",h5:"zui-heading zui-heading-5 text-lg font-bold mb-1",h6:"zui-heading zui-heading-6 text-base font-bold mb-1"},list:{listitem:"ms-8",listitemChecked:"line-through opacity-50",listitemUnchecked:"",nested:{listitem:"ms-8"},checklist:"zui-checklist",ol:"zui-list zui-list-ordered list-decimal ms-4",ul:"zui-list zui-list-unordered list-disc ms-4"},link:"text-primary underline hover:opacity-80 cursor-pointer",text:{bold:"font-bold",code:"bg-muted px-1.5 py-0.5 rounded-sm font-mono text-sm",italic:"italic",strikethrough:"line-through",subscript:"text-xs align-sub",superscript:"text-xs align-super",underline:"underline",underlineStrikethrough:"underline line-through"},code:"zui-code bg-muted rounded-md p-4 font-mono text-sm block my-2 overflow-x-auto",codeHighlight:Object.fromEntries(Ne.map(e=>[e,`zui-token zui-token-${e}`])),quote:"zui-quote border-s-4 border-border ps-4 italic",frontmatter:"zui-frontmatter",table:"zui-table",tableCell:"zui-table-cell",tableCellHeader:"zui-table-cell-header",tableSelected:"zui-table-selected",tableSelection:"zui-table-selection",drawing:"zui-drawing"};function Kt(e,t){let o={...e};for(let[r,n]of Object.entries(t)){let i=o[r];o[r]=typeof n=="object"&&n!==null&&typeof i=="object"&&i!==null?{...i,...n}:n}return o}import{useEffect as Dt,useRef as qo,useState as Ht}from"react";import{useLexicalComposerContext as Zo}from"@lexical/react/LexicalComposerContext";import{$getRoot as _t}from"lexical";import{Fragment as Xo,jsx as Ft,jsxs as Jo}from"react/jsx-runtime";function Y({className:e}={}){let[t]=Zo(),{mode:o,rawValue:r,maxLength:n,labels:i}=_(),[l,s]=Ht(()=>t.getEditorState().read(()=>_t().getTextContentSize())),[u,a]=Ht(""),c=qo(!1);Dt(()=>t.registerUpdateListener(({editorState:C})=>{s(C.read(()=>_t().getTextContentSize()))}),[t]);let m=o==="edit-raw"?r.length:l,p=n!==void 0&&m>n;return Dt(()=>{p!==c.current&&(c.current=p,n!==void 0&&a(p?i.limitExceeded(n):i.limitRestored(n)))},[p,n,i]),Jo(Xo,{children:[Ft("div",{className:`zui-text-editor-count ${p?"is-over":""} ${e??""}`,"data-slot":"count",children:i.count(m,n)}),n!==void 0&&Ft("div",{className:"zui-text-editor-live",role:"status","aria-live":"polite","aria-atomic":"true","data-slot":"count-status",children:u})]})}import{useCallback as Xt,useEffect as pe,useMemo as V,useRef as ee,useState as qt,useSyncExternalStore as Jn}from"react";import{LexicalComposer as Qn}from"@lexical/react/LexicalComposer";import{HistoryPlugin as jn}from"@lexical/react/LexicalHistoryPlugin";import{ListPlugin as er}from"@lexical/react/LexicalListPlugin";import{CheckListPlugin as tr}from"@lexical/react/LexicalCheckListPlugin";import{LinkPlugin as or}from"@lexical/react/LexicalLinkPlugin";import{MarkdownShortcutPlugin as nr}from"@lexical/react/LexicalMarkdownShortcutPlugin";import{AutoFocusPlugin as rr}from"@lexical/react/LexicalAutoFocusPlugin";import{TablePlugin as ir}from"@lexical/react/LexicalTablePlugin";import{$convertFromMarkdownString as lr}from"@lexical/markdown";import{$getRoot as sr,createEditor as ar}from"lexical";import{useLexicalComposerContext as Jt}from"@lexical/react/LexicalComposerContext";import{useEffect as Qo}from"react";import{useLexicalComposerContext as jo}from"@lexical/react/LexicalComposerContext";import{$isListItemNode as en,$isListNode as Gt,ListNode as tn}from"@lexical/list";import{$getNodeByKey as on,TextNode as nn}from"lexical";var rn=/^\[(\s|x)?\]\s/i;function Be(){let[e]=jo();return Qo(()=>{let t=e.registerMutationListener(tn,r=>{e.getEditorState().read(()=>{for(let[n,i]of r){if(i==="destroyed")continue;let l=e.getElementByKey(n),s=on(n);l&&Gt(s)&&(l.__lexicalListType=s.getListType())}})}),o=e.registerNodeTransform(nn,r=>{let n=r.getParent();if(!en(n)||n.getFirstChild()?.getKey()!==r.getKey())return;let i=n.getParent();if(!Gt(i)||i.getListType()==="check")return;let l=r.getTextContent(),s=l.match(rn);if(!s)return;let u=s[1]==="x"||s[1]==="X";r.setTextContent(l.slice(s[0].length)),i.setListType("check"),n.setChecked(u),r.select(0,0)});return()=>{t(),o()}},[e]),null}import{useEffect as ln}from"react";import{useLexicalComposerContext as sn}from"@lexical/react/LexicalComposerContext";import{$createParagraphNode as an,$getSelection as un,$isLineBreakNode as cn,$isParagraphNode as dn,$isRangeSelection as mn,$isRootOrShadowRoot as Ut,COMMAND_PRIORITY_LOW as fn,KEY_ARROW_DOWN_COMMAND as pn,TextNode as gn}from"lexical";import{$createCodeNode as hn,$isCodeNode as yn}from"@lexical/code";var bn=/^```(\w[\w-]*)?$/;function Oe(){let[e]=sn();return ln(()=>{let t=e.registerNodeTransform(gn,r=>{let n=r.getParent();if(!dn(n)||n.getFirstChild()?.getKey()!==r.getKey())return;let i=n.getParent();if(!i||!Ut(i))return;let s=r.getTextContent().trimEnd().match(bn);if(!s)return;let u=s[1]||void 0,a=hn(u);n.replace(a),a.selectEnd()}),o=e.registerCommand(pn,()=>{let r=un();if(!mn(r)||!r.isCollapsed())return!1;let n=r.anchor,i=n.getNode(),l=i;for(;l.getParent()&&!Ut(l.getParent());)l=l.getParent();if(!yn(l))return!1;let s=l.getParent();if(!s||s.getLastChild()?.getKey()!==l.getKey())return!1;let u=m=>cn(m)||m.getTextContent().includes(`
|
|
4
|
+
`),a;if(i.getKey()===l.getKey())a=l.getChildren().slice(n.offset).some(u);else if(i.getTextContent().slice(n.offset).includes(`
|
|
5
|
+
`))a=!0;else{let m=i;for(;m.getParent()&&m.getParent().getKey()!==l.getKey();)m=m.getParent();a=m.getNextSiblings().some(u)}if(a)return!1;let c=an();return l.insertAfter(c),c.selectStart(),!0},fn);return()=>{t(),o()}},[e]),null}import{useEffect as xn}from"react";import{useLexicalComposerContext as Cn}from"@lexical/react/LexicalComposerContext";function Ke(){let[e]=Cn();return xn(()=>ve(e),[e]),null}import{useEffect as En,useRef as Wt}from"react";import{useLexicalComposerContext as Tn}from"@lexical/react/LexicalComposerContext";import{$getRoot as Rn,$getSelection as Ln,$isRangeSelection as kn,RootNode as Sn}from"lexical";import{$trimTextContentFromAnchor as wn}from"@lexical/selection";import{mergeRegister as Pn}from"@lexical/utils";function De(){return Rn().getTextContentSize()}function He({maxLength:e,onCharacterCountChange:t}){let[o]=Tn(),r=Wt(t);r.current=t;let n=Wt(null);return En(()=>{let i=s=>{n.current!==s&&(n.current=s,r.current?.(s))},l=!0;return queueMicrotask(()=>{l&&i(o.getEditorState().read(De))}),Pn(()=>{l=!1},o.registerUpdateListener(({editorState:s,dirtyElements:u,dirtyLeaves:a})=>{u.size===0&&a.size===0||i(s.read(De))}),e===void 0?()=>{}:o.registerNodeTransform(Sn,s=>{let u=Ln();if(!kn(u)||!u.isCollapsed())return;let a=o.getEditorState().read(De),c=s.getTextContentSize();if(c===a)return;let m=c-e;m>0&&wn(o,u.anchor,m)}))},[o,e]),null}import{useEffect as vn}from"react";import{useLexicalComposerContext as Nn}from"@lexical/react/LexicalComposerContext";import{$hasUpdateTag as zn,PASTE_TAG as Mn}from"lexical";import{LinkNode as In}from"@lexical/link";function _e(){let[e]=Nn();return vn(()=>e.registerNodeTransform(In,t=>{if(!(!zn(Mn)||O(t.getURL()))){for(let o of t.getChildren())t.insertBefore(o);t.remove()}}),[e]),null}import{useEffect as Fn}from"react";import{useLexicalComposerContext as Gn}from"@lexical/react/LexicalComposerContext";import{$getSelection as Un,$isRangeSelection as Wn,COMMAND_PRIORITY_HIGH as Yn,KEY_DOWN_COMMAND as Vn}from"lexical";import{useEffect as $n,useState as Yt}from"react";import{useLexicalComposerContext as An}from"@lexical/react/LexicalComposerContext";import{jsx as Bn}from"react/jsx-runtime";var me=new Map;function v(e,t){me.get(e)?.(t)}function fe(){let[e]=An(),[t,o]=Yt(!1),[r,n]=Yt("");return $n(()=>{if(me.has(e))return;let i=!1;return me.set(e,l=>{i=!i,n(i?l:`${l}\xA0`)}),o(!0),()=>{me.delete(e),o(!1)}},[e]),t?Bn("div",{className:"zui-text-editor-live",role:"status","aria-live":"polite","aria-atomic":"true",children:r}):null}import{useEffect as On}from"react";import{useLexicalComposerContext as Kn}from"@lexical/react/LexicalComposerContext";import{COMMAND_PRIORITY_HIGH as Dn,KEY_DOWN_COMMAND as Hn}from"lexical";function _n(e){return!(e.metaKey||e.ctrlKey)||!e.altKey?null:e.key==="Enter"?e.shiftKey?"insert-before":"insert-after":e.key==="Backspace"&&e.shiftKey?"delete":null}function Fe({labels:e}={}){let[t]=Kn(),o=w().table,r=e?.inserted??o.columnInserted,n=e?.deleted??o.columnDeleted;return On(()=>t.registerCommand(Hn,i=>{let l=_n(i);if(!l)return!1;let s=K();return s?(i.preventDefault(),l==="delete"?Ct(s)&&v(t,n):xt(s,l==="insert-after"?"after":"before")&&v(t,r),!0):!1},Dn),[t,r,n]),null}import{Fragment as Zn,jsx as Vt,jsxs as Xn}from"react/jsx-runtime";function qn(e){let t=e.metaKey||e.ctrlKey;return e.altKey?null:e.key==="Enter"&&t?e.shiftKey?"insert-above":"insert-below":e.key==="Backspace"&&t&&e.shiftKey?"delete":e.key==="Tab"&&!t&&!e.shiftKey?"tab":null}function Ge({labels:e,columnLabels:t}={}){let[o]=Gn(),r=w().table,n=e?.inserted??r.rowInserted,i=e?.deleted??r.rowDeleted;return Fn(()=>o.registerCommand(Vn,l=>{let s=qn(l);if(!s)return!1;let u=K(),a=le();if(!u||!a)return!1;if(s==="tab"){let c=Un();return!(a.row===a.rows-1&&a.column===a.columns-1)||!Wn(c)||!c.isCollapsed()?!1:(l.preventDefault(),se(u,a.rows),v(o,n),!0)}return l.preventDefault(),s==="delete"?pt(u)&&v(o,i):ft(u,s==="insert-above"?"above":"below")&&v(o,n),!0},Yn),[o,n,i]),Xn(Zn,{children:[Vt(Fe,{labels:t}),Vt(fe,{})]})}import{Fragment as yr,jsx as T,jsxs as Zt}from"react/jsx-runtime";var ur={};function Qt(e){console.error(e)}function cr(e,t){let o=ar({namespace:"ZuiTextEditorInit",nodes:t.nodes,onError:Qt});return o.update(()=>lr(e,t.sync),{discrete:!0}),o.getEditorState()}var dr=()=>()=>{};function mr(){return Jn(dr,()=>!0,()=>!1)}function fr({state:e}){let t=e.read(()=>sr().getChildren().map(o=>o.getTextContent()));return T("div",{className:"zui-text-editor-body",children:T("div",{className:"zui-text-editor-main",children:T("div",{className:"zui-text-editor-content","aria-readonly":"true",children:t.map((o,r)=>T("p",{children:o},r))})})})}function pr({readOnly:e}){let[t]=Jt();return pe(()=>{t.setEditable(!e)},[t,e]),null}function gr({onEditorReady:e}){let[t]=Jt();return pe(()=>{e?.(t)},[t,e]),null}function hr(e,t){let o=ee(e);o.current=e;let r=ee(null),n=ee(null);return pe(()=>()=>{if(r.current===null)return;clearTimeout(r.current),r.current=null;let i=n.current;n.current=null,i!==null&&o.current?.(i)},[]),Xt(i=>{if(t<=0){o.current?.(i);return}r.current!==null&&clearTimeout(r.current),n.current=i,r.current=setTimeout(()=>{r.current=null,n.current=null,o.current?.(i)},t)},[t])}function Ue({value:e,defaultValue:t,onValueChange:o,debounceMs:r=0,readOnly:n=!1,className:i,mode:l="edit-rich",autoFocus:s=!1,maxTextWidth:u,newBlockWidth:a=ur,drawingStyle:c="clean",onError:m=Qt,nodes:p,transformers:C,nodeClassNames:E,onEditorReady:L,labels:h,maxLength:y,onCharacterCountChange:d,id:f,name:x,"aria-label":P,"aria-labelledby":S,"aria-describedby":k,"aria-invalid":$,"aria-required":M,preset:g=ae,children:A}){let[D]=qt(()=>{let H=Et(g.transformers,C);return{nodes:[...g.nodes,...p??[]],sync:H,shortcuts:Tt(H),theme:E?Kt(Ae,E):Ae}}),[X,ne]=qt(t??""),B=e??X,re=ee(m);re.current=m;let J=hr(o,r),G=Xt(H=>{ne(H),J(H)},[J]),U=V(()=>l==="view"?cr(B,D):null,[]),Ee=V(()=>({namespace:"ZuiTextEditor",theme:D.theme,onError:H=>re.current(H),nodes:D.nodes,editable:!n&&l!=="view",editorState:U?JSON.stringify(U.toJSON()):void 0}),[]),b=mr(),R=V(()=>st(h),[h]),W=V(()=>({id:f,name:x,"aria-label":P,"aria-labelledby":S,"aria-describedby":k,"aria-invalid":$,"aria-required":M}),[f,x,P,S,k,$,M]),ie=V(()=>({mode:l,readOnly:n,autoFocus:s,rawValue:B,onRawChange:G,newBlockWidth:a,drawingStyle:c,labels:R,maxLength:y,field:W}),[l,n,s,B,G,a,c,R,y,W]),Q=l==="edit-raw",I=V(()=>u!==void 0?{"--zui-text-editor-measure":u}:void 0,[u]),j=ee(d);return j.current=d,pe(()=>{Q&&j.current?.(B.length)},[Q,B]),U&&!b?T("div",{className:`zui-text-editor ${i??""}`,style:I,children:T(fr,{state:U})}):T(Qn,{initialConfig:Ee,children:T(lt.Provider,{value:ie,children:Zt("div",{className:`zui-text-editor ${i??""}`,style:I,children:[T(gr,{onEditorReady:L}),A,!Q&&Zt(yr,{children:[T($e,{markdown:B,onValueChange:G,transformers:D.sync}),(y!==void 0||d!==void 0)&&T(He,{maxLength:y,onCharacterCountChange:d}),T(jn,{}),T(er,{}),T(tr,{}),T(Be,{}),T(Oe,{}),T(Ke,{}),T(ir,{}),T(Ge,{}),T(or,{validateUrl:O}),T(_e,{}),T(nr,{transformers:D.shortcuts}),T(pr,{readOnly:n||l==="view"}),s&&T(rr,{}),g.plugins]})]})})})}import{RichTextPlugin as ti}from"@lexical/react/LexicalRichTextPlugin";import{ContentEditable as oi}from"@lexical/react/LexicalContentEditable";import{LexicalErrorBoundary as ni}from"@lexical/react/LexicalErrorBoundary";import{useCallback as ge,useEffect as br,useLayoutEffect as xr,useRef as We,useState as Ye}from"react";import{$getRoot as Cr,$getSelection as Er,$isRangeSelection as Tr}from"lexical";import{useLexicalComposerContext as Rr}from"@lexical/react/LexicalComposerContext";import{$isHeadingNode as Ve}from"@lexical/rich-text";import{jsx as he,jsxs as wr}from"react/jsx-runtime";var jt={h1:1,h2:2,h3:3,h4:4,h5:5,h6:6},Lr={hidden:new Set,headings:[]};function kr(e,t){if(e.hidden.size!==t.hidden.size||e.headings.length!==t.headings.length)return!1;for(let o of e.hidden)if(!t.hidden.has(o))return!1;return e.headings.every((o,r)=>o.key===t.headings[r].key&&o.folded===t.headings[r].folded)}function Sr(e,t){return e.length===t.length&&e.every((o,r)=>{let n=t[r];return o.key===n.key&&o.folded===n.folded&&o.top===n.top&&o.height===n.height})}function qe({labels:e}={}){let[t]=Rr(),[o,r]=Ye(new Set),[n,i]=Ye(Lr),[l,s]=Ye([]),u=We(o);u.current=o;let a=We(n);a.current=n;let c={...w().collapsibleHeadings,...e},m=ge(()=>{t.getEditorState().read(()=>{let h=Cr().getChildren(),y=u.current,d=new Set,f=[];for(let S=0;S<h.length;S++){let k=h[S];if(!Ve(k))continue;let $=jt[k.getTag()]??6,M=y.has(k.getKey());if(f.push({key:k.getKey(),folded:M}),!!M)for(let g=S+1;g<h.length;g++){let A=h[g];if(Ve(A)&&(jt[A.getTag()]??6)<=$)break;d.add(A.getKey())}}let x=Er();if(Tr(x)){let S=x.anchor.getNode().getTopLevelElement();if(S&&d.has(S.getKey())){let k=S.getPreviousSibling();for(;k;){if(Ve(k)&&y.has(k.getKey())){let $=k.getKey();r(M=>{let g=new Set(M);return g.delete($),g});return}k=k.getPreviousSibling()}}}let P={hidden:d,headings:f};kr(a.current,P)||(a.current=P,i(P))})},[t]),p=We(new Set),C=ge(()=>{let{hidden:h,headings:y}=a.current,d=new Set;for(let f of h){let x=t.getElementByKey(f);x&&(d.add(x),x.style.display!=="none"&&(x.style.display="none"))}for(let f of p.current)!d.has(f)&&f.style.display==="none"&&(f.style.display="");p.current=d;for(let{key:f,folded:x}of y)t.getElementByKey(f)?.classList.toggle("zui-heading-folded",x)},[t]),E=ge(()=>{let h=a.current.headings.map(({key:y,folded:d})=>{let f=t.getElementByKey(y);return{key:y,folded:d,top:f?.offsetTop??0,height:f?.offsetHeight??0}});s(y=>Sr(y,h)?y:h)},[t]);xr(()=>{C(),E()},[n,C,E]),br(()=>{m();let h=()=>{m(),C(),E()},y=t.registerUpdateListener(h),d=t.getRootElement(),f=typeof ResizeObserver<"u"?new ResizeObserver(E):null;return d&&f&&f.observe(d),()=>{y(),f?.disconnect()}},[t,m,C,E,o]);let L=ge(h=>{let y=!u.current.has(h);r(d=>{let f=new Set(d);return f.has(h)?f.delete(h):f.add(h),f}),v(t,y?c.collapsed:c.expanded)},[t,c.collapsed,c.expanded]);return wr("div",{className:"zui-text-editor-fold-gutter",children:[he(fe,{}),l.map(({key:h,folded:y,top:d,height:f})=>he("button",{type:"button",className:`zui-text-editor-fold ${y?"is-folded":""}`,style:{top:d+Math.max(0,(Math.min(f,44)-18)/2)},title:y?c.expand:c.collapse,"aria-label":y?c.expand:c.collapse,"aria-expanded":!y,onClick:()=>L(h),children:he("svg",{viewBox:"0 0 20 20",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:he("path",{d:"M6 8l4 4 4-4"})})},h))]})}import{useCallback as Pr,useEffect as q,useRef as eo,useState as Ze}from"react";import{useLexicalComposerContext as vr}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as Nr}from"@lexical/react/useLexicalEditable";import{$createRangeSelection as zr,$getSelection as to,$isRangeSelection as oo,$setSelection as Mr,COMMAND_PRIORITY_LOW as Ir}from"lexical";import{$isLinkNode as $r,$toggleLink as Ar}from"@lexical/link";import{$findMatchingParent as Br}from"@lexical/utils";import{jsx as te,jsxs as Kr}from"react/jsx-runtime";function no(e){return{key:e.key,offset:e.offset,type:e.type}}function ro(e,t){return e.key===t.key&&e.offset===t.offset&&e.type===t.type}function io(e,t){let o=e.getRootElement()?.parentElement;if(!t||!o)return null;let r=o.getBoundingClientRect();return{top:t.bottom-r.top+o.scrollTop+4,insetInlineStart:Math.max(0,t.left-r.left+o.scrollLeft)}}function Or(e,t){let r=e.getRootElement()?.ownerDocument.defaultView?.getSelection();if(r&&r.rangeCount>0){let i=r.getRangeAt(0).getBoundingClientRect();if(i.width>0||i.height>0)return i}let n=e.getElementByKey(t);return n?n.getBoundingClientRect():null}function Xe(){let[e]=vr(),t=Nr(),{link:o,setLink:r}=Rt(),n=w(),[i,l]=Ze(""),[s,u]=Ze(null),[a,c]=Ze(null),m=eo(null),p=eo(null),C=o?.key??null,E=o?.url??"";q(()=>{l(E)},[C,E]),q(()=>{C!==null&&c(null)},[C]),q(()=>e.registerCommand(it,()=>{let d=to();if(!oo(d))return!1;if(Br(d.anchor.getNode(),$r))return m.current?.focus(),!0;if(d.isCollapsed())return!1;let f=io(e,Or(e,d.anchor.key));return f?(l(""),c({anchor:no(d.anchor),focus:no(d.focus),style:f}),!0):!1},Ir),[e]),q(()=>{if(a!==null)return e.registerUpdateListener(({editorState:d})=>{d.read(()=>{let x=to();return oo(x)&&ro(a.anchor,x.anchor)&&ro(a.focus,x.focus)})||c(null)})},[e,a]),q(()=>{a!==null&&m.current?.focus()},[a]),q(()=>{if(a!==null){u(a.style);return}if(C===null){u(null);return}let d=e.getElementByKey(C);u(io(e,d?d.getBoundingClientRect():null))},[e,C,E,a]);let L=Pr(()=>c(null),[]);if(Lt(p,s),!t||s===null||C===null&&a===null)return null;let h=()=>{let d=i.trim();if(a!==null){if(d===""||!O(d))return;c(null),e.update(()=>{let f=zr();f.anchor.set(a.anchor.key,a.anchor.offset,a.anchor.type),f.focus.set(a.focus.key,a.focus.offset,a.focus.type),Mr(f),Ar(d)});return}d===""?r(null):O(d)&&r(d)},y=i.trim()!==""&&!O(i);return Kr("div",{ref:p,className:"zui-text-editor-link-bubble",role:"group","aria-label":n.toolbar.link,style:s,"data-slot":"link-bubble",onBlur:d=>{a!==null&&!(d.relatedTarget instanceof Node&&p.current?.contains(d.relatedTarget))&&L()},children:[te("input",{ref:m,type:"url",className:"zui-text-editor-link-input","aria-label":n.toolbar.linkUrl,"aria-invalid":y||void 0,placeholder:n.toolbar.linkUrlPlaceholder,value:i,onChange:d=>l(d.target.value),onKeyDown:d=>{d.key==="Enter"?(d.preventDefault(),h(),e.focus()):d.key==="Escape"&&(d.preventDefault(),L(),e.focus())}}),te("button",{type:"button",className:"zui-text-editor-toolbar-button",onClick:h,disabled:y,children:n.toolbar.linkApply}),te("button",{type:"button",className:"zui-text-editor-toolbar-button",title:n.toolbar.removeLink,"aria-label":n.toolbar.removeLink,onClick:()=>{a!==null?L():r(null),e.focus()},children:te("svg",{viewBox:"0 0 20 20",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:te("path",{d:"M5 5l10 10M15 5L5 15"})})})]})}import{useCallback as co}from"react";import{useLexicalComposerContext as Jr}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as Qr}from"@lexical/react/useLexicalEditable";import{useCallback as oe,useEffect as lo,useRef as so,useState as Je}from"react";import{useLexicalComposerContext as Dr}from"@lexical/react/LexicalComposerContext";import{jsx as Z,jsxs as Hr}from"react/jsx-runtime";var Qe={row:28,column:24};function ye({axis:e,box:t,lanes:o,current:r,insertable:n,canDelete:i,onInsert:l,onDelete:s,labels:u}){let[a]=Dr(),c=w().table,m=so(null),[p,C]=Je(!1),[E,L]=Je(null),[h,y]=Je(!1),d=so(0),f=Qe[e],x=e==="row",P=oe(b=>{let R=m.current?.getBoundingClientRect();return R?x?b.clientY-R.top:b.clientX-R.left:null},[x]),S=oe(b=>{if(b<o.length)return o[b].start;let R=o[o.length-1];return R?R.start+R.size:0},[o]),k=oe(b=>{let R=P(b);R!==null&&L(R)},[P]),$=oe(b=>{if(b.pointerType==="mouse"||b.target instanceof Element&&b.target.closest(".zui-table-rail-handle"))return;let R=P(b);R!==null&&(L(R),y(!0),d.current=Date.now())},[P]),M=oe(()=>{h||L(null)},[h]);if(lo(()=>{y(!1),L(null)},[t.top,t.left,o.length]),lo(()=>{let b=m.current;b&&C(getComputedStyle(b).direction==="rtl")},[]),o.length===0)return null;let g=(()=>{if(E===null)return{mode:"insert",index:o.length};let b=o.length,R=Number.POSITIVE_INFINITY;for(let I of n){let j=Math.abs(S(I)-E);j<R&&(R=j,b=I)}let W=o.findIndex(I=>E>=I.start&&E<I.start+I.size),ie=o[W],Q=ie?Math.min(10,ie.size*.3):0;return!i||W===-1||R<=Q?{mode:"insert",index:b}:{mode:"delete",index:W}})(),A=b=>x?{top:b}:{left:b},D=b=>x?{top:b.start+3,height:Math.max(4,b.size-6)}:{left:b.start+3,width:Math.max(4,b.size-6)},X=x?{insetInlineStart:f,width:t.width}:{top:f,height:t.height},ne=p?t.right:t.left,B=o[Math.min(r,o.length-1)],re=g.mode==="insert"&&g.index===o.length,J=g.mode==="delete"?(x?c.deleteRow:c.deleteColumn)(g.index+1):re?x?c.addRow:c.addColumn:(x?c.insertRowBefore:c.insertColumnBefore)(g.index+1),G={inserted:x?c.rowInserted:c.columnInserted,deleted:x?c.rowDeleted:c.columnDeleted,...u},U=()=>{h&&Date.now()-d.current<350||(g.mode==="insert"?l(g.index):s(g.index),v(a,g.mode==="insert"?G.inserted:G.deleted))},Ee=g.mode==="insert"?{...A(S(g.index)),...X}:x?{top:o[g.index].start,height:o[g.index].size,...X}:{left:o[g.index].start,width:o[g.index].size,...X};return Hr("div",{ref:m,className:`zui-table-rail is-${e} ${h?"is-pinned":""}`,style:x?{top:t.top,insetInlineStart:ne-f,width:f,height:t.height}:{top:t.top-f,insetInlineStart:ne,width:t.width,height:f},onPointerDown:$,onPointerMove:k,onPointerLeave:M,children:[Z("div",{className:"zui-table-rail-marker",style:D(B),"aria-hidden":!0}),Z("button",{type:"button",className:`zui-table-rail-handle is-${g.mode} ${E===null?"is-resting":""}`,style:A(g.mode==="insert"?S(g.index):o[g.index].start+o[g.index].size/2),title:J,"aria-label":J,onMouseDown:b=>b.preventDefault(),onClick:U,children:Z("svg",{viewBox:"0 0 12 12",width:"12",height:"12",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:g.mode==="insert"?Z("path",{d:"M6 2.5v7M2.5 6h7"}):Z("path",{d:"M2.5 6h7"})})}),Z("div",{className:`zui-table-rail-preview is-${g.mode}`,style:Ee,"aria-hidden":!0})]})}import{jsx as be}from"react/jsx-runtime";function _r({children:e}){return be("svg",{viewBox:"0 0 20 20",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:e})}function je({settings:e,style:t,onSettings:o}){let r=wt(),n=w();return be("div",{className:"zui-table-settings",role:"toolbar","aria-label":n.table.settings,style:t,...r,children:kt.map(({preset:i,label:l,icon:s,width:u,density:a})=>be(ce,{label:n.layout[l],active:St(e.width)===i,onClick:()=>o({width:u,density:a}),children:be(_r,{children:s})},i))})}import{useCallback as Fr,useEffect as ao,useRef as Gr,useState as Ur}from"react";import{useLexicalComposerContext as Wr}from"@lexical/react/LexicalComposerContext";function Yr(e,t){return e.top===t.top&&e.left===t.left&&e.right===t.right&&e.width===t.width&&e.height===t.height}function uo(e,t){return e.length===t.length&&e.every((o,r)=>o.start===t[r].start&&o.size===t[r].size)}function Vr(e,t){return e===t?!0:!e||!t?!1:e.key===t.key&&e.settings===t.settings&&e.position===t.position&&Yr(e.box,t.box)&&uo(e.rows,t.rows)&&uo(e.columns,t.columns)}function qr(e,t){return e.row===t.row&&e.column===t.column&&e.rows===t.rows&&e.columns===t.columns&&e.hasHeader===t.hasHeader}function Zr(e,t){return e.width===t.width&&e.density===t.density}function Xr(e,t,o,r){let n=e.getBoundingClientRect(),i=t.getBoundingClientRect(),l=Array.from(e.querySelectorAll(":scope > tbody > tr, :scope > tr")),s=l.map(m=>{let p=m.getBoundingClientRect();return{start:p.top-n.top,size:p.height}}),u={top:n.top-i.top,left:n.left-i.left,right:i.right-n.right,width:n.width,height:n.height},c=o!==null&&o.key===r&&o.columns.length===(l[0]?.children.length??0)&&o.box.width===u.width&&o.box.height===u.height?o.columns:Array.from(l[0]?.children??[]).map(m=>{let p=m.getBoundingClientRect();return{start:p.left-n.left,size:p.width}});return{box:u,rows:s,columns:c}}function et(){let[e]=Wr(),[t,o]=Ur(null),r=Gr(t);r.current=t;let n=Fr(()=>{let l=e.getEditorState().read(()=>{let C=K(),E=le();return C&&E?{key:C.getKey(),settings:at(C),position:E}:null}),s=l?e.getElementByKey(l.key):null,u=e.getRootElement()?.parentElement,a=r.current;if(!l||!s||!u){a!==null&&o(null);return}let c=a&&a.key===l.key&&Zr(a.settings,l.settings)?a.settings:l.settings,m=a&&qr(a.position,l.position)?a.position:l.position,p={key:l.key,settings:c,position:m,...Xr(s,u,a,l.key)};Vr(a,p)||(r.current=p,o(p))},[e]);ao(()=>{n();let l=e.registerUpdateListener(n),s=e.getRootElement(),u=typeof ResizeObserver<"u"?new ResizeObserver(n):null;return s&&u&&u.observe(s),()=>{l(),u?.disconnect()}},[e,n]);let i=t?.key??null;return ao(()=>{if(i===null||typeof ResizeObserver>"u")return;let l=e.getElementByKey(i);if(!l)return;let s=new ResizeObserver(n);return s.observe(l),()=>s.disconnect()},[e,i,n]),t}import{Fragment as jr,jsx as tt,jsxs as ei}from"react/jsx-runtime";function ot(){let[e]=Jr(),t=Qr(),o=et(),r=co(l=>{e.update(()=>{let s=K();s&&l(s)})},[e]),n=co(l=>r(s=>ut(s,l)),[r]);if(!t||!o)return null;let{position:i}=o;return ei(jr,{children:[tt(je,{settings:o.settings,style:{top:o.box.top-Qe.column,right:Math.max(0,o.box.right)},onSettings:n}),tt(ye,{axis:"row",box:o.box,lanes:o.rows,current:i.row,insertable:ct(i),canDelete:dt(i),onInsert:l=>r(s=>se(s,l,i.column)),onDelete:l=>r(s=>mt(s,l,i.column))}),tt(ye,{axis:"column",box:o.box,lanes:o.columns,current:i.column,insertable:gt(i),canDelete:ht(i),onInsert:l=>r(s=>yt(s,l,i.row)),onDelete:l=>r(s=>bt(s,l,i.row))})]})}import{Fragment as ri,jsx as N,jsxs as nt}from"react/jsx-runtime";function xe({placeholder:e,collapsible:t=!0,showCharacterCount:o=!1,children:r}){let{mode:n,readOnly:i,autoFocus:l,rawValue:s,onRawChange:u,labels:a,maxLength:c,field:m}=_(),p=e??a.placeholder,{name:C,...E}=m;return n==="edit-raw"?nt(ri,{children:[N("textarea",{...m,className:"zui-text-editor-textarea",value:s,onChange:L=>u(L.target.value),placeholder:p,readOnly:i,autoFocus:l,maxLength:c,spellCheck:!1}),o&&N(Y,{})]}):nt("div",{className:"zui-text-editor-body",children:[nt("div",{className:"zui-text-editor-main",children:[N(ti,{contentEditable:N(oi,{...E,className:"zui-text-editor-content","aria-placeholder":p,placeholder:N("div",{className:"zui-text-editor-placeholder",children:p})}),ErrorBoundary:ni}),t&&N(qe,{}),N(ot,{}),N(Xe,{}),o&&N(Y,{}),C!==void 0&&N("input",{type:"hidden",name:C,value:s,readOnly:!0})]}),r]})}import{useCallback as ii,useEffect as fo,useState as mo}from"react";import{useLexicalComposerContext as li}from"@lexical/react/LexicalComposerContext";import{TableOfContentsPlugin as si}from"@lexical/react/LexicalTableOfContentsPlugin";import{jsx as F,jsxs as po}from"react/jsx-runtime";var ai={h1:0,h2:1,h3:2,h4:3,h5:4,h6:5};function ui(e,t){fo(()=>{for(let[o]of t)e.getElementByKey(o)?.setAttribute("data-outline-key",o)},[e,t])}function ci({editor:e,entries:t,activeKey:o,onSelect:r}){ui(e,t);let n=w().outline;return po("nav",{className:"zui-text-editor-outline-list","aria-label":n.title,children:[t.length===0&&F("div",{className:"zui-text-editor-outline-empty",children:n.empty}),t.map(([i,l,s])=>F("button",{type:"button",className:`zui-text-editor-outline-item ${i===o?"is-active":""}`,style:{paddingInlineStart:`${.5+ai[s]*.75}rem`},onClick:()=>r(i),children:l||n.untitled},i))]})}function Ce(){let[e]=li(),[t,o]=mo(!1),[r,n]=mo(null),i=w().outline;fo(()=>{let s=e.getRootElement(),u=s?.closest(".zui-text-editor");if(!s||!(u instanceof HTMLElement))return;let a=0,c=()=>{cancelAnimationFrame(a),a=requestAnimationFrame(()=>{let p=s.querySelectorAll("h1, h2, h3, h4, h5, h6"),C=u.scrollTop+80,E=null;for(let L of p)L.offsetTop<=C&&(E=L.getAttribute("data-outline-key"));n(E)})};c(),u.addEventListener("scroll",c,{passive:!0});let m=e.registerUpdateListener(c);return()=>{cancelAnimationFrame(a),u.removeEventListener("scroll",c),m()}},[e]);let l=ii(s=>{e.getEditorState().read(()=>{e.getElementByKey(s)?.scrollIntoView({behavior:"smooth",block:"start"})})},[e]);return F(si,{children:s=>po("div",{className:`zui-text-editor-outline ${t?"is-collapsed":""}`,children:[F("button",{type:"button",className:"zui-text-editor-outline-toggle",title:t?i.show:i.hide,"aria-label":t?i.show:i.hide,"aria-expanded":!t,onClick:()=>o(u=>!u),children:F("svg",{viewBox:"0 0 20 20",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:F("path",{d:"M4 5h12M4 10h8M4 15h10"})})}),!t&&F(ci,{editor:e,entries:s,activeKey:r,onSelect:l})]})})}import{jsx as z,jsxs as ho}from"react/jsx-runtime";function go({children:e,className:t}){let{mode:o,readOnly:r}=_();return o!=="edit-rich"||r?null:z(Pt,{className:t,children:e})}function Ra(e=ae){let t=e.plugins!==void 0,o={format:z(Le,{}),block:z(ke,{}),insert:z(Se,{drawing:t}),history:z(we,{})};function r(i){return z(Ue,{preset:e,...i})}function n({placeholder:i,toolbar:l=!0,outline:s=!1,collapsible:u=!0,showCharacterCount:a=!1,children:c,...m}){return ho(r,{...m,children:[l===!0&&ho(go,{children:[o.format,z(ue,{}),o.block,z(ue,{}),o.insert]}),typeof l=="function"&&l(o),z(xe,{placeholder:i,collapsible:u,showCharacterCount:a,children:s&&z(Ce,{})}),c]})}return n.Root=r,n.Content=xe,n.Toolbar=go,n.ToolbarButton=ce,n.ToolbarDivider=ue,n.FormatButtons=Le,n.BlockButtons=ke,n.InsertButtons=Se,n.HistoryButtons=we,n.Outline=Ce,n.CharacterCount=Y,n}export{de as a,Mt as b,ve as c,Ne as d,Me as e,Yo as f,Vo as g,Ae as h,Kt as i,Y as j,Ra as k};
|
package/dist/comments.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
"use client";import{a,b as s,c as C,d as p}from"./chunk-
|
|
2
|
+
"use client";import{a,b as s,c as C,d as p}from"./chunk-5J4TV6XA.js";import{a as e,b as o,c as m,d as t,e as r,f as n,g as M}from"./chunk-A7MCBSAZ.js";import"./chunk-6LHJXZZ2.js";import{MarkNode as i,$createMarkNode as l,$isMarkNode as $,$unwrapMarkNode as f,$wrapSelectionInMarkNode as g,$getMarkIDs as k}from"@lexical/mark";export{l as $createMarkNode,r as $getCommentIds,k as $getMarkIDs,t as $getMarkNodes,$ as $isMarkNode,M as $plainTextOffset,n as $removeComment,f as $unwrapMarkNode,g as $wrapSelectionInMarkNode,C as ADD_COMMENT_COMMAND,m as COMMENT,s as COMMENTS_THEME,p as CommentsPlugin,a as DEFAULT_COMMENTS_LABELS,i as MarkNode,e as formatCommentMarker,o as parseCommentIds};
|
package/dist/drawing.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
"use client";import{a as G}from"./chunk-32RX4GZF.js";import{A as M,B as y,C as k,a as o,b as i,c as n,d as a,e as t,f as S,g as D,h as p,i as d,j as N,k as E,l as g,m as _,n as w,o as m,p as R,q as T,r as A,s as O,t as f,u as x,v as l,w as I,x as s,y as P,z as C}from"./chunk-
|
|
2
|
+
"use client";import{a as G}from"./chunk-32RX4GZF.js";import{A as M,B as y,C as k,a as o,b as i,c as n,d as a,e as t,f as S,g as D,h as p,i as d,j as N,k as E,l as g,m as _,n as w,o as m,p as R,q as T,r as A,s as O,t as f,u as x,v as l,w as I,x as s,y as P,z as C}from"./chunk-6JQG6QDN.js";import"./chunk-N5JWZ2VW.js";import{r as e,s as r}from"./chunk-LDVPFZCN.js";export{l as $createDrawingNode,I as $isDrawingNode,R as COLOR_PRESETS,i as CONNECTOR_TYPES,P as DIAGRAM,s as DRAWING,G as DRAWING_DATA_JSON_SCHEMA,e as DRAWING_FOCUS_COMMAND,k as DRAWING_PRESET,M as DRAWING_PRESET_NODES,y as DRAWING_PRESET_TRANSFORMERS,f as DRAWING_SKELETON_JSON_SCHEMA,x as DrawingNode,C as DrawingPlugin,t as EMPTY_DRAWING,D as FILL_COLORS,r as INSERT_DRAWING_COMMAND,g as NODE_SHAPE_DEFINITIONS,o as NODE_SHAPE_TYPES,n as SHAPE_TYPES,p as SIDE_FIXED_POINTS,S as STROKE_COLORS,w as createBinding,N as deserializeDrawingData,m as drawingToMermaid,O as expandDrawingSkeleton,_ as findNodeShapeAt,T as isDrawingSkeleton,a as isNodeShapeType,E as normalizeDrawingData,A as parseDrawingSkeleton,d as serializeDrawingData};
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
"use client";import"./chunk-TGVEPLDM.js";import{a as Y,d as q,j as Ae,k as e}from"./chunk-
|
|
2
|
+
"use client";import"./chunk-TGVEPLDM.js";import{a as Y,d as q,j as Ae,k as e}from"./chunk-N6OUUWQO.js";import{a as C}from"./chunk-32RX4GZF.js";import{C as o,a as t,b as i,c as a,d as m,e as p,f as S,g,h as E,i as M,j as d,k as s,l as D,m as l,n as _,o as N,p as f,q as A,r as I,s as T,t as O,z as x}from"./chunk-6JQG6QDN.js";import{a as b,b as z,d as J,e as K,f as X,g as j,v as Ie,w as Te}from"./chunk-N5JWZ2VW.js";import{a as P,b as w,c as u,d as L}from"./chunk-3KAABUZQ.js";import"./chunk-5VRVC56Y.js";import{a as k,b as c,c as h,d as G}from"./chunk-5J4TV6XA.js";import{a as R,b as y}from"./chunk-A7MCBSAZ.js";import"./chunk-6LHJXZZ2.js";import{a as F,b as H,c as U,d as W}from"./chunk-QKHMJQO3.js";import{a as B}from"./chunk-7Z3CW6Q3.js";import{c as ae,d as me,i as pe,j as Se,o as ge,p as de,q as se,r as De,s as le,t as _e,u as Ne,v as fe}from"./chunk-AGTPMKLK.js";import{b as Z,c as $,d as ee,e as oe,f as re,o as ne,p as te,q as ie,r,s as n,t as Ee,u as Me}from"./chunk-LDVPFZCN.js";import"./chunk-XRJNLGI4.js";import{a as Oe,b as xe,c as Ce}from"./chunk-ZXZMYJ7F.js";import{a as v,b as Q,c as V}from"./chunk-YFFSTMIR.js";var Le=e(o);export{h as ADD_COMMENT_COMMAND,Ie as BLOCK_WIDTHS,b as BUILTIN_CODE_LANGUAGES,_e as BlockButtons,q as CODE_TOKEN_TYPES,f as COLOR_PRESETS,c as COMMENTS_THEME,i as CONNECTOR_TYPES,Ae as CharacterCount,G as CommentsPlugin,k as DEFAULT_COMMENTS_LABELS,B as DEFAULT_IMAGES_LABELS,$ as DEFAULT_LABELS,P as DEFAULT_MENTIONS_LABELS,re as DEFAULT_TABLE_SETTINGS,C as DRAWING_DATA_JSON_SCHEMA,r as DRAWING_FOCUS_COMMAND,O as DRAWING_SKELETON_JSON_SCHEMA,x as DrawingPlugin,Q as EDIT_LINK_COMMAND,p as EMPTY_DRAWING,g as FILL_COLORS,le as FormatButtons,fe as HistoryButtons,n as INSERT_DRAWING_COMMAND,F as INSERT_IMAGE_COMMAND,w as INSERT_MENTION_COMMAND,W as ImageButton,U as ImagesPlugin,Ne as InsertButtons,Le as MarkdownEditor,L as MentionsPlugin,D as NODE_SHAPE_DEFINITIONS,t as NODE_SHAPE_TYPES,z as PLAIN_LANGUAGE,Ce as PastePlugin,v as SAFE_LINK_PROTOCOLS,a as SHAPE_TYPES,E as SIDE_FIXED_POINTS,S as STROKE_COLORS,ne as TABLE_WIDTH_MARKER,Ee as TOOLBAR_ITEM_ATTRIBUTE,de as Toolbar,De as ToolbarButton,se as ToolbarDivider,H as UPLOAD_IMAGES_COMMAND,Se as canDeleteColumn,me as canDeleteRow,_ as createBinding,d as deserializeDrawingData,N as drawingToMermaid,T as expandDrawingSkeleton,u as findMentionMatch,l as findNodeShapeAt,R as formatCommentMarker,ie as formatTableSettingsMarker,j as getCodeLanguages,K as hasCodeLanguage,pe as insertableColumnIndices,ae as insertableRowIndices,Te as isBlockWidth,A as isDrawingSkeleton,m as isNodeShapeType,xe as isRichSourceHtml,V as isSafeUrl,s as normalizeDrawingData,Oe as normalizePastedHtml,y as parseCommentIds,I as parseDrawingSkeleton,te as parseTableSettingsMarker,J as registerCodeLanguage,X as resolveCodeLanguage,ee as resolveLabels,M as serializeDrawingData,Y as tokenizeCode,Z as useEditorContext,oe as useLabels,ge as useMarkdownEditor,Me as useToolbarKeyboard};
|
package/dist/lexical.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
"use client";import{b as e,c as o,e as t,f as r,g as a,h as b,i as D,k as h}from"./chunk-
|
|
2
|
+
"use client";import{b as e,c as o,e as t,f as r,g as a,h as b,i as D,k as h}from"./chunk-N6OUUWQO.js";import{A as v,B as H,C as U,u as k,v as z,w as K,x as L,y as B}from"./chunk-6JQG6QDN.js";import{h as c,i as I,j as C,k as O,l as w,m as _,n as W,o as u,p as y,q as F,r as G,s as P}from"./chunk-N5JWZ2VW.js";import{a as X,b as j,c as q,d as J}from"./chunk-5VRVC56Y.js";import{c as Q,d as V,e as Y,f as Z,g as ee}from"./chunk-A7MCBSAZ.js";import"./chunk-6LHJXZZ2.js";import{c as oe,d as te,e as re,f as ae,g as ne}from"./chunk-7Z3CW6Q3.js";import{a as p,b as $,e as f,f as g,g as R,h as E,k as x,l as A,m as S,n as M}from"./chunk-AGTPMKLK.js";import{g as n,h as d,i,j as m,k as l,l as s,m as N,n as T}from"./chunk-LDVPFZCN.js";import"./chunk-XRJNLGI4.js";import"./chunk-YFFSTMIR.js";export{z as $createDrawingNode,I as $createFrontmatterNode,te as $createImageNode,j as $createMentionNode,A as $deleteTableColumnAt,M as $deleteTableColumnNear,g as $deleteTableRowAt,E as $deleteTableRowNear,Y as $getCommentIds,V as $getMarkNodes,ae as $getSelectedImage,T as $getSelectedTable,p as $getSelectedTableCell,$ as $getTableCellPosition,s as $getTableDensity,n as $getTableSettings,m as $getTableWidth,x as $insertTableColumnAt,S as $insertTableColumnNear,f as $insertTableRowAt,R as $insertTableRowNear,K as $isDrawingNode,C as $isFrontmatterNode,re as $isImageNode,q as $isMentionNode,i as $isTableWidthExplicit,ee as $plainTextOffset,Z as $removeComment,r as $replaceMarkdown,N as $setTableDensity,d as $setTableSettings,l as $setTableWidth,W as CODE_BLOCK,Q as COMMENT,B as DIAGRAM,L as DRAWING,U as DRAWING_PRESET,v as DRAWING_PRESET_NODES,H as DRAWING_PRESET_TRANSFORMERS,k as DrawingNode,t as EXTERNAL_UPDATE_TAG,O as FRONTMATTER,c as FrontmatterNode,ne as IMAGE,oe as ImageNode,_ as LISTS,u as MARKDOWN_NODES,F as MARKDOWN_PRESET,y as MARKDOWN_TRANSFORMERS,J as MENTION,X as MentionNode,w as TABLE,e as codeTokenizer,h as createMarkdownEditor,b as editorNodeClassNames,D as mergeNodeClassNames,o as registerCodeBlockHighlighting,a as replaceMarkdown,G as resolveTransformers,P as shortcutTransformers};
|