weapp-tailwindcss 2.11.0 → 3.0.1

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 (51) hide show
  1. package/dist/{gulp → bundlers/gulp}/index.d.ts +1 -1
  2. package/dist/{vite → bundlers/vite}/index.d.ts +1 -1
  3. package/dist/{webpack → bundlers/webpack}/BaseUnifiedPlugin/v5.d.ts +1 -1
  4. package/dist/cli.js +7 -7
  5. package/dist/cli.mjs +7 -7
  6. package/dist/core.js +7 -7
  7. package/dist/core.mjs +7 -7
  8. package/dist/css-macro/index.js +1 -1
  9. package/dist/css-macro/index.mjs +1 -1
  10. package/dist/{defaults-0O-zKoXE.js → defaults-QOAV8NSV.js} +10 -5
  11. package/dist/{defaults-dz6xGhOP.mjs → defaults-TZpmwtzd.mjs} +10 -6
  12. package/dist/defaults.js +2 -1
  13. package/dist/defaults.mjs +2 -1
  14. package/dist/{defu-VMJMz2AB.js → defu-KWuJnZLV.js} +1 -0
  15. package/dist/{defu-NLkZUlr9.mjs → defu-ms_ZBCiB.mjs} +1 -1
  16. package/dist/gulp.d.ts +1 -1
  17. package/dist/gulp.js +7 -7
  18. package/dist/gulp.mjs +7 -7
  19. package/dist/index.js +7 -7
  20. package/dist/index.mjs +7 -7
  21. package/dist/js/handlers.d.ts +0 -1
  22. package/dist/{options-lXV72tWf.js → options-M6TutRrF.js} +70 -186
  23. package/dist/{options-M8pGfjj_.mjs → options-mJwenBmV.mjs} +71 -186
  24. package/dist/postcss/mp.d.ts +1 -1
  25. package/dist/postcss/plugins/ctx.d.ts +4 -0
  26. package/dist/postcss/plugins/index.d.ts +7 -0
  27. package/dist/postcss/plugins/post.d.ts +5 -0
  28. package/dist/postcss/plugins/pre.d.ts +5 -0
  29. package/dist/postcss/shared.d.ts +1 -0
  30. package/dist/postcss/symbols.d.ts +1 -0
  31. package/dist/{postcss-Et8j4ugT.js → postcss-XAQSRPqF.js} +152 -62
  32. package/dist/{postcss-W8i3cl5I.mjs → postcss-kpIT_QQe.mjs} +148 -62
  33. package/dist/postcss.d.ts +1 -1
  34. package/dist/postcss.js +11 -3
  35. package/dist/postcss.mjs +3 -2
  36. package/dist/replace.js +1 -1
  37. package/dist/replace.mjs +1 -1
  38. package/dist/{shared-S0v7ZvWs.mjs → shared-0D5OOeXo.mjs} +10 -1
  39. package/dist/{shared-nXoJWFdz.js → shared-AxeHlAoJ.js} +10 -0
  40. package/dist/types.d.ts +17 -21
  41. package/dist/utils.d.ts +9 -0
  42. package/dist/vite.d.ts +1 -1
  43. package/dist/vite.js +7 -7
  44. package/dist/vite.mjs +7 -7
  45. package/dist/webpack.d.ts +1 -1
  46. package/dist/webpack.js +7 -7
  47. package/dist/webpack.mjs +7 -7
  48. package/package.json +26 -34
  49. package/dist/postcss/plugin.d.ts +0 -6
  50. /package/dist/{webpack → bundlers/webpack}/index.d.ts +0 -0
  51. /package/dist/{webpack → bundlers/webpack}/loaders/weapp-tw-runtime-loader.d.ts +0 -0
@@ -1,33 +1,30 @@
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
- var shared = require('./shared-nXoJWFdz.js');
6
+ var shared = require('./shared-AxeHlAoJ.js');
5
7
  var postcss = require('postcss');
6
- require('@csstools/postcss-is-pseudo-class');
7
8
 
