import{k as D,j as v,t as H,h as J,m as _,n as S,p as l,w as R,q as Y,i as z,v as Z,A as $,x as C,s as G}from"./web.Os7kOAdY.js";import{c as O}from"./clipboard.BNxbz_oK.js";import{g as M,t as U}from"./i18n-runtime._BAkvU05.js";var X=$(`<div class=tool-card style=padding:20px><div style=display:flex;gap:12px;align-items:center;margin-bottom:16px;flex-wrap:wrap><span style=font-size:13px;font-weight:600;color:var(--c-muted,#666)></span><button style="margin-left:auto;padding:6px 16px;font-size:13px;border-radius:6px;cursor:pointer;background:var(--c-accent,#4f46e5);color:#fff;border:none"></button></div><div class=mobile-stack-grid style="display:grid;grid-template-columns:1fr 1fr;gap:16px"><div><div style=font-size:12px;font-weight:600;margin-bottom:6px;color:var(--c-muted,#666)></div><textarea placeholder="docker run -d --name myapp -p 8080:80 -v ./data:/app/data nginx:latest"style="width:100%;min-height:360px;padding:12px;font-family:'JetBrains Mono',monospace;font-size:13px;line-height:1.6;border:1px solid var(--c-border,#ddd);border-radius:8px;resize:vertical;background:var(--c-surface,#fafafa)"></textarea></div><div><div style=font-size:12px;font-weight:600;margin-bottom:6px;color:var(--c-muted,#666)>docker-compose.yml</div><pre style="width:100%;min-height:360px;padding:12px;font-family:'JetBrains Mono',monospace;font-size:13px;line-height:1.6;border:1px solid var(--c-border,#ddd);border-radius:8px;background:#1e1e2e;color:#cdd6f4;overflow:auto;margin:0;white-space:pre-wrap"></pre></div></div><!$><!/><div style="margin-top:12px;padding:10px 14px;background:var(--c-surface,#f9fafb);border-radius:6px;font-size:12px;color:var(--c-muted,#666)">`),F=$('<div style="margin-top:12px;padding:10px 14px;background:#fef2f2;border:1px solid #fecaca;border-radius:6px">'),K=$("<div style=font-size:12px;color:#dc2626>⚠ <!$><!/>");function Q(i){const a=[],e={image:""},c=i.replace(/\\\s*\n/g," ").trim().match(/^docker\s+run\s+(.*)$/i);if(!c)return a.push('输入必须以 "docker run" 开头'),{service:e,errors:a};const u=c[1],o=[],p=/(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|(\S+))/g;let d;for(;(d=p.exec(u))!==null;)o.push(d[1]??d[2]??d[3]);let n=0;const s=[];for(;n<o.length;){const t=o[n];t==="--name"&&n+1<o.length?e.container_name=o[++n]:t==="-p"||t==="--publish"?n+1<o.length&&(e.ports||(e.ports=[]),e.ports.push(o[++n])):t==="-v"||t==="--volume"?n+1<o.length&&(e.volumes||(e.volumes=[]),e.volumes.push(o[++n])):t==="-e"||t==="--env"?n+1<o.length&&(e.environment||(e.environment=[]),e.environment.push(o[++n])):t==="--env-file"?n+1<o.length&&(e.env_file||(e.env_file=[]),e.env_file.push(o[++n])):t==="--network"||t==="--net"?n+1<o.length&&(e.networks||(e.networks=[]),e.networks.push(o[++n])):t==="--restart"?n+1<o.length&&(e.restart=o[++n]):t==="-d"||t==="--detach"||(t==="--privileged"?e.privileged=!0:t==="--cap-add"?n+1<o.length&&(e.cap_add||(e.cap_add=[]),e.cap_add.push(o[++n])):t==="-w"||t==="--workdir"?n+1<o.length&&(e.working_dir=o[++n]):t==="--entrypoint"?n+1<o.length&&(e.entrypoint=o[++n]):t==="-it"||t==="-ti"||t==="-i"||t==="-t"||t==="--rm"||(t.startsWith("-p")&&t.length>2?(e.ports||(e.ports=[]),e.ports.push(t.slice(2))):t.startsWith("-e")&&t.length>2?(e.environment||(e.environment=[]),e.environment.push(t.slice(2))):t.startsWith("--")||t.startsWith("-")?(a.push(`未识别的参数: ${t}`),n+1<o.length&&!o[n+1].startsWith("-")&&n++):s.push(t))),n++}return s.length>0?(e.image=s[0],s.length>1&&(e.command=s.slice(1).join(" "))):a.push("未找到镜像名称"),{service:e,errors:a}}function V(i,a){const e=[];if(e.push('version: "3.8"'),e.push(""),e.push("services:"),e.push(`  ${a}:`),e.push(`    image: ${i.image}`),i.container_name&&e.push(`    container_name: ${i.container_name}`),i.restart&&e.push(`    restart: ${i.restart}`),i.privileged&&e.push("    privileged: true"),i.working_dir&&e.push(`    working_dir: ${i.working_dir}`),i.entrypoint&&e.push(`    entrypoint: ${i.entrypoint}`),i.command&&e.push(`    command: ${i.command}`),i.ports&&i.ports.length>0){e.push("    ports:");for(const r of i.ports)e.push(`      - "${r}"`)}if(i.volumes&&i.volumes.length>0){e.push("    volumes:");for(const r of i.volumes)e.push(`      - ${r}`)}if(i.environment&&i.environment.length>0){e.push("    environment:");for(const r of i.environment)e.push(`      - ${r}`)}if(i.env_file&&i.env_file.length>0){e.push("    env_file:");for(const r of i.env_file)e.push(`      - ${r}`)}if(i.cap_add&&i.cap_add.length>0){e.push("    cap_add:");for(const r of i.cap_add)e.push(`      - ${r}`)}if(i.networks&&i.networks.length>0){e.push("    networks:");for(const r of i.networks)e.push(`      - ${r}`);e.push(""),e.push("networks:");for(const r of i.networks)e.push(`  ${r}:`),e.push("    external: true")}return e.join(`
`)}const ee=`docker run -d \\
  --name my-nginx \\
  -p 8080:80 \\
  -p 8443:443 \\
  -v /data/html:/usr/share/nginx/html:ro \\
  -v /data/nginx.conf:/etc/nginx/nginx.conf \\
  -e TZ=Asia/Shanghai \\
  -e NGINX_HOST=example.com \\
  --network my-net \\
  --restart unless-stopped \\
  nginx:alpine`;function oe(){const[i,a]=v(M(),{equals:!1}),e=n=>U(n,i());H(()=>{const n=s=>{const t=s.detail?.locale;t&&a(t)};window.addEventListener("taitan:locale-change",n),a(M()),G(()=>window.removeEventListener("taitan:locale-change",n))});const[r,c]=v(ee),[u,o]=v(!1),p=J(()=>{const n=r().trim();if(!n)return{yaml:"",errors:[]};const{service:s,errors:t}=Q(n);!s.image&&t.length===0&&t.push("未找到镜像名称");const f=s.container_name||s.image.split(":")[0].split("/").pop()||"app";return{yaml:s.image?V(s,f.replace(/[^a-zA-Z0-9_-]/g,"-")):"",errors:t}}),d=async()=>{await O(p().yaml),o(!0),setTimeout(()=>o(!1),1500)};return(()=>{var n=_(X),s=n.firstChild,t=s.firstChild,f=t.nextSibling,m=s.nextSibling,k=m.firstChild,y=k.firstChild,h=y.nextSibling,A=k.nextSibling,E=A.firstChild,L=E.nextSibling,T=m.nextSibling,[w,N]=S(T.nextSibling),W=w.nextSibling;return l(t,()=>e("粘贴 docker run 命令，自动生成 docker-compose.yml")),f.$$click=d,l(f,()=>u()?"已复制 ✓":"复制 YAML"),l(y,()=>e("docker run 命令")),h.$$input=g=>c(g.currentTarget.value),R(h,"spellcheck",!1),l(L,()=>p().yaml||"# 在左侧输入 docker run 命令..."),l(n,(()=>{var g=Y(()=>p().errors.length>0);return()=>g()&&(()=>{var b=_(F);return l(b,()=>p().errors.map(j=>(()=>{var x=_(K),I=x.firstChild,P=I.nextSibling,[q,B]=S(P.nextSibling);return l(x,j,q,B),x})())),b})()})(),w,N),l(W,()=>e("支持的参数：--name, -p, -v, -e, --env-file, --network, --restart, -d, --privileged, --cap-add, -w, --entrypoint, 镜像名, 命令")),z(()=>C(f,"disabled",!p().yaml)),z(()=>C(h,"value",r())),Z(),n})()}D(["click","input"]);export{oe as default};
