@weapp-tailwindcss/postcss 2.1.6-alpha.2 → 2.1.6-alpha.3

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.
Files changed (3) hide show
  1. package/dist/index.js +137 -35
  2. package/dist/index.mjs +132 -30
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3,6 +3,135 @@
3
3
  // src/handler.ts
4
4
  var _shared = require('@weapp-tailwindcss/shared');
5
5
 
6
+ // src/compat/uni-app-x.ts
7
+ var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
8
+ var UNI_APP_X_BASE_CARRIER_SELECTORS = /* @__PURE__ */ new Set([
9
+ "*",
10
+ "view",
11
+ "text",
12
+ "::before",
13
+ "::after",
14
+ ":before",
15
+ ":after",
16
+ "::backdrop"
17
+ ]);
18
+ var REQUIRED_TW_VAR_RE = /var\(\s*(--tw-[\w-]+)\s*\)/g;
19
+ var CLASS_SELECTOR_RE = /\.[\w-]+/;
20
+ var SELECTOR_WHITESPACE_RE = /\s+/g;
21
+ function isUniAppXEnabled(options) {
22
+ return Boolean(_optionalChain([options, 'optionalAccess', _ => _.uniAppX]));
23
+ }
24
+ function normalizeSelector(selector) {
25
+ return selector.replace(SELECTOR_WHITESPACE_RE, "").toLowerCase();
26
+ }
27
+ function isBaseCarrierSelector(selector) {
28
+ return UNI_APP_X_BASE_CARRIER_SELECTORS.has(normalizeSelector(selector));
29
+ }
30
+ function isBaseCarrierRule(rule) {
31
+ return Array.isArray(rule.selectors) && rule.selectors.length > 0 && rule.selectors.every(isBaseCarrierSelector);
32
+ }
33
+ function hasClassSelector(rule) {
34
+ return Array.isArray(rule.selectors) && rule.selectors.some((selector) => CLASS_SELECTOR_RE.test(selector));
35
+ }
36
+ function collectRequiredTwVars(value) {
37
+ const result = /* @__PURE__ */ new Set();
38
+ for (const match of value.matchAll(REQUIRED_TW_VAR_RE)) {
39
+ const variableName = match[1];
40
+ if (variableName) {
41
+ result.add(variableName);
42
+ }
43
+ }
44
+ return result;
45
+ }
46
+ function extractUniAppXBaseDefaults(result) {
47
+ const defaults = /* @__PURE__ */ new Map();
48
+ result.root.walkRules((rule) => {
49
+ if (!isBaseCarrierRule(rule)) {
50
+ return;
51
+ }
52
+ rule.walkDecls((decl) => {
53
+ if (!decl.prop.startsWith("--tw-") || defaults.has(decl.prop)) {
54
+ return;
55
+ }
56
+ defaults.set(decl.prop, {
57
+ prop: decl.prop,
58
+ value: decl.value,
59
+ important: decl.important
60
+ });
61
+ });
62
+ rule.remove();
63
+ });
64
+ return defaults;
65
+ }
66
+ function injectUniAppXBaseDefaults(result, defaults) {
67
+ if (defaults.size === 0) {
68
+ return;
69
+ }
70
+ result.root.walkRules((rule) => {
71
+ if (!hasClassSelector(rule)) {
72
+ return;
73
+ }
74
+ const declaredProps = /* @__PURE__ */ new Set();
75
+ const requiredProps = /* @__PURE__ */ new Set();
76
+ rule.walkDecls((decl) => {
77
+ declaredProps.add(decl.prop);
78
+ for (const variableName of collectRequiredTwVars(decl.value)) {
79
+ requiredProps.add(variableName);
80
+ }
81
+ });
82
+ const prependDecls = [];
83
+ for (const variableName of requiredProps) {
84
+ if (declaredProps.has(variableName)) {
85
+ continue;
86
+ }
87
+ const declaration = defaults.get(variableName);
88
+ if (declaration) {
89
+ prependDecls.push(declaration);
90
+ }
91
+ }
92
+ for (const declaration of prependDecls.reverse()) {
93
+ rule.prepend(_postcss2.default.decl({
94
+ prop: declaration.prop,
95
+ value: declaration.value,
96
+ important: declaration.important
97
+ }));
98
+ }
99
+ });
100
+ }
101
+ function applyUniAppXBaseCompatibility(result, options) {
102
+ if (!isUniAppXEnabled(options)) {
103
+ return result;
104
+ }
105
+ const defaults = extractUniAppXBaseDefaults(result);
106
+ injectUniAppXBaseDefaults(result, defaults);
107
+ if (defaults.size === 0) {
108
+ return result;
109
+ }
110
+ return result.root.toResult(result.opts);
111
+ }
112
+ function stripUnsupportedPseudoForUniAppX(node, enabled) {
113
+ if (!enabled) {
114
+ return;
115
+ }
116
+ if (node.value === ":host") {
117
+ return;
118
+ }
119
+ node.remove();
120
+ }
121
+ function stripUnsupportedNodeForUniAppX(node, options) {
122
+ if (!isUniAppXEnabled(options)) {
123
+ return false;
124
+ }
125
+ if (node.type === "attribute" || node.type === "pseudo") {
126
+ node.remove();
127
+ return true;
128
+ }
129
+ return false;
130
+ }
131
+ function shouldRemoveEmptyRuleForUniAppX(rule, options) {
132
+ return isUniAppXEnabled(options) && rule.nodes.length === 0;
133
+ }
134
+
6
135
  // src/defaults.ts
