weapp-tailwindcss 3.4.0-alpha.0 → 3.4.0-alpha.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/babel/index.d.ts +16 -0
- package/dist/bundlers/gulp/index.d.ts +8 -0
- package/dist/bundlers/vite/index.d.ts +3 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +8 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +8 -0
- package/dist/bundlers/webpack/index.d.ts +1 -0
- package/dist/{weapp-tw-runtime-loader.d.ts → bundlers/webpack/loaders/weapp-tw-runtime-loader.d.ts} +2 -4
- package/dist/cache/index.d.ts +32 -0
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +51 -1760
- package/dist/cli.mjs +45 -34
- package/dist/constants-CFM1J-h1.js +42 -0
- package/dist/constants-Dy2Dd3Fz.mjs +36 -0
- package/dist/constants.d.ts +7 -0
- package/dist/core.d.ts +2 -16
- package/dist/core.js +60 -1775
- package/dist/core.mjs +60 -46
- package/dist/css-macro/constants.d.ts +14 -0
- package/dist/css-macro/index.d.ts +4 -7
- package/dist/css-macro/index.js +30 -140
- package/dist/css-macro/index.mjs +28 -35
- package/dist/css-macro/postcss.d.ts +3 -5
- package/dist/css-macro/postcss.js +46 -99
- package/dist/css-macro/postcss.mjs +45 -54
- package/dist/debug/index.d.ts +2 -0
- package/dist/defaults-DW-EahCC.js +145 -0
- package/dist/defaults-w3rlKQwe.mjs +139 -0
- package/dist/defaults.d.ts +2 -16
- package/dist/defaults.js +7 -208
- package/dist/defaults.mjs +4 -9
- package/dist/defu-Cdz2PomB.js +60 -0
- package/dist/defu-n46TJT6t.mjs +57 -0
- package/dist/env.d.ts +2 -0
- package/dist/escape.d.ts +4 -0
- package/dist/extractors/split.d.ts +3 -0
- package/dist/gulp.d.ts +1 -26
- package/dist/gulp.js +38 -1898
- package/dist/gulp.mjs +30 -15
- package/dist/index-B2TNoaOv.mjs +134 -0
- package/dist/index-B5NiRecR.js +130 -0
- package/dist/index-BEIjgKpF.mjs +11 -0
- package/dist/index-BPzIdybK.mjs +513 -0
- package/dist/index-DeW_zXzo.mjs +124 -0
- package/dist/index-DmzxhHCX.js +136 -0
- package/dist/index-DwZHOkK3.js +526 -0
- package/dist/index-HC-Qkn0i.js +17 -0
- package/dist/index.d.ts +4 -17
- package/dist/index.js +43 -2291
- package/dist/index.mjs +33 -23
- package/dist/js/handlers.d.ts +13 -0
- package/dist/js/index.d.ts +7 -0
- package/dist/mangle/index.d.ts +8 -0
- package/dist/options-7EjuAISl.mjs +869 -0
- package/dist/options-C-rvBixk.js +901 -0
- package/dist/options.d.ts +2 -0
- package/dist/postcss/cssVars.d.ts +5 -0
- package/dist/postcss/index.d.ts +3 -0
- package/dist/postcss/mp.d.ts +8 -0
- package/dist/postcss/plugins/ctx.d.ts +6 -0
- package/dist/postcss/plugins/index.d.ts +7 -0
- package/dist/postcss/plugins/post.d.ts +5 -0
- package/dist/postcss/plugins/pre.d.ts +5 -0
- package/dist/postcss/preflight.d.ts +3 -0
- package/dist/postcss/selectorParser.d.ts +6 -0
- package/dist/postcss/shared.d.ts +3 -0
- package/dist/postcss/symbols.d.ts +1 -0
- package/dist/postcss.d.ts +1 -23
- package/dist/postcss.js +22 -598
- package/dist/postcss.mjs +8 -17
- package/dist/reg.d.ts +1 -0
- package/dist/replace.d.ts +3 -19
- package/dist/replace.js +42 -93
- package/dist/replace.mjs +26 -30
- package/dist/shared-DbJl6i6a.mjs +25 -0
- package/dist/shared-hzYeE1wX.js +28 -0
- package/dist/tailwindcss/patcher.d.ts +3 -0
- package/dist/types.d.ts +165 -0
- package/dist/utils.d.ts +18 -0
- package/dist/v5-BD9-sqra.mjs +174 -0
- package/dist/v5-Ch6783yy.js +181 -0
- package/dist/vite.d.ts +1 -22
- package/dist/vite.js +36 -1947
- package/dist/vite.mjs +28 -15
- package/dist/weapp-tw-runtime-loader.js +14 -41
- package/dist/weapp-tw-runtime-loader.mjs +8 -12
- package/dist/webpack.d.ts +1 -26
- package/dist/webpack.js +37 -1994
- package/dist/webpack.mjs +29 -15
- package/dist/webpack4.d.ts +1 -27
- package/dist/webpack4.js +190 -1979
- package/dist/webpack4.mjs +188 -211
- package/dist/wxml/Tokenizer.d.ts +31 -0
- package/dist/wxml/index.d.ts +2 -0
- package/dist/wxml/shared.d.ts +2 -0
- package/dist/wxml/utils.d.ts +13 -0
- package/package.json +3 -3
- package/dist/chunk-257YPDSI.mjs +0 -173
- package/dist/chunk-75EWCRQW.mjs +0 -13
- package/dist/chunk-AB467PG7.mjs +0 -43
- package/dist/chunk-E7XGHGC7.mjs +0 -62
- package/dist/chunk-GUE4UCRJ.mjs +0 -126
- package/dist/chunk-IOYI6MSW.mjs +0 -533
- package/dist/chunk-LDWI65M5.mjs +0 -152
- package/dist/chunk-NVFWRLOI.mjs +0 -27
- package/dist/chunk-ORMKM6ZA.mjs +0 -30
- package/dist/chunk-PC4B5JJB.mjs +0 -953
- package/dist/chunk-SRLZU2YE.mjs +0 -95
- package/dist/chunk-VECXHWWG.mjs +0 -31
- package/dist/chunk-VN37QGSM.mjs +0 -216
- package/dist/cli.d.mts +0 -2
- package/dist/core.d.mts +0 -22
- package/dist/css-macro/index.d.mts +0 -18
- package/dist/css-macro/postcss.d.mts +0 -7
- package/dist/defaults.d.mts +0 -16
- package/dist/gulp.d.mts +0 -26
- package/dist/index.d.mts +0 -17
- package/dist/postcss.d.mts +0 -23
- package/dist/replace.d.mts +0 -19
- package/dist/types-DSNuiOhH.d.mts +0 -519
- package/dist/types-DSNuiOhH.d.ts +0 -519
- package/dist/vite.d.mts +0 -22
- package/dist/weapp-tw-runtime-loader.d.mts +0 -7
- package/dist/webpack.d.mts +0 -26
- package/dist/webpack4.d.mts +0 -27
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var options = require('./options-C-rvBixk.js');
|
|
4
|
+
var index = require('./index-DwZHOkK3.js');
|
|
5
|
+
var defaults = require('./defaults-DW-EahCC.js');
|
|
6
|
+
var index$1 = require('./index-HC-Qkn0i.js');
|
|
7
|
+
|
|
8
|
+
const debug = index$1.createDebug();
|
|
9
|
+
function UnifiedViteWeappTailwindcssPlugin(options$1 = {}) {
|
|
10
|
+
const opts = options.getOptions(options$1);
|
|
11
|
+
const { disabled, onEnd, onLoad, onStart, onUpdate, templateHandler, styleHandler, patch, jsHandler, mainCssChunkMatcher, appType, setMangleRuntimeSet, cache, twPatcher, } = opts;
|
|
12
|
+
if (disabled) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
patch === null || patch === void 0 ? void 0 : patch();
|
|
16
|
+
onLoad();
|
|
17
|
+
return {
|
|
18
|
+
name: index.vitePluginName,
|
|
19
|
+
enforce: 'post',
|
|
20
|
+
generateBundle(opt, bundle) {
|
|
21
|
+
return options.__awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
debug('start');
|
|
23
|
+
onStart();
|
|
24
|
+
const entries = Object.entries(bundle);
|
|
25
|
+
const groupedEntries = defaults.getGroupedEntries(entries, opts);
|
|
26
|
+
const runtimeSet = twPatcher.getClassSet();
|
|
27
|
+
setMangleRuntimeSet(runtimeSet);
|
|
28
|
+
debug('get runtimeSet, class count: %d', runtimeSet.size);
|
|
29
|
+
if (Array.isArray(groupedEntries.html)) {
|
|
30
|
+
let noCachedCount = 0;
|
|
31
|
+
for (let i = 0; i < groupedEntries.html.length; i++) {
|
|
32
|
+
const [file, originalSource] = groupedEntries.html[i];
|
|
33
|
+
const oldVal = originalSource.source.toString();
|
|
34
|
+
const hash = cache.computeHash(oldVal);
|
|
35
|
+
cache.calcHashValueChanged(file, hash);
|
|
36
|
+
yield cache.process(file, () => {
|
|
37
|
+
const source = cache.get(file);
|
|
38
|
+
if (source) {
|
|
39
|
+
originalSource.source = source;
|
|
40
|
+
debug('html cache hit: %s', file);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}, () => options.__awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
originalSource.source = yield templateHandler(oldVal, {
|
|
47
|
+
runtimeSet,
|
|
48
|
+
});
|
|
49
|
+
onUpdate(file, oldVal, originalSource.source);
|
|
50
|
+
debug('html handle: %s', file);
|
|
51
|
+
noCachedCount++;
|
|
52
|
+
return {
|
|
53
|
+
key: file,
|
|
54
|
+
source: originalSource.source,
|
|
55
|
+
};
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
debug('html handle finish, total: %d, no-cached: %d', groupedEntries.html.length, noCachedCount);
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(groupedEntries.js)) {
|
|
61
|
+
let noCachedCount = 0;
|
|
62
|
+
for (let i = 0; i < groupedEntries.js.length; i++) {
|
|
63
|
+
const [file, originalSource] = groupedEntries.js[i];
|
|
64
|
+
const rawSource = originalSource.code;
|
|
65
|
+
const hash = cache.computeHash(rawSource);
|
|
66
|
+
cache.calcHashValueChanged(file, hash);
|
|
67
|
+
yield cache.process(file, () => {
|
|
68
|
+
const source = cache.get(file);
|
|
69
|
+
if (source) {
|
|
70
|
+
originalSource.code = source;
|
|
71
|
+
debug('js cache hit: %s', file);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}, () => options.__awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const mapFilename = `${file}.map`;
|
|
78
|
+
const hasMap = Boolean(bundle[mapFilename]);
|
|
79
|
+
const { code, map } = yield jsHandler(rawSource, runtimeSet, {
|
|
80
|
+
generateMap: hasMap,
|
|
81
|
+
});
|
|
82
|
+
originalSource.code = code;
|
|
83
|
+
onUpdate(file, rawSource, code);
|
|
84
|
+
debug('js handle: %s', file);
|
|
85
|
+
noCachedCount++;
|
|
86
|
+
if (hasMap && map) {
|
|
87
|
+
bundle[mapFilename].source = map.toString();
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
key: file,
|
|
91
|
+
source: code,
|
|
92
|
+
};
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
debug('js handle finish, total: %d, no-cached: %d', groupedEntries.js.length, noCachedCount);
|
|
96
|
+
}
|
|
97
|
+
if (Array.isArray(groupedEntries.css)) {
|
|
98
|
+
let noCachedCount = 0;
|
|
99
|
+
for (let i = 0; i < groupedEntries.css.length; i++) {
|
|
100
|
+
const [file, originalSource] = groupedEntries.css[i];
|
|
101
|
+
const rawSource = originalSource.source.toString();
|
|
102
|
+
const hash = cache.computeHash(rawSource);
|
|
103
|
+
cache.calcHashValueChanged(file, hash);
|
|
104
|
+
yield cache.process(file, () => {
|
|
105
|
+
const source = cache.get(file);
|
|
106
|
+
if (source) {
|
|
107
|
+
originalSource.source = source;
|
|
108
|
+
debug('css cache hit: %s', file);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}, () => options.__awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
const css = yield styleHandler(rawSource, {
|
|
115
|
+
isMainChunk: mainCssChunkMatcher(originalSource.fileName, appType),
|
|
116
|
+
});
|
|
117
|
+
originalSource.source = css;
|
|
118
|
+
onUpdate(file, rawSource, css);
|
|
119
|
+
debug('css handle: %s', file);
|
|
120
|
+
noCachedCount++;
|
|
121
|
+
return {
|
|
122
|
+
key: file,
|
|
123
|
+
source: css,
|
|
124
|
+
};
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
debug('css handle finish, total: %d, no-cached: %d', groupedEntries.css.length, noCachedCount);
|
|
128
|
+
}
|
|
129
|
+
onEnd();
|
|
130
|
+
debug('end');
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
exports.UnifiedViteWeappTailwindcssPlugin = UnifiedViteWeappTailwindcssPlugin;
|
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var postcssIsPseudoClass = require('@csstools/postcss-is-pseudo-class');
|
|
4
|
+
var postcssRem2rpx = require('postcss-rem-to-responsive-pixel');
|
|
5
|
+
var selectorParser = require('postcss-selector-parser');
|
|
6
|
+
var shared = require('./shared-hzYeE1wX.js');
|
|
7
|
+
var postcss = require('postcss');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var postcssIsPseudoClass__default = /*#__PURE__*/_interopDefaultCompat(postcssIsPseudoClass);
|
|
12
|
+
var postcssRem2rpx__default = /*#__PURE__*/_interopDefaultCompat(postcssRem2rpx);
|
|
13
|
+
var selectorParser__default = /*#__PURE__*/_interopDefaultCompat(selectorParser);
|
|
14
|
+
|
|
15
|
+
function createRuleTransform(rule, options) {
|
|
16
|
+
const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
|
|
17
|
+
const transform = (selectors) => {
|
|
18
|
+
selectors.walk((selector) => {
|
|
19
|
+
if (selector.type === 'universal' && cssSelectorReplacement && cssSelectorReplacement.universal) {
|
|
20
|
+
selector.value = shared.composeIsPseudo(cssSelectorReplacement.universal);
|
|
21
|
+
}
|
|
22
|
+
if (cssRemoveHoverPseudoClass && selector.type === 'selector') {
|
|
23
|
+
const node = selector.nodes.find(x => x.type === 'pseudo' && x.value === ':hover');
|
|
24
|
+
node && selector.remove();
|
|
25
|
+
}
|
|
26
|
+
if (selector.type === 'pseudo'
|
|
27
|
+
&& selector.value === ':root'
|
|
28
|
+
&& cssSelectorReplacement
|
|
29
|
+
&& cssSelectorReplacement.root) {
|
|
30
|
+
selector.value = shared.composeIsPseudo(cssSelectorReplacement.root);
|
|
31
|
+
}
|
|
32
|
+
if (selector.type === 'class') {
|
|
33
|
+
selector.value = shared.internalCssSelectorReplacer(selector.value, {
|
|
34
|
+
escapeMap,
|
|
35
|
+
mangleContext,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
if (selectors.length === 0) {
|
|
40
|
+
rule.remove();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return transform;
|
|
44
|
+
}
|
|
45
|
+
function getRuleTransformer(rule, options) {
|
|
46
|
+
return selectorParser__default["default"](createRuleTransform(rule, options));
|
|
47
|
+
}
|
|
48
|
+
function ruleTransformSync(rule, options) {
|
|
49
|
+
const transformer = getRuleTransformer(rule, options);
|
|
50
|
+
return transformer.transformSync(rule, {
|
|
51
|
+
lossless: false,
|
|
52
|
+
updateSelector: true,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function isOnlyBeforeAndAfterPseudoElement(node) {
|
|
56
|
+
let b = false;
|
|
57
|
+
let a = false;
|
|
58
|
+
selectorParser__default["default"]((selectors) => {
|
|
59
|
+
selectors.walkPseudos((s) => {
|
|
60
|
+
var _a;
|
|
61
|
+
if (((_a = s.parent) === null || _a === void 0 ? void 0 : _a.length) === 1) {
|
|
62
|
+
if (/^:?:before$/.test(s.value)) {
|
|
63
|
+
b = true;
|
|
64
|
+
}
|
|
65
|
+
if (/^:?:after$/.test(s.value)) {
|
|
66
|
+
a = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}).astSync(node);
|
|
71
|
+
return b && a;
|
|
72
|
+
}
|
|
73
|
+
const fallbackRemove = selectorParser__default["default"]((selectors) => {
|
|
74
|
+
selectors.walk((selector) => {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
if (selector.type === 'universal') {
|
|
77
|
+
(_a = selector.parent) === null || _a === void 0 ? void 0 : _a.remove();
|
|
78
|
+
}
|
|
79
|
+
if (selector.type === 'pseudo' && selector.value === ':is') {
|
|
80
|
+
(_b = selector.parent) === null || _b === void 0 ? void 0 : _b.remove();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
var cssVars = [
|
|
86
|
+
{
|
|
87
|
+
prop: '--tw-border-spacing-x',
|
|
88
|
+
value: '0',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
prop: '--tw-border-spacing-y',
|
|
92
|
+
value: '0',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
prop: '--tw-translate-x',
|
|
96
|
+
value: '0',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
prop: '--tw-translate-y',
|
|
100
|
+
value: '0',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
prop: '--tw-rotate',
|
|
104
|
+
value: '0',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
prop: '--tw-skew-x',
|
|
108
|
+
value: '0',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
prop: '--tw-skew-y',
|
|
112
|
+
value: '0',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
prop: '--tw-scale-x',
|
|
116
|
+
value: '1',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
prop: '--tw-scale-y',
|
|
120
|
+
value: '1',
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
prop: '--tw-pan-x',
|
|
124
|
+
value: ' ',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
prop: '--tw-pan-y',
|
|
128
|
+
value: ' ',
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
prop: '--tw-pinch-zoom',
|
|
132
|
+
value: ' ',
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
prop: '--tw-scroll-snap-strictness',
|
|
136
|
+
value: 'proximity',
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
prop: '--tw-gradient-from-position',
|
|
140
|
+
value: ' ',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
prop: '--tw-gradient-via-position',
|
|
144
|
+
value: ' ',
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
prop: '--tw-gradient-to-position',
|
|
148
|
+
value: ' ',
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
prop: '--tw-ordinal',
|
|
152
|
+
value: ' ',
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
prop: '--tw-slashed-zero',
|
|
156
|
+
value: ' ',
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
prop: '--tw-numeric-figure',
|
|
160
|
+
value: ' ',
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
prop: '--tw-numeric-spacing',
|
|
164
|
+
value: ' ',
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
prop: '--tw-numeric-fraction',
|
|
168
|
+
value: ' ',
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
prop: '--tw-ring-inset',
|
|
172
|
+
value: ' ',
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
prop: '--tw-ring-offset-width',
|
|
176
|
+
value: '0px',
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
prop: '--tw-ring-offset-color',
|
|
180
|
+
value: '#fff',
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
prop: '--tw-ring-color',
|
|
184
|
+
value: 'rgb(59 130 246 / 0.5)',
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
prop: '--tw-ring-offset-shadow',
|
|
188
|
+
value: '0 0 #0000',
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
prop: '--tw-ring-shadow',
|
|
192
|
+
value: '0 0 #0000',
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
prop: '--tw-shadow',
|
|
196
|
+
value: '0 0 #0000',
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
prop: '--tw-shadow-colored',
|
|
200
|
+
value: '0 0 #0000',
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
prop: '--tw-blur',
|
|
204
|
+
value: ' ',
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
prop: '--tw-brightness',
|
|
208
|
+
value: ' ',
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
prop: '--tw-contrast',
|
|
212
|
+
value: ' ',
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
prop: '--tw-grayscale',
|
|
216
|
+
value: ' ',
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
prop: '--tw-hue-rotate',
|
|
220
|
+
value: ' ',
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
prop: '--tw-invert',
|
|
224
|
+
value: ' ',
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
prop: '--tw-saturate',
|
|
228
|
+
value: ' ',
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
prop: '--tw-sepia',
|
|
232
|
+
value: ' ',
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
prop: '--tw-drop-shadow',
|
|
236
|
+
value: ' ',
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
prop: '--tw-backdrop-blur',
|
|
240
|
+
value: ' ',
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
prop: '--tw-backdrop-brightness',
|
|
244
|
+
value: ' ',
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
prop: '--tw-backdrop-contrast',
|
|
248
|
+
value: ' ',
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
prop: '--tw-backdrop-grayscale',
|
|
252
|
+
value: ' ',
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
prop: '--tw-backdrop-hue-rotate',
|
|
256
|
+
value: ' ',
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
prop: '--tw-backdrop-invert',
|
|
260
|
+
value: ' ',
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
prop: '--tw-backdrop-opacity',
|
|
264
|
+
value: ' ',
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
prop: '--tw-backdrop-saturate',
|
|
268
|
+
value: ' ',
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
prop: '--tw-backdrop-sepia',
|
|
272
|
+
value: ' ',
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
prop: '--tw-contain-size',
|
|
276
|
+
value: ' ',
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
prop: '--tw-contain-layout',
|
|
280
|
+
value: ' ',
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
prop: '--tw-contain-paint',
|
|
284
|
+
value: ' ',
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
prop: '--tw-contain-style',
|
|
288
|
+
value: ' ',
|
|
289
|
+
},
|
|
290
|
+
];
|
|
291
|
+
|
|
292
|
+
const initialNodes = cssVars.map((x) => {
|
|
293
|
+
return new postcss.Declaration({
|
|
294
|
+
prop: x.prop,
|
|
295
|
+
value: x.value,
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
const PATTERNS = [
|
|
299
|
+
/:not\(template\)\s*[~+]\s*:not\(template\)/.source,
|
|
300
|
+
/:not\(\[hidden\]\)\s*[~+]\s*:not\(\[hidden\]\)/.source,
|
|
301
|
+
].join('|');
|
|
302
|
+
const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g');
|
|
303
|
+
function testIfVariablesScope(node, count = 2) {
|
|
304
|
+
if (isOnlyBeforeAndAfterPseudoElement(node)) {
|
|
305
|
+
const nodes = node.nodes;
|
|
306
|
+
let c = 0;
|
|
307
|
+
for (const tryTestDecl of nodes) {
|
|
308
|
+
if (tryTestDecl && tryTestDecl.type === 'decl' && tryTestDecl.prop.startsWith('--tw-')) {
|
|
309
|
+
c++;
|
|
310
|
+
}
|
|
311
|
+
if (c >= count) {
|
|
312
|
+
return true;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
function testIfTwBackdrop(node, count = 2) {
|
|
320
|
+
if (node.type === 'rule' && node.selector === '::backdrop') {
|
|
321
|
+
const nodes = node.nodes;
|
|
322
|
+
let c = 0;
|
|
323
|
+
for (const tryTestDecl of nodes) {
|
|
324
|
+
if (tryTestDecl && tryTestDecl.type === 'decl' && tryTestDecl.prop.startsWith('--tw-')) {
|
|
325
|
+
c++;
|
|
326
|
+
}
|
|
327
|
+
if (c >= count) {
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
function makePseudoVarRule() {
|
|
336
|
+
const pseudoVarRule = new postcss.Rule({
|
|
337
|
+
selector: '::before,::after',
|
|
338
|
+
});
|
|
339
|
+
pseudoVarRule.append(new postcss.Declaration({
|
|
340
|
+
prop: '--tw-content',
|
|
341
|
+
value: '""',
|
|
342
|
+
}));
|
|
343
|
+
return pseudoVarRule;
|
|
344
|
+
}
|
|
345
|
+
function remakeCssVarSelector(selectors, options) {
|
|
346
|
+
const { cssPreflightRange, cssSelectorReplacement } = options;
|
|
347
|
+
if (cssPreflightRange === 'all'
|
|
348
|
+
&& !selectors.includes(':not(not)')) {
|
|
349
|
+
selectors.push(':not(not)');
|
|
350
|
+
}
|
|
351
|
+
if (cssSelectorReplacement) {
|
|
352
|
+
if (Array.isArray(cssSelectorReplacement.universal)) {
|
|
353
|
+
if (!cssSelectorReplacement.universal.every((x) => {
|
|
354
|
+
return selectors.includes(x);
|
|
355
|
+
})
|
|
356
|
+
&& !selectors.includes('*')) {
|
|
357
|
+
selectors.unshift('*');
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
else if (typeof cssSelectorReplacement.universal === 'string'
|
|
361
|
+
&& !selectors.includes(cssSelectorReplacement.universal)
|
|
362
|
+
&& !selectors.includes('*')) {
|
|
363
|
+
selectors.unshift('*');
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return selectors;
|
|
367
|
+
}
|
|
368
|
+
function remakeCombinatorSelector(selector, cssChildCombinatorReplaceValue) {
|
|
369
|
+
let childCombinatorReplaceValue = 'view + view';
|
|
370
|
+
if (Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
|
|
371
|
+
const x = shared.composeIsPseudo(cssChildCombinatorReplaceValue);
|
|
372
|
+
childCombinatorReplaceValue = `${x} + ${x}`;
|
|
373
|
+
}
|
|
374
|
+
else if (typeof cssChildCombinatorReplaceValue === 'string') {
|
|
375
|
+
childCombinatorReplaceValue = cssChildCombinatorReplaceValue;
|
|
376
|
+
}
|
|
377
|
+
return selector.replaceAll(BROAD_MATCH_GLOBAL_REGEXP, childCombinatorReplaceValue);
|
|
378
|
+
}
|
|
379
|
+
function commonChunkPreflight(node, options) {
|
|
380
|
+
const { ctx, cssChildCombinatorReplaceValue, cssInjectPreflight, injectAdditionalCssVarScope } = options;
|
|
381
|
+
node.selector = remakeCombinatorSelector(node.selector, cssChildCombinatorReplaceValue);
|
|
382
|
+
if (testIfVariablesScope(node)) {
|
|
383
|
+
ctx === null || ctx === void 0 ? void 0 : ctx.markVariablesScope(node);
|
|
384
|
+
node.selectors = remakeCssVarSelector(node.selectors, options);
|
|
385
|
+
node.before(makePseudoVarRule());
|
|
386
|
+
if (typeof cssInjectPreflight === 'function') {
|
|
387
|
+
node.append(...cssInjectPreflight());
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if (injectAdditionalCssVarScope && testIfTwBackdrop(node)) {
|
|
391
|
+
const syntheticRule = new postcss.Rule({
|
|
392
|
+
selectors: ['*', '::after', '::before'],
|
|
393
|
+
nodes: initialNodes,
|
|
394
|
+
});
|
|
395
|
+
syntheticRule.selectors = remakeCssVarSelector(syntheticRule.selectors, options);
|
|
396
|
+
node.before(syntheticRule);
|
|
397
|
+
node.before(makePseudoVarRule());
|
|
398
|
+
if (typeof cssInjectPreflight === 'function') {
|
|
399
|
+
syntheticRule.append(...cssInjectPreflight());
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const postcssPlugin = 'postcss-weapp-tailwindcss-rename-plugin';
|
|
405
|
+
const pluginName = 'weapp-tailwindcss-webpack-plugin';
|
|
406
|
+
const vitePluginName = 'vite-plugin-uni-app-weapp-tailwindcss-adaptor';
|
|
407
|
+
const WEAPP_TW_REQUIRED_NODE_VERSION = '16.6.0';
|
|
408
|
+
|
|
409
|
+
function isAtMediaHover(atRule) {
|
|
410
|
+
return (/media\(\s*hover\s*:\s*hover\s*\)/.test(atRule.name)
|
|
411
|
+
|| (atRule.name === 'media' && /\(\s*hover\s*:\s*hover\s*\)/.test(atRule.params)));
|
|
412
|
+
}
|
|
413
|
+
const postcssWeappTailwindcssPrePlugin = (options = {
|
|
414
|
+
isMainChunk: true,
|
|
415
|
+
}) => {
|
|
416
|
+
const { isMainChunk } = options;
|
|
417
|
+
const p = {
|
|
418
|
+
postcssPlugin,
|
|
419
|
+
Rule(rule) {
|
|
420
|
+
ruleTransformSync(rule, options);
|
|
421
|
+
},
|
|
422
|
+
AtRule(atRule) {
|
|
423
|
+
if (isAtMediaHover(atRule)) {
|
|
424
|
+
if (atRule.nodes) {
|
|
425
|
+
atRule.replaceWith(atRule.nodes);
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
atRule.remove();
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
};
|
|
433
|
+
if (isMainChunk) {
|
|
434
|
+
p.Once = (root) => {
|
|
435
|
+
root.walkRules((rule) => {
|
|
436
|
+
commonChunkPreflight(rule, options);
|
|
437
|
+
});
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
return p;
|
|
441
|
+
};
|
|
442
|
+
postcssWeappTailwindcssPrePlugin.postcss = true;
|
|
443
|
+
|
|
444
|
+
const postcssWeappTailwindcssPostPlugin = (options = {
|
|
445
|
+
isMainChunk: true,
|
|
446
|
+
}) => {
|
|
447
|
+
const { customRuleCallback, isMainChunk, ctx } = options;
|
|
448
|
+
const p = {
|
|
449
|
+
postcssPlugin,
|
|
450
|
+
};
|
|
451
|
+
if (isMainChunk) {
|
|
452
|
+
p.OnceExit = (root) => {
|
|
453
|
+
root.walkRules((rule) => {
|
|
454
|
+
if (ctx) {
|
|
455
|
+
if (ctx.isVariablesScope(rule)) {
|
|
456
|
+
fallbackRemove.transformSync(rule, {
|
|
457
|
+
updateSelector: true,
|
|
458
|
+
lossless: false,
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
else if (testIfVariablesScope(rule)) {
|
|
463
|
+
fallbackRemove.transformSync(rule, {
|
|
464
|
+
updateSelector: true,
|
|
465
|
+
lossless: false,
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
if (typeof customRuleCallback === 'function') {
|
|
472
|
+
p.Rule = (rule) => {
|
|
473
|
+
customRuleCallback(rule, options);
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
return p;
|
|
477
|
+
};
|
|
478
|
+
postcssWeappTailwindcssPostPlugin.postcss = true;
|
|
479
|
+
|
|
480
|
+
const VariablesScopeSymbol = Symbol('VariablesScope');
|
|
481
|
+
|
|
482
|
+
function createContext() {
|
|
483
|
+
const variablesScopeWeakMap = new WeakMap();
|
|
484
|
+
function isVariablesScope(rule) {
|
|
485
|
+
return variablesScopeWeakMap.get(rule) === VariablesScopeSymbol;
|
|
486
|
+
}
|
|
487
|
+
function markVariablesScope(rule) {
|
|
488
|
+
variablesScopeWeakMap.set(rule, VariablesScopeSymbol);
|
|
489
|
+
}
|
|
490
|
+
return {
|
|
491
|
+
variablesScopeWeakMap,
|
|
492
|
+
isVariablesScope,
|
|
493
|
+
markVariablesScope,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function getPlugins(options) {
|
|
498
|
+
var _a, _b;
|
|
499
|
+
const ctx = createContext();
|
|
500
|
+
options.ctx = ctx;
|
|
501
|
+
const plugins = [
|
|
502
|
+
...((_b = (_a = options.postcssOptions) === null || _a === void 0 ? void 0 : _a.plugins) !== null && _b !== void 0 ? _b : []),
|
|
503
|
+
postcssWeappTailwindcssPrePlugin(options),
|
|
504
|
+
postcssIsPseudoClass__default["default"]({
|
|
505
|
+
specificityMatchingName: 'weapp-tw-ig',
|
|
506
|
+
}),
|
|
507
|
+
];
|
|
508
|
+
if (options.rem2rpx) {
|
|
509
|
+
plugins.push(postcssRem2rpx__default["default"](typeof options.rem2rpx === 'object'
|
|
510
|
+
? options.rem2rpx
|
|
511
|
+
: {
|
|
512
|
+
rootValue: 32,
|
|
513
|
+
propList: ['*'],
|
|
514
|
+
transformUnit: 'rpx',
|
|
515
|
+
}));
|
|
516
|
+
}
|
|
517
|
+
plugins.push(postcssWeappTailwindcssPostPlugin(options));
|
|
518
|
+
return plugins;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
exports.WEAPP_TW_REQUIRED_NODE_VERSION = WEAPP_TW_REQUIRED_NODE_VERSION;
|
|
522
|
+
exports.getPlugins = getPlugins;
|
|
523
|
+
exports.pluginName = pluginName;
|
|
524
|
+
exports.postcssWeappTailwindcssPostPlugin = postcssWeappTailwindcssPostPlugin;
|
|
525
|
+
exports.postcssWeappTailwindcssPrePlugin = postcssWeappTailwindcssPrePlugin;
|
|
526
|
+
exports.vitePluginName = vitePluginName;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _createDebug = require('debug');
|
|
4
|
+
|
|
5
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var _createDebug__default = /*#__PURE__*/_interopDefaultCompat(_createDebug);
|
|
8
|
+
|
|
9
|
+
const _debug = _createDebug__default["default"]('weapp-tw');
|
|
10
|
+
function createDebug(prefix) {
|
|
11
|
+
function debug(formatter, ...args) {
|
|
12
|
+
return _debug(('') + formatter, ...args);
|
|
13
|
+
}
|
|
14
|
+
return debug;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.createDebug = createDebug;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
import 'webpack';
|
|
6
|
-
import 'vite';
|
|
7
|
-
import 'node:stream';
|
|
8
|
-
import 'postcss';
|
|
9
|
-
import '@tailwindcss-mangle/shared';
|
|
10
|
-
import 'magic-string';
|
|
11
|
-
import '@babel/generator';
|
|
12
|
-
import '@babel/parser';
|
|
13
|
-
import 'postcss-rem-to-responsive-pixel';
|
|
14
|
-
import 'postcss-load-config';
|
|
15
|
-
import 'tailwindcss-patch';
|
|
16
|
-
import 'node:buffer';
|
|
17
|
-
import 'lru-cache';
|
|
1
|
+
export * from './webpack';
|
|
2
|
+
export * from './vite';
|
|
3
|
+
export * from './gulp';
|
|
4
|
+
export * from './types';
|