import{readFileSync as S}from"fs";import{join as d}from"path";import{isLocalLink as l}from"../../../utils/path/is-local-link.js";import{copyStaticFile as g}from"../../utils/fs.js";function b(r,t){return a(r,"src",(o,e)=>`<script ${o}>${e}</script>`,t)}function v(r,t){return a(r,"href",o=>`<link ${o} />`,{...t,defaultAttrs:{rel:"stylesheet"}})}function a(r=[],t,o,{contentDir:e,outdir:m,defaultAttrs:p={}}){if(!Array.isArray(r)||!r.length)return"";const f=[];for(const i of r){const h=typeof i=="string"?{[t]:i}:{...i},{src:y,href:C,inline:c,...$}=h;let n=t==="href"?C:y,u="";if(l(n)&&!c){const s=g(e,n,m);if(!s)continue;n=s}else l(n)&&c&&(u=S(d(e,n),"utf-8"),n=!1);const k=j({...p,...$,[t]:n});f.push(o(k,u))}return f.join("")}function j(r){const t=[];for(let o in r){const e=r[o];e!==!1&&(e===!0?t.push(o):t.push(`${o}="${e}"`))}return t.join(" ")}export{v as formatCustomLinks,b as formatCustomScripts};
