@mulanjs/mulanjs 1.0.1-dev.20260220104511 → 1.0.1-dev.20260220121828

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.
@@ -45,11 +45,15 @@ export function muSurge(array, taskFn, onProgress) {
45
45
  // Convert function to string if it isn't already
46
46
  const fnStr = typeof taskFn === 'function' ? taskFn.toString() : taskFn;
47
47
  const workerCode = `
48
+ const taskFn = ${fnStr};
48
49
  self.onmessage = function(e) {
49
- const { chunk, startIndex, fnStr } = e.data;
50
- const fn = new Function('item', 'return (' + fnStr + ')(item)');
51
- const results = chunk.map(fn);
52
- self.postMessage({ results, startIndex });
50
+ const { chunk, startIndex } = e.data;
51
+ try {
52
+ const results = chunk.map(taskFn);
53
+ self.postMessage({ results, startIndex });
54
+ } catch (err) {
55
+ self.postMessage({ error: err.message, startIndex });
56
+ }
53
57
  };
54
58
  `;
55
59
  const blob = new Blob([workerCode], { type: 'application/javascript' });
@@ -1,24 +1,7 @@
1
1
  import { muEffect } from './hooks';
2
2
  import { reactive } from './reactive';
3
- const MULAN_SECRET = 'b3ast_mulan_s3cur1ty_k3y';
4
- function beastXOR(str) {
5
- let result = '';
6
- for (let i = 0; i < str.length; i++) {
7
- result += String.fromCharCode(str.charCodeAt(i) ^ MULAN_SECRET.charCodeAt(i % MULAN_SECRET.length));
8
- }
9
- return btoa(result);
10
- }
11
- function beastDecode(encoded) {
12
- const str = atob(encoded);
13
- let result = '';
14
- for (let i = 0; i < str.length; i++) {
15
- result += String.fromCharCode(str.charCodeAt(i) ^ MULAN_SECRET.charCodeAt(i % MULAN_SECRET.length));
16
- }
17
- return result;
18
- }
19
3
  /**
20
4
  * Mulan Vault: The World's First Native Persistent State Primitive.
21
- * Now fortified with Iron Fortress Obfuscation.
22
5
  */
23
6
  export function persistent(key, initialValue, options = {}) {
24
7
  const storage = options.storage || window.localStorage;
@@ -27,11 +10,10 @@ export function persistent(key, initialValue, options = {}) {
27
10
  let startVal = initialValue;
28
11
  if (stored) {
29
12
  try {
30
- const raw = options.encrypt ? beastDecode(stored) : stored;
31
- startVal = JSON.parse(raw);
13
+ startVal = JSON.parse(stored);
32
14
  }
33
15
  catch (e) {
34
- console.warn(`[Iron Fortress] Corrupt persistent data for key "${key}", resetting.`);
16
+ console.warn(`[Mulan Vault] Corrupt persistent data for key "${key}", resetting.`);
35
17
  }
36
18
  }
37
19
  // 2. Create Reactive State (Follow muState pattern for consistency)
@@ -41,20 +23,19 @@ export function persistent(key, initialValue, options = {}) {
41
23
  muEffect(() => {
42
24
  try {
43
25
  const payload = isObject ? state : state.value;
44
- const raw = JSON.stringify(payload);
45
- const toSave = options.encrypt ? beastXOR(raw) : raw;
26
+ const toSave = JSON.stringify(payload);
27
+ // Non-obfuscated persistence to satisfy security audits
46
28
  storage.setItem(key, toSave);
47
29
  }
48
30
  catch (e) {
49
- console.error(`[Iron Fortress] Failed to save key "${key}"`);
31
+ console.error(`[Mulan Vault] Failed to save key "${key}"`);
50
32
  }
51
33
  });
52
34
  // 4. Sync across Tabs
53
35
  const sync = (e) => {
54
36
  if (e.key === key && e.newValue) {
55
37
  try {
56
- const raw = options.encrypt ? beastDecode(e.newValue) : e.newValue;
57
- const newVal = JSON.parse(raw);
38
+ const newVal = JSON.parse(e.newValue);
58
39
  if (isObject) {
59
40
  Object.assign(state, newVal);
60
41
  }
package/dist/mulan.esm.js CHANGED
@@ -1582,11 +1582,15 @@ function muSurge(array, taskFn, onProgress) {
1582
1582
  // Convert function to string if it isn't already
1583
1583
  const fnStr = typeof taskFn === 'function' ? taskFn.toString() : taskFn;
1584
1584
  const workerCode = `
1585
+ const taskFn = ${fnStr};
1585
1586
  self.onmessage = function(e) {
1586
- const { chunk, startIndex, fnStr } = e.data;
1587
- const fn = new Function('item', 'return (' + fnStr + ')(item)');
1588
- const results = chunk.map(fn);
1589
- self.postMessage({ results, startIndex });
1587
+ const { chunk, startIndex } = e.data;
1588
+ try {
1589
+ const results = chunk.map(taskFn);
1590
+ self.postMessage({ results, startIndex });
1591
+ } catch (err) {
1592
+ self.postMessage({ error: err.message, startIndex });
1593
+ }
1590
1594
  };
1591
1595
  `;
1592
1596
  const blob = new Blob([workerCode], { type: 'application/javascript' });
@@ -1641,25 +1645,8 @@ __webpack_require__.r(__webpack_exports__);
1641
1645
  /* harmony import */ var _reactive__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./reactive */ "./src/core/reactive.ts");
1642
1646
 
1643
1647
 
1644
- const MULAN_SECRET = 'b3ast_mulan_s3cur1ty_k3y';
1645
- function beastXOR(str) {
1646
- let result = '';
1647
- for (let i = 0; i < str.length; i++) {
1648
- result += String.fromCharCode(str.charCodeAt(i) ^ MULAN_SECRET.charCodeAt(i % MULAN_SECRET.length));
1649
- }
1650
- return btoa(result);
1651
- }
1652
- function beastDecode(encoded) {
1653
- const str = atob(encoded);
1654
- let result = '';
1655
- for (let i = 0; i < str.length; i++) {
1656
- result += String.fromCharCode(str.charCodeAt(i) ^ MULAN_SECRET.charCodeAt(i % MULAN_SECRET.length));
1657
- }
1658
- return result;
1659
- }
1660
1648
  /**
1661
1649
  * Mulan Vault: The World's First Native Persistent State Primitive.
1662
- * Now fortified with Iron Fortress Obfuscation.
1663
1650
  */
1664
1651
  function persistent(key, initialValue, options = {}) {
1665
1652
  const storage = options.storage || window.localStorage;
@@ -1668,11 +1655,10 @@ function persistent(key, initialValue, options = {}) {
1668
1655
  let startVal = initialValue;
1669
1656
  if (stored) {
1670
1657
  try {
1671
- const raw = options.encrypt ? beastDecode(stored) : stored;
1672
- startVal = JSON.parse(raw);
1658
+ startVal = JSON.parse(stored);
1673
1659
  }
1674
1660
  catch (e) {
1675
- console.warn(`[Iron Fortress] Corrupt persistent data for key "${key}", resetting.`);
1661
+ console.warn(`[Mulan Vault] Corrupt persistent data for key "${key}", resetting.`);
1676
1662
  }
1677
1663
  }
1678
1664
  // 2. Create Reactive State (Follow muState pattern for consistency)
@@ -1682,20 +1668,19 @@ function persistent(key, initialValue, options = {}) {
1682
1668
  (0,_hooks__WEBPACK_IMPORTED_MODULE_0__.muEffect)(() => {
1683
1669
  try {
1684
1670
  const payload = isObject ? state : state.value;
1685
- const raw = JSON.stringify(payload);
1686
- const toSave = options.encrypt ? beastXOR(raw) : raw;
1671
+ const toSave = JSON.stringify(payload);
1672
+ // Non-obfuscated persistence to satisfy security audits
1687
1673
  storage.setItem(key, toSave);
1688
1674
  }
1689
1675
  catch (e) {
1690
- console.error(`[Iron Fortress] Failed to save key "${key}"`);
1676
+ console.error(`[Mulan Vault] Failed to save key "${key}"`);
1691
1677
  }
1692
1678
  });
1693
1679
  // 4. Sync across Tabs
1694
1680
  const sync = (e) => {
1695
1681
  if (e.key === key && e.newValue) {
1696
1682
  try {
1697
- const raw = options.encrypt ? beastDecode(e.newValue) : e.newValue;
1698
- const newVal = JSON.parse(raw);
1683
+ const newVal = JSON.parse(e.newValue);
1699
1684
  if (isObject) {
1700
1685
  Object.assign(state, newVal);
1701
1686
  }
package/dist/mulan.js CHANGED
@@ -106,7 +106,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
106
106
  \***************************/
107
107
  (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
108
108
 
109
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ muBurst: () => (/* binding */ muBurst),\n/* harmony export */ muSurge: () => (/* binding */ muSurge)\n/* harmony export */ });\n/**\n * muBurst - Adaptive Non-blocking Iterator\n * Processes large arrays in batches within a frame budget (typically 8-16ms)\n * to keep the UI responsive while executing at near-native loop speeds.\n */\nfunction muBurst(array, callback, options = {}) {\n const { chunkSize = 1000, timeout = 8, onProgress } = options;\n return new Promise((resolve) => {\n let index = 0;\n const total = array.length;\n function process() {\n const start = performance.now();\n // Tight loop for high-speed processing\n while (index < total && (performance.now() - start) < timeout) {\n // Process in smaller bursts to allow more frequent time checks if needed\n const endBurst = Math.min(index + chunkSize, total);\n for (; index < endBurst; index++) {\n callback(array[index], index);\n }\n }\n if (onProgress) {\n onProgress((index / total) * 100);\n }\n if (index < total) {\n requestAnimationFrame(process);\n }\n else {\n resolve();\n }\n }\n process();\n });\n}\n/**\n * muSurge - Truly Parallel Execution\n * Distributes work across CPU cores using Web Workers.\n * Logic must be serializable.\n */\nfunction muSurge(array, taskFn, onProgress) {\n const n = navigator.hardwareConcurrency || 4;\n const chunkSize = Math.ceil(array.length / n);\n const results = new Array(array.length);\n let completedChunks = 0;\n let completedItems = 0;\n // Convert function to string if it isn't already\n const fnStr = typeof taskFn === 'function' ? taskFn.toString() : taskFn;\n const workerCode = `\r\n self.onmessage = function(e) {\r\n const { chunk, startIndex, fnStr } = e.data;\r\n const fn = new Function('item', 'return (' + fnStr + ')(item)');\r\n const results = chunk.map(fn);\r\n self.postMessage({ results, startIndex });\r\n };\r\n `;\n const blob = new Blob([workerCode], { type: 'application/javascript' });\n const workerUrl = URL.createObjectURL(blob);\n return new Promise((resolve) => {\n if (array.length === 0)\n return resolve([]);\n for (let i = 0; i < n; i++) {\n const start = i * chunkSize;\n const end = Math.min(start + chunkSize, array.length);\n if (start >= end) {\n completedChunks++;\n continue;\n }\n const chunk = array.slice(start, end);\n const worker = new Worker(workerUrl);\n worker.onmessage = (e) => {\n const { results: chunkResults, startIndex } = e.data;\n // Merge results back into main array\n for (let j = 0; j < chunkResults.length; j++) {\n results[startIndex + j] = chunkResults[j];\n }\n completedChunks++;\n completedItems += chunkResults.length;\n if (onProgress)\n onProgress((completedItems / array.length) * 100);\n worker.terminate();\n if (completedChunks === n) {\n URL.revokeObjectURL(workerUrl);\n resolve(results);\n }\n };\n worker.postMessage({ chunk, startIndex: start, fnStr });\n }\n });\n}\n\n\n//# sourceURL=webpack://Mulan/./src/core/surge.ts?\n}");
109
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ muBurst: () => (/* binding */ muBurst),\n/* harmony export */ muSurge: () => (/* binding */ muSurge)\n/* harmony export */ });\n/**\n * muBurst - Adaptive Non-blocking Iterator\n * Processes large arrays in batches within a frame budget (typically 8-16ms)\n * to keep the UI responsive while executing at near-native loop speeds.\n */\nfunction muBurst(array, callback, options = {}) {\n const { chunkSize = 1000, timeout = 8, onProgress } = options;\n return new Promise((resolve) => {\n let index = 0;\n const total = array.length;\n function process() {\n const start = performance.now();\n // Tight loop for high-speed processing\n while (index < total && (performance.now() - start) < timeout) {\n // Process in smaller bursts to allow more frequent time checks if needed\n const endBurst = Math.min(index + chunkSize, total);\n for (; index < endBurst; index++) {\n callback(array[index], index);\n }\n }\n if (onProgress) {\n onProgress((index / total) * 100);\n }\n if (index < total) {\n requestAnimationFrame(process);\n }\n else {\n resolve();\n }\n }\n process();\n });\n}\n/**\n * muSurge - Truly Parallel Execution\n * Distributes work across CPU cores using Web Workers.\n * Logic must be serializable.\n */\nfunction muSurge(array, taskFn, onProgress) {\n const n = navigator.hardwareConcurrency || 4;\n const chunkSize = Math.ceil(array.length / n);\n const results = new Array(array.length);\n let completedChunks = 0;\n let completedItems = 0;\n // Convert function to string if it isn't already\n const fnStr = typeof taskFn === 'function' ? taskFn.toString() : taskFn;\n const workerCode = `\r\n const taskFn = ${fnStr};\r\n self.onmessage = function(e) {\r\n const { chunk, startIndex } = e.data;\r\n try {\r\n const results = chunk.map(taskFn);\r\n self.postMessage({ results, startIndex });\r\n } catch (err) {\r\n self.postMessage({ error: err.message, startIndex });\r\n }\r\n };\r\n `;\n const blob = new Blob([workerCode], { type: 'application/javascript' });\n const workerUrl = URL.createObjectURL(blob);\n return new Promise((resolve) => {\n if (array.length === 0)\n return resolve([]);\n for (let i = 0; i < n; i++) {\n const start = i * chunkSize;\n const end = Math.min(start + chunkSize, array.length);\n if (start >= end) {\n completedChunks++;\n continue;\n }\n const chunk = array.slice(start, end);\n const worker = new Worker(workerUrl);\n worker.onmessage = (e) => {\n const { results: chunkResults, startIndex } = e.data;\n // Merge results back into main array\n for (let j = 0; j < chunkResults.length; j++) {\n results[startIndex + j] = chunkResults[j];\n }\n completedChunks++;\n completedItems += chunkResults.length;\n if (onProgress)\n onProgress((completedItems / array.length) * 100);\n worker.terminate();\n if (completedChunks === n) {\n URL.revokeObjectURL(workerUrl);\n resolve(results);\n }\n };\n worker.postMessage({ chunk, startIndex: start, fnStr });\n }\n });\n}\n\n\n//# sourceURL=webpack://Mulan/./src/core/surge.ts?\n}");
110
110
 
111
111
  /***/ },
112
112
 
@@ -116,7 +116,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
116
116
  \***************************/
117
117
  (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
118
118
 
119
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ persistent: () => (/* binding */ persistent)\n/* harmony export */ });\n/* harmony import */ var _hooks__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./hooks */ \"./src/core/hooks.ts\");\n/* harmony import */ var _reactive__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./reactive */ \"./src/core/reactive.ts\");\n\n\nconst MULAN_SECRET = 'b3ast_mulan_s3cur1ty_k3y';\nfunction beastXOR(str) {\n let result = '';\n for (let i = 0; i < str.length; i++) {\n result += String.fromCharCode(str.charCodeAt(i) ^ MULAN_SECRET.charCodeAt(i % MULAN_SECRET.length));\n }\n return btoa(result);\n}\nfunction beastDecode(encoded) {\n const str = atob(encoded);\n let result = '';\n for (let i = 0; i < str.length; i++) {\n result += String.fromCharCode(str.charCodeAt(i) ^ MULAN_SECRET.charCodeAt(i % MULAN_SECRET.length));\n }\n return result;\n}\n/**\n * Mulan Vault: The World's First Native Persistent State Primitive.\n * Now fortified with Iron Fortress Obfuscation.\n */\nfunction persistent(key, initialValue, options = {}) {\n const storage = options.storage || window.localStorage;\n // 1. Load from Storage\n const stored = storage.getItem(key);\n let startVal = initialValue;\n if (stored) {\n try {\n const raw = options.encrypt ? beastDecode(stored) : stored;\n startVal = JSON.parse(raw);\n }\n catch (e) {\n console.warn(`[Iron Fortress] Corrupt persistent data for key \"${key}\", resetting.`);\n }\n }\n // 2. Create Reactive State (Follow muState pattern for consistency)\n const isObject = typeof startVal === 'object' && startVal !== null;\n const state = isObject ? (0,_reactive__WEBPACK_IMPORTED_MODULE_1__.reactive)(startVal) : (0,_reactive__WEBPACK_IMPORTED_MODULE_1__.reactive)({ value: startVal });\n // 3. Auto-Save on Change\n (0,_hooks__WEBPACK_IMPORTED_MODULE_0__.muEffect)(() => {\n try {\n const payload = isObject ? state : state.value;\n const raw = JSON.stringify(payload);\n const toSave = options.encrypt ? beastXOR(raw) : raw;\n storage.setItem(key, toSave);\n }\n catch (e) {\n console.error(`[Iron Fortress] Failed to save key \"${key}\"`);\n }\n });\n // 4. Sync across Tabs\n const sync = (e) => {\n if (e.key === key && e.newValue) {\n try {\n const raw = options.encrypt ? beastDecode(e.newValue) : e.newValue;\n const newVal = JSON.parse(raw);\n if (isObject) {\n Object.assign(state, newVal);\n }\n else {\n state.value = newVal;\n }\n }\n catch (e) { }\n }\n };\n window.addEventListener('storage', sync);\n // Auto-cleanup if used inside a component\n try {\n const { onMuDestroy } = __webpack_require__(/*! ./hooks */ \"./src/core/hooks.ts\");\n onMuDestroy(() => {\n window.removeEventListener('storage', sync);\n });\n }\n catch (e) {\n // muVault might be used outside component setup in some advanced cases, \n // fallback to manual or no-cleanup if so.\n }\n return state;\n}\n\n\n//# sourceURL=webpack://Mulan/./src/core/vault.ts?\n}");
119
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ persistent: () => (/* binding */ persistent)\n/* harmony export */ });\n/* harmony import */ var _hooks__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./hooks */ \"./src/core/hooks.ts\");\n/* harmony import */ var _reactive__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./reactive */ \"./src/core/reactive.ts\");\n\n\n/**\n * Mulan Vault: The World's First Native Persistent State Primitive.\n */\nfunction persistent(key, initialValue, options = {}) {\n const storage = options.storage || window.localStorage;\n // 1. Load from Storage\n const stored = storage.getItem(key);\n let startVal = initialValue;\n if (stored) {\n try {\n startVal = JSON.parse(stored);\n }\n catch (e) {\n console.warn(`[Mulan Vault] Corrupt persistent data for key \"${key}\", resetting.`);\n }\n }\n // 2. Create Reactive State (Follow muState pattern for consistency)\n const isObject = typeof startVal === 'object' && startVal !== null;\n const state = isObject ? (0,_reactive__WEBPACK_IMPORTED_MODULE_1__.reactive)(startVal) : (0,_reactive__WEBPACK_IMPORTED_MODULE_1__.reactive)({ value: startVal });\n // 3. Auto-Save on Change\n (0,_hooks__WEBPACK_IMPORTED_MODULE_0__.muEffect)(() => {\n try {\n const payload = isObject ? state : state.value;\n const toSave = JSON.stringify(payload);\n // Non-obfuscated persistence to satisfy security audits\n storage.setItem(key, toSave);\n }\n catch (e) {\n console.error(`[Mulan Vault] Failed to save key \"${key}\"`);\n }\n });\n // 4. Sync across Tabs\n const sync = (e) => {\n if (e.key === key && e.newValue) {\n try {\n const newVal = JSON.parse(e.newValue);\n if (isObject) {\n Object.assign(state, newVal);\n }\n else {\n state.value = newVal;\n }\n }\n catch (e) { }\n }\n };\n window.addEventListener('storage', sync);\n // Auto-cleanup if used inside a component\n try {\n const { onMuDestroy } = __webpack_require__(/*! ./hooks */ \"./src/core/hooks.ts\");\n onMuDestroy(() => {\n window.removeEventListener('storage', sync);\n });\n }\n catch (e) {\n // muVault might be used outside component setup in some advanced cases, \n // fallback to manual or no-cleanup if so.\n }\n return state;\n}\n\n\n//# sourceURL=webpack://Mulan/./src/core/vault.ts?\n}");
120
120
 
121
121
  /***/ },
122
122
 
@@ -7,6 +7,5 @@ export interface VaultOptions {
7
7
  }
8
8
  /**
9
9
  * Mulan Vault: The World's First Native Persistent State Primitive.
10
- * Now fortified with Iron Fortress Obfuscation.
11
10
  */
12
11
  export declare function persistent<T>(key: string, initialValue: T, options?: VaultOptions): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulanjs/mulanjs",
3
- "version": "1.0.1-dev.20260220104511",
3
+ "version": "1.0.1-dev.20260220121828",
4
4
  "description": "A powerful, secure, and enterprise-grade JavaScript framework.",
5
5
  "main": "dist/mulan.js",
6
6
  "module": "dist/mulan.esm.js",