@weapp-tailwindcss/postcss 3.3.4 → 3.3.6
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/README.md +10 -0
- package/README.zh-CN.md +6 -0
- package/dist/compat/author-selector.d.ts +2 -0
- package/dist/compat/index.d.ts +57 -0
- package/dist/compat/legacy-css/apply.d.ts +2 -0
- package/dist/compat/legacy-css/dedupe.d.ts +2 -0
- package/dist/compat/legacy-css/index.d.ts +4 -0
- package/dist/compat/legacy-css/selectors.d.ts +7 -0
- package/dist/compat/legacy-css/source-cleanup.d.ts +2 -0
- package/dist/compat/legacy-css/units.d.ts +1 -0
- package/dist/compat/mini-program-css/class-presence.d.ts +3 -0
- package/dist/compat/mini-program-css/content-init.d.ts +3 -0
- package/dist/compat/mini-program-css/empty-blocks.d.ts +3 -0
- package/dist/compat/mini-program-css/index.d.ts +2 -0
- package/dist/compat/mini-program-css/output-import-shell.d.ts +8 -0
- package/dist/compat/native/compile.d.ts +2 -0
- package/dist/compat/native/properties.d.ts +15 -0
- package/dist/compat/native/selectors.d.ts +8 -0
- package/dist/compat/native/types.d.ts +23 -0
- package/dist/compat/processed-css/cleanup.d.ts +4 -0
- package/dist/compat/processed-css/composition.d.ts +6 -0
- package/dist/compat/processed-css/entry-directives.d.ts +1 -0
- package/dist/compat/processed-css/imports.d.ts +8 -0
- package/dist/compat/scoped-css/cleanup.d.ts +4 -0
- package/dist/compat/scoped-css/coverage.d.ts +10 -0
- package/dist/compat/scoped-css/covered-rules.d.ts +4 -0
- package/dist/compat/scoped-css/predicates.d.ts +13 -0
- package/dist/compat/tailwind-directive-injection.d.ts +8 -0
- package/dist/compat/tailwindcss-v4/author-functions.d.ts +7 -0
- package/dist/compat/tailwindcss-v4/generated-output.d.ts +5 -0
- package/dist/compat/tailwindcss-v4/package-import-statements.d.ts +1 -0
- package/dist/compat/tailwindcss-v4/preflight-imports.d.ts +3 -0
- package/dist/compat/tailwindcss-v4/rpx-candidates.d.ts +6 -0
- package/dist/compat/tailwindcss-v4/theme-injection.d.ts +1 -0
- package/dist/compat/tailwindcss-v4/theme-source.d.ts +9 -0
- package/dist/compat/tailwindcss-v4/user-css/apply-only.d.ts +6 -0
- package/dist/compat/tailwindcss-v4/user-css/apply-reference.d.ts +4 -0
- package/dist/compat/tailwindcss-v4/user-css/at-rules.d.ts +3 -0
- package/dist/compat/tailwindcss-v4/user-css/class-selectors.d.ts +2 -0
- package/dist/compat/tailwindcss-v4/user-css/directives/entry-source.d.ts +9 -0
- package/dist/compat/tailwindcss-v4/user-css/directives/fallback.d.ts +11 -0
- package/dist/compat/tailwindcss-v4/user-css/directives/index.d.ts +2 -0
- package/dist/compat/tailwindcss-v4/user-css/directives/shared.d.ts +26 -0
- package/dist/compat/tailwindcss-v4/user-css/framework-composition.d.ts +2 -0
- package/dist/compat/tailwindcss-v4/user-css/framework-source.d.ts +1 -0
- package/dist/compat/tailwindcss-v4/user-css/generated-cleanup.d.ts +7 -0
- package/dist/compat/tailwindcss-v4/user-css/identity.d.ts +1 -0
- package/dist/compat/tailwindcss-v4/user-css/markers.d.ts +32 -0
- package/dist/compat/tailwindcss-v4/user-css/rule-deduplication.d.ts +1 -0
- package/dist/compat/tailwindcss-v4/user-css/scoped-rules.d.ts +4 -0
- package/dist/compat/tailwindcss-v4/user-css/source-fragments.d.ts +15 -0
- package/dist/compat/tailwindcss-v4/user-css/transform.d.ts +14 -0
- package/dist/compat/tailwindcss-v4/user-css/user-layer-order.d.ts +10 -0
- package/dist/compat/tailwindcss-v4/user-css/user-layers.d.ts +15 -0
- package/dist/compat/tailwindcss-v4.d.ts +1 -0
- package/dist/compat/uni-app-x/apply-source.d.ts +2 -0
- package/dist/compat/uni-app-x/harmony-apply.d.ts +2 -0
- package/dist/compat/uni-app-x/reference-paths.d.ts +2 -0
- package/dist/compat/uni-app-x-author-apply.d.ts +10 -0
- package/dist/compat/uni-app-x-border.d.ts +6 -0
- package/dist/compat/uni-app-x-style-value.d.ts +11 -0
- package/dist/compat/webpack-css/bare-selectors.d.ts +1 -0
- package/dist/compat/webpack-css/generated-cleanup.d.ts +4 -0
- package/dist/compat/webpack-css/identity.d.ts +5 -0
- package/dist/compat/webpack-css/preflight.d.ts +5 -0
- package/dist/compat/webpack-css/user-source.d.ts +6 -0
- package/dist/diagnostics/rpx-theme.d.ts +9 -0
- package/dist/directives-DTKFO5Hv.js +2630 -0
- package/dist/experimental/lightningcss/index.cjs +256 -0
- package/dist/experimental/lightningcss/index.d.ts +3 -0
- package/dist/experimental/lightningcss/index.js +245 -0
- package/dist/experimental/lightningcss/options.d.ts +3 -0
- package/dist/experimental/lightningcss/selector-transform.d.ts +10 -0
- package/dist/experimental/lightningcss/selector-utils.d.ts +10 -0
- package/dist/framework-pipeline.d.ts +4 -0
- package/dist/generator-plugin/config-directive.d.ts +5 -0
- package/dist/generator-plugin/local-imports.d.ts +6 -1
- package/dist/generator-plugin/source-files.d.ts +5 -5
- package/dist/generator-plugin/types.d.ts +5 -0
- package/dist/index.cjs +388 -7960
- package/dist/index.d.ts +2 -33
- package/dist/index.js +10 -7840
- package/dist/native.cjs +425 -0
- package/dist/native.d.ts +3 -0
- package/dist/native.js +419 -0
- package/dist/plugin-BWDgxMn5.cjs +194 -0
- package/dist/plugin-CpkRzMhp.js +185 -0
- package/dist/plugin.cjs +3 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +2 -0
- package/dist/plugins/applyConfiguredCssCalc.d.ts +9 -0
- package/dist/postcss-runtime-i5rHe_mj.js +2 -0
- package/dist/postcss-runtime.d.ts +1 -1
- package/dist/preflight-BTZL2nvC.cjs +21 -0
- package/dist/preflight-DVg4eehD.js +16 -0
- package/dist/resolve-DQiOQfoY.js +354 -0
- package/dist/resolve-EBh65bS8.cjs +3556 -0
- package/dist/rewrite-imports-CdZQE6CI.js +146 -0
- package/dist/selectorParser/utils.d.ts +1 -1
- package/dist/shared-CELzerNo.cjs +34 -0
- package/dist/shared-CfQUwapA.js +23 -0
- package/dist/source-scan/candidates.d.ts +4 -0
- package/dist/source-scan/description.d.ts +15 -0
- package/dist/source-scan/params.d.ts +5 -0
- package/dist/source-scan/resolve.d.ts +30 -0
- package/dist/source-scan/tailwind-v4/entry-source.d.ts +16 -0
- package/dist/source-scan/tailwind-v4/fingerprint.d.ts +5 -0
- package/dist/source-scan.d.ts +3 -24
- package/dist/syntax/css-import.d.ts +20 -0
- package/dist/syntax/index.d.ts +3 -0
- package/dist/syntax/location-dependencies.d.ts +2 -0
- package/dist/syntax/parse.d.ts +13 -0
- package/dist/syntax/rewrite-imports.d.ts +5 -0
- package/dist/syntax/runtime-signature.d.ts +2 -0
- package/dist/syntax/source-style.d.ts +1 -0
- package/dist/syntax.cjs +547 -0
- package/dist/syntax.d.ts +6 -0
- package/dist/syntax.js +3 -0
- package/dist/transform-Djx5HILQ.js +9239 -0
- package/dist/transform-Xb48e-Wk.cjs +10957 -0
- package/dist/transform.cjs +421 -0
- package/dist/transform.d.ts +40 -0
- package/dist/transform.js +10 -0
- package/dist/types.d.ts +1 -1
- package/dist/utils/apply-source.d.ts +11 -0
- package/dist/utils/css-source-trace.d.ts +6 -0
- package/dist/utils/custom-property-values.d.ts +4 -0
- package/dist/utils/generated-css-marker.d.ts +12 -0
- package/package.json +48 -8
package/dist/native.cjs
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.cjs");
|
|
3
|
+
let postcss = require("postcss");
|
|
4
|
+
postcss = require_rolldown_runtime.__toESM(postcss, 1);
|
|
5
|
+
//#region src/compat/native/properties.ts
|
|
6
|
+
const COLOR_PROPERTIES = /* @__PURE__ */ new Set([
|
|
7
|
+
"color",
|
|
8
|
+
"backgroundColor",
|
|
9
|
+
"borderColor",
|
|
10
|
+
"borderTopColor",
|
|
11
|
+
"borderRightColor",
|
|
12
|
+
"borderBottomColor",
|
|
13
|
+
"borderLeftColor",
|
|
14
|
+
"shadowColor",
|
|
15
|
+
"textDecorationColor"
|
|
16
|
+
]);
|
|
17
|
+
const NUMERIC_PROPERTIES = /* @__PURE__ */ new Set([
|
|
18
|
+
"aspectRatio",
|
|
19
|
+
"borderBottomWidth",
|
|
20
|
+
"borderLeftWidth",
|
|
21
|
+
"borderRadius",
|
|
22
|
+
"borderRightWidth",
|
|
23
|
+
"borderTopLeftRadius",
|
|
24
|
+
"borderTopRightRadius",
|
|
25
|
+
"borderTopWidth",
|
|
26
|
+
"borderWidth",
|
|
27
|
+
"bottom",
|
|
28
|
+
"elevation",
|
|
29
|
+
"flex",
|
|
30
|
+
"flexBasis",
|
|
31
|
+
"flexGrow",
|
|
32
|
+
"flexShrink",
|
|
33
|
+
"fontSize",
|
|
34
|
+
"gap",
|
|
35
|
+
"height",
|
|
36
|
+
"left",
|
|
37
|
+
"letterSpacing",
|
|
38
|
+
"lineHeight",
|
|
39
|
+
"margin",
|
|
40
|
+
"marginBottom",
|
|
41
|
+
"marginHorizontal",
|
|
42
|
+
"marginLeft",
|
|
43
|
+
"marginRight",
|
|
44
|
+
"marginTop",
|
|
45
|
+
"marginVertical",
|
|
46
|
+
"maxHeight",
|
|
47
|
+
"maxWidth",
|
|
48
|
+
"minHeight",
|
|
49
|
+
"minWidth",
|
|
50
|
+
"opacity",
|
|
51
|
+
"padding",
|
|
52
|
+
"paddingBottom",
|
|
53
|
+
"paddingHorizontal",
|
|
54
|
+
"paddingLeft",
|
|
55
|
+
"paddingRight",
|
|
56
|
+
"paddingTop",
|
|
57
|
+
"paddingVertical",
|
|
58
|
+
"right",
|
|
59
|
+
"top",
|
|
60
|
+
"width",
|
|
61
|
+
"zIndex"
|
|
62
|
+
]);
|
|
63
|
+
const STRING_PROPERTIES = /* @__PURE__ */ new Set([
|
|
64
|
+
"alignContent",
|
|
65
|
+
"alignItems",
|
|
66
|
+
"alignSelf",
|
|
67
|
+
"borderStyle",
|
|
68
|
+
"direction",
|
|
69
|
+
"display",
|
|
70
|
+
"flexDirection",
|
|
71
|
+
"flexWrap",
|
|
72
|
+
"fontFamily",
|
|
73
|
+
"fontStyle",
|
|
74
|
+
"fontWeight",
|
|
75
|
+
"justifyContent",
|
|
76
|
+
"overflow",
|
|
77
|
+
"position",
|
|
78
|
+
"textAlign",
|
|
79
|
+
"textDecorationLine",
|
|
80
|
+
"textDecorationStyle",
|
|
81
|
+
"textTransform",
|
|
82
|
+
"writingDirection"
|
|
83
|
+
]);
|
|
84
|
+
const SHORTHANDS = {
|
|
85
|
+
margin: [
|
|
86
|
+
"marginTop",
|
|
87
|
+
"marginRight",
|
|
88
|
+
"marginBottom",
|
|
89
|
+
"marginLeft"
|
|
90
|
+
],
|
|
91
|
+
padding: [
|
|
92
|
+
"paddingTop",
|
|
93
|
+
"paddingRight",
|
|
94
|
+
"paddingBottom",
|
|
95
|
+
"paddingLeft"
|
|
96
|
+
]
|
|
97
|
+
};
|
|
98
|
+
const UNSUPPORTED_PROPERTIES = /* @__PURE__ */ new Set([
|
|
99
|
+
"filter",
|
|
100
|
+
"backdropFilter",
|
|
101
|
+
"animation",
|
|
102
|
+
"transition",
|
|
103
|
+
"textShadow",
|
|
104
|
+
"backgroundImage",
|
|
105
|
+
"appearance",
|
|
106
|
+
"content",
|
|
107
|
+
"cursor",
|
|
108
|
+
"userSelect",
|
|
109
|
+
"whiteSpace",
|
|
110
|
+
"objectFit",
|
|
111
|
+
"listStyleType",
|
|
112
|
+
"outline"
|
|
113
|
+
]);
|
|
114
|
+
function propertyName(property) {
|
|
115
|
+
return {
|
|
116
|
+
"padding-inline": "paddingHorizontal",
|
|
117
|
+
"padding-inline-start": "paddingLeft",
|
|
118
|
+
"padding-inline-end": "paddingRight",
|
|
119
|
+
"padding-block": "paddingVertical",
|
|
120
|
+
"padding-block-start": "paddingTop",
|
|
121
|
+
"padding-block-end": "paddingBottom",
|
|
122
|
+
"margin-inline": "marginHorizontal",
|
|
123
|
+
"margin-inline-start": "marginLeft",
|
|
124
|
+
"margin-inline-end": "marginRight",
|
|
125
|
+
"margin-block": "marginVertical",
|
|
126
|
+
"margin-block-start": "marginTop",
|
|
127
|
+
"margin-block-end": "marginBottom"
|
|
128
|
+
}[property] ?? property.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
129
|
+
}
|
|
130
|
+
function splitValue(value) {
|
|
131
|
+
return value.trim().split(/\s+/).filter(Boolean);
|
|
132
|
+
}
|
|
133
|
+
function parseNumber(value, variables) {
|
|
134
|
+
const resolved = resolveVariables(value, variables);
|
|
135
|
+
const fraction = resolved.match(/^(-?(?:\d+\.\d+|\d+|\.\d+))\s*\/\s*(-?(?:\d+\.\d+|\d+|\.\d+))$/);
|
|
136
|
+
if (fraction && Number(fraction[2]) !== 0) return Number(fraction[1]) / Number(fraction[2]);
|
|
137
|
+
const calculated = resolved.match(/^calc\(\s*(-?(?:\d+\.\d+|\d+|\.\d+))(px|rem|em|%)?\s*\*\s*(-?(?:\d+\.\d+|\d+|\.\d+))\s*\)$/);
|
|
138
|
+
if (calculated) {
|
|
139
|
+
const base = parseNumber(`${calculated[1]}${calculated[2] ?? ""}`, variables);
|
|
140
|
+
return typeof base === "number" ? base * Number(calculated[3]) : void 0;
|
|
141
|
+
}
|
|
142
|
+
const match = resolved.match(/^(-?(?:\d+\.\d+|\d+|\.\d+))(px|rem|em|%)?$/);
|
|
143
|
+
if (!match) return;
|
|
144
|
+
const number = Number(match[1]);
|
|
145
|
+
if (match[2] === "%") return `${number}%`;
|
|
146
|
+
if (match[2] === "rem" || match[2] === "em") return number * 16;
|
|
147
|
+
return number;
|
|
148
|
+
}
|
|
149
|
+
function resolveVariables(value, variables) {
|
|
150
|
+
return value.replace(/var\((--[\w-]+)(?:,\s*([^)]*))?\)/g, (_, key, fallback) => variables[key] ?? fallback ?? `var(${key})`);
|
|
151
|
+
}
|
|
152
|
+
function isColor(value) {
|
|
153
|
+
return /^(?:#[\da-f]{3,8}|(?:rgb|rgba|hsl|hsla|oklch|oklab)\([^)]*\)|[a-z]+)$/i.test(value);
|
|
154
|
+
}
|
|
155
|
+
function oklchToHex(value) {
|
|
156
|
+
const match = value.match(/^oklch\(\s*([\d.]+)%?\s+([\d.]+)\s+([\d.]+)(?:\s+\/\s*([\d.]+))?\s*\)$/i);
|
|
157
|
+
if (!match) return;
|
|
158
|
+
const lightness = Number(match[1]) > 1 ? Number(match[1]) / 100 : Number(match[1]);
|
|
159
|
+
const chroma = Number(match[2]);
|
|
160
|
+
const hue = Number(match[3]) * Math.PI / 180;
|
|
161
|
+
const alpha = match[4] === void 0 ? 1 : Number(match[4]);
|
|
162
|
+
const a = chroma * Math.cos(hue);
|
|
163
|
+
const b = chroma * Math.sin(hue);
|
|
164
|
+
const l = lightness + .3963377774 * a + .2158037573 * b;
|
|
165
|
+
const m = lightness - .1055613458 * a - .0638541728 * b;
|
|
166
|
+
const s = lightness - .0894841775 * a - 1.291485548 * b;
|
|
167
|
+
const linear = (channel) => channel ** 3;
|
|
168
|
+
const red = 4.0767416621 * linear(l) - 3.3077115913 * linear(m) + .2309699292 * linear(s);
|
|
169
|
+
const green = -1.2684380046 * linear(l) + 2.6097574011 * linear(m) - .3413193965 * linear(s);
|
|
170
|
+
const blue = -.0041960863 * linear(l) - .7034186147 * linear(m) + 1.707614701 * linear(s);
|
|
171
|
+
const toByte = (channel) => Math.round(Math.max(0, Math.min(1, channel <= .0031308 ? 12.92 * channel : 1.055 * channel ** (1 / 2.4) - .055)) * 255);
|
|
172
|
+
const hex = [
|
|
173
|
+
red,
|
|
174
|
+
green,
|
|
175
|
+
blue
|
|
176
|
+
].map((channel) => toByte(channel).toString(16).padStart(2, "0")).join("");
|
|
177
|
+
return alpha < 1 ? `#${hex}${Math.round(alpha * 255).toString(16).padStart(2, "0")}` : `#${hex}`;
|
|
178
|
+
}
|
|
179
|
+
function normalizeColor(value) {
|
|
180
|
+
return /^oklch\(/i.test(value) ? oklchToHex(value) : value;
|
|
181
|
+
}
|
|
182
|
+
function parseTransform(value, variables) {
|
|
183
|
+
const transform = [];
|
|
184
|
+
for (const match of value.matchAll(/(translateX|translateY|translate|scaleX|scaleY|scale|rotate|skewX|skewY)\(([^)]*)\)/g)) {
|
|
185
|
+
const name = match[1];
|
|
186
|
+
const values = splitValue(resolveVariables(match[2] ?? "", variables).replace(",", " "));
|
|
187
|
+
if (!name || !values.length) continue;
|
|
188
|
+
if (name.startsWith("scale")) {
|
|
189
|
+
const number = Number(values[0] ?? "");
|
|
190
|
+
if (Number.isFinite(number)) transform.push({ [name]: number });
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (name === "translate") {
|
|
194
|
+
const x = parseNumber(values[0] ?? "", variables);
|
|
195
|
+
const y = parseNumber(values[1] ?? "0", variables);
|
|
196
|
+
if (x !== void 0 && y !== void 0) transform.push({ translateX: x }, { translateY: y });
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
const property = name.replace(/^translate$/, "translateX");
|
|
200
|
+
const parsed = name.startsWith("rotate") || name.startsWith("skew") ? values[0] : parseNumber(values[0] ?? "", variables);
|
|
201
|
+
if (parsed !== void 0) transform.push({ [property]: parsed });
|
|
202
|
+
}
|
|
203
|
+
return transform.length ? transform : void 0;
|
|
204
|
+
}
|
|
205
|
+
function parseShadow(value, variables) {
|
|
206
|
+
const resolved = resolveVariables(value, variables);
|
|
207
|
+
const color = resolved.match(/(?:rgba?|hsla?)\([^)]*\)|#[\da-f]{3,8}/i)?.[0];
|
|
208
|
+
const parts = splitValue(color ? resolved.replace(color, "") : resolved);
|
|
209
|
+
const lengths = parts.filter((part) => parseNumber(part, variables) !== void 0).slice(0, 3);
|
|
210
|
+
if (lengths.length < 2) return;
|
|
211
|
+
const [x = "0", y = "0", blur = "0"] = lengths;
|
|
212
|
+
const shadowColor = normalizeColor(color ?? parts.find((part) => isColor(part)) ?? "#000000") ?? "#000000";
|
|
213
|
+
const opacity = /rgba\([^,]+,[^,]+,[^,]+,\s*([\d.]+)\)/i.exec(shadowColor)?.[1];
|
|
214
|
+
return {
|
|
215
|
+
shadowOffset: {
|
|
216
|
+
width: parseNumber(x, variables),
|
|
217
|
+
height: parseNumber(y, variables)
|
|
218
|
+
},
|
|
219
|
+
shadowRadius: parseNumber(blur, variables),
|
|
220
|
+
shadowColor,
|
|
221
|
+
...opacity ? { shadowOpacity: Number(opacity) } : {}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function parseValue(property, value, variables) {
|
|
225
|
+
const trimmed = value.trim();
|
|
226
|
+
if (UNSUPPORTED_PROPERTIES.has(property)) return;
|
|
227
|
+
if (trimmed.includes("linear-gradient(") || trimmed.includes("url(")) return;
|
|
228
|
+
if (COLOR_PROPERTIES.has(property)) {
|
|
229
|
+
const color = resolveVariables(trimmed, variables);
|
|
230
|
+
return isColor(color) ? normalizeColor(color) : void 0;
|
|
231
|
+
}
|
|
232
|
+
if (NUMERIC_PROPERTIES.has(property)) {
|
|
233
|
+
const number = parseNumber(trimmed, variables);
|
|
234
|
+
if (property === "opacity" && typeof number === "string" && number.endsWith("%")) return Number.parseFloat(number) / 100;
|
|
235
|
+
return number;
|
|
236
|
+
}
|
|
237
|
+
if (property === "transform") return parseTransform(trimmed, variables);
|
|
238
|
+
if (property === "boxShadow") return parseShadow(trimmed, variables);
|
|
239
|
+
if (property === "display" && !["flex", "none"].includes(trimmed)) return;
|
|
240
|
+
return STRING_PROPERTIES.has(property) ? trimmed : void 0;
|
|
241
|
+
}
|
|
242
|
+
function expandDeclaration(property, value, variables) {
|
|
243
|
+
if (property === "margin" || property === "padding") {
|
|
244
|
+
const parts = splitValue(value).map((item) => parseNumber(item, variables));
|
|
245
|
+
if (parts.includes(void 0)) return;
|
|
246
|
+
const [top, right = top, bottom = top, left = right] = parts;
|
|
247
|
+
return Object.fromEntries(SHORTHANDS[property].map((key, index) => [key, [
|
|
248
|
+
top,
|
|
249
|
+
right,
|
|
250
|
+
bottom,
|
|
251
|
+
left
|
|
252
|
+
][index]]));
|
|
253
|
+
}
|
|
254
|
+
if (property === "border") {
|
|
255
|
+
const width = splitValue(value).find((item) => /^\d/.test(item));
|
|
256
|
+
const color = splitValue(value).find((item) => isColor(item));
|
|
257
|
+
return {
|
|
258
|
+
...width ? { borderWidth: parseNumber(width, variables) } : {},
|
|
259
|
+
...color ? { borderColor: color } : {}
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
if (property === "boxShadow") return parseShadow(value, variables);
|
|
263
|
+
const parsed = parseValue(property, value, variables);
|
|
264
|
+
return parsed === void 0 ? void 0 : { [property]: parsed };
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/compat/native/selectors.ts
|
|
268
|
+
const CLASS_SELECTOR_RE = /\.((?:\\.|[^\s.#:[>+~])+)/g;
|
|
269
|
+
function decodeCssIdentifier(value) {
|
|
270
|
+
return value.replace(/\\([0-9a-f]{1,6})\s?/gi, (_, code) => String.fromCodePoint(Number.parseInt(code, 16))).replace(/\\(.)/g, "$1");
|
|
271
|
+
}
|
|
272
|
+
function splitClassName(className) {
|
|
273
|
+
const parts = [];
|
|
274
|
+
let current = "";
|
|
275
|
+
let bracketDepth = 0;
|
|
276
|
+
let escaped = false;
|
|
277
|
+
for (const character of className) {
|
|
278
|
+
if (escaped) {
|
|
279
|
+
current += character;
|
|
280
|
+
escaped = false;
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
if (character === "\\") {
|
|
284
|
+
current += character;
|
|
285
|
+
escaped = true;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (character === "[") bracketDepth += 1;
|
|
289
|
+
if (character === "]") bracketDepth = Math.max(0, bracketDepth - 1);
|
|
290
|
+
if (character === ":" && bracketDepth === 0) {
|
|
291
|
+
parts.push(current);
|
|
292
|
+
current = "";
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
current += character;
|
|
296
|
+
}
|
|
297
|
+
parts.push(current);
|
|
298
|
+
return parts;
|
|
299
|
+
}
|
|
300
|
+
function baseClassName(className) {
|
|
301
|
+
return splitClassName(className).at(-1);
|
|
302
|
+
}
|
|
303
|
+
function unsupportedVariant(className) {
|
|
304
|
+
return splitClassName(className).slice(0, -1).find((variant) => ![
|
|
305
|
+
"dark",
|
|
306
|
+
"ios",
|
|
307
|
+
"android",
|
|
308
|
+
"native"
|
|
309
|
+
].includes(variant));
|
|
310
|
+
}
|
|
311
|
+
function walkClasses(selector) {
|
|
312
|
+
const classes = [];
|
|
313
|
+
for (const match of selector.matchAll(CLASS_SELECTOR_RE)) {
|
|
314
|
+
const token = decodeCssIdentifier(match[1]);
|
|
315
|
+
if (token && !classes.includes(token)) classes.push(token);
|
|
316
|
+
}
|
|
317
|
+
return classes;
|
|
318
|
+
}
|
|
319
|
+
function variantForClass(className) {
|
|
320
|
+
const result = {};
|
|
321
|
+
for (const variant of splitClassName(className).slice(0, -1)) {
|
|
322
|
+
if (variant === "dark") result.colorScheme = "dark";
|
|
323
|
+
if (variant === "ios" || variant === "android" || variant === "native") result.platform = variant;
|
|
324
|
+
}
|
|
325
|
+
return result;
|
|
326
|
+
}
|
|
327
|
+
function atRuleVariant(node) {
|
|
328
|
+
if (!node) return {};
|
|
329
|
+
const params = node.params.toLowerCase();
|
|
330
|
+
if (params.includes("prefers-color-scheme") && params.includes("dark")) return { colorScheme: "dark" };
|
|
331
|
+
if (params.includes("platform") && params.includes("ios")) return { platform: "ios" };
|
|
332
|
+
if (params.includes("platform") && params.includes("android")) return { platform: "android" };
|
|
333
|
+
return {};
|
|
334
|
+
}
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region src/compat/native/compile.ts
|
|
337
|
+
function ancestors(node) {
|
|
338
|
+
const result = [];
|
|
339
|
+
let current = node.parent;
|
|
340
|
+
while (current && current.type !== "root") {
|
|
341
|
+
if (current.type === "atrule") result.unshift(current);
|
|
342
|
+
current = current.parent;
|
|
343
|
+
}
|
|
344
|
+
return result;
|
|
345
|
+
}
|
|
346
|
+
function collectVariables(root) {
|
|
347
|
+
const variables = {};
|
|
348
|
+
root.walkDecls((decl) => {
|
|
349
|
+
if (decl.prop.startsWith("--")) variables[decl.prop] = decl.value.trim();
|
|
350
|
+
});
|
|
351
|
+
return variables;
|
|
352
|
+
}
|
|
353
|
+
function addWarning(warnings, warning) {
|
|
354
|
+
if (!warnings.some((item) => item.message === warning.message && item.property === warning.property && item.className === warning.className)) warnings.push(warning);
|
|
355
|
+
}
|
|
356
|
+
function compileRule(rule, className, variables, warnings, order) {
|
|
357
|
+
const unsupported = unsupportedVariant(className);
|
|
358
|
+
if (unsupported) {
|
|
359
|
+
addWarning(warnings, {
|
|
360
|
+
className,
|
|
361
|
+
property: "variant",
|
|
362
|
+
message: `不支持将 ${unsupported}: 变体编译为 React Native 条件样式`
|
|
363
|
+
});
|
|
364
|
+
return [];
|
|
365
|
+
}
|
|
366
|
+
const styles = {
|
|
367
|
+
normal: {},
|
|
368
|
+
important: {}
|
|
369
|
+
};
|
|
370
|
+
rule.walkDecls((decl) => {
|
|
371
|
+
if (decl.prop.startsWith("--")) return;
|
|
372
|
+
const property = propertyName(decl.prop);
|
|
373
|
+
const important = decl.important || /!important\s*$/i.test(decl.value);
|
|
374
|
+
const value = decl.value.replace(/\s*!important\s*$/i, "");
|
|
375
|
+
const expanded = expandDeclaration(property, value, variables);
|
|
376
|
+
if (!expanded || Object.values(expanded).includes(void 0)) {
|
|
377
|
+
addWarning(warnings, {
|
|
378
|
+
className,
|
|
379
|
+
property,
|
|
380
|
+
message: `不支持将 ${decl.prop}: ${value} 编译为 React Native style`
|
|
381
|
+
});
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
Object.assign(styles[important ? "important" : "normal"], expanded);
|
|
385
|
+
});
|
|
386
|
+
const variant = {
|
|
387
|
+
...variantForClass(className),
|
|
388
|
+
...ancestors(rule).reduce((result, node) => ({
|
|
389
|
+
...result,
|
|
390
|
+
...atRuleVariant(node)
|
|
391
|
+
}), {})
|
|
392
|
+
};
|
|
393
|
+
return ["normal", "important"].filter((kind) => Object.keys(styles[kind]).length > 0).map((kind) => ({
|
|
394
|
+
style: styles[kind],
|
|
395
|
+
...variant,
|
|
396
|
+
important: kind === "important" || void 0,
|
|
397
|
+
order
|
|
398
|
+
}));
|
|
399
|
+
}
|
|
400
|
+
function compileNativeCss(css, options = {}) {
|
|
401
|
+
const root = postcss.default.parse(css);
|
|
402
|
+
const variables = collectVariables(root);
|
|
403
|
+
const allowed = options.classSet ? new Set(options.classSet) : void 0;
|
|
404
|
+
const rules = {};
|
|
405
|
+
const warnings = [];
|
|
406
|
+
let order = 0;
|
|
407
|
+
root.walkRules((rule) => {
|
|
408
|
+
if (options.ignorePreflight !== false && (rule.selector.includes(":root") || rule.selector.includes("*") || rule.selector.includes("::"))) return;
|
|
409
|
+
for (const selector of rule.selectors) for (const className of walkClasses(selector)) {
|
|
410
|
+
if (allowed && !allowed.has(className)) continue;
|
|
411
|
+
const compiled = compileRule(rule, className, variables, warnings, order++);
|
|
412
|
+
if (compiled.length) (rules[className] ??= []).push(...compiled);
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
return {
|
|
416
|
+
rules,
|
|
417
|
+
variables,
|
|
418
|
+
warnings
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
//#endregion
|
|
422
|
+
exports.baseClassName = baseClassName;
|
|
423
|
+
exports.compileNativeCss = compileNativeCss;
|
|
424
|
+
exports.splitClassName = splitClassName;
|
|
425
|
+
exports.variantForClass = variantForClass;
|
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { compileNativeCss } from './compat/native/compile.js';
|
|
2
|
+
export { baseClassName, splitClassName, variantForClass } from './compat/native/selectors.js';
|
|
3
|
+
export type { CompileNativeStylesheetOptions, NativeCompilerWarning, NativeCssStylesheet, NativePlatform, NativeStyleRule } from './compat/native/types.js';
|