8
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
10
 
11
+ var postcssIsPseudoClass__default = /*#__PURE__*/_interopDefaultCompat(postcssIsPseudoClass);
12
+ var postcssRem2rpx__default = /*#__PURE__*/_interopDefaultCompat(postcssRem2rpx);
10
13
  var selectorParser__default = /*#__PURE__*/_interopDefaultCompat(selectorParser);
11
14
 
12
15
  const createTransform = (rule, options) => {
13
- const { replaceUniversalSelectorWith, escapeMap, mangleContext, cssSelectorReplacement } = options;
14
- const replaceFlag = replaceUniversalSelectorWith !== false;
16
+ const { escapeMap, mangleContext, cssSelectorReplacement } = options;
15
17
  const transform = (selectors) => {
16
18
  selectors.walk((selector) => {
17
- if (selector.type === 'universal') {
18
- if (replaceFlag) {
19
- selector.value = replaceUniversalSelectorWith;
20
- }
21
- else if (cssSelectorReplacement && cssSelectorReplacement.universal) {
22
- selector.value = cssSelectorReplacement.universal;
23
- }
19
+ if (selector.type === 'universal' && cssSelectorReplacement && cssSelectorReplacement.universal) {
20
+ selector.value = shared.composeIsPseudo(cssSelectorReplacement.universal);
24
21
  }
25
22
  if (selector.type === 'selector') {
26
23
  const node = selector.nodes.find((x) => x.type === 'pseudo' && x.value === ':hover');
27
24
  node && selector.remove();
28
25
  }
29
26
  if (selector.type === 'pseudo' && selector.value === ':root' && cssSelectorReplacement && cssSelectorReplacement.root) {
30
- selector.value = cssSelectorReplacement.root;
27
+ selector.value = shared.composeIsPseudo(cssSelectorReplacement.root);
31
28
  }
32
29
  if (selector.type === 'class') {
33
30
  selector.value = shared.internalCssSelectorReplacer(selector.value, {
@@ -244,6 +241,8 @@ var cssVars = [
244
241
  }
245
242
  ];
246
243
 
244
+ const VariablesScopeSymbol = Symbol('VariablesScope');
245
+
247
246
  const initialNodes = cssVars.map((x) => {
248
247
  return new postcss.Declaration({
249
248
  prop: x.prop,
@@ -252,33 +251,35 @@ const initialNodes = cssVars.map((x) => {
252
251
  });
253
252
  const PATTERNS = [/:not\(template\)\s*~\s*:not\(template\)/.source, /:not\(\[hidden\]\)\s*~\s*:not\(\[hidden\]\)/.source].join('|');
254
253
  const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g');
255
- function testIfVariablesScope(node, count = 1) {
254
+ function testIfVariablesScope(node, count = 2) {
256
255
  if (/:?:before/.test(node.selector) && /:?:after/.test(node.selector)) {
257
- for (let i = 0; i < count; i++) {
258
- const tryTestDecl = node.nodes[i];
256
+ const nodes = node.nodes;
257
+ let c = 0;
258
+ for (const tryTestDecl of nodes) {
259
259
  if (tryTestDecl && tryTestDecl.type === 'decl' && tryTestDecl.prop.startsWith('--tw-')) {
260
- continue;
260
+ c++;
261
261
  }
262
- else {
263
- return false;
262
+ if (c >= count) {
263
+ return true;
264
264
  }
265
265
  }
266
- return true;
266
+ return false;
267
267
  }
268
268
  return false;
269
269
  }
270
- function testIfTwBackdrop(node, count = 1) {
270
+ function testIfTwBackdrop(node, count = 2) {
271
271
  if (node.type === 'rule' && node.selector === '::backdrop') {
272
- for (let i = 0; i < count; i++) {
273
- const tryTestDecl = node.nodes[i];
272
+ const nodes = node.nodes;
273
+ let c = 0;
274
+ for (const tryTestDecl of nodes) {
274
275
  if (tryTestDecl && tryTestDecl.type === 'decl' && tryTestDecl.prop.startsWith('--tw-')) {
275
- continue;
276
+ c++;
276
277
  }
277
- else {
278
- return false;
278
+ if (c >= count) {
279
+ return true;
279
280
  }
280
281
  }
281
- return true;
282
+ return false;
282
283
  }
283
284
  return false;
284
285
  }
@@ -292,28 +293,32 @@ function makePseudoVarRule() {
292
293
  }));
293
294
  return pseudoVarRule;
294
295
  }
295
- function remakeCssVarSelector(selectors, cssPreflightRange) {
296
- const idx = selectors.indexOf('*');
297
- if (idx > -1) {
298
- selectors.splice(idx, 1);
299
- }
300
- if (!selectors.includes('view')) {
301
- selectors.push('view');
302
- }
296
+ function remakeCssVarSelector(selectors, options) {
297
+ const { cssPreflightRange, cssSelectorReplacement } = options;
303
298
  if (cssPreflightRange === 'all' &&
304
299
  !selectors.includes(':not(not)')) {
305
300
  selectors.push(':not(not)');
306
301
  }
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
+ }
314
+ }
307
315
  return selectors;
308
316
  }
309
317
  function remakeCombinatorSelector(selector, cssChildCombinatorReplaceValue) {
310
318
  let childCombinatorReplaceValue = 'view + view';
311
- if (Array.isArray(cssChildCombinatorReplaceValue)) {
312
- childCombinatorReplaceValue = cssChildCombinatorReplaceValue
313
- .map((x) => {
314
- return x + ' + ' + x;
315
- })
316
- .join(',');
319
+ if (Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
320
+ const x = shared.composeIsPseudo(cssChildCombinatorReplaceValue);
321
+ childCombinatorReplaceValue = x + ' + ' + x;
317
322
  }
318
323
  else if (typeof cssChildCombinatorReplaceValue === 'string') {
319
324
  childCombinatorReplaceValue = cssChildCombinatorReplaceValue;
@@ -321,24 +326,26 @@ function remakeCombinatorSelector(selector, cssChildCombinatorReplaceValue) {
321
326
  return selector.replaceAll(BROAD_MATCH_GLOBAL_REGEXP, childCombinatorReplaceValue);
322
327
  }
323
328
  function commonChunkPreflight(node, options) {
324
- node.selector = remakeCombinatorSelector(node.selector, options.cssChildCombinatorReplaceValue);
329
+ const { ctx, cssChildCombinatorReplaceValue, cssInjectPreflight, injectAdditionalCssVarScope } = options;
330
+ node.selector = remakeCombinatorSelector(node.selector, cssChildCombinatorReplaceValue);
325
331
  if (testIfVariablesScope(node)) {
326
- 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);
327
334
  node.before(makePseudoVarRule());
328
- if (typeof options.cssInjectPreflight === 'function') {
329
- node.append(...options.cssInjectPreflight());
335
+ if (typeof cssInjectPreflight === 'function') {
336
+ node.append(...cssInjectPreflight());
330
337
  }
331
338
  }
332
- if (options.injectAdditionalCssVarScope && testIfTwBackdrop(node)) {
339
+ if (injectAdditionalCssVarScope && testIfTwBackdrop(node)) {
333
340
  const syntheticRule = new postcss.Rule({
334
- selectors: ['::after', '::before'],
341
+ selectors: ['*', '::after', '::before'],
335
342
  nodes: initialNodes
336
343
  });
337
- syntheticRule.selectors = remakeCssVarSelector(syntheticRule.selectors, options.cssPreflightRange);
344
+ syntheticRule.selectors = remakeCssVarSelector(syntheticRule.selectors, options);
338
345
  node.before(syntheticRule);
339
346
  node.before(makePseudoVarRule());
340
- if (typeof options.cssInjectPreflight === 'function') {
341
- syntheticRule.append(...options.cssInjectPreflight());
347
+ if (typeof cssInjectPreflight === 'function') {
348
+ syntheticRule.append(...cssInjectPreflight());
342
349
  }
343
350
  }
344
351
  }
@@ -347,30 +354,113 @@ const postcssPlugin = 'postcss-weapp-tailwindcss-rename-plugin';
347
354
  const pluginName = 'weapp-tailwindcss-webpack-plugin';
348
355
  const vitePluginName = 'vite-plugin-uni-app-weapp-tailwindcss-adaptor';
349
356
 
350
- const postcssWeappTailwindcss = (options = {
357
+ function isAtMediaHover(atRule) {
358
+ return /media\(\s*hover\s*:\s*hover\s*\)/.test(atRule.name) || (atRule.name === 'media' && /\(\s*hover\s*:\s*hover\s*\)/.test(atRule.params));
359
+ }
360
+ const postcssWeappTailwindcssPrePlugin = (options = {
351
361
  isMainChunk: true
352
362
  }) => {
353
- const { customRuleCallback, isMainChunk } = options;
354
- const isCustomRuleCallbackFn = typeof customRuleCallback === 'function';
355
- return {
363
+ const { isMainChunk } = options;
364
+ const p = {
356
365
  postcssPlugin,
357
- Once(css) {
358
- css.walkRules((rule) => {
359
- transformSync(rule, options);
360
- isMainChunk && commonChunkPreflight(rule, options);
361
- isCustomRuleCallbackFn && customRuleCallback(rule, options);
362
- });
366
+ Rule(rule) {
367
+ transformSync(rule, options);
363
368
  },
364
369
  AtRule(atRule) {
365
- if (atRule.name === 'media' && /\(hover:\s*hover\)/.test(atRule.params)) {
370
+ if (isAtMediaHover(atRule)) {
366
371
  atRule.before(atRule.nodes);
367
372
  atRule.remove();
368
373
  }
369
374
  }
370
375
  };
376
+ if (isMainChunk) {
377
+ p.Once = (root) => {
378
+ root.walkRules((rule) => {
379
+ commonChunkPreflight(rule, options);
380
+ });
381
+ };
382
+ }
383
+ return p;
371
384
  };
372
- postcssWeappTailwindcss.postcss = true;
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;
431
+ };
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
+ }
373
461
 
462
+ exports.getPlugins = getPlugins;
374
463
  exports.pluginName = pluginName;
375
- exports.postcssWeappTailwindcss = postcssWeappTailwindcss;
464
+ exports.postcssWeappTailwindcssPostPlugin = postcssWeappTailwindcssPostPlugin;
465
+ exports.postcssWeappTailwindcssPrePlugin = postcssWeappTailwindcssPrePlugin;
376
466
  exports.vitePluginName = vitePluginName;
@@ -1,27 +1,22 @@
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
- import { i as internalCssSelectorReplacer } from './shared-S0v7ZvWs.mjs';
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
6
 
6
7
  const createTransform = (rule, options) => {
7
- const { replaceUniversalSelectorWith, escapeMap, mangleContext, cssSelectorReplacement } = options;
8
- const replaceFlag = replaceUniversalSelectorWith !== false;
8
+ const { escapeMap, mangleContext, cssSelectorReplacement } = options;
9
9
  const transform = (selectors) => {
10
10
  selectors.walk((selector) => {
11
- if (selector.type === 'universal') {
12
- if (replaceFlag) {
13
- selector.value = replaceUniversalSelectorWith;
14
- }
15
- else if (cssSelectorReplacement && cssSelectorReplacement.universal) {
16
- selector.value = cssSelectorReplacement.universal;
17
- }
11
+ if (selector.type === 'universal' && cssSelectorReplacement && cssSelectorReplacement.universal) {
12
+ selector.value = composeIsPseudo(cssSelectorReplacement.universal);
18
13
  }
19
14
  if (selector.type === 'selector') {
20
15
  const node = selector.nodes.find((x) => x.type === 'pseudo' && x.value === ':hover');
21
16
  node && selector.remove();
22
17
  }
23
18
  if (selector.type === 'pseudo' && selector.value === ':root' && cssSelectorReplacement && cssSelectorReplacement.root) {
24
- selector.value = cssSelectorReplacement.root;
19
+ selector.value = composeIsPseudo(cssSelectorReplacement.root);
25
20
  }
26
21
  if (selector.type === 'class') {
27
22
  selector.value = internalCssSelectorReplacer(selector.value, {
@@ -238,6 +233,8 @@ var cssVars = [
238
233
  }
239
234
  ];
240
235
 
236
+ const VariablesScopeSymbol = Symbol('VariablesScope');
237
+
241
238
  const initialNodes = cssVars.map((x) => {
242
239
  return new Declaration({
243
240
  prop: x.prop,
@@ -246,33 +243,35 @@ const initialNodes = cssVars.map((x) => {
246
243
  });
247
244
  const PATTERNS = [/:not\(template\)\s*~\s*:not\(template\)/.source, /:not\(\[hidden\]\)\s*~\s*:not\(\[hidden\]\)/.source].join('|');
248
245
  const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g');
249
- function testIfVariablesScope(node, count = 1) {
246
+ function testIfVariablesScope(node, count = 2) {
250
247
  if (/:?:before/.test(node.selector) && /:?:after/.test(node.selector)) {
251
- for (let i = 0; i < count; i++) {
252
- const tryTestDecl = node.nodes[i];
248
+ const nodes = node.nodes;
249
+ let c = 0;
250
+ for (const tryTestDecl of nodes) {
253
251
  if (tryTestDecl && tryTestDecl.type === 'decl' && tryTestDecl.prop.startsWith('--tw-')) {
254
- continue;
252
+ c++;
255
253
  }
256
- else {
257
- return false;
254
+ if (c >= count) {
255
+ return true;
258
256
  }
259
257
  }
260
- return true;
258
+ return false;
261
259
  }
262
260
  return false;
263
261
  }
264
- function testIfTwBackdrop(node, count = 1) {
262
+ function testIfTwBackdrop(node, count = 2) {
265
263
  if (node.type === 'rule' && node.selector === '::backdrop') {
266
- for (let i = 0; i < count; i++) {
267
- const tryTestDecl = node.nodes[i];
264
+ const nodes = node.nodes;
265
+ let c = 0;
266
+ for (const tryTestDecl of nodes) {
268
267
  if (tryTestDecl && tryTestDecl.type === 'decl' && tryTestDecl.prop.startsWith('--tw-')) {
269
- continue;
268
+ c++;
270
269
  }
271
- else {
272
- return false;
270
+ if (c >= count) {
271
+ return true;
273
272
  }
274
273
  }
275
- return true;
274
+ return false;
276
275
  }
277
276
  return false;
278
277
  }
@@ -286,28 +285,32 @@ function makePseudoVarRule() {
286
285
  }));
287
286
  return pseudoVarRule;
288
287
  }
289
- function remakeCssVarSelector(selectors, cssPreflightRange) {
290
- const idx = selectors.indexOf('*');
291
- if (idx > -1) {
292
- selectors.splice(idx, 1);
293
- }
294
- if (!selectors.includes('view')) {
295
- selectors.push('view');
296
- }
288
+ function remakeCssVarSelector(selectors, options) {
289
+ const { cssPreflightRange, cssSelectorReplacement } = options;
297
290
  if (cssPreflightRange === 'all' &&
298
291
  !selectors.includes(':not(not)')) {
299
292
  selectors.push(':not(not)');
300
293
  }
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
+ }
306
+ }
301
307
  return selectors;
302
308
  }
303
309
  function remakeCombinatorSelector(selector, cssChildCombinatorReplaceValue) {
304
310
  let childCombinatorReplaceValue = 'view + view';
305
- if (Array.isArray(cssChildCombinatorReplaceValue)) {
306
- childCombinatorReplaceValue = cssChildCombinatorReplaceValue
307
- .map((x) => {
308
- return x + ' + ' + x;
309
- })
310
- .join(',');
311
+ if (Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
312
+ const x = composeIsPseudo(cssChildCombinatorReplaceValue);
313
+ childCombinatorReplaceValue = x + ' + ' + x;
311
314
  }
312
315
  else if (typeof cssChildCombinatorReplaceValue === 'string') {
313
316
  childCombinatorReplaceValue = cssChildCombinatorReplaceValue;
@@ -315,24 +318,26 @@ function remakeCombinatorSelector(selector, cssChildCombinatorReplaceValue) {
315
318
  return selector.replaceAll(BROAD_MATCH_GLOBAL_REGEXP, childCombinatorReplaceValue);
316
319
  }
317
320
  function commonChunkPreflight(node, options) {
318
- node.selector = remakeCombinatorSelector(node.selector, options.cssChildCombinatorReplaceValue);
321
+ const { ctx, cssChildCombinatorReplaceValue, cssInjectPreflight, injectAdditionalCssVarScope } = options;
322
+ node.selector = remakeCombinatorSelector(node.selector, cssChildCombinatorReplaceValue);
319
323
  if (testIfVariablesScope(node)) {
320
- 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);
321
326
  node.before(makePseudoVarRule());
322
- if (typeof options.cssInjectPreflight === 'function') {
323
- node.append(...options.cssInjectPreflight());
327
+ if (typeof cssInjectPreflight === 'function') {
328
+ node.append(...cssInjectPreflight());
324
329
  }
325
330
  }
326
- if (options.injectAdditionalCssVarScope && testIfTwBackdrop(node)) {
331
+ if (injectAdditionalCssVarScope && testIfTwBackdrop(node)) {
327
332
  const syntheticRule = new Rule({
328
- selectors: ['::after', '::before'],
333
+ selectors: ['*', '::after', '::before'],
329
334
  nodes: initialNodes
330
335
  });
331
- syntheticRule.selectors = remakeCssVarSelector(syntheticRule.selectors, options.cssPreflightRange);
336
+ syntheticRule.selectors = remakeCssVarSelector(syntheticRule.selectors, options);
332
337
  node.before(syntheticRule);
333
338
  node.before(makePseudoVarRule());
334
- if (typeof options.cssInjectPreflight === 'function') {
335
- syntheticRule.append(...options.cssInjectPreflight());
339
+ if (typeof cssInjectPreflight === 'function') {
340
+ syntheticRule.append(...cssInjectPreflight());
336
341
  }
337
342
  }
338
343
  }
@@ -341,28 +346,109 @@ const postcssPlugin = 'postcss-weapp-tailwindcss-rename-plugin';
341
346
  const pluginName = 'weapp-tailwindcss-webpack-plugin';
342
347
  const vitePluginName = 'vite-plugin-uni-app-weapp-tailwindcss-adaptor';
343
348
 
344
- const postcssWeappTailwindcss = (options = {
349
+ function isAtMediaHover(atRule) {
350
+ return /media\(\s*hover\s*:\s*hover\s*\)/.test(atRule.name) || (atRule.name === 'media' && /\(\s*hover\s*:\s*hover\s*\)/.test(atRule.params));
351
+ }
352
+ const postcssWeappTailwindcssPrePlugin = (options = {
345
353
  isMainChunk: true
346
354
  }) => {
347
- const { customRuleCallback, isMainChunk } = options;
348
- const isCustomRuleCallbackFn = typeof customRuleCallback === 'function';
349
- return {
355
+ const { isMainChunk } = options;
356
+ const p = {
350
357
  postcssPlugin,
351
- Once(css) {
352
- css.walkRules((rule) => {
353
- transformSync(rule, options);
354
- isMainChunk && commonChunkPreflight(rule, options);
355
- isCustomRuleCallbackFn && customRuleCallback(rule, options);
356
- });
358
+ Rule(rule) {
359
+ transformSync(rule, options);
357
360
  },
358
361
  AtRule(atRule) {
359
- if (atRule.name === 'media' && /\(hover:\s*hover\)/.test(atRule.params)) {
362
+ if (isAtMediaHover(atRule)) {
360
363
  atRule.before(atRule.nodes);
361
364
  atRule.remove();
362
365
  }
363
366
  }
364
367
  };
368
+ if (isMainChunk) {
369
+ p.Once = (root) => {
370
+ root.walkRules((rule) => {
371
+ commonChunkPreflight(rule, options);
372
+ });
373
+ };
374
+ }
375
+ return p;
365
376
  };
366
- postcssWeappTailwindcss.postcss = true;
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;
423
+ };
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
+ }
367
453
 
368
- 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 };
package/dist/postcss.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './postcss/plugin';
1
+ export * from './postcss/plugins';
package/dist/postcss.js CHANGED
@@ -2,10 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var postcss = require('./postcss-Et8j4ugT.js');
5
+ var postcss = require('./postcss-XAQSRPqF.js');
6
6
  var postcssIsPseudoClass = require('@csstools/postcss-is-pseudo-class');
7
+ var postcssRem2rpx = require('postcss-rem-to-responsive-pixel');
7
8
  require('postcss-selector-parser');
8
- require('./shared-nXoJWFdz.js');
9
+ require('./shared-AxeHlAoJ.js');
9
10
  require('@weapp-core/escape');
10
11
  require('@ast-core/escape');
11
12
  require('postcss');
@@ -13,11 +14,18 @@ require('postcss');
13
14
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
15
 
15
16
  var postcssIsPseudoClass__default = /*#__PURE__*/_interopDefaultCompat(postcssIsPseudoClass);
17
+ var postcssRem2rpx__default = /*#__PURE__*/_interopDefaultCompat(postcssRem2rpx);
16
18
 
17
19
 
18
20
 
19
- exports.postcssWeappTailwindcss = postcss.postcssWeappTailwindcss;
21
+ exports.getPlugins = postcss.getPlugins;
22
+ exports.postcssWeappTailwindcssPostPlugin = postcss.postcssWeappTailwindcssPostPlugin;
23
+ exports.postcssWeappTailwindcssPrePlugin = postcss.postcssWeappTailwindcssPrePlugin;
20
24
  Object.defineProperty(exports, 'postcssIsPseudoClass', {
21
25
  enumerable: true,
22
26
  get: function () { return postcssIsPseudoClass__default["default"]; }
23
27
  });
28
+ Object.defineProperty(exports, 'postcssRem2rpx', {
29
+ enumerable: true,
30
+ get: function () { return postcssRem2rpx__default["default"]; }
31
+ });
package/dist/postcss.mjs CHANGED
@@ -1,7 +1,8 @@
1
- export { p as postcssWeappTailwindcss } from './postcss-W8i3cl5I.mjs';
1
+ export { g as getPlugins, a as postcssWeappTailwindcssPostPlugin, b as postcssWeappTailwindcssPrePlugin } from './postcss-kpIT_QQe.mjs';
2
2
  export { default as postcssIsPseudoClass } from '@csstools/postcss-is-pseudo-class';
3
+ export { default as postcssRem2rpx } from 'postcss-rem-to-responsive-pixel';
3
4
  import 'postcss-selector-parser';
4
- import './shared-S0v7ZvWs.mjs';
5
+ import './shared-0D5OOeXo.mjs';
5
6
  import '@weapp-core/escape';
6
7
  import '@ast-core/escape';
7
8
  import 'postcss';
package/dist/replace.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var escape = require('@weapp-core/escape');
6
6
  require('@ast-core/escape');
7
- var shared = require('./shared-nXoJWFdz.js');
7
+ var shared = require('./shared-AxeHlAoJ.js');
8
8
 
9
9
  function replaceWxml(original, options = {
10
10
  keepEOL: false,