7
136
  function getDefaultOptions(options) {
8
137
  return {
@@ -15,9 +144,9 @@ function getDefaultOptions(options) {
15
144
  },
16
145
  "oklab-function": true,
17
146
  "color-mix": true,
18
- "color-functional-notation": _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.cssPresetEnv, 'optionalAccess', _2 => _2.features, 'optionalAccess', _3 => _3["color-functional-notation"]]), () => ( { preserve: false })),
147
+ "color-functional-notation": _nullishCoalesce(_optionalChain([options, 'optionalAccess', _2 => _2.cssPresetEnv, 'optionalAccess', _3 => _3.features, 'optionalAccess', _4 => _4["color-functional-notation"]]), () => ( { preserve: false })),
19
148
  // 在 calc 下,这个需要开启
20
- "custom-properties": _nullishCoalesce(_optionalChain([options, 'optionalAccess', _4 => _4.cssPresetEnv, 'optionalAccess', _5 => _5.features, 'optionalAccess', _6 => _6["custom-properties"]]), () => ( _optionalChain([options, 'optionalAccess', _7 => _7.cssCalc]))) ? { preserve: true } : false
149
+ "custom-properties": _nullishCoalesce(_optionalChain([options, 'optionalAccess', _5 => _5.cssPresetEnv, 'optionalAccess', _6 => _6.features, 'optionalAccess', _7 => _7["custom-properties"]]), () => ( _optionalChain([options, 'optionalAccess', _8 => _8.cssCalc]))) ? { preserve: true } : false
21
150
  },
