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,19 +1,16 @@
1
- import { isMatch } from 'micromatch';
2
1
  import MagicString from 'magic-string';
3
2
  import { replaceJs as replaceWxml } from './replace.mjs';
4
3
  import { escapeStringRegexp, variableRegExp } from '@weapp-core/regex';
5
- import { SimpleMappingChars2String, MappingChars2String } from '@weapp-core/escape';
4
+ import { SimpleMappingChars2String } from '@weapp-core/escape';
6
5
  import { jsStringEscape } from '@ast-core/escape';
7
6
  import generate from '@babel/generator';
8
7
  import { parse, parseExpression } from '@babel/parser';
9
8
  import traverse from '@babel/traverse';
10
- import { d as defu } from './defu-NLkZUlr9.mjs';
11
- import { n as noop, d as defaultOptions, i as isMap } from './defaults-dz6xGhOP.mjs';
9
+ import { d as defuOverrideArray, n as noop, a as defaultOptions, i as isMap } from './defaults-TZpmwtzd.mjs';
12
10
  import * as t from '@babel/types';
13
11
  import { Parser } from 'htmlparser2';
14
12
  import postcss from 'postcss';
15
- import { p as postcssWeappTailwindcss } from './postcss-W8i3cl5I.mjs';
16
- import postcssIsPseudoClass from '@csstools/postcss-is-pseudo-class';
13
+ import { g as getPlugins } from './postcss-kpIT_QQe.mjs';
17
14
  import path from 'node:path';
18
15
  import fs from 'node:fs';
19
16
  import { gte } from 'semver';
@@ -63,33 +60,6 @@ const splitCode = (code, allowDoubleQuotes = false) => {
63
60
  return code.split(splitter).filter((element) => isValidSelector(element));
64
61
  };
65
62
 
