unpeek 1.11.0 → 1.12.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.
Files changed (83) hide show
  1. package/dist/ast/index.cjs +378 -89
  2. package/dist/ast/index.cjs.map +1 -1
  3. package/dist/ast/index.d.cts +6 -5
  4. package/dist/ast/index.d.ts +6 -5
  5. package/dist/ast/index.js +378 -89
  6. package/dist/ast/index.js.map +1 -1
  7. package/dist/browser.cjs +378 -89
  8. package/dist/browser.cjs.map +1 -1
  9. package/dist/browser.d.cts +1 -1
  10. package/dist/browser.d.ts +1 -1
  11. package/dist/browser.js +378 -89
  12. package/dist/browser.js.map +1 -1
  13. package/dist/bundler/detector.cjs +132 -41
  14. package/dist/bundler/detector.cjs.map +1 -1
  15. package/dist/bundler/detector.d.cts +7 -3
  16. package/dist/bundler/detector.d.ts +7 -3
  17. package/dist/bundler/detector.js +129 -41
  18. package/dist/bundler/detector.js.map +1 -1
  19. package/dist/bundler/sourcemap-vault.cjs +136 -46
  20. package/dist/bundler/sourcemap-vault.cjs.map +1 -1
  21. package/dist/bundler/sourcemap-vault.d.cts +2 -1
  22. package/dist/bundler/sourcemap-vault.d.ts +2 -1
  23. package/dist/bundler/sourcemap-vault.js +136 -46
  24. package/dist/bundler/sourcemap-vault.js.map +1 -1
  25. package/dist/bundler/unplugin.cjs +383 -91
  26. package/dist/bundler/unplugin.cjs.map +1 -1
  27. package/dist/bundler/unplugin.js +383 -91
  28. package/dist/bundler/unplugin.js.map +1 -1
  29. package/dist/cli/index.cjs +875 -205
  30. package/dist/cli/index.cjs.map +1 -1
  31. package/dist/cli/index.js +860 -190
  32. package/dist/cli/index.js.map +1 -1
  33. package/dist/cli/init.cjs +78 -29
  34. package/dist/cli/init.cjs.map +1 -1
  35. package/dist/cli/init.js +78 -29
  36. package/dist/cli/init.js.map +1 -1
  37. package/dist/cli/protect.cjs +892 -222
  38. package/dist/cli/protect.cjs.map +1 -1
  39. package/dist/cli/protect.js +868 -198
  40. package/dist/cli/protect.js.map +1 -1
  41. package/dist/config.cjs +333 -0
  42. package/dist/config.cjs.map +1 -0
  43. package/dist/config.d.cts +12 -0
  44. package/dist/config.d.ts +12 -0
  45. package/dist/config.js +291 -0
  46. package/dist/config.js.map +1 -0
  47. package/dist/esbuild.cjs +383 -91
  48. package/dist/esbuild.cjs.map +1 -1
  49. package/dist/esbuild.d.cts +1 -1
  50. package/dist/esbuild.d.ts +1 -1
  51. package/dist/esbuild.js +383 -91
  52. package/dist/esbuild.js.map +1 -1
  53. package/dist/index.cjs +970 -242
  54. package/dist/index.cjs.map +1 -1
  55. package/dist/index.d.cts +3 -2
  56. package/dist/index.d.ts +3 -2
  57. package/dist/index.js +936 -215
  58. package/dist/index.js.map +1 -1
  59. package/dist/rollup.cjs +383 -91
  60. package/dist/rollup.cjs.map +1 -1
  61. package/dist/rollup.d.cts +1 -1
  62. package/dist/rollup.d.ts +1 -1
  63. package/dist/rollup.js +383 -91
  64. package/dist/rollup.js.map +1 -1
  65. package/dist/runtime/index.cjs +3 -2
  66. package/dist/runtime/index.cjs.map +1 -1
  67. package/dist/runtime/index.js +3 -2
  68. package/dist/runtime/index.js.map +1 -1
  69. package/dist/{types-DBNcJBCS.d.cts → types-CgWUnSfX.d.cts} +65 -1
  70. package/dist/{types-DBNcJBCS.d.ts → types-CgWUnSfX.d.ts} +65 -1
  71. package/dist/vite.cjs +383 -91
  72. package/dist/vite.cjs.map +1 -1
  73. package/dist/vite.d.cts +1 -1
  74. package/dist/vite.d.ts +1 -1
  75. package/dist/vite.js +383 -91
  76. package/dist/vite.js.map +1 -1
  77. package/dist/webpack.cjs +383 -91
  78. package/dist/webpack.cjs.map +1 -1
  79. package/dist/webpack.d.cts +1 -1
  80. package/dist/webpack.d.ts +1 -1
  81. package/dist/webpack.js +383 -91
  82. package/dist/webpack.js.map +1 -1
  83. package/package.json +1 -1
@@ -69,6 +69,23 @@ var ANIMATION_FRAME_CALLS = /* @__PURE__ */ new Set([
69
69
  "updateMatrixWorld",
70
70
  "raf"
71
71
  ]);
72
+ var DEFAULT_IMPORT_SOURCES = {
73
+ "@react-three/fiber": ["useFrame"],
74
+ lenis: ["useLenis", "raf"],
75
+ "lenis/react": ["useLenis"],
76
+ three: ["onBeforeRender", "updateMatrixWorld", "useFrame"],
77
+ gsap: ["ticker"]
78
+ };
79
+ var DEFAULT_HOC_WRAPPERS = /* @__PURE__ */ new Set([
80
+ "memo",
81
+ "forwardRef",
82
+ "React.memo",
83
+ "React.forwardRef",
84
+ "observer",
85
+ "connect"
86
+ ]);
87
+ var DEFAULT_EVENT_HANDLER_REGEX = /^(?:on|handle)(?!Tick|Render|Update|Frame|Animate|Physics)[A-Z]/;
88
+ var DEFAULT_HOOK_REGEX = /^use[A-Z0-9]/;
72
89
  var REACT_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
73
90
  "useState",
74
91
  "useEffect",
@@ -109,7 +126,24 @@ function parseJavaScriptAst(code) {
109
126
  }
110
127
  }
111
128
  }
