@unocss/preset-attributify 0.46.5 → 0.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -118,7 +118,7 @@ const strippedPrefixes = [
118
118
  ];
119
119
  const splitterRE = /[\s'"`;]+/g;
120
120
  const elementRE = /<\w(?=.*>)[\w:\.$-]*\s((?:['"`\{].*?['"`\}]|.*?)*?)>/gs;
121
- const valuedAttributeRE = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:!%-]+)(?:={?(["'])([^\2]*?)\2}?)?/g;
121
+ const valuedAttributeRE = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:!%-]+)=?(?:["]([^"]*)["]|[']([^']*)[']|[{]([^}]*)[}])?/gms;
122
122
  const defaultIgnoreAttributes = ["placeholder"];
123
123
  const extractorAttributify = (options) => {
124
124
  const ignoreAttributes = options?.ignoreAttributes ?? defaultIgnoreAttributes;
@@ -127,7 +127,8 @@ const extractorAttributify = (options) => {
127
127
  return {
128
128
  name: "attributify",
129
129
  extract({ code }) {
130
- const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, _, content]) => {
130
+ const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, ...contents]) => {
131
+ const content = contents.filter(Boolean).join("");
131
132
  if (ignoreAttributes.includes(name))
132
133
  return [];
133
134
  for (const prefix of strippedPrefixes) {
@@ -148,7 +149,8 @@ const extractorAttributify = (options) => {
148
149
  if (["class", "className"].includes(name)) {
149
150
  return content.split(splitterRE).filter(core.isValidSelector);
150
151
  } else {
151
- return content.split(splitterRE).filter(Boolean).map((v) => `[${name}~="${v}"]`);
152
+ const extractTernary = Array.from(content.matchAll(/(?:[\?:].*?)(["'])([^\1]*?)\1/gms)).map(([, , v]) => v.split(splitterRE)).flat();
153
+ return (extractTernary.length ? extractTernary : content.split(splitterRE)).filter(Boolean).map((v) => `[${name}~="${v}"]`);
152
154
  }
153
155
  });
154
156
  return new Set(result);
package/dist/index.d.ts CHANGED
@@ -50,20 +50,20 @@ declare const extractorAttributify: (options?: AttributifyOptions) => Extractor;
50
50
  declare const variantsRE: RegExp;
51
51
  declare const variantAttributify: (options?: AttributifyOptions) => VariantObject;
52
52
 
53
- declare type TwoStringsCompositionPrefix = 'm' | 'p';
54
- declare type TwoStringsCompositionSuffix = 'r' | 'b' | 'l' | 't' | 'a';
53
+ type TwoStringsCompositionPrefix = 'm' | 'p';
54
+ type TwoStringsCompositionSuffix = 'r' | 'b' | 'l' | 't' | 'a';
55
55
  /** Some words can compose with two strings to become a complete unocss rule such as ha, mr, mb */
56
- declare type TwoStringsComposition = `${TwoStringsCompositionPrefix}${TwoStringsCompositionSuffix}` | 'ha' | 'wa';
56
+ type TwoStringsComposition = `${TwoStringsCompositionPrefix}${TwoStringsCompositionSuffix}` | 'ha' | 'wa';
57
57
  /** Some words can be a complete unocss rule by itself */
58
- declare type SpecialSingleWord = 'container' | 'flex' | 'block' | 'inline' | 'block' | 'table' | 'isolate' | 'absolute' | 'relative' | 'fixed' | 'sticky' | 'static' | 'visible' | 'invisible' | 'grow' | 'shrink' | 'antialiased' | 'italic' | 'ordinal' | 'overline' | 'underline' | 'uppercase' | 'lowercase' | 'capitalize' | 'truncate' | 'border' | 'rounded' | 'outline' | 'ring' | 'shadow' | 'blur' | 'grayscale' | 'invert' | 'sepia' | 'transition' | 'resize' | 'transform' | 'filter';
59
- declare type StringNumberCompositionPrefix = 'op' | 'opacity' | 'fw' | 'p' | 'm' | 'w' | 'h' | 'z';
58
+ type SpecialSingleWord = 'container' | 'flex' | 'block' | 'inline' | 'block' | 'table' | 'isolate' | 'absolute' | 'relative' | 'fixed' | 'sticky' | 'static' | 'visible' | 'invisible' | 'grow' | 'shrink' | 'antialiased' | 'italic' | 'ordinal' | 'overline' | 'underline' | 'uppercase' | 'lowercase' | 'capitalize' | 'truncate' | 'border' | 'rounded' | 'outline' | 'ring' | 'shadow' | 'blur' | 'grayscale' | 'invert' | 'sepia' | 'transition' | 'resize' | 'transform' | 'filter';
59
+ type StringNumberCompositionPrefix = 'op' | 'opacity' | 'fw' | 'p' | 'm' | 'w' | 'h' | 'z';
60
60
  /** Some words can be a complete unocss rule by compose a string and a number, such as op80, fw300, p2, p10px */
61
- declare type StringNumberComposition = `${StringNumberCompositionPrefix}${number}${'px' | ''}`;
62
- declare type PseudoPrefix = 'active' | 'before' | 'after' | 'dark' | 'light' | 'first' | 'last' | 'focus' | 'hover' | 'link' | 'root' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'enabled' | 'disabled' | 'all' | 'children';
61
+ type StringNumberComposition = `${StringNumberCompositionPrefix}${number}${'px' | ''}`;
62
+ type PseudoPrefix = 'active' | 'before' | 'after' | 'dark' | 'light' | 'first' | 'last' | 'focus' | 'hover' | 'link' | 'root' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'enabled' | 'disabled' | 'all' | 'children';
63
63
  /** Some words can be used to separate utilities, such as font="mono light", text="sm white" */
64
- declare type SeparateEnabled = 'align' | 'animate' | 'backdrop' | 'bg' | 'blend' | 'border' | 'box' | 'container' | 'content' | 'cursor' | 'display' | 'divide' | 'filter' | 'flex' | 'font' | 'gap' | 'gradient' | 'grid' | 'h' | 'icon' | 'items' | 'justify' | 'list' | 'm' | 'opacity' | 'order' | 'outline' | 'overflow' | 'p' | 'place' | 'pos' | 'ring' | 'select' | 'shadow' | 'space' | 'table' | 'text' | 'transform' | 'transition' | 'underline' | 'w' | 'z' | PseudoPrefix;
65
- declare type BasicAttributes = StringNumberComposition | SpecialSingleWord | TwoStringsComposition | SeparateEnabled;
66
- declare type AttributifyNames<Prefix extends string = ''> = `${Prefix}${BasicAttributes}` | `${Prefix}${PseudoPrefix}:${BasicAttributes}`;
64
+ type SeparateEnabled = 'align' | 'animate' | 'backdrop' | 'bg' | 'blend' | 'border' | 'box' | 'container' | 'content' | 'cursor' | 'display' | 'divide' | 'filter' | 'flex' | 'font' | 'gap' | 'gradient' | 'grid' | 'h' | 'icon' | 'items' | 'justify' | 'list' | 'm' | 'opacity' | 'order' | 'outline' | 'overflow' | 'p' | 'place' | 'pos' | 'ring' | 'select' | 'shadow' | 'space' | 'table' | 'text' | 'transform' | 'transition' | 'underline' | 'w' | 'z' | PseudoPrefix;
65
+ type BasicAttributes = StringNumberComposition | SpecialSingleWord | TwoStringsComposition | SeparateEnabled;
66
+ type AttributifyNames<Prefix extends string = ''> = `${Prefix}${BasicAttributes}` | `${Prefix}${PseudoPrefix}:${BasicAttributes}`;
67
67
  interface AttributifyAttributes extends Partial<Record<AttributifyNames, string | boolean>> {
68
68
  }
69
69
 
package/dist/index.mjs CHANGED
@@ -114,7 +114,7 @@ const strippedPrefixes = [
114
114
  ];
115
115
  const splitterRE = /[\s'"`;]+/g;
116
116
  const elementRE = /<\w(?=.*>)[\w:\.$-]*\s((?:['"`\{].*?['"`\}]|.*?)*?)>/gs;
117
- const valuedAttributeRE = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:!%-]+)(?:={?(["'])([^\2]*?)\2}?)?/g;
117
+ const valuedAttributeRE = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:!%-]+)=?(?:["]([^"]*)["]|[']([^']*)[']|[{]([^}]*)[}])?/gms;
118
118
  const defaultIgnoreAttributes = ["placeholder"];
119
119
  const extractorAttributify = (options) => {
120
120
  const ignoreAttributes = options?.ignoreAttributes ?? defaultIgnoreAttributes;
@@ -123,7 +123,8 @@ const extractorAttributify = (options) => {
123
123
  return {
124
124
  name: "attributify",
125
125
  extract({ code }) {
126
- const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, _, content]) => {
126
+ const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, ...contents]) => {
127
+ const content = contents.filter(Boolean).join("");
127
128
  if (ignoreAttributes.includes(name))
128
129
  return [];
129
130
  for (const prefix of strippedPrefixes) {
@@ -144,7 +145,8 @@ const extractorAttributify = (options) => {
144
145
  if (["class", "className"].includes(name)) {
145
146
  return content.split(splitterRE).filter(isValidSelector);
146
147
  } else {
147
- return content.split(splitterRE).filter(Boolean).map((v) => `[${name}~="${v}"]`);
148
+ const extractTernary = Array.from(content.matchAll(/(?:[\?:].*?)(["'])([^\1]*?)\1/gms)).map(([, , v]) => v.split(splitterRE)).flat();
149
+ return (extractTernary.length ? extractTernary : content.split(splitterRE)).filter(Boolean).map((v) => `[${name}~="${v}"]`);
148
150
  }
149
151
  });
150
152
  return new Set(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/preset-attributify",
3
- "version": "0.46.5",
3
+ "version": "0.47.0",
4
4
  "description": "Attributify preset for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -33,7 +33,7 @@
33
33
  "dist"
34
34
  ],
35
35
  "dependencies": {
36
- "@unocss/core": "0.46.5"
36
+ "@unocss/core": "0.47.0"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "unbuild",