66
- function regenerateHandleValue(str, node, options) {
67
- var _a;
68
- const set = options.classNameSet;
69
- const escapeMap = options.escapeMap;
70
- const allowDoubleQuotes = (_a = options.arbitraryValues) === null || _a === void 0 ? void 0 : _a.allowDoubleQuotes;
71
- const ctx = options.mangleContext;
72
- const jsPreserveClass = options.jsPreserveClass;
73
- const arr = splitCode(str, allowDoubleQuotes);
74
- let rawStr = str;
75
- for (const v of arr) {
76
- if (set.has(v) && !(jsPreserveClass === null || jsPreserveClass === void 0 ? void 0 : jsPreserveClass(v))) {
77
- let ignoreFlag = false;
78
- if (Array.isArray(node.leadingComments)) {
79
- ignoreFlag = node.leadingComments.findIndex((x) => x.value.includes('weapp-tw') && x.value.includes('ignore')) > -1;
80
- }
81
- if (!ignoreFlag) {
82
- if (ctx) {
83
- rawStr = ctx.jsHandler(rawStr);
84
- }
85
- rawStr = rawStr.replaceAll(new RegExp(escapeStringRegexp(v), 'g'), replaceWxml(v, {
86
- escapeMap
87
- }));
88
- }
89
- }
90
- }
91
- return rawStr;
92
- }
93
63
  function replaceHandleValue(str, node, options, ms, offset = 0, needEscaped = false) {
94
64
  var _a;
95
65
  const set = options.classNameSet;
@@ -126,8 +96,6 @@ function replaceHandleValue(str, node, options, ms, offset = 0, needEscaped = fa
126
96
  return rawStr;
127
97
  }
128
98
 
129
- const isProd = () => process.env.NODE_ENV === 'production';
130
-
131
99
  function isEvalPath(p) {
132
100
  if (p.isCallExpression()) {
133
101
  const calleePath = p.get('callee');
@@ -136,149 +104,94 @@ function isEvalPath(p) {
136
104
  return false;
137
105
  }
138
106
  function jsHandler(rawSource, options) {
139
- var _a;
140
107
  let ast;
141
108
  try {
142
109
  ast = parse(rawSource, {
143
110
  sourceType: 'unambiguous'
144
111
  });
145
112
  }
146
- catch (_b) {
113
+ catch (_a) {
147
114
  return {
148
115
  code: rawSource
149
116
  };
150
117
  }
151
- if (options.strategy === 'replace') {
152
- const ms = new MagicString(rawSource);
153
- const ropt = {
154
- StringLiteral: {
155
- enter(p) {
156
- var _a;
157
- if (isEvalPath(p.parentPath)) {
158
- return;
159
- }
160
- const n = p.node;
161
- replaceHandleValue(n.value, n, options, ms, 1, (_a = options.needEscaped) !== null && _a !== void 0 ? _a : true);
118
+ const ms = new MagicString(rawSource);
119
+ const ropt = {
120
+ StringLiteral: {
121
+ enter(p) {
122
+ var _a;
123
+ if (isEvalPath(p.parentPath)) {
124
+ return;
162
125
  }
163
- },
164
- TemplateElement: {
165
- enter(p) {
166
- if (p.parentPath.isTemplateLiteral() && isEvalPath(p.parentPath.parentPath)) {
167
- return;
168
- }
169
- const n = p.node;
170
- replaceHandleValue(n.value.raw, n, options, ms, 0, false);
126
+ const n = p.node;
127
+ replaceHandleValue(n.value, n, options, ms, 1, (_a = options.needEscaped) !== null && _a !== void 0 ? _a : true);
128
+ }
129
+ },
130
+ TemplateElement: {
131
+ enter(p) {
132
+ if (p.parentPath.isTemplateLiteral() && isEvalPath(p.parentPath.parentPath)) {
133
+ return;
171
134
  }
172
- },
173
- CallExpression: {
174
- enter(p) {
175
- if (isEvalPath(p)) {
176
- p.traverse({
177
- StringLiteral: {
178
- enter(s) {
179
- const res = jsHandler(s.node.value, Object.assign(Object.assign({}, options), { needEscaped: false, generateMap: false }));
180
- if (res.code) {
181
- const node = s.node;
182
- if (typeof node.start === 'number' && typeof node.end === 'number') {
183
- const start = node.start + 1;
184
- const end = node.end - 1;
185
- if (start < end && s.node.value !== res.code) {
186
- ms.update(start, end, jsStringEscape(res.code));
187
- node.value = res.code;
188
- }
189
- }
190
- }
191
- }
192
- },
193
- TemplateElement: {
194
- enter(s) {
195
- const res = jsHandler(s.node.value.raw, Object.assign(Object.assign({}, options), { generateMap: false }));
196
- if (res.code) {
197
- const node = s.node;
198
- if (typeof node.start === 'number' && typeof node.end === 'number') {
199
- const start = node.start;
200
- const end = node.end;
201
- if (start < end && s.node.value.raw !== res.code) {
202
- ms.update(start, end, res.code);
203
- s.node.value.raw = res.code;
204
- }
135
+ const n = p.node;
136
+ replaceHandleValue(n.value.raw, n, options, ms, 0, false);
137
+ }
138
+ },
139
+ CallExpression: {
140
+ enter(p) {
141
+ if (isEvalPath(p)) {
142
+ p.traverse({
143
+ StringLiteral: {
144
+ enter(s) {
145
+ const res = jsHandler(s.node.value, Object.assign(Object.assign({}, options), { needEscaped: false, generateMap: false }));
146
+ if (res.code) {
147
+ const node = s.node;
148
+ if (typeof node.start === 'number' && typeof node.end === 'number') {
149
+ const start = node.start + 1;
150
+ const end = node.end - 1;
151
+ if (start < end && s.node.value !== res.code) {
152
+ ms.update(start, end, jsStringEscape(res.code));
153
+ node.value = res.code;
205
154
  }
206
155
  }
207
156
  }
208
157
  }
209
- });
210
- }
211
- }
212
- }
213
- };
214
- traverse(ast, ropt);
215
- const result = {
216
- code: ms.toString()
217
- };
218
- return result;
219
- }
220
- else {
221
- const gopt = {
222
- StringLiteral: {
223
- enter(p) {
224
- if (isEvalPath(p.parentPath)) {
225
- return;
226
- }
227
- const n = p.node;
228
- n.value = regenerateHandleValue(n.value, n, options);
229
- }
230
- },
231
- TemplateElement: {
232
- enter(p) {
233
- if (p.parentPath.isTemplateLiteral() && isEvalPath(p.parentPath.parentPath)) {
234
- return;
235
- }
236
- const n = p.node;
237
- n.value.raw = regenerateHandleValue(n.value.raw, n, options);
238
- }
239
- },
240
- CallExpression: {
241
- enter(p) {
242
- if (isEvalPath(p)) {
243
- p.traverse({
244
- StringLiteral: {
245
- enter(s) {
246
- const res = jsHandler(s.node.value, options);
247
- if (res.code) {
248
- s.node.value = res.code;
249
- }
250
- }
251
- },
252
- TemplateElement: {
253
- enter(s) {
254
- const res = jsHandler(s.node.value.raw, options);
255
- if (res.code) {
256
- s.node.value.raw = res.code;
158
+ },
159
+ TemplateElement: {
160
+ enter(s) {
161
+ const res = jsHandler(s.node.value.raw, Object.assign(Object.assign({}, options), { generateMap: false }));
162
+ if (res.code) {
163
+ const node = s.node;
164
+ if (typeof node.start === 'number' && typeof node.end === 'number') {
165
+ const start = node.start;
166
+ const end = node.end;
167
+ if (start < end && s.node.value.raw !== res.code) {
168
+ ms.update(start, end, res.code);
169
+ s.node.value.raw = res.code;
170
+ }
257
171
  }
258
172
  }
259
173
  }
260
- });
261
- }
174
+ }
175
+ });
262
176
  }
263
177
  }
264
- };
265
- traverse(ast, gopt);
266
- return generate(ast, {
267
- minified: (_a = options.minifiedJs) !== null && _a !== void 0 ? _a : isProd()
268
- });
269
- }
178
+ }
179
+ };
180
+ traverse(ast, ropt);
181
+ const result = {
182
+ code: ms.toString()
183
+ };
184
+ return result;
270
185
  }
271
186
  function createJsHandler(options) {
272
- const { mangleContext, arbitraryValues, minifiedJs, escapeMap, jsPreserveClass, strategy, generateMap } = options;
187
+ const { mangleContext, arbitraryValues, escapeMap, jsPreserveClass, generateMap } = options;
273
188
  return (rawSource, set, options) => {
274
- const opts = defu(options, {
189
+ const opts = defuOverrideArray(options, {
275
190
  classNameSet: set,
276
- minifiedJs,
277
191
  escapeMap,
278
192
  arbitraryValues,
279
193
  mangleContext,
280
194
  jsPreserveClass,
281
- strategy,
282
195
  generateMap
283
196
  });
284
197
  return jsHandler(rawSource, opts);
@@ -286,8 +199,7 @@ function createJsHandler(options) {
286
199
  }
287
200
 
288
201
  function getQuotes(quote) {
289
- const quotes = quote === "'" ? 'double' : 'single';
290
- return quotes;
202
+ return quote === "'" ? 'double' : 'single';
291
203
  }
292
204
  function generateCode(match, options = {}) {
293
205
  const ast = parseExpression(match);
@@ -445,20 +357,18 @@ function customTemplateHandler(rawSource, options) {
445
357
  }
446
358
  function createTemplateHandler(options = {}) {
447
359
  return (rawSource, opt = {}) => {
448
- return customTemplateHandler(rawSource, defu(opt, options));
360
+ return customTemplateHandler(rawSource, defuOverrideArray(opt, options));
449
361
  };
450
362
  }
451
363
 
452
364
  function styleHandler(rawSource, options) {
453
365
  return __awaiter(this, void 0, void 0, function* () {
454
- return (yield postcss([postcssIsPseudoClass(), postcssWeappTailwindcss(options)])
455
- .process(rawSource)
456
- .async()).css;
366
+ return (yield postcss(getPlugins(options)).process(rawSource).async()).css;
457
367
  });
458
368
  }
459
369
  function createStyleHandler(options) {
460
370
  return (rawSource, opt) => {
461
- return styleHandler(rawSource, defu(opt, options));
371
+ return styleHandler(rawSource, defuOverrideArray(opt, options));
462
372
  };
463
373
  }
464
374
 
@@ -728,62 +638,37 @@ function createCache() {
728
638
  };
729
639
  }
730
640
 
731
- function createGlobMatcher(pattern) {
732
- return function (file) {
733
- return isMatch(file, pattern);
734
- };
735
- }
736
- function normalizeMatcher(options, key) {
737
- if (typeof options[key] === 'string' || Array.isArray(options[key])) {
738
- options[key] = createGlobMatcher(options[key]);
739
- }
740
- }
741
641
  function getOptions(options = {}) {
742
- if (options.supportCustomLengthUnitsPatch === true) {
743
- options.supportCustomLengthUnitsPatch = undefined;
744
- }
745
642
  if (options.customReplaceDictionary === undefined || options.customReplaceDictionary === 'simple') {
746
643
  options.customReplaceDictionary = SimpleMappingChars2String;
747
644
  }
748
- else if (options.customReplaceDictionary === 'complex') {
749
- options.customReplaceDictionary = MappingChars2String;
750
- }
751
- normalizeMatcher(options, 'cssMatcher');
752
- normalizeMatcher(options, 'htmlMatcher');
753
- normalizeMatcher(options, 'jsMatcher');
754
- normalizeMatcher(options, 'wxsMatcher');
755
- normalizeMatcher(options, 'mainCssChunkMatcher');
756
- const result = defu(options, defaultOptions, {
757
- minifiedJs: isProd()
758
- });
759
- const { cssPreflight, customRuleCallback, cssPreflightRange, replaceUniversalSelectorWith, customAttributes, customReplaceDictionary, supportCustomLengthUnitsPatch, arbitraryValues, cssChildCombinatorReplaceValue, inlineWxs, injectAdditionalCssVarScope, jsPreserveClass, disabledDefaultTemplateHandler, jsEscapeStrategy, cssSelectorReplacement } = result;
645
+ const result = defuOverrideArray(options, defaultOptions, {});
646
+ const { cssPreflight, customRuleCallback, cssPreflightRange, customAttributes, customReplaceDictionary, supportCustomLengthUnitsPatch, arbitraryValues, cssChildCombinatorReplaceValue, inlineWxs, injectAdditionalCssVarScope, jsPreserveClass, disabledDefaultTemplateHandler, cssSelectorReplacement, rem2rpx } = result;
760
647
  result.escapeMap = customReplaceDictionary;
761
648
  const cssInjectPreflight = createInjectPreflight(cssPreflight);
762
649
  const customAttributesEntities = isMap(options.customAttributes)
763
650
  ? [...options.customAttributes.entries()]
764
651
  : Object.entries(customAttributes);
765
- const { escapeMap, minifiedJs } = result;
652
+ const { escapeMap } = result;
766
653
  const { initMangle, mangleContext, setMangleRuntimeSet } = useMangleStore();
767
654
  initMangle(options.mangle);
768
655
  const styleHandler = createStyleHandler({
769
656
  cssInjectPreflight,
770
657
  customRuleCallback,
771
658
  cssPreflightRange,
772
- replaceUniversalSelectorWith,
773
659
  escapeMap,
774
660
  mangleContext,
775
661
  cssChildCombinatorReplaceValue,
776
662
  injectAdditionalCssVarScope,
777
- cssSelectorReplacement
663
+ cssSelectorReplacement,
664
+ rem2rpx
778
665
  });
779
666
  result.styleHandler = styleHandler;
780
667
  const jsHandler = createJsHandler({
781
- minifiedJs,
782
668
  escapeMap,
783
669
  mangleContext,
784
670
  arbitraryValues,
785
671
  jsPreserveClass,
786
- strategy: jsEscapeStrategy,
787
672
  generateMap: true
788
673
  });
789
674
  result.jsHandler = jsHandler;
@@ -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 };
@@ -1,2 +1,3 @@
1
1
  import { InternalCssSelectorReplacerOptions } from "../types";
2
2
  export declare function internalCssSelectorReplacer(selectors: string, options?: InternalCssSelectorReplacerOptions): string;
3
+ export declare function composeIsPseudo(strs: string | string[]): string;
@@ -0,0 +1 @@
1
+ export declare const VariablesScopeSymbol: unique symbol;