@weapp-tailwindcss/postcss 1.2.2 → 1.3.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,11 +1,11 @@
1
- import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-C5X6IWCb.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-C5X6IWCb.mjs';
1
+ import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-3q99gNro.mjs';
2
+ export { C as CssCalcOptions, e as CssPreflightOptions, b as CustomRuleCallback, d as IPropValue, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions, c as createInjectPreflight } from './types-3q99gNro.mjs';
3
3
  import postcss from 'postcss';
4
- export { PostCssCalcOptions as CssCalcOptions } from '@weapp-tailwindcss/postcss-calc';
5
4
  export { pluginOptions as PresetEnvOptions } from 'postcss-preset-env';
6
5
  export { PxtransformOptions as Px2rpxOptions } from 'postcss-pxtransform';
7
6
  export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
8
7
  import '@weapp-tailwindcss/mangle';
8
+ import '@weapp-tailwindcss/postcss-calc';
9
9
  import 'postcss-load-config';
10
10
 
11
11
  declare function createStyleHandler(options?: Partial<IStyleHandlerOptions>): (rawSource: string, opt?: Partial<IStyleHandlerOptions>) => Promise<postcss.Result<postcss.Document | postcss.Root>>;
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-C5X6IWCb.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-C5X6IWCb.js';
1
+ import { I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions } from './types-3q99gNro.js';
2
+ export { C as CssCalcOptions, e as CssPreflightOptions, b as CustomRuleCallback, d as IPropValue, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions, c as createInjectPreflight } from './types-3q99gNro.js';
3
3
  import postcss from 'postcss';
4
- export { PostCssCalcOptions as CssCalcOptions } from '@weapp-tailwindcss/postcss-calc';
5
4
  export { pluginOptions as PresetEnvOptions } from 'postcss-preset-env';
6
5
  export { PxtransformOptions as Px2rpxOptions } from 'postcss-pxtransform';
7
6
  export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
8
7
  import '@weapp-tailwindcss/mangle';
8
+ import '@weapp-tailwindcss/postcss-calc';
9
9
  import 'postcss-load-config';
10
10
 
11
11
  declare function createStyleHandler(options?: Partial<IStyleHandlerOptions>): (rawSource: string, opt?: Partial<IStyleHandlerOptions>) => Promise<postcss.Result<postcss.Document | postcss.Root>>;
package/dist/index.js CHANGED
@@ -37,9 +37,22 @@ function getDefaultOptions(options) {
37
37
  // src/plugins/index.ts
38
38
  var _postcsscalc = require('@weapp-tailwindcss/postcss-calc'); var _postcsscalc2 = _interopRequireDefault(_postcsscalc);
39
39
 
40
+
41
+ // ../../node_modules/.pnpm/es-toolkit@1.39.10/node_modules/es-toolkit/dist/object/omit.mjs
42
+ function omit(obj, keys) {
43
+ const result = { ...obj };
44
+ for (let i = 0; i < keys.length; i++) {
45
+ const key = keys[i];
46
+ delete result[key];
47
+ }
48
+ return result;
49
+ }
50
+
51
+ // src/plugins/index.ts
40
52
  var _postcsspresetenv = require('postcss-preset-env'); var _postcsspresetenv2 = _interopRequireDefault(_postcsspresetenv);
41
53
  var _postcsspxtransform = require('postcss-pxtransform'); var _postcsspxtransform2 = _interopRequireDefault(_postcsspxtransform);
42
54
  var _postcssremtoresponsivepixel = require('postcss-rem-to-responsive-pixel'); var _postcssremtoresponsivepixel2 = _interopRequireDefault(_postcssremtoresponsivepixel);
55
+ var _postcssvalueparser = require('postcss-value-parser'); var _postcssvalueparser2 = _interopRequireDefault(_postcssvalueparser);
43
56
 
44
57
  // src/plugins/ctx.ts
45
58
  function createContext() {
@@ -956,15 +969,41 @@ function getPlugins(options) {
956
969
  )
957
970
  );
958
971
  }
