@weapp-tailwindcss/postcss 1.2.2 → 1.3.1

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 && /--/.test(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
 
@@ -988,14 +1027,40 @@ function createInjectPreflight(options) {
988
1027
  }
989
1028
 
990
1029
  // src/handler.ts
1030
+ function createProcessOptions(options) {
1031
+ return {
1032
+ from: void 0,
1033
+ ..._nullishCoalesce(_optionalChain([options, 'access', _45 => _45.postcssOptions, 'optionalAccess', _46 => _46.options]), () => ( {}))
1034
+ };
1035
+ }
1036
+ var pluginCache = /* @__PURE__ */ new WeakMap();
1037
+ var processOptionsCache = /* @__PURE__ */ new WeakMap();
1038
+ var processOptionsSourceCache = /* @__PURE__ */ new WeakMap();
1039
+ function getCachedPlugins(options) {
1040
+ let plugins = pluginCache.get(options);
1041
+ if (!plugins) {
1042
+ plugins = getPlugins(options);
1043
+ pluginCache.set(options, plugins);
1044
+ }
1045
+ return plugins;
1046
+ }
1047
+ function getCachedProcessOptions(options) {
1048
+ const source = _optionalChain([options, 'access', _47 => _47.postcssOptions, 'optionalAccess', _48 => _48.options]);
1049
+ let cached = processOptionsCache.get(options);
1050
+ const cachedSource = processOptionsSourceCache.get(options);
1051
+ if (!cached || cachedSource !== source) {
1052
+ cached = createProcessOptions(options);
1053
+ processOptionsCache.set(options, cached);
1054
+ processOptionsSourceCache.set(options, source);
1055
+ }
1056
+ return { ...cached };
1057
+ }
991
1058
  function styleHandler(rawSource, options) {
992
- return _postcss2.default.call(void 0,
993
- getPlugins(options)
994
- ).process(
1059
+ const plugins = getCachedPlugins(options);
1060
+ const processOptions = getCachedProcessOptions(options);
1061
+ return _postcss2.default.call(void 0, plugins).process(
995
1062
  rawSource,
996
- _shared.defu.call(void 0, _optionalChain([options, 'access', _42 => _42.postcssOptions, 'optionalAccess', _43 => _43.options]), {
997
- from: void 0
998
- })
1063
+ processOptions
999
1064
  ).async();
1000
1065
  }
1001
1066
  function createStyleHandler(options) {
@@ -1004,10 +1069,13 @@ function createStyleHandler(options) {
1004
1069
  getDefaultOptions(options)
1005
1070
  );
1006
1071
  cachedOptions.cssInjectPreflight = createInjectPreflight(cachedOptions.cssPreflight);
1072
+ getCachedPlugins(cachedOptions);
1073
+ getCachedProcessOptions(cachedOptions);
1007
1074
  return (rawSource, opt) => {
1075
+ const resolvedOptions = _shared.defuOverrideArray.call(void 0, opt, cachedOptions);
1008
1076
  return styleHandler(
1009
1077
  rawSource,
1010
- _shared.defuOverrideArray.call(void 0, opt, cachedOptions)
1078
+ resolvedOptions
1011
1079
  );
1012
1080
  };
1013
1081
  }
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./chunk-WAXGOBY2.mjs";
2
2
 
3
3
  // src/handler.ts
4
- import { defu as defu3, defuOverrideArray as defuOverrideArray3 } from "@weapp-tailwindcss/shared";
4
+ import { defuOverrideArray as defuOverrideArray3 } from "@weapp-tailwindcss/shared";
5
5
  import postcss from "postcss";
6
6
 
7
7
  // src/defaults.ts
@@ -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 && /--/.test(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
 
@@ -988,14 +1027,40 @@ function createInjectPreflight(options) {
988
1027
  }
989
1028
 
990
1029
  // src/handler.ts
1030
+ function createProcessOptions(options) {
1031
+ return {
1032
+ from: void 0,
1033
+ ...options.postcssOptions?.options ?? {}
1034
+ };
1035
+ }
1036
+ var pluginCache = /* @__PURE__ */ new WeakMap();
1037
+ var processOptionsCache = /* @__PURE__ */ new WeakMap();
1038
+ var processOptionsSourceCache = /* @__PURE__ */ new WeakMap();
1039
+ function getCachedPlugins(options) {
1040
+ let plugins = pluginCache.get(options);
1041
+ if (!plugins) {
1042
+ plugins = getPlugins(options);
1043
+ pluginCache.set(options, plugins);
1044
+ }
1045
+ return plugins;
1046
+ }
1047
+ function getCachedProcessOptions(options) {
1048
+ const source = options.postcssOptions?.options;
1049
+ let cached = processOptionsCache.get(options);
1050
+ const cachedSource = processOptionsSourceCache.get(options);
1051
+ if (!cached || cachedSource !== source) {
1052
+ cached = createProcessOptions(options);
1053
+ processOptionsCache.set(options, cached);
1054
+ processOptionsSourceCache.set(options, source);
1055
+ }
1056
+ return { ...cached };
1057
+ }
991
1058
  function styleHandler(rawSource, options) {
992
- return postcss(
993
- getPlugins(options)
994
- ).process(
1059
+ const plugins = getCachedPlugins(options);
1060
+ const processOptions = getCachedProcessOptions(options);
1061
+ return postcss(plugins).process(
995
1062
  rawSource,
996
- defu3(options.postcssOptions?.options, {
997
- from: void 0
998
- })
1063
+ processOptions
999
1064
  ).async();
1000
1065
  }
1001
1066
  function createStyleHandler(options) {
@@ -1004,10 +1069,13 @@ function createStyleHandler(options) {
1004
1069
  getDefaultOptions(options)
1005
1070
  );
1006
1071
  cachedOptions.cssInjectPreflight = createInjectPreflight(cachedOptions.cssPreflight);
1072
+ getCachedPlugins(cachedOptions);
1073
+ getCachedProcessOptions(cachedOptions);
1007
1074
  return (rawSource, opt) => {
1075
+ const resolvedOptions = defuOverrideArray3(opt, cachedOptions);
1008
1076
  return styleHandler(
1009
1077
  rawSource,
1010
- defuOverrideArray3(opt, cachedOptions)
1078
+ resolvedOptions
1011
1079
  );
1012
1080
  };
1013
1081
  }
@@ -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.1",
4
4
  "description": "@weapp-tailwindcss/postcss",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -42,16 +42,17 @@
42
42
  "@weapp-core/escape": "~4.0.1",
43
43
  "@weapp-tailwindcss/postcss-calc": "^1.0.0",
44
44
  "postcss": "~8.5.6",
45
- "postcss-preset-env": "^10.3.1",
46
- "postcss-pxtransform": "^4.1.6",
45
+ "postcss-preset-env": "^10.4.0",
46
+ "postcss-pxtransform": "^4.1.7",
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": {