"use strict";const x=require("node:fs"),C=require("node:path"),v=require("node:url"),A=require("sharp");var _=typeof document<"u"?document.currentScript:null;function q(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var E={exports:{}},O={exports:{}},$;function I(){return $||($=1,function(e){const w=typeof process<"u"&&process.env.TERM_PROGRAM==="Hyper",g=typeof process<"u"&&process.platform==="win32",b=typeof process<"u"&&process.platform==="linux",r={ballotDisabled:"☒",ballotOff:"☐",ballotOn:"☑",bullet:"•",bulletWhite:"◦",fullBlock:"█",heart:"❤",identicalTo:"≡",line:"─",mark:"※",middot:"·",minus:"-",multiplication:"×",obelus:"÷",pencilDownRight:"✎",pencilRight:"✏",pencilUpRight:"✐",percent:"%",pilcrow2:"❡",pilcrow:"¶",plusMinus:"±",question:"?",section:"§",starsOff:"☆",starsOn:"★",upDownArrow:"↕"},t=Object.assign({},r,{check:"√",cross:"×",ellipsisLarge:"...",ellipsis:"...",info:"i",questionSmall:"?",pointer:">",pointerSmall:"»",radioOff:"( )",radioOn:"(*)",warning:"‼"}),i=Object.assign({},r,{ballotCross:"✘",check:"✔",cross:"✖",ellipsisLarge:"⋯",ellipsis:"…",info:"ℹ",questionFull:"?",questionSmall:"﹖",pointer:b?"▸":"❯",pointerSmall:b?"‣":"›",radioOff:"◯",radioOn:"◉",warning:"⚠"});e.exports=g&&!w?t:i,Reflect.defineProperty(e.exports,"common",{enumerable:!1,value:r}),Reflect.defineProperty(e.exports,"windows",{enumerable:!1,value:t}),Reflect.defineProperty(e.exports,"other",{enumerable:!1,value:i})}(O)),O.exports}const F=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),L=/[\u001b\u009b][[\]#;?()]*(?:(?:(?:[^\W_]*;?[^\W_]*)\u0007)|(?:(?:[0-9]{1,4}(;[0-9]{0,4})*)?[~0-9=<>cf-nqrtyA-PRZ]))/g,z=()=>typeof process<"u"?process.env.FORCE_COLOR!=="0":!1,P=()=>{const e={enabled:z(),visible:!0,styles:{},keys:{}},w=t=>{let i=t.open=`\x1B[${t.codes[0]}m`,s=t.close=`\x1B[${t.codes[1]}m`,u=t.regex=new RegExp(`\\u001b\\[${t.codes[1]}m`,"g");return t.wrap=(c,R)=>{c.includes(s)&&(c=c.replace(u,s+i));let n=i+c+s;return R?n.replace(/\r*\n/g,`${s}$&${i}`):n},t},g=(t,i,s)=>typeof t=="function"?t(i):t.wrap(i,s),b=(t,i)=>{if(t===""||t==null)return"";if(e.enabled===!1)return t;if(e.visible===!1)return"";let s=""+t,u=s.includes(` `),c=i.length;for(c>0&&i.includes("unstyle")&&(i=[...new Set(["unstyle",...i])].reverse());c-- >0;)s=g(e.styles[i[c]],s,u);return s},r=(t,i,s)=>{e.styles[t]=w({name:t,codes:i}),(e.keys[s]||(e.keys[s]=[])).push(t),Reflect.defineProperty(e,t,{configurable:!0,enumerable:!0,set(c){e.alias(t,c)},get(){let c=R=>b(R,c.stack);return Reflect.setPrototypeOf(c,e),c.stack=this.stack?this.stack.concat(t):[t],c}})};return r("reset",[0,0],"modifier"),r("bold",[1,22],"modifier"),r("dim",[2,22],"modifier"),r("italic",[3,23],"modifier"),r("underline",[4,24],"modifier"),r("inverse",[7,27],"modifier"),r("hidden",[8,28],"modifier"),r("strikethrough",[9,29],"modifier"),r("black",[30,39],"color"),r("red",[31,39],"color"),r("green",[32,39],"color"),r("yellow",[33,39],"color"),r("blue",[34,39],"color"),r("magenta",[35,39],"color"),r("cyan",[36,39],"color"),r("white",[37,39],"color"),r("gray",[90,39],"color"),r("grey",[90,39],"color"),r("bgBlack",[40,49],"bg"),r("bgRed",[41,49],"bg"),r("bgGreen",[42,49],"bg"),r("bgYellow",[43,49],"bg"),r("bgBlue",[44,49],"bg"),r("bgMagenta",[45,49],"bg"),r("bgCyan",[46,49],"bg"),r("bgWhite",[47,49],"bg"),r("blackBright",[90,39],"bright"),r("redBright",[91,39],"bright"),r("greenBright",[92,39],"bright"),r("yellowBright",[93,39],"bright"),r("blueBright",[94,39],"bright"),r("magentaBright",[95,39],"bright"),r("cyanBright",[96,39],"bright"),r("whiteBright",[97,39],"bright"),r("bgBlackBright",[100,49],"bgBright"),r("bgRedBright",[101,49],"bgBright"),r("bgGreenBright",[102,49],"bgBright"),r("bgYellowBright",[103,49],"bgBright"),r("bgBlueBright",[104,49],"bgBright"),r("bgMagentaBright",[105,49],"bgBright"),r("bgCyanBright",[106,49],"bgBright"),r("bgWhiteBright",[107,49],"bgBright"),e.ansiRegex=L,e.hasColor=e.hasAnsi=t=>(e.ansiRegex.lastIndex=0,typeof t=="string"&&t!==""&&e.ansiRegex.test(t)),e.alias=(t,i)=>{let s=typeof i=="string"?e[i]:i;if(typeof s!="function")throw new TypeError("Expected alias to be the name of an existing color (string) or a function");s.stack||(Reflect.defineProperty(s,"name",{value:t}),e.styles[t]=s,s.stack=[t]),Reflect.defineProperty(e,t,{configurable:!0,enumerable:!0,set(u){e.alias(t,u)},get(){let u=c=>b(c,u.stack);return Reflect.setPrototypeOf(u,e),u.stack=this.stack?this.stack.concat(s.stack):s.stack,u}})},e.theme=t=>{if(!F(t))throw new TypeError("Expected theme to be an object");for(let i of Object.keys(t))e.alias(i,t[i]);return e},e.alias("unstyle",t=>typeof t=="string"&&t!==""?(e.ansiRegex.lastIndex=0,t.replace(e.ansiRegex,"")):""),e.alias("noop",t=>t),e.none=e.clear=e.noop,e.stripColor=e.unstyle,e.symbols=I(),e.define=r,e};E.exports=P();E.exports.create=P;var M=E.exports;const S=q(M);let j,k;typeof j>"u"?(j=v.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.src||new URL("index.cjs",document.baseURI).href),k=C.dirname(j)):k=k;function N(e){let w;e.log=e.log??!0,e.cache=e.cache??!0;const g={},b={};function r(n){return/\.(?:jpg|jpeg|png|gif|bmp|webp)$/i.test(n)}function t(n,o){return Object.prototype.toString.call(o)==="[object String]"?n===o:Object.prototype.toString.call(o)==="[object RegExp]"?o.test(n):Array.isArray(o)?o.includes(n):!1}function i(n){return r(n)?e.include&&t(n,e.include)?!0:!(e.exclude&&t(n,e.exclude)||e.test&&!e.test.test(n)):!1}async function s(){const n=C.join(k,"cache.json");let o={};try{if(e.cache===!0){await x.promises.access(n,x.promises.constants.F_OK);const l=await x.promises.readFile(n,"utf8");o=JSON.parse(l)}}catch(l){if(l.code==="ENOENT"){const p=JSON.stringify(o,null,2);await x.promises.writeFile(n,p,"utf8")}else console.error("Error:",l)}return{cache:o,async updateCache(){if(e.cache===!1)return;const l=JSON.stringify(o,null,2);await x.promises.writeFile(n,l,"utf8")}}}async function u(n){const o=n.map(async l=>{const{name:p,source:d}=l,a=p.split("."),y=a[a.length-1];return await A(d).toFormat(y,e[y]||{quality:80}).toBuffer().then(f=>{const h=l.source.byteLength,B=f.byteLength;g[p]=g[p]||{},g[p].oldSize=h,g[p].newSize=B,B{b[y]=a[h].url,l[m]=a[h].url,g[f].url=a[h].url,delete n[y]}),p()}async function R(n){const o=new RegExp(`(?:../|\\.\\.)*${w.base}(${w.build.assetsDir}/.*?\\.(?:jpg|jpeg|png|gif|bmp|webp))`,"gi"),l=(d,a)=>b[a]||d;Object.keys(n).forEach(d=>{const a=n[d];a.source?a.source=a.source.replace(o,l):a.code=a.code.replace(o,l)})}return{name:"vite-img-upload",enforce:"post",configResolved(n){w=n},generateBundle:async(n,o)=>{await c(o),R(o)},closeBundle(){if(e.log){console.info(S.greenBright(` vite-img-upload:`));for(const n in g){const o=g[n],l=o.oldSize>o.newSize?`compress: ${o.oldSize} -> ${o.newSize}`:"compress: none";console.info(`${S.yellow(n)}: ${o.url} ${l}`)}console.info(S.greenBright(` vite-img-upload finished!`))}}}}module.exports=N;