@fangzhongya/utils 0.0.73 → 0.0.74

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.
Files changed (37) hide show
  1. package/dist/basic/index.cjs +5 -5
  2. package/dist/basic/index.js +4 -4
  3. package/dist/basic/string/index.cjs +3 -3
  4. package/dist/basic/string/index.js +2 -2
  5. package/dist/basic/string/toFunctionParam.cjs +2 -2
  6. package/dist/basic/string/toFunctionParam.d.cts +7 -4
  7. package/dist/basic/string/toFunctionParam.d.ts +7 -4
  8. package/dist/basic/string/toFunctionParam.js +1 -1
  9. package/dist/{chunk-OCYQMNHW.cjs → chunk-BV6LMCAF.cjs} +3 -3
  10. package/dist/{chunk-ZZKR5C3Y.cjs → chunk-BWXXXTFU.cjs} +87 -22
  11. package/dist/{chunk-IBSTABZR.cjs → chunk-MKAI4SMJ.cjs} +2 -2
  12. package/dist/{chunk-SE2X5XKO.js → chunk-U6V3V5KH.js} +87 -22
  13. package/dist/{chunk-5CHESUXV.js → chunk-WWAVGLQE.js} +1 -1
  14. package/dist/{chunk-BQZX7DEK.js → chunk-YQETDPCJ.js} +1 -1
  15. package/dist/css/index.cjs +13 -13
  16. package/dist/css/index.js +18 -18
  17. package/dist/date/index.cjs +4 -4
  18. package/dist/date/index.js +4 -4
  19. package/dist/index.cjs +45 -45
  20. package/dist/index.js +46 -46
  21. package/dist/tree/index.cjs +3 -3
  22. package/dist/tree/index.js +6 -6
  23. package/dist/urls/index.cjs +13 -13
  24. package/dist/urls/index.js +16 -16
  25. package/dist/window/index.cjs +5 -5
  26. package/dist/window/index.js +14 -14
  27. package/package.json +1 -1
  28. package/dist/{chunk-Y3UJ5NPB.js → chunk-2AZDXCHJ.js} +13 -13
  29. package/dist/{chunk-UJBXAZW7.cjs → chunk-2KAMKGPZ.cjs} +11 -11
  30. package/dist/{chunk-UIVSKRGG.js → chunk-3DUFQKFF.js} +15 -15
  31. package/dist/{chunk-7NEXCOZZ.cjs → chunk-5SOPYS7L.cjs} +3 -3
  32. package/dist/{chunk-AU3BKC3U.cjs → chunk-7GCUYESU.cjs} +12 -12
  33. package/dist/{chunk-JPQN3LUH.js → chunk-H22VVRP6.js} +3 -3
  34. package/dist/{chunk-P2M6G3BJ.cjs → chunk-MDSCUXDF.cjs} +4 -4
  35. package/dist/{chunk-QUIZWAFR.js → chunk-OVHYLUAS.js} +5 -5
  36. package/dist/{chunk-APRM3ELY.cjs → chunk-PV2N6PF2.cjs} +2 -2
  37. package/dist/{chunk-2LB4NKNM.js → chunk-QM6EWX7J.js} +16 -16
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-IBSTABZR.cjs');
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-MKAI4SMJ.cjs');
2
2
 
3
3
 
4
- var _chunkOCYQMNHWcjs = require('../chunk-OCYQMNHW.cjs');
5
- require('../chunk-ZZKR5C3Y.cjs');
4
+ var _chunkBV6LMCAFcjs = require('../chunk-BV6LMCAF.cjs');
5
+ require('../chunk-BWXXXTFU.cjs');
6
6
  require('../chunk-K2XKKEE7.cjs');
7
7
  require('../chunk-TKE7IK2M.cjs');
8
8
  require('../chunk-HLKHFBMF.cjs');
@@ -40,9 +40,9 @@ require('../chunk-ILJLXJ5O.cjs');
40
40
  require('../chunk-OJBZ7UUC.cjs');
41
41
  require('../chunk-JR6ZN6QD.cjs');
42
42
  require('../chunk-PW7RP73J.cjs');
43
+ require('../chunk-XW3XIK3D.cjs');
43
44
  require('../chunk-UEVMS6QD.cjs');
44
45
  require('../chunk-OQL4GIEJ.cjs');
45
- require('../chunk-XW3XIK3D.cjs');
46
46
  require('../chunk-WWAPPA4E.cjs');
47
47
  require('../chunk-A5LHXE5X.cjs');
48
48
  require('../chunk-MIC3W2VY.cjs');
@@ -52,4 +52,4 @@ require('../chunk-75ZPJI57.cjs');
52
52
 
53
53
 
54
54
 