972
+ const includeCustomProperties = Array.isArray(options.cssCalc) ? options.cssCalc : typeof options.cssCalc === "object" ? options.cssCalc.includeCustomProperties : [];
959
973
  if (options.cssCalc) {
960
974
  plugins.push(
961
975
  // 核心在 OnceExit 的时候去执行的
962
976
  _postcsscalc2.default.call(void 0,
963
- typeof options.cssCalc === "object" ? options.cssCalc : {}
977
+ Array.isArray(options.cssCalc) ? {} : typeof options.cssCalc === "object" ? omit(options.cssCalc, ["includeCustomProperties"]) : {}
964
978
  )
965
979
  );
966
980
  }
967
981
  plugins.push(postcssWeappTailwindcssPostPlugin(options));
982
+ if (includeCustomProperties) {
983
+ plugins.push({
984
+ postcssPlugin: "postcss-remove-include-custom-properties",
985
+ OnceExit(root) {
986
+ root.walkDecls((decl, idx) => {
987
+ if (idx > 0 && _shared.regExpTest.call(void 0, includeCustomProperties, decl.value)) {
988
+ const prevNode = _optionalChain([decl, 'access', _42 => _42.parent, 'optionalAccess', _43 => _43.nodes, 'access', _44 => _44[idx - 1]]);
989
+ if (prevNode && prevNode.prop === decl.prop) {
990
+ const parsed = _postcssvalueparser2.default.call(void 0, decl.value);
991
+ parsed.walk((node) => {
992
+ if (node.type === "function" && node.value === "var") {
993
+ const item = node.nodes.find((x) => {
994
+ return x.type === "word" && _shared.regExpTest.call(void 0, includeCustomProperties, x.value);
995
+ });
996
+ if (item) {
997
+ decl.remove();
998
+ }
999
+ }
1000
+ });
1001
+ }
1002
+ }
1003
+ });
1004
+ }
1005
+ });
1006
+ }
968
1007
  return plugins;
969
1008
  }
970
1009
 