112
- function getFunctionLabel(node, ancestors) {
129
+ function isHocCall(callNode, hocWrappers) {
130
+ if (!callNode || callNode.type !== "CallExpression") return false;
131
+ const callee = callNode.callee;
132
+ if (!callee) return false;
133
+ const wrappers = hocWrappers ?? DEFAULT_HOC_WRAPPERS;
134
+ if (callee.type === "Identifier") {
135
+ return wrappers.has(callee.name);
136
+ }
137
+ if (callee.type === "MemberExpression" && !callee.computed && callee.property?.type === "Identifier") {
138
+ if (wrappers.has(callee.property.name)) return true;
139
+ if (callee.object?.type === "Identifier") {
140
+ const full2 = `${callee.object.name}.${callee.property.name}`;
141
+ if (wrappers.has(full2)) return true;
142
+ }
143
+ }
144
+ return false;
145
+ }
146
+ function getFunctionLabel(node, ancestors, hocWrappers) {
113
147
  if (node.id && typeof node.id.name === "string") {
114
148
  return node.id.name;
115
149
  }
@@ -132,14 +166,35 @@ function getFunctionLabel(node, ancestors) {
132
166
  if (parent.type === "AssignmentExpression" && parent.left?.type === "Identifier") {
133
167
  return parent.left.name;
134
168
  }
169
+ if (parent.type === "CallExpression") {
170
+ let idx = ancestors.length - 2;
171
+ let matchedHoc = false;
172
+ while (idx >= 0 && ancestors[idx].type === "CallExpression") {
173
+ if (isHocCall(ancestors[idx], hocWrappers)) {
174
+ matchedHoc = true;
175
+ idx--;
176
+ } else {
177
+ break;
178
+ }
179
+ }
180
+ if (matchedHoc && idx >= 0) {
181
+ const outer = ancestors[idx];
182
+ if (outer.type === "VariableDeclarator" && outer.id?.type === "Identifier") {
183
+ return outer.id.name;
184
+ }
185
+ if (outer.type === "AssignmentExpression" && outer.left?.type === "Identifier") {
186
+ return outer.left.name;
187
+ }
188
+ }
189
+ }
135
190
  }
136
191
  return `anonymous_${node.start}`;
137
192
  }
138
193
  function isPascalCaseComponent(name) {
139
194
  return /^[A-Z][a-zA-Z0-9]*$/.test(name);
140
195
  }
141
- function isEventHandlerName(name) {
142
- return /^(?:on|handle)[A-Z]/.test(name);
196
+ function isEventHandlerName(name, regex = DEFAULT_EVENT_HANDLER_REGEX) {
197
+ return regex.test(name);
143
198
  }
144
199
  function findEnclosingScopeNode(ancestors, selfNode) {
145
200
  for (let i = ancestors.length - 1; i >= 0; i--) {
@@ -181,7 +236,7 @@ function isZeroArgIifeFactoryFunction(node) {
181
236
  const callee = retArg.callee;
182
237
  return callee && (callee.type === "FunctionExpression" || callee.type === "ArrowFunctionExpression") && callee.body?.type === "BlockStatement";
183
238
  }
184
- function containsLoopOrAnimation(fnNode) {
239
+ function containsLoopOrAnimation(fnNode, animationCalls = ANIMATION_FRAME_CALLS) {
185
240
  let found = false;
186
241
  walk.simple(fnNode, {
187
242
  ForStatement() {
@@ -208,14 +263,14 @@ function containsLoopOrAnimation(fnNode) {
208
263
  mProp = callNode.callee.property.name;
209
264
  }
210
265
  const isTickerAdd = mProp === "add" && (callNode.callee?.object?.name === "ticker" || callNode.callee?.object?.property?.name === "ticker");
211
- if (ANIMATION_FRAME_CALLS.has(cName) || ANIMATION_FRAME_CALLS.has(mProp) || isTickerAdd) {
266
+ if (animationCalls.has(cName) || animationCalls.has(mProp) || isTickerAdd) {
212
267
  found = true;
213
268
  }
214
269
  }
215
270
  });
216
271
  return found;
217
272
  }
218
- function analyzeAstHotPaths(ast) {
273
+ function analyzeAstHotPaths(ast, config) {
219
274
  const hotFunctionNodes = /* @__PURE__ */ new WeakSet();
220
275
  const coldFunctionNodes = /* @__PURE__ */ new WeakSet();
221
276
  const hotExemptNodes = /* @__PURE__ */ new WeakSet();
@@ -236,6 +291,59 @@ function analyzeAstHotPaths(ast) {
236
291
  const pendingSerializedRefs = [];
237
292
  const pendingHotRefs = [];
238
293
  const allCallSites = [];
294
+ const animationCalls = new Set(ANIMATION_FRAME_CALLS);
295
+ if (config?.hotPath?.customAnimationCalls) {
296
+ for (const c of config.hotPath.customAnimationCalls) {
297
+ animationCalls.add(c);
298
+ }
299
+ }
300
+ const mergedImportSources = {
301
+ ...DEFAULT_IMPORT_SOURCES,
302
+ ...config?.hotPath?.importSources ?? {}
303
+ };
304
+ if (ast && Array.isArray(ast.body)) {
305
+ for (const stmt of ast.body) {
306
+ if (stmt.type === "ImportDeclaration" && stmt.source?.value) {
307
+ const sourcePkg = String(stmt.source.value);
308
+ const sourceMethods = mergedImportSources[sourcePkg];
309
+ for (const spec of stmt.specifiers || []) {
310
+ if (spec.type === "ImportSpecifier") {
311
+ const importedName = spec.imported?.name ?? spec.imported?.value;
312
+ const localName = spec.local?.name;
313
+ if (localName && importedName) {
314
+ const isKnownSource = sourceMethods !== void 0;
315
+ const isListedMethod = sourceMethods && (sourceMethods.includes(importedName) || sourceMethods.includes("*"));
316
+ const isKnownAnimCall = ANIMATION_FRAME_CALLS.has(importedName);
317
+ if (isKnownSource && isListedMethod || isKnownAnimCall) {
318
+ animationCalls.add(localName);
319
+ }
320
+ }
321
+ }
322
+ }
323
+ }
324
+ }
325
+ }
326
+ const hocWrappers = new Set(DEFAULT_HOC_WRAPPERS);
327
+ if (config?.hotPath?.hocWrappers) {
328
+ for (const h of config.hotPath.hocWrappers) {
329
+ hocWrappers.add(h);
330
+ }
331
+ }
332
+ const arrayHofMethods = new Set(ARRAY_HOF_METHODS);
333
+ if (config?.hotPath?.arrayHofMethods) {
334
+ for (const m of config.hotPath.arrayHofMethods) {
335
+ arrayHofMethods.add(m);
336
+ }
337
+ }
338
+ const eventHandlerRegex = config?.hotPath?.eventHandlerRegex ?? DEFAULT_EVENT_HANDLER_REGEX;
339
+ const hookRegex = config?.hotPath?.hookPattern ?? DEFAULT_HOOK_REGEX;
340
+ const customHooksSet = new Set(config?.hotPath?.customHooks ?? []);
341
+ function isHookName(name) {
342
+ if (!name) return false;
343
+ return customHooksSet.has(name) || hookRegex.test(name);
344
+ }
345
+ const excludedComponents = new Set(config?.hotPath?.excludeComponents ?? []);
346
+ const maxPipelineCallers = config?.hotPath?.maxPipelineCallers ?? 2;
239
347
  function ensureFnParams(fnNode) {
240
348
  let paramSet = fnParams.get(fnNode);
241
349
  if (!paramSet) {
@@ -278,7 +386,7 @@ function analyzeAstHotPaths(ast) {
278
386
  hotExemptNodes.add(node);
279
387
  }
280
388
  function registerFunctionNode(node, ancestors) {
281
- const name = getFunctionLabel(node, ancestors);
389
+ const name = getFunctionLabel(node, ancestors, hocWrappers);
282
390
  allFunctions.push({ node, name });
283
391
  fnByName.set(name, node);
284
392
  const paramSet = /* @__PURE__ */ new Set();
@@ -328,7 +436,13 @@ function analyzeAstHotPaths(ast) {
328
436
  }
329
437
  }
330
438
  fnScopeChain.set(node, chain);
331
- if (isPascalCaseComponent(name)) {
439
+ if (isPascalCaseComponent(name) && !excludedComponents.has(name)) {
440
+ shallowComponentNodes.add(node);
441
+ hotFunctionNodes.add(node);
442
+ directHotNodes.add(node);
443
+ hotExemptNodes.add(node);
444
+ }
445
+ if (isHookName(name)) {
332
446
  shallowComponentNodes.add(node);
333
447
  hotFunctionNodes.add(node);
334
448
  directHotNodes.add(node);
@@ -464,7 +578,7 @@ function analyzeAstHotPaths(ast) {
464
578
  callerToCallees.set(enclosingFn, set);
465
579
  }
466
580
  if (qualifiedCall) set.add(qualifiedCall);
467
- if (memberProp && !ARRAY_HOF_METHODS.has(memberProp)) {
581
+ if (memberProp && !arrayHofMethods.has(memberProp)) {
468
582
  set.add(memberProp);
469
583
  }
470
584
  }
@@ -501,7 +615,7 @@ function analyzeAstHotPaths(ast) {
501
615
  if (outerFn) markSerializedFunction(outerFn);
502
616
  }
503
617
  const isTickerAdd = memberProp === "add" && (callee?.object?.name === "ticker" || callee?.object?.property?.name === "ticker");
504
- if (ANIMATION_FRAME_CALLS.has(calleeName) || ANIMATION_FRAME_CALLS.has(memberProp) || isTickerAdd) {
618
+ if (animationCalls.has(calleeName) || animationCalls.has(memberProp) || isTickerAdd) {
505
619
  if (enclosingFn) {
506
620
  trueHotNodes.add(enclosingFn);
507
621
  hotFunctionNodes.add(enclosingFn);
@@ -523,7 +637,7 @@ function analyzeAstHotPaths(ast) {
523
637
  }
524
638
  }
525
639
  }
526
- if (ARRAY_HOF_METHODS.has(memberProp)) {
640
+ if (arrayHofMethods.has(memberProp)) {
527
641
  if (enclosingFn !== null) {
528
642
  for (const arg of node.arguments || []) {
529
643
  if (FUNCTION_NODE_TYPES.has(arg.type)) {
@@ -541,7 +655,8 @@ function analyzeAstHotPaths(ast) {
541
655
  }
542
656
  } else {
543
657
  for (const arg of node.arguments || []) {
544
- if (FUNCTION_NODE_TYPES.has(arg.type)) {
658
+ const isAnonymousFunction = arg.type === "FunctionExpression" && !arg.id || arg.type === "ArrowFunctionExpression";
659
+ if (isAnonymousFunction) {
545
660
  coldForcedNodes.add(arg);
546
661
  }
547
662
  }
@@ -550,11 +665,11 @@ function analyzeAstHotPaths(ast) {
550
665
  if (calleeName === "useEffect" || memberProp === "useEffect" || calleeName === "useLayoutEffect" || memberProp === "useLayoutEffect") {
551
666
  const effectArg = node.arguments?.[0];
552
667
  if (effectArg && FUNCTION_NODE_TYPES.has(effectArg.type)) {
553
- if (!containsLoopOrAnimation(effectArg)) {
668
+ if (!containsLoopOrAnimation(effectArg, animationCalls)) {
554
669
  coldForcedNodes.add(effectArg);
555
670
  if (effectArg.body?.type === "BlockStatement") {
556
671
  for (const s of effectArg.body.body || []) {
557
- if (s.type === "ReturnStatement" && s.argument && FUNCTION_NODE_TYPES.has(s.argument.type) && !containsLoopOrAnimation(s.argument)) {
672
+ if (s.type === "ReturnStatement" && s.argument && FUNCTION_NODE_TYPES.has(s.argument.type) && !containsLoopOrAnimation(s.argument, animationCalls)) {
558
673
  coldForcedNodes.add(s.argument);
559
674
  }
560
675
  }
@@ -562,7 +677,7 @@ function analyzeAstHotPaths(ast) {
562
677
  }
563
678
  }
564
679
  }
565
- if (REACT_HOOK_OR_RENDER_CALLS.has(calleeName) || REACT_HOOK_OR_RENDER_CALLS.has(memberProp)) {
680
+ if (REACT_HOOK_OR_RENDER_CALLS.has(calleeName) || REACT_HOOK_OR_RENDER_CALLS.has(memberProp) || isHookName(calleeName) || isHookName(memberProp)) {
566
681
  if (enclosingFn) {
567
682
  shallowComponentNodes.add(enclosingFn);
568
683
  hotFunctionNodes.add(enclosingFn);
@@ -641,9 +756,11 @@ function analyzeAstHotPaths(ast) {
641
756
  }
642
757
  }
643
758
  for (const fn of allFunctions) {
644
- if (!trueHotNodes.has(fn.node) && !containsLoopOrAnimation(fn.node)) {
645
- if (fn.node.async === true || isEventHandlerName(fn.name)) {
646
- coldForcedNodes.add(fn.node);
759
+ if (!trueHotNodes.has(fn.node) && !containsLoopOrAnimation(fn.node, animationCalls)) {
760
+ if (!shallowComponentNodes.has(fn.node)) {
761
+ if (fn.node.async === true || isEventHandlerName(fn.name, eventHandlerRegex)) {
762
+ coldForcedNodes.add(fn.node);
763
+ }
647
764
  }
648
765
  }
649
766
  }
@@ -733,7 +850,7 @@ function analyzeAstHotPaths(ast) {
733
850
  const targetNode = resolveCalleeNode(callerNode, cName);
734
851
  if (targetNode && trueHotNodes.has(targetNode)) {
735
852
  const callers = calleeToCallers.get(targetNode);
736
- const isDedicatedPipeline = callers && callers.size <= 2;
853
+ const isDedicatedPipeline = callers && callers.size <= maxPipelineCallers;
737
854
  if (isDedicatedPipeline) {
738
855
  trueHotNodes.add(callerNode);
739
856
  hotFunctionNodes.add(callerNode);
@@ -771,7 +888,7 @@ function analyzeAstHotPaths(ast) {
771
888
  serializedFunctionNodes
772
889
  };
773
890
  }
774
- function detectHotPaths(code) {
891
+ function detectHotPaths(code, config) {
775
892
  const ast = parseJavaScriptAst(code);
776
893
  if (!ast) {
777
894
  return {
@@ -780,7 +897,7 @@ function detectHotPaths(code) {
780
897
  coldFunctionsProtected: []
781
898
  };
782
899
  }
783
- return analyzeAstHotPaths(ast).report;
900
+ return analyzeAstHotPaths(ast, config).report;
784
901
  }
785
902
 
786
903
  // src/ast/string-vault.ts
@@ -1158,7 +1275,7 @@ function createDeterrentSnippet(config) {
1158
1275
  const fnName = deriveIntegrityFnName(seed);
1159
1276
  const sym = config.windowKeySymbol ?? deriveWindowKeySymbol(seed);
1160
1277
  const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=function(){return 0;};" : "";
1161
- return `(function ${fnName}(w){if(w){try{var s=Function.prototype.toString,n=w.navigator||0,src=s.call(${fnName}),t=s.call(s).indexOf('[native code]')<0||/\\n/.test(src)||n.webdriver||/HeadlessChrome/.test(n.userAgent);for(var h=0x811c9dc5,i=0;i<src.length;i++)h=Math.imul(h^src.charCodeAt(i),0x01000193)>>>0;var d=(h&31);if(t){w.__unpeek_tampered=!0;w.__unpeek_seed=((w.__unpeek_seed||${seed})^1)>>>0;String.prototype._u=14;w['${sym}']=d^29;try{${consoleSilence}w.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(e){}}else{w['${sym}']=d;}}catch(e){}}})(typeof window!=='undefined'&&window);`;
1278
+ return `(function ${fnName}(w){var G=typeof globalThis!=='undefined'?globalThis:(typeof window!=='undefined'?window:(typeof self!=='undefined'?self:this));if(w){try{var s=Function.prototype.toString,n=w.navigator||0,src=s.call(${fnName}),t=s.call(s).indexOf('[native code]')<0||/\\n/.test(src)||n.webdriver||/HeadlessChrome/.test(n.userAgent);for(var h=0x811c9dc5,i=0;i<src.length;i++)h=Math.imul(h^src.charCodeAt(i),0x01000193)>>>0;var d=(h&31);if(t){G.__unpeek_tampered=w.__unpeek_tampered=!0;G.__unpeek_seed=w.__unpeek_seed=((w.__unpeek_seed||${seed})^1)>>>0;String.prototype._u=14;G['${sym}']=w['${sym}']=d^29;G.__unpeek_delta=w.__unpeek_delta=d^29;try{${consoleSilence}if(typeof w.dispatchEvent==='function')w.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(e){}}else{G['${sym}']=w['${sym}']=d;}}catch(e){}}})(typeof window!=='undefined'?window:(typeof self!=='undefined'?self:0));`;
1162
1279
  }
1163
1280
 
1164
1281
  // src/runtime/index.ts
@@ -1171,7 +1288,8 @@ function generateRuntimeShield(config) {
1171
1288
  windowKeySymbol
1172
1289
  });
1173
1290
  const fnStart = preambleCode.indexOf("function");
1174
- const fnEnd = preambleCode.lastIndexOf("(") - 1;
1291
+ const endMarker = preambleCode.indexOf("})(");
1292
+ const fnEnd = endMarker !== -1 ? endMarker + 1 : preambleCode.lastIndexOf("(") - 1;
1175
1293
  const fnDecl = preambleCode.slice(fnStart, fnEnd);
1176
1294
  const computedHash = computeIntegrityHash(fnDecl, 0);
1177
1295
  const expectedHash = config.expectedIntegrityHash !== void 0 ? config.expectedIntegrityHash >>> 0 : computedHash;
@@ -1389,17 +1507,11 @@ try {
1389
1507
  }
1390
1508
 
1391
1509
  // src/ast/salted-vault.ts
1392
- var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
1393
- "use strict",
1394
- "use client",
1395
- "use server",
1396
- "use asm"
1397
- ]);
1398
1510
  function computeCallSiteSalt(seed, idx) {
1399
1511
  return ((seed & 15 ^ idx * 5 + 3) & 31) >>> 0;
1400
1512
  }
1401
1513
  function createSaltedDecryptorFnAst(seed, pChars, expectedDelta, windowKeySymbol, safeAlpha = SAFE_ALPHA) {
1402
- const fBody = `var memo=[];var s=Function.prototype.toString,w=typeof window!=='undefined'&&window,src=s.call(f);for(var h=0x811c9dc5,j=0;j<src.length;j++)h=Math.imul(h^src.charCodeAt(j),0x01000193)>>>0;var rot=(h^((""._u||a._u||0))^(w?(w['${windowKeySymbol}']!=null?w['${windowKeySymbol}']:0):${expectedDelta}))&31;var A="${safeAlpha}",P="${pChars}";return function(i,s){if(memo[i]!==void 0)return memo[i];var p=a[i];if(!p)return "";var o="";for(var j=0;j<p.length;j++){var c=p.charAt(j),k=A.indexOf(c);if(k<0){o+=c;}else{var y=(k-s+rot+9200)%92;var z=A.indexOf(P.charAt(y));o+=A.charAt((z-rot+9200)%92);}}return(memo[i]=o);};`;
1514
+ const fBody = `var memo=[],s=Function.prototype.toString,G=typeof globalThis!=='undefined'?globalThis:(typeof window!=='undefined'?window:(typeof self!=='undefined'?self:this)),w=typeof window!=='undefined'?window:(typeof self!=='undefined'?self:0),src=s.call(f);for(var h=0x811c9dc5,j=0;j<src.length;j++)h=Math.imul(h^src.charCodeAt(j),0x01000193)>>>0;var delta=G['${windowKeySymbol}']!=null?G['${windowKeySymbol}']:(w?0:${expectedDelta}),rot=(h^((""._u||a._u||0))^delta)&31,A="${safeAlpha}",P="${pChars}";return function(i,s){if(memo[i]!==void 0)return memo[i];var p=a[i],o="";if(!p)return "";for(var j=0;j<p.length;j++){var c=p.charAt(j),k=A.indexOf(c);if(k<0)o+=c;else{var y=(k-s+rot+9200)%92;o+=A.charAt((A.indexOf(P.charAt(y))-rot+9200)%92);}}return(memo[i]=o);};`;
1403
1515
  return acorn3.parse(`(function f(a){${fBody}})`, {
1404
1516
  ecmaVersion: "latest",
1405
1517
  sourceType: "script"
@@ -1470,7 +1582,7 @@ function replaceNodeInParent(parent, oldNode, newNode) {
1470
1582
  }
1471
1583
  return false;
1472
1584
  }
1473
- function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes) {
1585
+ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, config) {
1474
1586
  if (isAstAlreadySalted(ast)) {
1475
1587
  return {
1476
1588
  encryptedStringsCount: 0,
@@ -1479,16 +1591,32 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
1479
1591
  decryptFnName: ""
1480
1592
  };
1481
1593
  }
1594
+ const minLen = config?.vault?.minStringLength ?? minStringLength;
1595
+ const activeDirectives = new Set(DIRECTIVE_STRINGS);
1596
+ if (config?.vault?.customDirectives) {
1597
+ for (const dir of config.vault.customDirectives) {
1598
+ activeDirectives.add(dir);
1599
+ }
1600
+ }
1601
+ const customReserved = config?.vault?.reservedProps ? new Set(config.vault.reservedProps) : void 0;
1482
1602
  const targetsToReplace = [];
1483
1603
  const encryptedPayloads = [];
1484
1604
  walk2.ancestor(ast, {
1485
1605
  Literal(node, ancestors) {
1486
1606
  if (typeof node.value !== "string") return;
1487
- if (node.value.length < minStringLength) return;
1488
- if (DIRECTIVE_STRINGS.has(node.value)) return;
1607
+ if (node.value.length < minLen) return;
1608
+ if (activeDirectives.has(node.value)) return;
1489
1609
  const parent = ancestors[ancestors.length - 2];
1490
1610
  if (!parent) return;
1491
- if ((parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration") && parent.source === node) {
1611
+ if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(node.value))) {
1612
+ return;
1613
+ }
1614
+ for (let i = ancestors.length - 2; i >= 0; i--) {
1615
+ if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
1616
+ return;
1617
+ }
1618
+ }
1619
+ if ((parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") && parent.source === node) {
1492
1620
  return;
1493
1621
  }
1494
1622
  if (parent.type === "Property" && parent.key === node && !parent.computed) {
@@ -1504,6 +1632,9 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
1504
1632
  }
1505
1633
  }
1506
1634
  }
1635
+ if (isReservedProp(node.value, customReserved)) return;
1636
+ if (isTailwindNoise(node.value)) return;
1637
+ if (isSvgPathString(node.value, parent)) return;
1507
1638
  const callSiteIdx = targetsToReplace.length;
1508
1639
  const localSalt = computeFnv1aHash(`salt:${seed}:${callSiteIdx}`, seed) & 2147483647 | 1;
1509
1640
  targetsToReplace.push({
@@ -1556,11 +1687,13 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
1556
1687
  }
1557
1688
  const serializedTable = JSON.stringify(encryptedPayloads);
1558
1689
  const integrityToken = computeFnv1aHash(serializedTable, seed);
1690
+ const sym = deriveWindowKeySymbol(seed);
1559
1691
  const helperSnippet = `var ${vaultVarName} = ${serializedTable};
1560
1692
  var ${cacheVarName} = [];
1561
1693
  function ${decryptFnName}(i, s) {
1562
1694
  if (${cacheVarName}[i] !== void 0) return ${cacheVarName}[i];
1563
- var d = typeof window !== 'undefined' && window.__unpeek_delta != null ? window.__unpeek_delta : 0;
1695
+ var G = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : (typeof self !== 'undefined' ? self : this));
1696
+ var d = G && G.__unpeek_delta != null ? G.__unpeek_delta : 0;
1564
1697
  var k = ${kdfFnName}(i, s, d);
1565
1698
  var p = ${vaultVarName}[i], o = '';
1566
1699
  for (var j = 0; j < p.length; j++) {
@@ -1572,7 +1705,17 @@ function ${decryptFnName}(i, s) {
1572
1705
  ecmaVersion: "latest",
1573
1706
  sourceType: "script"
1574
1707
  });
1575
- ast.body.unshift(...parsedHelper.body);
1708
+ let insertIdx = 0;
1709
+ while (insertIdx < ast.body.length) {
1710
+ const stmt = ast.body[insertIdx];
1711
+ const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" && (activeDirectives.has(stmt.expression.value) || /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim())));
1712
+ if (isDirective || stmt.type === "ImportDeclaration") {
1713
+ insertIdx++;
1714
+ } else {
1715
+ break;
1716
+ }
1717
+ }
1718
+ ast.body.splice(insertIdx, 0, ...parsedHelper.body);
1576
1719
  return {
1577
1720
  encryptedStringsCount: targetsToReplace.length,
1578
1721
  integrityToken,
@@ -1583,11 +1726,15 @@ function ${decryptFnName}(i, s) {
1583
1726
 
1584
1727
  // src/ast/string-vault.ts
1585
1728
  var SAFE_ALPHA = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~";
1586
- var DIRECTIVE_STRINGS2 = /* @__PURE__ */ new Set([
1729
+ var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
1587
1730
  "use strict",
1588
1731
  "use client",
1589
1732
  "use server",
1590
- "use asm"
1733
+ "use asm",
1734
+ "use cache",
1735
+ "use worklet",
1736
+ "use worker",
1737
+ "use memo"
1591
1738
  ]);
1592
1739
  var STANDARD_PROP_KEYS = /* @__PURE__ */ new Set([
1593
1740
  "id",
@@ -1603,8 +1750,22 @@ var STANDARD_PROP_KEYS = /* @__PURE__ */ new Set([
1603
1750
  "href",
1604
1751
  "alt",
1605
1752
  "role",
1606
- "tabIndex"
1753
+ "tabIndex",
1754
+ "class",
1755
+ "part",
1756
+ "slot",
1757
+ "is",
1758
+ "innerHTML",
1759
+ "disabled",
1760
+ "title"
1607
1761
  ]);
1762
+ var STANDARD_PROP_PREFIX_RE = /^(?:data-|aria-|on[A-Z]|v-|bind:)/;
1763
+ function isReservedProp(propName, customReserved) {
1764
+ if (STANDARD_PROP_KEYS.has(propName)) return true;
1765
+ if (customReserved && customReserved.has(propName)) return true;
1766
+ if (STANDARD_PROP_PREFIX_RE.test(propName)) return true;
1767
+ return false;
1768
+ }
1608
1769
  var LOOP_NODE_TYPES = /* @__PURE__ */ new Set([
1609
1770
  "ForStatement",
1610
1771
  "ForInStatement",
@@ -1612,45 +1773,104 @@ var LOOP_NODE_TYPES = /* @__PURE__ */ new Set([
1612
1773
  "WhileStatement",
1613
1774
  "DoWhileStatement"
1614
1775
  ]);
1615
- function isReactDomSpecialProp(val, node, parent) {
1616
- if (STANDARD_PROP_KEYS.has(val)) return true;
1776
+ function isReactDomSpecialProp(val, node, parent, customReserved) {
1777
+ if (isReservedProp(val, customReserved)) return true;
1617
1778
  if (!parent) return false;
1618
1779
  if (parent.type === "Property") {
1619
1780
  if (parent.key === node && !parent.computed) {
1620
1781
  return true;
1621
1782
  }
1622
1783
  const keyName = parent.key?.type === "Identifier" ? parent.key.name : parent.key?.type === "Literal" ? String(parent.key.value) : "";
1623
- if (keyName && STANDARD_PROP_KEYS.has(keyName)) {
1784
+ if (keyName && isReservedProp(keyName, customReserved)) {
1624
1785
  return true;
1625
1786
  }
1626
1787
  }
1627
1788
  return false;
1628
1789
  }
1790
+ var TAILWIND_TOKEN_RE = /^(?:flex|grid|block|inline|hidden|relative|absolute|fixed|w-|h-|min-|max-|p[xytrbl]?-|m[xytrbl]?-|space-[xy]-|text-|font-|bg-|border|rounded|shadow|ring|outline|transition|duration|opacity|cursor|pointer-events|select-|items-|justify-|gap-|overflow-|z-|inset-|top-|left-|right-|bottom-|hover:|focus:|focus-visible:|disabled:|dark:|data-\[|aria-|\[&_)/;
1791
+ var TAILWIND_VARIANT_PREFIX_RE = /^(?:[a-zA-Z0-9_@-]+:)+/;
1792
+ function stripTailwindVariants(token) {
1793
+ return token.replace(TAILWIND_VARIANT_PREFIX_RE, "");
1794
+ }
1629
1795
  function isTailwindNoise(val) {
1630
1796
  const trimmed = val.trim();
1631
1797
  if (!trimmed) return false;
1798
+ const isMatch = (t) => {
1799
+ const stripped = stripTailwindVariants(t);
1800
+ return TAILWIND_TOKEN_RE.test(stripped) || stripped.startsWith("btn") || stripped.startsWith("p-") || stripped.startsWith("m-");
1801
+ };
1632
1802
  if (trimmed.includes(" ")) {
1633
1803
  const tokens = trimmed.split(/\s+/);
1634
1804
  let twHits = 0;
1635
1805
  for (const t of tokens) {
1636
- if (TAILWIND_TOKEN_RE.test(t) || t.startsWith("btn") || t.startsWith("p-") || t.startsWith("m-")) {
1806
+ if (isMatch(t)) {
1637
1807
  twHits++;
1638
1808
  }
1639
1809
  }
1640
1810
  if (twHits / tokens.length >= 0.5) return true;
1641
1811
  } else {
1642
- if (TAILWIND_TOKEN_RE.test(trimmed)) return true;
1812
+ if (isMatch(trimmed)) return true;
1643
1813
  }
1644
1814
  return false;
1645
1815
  }
1646
- function isSvgPathString(val) {
1647
- return SVG_PATH_RE.test(val) || /^M\s*[-+]?\d*\.?\d+(?:[\s,]+[-+]?\d*\.?\d+)*[a-df-z]/i.test(val) || val.length > 15 && (/^M\s*[-+]?\d/i.test(val.trim()) || /[Mm]\s*[-+]?\d.*[a-df-z]/i.test(val));
1816
+ function isParentSvgPathProperty(parent) {
1817
+ if (!parent) return false;
1818
+ if (parent.type === "Property") {
1819
+ const keyName = parent.key?.type === "Identifier" ? parent.key.name : parent.key?.type === "Literal" ? String(parent.key.value) : "";
1820
+ if (keyName === "d" || keyName === "path") return true;
1821
+ }
1822
+ if (parent.type === "JSXAttribute") {
1823
+ const attrName = parent.name?.name;
1824
+ if (attrName === "d" || attrName === "path") return true;
1825
+ }
1826
+ return false;
1827
+ }
1828
+ function isSvgPathString(val, parent) {
1829
+ if (typeof val !== "string" || val.length < 4) return false;
1830
+ const trimmed = val.trim();
1831
+ if (!/^[Mm]\s*[-+]?(?:\d*\.\d+|\d+)/.test(trimmed)) {
1832
+ return false;
1833
+ }
1834
+ if (parent && isParentSvgPathProperty(parent)) {
1835
+ return true;
1836
+ }
1837
+ return /[zZ]$/.test(trimmed) || /[Mm]\s*[-+]?\d.*[a-df-zA-DF-Z]\s*[-+]?\d/.test(trimmed) || /^[Mm]\s*[-+]?\d+(?:\.\d+)?[\s,]+-?\d+(?:\.\d+)?(?:\s+[a-zA-Z][-+]?\d+.*)?$/.test(
1838
+ trimmed
1839
+ );
1840
+ }
1841
+ var DEFAULT_SEMANTIC_ANCHOR_RE = /(?:\bapi\/|\bcheckout\b|\badmin\b|\bauth\b|\btoken\b|\bcredential\b|\bsecret\b|\bpassword\b|\bbearer\b)/i;
1842
+ function isUiClassName(val, parent) {
1843
+ if (parent) {
1844
+ if (parent.type === "Property") {
1845
+ const k = parent.key?.type === "Identifier" ? parent.key.name : parent.key?.type === "Literal" ? String(parent.key.value) : "";
1846
+ if (k === "className" || k === "class" || k === "classList") return true;
1847
+ }
1848
+ if (parent.type === "JSXAttribute") {
1849
+ const name = parent.name?.name;
1850
+ if (name === "className" || name === "class") return true;
1851
+ }
1852
+ }
1853
+ if (isTailwindNoise(val)) return true;
1854
+ if (/^[a-z0-9_-]+(?:\s+[a-z0-9_-]+)+$/i.test(val.trim())) {
1855
+ return true;
1856
+ }
1857
+ return false;
1648
1858
  }
1649
- function isEligibleHotLiteral(val, node, parent, ancestors, minLen) {
1650
- if (val.length < minLen || DIRECTIVE_STRINGS2.has(val)) return false;
1651
- if (isReactDomSpecialProp(val, node, parent)) return false;
1859
+ function isAdversaryDecoy(val, seed) {
1860
+ if (val.startsWith("/api/v2/auth/") || val === "superadmin_token" || val === "elevate" || val === "_verifyMasterToken" || val === "mock_jwt_bypass_signature" || val === "debug_supervisor_override" || val.startsWith("_decoy_") || val.startsWith("_auth_bypass_")) {
1861
+ return true;
1862
+ }
1863
+ const s = (seed >>> 0 & 65535).toString(36);
1864
+ if (val.includes(s) && (val.includes("auth") || val.includes("token") || val.includes("decoy") || val.includes("elevate"))) {
1865
+ return true;
1866
+ }
1867
+ return false;
1868
+ }
1869
+ function isEligibleHotLiteral(val, node, parent, ancestors, minLen, seed = 2654435769, customReserved, activeDirectives = DIRECTIVE_STRINGS, semanticAnchorPatterns, excludeUiClasses = true) {
1870
+ if (val.length < minLen || activeDirectives.has(val)) return false;
1871
+ if (isReactDomSpecialProp(val, node, parent, customReserved)) return false;
1652
1872
  if (isTailwindNoise(val)) return false;
1653
- if (isSvgPathString(val)) return false;
1873
+ if (isSvgPathString(val, parent)) return false;
1654
1874
  for (let i = ancestors.length - 2; i >= 0; i--) {
1655
1875
  if (LOOP_NODE_TYPES.has(ancestors[i].type)) {
1656
1876
  return false;
@@ -1662,9 +1882,15 @@ function isEligibleHotLiteral(val, node, parent, ancestors, minLen) {
1662
1882
  }
1663
1883
  }
1664
1884
  if (val.startsWith("HOT_")) return false;
1665
- const isSemanticAnchor = /(?:api\/|checkout|admin|auth|token|credential|secret|password|bearer)/i.test(
1666
- val
1667
- );
1885
+ let isSemanticAnchor = false;
1886
+ if (semanticAnchorPatterns && semanticAnchorPatterns.length > 0) {
1887
+ isSemanticAnchor = semanticAnchorPatterns.some((re) => re.test(val));
1888
+ } else {
1889
+ isSemanticAnchor = DEFAULT_SEMANTIC_ANCHOR_RE.test(val);
1890
+ }
1891
+ if (isSemanticAnchor && excludeUiClasses && isUiClassName(val, parent)) {
1892
+ isSemanticAnchor = false;
1893
+ }
1668
1894
  let isInsideRender = false;
1669
1895
  for (let i = ancestors.length - 2; i >= 0; i--) {
1670
1896
  const a = ancestors[i];
@@ -1680,7 +1906,7 @@ function isEligibleHotLiteral(val, node, parent, ancestors, minLen) {
1680
1906
  }
1681
1907
  }
1682
1908
  if (!isSemanticAnchor && !isInsideRender) return false;
1683
- if (val.startsWith("/api/v2/auth/") || val === "superadmin_token" || val === "elevate" || val === "_verifyMasterToken" || val === "mock_jwt_bypass_signature" || val === "debug_supervisor_override") {
1909
+ if (isAdversaryDecoy(val, seed)) {
1684
1910
  return false;
1685
1911
  }
1686
1912
  if (parent) {
@@ -1696,22 +1922,12 @@ function isEligibleHotLiteral(val, node, parent, ancestors, minLen) {
1696
1922
  }
1697
1923
  return true;
1698
1924
  }
1699
- var TAILWIND_TOKEN_RE = /^(?:flex|grid|block|inline|hidden|relative|absolute|fixed|w-|h-|min-|max-|p[xytrbl]?-|m[xytrbl]?-|space-[xy]-|text-|font-|bg-|border|rounded|shadow|ring|outline|transition|duration|opacity|cursor|pointer-events|select-|items-|justify-|gap-|overflow-|z-|inset-|top-|left-|right-|bottom-|hover:|focus:|focus-visible:|disabled:|dark:|data-\[|aria-|\[&_)/;
1700
- var SVG_PATH_RE = /^[Mm]\s*-?\d+(?:\.\d+)?[\s,]+-?\d+/;
1701
1925
  var SHADER_SIG_RE = /@group|@binding|@vertex|@fragment|@compute|vec4f|gl_Position|uniform/;
1702
- function shouldEncryptString(val, minLen) {
1703
- if (val.length < minLen || DIRECTIVE_STRINGS2.has(val)) return false;
1704
- if (SVG_PATH_RE.test(val)) return false;
1705
- if (val.includes(" ")) {
1706
- const tokens = val.trim().split(/\s+/);
1707
- if (tokens.length >= 3) {
1708
- let twHits = 0;
1709
- for (const t of tokens) {
1710
- if (TAILWIND_TOKEN_RE.test(t)) twHits++;
1711
- }
1712
- if (twHits / tokens.length >= 0.5) return false;
1713
- }
1714
- }
1926
+ function shouldEncryptString(val, minLen, parent, activeDirectives = DIRECTIVE_STRINGS, customReserved) {
1927
+ if (val.length < minLen || activeDirectives.has(val)) return false;
1928
+ if (isReservedProp(val, customReserved)) return false;
1929
+ if (isSvgPathString(val, parent)) return false;
1930
+ if (isTailwindNoise(val)) return false;
1715
1931
  return true;
1716
1932
  }
1717
1933
  function computeFnv1aHash(input, seed = 2166136261) {
@@ -1782,7 +1998,17 @@ function createShaderVaultAst(shaderVarName, shaderPayloads, seed) {
1782
1998
  )};var k=${key};var b=B.map(function(s){var bin=typeof atob==='function'?atob(s):(typeof Buffer!=='undefined'?Buffer.from(s,'base64').toString('binary'):'');var u=new Uint8Array(bin.length);for(var i=0;i<bin.length;i++)u[i]=bin.charCodeAt(i);return u;});var d=typeof TextDecoder!=='undefined'?new TextDecoder():null;return function(i){var u=b[i];for(var j=0;j<u.length;j++)u[j]^=k;try{return d?d.decode(u):String.fromCharCode.apply(null,u);}finally{for(var j=0;j<u.length;j++)u[j]^=k;}};})();`;
1783
1999
  return acorn4.parse(shaderCode, { ecmaVersion: "latest", sourceType: "script" }).body[0];
1784
2000
  }
1785
- function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta, deterrentMode) {
2001
+ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta, deterrentMode, config) {
2002
+ const minLen = config?.vault?.minStringLength ?? minStringLength;
2003
+ const activeDirectives = new Set(DIRECTIVE_STRINGS);
2004
+ if (config?.vault?.customDirectives) {
2005
+ for (const dir of config.vault.customDirectives) {
2006
+ activeDirectives.add(dir);
2007
+ }
2008
+ }
2009
+ const customReserved = config?.vault?.reservedProps ? new Set(config.vault.reservedProps) : void 0;
2010
+ const semanticPatterns = config?.vault?.semanticAnchors?.patterns;
2011
+ const excludeUi = config?.vault?.semanticAnchors?.excludeUiClasses !== false;
1786
2012
  const suffix = (seed >>> 0 & 65535).toString(36);
1787
2013
  const decryptFnName = `_uD${suffix}`;
1788
2014
  const cacheVarName = derivePolymorphicIdent(seed, "vault");
@@ -1839,7 +2065,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
1839
2065
  Literal(node, _state, ancestors) {
1840
2066
  if (typeof node.value !== "string") return;
1841
2067
  const val = node.value;
1842
- if (DIRECTIVE_STRINGS2.has(val)) return;
2068
+ if (activeDirectives.has(val)) return;
1843
2069
  let isHotExempt = false;
1844
2070
  if (hotExemptNodes) {
1845
2071
  for (let i = ancestors.length - 2; i >= 0; i--) {
@@ -1851,7 +2077,14 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
1851
2077
  }
1852
2078
  const parent = ancestors[ancestors.length - 2];
1853
2079
  if (!parent) return;
1854
- if (parent.type === "ExpressionStatement" && parent.directive) return;
2080
+ if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
2081
+ return;
2082
+ }
2083
+ for (let i = ancestors.length - 2; i >= 0; i--) {
2084
+ if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
2085
+ return;
2086
+ }
2087
+ }
1855
2088
  if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
1856
2089
  if (parent.source === node) return;
1857
2090
  }
@@ -1862,7 +2095,18 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
1862
2095
  return;
1863
2096
  }
1864
2097
  if (isHotExempt) {
1865
- if (isEligibleHotLiteral(val, node, parent, ancestors, minStringLength)) {
2098
+ if (isEligibleHotLiteral(
2099
+ val,
2100
+ node,
2101
+ parent,
2102
+ ancestors,
2103
+ minLen,
2104
+ seed,
2105
+ customReserved,
2106
+ activeDirectives,
2107
+ semanticPatterns,
2108
+ excludeUi
2109
+ )) {
1866
2110
  hotTargetsToReplace.push({
1867
2111
  node,
1868
2112
  parent,
@@ -1873,10 +2117,13 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
1873
2117
  return;
1874
2118
  }
1875
2119
  if (parent.type === "Property" && parent.key === node && !parent.computed) {
1876
- if (STANDARD_PROP_KEYS.has(val)) {
2120
+ if (isReservedProp(val, customReserved)) {
1877
2121
  return;
1878
2122
  }
1879
2123
  }
2124
+ if (isReservedProp(val, customReserved)) return;
2125
+ if (isTailwindNoise(val)) return;
2126
+ if (isSvgPathString(val, parent)) return;
1880
2127
  const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
1881
2128
  if (isShader) {
1882
2129
  let idx = shaderToIndex.get(val);
@@ -1887,7 +2134,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
1887
2134
  }
1888
2135
  targetsToReplace.push({ type: "shader", node, parent, idx });
1889
2136
  } else {
1890
- if (!shouldEncryptString(val, minStringLength)) return;
2137
+ if (!shouldEncryptString(val, minLen, parent, activeDirectives, customReserved)) return;
1891
2138
  let idx = stringToIndex.get(val);
1892
2139
  if (idx === void 0) {
1893
2140
  idx = encryptedPayloads.length;
@@ -1904,7 +2151,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
1904
2151
  if (!node.quasis || node.quasis.length !== 1) return;
1905
2152
  if (node.expressions && node.expressions.length !== 0) return;
1906
2153
  const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
1907
- if (typeof val !== "string" || DIRECTIVE_STRINGS2.has(val)) return;
2154
+ if (typeof val !== "string" || activeDirectives.has(val)) return;
1908
2155
  let isHotExempt = false;
1909
2156
  if (hotExemptNodes) {
1910
2157
  for (let i = ancestors.length - 2; i >= 0; i--) {
@@ -1916,8 +2163,27 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
1916
2163
  }
1917
2164
  const parent = ancestors[ancestors.length - 2];
1918
2165
  if (!parent) return;
2166
+ if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
2167
+ return;
2168
+ }
2169
+ for (let i = ancestors.length - 2; i >= 0; i--) {
2170
+ if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
2171
+ return;
2172
+ }
2173
+ }
1919
2174
  if (isHotExempt) {
1920
- if (isEligibleHotLiteral(val, node, parent, ancestors, minStringLength)) {
2175
+ if (isEligibleHotLiteral(
2176
+ val,
2177
+ node,
2178
+ parent,
2179
+ ancestors,
2180
+ minLen,
2181
+ seed,
2182
+ customReserved,
2183
+ activeDirectives,
2184
+ semanticPatterns,
2185
+ excludeUi
2186
+ )) {
1921
2187
  hotTargetsToReplace.push({
1922
2188
  node,
1923
2189
  parent,
@@ -1927,6 +2193,9 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
1927
2193
  }
1928
2194
  return;
1929
2195
  }
2196
+ if (isReservedProp(val, customReserved)) return;
2197
+ if (isTailwindNoise(val)) return;
2198
+ if (isSvgPathString(val, parent)) return;
1930
2199
  const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
1931
2200
  if (isShader) {
1932
2201
  let idx = shaderToIndex.get(val);
@@ -1937,7 +2206,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
1937
2206
  }
1938
2207
  targetsToReplace.push({ type: "shader", node, parent, idx });
1939
2208
  } else {
1940
- if (!shouldEncryptString(val, minStringLength)) return;
2209
+ if (!shouldEncryptString(val, minLen, parent, activeDirectives, customReserved)) return;
1941
2210
  let idx = stringToIndex.get(val);
1942
2211
  if (idx === void 0) {
1943
2212
  idx = encryptedPayloads.length;
@@ -2045,7 +2314,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
2045
2314
  let insertIdx = 0;
2046
2315
  while (insertIdx < ast.body.length) {
2047
2316
  const stmt = ast.body[insertIdx];
2048
- const isDirective = stmt.type === "ExpressionStatement" && (stmt.directive || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" && DIRECTIVE_STRINGS2.has(stmt.expression.value));
2317
+ const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" && (activeDirectives.has(stmt.expression.value) || /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim())));
2049
2318
  if (isDirective || stmt.type === "ImportDeclaration") {
2050
2319
  insertIdx++;
2051
2320
  } else {
@@ -2128,7 +2397,17 @@ var RESERVED_IDENTIFIERS = /* @__PURE__ */ new Set([
2128
2397
  "require",
2129
2398
  "module",
2130
2399
  "exports",
2131
- "React"
2400
+ "React",
2401
+ "navigator",
2402
+ "crypto",
2403
+ "location",
2404
+ "history",
2405
+ "indexedDB",
2406
+ "fetch",
2407
+ "WebSocket",
2408
+ "Worker",
2409
+ "AudioContext",
2410
+ "performance"
2132
2411
  ]);
2133
2412
  var FUNCTION_TYPES = /* @__PURE__ */ new Set([
2134
2413
  "FunctionDeclaration",
@@ -2181,10 +2460,17 @@ function collectPatternTargets(pattern, out, shorthandProp) {
2181
2460
  break;
2182
2461
  }
2183
2462
  }
2184
- function isMangleableName(origName) {
2185
- return origName.length > 2 && !RESERVED_IDENTIFIERS.has(origName) && !origName.startsWith("_u") && !origName.startsWith("_0x") && !origName.startsWith("$$");
2463
+ function isMangleableName(origName, reservedSet = RESERVED_IDENTIFIERS, manglerConfig) {
2464
+ return origName.length > 2 && !reservedSet.has(origName) && !origName.startsWith("$") && !origName.startsWith("__") && !origName.startsWith("_u") && !origName.startsWith("_0x") && (!manglerConfig?.excludePrefixes || !manglerConfig.excludePrefixes.some((p) => origName.startsWith(p))) && (!manglerConfig?.excludePatterns || !manglerConfig.excludePatterns.some((re) => re.test(origName)));
2186
2465
  }
2187
- function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes) {
2466
+ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes, config) {
2467
+ const activeReserved = new Set(RESERVED_IDENTIFIERS);
2468
+ if (config?.mangler?.reservedIdentifiers) {
2469
+ for (const id of config.mangler.reservedIdentifiers) {
2470
+ activeReserved.add(id);
2471
+ }
2472
+ }
2473
+ const manglerConfig = config?.mangler;
2188
2474
  const scopeRecords = /* @__PURE__ */ new Map();
2189
2475
  const existingIdentifiers = /* @__PURE__ */ new Set();
2190
2476
  let counter = 0;
@@ -2234,7 +2520,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
2234
2520
  const scope = scopeRecords.get(scopeNode);
2235
2521
  if (!scope) return;
2236
2522
  const origName = target.idNode.name;
2237
- let canMangle = shouldMangle && isMangleableName(origName);
2523
+ let canMangle = shouldMangle && isMangleableName(origName, activeReserved, manglerConfig);
2238
2524
  if (canMangle && fnScope) {
2239
2525
  if (serializedFunctionNodes && serializedFunctionNodes.has(fnScope)) {
2240
2526
  canMangle = false;
@@ -3510,7 +3796,7 @@ function isAstAlreadyProtected(ast) {
3510
3796
  }
3511
3797
  function transformJavaScript(code, options = {}) {
3512
3798
  const seed = options.seed ?? 2654435769;
3513
- const minStringLength = options.minStringLength ?? 4;
3799
+ const minStringLength = options.minStringLength ?? options.config?.vault?.minStringLength ?? 4;
3514
3800
  const isAggressive = options.aggressive ?? false;
3515
3801
  if (!code || !code.trim()) {
3516
3802
  return {
@@ -3549,7 +3835,7 @@ function transformJavaScript(code, options = {}) {
3549
3835
  hotFunctionNodes,
3550
3836
  hotExemptNodes,
3551
3837
  serializedFunctionNodes
3552
- } = analyzeAstHotPaths(ast);
3838
+ } = analyzeAstHotPaths(ast, options.config);
3553
3839
  let virtualizedFunctionsCount = 0;
3554
3840
  if (isAggressive) {
3555
3841
  const vmRes = applyMicroVm(
@@ -3564,7 +3850,8 @@ function transformJavaScript(code, options = {}) {
3564
3850
  const mangledSymbolsCount = applyPolymorphicMangler(
3565
3851
  ast,
3566
3852
  seed,
3567
- serializedFunctionNodes
3853
+ serializedFunctionNodes,
3854
+ options.config
3568
3855
  );
3569
3856
  let encryptedStringsCount = 0;
3570
3857
  let integrityToken = 0;
@@ -3575,7 +3862,8 @@ function transformJavaScript(code, options = {}) {
3575
3862
  ast,
3576
3863
  seed,
3577
3864
  minStringLength,
3578
- hotExemptNodes
3865
+ hotExemptNodes,
3866
+ options.config
3579
3867
  );
3580
3868
  encryptedStringsCount = saltedRes.encryptedStringsCount;
3581
3869
  integrityToken = saltedRes.integrityToken;
@@ -3587,7 +3875,8 @@ function transformJavaScript(code, options = {}) {
3587
3875
  hotExemptNodes,
3588
3876
  void 0,
3589
3877
  void 0,
3590
- options.deterrentMode
3878
+ options.deterrentMode,
3879
+ options.config
3591
3880
  );
3592
3881
  encryptedStringsCount = vaultRes.encryptedStringsCount;
3593
3882
  integrityToken = vaultRes.integrityToken;