55
- exports.array = _chunk65O7KWP4cjs.array_exports; exports.object = _chunkYUKBGZQ4cjs.object_exports; exports.string = _chunkOCYQMNHWcjs.string_exports;
55
+ exports.array = _chunk65O7KWP4cjs.array_exports; exports.object = _chunkYUKBGZQ4cjs.object_exports; exports.string = _chunkBV6LMCAFcjs.string_exports;
@@ -1,8 +1,8 @@
1
- import "../chunk-BQZX7DEK.js";
1
+ import "../chunk-YQETDPCJ.js";
2
2
  import {
3
3
  string_exports
4
- } from "../chunk-5CHESUXV.js";
5
- import "../chunk-SE2X5XKO.js";
4
+ } from "../chunk-WWAVGLQE.js";
5
+ import "../chunk-U6V3V5KH.js";
6
6
  import "../chunk-TIZFQBWC.js";
7
7
  import "../chunk-ZADO6V3Z.js";
8
8
  import "../chunk-ADPTUJSF.js";
@@ -40,9 +40,9 @@ import "../chunk-P7AWHISY.js";
40
40
  import "../chunk-LPMR5W6M.js";
41
41
  import "../chunk-DMZP4RPN.js";
42
42
  import "../chunk-A276ZDLP.js";
43
+ import "../chunk-O34QAOO7.js";
43
44
  import "../chunk-4OBNLDTJ.js";
44
45
  import "../chunk-EWJJKQIO.js";
45
- import "../chunk-O34QAOO7.js";
46
46
  import "../chunk-BEKTNBRJ.js";
47
47
  import "../chunk-GYE23WAN.js";
48
48
  import "../chunk-MXY4W3K5.js";
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../../chunk-OCYQMNHW.cjs');
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../../chunk-BV6LMCAF.cjs');
2
2
 
3
3
 
4
4
 
5
- var _chunkZZKR5C3Ycjs = require('../../chunk-ZZKR5C3Y.cjs');
5
+ var _chunkBWXXXTFUcjs = require('../../chunk-BWXXXTFU.cjs');
6
6
 
7
7
 
8
8
 
@@ -88,4 +88,4 @@ require('../../chunk-75ZPJI57.cjs');
88
88
 
89
89
 
90
90
 