@@ -993,7 +1032,7 @@ function styleHandler(rawSource, options) {
993
1032
  getPlugins(options)
994
1033
  ).process(
995
1034
  rawSource,
996
- _shared.defu.call(void 0, _optionalChain([options, 'access', _42 => _42.postcssOptions, 'optionalAccess', _43 => _43.options]), {
1035
+ _shared.defu.call(void 0, _optionalChain([options, 'access', _45 => _45.postcssOptions, 'optionalAccess', _46 => _46.options]), {
997
1036
  from: void 0
998
1037
  })
999
1038
  ).async();
package/dist/index.mjs CHANGED
@@ -36,10 +36,23 @@ function getDefaultOptions(options) {
36
36
 
37
37
  // src/plugins/index.ts
38
38
  import postcssCalc from "@weapp-tailwindcss/postcss-calc";
39
- import { defuOverrideArray as defuOverrideArray2 } from "@weapp-tailwindcss/shared";
39
+ import { defuOverrideArray as defuOverrideArray2, regExpTest } from "@weapp-tailwindcss/shared";
40
+
41
+ // ../../node_modules/.pnpm/es-toolkit@1.39.10/node_modules/es-toolkit/dist/object/omit.mjs
42
+ function omit(obj, keys) {
43
+ const result = { ...obj };
44
+ for (let i = 0; i < keys.length; i++) {
45
+ const key = keys[i];
46
+ delete result[key];
47
+ }
48
+ return result;
49
+ }
50
+
51
+ // src/plugins/index.ts
40
52
  import postcssPresetEnv from "postcss-preset-env";
41
53
  import postcssPxtransform from "postcss-pxtransform";
42
54
  import postcssRem2rpx from "postcss-rem-to-responsive-pixel";
55
+ import valueParser from "postcss-value-parser";
43
56
 
44
57
  // src/plugins/ctx.ts
45
58
  function createContext() {
@@ -956,15 +969,41 @@ function getPlugins(options) {
956
969
  )
957
970
  );
958
971
  }
972
+ const includeCustomProperties = Array.isArray(options.cssCalc) ? options.cssCalc : typeof options.cssCalc === "object" ? options.cssCalc.includeCustomProperties : [];
959
973
  if (options.cssCalc) {
960
974
  plugins.push(
961
975
  // 核心在 OnceExit 的时候去执行的
962
976
  postcssCalc(
963
- typeof options.cssCalc === "object" ? options.cssCalc : {}
977
+ Array.isArray(options.cssCalc) ? {} : typeof options.cssCalc === "object" ? omit(options.cssCalc, ["includeCustomProperties"]) : {}
964
978
  )
965
979
  );
966
980
  }
967
981
  plugins.push(postcssWeappTailwindcssPostPlugin(options));
982
+ if (includeCustomProperties) {
983
+ plugins.push({
984
+ postcssPlugin: "postcss-remove-include-custom-properties",
985
+ OnceExit(root) {
986
+ root.walkDecls((decl, idx) => {
987
+ if (idx > 0 && regExpTest(includeCustomProperties, decl.value)) {
988
+ const prevNode = decl.parent?.nodes[idx - 1];
989
+ if (prevNode && prevNode.prop === decl.prop) {
990
+ const parsed = valueParser(decl.value);
991
+ parsed.walk((node) => {
992
+ if (node.type === "function" && node.value === "var") {
993
+ const item = node.nodes.find((x) => {
994
+ return x.type === "word" && regExpTest(includeCustomProperties, x.value);
995
+ });
996
+ if (item) {
997
+ decl.remove();
998
+ }
999
+ }
1000
+ });
1001
+ }
1002
+ }
1003
+ });
1004
+ }
1005
+ });
1006
+ }
968
1007
  return plugins;
969
1008
  }
970
1009
 
@@ -38,6 +38,9 @@ interface InternalCssSelectorReplacerOptions {
38
38
  mangleContext?: IMangleScopeContext;
39
39
  escapeMap?: Record<string, string>;
40
40
  }
41
+ interface CssCalcOptions extends PostCssCalcOptions {
42
+ includeCustomProperties?: (string | RegExp)[];
43
+ }
41
44
  type IStyleHandlerOptions = {
42
45
  customRuleCallback?: CustomRuleCallback;
43
46
  mangleContext?: IMangleScopeContext;
@@ -46,7 +49,7 @@ type IStyleHandlerOptions = {
46
49
  cssRemoveProperty?: boolean;
47
50
  cssRemoveHoverPseudoClass?: boolean;
48
51
  cssPresetEnv?: pluginOptions;
49
- cssCalc?: boolean | PostCssCalcOptions;
52
+ cssCalc?: boolean | CssCalcOptions | (string | RegExp)[];
50
53
  atRules?: {
51
54
  property?: boolean;
52
55
  supports?: boolean;
@@ -74,4 +77,4 @@ interface UserDefinedPostcssOptions {
74
77
  uniAppX?: boolean;
75
78
  }
76
79
 
77
- 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 };
80
+ export { type CssCalcOptions as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type RequiredStyleHandlerOptions as R, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type CustomRuleCallback as b, createInjectPreflight as c, type IPropValue as d, type CssPreflightOptions as e };
@@ -38,6 +38,9 @@ interface InternalCssSelectorReplacerOptions {
38
38
  mangleContext?: IMangleScopeContext;
39
39
  escapeMap?: Record<string, string>;
40
40
  }
41
+ interface CssCalcOptions extends PostCssCalcOptions {
42
+ includeCustomProperties?: (string | RegExp)[];
43
+ }
41
44
  type IStyleHandlerOptions = {
42
45
  customRuleCallback?: CustomRuleCallback;
43
46
  mangleContext?: IMangleScopeContext;
@@ -46,7 +49,7 @@ type IStyleHandlerOptions = {
46
49
  cssRemoveProperty?: boolean;
47
50
  cssRemoveHoverPseudoClass?: boolean;
48
51
  cssPresetEnv?: pluginOptions;
49
- cssCalc?: boolean | PostCssCalcOptions;
52
+ cssCalc?: boolean | CssCalcOptions | (string | RegExp)[];
50
53
  atRules?: {
51
54
  property?: boolean;
52
55
  supports?: boolean;
@@ -74,4 +77,4 @@ interface UserDefinedPostcssOptions {
74
77
  uniAppX?: boolean;
75
78
  }
76
79
 
77
- 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 };
80
+ export { type CssCalcOptions as C, type IStyleHandlerOptions as I, type LoadedPostcssOptions as L, type RequiredStyleHandlerOptions as R, type UserDefinedPostcssOptions as U, type InternalCssSelectorReplacerOptions as a, type CustomRuleCallback as b, createInjectPreflight as c, type IPropValue as d, type CssPreflightOptions as e };
package/dist/types.d.mts CHANGED
@@ -1,8 +1,8 @@
1
1
  import '@weapp-tailwindcss/mangle';
2
- export { PostCssCalcOptions as CssCalcOptions } from '@weapp-tailwindcss/postcss-calc';
2
+ import '@weapp-tailwindcss/postcss-calc';
3
3
  import 'postcss';
4
4
  import 'postcss-load-config';
5
5
  export { pluginOptions as PresetEnvOptions } from 'postcss-preset-env';
6
6
  export { PxtransformOptions as Px2rpxOptions } from 'postcss-pxtransform';
7
7
  export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
8
- 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-C5X6IWCb.mjs';
8
+ export { C as CssCalcOptions, e as CssPreflightOptions, b as CustomRuleCallback, d as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions } from './types-3q99gNro.mjs';
package/dist/types.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import '@weapp-tailwindcss/mangle';
2
- export { PostCssCalcOptions as CssCalcOptions } from '@weapp-tailwindcss/postcss-calc';
2
+ import '@weapp-tailwindcss/postcss-calc';
3
3
  import 'postcss';
4
4
  import 'postcss-load-config';
5
5
  export { pluginOptions as PresetEnvOptions } from 'postcss-preset-env';
6
6
  export { PxtransformOptions as Px2rpxOptions } from 'postcss-pxtransform';
7
7
  export { UserDefinedOptions as Rem2rpxOptions } from 'postcss-rem-to-responsive-pixel';
8
- 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-C5X6IWCb.js';
8
+ export { C as CssCalcOptions, e as CssPreflightOptions, b as CustomRuleCallback, d as IPropValue, I as IStyleHandlerOptions, a as InternalCssSelectorReplacerOptions, L as LoadedPostcssOptions, R as RequiredStyleHandlerOptions, U as UserDefinedPostcssOptions } from './types-3q99gNro.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/postcss",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "description": "@weapp-tailwindcss/postcss",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -46,12 +46,13 @@
46
46
  "postcss-pxtransform": "^4.1.6",
47
47
  "postcss-rem-to-responsive-pixel": "~6.1.0",
48
48
  "postcss-selector-parser": "~7.1.0",
49
+ "postcss-value-parser": "^4.2.0",
49
50
  "@weapp-tailwindcss/shared": "1.0.3"
50
51
  },
51
52
  "devDependencies": {
52
53
  "@csstools/postcss-is-pseudo-class": "^5.0.3",
53
54
  "postcss-calc": "^10.1.1",
54
- "postcss-value-parser": "^4.2.0",
55
+ "postcss-custom-properties": "^14.0.6",
55
56
  "@weapp-tailwindcss/mangle": "1.0.5"
56
57
  },
57
58
  "scripts": {