import{u as he}from"./useBasicLayout-a4f17bae.js";import{a as pe,u as ge,t as _,Z as ve}from"./index-d64a7cc4.js";import{i as ye,e as we,K as ce,z,Z as xe}from"./naive-ui-fedd20b1.js";import{b as be,M as Pe,F as le,t as Ae}from"./index-b71062e6.js";import{d as Ee,r as X,f as fe,Q as Te,U as Y,a3 as b,M as h,a4 as I,a5 as de,X as M,W as O,S as ee,c as W}from"./vue-10b4afc0.js";import"./vueuse-motion-d4cdaf7b.js";var me={exports:{}};(function(ue){(function(te){var c=Z(),B=Q(),$=g(),q=v(),J={imagePlaceholder:void 0,cacheBust:!1},p={toSvg:j,toPng:N,toJpeg:C,toBlob:ne,toPixelData:F,impl:{fontFaces:$,images:q,util:c,inliner:B,options:{}}};ue.exports=p;function j(t,e){return e=e||{},G(e),Promise.resolve(t).then(function(o){return K(o,e.filter,!0)}).then(re).then(ae).then(a).then(function(o){return oe(o,e.width||c.width(t),e.height||c.height(t))});function a(o){return e.bgcolor&&(o.style.backgroundColor=e.bgcolor),e.width&&(o.style.width=e.width+"px"),e.height&&(o.style.height=e.height+"px"),e.style&&Object.keys(e.style).forEach(function(u){o.style[u]=e.style[u]}),o}}function F(t,e){return V(t,e||{}).then(function(a){return a.getContext("2d").getImageData(0,0,c.width(t),c.height(t)).data})}function N(t,e){return V(t,e||{}).then(function(a){return a.toDataURL()})}function C(t,e){return e=e||{},V(t,e).then(function(a){return a.toDataURL("image/jpeg",e.quality||1)})}function ne(t,e){return V(t,e||{}).then(c.canvasToBlob)}function G(t){typeof t.imagePlaceholder>"u"?p.impl.options.imagePlaceholder=J.imagePlaceholder:p.impl.options.imagePlaceholder=t.imagePlaceholder,typeof t.cacheBust>"u"?p.impl.options.cacheBust=J.cacheBust:p.impl.options.cacheBust=t.cacheBust}function V(t,e){return j(t,e).then(c.makeImage).then(c.delay(100)).then(function(o){var u=a(t);return u.getContext("2d").drawImage(o,0,0),u});function a(o){var u=document.createElement("canvas");if(u.width=e.width||c.width(o),u.height=e.height||c.height(o),e.bgcolor){var s=u.getContext("2d");s.fillStyle=e.bgcolor,s.fillRect(0,0,u.width,u.height)}return u}}function K(t,e,a){if(!a&&e&&!e(t))return Promise.resolve();return Promise.resolve(t).then(o).then(function(r){return u(t,r,e)}).then(function(r){return s(t,r)});function o(r){return r instanceof HTMLCanvasElement?c.makeImage(r.toDataURL()):r.cloneNode(!1)}function u(r,i,w){var P=r.childNodes;if(P.length===0)return Promise.resolve(i);return m(i,c.asArray(P),w).then(function(){return i});function m(L,A,y){var E=Promise.resolve();return A.forEach(function(R){E=E.then(function(){return K(R,y)}).then(function(T){T&&L.appendChild(T)})}),E}}function s(r,i){if(!(i instanceof Element))return i;return Promise.resolve().then(w).then(P).then(m).then(L).then(function(){return i});function w(){A(window.getComputedStyle(r),i.style);function A(y,E){y.cssText?E.cssText=y.cssText:R(y,E);function R(T,U){c.asArray(T).forEach(function(n){U.setProperty(n,T.getPropertyValue(n),T.getPropertyPriority(n))})}}}function P(){[":before",":after"].forEach(function(y){A(y)});function A(y){var E=window.getComputedStyle(r,y),R=E.getPropertyValue("content");if(R===""||R==="none")return;var T=c.uid();i.className=i.className+" "+T;var U=document.createElement("style");U.appendChild(n(T,y,E)),i.appendChild(U);function n(l,d,f){var x="."+l+":"+d,S=f.cssText?ie(f):se(f);return document.createTextNode(x+"{"+S+"}");function ie(k){var D=k.getPropertyValue("content");return k.cssText+" content: "+D+";"}function se(k){return c.asArray(k).map(D).join("; ")+";";function D(H){return H+": "+k.getPropertyValue(H)+(k.getPropertyPriority(H)?" !important":"")}}}}}function m(){r instanceof HTMLTextAreaElement&&(i.innerHTML=r.value),r instanceof HTMLInputElement&&i.setAttribute("value",r.value)}function L(){i instanceof SVGElement&&(i.setAttribute("xmlns","http://www.w3.org/2000/svg"),i instanceof SVGRectElement&&["width","height"].forEach(function(A){var y=i.getAttribute(A);y&&i.style.setProperty(A,y)}))}}}function re(t){return $.resolveAll().then(function(e){var a=document.createElement("style");return t.appendChild(a),a.appendChild(document.createTextNode(e)),t})}function ae(t){return q.inlineAll(t).then(function(){return t})}function oe(t,e,a){return Promise.resolve(t).then(function(o){return o.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),new XMLSerializer().serializeToString(o)}).then(c.escapeXhtml).then(function(o){return''+o+""}).then(function(o){return'"}).then(function(o){return"data:image/svg+xml;charset=utf-8,"+o})}function Z(){return{escape:L,parseExtension:e,mimeType:a,dataAsUrl:m,isDataUrl:o,canvasToBlob:s,resolveUrl:r,getAndEncode:P,uid:i(),delay:A,asArray:y,escapeXhtml:E,makeImage:w,width:R,height:T};function t(){var n="application/font-woff",l="image/jpeg";return{woff:n,woff2:n,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:l,jpeg:l,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml"}}function e(n){var l=/\.([^\.\/]*?)$/g.exec(n);return l?l[1]:""}function a(n){var l=e(n).toLowerCase();return t()[l]||""}function o(n){return n.search(/^(data:)/)!==-1}function u(n){return new Promise(function(l){for(var d=window.atob(n.toDataURL().split(",")[1]),f=d.length,x=new Uint8Array(f),S=0;S{setTimeout(()=>{ne()},1e3)});let G;function V(){const g=new XMLSerializer().serializeToString(N.value),v=new Blob([g],{type:"image/svg+xml;charset=utf-8"});le.saveAs(v,"nineai-mind.svg")}async function K(){const v=`
Markmap Export
${await Ce.toSvg(N.value)}
`,t=new Blob([v],{type:"text/html;charset=utf-8"});le.saveAs(t,"nineai-mind.html")}async function re(){p.value=!0,C.value="";try{const g="";let v="";const t=()=>(C.value=v,p.value?!0:(C.value=v,!1)),e=setInterval(()=>{t()||clearInterval(e)},1e3);await(async()=>{let o=0;await ve({prompt:F.value,onDownloadProgress:({event:u})=>{const r=u.target.responseText,i=r.substring(o);o=r.length,i.trim().split(`
`).forEach(P=>{try{const m=JSON.parse(P);m.userBalance&&te.updateUserBalance(m.userBalance),m.text&&(v+=m.text)}catch{}})}}),p.value=!1})()}catch(g){p.value=!1;const{code:v=500,message:t="好像出错了,请稍后再试!"}=g;if(v===429&&t.includes("balance has been exhausted"))return B.error("当前系统Key余额耗尽、请联系管理员补充!");if(v===500){let e=(g==null?void 0:g.message)??"好像出错了,请稍后再试!";e==="Request failed with status code 401"&&(e="非法操作、请先登录后再进行问答使用!"),B.error(e);return}if(g.code===402){B.error(g.message,{duration:5e3}),c.updateGoodsDialog(!0);return}B.error("出了点小错误、请稍后试试吧!")}finally{p.value=!1}}async function ae(){const g=await Ae(N.value);le.saveAs(g,"markmap.png")}function oe(){C.value=He}const Z=()=>{const{root:g}=J.transform(C.value);G.setData(g),G.fit()};return fe(()=>{G=Pe.create(N.value),Z()}),Te(Z),(g,v)=>(ee(),Y("div",Se,[b("div",Ie,[b("div",Be,[h(j)?(ee(),Y("header",Ue,[b("h2",ke,I(h(_)("mindmap.title")),1)])):de("",!0),b("h4",De,I(h(_)("mindmap.yourNeeds")),1),M(h(ce),{ref_key:"inputRef",ref:q,value:F.value,"onUpdate:value":v[0]||(v[0]=t=>F.value=t),type:"textarea",disabled:p.value,autosize:{minRows:3},placeholder:h(_)("mindmap.inputPlaceholder")},null,8,["value","disabled","placeholder"]),b("div",Re,[M(h(z),{type:"primary",size:"small",style:{width:"100%"},loading:p.value,onClick:re},{default:O(()=>[W(I(h(_)("mindmap.generateMindMapButton")),1)]),_:1},8,["loading"])]),b("div",Me,[b("h4",Ne,I(h(_)("mindmap.contentRequirements")),1),M(h(z),{text:"",onClick:oe},{default:O(()=>[W(I(h(_)("mindmap.tryDemoButton")),1)]),_:1})]),M(h(ce),{value:C.value,"onUpdate:value":v[1]||(v[1]=t=>C.value=t),type:"textarea",disabled:p.value,autosize:{minRows:8,maxRows:24},placeholder:"请用markdown语法输入您想要生成思维导图的内容或在上方使用描述让AI帮您完善!"},null,8,["value","disabled"])]),b("div",Le,[b("div",Ve,I(h(_)("mindmap.usageCredits")),1),b("div",null,[M(h(xe),{size:"small"},{default:O(()=>[M(h(z),{type:"primary",onClick:K},{default:O(()=>[W(I(h(_)("mindmap.exportHTML")),1)]),_:1}),M(h(z),{type:"primary",onClick:ae},{default:O(()=>[W(I(h(_)("mindmap.exportPNG")),1)]),_:1}),M(h(z),{type:"warning",onClick:V},{default:O(()=>[W(I(h(_)("mindmap.exportSVG")),1)]),_:1})]),_:1})])])]),b("div",Oe,[h(j)?de("",!0):(ee(),Y("header",je,[b("h2",Fe,I(h(_)("mindmap.title")),1)])),b("div",Ge,[(ee(),Y("svg",{ref_key:"svgRef",ref:N,class:"box-border w-full h-full border rounded-md"},null,512))])])]))}});export{Ze as default};