@weapp-tailwindcss/experimental 0.0.42 → 0.0.44
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/index-DRm95hGG.d.ts +26 -0
- package/dist/index-DgmspOJt.d.ts +26 -0
- package/dist/index.cjs +70 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/lightningcss/index.cjs +123 -14
- package/dist/lightningcss/index.d.ts +1 -1
- package/dist/lightningcss/index.mjs +1 -1
- package/dist/lightningcss-Dt-baC0L.mjs +56 -0
- package/package.json +2 -2
- package/dist/index-BXAviB07.d.ts +0 -49
- package/dist/index-DyBd14D_.d.ts +0 -49
- package/dist/lightningcss-B7w6ItZb.cjs +0 -374
- package/dist/lightningcss-BXrk4rpg.mjs +0 -297
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { TransformOptions, Warning } from "lightningcss";
|
|
3
|
+
import { SelectorTransformContext, assignNestedSelectors, buildChildCombinatorReplacement, cloneComponent, cloneComponents, createRootSpecificityReplacer, createTypeSelector, createVisitor, matchesHiddenNot, normalizeNestedSelectors, prepareStyleOptions, trimCombinators } from "@weapp-tailwindcss/postcss/experimental/lightningcss";
|
|
4
|
+
import { IStyleHandlerOptions } from "@weapp-tailwindcss/postcss";
|
|
5
|
+
//#region src/lightningcss/index.d.ts
|
|
6
|
+
type CustomAtRules = Record<string, never>;
|
|
7
|
+
interface LightningcssStyleHandlerResult {
|
|
8
|
+
code: string;
|
|
9
|
+
map?: string | undefined;
|
|
10
|
+
warnings: Warning[];
|
|
11
|
+
}
|
|
12
|
+
interface LightningcssTransformConfig {
|
|
13
|
+
filename?: string | undefined;
|
|
14
|
+
transformOptions?: Omit<TransformOptions<CustomAtRules>, 'filename' | 'code' | 'visitor'> | undefined;
|
|
15
|
+
}
|
|
16
|
+
interface LightningcssStyleHandler {
|
|
17
|
+
(rawSource: string, overrideOptions?: Partial<IStyleHandlerOptions>): Promise<LightningcssStyleHandlerResult>;
|
|
18
|
+
}
|
|
19
|
+
declare function createLightningcssStyleHandler(options?: Partial<IStyleHandlerOptions>, config?: LightningcssTransformConfig): LightningcssStyleHandler;
|
|
20
|
+
declare function transformCss(css?: string | Buffer): Promise<{
|
|
21
|
+
code: Buffer<ArrayBuffer>;
|
|
22
|
+
map: Buffer<ArrayBuffer> | undefined;
|
|
23
|
+
warnings: Warning[];
|
|
24
|
+
}>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { assignNestedSelectors as a, createTypeSelector as c, trimCombinators as d, SelectorTransformContext as f, prepareStyleOptions as g, createRootSpecificityReplacer as h, transformCss as i, matchesHiddenNot as l, createVisitor as m, LightningcssTransformConfig as n, cloneComponent as o, buildChildCombinatorReplacement as p, createLightningcssStyleHandler as r, cloneComponents as s, LightningcssStyleHandlerResult as t, normalizeNestedSelectors as u };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IStyleHandlerOptions } from "@weapp-tailwindcss/postcss";
|
|
2
|
+
import { TransformOptions, Warning } from "lightningcss";
|
|
3
|
+
import { Buffer } from "node:buffer";
|
|
4
|
+
import { SelectorTransformContext, assignNestedSelectors, buildChildCombinatorReplacement, cloneComponent, cloneComponents, createRootSpecificityReplacer, createTypeSelector, createVisitor, matchesHiddenNot, normalizeNestedSelectors, prepareStyleOptions, trimCombinators } from "@weapp-tailwindcss/postcss/experimental/lightningcss";
|
|
5
|
+
//#region src/lightningcss/index.d.ts
|
|
6
|
+
type CustomAtRules = Record<string, never>;
|
|
7
|
+
interface LightningcssStyleHandlerResult {
|
|
8
|
+
code: string;
|
|
9
|
+
map?: string | undefined;
|
|
10
|
+
warnings: Warning[];
|
|
11
|
+
}
|
|
12
|
+
interface LightningcssTransformConfig {
|
|
13
|
+
filename?: string | undefined;
|
|
14
|
+
transformOptions?: Omit<TransformOptions<CustomAtRules>, 'filename' | 'code' | 'visitor'> | undefined;
|
|
15
|
+
}
|
|
16
|
+
interface LightningcssStyleHandler {
|
|
17
|
+
(rawSource: string, overrideOptions?: Partial<IStyleHandlerOptions>): Promise<LightningcssStyleHandlerResult>;
|
|
18
|
+
}
|
|
19
|
+
declare function createLightningcssStyleHandler(options?: Partial<IStyleHandlerOptions>, config?: LightningcssTransformConfig): LightningcssStyleHandler;
|
|
20
|
+
declare function transformCss(css?: string | Buffer): Promise<{
|
|
21
|
+
code: Buffer<ArrayBuffer>;
|
|
22
|
+
map: Buffer<ArrayBuffer> | undefined;
|
|
23
|
+
warnings: Warning[];
|
|
24
|
+
}>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { assignNestedSelectors as a, createTypeSelector as c, trimCombinators as d, SelectorTransformContext as f, prepareStyleOptions as g, createRootSpecificityReplacer as h, transformCss as i, matchesHiddenNot as l, createVisitor as m, LightningcssTransformConfig as n, cloneComponent as o, buildChildCombinatorReplacement as p, createLightningcssStyleHandler as r, cloneComponents as s, LightningcssStyleHandlerResult as t, normalizeNestedSelectors as u };
|
package/dist/index.cjs
CHANGED
|
@@ -1,15 +1,71 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
exports
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
const require_lightningcss_index = require("./lightningcss/index.cjs");
|
|
3
|
+
let _weapp_tailwindcss_postcss_experimental_lightningcss = require("@weapp-tailwindcss/postcss/experimental/lightningcss");
|
|
4
|
+
Object.defineProperty(exports, "assignNestedSelectors", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
get: function() {
|
|
7
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.assignNestedSelectors;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
Object.defineProperty(exports, "buildChildCombinatorReplacement", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function() {
|
|
13
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.buildChildCombinatorReplacement;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "cloneComponent", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function() {
|
|
19
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.cloneComponent;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, "cloneComponents", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function() {
|
|
25
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.cloneComponents;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
exports.createLightningcssStyleHandler = require_lightningcss_index.createLightningcssStyleHandler;
|
|
29
|
+
Object.defineProperty(exports, "createRootSpecificityReplacer", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function() {
|
|
32
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.createRootSpecificityReplacer;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, "createTypeSelector", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function() {
|
|
38
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.createTypeSelector;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(exports, "createVisitor", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function() {
|
|
44
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.createVisitor;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(exports, "matchesHiddenNot", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: function() {
|
|
50
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.matchesHiddenNot;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(exports, "normalizeNestedSelectors", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get: function() {
|
|
56
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.normalizeNestedSelectors;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(exports, "prepareStyleOptions", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
get: function() {
|
|
62
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.prepareStyleOptions;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
exports.transformCss = require_lightningcss_index.transformCss;
|
|
66
|
+
Object.defineProperty(exports, "trimCombinators", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function() {
|
|
69
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.trimCombinators;
|
|
70
|
+
}
|
|
71
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as assignNestedSelectors, c as createTypeSelector, d as trimCombinators, f as SelectorTransformContext, g as prepareStyleOptions, h as createRootSpecificityReplacer, i as transformCss, l as matchesHiddenNot, m as createVisitor, n as LightningcssTransformConfig, o as cloneComponent, p as buildChildCombinatorReplacement, r as createLightningcssStyleHandler, s as cloneComponents, t as LightningcssStyleHandlerResult, u as normalizeNestedSelectors } from "./index-
|
|
1
|
+
import { a as assignNestedSelectors, c as createTypeSelector, d as trimCombinators, f as SelectorTransformContext, g as prepareStyleOptions, h as createRootSpecificityReplacer, i as transformCss, l as matchesHiddenNot, m as createVisitor, n as LightningcssTransformConfig, o as cloneComponent, p as buildChildCombinatorReplacement, r as createLightningcssStyleHandler, s as cloneComponents, t as LightningcssStyleHandlerResult, u as normalizeNestedSelectors } from "./index-DgmspOJt.js";
|
|
2
2
|
export { LightningcssStyleHandlerResult, LightningcssTransformConfig, type SelectorTransformContext, assignNestedSelectors, buildChildCombinatorReplacement, cloneComponent, cloneComponents, createLightningcssStyleHandler, createRootSpecificityReplacer, createTypeSelector, createVisitor, matchesHiddenNot, normalizeNestedSelectors, prepareStyleOptions, transformCss, trimCombinators };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as cloneComponents, c as normalizeNestedSelectors, d as createVisitor, f as createRootSpecificityReplacer, i as cloneComponent, l as trimCombinators, n as transformCss, o as createTypeSelector, p as prepareStyleOptions, r as assignNestedSelectors, s as matchesHiddenNot, t as createLightningcssStyleHandler, u as buildChildCombinatorReplacement } from "./lightningcss-Dt-baC0L.mjs";
|
|
2
2
|
export { assignNestedSelectors, buildChildCombinatorReplacement, cloneComponent, cloneComponents, createLightningcssStyleHandler, createRootSpecificityReplacer, createTypeSelector, createVisitor, matchesHiddenNot, normalizeNestedSelectors, prepareStyleOptions, transformCss, trimCombinators };
|
|
@@ -1,15 +1,124 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
let node_buffer = require("node:buffer");
|
|
3
|
+
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
4
|
+
let lightningcss = require("lightningcss");
|
|
5
|
+
let _weapp_tailwindcss_postcss_experimental_lightningcss = require("@weapp-tailwindcss/postcss/experimental/lightningcss");
|
|
6
|
+
//#region src/lightningcss/index.ts
|
|
7
|
+
const textDecoder = new TextDecoder();
|
|
8
|
+
const defaultLightningFilename = "inline.css";
|
|
9
|
+
function omitUndefined(value) {
|
|
10
|
+
const result = {};
|
|
11
|
+
for (const [key, item] of Object.entries(value)) if (item !== void 0) result[key] = item;
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
function createPreparedRuntime(options) {
|
|
15
|
+
const resolvedOptions = (0, _weapp_tailwindcss_postcss_experimental_lightningcss.prepareStyleOptions)(options);
|
|
16
|
+
const ctx = omitUndefined({
|
|
17
|
+
options: resolvedOptions,
|
|
18
|
+
childCombinatorReplacement: (0, _weapp_tailwindcss_postcss_experimental_lightningcss.buildChildCombinatorReplacement)(resolvedOptions)
|
|
19
|
+
});
|
|
20
|
+
return omitUndefined({
|
|
21
|
+
options: resolvedOptions,
|
|
22
|
+
replaceSpecificity: (0, _weapp_tailwindcss_postcss_experimental_lightningcss.createRootSpecificityReplacer)(resolvedOptions),
|
|
23
|
+
visitor: (0, _weapp_tailwindcss_postcss_experimental_lightningcss.createVisitor)(ctx)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function createLightningcssStyleHandler(options, config = {}) {
|
|
27
|
+
const baseRuntime = createPreparedRuntime(options);
|
|
28
|
+
const { transformOptions, filename } = config;
|
|
29
|
+
const transformOverrides = transformOptions ?? {};
|
|
30
|
+
return async (rawSource, overrideOptions) => {
|
|
31
|
+
const runtime = !overrideOptions || Object.keys(overrideOptions).length === 0 ? baseRuntime : createPreparedRuntime((0, _weapp_tailwindcss_shared.defuOverrideArray)(overrideOptions, baseRuntime.options));
|
|
32
|
+
const lightningResult = (0, lightningcss.transform)(omitUndefined({
|
|
33
|
+
filename: filename ?? defaultLightningFilename,
|
|
34
|
+
code: node_buffer.Buffer.from(rawSource),
|
|
35
|
+
visitor: runtime.visitor,
|
|
36
|
+
minify: false,
|
|
37
|
+
...transformOverrides
|
|
38
|
+
}));
|
|
39
|
+
const decodedCode = textDecoder.decode(lightningResult.code);
|
|
40
|
+
return omitUndefined({
|
|
41
|
+
code: runtime.replaceSpecificity ? runtime.replaceSpecificity(decodedCode) : decodedCode,
|
|
42
|
+
map: lightningResult.map ? textDecoder.decode(lightningResult.map) : void 0,
|
|
43
|
+
warnings: lightningResult.warnings
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const defaultHandler = createLightningcssStyleHandler(void 0, { transformOptions: { minify: true } });
|
|
48
|
+
async function transformCss(css = ".foo { color: red }") {
|
|
49
|
+
const result = await defaultHandler(typeof css === "string" ? css : css.toString());
|
|
50
|
+
return {
|
|
51
|
+
...result,
|
|
52
|
+
code: node_buffer.Buffer.from(result.code),
|
|
53
|
+
map: result.map ? node_buffer.Buffer.from(result.map) : void 0
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
Object.defineProperty(exports, "assignNestedSelectors", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function() {
|
|
60
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.assignNestedSelectors;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(exports, "buildChildCombinatorReplacement", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function() {
|
|
66
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.buildChildCombinatorReplacement;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(exports, "cloneComponent", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function() {
|
|
72
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.cloneComponent;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(exports, "cloneComponents", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function() {
|
|
78
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.cloneComponents;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
exports.createLightningcssStyleHandler = createLightningcssStyleHandler;
|
|
82
|
+
Object.defineProperty(exports, "createRootSpecificityReplacer", {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
get: function() {
|
|
85
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.createRootSpecificityReplacer;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(exports, "createTypeSelector", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
get: function() {
|
|
91
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.createTypeSelector;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(exports, "createVisitor", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
get: function() {
|
|
97
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.createVisitor;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
Object.defineProperty(exports, "matchesHiddenNot", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
get: function() {
|
|
103
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.matchesHiddenNot;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
Object.defineProperty(exports, "normalizeNestedSelectors", {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
get: function() {
|
|
109
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.normalizeNestedSelectors;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
Object.defineProperty(exports, "prepareStyleOptions", {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
get: function() {
|
|
115
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.prepareStyleOptions;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
exports.transformCss = transformCss;
|
|
119
|
+
Object.defineProperty(exports, "trimCombinators", {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
get: function() {
|
|
122
|
+
return _weapp_tailwindcss_postcss_experimental_lightningcss.trimCombinators;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as assignNestedSelectors, c as createTypeSelector, d as trimCombinators, f as SelectorTransformContext, g as prepareStyleOptions, h as createRootSpecificityReplacer, i as transformCss, l as matchesHiddenNot, m as createVisitor, n as LightningcssTransformConfig, o as cloneComponent, p as buildChildCombinatorReplacement, r as createLightningcssStyleHandler, s as cloneComponents, t as LightningcssStyleHandlerResult, u as normalizeNestedSelectors } from "../index-
|
|
1
|
+
import { a as assignNestedSelectors, c as createTypeSelector, d as trimCombinators, f as SelectorTransformContext, g as prepareStyleOptions, h as createRootSpecificityReplacer, i as transformCss, l as matchesHiddenNot, m as createVisitor, n as LightningcssTransformConfig, o as cloneComponent, p as buildChildCombinatorReplacement, r as createLightningcssStyleHandler, s as cloneComponents, t as LightningcssStyleHandlerResult, u as normalizeNestedSelectors } from "../index-DgmspOJt.js";
|
|
2
2
|
export { LightningcssStyleHandlerResult, LightningcssTransformConfig, type SelectorTransformContext, assignNestedSelectors, buildChildCombinatorReplacement, cloneComponent, cloneComponents, createLightningcssStyleHandler, createRootSpecificityReplacer, createTypeSelector, createVisitor, matchesHiddenNot, normalizeNestedSelectors, prepareStyleOptions, transformCss, trimCombinators };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as cloneComponents, c as normalizeNestedSelectors, d as createVisitor, f as createRootSpecificityReplacer, i as cloneComponent, l as trimCombinators, n as transformCss, o as createTypeSelector, p as prepareStyleOptions, r as assignNestedSelectors, s as matchesHiddenNot, t as createLightningcssStyleHandler, u as buildChildCombinatorReplacement } from "../lightningcss-Dt-baC0L.mjs";
|
|
2
2
|
export { assignNestedSelectors, buildChildCombinatorReplacement, cloneComponent, cloneComponents, createLightningcssStyleHandler, createRootSpecificityReplacer, createTypeSelector, createVisitor, matchesHiddenNot, normalizeNestedSelectors, prepareStyleOptions, transformCss, trimCombinators };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { defuOverrideArray } from "@weapp-tailwindcss/shared";
|
|
3
|
+
import { transform } from "lightningcss";
|
|
4
|
+
import { assignNestedSelectors, buildChildCombinatorReplacement, cloneComponent, cloneComponents, createRootSpecificityReplacer, createTypeSelector, createVisitor, matchesHiddenNot, normalizeNestedSelectors, prepareStyleOptions, trimCombinators } from "@weapp-tailwindcss/postcss/experimental/lightningcss";
|
|
5
|
+
//#region src/lightningcss/index.ts
|
|
6
|
+
const textDecoder = new TextDecoder();
|
|
7
|
+
const defaultLightningFilename = "inline.css";
|
|
8
|
+
function omitUndefined(value) {
|
|
9
|
+
const result = {};
|
|
10
|
+
for (const [key, item] of Object.entries(value)) if (item !== void 0) result[key] = item;
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
function createPreparedRuntime(options) {
|
|
14
|
+
const resolvedOptions = prepareStyleOptions(options);
|
|
15
|
+
const ctx = omitUndefined({
|
|
16
|
+
options: resolvedOptions,
|
|
17
|
+
childCombinatorReplacement: buildChildCombinatorReplacement(resolvedOptions)
|
|
18
|
+
});
|
|
19
|
+
return omitUndefined({
|
|
20
|
+
options: resolvedOptions,
|
|
21
|
+
replaceSpecificity: createRootSpecificityReplacer(resolvedOptions),
|
|
22
|
+
visitor: createVisitor(ctx)
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function createLightningcssStyleHandler(options, config = {}) {
|
|
26
|
+
const baseRuntime = createPreparedRuntime(options);
|
|
27
|
+
const { transformOptions, filename } = config;
|
|
28
|
+
const transformOverrides = transformOptions ?? {};
|
|
29
|
+
return async (rawSource, overrideOptions) => {
|
|
30
|
+
const runtime = !overrideOptions || Object.keys(overrideOptions).length === 0 ? baseRuntime : createPreparedRuntime(defuOverrideArray(overrideOptions, baseRuntime.options));
|
|
31
|
+
const lightningResult = transform(omitUndefined({
|
|
32
|
+
filename: filename ?? defaultLightningFilename,
|
|
33
|
+
code: Buffer.from(rawSource),
|
|
34
|
+
visitor: runtime.visitor,
|
|
35
|
+
minify: false,
|
|
36
|
+
...transformOverrides
|
|
37
|
+
}));
|
|
38
|
+
const decodedCode = textDecoder.decode(lightningResult.code);
|
|
39
|
+
return omitUndefined({
|
|
40
|
+
code: runtime.replaceSpecificity ? runtime.replaceSpecificity(decodedCode) : decodedCode,
|
|
41
|
+
map: lightningResult.map ? textDecoder.decode(lightningResult.map) : void 0,
|
|
42
|
+
warnings: lightningResult.warnings
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const defaultHandler = createLightningcssStyleHandler(void 0, { transformOptions: { minify: true } });
|
|
47
|
+
async function transformCss(css = ".foo { color: red }") {
|
|
48
|
+
const result = await defaultHandler(typeof css === "string" ? css : css.toString());
|
|
49
|
+
return {
|
|
50
|
+
...result,
|
|
51
|
+
code: Buffer.from(result.code),
|
|
52
|
+
map: result.map ? Buffer.from(result.map) : void 0
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { cloneComponents as a, normalizeNestedSelectors as c, createVisitor as d, createRootSpecificityReplacer as f, cloneComponent as i, trimCombinators as l, transformCss as n, createTypeSelector as o, prepareStyleOptions as p, assignNestedSelectors as r, matchesHiddenNot as s, createLightningcssStyleHandler as t, buildChildCombinatorReplacement as u };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/experimental",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.44",
|
|
5
5
|
"description": "Experimental integrations for cross-platform Tailwind CSS. 跨端 Tailwind CSS 实验性集成能力。",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "ISC",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"node": "^20.19.0 || >=22.12.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@weapp-tailwindcss/postcss": "3.3.
|
|
41
|
+
"@weapp-tailwindcss/postcss": "3.3.7",
|
|
42
42
|
"@weapp-tailwindcss/shared": "2.0.3",
|
|
43
43
|
"lightningcss": "^1.33.0"
|
|
44
44
|
},
|
package/dist/index-BXAviB07.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Buffer } from "node:buffer";
|
|
2
|
-
import { Selector, SelectorComponent, TransformOptions, Warning } from "lightningcss";
|
|
3
|
-
import { IStyleHandlerOptions } from "@weapp-tailwindcss/postcss";
|
|
4
|
-
//#region src/lightningcss/options.d.ts
|
|
5
|
-
declare function createRootSpecificityReplacer(options: IStyleHandlerOptions): ((code: string) => string) | undefined;
|
|
6
|
-
declare function prepareStyleOptions(options?: Partial<IStyleHandlerOptions>): IStyleHandlerOptions;
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/lightningcss/selector-transform.d.ts
|
|
9
|
-
type CustomAtRules$1 = Record<string, never>;
|
|
10
|
-
interface SelectorTransformContext {
|
|
11
|
-
options: IStyleHandlerOptions;
|
|
12
|
-
childCombinatorReplacement?: SelectorComponent[] | undefined;
|
|
13
|
-
}
|
|
14
|
-
declare function buildChildCombinatorReplacement(options: IStyleHandlerOptions): SelectorComponent[] | undefined;
|
|
15
|
-
declare function createVisitor(ctx: SelectorTransformContext): import("lightningcss").Visitor<CustomAtRules$1>;
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region src/lightningcss/selector-utils.d.ts
|
|
18
|
-
declare function createTypeSelector(name: string): SelectorComponent;
|
|
19
|
-
declare function cloneComponent<T>(value: T): T;
|
|
20
|
-
declare function cloneComponents(list: SelectorComponent[]): SelectorComponent[];
|
|
21
|
-
declare function normalizeNestedSelectors(selectors: Selector[] | Selector | null | undefined): Selector[] | undefined;
|
|
22
|
-
declare function assignNestedSelectors(target: SelectorComponent & {
|
|
23
|
-
selectors?: Selector[] | Selector | null;
|
|
24
|
-
}, value: Selector[] | undefined): void;
|
|
25
|
-
declare function trimCombinators(components: SelectorComponent[]): SelectorComponent[];
|
|
26
|
-
declare function matchesHiddenNot(component: SelectorComponent | undefined): boolean;
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/lightningcss/index.d.ts
|
|
29
|
-
type CustomAtRules = Record<string, never>;
|
|
30
|
-
interface LightningcssStyleHandlerResult {
|
|
31
|
-
code: string;
|
|
32
|
-
map?: string | undefined;
|
|
33
|
-
warnings: Warning[];
|
|
34
|
-
}
|
|
35
|
-
interface LightningcssTransformConfig {
|
|
36
|
-
filename?: string | undefined;
|
|
37
|
-
transformOptions?: Omit<TransformOptions<CustomAtRules>, 'filename' | 'code' | 'visitor'> | undefined;
|
|
38
|
-
}
|
|
39
|
-
interface LightningcssStyleHandler {
|
|
40
|
-
(rawSource: string, overrideOptions?: Partial<IStyleHandlerOptions>): Promise<LightningcssStyleHandlerResult>;
|
|
41
|
-
}
|
|
42
|
-
declare function createLightningcssStyleHandler(options?: Partial<IStyleHandlerOptions>, config?: LightningcssTransformConfig): LightningcssStyleHandler;
|
|
43
|
-
declare function transformCss(css?: string | Buffer): Promise<{
|
|
44
|
-
code: Buffer<ArrayBuffer>;
|
|
45
|
-
map: Buffer<ArrayBuffer> | undefined;
|
|
46
|
-
warnings: Warning[];
|
|
47
|
-
}>;
|
|
48
|
-
//#endregion
|
|
49
|
-
export { assignNestedSelectors as a, createTypeSelector as c, trimCombinators as d, SelectorTransformContext as f, prepareStyleOptions as g, createRootSpecificityReplacer as h, transformCss as i, matchesHiddenNot as l, createVisitor as m, LightningcssTransformConfig as n, cloneComponent as o, buildChildCombinatorReplacement as p, createLightningcssStyleHandler as r, cloneComponents as s, LightningcssStyleHandlerResult as t, normalizeNestedSelectors as u };
|
package/dist/index-DyBd14D_.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { IStyleHandlerOptions } from "@weapp-tailwindcss/postcss";
|
|
2
|
-
import { Selector, SelectorComponent, TransformOptions, Warning } from "lightningcss";
|
|
3
|
-
import { Buffer } from "node:buffer";
|
|
4
|
-
//#region src/lightningcss/options.d.ts
|
|
5
|
-
declare function createRootSpecificityReplacer(options: IStyleHandlerOptions): ((code: string) => string) | undefined;
|
|
6
|
-
declare function prepareStyleOptions(options?: Partial<IStyleHandlerOptions>): IStyleHandlerOptions;
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/lightningcss/selector-transform.d.ts
|
|
9
|
-
type CustomAtRules$1 = Record<string, never>;
|
|
10
|
-
interface SelectorTransformContext {
|
|
11
|
-
options: IStyleHandlerOptions;
|
|
12
|
-
childCombinatorReplacement?: SelectorComponent[] | undefined;
|
|
13
|
-
}
|
|
14
|
-
declare function buildChildCombinatorReplacement(options: IStyleHandlerOptions): SelectorComponent[] | undefined;
|
|
15
|
-
declare function createVisitor(ctx: SelectorTransformContext): import("lightningcss").Visitor<CustomAtRules$1>;
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region src/lightningcss/selector-utils.d.ts
|
|
18
|
-
declare function createTypeSelector(name: string): SelectorComponent;
|
|
19
|
-
declare function cloneComponent<T>(value: T): T;
|
|
20
|
-
declare function cloneComponents(list: SelectorComponent[]): SelectorComponent[];
|
|
21
|
-
declare function normalizeNestedSelectors(selectors: Selector[] | Selector | null | undefined): Selector[] | undefined;
|
|
22
|
-
declare function assignNestedSelectors(target: SelectorComponent & {
|
|
23
|
-
selectors?: Selector[] | Selector | null;
|
|
24
|
-
}, value: Selector[] | undefined): void;
|
|
25
|
-
declare function trimCombinators(components: SelectorComponent[]): SelectorComponent[];
|
|
26
|
-
declare function matchesHiddenNot(component: SelectorComponent | undefined): boolean;
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/lightningcss/index.d.ts
|
|
29
|
-
type CustomAtRules = Record<string, never>;
|
|
30
|
-
interface LightningcssStyleHandlerResult {
|
|
31
|
-
code: string;
|
|
32
|
-
map?: string | undefined;
|
|
33
|
-
warnings: Warning[];
|
|
34
|
-
}
|
|
35
|
-
interface LightningcssTransformConfig {
|
|
36
|
-
filename?: string | undefined;
|
|
37
|
-
transformOptions?: Omit<TransformOptions<CustomAtRules>, 'filename' | 'code' | 'visitor'> | undefined;
|
|
38
|
-
}
|
|
39
|
-
interface LightningcssStyleHandler {
|
|
40
|
-
(rawSource: string, overrideOptions?: Partial<IStyleHandlerOptions>): Promise<LightningcssStyleHandlerResult>;
|
|
41
|
-
}
|
|
42
|
-
declare function createLightningcssStyleHandler(options?: Partial<IStyleHandlerOptions>, config?: LightningcssTransformConfig): LightningcssStyleHandler;
|
|
43
|
-
declare function transformCss(css?: string | Buffer): Promise<{
|
|
44
|
-
code: Buffer<ArrayBuffer>;
|
|
45
|
-
map: Buffer<ArrayBuffer> | undefined;
|
|
46
|
-
warnings: Warning[];
|
|
47
|
-
}>;
|
|
48
|
-
//#endregion
|
|
49
|
-
export { assignNestedSelectors as a, createTypeSelector as c, trimCombinators as d, SelectorTransformContext as f, prepareStyleOptions as g, createRootSpecificityReplacer as h, transformCss as i, matchesHiddenNot as l, createVisitor as m, LightningcssTransformConfig as n, cloneComponent as o, buildChildCombinatorReplacement as p, createLightningcssStyleHandler as r, cloneComponents as s, LightningcssStyleHandlerResult as t, normalizeNestedSelectors as u };
|
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
let node_buffer = require("node:buffer");
|
|
2
|
-
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
3
|
-
let lightningcss = require("lightningcss");
|
|
4
|
-
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
5
|
-
//#region src/lightningcss/options.ts
|
|
6
|
-
const FALLBACK_PLACEHOLDER_SUFFIXES = [":not(#n)", ":not(#\\#)"];
|
|
7
|
-
function normalizeSelectorList(value) {
|
|
8
|
-
if (value === void 0 || value === false) return [];
|
|
9
|
-
return Array.isArray(value) ? value.filter(Boolean) : [value];
|
|
10
|
-
}
|
|
11
|
-
function getSpecificityMatchingName(options) {
|
|
12
|
-
const feature = options.cssPresetEnv?.features?.["is-pseudo-class"];
|
|
13
|
-
if (feature && typeof feature === "object" && "specificityMatchingName" in feature) {
|
|
14
|
-
const specificityName = feature.specificityMatchingName;
|
|
15
|
-
return typeof specificityName === "string" && specificityName.length > 0 ? specificityName : void 0;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function createRootSpecificityReplacer(options) {
|
|
19
|
-
const specificityMatchingName = getSpecificityMatchingName(options);
|
|
20
|
-
const selectors = normalizeSelectorList(options.cssSelectorReplacement?.root);
|
|
21
|
-
const replaceFallbackPlaceholder = (code) => {
|
|
22
|
-
let output = code;
|
|
23
|
-
for (const suffix of FALLBACK_PLACEHOLDER_SUFFIXES) if (output.includes(suffix)) output = output.split(suffix).join("");
|
|
24
|
-
return output;
|
|
25
|
-
};
|
|
26
|
-
if (!specificityMatchingName || selectors.length === 0) return replaceFallbackPlaceholder;
|
|
27
|
-
const suffix = `:not(.${specificityMatchingName})`;
|
|
28
|
-
const targets = selectors.map((selector) => selector?.trim()).filter((selector) => Boolean(selector?.length)).map((selector) => ({
|
|
29
|
-
match: `${selector}${suffix}`,
|
|
30
|
-
spacedMatch: `${selector} ${suffix}`,
|
|
31
|
-
replacement: selector
|
|
32
|
-
}));
|
|
33
|
-
if (!targets.length) return;
|
|
34
|
-
return (code) => {
|
|
35
|
-
let output = replaceFallbackPlaceholder(code);
|
|
36
|
-
for (const target of targets) {
|
|
37
|
-
if (output.includes(target.match)) output = output.split(target.match).join(target.replacement);
|
|
38
|
-
if (output.includes(target.spacedMatch)) output = output.split(target.spacedMatch).join(target.replacement);
|
|
39
|
-
}
|
|
40
|
-
return output;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function getLightningDefaultOptions(options) {
|
|
44
|
-
const customPropertiesFeature = options?.cssPresetEnv?.features?.["custom-properties"];
|
|
45
|
-
return {
|
|
46
|
-
cssPresetEnv: {
|
|
47
|
-
features: {
|
|
48
|
-
"cascade-layers": true,
|
|
49
|
-
"is-pseudo-class": { specificityMatchingName: "weapp-tw-ig" },
|
|
50
|
-
"oklab-function": true,
|
|
51
|
-
"color-mix": true,
|
|
52
|
-
"custom-properties": customPropertiesFeature !== void 0 ? customPropertiesFeature : options?.cssCalc ? { preserve: true } : false
|
|
53
|
-
},
|
|
54
|
-
autoprefixer: { add: false }
|
|
55
|
-
},
|
|
56
|
-
cssRemoveProperty: true,
|
|
57
|
-
cssRemoveHoverPseudoClass: true,
|
|
58
|
-
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
59
|
-
cssSelectorReplacement: {
|
|
60
|
-
root: [
|
|
61
|
-
"page",
|
|
62
|
-
".tw-root",
|
|
63
|
-
"wx-root-portal-content"
|
|
64
|
-
],
|
|
65
|
-
universal: ["view", "text"]
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
function prepareStyleOptions(options) {
|
|
70
|
-
const merged = (0, _weapp_tailwindcss_shared.defuOverrideArray)(options, getLightningDefaultOptions(options));
|
|
71
|
-
merged.cssInjectPreflight = (0, _weapp_tailwindcss_postcss.createInjectPreflight)(merged.cssPreflight);
|
|
72
|
-
return merged;
|
|
73
|
-
}
|
|
74
|
-
//#endregion
|
|
75
|
-
//#region src/lightningcss/selector-utils.ts
|
|
76
|
-
function createTypeSelector(name) {
|
|
77
|
-
return {
|
|
78
|
-
type: "type",
|
|
79
|
-
name
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function cloneComponent(value) {
|
|
83
|
-
const structured = globalThis.structuredClone;
|
|
84
|
-
if (typeof structured === "function") return structured(value);
|
|
85
|
-
return JSON.parse(JSON.stringify(value));
|
|
86
|
-
}
|
|
87
|
-
function cloneComponents(list) {
|
|
88
|
-
return list.map(cloneComponent);
|
|
89
|
-
}
|
|
90
|
-
function normalizeNestedSelectors(selectors) {
|
|
91
|
-
if (!selectors) return;
|
|
92
|
-
if (Array.isArray(selectors)) {
|
|
93
|
-
if (selectors.length === 0) return [];
|
|
94
|
-
const first = selectors[0];
|
|
95
|
-
if (Array.isArray(first)) return selectors;
|
|
96
|
-
return [selectors];
|
|
97
|
-
}
|
|
98
|
-
return [selectors];
|
|
99
|
-
}
|
|
100
|
-
function assignNestedSelectors(target, value) {
|
|
101
|
-
if (!("selectors" in target)) return;
|
|
102
|
-
if (Array.isArray(target.selectors)) target.selectors = value ?? [];
|
|
103
|
-
else if (target.selectors && !Array.isArray(target.selectors)) target.selectors = value?.[0] ?? target.selectors;
|
|
104
|
-
}
|
|
105
|
-
function trimCombinators(components) {
|
|
106
|
-
let start = 0;
|
|
107
|
-
let end = components.length;
|
|
108
|
-
while (start < end && components[start]?.type === "combinator") start++;
|
|
109
|
-
while (end > start && components[end - 1]?.type === "combinator") end--;
|
|
110
|
-
return components.slice(start, end);
|
|
111
|
-
}
|
|
112
|
-
function matchesHiddenNot(component) {
|
|
113
|
-
if (!component || component.type !== "pseudo-class" || component.kind !== "not") return false;
|
|
114
|
-
const selectors = normalizeNestedSelectors(component.selectors);
|
|
115
|
-
if (!selectors || selectors.length !== 1) return false;
|
|
116
|
-
const [nestedSelector] = selectors;
|
|
117
|
-
if (!nestedSelector || nestedSelector.length !== 1) return false;
|
|
118
|
-
const [node] = nestedSelector;
|
|
119
|
-
if (!node) return false;
|
|
120
|
-
return node.type === "attribute" && node.name === "hidden" || node.type === "type" && node.name === "template";
|
|
121
|
-
}
|
|
122
|
-
//#endregion
|
|
123
|
-
//#region src/lightningcss/selector-transform.ts
|
|
124
|
-
function buildSelectorReplacement(value) {
|
|
125
|
-
if (!value) return null;
|
|
126
|
-
const targets = Array.isArray(value) ? value : [value];
|
|
127
|
-
if (!targets.length) return null;
|
|
128
|
-
if (targets.length === 1) return [createTypeSelector(targets[0])];
|
|
129
|
-
return [{
|
|
130
|
-
type: "pseudo-class",
|
|
131
|
-
kind: "is",
|
|
132
|
-
selectors: targets.map((name) => [createTypeSelector(name)])
|
|
133
|
-
}];
|
|
134
|
-
}
|
|
135
|
-
function buildChildCombinatorReplacement(options) {
|
|
136
|
-
const { cssChildCombinatorReplaceValue } = options;
|
|
137
|
-
if (!cssChildCombinatorReplaceValue) return;
|
|
138
|
-
const normalized = Array.isArray(cssChildCombinatorReplaceValue) ? cssChildCombinatorReplaceValue : [cssChildCombinatorReplaceValue];
|
|
139
|
-
if (!normalized.length) return;
|
|
140
|
-
const baseComponents = buildSelectorReplacement(normalized) ?? [createTypeSelector("view")];
|
|
141
|
-
const left = cloneComponents(baseComponents);
|
|
142
|
-
const right = cloneComponents(baseComponents);
|
|
143
|
-
return [
|
|
144
|
-
...left,
|
|
145
|
-
{
|
|
146
|
-
type: "combinator",
|
|
147
|
-
value: "next-sibling"
|
|
148
|
-
},
|
|
149
|
-
...right
|
|
150
|
-
];
|
|
151
|
-
}
|
|
152
|
-
function transformSelectorComponent(component, ctx, transformList) {
|
|
153
|
-
const { options } = ctx;
|
|
154
|
-
if (component.type === "class") {
|
|
155
|
-
const cloned = cloneComponent(component);
|
|
156
|
-
cloned.name = (0, _weapp_tailwindcss_postcss.internalCssSelectorReplacer)(component.name, { escapeMap: options.escapeMap });
|
|
157
|
-
return [cloned];
|
|
158
|
-
}
|
|
159
|
-
if (component.type === "universal") {
|
|
160
|
-
const replacement = buildSelectorReplacement(options.cssSelectorReplacement?.universal);
|
|
161
|
-
if (replacement) return cloneComponents(replacement);
|
|
162
|
-
return [cloneComponent(component)];
|
|
163
|
-
}
|
|
164
|
-
if (component.type === "type") {
|
|
165
|
-
if (options.uniAppX) return [];
|
|
166
|
-
return [cloneComponent(component)];
|
|
167
|
-
}
|
|
168
|
-
if (component.type === "attribute") {
|
|
169
|
-
if (options.uniAppX) return [];
|
|
170
|
-
return [cloneComponent(component)];
|
|
171
|
-
}
|
|
172
|
-
if (component.type === "combinator") return [cloneComponent(component)];
|
|
173
|
-
if (component.type === "pseudo-element") return [cloneComponent(component)];
|
|
174
|
-
if (component.type === "pseudo-class") {
|
|
175
|
-
if (component.kind === "hover" && options.cssRemoveHoverPseudoClass) return null;
|
|
176
|
-
if (component.kind === "root") {
|
|
177
|
-
const replacement = buildSelectorReplacement(options.cssSelectorReplacement?.root);
|
|
178
|
-
if (replacement) return cloneComponents(replacement);
|
|
179
|
-
return [cloneComponent(component)];
|
|
180
|
-
}
|
|
181
|
-
const cloned = cloneComponent(component);
|
|
182
|
-
if ("selectors" in cloned) {
|
|
183
|
-
const nestedSelectors = normalizeNestedSelectors(cloned.selectors);
|
|
184
|
-
if (nestedSelectors) assignNestedSelectors(cloned, transformList(nestedSelectors, ctx));
|
|
185
|
-
}
|
|
186
|
-
if (cloned.kind === "where" && options.uniAppX) cloned.kind = "is";
|
|
187
|
-
return [cloned];
|
|
188
|
-
}
|
|
189
|
-
return [cloneComponent(component)];
|
|
190
|
-
}
|
|
191
|
-
function transformSelector(selector, ctx, transformList) {
|
|
192
|
-
const { childCombinatorReplacement } = ctx;
|
|
193
|
-
const output = [];
|
|
194
|
-
for (let index = 0; index < selector.length; index++) {
|
|
195
|
-
const component = selector[index];
|
|
196
|
-
if (!component) continue;
|
|
197
|
-
if (component.type === "combinator" && component.value === "child" && childCombinatorReplacement) {
|
|
198
|
-
const next = selector[index + 1];
|
|
199
|
-
const combinator = selector[index + 2];
|
|
200
|
-
const third = selector[index + 3];
|
|
201
|
-
if (matchesHiddenNot(next) && combinator?.type === "combinator" && (combinator.value === "next-sibling" || combinator.value === "later-sibling") && matchesHiddenNot(third)) {
|
|
202
|
-
output.push(cloneComponent(component));
|
|
203
|
-
output.push(...cloneComponents(childCombinatorReplacement));
|
|
204
|
-
index += 3;
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
const replaced = transformSelectorComponent(component, ctx, transformList);
|
|
209
|
-
if (replaced === null) return null;
|
|
210
|
-
output.push(...replaced);
|
|
211
|
-
}
|
|
212
|
-
const trimmed = trimCombinators(output);
|
|
213
|
-
return trimmed.length > 0 ? trimmed : null;
|
|
214
|
-
}
|
|
215
|
-
function transformSelectorList(selectors, ctx) {
|
|
216
|
-
const result = [];
|
|
217
|
-
for (const selector of selectors) {
|
|
218
|
-
const transformed = transformSelector(selector, ctx, transformSelectorList);
|
|
219
|
-
if (transformed && transformed.length > 0) result.push(transformed);
|
|
220
|
-
}
|
|
221
|
-
return result;
|
|
222
|
-
}
|
|
223
|
-
function createVisitor(ctx) {
|
|
224
|
-
return {
|
|
225
|
-
Rule(rule) {
|
|
226
|
-
if (rule.type === "property" && ctx.options.cssRemoveProperty) return [];
|
|
227
|
-
if (rule.type !== "style") return rule;
|
|
228
|
-
const styleRule = rule.value;
|
|
229
|
-
if (!styleRule.selectors) return rule;
|
|
230
|
-
const selectors = transformSelectorList(styleRule.selectors, ctx);
|
|
231
|
-
if (!selectors.length) return [];
|
|
232
|
-
styleRule.selectors = selectors;
|
|
233
|
-
return rule;
|
|
234
|
-
},
|
|
235
|
-
RuleExit(rule) {
|
|
236
|
-
if (rule.type !== "style") return rule;
|
|
237
|
-
const styleRule = rule.value;
|
|
238
|
-
const hasValidSelectors = (styleRule.selectors ?? []).some((selector) => selector.length > 0);
|
|
239
|
-
const declarationCount = styleRule.declarations?.declarations?.length ?? 0;
|
|
240
|
-
if (!hasValidSelectors || ctx.options.uniAppX && declarationCount === 0) return [];
|
|
241
|
-
return rule;
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
//#endregion
|
|
246
|
-
//#region src/lightningcss/index.ts
|
|
247
|
-
const textDecoder = new TextDecoder();
|
|
248
|
-
const defaultLightningFilename = "inline.css";
|
|
249
|
-
function omitUndefined(value) {
|
|
250
|
-
const result = {};
|
|
251
|
-
for (const [key, item] of Object.entries(value)) if (item !== void 0) result[key] = item;
|
|
252
|
-
return result;
|
|
253
|
-
}
|
|
254
|
-
function createPreparedRuntime(options) {
|
|
255
|
-
const resolvedOptions = prepareStyleOptions(options);
|
|
256
|
-
const ctx = omitUndefined({
|
|
257
|
-
options: resolvedOptions,
|
|
258
|
-
childCombinatorReplacement: buildChildCombinatorReplacement(resolvedOptions)
|
|
259
|
-
});
|
|
260
|
-
return omitUndefined({
|
|
261
|
-
options: resolvedOptions,
|
|
262
|
-
replaceSpecificity: createRootSpecificityReplacer(resolvedOptions),
|
|
263
|
-
visitor: createVisitor(ctx)
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
function createLightningcssStyleHandler(options, config = {}) {
|
|
267
|
-
const baseRuntime = createPreparedRuntime(options);
|
|
268
|
-
const { transformOptions, filename } = config;
|
|
269
|
-
const transformOverrides = transformOptions ?? {};
|
|
270
|
-
return async (rawSource, overrideOptions) => {
|
|
271
|
-
const runtime = !overrideOptions || Object.keys(overrideOptions).length === 0 ? baseRuntime : createPreparedRuntime((0, _weapp_tailwindcss_shared.defuOverrideArray)(overrideOptions, baseRuntime.options));
|
|
272
|
-
const lightningResult = (0, lightningcss.transform)(omitUndefined({
|
|
273
|
-
filename: filename ?? defaultLightningFilename,
|
|
274
|
-
code: node_buffer.Buffer.from(rawSource),
|
|
275
|
-
visitor: runtime.visitor,
|
|
276
|
-
minify: false,
|
|
277
|
-
...transformOverrides
|
|
278
|
-
}));
|
|
279
|
-
const decodedCode = textDecoder.decode(lightningResult.code);
|
|
280
|
-
return omitUndefined({
|
|
281
|
-
code: runtime.replaceSpecificity ? runtime.replaceSpecificity(decodedCode) : decodedCode,
|
|
282
|
-
map: lightningResult.map ? textDecoder.decode(lightningResult.map) : void 0,
|
|
283
|
-
warnings: lightningResult.warnings
|
|
284
|
-
});
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
const defaultHandler = createLightningcssStyleHandler(void 0, { transformOptions: { minify: true } });
|
|
288
|
-
async function transformCss(css = ".foo { color: red }") {
|
|
289
|
-
const result = await defaultHandler(typeof css === "string" ? css : css.toString());
|
|
290
|
-
return {
|
|
291
|
-
...result,
|
|
292
|
-
code: node_buffer.Buffer.from(result.code),
|
|
293
|
-
map: result.map ? node_buffer.Buffer.from(result.map) : void 0
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
//#endregion
|
|
297
|
-
Object.defineProperty(exports, "assignNestedSelectors", {
|
|
298
|
-
enumerable: true,
|
|
299
|
-
get: function() {
|
|
300
|
-
return assignNestedSelectors;
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
Object.defineProperty(exports, "buildChildCombinatorReplacement", {
|
|
304
|
-
enumerable: true,
|
|
305
|
-
get: function() {
|
|
306
|
-
return buildChildCombinatorReplacement;
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
Object.defineProperty(exports, "cloneComponent", {
|
|
310
|
-
enumerable: true,
|
|
311
|
-
get: function() {
|
|
312
|
-
return cloneComponent;
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
Object.defineProperty(exports, "cloneComponents", {
|
|
316
|
-
enumerable: true,
|
|
317
|
-
get: function() {
|
|
318
|
-
return cloneComponents;
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
Object.defineProperty(exports, "createLightningcssStyleHandler", {
|
|
322
|
-
enumerable: true,
|
|
323
|
-
get: function() {
|
|
324
|
-
return createLightningcssStyleHandler;
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
Object.defineProperty(exports, "createRootSpecificityReplacer", {
|
|
328
|
-
enumerable: true,
|
|
329
|
-
get: function() {
|
|
330
|
-
return createRootSpecificityReplacer;
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
Object.defineProperty(exports, "createTypeSelector", {
|
|
334
|
-
enumerable: true,
|
|
335
|
-
get: function() {
|
|
336
|
-
return createTypeSelector;
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
Object.defineProperty(exports, "createVisitor", {
|
|
340
|
-
enumerable: true,
|
|
341
|
-
get: function() {
|
|
342
|
-
return createVisitor;
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
Object.defineProperty(exports, "matchesHiddenNot", {
|
|
346
|
-
enumerable: true,
|
|
347
|
-
get: function() {
|
|
348
|
-
return matchesHiddenNot;
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
Object.defineProperty(exports, "normalizeNestedSelectors", {
|
|
352
|
-
enumerable: true,
|
|
353
|
-
get: function() {
|
|
354
|
-
return normalizeNestedSelectors;
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
Object.defineProperty(exports, "prepareStyleOptions", {
|
|
358
|
-
enumerable: true,
|
|
359
|
-
get: function() {
|
|
360
|
-
return prepareStyleOptions;
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
Object.defineProperty(exports, "transformCss", {
|
|
364
|
-
enumerable: true,
|
|
365
|
-
get: function() {
|
|
366
|
-
return transformCss;
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
Object.defineProperty(exports, "trimCombinators", {
|
|
370
|
-
enumerable: true,
|
|
371
|
-
get: function() {
|
|
372
|
-
return trimCombinators;
|
|
373
|
-
}
|
|
374
|
-
});
|
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
import { Buffer } from "node:buffer";
|
|
2
|
-
import { defuOverrideArray } from "@weapp-tailwindcss/shared";
|
|
3
|
-
import { transform } from "lightningcss";
|
|
4
|
-
import { createInjectPreflight, internalCssSelectorReplacer } from "@weapp-tailwindcss/postcss";
|
|
5
|
-
//#region src/lightningcss/options.ts
|
|
6
|
-
const FALLBACK_PLACEHOLDER_SUFFIXES = [":not(#n)", ":not(#\\#)"];
|
|
7
|
-
function normalizeSelectorList(value) {
|
|
8
|
-
if (value === void 0 || value === false) return [];
|
|
9
|
-
return Array.isArray(value) ? value.filter(Boolean) : [value];
|
|
10
|
-
}
|
|
11
|
-
function getSpecificityMatchingName(options) {
|
|
12
|
-
const feature = options.cssPresetEnv?.features?.["is-pseudo-class"];
|
|
13
|
-
if (feature && typeof feature === "object" && "specificityMatchingName" in feature) {
|
|
14
|
-
const specificityName = feature.specificityMatchingName;
|
|
15
|
-
return typeof specificityName === "string" && specificityName.length > 0 ? specificityName : void 0;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function createRootSpecificityReplacer(options) {
|
|
19
|
-
const specificityMatchingName = getSpecificityMatchingName(options);
|
|
20
|
-
const selectors = normalizeSelectorList(options.cssSelectorReplacement?.root);
|
|
21
|
-
const replaceFallbackPlaceholder = (code) => {
|
|
22
|
-
let output = code;
|
|
23
|
-
for (const suffix of FALLBACK_PLACEHOLDER_SUFFIXES) if (output.includes(suffix)) output = output.split(suffix).join("");
|
|
24
|
-
return output;
|
|
25
|
-
};
|
|
26
|
-
if (!specificityMatchingName || selectors.length === 0) return replaceFallbackPlaceholder;
|
|
27
|
-
const suffix = `:not(.${specificityMatchingName})`;
|
|
28
|
-
const targets = selectors.map((selector) => selector?.trim()).filter((selector) => Boolean(selector?.length)).map((selector) => ({
|
|
29
|
-
match: `${selector}${suffix}`,
|
|
30
|
-
spacedMatch: `${selector} ${suffix}`,
|
|
31
|
-
replacement: selector
|
|
32
|
-
}));
|
|
33
|
-
if (!targets.length) return;
|
|
34
|
-
return (code) => {
|
|
35
|
-
let output = replaceFallbackPlaceholder(code);
|
|
36
|
-
for (const target of targets) {
|
|
37
|
-
if (output.includes(target.match)) output = output.split(target.match).join(target.replacement);
|
|
38
|
-
if (output.includes(target.spacedMatch)) output = output.split(target.spacedMatch).join(target.replacement);
|
|
39
|
-
}
|
|
40
|
-
return output;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function getLightningDefaultOptions(options) {
|
|
44
|
-
const customPropertiesFeature = options?.cssPresetEnv?.features?.["custom-properties"];
|
|
45
|
-
return {
|
|
46
|
-
cssPresetEnv: {
|
|
47
|
-
features: {
|
|
48
|
-
"cascade-layers": true,
|
|
49
|
-
"is-pseudo-class": { specificityMatchingName: "weapp-tw-ig" },
|
|
50
|
-
"oklab-function": true,
|
|
51
|
-
"color-mix": true,
|
|
52
|
-
"custom-properties": customPropertiesFeature !== void 0 ? customPropertiesFeature : options?.cssCalc ? { preserve: true } : false
|
|
53
|
-
},
|
|
54
|
-
autoprefixer: { add: false }
|
|
55
|
-
},
|
|
56
|
-
cssRemoveProperty: true,
|
|
57
|
-
cssRemoveHoverPseudoClass: true,
|
|
58
|
-
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
59
|
-
cssSelectorReplacement: {
|
|
60
|
-
root: [
|
|
61
|
-
"page",
|
|
62
|
-
".tw-root",
|
|
63
|
-
"wx-root-portal-content"
|
|
64
|
-
],
|
|
65
|
-
universal: ["view", "text"]
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
function prepareStyleOptions(options) {
|
|
70
|
-
const merged = defuOverrideArray(options, getLightningDefaultOptions(options));
|
|
71
|
-
merged.cssInjectPreflight = createInjectPreflight(merged.cssPreflight);
|
|
72
|
-
return merged;
|
|
73
|
-
}
|
|
74
|
-
//#endregion
|
|
75
|
-
//#region src/lightningcss/selector-utils.ts
|
|
76
|
-
function createTypeSelector(name) {
|
|
77
|
-
return {
|
|
78
|
-
type: "type",
|
|
79
|
-
name
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function cloneComponent(value) {
|
|
83
|
-
const structured = globalThis.structuredClone;
|
|
84
|
-
if (typeof structured === "function") return structured(value);
|
|
85
|
-
return JSON.parse(JSON.stringify(value));
|
|
86
|
-
}
|
|
87
|
-
function cloneComponents(list) {
|
|
88
|
-
return list.map(cloneComponent);
|
|
89
|
-
}
|
|
90
|
-
function normalizeNestedSelectors(selectors) {
|
|
91
|
-
if (!selectors) return;
|
|
92
|
-
if (Array.isArray(selectors)) {
|
|
93
|
-
if (selectors.length === 0) return [];
|
|
94
|
-
const first = selectors[0];
|
|
95
|
-
if (Array.isArray(first)) return selectors;
|
|
96
|
-
return [selectors];
|
|
97
|
-
}
|
|
98
|
-
return [selectors];
|
|
99
|
-
}
|
|
100
|
-
function assignNestedSelectors(target, value) {
|
|
101
|
-
if (!("selectors" in target)) return;
|
|
102
|
-
if (Array.isArray(target.selectors)) target.selectors = value ?? [];
|
|
103
|
-
else if (target.selectors && !Array.isArray(target.selectors)) target.selectors = value?.[0] ?? target.selectors;
|
|
104
|
-
}
|
|
105
|
-
function trimCombinators(components) {
|
|
106
|
-
let start = 0;
|
|
107
|
-
let end = components.length;
|
|
108
|
-
while (start < end && components[start]?.type === "combinator") start++;
|
|
109
|
-
while (end > start && components[end - 1]?.type === "combinator") end--;
|
|
110
|
-
return components.slice(start, end);
|
|
111
|
-
}
|
|
112
|
-
function matchesHiddenNot(component) {
|
|
113
|
-
if (!component || component.type !== "pseudo-class" || component.kind !== "not") return false;
|
|
114
|
-
const selectors = normalizeNestedSelectors(component.selectors);
|
|
115
|
-
if (!selectors || selectors.length !== 1) return false;
|
|
116
|
-
const [nestedSelector] = selectors;
|
|
117
|
-
if (!nestedSelector || nestedSelector.length !== 1) return false;
|
|
118
|
-
const [node] = nestedSelector;
|
|
119
|
-
if (!node) return false;
|
|
120
|
-
return node.type === "attribute" && node.name === "hidden" || node.type === "type" && node.name === "template";
|
|
121
|
-
}
|
|
122
|
-
//#endregion
|
|
123
|
-
//#region src/lightningcss/selector-transform.ts
|
|
124
|
-
function buildSelectorReplacement(value) {
|
|
125
|
-
if (!value) return null;
|
|
126
|
-
const targets = Array.isArray(value) ? value : [value];
|
|
127
|
-
if (!targets.length) return null;
|
|
128
|
-
if (targets.length === 1) return [createTypeSelector(targets[0])];
|
|
129
|
-
return [{
|
|
130
|
-
type: "pseudo-class",
|
|
131
|
-
kind: "is",
|
|
132
|
-
selectors: targets.map((name) => [createTypeSelector(name)])
|
|
133
|
-
}];
|
|
134
|
-
}
|
|
135
|
-
function buildChildCombinatorReplacement(options) {
|
|
136
|
-
const { cssChildCombinatorReplaceValue } = options;
|
|
137
|
-
if (!cssChildCombinatorReplaceValue) return;
|
|
138
|
-
const normalized = Array.isArray(cssChildCombinatorReplaceValue) ? cssChildCombinatorReplaceValue : [cssChildCombinatorReplaceValue];
|
|
139
|
-
if (!normalized.length) return;
|
|
140
|
-
const baseComponents = buildSelectorReplacement(normalized) ?? [createTypeSelector("view")];
|
|
141
|
-
const left = cloneComponents(baseComponents);
|
|
142
|
-
const right = cloneComponents(baseComponents);
|
|
143
|
-
return [
|
|
144
|
-
...left,
|
|
145
|
-
{
|
|
146
|
-
type: "combinator",
|
|
147
|
-
value: "next-sibling"
|
|
148
|
-
},
|
|
149
|
-
...right
|
|
150
|
-
];
|
|
151
|
-
}
|
|
152
|
-
function transformSelectorComponent(component, ctx, transformList) {
|
|
153
|
-
const { options } = ctx;
|
|
154
|
-
if (component.type === "class") {
|
|
155
|
-
const cloned = cloneComponent(component);
|
|
156
|
-
cloned.name = internalCssSelectorReplacer(component.name, { escapeMap: options.escapeMap });
|
|
157
|
-
return [cloned];
|
|
158
|
-
}
|
|
159
|
-
if (component.type === "universal") {
|
|
160
|
-
const replacement = buildSelectorReplacement(options.cssSelectorReplacement?.universal);
|
|
161
|
-
if (replacement) return cloneComponents(replacement);
|
|
162
|
-
return [cloneComponent(component)];
|
|
163
|
-
}
|
|
164
|
-
if (component.type === "type") {
|
|
165
|
-
if (options.uniAppX) return [];
|
|
166
|
-
return [cloneComponent(component)];
|
|
167
|
-
}
|
|
168
|
-
if (component.type === "attribute") {
|
|
169
|
-
if (options.uniAppX) return [];
|
|
170
|
-
return [cloneComponent(component)];
|
|
171
|
-
}
|
|
172
|
-
if (component.type === "combinator") return [cloneComponent(component)];
|
|
173
|
-
if (component.type === "pseudo-element") return [cloneComponent(component)];
|
|
174
|
-
if (component.type === "pseudo-class") {
|
|
175
|
-
if (component.kind === "hover" && options.cssRemoveHoverPseudoClass) return null;
|
|
176
|
-
if (component.kind === "root") {
|
|
177
|
-
const replacement = buildSelectorReplacement(options.cssSelectorReplacement?.root);
|
|
178
|
-
if (replacement) return cloneComponents(replacement);
|
|
179
|
-
return [cloneComponent(component)];
|
|
180
|
-
}
|
|
181
|
-
const cloned = cloneComponent(component);
|
|
182
|
-
if ("selectors" in cloned) {
|
|
183
|
-
const nestedSelectors = normalizeNestedSelectors(cloned.selectors);
|
|
184
|
-
if (nestedSelectors) assignNestedSelectors(cloned, transformList(nestedSelectors, ctx));
|
|
185
|
-
}
|
|
186
|
-
if (cloned.kind === "where" && options.uniAppX) cloned.kind = "is";
|
|
187
|
-
return [cloned];
|
|
188
|
-
}
|
|
189
|
-
return [cloneComponent(component)];
|
|
190
|
-
}
|
|
191
|
-
function transformSelector(selector, ctx, transformList) {
|
|
192
|
-
const { childCombinatorReplacement } = ctx;
|
|
193
|
-
const output = [];
|
|
194
|
-
for (let index = 0; index < selector.length; index++) {
|
|
195
|
-
const component = selector[index];
|
|
196
|
-
if (!component) continue;
|
|
197
|
-
if (component.type === "combinator" && component.value === "child" && childCombinatorReplacement) {
|
|
198
|
-
const next = selector[index + 1];
|
|
199
|
-
const combinator = selector[index + 2];
|
|
200
|
-
const third = selector[index + 3];
|
|
201
|
-
if (matchesHiddenNot(next) && combinator?.type === "combinator" && (combinator.value === "next-sibling" || combinator.value === "later-sibling") && matchesHiddenNot(third)) {
|
|
202
|
-
output.push(cloneComponent(component));
|
|
203
|
-
output.push(...cloneComponents(childCombinatorReplacement));
|
|
204
|
-
index += 3;
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
const replaced = transformSelectorComponent(component, ctx, transformList);
|
|
209
|
-
if (replaced === null) return null;
|
|
210
|
-
output.push(...replaced);
|
|
211
|
-
}
|
|
212
|
-
const trimmed = trimCombinators(output);
|
|
213
|
-
return trimmed.length > 0 ? trimmed : null;
|
|
214
|
-
}
|
|
215
|
-
function transformSelectorList(selectors, ctx) {
|
|
216
|
-
const result = [];
|
|
217
|
-
for (const selector of selectors) {
|
|
218
|
-
const transformed = transformSelector(selector, ctx, transformSelectorList);
|
|
219
|
-
if (transformed && transformed.length > 0) result.push(transformed);
|
|
220
|
-
}
|
|
221
|
-
return result;
|
|
222
|
-
}
|
|
223
|
-
function createVisitor(ctx) {
|
|
224
|
-
return {
|
|
225
|
-
Rule(rule) {
|
|
226
|
-
if (rule.type === "property" && ctx.options.cssRemoveProperty) return [];
|
|
227
|
-
if (rule.type !== "style") return rule;
|
|
228
|
-
const styleRule = rule.value;
|
|
229
|
-
if (!styleRule.selectors) return rule;
|
|
230
|
-
const selectors = transformSelectorList(styleRule.selectors, ctx);
|
|
231
|
-
if (!selectors.length) return [];
|
|
232
|
-
styleRule.selectors = selectors;
|
|
233
|
-
return rule;
|
|
234
|
-
},
|
|
235
|
-
RuleExit(rule) {
|
|
236
|
-
if (rule.type !== "style") return rule;
|
|
237
|
-
const styleRule = rule.value;
|
|
238
|
-
const hasValidSelectors = (styleRule.selectors ?? []).some((selector) => selector.length > 0);
|
|
239
|
-
const declarationCount = styleRule.declarations?.declarations?.length ?? 0;
|
|
240
|
-
if (!hasValidSelectors || ctx.options.uniAppX && declarationCount === 0) return [];
|
|
241
|
-
return rule;
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
//#endregion
|
|
246
|
-
//#region src/lightningcss/index.ts
|
|
247
|
-
const textDecoder = new TextDecoder();
|
|
248
|
-
const defaultLightningFilename = "inline.css";
|
|
249
|
-
function omitUndefined(value) {
|
|
250
|
-
const result = {};
|
|
251
|
-
for (const [key, item] of Object.entries(value)) if (item !== void 0) result[key] = item;
|
|
252
|
-
return result;
|
|
253
|
-
}
|
|
254
|
-
function createPreparedRuntime(options) {
|
|
255
|
-
const resolvedOptions = prepareStyleOptions(options);
|
|
256
|
-
const ctx = omitUndefined({
|
|
257
|
-
options: resolvedOptions,
|
|
258
|
-
childCombinatorReplacement: buildChildCombinatorReplacement(resolvedOptions)
|
|
259
|
-
});
|
|
260
|
-
return omitUndefined({
|
|
261
|
-
options: resolvedOptions,
|
|
262
|
-
replaceSpecificity: createRootSpecificityReplacer(resolvedOptions),
|
|
263
|
-
visitor: createVisitor(ctx)
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
function createLightningcssStyleHandler(options, config = {}) {
|
|
267
|
-
const baseRuntime = createPreparedRuntime(options);
|
|
268
|
-
const { transformOptions, filename } = config;
|
|
269
|
-
const transformOverrides = transformOptions ?? {};
|
|
270
|
-
return async (rawSource, overrideOptions) => {
|
|
271
|
-
const runtime = !overrideOptions || Object.keys(overrideOptions).length === 0 ? baseRuntime : createPreparedRuntime(defuOverrideArray(overrideOptions, baseRuntime.options));
|
|
272
|
-
const lightningResult = transform(omitUndefined({
|
|
273
|
-
filename: filename ?? defaultLightningFilename,
|
|
274
|
-
code: Buffer.from(rawSource),
|
|
275
|
-
visitor: runtime.visitor,
|
|
276
|
-
minify: false,
|
|
277
|
-
...transformOverrides
|
|
278
|
-
}));
|
|
279
|
-
const decodedCode = textDecoder.decode(lightningResult.code);
|
|
280
|
-
return omitUndefined({
|
|
281
|
-
code: runtime.replaceSpecificity ? runtime.replaceSpecificity(decodedCode) : decodedCode,
|
|
282
|
-
map: lightningResult.map ? textDecoder.decode(lightningResult.map) : void 0,
|
|
283
|
-
warnings: lightningResult.warnings
|
|
284
|
-
});
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
const defaultHandler = createLightningcssStyleHandler(void 0, { transformOptions: { minify: true } });
|
|
288
|
-
async function transformCss(css = ".foo { color: red }") {
|
|
289
|
-
const result = await defaultHandler(typeof css === "string" ? css : css.toString());
|
|
290
|
-
return {
|
|
291
|
-
...result,
|
|
292
|
-
code: Buffer.from(result.code),
|
|
293
|
-
map: result.map ? Buffer.from(result.map) : void 0
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
//#endregion
|
|
297
|
-
export { assignNestedSelectors as a, createTypeSelector as c, trimCombinators as d, createRootSpecificityReplacer as f, createVisitor as i, matchesHiddenNot as l, transformCss as n, cloneComponent as o, prepareStyleOptions as p, buildChildCombinatorReplacement as r, cloneComponents as s, createLightningcssStyleHandler as t, normalizeNestedSelectors as u };
|