@weapp-tailwindcss/postcss 3.3.6 → 3.3.8
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-Cr-gZPUc.js +8263 -0
- package/dist/fingerprint.d.ts +3 -0
- package/dist/index.cjs +6 -3
- package/dist/index.js +7 -7
- package/dist/mp.d.ts +5 -1
- package/dist/{plugin-CpkRzMhp.js → plugin-B-3Uojy6.js} +2 -2
- package/dist/{plugin-BWDgxMn5.cjs → plugin-BQGekI-c.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-CA9NfMTt.cjs +9999 -0
- package/dist/resolve-D-FbFBpF.js +1139 -0
- package/dist/{rewrite-imports-CdZQE6CI.js → rewrite-imports-Dk9TKKSF.js} +7 -8
- package/dist/syntax.cjs +638 -18
- package/dist/syntax.js +2 -2
- package/dist/{transform-Djx5HILQ.js → transform-D0hjc8vo.js} +330 -175
- package/dist/{transform-Xb48e-Wk.cjs → transform-D4J-AjP1.cjs} +351 -179
- package/dist/transform.cjs +5 -2
- package/dist/transform.d.ts +3 -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/package.json +11 -10
- package/dist/directives-DTKFO5Hv.js +0 -2630
- package/dist/resolve-DQiOQfoY.js +0 -354
- package/dist/resolve-EBh65bS8.cjs +0 -3556
|
@@ -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-CA9NfMTt.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");
|
|
@@ -11,7 +11,6 @@ let postcss_value_parser = require("postcss-value-parser");
|
|
|
11
11
|
postcss_value_parser = require_rolldown_runtime.__toESM(postcss_value_parser, 1);
|
|
12
12
|
let postcss_selector_parser = require("postcss-selector-parser");
|
|
13
13
|
postcss_selector_parser = require_rolldown_runtime.__toESM(postcss_selector_parser, 1);
|
|
14
|
-
let _csstools_css_tokenizer = require("@csstools/css-tokenizer");
|
|
15
14
|
let node_path = require("node:path");
|
|
16
15
|
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
17
16
|
let postcss_preset_env = require("postcss-preset-env");
|
|
@@ -296,19 +295,236 @@ function normalizeTailwindV4RuntimeCss(css) {
|
|
|
296
295
|
return root.toString();
|
|
297
296
|
}
|
|
298
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
|
|
299
508
|
//#region src/compat/mini-program-css/prune-generated.ts
|
|
300
509
|
const DEFAULT_WEAPP_VARIABLE_SCOPE = "page,.tw-root,wx-root-portal-content,:host";
|
|
301
510
|
const MINI_PROGRAM_PSEUDO_CONTENT_SCOPE_SELECTOR = "::before,\n::after";
|
|
302
511
|
const CLASS_SELECTOR_RE$2 = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
303
512
|
/**
|
|
304
|
-
*
|
|
513
|
+
* 在主题作用域改写前按配置预计算 calc,再展开 Tailwind 生成的嵌套规则并裁剪 Web-only 结构。
|
|
305
514
|
*/
|
|
306
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
|
+
});
|
|
307
523
|
return pruneMiniProgramGeneratedCss((await (0, postcss.default)([(0, postcss_preset_env.default)({
|
|
308
524
|
stage: false,
|
|
309
525
|
features: { "nesting-rules": true },
|
|
310
526
|
autoprefixer: false
|
|
311
|
-
})]).process(
|
|
527
|
+
})]).process(calculatedCss, { from: void 0 })).css, options);
|
|
312
528
|
}
|
|
313
529
|
function isConditionalCompilationComment(text) {
|
|
314
530
|
return /#(?:ifn?def|endif)\b/.test(text);
|
|
@@ -1067,7 +1283,7 @@ function applyUniAppXUvueCompatibility(result, options) {
|
|
|
1067
1283
|
const sfcStyleRequest = options?.isMainChunk !== true && isUvueSfcStyleRequest(result);
|
|
1068
1284
|
let root = result.root;
|
|
1069
1285
|
let calcMessages = [];
|
|
1070
|
-
consumeUniAppXSystemRootTheme(root, options?.customPropertyValues);
|
|
1286
|
+
consumeUniAppXSystemRootTheme(root, new Map([...options?.customPropertyCompatibilityValues ?? [], ...options?.customPropertyValues ?? []]));
|
|
1071
1287
|
if (root.type === "root" && Array.isArray(root.nodes) && typeof root.walkDecls === "function") {
|
|
1072
1288
|
root.walkDecls((decl) => {
|
|
1073
1289
|
require_resolve.normalizeTailwindcssV4Declaration(decl);
|
|
@@ -4467,7 +4683,7 @@ function getDefaultOptions(options) {
|
|
|
4467
4683
|
"oklab-function": true,
|
|
4468
4684
|
"color-mix": true,
|
|
4469
4685
|
"color-functional-notation": options?.cssPresetEnv?.features?.["color-functional-notation"] ?? { preserve: false },
|
|
4470
|
-
"custom-properties": options?.cssPresetEnv?.features?.["custom-properties"] ??
|
|
4686
|
+
"custom-properties": options?.cssPresetEnv?.features?.["custom-properties"] ?? false
|
|
4471
4687
|
},
|
|
4472
4688
|
autoprefixer: { add: false }
|
|
4473
4689
|
},
|
|
@@ -4500,12 +4716,17 @@ function fingerprintOptions(value, state = {
|
|
|
4500
4716
|
const marker = `ref:${state.counter++}`;
|
|
4501
4717
|
state.map.set(objectValue, marker);
|
|
4502
4718
|
if (Array.isArray(objectValue)) return `[${objectValue.map((entry) => fingerprintOptions(entry, state)).join(",")}]`;
|
|
4719
|
+
if (objectValue instanceof RegExp) return `regexp:${objectValue.source}/${objectValue.flags}`;
|
|
4503
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}`;
|
|
4504
4721
|
return `{${Object.keys(objectValue).sort().map((key) => `${key}:${fingerprintOptions(objectValue[key], state)}`).join(",")}}@${marker}`;
|
|
4505
4722
|
}
|
|
4723
|
+
/** 处理器运行时状态不参与输入签名,其余选项每次按实际内容计算。 */
|
|
4724
|
+
function fingerprintStyleOptions(options) {
|
|
4725
|
+
const { ctx: _ctx, ...inputs } = options;
|
|
4726
|
+
return fingerprintOptions(inputs);
|
|
4727
|
+
}
|
|
4506
4728
|
//#endregion
|
|
4507
4729
|
//#region src/options-resolver.ts
|
|
4508
|
-
const BASE_CACHE_KEY = "base";
|
|
4509
4730
|
const SIMPLE_OVERRIDE_UNSET = "__unset__";
|
|
4510
4731
|
const CSS_OPTION_KEYS = [
|
|
4511
4732
|
"cssPreflight",
|
|
@@ -4680,32 +4901,17 @@ function normalizeCssOptions(options, mirrorTopLevel = false) {
|
|
|
4680
4901
|
function createOptionsResolver(baseOptions) {
|
|
4681
4902
|
const normalizedBaseOptions = normalizeCssOptions(baseOptions);
|
|
4682
4903
|
const cacheByKey = /* @__PURE__ */ new Map();
|
|
4683
|
-
const cacheByRef = /* @__PURE__ */ new WeakMap();
|
|
4684
|
-
const cacheKeyByRef = /* @__PURE__ */ new WeakMap();
|
|
4685
|
-
const emptyOverrideRefs = /* @__PURE__ */ new WeakSet();
|
|
4686
|
-
cacheByKey.set(BASE_CACHE_KEY, normalizedBaseOptions);
|
|
4687
4904
|
const resolve = (overrides) => {
|
|
4688
4905
|
if (!overrides) return normalizedBaseOptions;
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
if (emptyOverrideRefs.has(overrides)) return normalizedBaseOptions;
|
|
4692
|
-
if (!hasOverrides(overrides)) {
|
|
4693
|
-
emptyOverrideRefs.add(overrides);
|
|
4694
|
-
return normalizedBaseOptions;
|
|
4695
|
-
}
|
|
4696
|
-
let key = cacheKeyByRef.get(overrides);
|
|
4697
|
-
if (!key) {
|
|
4698
|
-
key = getSimpleOverrideCacheKey(overrides) ?? fingerprintOptions(overrides);
|
|
4699
|
-
cacheKeyByRef.set(overrides, key);
|
|
4700
|
-
}
|
|
4906
|
+
if (!hasOverrides(overrides)) return normalizedBaseOptions;
|
|
4907
|
+
const key = getSimpleOverrideCacheKey(overrides) ?? fingerprintOptions(overrides);
|
|
4701
4908
|
const cached = cacheByKey.get(key);
|
|
4702
|
-
if (cached)
|
|
4703
|
-
cacheByRef.set(overrides, cached);
|
|
4704
|
-
return cached;
|
|
4705
|
-
}
|
|
4909
|
+
if (cached && fingerprintStyleOptions(cached.options) === cached.fingerprint) return cached.options;
|
|
4706
4910
|
const normalized = normalizeCssOptions((0, _weapp_tailwindcss_shared.defuOverrideArray)(normalizeCssOptions({ ...overrides }, true), normalizedBaseOptions));
|
|
4707
|
-
cacheByKey.set(key,
|
|
4708
|
-
|
|
4911
|
+
cacheByKey.set(key, {
|
|
4912
|
+
options: normalized,
|
|
4913
|
+
fingerprint: fingerprintStyleOptions(normalized)
|
|
4914
|
+
});
|
|
4709
4915
|
return normalized;
|
|
4710
4916
|
};
|
|
4711
4917
|
return { resolve };
|
|
@@ -4856,70 +5062,15 @@ function getCalcDuplicateCleaner(options) {
|
|
|
4856
5062
|
return calcDuplicateCleanerPlugin;
|
|
4857
5063
|
}
|
|
4858
5064
|
//#endregion
|
|
4859
|
-
//#region src/plugins/getCalcPlugin.ts
|
|
4860
|
-
const EMPTY_CALC_OPTIONS = {};
|
|
4861
|
-
function getCalcPlugin(options) {
|
|
4862
|
-
if (!options.cssCalc) return null;
|
|
4863
|
-
if (options.cssCalc === true || Array.isArray(options.cssCalc)) {
|
|
4864
|
-
const calcOptions = Array.isArray(options.cssCalc) ? {
|
|
4865
|
-
includeCustomProperties: options.cssCalc,
|
|
4866
|
-
...options.customPropertyValues ? { customPropertyValues: options.customPropertyValues } : {}
|
|
4867
|
-
} : options.customPropertyValues ? {
|
|
4868
|
-
customPropertyValues: options.customPropertyValues,
|
|
4869
|
-
includeCustomProperties: [...options.customPropertyValues.keys()]
|
|
4870
|
-
} : EMPTY_CALC_OPTIONS;
|
|
4871
|
-
return (0, _weapp_tailwindcss_postcss_calc.default)(calcOptions);
|
|
4872
|
-
}
|
|
4873
|
-
return (0, _weapp_tailwindcss_postcss_calc.default)({
|
|
4874
|
-
...options.cssCalc,
|
|
4875
|
-
...options.customPropertyValues ? { customPropertyValues: options.customPropertyValues } : {}
|
|
4876
|
-
});
|
|
4877
|
-
}
|
|
4878
|
-
//#endregion
|
|
4879
5065
|
//#region src/plugins/getCustomPropertyCleaner.ts
|
|
4880
5066
|
function getCustomPropertyCleaner(options) {
|
|
4881
|
-
|
|
4882
|
-
if (!(Array.isArray(includeCustomProperties) && includeCustomProperties.length > 0)) return null;
|
|
4883
|
-
const shouldInspectValue = (value) => value.includes("var(") && value.includes("--");
|
|
4884
|
-
const containsIncludedCustomProperty = (value) => {
|
|
4885
|
-
if (!shouldInspectValue(value)) return false;
|
|
4886
|
-
const parsed = (0, postcss_value_parser.default)(value);
|
|
4887
|
-
let containsIncludedCustomProperty = false;
|
|
4888
|
-
parsed.walk((node) => {
|
|
4889
|
-
if (node.type !== "function" || node.value !== "var" || containsIncludedCustomProperty) return;
|
|
4890
|
-
if (node.nodes.find((x) => {
|
|
4891
|
-
return x.type === "word" && (0, _weapp_tailwindcss_shared.regExpTest)(includeCustomProperties, x.value);
|
|
4892
|
-
})) containsIncludedCustomProperty = true;
|
|
4893
|
-
});
|
|
4894
|
-
return containsIncludedCustomProperty;
|
|
4895
|
-
};
|
|
4896
|
-
const hasSameSourceRange = (left, right) => {
|
|
4897
|
-
const leftSource = left.source;
|
|
4898
|
-
const rightSource = right.source;
|
|
4899
|
-
if (!leftSource?.start || !leftSource.end || !rightSource?.start || !rightSource.end || leftSource.input !== rightSource.input) return false;
|
|
4900
|
-
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;
|
|
4901
|
-
};
|
|
5067
|
+
if (!(Array.isArray(options.cssCalc) ? options.cssCalc : typeof options.cssCalc === "object" ? options.cssCalc.includeCustomProperties : void 0)?.length) return null;
|
|
4902
5068
|
return {
|
|
4903
5069
|
postcssPlugin: "postcss-remove-include-custom-properties",
|
|
4904
5070
|
OnceExit(root) {
|
|
4905
5071
|
root.walkDecls((decl) => {
|
|
4906
|
-
const
|
|
4907
|
-
if (
|
|
4908
|
-
decl.remove();
|
|
4909
|
-
return;
|
|
4910
|
-
}
|
|
4911
|
-
if (!containsIncludedCustomProperty(decl.value)) return;
|
|
4912
|
-
let fallbackDecl;
|
|
4913
|
-
let node = prevNode;
|
|
4914
|
-
while (node) {
|
|
4915
|
-
if (node.type === "decl" && node.prop === decl.prop) {
|
|
4916
|
-
fallbackDecl = node;
|
|
4917
|
-
break;
|
|
4918
|
-
}
|
|
4919
|
-
node = node.prev();
|
|
4920
|
-
}
|
|
4921
|
-
if (!fallbackDecl || fallbackDecl.important !== decl.important || fallbackDecl !== prevNode && !hasSameSourceRange(fallbackDecl, decl) || containsIncludedCustomProperty(fallbackDecl.value)) return;
|
|
4922
|
-
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();
|
|
4923
5074
|
});
|
|
4924
5075
|
}
|
|
4925
5076
|
};
|
|
@@ -6321,11 +6472,12 @@ function removeTailwindV4EmptyContentInit(node) {
|
|
|
6321
6472
|
if (isEmptyContentInitDeclaration(decl)) decl.remove();
|
|
6322
6473
|
});
|
|
6323
6474
|
}
|
|
6324
|
-
function injectPreflightDeclarations(node, options) {
|
|
6475
|
+
function injectPreflightDeclarations(node, options, contentUsage) {
|
|
6325
6476
|
const preflightDeclarations = options.cssInjectPreflight?.();
|
|
6326
6477
|
if (!preflightDeclarations || preflightDeclarations.length === 0) return;
|
|
6327
6478
|
node.prepend(...preflightDeclarations);
|
|
6328
6479
|
node.raws.semicolon = true;
|
|
6480
|
+
contentUsage?.invalidate();
|
|
6329
6481
|
}
|
|
6330
6482
|
function hasClassSelector$1(node) {
|
|
6331
6483
|
return node.selectors.some((selector) => selector.includes("."));
|
|
@@ -6351,7 +6503,7 @@ function resolveUniAppXVariableScopeSelectors(options) {
|
|
|
6351
6503
|
if (typeof universal === "string" && universal.length > 0) return [universal];
|
|
6352
6504
|
return ["view", "text"];
|
|
6353
6505
|
}
|
|
6354
|
-
function commonChunkPreflight(node, options) {
|
|
6506
|
+
function commonChunkPreflight(node, options, contentUsage) {
|
|
6355
6507
|
const { ctx, injectAdditionalCssVarScope } = options;
|
|
6356
6508
|
const uniAppXEnabled = isUniAppXEnabled(options);
|
|
6357
6509
|
const isTailwindcss4 = require_resolve.isTailwindcssV4(options);
|
|
@@ -6364,14 +6516,16 @@ function commonChunkPreflight(node, options) {
|
|
|
6364
6516
|
phase: "pre",
|
|
6365
6517
|
reason: "append-host-selector"
|
|
6366
6518
|
});
|
|
6367
|
-
if (isTailwindcss4 &&
|
|
6519
|
+
if (isTailwindcss4 && (!hasClassSelector$1(node) || isRootThemeScopeRule(node))) {
|
|
6520
|
+
if (!(contentUsage?.read() ?? require_resolve.usesTailwindcssV4ContentVariable(node.root()))) removeTailwindV4EmptyContentInit(node);
|
|
6521
|
+
}
|
|
6368
6522
|
if (testIfVariablesScope(node) || uniAppXEnabled && node.selectors.includes("*") && hasTwVars(node, 2)) {
|
|
6369
6523
|
ctx?.markVariablesScope(node);
|
|
6370
6524
|
assignRuleSelectors(node, uniAppXEnabled ? resolveUniAppXVariableScopeSelectors(options) : remakeCssVarSelector(node.selectors, options), {
|
|
6371
6525
|
phase: "pre",
|
|
6372
6526
|
reason: "rewrite-variable-scope"
|
|
6373
6527
|
});
|
|
6374
|
-
injectPreflightDeclarations(node, options);
|
|
6528
|
+
injectPreflightDeclarations(node, options, contentUsage);
|
|
6375
6529
|
}
|
|
6376
6530
|
if (injectAdditionalCssVarScope && isTailwindcss4 && require_resolve.testIfRootHostForV4(node)) {
|
|
6377
6531
|
const nodes = require_resolve.createUsedCssVarsV4Nodes(require_resolve.collectUsedTailwindcssV4Variables(node.root()));
|
|
@@ -6389,7 +6543,8 @@ function commonChunkPreflight(node, options) {
|
|
|
6389
6543
|
reason: "rewrite-synthetic-variable-scope"
|
|
6390
6544
|
});
|
|
6391
6545
|
node.before(syntheticRule);
|
|
6392
|
-
|
|
6546
|
+
contentUsage?.invalidate();
|
|
6547
|
+
injectPreflightDeclarations(syntheticRule, options, contentUsage);
|
|
6393
6548
|
}
|
|
6394
6549
|
}
|
|
6395
6550
|
//#endregion
|
|
@@ -6455,14 +6610,39 @@ const postcssWeappTailwindcssPrePlugin = (options) => {
|
|
|
6455
6610
|
}
|
|
6456
6611
|
});
|
|
6457
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
|
+
};
|
|
6458
6620
|
root.walkRules((rule) => {
|
|
6459
|
-
commonChunkPreflight(rule, opts);
|
|
6621
|
+
commonChunkPreflight(rule, opts, contentUsage);
|
|
6460
6622
|
});
|
|
6461
6623
|
};
|
|
6462
6624
|
return p;
|
|
6463
6625
|
};
|
|
6464
6626
|
postcssWeappTailwindcssPrePlugin.postcss = true;
|
|
6465
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
|
|
6466
6646
|
//#region src/pipeline.ts
|
|
6467
6647
|
function normalizeUserPlugins(plugins) {
|
|
6468
6648
|
if (!plugins) return [];
|
|
@@ -6498,11 +6678,11 @@ function isUniAppXNativeAuthorStyle(options) {
|
|
|
6498
6678
|
function appendUniAppXNativeAuthorDeclarationNodes(preparedNodes, options) {
|
|
6499
6679
|
if (options.uniAppXCssSource !== "author-apply") return;
|
|
6500
6680
|
const declarationPlugins = [
|
|
6681
|
+
["normal:calc", getCalcPlugin(options)],
|
|
6501
6682
|
["normal:units-to-px", getUnitsToPxPlugin(options)],
|
|
6502
6683
|
["normal:px-transform", getPxTransformPlugin(options)],
|
|
6503
6684
|
["normal:rem-transform", getRemTransformPlugin(options)],
|
|
6504
|
-
["normal:unit-conversion", getUnitConversionPlugin(options)]
|
|
6505
|
-
["normal:calc", getCalcPlugin(options)]
|
|
6685
|
+
["normal:unit-conversion", getUnitConversionPlugin(options)]
|
|
6506
6686
|
];
|
|
6507
6687
|
for (const [id, plugin] of declarationPlugins) if (plugin) preparedNodes.push(createPreparedNode(id, "normal", () => plugin));
|
|
6508
6688
|
}
|
|
@@ -6520,9 +6700,11 @@ function createPreparedNodes(options, signal) {
|
|
|
6520
6700
|
"cascade-layers": false
|
|
6521
6701
|
}
|
|
6522
6702
|
};
|
|
6523
|
-
userPlugins.forEach((plugin, index) => {
|
|
6703
|
+
(options.cssCalc && userPlugins.length > 0 ? [createUserPluginStage(userPlugins)] : userPlugins).forEach((plugin, index) => {
|
|
6524
6704
|
preparedNodes.push(createPreparedNode(`pre:user-${index}`, "pre", () => plugin));
|
|
6525
6705
|
});
|
|
6706
|
+
const calcPlugin = getCalcPlugin(options);
|
|
6707
|
+
if (calcPlugin) preparedNodes.push(createPreparedNode("pre:calc", "pre", () => calcPlugin));
|
|
6526
6708
|
preparedNodes.push(createPreparedNode("pre:core", "pre", () => postcssWeappTailwindcssPrePlugin(options)));
|
|
6527
6709
|
if (!signal || signal.hasPresetEnvFeatures) preparedNodes.push(createPreparedNode("normal:preset-env", "normal", () => (0, postcss_preset_env.default)(presetEnvOptions)));
|
|
6528
6710
|
if (!signal || signal.hasModernColorFunction) preparedNodes.push(createPreparedNode("normal:color-functional-fallback", "normal", () => createColorFunctionalFallback()));
|
|
@@ -6534,8 +6716,6 @@ function createPreparedNodes(options, signal) {
|
|
|
6534
6716
|
if (remTransformPlugin) preparedNodes.push(createPreparedNode("normal:rem-transform", "normal", () => remTransformPlugin));
|
|
6535
6717
|
const unitConversionPlugin = getUnitConversionPlugin(options);
|
|
6536
6718
|
if (unitConversionPlugin) preparedNodes.push(createPreparedNode("normal:unit-conversion", "normal", () => unitConversionPlugin));
|
|
6537
|
-
const calcPlugin = getCalcPlugin(options);
|
|
6538
|
-
if (calcPlugin) preparedNodes.push(createPreparedNode("normal:calc", "normal", () => calcPlugin));
|
|
6539
6719
|
const calcDuplicateCleaner = getCalcDuplicateCleaner(options);
|
|
6540
6720
|
if (calcDuplicateCleaner) preparedNodes.push(createPreparedNode("normal:calc-duplicate-cleaner", "normal", () => calcDuplicateCleaner));
|
|
6541
6721
|
const customPropertyCleaner = getCustomPropertyCleaner(options);
|
|
@@ -6644,10 +6824,9 @@ var StyleProcessorCache = class {
|
|
|
6644
6824
|
pipelineCacheByKey = /* @__PURE__ */ new Map();
|
|
6645
6825
|
processOptionsCache = /* @__PURE__ */ new WeakMap();
|
|
6646
6826
|
processorCacheByKey = /* @__PURE__ */ new Map();
|
|
6647
|
-
processorKeyCache = /* @__PURE__ */ new WeakMap();
|
|
6648
6827
|
createProcessorCacheKey(options) {
|
|
6649
|
-
if (options.postcssOptions?.options?.from == null) return
|
|
6650
|
-
return
|
|
6828
|
+
if (options.postcssOptions?.options?.from == null) return fingerprintStyleOptions(options);
|
|
6829
|
+
return fingerprintStyleOptions({
|
|
6651
6830
|
...options,
|
|
6652
6831
|
postcssOptions: {
|
|
6653
6832
|
...options.postcssOptions ?? {},
|
|
@@ -6666,11 +6845,7 @@ var StyleProcessorCache = class {
|
|
|
6666
6845
|
return `${optionsFingerprint}|${signalToCacheKey(signal)}`;
|
|
6667
6846
|
}
|
|
6668
6847
|
getPipeline(options, signal) {
|
|
6669
|
-
|
|
6670
|
-
if (!optionsKey) {
|
|
6671
|
-
optionsKey = this.createProcessorCacheKey(options);
|
|
6672
|
-
this.processorKeyCache.set(options, optionsKey);
|
|
6673
|
-
}
|
|
6848
|
+
const optionsKey = this.createProcessorCacheKey(options);
|
|
6674
6849
|
const compositeKey = this.createCompositeCacheKey(optionsKey, signal);
|
|
6675
6850
|
let pipeline = this.pipelineCacheByKey.get(compositeKey);
|
|
6676
6851
|
if (!pipeline) {
|
|
@@ -6694,11 +6869,7 @@ var StyleProcessorCache = class {
|
|
|
6694
6869
|
return { ...cached.value };
|
|
6695
6870
|
}
|
|
6696
6871
|
getProcessor(options, signal) {
|
|
6697
|
-
|
|
6698
|
-
if (!optionsKey) {
|
|
6699
|
-
optionsKey = this.createProcessorCacheKey(options);
|
|
6700
|
-
this.processorKeyCache.set(options, optionsKey);
|
|
6701
|
-
}
|
|
6872
|
+
const optionsKey = this.createProcessorCacheKey(options);
|
|
6702
6873
|
const compositeKey = this.createCompositeCacheKey(optionsKey, signal);
|
|
6703
6874
|
let processor = this.processorCacheByKey.get(compositeKey);
|
|
6704
6875
|
if (!processor) {
|
|
@@ -6726,25 +6897,14 @@ function simpleHash(str) {
|
|
|
6726
6897
|
return (hash >>> 0).toString(36);
|
|
6727
6898
|
}
|
|
6728
6899
|
function createStyleHandler(options) {
|
|
6729
|
-
const
|
|
6900
|
+
const normalizedOptions = normalizeCssOptions(options ?? {});
|
|
6901
|
+
const cachedOptions = (0, _weapp_tailwindcss_shared.defuOverrideArray)(normalizedOptions, normalizeCssOptions(getDefaultOptions(normalizedOptions), normalizedOptions.cssOptions !== void 0));
|
|
6730
6902
|
cachedOptions.cssInjectPreflight = require_preflight.createInjectPreflight(cachedOptions.cssPreflight);
|
|
6731
6903
|
const resolver = createOptionsResolver(cachedOptions);
|
|
6732
6904
|
const processorCache = new StyleProcessorCache();
|
|
6733
6905
|
const base = resolver.resolve();
|
|
6734
6906
|
processorCache.getProcessor(base);
|
|
6735
6907
|
processorCache.getProcessOptions(base);
|
|
6736
|
-
/** 选项指纹缓存,避免重复序列化 */
|
|
6737
|
-
const optionsFingerprintCache = /* @__PURE__ */ new WeakMap();
|
|
6738
|
-
/**
|
|
6739
|
-
* 获取选项指纹(带缓存)
|
|
6740
|
-
*/
|
|
6741
|
-
function getOptionsFingerprint(opts) {
|
|
6742
|
-
const cached = optionsFingerprintCache.get(opts);
|
|
6743
|
-
if (cached) return cached;
|
|
6744
|
-
const fp = fingerprintOptions(opts);
|
|
6745
|
-
optionsFingerprintCache.set(opts, fp);
|
|
6746
|
-
return fp;
|
|
6747
|
-
}
|
|
6748
6908
|
/** CSS 处理结果 LRU 缓存 */
|
|
6749
6909
|
const resultCache = new lru_cache.LRUCache({ max: CSS_RESULT_CACHE_MAX });
|
|
6750
6910
|
/** 检测是否配置了用户 postcss 插件(如 tailwindcss),有用户插件时不做内容探测 */
|
|
@@ -6772,7 +6932,7 @@ function createStyleHandler(options) {
|
|
|
6772
6932
|
} catch {
|
|
6773
6933
|
signal = void 0;
|
|
6774
6934
|
}
|
|
6775
|
-
const cacheKey = `${
|
|
6935
|
+
const cacheKey = `${fingerprintStyleOptions(resolvedOptions)}|${signal ? signalToCacheKey(signal) : ""}|${simpleHash(source)}`;
|
|
6776
6936
|
const cachedResult = resultCache.get(cacheKey);
|
|
6777
6937
|
if (cachedResult) {
|
|
6778
6938
|
resolvedOptions.onDiagnostic?.({
|
|
@@ -6861,51 +7021,6 @@ function assertRootResult(result) {
|
|
|
6861
7021
|
if (result.root.type !== "root") throw new TypeError("StyleHandler.transformRoot must return a single PostCSS Root.");
|
|
6862
7022
|
}
|
|
6863
7023
|
//#endregion
|
|
6864
|
-
//#region src/utils/custom-property-values.ts
|
|
6865
|
-
/** 按声明顺序收集构建期上下文,不推断级联或运行时作用域。 */
|
|
6866
|
-
function collectCustomPropertyValues(css) {
|
|
6867
|
-
const values = /* @__PURE__ */ new Map();
|
|
6868
|
-
mergeCustomPropertyValues$1(values, css);
|
|
6869
|
-
return values;
|
|
6870
|
-
}
|
|
6871
|
-
/** 直接合并到调用方上下文,避免中间 Map;后出现的声明覆盖旧值。 */
|
|
6872
|
-
function mergeCustomPropertyValues$1(target, css) {
|
|
6873
|
-
if (!css.includes("--")) return;
|
|
6874
|
-
try {
|
|
6875
|
-
postcss.default.parse(css).walkDecls((decl) => {
|
|
6876
|
-
if (decl.prop.startsWith("--")) target.set(decl.prop, decl.value.trim());
|
|
6877
|
-
});
|
|
6878
|
-
} catch {}
|
|
6879
|
-
}
|
|
6880
|
-
//#endregion
|
|
6881
|
-
//#region src/plugins/applyConfiguredCssCalc.ts
|
|
6882
|
-
function resolveCssCalcOption(options) {
|
|
6883
|
-
return options.cssOptions?.cssCalc ?? options.cssCalc;
|
|
6884
|
-
}
|
|
6885
|
-
function mergeCustomPropertyValues(css, options) {
|
|
6886
|
-
const values = collectCustomPropertyValues(options.contextCss ?? "");
|
|
6887
|
-
mergeCustomPropertyValues$1(values, css);
|
|
6888
|
-
for (const [name, value] of options.customPropertyValues ?? []) values.set(name, value);
|
|
6889
|
-
return values;
|
|
6890
|
-
}
|
|
6891
|
-
/**
|
|
6892
|
-
* 仅按 `cssCalc` 配置预计算 `calc()` / `var()`,不跑小程序选择器替换或单位转换。
|
|
6893
|
-
*/
|
|
6894
|
-
async function applyConfiguredCssCalc(css, options = {}) {
|
|
6895
|
-
const cssCalc = resolveCssCalcOption(options);
|
|
6896
|
-
if (!cssCalc || !css.includes("calc(")) return css;
|
|
6897
|
-
const plugin = getCalcPlugin({
|
|
6898
|
-
cssCalc,
|
|
6899
|
-
customPropertyValues: mergeCustomPropertyValues(css, options)
|
|
6900
|
-
});
|
|
6901
|
-
if (!plugin) return css;
|
|
6902
|
-
try {
|
|
6903
|
-
return (await (0, postcss.default)([plugin]).process(css, { from: void 0 })).css;
|
|
6904
|
-
} catch {
|
|
6905
|
-
return css;
|
|
6906
|
-
}
|
|
6907
|
-
}
|
|
6908
|
-
//#endregion
|
|
6909
7024
|
//#region src/compat/tailwindcss-v4/generated-output.ts
|
|
6910
7025
|
const defaultStyleHandler = createStyleHandler({
|
|
6911
7026
|
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
@@ -6927,7 +7042,7 @@ function normalizeTailwindV4GeneratedUrlValues(css) {
|
|
|
6927
7042
|
}
|
|
6928
7043
|
async function transformTailwindV4CssToWeapp(css, options) {
|
|
6929
7044
|
const compatibleCss = normalizeTailwindV4GeneratedUrlValues(hasCssMacroStyleOptions(options) ? await transformCssMacroCss(css, options) : css);
|
|
6930
|
-
const customPropertyValues = options?.customPropertyValues;
|
|
7045
|
+
const customPropertyValues = new Map([...options?.customPropertyCompatibilityValues ?? [], ...options?.customPropertyValues ?? []]);
|
|
6931
7046
|
const protectedCss = require_resolve.protectDynamicColorMixAlpha(compatibleCss, { customPropertyValues });
|
|
6932
7047
|
const result = await defaultStyleHandler(protectedCss.css, {
|
|
6933
7048
|
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
@@ -8084,6 +8199,7 @@ async function transformGeneratorUserCss(source, options) {
|
|
|
8084
8199
|
if (options.generatorTarget !== "weapp") return applyConfiguredCssCalc(userSource, {
|
|
8085
8200
|
cssCalc: options.generatorStyleOptions.cssOptions?.cssCalc ?? options.generatorStyleOptions.cssCalc ?? options.cssUserHandlerOptions.cssOptions?.cssCalc ?? options.cssUserHandlerOptions.cssCalc,
|
|
8086
8201
|
customPropertyValues: options.generatorStyleOptions.customPropertyValues ?? options.cssUserHandlerOptions.customPropertyValues,
|
|
8202
|
+
customPropertyContextCss: options.generatorStyleOptions.customPropertyContextCss ?? options.cssUserHandlerOptions.customPropertyContextCss,
|
|
8087
8203
|
contextCss: typeof options.generatedSource === "string" ? options.generatedSource : void 0
|
|
8088
8204
|
});
|
|
8089
8205
|
const { css } = await options.styleHandler(userSource, {
|
|
@@ -9081,6 +9197,27 @@ async function processFrameworkCss(css, options) {
|
|
|
9081
9197
|
});
|
|
9082
9198
|
}
|
|
9083
9199
|
//#endregion
|
|
9200
|
+
//#region src/plugins/applyConfiguredCssUnits.ts
|
|
9201
|
+
/** 在跨资产 calc 求值之后按原管线顺序转换单位,不重复选择器和框架兼容变换。 */
|
|
9202
|
+
async function applyConfiguredCssUnits(css, options = {}) {
|
|
9203
|
+
const resolved = {
|
|
9204
|
+
...options,
|
|
9205
|
+
platform: options.cssOptions?.platform ?? options.platform,
|
|
9206
|
+
rem2rpx: options.cssOptions?.rem2rpx ?? options.rem2rpx,
|
|
9207
|
+
px2rpx: options.cssOptions?.px2rpx ?? options.px2rpx,
|
|
9208
|
+
unitsToPx: options.cssOptions?.unitsToPx ?? options.unitsToPx,
|
|
9209
|
+
unitConversion: options.cssOptions?.unitConversion ?? options.unitConversion
|
|
9210
|
+
};
|
|
9211
|
+
const plugins = [
|
|
9212
|
+
getUnitsToPxPlugin(resolved),
|
|
9213
|
+
getPxTransformPlugin(resolved),
|
|
9214
|
+
getRemTransformPlugin(resolved),
|
|
9215
|
+
getUnitConversionPlugin(resolved)
|
|
9216
|
+
].filter((plugin) => plugin !== null);
|
|
9217
|
+
if (plugins.length === 0) return css;
|
|
9218
|
+
return (await (0, postcss.default)(plugins).process(css, { from: options.postcssOptions?.options?.from })).css;
|
|
9219
|
+
}
|
|
9220
|
+
//#endregion
|
|
9084
9221
|
//#region src/source-scan/tailwind-v4/entry-source.ts
|
|
9085
9222
|
function collectSourceDirectives(root) {
|
|
9086
9223
|
const descriptor = require_resolve.describeCssSources(root, isTailwindV4CssImportParam);
|
|
@@ -9268,22 +9405,22 @@ function isIndependentUrl(value) {
|
|
|
9268
9405
|
function hasCssLocationDependencies(source) {
|
|
9269
9406
|
if (!LOCATION_SYNTAX_HINT_RE.test(source)) return false;
|
|
9270
9407
|
let malformed = false;
|
|
9271
|
-
const stream =
|
|
9408
|
+
const stream = require_resolve.tokenizer({ css: source }, { onParseError() {
|
|
9272
9409
|
malformed = true;
|
|
9273
9410
|
} });
|
|
9274
9411
|
const nextSignificant = () => {
|
|
9275
9412
|
let token = stream.nextToken();
|
|
9276
|
-
while (token[0] ===
|
|
9413
|
+
while (token[0] === require_resolve.u.Whitespace || token[0] === require_resolve.u.Comment) token = stream.nextToken();
|
|
9277
9414
|
return token;
|
|
9278
9415
|
};
|
|
9279
9416
|
while (!stream.endOfFile()) {
|
|
9280
9417
|
const token = stream.nextToken();
|
|
9281
|
-
if (token[0] ===
|
|
9282
|
-
if (token[0] ===
|
|
9283
|
-
if (token[0] ===
|
|
9418
|
+
if (token[0] === require_resolve.u.AtKeyword && token[4].value.toLowerCase() === "import") return true;
|
|
9419
|
+
if (token[0] === require_resolve.u.URL && !isIndependentUrl(token[4].value)) return true;
|
|
9420
|
+
if (token[0] === require_resolve.u.Function && token[4].value.toLowerCase() === "url") {
|
|
9284
9421
|
const value = nextSignificant();
|
|
9285
|
-
if (value[0] !==
|
|
9286
|
-
if (nextSignificant()[0] !==
|
|
9422
|
+
if (value[0] !== require_resolve.u.String || !isIndependentUrl(value[4].value)) return true;
|
|
9423
|
+
if (nextSignificant()[0] !== require_resolve.u.CloseParen) return true;
|
|
9287
9424
|
}
|
|
9288
9425
|
}
|
|
9289
9426
|
return malformed;
|
|
@@ -9389,6 +9526,23 @@ function annotateCssTokenSources(css, tokenSources) {
|
|
|
9389
9526
|
}
|
|
9390
9527
|
}
|
|
9391
9528
|
//#endregion
|
|
9529
|
+
//#region src/utils/custom-property-values.ts
|
|
9530
|
+
/** 按声明顺序收集构建期上下文,不推断级联或运行时作用域。 */
|
|
9531
|
+
function collectCustomPropertyValues(css) {
|
|
9532
|
+
const values = /* @__PURE__ */ new Map();
|
|
9533
|
+
mergeCustomPropertyValues(values, css);
|
|
9534
|
+
return values;
|
|
9535
|
+
}
|
|
9536
|
+
/** 直接合并到调用方上下文,避免中间 Map;后出现的声明覆盖旧值。 */
|
|
9537
|
+
function mergeCustomPropertyValues(target, css) {
|
|
9538
|
+
if (!css.includes("--")) return;
|
|
9539
|
+
try {
|
|
9540
|
+
postcss.default.parse(css).walkDecls((decl) => {
|
|
9541
|
+
if (decl.prop.startsWith("--")) target.set(decl.prop, decl.value.trim());
|
|
9542
|
+
});
|
|
9543
|
+
} catch {}
|
|
9544
|
+
}
|
|
9545
|
+
//#endregion
|
|
9392
9546
|
Object.defineProperty(exports, "CSS_MACRO_STYLE_OPTIONS_MARKER", {
|
|
9393
9547
|
enumerable: true,
|
|
9394
9548
|
get: function() {
|
|
@@ -9461,6 +9615,12 @@ Object.defineProperty(exports, "VITE_MARKER_RE", {
|
|
|
9461
9615
|
return VITE_MARKER_RE;
|
|
9462
9616
|
}
|
|
9463
9617
|
});
|
|
9618
|
+
Object.defineProperty(exports, "analyzeCssCalcContext", {
|
|
9619
|
+
enumerable: true,
|
|
9620
|
+
get: function() {
|
|
9621
|
+
return analyzeCssCalcContext;
|
|
9622
|
+
}
|
|
9623
|
+
});
|
|
9464
9624
|
Object.defineProperty(exports, "analyzeTailwindV4EntrySource", {
|
|
9465
9625
|
enumerable: true,
|
|
9466
9626
|
get: function() {
|
|
@@ -9485,6 +9645,12 @@ Object.defineProperty(exports, "applyConfiguredCssCalc", {
|
|
|
9485
9645
|
return applyConfiguredCssCalc;
|
|
9486
9646
|
}
|
|
9487
9647
|
});
|
|
9648
|
+
Object.defineProperty(exports, "applyConfiguredCssUnits", {
|
|
9649
|
+
enumerable: true,
|
|
9650
|
+
get: function() {
|
|
9651
|
+
return applyConfiguredCssUnits;
|
|
9652
|
+
}
|
|
9653
|
+
});
|
|
9488
9654
|
Object.defineProperty(exports, "canProcessSourceStyleAsCss", {
|
|
9489
9655
|
enumerable: true,
|
|
9490
9656
|
get: function() {
|
|
@@ -10067,6 +10233,12 @@ Object.defineProperty(exports, "isCssAlreadyRepresentedByMarkers", {
|
|
|
10067
10233
|
return isCssAlreadyRepresentedByMarkers;
|
|
10068
10234
|
}
|
|
10069
10235
|
});
|
|
10236
|
+
Object.defineProperty(exports, "isCssCalcCustomPropertySelected", {
|
|
10237
|
+
enumerable: true,
|
|
10238
|
+
get: function() {
|
|
10239
|
+
return isCssCalcCustomPropertySelected;
|
|
10240
|
+
}
|
|
10241
|
+
});
|
|
10070
10242
|
Object.defineProperty(exports, "isCssImportOnly", {
|
|
10071
10243
|
enumerable: true,
|
|
10072
10244
|
get: function() {
|
|
@@ -10208,7 +10380,7 @@ Object.defineProperty(exports, "mergeCoveredCssRuleDeclarations", {
|
|
|
10208
10380
|
Object.defineProperty(exports, "mergeCustomPropertyValues", {
|
|
10209
10381
|
enumerable: true,
|
|
10210
10382
|
get: function() {
|
|
10211
|
-
return mergeCustomPropertyValues
|
|
10383
|
+
return mergeCustomPropertyValues;
|
|
10212
10384
|
}
|
|
10213
10385
|
});
|
|
10214
10386
|
Object.defineProperty(exports, "mergeMarkedUserLayerComponentsCss", {
|