'use strict'; const fs = require('node:fs'); const path = require('node:path'); const shared = require('@icestack/shared'); const extract = require('./shared/postcss-cva.8a3a518d.cjs'); const generator = require('./generator.cjs'); const pm = require('picomatch'); require('lodash'); require('postcss-selector-parser'); require('@babel/types'); require('@babel/generator'); function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; } const fs__default = /*#__PURE__*/_interopDefaultCompat(fs); const path__default = /*#__PURE__*/_interopDefaultCompat(path); const pm__default = /*#__PURE__*/_interopDefaultCompat(pm); function isArray(arg) { return Array.isArray(arg); } function ensureArray(thing) { if (isArray(thing)) return thing; if (thing == null) return []; return [thing]; } const normalizePath = function normalizePath2(filename) { return filename.split(path.win32.sep).join(path.posix.sep); }; function getMatcherString(id, resolutionBase) { if (resolutionBase === false || path.isAbsolute(id) || id.startsWith("**")) { return normalizePath(id); } const basePath = normalizePath(path.resolve(resolutionBase || "")).replaceAll(/[$()*+.?[\]^{|}-]/g, "\\$&"); return path.posix.join(basePath, normalizePath(id)); } const createFilter = function createFilter2(include, exclude, options) { const resolutionBase = options && options.resolve; const getMatcher = (id) => id instanceof RegExp ? id : { test: (what) => { const pattern = getMatcherString(id, resolutionBase); const fn = pm__default(pattern, { dot: true }); const result = fn(what); return result; } }; const includeMatchers = ensureArray(include).map((element) => getMatcher(element)); const excludeMatchers = ensureArray(exclude).map((element) => getMatcher(element)); return function result(id) { if (typeof id !== "string") return false; if (/\0/.test(id)) return false; const pathId = normalizePath(id); for (const matcher of excludeMatchers) { if (matcher.test(pathId)) return false; } for (const matcher of includeMatchers) { if (matcher.test(pathId)) return true; } return includeMatchers.length === 0; }; }; const creator = (opts) => { const { outdir, prefix, importFrom, dryRun, cwd, format, remove, exclude, include, exports } = shared.defuOverrideArray(opts, { cwd: process.cwd(), outdir: "cva", importFrom: "class-variance-authority", dryRun: false, format: "ts", remove: true, exclude: [/node_modules/], exports: { base: true, variants: true, compoundVariants: true, defaultVariants: true } }); const filter = createFilter(include, exclude); const extractPlugin = extract.creator({ prefix, process(res) { if (res) { const filename = res.meta.path; if (filename && !dryRun) { const isRelative = filename.startsWith("."); const targetFormat = res.meta.format ?? format; const { code } = generator.generateCva({ ...res, format: targetFormat, importFrom, exports }); const extname = path__default.extname(filename); if (isRelative) { if (res.file) { const filepath = path__default.resolve(path__default.dirname(res.file), filename); extract.ensureDir(path__default.dirname(filepath)); let file = filepath; if (!extname) { file = filepath + "." + targetFormat; } fs__default.writeFileSync(file, code, "utf8"); } } else { const filepath = path__default.resolve(cwd, outdir, filename); extract.ensureDir(path__default.dirname(filepath)); let file = filepath; if (!extname) { file = filepath + "." + targetFormat; } fs__default.writeFileSync(file, code, "utf8"); } } } }, remove, filter }); return { postcssPlugin: "postcss-cva", plugins: [extractPlugin] }; }; creator.postcss = true; const creator$1 = creator; module.exports = creator$1;