weapp-tailwindcss 3.0.0 → 3.0.2

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/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var options = require('./options-_u-7p8aC.js');
3
+ var options = require('./options-5eiKwcXx.js');
4
4
  require('magic-string');
5
5
  require('./replace.js');
6
6
  require('@weapp-core/escape');
@@ -15,10 +15,10 @@ require('./defu-KWuJnZLV.js');
15
15
  require('@babel/types');
16
16
  require('htmlparser2');
17
17
  require('postcss');
18
- require('./postcss-sB1dQbYV.js');
19
- require('postcss-selector-parser');
18
+ require('./postcss-zkCNv4BC.js');
20
19
  require('@csstools/postcss-is-pseudo-class');
21
20
  require('postcss-rem-to-responsive-pixel');
21
+ require('postcss-selector-parser');
22
22
  require('node:path');
23
23
  require('node:fs');
24
24
  require('semver');
package/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { g as getOptions, c as createPatch } from './options-vyKfCeIO.mjs';
1
+ import { g as getOptions, c as createPatch } from './options-UXRHB24i.mjs';
2
2
  import 'magic-string';
3
3
  import './replace.mjs';
4
4
  import '@weapp-core/escape';
@@ -13,10 +13,10 @@ import './defu-ms_ZBCiB.mjs';
13
13
  import '@babel/types';
14
14
  import 'htmlparser2';
15
15
  import 'postcss';
16
- import './postcss-4kTT_aj1.mjs';
17
- import 'postcss-selector-parser';
16
+ import './postcss-irzTcRfl.mjs';
18
17
  import '@csstools/postcss-is-pseudo-class';
19
18
  import 'postcss-rem-to-responsive-pixel';
19
+ import 'postcss-selector-parser';
20
20
  import 'node:path';
21
21
  import 'node:fs';
22
22
  import 'semver';
package/dist/core.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var options = require('./options-_u-7p8aC.js');
5
+ var options = require('./options-5eiKwcXx.js');
6
6
  require('magic-string');
7
7
  require('./replace.js');
8
8
  require('@weapp-core/escape');
@@ -17,10 +17,10 @@ require('./defu-KWuJnZLV.js');
17
17
  require('@babel/types');
18
18
  require('htmlparser2');
19
19
  require('postcss');
20
- require('./postcss-sB1dQbYV.js');
21
- require('postcss-selector-parser');
20
+ require('./postcss-zkCNv4BC.js');
22
21
  require('@csstools/postcss-is-pseudo-class');
23
22
  require('postcss-rem-to-responsive-pixel');
23
+ require('postcss-selector-parser');
24
24
  require('node:path');
25
25
  require('node:fs');
26
26
  require('semver');
package/dist/core.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { g as getOptions, a as createTailwindcssPatcher, _ as __awaiter } from './options-vyKfCeIO.mjs';
1
+ import { g as getOptions, a as createTailwindcssPatcher, _ as __awaiter } from './options-UXRHB24i.mjs';
2
2
  import 'magic-string';
3
3
  import './replace.mjs';
4
4
  import '@weapp-core/escape';
@@ -13,10 +13,10 @@ import './defu-ms_ZBCiB.mjs';
13
13
  import '@babel/types';
14
14
  import 'htmlparser2';
15
15
  import 'postcss';
16
- import './postcss-4kTT_aj1.mjs';
17
- import 'postcss-selector-parser';
16
+ import './postcss-irzTcRfl.mjs';
18
17
  import '@csstools/postcss-is-pseudo-class';
19
18
  import 'postcss-rem-to-responsive-pixel';
19
+ import 'postcss-selector-parser';
20
20
  import 'node:path';
21
21
  import 'node:fs';
22
22
  import 'semver';
package/dist/gulp.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var options = require('./options-_u-7p8aC.js');
5
+ var options = require('./options-5eiKwcXx.js');
6
6
  var stream = require('node:stream');
7
7
  require('magic-string');
8
8
  require('./replace.js');
@@ -18,10 +18,10 @@ require('./defu-KWuJnZLV.js');
18
18
  require('@babel/types');
19
19
  require('htmlparser2');
20
20
  require('postcss');
21
- require('./postcss-sB1dQbYV.js');
22
- require('postcss-selector-parser');
21
+ require('./postcss-zkCNv4BC.js');
23
22
  require('@csstools/postcss-is-pseudo-class');
24
23
  require('postcss-rem-to-responsive-pixel');
24
+ require('postcss-selector-parser');
25
25
  require('node:path');
26
26
  require('node:fs');
27
27
  require('semver');
package/dist/gulp.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { g as getOptions, a as createTailwindcssPatcher, _ as __awaiter } from './options-vyKfCeIO.mjs';
1
+ import { g as getOptions, a as createTailwindcssPatcher, _ as __awaiter } from './options-UXRHB24i.mjs';
2
2
  import stream from 'node:stream';
3
3
  import 'magic-string';
4
4
  import './replace.mjs';
@@ -14,10 +14,10 @@ import './defu-ms_ZBCiB.mjs';
14
14
  import '@babel/types';
15
15
  import 'htmlparser2';
16
16
  import 'postcss';
17
- import './postcss-4kTT_aj1.mjs';
18
- import 'postcss-selector-parser';
17
+ import './postcss-irzTcRfl.mjs';
19
18
  import '@csstools/postcss-is-pseudo-class';
20
19
  import 'postcss-rem-to-responsive-pixel';
20
+ import 'postcss-selector-parser';
21
21
  import 'node:path';
22
22
  import 'node:fs';
23
23
  import 'semver';
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var webpack = require('./webpack.js');
6
6
  var vite = require('./vite.js');
