@mulanjs/mulanjs 1.0.1-dev.20260227135307 → 1.0.1-dev.20260227172006
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler/ast-parser.d.ts +48 -0
- package/dist/compiler/ast-parser.js +54 -9
- package/dist/compiler/compiler.d.ts +9 -0
- package/dist/compiler/compiler.js +45 -2
- package/dist/compiler/dom-compiler.d.ts +7 -0
- package/dist/compiler/dom-compiler.js +90 -33
- package/dist/compiler/script-compiler.d.ts +11 -0
- package/dist/compiler/script-compiler.js +108 -116
- package/dist/compiler/sfc-parser.d.ts +21 -0
- package/dist/compiler/ssr-compiler.d.ts +7 -0
- package/dist/compiler/ssr-compiler.js +142 -0
- package/dist/compiler/style-compiler.d.ts +8 -0
- package/dist/compiler/template-compiler.d.ts +8 -0
- package/dist/components/bloch-sphere.js +9 -3
- package/dist/components/infinity-list.js +7 -1
- package/dist/core/component.js +66 -15
- package/dist/core/hooks.js +53 -29
- package/dist/core/quantum.js +30 -17
- package/dist/core/query.js +11 -6
- package/dist/core/reactive.js +88 -7
- package/dist/core/renderer.js +9 -8
- package/dist/core/ssr.js +50 -0
- package/dist/core/surge.js +7 -2
- package/dist/core/vault.js +9 -5
- package/dist/index.js +63 -27
- package/dist/mulan.esm.js +1933 -1626
- package/dist/mulan.esm.js.map +1 -1
- package/dist/mulan.js +1890 -1590
- package/dist/mulan.js.map +1 -1
- package/dist/router/index.js +17 -10
- package/dist/security/sanitizer.js +5 -1
- package/dist/store/index.js +9 -5
- package/dist/types/ast-parser.d.ts +2 -0
- package/dist/types/compiler/ast-parser.d.ts +2 -0
- package/dist/types/compiler/compiler.d.ts +1 -0
- package/dist/types/compiler/ssr-compiler.d.ts +7 -0
- package/dist/types/compiler.d.ts +1 -0
- package/dist/types/components/bloch-sphere.d.ts +3 -1
- package/dist/types/components/infinity-list.d.ts +3 -1
- package/dist/types/core/component.d.ts +14 -0
- package/dist/types/core/reactive.d.ts +5 -1
- package/dist/types/core/renderer.d.ts +0 -1
- package/dist/types/core/ssr.d.ts +9 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/ssr-compiler.d.ts +7 -0
- package/package.json +1 -1
- package/src/compiler/ast-parser.ts +62 -10
- package/src/compiler/compiler.ts +46 -1
- package/src/compiler/dom-compiler.ts +100 -34
- package/src/compiler/script-compiler.ts +117 -126
- package/src/compiler/ssr-compiler.ts +157 -0
- package/src/loader/index.js +12 -19
package/dist/core/ssr.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderToString = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Renders a Mulan component to a static HTML string with a resumability envelope.
|
|
6
|
+
*/
|
|
7
|
+
function renderToString(ComponentClass, props = {}) {
|
|
8
|
+
// 1. Initialize component in a virtual container (not used for DOM)
|
|
9
|
+
// On server, we mock the container or just pass a dummy object
|
|
10
|
+
const dummyContainer = {
|
|
11
|
+
querySelector: () => null,
|
|
12
|
+
querySelectorAll: () => [],
|
|
13
|
+
appendChild: () => { },
|
|
14
|
+
removeChild: () => { },
|
|
15
|
+
getAttribute: () => null
|
|
16
|
+
};
|
|
17
|
+
const instance = new ComponentClass(dummyContainer);
|
|
18
|
+
// Pass props
|
|
19
|
+
Object.assign(instance, props);
|
|
20
|
+
// 2. Render to HTML
|
|
21
|
+
if (typeof instance.renderToString !== 'function') {
|
|
22
|
+
throw new Error(`Component ${ComponentClass.name} was not compiled for SSR.`);
|
|
23
|
+
}
|
|
24
|
+
const html = instance.renderToString();
|
|
25
|
+
// 3. Extract State for Resumability
|
|
26
|
+
// We only want to serialize data that was exposed in setup()
|
|
27
|
+
// For now, we'll serialize any property on the instance that isn't internal
|
|
28
|
+
const state = {};
|
|
29
|
+
for (const key in instance) {
|
|
30
|
+
if (key.startsWith('_') || key === 'container' || key === 'state' || typeof instance[key] === 'function')
|
|
31
|
+
continue;
|
|
32
|
+
const value = instance[key];
|
|
33
|
+
// Handle signals specifically
|
|
34
|
+
if (value && typeof value === 'object' && 'value' in value) {
|
|
35
|
+
state[key] = value.value;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
state[key] = value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// 4. Construct Resumability Envelope
|
|
42
|
+
const stateScript = `<script type="mulan/state" data-mu-uid="${instance.$uid}">${JSON.stringify(state)}</script>`;
|
|
43
|
+
const envelope = `<div data-mu-root="${instance.$uid}">${html}${stateScript}</div>`;
|
|
44
|
+
return {
|
|
45
|
+
html,
|
|
46
|
+
state,
|
|
47
|
+
envelope
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
exports.renderToString = renderToString;
|
package/dist/core/surge.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.muSurge = exports.muBurst = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* muBurst - Adaptive Non-blocking Iterator
|
|
3
6
|
* Processes large arrays in batches within a frame budget (typically 8-16ms)
|
|
4
7
|
* to keep the UI responsive while executing at near-native loop speeds.
|
|
5
8
|
*/
|
|
6
|
-
|
|
9
|
+
function muBurst(array, callback, options = {}) {
|
|
7
10
|
const { chunkSize = 1000, timeout = 8, onProgress } = options;
|
|
8
11
|
return new Promise((resolve) => {
|
|
9
12
|
let index = 0;
|
|
@@ -31,12 +34,13 @@ export function muBurst(array, callback, options = {}) {
|
|
|
31
34
|
process();
|
|
32
35
|
});
|
|
33
36
|
}
|
|
37
|
+
exports.muBurst = muBurst;
|
|
34
38
|
/**
|
|
35
39
|
* muSurge - Truly Parallel Execution
|
|
36
40
|
* Distributes work across CPU cores using Web Workers.
|
|
37
41
|
* Logic must be serializable.
|
|
38
42
|
*/
|
|
39
|
-
|
|
43
|
+
function muSurge(array, taskFn, onProgress) {
|
|
40
44
|
const n = navigator.hardwareConcurrency || 4;
|
|
41
45
|
const chunkSize = Math.ceil(array.length / n);
|
|
42
46
|
const results = new Array(array.length);
|
|
@@ -85,3 +89,4 @@ export function muSurge(array, taskFn, onProgress) {
|
|
|
85
89
|
}
|
|
86
90
|
});
|
|
87
91
|
}
|
|
92
|
+
exports.muSurge = muSurge;
|
package/dist/core/vault.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.persistent = void 0;
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
|
+
const reactive_1 = require("./reactive");
|
|
3
6
|
/**
|
|
4
7
|
* Mulan Vault: The World's First Native Persistent State Primitive.
|
|
5
8
|
*/
|
|
6
|
-
|
|
9
|
+
function persistent(key, initialValue, options = {}) {
|
|
7
10
|
const storage = options.storage || window.localStorage;
|
|
8
11
|
// 1. Load from Storage
|
|
9
12
|
const stored = storage.getItem(key);
|
|
@@ -18,9 +21,9 @@ export function persistent(key, initialValue, options = {}) {
|
|
|
18
21
|
}
|
|
19
22
|
// 2. Create Reactive State (Follow muState pattern for consistency)
|
|
20
23
|
const isObject = typeof startVal === 'object' && startVal !== null;
|
|
21
|
-
const state = isObject ? reactive(startVal) : reactive({ value: startVal });
|
|
24
|
+
const state = isObject ? (0, reactive_1.reactive)(startVal) : (0, reactive_1.reactive)({ value: startVal });
|
|
22
25
|
// 3. Auto-Save on Change
|
|
23
|
-
muEffect(() => {
|
|
26
|
+
(0, hooks_1.muEffect)(() => {
|
|
24
27
|
try {
|
|
25
28
|
const payload = isObject ? state : state.value;
|
|
26
29
|
const toSave = JSON.stringify(payload);
|
|
@@ -55,3 +58,4 @@ export function persistent(key, initialValue, options = {}) {
|
|
|
55
58
|
}
|
|
56
59
|
return state;
|
|
57
60
|
}
|
|
61
|
+
exports.persistent = persistent;
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.MuStore = exports.Router = exports.MuRouter = exports.defineComponent = exports.Component = exports.MuComponent = void 0;
|
|
30
|
+
__exportStar(require("./core/reactive"), exports);
|
|
31
|
+
var component_1 = require("./core/component");
|
|
32
|
+
Object.defineProperty(exports, "MuComponent", { enumerable: true, get: function () { return component_1.MuComponent; } });
|
|
33
|
+
Object.defineProperty(exports, "Component", { enumerable: true, get: function () { return component_1.MuComponent; } });
|
|
34
|
+
Object.defineProperty(exports, "defineComponent", { enumerable: true, get: function () { return component_1.defineComponent; } });
|
|
35
|
+
__exportStar(require("./core/renderer"), exports);
|
|
36
|
+
var index_1 = require("./router/index");
|
|
37
|
+
Object.defineProperty(exports, "MuRouter", { enumerable: true, get: function () { return index_1.MuRouter; } });
|
|
38
|
+
Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return index_1.MuRouter; } });
|
|
39
|
+
var index_2 = require("./store/index");
|
|
40
|
+
Object.defineProperty(exports, "MuStore", { enumerable: true, get: function () { return index_2.MuStore; } });
|
|
41
|
+
__exportStar(require("./security/sanitizer"), exports);
|
|
42
|
+
__exportStar(require("./core/hooks"), exports);
|
|
43
|
+
__exportStar(require("./core/query"), exports);
|
|
44
|
+
__exportStar(require("./core/vault"), exports);
|
|
45
|
+
__exportStar(require("./core/quantum"), exports);
|
|
46
|
+
__exportStar(require("./core/surge"), exports);
|
|
47
|
+
__exportStar(require("./components/bloch-sphere"), exports);
|
|
48
|
+
__exportStar(require("./components/infinity-list"), exports);
|
|
49
|
+
__exportStar(require("./core/ssr"), exports);
|
|
14
50
|
// Global Mulan Object for non-module usage
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const Mulan = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ reactive,
|
|
27
|
-
effect, Component: MuComponent, defineComponent, Router: MuRouter, createRouter, Store: MuStore, Security: Security }, Hooks), Query), Quantum), Surge), InfinityList), { render,
|
|
51
|
+
const reactive_1 = require("./core/reactive");
|
|
52
|
+
const component_2 = require("./core/component");
|
|
53
|
+
const index_3 = require("./router/index");
|
|
54
|
+
const index_4 = require("./store/index");
|
|
55
|
+
const sanitizer_1 = require("./security/sanitizer");
|
|
56
|
+
const Hooks = __importStar(require("./core/hooks"));
|
|
57
|
+
const Query = __importStar(require("./core/query"));
|
|
58
|
+
const renderer_1 = require("./core/renderer");
|
|
59
|
+
const Quantum = __importStar(require("./core/quantum"));
|
|
60
|
+
const Surge = __importStar(require("./core/surge"));
|
|
61
|
+
const InfinityList = __importStar(require("./components/infinity-list"));
|
|
62
|
+
const Mulan = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ reactive: reactive_1.reactive,
|
|
63
|
+
effect: reactive_1.effect, Component: component_2.MuComponent, defineComponent: component_2.defineComponent, Router: index_3.MuRouter, createRouter: index_3.createRouter, Store: index_4.MuStore, Security: sanitizer_1.Security }, Hooks), Query), Quantum), Surge), InfinityList), { render: renderer_1.render,
|
|
28
64
|
// MULAN INSIGHT: Branded Logging
|
|
29
65
|
log: (msg, ...args) => {
|
|
30
66
|
console.log(`%c[MulanJS]%c ${msg}`, "color: #ff3e00; font-weight: bold; background: #222; padding: 2px 4px; border-radius: 3px;", "", ...args);
|
|
@@ -56,4 +92,4 @@ if (typeof window !== 'undefined') {
|
|
|
56
92
|
if (typeof window !== 'undefined') {
|
|
57
93
|
window.Mulan = Mulan;
|
|
58
94
|
}
|
|
59
|
-
|
|
95
|
+
exports.default = Mulan;
|