@zuilib/text-editor 0.11.1 → 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 +202 -18
- package/DRAWING_FORMAT.md +23 -21
- package/README.md +531 -87
- package/dist/chunk-32RX4GZF.js +2 -0
- package/dist/chunk-3KAABUZQ.js +2 -0
- package/dist/chunk-5J4TV6XA.js +2 -0
- package/dist/chunk-5VRVC56Y.js +2 -0
- package/dist/chunk-6JQG6QDN.js +16 -0
- package/dist/chunk-6LHJXZZ2.js +2 -0
- package/dist/chunk-7Z3CW6Q3.js +2 -0
- package/dist/chunk-A7MCBSAZ.js +2 -0
- package/dist/chunk-AGTPMKLK.js +2 -0
- package/dist/chunk-LDVPFZCN.js +2 -0
- package/dist/chunk-N5JWZ2VW.js +9 -0
- package/dist/chunk-N6OUUWQO.js +5 -0
- package/dist/chunk-QKHMJQO3.js +2 -0
- package/dist/chunk-TGVEPLDM.js +1 -0
- package/dist/chunk-XRJNLGI4.js +2 -0
- package/dist/chunk-YFFSTMIR.js +2 -0
- package/dist/chunk-ZXZMYJ7F.js +2 -0
- package/dist/comment-markers-BrrrAdSL.d.ts +27 -0
- package/dist/comments.d.ts +68 -0
- package/dist/comments.js +2 -0
- package/dist/drawing-data-EWzEQ1_i.d.ts +111 -0
- package/dist/drawing-preset-Ag7a7F9h.d.ts +69 -0
- package/dist/drawing.d.ts +7 -0
- package/dist/drawing.js +2 -0
- package/dist/image-node-kR1Zf5kz.d.ts +70 -0
- package/dist/images.d.ts +66 -0
- package/dist/images.js +2 -0
- package/dist/index-A4S7bRwQ.d.ts +425 -0
- package/dist/index.d.ts +36 -1394
- package/dist/index.js +1 -7449
- package/dist/lexical.d.ts +117 -0
- package/dist/lexical.js +2 -0
- package/dist/markdown.d.ts +29 -0
- package/dist/markdown.js +2 -0
- package/dist/mention-node-eSsjUpaE.d.ts +44 -0
- package/dist/mentions-plugin-gio3_XKd.d.ts +74 -0
- package/dist/mentions.d.ts +5 -0
- package/dist/mentions.js +2 -0
- package/dist/mermaid-BwGHjwpk.d.ts +553 -0
- package/dist/paste.d.ts +45 -0
- package/dist/paste.js +2 -0
- package/dist/presets-BtNPH0pa.d.ts +78 -0
- package/dist/styles.css +612 -96
- package/dist/table-grid-D70tNhp2.d.ts +459 -0
- package/dist/tailwind.css +7 -0
- package/package.json +58 -27
- package/dist/index.css +0 -79
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var e={$schema:"http://json-schema.org/draft-07/schema#",title:"DrawingData",description:"Vector drawing embedded in markdown as a ```drawing fenced code block (format version 3)",type:"object",required:["version","canvasHeight","shapes"],additionalProperties:!1,properties:{version:{const:3,description:"Format version; always 3"},canvasHeight:{type:"number",minimum:80,description:"Canvas height in pixels. Make it large enough to contain every shape plus ~20px margin."},canvasWidth:{type:"number",minimum:120,description:"Optional logical canvas width in pixels. When set, the drawing is scaled down to fit narrower layouts (SVG viewBox) so coordinates can assume this width. When omitted the canvas is fluid and coordinates are CSS pixels."},width:{enum:["full","text","content"],description:`Block width: "full" (default, omit it) spans the editor; "text" aligns the block with the text column (same as "full" unless the app sets a text measure); "content" fits the shapes' horizontal extent and left-aligns with the text`},title:{type:"string",description:"Optional accessible name of the drawing, read by screen readers in place of the shapes"},description:{type:"string",description:"Optional longer accessible description of what the drawing shows"},shapes:{type:"array",items:{$ref:"#/definitions/shape"},maxItems:5e3,description:"Render order: later shapes draw on top"}},definitions:{point:{type:"object",required:["x","y"],additionalProperties:!1,properties:{x:{type:"number",description:"Absolute canvas x"},y:{type:"number",description:"Absolute canvas y"}}},binding:{type:"object",description:"Where a connector endpoint attaches to a box. Omit fixedPoint to let the endpoint auto-aim from the box center at the other end.",required:["id"],additionalProperties:!1,properties:{id:{type:"string",description:"Id of the box this endpoint is attached to"},fixedPoint:{type:"array",items:{type:"number",minimum:0,maximum:1},minItems:2,maxItems:2,description:"Attach point as a ratio of the box's bounding box: [0,0] top-left, [1,1] bottom-right, [0.5,0] top edge midpoint, [1,0.5] right edge midpoint. Omitted: the endpoint auto-aims from the box center at the other end."},mode:{enum:["orbit","inside"],description:'"orbit" (default): the endpoint is projected onto the box outline with a 6px gap. "inside": the endpoint sits exactly on the fixed point.'}}},shape:{type:"object",required:["id","type","x","y","width","height","stroke","fill","strokeWidth"],additionalProperties:!1,properties:{id:{type:"string",description:"Unique within the drawing; connector bindings reference it"},type:{enum:["rect","ellipse","diamond","note","cylinder","cloud","queue","actor","arrow","line","text"],description:"Boxes (cards with label/text/footer slots): rect, ellipse, diamond, note (sticky note with a folded corner), cylinder (database), cloud, queue (horizontal cylinder), actor (stick figure; only the text slot, rendered as a name under the figure). Connectors: arrow (head at the end), line. Free-floating annotation: text."},x:{type:"number",description:"Boxes/text: left edge of the bounding box. Connectors: start point x."},y:{type:"number",description:"Boxes/text: top edge of the bounding box. Connectors: start point y."},width:{type:"number",description:"Boxes/text: width (non-negative). Connectors: delta x to the end point (may be negative)."},height:{type:"number",description:"Boxes/text: height (non-negative). Connectors: delta y to the end point (may be negative)."},stroke:{type:"string",description:"CSS color of the outline (and of any text). Palette: #1e1e1e (default), #e03131 red, #2f9e44 green, #1971c2 blue, #f08c00 orange, #7048e8 purple."},fill:{type:"string",description:'CSS color of the interior; "transparent" for none. Palette: #ffc9c9 red, #b2f2bb green, #a5d8ff blue, #ffec99 yellow, #d0bfff purple.'},strokeWidth:{type:"number",description:"Outline width; use 2"},text:{type:"string",description:"Standalone text content; center content of a box (the name under an actor); midpoint label of a connector"},label:{type:"string",description:"Boxes only (not actor): small bold heading at the top"},footer:{type:"string",description:"Boxes only (not actor): small dim line at the bottom"},startBinding:{$ref:"#/definitions/binding",description:"Connectors only: box the start point attaches to. The editor re-anchors the endpoint onto that box and keeps it attached as the box moves."},endBinding:{$ref:"#/definitions/binding",description:"Connectors only: box the end point attaches to"},bidirectional:{type:"boolean",description:"Arrows only: arrowheads on both ends"},routing:{const:"elbow",description:"Connectors only: right-angled auto-routed path. It leaves the box perpendicular to the attach side, avoids every box on the canvas and minimises bends. Ignored when waypoints are present."},elbow:{type:"number",minimum:0,maximum:1,description:"Elbow override: position of the middle segment as a fraction of the span. Applied only when the routed path is a simple three-segment Z."},waypoints:{type:"array",items:{$ref:"#/definitions/point"},description:"Connectors only: intermediate path points in canvas coordinates, ordered start to end. Takes precedence over routing."}}}}};export{e as a};
|
|
@@ -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,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{a,c as g}from"./chunk-XRJNLGI4.js";import{$applyNodeReplacement as c,TextNode as p}from"lexical";function u(e){return e.replace(/[%)\s]/g,t=>t===")"?"%29":encodeURIComponent(t))}function m(e){try{return decodeURIComponent(e)}catch{return e}}var o=class e extends p{static getType(){return"mention"}static clone(t){return new e(t.__id,t.__name,t.__trigger,t.__key)}constructor(t,n,r="@",i){super(r+n,i),this.__id=t,this.__name=n,this.__trigger=r}static importJSON(t){return s(t.mentionId,t.mentionName,t.trigger).updateFromJSON(t)}exportJSON(){return{...super.exportJSON(),type:"mention",version:1,mentionId:this.__id,mentionName:this.__name,trigger:this.__trigger}}createDOM(t){let n=super.createDOM(t),r=t.theme.mention;return n.className=typeof r=="string"?r:"zui-mention",n.setAttribute("data-mention",this.__id),n.setAttribute("data-slot","mention"),n.spellcheck=!1,n}exportDOM(){let t=document.createElement("span");return t.setAttribute("data-lexical-mention",this.__id),t.setAttribute("data-trigger",this.__trigger),t.textContent=this.getTextContent(),{element:t}}static importDOM(){return{span:t=>t.hasAttribute("data-lexical-mention")?{conversion:n=>{let r=n.getAttribute("data-trigger")??"@",i=n.textContent??"",d=i.startsWith(r)?i.slice(r.length):i;return{node:s(n.getAttribute("data-lexical-mention")??"",d,r)}},priority:2}:null}}getMentionId(){return this.getLatest().__id}getMentionName(){return this.getLatest().__name}getTrigger(){return this.getLatest().__trigger}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}isTextEntity(){return!0}};function s(e,t,n="@"){let r=new o(e,t,n);return r.setMode("token").toggleDirectionless(),c(r)}function l(e){return e instanceof o}var _=/\[([^\w\s\]\\])((?:\\.|[^\]\\])+)\]\(mention:([^)\s]+)\)/,M=/\[([^\w\s\]\\])((?:\\.|[^\]\\])+)\]\(mention:([^)\s]+)\)$/,h={dependencies:[o],export:e=>l(e)?`[${e.getTrigger()}${a(e.getMentionName())}](mention:${u(e.getMentionId())})`:null,importRegExp:_,regExp:M,replace:(e,t)=>{let[,n,r,i]=t;e.replace(s(m(i),g(r),n))},trigger:")",type:"text-match"};export{o as a,s as b,l as c,h 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,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{a as I,b as E,c as m}from"./chunk-XRJNLGI4.js";import{c as d}from"./chunk-YFFSTMIR.js";import{useCallback as O,useEffect as L,useRef as D,useState as T}from"react";import{$applyNodeReplacement as C,$getNodeByKey as R,$getSelection as $,$isNodeSelection as k,CLICK_COMMAND as z,COMMAND_PRIORITY_LOW as w,DecoratorNode as v}from"lexical";import{useLexicalComposerContext as P}from"@lexical/react/LexicalComposerContext";import{useLexicalNodeSelection as K}from"@lexical/react/useLexicalNodeSelection";import{useLexicalEditable as B}from"@lexical/react/useLexicalEditable";import{mergeRegister as W}from"@lexical/utils";import{jsx as l,jsxs as Q}from"react/jsx-runtime";function M(t){return t.replace(/[\s()]/g,e=>e==="("?"%28":e===")"?"%29":encodeURIComponent(e))}var G={altText:"Alt text",altPlaceholder:"Describe the image",uploading:"Uploading image",insertImage:"Insert image"},S=new WeakMap;function ie(t,e){S.set(t,e)}function H(t){return S.get(t)??G}function U({nodeKey:t,src:e,alt:r,title:n,pending:a}){let[s]=P(),A=B(),[x,h,b]=K(t),u=H(s),p=D(null),[c,y]=T(r);L(()=>y(r),[r]),L(()=>W(s.registerCommand(z,i=>{let g=i.target;return!(g instanceof Node)||!p.current?.contains(g)||g instanceof HTMLElement&&g.closest("input")?!1:(i.shiftKey||b(),h(!0),!0)},w)),[s,h,b]);let N=O(()=>{s.update(()=>{let i=R(t);f(i)&&i.getAlt()!==c&&i.setAlt(c)})},[s,t,c]);return a?l("span",{ref:p,className:"zui-image-pending",role:"progressbar","aria-label":u.uploading,"aria-busy":"true","data-slot":"image-pending",children:l("span",{className:"zui-image-spinner","aria-hidden":"true"})}):Q("span",{ref:p,className:`zui-image-frame${x?" is-selected":""}`,"data-slot":"image",children:[l("img",{src:e,alt:r,title:n,draggable:!1}),x&&A&&l("span",{className:"zui-image-alt","data-slot":"image-alt",children:l("input",{type:"text",className:"zui-text-editor-link-input","aria-label":u.altText,placeholder:u.altPlaceholder,value:c,onChange:i=>y(i.target.value),onBlur:N,onKeyDown:i=>{(i.key==="Enter"||i.key==="Escape")&&(i.preventDefault(),N(),s.focus())}})})]})}var o=class t extends v{static getType(){return"image"}static clone(e){return new t(e.__src,e.__alt,e.__title,e.__pending,e.__key)}constructor(e,r="",n,a=!1,s){super(s),this.__src=M(e),this.__alt=r,this.__title=n,this.__pending=a}static importJSON(e){return _({src:e.src,alt:e.alt,title:e.title})}exportJSON(){return{type:"image",version:1,src:this.__src,alt:this.__alt,title:this.__title}}createDOM(e){let r=document.createElement("span"),n=e.theme.image;return r.className=typeof n=="string"?n:"zui-image",r}updateDOM(){return!1}exportDOM(){let e=document.createElement("img");return e.setAttribute("src",this.__src),e.setAttribute("alt",this.__alt),this.__title&&e.setAttribute("title",this.__title),{element:e}}static importDOM(){return{img:()=>({conversion:e=>{let r=e.getAttribute("src")??"";return!r||!d(r)?null:{node:_({src:r,alt:e.getAttribute("alt")??"",title:e.getAttribute("title")??void 0})}},priority:1})}}isInline(){return!0}isKeyboardSelectable(){return!0}getSrc(){return this.getLatest().__src}getAlt(){return this.getLatest().__alt}getTitle(){return this.getLatest().__title}isPending(){return this.getLatest().__pending}setSrc(e){let r=this.getWritable();return r.__src=M(e),r}setAlt(e){let r=this.getWritable();return r.__alt=e,r}setPending(e){let r=this.getWritable();return r.__pending=e,r}getTextContent(){return this.__pending?"":this.__alt}decorate(){return l(U,{nodeKey:this.__key,src:this.__src,alt:this.__alt,title:this.__title,pending:this.__pending})}};function _({src:t,alt:e="",title:r,pending:n=!1}){return C(new o(t,e,r,n))}function f(t){return t instanceof o}function ne(){let t=$();if(!k(t))return null;let e=t.getNodes();return e.length===1&&f(e[0])?e[0]:null}function J(t){let e=I(t.getAlt()),r=t.getTitle();return r?`} "${E(r)}")`:`})`}var Y=/!\[((?:\\.|[^\]\\])*)\]\(([^()\s]+)(?:\s"((?:\\.|[^"\\])*)")?\)/,F=/!\[((?:\\.|[^\]\\])*)\]\(([^()\s]+)(?:\s"((?:\\.|[^"\\])*)")?\)$/,se={dependencies:[o],export:t=>f(t)?t.isPending()?"":J(t):null,importRegExp:Y,regExp:F,replace:(t,e)=>{let[,r,n,a]=e;d(n)&&t.replace(_({src:n,alt:m(r),title:a===void 0?void 0:m(a)}))},trigger:")",type:"text-match"};export{G as a,ie as b,o as c,_ as d,f as e,ne as f,se as g};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{$createTextNode as l,$getRoot as c,$isElementNode as m}from"lexical";import{$createMarkNode as u,$isMarkNode as a,$unwrapMarkNode as p,MarkNode as g}from"@lexical/mark";import{$dfs as d}from"@lexical/utils";var x=/<!-- zui:comment ([^\s>]+) -->([\s\S]*?)<!-- \/zui:comment -->/,M=/<!-- zui:comment ([^\s>]+) -->([\s\S]*?)<!-- \/zui:comment -->$/;function $(e,t){return`<!-- zui:comment ${e.join(",")} -->${t}<!-- /zui:comment -->`}function N(e){return e.split(",").filter(t=>t.length>0)}var C={dependencies:[g],export:(e,t)=>a(e)?$(e.getIDs(),t(e)):null,importRegExp:x,regExp:M,replace:(e,t)=>{let[,r,o]=t,i=u(N(r)),n=l(o);return n.setFormat(e.getFormat()),i.append(n),e.replace(i),n},type:"text-match"};function f(){return d(c()).map(e=>e.node).filter(a)}function I(){let e=[];for(let t of f())for(let r of t.getIDs())e.includes(r)||e.push(r);return e}function z(e){let t=!1;for(let r of f())r.hasID(e)&&(t=!0,r.getIDs().length===1?p(r):r.deleteID(e));return t}function E(e){let t=0,r=o=>{if(o.is(e))return!0;if(m(o)){let i=o.getChildren();for(let n=0;n<i.length;n++){let s=i[n];if(r(s))return!0;m(s)&&!s.isInline()&&n<i.length-1&&(t+=2)}return!1}return t+=o.getTextContentSize(),!1};return r(c()),t}export{$ as a,N as b,C as c,f as d,I as e,z as f,E as g};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{b as G,e as S,g as Q,h as I,n as p,r as V,s as X,t as Y,u as j}from"./chunk-LDVPFZCN.js";import{b as z}from"./chunk-YFFSTMIR.js";import{$createParagraphNode as Le,$getNodeByKey as De,$getSelection as Oe,$isRangeSelection as Ee}from"lexical";import{$findMatchingParent as Ae}from"@lexical/utils";import{$createTableCellNode as Ie,$createTableRowNode as _e,$isTableCellNode as _,$isTableNode as Pe,$isTableRowNode as J,$isTableSelection as Fe,TableCellHeaderStates as T}from"@lexical/table";function y(e){return e.getChildren().filter(J)}function g(e){return e.getChildren().filter(_)}function O(e){let t=e?g(e):[];return t.length>0&&t.every(o=>o.hasHeaderState(T.ROW))}function F(e){let t=y(e)[0];return t?g(t).length:0}function P(e){return Ie(e).append(Le())}function E(e,t,o){let l=y(e),a=l[Math.max(0,Math.min(t,l.length-1))],i=a?g(a):[];i[Math.max(0,Math.min(o,i.length-1))]?.selectStart()}function He(){let e=Oe(),t=null;if(Fe(e)?t=De(e.anchor.key):Ee(e)&&(t=e.anchor.getNode()),!t)return null;let o=Ae(t,l=>_(l));return _(o)?o:null}function R(){let e=He(),t=e?.getParent(),o=t?.getParent();if(!e||!J(t)||!Pe(o))return null;let l=y(o);return{row:l.indexOf(t),column:g(t).indexOf(e),rows:l.length,columns:F(o),hasHeader:O(l[0])}}function Rt(e){let t=[];for(let o=e.hasHeader?1:0;o<=e.rows;o++)t.push(o);return t}function Ke(e){return e.rows>1}function Ue(e,t,o=0){let l=y(e),a=O(l[0])?1:0,i=Math.max(a,Math.min(t,l.length)),d=l[Math.max(0,i-1)]??l[0],m=d?g(d):[],h=_e();for(let x of m)h.append(P(x.hasHeaderState(T.COLUMN)?T.COLUMN:T.NO_STATUS));return m.length===0&&h.append(P(T.NO_STATUS)),i>=l.length?e.append(h):l[i].insertBefore(h),E(e,i,o),h}function qe(e,t,o=0){let l=y(e),a=l[t];if(!a||l.length<2)return!1;let i=t===0&&O(a);a.remove();let d=y(e);if(i)for(let m of g(d[0]))m.setHeaderStyles(T.ROW,T.ROW);return E(e,t,o),!0}function Z(e,t){let o=R();return o?Ue(e,t==="below"?o.row+1:o.row,o.column):null}function ee(e){let t=R();return!t||!Ke(t)?!1:qe(e,t.row,t.column)}function Bt(e){let t=[];for(let o=0;o<=e.columns;o++)t.push(o);return t}function ze(e){return e.columns>1}function Ge(e,t,o=0){let l=Math.max(0,Math.min(t,F(e)));for(let a of y(e)){let i=g(a),d=P(O(a)?T.ROW:T.NO_STATUS);l<i.length?i[l].insertBefore(d):a.append(d)}E(e,o,l)}function Qe(e,t,o=0){let l=F(e);if(t<0||t>=l||l<2)return!1;for(let a of y(e))g(a)[t]?.remove();return E(e,o,t),!0}function te(e,t){let o=R();return o?(Ge(e,t==="after"?o.column+1:o.column,o.row),!0):!1}function oe(e){let t=R();return!t||!ze(t)?!1:Qe(e,t.column,t.row)}import{useCallback as u,useEffect as Ve,useRef as Xe,useState as f}from"react";import{$createParagraphNode as Ye,$getNodeByKey as ie,$getSelection as v,$isRangeSelection as L,$isRootOrShadowRoot as je,CAN_REDO_COMMAND as Je,CAN_UNDO_COMMAND as Ze,COMMAND_PRIORITY_LOW as H,FORMAT_TEXT_COMMAND as et,REDO_COMMAND as tt,UNDO_COMMAND as ot}from"lexical";import{useLexicalComposerContext as nt}from"@lexical/react/LexicalComposerContext";import{INSERT_TABLE_COMMAND as lt}from"@lexical/table";import{$findMatchingParent as K,mergeRegister as rt}from"@lexical/utils";import{$setBlocksType as at}from"@lexical/selection";import{$createHeadingNode as it,$createQuoteNode as ct,$isHeadingNode as st,$isQuoteNode as dt}from"@lexical/rich-text";import{$isListNode as ne,INSERT_CHECK_LIST_COMMAND as ut,INSERT_ORDERED_LIST_COMMAND as bt,INSERT_UNORDERED_LIST_COMMAND as ht,REMOVE_LIST_COMMAND as le}from"@lexical/list";import{$isLinkNode as mt,TOGGLE_LINK_COMMAND as pt}from"@lexical/link";var Tt=["bold","italic","underline","strikethrough","code"];function ce(e){return e!==null&&typeof e.getBlockWidth=="function"&&typeof e.setBlockWidth=="function"}function $(){let e=v();if(!L(e))return null;let t=e.anchor.getNode(),o=t.getKey()==="root"?t:K(t,l=>{let a=l.getParent();return a!==null&&je(a)});if(o===null)return null;if(ne(o)){let a=(K(t,i=>ne(i)&&i.getParent()?.getType()!=="listitem")??o).getListType();return a==="bullet"?"bullet":a==="number"?"number":"check"}return st(o)?o.getTag():dt(o)?"quote":"paragraph"}function re(){let e=v();if(!L(e))return null;let t=K(e.anchor.getNode(),mt);return t?{key:t.getKey(),url:t.getURL()}:null}function ae(e){if(e===null)return null;let t=ie(e);return ce(t)?t.getBlockWidth():null}function B(){let[e]=nt(),{newBlockWidth:t}=G(),[o,l]=f(new Set),[a,i]=f(!1),[d,m]=f(!1),[h,x]=f(null),[de,ue]=f(null),[be,he]=f(null),[me,pe]=f(null),[Te,U]=f(!1),A=Xe(null),[fe,q]=f(null);Ve(()=>rt(e.registerUpdateListener(({editorState:r})=>{r.read(()=>{let c=p();x(c?Q(c):null),ue(c?R():null),q(ae(A.current)),he($());let b=re();pe(w=>w?.key===b?.key&&w?.url===b?.url?w:b);let W=v();if(!L(W)){l(new Set),U(!1);return}U(!W.isCollapsed());let C=new Set;for(let w of Tt)W.hasFormat(w)&&C.add(w);l(C)})}),e.registerCommand(V,r=>(A.current=r,q(e.getEditorState().read(()=>ae(r))),!1),H),e.registerCommand(Ze,r=>(i(r),!1),H),e.registerCommand(Je,r=>(m(r),!1),H)),[e]);let ke=u(r=>{e.dispatchCommand(et,r)},[e]),ye=u(({rows:r=3,columns:c=3,width:b=t.table}={})=>{let W=e.getEditorState().read(()=>p()?.getKey());e.dispatchCommand(lt,{columns:String(c),rows:String(r),includeHeaders:{rows:!0,columns:!1}}),b!==void 0&&e.update(()=>{let C=p();C&&C.getKey()!==W&&I(C,{width:b},{explicitWidth:!0})})},[e,t.table]),ge=u(({width:r=t.drawing}={})=>{e.dispatchCommand(X,r===void 0?void 0:{width:r})},[e,t.drawing]),Ne=u(r=>{if(r==="bullet"||r==="number"||r==="check"){if(e.getEditorState().read($)===r){e.dispatchCommand(le,void 0);return}let b=r==="bullet"?ht:r==="number"?bt:ut;e.dispatchCommand(b,void 0);return}e.update(()=>{let c=v();L(c)&&(($()==="bullet"||$()==="number"||$()==="check")&&e.dispatchCommand(le,void 0),at(c,()=>r==="paragraph"?Ye():r==="quote"?ct():it(r)))})},[e]),Me=u(r=>{r!==null&&!e.getEditorState().read(()=>{let b=v();return L(b)?!b.isCollapsed()||re()!==null:!1})||e.dispatchCommand(pt,r)},[e]),M=u(r=>{e.update(()=>{let c=p();c&&I(c,r)})},[e]),Ce=u(r=>M({width:r}),[M]),we=u(r=>M({density:r}),[M]),Re=u((r="below")=>{e.update(()=>{let c=p();c&&Z(c,r)})},[e]),Be=u(()=>{e.update(()=>{let r=p();r&&ee(r)})},[e]),xe=u((r="after")=>{e.update(()=>{let c=p();c&&te(c,r)})},[e]),We=u(()=>{e.update(()=>{let r=p();r&&oe(r)})},[e]),Se=u(r=>{let c=A.current;if(c===null){M({width:r});return}e.update(()=>{let b=ie(c);ce(b)&&b.setBlockWidth(r)})},[e,M]),$e=u(()=>{e.dispatchCommand(ot,void 0)},[e]),ve=u(()=>{e.dispatchCommand(tt,void 0)},[e]);return{editor:e,activeFormats:o,toggleFormat:ke,blockType:be,setBlockType:Ne,link:me,setLink:Me,hasSelection:Te,insertTable:ye,insertDrawing:ge,blockWidth:fe??h?.width??null,setBlockWidth:Se,tableWidth:h?.width??null,setTableWidth:Ce,tableDensity:h?.density??null,setTableDensity:we,tableCell:de,insertTableRow:Re,deleteTableRow:Be,insertTableColumn:xe,deleteTableColumn:We,canUndo:a,canRedo:d,undo:$e,redo:ve}}import{Fragment as D,jsx as n,jsxs as k}from"react/jsx-runtime";function Qt({children:e,className:t,label:o}){let l=j();return n("div",{className:`zui-text-editor-toolbar ${t??""}`,role:"toolbar","aria-label":o,"data-slot":"toolbar",...l,children:e??k(D,{children:[n(kt,{}),n(se,{}),n(gt,{}),n(se,{}),n(Nt,{})]})})}function se(){return n("div",{className:"zui-text-editor-toolbar-divider",role:"separator","aria-orientation":"vertical"})}function N({label:e,onClick:t,children:o,active:l=!1,disabled:a=!1,className:i}){return n("button",{type:"button",title:e,"aria-label":e,"aria-pressed":l,disabled:a,className:`zui-text-editor-toolbar-button ${l?"is-active":""} ${i??""}`,onMouseDown:d=>d.preventDefault(),onClick:t,[Y]:"",children:o})}function s({children:e,strokeWidth:t=1.5}){return n("svg",{viewBox:"0 0 20 20",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:t,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e})}var ft=[{format:"bold",label:"bold",icon:n(s,{strokeWidth:1.8,children:n("path",{d:"M6 3.5h5a3 3 0 0 1 0 6H6zm0 6h6a3 3 0 0 1 0 6H6z"})})},{format:"italic",label:"italic",icon:n(s,{strokeWidth:1.6,children:n("path",{d:"M8.5 3.5h6M5.5 16.5h6M11.5 3.5l-3 13"})})},{format:"strikethrough",label:"strikethrough",icon:n(s,{strokeWidth:1.6,children:n("path",{d:"M4 10h12M13.5 5.5c-.6-1.2-2-2-3.5-2-2 0-3.5 1.2-3.5 2.8 0 .5.1.9.4 1.3m-.4 5c.5 1.6 2 2.9 3.9 2.9 2 0 3.6-1.2 3.6-2.9 0-.4-.1-.8-.2-1.1"})})},{format:"code",label:"code",icon:n(s,{strokeWidth:1.6,children:n("path",{d:"M7.5 6L4 10l3.5 4M12.5 6L16 10l-3.5 4"})})}];function kt(){let{editor:e,activeFormats:t,toggleFormat:o,link:l,setLink:a,hasSelection:i}=B(),d=S().toolbar;return k(D,{children:[ft.map(({format:m,label:h,icon:x})=>n(N,{label:d[h],active:t.has(m),onClick:()=>o(m),children:x},m)),n(N,{label:l?d.removeLink:d.link,active:l!==null,disabled:l===null&&!i,onClick:()=>l?a(null):e.dispatchCommand(z,void 0),children:n(s,{strokeWidth:1.6,children:n("path",{d:"M8.5 11.5l3-3M11 6.5l1.5-1.5a2.5 2.5 0 0 1 3.5 3.5L14.5 10M9 13.5L7.5 15a2.5 2.5 0 0 1-3.5-3.5L5.5 10"})})})]})}var yt=[{type:"h1",label:"heading1",icon:n(s,{strokeWidth:1.6,children:n("path",{d:"M3 4.5v11M3 10h7M10 4.5v11M14.5 15.5v-6l-1.5 1"})})},{type:"h2",label:"heading2",icon:n(s,{strokeWidth:1.6,children:n("path",{d:"M3 4.5v11M3 10h7M10 4.5v11M13.5 10.5a1.5 1.5 0 0 1 3 0c0 1.5-3 2.5-3 5h3.2"})})},{type:"h3",label:"heading3",icon:n(s,{strokeWidth:1.6,children:n("path",{d:"M3 4.5v11M3 10h7M10 4.5v11M13.5 9.5h3l-2 2.5a1.5 1.5 0 1 1-1.2 2.5"})})},{type:"bullet",label:"bulletList",icon:k(s,{strokeWidth:1.6,children:[n("path",{d:"M7 5.5h10M7 10h10M7 14.5h10"}),n("circle",{cx:"3.5",cy:"5.5",r:"0.8",fill:"currentColor"}),n("circle",{cx:"3.5",cy:"10",r:"0.8",fill:"currentColor"}),n("circle",{cx:"3.5",cy:"14.5",r:"0.8",fill:"currentColor"})]})},{type:"number",label:"numberedList",icon:n(s,{strokeWidth:1.6,children:n("path",{d:"M8 5.5h9M8 10h9M8 14.5h9M3 4l1-.5v3.5M2.8 11.5a1 1 0 0 1 2 0c0 1-2 1.5-2 2.5h2.2"})})},{type:"check",label:"checklist",icon:n(s,{strokeWidth:1.6,children:n("path",{d:"M9 5.5h8M9 10h8M9 14.5h8M2.5 6l1.5 1.5 2.5-3M2.5 10.5l1.5 1.5 2.5-3"})})},{type:"quote",label:"quote",icon:n(s,{strokeWidth:1.6,children:n("path",{d:"M4 5v10M8 6h8M8 10h8M8 14h5"})})}];function gt(){let{blockType:e,setBlockType:t}=B(),o=S().toolbar;return n(D,{children:yt.map(({type:l,label:a,icon:i})=>n(N,{label:o[a],active:e===l,onClick:()=>t(e===l?"paragraph":l),children:i},l))})}function Nt({drawing:e=!0}={}){let{insertTable:t,insertDrawing:o}=B(),l=S().toolbar;return k(D,{children:[n(N,{label:l.insertTable,onClick:()=>t(),children:k(s,{children:[n("rect",{x:"3",y:"3.5",width:"14",height:"13",rx:"1.5"}),n("path",{d:"M3 8h14M8 8v8.5M13 8v8.5"})]})}),e&&n(N,{label:l.insertDrawing,onClick:()=>o(),children:k(s,{children:[n("rect",{x:"3",y:"5",width:"8",height:"6",rx:"1.5"}),n("path",{d:"M13.5 8h3M14.5 6.5L17.5 8l-3 1.5"}),n("ellipse",{cx:"13",cy:"14.5",rx:"4",ry:"2.8"})]})})]})}function Vt(){let{canUndo:e,canRedo:t,undo:o,redo:l}=B(),a=S().toolbar;return k(D,{children:[n(N,{label:a.undo,onClick:o,disabled:!e,children:k(s,{children:[n("path",{d:"M7 6L3.5 9.5 7 13"}),n("path",{d:"M3.5 9.5H12a4 4 0 0 1 0 8h-1"})]})}),n(N,{label:a.redo,onClick:l,disabled:!t,children:k(s,{children:[n("path",{d:"M13 6l3.5 3.5L13 13"}),n("path",{d:"M16.5 9.5H8a4 4 0 0 0 0 8h1"})]})})]})}export{He as a,R as b,Rt as c,Ke as d,Ue as e,qe as f,Z as g,ee as h,Bt as i,ze as j,Ge as k,Qe as l,te as m,oe as n,B as o,Qt as p,se as q,N as r,kt as s,gt as t,Nt as u,Vt as v};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{createContext as N,useContext as I}from"react";var b=N(null);function Y(){let e=I(b);if(!e)throw new Error("@zuilib/text-editor: this component must be rendered inside <MarkdownEditor> or <MarkdownEditor.Root>");return e}import{useContext as $}from"react";var m={placeholder:"Start writing...",toolbar:{bold:"Bold",italic:"Italic",strikethrough:"Strikethrough",code:"Inline code",link:"Link",removeLink:"Remove link",heading1:"Heading 1",heading2:"Heading 2",heading3:"Heading 3",paragraph:"Paragraph",bulletList:"Bullet list",numberedList:"Numbered list",checklist:"Checklist",quote:"Quote",insertTable:"Insert table",insertDrawing:"Insert drawing",undo:"Undo",redo:"Redo",linkUrl:"Link URL",linkUrlPlaceholder:"https://",linkApply:"Apply"},count:(e,t)=>t===void 0?String(e):`${e} / ${t}`,limitExceeded:e=>`Over the limit of ${e} characters`,limitRestored:e=>`Within the limit of ${e} characters`,outline:{show:"Show outline",hide:"Hide outline",title:"Table of contents",empty:"No headings",untitled:"Untitled"},collapsibleHeadings:{collapse:"Collapse section",expand:"Expand section",collapsed:"Section collapsed",expanded:"Section expanded"},table:{settings:"Table settings",rowInserted:"Row inserted",rowDeleted:"Row deleted",columnInserted:"Column inserted",columnDeleted:"Column deleted",addRow:"Add row",addColumn:"Add column",insertRowBefore:e=>`Insert row before row ${e}`,insertColumnBefore:e=>`Insert column before column ${e}`,deleteRow:e=>`Delete row ${e}`,deleteColumn:e=>`Delete column ${e}`},layout:{compact:"Compact (shrink to content, tight rows)",comfortable:"Comfortable (text width)",full:"Full width"},drawing:{canvas:"Drawing",tools:"Drawing tools",select:"Select",rect:"Rectangle",ellipse:"Ellipse",diamond:"Diamond",arrow:"Arrow",line:"Line",text:"Text",note:"Note",cylinder:"Database",cloud:"Cloud",queue:"Queue",actor:"Actor",moreShapes:"More shapes",copyMermaid:"Copy as Mermaid",copiedMermaid:"Copied Mermaid to clipboard",colors:"Color",color:e=>`Color ${e}`,connectorRouting:"Connector routing",straight:"Straight connector",elbow:"Elbow connector (auto-routed)",arrowDirection:"Arrow direction",oneWay:"One-way arrow",twoWay:"Two-way arrow",deleteShape:"Delete shape",deleteShapes:e=>`Delete ${e} shapes`,resize:"Drag to resize the canvas",waypoint:"Drag to move, double-click to remove",elbowHandle:"Slide the middle segment",labelPlaceholder:"Label",textPlaceholder:"Text",footerPlaceholder:"Footer"}};function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function R(e,t){if(!S(e)||!S(t))return t===void 0?e:t;let n={...e};for(let r of Object.keys(t))r in e&&(n[r]=R(e[r],t[r]));return n}function Z(e){return e?R(m,e):m}function ee(){return $(b)?.labels??m}import{$getNodeByKey as W,$getSelection as P,$isRangeSelection as B}from"lexical";import{$findMatchingParent as _}from"@lexical/utils";import{$isTableNode as f,$isTableSelection as H}from"@lexical/table";var D={width:"full",density:"comfortable"},k="--zui-text-editor-block-bleed",g={width:{full:{},content:{width:"auto","table-layout":"auto",[k]:"0px"},text:{[k]:"0px"}},density:{comfortable:{},compact:{"--zui-table-cell-padding":"0.25rem 0.5rem","--zui-table-font-size":"0.8125rem"},spacious:{"--zui-table-cell-padding":"0.875rem 1rem","--zui-table-font-size":"0.9375rem"}}},C=Object.keys(g),y="--zui-table-width";function h(e){let t=new Map;for(let n of e.split(";")){let r=n.indexOf(":");if(r===-1)continue;let o=n.slice(0,r).trim(),l=n.slice(r+1).trim();o&&l&&t.set(o,l)}return t}function z(e){return[...e].map(([t,n])=>`${t}: ${n}`).join("; ")}function M(e){return Object.entries(g[e])}function T(e,t){for(let[n,r]of M(t)){let o=Object.entries(r);if(o.length!==0&&o.every(([l,a])=>e.get(l)===a))return n}return D[t]}function F(e,t,n){for(let[,r]of M(t))for(let o of Object.keys(r))e.delete(o);for(let[r,o]of Object.entries(g[t][n]))e.set(r,o)}function A(e){let t=h(e.getStyle());return{width:T(t,"width"),density:T(t,"density")}}function v(e,t,n={}){let r=h(e.getStyle());for(let o of C){let l=t[o];l!==void 0&&F(r,o,l)}t.width!==void 0&&(n.explicitWidth?r.set(y,t.width):r.delete(y)),e.setStyle(z(r))}function ie(e){let t=h(e.getStyle());return t.get(y)===T(t,"width")}function le(e){return A(e).width}function se(e,t){v(e,{width:t})}function ae(e){return A(e).density}function de(e,t){v(e,{density:t})}function ce(){let e=P();if(H(e)){let n=W(e.tableKey);return f(n)?n:null}if(!B(e))return null;let t=_(e.anchor.getNode(),n=>f(n));return f(t)?t:null}var j=/^<!--\s*([a-z]+\s*:\s*[a-z]+(?:\s*;\s*[a-z]+\s*:\s*[a-z]+)*)\s*;?\s*-->\s*$/;function L(e,t){return t in g[e]}var ue="<!-- width: content -->";function ge(e){let t=j.exec(e);if(!t)return null;let n={},r=!1;for(let o of t[1].split(";")){let[l,a]=o.split(":").map(i=>i.trim());l!=="width"&&l!=="density"||(r=!0,l==="width"&&L("width",a)&&(n.width=a),l==="density"&&L("density",a)&&(n.density=a))}return r?n:null}function pe(e,t={}){let n=C.filter(r=>e[r]!==D[r]||r==="width"&&t.explicitWidth).map(r=>`${r}: ${e[r]}`);return n.length>0?`<!-- ${n.join("; ")} -->`:null}import{createCommand as K}from"lexical";var fe=K("DRAWING_FOCUS_COMMAND"),ye=K("INSERT_DRAWING_COMMAND");import{useCallback as w,useEffect as U,useRef as x}from"react";var G="data-toolbar-item",E=`[${G}]`;function q(e,t,n,r="horizontal",o=!1){if(n===0)return null;let[l,a]=r==="vertical"?["ArrowUp","ArrowDown"]:o?["ArrowRight","ArrowLeft"]:["ArrowLeft","ArrowRight"],i=Math.max(0,t);switch(e){case l:return(i-1+n)%n;case a:return(i+1)%n;case"Home":return 0;case"End":return n-1;default:return null}}function O(e){return Array.from(e.querySelectorAll(E)).filter(t=>{if(t.disabled)return!1;let n=t.closest('[role="menu"], [role="listbox"]');return!n||!e.contains(n)})}function we(e="horizontal"){let t=x(null),n=x(null),r=x(!1),o=w(i=>{let s=t.current;if(!s)return;let d=O(s),c=i&&d.includes(i)?i:d.includes(n.current)?n.current:d[0]??null;n.current=c;for(let u of d)u.tabIndex=u===c?0:-1},[]);U(()=>{let i=t.current;if(!i||(r.current=typeof getComputedStyle=="function"&&getComputedStyle(i).direction==="rtl",o(null),typeof MutationObserver>"u"))return;let s=new MutationObserver(()=>o(null));return s.observe(i,{childList:!0,subtree:!0,attributeFilter:["disabled"]}),()=>s.disconnect()},[o]);let l=w(i=>{let s=i.target;s!==n.current&&s.matches(E)&&o(s)},[o]),a=w(i=>{let s=t.current;if(!s||i.altKey||i.ctrlKey||i.metaKey)return;let d=i.target;if(!d.matches(E)||d.closest('[role="menu"], [role="listbox"]'))return;let c=O(s),u=c.indexOf(d),p=q(i.key,u,c.length,e,r.current);p!==null&&(i.preventDefault(),o(c[p]),c[p].focus())},[e,o]);return{ref:t,onKeyDown:a,onFocus:l,"aria-orientation":e}}export{b as a,Y as b,m as c,Z as d,ee as e,D as f,A as g,v as h,ie as i,le as j,se as k,ae as l,de as m,ce as n,ue as o,ge as p,pe as q,fe as r,ye as s,G as t,we as u};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{g as q,h as H,i as J,p as X,q as Y}from"./chunk-LDVPFZCN.js";var u=String.raw`//[^\n]*`,p=String.raw`/\*[^]*?(?:\*/|$)`,Z=String.raw`#[^\n]*`,f=String.raw`"(?:[^"\\\n]|\\[^])*"?`,h=String.raw`'(?:[^'\\\n]|\\[^])*'?`,O=String.raw`"""[^]*?(?:"""|$)`,Pe=String.raw`'''[^]*?(?:'''|$)`,V=String.raw`\`(?:[^\`\\]|\\[^])*\`?`,w=String.raw`\b(?:0[xX][\da-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|\d[\d_]*(?:\.\d[\d_]*)?(?:[eE][+-]?\d+)?)[a-zA-Z]*\b`,T=String.raw`@[\w.]+`,d=String.raw`(?<=\.\s*)[A-Za-z_$][\w$]*\b(?!\s*\()`,y=String.raw`[-+*/%=!<>&|^~?:]+`,g=String.raw`[{}()\[\];,.]`;var $t=String.raw`(?<=^|\n)[ \t]*#[ \t]*\w+[^\n]*`,tt={name:"c",aliases:["h","cpp","c++","cc","cxx","hpp","hh"],rules:[{type:"comment",match:u},{type:"comment",match:p},{type:"meta",match:$t},{type:"string",match:f},{type:"string",match:h},{type:"number",match:w},{type:"property",match:d},{type:"operator",match:String.raw`->|::|`+y},{type:"punctuation",match:g}],keywords:["auto","break","case","const","continue","default","do","else","enum","extern","for","goto","if","inline","register","restrict","return","sizeof","static","struct","switch","typedef","union","volatile","while","catch","class","const_cast","constexpr","consteval","delete","dynamic_cast","explicit","export","final","friend","mutable","namespace","new","noexcept","operator","override","private","protected","public","reinterpret_cast","static_cast","template","this","throw","try","typename","using","virtual"],types:["bool","char","double","float","int","long","short","signed","unsigned","void","wchar_t","size_t","ssize_t","int8_t","int16_t","int32_t","int64_t","uint8_t","uint16_t","uint32_t","uint64_t"],constants:["true","false","NULL","nullptr"],callIsFunction:!0,capitalizedIsType:!0};var et={name:"css",aliases:["scss","less","postcss"],rules:[{type:"comment",match:p},{type:"comment",match:u},{type:"keyword",match:String.raw`@[\w-]+|!\s*important\b`},{type:"variable",match:String.raw`--[\w-]+|\$[\w-]+`},{type:"string",match:f},{type:"string",match:h},{type:"tag",match:String.raw`(?<=(?:^|[{};]|\*/)\s*)[^{};@\s][^{};]*?(?=\s*\{)`},{type:"property",match:String.raw`(?<=[{;(]\s*)[-\w]+(?=\s*:)`},{type:"constant",match:String.raw`#[\da-fA-F]{3,8}\b`},{type:"function",match:String.raw`[-\w]+(?=\()`},{type:"number",match:String.raw`(?<![\w-])[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?(?:%|[a-zA-Z]+)?`},{type:"punctuation",match:String.raw`[{}()\[\];:,]`},{type:"operator",match:String.raw`[>+~*/=]`}]};var L=String.raw`[^\n]*`,M=String.raw`(?<=^|\n)`,rt={name:"diff",aliases:["patch"],rules:[{type:"comment",match:M+String.raw`(?:diff |index |--- |\+\+\+ |Index: |={3,}|\*{3} )`+L},{type:"meta",match:M+String.raw`@@`+L},{type:"inserted",match:M+String.raw`\+`+L},{type:"deleted",match:M+"-"+L}]};var nt={name:"go",aliases:["golang"],rules:[{type:"comment",match:u},{type:"comment",match:p},{type:"string",match:String.raw`\`[^\`]*\`?`},{type:"string",match:f},{type:"string",match:h},{type:"number",match:w},{type:"property",match:d},{type:"operator",match:String.raw`:=|<-|\.\.\.|`+y},{type:"punctuation",match:g}],keywords:["break","case","chan","const","continue","default","defer","else","fallthrough","for","func","go","goto","if","import","interface","map","package","range","return","select","struct","switch","type","var"],types:["any","bool","byte","comparable","complex64","complex128","error","float32","float64","int","int8","int16","int32","int64","rune","string","uint","uint8","uint16","uint32","uint64","uintptr"],builtins:["append","cap","clear","close","complex","copy","delete","imag","len","make","max","min","new","panic","print","println","real","recover"],constants:["true","false","nil","iota"],callIsFunction:!0,capitalizedIsType:!1};var at={name:"java",rules:[{type:"comment",match:u},{type:"comment",match:p},{type:"string",match:O},{type:"string",match:f},{type:"string",match:h},{type:"meta",match:T},{type:"number",match:w},{type:"property",match:d},{type:"operator",match:String.raw`->|::|`+y},{type:"punctuation",match:g}],keywords:["abstract","assert","break","case","catch","class","const","continue","default","do","else","enum","extends","final","finally","for","goto","if","implements","import","instanceof","interface","native","new","package","permits","private","protected","public","record","return","sealed","static","strictfp","super","switch","synchronized","this","throw","throws","transient","try","var","volatile","while","yield"],types:["boolean","byte","char","double","float","int","long","short","void"],constants:["true","false","null"],callIsFunction:!0,capitalizedIsType:!0};var Bt=String.raw`(?<=(?:^|[=(,:;!&|?{}\[+\-*%<>~^]|\breturn|\btypeof|\bcase|\bof|\bin)\s*)/(?![/*])(?:[^/\\\n\[]|\\[^]|\[(?:[^\]\\\n]|\\[^])*\])+/[dgimsuyv]*`,Gt=String.raw`(?<=<\/?)[A-Za-z][\w.:-]*`,v=[{type:"comment",match:u},{type:"comment",match:p},{type:"string",match:V},{type:"string",match:f},{type:"string",match:h},{type:"regex",match:Bt},{type:"meta",match:T},{type:"number",match:w},{type:"property",match:d},{type:"tag",match:Gt},{type:"operator",match:String.raw`=>|\.\.\.|`+y},{type:"punctuation",match:g}],U=["as","async","await","break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","export","extends","finally","for","from","function","get","if","implements","import","in","instanceof","interface","let","new","of","package","private","protected","public","return","set","static","super","switch","this","throw","try","typeof","var","void","while","with","yield"],$=["Array","BigInt","Boolean","Date","Error","JSON","Map","Math","Number","Object","Promise","Proxy","Reflect","RegExp","Set","String","Symbol","WeakMap","WeakSet","console","document","globalThis","window","parseFloat","parseInt","setTimeout","setInterval","clearTimeout","clearInterval","fetch","require","process"],B=["true","false","null","undefined","NaN","Infinity"],ot={name:"javascript",aliases:["js","jsx","mjs","cjs"],rules:v,keywords:U,builtins:$,constants:B,callIsFunction:!0,capitalizedIsType:!0};var it={name:"json",aliases:["jsonc","json5"],rules:[{type:"comment",match:String.raw`//[^\n]*|/\*[^]*?(?:\*/|$)`},{type:"property",match:String.raw`"(?:[^"\\\n]|\\[^])*"(?=\s*:)`},{type:"string",match:String.raw`"(?:[^"\\\n]|\\[^])*"?`},{type:"number",match:String.raw`-?\b\d+(?:\.\d+)?(?:[eE][+-]?\d+)?\b`},{type:"punctuation",match:String.raw`[{}\[\]:,]`}],constants:["true","false","null"]};var st={name:"kotlin",aliases:["kt","kts"],rules:[{type:"comment",match:u},{type:"comment",match:p},{type:"string",match:O},{type:"string",match:f},{type:"string",match:h},{type:"meta",match:T},{type:"number",match:w},{type:"property",match:d},{type:"operator",match:String.raw`->|\.\.|\?:|!!|`+y},{type:"punctuation",match:g}],keywords:["abstract","actual","annotation","as","break","by","catch","class","companion","const","constructor","continue","crossinline","data","do","else","enum","expect","external","final","finally","for","fun","get","if","import","in","infix","init","inline","inner","interface","internal","is","lateinit","noinline","object","open","operator","out","override","package","private","protected","public","reified","return","sealed","set","super","suspend","tailrec","this","throw","try","typealias","val","value","var","vararg","when","where","while"],builtins:["it","println","print","listOf","mutableListOf","mapOf","mutableMapOf","setOf","mutableSetOf","arrayOf","emptyList","emptyMap","lazy","require","check","error","TODO","apply","also","let","run","with","takeIf","takeUnless","repeat"],constants:["true","false","null"],callIsFunction:!0,capitalizedIsType:!0};var G=String.raw`(?<=^|\n)`,lt={name:"markdown",aliases:["md","mdx"],rules:[{type:"comment",match:String.raw`<!--[^]*?(?:-->|$)`},{type:"string",match:String.raw`\`\`\`[^]*?(?:\`\`\`|$)|\`[^\`\n]*\``},{type:"keyword",match:G+String.raw`#{1,6}[ \t][^\n]*`},{type:"meta",match:G+String.raw`(?:>|[-*+]|\d+\.)(?=\s)`},{type:"tag",match:String.raw`\*\*[^*\n]+\*\*|__[^_\n]+__`},{type:"variable",match:String.raw`(?<![*\w])\*[^*\n]+\*(?!\w)|(?<![_\w])_[^_\n]+_(?!\w)`},{type:"function",match:String.raw`!?\[[^\]\n]*\](?=\()`},{type:"string",match:String.raw`(?<=\]\()[^)\n]*(?=\))`},{type:"punctuation",match:G+String.raw`(?:---+|\*\*\*+|___+)(?=\n|$)`}]};var ct={name:"html",aliases:["xml","svg","xhtml","vue","markup","rss","atom"],rules:[{type:"comment",match:String.raw`<!--[^]*?(?:-->|$)`},{type:"string",match:String.raw`<!\[CDATA\[[^]*?(?:\]\]>|$)`},{type:"meta",match:String.raw`<![\w]+[^>]*>?|<\?[^]*?(?:\?>|$)`},{type:"tag",match:String.raw`(?<=<\/?)[A-Za-z][\w:.-]*`},{type:"string",match:String.raw`(?<=<[^>]*=\s*)(?:"[^"]*"|'[^']*')`},{type:"attr",match:String.raw`(?<=<[^>]*\s)[^\s"'<>/=]+`},{type:"punctuation",match:String.raw`<\/?|\/?>|(?<=<[^>]*)=`},{type:"constant",match:String.raw`&#?\w+;`}]};var R=String.raw`(?:\b[rRbBuUfF]{1,2})?`,Dt=String.raw`\b(?:0[xX][\da-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|\d[\d_]*(?:\.\d[\d_]*)?(?:[eE][+-]?\d+)?[jJ]?)\b`,mt={name:"python",aliases:["py","py3"],rules:[{type:"comment",match:Z},{type:"string",match:R+String.raw`"""[^]*?(?:"""|$)`},{type:"string",match:R+String.raw`'''[^]*?(?:'''|$)`},{type:"string",match:R+String.raw`"(?:[^"\\\n]|\\[^])*"?`},{type:"string",match:R+String.raw`'(?:[^'\\\n]|\\[^])*'?`},{type:"meta",match:String.raw`@[\w.]+`},{type:"number",match:Dt},{type:"property",match:d},{type:"operator",match:String.raw`->|:=|\*\*|//|[-+*/%=!<>&|^~@]+`},{type:"punctuation",match:g+"|:"}],keywords:["and","as","assert","async","await","break","case","class","continue","def","del","elif","else","except","finally","for","from","global","if","import","in","is","lambda","match","nonlocal","not","or","pass","raise","return","try","while","with","yield"],builtins:["self","cls","print","len","range","enumerate","zip","map","filter","sorted","reversed","open","input","abs","min","max","sum","any","all","iter","next","isinstance","issubclass","getattr","setattr","hasattr","super","type","id","hash","repr","format","vars","dir"],types:["int","float","str","bytes","bool","list","dict","set","tuple","object","complex","frozenset"],constants:["True","False","None","Ellipsis","NotImplemented"],callIsFunction:!0,capitalizedIsType:!0};var Pt=String.raw`\b(?:0[xX][\da-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|\d[\d_]*(?:\.\d[\d_]*)?(?:[eE][+-]?\d+)?)(?:[iuf](?:8|16|32|64|128|size))?\b`,pt={name:"rust",aliases:["rs"],rules:[{type:"comment",match:u},{type:"comment",match:p},{type:"meta",match:String.raw`#!?\[[^\]\n]*\]`},{type:"string",match:String.raw`b?r#*"[^]*?(?:"#*|$)`},{type:"string",match:String.raw`b?"(?:[^"\\]|\\[^])*"?`},{type:"string",match:String.raw`b?'(?:[^'\\\n]|\\[^])'`},{type:"variable",match:String.raw`'[a-z_]\w*\b(?!')`},{type:"function",match:String.raw`\b[a-z_]\w*!(?=[\s(\[{])`},{type:"number",match:Pt},{type:"property",match:d},{type:"operator",match:String.raw`->|=>|::|\.\.=?|`+y},{type:"punctuation",match:g+"|#"}],keywords:["as","async","await","break","const","continue","crate","dyn","else","enum","extern","fn","for","if","impl","in","let","loop","match","mod","move","mut","pub","ref","return","self","Self","static","struct","super","trait","type","union","unsafe","use","where","while"],types:["bool","char","f32","f64","i8","i16","i32","i64","i128","isize","str","u8","u16","u32","u64","u128","usize","String","Vec","Option","Result","Box","Rc","Arc","HashMap","HashSet"],constants:["true","false","None","Some","Ok","Err"],callIsFunction:!0,capitalizedIsType:!0};var ut={name:"shell",aliases:["sh","bash","zsh","console","shellsession"],rules:[{type:"variable",match:String.raw`\$\{[^}\n]*\}|\$\w+|\$[@#?*!$-]`},{type:"comment",match:String.raw`(?<=^|\s)#[^\n]*`},{type:"string",match:String.raw`"(?:[^"\\\n]|\\[^])*"?`},{type:"string",match:String.raw`'[^'\n]*'?`},{type:"punctuation",match:String.raw`(?<=^|\n)[$#](?=\s)`},{type:"attr",match:String.raw`(?<=\s)--?[A-Za-z][\w-]*`},{type:"operator",match:String.raw`\|\|?|&&?|;;?|[<>]+|=`},{type:"punctuation",match:String.raw`[(){}\[\]]`}],identifier:String.raw`[A-Za-z_][\w.-]*`,keywords:["if","then","else","elif","fi","for","while","until","do","done","case","esac","in","function","select","time","return","exit","local","export","readonly","declare","set","unset","shift","source","alias","break","continue"],builtins:["echo","cd","ls","pwd","cat","grep","sed","awk","mkdir","rm","cp","mv","chmod","chown","curl","wget","git","npm","pnpm","yarn","npx","node","python","python3","pip","docker","kubectl","sudo","test","printf","read","eval","exec","trap","wait","kill","ps","tar","zip","unzip","touch","find","xargs","sort","uniq","head","tail","wc","tee","which","env","ssh","scp","make","cargo","go","brew","apt","apt-get","gradle","mvn","java","jq","true","false"]};var dt={name:"sql",aliases:["mysql","postgres","postgresql","pgsql","plsql","sqlite","soql"],caseInsensitive:!0,rules:[{type:"comment",match:String.raw`--[^\n]*`},{type:"comment",match:p},{type:"string",match:String.raw`'(?:[^'\n]|'')*'?`},{type:"variable",match:String.raw`[@:]\w+|\$\d+`},{type:"number",match:String.raw`\b\d+(?:\.\d+)?(?:[eE][+-]?\d+)?\b`},{type:"operator",match:String.raw`\|\||::|[-+*/%=<>!]+`},{type:"punctuation",match:String.raw`[(),;.]`}],keywords:["add","all","alter","and","as","asc","begin","between","by","cascade","case","check","column","commit","constraint","create","cross","default","delete","desc","distinct","drop","else","end","except","exists","foreign","from","full","group","having","if","in","index","inner","insert","intersect","into","is","join","key","left","like","limit","not","null","offset","on","or","order","outer","primary","references","returning","right","rollback","select","set","table","then","top","transaction","truncate","union","unique","update","using","values","view","when","where","with","recursive","ilike","over","partition","window","rows","range","fetch","first","next","only","nulls","last","explain","analyze","grant","revoke","schema","database","trigger","procedure","function","returns","declare","cursor","loop","while","for","exec","execute","merge","matched","replace","ignore","conflict","do","nothing","nowait","lock","share","lateral","natural","any","some","escape"],types:["int","integer","bigint","smallint","tinyint","varchar","char","text","boolean","bool","date","timestamp","timestamptz","time","interval","decimal","numeric","float","real","double","serial","bigserial","uuid","json","jsonb","bytea","blob","array","money","precision","varying"],builtins:["count","sum","avg","min","max","coalesce","now","cast","concat","lower","upper","length","substring","round","trim","nullif","greatest","least","array_agg","string_agg","json_agg","row_number","rank","dense_rank","date_trunc","extract","current_date","current_timestamp","current_user","exists","abs","ceil","floor","random","generate_series"],constants:["true","false","null","unknown"],callIsFunction:!0};var zt=String.raw`(?<=<)[A-Za-z_$][\w$]*(?=[,>\s|&\[])`,gt={name:"typescript",aliases:["ts","tsx","mts","cts"],rules:[{type:"type",match:zt},...v],keywords:[...U,"abstract","asserts","declare","infer","is","keyof","module","namespace","override","readonly","satisfies","type","unique","accessor","out"],types:["any","bigint","boolean","never","null","number","object","string","symbol","undefined","unknown","void"],builtins:[...$,"Partial","Required","Readonly","Record","Pick","Omit","Exclude","Extract","NonNullable","ReturnType","Parameters","Awaited"],constants:B,callIsFunction:!0,capitalizedIsType:!0};var Ft=String.raw`(?<=^|\n)`,Wt=String.raw`(?<=^|\n|\s|-\s)(?:"(?:[^"\\\n]|\\[^])*"|'(?:[^'\n]|'')*'|[^\s"'#\-\[\]{},:!&*?|>][^:#\n]*?)(?=:(?:\s|$))`,ft={name:"yaml",aliases:["yml"],rules:[{type:"comment",match:String.raw`(?<=^|\s)#[^\n]*`},{type:"meta",match:Ft+String.raw`(?:---|\.\.\.)(?=\s|$)`},{type:"property",match:Wt},{type:"variable",match:String.raw`[&*][\w-]+`},{type:"meta",match:String.raw`![\w!/:-]*`},{type:"string",match:String.raw`"(?:[^"\\\n]|\\[^])*"?`},{type:"string",match:String.raw`'(?:[^'\n]|'')*'?`},{type:"punctuation",match:String.raw`(?<=:\s*)[|>][-+]?\d*(?=[ \t]*(?:\n|$|#))`},{type:"punctuation",match:String.raw`(?<=^|\n|\s)-(?=\s)|[\[\]{},:]`},{type:"constant",match:String.raw`(?<=:\s)~(?=\s|$)`},{type:"number",match:String.raw`(?<![\w.-])[-+]?(?:0x[\da-fA-F]+|\d[\d_]*(?:\.\d*)?(?:[eE][+-]?\d+)?|\.inf|\.nan)(?![\w.-])`}],constants:["true","false","null","yes","no","on","off","True","False","Null","Yes","No","On","Off","TRUE","FALSE","NULL","YES","NO","ON","OFF"]};var ht=[ot,gt,st,at,tt,mt,nt,pt,it,ft,ut,dt,et,ct,rt,lt];var z="plain",D={name:z,aliases:["plaintext","text","txt"],rules:[]},N=new Map,yt=!1;function F(t){return t.trim().toLowerCase()}function P(t){for(let e of[t.name,...t.aliases??[]])N.set(F(e),t)}function A(){if(!yt){yt=!0,P(D);for(let t of ht)P(t)}}function Ir(t){A(),P(t)}function kr(t){return A(),N.has(F(t))}function vr(t){if(A(),!t)return D;let e=F(t);return N.get(e)??(e.startsWith("diff-")?N.get("diff"):void 0)??D}function Ur(){return A(),[...new Set([...N.values()].map(t=>t.name))].sort()}import{$applyNodeReplacement as jt,$createLineBreakNode as Kt,$createTextNode as Qt,ElementNode as qt}from"lexical";var E=class t extends qt{static getType(){return"frontmatter"}static clone(e){return new t(e.__key)}constructor(e){super(e)}createDOM(e){let r=document.createElement("div"),n=e.theme.frontmatter;return r.className=typeof n=="string"?n:"zui-frontmatter",r}updateDOM(){return!1}static importJSON(e){return St()}exportJSON(){return{...super.exportJSON(),type:"frontmatter",version:1}}isInline(){return!1}canBeEmpty(){return!1}canIndent(){return!1}};function St(){return jt(new E)}function Ht(t){return t instanceof E}var wt=/^---\s*$/,Et={dependencies:[E],export:t=>{if(!Ht(t))return null;let e=t.getTextContent();return e?`---
|
|
3
|
+
${e}
|
|
4
|
+
---`:`---
|
|
5
|
+
---`},regExpStart:wt,regExpEnd:wt,replace:(t,e,r,n,s,l)=>{if(!l||e!=null||s==null||t.getChildrenSize()!==0)return!1;let o=[...s];for(;o.length>0&&o[0].length===0;)o.shift();for(;o.length>0&&o[o.length-1].length===0;)o.pop();let a=St();o.forEach((m,i)=>{i>0&&a.append(Kt()),a.append(Qt(m))}),t.append(a)},type:"multiline-element"};import{$isParagraphNode as Nt,$isTextNode as Ct}from"lexical";import{$convertFromMarkdownString as Jt,$convertToMarkdownString as Xt,TRANSFORMERS as _t}from"@lexical/markdown";import{$createTableCellNode as Yt,$createTableNode as Zt,$createTableRowNode as Vt,$isTableCellNode as I,$isTableNode as W,$isTableRowNode as C,TableCellHeaderStates as _,TableCellNode as te,TableNode as ee,TableRowNode as re}from"@lexical/table";var xt=/^\|(.+)\|\s?$/,ne=/^(\| ?:?-+:? ?)+\|\s?$/,ae=/(?<!\\)\|/,Tt="text-align";function oe(t){let e=t.trim(),r=e.startsWith(":"),n=e.endsWith(":");return r&&n?"center":n?"right":r?"left":null}function ie(t){return t==="center"?":---:":t==="right"?"---:":t==="left"?":---":"---"}function se(t){let e=t.getStyle().match(/(?:^|;)\s*text-align\s*:\s*(left|center|right)\s*(?:;|$)/);return e?e[1]:null}function le(t,e){let r=t.getStyle().split(";").map(n=>n.trim()).filter(n=>n&&!n.replace(/\s/g,"").startsWith(`${Tt}:`));e&&r.push(`${Tt}: ${e}`),t.setStyle(r.join("; "))}function ce(t,e){for(let r of t.getChildren())C(r)&&r.getChildren().forEach((n,s)=>{I(n)&&e[s]&&le(n,e[s])})}function me(t){if(!Nt(t)||t.getChildrenSize()!==1)return null;let e=t.getFirstChild();return Ct(e)?X(e.getTextContent()):null}function pe(t){let e=t.getFirstChild();return C(e)?e.getChildrenSize():0}function j(t){let e=t.replace(/\\n/g,`
|
|
6
|
+
`).replace(/\\\|/g,"|"),r=Yt(_.NO_STATUS);return Jt(e,_t,r,!0),r}function ue(t){return Xt(_t,t,!0).replace(/\|/g,"\\|").replace(/\n/g,"\\n")}function bt(t){let e=t.match(xt);return!e||!e[1]?null:e[1].split(ae).map(r=>j(r.trim()))}function de(t,e){let r=t.getFirstChild(),n=I(r)?r.__headerState:_.NO_STATUS;for(;t.getChildrenSize()<e;)t.append(j("").setHeaderStyles(n,n))}var Ot={dependencies:[ee,re,te],export:t=>{if(!W(t))return null;let e=[],r=Y(q(t),{explicitWidth:J(t)});r&&e.push(r);for(let n of t.getChildren()){if(!C(n))continue;let s=[],l=[],o=!1;for(let a of n.getChildren())I(a)&&(s.push(ue(a)),l.push(se(a)),a.__headerState===_.ROW&&(o=!0));e.push(`| ${s.join(" | ")} |`),o&&e.push(`| ${l.map(ie).join(" | ")} |`)}return e.join(`
|
|
7
|
+
`)},regExp:xt,replace:(t,e,r)=>{if(ne.test(r[0])){let i=t.getPreviousSibling();if(!i||!W(i))return;let c=i.getLastChild();if(!c||!C(c))return;c.getChildren().forEach(S=>{I(S)&&S.setHeaderStyles(_.ROW,_.ROW)}),ce(i,r[0].split("|").slice(1,-1).map(oe)),t.remove();return}let n=bt(r[0]);if(n==null)return;let s=[n],l=t.getPreviousSibling(),o=n.length;for(;l&&!(!Nt(l)||l.getChildrenSize()!==1);){let i=l.getFirstChild();if(!Ct(i))break;let c=bt(i.getTextContent());if(c==null)break;o=Math.max(o,c.length),s.unshift(c);let S=l.getPreviousSibling();l.remove(),l=S}let a=Zt();for(let i of s){let c=Vt();a.append(c);for(let S=0;S<o;S++)c.append(S<i.length?i[S]:j(""))}let m=t.getPreviousSibling();if(W(m)){let i=Math.max(pe(m),o);for(let c of[...m.getChildren(),...a.getChildren()])C(c)&&de(c,i);m.append(...a.getChildren()),t.remove()}else{let i=me(m);i&&(H(a,i,{explicitWidth:!0}),m?.remove()),t.replace(a)}a.selectEnd()},type:"element"};import{$isListItemNode as ge,$isListNode as Lt,ListItemNode as fe,ListNode as he}from"@lexical/list";var x=/^([ \t]*)(?:[-*+]|\d{1,}\.)\s/,k=4;function ye(t){let e=0;for(let r of t)e+=r===" "?k:1;return e}function we(t,e){let r=e;for(;r<t.length&&x.test(t[r]);)r++;let n=[];for(let a=e;a<r;a++)n.push(ye(t[a].match(x)[1]));if(n.every(a=>a%k===0))return r;let s=t[e].match(x)[1],l=(s.match(/\t/g)??[]).length+Math.floor((s.match(/ /g)??[]).length/k),o=[n[0]];for(let a=1;a<n.length;a++){let m=n[a];for(;o.length>1&&m<o[o.length-1];)o.pop();m>o[o.length-1]&&o.push(m);let i=l+o.length-1,c=t[e+a];t[e+a]=" ".repeat(i*k)+c.slice(c.match(x)[1].length)}return r}function Mt(t,e,r){let n=[],s=t.getListType(),l=0,o=r+" ";for(let a of t.getChildren()){if(!ge(a))continue;let m=a.getFirstChild();if(a.getChildrenSize()===1&&Lt(m)){n.push(Mt(m,e,o));continue}let i=s==="number"?`${t.getStart()+l}. `:s==="check"?`- [${a.getChecked()?"x":" "}] `:"- ";n.push(r+i+e(a)),o=r+" ".repeat(s==="number"?i.length:2),l++}return n.join(`
|
|
8
|
+
`)}var Rt={dependencies:[he,fe],export:(t,e)=>Lt(t)?Mt(t,e,""):null,regExpStart:x,handleImportAfterStartMatch:({lines:t,startLineIndex:e})=>(we(t,e),null),replace:()=>!1,type:"multiline-element"};import{CODE as At}from"@lexical/markdown";import{$isCodeNode as It}from"@lexical/code";var Se=/^[ \t]*```([^`\n]*)/,kt="--zui-code-meta",Ee=/(?:^|;)\s*--zui-code-meta\s*:\s*"((?:[^"\\]|\\.)*)"\s*(?:;|$)/;function Te(t){let e=t.getStyle().match(Ee);return e?e[1].replace(/\\(.)/g,"$1"):""}function be(t,e){let r=t.getStyle().split(";").map(n=>n.trim()).filter(n=>n&&!n.startsWith(kt));e&&r.push(`${kt}: "${e.replace(/["\\]/g,"\\$&")}"`),t.setStyle(r.join("; "))}function Ne(t){let e=t.trim(),r=e.search(/\s/);return r===-1?[e,""]:[e.slice(0,r),e.slice(r).trim()]}var vt={...At,regExpStart:Se,replace:(t,e,r,n,s,l)=>{let[o,a]=Ne(r[1]??""),m=[...r];m[1]=o;let i=At.replace(t,e,m,n,s,l);if(i===!1)return!1;let c=t.getLastChild();return a&&!e&&It(c)&&be(c,a),i},export:t=>{if(!It(t))return null;let e=t.getLanguage(),r=Te(t),n=(e===z?"":e||"")+(r?" "+r:""),s=t.getTextContent();return"```"+n+(s?`
|
|
9
|
+
`+s:"")+"\n```"}};import{CHECK_LIST as Ut,CODE as Ce,TRANSFORMERS as _e}from"@lexical/markdown";import{HeadingNode as xe,QuoteNode as Oe}from"@lexical/rich-text";import{ListItemNode as Le,ListNode as Me}from"@lexical/list";import{CodeHighlightNode as Re,CodeNode as Ae}from"@lexical/code";import{AutoLinkNode as Ie,LinkNode as ke}from"@lexical/link";import{TableCellNode as ve,TableNode as Ue,TableRowNode as $e}from"@lexical/table";var Be=[xe,Me,Le,Oe,Ae,Re,Ie,ke,E,Ue,$e,ve],Ge=[Et,Rt,Ut,Ot,vt,..._e.filter(t=>t!==Ce)],sn={nodes:Be,transformers:Ge};function ln(t,e){return e===void 0?[...t]:typeof e=="function"?[...e(t)]:[...e,...t.filter(r=>!e.includes(r))]}function cn(t){return t.filter(e=>e.type!=="multiline-element"&&e!==Ut)}var De=["full","text","content"];function pn(t){return typeof t=="string"&&De.includes(t)}import{Fragment as K,jsx as b,jsxs as Q}from"react/jsx-runtime";var dn=[{preset:"compact",label:"compact",width:"content",density:"compact",icon:Q(K,{children:[b("path",{d:"M3 4v12M17 4v12"}),b("path",{d:"M5.5 10h3M11.5 10h3M6.5 7.5L9 10l-2.5 2.5M13.5 7.5L11 10l2.5 2.5"})]})},{preset:"comfortable",label:"comfortable",width:"text",density:"comfortable",icon:Q(K,{children:[b("path",{d:"M3 4v12M17 4v12"}),b("path",{d:"M6.5 7h7M6.5 10h7M6.5 13h4.5"})]})},{preset:"full",label:"full",width:"full",density:"comfortable",icon:Q(K,{children:[b("path",{d:"M3 4v12M17 4v12"}),b("path",{d:"M6 10h8M8.5 7.5L6 10l2.5 2.5M11.5 7.5L14 10l-2.5 2.5"})]})}];function gn(t){return t==="content"?"compact":t==="text"?"comfortable":"full"}export{ht as a,z as b,D as c,Ir as d,kr as e,vr as f,Ur as g,E as h,St as i,Ht as j,Et as k,Ot as l,Rt as m,vt as n,Be as o,Ge as p,sn as q,ln as r,cn as s,dn as t,gn as u,De as v,pn as w};
|
|
@@ -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};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{a as y,b,d as I,e as R}from"./chunk-7Z3CW6Q3.js";import{r as E}from"./chunk-AGTPMKLK.js";import{c as f}from"./chunk-YFFSTMIR.js";import{useEffect as L,useMemo as T,useRef as A}from"react";import{useLexicalComposerContext as O}from"@lexical/react/LexicalComposerContext";import{DRAG_DROP_PASTE as F}from"@lexical/rich-text";import{$getNodeByKey as x,$getSelection as k,$insertNodes as P,$isRangeSelection as v,COMMAND_PRIORITY_EDITOR as _,COMMAND_PRIORITY_LOW as B,createCommand as D}from"lexical";import{mergeRegister as G}from"@lexical/utils";import{Fragment as K,jsx as u,jsxs as N}from"react/jsx-runtime";var U=D("INSERT_IMAGE_COMMAND"),S=D("UPLOAD_IMAGES_COMMAND");function $(o,t){return t?t.includes(o.type):o.type.startsWith("image/")}function w({upload:o,maxSize:t,accept:s,onError:d,labels:m}){let[e]=O(),c=T(()=>({...y,...m}),[m]),M=A(o);M.current=o;let a=A(d);return a.current=d,L(()=>{b(e,c)},[e,c]),L(()=>{let C=r=>{let p=!1;for(let n of r){if(!$(n,s)){a.current?.({type:"unsupported",file:n});continue}if(t!==void 0&&n.size>t){a.current?.({type:"too-large",file:n,maxSize:t});continue}p=!0;let g=I({src:"",pending:!0});P([g]);let h=g.getKey();M.current(n).then(i=>{e.update(()=>{let l=x(h);if(R(l)){if(!f(i.src)){l.remove(),a.current?.({type:"unsafe-src",src:i.src});return}l.setSrc(i.src).setAlt(i.alt??"").setPending(!1)}})},i=>{e.update(()=>{let l=x(h);R(l)&&l.remove()}),a.current?.({type:"upload",file:n,error:i})})}return p};return G(e.registerCommand(F,r=>C(r),B),e.registerCommand(S,r=>C(r),_),e.registerCommand(U,({src:r,alt:p,title:n})=>{if(!f(r))return a.current?.({type:"unsafe-src",src:r}),!1;let g=k();return v(g)?(P([I({src:r,alt:p,title:n})]),!0):!1},_))},[e,s,t]),null}function V({accept:o="image/*",labels:t}){let[s]=O(),d=A(null),m=t?.insertImage??y.insertImage;return N(K,{children:[u(E,{label:m,onClick:()=>d.current?.click(),children:N("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:[u("rect",{x:"3",y:"4",width:"14",height:"12",rx:"1.5"}),u("circle",{cx:"7.5",cy:"8.5",r:"1.5"}),u("path",{d:"M17 13l-4-4-6 6"})]})}),u("input",{ref:d,type:"file",accept:o,multiple:!0,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:e=>{let c=Array.from(e.target.files??[]);e.target.value="",c.length>0&&s.focus(()=>s.dispatchCommand(S,c))}})]})}export{U as a,S as b,w as c,V as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use client';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{createCommand as o}from"lexical";var r=["http:","https:","mailto:","tel:"],a=/^[a-z][a-z0-9+.-]*:/i,m=o("EDIT_LINK_COMMAND");function c(n){let t=n.trim();if(t==="")return!1;let e=a.exec(t);return e?r.includes(e[0].toLowerCase()):!0}export{r as a,m as b,c};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{c as b}from"./chunk-YFFSTMIR.js";import{useEffect as L,useRef as z}from"react";import{useLexicalComposerContext as H}from"@lexical/react/LexicalComposerContext";import{$generateNodesFromDOM as M}from"@lexical/html";import{$insertGeneratedNodes as k}from"@lexical/clipboard";import{$addUpdateTag as _,$getSelection as U,$isRangeSelection as $,COMMAND_PRIORITY_HIGH as B,PASTE_COMMAND as W,PASTE_TAG as q}from"lexical";var N=new Set(["p","h1","h2","h3","h4","h5","h6","ul","ol","li","blockquote","pre","code","table","thead","tbody","tfoot","tr","th","td","br","hr","strong","em","b","i","s","del","u","a","img","sub","sup"]),R=new Set(["script","style","meta","link","title","head","noscript","template","iframe","object","embed","button","input","select","textarea","svg","canvas","colgroup","col","caption"]),w={a:["href","title"],img:["src","alt","title"],td:["colspan","rowspan"],th:["colspan","rowspan"],ol:["start"]};function P(e){return(e.getAttribute("style")??"").toLowerCase().replace(/\s/g,"")}function v(e){let o=P(e),r=[];return/font-weight:(bold|bolder|[6-9]00)/.exec(o)&&r.push("strong"),/font-style:italic/.test(o)&&r.push("em"),/text-decoration:[^;]*line-through/.test(o)&&r.push("s"),r}function A(e){return e.tagName.toLowerCase()==="b"&&/font-weight:normal/.test(P(e))}var T=/msolist/i,O=/^[·•●■○–\-o]\s*$/,S=/^(\d+[.)]|[a-z][.)]|[ivx]+[.)])\s*$/i;function p(e){let o=e.parentNode;if(o){for(;e.firstChild;)o.insertBefore(e.firstChild,e);o.removeChild(e)}}function C(e,o,r){let n=e.createElement(r);for(;o.firstChild;)n.appendChild(o.firstChild);return o.parentNode?.replaceChild(n,o),n}function D(e){let o=Array.from(e.body.querySelectorAll("p")).filter(n=>T.test(n.getAttribute("class")??"")),r=null;for(let n of o){let l=n.firstChild,i=(l?.textContent?.replace(/ /g," ")??"").trim(),m=S.test(i),a=O.test(i);if(!m&&!a){r=null;continue}l&&n.removeChild(l);let s=m?"ol":"ul",c=n.previousElementSibling;r&&c===r&&r.tagName.toLowerCase()===s||(r=e.createElement(s),n.parentNode?.insertBefore(r,n));let f=e.createElement("li");for(;n.firstChild;)f.appendChild(n.firstChild);r.appendChild(f),n.parentNode?.removeChild(n)}}function u(e,o,r){let n=Array.from(o.childNodes);for(let l of n){if(l.nodeType===8){o.removeChild(l);continue}if(l.nodeType!==1)continue;let t=l,i=t.tagName.toLowerCase();if(R.has(i)||i.includes(":")){i.includes(":")?p(t):o.removeChild(t);continue}if(A(t)){u(e,t,r),p(t);continue}if(i==="span"||i==="font"||i==="div"||i==="section"||i==="article"){u(e,t,r);let a=i==="span"?v(t):[];if(a.length>0){let s=t;for(let c of a)s=C(e,s,c);s.removeAttribute("style")}else p(t);continue}if((i==="b"||i==="i")&&(t=C(e,t,i==="b"?"strong":"em")),i==="a"&&(!r.links||!b(t.getAttribute("href")??""))){u(e,t,r),p(t);continue}if(i==="img"&&!r.images){o.removeChild(t);continue}if(i==="table"&&!r.tables){let a=Array.from(t.querySelectorAll("td, th"));for(let s of a){u(e,s,r);let c=e.createElement("p");for(;s.firstChild;)c.appendChild(s.firstChild);t.parentNode?.insertBefore(c,t)}o.removeChild(t);continue}if(!N.has(t.tagName.toLowerCase())){u(e,t,r),p(t);continue}let m=w[t.tagName.toLowerCase()]??[];for(let a of Array.from(t.attributes))m.includes(a.name)||t.removeAttribute(a.name);u(e,t,r)}}function h(e,o={}){let r={tables:o.tables??!0,links:o.links??!0,images:o.images??!0},n=new DOMParser().parseFromString(e,"text/html");return D(n),u(n,n.body,r),n.body.innerHTML}function g(e){return/docs-internal-guid|urn:schemas-microsoft-com|class="?Mso|data-pm-slice|confluence|WordDocument|xmlns:o=/i.test(e)}function y({when:e="rich-sources",transform:o,tables:r,links:n,images:l}={}){let[t]=H(),i=z(o);return i.current=o,L(()=>t.registerCommand(W,m=>{let a=m.clipboardData;if(!a)return!1;let s=m.target;if(s instanceof HTMLElement&&s.closest("input, textarea"))return!1;let c=a.getData("text/html");if(!c||e==="rich-sources"&&!g(c))return!1;let f=U();if(!$(f))return!1;m.preventDefault();let d=h(c,{tables:r,links:n,images:l});i.current&&(d=i.current(d));let E=new DOMParser().parseFromString(d,"text/html"),x=M(t,E);return _(q),k(t,x,f),!0},B),[t,e,r,n,l]),null}export{h as a,g as b,y as c};
|