@visulima/packem
Version:
A fast and modern bundler for Node.js and TypeScript.
53 lines • 205 kB
JavaScript
#!/usr/bin/env node
var Fo=Object.defineProperty;var h=(e,t)=>Fo(e,"name",{value:t,configurable:!0});import Jo from"@visulima/cerebro";import{SimpleReporter as Lo}from"@visulima/pail/reporter";import Ae,{cwd as Ot,env as Bo,versions as qo,exit as Wo}from"node:process";import{installPackage as xt}from"@antfu/install-pkg";import{spinner as yt,select as ee,multiselect as Oi,confirm as V,intro as Uo,log as zt,cancel as Vo,outro as Ko}from"@clack/prompts";import{isAccessible as Ze,readFile as Ce,writeFile as Pi,isAccessibleSync as J,collectSync as Go,readFileSync as et,writeFileSync as pe,ensureDir as At,emptyDir as Ho,readJsonSync as Xo,writeJsonSync as Di,readJson as Ci,walk as Yo,writeJson as Qo,ensureDirSync as Zo}from"@visulima/fs";import{join as j,resolve as O,extname as Me,toNamespacedPath as ve,isAbsolute as Ie,relative as A,normalize as G,dirname as I,basename as H,parse as ct,sep as Rt}from"@visulima/path";import z from"magic-string";import{defu as Ni}from"defu";import{createJiti as Mi}from"jiti";import{cyan as C,bold as K,gray as Z,yellow as Ii,grey as en,green as tn}from"@visulima/colorize";import{findCacheDirSync as on}from"@visulima/find-cache-dir";import{parseBytes as Ft,formatBytes as R,duration as Jt}from"@visulima/humanizer";import{hasPackageJsonAnyDependency as _i}from"@visulima/package";import nn from"browserslist";import{createHooks as an}from"hookable";import{watch as Lt,rollup as Ti,VERSION as sn}from"rollup";import{exec as rn}from"tinyexec";import{parsePackageJson as zi,findPackageJson as ln}from"@visulima/package/package-json";import{readTsConfig as pn,findTsConfig as cn}from"@visulima/tsconfig";import{NotFoundError as dn}from"@visulima/fs/error";import{isRelative as Pt,resolveAlias as un}from"@visulima/path/utils";import{isDynamicPattern as Bt,globSync as mn,glob as fn}from"tinyglobby";import{fileURLToPath as gn,resolveModuleExportNames as vn,resolvePath as qt,interopDefault as hn,loadModule as xn,findStaticImports as tt,findExports as yn,parseStaticImport as bn,isNodeBuiltin as Re,parseNodeModulePath as Wt}from"mlly";import{chmod as wn,stat as Dt,readFile as $n,readdir as kn,rm as jn}from"node:fs/promises";import En,{createHash as Sn}from"node:crypto";import Ai from"@rollup/plugin-alias";import On from"@rollup/plugin-commonjs";import Pn from"@rollup/plugin-dynamic-import-vars";import{nodeResolve as Ri}from"@rollup/plugin-node-resolve";import Fi from"@rollup/plugin-replace";import{wasm as Dn}from"@rollup/plugin-wasm";import Cn from"rollup-plugin-polyfill-node";import{PluginPure as Nn}from"rollup-plugin-pure";import{visualizer as Mn}from"rollup-plugin-visualizer";import{minVersion as Ji,validRange as In,satisfies as _n,valid as Tn,coerce as zn}from"semver";import Ue from"node:assert/strict";import{extractAssignedNames as An,createFilter as X}from"@rollup/pluginutils";import Rn from"glob-parent";import{SourceMapConsumer as Fn,SourceMapGenerator as Jn}from"source-map-js";import{fileURLToPath as Li}from"node:url";import{ResolverFactory as Bi}from"oxc-resolver";import{parseSync as qi,parseAsync as Ln}from"oxc-parser";import Bn from"@rollup/plugin-json";import qn from"rollup-plugin-license";import{readdirSync as Wn,createReadStream as Ct,createWriteStream as Un,existsSync as Vn}from"node:fs";import{loadSourceMap as Kn}from"@visulima/source-map";import{parse as Gn}from"@babel/parser";import Hn from"child_process";import{distance as Xn}from"fastest-levenshtein";import Yn from"picomatch";import{createBrotliCompress as Qn,constants as Zn,createGzip as ea}from"node:zlib";import __cjs_url__ from "node:url"; // -- packem CommonJS __filename shim --
import __cjs_path__ from "node:path"; // -- packem CommonJS __dirname shim --
import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
const __dirname = __cjs_path__.dirname(__filename);
const require = __cjs_mod__.createRequire(import.meta.url);
const ta="@visulima/packem",ia="1.28.2";var oa=Object.defineProperty,na=h((e,t)=>oa(e,"name",{value:t,configurable:!0}),"t$d");const Wi=na(async(e,t="")=>{let i=t;if(!i){const o=["packem.config.js","packem.config.mjs","packem.config.cjs","packem.config.ts","packem.config.cts","packem.config.mts"];for(const n of o)if(await Ze(j(e,n))){i=`./${n}`;break}}if(!/\.(?:js|mjs|cjs|ts|cts|mts)$/.test(i))throw new Error("Invalid packem config file extension. Only .js, .mjs, .cjs, .ts, .cts and .mts extensions are allowed.");return i},"findPackemFile"),Ui={less:["less"],lightningcss:["lightningcss"],"node-sass":["node-sass"],postcss:["postcss","postcss-load-config","postcss-modules-extract-imports","postcss-modules-local-by-default","postcss-modules-scope","postcss-modules-values","postcss-value-parser","icss-utils"],sass:["sass"],"sass-embedded":["sass-embedded"],stylus:["stylus"]};var aa=Object.defineProperty,Ut=h((e,t)=>aa(e,"name",{value:t,configurable:!0}),"g$8");const sa=["typedoc","typedoc-plugin-markdown","typedoc-plugin-rename-defaults"],ra=Ut(e=>{e.addCommand({argument:{description:"Add a packem feature to your project",name:"feature",required:!0},description:"Add a optional packem feature to your project",execute:Ut(async({argument:t,logger:i,options:o})=>{const n=yt(),s=O(Ot(),o.dir??".");let a;try{a=await Wi(s,o.config)}catch{i.error("Could not find a packem config file, please run `packem init` first.");return}const c=await Ce(a,{buffer:!1});let p="cjs";c.includes("import")&&(p="esm");const r=new z(c),l=" transformer,";let u=" transformer";if(c.includes(" transformer,")&&(u=" transformer,"),t.includes("typedoc")){if(c.includes("typedoc: typedocBuilder")||c.includes("@visulima/packem/builder/typedoc")){i.warn("Typedoc has already been added to the packem config.");return}p==="cjs"?r.prepend(`const typedocBuilder = require("@visulima/packem/builder/typedoc");
`):r.prepend(`import typedocBuilder from "@visulima/packem/builder/typedoc";
`),c.includes("builder: {")?r.replace("builder: {",`builder: {
typedoc: typedocBuilder,
`):r.replace(u,`${l}
builder: {
typedoc: typedocBuilder,
},`),i.info("Adding typedoc dependencies..."),n.start("Installing packages"),await xt(sa,{cwd:s,dev:!0,silent:!0}),n.stop("Installed packages"),i.success(`
Typedoc added!`)}if(t.includes("css")){if(c.includes("css: {")||c.includes("@visulima/packem/css")){i.warn("Css loaders have already been added to the packem config.");return}const d=[],m=await ee({message:"Pick a css loader",options:[{label:"PostCSS",value:"postcss"},{hint:"experimental",label:"Lightning CSS",value:"lightningcss"}]});d.push(m);let g=await Oi({message:"Pick extra loaders",options:[{label:"Sass",value:"sass"},{label:"Stylus",value:"stylus"},{label:"Less",value:"less"}],required:!1});if(g.includes("sass")){const w=await ee({message:"Pick a sass loader",options:[{hint:"recommended",label:"Sass embedded",value:"sass-embedded"},{label:"Sass",value:"sass"},{hint:"legacy",label:"Node Sass",value:"node-sass"}]});w!=="sass"&&(g=g.filter(b=>b!=="sass"),g.push(w))}d.push(...g);const v=[];for(const w of d)v.push(...Ui[w]);d.push("sourceMap");for(let w of d)(w==="sass-embedded"||w==="node-sass")&&(w="sass"),p==="cjs"?r.prepend(`const ${w}Loader = require("@visulima/packem/css/loader/${w.toLowerCase()}");
`):r.prepend(`import ${w}Loader from "@visulima/packem/css/loader/${w.toLowerCase()}";
`);const x=await V({initialValue:!1,message:"Do you want to minify your css?"});let f;x&&(f=await ee({message:"Pick a css minifier",options:[{label:"CSSNano",value:"cssnano"},{label:"Lightning CSS",value:"lightningcss"}]}),d.includes("lightningcss")||v.push(f),p==="cjs"?r.prepend(`const ${f}Minifier = require("@visulima/packem/css/minifier/${f.toLowerCase()}");
`):r.prepend(`import ${f}Minifier from "@visulima/packem/css/minifier/${f.toLowerCase()}";
`));const y=d.map(w=>((w==="sass-embedded"||w==="node-sass")&&(w="sass"),`${w}Loader`)).join(", ");c.includes("rollup: {")?r.replace("rollup: {",`rollup: {
css: {${f?`
minifier: ${f}Minifier,`:""}
loaders: [${y}],
},
`):r.replace(u,`${l}
rollup: {
css: {${f?`
minifier: ${f}Minifier,`:""}
loaders: [${y}],
},
},`),n.start("Installing packages"),await xt(v,{cwd:s,dev:!0,silent:!0}),n.stop("Installed packages"),i.success(`
CSS loaders added!`)}await Pi(a,r.toString(),{overwrite:!0})},"execute"),name:"add",options:[{defaultValue:".",description:"The directory to build",name:"dir",type:String},{description:"Use a custom config file",name:"config",type:String}]})},"createAddCommand");var la=Object.defineProperty,pa=h((e,t)=>la(e,"name",{value:t,configurable:!0}),"e$9");const ca=pa(async(e,t,i,o,n)=>{const s=await Wi(t,n);let a=await e.import(s,{default:!0,try:!0})||{};return typeof a=="function"&&(a=await a(i,o)),{config:a,path:s}},"loadPackemConfig");var da=Object.defineProperty,ua=h((e,t)=>da(e,"name",{value:t,configurable:!0}),"r$i");const E=ua((e,t)=>{e.warnings.has(t)||e.warnings.add(t)},"warn"),bt=[".js",".mjs",".cjs",".ts",".mts",".cts",".d.ts",".d.mts",".d.cts",".jsx",".tsx",".json",".node"],it=[...bt,".ctsx",".mtsx"],oe="production",Ve="development",Nt=new Set(["edge-light","react-native","react-server"]),Ke=new Set([Ve,oe,...Nt]),be=/node_modules/,ae=/(?:\.d\.[mc]?tsx?|\.\w+)$/,ma="packem_chunks",fa="packem_shared",we=/\.(?:m|c)?(?:j|t)sx?$/;var ga=Object.defineProperty,Vi=h((e,t)=>ga(e,"name",{value:t,configurable:!0}),"s$j");const Ge=Vi(e=>{if(e.endsWith(".mjs")||e.endsWith(".d.mts"))return"esm";if(e.endsWith(".cjs")||e.endsWith(".d.cts"))return"cjs"},"inferExportTypeFromFileName"),wt=Vi((e,t,i,o)=>{if(e==="module-sync")return"esm";if(o){const a=Ge(o);if(a)return a}if(e==="module"||e==="import")return"esm";if(e==="require")return"cjs";if(t.length===0)return i;const[n,...s]=t;return wt(n,s,i,o)},"inferExportType");var va=Object.defineProperty,ha=h((e,t)=>va(e,"name",{value:t,configurable:!0}),"y$a");const xa=new Set(["browser","bun","default","deno","electron","import","module-sync","node","node-addons","require","types","workerd",...Nt,...Ke]),Mt=ha((e,t,i,o=[])=>{if(!e)return[];if(typeof e=="string"){const n=Ge(e);if(n&&n!==t)throw new Error(`Exported file "${e}" has an extension that does not match the package.json type "${t==="esm"?"module":"commonjs"}".`);return[{file:e,key:"exports",type:n??t}]}if(typeof e=="object"){const n=Object.entries(e).filter(([a])=>!a.endsWith(".json"));let s=[];for(const[a,c]of n)if(typeof c=="string"){let p={};Number.isInteger(+a)?p={exportKey:"*"}:a.startsWith("./")?p={exportKey:a.replace("./","")}:p={exportKey:a==="."?".":"*",subKey:a},s.push({...p,file:c,key:"exports",type:wt(a,o,t,c)})}else if(typeof c=="object"&&c!==void 0)for(const[p,r]of Object.entries(c)){if(i===!1&&p==="types")continue;const l=Number.isInteger(+a)?p:a;typeof r=="string"?s.push({exportKey:l.replace("./",""),file:r,key:"exports",...xa.has(p)?{subKey:p}:{},type:wt(p,o,t,r)}):s=[...s,...Mt({[l]:r},t,i,[...o,p])]}return s}return[]},"extractExportFilenames");var ya=Object.defineProperty,ot=h((e,t)=>ya(e,"name",{value:t,configurable:!0}),"y$9");const ba=ot((e,t)=>e.key==="exports"&&e.subKey===oe?oe:e.key==="exports"&&e.subKey===Ve?Ve:t,"getEnvironment"),Fe=ot((e,t,i,o,n,s,a)=>{const c=ba(n,s.environment);let p=s.options.runtime;for(const u of Nt)if(n.file.includes(`.${u}.`)||n.subKey===u){p=u;break}let r=e.find(u=>u.input===t&&u.environment===c&&u.runtime===p);r===void 0?r=e[e.push({environment:c,exportKey:new Set([n.exportKey].filter(Boolean)),input:t,runtime:p})-1]:r.exportKey&&n.exportKey&&r.exportKey.add(n.exportKey),a&&(r.isGlob=!0),i&&(r.outDir=o),n.isExecutable?(r.executable=!0,r.declaration=!1,n.type==="cjs"?r.cjs=!0:n.type==="esm"&&(r.esm=!0)):(/\.d\.[mc]?ts$/.test(n.file)&&s.options.declaration!==!1&&(r.declaration=s.options.declaration),n.type==="cjs"?r.cjs=!0:n.type==="esm"&&(r.esm=!0));const l=n.file.replace(Me(n.file),"").replace(new RegExp(`^./${s.options.outDir.replace(/^\.\//,"")}/`),"");Ke.has(n.subKey)&&!t.includes(l)&&(r.fileAlias=l)},"createOrUpdateEntry");let Vt=!1;const Kt=ot(e=>{if(e.pkg?.dependencies?.typescript===void 0&&e.pkg?.devDependencies?.typescript===void 0)throw new Error("You tried to use a `.ts`, `.cts` or `.mts` file but `typescript` was not found in your package.json.")},"validateIfTypescriptIsInstalled"),wa=ot((e,t,i)=>{const o=[],n=(i.options.outputExtensionMap?.cjs??"cjs").replaceAll(".",String.raw`\.`),s=(i.options.outputExtensionMap?.esm??"mjs").replaceAll(".",String.raw`\.`);t.sort((r,l)=>r.split("/").length-l.split("/").length);const a=e.type==="module"?"esm":"cjs";a==="esm"&&(i.options.emitESM=!0),a==="cjs"&&(i.options.emitCJS=!0);const c=Mt(e.exports,a,i.options.declaration);if(e.bin){const r=(typeof e.bin=="string"?[e.bin]:Object.values(e.bin)).filter(Boolean);for(const l of r){const u=Ge(l);if(u&&u!==a)throw new Error(`Exported file "${l}" has an extension that does not match the package.json type "${e.type??"commonjs"}".`);c.push({file:l,isExecutable:!0,key:"bin",type:u??a})}}e.main&&c.push({file:e.main,key:"main",type:Ge(e.main)??a}),e.module&&c.push({file:e.module,key:"module",type:"esm"}),(e.types||e.typings)&&(Kt(i),i.options.declaration===void 0&&(i.options.declaration="compatible"),c.push({file:e.types??e.typings,key:"types"}));const p=[];for(const r of c){const l=Me(r.file);if(l!==""&&!it.includes(l))continue;i.options.declaration===void 0&&(r.key==="types"||r.subKey==="types")&&(i.options.declaration=r.file.includes(".d.ts")?"compatible":!0),i.options.emitCJS===void 0&&r.type==="cjs"&&(i.options.emitCJS=!0),i.options.emitESM===void 0&&r.type==="esm"&&(i.options.emitESM=!0);const u=r.file.replace(new RegExp(String.raw`(?:\*[^/\\]|\.d\.[mc]?ts|\.\w+|${[`\\.${n}`,`\\.${s}`].join("|")})$`),""),d=u.endsWith("/");if(d&&["./","/"].includes(u))continue;const m=u.replace(new RegExp(`(./)?${i.options.outDir}`),i.options.sourceDir).replace("./",""),g="(?<=/|$)",v=d?"":String.raw`(\.d\.[cm]?ts|(\.[cm]?[tj]sx?)|${[`\\.${n}`,`\\.${s}`].join("|")})$`;if(r.file.includes("/*")&&r.key==="exports"){Vt||(i.logger.debug("Private subfolders are not supported, if you need this feature please open an issue on GitHub."),Vt=!0);const w=[],b=new RegExp(g+m.replace("*","(.*)")+v),$=new RegExp(g+m.replace(/(.*)\.[^.]*$/,"$1").replace("*","(.*)")+v);for(const k of t)(b.test(k)||Ke.has(r.subKey)&&$.test(k))&&w.push(k);if(w.length===0){o.push(`Could not find entrypoint for \`${r.file}\``);continue}for(const k of w)Fe(p,k,d,u,r,i,!0);continue}const x=new RegExp(g+m+v);let f=t.find(w=>x.test(w));if(Ke.has(r.subKey)&&f===void 0){const w=m.replace(/^(.+?)\.[^.]*$/,"$1"),b=new RegExp(g+w+v);f=t.find($=>b.test($))}if(f===void 0){J(O(i.options.rootDir,r.file))||o.push(`Could not find entrypoint for \`${r.file}\``);continue}J(f)&&/\.[cm]?tsx?$/.test(f)&&Kt(i);const y=ve(f.replace(ae,""));J(`${y}.cts`)&&J(`${y}.mts`)?(Fe(p,`${y}.cts`,d,u,{...r,type:"cjs"},i,!1),Fe(p,`${y}.mts`,d,u,{...r,type:"esm"},i,!1)):Fe(p,f,d,u,r,i,!1)}return{entries:p,warnings:o}},"inferEntries");var $a=Object.defineProperty,ka=h((e,t)=>$a(e,"name",{value:t,configurable:!0}),"o$g");const ja=ka((e,t)=>{const{publishConfig:i}=e;return i&&(i.bin&&(typeof i.bin=="object"||typeof i.bin=="string")&&(e.bin=i.bin),i.type&&typeof i.type=="string"&&i.type!==""&&(e.type=i.type),i.main&&typeof i.main=="string"&&i.main!==""&&(e.main=i.main),i.module&&typeof i.module=="string"&&i.module!==""&&(e.module=i.module),t===void 0&&i.types&&typeof i.types=="string"&&i.types!==""?e.types=i.types:t===void 0&&i.typings&&typeof i.typings=="string"&&i.typings!==""&&(e.typings=i.typings),i.exports&&typeof i.exports=="object"&&(e.exports=i.exports)),e},"overwriteWithPublishConfig");var Ea=Object.defineProperty,Sa=h((e,t)=>Ea(e,"name",{value:t,configurable:!0}),"t$c");const Oa={hooks:{"build:prepare":Sa(function(e){if(e.options.entries.length>0)return;const t=j(e.options.rootDir,e.options.sourceDir);if(!J(t))throw new Error("No 'src' directory found. Please provide entries manually.");const i=Go(t,{extensions:[],includeDirs:!1,includeSymlinks:!1,skip:[/.*\/node_modules\/.*/,/.*\/dist\/.*/]});if(i.length===0)throw new Error("No source files found in 'src' directory. Please provide entries manually.");let o={...e.pkg};o.publishConfig&&(e.logger.info(`Using publishConfig found in package.json, to override the default key-value pairs of "${Object.keys(o.publishConfig).join(", ")}".`),e.logger.debug(o.publishConfig),o=ja(o,e.options.declaration));const n=wa(o,i,e);for(const s of n.warnings)E(e,s);if(e.options.entries.push(...n.entries),e.options.entries.length===0)throw new Error("No entries detected. Please provide entries manually.");e.logger.info("Automatically detected entries:",C(e.options.entries.map(s=>s.fileAlias?`${K(s.fileAlias)} => ${K(s.input.replace(`${e.options.rootDir}/`,"").replace(/\/$/,"/*"))}`:K(s.input.replace(`${e.options.rootDir}/`,"").replace(/\/$/,"/*"))).join(", ")),Z([e.options.emitESM&&"esm",e.options.emitCJS&&"cjs",e.options.declaration&&"dts"].filter(Boolean).map(s=>`[${s}]`).join(" ")))},"build:prepare")}};var Pa=Object.defineProperty,Da=h((e,t)=>Pa(e,"name",{value:t,configurable:!0}),"t$b");const Ca=Da(async(e,t)=>{if(e==="auto")e=Oa;else{if(e==="none")return{};typeof e=="string"&&(e=await t.import(e)||{})}return typeof e=="function"&&(e=e()),e},"loadPreset");var Na=Object.defineProperty,Ma=h((e,t)=>Na(e,"name",{value:t,configurable:!0}),"s$h");const Ki=Ma(e=>{const t=j(e,"package.json");if(!J(t))throw new Error(`package.json not found at ${t}`);const i=zi(t);return i.publishConfig&&Object.assign(i,i.publishConfig),{packageJson:i,packageJsonPath:t}},"loadPackageJson");var Ia=Object.defineProperty,_a=h((e,t)=>Ia(e,"name",{value:t,configurable:!0}),"a$s");const Ta=_a(async(e,t,i,o)=>{let n;if(o){const s=j(e,o);if(!await Ze(s))throw new Error(`tsconfig.json not found at ${s}`);n={config:pn(s),path:s},i.info("Using tsconfig settings at",s)}else if(_i(t,["typescript"]))try{n=await cn(e),i.debug("Using tsconfig settings found at",n.path)}catch{i.info("No tsconfig.json or jsconfig.json found.")}return n},"loadTsconfig");var za=Object.defineProperty,Gi=h((e,t)=>za(e,"name",{value:t,configurable:!0}),"r$h");const Gt=Gi(async(e,t)=>{if(typeof e.name!="string"){let i=Ie(e.input)?A(t.options.rootDir,e.input):G(e.input);i.startsWith("./")&&(i=i.slice(2)),e.name=i.replace(new RegExp(`^${t.options.sourceDir}/`),"").replace(ae,"")}if(!e.input)throw new Error(`Missing entry input: ${JSON.stringify(e)}`);Pt(e.input)&&(e.input=O(t.options.rootDir,e.input)),t.options.declaration&&e.declaration===void 0&&(e.declaration=t.options.declaration),e.executable&&(e.cjs===void 0||e.esm===void 0)?t.pkg.type==="commonjs"&&e.cjs===void 0&&t.options.emitCJS!==void 0?(e.cjs=t.options.emitCJS,e.esm=!1):t.pkg.type==="module"&&e.esm===void 0&&t.options.emitESM!==void 0&&(e.esm=t.options.emitESM,e.cjs=!1):e.cjs===void 0&&e.esm===void 0&&(t.options.emitCJS!==void 0&&(e.cjs=t.options.emitCJS),t.options.emitESM!==void 0&&(e.esm=t.options.emitESM)),e.outDir=O(t.options.rootDir,e.outDir??t.options.outDir)},"extendEntry"),Aa=Gi(async e=>{e.options.entries=e.options.entries.map(t=>typeof t=="string"?{input:t,isGlob:Bt(t)}:{...t,exportKey:t.exportKey??new Set,isGlob:Bt(t.input)});for(const t of e.options.entries.filter(i=>i.isGlob)){const{isGlob:i,...o}=t,n=["**/.git/**","**/node_modules/**","**/test-results/**"];if(e.options.rollup.watch){if(typeof e.options.rollup.watch.exclude=="string")n.push(e.options.rollup.watch.exclude);else if(Array.isArray(e.options.rollup.watch.exclude))for(const a of e.options.rollup.watch.exclude)typeof a=="string"&&n.push(a)}const s=mn([o.input],{cwd:e.options.rootDir,dot:!1,ignore:n,onlyFiles:!0});if(s.length===0)throw new dn(`No files found in the glob pattern: ${C(j(e.options.rootDir,o.input))}`);for(const a of s)e.options.entries.push({...o,input:O(e.options.rootDir,a)});e.options.entries.splice(e.options.entries.indexOf(t),1)}for(const t of e.options.entries.filter(i=>i.fileAlias===void 0))await Gt(t,e);for(const t of e.options.entries.filter(i=>i.fileAlias!==void 0))t.name=t.fileAlias,t.fileAlias=void 0,await Gt(t,e)},"prepareEntries");var Ra=Object.defineProperty,nt=h((e,t)=>Ra(e,"name",{value:t,configurable:!0}),"o$f");const He=/^#![^\n]*/,$t=nt(async e=>{await wn(e,493).catch(()=>{})},"makeExecutable"),Fa=nt((e,t)=>({name:"packem:shebang",renderChunk:{handler(i,o,n){if(!o.isEntry||!o.facadeModuleId)return;const s=i.startsWith("#")&&i[1]==="!";if(s&&t.replace)return i.replace(He,`${t.shebang}
`);if(!s&&e.includes(o.name)){const a=new z(i);return a.prepend(`${t.shebang}
`),{code:a.toString(),map:n.sourcemap?a.generateMap({hires:!0}):void 0}}},order:"post"},async writeBundle(i,o){for(const[n,s]of Object.entries(o))if(s.type==="chunk"&&He.test(s.code)&&i.dir){const a=O(i.dir,n);await $t(a)}}}),"shebangPlugin"),Ja=nt(()=>({name:"packem:remove-shebang",renderChunk(e){return e.replace(He,"")}}),"removeShebangPlugin"),La=nt((e,t=`
`)=>{const i=He.exec(e);return i?i+t:""},"getShebang");var Ba=Object.defineProperty,qa=h((e,t)=>Ba(e,"name",{value:t,configurable:!0}),"i$l");const at=qa((e,t)=>{let i={};return e.name&&(i[e.name]=t.rootDir),i={...i,...t.alias},t.rollup.alias&&(Array.isArray(t.rollup.alias.entries)?Object.assign(i,Object.fromEntries(t.rollup.alias.entries.map(o=>[o.find,o.replacement]))):Object.assign(i,t.rollup.alias.entries??t.rollup.alias)),i},"resolveAliases");var Wa=Object.defineProperty,Ua=h((e,t)=>Wa(e,"name",{value:t,configurable:!0}),"E$5");const Va=/^[_$a-z\u00A0-\uFFFF][\w$\u00A0-\uFFFF]*$/iu,Ka=Ua(async e=>{const t=e.options.jiti.transformOptions?.babel?.plugins,i=[],o=JSON.stringify({...e.options.jiti,alias:{...at(e.pkg,e.options),...e.options.jiti.alias},transformOptions:{...e.options.jiti.transformOptions,babel:{...e.options.jiti.transformOptions?.babel,plugins:"__$BABEL_PLUGINS"}}},void 0,2).replace('"__$BABEL_PLUGINS"',Array.isArray(t)?`[${t.map((n,s)=>{if(Array.isArray(n)){const[a,...c]=n;return i.push(a),`[${[`plugin${s}`,...c.map(p=>JSON.stringify(p))].join(", ")}]`}return i.push(n),`plugin${s}`}).join(",")}]`:"[]");for(const n of e.options.entries){const s=O(e.options.rootDir,e.options.outDir,n.name),a=gn(e.jiti.esmResolve(n.input,{try:!0})??n.input),c=a.replace(ae,""),p=et(a),r=La(p);let l=[];try{l=await vn(a,{extensions:it})}catch(d){E(e,`Cannot analyze ${a} for exports: ${d.toString()}`);return}const u=l.includes("default")||l.length===0;if(e.options.emitESM){const d=A(I(s),await qt("jiti",{conditions:["node","import"],url:import.meta.url})),m=`${c}.d.mts`;pe(`${s}.${e.options.outputExtensionMap?.esm??"mjs"}`,r+[`import { createJiti } from "${d}";`,...i.map((g,v)=>`import plugin${v} from "${g}";`),"",`const jiti = createJiti(import.meta.url, ${o});`,"",`/** @type {import("${m}")} */`,`const _module = await jiti.import("${a}");`,...u?["export default _module?.default ?? _module;"]:[],...l.filter(g=>g!=="default").map((g,v)=>{if(Va.test(g))return`export const ${g} = _module.${g};`;const x=`__packem_export_${v}`,f=g.startsWith("'")&&g.endsWith("'")?`_module[${g}]`:`_module[${JSON.stringify(g)}]`;return`const ${x} = ${f};
export { ${x} as ${JSON.stringify(g)} };`})].join(`
`)),e.options.declaration&&pe(`${s}.d.mts`,`export * from "${m}";
${u?`export { default } from "${m}";`:""}`)}if(e.options.emitCJS){const d=A(I(s),await qt("jiti",{conditions:["node","require"],url:import.meta.url})),m=`${c}.d.cts`;pe(`${s}.${e.options.outputExtensionMap?.cjs??"cjs"}`,r+[`const { createJiti } = require("${d}");`,...i.map((g,v)=>`const plugin${v} = require(${JSON.stringify(g)})`),"",`const jiti = createJiti(__filename, ${o});`,"",`/** @type {import("${m}")} */`,`module.exports = jiti("${a}")`].join(`
`)),e.options.declaration&&pe(`${s}.d.cts`,`export * from "${m}";
${u?`export { default } from "${m}";`:""}`)}r&&(await $t(`${s}.${e.options.outputExtensionMap?.cjs??"cjs"}`),await $t(`${s}.${e.options.outputExtensionMap?.esm??"mjs"}`))}await e.hooks.callHook("rollup:done",e)},"createStub");var Ga=Object.defineProperty,Ha=h((e,t)=>Ga(e,"name",{value:t,configurable:!0}),"t$9");const ie=Ha(e=>Sn("sha256").update(e).digest("hex"),"getHash");var Xa=Object.defineProperty,It=h((e,t)=>Xa(e,"name",{value:t,configurable:!0}),"i$j");const Ya=It(e=>{const{message:t,name:i="Error",stack:o}=e;if(!o)return;const n=`${i}: ${t}
`;return o.startsWith(n)?o.slice(n.length):o},"extractStack"),Qa=It(e=>`
${e.replaceAll(/^\n|\n$/g,"")}
`,"normalizeCodeFrame"),Hi=It(e=>{const t=Ya(e);let i=(e.plugin?`[${e.plugin}] `:"")+e.message;e.id&&(i+=`
file: ${C(e.id+(e.loc?`:${e.loc.line}:${e.loc.column}`:""))}`),e.frame&&(i+=`
${Ii(Qa(e.frame))}`),e.message=i,t!==void 0&&(e.stack=`${e.message}
${t}`)},"enhanceRollupError");var Za=Object.defineProperty,es=h((e,t)=>Za(e,"name",{value:t,configurable:!0}),"a$p");const Xe=es(e=>e==null?[]:Array.isArray(e)?e:[e],"arrayify");var ts=Object.defineProperty,Xi=h((e,t)=>ts(e,"name",{value:t,configurable:!0}),"s$e");const Yi=Xi((e,t,i)=>{const o=i??new Map;return((...n)=>{const s=t?typeof t=="function"?t(...n):t:JSON.stringify({args:n}),a=o.get(s);if(a!==void 0)return a;const c=e(...n);return o.set(s,c),c})},"memoize"),is=Xi(e=>{const t=new Map;return i=>Yi(e,i,t)},"memoizeByKey");var os=Object.defineProperty,_e=h((e,t)=>os(e,"name",{value:t,configurable:!0}),"r$g");const ns=_e(function*(e){switch(e.declaration?.type){case"ClassDeclaration":case"FunctionDeclaration":{const{id:t}=e.declaration;Ue.ok(t,"Expected class/function to have a name"),yield t.name;break}case"VariableDeclaration":{for(const t of e.declaration.declarations)for(const i of An(t.id))yield i;break}}},"exportName"),as=_e(function*(e){if(e.declaration)for(const t of ns(e))yield{exportedName:t,from:"self",type:"named"};else if(e.source)yield{bindings:e.specifiers.map(t=>({exportedName:t.exported.name,importedName:t.local.name})),from:"other",source:e.source.value,type:"named"};else for(const t of e.specifiers)yield{exportedName:t.exported.name,from:"self",type:"named"}},"parseExportNamed"),ss=_e(function*(e){e.exported?yield{exportedName:e.exported.name,from:"self",type:"named"}:yield{from:"other",source:e.source.value,type:"barrel"}},"parseExportAll"),rs=_e(function*(){yield{exportedName:"default",from:"self",type:"named"}},"parseExportDefault"),ls=_e(function*(e,t){Ue.ok(t.code!=null,`Module ${t.id} doesn't have associated code`);const i=e.parse(t.code);for(const o of i.body)switch(o.type){case"ExportAllDeclaration":{yield*ss(o);break}case"ExportDefaultDeclaration":{yield*rs();break}case"ExportNamedDeclaration":{yield*as(o);break}}},"parseExports");var ps=Object.defineProperty,Te=h((e,t)=>ps(e,"name",{value:t,configurable:!0}),"n$f");const Qi=Te(async function(e,t,i){const o=await e.resolve(t,i.id);if(Ue.ok(o,`Rollup can't resolve ${t} from ${i.id}`),o.external)return;const n=await e.load(o);return Ue.ok(n,`Rollup doesn't have a module for id ${o.id}`),n},"getImportedModule"),cs=Te(async function*(e,t,i){const o=await Qi(e,t.source,i);o&&(yield*_t(e,o))},"gatherBarrelReExports"),ds=Te(async function*(e,t,i){const o=await Qi(e,t.source,i);if(!o)return;const n=new Map(t.bindings.map(s=>[s.importedName,s]));for await(const s of _t(e,o)){const a=n.get(s.exportedName);a&&(yield{...s,exportedName:a.exportedName})}},"gatherNamedReExports"),us=Te(async function*(e,t){yield{exportedName:t.exportedName,id:e.id,sourceName:t.exportedName}},"gatherNamedSelfExports"),_t=Te(async function*(e,t){for(const i of ls(e,t))i.from==="self"?yield*us(t,i):i.type==="barrel"?yield*cs(e,i,t):yield*ds(e,i,t)},"gatherExports");var ms=Object.defineProperty,fs=h((e,t)=>ms(e,"name",{value:t,configurable:!0}),"r$f");const gs=fs(()=>({moduleParsed:{async handler(e){if(e.isEntry)for await(const t of _t(this,e))t.id!==e.id&&this.emitFile({id:t.id,name:t.exportedName,preserveSignature:"exports-only",type:"chunk"})},order:"post"},name:"packem:chunk-splitter"}),"chunkSplitter");var vs=Object.defineProperty,Ht=h((e,t)=>vs(e,"name",{value:t,configurable:!0}),"i$g");const Zi=Ht(({addDefaultProperty:e=!1,logger:t})=>({name:"packem:cjs-interop",renderChunk:Ht(async(i,o,n)=>{if(!(o.type!=="chunk"||!o.isEntry)&&n.format==="cjs"&&n.exports==="auto"){const s=/(exports(?:\['default'\]|\.default)) = (.*);/i.exec(i);if(s===null||s.length<3)return;const a=new z(i);a.replace("Object.defineProperty(exports, '__esModule', { value: true });",""),a.replaceAll(/exports\.(.*) = (.*);/g,"module.exports.$1 = $2;"),e&&a.append(`
module.exports.default = ${s[2]};`);let c=a.toString();return c=c.replace(/(?:module\.)?exports(?:\['default'\]|\.default)/i,"module.exports"),t.debug({message:`Applied CommonJS interop to entry chunk ${o.fileName}.`,prefix:"plugin:cjs-interop"}),{code:c,map:a.generateMap({hires:!0})}}},"renderChunk")}),"cjsInteropPlugin");var hs=Object.defineProperty,xs=h((e,t)=>hs(e,"name",{value:t,configurable:!0}),"f$c");const ys=xs((e,t)=>{const i=new Map,o={copyOnce:!0,exactFileNames:!0,flatten:!1,...e};let{targets:n}=o;return Array.isArray(n)?n=n.map(s=>{if(typeof s=="string")return{src:s};if(typeof s=="object"&&"src"in s)return s}).filter(Boolean):typeof n=="string"&&(n=[{src:n}]),{async buildStart(){const s=await Promise.all(n.flatMap(a=>Array.isArray(a.src)?a.src.map(c=>({...a,src:c})):a).map(async a=>await fn(Xe(a.src),{ignore:Xe(a.exclude).filter(Boolean)}).then(c=>({dest:a.dest??"",parent:Rn(a.src),src:c}))));for(const a of s)for(const c of a.src){let p;i.has(c)?p=i.get(c):(p={copied:[],dest:[],timestamp:0},i.set(c,p));const r=o.flatten?G(a.dest):j(a.dest,A(a.parent,I(c)));p.dest.includes(r)||p.dest.push(r),this.addWatchFile(c)}t.info({message:"Copying files...",prefix:"plugin:copy"}),await Promise.all([...i].map(async([a,c])=>{let p;try{const r=await Dt(a);if(!r.isFile())return;const l=r.mtime.getTime();l>c.timestamp&&(c.timestamp=l,c.copied=[]),p=await Ce(a,{buffer:!0})}catch(r){t.error({context:[r],message:`error reading file ${a}`,prefix:"plugin:copy"});return}for(const r of c.dest){if(o.copyOnce&&c.copied.includes(r))continue;const l=H(a),u=j(r,l);try{this.emitFile({[o.exactFileNames?"fileName":"name"]:u,source:p,type:"asset"}),t.debug({message:`copied ${a} → ${u}`,prefix:"plugin:copy"}),c.copied.push(r)}catch(d){t.error({context:[d],message:`error copying file ${a} → ${u}`,prefix:"plugin:copy"})}}}))},name:"packem:copy"}},"copyPlugin");function eo(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}h(eo,"getDefaultExportFromCjs");var dt={exports:{}},Xt;function bs(){return Xt||(Xt=1,(function(e){var t=Object.defineProperty,i=h((l,u)=>t(l,"name",{value:u,configurable:!0}),"c"),o=Object.prototype.hasOwnProperty,n="~";function s(){}h(s,"Events"),i(s,"Events"),Object.create&&(s.prototype=Object.create(null),new s().__proto__||(n=!1));function a(l,u,d){this.fn=l,this.context=u,this.once=d||!1}h(a,"EE"),i(a,"EE");function c(l,u,d,m,g){if(typeof d!="function")throw new TypeError("The listener must be a function");var v=new a(d,m||l,g),x=n?n+u:u;return l._events[x]?l._events[x].fn?l._events[x]=[l._events[x],v]:l._events[x].push(v):(l._events[x]=v,l._eventsCount++),l}h(c,"addListener"),i(c,"addListener");function p(l,u){--l._eventsCount===0?l._events=new s:delete l._events[u]}h(p,"clearEvent"),i(p,"clearEvent");function r(){this._events=new s,this._eventsCount=0}h(r,"EventEmitter"),i(r,"EventEmitter"),r.prototype.eventNames=i(function(){var l=[],u,d;if(this._eventsCount===0)return l;for(d in u=this._events)o.call(u,d)&&l.push(n?d.slice(1):d);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(u)):l},"eventNames"),r.prototype.listeners=i(function(l){var u=n?n+l:l,d=this._events[u];if(!d)return[];if(d.fn)return[d.fn];for(var m=0,g=d.length,v=new Array(g);m<g;m++)v[m]=d[m].fn;return v},"listeners"),r.prototype.listenerCount=i(function(l){var u=n?n+l:l,d=this._events[u];return d?d.fn?1:d.length:0},"listenerCount"),r.prototype.emit=i(function(l,u,d,m,g,v){var x=n?n+l:l;if(!this._events[x])return!1;var f=this._events[x],y=arguments.length,w,b;if(f.fn){switch(f.once&&this.removeListener(l,f.fn,void 0,!0),y){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,u),!0;case 3:return f.fn.call(f.context,u,d),!0;case 4:return f.fn.call(f.context,u,d,m),!0;case 5:return f.fn.call(f.context,u,d,m,g),!0;case 6:return f.fn.call(f.context,u,d,m,g,v),!0}for(b=1,w=new Array(y-1);b<y;b++)w[b-1]=arguments[b];f.fn.apply(f.context,w)}else{var $=f.length,k;for(b=0;b<$;b++)switch(f[b].once&&this.removeListener(l,f[b].fn,void 0,!0),y){case 1:f[b].fn.call(f[b].context);break;case 2:f[b].fn.call(f[b].context,u);break;case 3:f[b].fn.call(f[b].context,u,d);break;case 4:f[b].fn.call(f[b].context,u,d,m);break;default:if(!w)for(k=1,w=new Array(y-1);k<y;k++)w[k-1]=arguments[k];f[b].fn.apply(f[b].context,w)}}return!0},"emit"),r.prototype.on=i(function(l,u,d){return c(this,l,u,d,!1)},"on"),r.prototype.once=i(function(l,u,d){return c(this,l,u,d,!0)},"once"),r.prototype.removeListener=i(function(l,u,d,m){var g=n?n+l:l;if(!this._events[g])return this;if(!u)return p(this,g),this;var v=this._events[g];if(v.fn)v.fn===u&&(!m||v.once)&&(!d||v.context===d)&&p(this,g);else{for(var x=0,f=[],y=v.length;x<y;x++)(v[x].fn!==u||m&&!v[x].once||d&&v[x].context!==d)&&f.push(v[x]);f.length?this._events[g]=f.length===1?f[0]:f:p(this,g)}return this},"removeListener"),r.prototype.removeAllListeners=i(function(l){var u;return l?(u=n?n+l:l,this._events[u]&&p(this,u)):(this._events=new s,this._eventsCount=0),this},"removeAllListeners"),r.prototype.off=r.prototype.removeListener,r.prototype.addListener=r.prototype.on,r.prefixed=n,r.EventEmitter=r,e.exports=r})(dt)),dt.exports}h(bs,"requireEventemitter3");var ws=bs();const $s=eo(ws);var ks=Object.defineProperty,he=h((e,t)=>ks(e,"name",{value:t,configurable:!0}),"o$c");class to extends Error{static{h(this,"TimeoutError")}static{he(this,"TimeoutError")}constructor(t){super(t),this.name="TimeoutError"}}class js extends Error{static{h(this,"AbortError")}static{he(this,"AbortError")}constructor(t){super(),this.name="AbortError",this.message=t}}const Yt=he(e=>globalThis.DOMException===void 0?new js(e):new DOMException(e),"getDOMException"),Qt=he(e=>{const t=e.reason===void 0?Yt("This operation was aborted."):e.reason;return t instanceof Error?t:Yt(t)},"getAbortedReason");function io(e,t){const{milliseconds:i,fallback:o,message:n,customTimers:s={setTimeout,clearTimeout}}=t;let a,c;const p=new Promise((r,l)=>{if(typeof i!="number"||Math.sign(i)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${i}\``);if(t.signal){const{signal:d}=t;d.aborted&&l(Qt(d)),c=he(()=>{l(Qt(d))},"abortHandler"),d.addEventListener("abort",c,{once:!0})}if(i===Number.POSITIVE_INFINITY){e.then(r,l);return}const u=new to;a=s.setTimeout.call(void 0,()=>{if(o){try{r(o())}catch(d){l(d)}return}typeof e.cancel=="function"&&e.cancel(),n===!1?r():n instanceof Error?l(n):(u.message=n??`Promise timed out after ${i} milliseconds`,l(u))},i),(async()=>{try{r(await e)}catch(d){l(d)}})()}).finally(()=>{p.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return p.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},p}h(io,"p$b");he(io,"pTimeout");var Es=Object.defineProperty,Ss=h((e,t)=>Es(e,"name",{value:t,configurable:!0}),"i$f");function oo(e,t,i){let o=0,n=e.length;for(;n>0;){const s=Math.trunc(n/2);let a=o+s;i(e[a],t)<=0?(o=++a,n-=s+1):n=s}return o}h(oo,"r$e");Ss(oo,"lowerBound");var Os=Object.defineProperty,Ps=h((e,t)=>Os(e,"name",{value:t,configurable:!0}),"n$d");let Ds=class{static{h(this,"y")}static{Ps(this,"PriorityQueue")}#e=[];enqueue(t,i){i={priority:0,...i};const o={priority:i.priority,id:i.id,run:t};if(this.size===0||this.#e[this.size-1].priority>=i.priority){this.#e.push(o);return}const n=oo(this.#e,o,(s,a)=>a.priority-s.priority);this.#e.splice(n,0,o)}setPriority(t,i){const o=this.#e.findIndex(s=>s.id===t);if(o===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);const[n]=this.#e.splice(o,1);this.enqueue(n.run,{priority:i,id:t})}dequeue(){return this.#e.shift()?.run}filter(t){return this.#e.filter(i=>i.priority===t.priority).map(i=>i.run)}get size(){return this.#e.length}};var Cs=Object.defineProperty,Zt=h((e,t)=>Cs(e,"name",{value:t,configurable:!0}),"n$c");let Ns=class extends $s{static{h(this,"d")}static{Zt(this,"PQueue")}#e;#i;#a=0;#s;#r;#f=0;#o;#p;#t;#g;#n=0;#c;#l;#v;#y=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Ds,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#e=t.carryoverConcurrencyCount,this.#i=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#s=t.intervalCap,this.#r=t.interval,this.#t=new t.queueClass,this.#g=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#v=t.throwOnTimeout===!0,this.#l=t.autoStart===!1}get#b(){return this.#i||this.#a<this.#s}get#w(){return this.#n<this.#c}#$(){this.#n--,this.#d(),this.emit("next")}#k(){this.#x(),this.#h(),this.#p=void 0}get#j(){const t=Date.now();if(this.#o===void 0){const i=this.#f-t;if(i<0)this.#a=this.#e?this.#n:0;else return this.#p===void 0&&(this.#p=setTimeout(()=>{this.#k()},i)),!0}return!1}#d(){if(this.#t.size===0)return this.#o&&clearInterval(this.#o),this.#o=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#l){const t=!this.#j;if(this.#b&&this.#w){const i=this.#t.dequeue();return i?(this.emit("active"),i(),t&&this.#h(),!0):!1}}return!1}#h(){this.#i||this.#o!==void 0||(this.#o=setInterval(()=>{this.#x()},this.#r),this.#f=Date.now()+this.#r)}#x(){this.#a===0&&this.#n===0&&this.#o&&(clearInterval(this.#o),this.#o=void 0),this.#a=this.#e?this.#n:0,this.#u()}#u(){for(;this.#d(););}get concurrency(){return this.#c}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#c=t,this.#u()}async#E(t){return new Promise((i,o)=>{t.addEventListener("abort",()=>{o(t.reason)},{once:!0})})}setPriority(t,i){this.#t.setPriority(t,i)}async add(t,i={}){return i.id??=(this.#y++).toString(),i={timeout:this.timeout,throwOnTimeout:this.#v,...i},new Promise((o,n)=>{this.#t.enqueue(async()=>{this.#n++,this.#a++;try{i.signal?.throwIfAborted();let s=t({signal:i.signal});i.timeout&&(s=io(Promise.resolve(s),{milliseconds:i.timeout})),i.signal&&(s=Promise.race([s,this.#E(i.signal)]));const a=await s;o(a),this.emit("completed",a)}catch(s){if(s instanceof to&&!i.throwOnTimeout){o();return}n(s),this.emit("error",s)}finally{this.#$()}},i),this.emit("add"),this.#d()})}async addAll(t,i){return Promise.all(t.map(async o=>this.add(o,i)))}start(){return this.#l?(this.#l=!1,this.#u(),this):this}pause(){this.#l=!0}clear(){this.#t=new this.#g}async onEmpty(){this.#t.size!==0&&await this.#m("empty")}async onSizeLessThan(t){this.#t.size<t||await this.#m("next",()=>this.#t.size<t)}async onIdle(){this.#n===0&&this.#t.size===0||await this.#m("idle")}async#m(t,i){return new Promise(o=>{const n=Zt(()=>{i&&!i()||(this.off(t,n),o())},"listener");this.on(t,n)})}get size(){return this.#t.size}sizeBy(t){return this.#t.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#l}};var Ms=Object.defineProperty,Is=h((e,t)=>Ms(e,"name",{value:t,configurable:!0}),"r$d");const ei=Is((e,t)=>{if(!t)return!1;if(typeof t=="function")return t(e);if(typeof t.test=="function")return t.test(e);throw new Error("Invalid condition type")},"matchFile");var _s=Object.defineProperty,Ts=h((e,t)=>_s(e,"name",{value:t,configurable:!0}),"a$o");const zs=4,As=process.env.UV_THREADPOOL_SIZE?Number.parseInt(process.env.UV_THREADPOOL_SIZE,10):zs;let Rs=class{static{h(this,"f")}static{Ts(this,"LoaderManager")}test;loaders=new Map;options;workQueue;logger;constructor({extensions:t,loaders:i,logger:o,options:n}){this.test=s=>t.some(a=>s.toLowerCase().endsWith(a)),i.length>0&&this.add(...i),this.options=n,this.logger=o}add(...t){for(const i of t)this.loaders.has(i.name)||this.loaders.set(i.name,i)}isSupported(t){if(this.test(t))return!0;for(const[,i]of this.loaders)if(ei(t,i.test))return!0;return!1}async process(t,i){this.workQueue||(this.workQueue=new Ns({concurrency:As-1}));for await(const[o,n]of this.loaders){const s={...i,options:this.options[o]??{}};if(n.alwaysProcess||ei(s.id,n.test)){this.logger.debug(`Processing ${o} loader for ${s.id}`);const a=await this.workQueue.add(n.process.bind(s,t));a&&(t=a)}}return t}};const Fs=/data:[^\n\r;]+(?:;charset=[^\n\r;]+)?;base64,([\d+/A-Za-z]+={0,2})/;var Js=Object.defineProperty,st=h((e,t)=>Js(e,"name",{value:t,configurable:!0}),"i$e");const no=/(?:\n|\r\n)?\/\*[#*@]+\s*sourceMappingURL\s*=\s*(\S+)\s*\*+\//g,ao=/(?:\n|\r\n)?\/\/[#@]+\s*sourceMappingURL\s*=\s*(\S+)\s*?$/gm;let Ls=class{static{h(this,"S")}static{st(this,"MapModifier")}map;constructor(t){if(typeof t=="string")try{this.map=JSON.parse(t)}catch{}else this.map=t}modify(t){return this.map?(t(this.map),this):this}modifySources(t){return this.map?(this.map.sources&&(this.map.sources=this.map.sources.map(i=>t(i))),this):this}resolve(t=process.cwd()){return this.modifySources(i=>i==="<no source>"?i:O(t,i))}relative(t=process.cwd()){return this.modifySources(i=>i==="<no source>"?i:Ie(i)?A(t,i):G(i))}toObject(){return this.map}toString(){return this.map?JSON.stringify(this.map):this.map}toConsumer(){return this.map?new Fn(this.map):this.map}toCommentData(){const t=this.toString();return t?`
/*# sourceMappingURL=data:application/json;base64,${Buffer.from(t).toString("base64")} */`:""}toCommentFile(t){return this.map?`
/*# sourceMappingURL=${t} */`:""}};st(async(e,t)=>{const[,i]=no.exec(e)??ao.exec(e)??[];if(!i)return;const[,o]=Fs.exec(i)??[];if(o)return Buffer.from(o,"base64").toString();if(!t)throw new Error("Extracted map detected, but no ID is provided");const n=O(I(t),i);if(J(n))return et(n)},"getMap");st(e=>e.replaceAll(no,"").replaceAll(ao,""),"stripMap");const kt=st(e=>new Ls(e),"mm");var Bs=Object.defineProperty,qs=h((e,t)=>Bs(e,"name",{value:t,configurable:!0}),"u$b");const Ws=qs(async e=>{const t=new Jn({file:""}),i=[];let o=0;for await(const{css:n,map:s}of e){i.push(n);const a=kt(s),c=a.toObject();if(!c)continue;const p=a.toConsumer();if(p){if(p.eachMapping(r=>{t.addMapping({generated:{column:r.generatedColumn,line:o+r.generatedLine},name:r.name,original:{column:r.originalColumn,line:r.originalLine},source:r.source})}),c.sourcesContent)for(const r of c.sources)t.setSourceContent(r,p.sourceContentFor(r,!0));o+=n.split(`
`).length}}return{css:i.join(`
`),map:t}},"concat");var Us=Object.defineProperty,Vs=h((e,t)=>Us(e,"name",{value:t,configurable:!0}),"s$c");const so=Vs(e=>e.map((t,i,o)=>{const n=`\`${t}\``;switch(i){case o.length-1:return`or ${n}`;case o.length-2:return n;default:return`${n},`}}).join(" "),"default");var Ks=Object.defineProperty,Gs=h((e,t)=>Ks(e,"name",{value:t,configurable:!0}),"l$f");const Hs=I(Li(import.meta.url)),ti=Gs((e,t)=>{const i={baseDirs:[Hs],caller:"Resolver",extensions:[".mjs",".js",".cjs",".json"],symlinks:!0,...t},o=new Bi({extensions:i.extensions,symlinks:i.symlinks});for(const n of i.baseDirs)for(const s of e)try{const{error:a,path:c}=o.sync(n,s);if(c)return c;a&&console.debug(a,{context:[{basedir:n,caller:t.caller,extensions:t.extensions,id:s}]})}catch(a){console.debug(a.message,{context:[{basedir:n,caller:t.caller,error:a,extensions:t.extensions,id:s}]})}throw new Error(`${i.caller} could not resolve ${so(e)}`)},"resolve");var Xs=Object.defineProperty,Ys=h((e,t)=>Xs(e,"name",{value:t,configurable:!0}),"o$9");const re={},Qs=[".js",".mjs",".cjs",".json"],Zs=Ys(async(e,t)=>{if(re[e])return re[e];if(re[e]===null)return;const i={baseDirs:[t],caller:"Module loader",extensions:Qs,symlinks:!1};try{re[e]=require(ti([e,`./${e}`],i))}catch(n){if(n.code==="ERR_REQUIRE_ESM")try{re[e]=hn(await xn(ti([e,`./${e}`],i)))}catch{}else{re[e]=null;return}}const o=re[e];return o?.default??o},"loadModule");var er=Object.defineProperty,xe=h((e,t)=>er(e,"name",{value:t,configurable:!0}),"r$c");const ro=["inject","extract","emit"],tr=so(ro),ir=xe(e=>{const t=Array.isArray(e)?e:[e];if(t[0]&&!ro.includes(t[0]))throw new Error(`Incorrect mode provided, allowed modes are ${tr}`);return{emit:t[0]==="emit",extract:t[0]==="extract"&&(t[1]??!0),inject:(!t[0]||t[0]==="inject")&&(t[1]??!0)}},"inferModeOption"),jt=xe((e,t)=>typeof e=="boolean"?e&&{}:typeof e=="object"?e:t,"inferOption"),or=xe(e=>{const t=Array.isArray(e)?e:[e];return t[0]?{content:!0,...t[1],inline:t[0]==="inline"}:!1},"inferSourceMapOption"),ii=xe((e,t)=>{const i=jt(e,{});return t&&typeof i=="object"&&!i.alias&&(i.alias=t),i},"inferHandlerOption"),ge=xe(async(e,t,i)=>{if(typeof e!="string")return e;const o=await Zs(e,i);if(!o)throw new Error(`Unable to load PostCSS ${t} \`${e}\``);return o},"ensurePCSSOption"),nr=xe(async(e,t)=>{if(e===void 0)return[];if(e.length===0)return[];const i=[];for await(const o of e.filter(Boolean)){if(!Array.isArray(o)){i.push(await ge(o,"plugin",t));continue}const[n,s]=o;s?i.push((await ge(n,"plugin",t))(s)):i.push(await ge(n,"plugin",t))}return i},"ensurePCSSPlugins");var ar=Object.defineProperty,Ee=h((e,t)=>ar(e,"name",{value:t,configurable:!0}),"b$3");const sr=Ee(async(e,t)=>e.sort((i,o)=>t.indexOf(i.name)-t.indexOf(o.name)),"sortByNameOrder"),rr=Ee(async(e,t,i,o,n,s,a,c,p,r)=>{const l={...r,...e.alias},u=X(e.include,e.exclude),d=or(e.sourceMap),m={...ir(e.mode),autoModules:e.autoModules??!1,dts:e.dts,extensions:e.extensions,namedExports:e.namedExports};typeof m.inject=="object"&&m.inject.treeshakeable&&(m.namedExports=!1,t.info({message:"Disabling named exports due to `inject.treeshakeable` option",prefix:"css"}));let g=!1;if(e.loaders)for(const y of e.loaders)y.name==="postcss"&&(g=!0);else e.loaders=[];g&&(m.postcss={...e.postcss,config:jt(e.postcss?.config,{}),import:ii(e.postcss?.import,l),modules:jt(e.postcss?.modules,void 0),to:e.postcss?.to,url:ii(e.postcss?.url,l)},e.postcss?.parser&&(m.postcss.parser=await ge(e.postcss.parser,"parser",o)),e.postcss?.syntax&&(m.postcss.syntax=await ge(e.postcss.syntax,"syntax",o)),e.postcss?.stringifier&&(m.postcss.stringifier=await ge(e.postcss.stringifier,"stringifier",o)),e.postcss?.plugins&&(m.postcss.plugins=await nr(e.postcss.plugins,o)));const v=new Rs({extensions:m.extensions,loaders:await sr(e.loaders,["sourcemap","stylus","less","sass","postcss"]),logger:t,options:{...e,...m,alias:l}});let x=[];const f=Ee((y,w)=>{const b=[];for(const $ of Object.keys(y)){const k=new Set;let S=[$];do{const N=[];for(const M of S){if(k.has(M))continue;if(v.isSupported(M)){u(M)&&N.push(M);continue}k.add(M);const Y=w(M);Y&&N.push(...Y.importedIds)}S=N}while(S.some(N=>!v.isSupported(N)));b.push(...S)}return b},"traverseImportedModules");return{augmentChunkHash(y){if(x.length===0)return;const w=f(y.modules,this.getModuleInfo),b=x.filter($=>w.includes($.id)).sort(($,k)=>w.lastIndexOf($.id)-w.lastIndexOf(k.id)).map($=>`${H($.id)}:${$.css}`);if(b.length!==0)return b.join(":")},async generateBundle(y,w){if(x.length===0||!(y.dir||y.file))return;const b=Object.values(w),$=y.dir??I(y.file),k=b.filter(D=>D.type==="chunk"),S=k.filter(D=>!D.facadeModuleId),N=y.preserveModules?k:k.filter(D=>D.isEntry||D.isDynamicEntry),M=[],Y=Ee(async(D,_)=>{const P=typeof m.extract=="string"?G(m.extract).replace(/^\.[/\\]/,""):G(`${D}.css`);Ie(P)&&this.error(["Extraction path must be relative to the output directory,",`which is ${A(o,$)}`].join(`
`)),Pt(P)&&this.error(["Extraction path must be nested inside output directory,",`which is ${A(o,$)}`].join(`
`));const W=x.filter(U=>_.includes(U.id)).sort((U,ue)=>_.lastIndexOf(U.id)-_.lastIndexOf(ue.id)),ze=await Ws(W);return{css:ze.css,map:kt(ze.map.toString()).relative(I(O($,P))).toString(),name:P}},"getExtractedData"),Q=Ee(D=>{if(y.file)return ct(y.file).name;if(y.preserveModules){const{dir:_,name:P}=ct(D.fileName);return _?j(_,P):P}return D.name},"getName"),de=[];if(typeof m.extract=="string"){t.debug({message:`Extracting to ${m.extract}`,prefix:"css"});const D=[];for(const P of S){const W=f(P.modules,this.getModuleInfo);de.push(...W),D.push(...W)}for(const P of N)D.push(...f(P.modules,this.getModuleInfo).filter(W=>!de.includes(W)));const _=Q(k[0]);M.push([_,D])}else{t.debug({message:"Extracting to individual files",prefix:"css"});for(const D of S){const _=f(D.modules,this.getModuleInfo);if(_.length===0)continue;de.push(..._);const P=Q(D);M.push([P,_])}for(const D of N){const _=f(D.modules,this.getModuleInfo).filter(W=>!de.includes(W));if(_.length===0)continue;const P=Q(D);M.push([P,_])}}for await(const[D,_]of M){const P=await Y(D,_);if(typeof e.onExtract=="function"&&!e.onExtract(P))continue;if(p&&e.minifier){t.info({message:`Minifying ${P.name} with ${e.minifier.name}`,prefix:"css"});const{css:U,map:ue}=await e.minifier.handler.bind({browserTargets:i,warn:this.warn.bind(this)})(P,d,e[e.minifier.name]??{});P.css=U,P.map=ue}const W={fileName:P.name,name:P.name,names:[P.name],originalFileName:P.name,originalFileNames:[P.name],source:P.css,type:"asset"},ze=this.emitFile(W);if(P.map&&d){const U=this.getFileName(ze),ue=typeof y.assetFileNames=="string"?G(I(y.assetFileNames)):typeof y.assetFileNames=="function"?G(I(y.assetFileNames(W))):"assets",ye=kt(P.map).modify(T=>(T.file=H(U),T)).modifySources(T=>{if(T==="<no source>"||ue.length<=1)return T;T=`../${T}`;for(const pt of ue)pt==="/"&&(T=`../${T}`);return T});if(d.inline)ye.modify(T=>d.transform?.(T,G(j($,U)))),w[U].source+=ye.toCommentData();else{const T=`${U}.map`;ye.modify(Ro=>d.transform?.(Ro,G(j($,T)))),this.emitFile({fileName:T,source:ye.toString(),type:"asset"});const{base:pt}=ct(T);w[U].source+=ye.toCommen