@empjs/plugin-lightningcss 1.0.3 → 1.0.5
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.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/loader.js +1 -0
- package/dist/plugin.js +7 -0
- package/dist/postcss-config.d.ts +25 -21
- package/dist/postcss-config.js +3 -19
- package/dist/px-to-base.d.ts +36 -0
- package/dist/{px-to-viewport.js → px-to-base.js} +26 -1
- package/package.json +1 -1
- package/dist/px-to-viewport.d.ts +0 -17
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/loader.js
CHANGED
package/dist/plugin.js
CHANGED
|
@@ -17,6 +17,13 @@ const uselightningcssLoader = async (store, o) => {
|
|
|
17
17
|
.loader(importResolve('./loader.cjs', import.meta.url))
|
|
18
18
|
.options(loaderOptions);
|
|
19
19
|
useLightningcss.before('postcss');
|
|
20
|
+
if (!['sass', 'less'].includes(ruleName)) {
|
|
21
|
+
useLightningcss.before('postcss');
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
useLightningcss.before(`${ruleName}Loader`);
|
|
25
|
+
}
|
|
26
|
+
// 删除后引起重排
|
|
20
27
|
rule.uses.delete('postcss');
|
|
21
28
|
}
|
|
22
29
|
};
|
package/dist/postcss-config.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Visitor } from 'lightningcss';
|
|
2
|
-
import type { vwOptions } from './px-to-
|
|
3
|
-
|
|
4
|
-
rootValue?: number;
|
|
5
|
-
};
|
|
2
|
+
import type { vwOptions, PxToRemOptions } from './px-to-base.js';
|
|
3
|
+
import { CustomAtRules } from 'lightningcss';
|
|
6
4
|
/**
|
|
7
5
|
* // 插件编写 https://github.com/parcel-bundler/lightningcss/blob/master/node/test/visitor.test.mjs
|
|
8
6
|
*/
|
|
@@ -10,73 +8,79 @@ declare class PostcssConfig {
|
|
|
10
8
|
/**
|
|
11
9
|
* https://github.com/cuth/postcss-pxtorem
|
|
12
10
|
*/
|
|
13
|
-
px_to_rem(op
|
|
11
|
+
px_to_rem(op: PxToRemOptions): {
|
|
12
|
+
Selector(selectors: import("lightningcss").Selector): void;
|
|
13
|
+
Length(length: import("lightningcss").LengthValue): {
|
|
14
|
+
unit: "rem";
|
|
15
|
+
value: number;
|
|
16
|
+
} | undefined;
|
|
17
|
+
};
|
|
14
18
|
/**
|
|
15
19
|
* https://github.com/evrone/postcss-px-to-viewport
|
|
16
20
|
*/
|
|
17
|
-
px_to_viewport(op: vwOptions): Visitor<
|
|
21
|
+
px_to_viewport(op: vwOptions): Visitor<CustomAtRules>;
|
|
18
22
|
/**
|
|
19
23
|
* https://www.npmjs.com/package/postcss-apply
|
|
20
24
|
*/
|
|
21
|
-
apply(defined: Map<any, any>): Visitor<
|
|
25
|
+
apply(defined: Map<any, any>): Visitor<CustomAtRules>;
|
|
22
26
|
/**
|
|
23
27
|
* https://www.npmjs.com/package/postcss-prefix-selector
|
|
24
28
|
*/
|
|
25
|
-
selector_prefix(): Visitor<
|
|
29
|
+
selector_prefix(): Visitor<CustomAtRules>;
|
|
26
30
|
/**
|
|
27
31
|
* https://www.npmjs.com/package/postcss-simple-vars
|
|
28
32
|
*/
|
|
29
|
-
static_vars(declared: Map<any, any>): Visitor<
|
|
33
|
+
static_vars(declared: Map<any, any>): Visitor<CustomAtRules>;
|
|
30
34
|
/**
|
|
31
35
|
* https://www.npmjs.com/package/postcss-url
|
|
32
36
|
*/
|
|
33
|
-
url(hostUrl: string): Visitor<
|
|
37
|
+
url(hostUrl: string): Visitor<CustomAtRules>;
|
|
34
38
|
/**
|
|
35
39
|
* https://www.npmjs.com/package/postcss-env-function
|
|
36
40
|
*/
|
|
37
41
|
specific_environment_variables(tokens: {
|
|
38
42
|
[k: string]: any;
|
|
39
|
-
}): Visitor<
|
|
43
|
+
}): Visitor<CustomAtRules>;
|
|
40
44
|
/**
|
|
41
45
|
* https://www.npmjs.com/package/postcss-env-function
|
|
42
46
|
*/
|
|
43
|
-
env_function(tokens: any): Visitor<
|
|
47
|
+
env_function(tokens: any): Visitor<CustomAtRules>;
|
|
44
48
|
/**
|
|
45
49
|
* https://www.npmjs.com/package/@csstools/postcss-design-tokens
|
|
46
50
|
*/
|
|
47
|
-
design_tokens(tokens: any): Visitor<
|
|
51
|
+
design_tokens(tokens: any): Visitor<CustomAtRules>;
|
|
48
52
|
/**
|
|
49
53
|
* https://github.com/csstools/custom-units
|
|
50
54
|
*/
|
|
51
|
-
custom_units(): Visitor<
|
|
55
|
+
custom_units(): Visitor<CustomAtRules>;
|
|
52
56
|
/**
|
|
53
57
|
* https://www.npmjs.com/package/postcss-property-lookup
|
|
54
58
|
*/
|
|
55
|
-
property_lookup(): Visitor<
|
|
59
|
+
property_lookup(): Visitor<CustomAtRules>;
|
|
56
60
|
/**
|
|
57
61
|
* https://www.npmjs.com/package/postcss-focus-visible
|
|
58
62
|
*/
|
|
59
|
-
focus_visible(): Visitor<
|
|
63
|
+
focus_visible(): Visitor<CustomAtRules>;
|
|
60
64
|
/**
|
|
61
65
|
* https://github.com/postcss/postcss-dark-theme-class
|
|
62
66
|
*/
|
|
63
|
-
dark_theme_class(): Visitor<
|
|
67
|
+
dark_theme_class(): Visitor<CustomAtRules>;
|
|
64
68
|
/**
|
|
65
69
|
* https://github.com/postcss/postcss-100vh-fix
|
|
66
70
|
*/
|
|
67
|
-
fix_100vh(): Visitor<
|
|
71
|
+
fix_100vh(): Visitor<CustomAtRules>;
|
|
68
72
|
/**
|
|
69
73
|
* https://github.com/MohammadYounes/rtlcss
|
|
70
74
|
*/
|
|
71
|
-
logical_transforms(): Visitor<
|
|
75
|
+
logical_transforms(): Visitor<CustomAtRules>;
|
|
72
76
|
/**
|
|
73
77
|
* https://github.com/twbs/mq4-hover-shim
|
|
74
78
|
*/
|
|
75
|
-
hover_media_query(): Visitor<
|
|
79
|
+
hover_media_query(): Visitor<CustomAtRules>;
|
|
76
80
|
/**
|
|
77
81
|
* https://github.com/yunusga/postcss-momentum-scrolling
|
|
78
82
|
*/
|
|
79
|
-
momentum_scrolling(visitOverflow: any): Visitor<
|
|
83
|
+
momentum_scrolling(visitOverflow: any): Visitor<CustomAtRules>;
|
|
80
84
|
/**
|
|
81
85
|
* https://github.com/postcss/postcss-size
|
|
82
86
|
*/
|
package/dist/postcss-config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createPxToVwVisitor } from './px-to-
|
|
1
|
+
import { createPxToVwVisitor, createPxToRemVisitor } from './px-to-base.js';
|
|
2
2
|
import { composeVisitors } from 'lightningcss';
|
|
3
3
|
/**
|
|
4
4
|
* // 插件编写 https://github.com/parcel-bundler/lightningcss/blob/master/node/test/visitor.test.mjs
|
|
@@ -7,29 +7,13 @@ class PostcssConfig {
|
|
|
7
7
|
/**
|
|
8
8
|
* https://github.com/cuth/postcss-pxtorem
|
|
9
9
|
*/
|
|
10
|
-
px_to_rem(op
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
Length(length) {
|
|
14
|
-
if (length.unit === 'px') {
|
|
15
|
-
return {
|
|
16
|
-
unit: 'rem',
|
|
17
|
-
value: length.value / rv,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
};
|
|
10
|
+
px_to_rem(op) {
|
|
11
|
+
return createPxToRemVisitor(op);
|
|
22
12
|
}
|
|
23
13
|
/**
|
|
24
14
|
* https://github.com/evrone/postcss-px-to-viewport
|
|
25
15
|
*/
|
|
26
16
|
px_to_viewport(op) {
|
|
27
|
-
op = op
|
|
28
|
-
? op
|
|
29
|
-
: {
|
|
30
|
-
designWidth: 320,
|
|
31
|
-
minPixelValue: 1,
|
|
32
|
-
};
|
|
33
17
|
return composeVisitors([createPxToVwVisitor(op)]);
|
|
34
18
|
}
|
|
35
19
|
/**
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
designWidth: number;
|
|
3
|
+
minPixelValue: number;
|
|
4
|
+
excludeSelectors: {
|
|
5
|
+
type: string;
|
|
6
|
+
name: RegExp | string;
|
|
7
|
+
}[];
|
|
8
|
+
}
|
|
9
|
+
export declare function createExcludeFilter(excludes: Options['excludeSelectors']): (testItem: {
|
|
10
|
+
type: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
}) => boolean;
|
|
13
|
+
export type vwOptions = Partial<Options>;
|
|
14
|
+
export declare function createPxToVwVisitor(userOptions?: vwOptions): {
|
|
15
|
+
Selector(selectors: import("lightningcss").Selector): void;
|
|
16
|
+
Length(length: import("lightningcss").LengthValue): {
|
|
17
|
+
unit: "vw";
|
|
18
|
+
value: number;
|
|
19
|
+
} | undefined;
|
|
20
|
+
};
|
|
21
|
+
export type PxToRemOptions = {
|
|
22
|
+
rootValue?: number;
|
|
23
|
+
minPixelValue?: number;
|
|
24
|
+
excludeSelectors?: {
|
|
25
|
+
type: string;
|
|
26
|
+
name: RegExp | string;
|
|
27
|
+
}[];
|
|
28
|
+
};
|
|
29
|
+
export declare function createPxToRemVisitor(options?: PxToRemOptions): {
|
|
30
|
+
Selector(selectors: import("lightningcss").Selector): void;
|
|
31
|
+
Length(length: import("lightningcss").LengthValue): {
|
|
32
|
+
unit: "rem";
|
|
33
|
+
value: number;
|
|
34
|
+
} | undefined;
|
|
35
|
+
};
|
|
36
|
+
export {};
|
|
@@ -3,7 +3,7 @@ const baseOptions = {
|
|
|
3
3
|
minPixelValue: 1,
|
|
4
4
|
excludeSelectors: [],
|
|
5
5
|
};
|
|
6
|
-
function createExcludeFilter(excludes) {
|
|
6
|
+
export function createExcludeFilter(excludes) {
|
|
7
7
|
const isExclude = (testItem) => {
|
|
8
8
|
if (!testItem.name) {
|
|
9
9
|
return false;
|
|
@@ -47,3 +47,28 @@ export function createPxToVwVisitor(userOptions = {}) {
|
|
|
47
47
|
},
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
+
export function createPxToRemVisitor(options = {}) {
|
|
51
|
+
const op = Object.assign({ rootValue: 16, excludeSelectors: [], minPixelValue: 1 }, options);
|
|
52
|
+
const isExclude = createExcludeFilter(op.excludeSelectors);
|
|
53
|
+
let skipCurrentSelector = false;
|
|
54
|
+
return {
|
|
55
|
+
Selector(selectors) {
|
|
56
|
+
skipCurrentSelector = false;
|
|
57
|
+
for (const selector of selectors) {
|
|
58
|
+
if (isExclude(selector)) {
|
|
59
|
+
skipCurrentSelector = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
Length(length) {
|
|
64
|
+
if (length.unit === 'px' && !skipCurrentSelector) {
|
|
65
|
+
if (length.value > op.minPixelValue) {
|
|
66
|
+
return {
|
|
67
|
+
unit: 'rem',
|
|
68
|
+
value: length.value / op.rootValue,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
package/package.json
CHANGED
package/dist/px-to-viewport.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
interface Options {
|
|
2
|
-
designWidth: number;
|
|
3
|
-
minPixelValue: number;
|
|
4
|
-
excludeSelectors: {
|
|
5
|
-
type: string;
|
|
6
|
-
name: RegExp | string;
|
|
7
|
-
}[];
|
|
8
|
-
}
|
|
9
|
-
export type vwOptions = Partial<Options>;
|
|
10
|
-
export declare function createPxToVwVisitor(userOptions?: vwOptions): {
|
|
11
|
-
Selector(selectors: import("lightningcss").Selector): void;
|
|
12
|
-
Length(length: import("lightningcss").LengthValue): {
|
|
13
|
-
unit: "vw";
|
|
14
|
-
value: number;
|
|
15
|
-
} | undefined;
|
|
16
|
-
};
|
|
17
|
-
export {};
|