import{r as p,R as O}from"./vendor-react-BUCujlKS.js";const j=(a,n,s)=>{const r=new URL(a??"https://embed.diagrams.net"),o=new URLSearchParams;return o.append("embed","1"),o.append("proto","json"),s&&o.append("configure","1"),n&&Object.keys(n).forEach(f=>{const i=n[f];i!==void 0&&(typeof i=="boolean"?o.append(f,i?"1":"0"):o.append(f,i.toString()))}),r.search=o.toString(),r.toString()};function A(a,n,s){if(!(!a.origin.includes("embed.diagrams.net")&&s&&!s.includes(a.origin)&&!a.origin.includes(s)))try{const r=JSON.parse(a.data);if(r.event in n){const o=n[r.event];o&&o(r)}}catch{}}const H=a=>{const n=(e,l)=>{a.current?.contentWindow?.postMessage(JSON.stringify({action:e,...l}),"*")};return{load:e=>{n("load",e)},configure:e=>{n("configure",e)},merge:e=>{n("merge",e)},dialog:e=>{n("dialog",e)},prompt:e=>{n("prompt",e)},template:e=>{n("template",e)},layout:e=>{n("layout",e)},draft:e=>{n("draft",e)},status:e=>{n("status",e)},spinner:e=>{n("spinner",e)},exportDiagram:e=>{n("export",e)}}},U=p.forwardRef((a,n)=>{const{autosave:s=!1,baseUrl:r,urlParameters:o,configuration:f,xml:i,csv:d,exportFormat:u,onAutoSave:x,onSave:v,onClose:m,onLoad:E,onConfigure:e,onDraft:l,onExport:h,onMerge:w,onPrompt:b,onTemplate:S}=a,D=p.useRef(null),g=H(D),I=j(r,o,!!f),[R,L]=p.useState(!1),y=c=>{A(c,{init:()=>{L(!0)},load:t=>{E&&E(t)},configure:t=>{f&&g.configure({config:f}),e&&e(t)},autosave:t=>{x&&x(t)},save:t=>{g.exportDiagram({format:u||"xmlsvg",exit:t.exit,parentEvent:"save"})},exit:t=>{m&&m(t)},draft:t=>{l&&l(t)},export:t=>{v&&v({event:"save",xml:t.data,parentEvent:t.message.parentEvent||"export"}),h&&h(t),t.message.exit&&m&&m({event:"exit",modified:!0,parentEvent:t.message.parentEvent||"export"})},merge:t=>{w&&w(t)},prompt:t=>{b&&b(t)},template:t=>{S&&S(t)}},r)};return p.useImperativeHandle(n,()=>({...g}),[]),p.useEffect(()=>{let c={};R&&(i?u==="xmlpng"?c={xmlpng:i}:c={xml:i}:d?c={descriptor:{format:"csv",data:d}}:c={xml:""},c={...c,autosave:s},g.load(c))},[R,i,d,s]),p.useEffect(()=>(window.addEventListener("message",y),()=>{window.removeEventListener("message",y)}),[]),O.createElement("iframe",{className:"diagrams-iframe",src:I,ref:D,allow:"clipboard-read; clipboard-write",title:"Diagrams.net",style:{width:"100%",height:"100%",minWidth:"400px",minHeight:"400px",border:"none"}})});export{U as D};