22
151
  autoprefixer: {
23
152
  add: false
@@ -253,7 +382,7 @@ function createInjectPreflight(options) {
253
382
  }
254
383
 
255
384
  // src/processor-cache.ts
256
- var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
385
+
257
386
 
258
387
  // src/pipeline.ts
259
388
  var _postcsspresetenv = require('postcss-preset-env'); var _postcsspresetenv2 = _interopRequireDefault(_postcsspresetenv);
@@ -265,10 +394,10 @@ var isSlashDiv = (node) => node.type === "div" && node.value === "/";
265
394
  function trimNodes(nodes2) {
266
395
  let start = 0;
267
396
  let end = nodes2.length;
268
- while (start < end && _optionalChain([nodes2, 'access', _8 => _8[start], 'optionalAccess', _9 => _9.type]) === "space") {
397
+ while (start < end && _optionalChain([nodes2, 'access', _9 => _9[start], 'optionalAccess', _10 => _10.type]) === "space") {
269
398
  start += 1;
270
399
  }
271
- while (end > start && _optionalChain([nodes2, 'access', _10 => _10[end - 1], 'optionalAccess', _11 => _11.type]) === "space") {
400
+ while (end > start && _optionalChain([nodes2, 'access', _11 => _11[end - 1], 'optionalAccess', _12 => _12.type]) === "space") {
272
401
  end -= 1;
273
402
  }
274
403
  return nodes2.slice(start, end);
@@ -553,7 +682,7 @@ function getUnitsToPxPlugin(options) {
553
682
  // src/compat/tailwindcss-rpx.ts
554
683
  var LENGTH_VALUE_REGEXP = /^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?rpx$/i;
555
684
  function normalizeTailwindcssRpxDeclaration(decl, options) {
556
- const majorVersion = _optionalChain([options, 'optionalAccess', _12 => _12.majorVersion]);
685
+ const majorVersion = _optionalChain([options, 'optionalAccess', _13 => _13.majorVersion]);
557
686
  const normalizedValue = decl.value.trim();
558
687
  if (LENGTH_VALUE_REGEXP.test(normalizedValue) && (majorVersion === void 0 || majorVersion === 2 || majorVersion === 3 || majorVersion === 4)) {
559
688
  const lowerProp = decl.prop.toLowerCase();
@@ -740,7 +869,7 @@ var MODERN_CHECK_COLOR_RGB_RE = /color\s*:\s*rgb\(\s*from\s+red\s+r\s+g\s+b\s*\)
740
869
  var RADIUS_VALUE_RE = /\b([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*(r?px)\b/gi;
741
870
  var SCIENTIFIC_NOTATION_RE = /e/i;
742
871
  function isTailwindcssV4(options) {
743
- return _optionalChain([options, 'optionalAccess', _13 => _13.majorVersion]) === 4;
872
+ return _optionalChain([options, 'optionalAccess', _14 => _14.majorVersion]) === 4;
744
873
  }
745
874
  function testIfRootHostForV4(node) {
746
875
  return node.type === "rule" && node.selector.includes(":root") && node.selector.includes(":host");
@@ -786,33 +915,6 @@ function normalizeTailwindcssV4Declaration(decl) {
786
915
  return false;
787
916
  }
788
917
 
789
- // src/compat/uni-app-x.ts
790
- function isUniAppXEnabled(options) {
791
- return Boolean(_optionalChain([options, 'optionalAccess', _14 => _14.uniAppX]));
792
- }
793
- function stripUnsupportedPseudoForUniAppX(node, enabled) {
794
- if (!enabled) {
795
- return;
796
- }
797
- if (node.value === ":host") {
798
- return;
799
- }
800
- node.remove();
801
- }
802
- function stripUnsupportedNodeForUniAppX(node, options) {
803
- if (!isUniAppXEnabled(options)) {
804
- return false;
805
- }
806
- if (node.type === "attribute" || node.type === "pseudo") {
807
- node.remove();
808
- return true;
809
- }
810
- return false;
811
- }
812
- function shouldRemoveEmptyRuleForUniAppX(rule, options) {
813
- return isUniAppXEnabled(options) && rule.nodes.length === 0;
814
- }
815
-
816
918
  // src/constants.ts
817
919
  var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
818
920
 
@@ -2481,7 +2583,7 @@ function createStyleHandler(options) {
2481
2583
  return processor.process(
2482
2584
  rawSource,
2483
2585
  processOptions
2484
- ).async();
2586
+ ).async().then((result) => applyUniAppXBaseCompatibility(result, resolvedOptions));
2485
2587
  });
2486
2588
  handler.getPipeline = (opt) => {
2487
2589
  const resolvedOptions = resolver.resolve(opt);
package/dist/index.mjs CHANGED
@@ -3,6 +3,135 @@ import "./chunk-WAXGOBY2.mjs";
3
3
  // src/handler.ts
4
4
  import { defuOverrideArray as defuOverrideArray4 } from "@weapp-tailwindcss/shared";
5
5
 
6
+ // src/compat/uni-app-x.ts
7
+ import postcss from "postcss";
8
+ var UNI_APP_X_BASE_CARRIER_SELECTORS = /* @__PURE__ */ new Set([
9
+ "*",
10
+ "view",
11
+ "text",
12
+ "::before",
13
+ "::after",
14
+ ":before",
15
+ ":after",
16
+ "::backdrop"
17
+ ]);
18
+ var REQUIRED_TW_VAR_RE = /var\(\s*(--tw-[\w-]+)\s*\)/g;
19
+ var CLASS_SELECTOR_RE = /\.[\w-]+/;
20
+ var SELECTOR_WHITESPACE_RE = /\s+/g;
21
+ function isUniAppXEnabled(options) {
22
+ return Boolean(options?.uniAppX);
23
+ }
24
+ function normalizeSelector(selector) {
25
+ return selector.replace(SELECTOR_WHITESPACE_RE, "").toLowerCase();
26
+ }
27
+ function isBaseCarrierSelector(selector) {
28
+ return UNI_APP_X_BASE_CARRIER_SELECTORS.has(normalizeSelector(selector));
29
+ }
30
+ function isBaseCarrierRule(rule) {
31
+ return Array.isArray(rule.selectors) && rule.selectors.length > 0 && rule.selectors.every(isBaseCarrierSelector);
32
+ }
33
+ function hasClassSelector(rule) {
34
+ return Array.isArray(rule.selectors) && rule.selectors.some((selector) => CLASS_SELECTOR_RE.test(selector));
35
+ }
36
+ function collectRequiredTwVars(value) {
37
+ const result = /* @__PURE__ */ new Set();
38
+ for (const match of value.matchAll(REQUIRED_TW_VAR_RE)) {
39
+ const variableName = match[1];
40
+ if (variableName) {
41
+ result.add(variableName);
42
+ }
43
+ }
44
+ return result;
45
+ }
46
+ function extractUniAppXBaseDefaults(result) {
47
+ const defaults = /* @__PURE__ */ new Map();
48
+ result.root.walkRules((rule) => {
49
+ if (!isBaseCarrierRule(rule)) {
50
+ return;
51
+ }
52
+ rule.walkDecls((decl) => {
53
+ if (!decl.prop.startsWith("--tw-") || defaults.has(decl.prop)) {
54
+ return;
55
+ }
56
+ defaults.set(decl.prop, {
57
+ prop: decl.prop,
58
+ value: decl.value,
59
+ important: decl.important
60
+ });
61
+ });
62
+ rule.remove();
63
+ });
64
+ return defaults;
65
+ }
66
+ function injectUniAppXBaseDefaults(result, defaults) {
67
+ if (defaults.size === 0) {
68
+ return;
69
+ }
70
+ result.root.walkRules((rule) => {
71
+ if (!hasClassSelector(rule)) {
72
+ return;
73
+ }
74
+ const declaredProps = /* @__PURE__ */ new Set();
75
+ const requiredProps = /* @__PURE__ */ new Set();
76
+ rule.walkDecls((decl) => {
77
+ declaredProps.add(decl.prop);
78
+ for (const variableName of collectRequiredTwVars(decl.value)) {
79
+ requiredProps.add(variableName);
80
+ }
81
+ });
82
+ const prependDecls = [];
83
+ for (const variableName of requiredProps) {
84
+ if (declaredProps.has(variableName)) {
85
+ continue;
86
+ }
87
+ const declaration = defaults.get(variableName);
88
+ if (declaration) {
89
+ prependDecls.push(declaration);
90
+ }
91
+ }
92
+ for (const declaration of prependDecls.reverse()) {
93
+ rule.prepend(postcss.decl({
94
+ prop: declaration.prop,
95
+ value: declaration.value,
96
+ important: declaration.important
97
+ }));
98
+ }
99
+ });
100
+ }
101
+ function applyUniAppXBaseCompatibility(result, options) {
102
+ if (!isUniAppXEnabled(options)) {
103
+ return result;
104
+ }
105
+ const defaults = extractUniAppXBaseDefaults(result);
106
+ injectUniAppXBaseDefaults(result, defaults);
107
+ if (defaults.size === 0) {
108
+ return result;
109
+ }
110
+ return result.root.toResult(result.opts);
111
+ }
112
+ function stripUnsupportedPseudoForUniAppX(node, enabled) {
113
+ if (!enabled) {
114
+ return;
115
+ }
116
+ if (node.value === ":host") {
117
+ return;
118
+ }
119
+ node.remove();
120
+ }
121
+ function stripUnsupportedNodeForUniAppX(node, options) {
122
+ if (!isUniAppXEnabled(options)) {
123
+ return false;
124
+ }
125
+ if (node.type === "attribute" || node.type === "pseudo") {
126
+ node.remove();
127
+ return true;
128
+ }
129
+ return false;
130
+ }
131
+ function shouldRemoveEmptyRuleForUniAppX(rule, options) {
132
+ return isUniAppXEnabled(options) && rule.nodes.length === 0;
133
+ }
134
+
6
135
  // src/defaults.ts
7
136
  function getDefaultOptions(options) {
8
137
  return {
@@ -253,7 +382,7 @@ function createInjectPreflight(options) {
253
382
  }
254
383
 
255
384
  // src/processor-cache.ts
256
- import postcss from "postcss";
385
+ import postcss2 from "postcss";
257
386
 
258
387
  // src/pipeline.ts
259
388
  import postcssPresetEnv from "postcss-preset-env";
@@ -786,33 +915,6 @@ function normalizeTailwindcssV4Declaration(decl) {
786
915
  return false;
787
916
  }
788
917
 
789
- // src/compat/uni-app-x.ts
790
- function isUniAppXEnabled(options) {
791
- return Boolean(options?.uniAppX);
792
- }
793
- function stripUnsupportedPseudoForUniAppX(node, enabled) {
794
- if (!enabled) {
795
- return;
796
- }
797
- if (node.value === ":host") {
798
- return;
799
- }
800
- node.remove();
801
- }
802
- function stripUnsupportedNodeForUniAppX(node, options) {
803
- if (!isUniAppXEnabled(options)) {
804
- return false;
805
- }
806
- if (node.type === "attribute" || node.type === "pseudo") {
807
- node.remove();
808
- return true;
809
- }
810
- return false;
811
- }
812
- function shouldRemoveEmptyRuleForUniAppX(rule, options) {
813
- return isUniAppXEnabled(options) && rule.nodes.length === 0;
814
- }
815
-
816
918
  // src/constants.ts
817
919
  var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
818
920
 
@@ -2453,7 +2555,7 @@ var StyleProcessorCache = class {
2453
2555
  processor = this.processorCacheByKey.get(cacheKey);
2454
2556
  if (!processor) {
2455
2557
  const pipeline = this.getPipeline(options);
2456
- processor = postcss(pipeline.plugins);
2558
+ processor = postcss2(pipeline.plugins);
2457
2559
  this.processorCacheByKey.set(cacheKey, processor);
2458
2560
  }
2459
2561
  this.processorCache.set(options, processor);
@@ -2481,7 +2583,7 @@ function createStyleHandler(options) {
2481
2583
  return processor.process(
2482
2584
  rawSource,
2483
2585
  processOptions
2484
- ).async();
2586
+ ).async().then((result) => applyUniAppXBaseCompatibility(result, resolvedOptions));
2485
2587
  });
2486
2588
  handler.getPipeline = (opt) => {
2487
2589
  const resolvedOptions = resolver.resolve(opt);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/postcss",
3
- "version": "2.1.6-alpha.2",
3
+ "version": "2.1.6-alpha.3",
4
4
  "description": "@weapp-tailwindcss/postcss",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",