@weapp-tailwindcss/postcss 1.0.0-alpha.8 → 1.0.0

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.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-CDLWJcpu.mjs';
2
- export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions, c as createInjectPreflight } from './types-CDLWJcpu.mjs';
1
+ import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-DiXihH4o.mjs';
2
+ export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions, c as createInjectPreflight } from './types-DiXihH4o.mjs';
3
3
  import postcss from 'postcss';
4
4
  import '@weapp-tailwindcss/mangle';
5
5
  import 'postcss-load-config';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-CDLWJcpu.js';
2
- export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions, c as createInjectPreflight } from './types-CDLWJcpu.js';
1
+ import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-DiXihH4o.js';
2
+ export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions, c as createInjectPreflight } from './types-DiXihH4o.js';
3
3
  import postcss from 'postcss';
4
4
  import '@weapp-tailwindcss/mangle';
5
5
  import 'postcss-load-config';
package/dist/index.js CHANGED
@@ -901,6 +901,25 @@ function getPlugins(options) {
901
901
  return plugins;
902
902
  }
903
903
 
904
+ // src/preflight.ts
905
+ function createInjectPreflight(options) {
906
+ const result = [];
907
+ if (options && typeof options === "object") {
908
+ const entries = Object.entries(options);
909
+ for (const [prop, value] of entries) {
910
+ if (value !== false) {
911
+ result.push({
912
+ prop,
913
+ value: value.toString()
914
+ });
915
+ }
916
+ }
917
+ }
918
+ return () => {
919
+ return result;
920
+ };
921
+ }
922
+
904
923
  // src/handler.ts
