/* esm.sh - yaml@2.9.1/browser/dist/stringify/stringifyCollection */
import{isNode as $,isPair as C}from"../nodes/identity.mjs";import{stringify as v}from"./stringify.mjs";import{lineComment as S,indentComment as W}from"./stringifyComment.mjs";function O(c,i,m){return(i.inFlow??c.flow?F:j)(c,i,m)}function j({comment:c,items:i},m,{blockItemPrefix:s,flowChars:a,itemIndent:g,onChompKeep:d,onComment:y}){let{indent:B,options:{commentString:o}}=m,k=Object.assign({},m,{indent:g,type:null}),n=!1,f=[];for(let t=0;t<i.length;++t){let e=i[t],l=null;if($(e))!n&&e.spaceBefore&&f.push(""),w(m,f,e.commentBefore,n),e.comment&&(l=e.comment);else if(C(e)){let r=$(e.key)?e.key:null;r&&(!n&&r.spaceBefore&&f.push(""),w(m,f,r.commentBefore,n))}n=!1;let u=v(e,k,()=>l=null,()=>n=!0);l&&(u+=S(u,g,o(l))),n&&l&&(n=!1),f.push(s+u)}let p;if(f.length===0)p=a.start+a.end;else{p=f[0];for(let t=1;t<f.length;++t){let e=f[t];p+=e?`
${B}${e}`:`
`}}return c?(p+=`
`+W(o(c),B),y&&y()):n&&d&&d(),p}function F({items:c},i,{flowChars:m,itemIndent:s}){let{indent:a,indentStep:g,flowCollectionPadding:d,options:{commentString:y}}=i;s+=g;let B=Object.assign({},i,{indent:s,inFlow:!0,type:null}),o=!1,k=0,n=[];for(let t=0;t<c.length;++t){let e=c[t],l=null;if($(e))e.spaceBefore&&n.push(""),w(i,n,e.commentBefore,!1),e.comment&&(l=e.comment);else if(C(e)){let r=$(e.key)?e.key:null;r&&(r.spaceBefore&&n.push(""),w(i,n,r.commentBefore,!1),r.comment&&(o=!0));let h=$(e.value)?e.value:null;h?(h.comment&&(l=h.comment),h.commentBefore&&(o=!0)):e.value==null&&r?.comment&&(l=r.comment)}l&&(o=!0);let u=v(e,B,()=>l=null);o||(o=n.length>k||u.includes(`
`)),t<c.length-1?u+=",":i.options.trailingComma&&(i.options.lineWidth>0&&(o||(o=n.reduce((r,h)=>r+h.length+2,2)+(u.length+2)>i.options.lineWidth)),o&&(u+=",")),l&&(u+=S(u,s,y(l))),n.push(u),k=n.length}let{start:f,end:p}=m;if(n.length===0)return f+p;if(!o){let t=n.reduce((e,l)=>e+l.length+2,2);o=i.options.lineWidth>0&&t>i.options.lineWidth}if(o){let t=f;for(let e of n)t+=e?`
${g}${a}${e}`:`
`;return`${t}
${a}${p}`}else return`${f}${d}${n.join(" ")}${d}${p}`}function w({indent:c,options:{commentString:i}},m,s,a){if(s&&a&&(s=s.replace(/^\n+/,"")),s){let g=W(i(s),c);m.push(g.trimStart())}}export{O as stringifyCollection};
//# sourceMappingURL=stringifyCollection.mjs.map