@windicss/plugin-utils
Advanced tools
Comparing version 1.8.9 to 1.8.10
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __defProps = Object.defineProperties; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
var __export = (target, all) => { | ||
@@ -281,3 +264,3 @@ for (var name in all) | ||
function DefaultExtractor(code, id) { | ||
if ((id == null ? void 0 : id.endsWith(".css")) || (id == null ? void 0 : id.endsWith(".postcss"))) { | ||
if (id?.endsWith(".css") || id?.endsWith(".postcss")) { | ||
return { | ||
@@ -328,3 +311,3 @@ classes: [], | ||
return Pug.compile(code2, { filename: id })(); | ||
} catch (e) { | ||
} catch { | ||
} | ||
@@ -378,3 +361,3 @@ }; | ||
try { | ||
require("pug"); | ||
require.resolve("pug"); | ||
extractors.push({ | ||
@@ -394,23 +377,8 @@ extractor: PugExtractor, | ||
return Promise.all((matchingExtractors.length ? matchingExtractors : [defaultExtract]).map((extractor) => extractor(code, id))).then((results) => { | ||
const attributesNames = results.flatMap((v) => { | ||
var _a, _b; | ||
return (_b = (_a = v.attributes) == null ? void 0 : _a.names) != null ? _b : []; | ||
}); | ||
const attributesValues = results.flatMap((v) => { | ||
var _a, _b; | ||
return (_b = (_a = v.attributes) == null ? void 0 : _a.values) != null ? _b : []; | ||
}); | ||
const attributesNames = results.flatMap((v) => v.attributes?.names ?? []); | ||
const attributesValues = results.flatMap((v) => v.attributes?.values ?? []); | ||
return { | ||
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 : []; | ||
})), | ||
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 ?? [])), | ||
attributes: attributesNames.length || attributesValues.length ? { | ||
@@ -442,3 +410,2 @@ names: attributesNames, | ||
async function resolveOptions(options = {}, utilsOptions = {}, loadConfigFile = false) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
if (isResolvedOptions(options)) | ||
@@ -451,10 +418,10 @@ return options; | ||
const root = options.root || utilsOptions.root || process.cwd(); | ||
let { config, filepath: configFilePath } = loadConfigFile ? (0, import_config.loadConfiguration)(__spreadProps(__spreadValues({ | ||
onConfigurationError: (error) => console.error(error) | ||
}, utilsOptions), { | ||
let { config, filepath: configFilePath } = loadConfigFile ? (0, import_config.loadConfiguration)({ | ||
onConfigurationError: (error) => console.error(error), | ||
...utilsOptions, | ||
root, | ||
config: options.config, | ||
configFiles: options.configFiles | ||
})) : { config: {}, filepath: void 0 }; | ||
const modifiedConfigs = await ((_a = options.onConfigResolved) == null ? void 0 : _a.call(options, config, configFilePath)); | ||
}) : { config: {}, filepath: void 0 }; | ||
const modifiedConfigs = await options.onConfigResolved?.(config, configFilePath); | ||
if (modifiedConfigs != null) | ||
@@ -506,5 +473,5 @@ config = modifiedConfigs; | ||
scanOptions.exclude = mergeArrays( | ||
(_b = config.extract) == null ? void 0 : _b.exclude, | ||
config.extract?.exclude, | ||
scanOptions.exclude, | ||
((_c = config.extract) == null ? void 0 : _c.exclude) ? [] : [ | ||
config.extract?.exclude ? [] : [ | ||
"node_modules", | ||
@@ -517,7 +484,7 @@ ".git", | ||
scanOptions.include = mergeArrays( | ||
(_d = config.extract) == null ? void 0 : _d.include, | ||
config.extract?.include, | ||
scanOptions.include, | ||
((_e = config.extract) == null ? void 0 : _e.include) ? [] : buildGlobs(scanOptions.dirs, scanOptions.fileExtensions) | ||
config.extract?.include ? [] : buildGlobs(scanOptions.dirs, scanOptions.fileExtensions) | ||
).map(resolveGlob); | ||
scanOptions.extractors = mergeArrays(getDefaultExtractors(), (_f = config.extract) == null ? void 0 : _f.extractors); | ||
scanOptions.extractors = mergeArrays(getDefaultExtractors(), config.extract?.extractors); | ||
const safelist = new Set(mergeArrays(config.safelist, options.safelist).flatMap((i) => i.split(" "))); | ||
@@ -528,7 +495,6 @@ const blocklist = new Set(mergeArrays(config.blocklist, options.blocklist).flatMap((i) => i.split(" "))); | ||
mergeArrays( | ||
configPreflightOptions == null ? void 0 : configPreflightOptions.safelist, | ||
configPreflightOptions?.safelist, | ||
Array.from(preflightOptions.safelist) | ||
).flatMap((i) => i.split(" ")).map((i) => { | ||
var _a2; | ||
const match = (_a2 = i.match(/^\[(.*?)\]$/)) == null ? void 0 : _a2[1]; | ||
const match = i.match(/^\[(.*?)\]$/)?.[1]; | ||
if (match) | ||
@@ -541,3 +507,3 @@ return `div ${match}`; | ||
mergeArrays( | ||
configPreflightOptions == null ? void 0 : configPreflightOptions.blocklist, | ||
configPreflightOptions?.blocklist, | ||
Array.from(preflightOptions.blocklist) | ||
@@ -547,5 +513,10 @@ ).flatMap((i) => i.split(" ")) | ||
preflightOptions.alias = Object.fromEntries( | ||
Object.entries(__spreadValues(__spreadValues(__spreadValues({}, defaultAlias), configPreflightOptions.alias), preflightOptions.alias)).filter(([k, v]) => [kebabCase(k), v]) | ||
Object.entries({ | ||
...defaultAlias, | ||
...configPreflightOptions.alias, | ||
...preflightOptions.alias | ||
}).filter(([k, v]) => [kebabCase(k), v]) | ||
); | ||
let resolvedOptions = __spreadProps(__spreadValues({}, options), { | ||
let resolvedOptions = { | ||
...options, | ||
root, | ||
@@ -564,4 +535,4 @@ config, | ||
__windi_resolved: true | ||
}); | ||
const modifiedOptions = await ((_g = resolvedOptions.onOptionsResolved) == null ? void 0 : _g.call(resolvedOptions, resolvedOptions)); | ||
}; | ||
const modifiedOptions = await resolvedOptions.onOptionsResolved?.(resolvedOptions); | ||
if (modifiedOptions != null && modifiedOptions !== resolvedOptions) | ||
@@ -750,7 +721,6 @@ resolvedOptions = Object.assign(resolvedOptions, modifiedOptions); | ||
async function extractFile(code, id, applyTransform = true) { | ||
var _a, _b, _c, _d; | ||
if (applyTransform) { | ||
code = (_b = (_a = _transformAlias(code, false)) == null ? void 0 : _a.code) != null ? _b : code; | ||
code = _transformAlias(code, false)?.code ?? code; | ||
if (options.transformGroups) | ||
code = (_d = (_c = transformGroups(code, false)) == null ? void 0 : _c.code) != null ? _d : code; | ||
code = transformGroups(code, false)?.code ?? code; | ||
} | ||
@@ -772,3 +742,3 @@ if (id) { | ||
const extractedAttrs = extractResult.attributes; | ||
if (extractedAttrs == null ? void 0 : extractedAttrs.names.length) { | ||
if (extractedAttrs?.names.length) { | ||
extractedAttrs.names.forEach((name2, i) => { | ||
@@ -779,3 +749,3 @@ attributes.push([name2, extractedAttrs.values[i]]); | ||
} | ||
changed = addClasses((extractedAttrs == null ? void 0 : extractedAttrs.classes) || extractResult.classes || []) || changed; | ||
changed = addClasses(extractedAttrs?.classes || extractResult.classes || []) || changed; | ||
} else { | ||
@@ -792,7 +762,6 @@ changed = addClasses(extractResult.classes || []) || changed; | ||
function transformCSS(css, id, transformOptions) { | ||
var _a; | ||
if (!options.transformCSS) | ||
return css; | ||
const style = new import_parser.CSSParser(css, processor).parse(); | ||
if (transformOptions == null ? void 0 : transformOptions.globaliseKeyframes) { | ||
if (transformOptions?.globaliseKeyframes) { | ||
const [nonKeyframeBlocks, keyframeBlocks] = (0, import_utils2.partition)( | ||
@@ -812,3 +781,3 @@ style.children, | ||
if (layerBlocks.length) | ||
(_a = transformOptions == null ? void 0 : transformOptions.onLayerUpdated) == null ? void 0 : _a.call(transformOptions); | ||
transformOptions?.onLayerUpdated?.(); | ||
return transformed; | ||
@@ -823,3 +792,2 @@ } | ||
function updateLayers(styles, filepath, replace = true) { | ||
var _a; | ||
const timestamp = +Date.now(); | ||
@@ -830,3 +798,3 @@ debug.compileLayer("update", filepath); | ||
if (replace) { | ||
(_a = layerStylesMap.get(filepath)) == null ? void 0 : _a.forEach((i) => changedLayers.add(i.meta.type)); | ||
layerStylesMap.get(filepath)?.forEach((i) => changedLayers.add(i.meta.type)); | ||
layerStylesMap.set(filepath, styles); | ||
@@ -846,7 +814,6 @@ } else { | ||
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 = (_a = options.config.prefixer) != null ? _a : true; | ||
style.prefixer = options.config.prefixer ?? true; | ||
debug.compileLayer(name2, style.children.length); | ||
@@ -861,4 +828,3 @@ if (options.sortUtilities) | ||
function buildPendingStyles() { | ||
var _a, _b; | ||
(_a = options.onBeforeGenerate) == null ? void 0 : _a.call(options, { | ||
options.onBeforeGenerate?.({ | ||
classesPending, | ||
@@ -917,3 +883,3 @@ tagsPending | ||
} | ||
(_b = options.onGenerated) == null ? void 0 : _b.call(options, { | ||
options.onGenerated?.({ | ||
classes: classesGenerated, | ||
@@ -1025,3 +991,2 @@ tags: tagsGenerated | ||
async function _init() { | ||
var _a; | ||
options = await resolveOptions(userOptions, utilsOptions, true); | ||
@@ -1031,3 +996,3 @@ files = []; | ||
clearCache(false); | ||
(_a = options.onInitialized) == null ? void 0 : _a.call(options, utils); | ||
options.onInitialized?.(utils); | ||
_transformAlias = buildAliasTransformer(options.config.alias); | ||
@@ -1057,3 +1022,3 @@ return processor; | ||
function deepMerge(a, b, rootPath) { | ||
a = __spreadValues({}, a); | ||
a = { ...a }; | ||
Object.keys(b).forEach((key) => { | ||
@@ -1060,0 +1025,0 @@ if (isObject(a[key])) |
{ | ||
"name": "@windicss/plugin-utils", | ||
"version": "1.8.9", | ||
"version": "1.8.10", | ||
"description": "Common utils for building integrations of Windi CSS", | ||
@@ -38,3 +38,3 @@ "author": "antfu <anthonyfu117@hotmail.com>", | ||
"windicss": "^3.5.6", | ||
"@windicss/config": "1.8.9" | ||
"@windicss/config": "1.8.10" | ||
}, | ||
@@ -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
75753
2356
+ Added@windicss/config@1.8.10(transitive)
- Removed@windicss/config@1.8.9(transitive)
Updated@windicss/config@1.8.10