905
924
  function styleHandler(rawSource, options) {
906
925
  return _postcss2.default.call(void 0,
@@ -917,6 +936,7 @@ function createStyleHandler(options) {
917
936
  options,
918
937
  getDefaultOptions()
919
938
  );
939
+ cachedOptions.cssInjectPreflight = createInjectPreflight(cachedOptions.cssPreflight);
920
940
  return (rawSource, opt) => {
921
941
  return styleHandler(
922
942
  rawSource,
@@ -925,25 +945,6 @@ function createStyleHandler(options) {
925
945
  };
926
946
  }
927
947
 
928
- // src/preflight.ts
929
- function createInjectPreflight(options) {
930
- const result = [];
931
- if (options && typeof options === "object") {
932
- const entries = Object.entries(options);
933
- for (const [prop, value] of entries) {
934
- if (value !== false) {
935
- result.push({
936
- prop,
937
- value: value.toString()
938
- });
939
- }
940
- }
941
- }
942
- return () => {
943
- return result;
944
- };
945
- }
946
-
947
948
 
948
949
 
949
950
 
package/dist/index.mjs CHANGED
@@ -901,6 +901,25 @@ function getPlugins(options) {
901
901
  return plugins;
902
902
  }
903
903
 
904
+ // src/preflight.ts
905
+ function createInjectPreflight(options) {
906
+ const result = [];
907
+ if (options && typeof options === "object") {
908
+ const entries = Object.entries(options);
909
+ for (const [prop, value] of entries) {
910
+ if (value !== false) {
911
+ result.push({
912
+ prop,
913
+ value: value.toString()
914
+ });
915
+ }
916
+ }
917
+ }
918
+ return () => {
919
+ return result;
920
+ };
921
+ }
922
+
904
923
  // src/handler.ts
905
924
  function styleHandler(rawSource, options) {
906
925
  return postcss(
@@ -917,6 +936,7 @@ function createStyleHandler(options) {
917
936
  options,
918
937
  getDefaultOptions()
919
938
  );
939
+ cachedOptions.cssInjectPreflight = createInjectPreflight(cachedOptions.cssPreflight);
920
940
  return (rawSource, opt) => {
921
941
  return styleHandler(
922
942
  rawSource,
@@ -924,25 +944,6 @@ function createStyleHandler(options) {
924
944
  );
925
945
  };
926
946
  }
927
-
928
- // src/preflight.ts
929
- function createInjectPreflight(options) {
930
- const result = [];
931
- if (options && typeof options === "object") {
932
- const entries = Object.entries(options);
933
- for (const [prop, value] of entries) {
934
- if (value !== false) {
935
- result.push({
936
- prop,
937
- value: value.toString()
938
- });
939
- }
940
- }
941
- }
942
- return () => {
943
- return result;
944
- };
945
- }
946
947
  export {
947
948
  createInjectPreflight,
948
949
  createStyleHandler,
@@ -0,0 +1,63 @@
1
+ import { IMangleScopeContext } from '@weapp-tailwindcss/mangle';
2
+ import { Rule } from 'postcss';
3
+ import { Result } from 'postcss-load-config';
4
+ import { pluginOptions } from 'postcss-preset-env';
5
+ import { UserDefinedOptions } from 'postcss-rem-to-responsive-pixel';
6
+
7
+ declare function createContext(): {
8
+ variablesScopeWeakMap: WeakMap<WeakKey, any>;
9
+ isVariablesScope: (rule: WeakKey) => boolean;
10
+ markVariablesScope: (rule: WeakKey) => void;
11
+ };
12
+ type IContext = ReturnType<typeof createContext>;
13
+
14
+ type InjectPreflight = () => IPropValue[];
15
+ declare function createInjectPreflight(options?: CssPreflightOptions): InjectPreflight;
16
+
17
+ type LoadedPostcssOptions = Partial<Omit<Result, 'file'>>;
18
+ type CustomRuleCallback = (node: Rule, options: Readonly<UserDefinedPostcssOptions>) => void;
19
+ interface IPropValue {
20
+ prop: string;
21
+ value: string;
22
+ }
23
+ type CssPreflightOptions = {
24
+ [key: string]: string | number | boolean;
25
+ } | false;
26
+ type RequiredStyleHandlerOptions = {
27
+ /**
28
+ * @description 默认为 true,此时会对样式主文件,进行猜测
29
+ */
30
+ isMainChunk?: boolean;
31
+ cssPreflight?: CssPreflightOptions;
32
+ cssInjectPreflight?: InjectPreflight;
33
+ escapeMap?: Record<string, string>;
34
+ } & Pick<UserDefinedPostcssOptions, 'cssPreflightRange' | 'cssChildCombinatorReplaceValue' | 'injectAdditionalCssVarScope' | 'cssSelectorReplacement' | 'rem2rpx'>;
35
+ interface InternalCssSelectorReplacerOptions {
36
+ mangleContext?: IMangleScopeContext;
37
+ escapeMap?: Record<string, string>;
38
+ }
39
+ type IStyleHandlerOptions = {
40
+ customRuleCallback?: CustomRuleCallback;
41
+ mangleContext?: IMangleScopeContext;
42
+ ctx?: IContext;
43
+ postcssOptions?: LoadedPostcssOptions;
44
+ cssRemoveHoverPseudoClass?: boolean;
45
+ cssPresetEnv?: pluginOptions;
46
+ } & RequiredStyleHandlerOptions;
47
+ interface UserDefinedPostcssOptions {
48
+ cssPreflight?: CssPreflightOptions;
49
+ cssPreflightRange?: 'all';
50
+ cssChildCombinatorReplaceValue?: string | string[];
51
+ cssPresetEnv?: pluginOptions;
52
+ injectAdditionalCssVarScope?: boolean;
53
+ cssSelectorReplacement?: {
54
+ root?: string | string[] | false;
55
+ universal?: string | string[] | false;
56
+ };
57
+ rem2rpx?: boolean | UserDefinedOptions;
58
+ postcssOptions?: LoadedPostcssOptions;
59
+ cssRemoveHoverPseudoClass?: boolean;
60
+ customRuleCallback?: CustomRuleCallback;
61
+ }
62
+
63
+ export { type CustomRuleCallback as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type RequiredStyleHandlerOptions as R, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type IPropValue as b, createInjectPreflight as c, type CssPreflightOptions as d };
@@ -0,0 +1,63 @@
1
+ import { IMangleScopeContext } from '@weapp-tailwindcss/mangle';
2
+ import { Rule } from 'postcss';
3
+ import { Result } from 'postcss-load-config';
4
+ import { pluginOptions } from 'postcss-preset-env';
5
+ import { UserDefinedOptions } from 'postcss-rem-to-responsive-pixel';
6
+
7
+ declare function createContext(): {
8
+ variablesScopeWeakMap: WeakMap<WeakKey, any>;
9
+ isVariablesScope: (rule: WeakKey) => boolean;
10
+ markVariablesScope: (rule: WeakKey) => void;
11
+ };
12
+ type IContext = ReturnType<typeof createContext>;
13
+
14
+ type InjectPreflight = () => IPropValue[];
15
+ declare function createInjectPreflight(options?: CssPreflightOptions): InjectPreflight;
16
+
17
+ type LoadedPostcssOptions = Partial<Omit<Result, 'file'>>;
18
+ type CustomRuleCallback = (node: Rule, options: Readonly<UserDefinedPostcssOptions>) => void;
19
+ interface IPropValue {
20
+ prop: string;
21
+ value: string;
22
+ }
23
+ type CssPreflightOptions = {
24
+ [key: string]: string | number | boolean;
25
+ } | false;
26
+ type RequiredStyleHandlerOptions = {
27
+ /**
28
+ * @description 默认为 true,此时会对样式主文件,进行猜测
29
+ */
30
+ isMainChunk?: boolean;
31
+ cssPreflight?: CssPreflightOptions;
32
+ cssInjectPreflight?: InjectPreflight;
33
+ escapeMap?: Record<string, string>;
34
+ } & Pick<UserDefinedPostcssOptions, 'cssPreflightRange' | 'cssChildCombinatorReplaceValue' | 'injectAdditionalCssVarScope' | 'cssSelectorReplacement' | 'rem2rpx'>;
35
+ interface InternalCssSelectorReplacerOptions {
36
+ mangleContext?: IMangleScopeContext;
37
+ escapeMap?: Record<string, string>;
38
+ }
39
+ type IStyleHandlerOptions = {
40
+ customRuleCallback?: CustomRuleCallback;
41
+ mangleContext?: IMangleScopeContext;
42
+ ctx?: IContext;
43
+ postcssOptions?: LoadedPostcssOptions;
44
+ cssRemoveHoverPseudoClass?: boolean;
45
+ cssPresetEnv?: pluginOptions;
46
+ } & RequiredStyleHandlerOptions;
47
+ interface UserDefinedPostcssOptions {
48
+ cssPreflight?: CssPreflightOptions;
49
+ cssPreflightRange?: 'all';
50
+ cssChildCombinatorReplaceValue?: string | string[];
51
+ cssPresetEnv?: pluginOptions;
52
+ injectAdditionalCssVarScope?: boolean;
53
+ cssSelectorReplacement?: {
54
+ root?: string | string[] | false;
55
+ universal?: string | string[] | false;
56
+ };
57
+ rem2rpx?: boolean | UserDefinedOptions;
58
+ postcssOptions?: LoadedPostcssOptions;
59
+ cssRemoveHoverPseudoClass?: boolean;
60
+ customRuleCallback?: CustomRuleCallback;
61
+ }
62
+
63
+ export { type CustomRuleCallback as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type RequiredStyleHandlerOptions as R, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type IPropValue as b, createInjectPreflight as c, type CssPreflightOptions as d };
package/dist/types.d.mts CHANGED
@@ -3,4 +3,4 @@ import 'postcss';
3
3
  import 'postcss-load-config';
4
4
  import 'postcss-preset-env';
5
5
  import 'postcss-rem-to-responsive-pixel';
6
- export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions } from './types-CDLWJcpu.mjs';
6
+ export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions } from './types-DiXihH4o.mjs';
package/dist/types.d.ts CHANGED
@@ -3,4 +3,4 @@ import 'postcss';
3
3
  import 'postcss-load-config';
4
4
  import 'postcss-preset-env';
5
5
  import 'postcss-rem-to-responsive-pixel';
6
- export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions } from './types-CDLWJcpu.js';
6
+ export { d as CssPreflightOptions, C as CustomRuleCallback, b as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions } from './types-DiXihH4o.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/postcss",
3
- "version": "1.0.0-alpha.8",
3
+ "version": "1.0.0",
4
4
  "description": "@weapp-tailwindcss/postcss",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -38,10 +38,10 @@
38
38
  "postcss-preset-env": "^10.1.3",
39
39
  "postcss-rem-to-responsive-pixel": "~6.0.2",
40
40
  "postcss-selector-parser": "~7.1.0",
41
- "@weapp-tailwindcss/shared": "1.0.0-alpha.4"
41
+ "@weapp-tailwindcss/shared": "1.0.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@weapp-tailwindcss/mangle": "1.0.0-alpha.5"
44
+ "@weapp-tailwindcss/mangle": "1.0.0"
45
45
  },
46
46
  "scripts": {
47
47
  "dev": "tsup --watch --sourcemap",
@@ -1,185 +0,0 @@
1
- import { IMangleScopeContext } from '@weapp-tailwindcss/mangle';
2
- import { Rule } from 'postcss';
3
- import { Result } from 'postcss-load-config';
4
- import { pluginOptions } from 'postcss-preset-env';
5
- import { UserDefinedOptions } from 'postcss-rem-to-responsive-pixel';
6
-
7
- declare function createContext(): {
8
- variablesScopeWeakMap: WeakMap<WeakKey, any>;
9
- isVariablesScope: (rule: WeakKey) => boolean;
10
- markVariablesScope: (rule: WeakKey) => void;
11
- };
12
- type IContext = ReturnType<typeof createContext>;
13
-
14
- type InjectPreflight = () => IPropValue[];
15
- declare function createInjectPreflight(options?: CssPreflightOptions): InjectPreflight;
16
-
17
- type LoadedPostcssOptions = Partial<Omit<Result, 'file'>>;
18
- type CustomRuleCallback = (node: Rule, options: Readonly<UserDefinedPostcssOptions>) => void;
19
- interface IPropValue {
20
- prop: string;
21
- value: string;
22
- }
23
- type CssPreflightOptions = {
24
- [key: string]: string | number | boolean;
25
- } | false;
26
- type RequiredStyleHandlerOptions = {
27
- /**
28
- * @description 默认为 true,此时会对样式主文件,进行猜测
29
- */
30
- isMainChunk?: boolean;
31
- cssInjectPreflight?: InjectPreflight;
32
- escapeMap?: Record<string, string>;
33
- } & Pick<UserDefinedPostcssOptions, 'cssPreflightRange' | 'cssChildCombinatorReplaceValue' | 'injectAdditionalCssVarScope' | 'cssSelectorReplacement' | 'rem2rpx'>;
34
- interface InternalCssSelectorReplacerOptions {
35
- mangleContext?: IMangleScopeContext;
36
- escapeMap?: Record<string, string>;
37
- }
38
- type IStyleHandlerOptions = {
39
- customRuleCallback?: CustomRuleCallback;
40
- mangleContext?: IMangleScopeContext;
41
- ctx?: IContext;
42
- postcssOptions?: LoadedPostcssOptions;
43
- cssRemoveHoverPseudoClass?: boolean;
44
- cssPresetEnv?: pluginOptions;
45
- } & RequiredStyleHandlerOptions;
46
- interface UserDefinedPostcssOptions {
47
- /**
48
- * @group 0.重要配置
49
- * @issue https://github.com/sonofmagic/weapp-tailwindcss/issues/7
50
- * @description 在所有 view节点添加的 css 预设,可根据情况自由的禁用原先的规则,或者添加新的规则。默认预置 `css` 同 `tailwindcss` 类似,详细用法如下:
51
- * ```js
52
- * // default 默认,这代表会添加给所有的 view / text 元素, 受到 cssPreflightRange 配置项影响 :
53
- cssPreflight: {
54
- 'box-sizing': 'border-box',
55
- 'border-width': '0',
56
- 'border-style': 'solid',
57
- 'border-color': 'currentColor'
58
- }
59
- // result
60
- // box-sizing: border-box;
61
- // border-width: 0;
62
- // border-style: solid;
63
- // border-color: currentColor
64
-
65
- // case 禁用所有
66
- cssPreflight: false
67
- // result
68
- // none
69
-
70
- // case 禁用单个属性
71
- cssPreflight: {
72
- 'box-sizing': false
73
- }
74
- // border-width: 0;
75
- // border-style: solid;
76
- // border-color: currentColor
77
-
78
- // case 更改和添加单个属性
79
- cssPreflight: {
80
- 'box-sizing': 'content-box',
81
- 'background': 'black'
82
- }
83
- // result
84
- // box-sizing: content-box;
85
- // border-width: 0;
86
- // border-style: solid;
87
- // border-color: currentColor;
88
- // background: black
89
- * ```
90
- */
91
- cssPreflight?: CssPreflightOptions;
92
- /**
93
- * @group 0.重要配置
94
- * @issue https://github.com/sonofmagic/weapp-tailwindcss/pull/62
95
- * @description 全局`dom`选择器,只有在这个选择器作用范围内的`dom`会被注入 `cssPreflight` 的变量和默认样式。只对所有的 `view`,`text` 和伪元素生效,想要对所有的元素生效,可切换为 `'all'`,此时需要自行处理和客户端默认样式的冲突
96
- */
97
- cssPreflightRange?: 'all';
98
- /**
99
- * @group 3.一般配置
100
- * @description 用于控制 tailwindcss 子组合器的生效标签范围, 这里我们用一个例子来说明这个配置是干啥用的.
101
- *
102
- * 我们布局的时候往往会使用 `space-x-4`
103
- * 那么实际上会生成这样的css选择器:
104
- * ```css
105
- * .space-x-4>:not([hidden])~:not([hidden]){}
106
- * ```
107
- * 然而很不幸,这个选择器在小程序中是不支持的,写了会报错导致编译失败。
108
- * 所以出于保守起见,我把它替换为了:
109
- * ```css
110
- * .space-x-4>view + view{}
111
- * ```
112
- * 这同时也是默认值, 而这个选项就允许你进行自定义子组合器的行为
113
- *
114
- * 你可以传入一个 字符串,或者字符串数组
115
- * 1. 传入字符串数组,比如 `['view','text']` 生成:
116
- * ```css
117
- * .space-y-4>view + view,text + text{}
118
- * ```
119
- *
120
- * 2. 传入一个字符串,此时行为变成了整个替换,比如 `'view,text,button,input ~ view,text,button,input'` 生成:
121
- * ```css
122
- * .space-y-4>view,text,button,input ~ view,text,button,input{}
123
- * ```
124
- * @default 'view + view'
125
- */
126
- cssChildCombinatorReplaceValue?: string | string[];
127
- /**
128
- * @group 0.重要配置
129
- * @version `^2.6.0`
130
- * @description 是否注入额外的 `tailwindcss css var scope` 区域,这个选项用于这样的场景
131
- *
132
- * 比如 `taro vue3` 使用 [NutUI](https://nutui.jd.com), 需要使用 `@tarojs/plugin-html`,而这个插件会启用 `postcss-html-transform` 从而移除所有带 `*` 选择器
133
- *
134
- * 这会导致 `tailwindcss css var scope` 区域被移除导致一些样式,比如渐变等等功能失效
135
- *
136
- * 这种场景下,启用这个选项会再次重新注入整个 `tailwindcss css var scope`
137
- *
138
- * @default false
139
- */
140
- injectAdditionalCssVarScope?: boolean;
141
- /**
142
- * @group 0.重要配置
143
- * @description 用于处理 css 选择器的替换规则
144
- */
145
- cssSelectorReplacement?: {
146
- /**
147
- * @default `'page'` <br/>
148
- * @description 把`css`中的全局选择器 **`:root`** 替换为指定值,默认替换为 `'page'`,设置为 `false` 时不进行替换
149
- */
150
- root?: string | string[] | false;
151
- /**
152
- * @issue https://github.com/sonofmagic/weapp-tailwindcss/issues/81 <br/>
153
- * @default `['view','text']` <br/>
154
- * @description 把`css`中的全局选择器 **`*`** 替换为指定值,默认替换为 `'view','text'`,设置为 `false` 时不进行替换,此时小程序会由于不认识`*`选择器而报错
155
- */
156
- universal?: string | string[] | false;
157
- };
158
- /**
159
- * @version `^3.0.0`
160
- * @group 0.重要配置
161
- * @description rem 转 rpx 配置,默认为 `undefined` 不开启,可传入 `true` 启用默认配置项,也可传入自定义配置项,配置项列表见 [postcss-rem-to-responsive-pixel](https://www.npmjs.com/package/postcss-rem-to-responsive-pixel)
162
- */
163
- rem2rpx?: boolean | UserDefinedOptions;
164
- /**
165
- * @version `^3.2.0`
166
- * @group 3.一般配置
167
- * @description 对解析 css 使用的 `postcss` 工具的配置
168
- */
169
- postcssOptions?: LoadedPostcssOptions;
170
- /**
171
- * @version `^3.2.1`
172
- * @group 3.一般配置
173
- * @issue https://github.com/sonofmagic/weapp-tailwindcss/issues/293
174
- * @default `true`
175
- * @description 是否删除 css :hover 选择器节点,默认为 `true`, 原因在于,小程序 css :hover 是不生效的,要使用 view 这种标签的 hover-class 属性
176
- */
177
- cssRemoveHoverPseudoClass?: boolean;
178
- /**
179
- * @group 3.一般配置
180
- * @description 用于自定义处理 css 的回调函数,可根据 Postcss walk 方法自由定制处理方案的 callback 方法
181
- */
182
- customRuleCallback?: CustomRuleCallback;
183
- }
184
-
185
- export { type CustomRuleCallback as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type RequiredStyleHandlerOptions as R, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type IPropValue as b, createInjectPreflight as c, type CssPreflightOptions as d };
@@ -1,185 +0,0 @@
1
- import { IMangleScopeContext } from '@weapp-tailwindcss/mangle';
2
- import { Rule } from 'postcss';
3
- import { Result } from 'postcss-load-config';
4
- import { pluginOptions } from 'postcss-preset-env';
5
- import { UserDefinedOptions } from 'postcss-rem-to-responsive-pixel';
6
-
7
- declare function createContext(): {
8
- variablesScopeWeakMap: WeakMap<WeakKey, any>;
9
- isVariablesScope: (rule: WeakKey) => boolean;
10
- markVariablesScope: (rule: WeakKey) => void;
11
- };
12
- type IContext = ReturnType<typeof createContext>;
13
-
14
- type InjectPreflight = () => IPropValue[];
15
- declare function createInjectPreflight(options?: CssPreflightOptions): InjectPreflight;
16
-
17
- type LoadedPostcssOptions = Partial<Omit<Result, 'file'>>;
18
- type CustomRuleCallback = (node: Rule, options: Readonly<UserDefinedPostcssOptions>) => void;
19
- interface IPropValue {
20
- prop: string;
21
- value: string;
22
- }
23
- type CssPreflightOptions = {
24
- [key: string]: string | number | boolean;
25
- } | false;
26
- type RequiredStyleHandlerOptions = {
27
- /**
28
- * @description 默认为 true,此时会对样式主文件,进行猜测
29
- */
30
- isMainChunk?: boolean;
31
- cssInjectPreflight?: InjectPreflight;
32
- escapeMap?: Record<string, string>;
33
- } & Pick<UserDefinedPostcssOptions, 'cssPreflightRange' | 'cssChildCombinatorReplaceValue' | 'injectAdditionalCssVarScope' | 'cssSelectorReplacement' | 'rem2rpx'>;
34
- interface InternalCssSelectorReplacerOptions {
35
- mangleContext?: IMangleScopeContext;
36
- escapeMap?: Record<string, string>;
37
- }
38
- type IStyleHandlerOptions = {
39
- customRuleCallback?: CustomRuleCallback;
40
- mangleContext?: IMangleScopeContext;
41
- ctx?: IContext;
42
- postcssOptions?: LoadedPostcssOptions;
43
- cssRemoveHoverPseudoClass?: boolean;
44
- cssPresetEnv?: pluginOptions;
45
- } & RequiredStyleHandlerOptions;
46
- interface UserDefinedPostcssOptions {
47
- /**
48
- * @group 0.重要配置
49
- * @issue https://github.com/sonofmagic/weapp-tailwindcss/issues/7
50
- * @description 在所有 view节点添加的 css 预设,可根据情况自由的禁用原先的规则,或者添加新的规则。默认预置 `css` 同 `tailwindcss` 类似,详细用法如下:
51
- * ```js
52
- * // default 默认,这代表会添加给所有的 view / text 元素, 受到 cssPreflightRange 配置项影响 :
53
- cssPreflight: {
54
- 'box-sizing': 'border-box',
55
- 'border-width': '0',
56
- 'border-style': 'solid',
57
- 'border-color': 'currentColor'
58
- }
59
- // result
60
- // box-sizing: border-box;
61
- // border-width: 0;
62
- // border-style: solid;
63
- // border-color: currentColor
64
-
65
- // case 禁用所有
66
- cssPreflight: false
67
- // result
68
- // none
69
-
70
- // case 禁用单个属性
71
- cssPreflight: {
72
- 'box-sizing': false
73
- }
74
- // border-width: 0;
75
- // border-style: solid;
76
- // border-color: currentColor
77
-
78
- // case 更改和添加单个属性
79
- cssPreflight: {
80
- 'box-sizing': 'content-box',
81
- 'background': 'black'
82
- }
83
- // result
84
- // box-sizing: content-box;
85
- // border-width: 0;
86
- // border-style: solid;
87
- // border-color: currentColor;
88
- // background: black
89
- * ```
90
- */
91
- cssPreflight?: CssPreflightOptions;
92
- /**
93
- * @group 0.重要配置
94
- * @issue https://github.com/sonofmagic/weapp-tailwindcss/pull/62
95
- * @description 全局`dom`选择器,只有在这个选择器作用范围内的`dom`会被注入 `cssPreflight` 的变量和默认样式。只对所有的 `view`,`text` 和伪元素生效,想要对所有的元素生效,可切换为 `'all'`,此时需要自行处理和客户端默认样式的冲突
96
- */
97
- cssPreflightRange?: 'all';
98
- /**
99
- * @group 3.一般配置
100
- * @description 用于控制 tailwindcss 子组合器的生效标签范围, 这里我们用一个例子来说明这个配置是干啥用的.
101
- *
102
- * 我们布局的时候往往会使用 `space-x-4`
103
- * 那么实际上会生成这样的css选择器:
104
- * ```css
105
- * .space-x-4>:not([hidden])~:not([hidden]){}
106
- * ```
107
- * 然而很不幸,这个选择器在小程序中是不支持的,写了会报错导致编译失败。
108
- * 所以出于保守起见,我把它替换为了:
109
- * ```css
110
- * .space-x-4>view + view{}
111
- * ```
112
- * 这同时也是默认值, 而这个选项就允许你进行自定义子组合器的行为
113
- *
114
- * 你可以传入一个 字符串,或者字符串数组
115
- * 1. 传入字符串数组,比如 `['view','text']` 生成:
116
- * ```css
117
- * .space-y-4>view + view,text + text{}
118
- * ```
119
- *
120
- * 2. 传入一个字符串,此时行为变成了整个替换,比如 `'view,text,button,input ~ view,text,button,input'` 生成:
121
- * ```css
122
- * .space-y-4>view,text,button,input ~ view,text,button,input{}
123
- * ```
124
- * @default 'view + view'
125
- */
126
- cssChildCombinatorReplaceValue?: string | string[];
127
- /**
128
- * @group 0.重要配置
129
- * @version `^2.6.0`
130
- * @description 是否注入额外的 `tailwindcss css var scope` 区域,这个选项用于这样的场景
131
- *
132
- * 比如 `taro vue3` 使用 [NutUI](https://nutui.jd.com), 需要使用 `@tarojs/plugin-html`,而这个插件会启用 `postcss-html-transform` 从而移除所有带 `*` 选择器
133
- *
134
- * 这会导致 `tailwindcss css var scope` 区域被移除导致一些样式,比如渐变等等功能失效
135
- *
136
- * 这种场景下,启用这个选项会再次重新注入整个 `tailwindcss css var scope`
137
- *
138
- * @default false
139
- */
140
- injectAdditionalCssVarScope?: boolean;
141
- /**
142
- * @group 0.重要配置
143
- * @description 用于处理 css 选择器的替换规则
144
- */
145
- cssSelectorReplacement?: {
146
- /**
147
- * @default `'page'` <br/>
148
- * @description 把`css`中的全局选择器 **`:root`** 替换为指定值,默认替换为 `'page'`,设置为 `false` 时不进行替换
149
- */
150
- root?: string | string[] | false;
151
- /**
152
- * @issue https://github.com/sonofmagic/weapp-tailwindcss/issues/81 <br/>
153
- * @default `['view','text']` <br/>
154
- * @description 把`css`中的全局选择器 **`*`** 替换为指定值,默认替换为 `'view','text'`,设置为 `false` 时不进行替换,此时小程序会由于不认识`*`选择器而报错
155
- */
156
- universal?: string | string[] | false;
157
- };
158
- /**
159
- * @version `^3.0.0`
160
- * @group 0.重要配置
161
- * @description rem 转 rpx 配置,默认为 `undefined` 不开启,可传入 `true` 启用默认配置项,也可传入自定义配置项,配置项列表见 [postcss-rem-to-responsive-pixel](https://www.npmjs.com/package/postcss-rem-to-responsive-pixel)
162
- */
163
- rem2rpx?: boolean | UserDefinedOptions;
164
- /**
165
- * @version `^3.2.0`
166
- * @group 3.一般配置
167
- * @description 对解析 css 使用的 `postcss` 工具的配置
168
- */
169
- postcssOptions?: LoadedPostcssOptions;
170
- /**
171
- * @version `^3.2.1`
172
- * @group 3.一般配置
173
- * @issue https://github.com/sonofmagic/weapp-tailwindcss/issues/293
174
- * @default `true`
175
- * @description 是否删除 css :hover 选择器节点,默认为 `true`, 原因在于,小程序 css :hover 是不生效的,要使用 view 这种标签的 hover-class 属性
176
- */
177
- cssRemoveHoverPseudoClass?: boolean;
178
- /**
179
- * @group 3.一般配置
180
- * @description 用于自定义处理 css 的回调函数,可根据 Postcss walk 方法自由定制处理方案的 callback 方法
181
- */
182
- customRuleCallback?: CustomRuleCallback;
183
- }
184
-
185
- export { type CustomRuleCallback as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type RequiredStyleHandlerOptions as R, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type IPropValue as b, createInjectPreflight as c, type CssPreflightOptions as d };