import{k as te,j as g,t as se,m as S,n as m,p as u,f as ne,q,v as k,i as N,A as C,x as re,s as ie,e as le,F as oe}from"./web.Os7kOAdY.js";import{c as ae}from"./clipboard.BNxbz_oK.js";import{g as H,t as ue}from"./i18n-runtime._BAkvU05.js";var ce=C('<div class=panel style=display:flex;flex-direction:column;gap:14px><div class=tool-field><span class=tool-label></span><textarea class=tool-input rows=6 placeholder="curl -X GET https://..."style=font-family:ui-monospace,monospace;font-size:13px;resize:vertical></textarea></div><div style=display:flex;gap:8px;flex-wrap:wrap;align-items:center><span class=tool-label style=margin-right:4px></span><!$><!/></div><button class=tool-btn></button><!$><!/><!$><!/>'),he=C("<button>"),pe=C("<div class=tool-error style=padding:8px;border-radius:6px;background:#fff0f0;color:#c00>⚠ <!$><!/>"),de=C('<div class=tool-field><div style=display:flex;align-items:center;justify-content:space-between><span class=tool-label><!$><!/> <!$><!/></span><button class=tool-btn style="padding:4px 12px;font-size:12px"></button></div><pre style=margin:0;padding:12px;background:var(--surface-2,#f5f5f5);border-radius:8px;font-size:13px;overflow-x:auto;white-space:pre-wrap;font-family:ui-monospace,monospace;max-height:500px;overflow-y:auto>');function fe(t){const e={method:"GET",url:"",headers:{},data:"",user:"",insecure:!1,compressed:!1},s=t.replace(/\\\s*\n/g," ").trim().replace(/^curl\s+/,""),o=[];let n=0;for(;n<s.length;){for(;n<s.length&&s[n]===" ";)n++;if(n>=s.length)break;let l="";const r=s[n];if(r==='"'||r==="'"){for(n++;n<s.length&&s[n]!==r;)s[n]==="\\"&&r==='"'?(n++,l+=s[n]||""):l+=s[n],n++;n++}else for(;n<s.length&&s[n]!==" ";)l+=s[n],n++;o.push(l)}for(let l=0;l<o.length;l++){const r=o[l];if(r==="-X"||r==="--request")e.method=(o[++l]||"GET").toUpperCase();else if(r==="-H"||r==="--header"){const _=o[++l]||"",f=_.indexOf(":");f>0&&(e.headers[_.slice(0,f).trim()]=_.slice(f+1).trim())}else r==="-d"||r==="--data"||r==="--data-raw"||r==="--data-binary"?(e.data=o[++l]||"",(!e.method||e.method==="GET")&&(e.method="POST")):r==="-u"||r==="--user"?e.user=o[++l]||"":r==="--url"?e.url=o[++l]||"":r==="-k"||r==="--insecure"?e.insecure=!0:r==="--compressed"?e.compressed=!0:!r.startsWith("-")&&!e.url&&(e.url=r)}return e}function $e(t){const e=["import requests",""],i=Object.keys(t.headers).length>0;if(i){e.push("headers = {");for(const[n,l]of Object.entries(t.headers))e.push(`    "${n}": "${l}",`);e.push("}"),e.push("")}if(t.user){const n=t.user.split(":");e.push(`auth = ("${n[0]}", "${n.slice(1).join(":")}")`),e.push("")}const s=[`"${t.url}"`];i&&s.push("headers=headers"),t.data&&s.push(`data='${t.data}'`),t.user&&s.push("auth=auth"),t.insecure&&s.push("verify=False");const o=t.method.toLowerCase();return e.push(`response = requests.${o}(${s.join(", ")})`),e.push("print(response.status_code)"),e.push("print(response.text)"),e.join(`
`)}function ge(t){const e=[],i=[];return i.push(`  method: "${t.method}"`),Object.keys(t.headers).length>0&&i.push(`  headers: ${JSON.stringify(t.headers,null,4).replace(/\n/g,`
  `)}`),t.data&&i.push(`  body: ${JSON.stringify(t.data)}`),e.push(`const response = await fetch("${t.url}", {`),e.push(i.join(`,
`)),e.push("});"),e.push(""),e.push("const data = await response.text();"),e.push("console.log(data);"),e.join(`
`)}function me(t){const e=["package main","","import (",'	"fmt"','	"io"','	"net/http"'];t.data&&e.push('	"strings"'),t.insecure&&e.push('	"crypto/tls"'),e.push(")"),e.push(""),e.push("func main() {"),t.data?(e.push(`	body := strings.NewReader(${JSON.stringify(t.data)})`),e.push(`	req, err := http.NewRequest("${t.method}", "${t.url}", body)`)):e.push(`	req, err := http.NewRequest("${t.method}", "${t.url}", nil)`),e.push("	if err != nil { panic(err) }");for(const[i,s]of Object.entries(t.headers))e.push(`	req.Header.Set("${i}", "${s}")`);if(t.user){const i=t.user.split(":");e.push(`	req.SetBasicAuth("${i[0]}", "${i.slice(1).join(":")}")`)}return t.insecure?e.push("	client := &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}}"):e.push("	client := &http.Client{}"),e.push("	resp, err := client.Do(req)"),e.push("	if err != nil { panic(err) }"),e.push("	defer resp.Body.Close()"),e.push("	resBody, _ := io.ReadAll(resp.Body)"),e.push("	fmt.Println(string(resBody))"),e.push("}"),e.join(`
`)}function _e(t){const e=['// Cargo.toml: reqwest = { version = "0.11", features = ["blocking"] }',"use reqwest::blocking::Client;","","fn main() -> Result<(), Box<dyn std::error::Error>> {","	let client = Client::new();"],i=t.method.toLowerCase();e.push(`	let response = client.${i}("${t.url}")`);for(const[s,o]of Object.entries(t.headers))e.push(`		.header("${s}", "${o}")`);if(t.user){const s=t.user.split(":");e.push(`		.basic_auth("${s[0]}", Some("${s.slice(1).join(":")}"))`)}return t.data&&e.push(`		.body(${JSON.stringify(t.data)})`),e.push("		.send()?;"),e.push('	println!("{}", response.text()?);'),e.push("	Ok(())"),e.push("}"),e.join(`
`)}function be(t){const e=["<?php","","$ch = curl_init();",""];if(e.push(`curl_setopt($ch, CURLOPT_URL, "${t.url}");`),e.push("curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);"),t.method!=="GET"&&e.push(`curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "${t.method}");`),Object.keys(t.headers).length>0){e.push("curl_setopt($ch, CURLOPT_HTTPHEADER, [");for(const[i,s]of Object.entries(t.headers))e.push(`    "${i}: ${s}",`);e.push("]);")}return t.data&&e.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${t.data}');`),t.user&&e.push(`curl_setopt($ch, CURLOPT_USERPWD, "${t.user}");`),t.insecure&&e.push("curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);"),e.push(""),e.push("$response = curl_exec($ch);"),e.push("curl_close($ch);"),e.push("echo $response;"),e.join(`
`)}const O=[{id:"python",label:"Python",fn:$e},{id:"javascript",label:"JavaScript",fn:ge},{id:"go",label:"Go",fn:me},{id:"rust",label:"Rust",fn:_e},{id:"php",label:"PHP",fn:be}];function Se(){const[t,e]=g(H(),{equals:!1}),i=a=>ue(a,t());se(()=>{const a=h=>{const d=h.detail?.locale;d&&e(d)};window.addEventListener("taitan:locale-change",a),e(H()),ie(()=>window.removeEventListener("taitan:locale-change",a))});const[s,o]=g(`curl -X POST https://api.example.com/data \\
  -H "Content-Type: application/json" \\
  -H "Authorization: Bearer token123" \\
  -d '{"name":"test","value":42}'`),[n,l]=g("python"),[r,_]=g(""),[f,b]=g(""),[G,E]=g(!1);function L(){b("");const a=s().trim();if(!a){b("请输入 cURL 命令");return}if(!a.startsWith("curl")){b("输入应以 curl 开头");return}try{const h=fe(a);if(!h.url){b("未能解析到 URL");return}const d=O.find(x=>x.id===n());_(d?d.fn(h):"")}catch(h){b(h.message||"解析失败")}}function z(){ae(r()),E(!0),setTimeout(()=>E(!1),1500)}return L(),(()=>{var a=S(ce),h=a.firstChild,d=h.firstChild,x=d.nextSibling,T=h.nextSibling,j=T.firstChild,A=j.nextSibling,[B,F]=m(A.nextSibling),R=T.nextSibling,J=R.nextSibling,[P,D]=m(J.nextSibling),I=P.nextSibling,[M,W]=m(I.nextSibling);return u(d,()=>i("cURL 命令")),x.$$input=p=>o(p.currentTarget.value),u(j,()=>i("目标语言：")),u(T,ne(oe,{each:O,children:p=>(()=>{var c=S(he);return c.$$click=()=>l(p.id),u(c,()=>p.label),N(()=>le(c,`tool-btn ${n()===p.id?"":"is-ghost"}`)),k(),c})()}),B,F),R.$$click=L,u(R,()=>i("转换")),u(a,(()=>{var p=q(()=>!!f());return()=>p()&&(()=>{var c=S(pe),y=c.firstChild,$=y.nextSibling,[w,v]=m($.nextSibling);return u(c,f,w,v),c})()})(),P,D),u(a,(()=>{var p=q(()=>!!r());return()=>p()&&(()=>{var c=S(de),y=c.firstChild,$=y.firstChild,w=$.firstChild,[v,X]=m(w.nextSibling),V=v.nextSibling,Q=V.nextSibling,[Y,K]=m(Q.nextSibling),U=$.nextSibling,Z=y.nextSibling;return u($,()=>O.find(ee=>ee.id===n())?.label,v,X),u($,()=>i("代码"),Y,K),U.$$click=z,u(U,()=>G()?"已复制 ✓":"复制代码"),u(Z,r),k(),c})()})(),M,W),N(()=>re(x,"value",s())),k(),a})()}te(["input","click"]);export{Se as default};
