import{computed as D,resolveComponent as B,createElementBlock as f,openBlock as y,Fragment as K,renderList as V,normalizeStyle as S,unref as u,createElementVNode as o,renderSlot as $,toDisplayString as r,withDirectives as p,createCommentVNode as _,vShow as v,createVNode as A,normalizeClass as J,ref as O,watch as z,createTextVNode as b}from"/vue.js";import{n as c}from"./nc-main.DEgIQeOo.js";import"./service-worker.DGZzV4eE.js";const E={class:"nc-json-line"},T=["onClick"],F={key:0,class:"nc-json-k"},I={class:"nc-json-line"},P={class:"nc-json-k"},U=["onClick"],q={key:0,class:"nc-json-k"},G={class:"nc-json-line"},H={class:"nc-json-k"},M={key:0,class:"nc-json-k"},Q=Object.assign({name:"NcJsonTree"},{__name:"nc-json-tree",props:{data:{type:Array,default:()=>[]},showLeaf:{type:Boolean,default:!0},indent:{type:Number,default:1},needKey:{type:Boolean,default:!0}},setup(e){const a=e,n=D(()=>({textIndent:`${(a.indent+1)*20}px`}));function s(t){t.show=!t.show}function i(t){return t==="Object"}function k(t){return t==="Array"}function d(t){return t===a.data.length-1?"":","}function j(t){return t==="Number"?"nc-json-number":t==="String"?"nc-json-string":t==="Boolean"?"nc-json-boolean":t==="Undefined"?"nc-json-undefined":t==="Null"?"nc-json-null":""}return(t,w)=>{const m=B("nc-json-tree",!0);return y(),f("div",null,[(y(!0),f(K,null,V(e.data,(l,g)=>(y(),f("p",{key:g,class:"nc-json-p",style:S(u(n))},[o("span",E,r(l.line),1),i(l.type)?$(t.$slots,"default",{key:0},()=>[o("p",{class:"nc-json-f",onClick:L=>s(l)},[e.needKey?(y(),f("span",F,'"'+r(l.key)+'": ',1)):_("",!0),w[0]||(w[0]=o("span",{class:"nc-json-k"},"{",-1)),p(o("span",{class:"nc-json-k"}," ... } "+r(d(g)),513),[[v,!l.show]])],8,T),p(A(m,{data:l.value,"show-leaf":!1,indent:e.indent+1,"need-key":!0},null,8,["data","indent"]),[[v,l.show]]),p(o("p",{style:S(u(n)),class:"nc-json-p"},[o("span",I,r(l.lastLine),1),o("span",P,"} "+r(d(g)),1)],4),[[v,l.show]])]):k(l.type)?$(t.$slots,"default",{key:1},()=>[o("p",{class:"nc-json-f",onClick:L=>s(l)},[e.needKey?(y(),f("span",q,'"'+r(l.key)+'": ',1)):_("",!0),w[1]||(w[1]=o("span",{class:"nc-json-k"},"[",-1)),p(o("span",{class:"nc-json-k"}," ... ] "+r(d(g)),513),[[v,!l.show]])],8,U),p(A(m,{data:l.value,"show-leaf":!1,indent:e.indent+1,"need-key":!1},null,8,["data","indent"]),[[v,l.show]]),p(o("p",{style:S(u(n)),class:"nc-json-p"},[o("span",G,r(l.lastLine),1),o("span",H,"] "+r(d(g)),1)],4),[[v,l.show]])]):$(t.$slots,"default",{key:2},()=>[e.needKey?(y(),f("span",M,'"'+r(l.key)+'": ',1)):_("",!0),o("span",{class:J(j(l.type))},r(l.value)+r(d(g)),3)])],4))),128))])}}});let h=1;const R=e=>{h=1;let a=[];if(c.isObject(e))a=C(e);else if(c.isArray(e))a=N(e);else return[{key:"",value:"error: data should be an Object or Array type",type:"String",line:"1"}];return a},C=e=>{let a=[];for(let n in e){let s=Object.create(null);s.type=c.type(e[n]),s.line=h++,s.key=n,c.isObject(e[n])?(s.value=C(e[n]),s.lastLine=h++,s.show=!0):c.isArray(e[n])?(s.value=N(e[n]),s.lastLine=h++,s.show=!0):e[n]==null?s.value="null":e[n]===void 0?s.value="undefined":c.isString(e[n])?s.value='"'+e[n]+'"':s.value=e[n],a.push(s)}return a},N=e=>{let a=[];for(let n=0;n<e.length;n++){let s=Object.create(null);s.type=c.type(e[n]),s.key=n,s.line=h++,c.isObject(e[n])?(s.value=C(e[n]),s.lastLine=h++,s.show=!0):c.isArray(e[n])?(s.value=N(e[n]),s.lastLine=h++,s.show=!0):e[n]==null?s.value="null":e[n]===void 0?s.value="undefined":c.isString(e[n])?s.value='"'+e[n]+'"':s.value=e[n],a.push(s)}return a},W={class:"nc-json"},X={key:2},Y={key:3},ne=Object.assign({name:"NcJson"},{__name:"nc-json",props:{data:{type:[Object,Array,String],default:()=>{}}},setup(e){const a=e,n=O({}),s=O([]),i=O(!0),k=O(!0),d=O(!1);return z(()=>a.data,()=>{if(d.value=!1,c.isString(a.data)){let j;try{j=JSON.parse(a.data)}catch{k.value=!1;return}n.value=j}else n.value=a.data;c.isObject(n.value)?(k.value=!0,d.value=!0):c.isArray(n.value)?(k.value=!1,d.value=!0):k.value=!1,d.value&&(s.value=R(n.value))},{immediate:!0}),(j,t)=>(y(),f("code",W,[o("div",null,[u(d)?$(j.$slots,"default",{key:0},()=>[u(k)?(y(),f("p",{key:0,class:"nc-json-f",onClick:t[0]||(t[0]=w=>i.value=!u(i))},[t[2]||(t[2]=b(" { ",-1)),p(o("span",null,"... }",512),[[v,!u(i)]])])):(y(),f("p",{key:1,class:"nc-json-f",onClick:t[1]||(t[1]=w=>i.value=!u(i))},[t[3]||(t[3]=b(" [ ",-1)),p(o("span",null,"... ]",512),[[v,!u(i)]])])),p(A(Q,{data:u(s),"need-key":u(k)},null,8,["data","need-key"]),[[v,u(i)]]),u(k)?p((y(),f("p",X,"}",512)),[[v,u(i)]]):p((y(),f("p",Y,"]",512)),[[v,u(i)]])]):$(j.$slots,"default",{key:1},()=>[b(r(e.data),1)])])]))}});export{ne as default};