7
7
  var gulp = require('./gulp.js');
8
- require('./options-_u-7p8aC.js');
8
+ require('./options-5eiKwcXx.js');
9
9
  require('magic-string');
10
10
  require('./replace.js');
11
11
  require('@weapp-core/escape');
@@ -20,10 +20,10 @@ require('./defu-KWuJnZLV.js');
20
20
  require('@babel/types');
21
21
  require('htmlparser2');
22
22
  require('postcss');
23
- require('./postcss-sB1dQbYV.js');
24
- require('postcss-selector-parser');
23
+ require('./postcss-zkCNv4BC.js');
25
24
  require('@csstools/postcss-is-pseudo-class');
26
25
  require('postcss-rem-to-responsive-pixel');
26
+ require('postcss-selector-parser');
27
27
  require('node:path');
28
28
  require('node:fs');
29
29
  require('semver');
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  export { UnifiedWebpackPluginV5 } from './webpack.mjs';
2
2
  export { UnifiedViteWeappTailwindcssPlugin } from './vite.mjs';
3
3
  export { createPlugins } from './gulp.mjs';
4
- import './options-vyKfCeIO.mjs';
4
+ import './options-UXRHB24i.mjs';
5
5
  import 'magic-string';
6
6
  import './replace.mjs';
7
7
  import '@weapp-core/escape';
@@ -16,10 +16,10 @@ import './defu-ms_ZBCiB.mjs';
16
16
  import '@babel/types';
17
17
  import 'htmlparser2';
18
18
  import 'postcss';
19
- import './postcss-4kTT_aj1.mjs';
20
- import 'postcss-selector-parser';
19
+ import './postcss-irzTcRfl.mjs';
21
20
  import '@csstools/postcss-is-pseudo-class';
22
21
  import 'postcss-rem-to-responsive-pixel';
22
+ import 'postcss-selector-parser';
23
23
  import 'node:path';
24
24
  import 'node:fs';
25
25
  import 'semver';
@@ -11,10 +11,8 @@ var traverse = require('@babel/traverse');
11
11
  var defaults = require('./defaults-QOAV8NSV.js');
12
12
  var t = require('@babel/types');
13
13
  var htmlparser2 = require('htmlparser2');
14
- var postcss$1 = require('postcss');
15
- var postcss = require('./postcss-sB1dQbYV.js');
16
- var postcssIsPseudoClass = require('@csstools/postcss-is-pseudo-class');
17
- var postcssRem2rpx = require('postcss-rem-to-responsive-pixel');
14
+ var postcss = require('postcss');
15
+ var postcss$1 = require('./postcss-zkCNv4BC.js');
18
16
  var path = require('node:path');
19
17
  var fs = require('node:fs');
20
18
  var semver = require('semver');
@@ -47,9 +45,7 @@ var MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
47
45
  var generate__default = /*#__PURE__*/_interopDefaultCompat(generate);
48
46
  var traverse__default = /*#__PURE__*/_interopDefaultCompat(traverse);
49
47
  var t__namespace = /*#__PURE__*/_interopNamespaceCompat(t);
50
- var postcss__default = /*#__PURE__*/_interopDefaultCompat(postcss$1);
51
- var postcssIsPseudoClass__default = /*#__PURE__*/_interopDefaultCompat(postcssIsPseudoClass);
52
- var postcssRem2rpx__default = /*#__PURE__*/_interopDefaultCompat(postcssRem2rpx);
48
+ var postcss__default = /*#__PURE__*/_interopDefaultCompat(postcss);
53
49
  var path__default = /*#__PURE__*/_interopDefaultCompat(path);
54
50
  var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
55
51
  var md5__default = /*#__PURE__*/_interopDefaultCompat(md5);
