@weapp-tailwindcss/postcss 3.3.7 → 3.3.9
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/compat/mini-program-css/prune-generated.d.ts +3 -2
- package/dist/compat/uni-app-x-uvue.d.ts +1 -1
- package/dist/{directives-C7XTve1w.js → directives-DMB7AQE_.js} +616 -572
- package/dist/fingerprint.d.ts +3 -0
- package/dist/index.cjs +9 -3
- package/dist/index.js +7 -7
- package/dist/mp.d.ts +5 -1
- package/dist/{plugin-CRzZbcEf.js → plugin-BxhTytFU.js} +2 -2
- package/dist/{plugin-DwoAGHyN.cjs → plugin-CfrVcQt8.cjs} +1 -1
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugins/applyConfiguredCssCalc.d.ts +1 -1
- package/dist/plugins/applyConfiguredCssUnits.d.ts +4 -0
- package/dist/plugins/user-plugin-stage.d.ts +3 -0
- package/dist/processor-cache.d.ts +0 -1
- package/dist/{resolve-D-FbFBpF.js → resolve-Cb3XkcFk.js} +102 -99
- package/dist/{resolve-BFphwPip.cjs → resolve-DcV8mpsu.cjs} +727 -668
- package/dist/{rewrite-imports-Dk9TKKSF.js → rewrite-imports-Cx1wGYaN.js} +1 -1
- package/dist/syntax.cjs +94 -94
- package/dist/syntax.js +2 -2
- package/dist/{transform-DpFypcaN.cjs → transform-CmPPSR36.cjs} +384 -172
- package/dist/{transform-BGYgGeQj.js → transform-DhUndykm.js} +352 -176
- package/dist/transform.cjs +8 -2
- package/dist/transform.d.ts +4 -0
- package/dist/transform.js +6 -6
- package/dist/types.d.ts +10 -0
- package/dist/utils/css-calc-context.d.ts +12 -0
- package/dist/utils/css-custom-property.d.ts +14 -0
- package/dist/utils/deferred-css-source.d.ts +6 -0
- package/package.json +9 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.cjs");
|
|
2
|
-
const require_resolve = require("./resolve-
|
|
2
|
+
const require_resolve = require("./resolve-DcV8mpsu.cjs");
|
|
3
3
|
const require_shared = require("./shared-CELzerNo.cjs");
|
|
4
4
|
const require_postcss = require("./postcss-CfbYRXJi.cjs");
|
|
5
5
|
const require_preflight = require("./preflight-BTZL2nvC.cjs");
|
|
@@ -295,19 +295,236 @@ function normalizeTailwindV4RuntimeCss(css) {
|
|
|
295
295
|
return root.toString();
|
|
296
296
|
}
|
|
297
297
|
//#endregion
|
|
298
|
+
//#region src/utils/css-custom-property.ts
|
|
299
|
+
function decodeCssIdentifier(source) {
|
|
300
|
+
if (/^[-_a-z][\w-]*$/i.test(source)) return source;
|
|
301
|
+
const tokens = require_resolve.tokenize({ css: source }).filter((token) => token[0] !== require_resolve.u.Whitespace && token[0] !== require_resolve.u.Comment && token[0] !== require_resolve.u.EOF);
|
|
302
|
+
const token = tokens[0];
|
|
303
|
+
return tokens.length === 1 && token?.[0] === require_resolve.u.Ident ? token[4].value : void 0;
|
|
304
|
+
}
|
|
305
|
+
/** PostCSS 可能把十六进制转义的终止空白拆入 params,需要按原始前导 token 还原。 */
|
|
306
|
+
function getCssAtRulePrelude(rule) {
|
|
307
|
+
if (!rule.name.includes("\\") && !(rule.raws.afterName === "" && rule.params.startsWith("\\"))) return {
|
|
308
|
+
name: rule.name,
|
|
309
|
+
params: rule.params
|
|
310
|
+
};
|
|
311
|
+
const source = `@${rule.name}${rule.raws.afterName ?? " "}${rule.params}`;
|
|
312
|
+
const token = require_resolve.tokenize({ css: source })[0];
|
|
313
|
+
return token?.[0] === require_resolve.u.AtKeyword ? {
|
|
314
|
+
name: token[4].value,
|
|
315
|
+
params: source.slice(token[3] + 1).trimStart()
|
|
316
|
+
} : {
|
|
317
|
+
name: rule.name,
|
|
318
|
+
params: rule.params
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
/** 按 CSS token 解码名称,保留自定义属性的大小写及转义终止空白语义。 */
|
|
322
|
+
function getCssCustomPropertyName(source) {
|
|
323
|
+
if (/^--[\w-]+$/.test(source)) return source;
|
|
324
|
+
if (!source.trimStart().startsWith("--") && !source.includes("\\")) return;
|
|
325
|
+
const name = decodeCssIdentifier(source);
|
|
326
|
+
return name?.startsWith("--") && name.length > 2 ? name : void 0;
|
|
327
|
+
}
|
|
328
|
+
function isCssVarFunction(name) {
|
|
329
|
+
return (name.includes("\\") ? decodeCssIdentifier(name) : name)?.toLowerCase() === "var";
|
|
330
|
+
}
|
|
331
|
+
/** 同时保留引用处的原始拼写,供底层 calc 匹配;安全判断只使用解码后的身份。 */
|
|
332
|
+
function getCssCalcVariableReferences(value) {
|
|
333
|
+
const references = /* @__PURE__ */ new Map();
|
|
334
|
+
if (!value.includes("(")) return references;
|
|
335
|
+
(0, postcss_value_parser.default)(value).walk((node) => {
|
|
336
|
+
if (node.type !== "function" || !isCssVarFunction(node.value)) return;
|
|
337
|
+
const comma = node.nodes.findIndex((child) => child.type === "div" && child.value === ",");
|
|
338
|
+
const raw = postcss_value_parser.default.stringify(comma < 0 ? node.nodes : node.nodes.slice(0, comma));
|
|
339
|
+
references.set(raw.trim(), getCssCustomPropertyName(raw) ?? raw.trim());
|
|
340
|
+
});
|
|
341
|
+
return references;
|
|
342
|
+
}
|
|
343
|
+
/** 内部共享匹配入口:字符串按 CSS 名称解码,正则匹配解码后的身份。 */
|
|
344
|
+
function isCssCalcCustomPropertySelected(name, includes) {
|
|
345
|
+
return includes?.some((entry) => typeof entry === "string" ? getCssCustomPropertyName(entry) === name : new RegExp(entry.source, entry.flags).test(name)) ?? false;
|
|
346
|
+
}
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region src/utils/css-calc-context.ts
|
|
349
|
+
/** 只接受无条件主题根;层叠层允许提供候选值,冲突统一在后续排除。 */
|
|
350
|
+
function isCssCalcThemeDeclaration(decl) {
|
|
351
|
+
const rule = decl.parent;
|
|
352
|
+
if (rule?.type !== "rule" || !rule.selectors.length || !rule.selectors.every((selector) => require_resolve.MINI_PROGRAM_THEME_SCOPE_SELECTORS.has(selector.trim()))) return false;
|
|
353
|
+
if (!rule.selectors.some((selector) => [":root", "page"].includes(selector.trim()))) return false;
|
|
354
|
+
let parent = rule.parent;
|
|
355
|
+
while (parent && parent.type !== "root") {
|
|
356
|
+
if (parent.type !== "atrule" || getCssAtRulePrelude(parent).name.toLowerCase() !== "layer") return false;
|
|
357
|
+
parent = parent.parent;
|
|
358
|
+
}
|
|
359
|
+
return parent?.type === "root";
|
|
360
|
+
}
|
|
361
|
+
function isSourceThemeDeclaration(decl) {
|
|
362
|
+
let parent = decl.parent;
|
|
363
|
+
while (parent && parent.type !== "root") {
|
|
364
|
+
if (parent.type === "atrule" && getCssAtRulePrelude(parent).name.toLowerCase() === "theme") return true;
|
|
365
|
+
parent = parent.parent;
|
|
366
|
+
}
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
function getDependencies(value) {
|
|
370
|
+
return new Set(getCssCalcVariableReferences(value).values());
|
|
371
|
+
}
|
|
372
|
+
function isCssWideValue(value) {
|
|
373
|
+
return /^(?:initial|inherit|unset|revert|revert-layer)$/i.test(decodeCssIdentifier(value) ?? value);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* 推导可供 calc 静态化的主题变量;局部、条件、冲突及未解析依赖一律保留运行时语义。
|
|
377
|
+
* 原始 @theme 由编译器处理,此处只消费其生成的有效主题根。
|
|
378
|
+
*/
|
|
379
|
+
function analyzeCssCalcContext(css, explicitValues) {
|
|
380
|
+
const customPropertyValues = /* @__PURE__ */ new Map();
|
|
381
|
+
const unsafeCustomProperties = /* @__PURE__ */ new Set();
|
|
382
|
+
try {
|
|
383
|
+
const root = postcss.default.parse(css);
|
|
384
|
+
root.walkAtRules((rule) => {
|
|
385
|
+
const prelude = getCssAtRulePrelude(rule);
|
|
386
|
+
if (prelude.name.toLowerCase() === "property") unsafeCustomProperties.add(getCssCustomPropertyName(prelude.params) ?? prelude.params.trim());
|
|
387
|
+
});
|
|
388
|
+
root.walkDecls((decl) => {
|
|
389
|
+
const name = getCssCustomPropertyName(decl.prop);
|
|
390
|
+
if (!name || isSourceThemeDeclaration(decl)) return;
|
|
391
|
+
const value = decl.value.trim();
|
|
392
|
+
if (!isCssCalcThemeDeclaration(decl) || isCssWideValue(value) || customPropertyValues.has(name) && customPropertyValues.get(name) !== value) unsafeCustomProperties.add(name);
|
|
393
|
+
else customPropertyValues.set(name, value);
|
|
394
|
+
});
|
|
395
|
+
} catch {
|
|
396
|
+
return {
|
|
397
|
+
customPropertyValues,
|
|
398
|
+
unsafeCustomProperties
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
const dependencies = new Map([...customPropertyValues].map(([name, value]) => [name, getDependencies(value)]));
|
|
402
|
+
for (const [rawName, value] of explicitValues ?? []) {
|
|
403
|
+
const name = getCssCustomPropertyName(rawName);
|
|
404
|
+
if (name && !unsafeCustomProperties.has(name)) {
|
|
405
|
+
customPropertyValues.set(name, value);
|
|
406
|
+
dependencies.set(name, /* @__PURE__ */ new Set([...dependencies.get(name) ?? [], ...getDependencies(value)]));
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
410
|
+
const resolved = /* @__PURE__ */ new Set();
|
|
411
|
+
function isSafe(name) {
|
|
412
|
+
if (unsafeCustomProperties.has(name)) return false;
|
|
413
|
+
if (resolved.has(name)) return true;
|
|
414
|
+
const value = customPropertyValues.get(name);
|
|
415
|
+
if (value === void 0 || isCssWideValue(value) || visiting.has(name) || visiting.size >= 256) {
|
|
416
|
+
unsafeCustomProperties.add(name);
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
visiting.add(name);
|
|
420
|
+
for (const dependency of dependencies.get(name) ?? []) if (!isSafe(dependency)) {
|
|
421
|
+
visiting.delete(name);
|
|
422
|
+
unsafeCustomProperties.add(name);
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
425
|
+
visiting.delete(name);
|
|
426
|
+
if (dependencies.get(name)?.size) {
|
|
427
|
+
const parsed = (0, postcss_value_parser.default)(value);
|
|
428
|
+
parsed.walk((node, index, nodes) => {
|
|
429
|
+
if (node.type !== "function" || !isCssVarFunction(node.value)) return;
|
|
430
|
+
const comma = node.nodes.findIndex((child) => child.type === "div" && child.value === ",");
|
|
431
|
+
const rawDependency = postcss_value_parser.default.stringify(comma < 0 ? node.nodes : node.nodes.slice(0, comma));
|
|
432
|
+
const dependency = getCssCustomPropertyName(rawDependency) ?? rawDependency.trim();
|
|
433
|
+
nodes[index] = {
|
|
434
|
+
type: "word",
|
|
435
|
+
value: customPropertyValues.get(dependency),
|
|
436
|
+
sourceIndex: node.sourceIndex,
|
|
437
|
+
sourceEndIndex: node.sourceEndIndex
|
|
438
|
+
};
|
|
439
|
+
return false;
|
|
440
|
+
});
|
|
441
|
+
customPropertyValues.set(name, parsed.toString());
|
|
442
|
+
}
|
|
443
|
+
resolved.add(name);
|
|
444
|
+
return true;
|
|
445
|
+
}
|
|
446
|
+
for (const name of customPropertyValues.keys()) if (!isSafe(name)) customPropertyValues.delete(name);
|
|
447
|
+
return {
|
|
448
|
+
customPropertyValues,
|
|
449
|
+
unsafeCustomProperties
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
//#endregion
|
|
453
|
+
//#region src/plugins/getCalcPlugin.ts
|
|
454
|
+
function getCalcPlugin(options) {
|
|
455
|
+
if (!options.cssCalc) return null;
|
|
456
|
+
const configured = typeof options.cssCalc === "object" && !Array.isArray(options.cssCalc) ? { ...options.cssCalc } : {};
|
|
457
|
+
const includes = [...(Array.isArray(options.cssCalc) ? options.cssCalc : configured.includeCustomProperties) ?? []];
|
|
458
|
+
const inputValues = options.customPropertyValues ?? configured.customPropertyValues;
|
|
459
|
+
const explicitValues = inputValues ? new Map(inputValues) : void 0;
|
|
460
|
+
const contextCss = options.customPropertyContextCss ?? "";
|
|
461
|
+
const selectAll = options.cssCalc === true;
|
|
462
|
+
return {
|
|
463
|
+
postcssPlugin: "postcss-calc",
|
|
464
|
+
Once(root, helpers) {
|
|
465
|
+
const context = analyzeCssCalcContext([contextCss, root.toString()].join("\n"), explicitValues);
|
|
466
|
+
const selectedValues = new Map([...context.customPropertyValues].filter(([name]) => selectAll || isCssCalcCustomPropertySelected(name, includes)));
|
|
467
|
+
const customPropertyValues = /* @__PURE__ */ new Map();
|
|
468
|
+
root.walk((node) => {
|
|
469
|
+
const value = node.type === "decl" ? node.value : node.type === "atrule" && configured.mediaQueries ? node.params : node.type === "rule" && configured.selectors ? node.selector : void 0;
|
|
470
|
+
if (!value) return;
|
|
471
|
+
for (const [rawName, name] of getCssCalcVariableReferences(value)) {
|
|
472
|
+
const resolved = selectedValues.get(name);
|
|
473
|
+
if (resolved !== void 0) customPropertyValues.set(rawName, resolved);
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
return (0, _weapp_tailwindcss_postcss_calc.default)({
|
|
477
|
+
...configured,
|
|
478
|
+
customPropertyValues,
|
|
479
|
+
includeCustomProperties: [...customPropertyValues.keys()]
|
|
480
|
+
}).OnceExit?.(root, helpers);
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
//#endregion
|
|
485
|
+
//#region src/plugins/applyConfiguredCssCalc.ts
|
|
486
|
+
function resolveCssCalcOption(options) {
|
|
487
|
+
return options.cssOptions?.cssCalc ?? options.cssCalc;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* 仅按 `cssCalc` 配置预计算 `calc()` / `var()`,不跑小程序选择器替换或单位转换。
|
|
491
|
+
*/
|
|
492
|
+
async function applyConfiguredCssCalc(css, options = {}) {
|
|
493
|
+
const cssCalc = resolveCssCalcOption(options);
|
|
494
|
+
if (!cssCalc || !css.includes("calc(")) return css;
|
|
495
|
+
const plugin = getCalcPlugin({
|
|
496
|
+
cssCalc,
|
|
497
|
+
customPropertyValues: options.customPropertyValues,
|
|
498
|
+
customPropertyContextCss: [options.customPropertyContextCss ?? "", options.contextCss ?? ""].join("\n")
|
|
499
|
+
});
|
|
500
|
+
if (!plugin) return css;
|
|
501
|
+
try {
|
|
502
|
+
return (await (0, postcss.default)([plugin]).process(css, { from: void 0 })).css;
|
|
503
|
+
} catch {
|
|
504
|
+
return css;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
//#endregion
|
|
298
508
|
//#region src/compat/mini-program-css/prune-generated.ts
|
|
299
509
|
const DEFAULT_WEAPP_VARIABLE_SCOPE = "page,.tw-root,wx-root-portal-content,:host";
|
|
300
510
|
const MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR = "::before,\n::after";
|
|
301
511
|
const CLASS_SELECTOR_RE$2 = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
302
512
|
/**
|
|
303
|
-
*
|
|
513
|
+
* 在主题作用域改写前按配置预计算 calc,再展开 Tailwind 生成的嵌套规则并裁剪 Web-only 结构。
|
|
304
514
|
*/
|
|
305
515
|
async function normalizeMiniProgramGeneratedCssForPostcss(css, options = {}) {
|
|
516
|
+
const calculatedCss = await applyConfiguredCssCalc(css, {
|
|
517
|
+
cssCalc: options.cssCalc,
|
|
518
|
+
cssOptions: options.cssOptions,
|
|
519
|
+
customPropertyValues: options.customPropertyValues,
|
|
520
|
+
customPropertyContextCss: options.customPropertyContextCss,
|
|
521
|
+
contextCss: options.contextCss ?? css
|
|
522
|
+
});
|
|
306
523
|
return pruneMiniProgramGeneratedCss((await (0, postcss.default)([(0, postcss_preset_env.default)({
|
|
307
524
|
stage: false,
|
|
308
525
|
features: { "nesting-rules": true },
|
|
309
526
|
autoprefixer: false
|
|
310
|
-
})]).process(
|
|
527
|
+
})]).process(calculatedCss, { from: void 0 })).css, options);
|
|
311
528
|
}
|
|
312
529
|
function isConditionalCompilationComment(text) {
|
|
313
530
|
return /#(?:ifn?def|endif)\b/.test(text);
|
|
@@ -1066,7 +1283,7 @@ function applyUniAppXUvueCompatibility(result, options) {
|
|
|
1066
1283
|
const sfcStyleRequest = options?.isMainChunk !== true && isUvueSfcStyleRequest(result);
|
|
1067
1284
|
let root = result.root;
|
|
1068
1285
|
let calcMessages = [];
|
|
1069
|
-
consumeUniAppXSystemRootTheme(root, options?.customPropertyValues);
|
|
1286
|
+
consumeUniAppXSystemRootTheme(root, new Map([...options?.customPropertyCompatibilityValues ?? [], ...options?.customPropertyValues ?? []]));
|
|
1070
1287
|
if (root.type === "root" && Array.isArray(root.nodes) && typeof root.walkDecls === "function") {
|
|
1071
1288
|
root.walkDecls((decl) => {
|
|
1072
1289
|
require_resolve.normalizeTailwindcssV4Declaration(decl);
|
|
@@ -4466,7 +4683,7 @@ function getDefaultOptions(options) {
|
|
|
4466
4683
|
"oklab-function": true,
|
|
4467
4684
|
"color-mix": true,
|
|
4468
4685
|
"color-functional-notation": options?.cssPresetEnv?.features?.["color-functional-notation"] ?? { preserve: false },
|
|
4469
|
-
"custom-properties": options?.cssPresetEnv?.features?.["custom-properties"] ??
|
|
4686
|
+
"custom-properties": options?.cssPresetEnv?.features?.["custom-properties"] ?? false
|
|
4470
4687
|
},
|
|
4471
4688
|
autoprefixer: { add: false }
|
|
4472
4689
|
},
|
|
@@ -4499,12 +4716,17 @@ function fingerprintOptions(value, state = {
|
|
|
4499
4716
|
const marker = `ref:${state.counter++}`;
|
|
4500
4717
|
state.map.set(objectValue, marker);
|
|
4501
4718
|
if (Array.isArray(objectValue)) return `[${objectValue.map((entry) => fingerprintOptions(entry, state)).join(",")}]`;
|
|
4719
|
+
if (objectValue instanceof RegExp) return `regexp:${objectValue.source}/${objectValue.flags}`;
|
|
4502
4720
|
if (objectValue instanceof Map) return `map:{${[...objectValue.entries()].map(([key, entry]) => [fingerprintOptions(key, state), fingerprintOptions(entry, state)]).sort(([left], [right]) => left.localeCompare(right)).map(([key, entry]) => `${key}:${entry}`).join(",")}}@${marker}`;
|
|
4503
4721
|
return `{${Object.keys(objectValue).sort().map((key) => `${key}:${fingerprintOptions(objectValue[key], state)}`).join(",")}}@${marker}`;
|
|
4504
4722
|
}
|
|
4723
|
+
/** 处理器运行时状态不参与输入签名,其余选项每次按实际内容计算。 */
|
|
4724
|
+
function fingerprintStyleOptions(options) {
|
|
4725
|
+
const { ctx: _ctx, ...inputs } = options;
|
|
4726
|
+
return fingerprintOptions(inputs);
|
|
4727
|
+
}
|
|
4505
4728
|
//#endregion
|
|
4506
4729
|
//#region src/options-resolver.ts
|
|
4507
|
-
const BASE_CACHE_KEY = "base";
|
|
4508
4730
|
const SIMPLE_OVERRIDE_UNSET = "__unset__";
|
|
4509
4731
|
const CSS_OPTION_KEYS = [
|
|
4510
4732
|
"cssPreflight",
|
|
@@ -4679,32 +4901,17 @@ function normalizeCssOptions(options, mirrorTopLevel = false) {
|
|
|
4679
4901
|
function createOptionsResolver(baseOptions) {
|
|
4680
4902
|
const normalizedBaseOptions = normalizeCssOptions(baseOptions);
|
|
4681
4903
|
const cacheByKey = /* @__PURE__ */ new Map();
|
|
4682
|
-
const cacheByRef = /* @__PURE__ */ new WeakMap();
|
|
4683
|
-
const cacheKeyByRef = /* @__PURE__ */ new WeakMap();
|
|
4684
|
-
const emptyOverrideRefs = /* @__PURE__ */ new WeakSet();
|
|
4685
|
-
cacheByKey.set(BASE_CACHE_KEY, normalizedBaseOptions);
|
|
4686
4904
|
const resolve = (overrides) => {
|
|
4687
4905
|
if (!overrides) return normalizedBaseOptions;
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
if (emptyOverrideRefs.has(overrides)) return normalizedBaseOptions;
|
|
4691
|
-
if (!hasOverrides(overrides)) {
|
|
4692
|
-
emptyOverrideRefs.add(overrides);
|
|
4693
|
-
return normalizedBaseOptions;
|
|
4694
|
-
}
|
|
4695
|
-
let key = cacheKeyByRef.get(overrides);
|
|
4696
|
-
if (!key) {
|
|
4697
|
-
key = getSimpleOverrideCacheKey(overrides) ?? fingerprintOptions(overrides);
|
|
4698
|
-
cacheKeyByRef.set(overrides, key);
|
|
4699
|
-
}
|
|
4906
|
+
if (!hasOverrides(overrides)) return normalizedBaseOptions;
|
|
4907
|
+
const key = getSimpleOverrideCacheKey(overrides) ?? fingerprintOptions(overrides);
|
|
4700
4908
|
const cached = cacheByKey.get(key);
|
|
4701
|
-
if (cached)
|
|
4702
|
-
cacheByRef.set(overrides, cached);
|
|
4703
|
-
return cached;
|
|
4704
|
-
}
|
|
4909
|
+
if (cached && fingerprintStyleOptions(cached.options) === cached.fingerprint) return cached.options;
|
|
4705
4910
|
const normalized = normalizeCssOptions((0, _weapp_tailwindcss_shared.defuOverrideArray)(normalizeCssOptions({ ...overrides }, true), normalizedBaseOptions));
|
|
4706
|
-
cacheByKey.set(key,
|
|
4707
|
-
|
|
4911
|
+
cacheByKey.set(key, {
|
|
4912
|
+
options: normalized,
|
|
4913
|
+
fingerprint: fingerprintStyleOptions(normalized)
|
|
4914
|
+
});
|
|
4708
4915
|
return normalized;
|
|
4709
4916
|
};
|
|
4710
4917
|
return { resolve };
|
|
@@ -4855,70 +5062,15 @@ function getCalcDuplicateCleaner(options) {
|
|
|
4855
5062
|
return calcDuplicateCleanerPlugin;
|
|
4856
5063
|
}
|
|
4857
5064
|
//#endregion
|
|
4858
|
-
//#region src/plugins/getCalcPlugin.ts
|
|
4859
|
-
const EMPTY_CALC_OPTIONS = {};
|
|
4860
|
-
function getCalcPlugin(options) {
|
|
4861
|
-
if (!options.cssCalc) return null;
|
|
4862
|
-
if (options.cssCalc === true || Array.isArray(options.cssCalc)) {
|
|
4863
|
-
const calcOptions = Array.isArray(options.cssCalc) ? {
|
|
4864
|
-
includeCustomProperties: options.cssCalc,
|
|
4865
|
-
...options.customPropertyValues ? { customPropertyValues: options.customPropertyValues } : {}
|
|
4866
|
-
} : options.customPropertyValues ? {
|
|
4867
|
-
customPropertyValues: options.customPropertyValues,
|
|
4868
|
-
includeCustomProperties: [...options.customPropertyValues.keys()]
|
|
4869
|
-
} : EMPTY_CALC_OPTIONS;
|
|
4870
|
-
return (0, _weapp_tailwindcss_postcss_calc.default)(calcOptions);
|
|
4871
|
-
}
|
|
4872
|
-
return (0, _weapp_tailwindcss_postcss_calc.default)({
|
|
4873
|
-
...options.cssCalc,
|
|
4874
|
-
...options.customPropertyValues ? { customPropertyValues: options.customPropertyValues } : {}
|
|
4875
|
-
});
|
|
4876
|
-
}
|
|
4877
|
-
//#endregion
|
|
4878
5065
|
//#region src/plugins/getCustomPropertyCleaner.ts
|
|
4879
5066
|
function getCustomPropertyCleaner(options) {
|
|
4880
|
-
|
|
4881
|
-
if (!(Array.isArray(includeCustomProperties) && includeCustomProperties.length > 0)) return null;
|
|
4882
|
-
const shouldInspectValue = (value) => value.includes("var(") && value.includes("--");
|
|
4883
|
-
const containsIncludedCustomProperty = (value) => {
|
|
4884
|
-
if (!shouldInspectValue(value)) return false;
|
|
4885
|
-
const parsed = (0, postcss_value_parser.default)(value);
|
|
4886
|
-
let containsIncludedCustomProperty = false;
|
|
4887
|
-
parsed.walk((node) => {
|
|
4888
|
-
if (node.type !== "function" || node.value !== "var" || containsIncludedCustomProperty) return;
|
|
4889
|
-
if (node.nodes.find((x) => {
|
|
4890
|
-
return x.type === "word" && (0, _weapp_tailwindcss_shared.regExpTest)(includeCustomProperties, x.value);
|
|
4891
|
-
})) containsIncludedCustomProperty = true;
|
|
4892
|
-
});
|
|
4893
|
-
return containsIncludedCustomProperty;
|
|
4894
|
-
};
|
|
4895
|
-
const hasSameSourceRange = (left, right) => {
|
|
4896
|
-
const leftSource = left.source;
|
|
4897
|
-
const rightSource = right.source;
|
|
4898
|
-
if (!leftSource?.start || !leftSource.end || !rightSource?.start || !rightSource.end || leftSource.input !== rightSource.input) return false;
|
|
4899
|
-
return leftSource.start.line === rightSource.start.line && leftSource.start.column === rightSource.start.column && leftSource.end.line === rightSource.end.line && leftSource.end.column === rightSource.end.column;
|
|
4900
|
-
};
|
|
5067
|
+
if (!(Array.isArray(options.cssCalc) ? options.cssCalc : typeof options.cssCalc === "object" ? options.cssCalc.includeCustomProperties : void 0)?.length) return null;
|
|
4901
5068
|
return {
|
|
4902
5069
|
postcssPlugin: "postcss-remove-include-custom-properties",
|
|
4903
5070
|
OnceExit(root) {
|
|
4904
5071
|
root.walkDecls((decl) => {
|
|
4905
|
-
const
|
|
4906
|
-
if (
|
|
4907
|
-
decl.remove();
|
|
4908
|
-
return;
|
|
4909
|
-
}
|
|
4910
|
-
if (!containsIncludedCustomProperty(decl.value)) return;
|
|
4911
|
-
let fallbackDecl;
|
|
4912
|
-
let node = prevNode;
|
|
4913
|
-
while (node) {
|
|
4914
|
-
if (node.type === "decl" && node.prop === decl.prop) {
|
|
4915
|
-
fallbackDecl = node;
|
|
4916
|
-
break;
|
|
4917
|
-
}
|
|
4918
|
-
node = node.prev();
|
|
4919
|
-
}
|
|
4920
|
-
if (!fallbackDecl || fallbackDecl.important !== decl.important || fallbackDecl !== prevNode && !hasSameSourceRange(fallbackDecl, decl) || containsIncludedCustomProperty(fallbackDecl.value)) return;
|
|
4921
|
-
decl.remove();
|
|
5072
|
+
const previous = decl.prev();
|
|
5073
|
+
if (previous?.type === "decl" && previous.prop === decl.prop && previous.important === decl.important && previous.value === decl.value) decl.remove();
|
|
4922
5074
|
});
|
|
4923
5075
|
}
|
|
4924
5076
|
};
|
|
@@ -6320,11 +6472,12 @@ function removeTailwindV4EmptyContentInit(node) {
|
|
|
6320
6472
|
if (isEmptyContentInitDeclaration(decl)) decl.remove();
|
|
6321
6473
|
});
|
|
6322
6474
|
}
|
|
6323
|
-
function injectPreflightDeclarations(node, options) {
|
|
6475
|
+
function injectPreflightDeclarations(node, options, contentUsage) {
|
|
6324
6476
|
const preflightDeclarations = options.cssInjectPreflight?.();
|
|
6325
6477
|
if (!preflightDeclarations || preflightDeclarations.length === 0) return;
|
|
6326
6478
|
node.prepend(...preflightDeclarations);
|
|
6327
6479
|
node.raws.semicolon = true;
|
|
6480
|
+
contentUsage?.invalidate();
|
|
6328
6481
|
}
|
|
6329
6482
|
function hasClassSelector$1(node) {
|
|
6330
6483
|
return node.selectors.some((selector) => selector.includes("."));
|
|
@@ -6350,7 +6503,7 @@ function resolveUniAppXVariableScopeSelectors(options) {
|
|
|
6350
6503
|
if (typeof universal === "string" && universal.length > 0) return [universal];
|
|
6351
6504
|
return ["view", "text"];
|
|
6352
6505
|
}
|
|
6353
|
-
function commonChunkPreflight(node, options) {
|
|
6506
|
+
function commonChunkPreflight(node, options, contentUsage) {
|
|
6354
6507
|
const { ctx, injectAdditionalCssVarScope } = options;
|
|
6355
6508
|
const uniAppXEnabled = isUniAppXEnabled(options);
|
|
6356
6509
|
const isTailwindcss4 = require_resolve.isTailwindcssV4(options);
|
|
@@ -6363,14 +6516,16 @@ function commonChunkPreflight(node, options) {
|
|
|
6363
6516
|
phase: "pre",
|
|
6364
6517
|
reason: "append-host-selector"
|
|
6365
6518
|
});
|
|
6366
|
-
if (isTailwindcss4 &&
|
|
6519
|
+
if (isTailwindcss4 && (!hasClassSelector$1(node) || isRootThemeScopeRule(node))) {
|
|
6520
|
+
if (!(contentUsage?.read() ?? require_resolve.usesTailwindcssV4ContentVariable(node.root()))) removeTailwindV4EmptyContentInit(node);
|
|
6521
|
+
}
|
|
6367
6522
|
if (testIfVariablesScope(node) || uniAppXEnabled && node.selectors.includes("*") && hasTwVars(node, 2)) {
|
|
6368
6523
|
ctx?.markVariablesScope(node);
|
|
6369
6524
|
assignRuleSelectors(node, uniAppXEnabled ? resolveUniAppXVariableScopeSelectors(options) : remakeCssVarSelector(node.selectors, options), {
|
|
6370
6525
|
phase: "pre",
|
|
6371
6526
|
reason: "rewrite-variable-scope"
|
|
6372
6527
|
});
|
|
6373
|
-
injectPreflightDeclarations(node, options);
|
|
6528
|
+
injectPreflightDeclarations(node, options, contentUsage);
|
|
6374
6529
|
}
|
|
6375
6530
|
if (injectAdditionalCssVarScope && isTailwindcss4 && require_resolve.testIfRootHostForV4(node)) {
|
|
6376
6531
|
const nodes = require_resolve.createUsedCssVarsV4Nodes(require_resolve.collectUsedTailwindcssV4Variables(node.root()));
|
|
@@ -6388,7 +6543,8 @@ function commonChunkPreflight(node, options) {
|
|
|
6388
6543
|
reason: "rewrite-synthetic-variable-scope"
|
|
6389
6544
|
});
|
|
6390
6545
|
node.before(syntheticRule);
|
|
6391
|
-
|
|
6546
|
+
contentUsage?.invalidate();
|
|
6547
|
+
injectPreflightDeclarations(syntheticRule, options, contentUsage);
|
|
6392
6548
|
}
|
|
6393
6549
|
}
|
|
6394
6550
|
//#endregion
|
|
@@ -6454,14 +6610,39 @@ const postcssWeappTailwindcssPrePlugin = (options) => {
|
|
|
6454
6610
|
}
|
|
6455
6611
|
});
|
|
6456
6612
|
require_resolve.consumeCascadeLayers(root);
|
|
6613
|
+
let contentVariableUsedInRoot = require_resolve.isTailwindcssV4(opts) ? require_resolve.usesTailwindcssV4ContentVariable(root) : void 0;
|
|
6614
|
+
const contentUsage = {
|
|
6615
|
+
read: () => contentVariableUsedInRoot ??= require_resolve.usesTailwindcssV4ContentVariable(root),
|
|
6616
|
+
invalidate: () => {
|
|
6617
|
+
contentVariableUsedInRoot = void 0;
|
|
6618
|
+
}
|
|
6619
|
+
};
|
|
6457
6620
|
root.walkRules((rule) => {
|
|
6458
|
-
commonChunkPreflight(rule, opts);
|
|
6621
|
+
commonChunkPreflight(rule, opts, contentUsage);
|
|
6459
6622
|
});
|
|
6460
6623
|
};
|
|
6461
6624
|
return p;
|
|
6462
6625
|
};
|
|
6463
6626
|
postcssWeappTailwindcssPrePlugin.postcss = true;
|
|
6464
6627
|
//#endregion
|
|
6628
|
+
//#region src/plugins/user-plugin-stage.ts
|
|
6629
|
+
/** 完成作者插件的全部 visitor 后再进入平台适配,避免 calc 读取中间态。 */
|
|
6630
|
+
function createUserPluginStage(plugins) {
|
|
6631
|
+
const processor = (0, postcss.default)(plugins);
|
|
6632
|
+
return {
|
|
6633
|
+
postcssPlugin: "weapp-tailwindcss-author-stage",
|
|
6634
|
+
async Once(root, { result }) {
|
|
6635
|
+
const processed = await processor.process(root, {
|
|
6636
|
+
...result.opts,
|
|
6637
|
+
map: false
|
|
6638
|
+
}).async();
|
|
6639
|
+
result.messages.push(...processed.messages);
|
|
6640
|
+
root.markDirty();
|
|
6641
|
+
root.walk((node) => node.markDirty());
|
|
6642
|
+
}
|
|
6643
|
+
};
|
|
6644
|
+
}
|
|
6645
|
+
//#endregion
|
|
6465
6646
|
//#region src/pipeline.ts
|
|
6466
6647
|
function normalizeUserPlugins(plugins) {
|
|
6467
6648
|
if (!plugins) return [];
|
|
@@ -6497,11 +6678,11 @@ function isUniAppXNativeAuthorStyle(options) {
|
|
|
6497
6678
|
function appendUniAppXNativeAuthorDeclarationNodes(preparedNodes, options) {
|
|
6498
6679
|
if (options.uniAppXCssSource !== "author-apply") return;
|
|
6499
6680
|
const declarationPlugins = [
|
|
6681
|
+
["normal:calc", getCalcPlugin(options)],
|
|
6500
6682
|
["normal:units-to-px", getUnitsToPxPlugin(options)],
|
|
6501
6683
|
["normal:px-transform", getPxTransformPlugin(options)],
|
|
6502
6684
|
["normal:rem-transform", getRemTransformPlugin(options)],
|
|
6503
|
-
["normal:unit-conversion", getUnitConversionPlugin(options)]
|
|
6504
|
-
["normal:calc", getCalcPlugin(options)]
|
|
6685
|
+
["normal:unit-conversion", getUnitConversionPlugin(options)]
|
|
6505
6686
|
];
|
|
6506
6687
|
for (const [id, plugin] of declarationPlugins) if (plugin) preparedNodes.push(createPreparedNode(id, "normal", () => plugin));
|
|
6507
6688
|
}
|
|
@@ -6519,9 +6700,11 @@ function createPreparedNodes(options, signal) {
|
|
|
6519
6700
|
"cascade-layers": false
|
|
6520
6701
|
}
|
|
6521
6702
|
};
|
|
6522
|
-
userPlugins.forEach((plugin, index) => {
|
|
6703
|
+
(options.cssCalc && userPlugins.length > 0 ? [createUserPluginStage(userPlugins)] : userPlugins).forEach((plugin, index) => {
|
|
6523
6704
|
preparedNodes.push(createPreparedNode(`pre:user-${index}`, "pre", () => plugin));
|
|
6524
6705
|
});
|
|
6706
|
+
const calcPlugin = getCalcPlugin(options);
|
|
6707
|
+
if (calcPlugin) preparedNodes.push(createPreparedNode("pre:calc", "pre", () => calcPlugin));
|
|
6525
6708
|
preparedNodes.push(createPreparedNode("pre:core", "pre", () => postcssWeappTailwindcssPrePlugin(options)));
|
|
6526
6709
|
if (!signal || signal.hasPresetEnvFeatures) preparedNodes.push(createPreparedNode("normal:preset-env", "normal", () => (0, postcss_preset_env.default)(presetEnvOptions)));
|
|
6527
6710
|
if (!signal || signal.hasModernColorFunction) preparedNodes.push(createPreparedNode("normal:color-functional-fallback", "normal", () => createColorFunctionalFallback()));
|
|
@@ -6533,8 +6716,6 @@ function createPreparedNodes(options, signal) {
|
|
|
6533
6716
|
if (remTransformPlugin) preparedNodes.push(createPreparedNode("normal:rem-transform", "normal", () => remTransformPlugin));
|
|
6534
6717
|
const unitConversionPlugin = getUnitConversionPlugin(options);
|
|
6535
6718
|
if (unitConversionPlugin) preparedNodes.push(createPreparedNode("normal:unit-conversion", "normal", () => unitConversionPlugin));
|
|
6536
|
-
const calcPlugin = getCalcPlugin(options);
|
|
6537
|
-
if (calcPlugin) preparedNodes.push(createPreparedNode("normal:calc", "normal", () => calcPlugin));
|
|
6538
6719
|
const calcDuplicateCleaner = getCalcDuplicateCleaner(options);
|
|
6539
6720
|
if (calcDuplicateCleaner) preparedNodes.push(createPreparedNode("normal:calc-duplicate-cleaner", "normal", () => calcDuplicateCleaner));
|
|
6540
6721
|
const customPropertyCleaner = getCustomPropertyCleaner(options);
|
|
@@ -6643,10 +6824,9 @@ var StyleProcessorCache = class {
|
|
|
6643
6824
|
pipelineCacheByKey = /* @__PURE__ */ new Map();
|
|
6644
6825
|
processOptionsCache = /* @__PURE__ */ new WeakMap();
|
|
6645
6826
|
processorCacheByKey = /* @__PURE__ */ new Map();
|
|
6646
|
-
processorKeyCache = /* @__PURE__ */ new WeakMap();
|
|
6647
6827
|
createProcessorCacheKey(options) {
|
|
6648
|
-
if (options.postcssOptions?.options?.from == null) return
|
|
6649
|
-
return
|
|
6828
|
+
if (options.postcssOptions?.options?.from == null) return fingerprintStyleOptions(options);
|
|
6829
|
+
return fingerprintStyleOptions({
|
|
6650
6830
|
...options,
|
|
6651
6831
|
postcssOptions: {
|
|
6652
6832
|
...options.postcssOptions ?? {},
|
|
@@ -6665,11 +6845,7 @@ var StyleProcessorCache = class {
|
|
|
6665
6845
|
return `${optionsFingerprint}|${signalToCacheKey(signal)}`;
|
|
6666
6846
|
}
|
|
6667
6847
|
getPipeline(options, signal) {
|
|
6668
|
-
|
|
6669
|
-
if (!optionsKey) {
|
|
6670
|
-
optionsKey = this.createProcessorCacheKey(options);
|
|
6671
|
-
this.processorKeyCache.set(options, optionsKey);
|
|
6672
|
-
}
|
|
6848
|
+
const optionsKey = this.createProcessorCacheKey(options);
|
|
6673
6849
|
const compositeKey = this.createCompositeCacheKey(optionsKey, signal);
|
|
6674
6850
|
let pipeline = this.pipelineCacheByKey.get(compositeKey);
|
|
6675
6851
|
if (!pipeline) {
|
|
@@ -6693,11 +6869,7 @@ var StyleProcessorCache = class {
|
|
|
6693
6869
|
return { ...cached.value };
|
|
6694
6870
|
}
|
|
6695
6871
|
getProcessor(options, signal) {
|
|
6696
|
-
|
|
6697
|
-
if (!optionsKey) {
|
|
6698
|
-
optionsKey = this.createProcessorCacheKey(options);
|
|
6699
|
-
this.processorKeyCache.set(options, optionsKey);
|
|
6700
|
-
}
|
|
6872
|
+
const optionsKey = this.createProcessorCacheKey(options);
|
|
6701
6873
|
const compositeKey = this.createCompositeCacheKey(optionsKey, signal);
|
|
6702
6874
|
let processor = this.processorCacheByKey.get(compositeKey);
|
|
6703
6875
|
if (!processor) {
|
|
@@ -6725,25 +6897,14 @@ function simpleHash(str) {
|
|
|
6725
6897
|
return (hash >>> 0).toString(36);
|
|
6726
6898
|
}
|
|
6727
6899
|
function createStyleHandler(options) {
|
|
6728
|
-
const
|
|
6900
|
+
const normalizedOptions = normalizeCssOptions(options ?? {});
|
|
6901
|
+
const cachedOptions = (0, _weapp_tailwindcss_shared.defuOverrideArray)(normalizedOptions, normalizeCssOptions(getDefaultOptions(normalizedOptions), normalizedOptions.cssOptions !== void 0));
|
|
6729
6902
|
cachedOptions.cssInjectPreflight = require_preflight.createInjectPreflight(cachedOptions.cssPreflight);
|
|
6730
6903
|
const resolver = createOptionsResolver(cachedOptions);
|
|
6731
6904
|
const processorCache = new StyleProcessorCache();
|
|
6732
6905
|
const base = resolver.resolve();
|
|
6733
6906
|
processorCache.getProcessor(base);
|
|
6734
6907
|
processorCache.getProcessOptions(base);
|
|
6735
|
-
/** 选项指纹缓存,避免重复序列化 */
|
|
6736
|
-
const optionsFingerprintCache = /* @__PURE__ */ new WeakMap();
|
|
6737
|
-
/**
|
|
6738
|
-
* 获取选项指纹(带缓存)
|
|
6739
|
-
*/
|
|
6740
|
-
function getOptionsFingerprint(opts) {
|
|
6741
|
-
const cached = optionsFingerprintCache.get(opts);
|
|
6742
|
-
if (cached) return cached;
|
|
6743
|
-
const fp = fingerprintOptions(opts);
|
|
6744
|
-
optionsFingerprintCache.set(opts, fp);
|
|
6745
|
-
return fp;
|
|
6746
|
-
}
|
|
6747
6908
|
/** CSS 处理结果 LRU 缓存 */
|
|
6748
6909
|
const resultCache = new lru_cache.LRUCache({ max: CSS_RESULT_CACHE_MAX });
|
|
6749
6910
|
/** 检测是否配置了用户 postcss 插件(如 tailwindcss),有用户插件时不做内容探测 */
|
|
@@ -6771,7 +6932,7 @@ function createStyleHandler(options) {
|
|
|
6771
6932
|
} catch {
|
|
6772
6933
|
signal = void 0;
|
|
6773
6934
|
}
|
|
6774
|
-
const cacheKey = `${
|
|
6935
|
+
const cacheKey = `${fingerprintStyleOptions(resolvedOptions)}|${signal ? signalToCacheKey(signal) : ""}|${simpleHash(source)}`;
|
|
6775
6936
|
const cachedResult = resultCache.get(cacheKey);
|
|
6776
6937
|
if (cachedResult) {
|
|
6777
6938
|
resolvedOptions.onDiagnostic?.({
|
|
@@ -6860,51 +7021,6 @@ function assertRootResult(result) {
|
|
|
6860
7021
|
if (result.root.type !== "root") throw new TypeError("StyleHandler.transformRoot must return a single PostCSS Root.");
|
|
6861
7022
|
}
|
|
6862
7023
|
//#endregion
|
|
6863
|
-
//#region src/utils/custom-property-values.ts
|
|
6864
|
-
/** 按声明顺序收集构建期上下文,不推断级联或运行时作用域。 */
|
|
6865
|
-
function collectCustomPropertyValues(css) {
|
|
6866
|
-
const values = /* @__PURE__ */ new Map();
|
|
6867
|
-
mergeCustomPropertyValues$1(values, css);
|
|
6868
|
-
return values;
|
|
6869
|
-
}
|
|
6870
|
-
/** 直接合并到调用方上下文,避免中间 Map;后出现的声明覆盖旧值。 */
|
|
6871
|
-
function mergeCustomPropertyValues$1(target, css) {
|
|
6872
|
-
if (!css.includes("--")) return;
|
|
6873
|
-
try {
|
|
6874
|
-
postcss.default.parse(css).walkDecls((decl) => {
|
|
6875
|
-
if (decl.prop.startsWith("--")) target.set(decl.prop, decl.value.trim());
|
|
6876
|
-
});
|
|
6877
|
-
} catch {}
|
|
6878
|
-
}
|
|
6879
|
-
//#endregion
|
|
6880
|
-
//#region src/plugins/applyConfiguredCssCalc.ts
|
|
6881
|
-
function resolveCssCalcOption(options) {
|
|
6882
|
-
return options.cssOptions?.cssCalc ?? options.cssCalc;
|
|
6883
|
-
}
|
|
6884
|
-
function mergeCustomPropertyValues(css, options) {
|
|
6885
|
-
const values = collectCustomPropertyValues(options.contextCss ?? "");
|
|
6886
|
-
mergeCustomPropertyValues$1(values, css);
|
|
6887
|
-
for (const [name, value] of options.customPropertyValues ?? []) values.set(name, value);
|
|
6888
|
-
return values;
|
|
6889
|
-
}
|
|
6890
|
-
/**
|
|
6891
|
-
* 仅按 `cssCalc` 配置预计算 `calc()` / `var()`,不跑小程序选择器替换或单位转换。
|
|
6892
|
-
*/
|
|
6893
|
-
async function applyConfiguredCssCalc(css, options = {}) {
|
|
6894
|
-
const cssCalc = resolveCssCalcOption(options);
|
|
6895
|
-
if (!cssCalc || !css.includes("calc(")) return css;
|
|
6896
|
-
const plugin = getCalcPlugin({
|
|
6897
|
-
cssCalc,
|
|
6898
|
-
customPropertyValues: mergeCustomPropertyValues(css, options)
|
|
6899
|
-
});
|
|
6900
|
-
if (!plugin) return css;
|
|
6901
|
-
try {
|
|
6902
|
-
return (await (0, postcss.default)([plugin]).process(css, { from: void 0 })).css;
|
|
6903
|
-
} catch {
|
|
6904
|
-
return css;
|
|
6905
|
-
}
|
|
6906
|
-
}
|
|
6907
|
-
//#endregion
|
|
6908
7024
|
//#region src/compat/tailwindcss-v4/generated-output.ts
|
|
6909
7025
|
const defaultStyleHandler = createStyleHandler({
|
|
6910
7026
|
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
@@ -6926,7 +7042,7 @@ function normalizeTailwindV4GeneratedUrlValues(css) {
|
|
|
6926
7042
|
}
|
|
6927
7043
|
async function transformTailwindV4CssToWeapp(css, options) {
|
|
6928
7044
|
const compatibleCss = normalizeTailwindV4GeneratedUrlValues(hasCssMacroStyleOptions(options) ? await transformCssMacroCss(css, options) : css);
|
|
6929
|
-
const customPropertyValues = options?.customPropertyValues;
|
|
7045
|
+
const customPropertyValues = new Map([...options?.customPropertyCompatibilityValues ?? [], ...options?.customPropertyValues ?? []]);
|
|
6930
7046
|
const protectedCss = require_resolve.protectDynamicColorMixAlpha(compatibleCss, { customPropertyValues });
|
|
6931
7047
|
const result = await defaultStyleHandler(protectedCss.css, {
|
|
6932
7048
|
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
@@ -8083,6 +8199,7 @@ async function transformGeneratorUserCss(source, options) {
|
|
|
8083
8199
|
if (options.generatorTarget !== "weapp") return applyConfiguredCssCalc(userSource, {
|
|
8084
8200
|
cssCalc: options.generatorStyleOptions.cssOptions?.cssCalc ?? options.generatorStyleOptions.cssCalc ?? options.cssUserHandlerOptions.cssOptions?.cssCalc ?? options.cssUserHandlerOptions.cssCalc,
|
|
8085
8201
|
customPropertyValues: options.generatorStyleOptions.customPropertyValues ?? options.cssUserHandlerOptions.customPropertyValues,
|
|
8202
|
+
customPropertyContextCss: options.generatorStyleOptions.customPropertyContextCss ?? options.cssUserHandlerOptions.customPropertyContextCss,
|
|
8086
8203
|
contextCss: typeof options.generatedSource === "string" ? options.generatedSource : void 0
|
|
8087
8204
|
});
|
|
8088
8205
|
const { css } = await options.styleHandler(userSource, {
|
|
@@ -8655,6 +8772,27 @@ function isWebpackTailwindGeneratedUtilitySelector(selector, includePrefix) {
|
|
|
8655
8772
|
return WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE.test(selector) || includePrefix && WEBPACK_TAILWIND_UTILITY_PREFIX_RE.test(selector);
|
|
8656
8773
|
}
|
|
8657
8774
|
//#endregion
|
|
8775
|
+
//#region src/utils/deferred-css-source.ts
|
|
8776
|
+
const marker = /\/\*!?\s*weapp-tailwindcss deferred-source:([^\s*]+)\s*\*\//g;
|
|
8777
|
+
/** 为延后生成的入口保留来源身份,供构建器在合并后查询生命周期缓存。 */
|
|
8778
|
+
function createDeferredCssSourceMarker(file) {
|
|
8779
|
+
return `/*! weapp-tailwindcss deferred-source:${encodeURIComponent(file).replace(/\*/g, "%2A")} */`;
|
|
8780
|
+
}
|
|
8781
|
+
/** 按产物中的出现顺序读取来源,不把标记当作文件系统读取授权。 */
|
|
8782
|
+
function readDeferredCssSourceMarkers(css) {
|
|
8783
|
+
return [...new Set([...css.matchAll(marker)].flatMap((match) => {
|
|
8784
|
+
try {
|
|
8785
|
+
return [decodeURIComponent(match[1])];
|
|
8786
|
+
} catch {
|
|
8787
|
+
return [];
|
|
8788
|
+
}
|
|
8789
|
+
}))];
|
|
8790
|
+
}
|
|
8791
|
+
/** 最终产物不保留构建期来源标记。 */
|
|
8792
|
+
function stripDeferredCssSourceMarkers(css) {
|
|
8793
|
+
return css.replace(marker, "");
|
|
8794
|
+
}
|
|
8795
|
+
//#endregion
|
|
8658
8796
|
//#region src/utils/generated-css-marker.ts
|
|
8659
8797
|
const BUNDLER_GENERATED_CSS_MARKER_RE = /\/\*!?\s*weapp-tailwindcss (?:gulp|vite|webpack)-generated-css(?:\s*:\s*[^\s*]+)?\s*\*\/\s*/i;
|
|
8660
8798
|
const BUNDLER_GENERATED_CSS_MARKER_GLOBAL_RE = /\/\*!?\s*weapp-tailwindcss (?:gulp|vite|webpack)-generated-css(?:\s*:\s*[^\s*]+)?\s*\*\/\s*/gi;
|
|
@@ -8671,7 +8809,7 @@ function hasBundlerGeneratedCssMarker(source) {
|
|
|
8671
8809
|
return typeof source === "string" && BUNDLER_GENERATED_CSS_MARKER_RE.test(source);
|
|
8672
8810
|
}
|
|
8673
8811
|
function stripBundlerGeneratedCssMarkers(source) {
|
|
8674
|
-
return source.replace(BUNDLER_GENERATED_CSS_MARKER_GLOBAL_RE, "").replace(BUNDLER_GENERATED_CSS_END_MARKER_GLOBAL_RE, "").replace(VITE_INTERNAL_CSS_MARKER_GLOBAL_RE, "");
|
|
8812
|
+
return stripDeferredCssSourceMarkers(source).replace(BUNDLER_GENERATED_CSS_MARKER_GLOBAL_RE, "").replace(BUNDLER_GENERATED_CSS_END_MARKER_GLOBAL_RE, "").replace(VITE_INTERNAL_CSS_MARKER_GLOBAL_RE, "");
|
|
8675
8813
|
}
|
|
8676
8814
|
function parseBundlerGeneratedCssMarkerBlocks(source) {
|
|
8677
8815
|
const blocks = [];
|
|
@@ -9080,6 +9218,27 @@ async function processFrameworkCss(css, options) {
|
|
|
9080
9218
|
});
|
|
9081
9219
|
}
|
|
9082
9220
|
//#endregion
|
|
9221
|
+
//#region src/plugins/applyConfiguredCssUnits.ts
|
|
9222
|
+
/** 在跨资产 calc 求值之后按原管线顺序转换单位,不重复选择器和框架兼容变换。 */
|
|
9223
|
+
async function applyConfiguredCssUnits(css, options = {}) {
|
|
9224
|
+
const resolved = {
|
|
9225
|
+
...options,
|
|
9226
|
+
platform: options.cssOptions?.platform ?? options.platform,
|
|
9227
|
+
rem2rpx: options.cssOptions?.rem2rpx ?? options.rem2rpx,
|
|
9228
|
+
px2rpx: options.cssOptions?.px2rpx ?? options.px2rpx,
|
|
9229
|
+
unitsToPx: options.cssOptions?.unitsToPx ?? options.unitsToPx,
|
|
9230
|
+
unitConversion: options.cssOptions?.unitConversion ?? options.unitConversion
|
|
9231
|
+
};
|
|
9232
|
+
const plugins = [
|
|
9233
|
+
getUnitsToPxPlugin(resolved),
|
|
9234
|
+
getPxTransformPlugin(resolved),
|
|
9235
|
+
getRemTransformPlugin(resolved),
|
|
9236
|
+
getUnitConversionPlugin(resolved)
|
|
9237
|
+
].filter((plugin) => plugin !== null);
|
|
9238
|
+
if (plugins.length === 0) return css;
|
|
9239
|
+
return (await (0, postcss.default)(plugins).process(css, { from: options.postcssOptions?.options?.from })).css;
|
|
9240
|
+
}
|
|
9241
|
+
//#endregion
|
|
9083
9242
|
//#region src/source-scan/tailwind-v4/entry-source.ts
|
|
9084
9243
|
function collectSourceDirectives(root) {
|
|
9085
9244
|
const descriptor = require_resolve.describeCssSources(root, isTailwindV4CssImportParam);
|
|
@@ -9388,6 +9547,23 @@ function annotateCssTokenSources(css, tokenSources) {
|
|
|
9388
9547
|
}
|
|
9389
9548
|
}
|
|
9390
9549
|
//#endregion
|
|
9550
|
+
//#region src/utils/custom-property-values.ts
|
|
9551
|
+
/** 按声明顺序收集构建期上下文,不推断级联或运行时作用域。 */
|
|
9552
|
+
function collectCustomPropertyValues(css) {
|
|
9553
|
+
const values = /* @__PURE__ */ new Map();
|
|
9554
|
+
mergeCustomPropertyValues(values, css);
|
|
9555
|
+
return values;
|
|
9556
|
+
}
|
|
9557
|
+
/** 直接合并到调用方上下文,避免中间 Map;后出现的声明覆盖旧值。 */
|
|
9558
|
+
function mergeCustomPropertyValues(target, css) {
|
|
9559
|
+
if (!css.includes("--")) return;
|
|
9560
|
+
try {
|
|
9561
|
+
postcss.default.parse(css).walkDecls((decl) => {
|
|
9562
|
+
if (decl.prop.startsWith("--")) target.set(decl.prop, decl.value.trim());
|
|
9563
|
+
});
|
|
9564
|
+
} catch {}
|
|
9565
|
+
}
|
|
9566
|
+
//#endregion
|
|
9391
9567
|
Object.defineProperty(exports, "CSS_MACRO_STYLE_OPTIONS_MARKER", {
|
|
9392
9568
|
enumerable: true,
|
|
9393
9569
|
get: function() {
|
|
@@ -9460,6 +9636,12 @@ Object.defineProperty(exports, "VITE_MARKER_RE", {
|
|
|
9460
9636
|
return VITE_MARKER_RE;
|
|
9461
9637
|
}
|
|
9462
9638
|
});
|
|
9639
|
+
Object.defineProperty(exports, "analyzeCssCalcContext", {
|
|
9640
|
+
enumerable: true,
|
|
9641
|
+
get: function() {
|
|
9642
|
+
return analyzeCssCalcContext;
|
|
9643
|
+
}
|
|
9644
|
+
});
|
|
9463
9645
|
Object.defineProperty(exports, "analyzeTailwindV4EntrySource", {
|
|
9464
9646
|
enumerable: true,
|
|
9465
9647
|
get: function() {
|
|
@@ -9484,6 +9666,12 @@ Object.defineProperty(exports, "applyConfiguredCssCalc", {
|
|
|
9484
9666
|
return applyConfiguredCssCalc;
|
|
9485
9667
|
}
|
|
9486
9668
|
});
|
|
9669
|
+
Object.defineProperty(exports, "applyConfiguredCssUnits", {
|
|
9670
|
+
enumerable: true,
|
|
9671
|
+
get: function() {
|
|
9672
|
+
return applyConfiguredCssUnits;
|
|
9673
|
+
}
|
|
9674
|
+
});
|
|
9487
9675
|
Object.defineProperty(exports, "canProcessSourceStyleAsCss", {
|
|
9488
9676
|
enumerable: true,
|
|
9489
9677
|
get: function() {
|
|
@@ -9706,6 +9894,12 @@ Object.defineProperty(exports, "createCssSourceOrderAppend", {
|
|
|
9706
9894
|
return createCssSourceOrderAppend;
|
|
9707
9895
|
}
|
|
9708
9896
|
});
|
|
9897
|
+
Object.defineProperty(exports, "createDeferredCssSourceMarker", {
|
|
9898
|
+
enumerable: true,
|
|
9899
|
+
get: function() {
|
|
9900
|
+
return createDeferredCssSourceMarker;
|
|
9901
|
+
}
|
|
9902
|
+
});
|
|
9709
9903
|
Object.defineProperty(exports, "createFallbackPlaceholderReplacer", {
|
|
9710
9904
|
enumerable: true,
|
|
9711
9905
|
get: function() {
|
|
@@ -10066,6 +10260,12 @@ Object.defineProperty(exports, "isCssAlreadyRepresentedByMarkers", {
|
|
|
10066
10260
|
return isCssAlreadyRepresentedByMarkers;
|
|
10067
10261
|
}
|
|
10068
10262
|
});
|
|
10263
|
+
Object.defineProperty(exports, "isCssCalcCustomPropertySelected", {
|
|
10264
|
+
enumerable: true,
|
|
10265
|
+
get: function() {
|
|
10266
|
+
return isCssCalcCustomPropertySelected;
|
|
10267
|
+
}
|
|
10268
|
+
});
|
|
10069
10269
|
Object.defineProperty(exports, "isCssImportOnly", {
|
|
10070
10270
|
enumerable: true,
|
|
10071
10271
|
get: function() {
|
|
@@ -10207,7 +10407,7 @@ Object.defineProperty(exports, "mergeCoveredCssRuleDeclarations", {
|
|
|
10207
10407
|
Object.defineProperty(exports, "mergeCustomPropertyValues", {
|
|
10208
10408
|
enumerable: true,
|
|
10209
10409
|
get: function() {
|
|
10210
|
-
return mergeCustomPropertyValues
|
|
10410
|
+
return mergeCustomPropertyValues;
|
|
10211
10411
|
}
|
|
10212
10412
|
});
|
|
10213
10413
|
Object.defineProperty(exports, "mergeMarkedUserLayerComponentsCss", {
|
|
@@ -10444,6 +10644,12 @@ Object.defineProperty(exports, "pruneMiniProgramGeneratedCss", {
|
|
|
10444
10644
|
return pruneMiniProgramGeneratedCss;
|
|
10445
10645
|
}
|
|
10446
10646
|
});
|
|
10647
|
+
Object.defineProperty(exports, "readDeferredCssSourceMarkers", {
|
|
10648
|
+
enumerable: true,
|
|
10649
|
+
get: function() {
|
|
10650
|
+
return readDeferredCssSourceMarkers;
|
|
10651
|
+
}
|
|
10652
|
+
});
|
|
10447
10653
|
Object.defineProperty(exports, "removeBalancedAtRuleBlock", {
|
|
10448
10654
|
enumerable: true,
|
|
10449
10655
|
get: function() {
|
|
@@ -10846,6 +11052,12 @@ Object.defineProperty(exports, "stripBundlerGeneratedCssMarkers", {
|
|
|
10846
11052
|
return stripBundlerGeneratedCssMarkers;
|
|
10847
11053
|
}
|
|
10848
11054
|
});
|
|
11055
|
+
Object.defineProperty(exports, "stripDeferredCssSourceMarkers", {
|
|
11056
|
+
enumerable: true,
|
|
11057
|
+
get: function() {
|
|
11058
|
+
return stripDeferredCssSourceMarkers;
|
|
11059
|
+
}
|
|
11060
|
+
});
|
|
10849
11061
|
Object.defineProperty(exports, "stripGeneratorPlaceholderMarkers", {
|
|
10850
11062
|
enumerable: true,
|
|
10851
11063
|
get: function() {
|