import{k as j,j as v,t as I,m as W,n as L,p as m,q as B,v as R,i as D,A,e as H,w as K,x as tt,s as et}from"./web.Os7kOAdY.js";import{c as nt}from"./clipboard.BNxbz_oK.js";import{g as P,t as rt}from"./i18n-runtime._BAkvU05.js";var it=A('<div class=panel style=display:flex;flex-direction:column;gap:14px><div style=display:flex;gap:8px;align-items:center;flex-wrap:wrap><button>JSON → YAML</button><button>YAML → JSON</button><button class="tool-btn is-ghost"></button></div><div class=tool-field><span class=tool-label></span><textarea class=tool-input rows=12 style=font-family:ui-monospace,monospace;font-size:13px;resize:vertical></textarea></div><div style=display:flex;gap:8px><button class=tool-btn></button></div><!$><!/><!$><!/>'),lt=A("<div class=tool-error style=padding:8px;border-radius:6px;background:#fff0f0;color:#c00>⚠ <!$><!/>"),st=A('<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:400px;overflow-y:auto>');function S(t,n=0){const r="  ".repeat(n);if(t==null)return r+"null";if(typeof t=="boolean")return r+(t?"true":"false");if(typeof t=="number")return r+String(t);if(typeof t=="string")return t===""||t.includes(`
`)||t.includes(":")||t.includes("#")||t.includes('"')||t.includes("'")||/^[\s\-\[\]{}>|*&!%@`,?]/.test(t)||t==="true"||t==="false"||t==="null"||!isNaN(Number(t))?r+JSON.stringify(t):r+t;if(Array.isArray(t))return t.length===0?r+"[]":t.map(s=>{if(typeof s=="object"&&s!==null){const e=S(s,n+1).trimStart();return r+"- "+e}const i=S(s,0).trimStart();return r+"- "+i}).join(`
`);if(typeof t=="object"){const s=Object.entries(t);return s.length===0?r+"{}":s.map(([i,e])=>{const l=/^[a-zA-Z0-9_\-]+$/.test(i)?i:JSON.stringify(i);return e==null?r+l+": null":typeof e!="object"?r+l+": "+S(e,0).trimStart():r+l+`:
`+S(e,n+1)}).join(`
`)}return r+String(t)}function ot(t){const n=t.split(`
`),r=[];for(const i of n){const e=i;if(i.trim()===""||i.trim().startsWith("#"))continue;const l=i.length-i.trimStart().length,o=i.trimStart();r.push({indent:l,raw:e,content:o})}if(r.length===0)return null;const[s]=w(r,0,0);return s}function w(t,n,r){if(n>=t.length)return[null,n];const s=t[n];if(s.content.startsWith("- ")||s.content==="-"){const i=[];let e=n;for(;e<t.length&&t[e].indent===r&&!(!t[e].content.startsWith("- ")&&t[e].content!=="-");){const l=t[e].content==="-"?"":t[e].content.slice(2),o=e+1;if(l===""&&o<t.length&&t[o].indent>r){const[u,f]=w(t,o,t[o].indent);i.push(u),e=f}else if(l.includes(": ")||o<t.length&&t[o].indent>r){const u=[{indent:r+2,raw:"",content:l},...at(t,o,r)];if(l&&(l.includes(": ")||l.includes(":"))){const[f,p]=w(u,0,r+2);for(i.push(f),e=o;e<t.length&&t[e].indent>r;)e++}else i.push(_(l)),e=o}else i.push(_(l)),e=o}return[i,e]}if(s.content.includes(":")){const i={};let e=n;for(;e<t.length&&t[e].indent===r;){const l=t[e];if(l.content.startsWith("- "))break;const o=l.content.indexOf(":");if(o===-1)break;const u=l.content.slice(0,o).trim().replace(/^["']|["']$/g,""),f=l.content.slice(o+1).trim();if(f===""||f==="|"||f===">"){const p=e+1;if(p<t.length&&t[p].indent>r){const[N,b]=w(t,p,t[p].indent);i[u]=N,e=b}else i[u]=null,e=p}else f==="[]"?(i[u]=[],e++):f==="{}"?(i[u]={},e++):(i[u]=_(f),e++)}return[i,e]}return[_(s.content),n+1]}function at(t,n,r){const s=[];let i=n;for(;i<t.length&&t[i].indent>r;)s.push(t[i]),i++;return s}function _(t){const n=t.trim();if(n==="null"||n==="~"||n==="")return null;if(n==="true")return!0;if(n==="false")return!1;if(n.startsWith('"')&&n.endsWith('"')||n.startsWith("'")&&n.endsWith("'"))return n.slice(1,-1);if(n.startsWith("[")&&n.endsWith("]")){try{return JSON.parse(n)}catch{}return n.slice(1,-1).split(",").map(s=>_(s.trim()))}if(n.startsWith("{")&&n.endsWith("}"))try{return JSON.parse(n)}catch{}const r=Number(n);return!isNaN(r)&&n!==""?r:n}function pt(){const[t,n]=v(P(),{equals:!1}),r=a=>rt(a,t());I(()=>{const a=y=>{const $=y.detail?.locale;$&&n($)};window.addEventListener("taitan:locale-change",a),n(P()),et(()=>window.removeEventListener("taitan:locale-change",a))});const[s,i]=v(`{
  "name": "example",
  "version": 1,
  "tags": ["tool", "converter"],
  "nested": {
    "enabled": true,
    "count": 42
  }
}`),[e,l]=v(""),[o,u]=v("json2yaml"),[f,p]=v(""),[N,b]=v(!1);function Y(){p("");try{if(o()==="json2yaml"){const a=JSON.parse(s());l(S(a))}else{const a=ot(s());l(JSON.stringify(a,null,2))}}catch(a){p(a.message||"转换失败"),l("")}}function Z(){const a=e();a&&(i(a),l(""),u(y=>y==="json2yaml"?"yaml2json":"json2yaml"))}function F(){nt(e()),b(!0),setTimeout(()=>b(!1),1500)}return e()||Y(),(()=>{var a=W(it),y=a.firstChild,$=y.firstChild,k=$.nextSibling,O=k.nextSibling,E=y.nextSibling,M=E.firstChild,C=M.nextSibling,z=E.nextSibling,T=z.firstChild,G=z.nextSibling,[q,Q]=L(G.nextSibling),U=q.nextSibling,[V,X]=L(U.nextSibling);return $.$$click=()=>{u("json2yaml"),p("")},k.$$click=()=>{u("yaml2json"),p("")},O.$$click=Z,m(O,()=>r("⇄ 交换")),m(M,()=>o()==="json2yaml"?"JSON 输入":"YAML 输入"),C.$$input=c=>i(c.currentTarget.value),T.$$click=Y,m(T,()=>r("转换")),m(a,(()=>{var c=B(()=>!!f());return()=>c()&&(()=>{var d=W(lt),g=d.firstChild,h=g.nextSibling,[x,J]=L(h.nextSibling);return m(d,f,x,J),d})()})(),q,Q),m(a,(()=>{var c=B(()=>!!e());return()=>c()&&(()=>{var d=W(st),g=d.firstChild,h=g.firstChild,x=h.nextSibling,J=g.nextSibling;return m(h,()=>o()==="json2yaml"?"YAML 输出":"JSON 输出"),x.$$click=F,m(x,()=>N()?"已复制 ✓":"复制"),m(J,e),R(),d})()})(),V,X),D(c=>{var d=`tool-btn ${o()==="json2yaml"?"":"is-ghost"}`,g=`tool-btn ${o()==="yaml2json"?"":"is-ghost"}`,h=r("交换输入输出"),x=o()==="json2yaml"?"粘贴 JSON...":"粘贴 YAML...";return d!==c.e&&H($,c.e=d),g!==c.t&&H(k,c.t=g),h!==c.a&&K(O,"title",c.a=h),x!==c.o&&K(C,"placeholder",c.o=x),c},{e:void 0,t:void 0,a:void 0,o:void 0}),D(()=>tt(C,"value",s())),R(),a})()}j(["click","input"]);export{pt as default};
