@windicss/plugin-utils
Advanced tools
Comparing version 1.8.8 to 1.8.9
@@ -13,3 +13,3 @@ import { FullConfig, Extractor, ExtractorResultDetailed } from 'windicss/types/interfaces'; | ||
declare const htmlTags: readonly ["html", "body", "div", "a", "abbr", "address", "area", "article", "aside", "audio", "base", "basefont", "bdo", "blink", "blockquote", "br", "button", "canvas", "caption", "center", "col", "colgroup", "command", "comment", "datalist", "dd", "del", "details", "dir", "dl", "dt", "embed", "fieldset", "figure", "b", "big", "i", "small", "tt", "font", "footer", "form", "frame", "frameset", "head", "header", "hgroup", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "isindex", "iframe", "ilayer", "img", "input", "ins", "keygen", "keygen", "label", "layer", "legend", "li", "link", "map", "mark", "marquee", "menu", "meta", "meter", "multicol", "nav", "nobr", "noembed", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "cite", "code", "dfn", "em", "kbd", "samp", "strong", "var", "plaintext", "pre", "progress", "q", "ruby", "script", "section", "select", "spacer", "span", "s", "strike", "style", "sub", "sup", "svg", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "u", "ul", "video", "wbr", "wbr", "xmp"]; | ||
declare type TagNames = (typeof htmlTags)[number]; | ||
type TagNames = (typeof htmlTags)[number]; | ||
@@ -21,4 +21,4 @@ declare function defineConfig(config: FullConfig): FullConfig; | ||
} | ||
declare type TransformerFunction = (code: string, id: string) => string | undefined | null; | ||
declare type Transformer<T extends TransformerOptions> = (options?: T) => TransformerFunction; | ||
type TransformerFunction = (code: string, id: string) => string | undefined | null; | ||
type Transformer<T extends TransformerOptions> = (options?: T) => TransformerFunction; | ||
declare function transformGroups(code: string, sourcemap?: boolean): { | ||
@@ -206,3 +206,3 @@ code: string; | ||
} | ||
declare type WindiPluginUtilsOptions = Omit<LoadConfigurationOptions, 'config' | 'configFiles'> & { | ||
type WindiPluginUtilsOptions = Omit<LoadConfigurationOptions, 'config' | 'configFiles'> & { | ||
/** | ||
@@ -262,4 +262,4 @@ * Reuse existing plugin instance | ||
declare type CompletionsResult = ReturnType<typeof generateCompletions>; | ||
declare type LayerName = 'base' | 'utilities' | 'components'; | ||
type CompletionsResult = ReturnType<typeof generateCompletions>; | ||
type LayerName = 'base' | 'utilities' | 'components'; | ||
declare const SupportedLayers: readonly ["base", "utilities", "components"]; | ||
@@ -317,3 +317,3 @@ interface LayerMeta { | ||
declare type NestedArrayable<T> = T | (T | T[])[]; | ||
type NestedArrayable<T> = T | (T | T[])[]; | ||
declare function flattenArray<T>(v: NestedArrayable<T>): T[]; | ||
@@ -320,0 +320,0 @@ declare function mergeArrays<T>(...args: (NestedArrayable<T> | undefined)[]): T[]; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __create = Object.create; | ||
@@ -37,3 +38,6 @@ var __defProp = Object.defineProperty; | ||
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
@@ -324,3 +328,3 @@ | ||
return Pug.compile(code2, { filename: id })(); | ||
} catch { | ||
} catch (e) { | ||
} | ||
@@ -390,13 +394,22 @@ }; | ||
const attributesNames = results.flatMap((v) => { | ||
var _a; | ||
return ((_a = v.attributes) == null ? void 0 : _a.names) ?? []; | ||
var _a, _b; | ||
return (_b = (_a = v.attributes) == null ? void 0 : _a.names) != null ? _b : []; | ||
}); | ||
const attributesValues = results.flatMap((v) => { | ||
var _a; | ||
return ((_a = v.attributes) == null ? void 0 : _a.values) ?? []; | ||
var _a, _b; | ||
return (_b = (_a = v.attributes) == null ? void 0 : _a.values) != null ? _b : []; | ||
}); | ||
return { | ||
tags: (0, import_utils3.uniq)(results.flatMap((v) => v.tags ?? [])), | ||
ids: (0, import_utils3.uniq)(results.flatMap((v) => v.ids ?? [])), | ||
classes: (0, import_utils3.uniq)(results.flatMap((v) => v.classes ?? [])), | ||
tags: (0, import_utils3.uniq)(results.flatMap((v) => { | ||
var _a; | ||
return (_a = v.tags) != null ? _a : []; | ||
})), | ||
ids: (0, import_utils3.uniq)(results.flatMap((v) => { | ||
var _a; | ||
return (_a = v.ids) != null ? _a : []; | ||
})), | ||
classes: (0, import_utils3.uniq)(results.flatMap((v) => { | ||
var _a; | ||
return (_a = v.classes) != null ? _a : []; | ||
})), | ||
attributes: attributesNames.length || attributesValues.length ? { | ||
@@ -418,3 +431,8 @@ names: attributesNames, | ||
const exts = (0, import_utils2.toArray)(fileExtensions); | ||
const globs = exts.length ? dirs.map((i) => import_path2.default.posix.join(i, exts.length > 1 ? `**/*.{${exts.join(",")}}` : `**/*.${exts[0]}`)) : []; | ||
const globs = exts.length ? dirs.map( | ||
(i) => import_path2.default.posix.join( | ||
i, | ||
exts.length > 1 ? `**/*.{${exts.join(",")}}` : `**/*.${exts[0]}` | ||
) | ||
) : []; | ||
globs.push("index.html"); | ||
@@ -449,26 +467,33 @@ return globs; | ||
} = options; | ||
const preflightOptions = Object.assign({ | ||
includeBase: true, | ||
includeGlobal: true, | ||
includePlugin: true, | ||
enableAll: false, | ||
includeAll: false, | ||
safelist: [], | ||
blocklist: [], | ||
alias: {} | ||
}, typeof config.preflight === "boolean" ? {} : config.preflight, typeof preflight === "boolean" ? {} : preflight); | ||
const preflightOptions = Object.assign( | ||
{ | ||
includeBase: true, | ||
includeGlobal: true, | ||
includePlugin: true, | ||
enableAll: false, | ||
includeAll: false, | ||
safelist: [], | ||
blocklist: [], | ||
alias: {} | ||
}, | ||
typeof config.preflight === "boolean" ? {} : config.preflight, | ||
typeof preflight === "boolean" ? {} : preflight | ||
); | ||
preflightOptions.includeAll = preflightOptions.includeAll || preflightOptions.enableAll; | ||
const scanOptions = Object.assign({ | ||
fileExtensions: ["html", "vue", "md", "mdx", "pug", "jsx", "tsx", "svelte", "ts", "js", "css", "postcss", "pcss"], | ||
dirs: ["src"], | ||
exclude: [], | ||
include: [], | ||
runOnStartup: true, | ||
transformers: [], | ||
extractors: [], | ||
extraTransformTargets: { | ||
css: [], | ||
detect: [] | ||
} | ||
}, typeof scan === "boolean" ? {} : scan); | ||
const scanOptions = Object.assign( | ||
{ | ||
fileExtensions: ["html", "vue", "md", "mdx", "pug", "jsx", "tsx", "svelte", "ts", "js", "css", "postcss", "pcss"], | ||
dirs: ["src"], | ||
exclude: [], | ||
include: [], | ||
runOnStartup: true, | ||
transformers: [], | ||
extractors: [], | ||
extraTransformTargets: { | ||
css: [], | ||
detect: [] | ||
} | ||
}, | ||
typeof scan === "boolean" ? {} : scan | ||
); | ||
function resolveGlob(glob) { | ||
@@ -479,9 +504,17 @@ if (glob.startsWith("!")) | ||
} | ||
scanOptions.exclude = mergeArrays((_b = config.extract) == null ? void 0 : _b.exclude, scanOptions.exclude, ((_c = config.extract) == null ? void 0 : _c.exclude) ? [] : [ | ||
"node_modules", | ||
".git", | ||
"windi.config.{ts,js}", | ||
"tailwind.config.{ts,js}" | ||
]).map(resolveGlob); | ||
scanOptions.include = mergeArrays((_d = config.extract) == null ? void 0 : _d.include, scanOptions.include, ((_e = config.extract) == null ? void 0 : _e.include) ? [] : buildGlobs(scanOptions.dirs, scanOptions.fileExtensions)).map(resolveGlob); | ||
scanOptions.exclude = mergeArrays( | ||
(_b = config.extract) == null ? void 0 : _b.exclude, | ||
scanOptions.exclude, | ||
((_c = config.extract) == null ? void 0 : _c.exclude) ? [] : [ | ||
"node_modules", | ||
".git", | ||
"windi.config.{ts,js}", | ||
"tailwind.config.{ts,js}" | ||
] | ||
).map(resolveGlob); | ||
scanOptions.include = mergeArrays( | ||
(_d = config.extract) == null ? void 0 : _d.include, | ||
scanOptions.include, | ||
((_e = config.extract) == null ? void 0 : _e.include) ? [] : buildGlobs(scanOptions.dirs, scanOptions.fileExtensions) | ||
).map(resolveGlob); | ||
scanOptions.extractors = mergeArrays(getDefaultExtractors(), (_f = config.extract) == null ? void 0 : _f.extractors); | ||
@@ -491,11 +524,23 @@ const safelist = new Set(mergeArrays(config.safelist, options.safelist).flatMap((i) => i.split(" "))); | ||
const configPreflightOptions = typeof config.preflight === "boolean" ? {} : config.preflight || {}; | ||
preflightOptions.safelist = new Set(mergeArrays(configPreflightOptions == null ? void 0 : configPreflightOptions.safelist, Array.from(preflightOptions.safelist)).flatMap((i) => i.split(" ")).map((i) => { | ||
var _a2; | ||
const match = (_a2 = i.match(/^\[(.*?)\]$/)) == null ? void 0 : _a2[1]; | ||
if (match) | ||
return `div ${match}`; | ||
return i; | ||
})); | ||
preflightOptions.blocklist = new Set(mergeArrays(configPreflightOptions == null ? void 0 : configPreflightOptions.blocklist, Array.from(preflightOptions.blocklist)).flatMap((i) => i.split(" "))); | ||
preflightOptions.alias = Object.fromEntries(Object.entries(__spreadValues(__spreadValues(__spreadValues({}, defaultAlias), configPreflightOptions.alias), preflightOptions.alias)).filter(([k, v]) => [kebabCase(k), v])); | ||
preflightOptions.safelist = new Set( | ||
mergeArrays( | ||
configPreflightOptions == null ? void 0 : configPreflightOptions.safelist, | ||
Array.from(preflightOptions.safelist) | ||
).flatMap((i) => i.split(" ")).map((i) => { | ||
var _a2; | ||
const match = (_a2 = i.match(/^\[(.*?)\]$/)) == null ? void 0 : _a2[1]; | ||
if (match) | ||
return `div ${match}`; | ||
return i; | ||
}) | ||
); | ||
preflightOptions.blocklist = new Set( | ||
mergeArrays( | ||
configPreflightOptions == null ? void 0 : configPreflightOptions.blocklist, | ||
Array.from(preflightOptions.blocklist) | ||
).flatMap((i) => i.split(" ")) | ||
); | ||
preflightOptions.alias = Object.fromEntries( | ||
Object.entries(__spreadValues(__spreadValues(__spreadValues({}, defaultAlias), configPreflightOptions.alias), preflightOptions.alias)).filter(([k, v]) => [kebabCase(k), v]) | ||
); | ||
let resolvedOptions = __spreadProps(__spreadValues({}, options), { | ||
@@ -614,8 +659,11 @@ root, | ||
debug.scanGlob("exclude", options.scanOptions.exclude); | ||
const files2 = await (0, import_fast_glob.default)(options.scanOptions.include, { | ||
cwd: options.root, | ||
ignore: options.scanOptions.exclude, | ||
onlyFiles: true, | ||
absolute: true | ||
}); | ||
const files2 = await (0, import_fast_glob.default)( | ||
options.scanOptions.include, | ||
{ | ||
cwd: options.root, | ||
ignore: options.scanOptions.exclude, | ||
onlyFiles: true, | ||
absolute: true | ||
} | ||
); | ||
files2.sort(); | ||
@@ -630,9 +678,13 @@ debug.scanGlob("files", files2); | ||
files.push(...await getFiles()); | ||
const contents = await Promise.all(files.filter((id) => isDetectTarget(id)).map(async (id) => [await import_fs.default.promises.readFile(id, "utf-8"), id])); | ||
await Promise.all(contents.map(async ([content, id]) => { | ||
if (isCssTransformTarget(id)) | ||
return transformCSS(content, id); | ||
else | ||
return extractFile(content, id, true); | ||
})); | ||
const contents = await Promise.all( | ||
files.filter((id) => isDetectTarget(id)).map(async (id) => [await import_fs.default.promises.readFile(id, "utf-8"), id]) | ||
); | ||
await Promise.all(contents.map( | ||
async ([content, id]) => { | ||
if (isCssTransformTarget(id)) | ||
return transformCSS(content, id); | ||
else | ||
return extractFile(content, id, true); | ||
} | ||
)); | ||
scanned = true; | ||
@@ -695,7 +747,7 @@ debug.scan("finished"); | ||
async function extractFile(code, id, applyTransform = true) { | ||
var _a, _b; | ||
var _a, _b, _c, _d; | ||
if (applyTransform) { | ||
code = ((_a = _transformAlias(code, false)) == null ? void 0 : _a.code) ?? code; | ||
code = (_b = (_a = _transformAlias(code, false)) == null ? void 0 : _a.code) != null ? _b : code; | ||
if (options.transformGroups) | ||
code = ((_b = transformGroups(code, false)) == null ? void 0 : _b.code) ?? code; | ||
code = (_d = (_c = transformGroups(code, false)) == null ? void 0 : _c.code) != null ? _d : code; | ||
} | ||
@@ -740,3 +792,6 @@ if (id) { | ||
if (transformOptions == null ? void 0 : transformOptions.globaliseKeyframes) { | ||
const [nonKeyframeBlocks, keyframeBlocks] = (0, import_utils2.partition)(style.children, (i) => !i.atRules || !i.atRules[0].match(/keyframes (pulse|spin|ping|bounce)/)); | ||
const [nonKeyframeBlocks, keyframeBlocks] = (0, import_utils2.partition)( | ||
style.children, | ||
(i) => !i.atRules || !i.atRules[0].match(/keyframes (pulse|spin|ping|bounce)/) | ||
); | ||
updateLayers(keyframeBlocks, "__classes", false); | ||
@@ -783,6 +838,7 @@ style.children = nonKeyframeBlocks; | ||
function buildLayerCss(name2) { | ||
var _a; | ||
const layer = layers[name2]; | ||
if (layer.cssCache == null) { | ||
const style = new import_style.StyleSheet(Array.from(layerStylesMap.values()).flatMap((i) => i).filter((i) => i.meta.type === name2)); | ||
style.prefixer = options.config.prefixer ?? true; | ||
style.prefixer = (_a = options.config.prefixer) != null ? _a : true; | ||
debug.compileLayer(name2, style.children.length); | ||
@@ -815,7 +871,17 @@ if (options.sortUtilities) | ||
if (!layerStylesMap.has("__preflights")) { | ||
const preflightStyle = processor.preflight(void 0, options.preflightOptions.includeBase, options.preflightOptions.includeGlobal, options.preflightOptions.includePlugin); | ||
const preflightStyle = processor.preflight( | ||
void 0, | ||
options.preflightOptions.includeBase, | ||
options.preflightOptions.includeGlobal, | ||
options.preflightOptions.includePlugin | ||
); | ||
updateLayers(preflightStyle.children, "__preflights", true); | ||
} | ||
} else if (tagsPending.size) { | ||
const preflightStyle = processor.preflight(Array.from(tagsPending).map((i) => `<${i}/>`).join(" "), options.preflightOptions.includeBase, options.preflightOptions.includeGlobal, options.preflightOptions.includePlugin); | ||
const preflightStyle = processor.preflight( | ||
Array.from(tagsPending).map((i) => `<${i}/>`).join(" "), | ||
options.preflightOptions.includeBase, | ||
options.preflightOptions.includeGlobal, | ||
options.preflightOptions.includePlugin | ||
); | ||
updateLayers(preflightStyle.children, "__preflights", false); | ||
@@ -832,5 +898,9 @@ include(tagsGenerated, tagsPending); | ||
attributesObject[name2] = []; | ||
attributesObject[name2].push(...String(value).split(regexClassSplitter).filter(Boolean)); | ||
attributesObject[name2].push( | ||
...String(value).split(regexClassSplitter).filter(Boolean) | ||
); | ||
}); | ||
const attributifyStyle = processor.attributify(attributesObject); | ||
const attributifyStyle = processor.attributify( | ||
attributesObject | ||
); | ||
updateLayers(attributifyStyle.styleSheet.children, "__attributify", false); | ||
@@ -837,0 +907,0 @@ attributes.length = 0; |
{ | ||
"name": "@windicss/plugin-utils", | ||
"version": "1.8.8", | ||
"version": "1.8.9", | ||
"description": "Common utils for building integrations of Windi CSS", | ||
@@ -32,9 +32,9 @@ "author": "antfu <anthonyfu117@hotmail.com>", | ||
"dependencies": { | ||
"@antfu/utils": "^0.5.2", | ||
"@windicss/config": "1.8.8", | ||
"@antfu/utils": "^0.7.2", | ||
"debug": "^4.3.4", | ||
"fast-glob": "^3.2.11", | ||
"magic-string": "^0.26.2", | ||
"fast-glob": "^3.2.12", | ||
"magic-string": "^0.27.0", | ||
"micromatch": "^4.0.5", | ||
"windicss": "^3.5.6" | ||
"windicss": "^3.5.6", | ||
"@windicss/config": "1.8.9" | ||
}, | ||
@@ -41,0 +41,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80121
2426
+ Added@antfu/utils@0.7.10(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@windicss/config@1.8.9(transitive)
+ Addedmagic-string@0.27.0(transitive)
- Removed@antfu/utils@0.5.2(transitive)
- Removed@windicss/config@1.8.8(transitive)
- Removedmagic-string@0.26.7(transitive)
- Removedsourcemap-codec@1.4.8(transitive)
Updated@antfu/utils@^0.7.2
Updated@windicss/config@1.8.9
Updatedfast-glob@^3.2.12
Updatedmagic-string@^0.27.0