91
- exports.appearNum = _chunkOJBZ7UUCcjs.appearNum; exports.appearNumSeat = _chunkJR6ZN6QDcjs.appearNumSeat; exports.deComment = _chunkXWCRGY54cjs.deComment; exports.extractParams = _chunkJJ37YIPJcjs.extractParams; exports.firstLower = _chunkUEVMS6QDcjs.firstLower; exports.firstUpper = _chunkOQL4GIEJcjs.firstUpper; exports.getContent = _chunk4PUYFFPOcjs.getContent; exports.getContents = _chunk4PUYFFPOcjs.getContents; exports.getFunctionFormat = _chunkJJ37YIPJcjs.getFunctionFormat; exports.getImports = _chunkHWHYHL6Jcjs.getImports; exports.getImportss = _chunkHWHYHL6Jcjs.getImportss; exports.getStartSame = _chunkJ7S3KBHLcjs.getStartSame; exports.getStartSames = _chunkPW7RP73Jcjs.getStartSames; exports.getStrNunPosit = _chunk2H3KVSFAcjs.getStrNunPosit; exports.serializeCodeBlock = _chunkTKE7IK2Mcjs.serializeCodeBlock; exports.serializeFunctionRef = _chunkTKE7IK2Mcjs.serializeFunctionRef; exports.splitUpper = _chunkL7FSHU27cjs.splitUpper; exports.startsNum = _chunkILJLXJ5Ocjs.startsNum; exports.toFunction = _chunkJJ37YIPJcjs.toFunction; exports.toFunctionParam = _chunkZZKR5C3Ycjs.toFunctionParam; exports.toFunctionParamOptions = _chunkZZKR5C3Ycjs.toFunctionParamOptions; exports.toJSONParse = _chunkK2XKKEE7cjs.toJSONParse; exports.toJSONSParse = _chunkTKE7IK2Mcjs.toJSONSParse; exports.toJSONSStringify = _chunkTKE7IK2Mcjs.toJSONSStringify; exports.toJSONStringify = _chunkK2XKKEE7cjs.toJSONStringify; exports.toStringParse = _chunkHLKHFBMFcjs.toStringParse;
91
+ exports.appearNum = _chunkOJBZ7UUCcjs.appearNum; exports.appearNumSeat = _chunkJR6ZN6QDcjs.appearNumSeat; exports.deComment = _chunkXWCRGY54cjs.deComment; exports.extractParams = _chunkJJ37YIPJcjs.extractParams; exports.firstLower = _chunkUEVMS6QDcjs.firstLower; exports.firstUpper = _chunkOQL4GIEJcjs.firstUpper; exports.getContent = _chunk4PUYFFPOcjs.getContent; exports.getContents = _chunk4PUYFFPOcjs.getContents; exports.getFunctionFormat = _chunkJJ37YIPJcjs.getFunctionFormat; exports.getImports = _chunkHWHYHL6Jcjs.getImports; exports.getImportss = _chunkHWHYHL6Jcjs.getImportss; exports.getStartSame = _chunkJ7S3KBHLcjs.getStartSame; exports.getStartSames = _chunkPW7RP73Jcjs.getStartSames; exports.getStrNunPosit = _chunk2H3KVSFAcjs.getStrNunPosit; exports.serializeCodeBlock = _chunkTKE7IK2Mcjs.serializeCodeBlock; exports.serializeFunctionRef = _chunkTKE7IK2Mcjs.serializeFunctionRef; exports.splitUpper = _chunkL7FSHU27cjs.splitUpper; exports.startsNum = _chunkILJLXJ5Ocjs.startsNum; exports.toFunction = _chunkJJ37YIPJcjs.toFunction; exports.toFunctionParam = _chunkBWXXXTFUcjs.toFunctionParam; exports.toFunctionParamOptions = _chunkBWXXXTFUcjs.toFunctionParamOptions; exports.toJSONParse = _chunkK2XKKEE7cjs.toJSONParse; exports.toJSONSParse = _chunkTKE7IK2Mcjs.toJSONSParse; exports.toJSONSStringify = _chunkTKE7IK2Mcjs.toJSONSStringify; exports.toJSONStringify = _chunkK2XKKEE7cjs.toJSONStringify; exports.toStringParse = _chunkHLKHFBMFcjs.toStringParse;
@@ -1,8 +1,8 @@
1
- import "../../chunk-5CHESUXV.js";
1
+ import "../../chunk-WWAVGLQE.js";
2
2
  import {
3
3
  toFunctionParam,
4
4
  toFunctionParamOptions
5
- } from "../../chunk-SE2X5XKO.js";
5
+ } from "../../chunk-U6V3V5KH.js";
6
6
  import {
7
7
  toJSONParse,
8
8
  toJSONStringify
@@ -1,10 +1,10 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunkZZKR5C3Ycjs = require('../../chunk-ZZKR5C3Y.cjs');
4
+ var _chunkBWXXXTFUcjs = require('../../chunk-BWXXXTFU.cjs');
5
5
  require('../../chunk-JJ37YIPJ.cjs');
6
6
  require('../../chunk-75ZPJI57.cjs');
7
7
 
8
8
 
9
9
 
10
- exports.toFunctionParam = _chunkZZKR5C3Ycjs.toFunctionParam; exports.toFunctionParamOptions = _chunkZZKR5C3Ycjs.toFunctionParamOptions;
10
+ exports.toFunctionParam = _chunkBWXXXTFUcjs.toFunctionParam; exports.toFunctionParamOptions = _chunkBWXXXTFUcjs.toFunctionParamOptions;
@@ -1,18 +1,21 @@
1
1
  type ObjAny = Record<string, any>;
2
2
  /**
3
- * 优化的toFunctionParam函数 - 保持简洁和快速
3
+ * 优化的toFunctionParam函数 - 修复版本
4
4
  */
5
- declare function toFunctionParam(str: string | Function, externalParams?: ObjAny): Function | undefined;
5
+ declare function toFunctionParam(str: string | Function, externalParams?: ObjAny | (() => ObjAny)): Function | undefined;
6
6
  /**
7
- * 增强版,支持更多选项(保持向后兼容)
7
+ * 增强版,支持更多选项(修复版本)
8
8
  */
9
- declare function toFunctionParamOptions(str: string | Function, externalParams?: ObjAny, options?: {
9
+ declare function toFunctionParamOptions(str: string | Function, externalParams?: ObjAny | (() => ObjAny), options?: {
10
10
  useClosure?: boolean;
11
11
  strictMode?: boolean;
12
12
  context?: ObjAny;
13
13
  paramDefaults?: Record<string, any>;
14
14
  bindThis?: boolean;
15
15
  name?: string;
16
+ autoRebind?: boolean;
17
+ autoFirst?: boolean;
18
+ useProxy?: boolean;
16
19
  }): Function | undefined;
17
20
 
18
21
  export { toFunctionParam, toFunctionParamOptions };
@@ -1,18 +1,21 @@
1
1
  type ObjAny = Record<string, any>;
2
2
  /**
3
- * 优化的toFunctionParam函数 - 保持简洁和快速
3
+ * 优化的toFunctionParam函数 - 修复版本
4
4
  */
5
- declare function toFunctionParam(str: string | Function, externalParams?: ObjAny): Function | undefined;
5
+ declare function toFunctionParam(str: string | Function, externalParams?: ObjAny | (() => ObjAny)): Function | undefined;
6
6
  /**
7
- * 增强版,支持更多选项(保持向后兼容)
7
+ * 增强版,支持更多选项(修复版本)
8
8
  */
9
- declare function toFunctionParamOptions(str: string | Function, externalParams?: ObjAny, options?: {
9
+ declare function toFunctionParamOptions(str: string | Function, externalParams?: ObjAny | (() => ObjAny), options?: {
10
10
  useClosure?: boolean;
11
11
  strictMode?: boolean;
12
12
  context?: ObjAny;
13
13
  paramDefaults?: Record<string, any>;
14
14
  bindThis?: boolean;
15
15
  name?: string;
16
+ autoRebind?: boolean;
17
+ autoFirst?: boolean;
18
+ useProxy?: boolean;
16
19
  }): Function | undefined;
17
20
 
18
21
  export { toFunctionParam, toFunctionParamOptions };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  toFunctionParam,
3
3
  toFunctionParamOptions
4
- } from "../../chunk-SE2X5XKO.js";
4
+ } from "../../chunk-U6V3V5KH.js";
5
5
  import "../../chunk-Q6BNW3MO.js";
6
6
  import "../../chunk-MLKGABMK.js";
7
7
  export {
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunkZZKR5C3Ycjs = require('./chunk-ZZKR5C3Y.cjs');
4
+ var _chunkBWXXXTFUcjs = require('./chunk-BWXXXTFU.cjs');
5
5
 
6
6
 
7
7
 
@@ -84,8 +84,8 @@ _chunk75ZPJI57cjs.__export.call(void 0, string_exports, {
84
84
  splitUpper: () => _chunkL7FSHU27cjs.splitUpper,
85
85
  startsNum: () => _chunkILJLXJ5Ocjs.startsNum,
86
86
  toFunction: () => _chunkJJ37YIPJcjs.toFunction,
87
- toFunctionParam: () => _chunkZZKR5C3Ycjs.toFunctionParam,
88
- toFunctionParamOptions: () => _chunkZZKR5C3Ycjs.toFunctionParamOptions,
87
+ toFunctionParam: () => _chunkBWXXXTFUcjs.toFunctionParam,
88
+ toFunctionParamOptions: () => _chunkBWXXXTFUcjs.toFunctionParamOptions,
89
89
  toJSONParse: () => _chunkK2XKKEE7cjs.toJSONParse,
90
90
  toJSONSParse: () => _chunkTKE7IK2Mcjs.toJSONSParse,
91
91
  toJSONSStringify: () => _chunkTKE7IK2Mcjs.toJSONSStringify,
@@ -13,37 +13,76 @@ function buildFunctionString(obj) {
13
13
  function createSimpleFunction(obj) {
14
14
  return new Function(`return ${buildFunctionString(obj)}`)();
15
15
  }
16
+ function getKeys(externalKeys, body) {
17
+ return externalKeys.filter((o) => body.includes(o));
18
+ }
16
19
  function createFunctionWithClosure(obj, externalParams) {
17
20
  const externalKeys = Object.keys(externalParams);
18
21
  if (externalKeys.length === 0) {
19
22
  return createSimpleFunction(obj);
20
23
  }
21
24
  try {
25
+ const keys = getKeys(externalKeys, obj.body);
22
26
  const factory = new Function(
23
- ...externalKeys,
27
+ ...keys,
24
28
  `return ${buildFunctionString(obj)};`
25
29
  );
26
- return factory(...externalKeys.map((k) => externalParams[k]));
30
+ const currentValues = keys.map((k) => externalParams[k]);
31
+ return factory(...currentValues);
27
32
  } catch (error) {
28
33
  const { param, body } = obj;
34
+ const keys = getKeys(externalKeys, body);
29
35
  const funcParams = param ? _chunkJJ37YIPJcjs.extractParams.call(void 0, param) : [];
30
- const allParams = [...funcParams, ...externalKeys];
31
- const closure = new Function(...allParams, body);
36
+ return (...args) => {
37
+ const currentExternalValues = keys.map((k) => externalParams[k]);
38
+ return new Function(
39
+ ...funcParams,
40
+ ...keys,
41
+ `'use strict'; ${body}`
42
+ )(...currentExternalValues, ...args);
43
+ };
44
+ }
45
+ }
46
+ function createFunctionWithDynamicBinding(obj, externalParams, autoFirst = false) {
47
+ const { param, body } = obj;
48
+ const funcParams = param ? _chunkJJ37YIPJcjs.extractParams.call(void 0, param) : [];
49
+ const getExternalParams = typeof externalParams === "function" ? externalParams : () => externalParams;
50
+ if (autoFirst) {
51
+ const currentExternal = getExternalParams();
52
+ const externalKeys = Object.keys(currentExternal);
53
+ const keys = getKeys(externalKeys, body);
54
+ const externalValues = keys.map((k) => currentExternal[k]);
55
+ const func = new Function(
56
+ ...funcParams,
57
+ ...keys,
58
+ `'use strict'; ${body}`
59
+ );
32
60
  return function(...args) {
33
- return closure(
34
- ...args,
35
- ...externalKeys.map((k) => externalParams[k])
61
+ return func(...externalValues, ...args);
62
+ };
63
+ } else {
64
+ return function(...args) {
65
+ const currentExternal = getExternalParams();
66
+ const externalKeys = Object.keys(currentExternal);
67
+ const keys = getKeys(externalKeys, body);
68
+ const externalValues = keys.map((k) => currentExternal[k]);
69
+ const func = new Function(
70
+ ...keys,
71
+ ...funcParams,
72
+ `'use strict'; ${body}`
36
73
  );
74
+ return func(...externalValues, ...args);
37
75
  };
38
76
  }
39
77
  }
40
78
  function createFunctionWithoutClosure(obj, externalParams) {
41
79
  const funcParams = obj.param ? _chunkJJ37YIPJcjs.extractParams.call(void 0, obj.param) : [];
42
80
  const externalKeys = Object.keys(externalParams);
81
+ const keys = getKeys(externalKeys, obj.body);
43
82
  const baseFunc = createSimpleFunction(obj);
44
83
  return function(...args) {
45
84
  const context = {};
46
- externalKeys.forEach((k) => {
85
+ keys.forEach((k) => {
47
86
  context[k] = externalParams[k];
48
87
  });
49
88
  funcParams.forEach((paramName, index) => {
@@ -57,18 +96,19 @@ function toFunctionParam(str, externalParams) {
57
96
  try {
58
97
  const obj = _chunkJJ37YIPJcjs.getFunctionFormat.call(void 0, str);
59
98
  if (!_optionalChain([obj, 'optionalAccess', _ => _.body])) return void 0;
60
- if (obj.param) {
61
- const paramCount = _chunkJJ37YIPJcjs.extractParams.call(void 0, obj.param).length;
62
- if (paramCount > 1e3) {
63
- console.warn("Too many parameters, limiting to 1000");
64
- return void 0;
99
+ if (externalParams) {
100
+ if (typeof externalParams === "function") {
101
+ return createFunctionWithDynamicBinding(
102
+ obj,
103
+ externalParams,
104
+ false
105
+ // 改为 false,避免缓存
106
+ );
107
+ } else if (Object.keys(externalParams).length > 0) {
108
+ return createFunctionWithClosure(obj, externalParams);
65
109
  }
66
110
  }
67
- if (externalParams && Object.keys(externalParams).length > 0) {
68
- return createFunctionWithClosure(obj, externalParams);
69
- } else {
70
- return createSimpleFunction(obj);
71
- }
111
+ return createSimpleFunction(obj);
72
112
  } catch (error) {
73
113
  console.error("Function creation failed:", error);
74
114
  return void 0;
@@ -80,11 +120,15 @@ function toFunctionParamOptions(str, externalParams, options) {
80
120
  if (!_optionalChain([obj, 'optionalAccess', _2 => _2.body])) return void 0;
81
121
  const opts = {
82
122
  useClosure: true,
83
- // 默认使用闭包方式(性能更好)
84
123
  strictMode: true,
85
124
  context: {},
86
125
  paramDefaults: {},
87
126
  bindThis: false,
127
+ autoRebind: true,
128
+ // 默认自动重新绑定
129
+ autoFirst: true,
130
+ useProxy: false,
131
+ // 默认不使用proxy
88
132
  ...options
89
133
  };
90
134
  let functionBody = obj.body;
@@ -104,9 +148,30 @@ function toFunctionParamOptions(str, externalParams, options) {
104
148
  funcObj.name = opts.name;
105
149
  }
106
150
  let result;
107
- if (externalParams && Object.keys(externalParams).length > 0) {
108
- if (opts.useClosure) {
109
- result = createFunctionWithClosure(funcObj, externalParams);
151
+ if (externalParams) {
152
+ if (opts.useProxy && typeof externalParams === "object") {
153
+ const proxyHandler = {
154
+ get: (target, prop) => {
155
+ return target[prop];
156
+ }
157
+ };
158
+ const proxiedParams = new Proxy(
159
+ externalParams,
160
+ proxyHandler
161
+ );
162
+ result = createFunctionWithClosure(funcObj, proxiedParams);
163
+ } else if (opts.autoRebind || typeof externalParams === "function") {
164
+ const getExternal = typeof externalParams === "function" ? externalParams : () => externalParams;
165
+ result = createFunctionWithDynamicBinding(
166
+ funcObj,
167
+ getExternal,
168
+ opts.autoFirst
169
+ );
170
+ } else if (opts.useClosure) {
171
+ result = createFunctionWithClosure(
172
+ funcObj,
173
+ externalParams
174
+ );
110
175
  } else {
111
176
  result = createFunctionWithoutClosure(funcObj, externalParams);
112
177
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkOCYQMNHWcjs = require('./chunk-OCYQMNHW.cjs');
3
+ var _chunkBV6LMCAFcjs = require('./chunk-BV6LMCAF.cjs');
4
4
 
5
5
 
6
6
  var _chunkYUKBGZQ4cjs = require('./chunk-YUKBGZQ4.cjs');
@@ -16,7 +16,7 @@ var basic_exports = {};
16
16
  _chunk75ZPJI57cjs.__export.call(void 0, basic_exports, {
17
17
  array: () => _chunk65O7KWP4cjs.array_exports,
18
18
  object: () => _chunkYUKBGZQ4cjs.object_exports,
19
- string: () => _chunkOCYQMNHWcjs.string_exports
19
+ string: () => _chunkBV6LMCAFcjs.string_exports
20
20
  });
21
21
 
22
22
 
@@ -13,37 +13,76 @@ function buildFunctionString(obj) {
13
13
  function createSimpleFunction(obj) {
14
14
  return new Function(`return ${buildFunctionString(obj)}`)();
15
15
  }
16
+ function getKeys(externalKeys, body) {
17
+ return externalKeys.filter((o) => body.includes(o));
18
+ }
16
19
  function createFunctionWithClosure(obj, externalParams) {
17
20
  const externalKeys = Object.keys(externalParams);
18
21
  if (externalKeys.length === 0) {
19
22
  return createSimpleFunction(obj);
20
23
  }
21
24
  try {
25
+ const keys = getKeys(externalKeys, obj.body);
22
26
  const factory = new Function(
23
- ...externalKeys,
27
+ ...keys,
24
28
  `return ${buildFunctionString(obj)};`
25
29
  );
26
- return factory(...externalKeys.map((k) => externalParams[k]));
30
+ const currentValues = keys.map((k) => externalParams[k]);
31
+ return factory(...currentValues);
27
32
  } catch (error) {
28
33
  const { param, body } = obj;
34
+ const keys = getKeys(externalKeys, body);
29
35
  const funcParams = param ? extractParams(param) : [];
30
- const allParams = [...funcParams, ...externalKeys];
31
- const closure = new Function(...allParams, body);
36
+ return (...args) => {
37
+ const currentExternalValues = keys.map((k) => externalParams[k]);
38
+ return new Function(
39
+ ...funcParams,
40
+ ...keys,
41
+ `'use strict'; ${body}`
42
+ )(...currentExternalValues, ...args);
43
+ };
44
+ }
45
+ }
46
+ function createFunctionWithDynamicBinding(obj, externalParams, autoFirst = false) {
47
+ const { param, body } = obj;
48
+ const funcParams = param ? extractParams(param) : [];
49
+ const getExternalParams = typeof externalParams === "function" ? externalParams : () => externalParams;
50
+ if (autoFirst) {
51
+ const currentExternal = getExternalParams();
52
+ const externalKeys = Object.keys(currentExternal);
53
+ const keys = getKeys(externalKeys, body);
54
+ const externalValues = keys.map((k) => currentExternal[k]);
55
+ const func = new Function(
56
+ ...funcParams,
57
+ ...keys,
58
+ `'use strict'; ${body}`
59
+ );
32
60
  return function(...args) {
33
- return closure(
34
- ...args,
35
- ...externalKeys.map((k) => externalParams[k])
61
+ return func(...externalValues, ...args);
62
+ };
63
+ } else {
64
+ return function(...args) {
65
+ const currentExternal = getExternalParams();
66
+ const externalKeys = Object.keys(currentExternal);
67
+ const keys = getKeys(externalKeys, body);
68
+ const externalValues = keys.map((k) => currentExternal[k]);
69
+ const func = new Function(
70
+ ...keys,
71
+ ...funcParams,
72
+ `'use strict'; ${body}`
36
73
  );
74
+ return func(...externalValues, ...args);
37
75
  };
38
76
  }
39
77
  }
40
78
  function createFunctionWithoutClosure(obj, externalParams) {
41
79
  const funcParams = obj.param ? extractParams(obj.param) : [];
42
80
  const externalKeys = Object.keys(externalParams);
81
+ const keys = getKeys(externalKeys, obj.body);
43
82
  const baseFunc = createSimpleFunction(obj);
44
83
  return function(...args) {
45
84
  const context = {};
46
- externalKeys.forEach((k) => {
85
+ keys.forEach((k) => {
47
86
  context[k] = externalParams[k];
48
87
  });
49
88
  funcParams.forEach((paramName, index) => {
@@ -57,18 +96,19 @@ function toFunctionParam(str, externalParams) {
57
96
  try {
58
97
  const obj = getFunctionFormat(str);
59
98
  if (!obj?.body) return void 0;
60
- if (obj.param) {
61
- const paramCount = extractParams(obj.param).length;
62
- if (paramCount > 1e3) {
63
- console.warn("Too many parameters, limiting to 1000");
64
- return void 0;
99
+ if (externalParams) {
100
+ if (typeof externalParams === "function") {
101
+ return createFunctionWithDynamicBinding(
102
+ obj,
103
+ externalParams,
104
+ false
105
+ // 改为 false,避免缓存
106
+ );
107
+ } else if (Object.keys(externalParams).length > 0) {
108
+ return createFunctionWithClosure(obj, externalParams);
65
109
  }
66
110
  }
67
- if (externalParams && Object.keys(externalParams).length > 0) {
68
- return createFunctionWithClosure(obj, externalParams);
69
- } else {
70
- return createSimpleFunction(obj);
71
- }
111
+ return createSimpleFunction(obj);
72
112
  } catch (error) {
73
113
  console.error("Function creation failed:", error);
74
114
  return void 0;
@@ -80,11 +120,15 @@ function toFunctionParamOptions(str, externalParams, options) {
80
120
  if (!obj?.body) return void 0;
81
121
  const opts = {
82
122
  useClosure: true,
83
- // 默认使用闭包方式(性能更好)
84
123
  strictMode: true,
85
124
  context: {},
86
125
  paramDefaults: {},
87
126
  bindThis: false,
127
+ autoRebind: true,
128
+ // 默认自动重新绑定
129
+ autoFirst: true,
130
+ useProxy: false,
131
+ // 默认不使用proxy
88
132
  ...options
89
133
  };
90
134
  let functionBody = obj.body;
@@ -104,9 +148,30 @@ function toFunctionParamOptions(str, externalParams, options) {
104
148
  funcObj.name = opts.name;
105
149
  }
106
150
  let result;
107
- if (externalParams && Object.keys(externalParams).length > 0) {
108
- if (opts.useClosure) {
109
- result = createFunctionWithClosure(funcObj, externalParams);
151
+ if (externalParams) {
152
+ if (opts.useProxy && typeof externalParams === "object") {
153
+ const proxyHandler = {
154
+ get: (target, prop) => {
155
+ return target[prop];
156
+ }
157
+ };
158
+ const proxiedParams = new Proxy(
159
+ externalParams,
160
+ proxyHandler
161
+ );
162
+ result = createFunctionWithClosure(funcObj, proxiedParams);
163
+ } else if (opts.autoRebind || typeof externalParams === "function") {
164
+ const getExternal = typeof externalParams === "function" ? externalParams : () => externalParams;
165
+ result = createFunctionWithDynamicBinding(
166
+ funcObj,
167
+ getExternal,
168
+ opts.autoFirst
169
+ );
170
+ } else if (opts.useClosure) {
171
+ result = createFunctionWithClosure(
172
+ funcObj,
173
+ externalParams
174
+ );
110
175
  } else {
111
176
  result = createFunctionWithoutClosure(funcObj, externalParams);
112
177
  }
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  toFunctionParam,
3
3
  toFunctionParamOptions
4
- } from "./chunk-SE2X5XKO.js";
4
+ } from "./chunk-U6V3V5KH.js";
5
5
  import {
6
6
  toJSONParse,
7
7
  toJSONStringify
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  string_exports
3
- } from "./chunk-5CHESUXV.js";
3
+ } from "./chunk-WWAVGLQE.js";
4
4
  import {
5
5
  object_exports
6
6
  } from "./chunk-PRGC5MIZ.js";
@@ -1,40 +1,40 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-UJBXAZW7.cjs');
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-2KAMKGPZ.cjs');
2
2
 
3
3
 
4
- var _chunk4X7AFGTVcjs = require('../chunk-4X7AFGTV.cjs');
4
+ var _chunkSJPWB2OHcjs = require('../chunk-SJPWB2OH.cjs');
5
5
 
6
6
 
7
7
 
8
- var _chunkHJTIJGIFcjs = require('../chunk-HJTIJGIF.cjs');
8
+ var _chunk464TCOCRcjs = require('../chunk-464TCOCR.cjs');
9
9
 
10
10
 
11
- var _chunkVY5VQ7WEcjs = require('../chunk-VY5VQ7WE.cjs');
11
+ var _chunkCTLBHJGFcjs = require('../chunk-CTLBHJGF.cjs');
12
12
 
13
13
 
14
- var _chunkUGS2F6DKcjs = require('../chunk-UGS2F6DK.cjs');
14
+ var _chunk4X7AFGTVcjs = require('../chunk-4X7AFGTV.cjs');
15
+ require('../chunk-LTVXRDTD.cjs');
15
16
 
16
17
 
17
- var _chunkIFVVMDAWcjs = require('../chunk-IFVVMDAW.cjs');
18
18
 
19
+ var _chunkHJTIJGIFcjs = require('../chunk-HJTIJGIF.cjs');
19
20
 
20
- var _chunk6TH2K7LEcjs = require('../chunk-6TH2K7LE.cjs');
21
21
 
22
+ var _chunkUGFSIZ5Pcjs = require('../chunk-UGFSIZ5P.cjs');
22
23
 
23
- var _chunkSJPWB2OHcjs = require('../chunk-SJPWB2OH.cjs');
24
24
 
25
+ var _chunkTE3XNGF4cjs = require('../chunk-TE3XNGF4.cjs');
25
26
 
26
27
 
27
- var _chunk464TCOCRcjs = require('../chunk-464TCOCR.cjs');
28
- require('../chunk-LTVXRDTD.cjs');
28
+ var _chunkVY5VQ7WEcjs = require('../chunk-VY5VQ7WE.cjs');
29
29
 
30
30
 
31
- var _chunkCTLBHJGFcjs = require('../chunk-CTLBHJGF.cjs');
31
+ var _chunkUGS2F6DKcjs = require('../chunk-UGS2F6DK.cjs');
32
32
 
33
33
 
34
- var _chunkUGFSIZ5Pcjs = require('../chunk-UGFSIZ5P.cjs');
34
+ var _chunkIFVVMDAWcjs = require('../chunk-IFVVMDAW.cjs');
35
35
 
36
36
 
37
- var _chunkTE3XNGF4cjs = require('../chunk-TE3XNGF4.cjs');
37
+ var _chunk6TH2K7LEcjs = require('../chunk-6TH2K7LE.cjs');
38
38
  require('../chunk-75ZPJI57.cjs');
39
39
 
40
40
 
package/dist/css/index.js CHANGED
@@ -1,11 +1,28 @@
1
- import "../chunk-2LB4NKNM.js";
1
+ import "../chunk-QM6EWX7J.js";
2
+ import {
3
+ getScssImports
4
+ } from "../chunk-NW2ZNMSV.js";
5
+ import {
6
+ getBasisSVG,
7
+ getSVG
8
+ } from "../chunk-UQ3Z6VG7.js";
9
+ import {
10
+ setClassName
11
+ } from "../chunk-D3YMEKIF.js";
2
12
  import {
3
13
  setCss
4
14
  } from "../chunk-XUL6LPTN.js";
15
+ import "../chunk-J7CICTHH.js";
5
16
  import {
6
17
  setObjStyle,
7
18
  toStyleString
8
19
  } from "../chunk-M323GS33.js";
20
+ import {
21
+ fetchUnitValue
22
+ } from "../chunk-WX3JYE47.js";
23
+ import {
24
+ getAttrObj
25
+ } from "../chunk-N3FZ4WUI.js";
9
26
  import {
10
27
  getPositionRelative
11
28
  } from "../chunk-MQHLAQQA.js";
@@ -18,23 +35,6 @@ import {
18
35
  import {
19
36
  getPrentCorres
20
37
  } from "../chunk-VNY5UA2Q.js";
21
- import {
22
- getScssImports
23
- } from "../chunk-NW2ZNMSV.js";
24
- import {
25
- getBasisSVG,
26
- getSVG
27
- } from "../chunk-UQ3Z6VG7.js";
28
- import "../chunk-J7CICTHH.js";
29
- import {
30
- setClassName
31
- } from "../chunk-D3YMEKIF.js";
32
- import {
33
- fetchUnitValue
34
- } from "../chunk-WX3JYE47.js";
35
- import {
36
- getAttrObj
37
- } from "../chunk-N3FZ4WUI.js";
38
38
  import "../chunk-MLKGABMK.js";
39
39
  export {
40
40
  fetchUnitValue,