@@ -398,22 +394,7 @@ function createTemplateHandler(options = {}) {
398
394
 
399
395
  function styleHandler(rawSource, options) {
400
396
  return __awaiter(this, void 0, void 0, function* () {
401
- const plugins = [
402
- postcss.postcssWeappTailwindcss(options),
403
- postcssIsPseudoClass__default["default"]({
404
- specificityMatchingName: 'weapp-tw-ig'
405
- })
406
- ];
407
- if (options.rem2rpx) {
408
- plugins.push(postcssRem2rpx__default["default"](typeof options.rem2rpx === 'object'
409
- ? options.rem2rpx
410
- : {
411
- rootValue: 32,
412
- propList: ['*'],
413
- transformUnit: 'rpx'
414
- }));
415
- }
416
- return (yield postcss__default["default"](plugins).process(rawSource).async()).css;
397
+ return (yield postcss__default["default"](postcss$1.getPlugins(options)).process(rawSource).async()).css;
417
398
  });
418
399
  }
419
400
  function createStyleHandler(options) {
@@ -10,9 +10,7 @@ import { d as defuOverrideArray, n as noop, a as defaultOptions, i as isMap } fr
10
10
  import * as t from '@babel/types';
11
11
  import { Parser } from 'htmlparser2';
12
12
  import postcss from 'postcss';
13
- import { p as postcssWeappTailwindcss } from './postcss-4kTT_aj1.mjs';
14
- import postcssIsPseudoClass from '@csstools/postcss-is-pseudo-class';
15
- import postcssRem2rpx from 'postcss-rem-to-responsive-pixel';
13
+ import { g as getPlugins } from './postcss-irzTcRfl.mjs';
16
14
  import path from 'node:path';
17
15
  import fs from 'node:fs';
18
16
  import { gte } from 'semver';
@@ -365,22 +363,7 @@ function createTemplateHandler(options = {}) {
365
363
 
366
364
  function styleHandler(rawSource, options) {
367
365
  return __awaiter(this, void 0, void 0, function* () {
368
- const plugins = [
369
- postcssWeappTailwindcss(options),
370
- postcssIsPseudoClass({
371
- specificityMatchingName: 'weapp-tw-ig'
372
- })
373
- ];
374
- if (options.rem2rpx) {
375
- plugins.push(postcssRem2rpx(typeof options.rem2rpx === 'object'
376
- ? options.rem2rpx
377
- : {
378
- rootValue: 32,
379
- propList: ['*'],
380
- transformUnit: 'rpx'
381
- }));
382
- }
383
- return (yield postcss(plugins).process(rawSource).async()).css;
366
+ return (yield postcss(getPlugins(options)).process(rawSource).async()).css;
384
367
  });
385
368
  }
386
369
  function createStyleHandler(options) {
@@ -3,6 +3,6 @@ import type { IStyleHandlerOptions } from "../types";
3
3
  export declare function testIfVariablesScope(node: Rule, count?: number): boolean;
4
4
  export declare function testIfTwBackdrop(node: Rule, count?: number): boolean;
5
5
  export declare function makePseudoVarRule(): Rule;
6
- export declare function remakeCssVarSelector(selectors: string[], cssPreflightRange: IStyleHandlerOptions['cssPreflightRange']): string[];
6
+ export declare function remakeCssVarSelector(selectors: string[], options: IStyleHandlerOptions): string[];
7
7
  export declare function remakeCombinatorSelector(selector: string, cssChildCombinatorReplaceValue: IStyleHandlerOptions['cssChildCombinatorReplaceValue']): string;
8
8
  export declare function commonChunkPreflight(node: Rule, options: IStyleHandlerOptions): void;
@@ -0,0 +1,4 @@
1
+ export declare function createContext(): {
2
+ variablesScopeWeakMap: WeakMap<object, any>;
3
+ };
4
+ export type IContext = ReturnType<typeof createContext>;
@@ -0,0 +1,7 @@
1
+ import { AcceptedPlugin } from 'postcss';
2
+ import { IStyleHandlerOptions } from "../../types";
3
+ export declare function getPlugins(options: IStyleHandlerOptions): AcceptedPlugin[];
4
+ export { postcssWeappTailwindcssPostPlugin } from './post';
5
+ export { postcssWeappTailwindcssPrePlugin } from './pre';
6
+ export { default as postcssIsPseudoClass } from '@csstools/postcss-is-pseudo-class';
7
+ export { default as postcssRem2rpx } from 'postcss-rem-to-responsive-pixel';
@@ -0,0 +1,5 @@
1
+ import type { PluginCreator } from 'postcss';
2
+ import type { IStyleHandlerOptions } from "../../types";
3
+ export type PostcssWeappTailwindcssRenamePlugin = PluginCreator<IStyleHandlerOptions>;
4
+ declare const postcssWeappTailwindcssPostPlugin: PostcssWeappTailwindcssRenamePlugin;
5
+ export { postcssWeappTailwindcssPostPlugin };
@@ -0,0 +1,5 @@
1
+ import type { PluginCreator } from 'postcss';
2
+ import type { IStyleHandlerOptions } from "../../types";
3
+ export type PostcssWeappTailwindcssRenamePlugin = PluginCreator<IStyleHandlerOptions>;
4
+ declare const postcssWeappTailwindcssPrePlugin: PostcssWeappTailwindcssRenamePlugin;
5
+ export { postcssWeappTailwindcssPrePlugin };
@@ -0,0 +1 @@
1
+ export declare const VariablesScopeSymbol: unique symbol;
@@ -1,8 +1,8 @@
1
+ import postcssIsPseudoClass from '@csstools/postcss-is-pseudo-class';
2
+ import postcssRem2rpx from 'postcss-rem-to-responsive-pixel';
1
3
  import selectorParser from 'postcss-selector-parser';
2
4
  import { c as composeIsPseudo, i as internalCssSelectorReplacer } from './shared-0D5OOeXo.mjs';
3
5
  import { Declaration, Rule } from 'postcss';
4
- import '@csstools/postcss-is-pseudo-class';
5
- import 'postcss-rem-to-responsive-pixel';
6
6
 
7
7
  const createTransform = (rule, options) => {
8
8
  const { escapeMap, mangleContext, cssSelectorReplacement } = options;
@@ -233,13 +233,15 @@ var cssVars = [
233
233
  }
234
234
  ];
235
235
 
236
+ const VariablesScopeSymbol = Symbol('VariablesScope');
237
+
236
238
  const initialNodes = cssVars.map((x) => {
237
239
  return new Declaration({
238
240
  prop: x.prop,
239
241
  value: x.value
240
242
  });
241
243
  });
242
- const PATTERNS = [/:not\(template\)\s*~\s*:not\(template\)/.source, /:not\(\[hidden\]\)\s*~\s*:not\(\[hidden\]\)/.source].join('|');
244
+ const PATTERNS = [/:not\(template\)\s*[~+]\s*:not\(template\)/.source, /:not\(\[hidden\]\)\s*[~+]\s*:not\(\[hidden\]\)/.source].join('|');
243
245
  const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g');
244
246
  function testIfVariablesScope(node, count = 2) {
245
247
  if (/:?:before/.test(node.selector) && /:?:after/.test(node.selector)) {
@@ -283,13 +285,24 @@ function makePseudoVarRule() {
283
285
  }));
284
286
  return pseudoVarRule;
285
287
  }
286
- function remakeCssVarSelector(selectors, cssPreflightRange) {
288
+ function remakeCssVarSelector(selectors, options) {
289
+ const { cssPreflightRange, cssSelectorReplacement } = options;
287
290
  if (cssPreflightRange === 'all' &&
288
291
  !selectors.includes(':not(not)')) {
289
292
  selectors.push(':not(not)');
290
293
  }
291
- if (!selectors.includes('*')) {
292
- selectors.unshift('*');
294
+ if (cssSelectorReplacement) {
295
+ if (Array.isArray(cssSelectorReplacement.universal)) {
296
+ if (!cssSelectorReplacement.universal.every((x) => {
297
+ return selectors.includes(x);
298
+ }) &&
299
+ !selectors.includes('*')) {
300
+ selectors.unshift('*');
301
+ }
302
+ }
303
+ else if (typeof cssSelectorReplacement.universal === 'string' && !selectors.includes(cssSelectorReplacement.universal) && !selectors.includes('*')) {
304
+ selectors.unshift('*');
305
+ }
293
306
  }
294
307
  return selectors;
295
308
  }
@@ -305,24 +318,26 @@ function remakeCombinatorSelector(selector, cssChildCombinatorReplaceValue) {
305
318
  return selector.replaceAll(BROAD_MATCH_GLOBAL_REGEXP, childCombinatorReplaceValue);
306
319
  }
307
320
  function commonChunkPreflight(node, options) {
308
- node.selector = remakeCombinatorSelector(node.selector, options.cssChildCombinatorReplaceValue);
321
+ const { ctx, cssChildCombinatorReplaceValue, cssInjectPreflight, injectAdditionalCssVarScope } = options;
322
+ node.selector = remakeCombinatorSelector(node.selector, cssChildCombinatorReplaceValue);
309
323
  if (testIfVariablesScope(node)) {
310
- node.selectors = remakeCssVarSelector(node.selectors, options.cssPreflightRange);
324
+ ctx === null || ctx === void 0 ? void 0 : ctx.variablesScopeWeakMap.set(node, VariablesScopeSymbol);
325
+ node.selectors = remakeCssVarSelector(node.selectors, options);
311
326
  node.before(makePseudoVarRule());
312
- if (typeof options.cssInjectPreflight === 'function') {
313
- node.append(...options.cssInjectPreflight());
327
+ if (typeof cssInjectPreflight === 'function') {
328
+ node.append(...cssInjectPreflight());
314
329
  }
315
330
  }
316
- if (options.injectAdditionalCssVarScope && testIfTwBackdrop(node)) {
331
+ if (injectAdditionalCssVarScope && testIfTwBackdrop(node)) {
317
332
  const syntheticRule = new Rule({
318
333
  selectors: ['*', '::after', '::before'],
319
334
  nodes: initialNodes
320
335
  });
321
- syntheticRule.selectors = remakeCssVarSelector(syntheticRule.selectors, options.cssPreflightRange);
336
+ syntheticRule.selectors = remakeCssVarSelector(syntheticRule.selectors, options);
322
337
  node.before(syntheticRule);
323
338
  node.before(makePseudoVarRule());
324
- if (typeof options.cssInjectPreflight === 'function') {
325
- syntheticRule.append(...options.cssInjectPreflight());
339
+ if (typeof cssInjectPreflight === 'function') {
340
+ syntheticRule.append(...cssInjectPreflight());
326
341
  }
327
342
  }
328
343
  }
@@ -334,22 +349,14 @@ const vitePluginName = 'vite-plugin-uni-app-weapp-tailwindcss-adaptor';
334
349
  function isAtMediaHover(atRule) {
335
350
  return /media\(\s*hover\s*:\s*hover\s*\)/.test(atRule.name) || (atRule.name === 'media' && /\(\s*hover\s*:\s*hover\s*\)/.test(atRule.params));
336
351
  }
337
- const postcssWeappTailwindcss = (options = {
352
+ const postcssWeappTailwindcssPrePlugin = (options = {
338
353
  isMainChunk: true
339
354
  }) => {
340
- const { customRuleCallback, isMainChunk } = options;
341
- const isCustomRuleCallbackFn = typeof customRuleCallback === 'function';
342
- return {
355
+ const { isMainChunk } = options;
356
+ const p = {
343
357
  postcssPlugin,
344
- Once(css) {
345
- isMainChunk &&
346
- css.walkRules((rule) => {
347
- commonChunkPreflight(rule, options);
348
- });
349
- },
350
358
  Rule(rule) {
351
359
  transformSync(rule, options);
352
- isCustomRuleCallbackFn && customRuleCallback(rule, options);
353
360
  },
354
361
  AtRule(atRule) {
355
362
  if (isAtMediaHover(atRule)) {
@@ -358,7 +365,90 @@ const postcssWeappTailwindcss = (options = {
358
365
  }
359
366
  }
360
367
  };
368
+ if (isMainChunk) {
369
+ p.Once = (root) => {
370
+ root.walkRules((rule) => {
371
+ commonChunkPreflight(rule, options);
372
+ });
373
+ };
374
+ }
375
+ return p;
376
+ };
377
+ postcssWeappTailwindcssPrePlugin.postcss = true;
378
+
379
+ const fallback = selectorParser((selectors) => {
380
+ selectors.walk((selector) => {
381
+ var _a, _b;
382
+ if (selector.type === 'universal') {
383
+ (_a = selector.parent) === null || _a === void 0 ? void 0 : _a.remove();
384
+ }
385
+ if (selector.type === 'pseudo' && selector.value === ':is') {
386
+ (_b = selector.parent) === null || _b === void 0 ? void 0 : _b.remove();
387
+ }
388
+ });
389
+ });
390
+ const postcssWeappTailwindcssPostPlugin = (options = {
391
+ isMainChunk: true
392
+ }) => {
393
+ const { customRuleCallback, isMainChunk, ctx } = options;
394
+ const p = {
395
+ postcssPlugin
396
+ };
397
+ if (isMainChunk) {
398
+ p.OnceExit = (root) => {
399
+ root.walkRules((rule) => {
400
+ if (ctx) {
401
+ if (ctx.variablesScopeWeakMap.get(rule) === VariablesScopeSymbol) {
402
+ fallback.transformSync(rule, {
403
+ updateSelector: true,
404
+ lossless: false
405
+ });
406
+ }
407
+ }
408
+ else if (testIfVariablesScope(rule)) {
409
+ fallback.transformSync(rule, {
410
+ updateSelector: true,
411
+ lossless: false
412
+ });
413
+ }
414
+ });
415
+ };
416
+ }
417
+ if (typeof customRuleCallback === 'function') {
418
+ p.Rule = (rule) => {
419
+ customRuleCallback(rule, options);
420
+ };
421
+ }
422
+ return p;
361
423
  };
362
- postcssWeappTailwindcss.postcss = true;
424
+ postcssWeappTailwindcssPostPlugin.postcss = true;
425
+
426
+ function createContext() {
427
+ return {
428
+ variablesScopeWeakMap: new WeakMap()
429
+ };
430
+ }
431
+
432
+ function getPlugins(options) {
433
+ const ctx = createContext();
434
+ options.ctx = ctx;
435
+ const plugins = [
436
+ postcssWeappTailwindcssPrePlugin(options),
437
+ postcssIsPseudoClass({
438
+ specificityMatchingName: 'weapp-tw-ig'
439
+ })
440
+ ];
441
+ if (options.rem2rpx) {
442
+ plugins.push(postcssRem2rpx(typeof options.rem2rpx === 'object'
443
+ ? options.rem2rpx
444
+ : {
445
+ rootValue: 32,
446
+ propList: ['*'],
447
+ transformUnit: 'rpx'
448
+ }));
449
+ }
450
+ plugins.push(postcssWeappTailwindcssPostPlugin(options));
451
+ return plugins;
452
+ }
363
453
 
364
- export { pluginName as a, postcssWeappTailwindcss as p, vitePluginName as v };
454
+ export { postcssWeappTailwindcssPostPlugin as a, postcssWeappTailwindcssPrePlugin as b, getPlugins as g, pluginName as p, vitePluginName as v };
@@ -1,13 +1,15 @@
1
1
  'use strict';
2
2
 
3
+ var postcssIsPseudoClass = require('@csstools/postcss-is-pseudo-class');
4
+ var postcssRem2rpx = require('postcss-rem-to-responsive-pixel');
3
5
  var selectorParser = require('postcss-selector-parser');
4
6
  var shared = require('./shared-AxeHlAoJ.js');
5
7
  var postcss = require('postcss');
6
- require('@csstools/postcss-is-pseudo-class');
7
- require('postcss-rem-to-responsive-pixel');
8
8
 
9
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
10
 
11
+ var postcssIsPseudoClass__default = /*#__PURE__*/_interopDefaultCompat(postcssIsPseudoClass);
12
+ var postcssRem2rpx__default = /*#__PURE__*/_interopDefaultCompat(postcssRem2rpx);
11
13
  var selectorParser__default = /*#__PURE__*/_interopDefaultCompat(selectorParser);
12
14
 
13
15
  const createTransform = (rule, options) => {
@@ -239,13 +241,15 @@ var cssVars = [
239
241
  }
240
242
  ];
241
243
 
244
+ const VariablesScopeSymbol = Symbol('VariablesScope');
245
+
242
246
  const initialNodes = cssVars.map((x) => {
243
247
  return new postcss.Declaration({
244
248
  prop: x.prop,
245
249
  value: x.value
246
250
  });
247
251
  });
248
- const PATTERNS = [/:not\(template\)\s*~\s*:not\(template\)/.source, /:not\(\[hidden\]\)\s*~\s*:not\(\[hidden\]\)/.source].join('|');
252
+ const PATTERNS = [/:not\(template\)\s*[~+]\s*:not\(template\)/.source, /:not\(\[hidden\]\)\s*[~+]\s*:not\(\[hidden\]\)/.source].join('|');
249
253
  const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g');
250
254
  function testIfVariablesScope(node, count = 2) {
251
255
  if (/:?:before/.test(node.selector) && /:?:after/.test(node.selector)) {
@@ -289,13 +293,24 @@ function makePseudoVarRule() {
289
293
  }));
290
294
  return pseudoVarRule;
291
295
  }
292
- function remakeCssVarSelector(selectors, cssPreflightRange) {
296
+ function remakeCssVarSelector(selectors, options) {
297
+ const { cssPreflightRange, cssSelectorReplacement } = options;
293
298
  if (cssPreflightRange === 'all' &&
294
299
  !selectors.includes(':not(not)')) {
295
300
  selectors.push(':not(not)');
296
301
  }
297
- if (!selectors.includes('*')) {
298
- selectors.unshift('*');
302
+ if (cssSelectorReplacement) {
303
+ if (Array.isArray(cssSelectorReplacement.universal)) {
304
+ if (!cssSelectorReplacement.universal.every((x) => {
305
+ return selectors.includes(x);
306
+ }) &&
307
+ !selectors.includes('*')) {
308
+ selectors.unshift('*');
309
+ }
310
+ }
311
+ else if (typeof cssSelectorReplacement.universal === 'string' && !selectors.includes(cssSelectorReplacement.universal) && !selectors.includes('*')) {
312
+ selectors.unshift('*');
313
+ }
299
314
  }
300
315
  return selectors;
301
316
  }
@@ -311,24 +326,26 @@ function remakeCombinatorSelector(selector, cssChildCombinatorReplaceValue) {
311
326
  return selector.replaceAll(BROAD_MATCH_GLOBAL_REGEXP, childCombinatorReplaceValue);
312
327
  }
313
328
  function commonChunkPreflight(node, options) {
314
- node.selector = remakeCombinatorSelector(node.selector, options.cssChildCombinatorReplaceValue);
329
+ const { ctx, cssChildCombinatorReplaceValue, cssInjectPreflight, injectAdditionalCssVarScope } = options;
330
+ node.selector = remakeCombinatorSelector(node.selector, cssChildCombinatorReplaceValue);
315
331
  if (testIfVariablesScope(node)) {
316
- node.selectors = remakeCssVarSelector(node.selectors, options.cssPreflightRange);
332
+ ctx === null || ctx === void 0 ? void 0 : ctx.variablesScopeWeakMap.set(node, VariablesScopeSymbol);
333
+ node.selectors = remakeCssVarSelector(node.selectors, options);
317
334
  node.before(makePseudoVarRule());
318
- if (typeof options.cssInjectPreflight === 'function') {
319
- node.append(...options.cssInjectPreflight());
335
+ if (typeof cssInjectPreflight === 'function') {
336
+ node.append(...cssInjectPreflight());
320
337
  }
321
338
  }
322
- if (options.injectAdditionalCssVarScope && testIfTwBackdrop(node)) {
339
+ if (injectAdditionalCssVarScope && testIfTwBackdrop(node)) {
323
340
  const syntheticRule = new postcss.Rule({
324
341
  selectors: ['*', '::after', '::before'],
325
342
  nodes: initialNodes
326
343
  });
327
- syntheticRule.selectors = remakeCssVarSelector(syntheticRule.selectors, options.cssPreflightRange);
344
+ syntheticRule.selectors = remakeCssVarSelector(syntheticRule.selectors, options);
328
345
  node.before(syntheticRule);
329
346
  node.before(makePseudoVarRule());
330
- if (typeof options.cssInjectPreflight === 'function') {
331
- syntheticRule.append(...options.cssInjectPreflight());
347
+ if (typeof cssInjectPreflight === 'function') {
348
+ syntheticRule.append(...cssInjectPreflight());
332
349
  }
333
350
  }
334
351
  }
@@ -340,22 +357,14 @@ const vitePluginName = 'vite-plugin-uni-app-weapp-tailwindcss-adaptor';
340
357
  function isAtMediaHover(atRule) {
341
358
  return /media\(\s*hover\s*:\s*hover\s*\)/.test(atRule.name) || (atRule.name === 'media' && /\(\s*hover\s*:\s*hover\s*\)/.test(atRule.params));
342
359
  }
343
- const postcssWeappTailwindcss = (options = {
360
+ const postcssWeappTailwindcssPrePlugin = (options = {
344
361
  isMainChunk: true
345
362
  }) => {
346
- const { customRuleCallback, isMainChunk } = options;
347
- const isCustomRuleCallbackFn = typeof customRuleCallback === 'function';
348
- return {
363
+ const { isMainChunk } = options;
364
+ const p = {
349
365
  postcssPlugin,
350
- Once(css) {
351
- isMainChunk &&
352
- css.walkRules((rule) => {
353
- commonChunkPreflight(rule, options);
354
- });
355
- },
356
366
  Rule(rule) {
357
367
  transformSync(rule, options);
358
- isCustomRuleCallbackFn && customRuleCallback(rule, options);
359
368
  },
360
369
  AtRule(atRule) {
361
370
  if (isAtMediaHover(atRule)) {
@@ -364,9 +373,94 @@ const postcssWeappTailwindcss = (options = {
364
373
  }
365
374
  }
366
375
  };
376
+ if (isMainChunk) {
377
+ p.Once = (root) => {
378
+ root.walkRules((rule) => {
379
+ commonChunkPreflight(rule, options);
380
+ });
381
+ };
382
+ }
383
+ return p;
384
+ };
385
+ postcssWeappTailwindcssPrePlugin.postcss = true;
386
+
387
+ const fallback = selectorParser__default["default"]((selectors) => {
388
+ selectors.walk((selector) => {
389
+ var _a, _b;
390
+ if (selector.type === 'universal') {
391
+ (_a = selector.parent) === null || _a === void 0 ? void 0 : _a.remove();
392
+ }
393
+ if (selector.type === 'pseudo' && selector.value === ':is') {
394
+ (_b = selector.parent) === null || _b === void 0 ? void 0 : _b.remove();
395
+ }
396
+ });
397
+ });
398
+ const postcssWeappTailwindcssPostPlugin = (options = {
399
+ isMainChunk: true
400
+ }) => {
401
+ const { customRuleCallback, isMainChunk, ctx } = options;
402
+ const p = {
403
+ postcssPlugin
404
+ };
405
+ if (isMainChunk) {
406
+ p.OnceExit = (root) => {
407
+ root.walkRules((rule) => {
408
+ if (ctx) {
409
+ if (ctx.variablesScopeWeakMap.get(rule) === VariablesScopeSymbol) {
410
+ fallback.transformSync(rule, {
411
+ updateSelector: true,
412
+ lossless: false
413
+ });
414
+ }
415
+ }
416
+ else if (testIfVariablesScope(rule)) {
417
+ fallback.transformSync(rule, {
418
+ updateSelector: true,
419
+ lossless: false
420
+ });
421
+ }
422
+ });
423
+ };
424
+ }
425
+ if (typeof customRuleCallback === 'function') {
426
+ p.Rule = (rule) => {
427
+ customRuleCallback(rule, options);
428
+ };
429
+ }
430
+ return p;
367
431
  };
368
- postcssWeappTailwindcss.postcss = true;
432
+ postcssWeappTailwindcssPostPlugin.postcss = true;
433
+
434
+ function createContext() {
435
+ return {
436
+ variablesScopeWeakMap: new WeakMap()
437
+ };
438
+ }
439
+
440
+ function getPlugins(options) {
441
+ const ctx = createContext();
442
+ options.ctx = ctx;
443
+ const plugins = [
444
+ postcssWeappTailwindcssPrePlugin(options),
445
+ postcssIsPseudoClass__default["default"]({
446
+ specificityMatchingName: 'weapp-tw-ig'
447
+ })
448
+ ];
449
+ if (options.rem2rpx) {
450
+ plugins.push(postcssRem2rpx__default["default"](typeof options.rem2rpx === 'object'
451
+ ? options.rem2rpx
452
+ : {
453
+ rootValue: 32,
454
+ propList: ['*'],
455
+ transformUnit: 'rpx'
456
+ }));
457
+ }
458
+ plugins.push(postcssWeappTailwindcssPostPlugin(options));
459
+ return plugins;
460
+ }
369
461
 
462
+ exports.getPlugins = getPlugins;
370
463
  exports.pluginName = pluginName;
371
- exports.postcssWeappTailwindcss = postcssWeappTailwindcss;
464
+ exports.postcssWeappTailwindcssPostPlugin = postcssWeappTailwindcssPostPlugin;
465
+ exports.postcssWeappTailwindcssPrePlugin = postcssWeappTailwindcssPrePlugin;
372
466
  exports.vitePluginName = vitePluginName;
package/dist/postcss.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './postcss/plugin';
1
+ export * from './postcss/plugins';
package/dist/postcss.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var postcss = require('./postcss-sB1dQbYV.js');
5
+ var postcss = require('./postcss-zkCNv4BC.js');
6
6
  var postcssIsPseudoClass = require('@csstools/postcss-is-pseudo-class');
7
7
  var postcssRem2rpx = require('postcss-rem-to-responsive-pixel');
8
8
  require('postcss-selector-parser');
@@ -18,7 +18,9 @@ var postcssRem2rpx__default = /*#__PURE__*/_interopDefaultCompat(postcssRem2rpx)
18
18
 
19
19
 
20
20
 
21
- exports.postcssWeappTailwindcss = postcss.postcssWeappTailwindcss;
21
+ exports.getPlugins = postcss.getPlugins;
22
+ exports.postcssWeappTailwindcssPostPlugin = postcss.postcssWeappTailwindcssPostPlugin;
23
+ exports.postcssWeappTailwindcssPrePlugin = postcss.postcssWeappTailwindcssPrePlugin;
22
24
  Object.defineProperty(exports, 'postcssIsPseudoClass', {
23
25
  enumerable: true,
24
26
  get: function () { return postcssIsPseudoClass__default["default"]; }
package/dist/postcss.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { p as postcssWeappTailwindcss } from './postcss-4kTT_aj1.mjs';
1
+ export { g as getPlugins, a as postcssWeappTailwindcssPostPlugin, b as postcssWeappTailwindcssPrePlugin } from './postcss-irzTcRfl.mjs';
2
2
  export { default as postcssIsPseudoClass } from '@csstools/postcss-is-pseudo-class';
3
3
  export { default as postcssRem2rpx } from 'postcss-rem-to-responsive-pixel';
4
4
  import 'postcss-selector-parser';
package/dist/types.d.ts CHANGED
@@ -4,6 +4,7 @@ import type { SourceMap } from 'magic-string';
4
4
  import type { GeneratorResult } from '@babel/generator';
5
5
  import type { UserDefinedOptions as rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
6
6
  import type { InjectPreflight } from './postcss/preflight';
7
+ import type { IContext as PostcssContext } from './postcss/plugins/ctx';
7
8
  import type { ICreateCacheReturnType } from "./cache";
8
9
  export type ItemOrItemArray<T> = T | T[];
9
10
  export type AppType = 'uni-app' | 'uni-app-vite' | 'taro' | 'remax' | 'rax' | 'native' | 'kbone' | 'mpx';
@@ -28,6 +29,7 @@ export interface InternalCssSelectorReplacerOptions {
28
29
  export type IStyleHandlerOptions = {
29
30
  customRuleCallback?: CustomRuleCallback;
30
31
  mangleContext?: IMangleScopeContext;
32
+ ctx?: PostcssContext;
31
33
  } & RequiredStyleHandlerOptions;
32
34
  export type JsHandlerReplaceResult = {
33
35
  code: string;
package/dist/vite.js CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var options = require('./options-_u-7p8aC.js');
6
- var postcss = require('./postcss-sB1dQbYV.js');
5
+ var options = require('./options-5eiKwcXx.js');
6
+ var postcss = require('./postcss-zkCNv4BC.js');
7
7
  var defaults = require('./defaults-QOAV8NSV.js');
8
8
  var index = require('./index-z25r_Htj.js');
9
9
  require('magic-string');
@@ -18,8 +18,6 @@ require('@babel/traverse');
18
18
  require('@babel/types');
19
19
  require('htmlparser2');
20
20
  require('postcss');
21
- require('@csstools/postcss-is-pseudo-class');
22
- require('postcss-rem-to-responsive-pixel');
23
21
  require('node:path');
24
22
  require('node:fs');
25
23
  require('semver');
@@ -27,6 +25,8 @@ require('tailwindcss-patch');
27
25
  require('@tailwindcss-mangle/shared');
28
26
  require('lru-cache');
29
27
  require('md5');
28
+ require('@csstools/postcss-is-pseudo-class');
29
+ require('postcss-rem-to-responsive-pixel');
30
30
  require('postcss-selector-parser');
31
31
  require('./defu-KWuJnZLV.js');
32
32
  require('debug');
package/dist/vite.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { g as getOptions, a as createTailwindcssPatcher, _ as __awaiter } from './options-vyKfCeIO.mjs';
2
- import { v as vitePluginName } from './postcss-4kTT_aj1.mjs';
1
+ import { g as getOptions, a as createTailwindcssPatcher, _ as __awaiter } from './options-UXRHB24i.mjs';
2
+ import { v as vitePluginName } from './postcss-irzTcRfl.mjs';
3
3
  import { g as getGroupedEntries } from './defaults-TZpmwtzd.mjs';
4
4
  import { c as createDebug } from './index-06BoOZig.mjs';
5
5
  import 'magic-string';
@@ -14,8 +14,6 @@ import '@babel/traverse';
14
14
  import '@babel/types';
15
15
  import 'htmlparser2';
16
16
  import 'postcss';
17
- import '@csstools/postcss-is-pseudo-class';
18
- import 'postcss-rem-to-responsive-pixel';
19
17
  import 'node:path';
20
18
  import 'node:fs';
21
19
  import 'semver';
@@ -23,6 +21,8 @@ import 'tailwindcss-patch';
23
21
  import '@tailwindcss-mangle/shared';
24
22
  import 'lru-cache';
25
23
  import 'md5';
24
+ import '@csstools/postcss-is-pseudo-class';
25
+ import 'postcss-rem-to-responsive-pixel';
26
26
  import 'postcss-selector-parser';
27
27
  import './defu-ms_ZBCiB.mjs';
28
28
  import 'debug';
package/dist/webpack.js CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var options = require('./options-_u-7p8aC.js');
5
+ var options = require('./options-5eiKwcXx.js');
6
6
  var path = require('node:path');
7
7
  var fs = require('node:fs');
8
- var postcss = require('./postcss-sB1dQbYV.js');
8
+ var postcss = require('./postcss-zkCNv4BC.js');
9
9
  var defaults = require('./defaults-QOAV8NSV.js');
10
10
  var index = require('./index-z25r_Htj.js');
11
11
  require('magic-string');
@@ -20,13 +20,13 @@ require('@babel/traverse');
20
20
  require('@babel/types');
21
21
  require('htmlparser2');
22
22
  require('postcss');
23
- require('@csstools/postcss-is-pseudo-class');
24
- require('postcss-rem-to-responsive-pixel');
25
23
  require('semver');
26
24
  require('tailwindcss-patch');
27
25
  require('@tailwindcss-mangle/shared');
28
26
  require('lru-cache');
29
27
  require('md5');
28
+ require('@csstools/postcss-is-pseudo-class');
29
+ require('postcss-rem-to-responsive-pixel');
30
30
  require('postcss-selector-parser');
31
31
  require('./defu-KWuJnZLV.js');
32
32
  require('debug');
package/dist/webpack.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { g as getOptions, a as createTailwindcssPatcher, _ as __awaiter } from './options-vyKfCeIO.mjs';
1
+ import { g as getOptions, a as createTailwindcssPatcher, _ as __awaiter } from './options-UXRHB24i.mjs';
2
2
  import path from 'node:path';
3
3
  import fs from 'node:fs';
4
- import { a as pluginName } from './postcss-4kTT_aj1.mjs';
4
+ import { p as pluginName } from './postcss-irzTcRfl.mjs';
5
5
  import { g as getGroupedEntries, r as removeExt } from './defaults-TZpmwtzd.mjs';
6
6
  import { c as createDebug } from './index-06BoOZig.mjs';
7
7
  import 'magic-string';
@@ -16,13 +16,13 @@ import '@babel/traverse';
16
16
  import '@babel/types';
17
17
  import 'htmlparser2';
18
18
  import 'postcss';
19
- import '@csstools/postcss-is-pseudo-class';
20
- import 'postcss-rem-to-responsive-pixel';
21
19
  import 'semver';
22
20
  import 'tailwindcss-patch';
23
21
  import '@tailwindcss-mangle/shared';
24
22
  import 'lru-cache';
25
23
  import 'md5';
24
+ import '@csstools/postcss-is-pseudo-class';
25
+ import 'postcss-rem-to-responsive-pixel';
26
26
  import 'postcss-selector-parser';
27
27
  import './defu-ms_ZBCiB.mjs';
28
28
  import 'debug';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weapp-tailwindcss",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "把tailwindcss jit引擎,带给小程序开发者们! bring tailwindcss jit engine to miniprogram developers!",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -1,7 +0,0 @@
1
- import type { PluginCreator } from 'postcss';
2
- import type { IStyleHandlerOptions } from "../types";
3
- export type PostcssWeappTailwindcssRenamePlugin = PluginCreator<IStyleHandlerOptions>;
4
- declare const postcssWeappTailwindcss: PostcssWeappTailwindcssRenamePlugin;
5
- export { postcssWeappTailwindcss };
6
- export { default as postcssIsPseudoClass } from '@csstools/postcss-is-pseudo-class';
7
- export { default as postcssRem2rpx } from 'postcss-rem-to-responsive-pixel';