@windicss/plugin-utils
Advanced tools
Comparing version 0.15.7 to 0.16.0-beta.1
@@ -362,2 +362,8 @@ import * as windicss_types_interfaces from 'windicss/types/interfaces'; | ||
declare module 'windicss/types/interfaces' { | ||
interface FullConfig { | ||
attributify?: boolean; | ||
} | ||
} | ||
export { Arrayable, CompletionsResult, DefaultExtractor, LayerMeta, LayerName, LoadConfigurationOptions, NestedArrayable, PugExtractor, ResolvedOptions, SupportedLayers, TagNames, Transformer, TransformerFunction, TransformerOptions, UserOptions, WindiPluginUtils, WindiPluginUtilsOptions, applyExtractors, createUtils, defaultAlias, defaultConfigureFiles, defineConfig, exclude, flattenArray, getDefaultExtractors, htmlTags, include, isResolvedOptions, kebabCase, loadConfiguration, mergeArrays, mergeWindicssConfig, partition, preflightTags, resolveOptions, slash, toArray, transformGroups, transformGroupsWithSourcemap }; |
@@ -192,5 +192,6 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __defProp = Object.defineProperty; | ||
var regexQuotedString = /(["'`])((?:\\\1|(?:(?!\1)|\n|\r).)*?)\1/mg; | ||
var regexHtmlTag = /<(\w[\w-]*)[\S\s]*?\/?>/mg; | ||
var regexHtmlTag = /<(\w[\w-]*)([\S\s]*?)\/?>/mg; | ||
var regexClassSplitter = /[\s'"`{}]/g; | ||
var regexClassGroup = /([!\w+-<@][\w+:_/-]*?\w):\(([!\w\s:/\\,%#\[\].$-]*?)\)/gm; | ||
var regexAttributifyItem = /([\w+:_/-]+)=(['"])([!\w\s\n:/\\,%#\[\].$-]*?)\2/gm; | ||
var regexClassCheck1 = /^[!a-z\d@<>.+-](?:\([\w,.%#-]*\)|[\w:/\\,%#\[\].$-])*$/; | ||
@@ -305,7 +306,22 @@ var regexClassCheck2 = /[a-z].*[\w)\]]$/; | ||
} | ||
const classes = Array.from(code.matchAll(regexQuotedString)).flatMap((m) => (m[2] || "").split(regexClassSplitter)).filter(validClassName); | ||
const tags = Array.from(code.matchAll(regexHtmlTag)).map((i) => i[1]); | ||
const tags = Array.from(code.matchAll(regexHtmlTag)); | ||
const tagNames = tags.map((i) => i[1]); | ||
return { | ||
classes, | ||
tags | ||
tags: tagNames, | ||
get classes() { | ||
return Array.from(code.matchAll(regexQuotedString)).flatMap((m) => (m[2] || "").split(regexClassSplitter)).filter(validClassName); | ||
}, | ||
get attributes() { | ||
const attributes = { | ||
names: [], | ||
values: [] | ||
}; | ||
tags.forEach((i) => { | ||
return Array.from(i[2].matchAll(regexAttributifyItem) || []).forEach(([, name, , value]) => { | ||
attributes.names.push(name); | ||
attributes.values.push(value); | ||
}); | ||
}); | ||
return attributes; | ||
} | ||
}; | ||
@@ -547,2 +563,3 @@ } | ||
detectTag: _debug4.default.call(void 0, `${name}:detect:tag`), | ||
detectAttrs: _debug4.default.call(void 0, `${name}:detect:attrs`), | ||
compileLayer: _debug4.default.call(void 0, `${name}:compile:layer`) | ||
@@ -559,2 +576,3 @@ }; | ||
const tagsAvailable = new Set(); | ||
const attributes = []; | ||
function getCompletions() { | ||
@@ -661,3 +679,4 @@ if (!completions) | ||
} | ||
const {classes, tags} = await applyExtractors2(code, id); | ||
const extractResult = await applyExtractors2(code, id); | ||
const {classes, tags} = extractResult; | ||
let changed = false; | ||
@@ -668,5 +687,15 @@ changed = addClasses(classes || []) || changed; | ||
} | ||
if (options.config.attributify) { | ||
const extractedAttrs = extractResult.attributes; | ||
if (extractedAttrs == null ? void 0 : extractedAttrs.names.length) { | ||
extractedAttrs.names.forEach((name2, i) => { | ||
attributes.push([name2, extractedAttrs.values[i]]); | ||
}); | ||
changed = true; | ||
} | ||
} | ||
if (changed) { | ||
debug.detectClass(classesPending); | ||
debug.detectTag(tagsPending); | ||
debug.detectAttrs(attributes); | ||
} | ||
@@ -755,2 +784,15 @@ return changed; | ||
} | ||
if (options.config.attributify) { | ||
if (attributes.length) { | ||
const attributesObject = {}; | ||
attributes.forEach(([name2, value]) => { | ||
if (!attributesObject[name2]) | ||
attributesObject[name2] = []; | ||
attributesObject[name2].push(...value.split(/\s+/g).filter(Boolean)); | ||
}); | ||
const attributifyStyle = processor.attributify(attributesObject); | ||
updateLayers(attributifyStyle.styleSheet.children, "__attributify", false); | ||
attributes.length = 0; | ||
} | ||
} | ||
(_b = options.onGenerated) == null ? void 0 : _b.call(options, { | ||
@@ -757,0 +799,0 @@ classes: classesGenerated, |
{ | ||
"name": "@windicss/plugin-utils", | ||
"version": "0.15.7", | ||
"version": "0.16.0-beta.1", | ||
"description": "Common utils for building integrations of Windi CSS", | ||
@@ -31,3 +31,3 @@ "keywords": [ | ||
"sucrase": "^3.18.1", | ||
"windicss": "^2.5.14" | ||
"windicss": "^3.0.0-beta.1" | ||
}, | ||
@@ -38,6 +38,6 @@ "devDependencies": { | ||
"@types/micromatch": "^4.0.1", | ||
"@types/node": "^14.14.41", | ||
"@types/node": "^15.0.1", | ||
"@types/pug": "^2.0.4", | ||
"pug": "^3.0.2", | ||
"tsup": "^4.9.1", | ||
"tsup": "^4.10.0", | ||
"typescript": "^4.2.4" | ||
@@ -44,0 +44,0 @@ }, |
Sorry, the diff of this file is not supported yet
73210
2193
+ Addedwindicss@3.5.6(transitive)
- Removedwindicss@2.5.14(transitive)
Updatedwindicss@^3.0.0-beta.1