@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/mulan.esm.js
CHANGED
|
@@ -1,417 +1,504 @@
|
|
|
1
|
-
/******/
|
|
2
|
-
/******/ var __webpack_require__ = {};
|
|
3
|
-
/******/
|
|
4
|
-
/************************************************************************/
|
|
5
|
-
/******/ /* webpack/runtime/define property getters */
|
|
6
|
-
/******/ (() => {
|
|
7
|
-
/******/ // define getter functions for harmony exports
|
|
8
|
-
/******/ __webpack_require__.d = (exports, definition) => {
|
|
9
|
-
/******/ for(var key in definition) {
|
|
10
|
-
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
11
|
-
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
12
|
-
/******/ }
|
|
13
|
-
/******/ }
|
|
14
|
-
/******/ };
|
|
15
|
-
/******/ })();
|
|
16
|
-
/******/
|
|
17
|
-
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
18
|
-
/******/ (() => {
|
|
19
|
-
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
20
|
-
/******/ })();
|
|
21
|
-
/******/
|
|
22
|
-
/******/ /* webpack/runtime/make namespace object */
|
|
23
|
-
/******/ (() => {
|
|
24
|
-
/******/ // define __esModule on exports
|
|
25
|
-
/******/ __webpack_require__.r = (exports) => {
|
|
26
|
-
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
27
|
-
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
28
|
-
/******/ }
|
|
29
|
-
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
30
|
-
/******/ };
|
|
31
|
-
/******/ })();
|
|
32
|
-
/******/
|
|
33
|
-
/************************************************************************/
|
|
34
|
-
var __webpack_exports__ = {};
|
|
35
|
-
|
|
36
|
-
// NAMESPACE OBJECT: ./src/core/hooks.ts
|
|
37
|
-
var hooks_namespaceObject = {};
|
|
38
|
-
__webpack_require__.r(hooks_namespaceObject);
|
|
39
|
-
__webpack_require__.d(hooks_namespaceObject, {
|
|
40
|
-
getCurrentInstance: () => (getCurrentInstance),
|
|
41
|
-
muDebounced: () => (muDebounced),
|
|
42
|
-
muEffect: () => (muEffect),
|
|
43
|
-
muGeom: () => (muGeom),
|
|
44
|
-
muHistory: () => (muHistory),
|
|
45
|
-
muMemo: () => (muMemo),
|
|
46
|
-
muPulse: () => (muPulse),
|
|
47
|
-
muState: () => (muState),
|
|
48
|
-
muSuspense: () => (muSuspense),
|
|
49
|
-
muThrottled: () => (muThrottled),
|
|
50
|
-
muVault: () => (muVault),
|
|
51
|
-
onMuDestroy: () => (onMuDestroy),
|
|
52
|
-
onMuIdle: () => (onMuIdle),
|
|
53
|
-
onMuInit: () => (onMuInit),
|
|
54
|
-
onMuMount: () => (onMuMount),
|
|
55
|
-
onMuPanic: () => (onMuPanic),
|
|
56
|
-
onMuResume: () => (onMuResume),
|
|
57
|
-
onMuShake: () => (onMuShake),
|
|
58
|
-
onMuVisibility: () => (onMuVisibility),
|
|
59
|
-
onMuVoice: () => (onMuVoice),
|
|
60
|
-
setCurrentInstance: () => (setCurrentInstance)
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// NAMESPACE OBJECT: ./src/core/query.ts
|
|
64
|
-
var query_namespaceObject = {};
|
|
65
|
-
__webpack_require__.r(query_namespaceObject);
|
|
66
|
-
__webpack_require__.d(query_namespaceObject, {
|
|
67
|
-
useMutation: () => (useMutation),
|
|
68
|
-
useQuery: () => (useQuery)
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// NAMESPACE OBJECT: ./src/core/quantum.ts
|
|
72
|
-
var quantum_namespaceObject = {};
|
|
73
|
-
__webpack_require__.r(quantum_namespaceObject);
|
|
74
|
-
__webpack_require__.d(quantum_namespaceObject, {
|
|
75
|
-
activeControls: () => (activeControls),
|
|
76
|
-
muControl: () => (muControl),
|
|
77
|
-
muEntangle: () => (muEntangle),
|
|
78
|
-
muGate: () => (muGate),
|
|
79
|
-
muMeasure: () => (muMeasure),
|
|
80
|
-
muParallel: () => (muParallel),
|
|
81
|
-
muQubit: () => (muQubit),
|
|
82
|
-
muRegister: () => (muRegister),
|
|
83
|
-
muSearch: () => (muSearch),
|
|
84
|
-
muSwitch: () => (muSwitch),
|
|
85
|
-
muTeleport: () => (muTeleport)
|
|
86
|
-
});
|
|
1
|
+
/******/ var __webpack_modules__ = ({
|
|
87
2
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
__webpack_require__.r(surge_namespaceObject);
|
|
91
|
-
__webpack_require__.d(surge_namespaceObject, {
|
|
92
|
-
muBurst: () => (muBurst),
|
|
93
|
-
muSurge: () => (muSurge)
|
|
94
|
-
});
|
|
3
|
+
/***/ 37
|
|
4
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
95
5
|
|
|
96
|
-
// NAMESPACE OBJECT: ./src/components/infinity-list.ts
|
|
97
|
-
var infinity_list_namespaceObject = {};
|
|
98
|
-
__webpack_require__.r(infinity_list_namespaceObject);
|
|
99
|
-
__webpack_require__.d(infinity_list_namespaceObject, {
|
|
100
|
-
MuInfinity: () => (MuInfinity)
|
|
101
|
-
});
|
|
102
6
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
//
|
|
110
|
-
class
|
|
111
|
-
constructor(
|
|
112
|
-
this.
|
|
113
|
-
this.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
7
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
8
|
+
exports.defineComponent = exports.MuComponent = void 0;
|
|
9
|
+
const renderer_1 = __webpack_require__(619);
|
|
10
|
+
const hooks_1 = __webpack_require__(166);
|
|
11
|
+
const reactive_1 = __webpack_require__(359);
|
|
12
|
+
// Or a simple component that returns an object of state/methods used by template?
|
|
13
|
+
// For Mulan 2.0, let's say functional component returns a template string render function explicitly.
|
|
14
|
+
class MuComponent {
|
|
15
|
+
constructor(container) {
|
|
16
|
+
this._hooks = {};
|
|
17
|
+
this._effects = [];
|
|
18
|
+
this._domEffects = [];
|
|
19
|
+
this._isDestroyed = false;
|
|
20
|
+
this._isResuming = false; // Quantum Resumability Flag
|
|
21
|
+
this._resumeRoot = null;
|
|
22
|
+
this._propsQueue = [];
|
|
23
|
+
this._eventQueue = [];
|
|
24
|
+
// --- MulanJS List Reconciliation Engine (No-VDOM) ---
|
|
25
|
+
// Cache to store generated DOM rows by mu-key
|
|
26
|
+
this._listCaches = new Map();
|
|
27
|
+
// --- MulanJS Conditional Engine (No-VDOM) ---
|
|
28
|
+
// Cache to store conditionally toggled blocks
|
|
29
|
+
this._ifCaches = new Map();
|
|
30
|
+
this.container = container;
|
|
31
|
+
this.state = {};
|
|
32
|
+
this.$uid = 'mu_' + Math.random().toString(36).substr(2, 9);
|
|
33
|
+
// MULAN INSIGHT: Quantum Resumability Detection
|
|
34
|
+
if (typeof window !== 'undefined' && container) {
|
|
35
|
+
const rootAttr = container.getAttribute('data-mu-root');
|
|
36
|
+
const stateScript = container.querySelector('script[type="mulan/state"]');
|
|
37
|
+
if (rootAttr || stateScript) {
|
|
38
|
+
console.log(`%c[Mulan Quantum]%c Resuming component from server state...`, "color: #00ffcc; font-weight: bold;", "");
|
|
39
|
+
this._isResuming = true;
|
|
40
|
+
this.$uid = rootAttr || this.$uid;
|
|
41
|
+
if (stateScript) {
|
|
42
|
+
try {
|
|
43
|
+
const serverState = JSON.parse(stateScript.textContent || '{}');
|
|
44
|
+
// Inject server state into this instance
|
|
45
|
+
Object.assign(this, serverState);
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
console.error("[Mulan Quantum] Failed to parse server state:", e);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
118
52
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
this
|
|
124
|
-
this.notify();
|
|
53
|
+
// MULAN INSIGHT: Global Registry for Debugging
|
|
54
|
+
if (typeof window !== 'undefined') {
|
|
55
|
+
const global = window;
|
|
56
|
+
global.__MULAN_INSIGHT__ = global.__MULAN_INSIGHT__ || { components: new Map() };
|
|
57
|
+
global.__MULAN_INSIGHT__.components.set(this.$uid, this);
|
|
125
58
|
}
|
|
59
|
+
// Setup context for hooks
|
|
60
|
+
(0, hooks_1.setCurrentInstance)(this);
|
|
61
|
+
this.setup();
|
|
62
|
+
(0, hooks_1.setCurrentInstance)(null);
|
|
126
63
|
}
|
|
127
|
-
|
|
128
|
-
|
|
64
|
+
// Optional setup method for class components wanting to use hooks
|
|
65
|
+
setup() { }
|
|
66
|
+
onMount() {
|
|
67
|
+
var _a, _c;
|
|
68
|
+
// Mulan Cycle: Init
|
|
69
|
+
(_a = this._hooks.onMuInit) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn());
|
|
70
|
+
// Mulan Cycle: Mount (Simulated immediately after init for now in this version)
|
|
71
|
+
(_c = this._hooks.onMuMount) === null || _c === void 0 ? void 0 : _c.forEach(fn => fn());
|
|
129
72
|
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const run = () => {
|
|
135
|
-
if (stopped)
|
|
73
|
+
onUpdate() { }
|
|
74
|
+
onDestroy() {
|
|
75
|
+
var _a, _c;
|
|
76
|
+
if (this._isDestroyed)
|
|
136
77
|
return;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
activeEffectRunner = prevRunner;
|
|
78
|
+
this._isDestroyed = true;
|
|
79
|
+
console.log(`[Mulan Cycle] Destroying component ${this.$uid} (${this.constructor.name})`);
|
|
80
|
+
// MULAN INSIGHT: Cleanup
|
|
81
|
+
if (typeof window !== 'undefined') {
|
|
82
|
+
const global = window;
|
|
83
|
+
(_a = global.__MULAN_INSIGHT__) === null || _a === void 0 ? void 0 : _a.components.delete(this.$uid);
|
|
144
84
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
85
|
+
// Mulan Cycle: Stop all effects to prevent leaks
|
|
86
|
+
console.log(`[Mulan Cycle] Stopping ${this._effects.length} effects for ${this.$uid}`);
|
|
87
|
+
this._effects.forEach(stop => stop());
|
|
88
|
+
this._effects = [];
|
|
89
|
+
console.log(`[Mulan Cycle] Stopping ${this._domEffects.length} DOM effects for ${this.$uid}`);
|
|
90
|
+
this._domEffects.forEach(stop => stop());
|
|
91
|
+
this._domEffects = [];
|
|
92
|
+
// Mulan Cycle: Destroy hooks
|
|
93
|
+
(_c = this._hooks.onMuDestroy) === null || _c === void 0 ? void 0 : _c.forEach(fn => fn());
|
|
94
|
+
}
|
|
95
|
+
// Helper for compiler to register property bindings
|
|
96
|
+
_b(id, prop, value) {
|
|
97
|
+
this._propsQueue.push([id, prop, value]);
|
|
98
|
+
return "";
|
|
99
|
+
}
|
|
100
|
+
// Helper for compiler to register event bindings
|
|
101
|
+
_e(id, type, handler) {
|
|
102
|
+
this._eventQueue.push([id, type, handler]);
|
|
103
|
+
return "";
|
|
104
|
+
}
|
|
105
|
+
// Manual binding helper for template literals
|
|
106
|
+
bind(handler, type = 'click') {
|
|
107
|
+
const id = 'ev_' + Math.random().toString(36).substr(2, 9);
|
|
108
|
+
this._e(id, type, handler);
|
|
109
|
+
return `data-mu-id="${id}"`;
|
|
110
|
+
}
|
|
111
|
+
mount() {
|
|
112
|
+
console.log(`[Mulan Cycle] Mounting component ${this.$uid}`);
|
|
113
|
+
if (this._isResuming) {
|
|
114
|
+
// Quantum Resumability: Skip initial render, just attach effects to existing DOM
|
|
115
|
+
console.log(`[Mulan Quantum] Skipping initial render, recovering DOM nodes...`);
|
|
116
|
+
this._resume();
|
|
156
117
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
118
|
+
else {
|
|
119
|
+
// Standard Hydration/Mount
|
|
120
|
+
const stop = (0, reactive_1.effect)(() => {
|
|
121
|
+
console.log(`[Mulan Reactivity] Triggering macro-update for ${this.$uid}`);
|
|
122
|
+
this.update();
|
|
123
|
+
});
|
|
124
|
+
this._effects.push(stop);
|
|
160
125
|
}
|
|
161
|
-
|
|
126
|
+
this.onMount();
|
|
162
127
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Internal method to execute the resumability pass.
|
|
130
|
+
* Overridden by compiler-generated code.
|
|
131
|
+
*/
|
|
132
|
+
_resume() {
|
|
133
|
+
// Clear queues
|
|
134
|
+
this._propsQueue = [];
|
|
135
|
+
this._eventQueue = [];
|
|
136
|
+
// Call the template with resumption context
|
|
137
|
+
// In a real implementation, the compiler will inject 'recovery' instructions
|
|
138
|
+
this._recoveryMode = true;
|
|
139
|
+
this.template();
|
|
140
|
+
this._recoveryMode = false;
|
|
141
|
+
// Flush bindings (events/props) to existing nodes
|
|
142
|
+
this.flushProps();
|
|
143
|
+
this.flushEvents();
|
|
171
144
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Creates a standalone reactive reference.
|
|
205
|
-
* Backed by the Mulan Signal Engine.
|
|
206
|
-
*/
|
|
207
|
-
function ref(value) {
|
|
208
|
-
return new Signal(value);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
;// ./src/core/renderer.ts
|
|
212
|
-
function render(template, container) {
|
|
213
|
-
// Focus Preservation (The "Mulan Glance" Technique)
|
|
214
|
-
let focusedId = null;
|
|
215
|
-
let selectionStart = null;
|
|
216
|
-
let selectionEnd = null;
|
|
217
|
-
let preservedValue = null;
|
|
218
|
-
if (document.activeElement && container.contains(document.activeElement)) {
|
|
219
|
-
const el = document.activeElement;
|
|
220
|
-
if (el.hasAttribute('data-mu-id')) {
|
|
221
|
-
focusedId = el.getAttribute('data-mu-id');
|
|
222
|
-
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
|
|
223
|
-
selectionStart = el.selectionStart;
|
|
224
|
-
selectionEnd = el.selectionEnd;
|
|
225
|
-
preservedValue = el.value;
|
|
145
|
+
// New helper for the compiler to register a fine-grained DOM property effect
|
|
146
|
+
_bindEffect(fn, targetNode) {
|
|
147
|
+
const stop = (0, reactive_1.effect)(fn, targetNode);
|
|
148
|
+
this._domEffects.push(stop);
|
|
149
|
+
return stop;
|
|
150
|
+
}
|
|
151
|
+
update() {
|
|
152
|
+
if (this._isDestroyed) {
|
|
153
|
+
console.warn(`[Mulan Warning] Update called on destroyed component ${this.$uid}. Blocking render.`);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
// Clear queues before render
|
|
157
|
+
this._propsQueue = [];
|
|
158
|
+
this._eventQueue = [];
|
|
159
|
+
const template = this.template();
|
|
160
|
+
// Render HTML
|
|
161
|
+
(0, renderer_1.render)(template, this.container);
|
|
162
|
+
// Flush Side Effects
|
|
163
|
+
this.flushProps();
|
|
164
|
+
this.flushEvents();
|
|
165
|
+
this.onUpdate();
|
|
166
|
+
}
|
|
167
|
+
flushProps() {
|
|
168
|
+
for (const [id, prop, value] of this._propsQueue) {
|
|
169
|
+
const el = this.container.querySelector(`[data-mu-id="${id}"]`);
|
|
170
|
+
if (el) {
|
|
171
|
+
// @ts-ignore
|
|
172
|
+
el[prop] = value;
|
|
226
173
|
}
|
|
227
174
|
}
|
|
175
|
+
this._propsQueue = [];
|
|
228
176
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const key = el.getAttribute('mu-key') || el.id;
|
|
236
|
-
if (key) {
|
|
237
|
-
animationSnapshots.set(key, el.getBoundingClientRect());
|
|
177
|
+
flushEvents() {
|
|
178
|
+
for (const [id, type, handler] of this._eventQueue) {
|
|
179
|
+
const el = this.container.querySelector(`[data-mu-id="${id}"]`);
|
|
180
|
+
if (el) {
|
|
181
|
+
// Bind handler to this component instance to ensure 'this' works in methods
|
|
182
|
+
el.addEventListener(type, handler.bind(this));
|
|
238
183
|
}
|
|
239
|
-
}
|
|
184
|
+
}
|
|
185
|
+
this._eventQueue = [];
|
|
240
186
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Reconciles a list of bound data to an existing DOM parent segment.
|
|
189
|
+
* @param listId Unique ID for this specific mu-for directive Block
|
|
190
|
+
* @param container The DOM Element or Fragment where children are attached
|
|
191
|
+
* @param array The current state array
|
|
192
|
+
* @param keyProp The property to extract from each item to use as a unique key (e.g. 'id')
|
|
193
|
+
* @param renderRow A function that takes an item and returns a new { fragment, effects }
|
|
194
|
+
*/
|
|
195
|
+
_reconcileList(listId, anchorToken, array, keyProp, renderRow) {
|
|
196
|
+
if (!this._listCaches.has(listId)) {
|
|
197
|
+
this._listCaches.set(listId, new Map());
|
|
198
|
+
}
|
|
199
|
+
const cache = this._listCaches.get(listId);
|
|
200
|
+
const newKeys = new Set();
|
|
201
|
+
const parent = anchorToken.parentNode;
|
|
202
|
+
if (!parent)
|
|
203
|
+
return;
|
|
204
|
+
// 1. Array Iteration: Match against cache or Create
|
|
205
|
+
// Use a DocumentFragment to batch new node insertions natively
|
|
206
|
+
const collectorFrag = document.createDocumentFragment();
|
|
207
|
+
const newOrderNodes = [];
|
|
208
|
+
const newOrderKeys = [];
|
|
209
|
+
let requiresSwap = false;
|
|
210
|
+
let lastCachedIndex = -1;
|
|
211
|
+
for (let i = 0; i < array.length; i++) {
|
|
212
|
+
const item = array[i];
|
|
213
|
+
const key = keyProp ? item[keyProp] : i; // fallback to index if no key
|
|
214
|
+
newKeys.add(key);
|
|
215
|
+
newOrderKeys.push(key);
|
|
216
|
+
let cached = cache.get(key);
|
|
217
|
+
if (!cached) {
|
|
218
|
+
// Not in cache, Render a brand new row structure
|
|
219
|
+
const { fragment, effects } = renderRow(item, i);
|
|
220
|
+
// Track actual DOM nodes
|
|
221
|
+
const createdNodes = Array.from(fragment.childNodes);
|
|
222
|
+
cached = { nodes: createdNodes, effects, index: i }; // Store index for fast swap detection
|
|
223
|
+
cache.set(key, cached);
|
|
224
|
+
// Batch append to our in-memory fragment!
|
|
225
|
+
// This eliminates thousands of live DOM reflows on creation.
|
|
226
|
+
collectorFrag.appendChild(fragment);
|
|
227
|
+
newOrderNodes.push(...createdNodes);
|
|
255
228
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
229
|
+
else {
|
|
230
|
+
// Exists in cache
|
|
231
|
+
// Batch append to the in-memory array for index tracking
|
|
232
|
+
newOrderNodes.push(...cached.nodes);
|
|
233
|
+
// Fast-Path Swap Detection: If the cached index is physically out of numerical sequence,
|
|
234
|
+
// we know the array order was unsynchronized and needs reconciliation.
|
|
235
|
+
if (cached.index < lastCachedIndex) {
|
|
236
|
+
requiresSwap = true;
|
|
260
237
|
}
|
|
261
|
-
|
|
262
|
-
|
|
238
|
+
cached.index = i;
|
|
239
|
+
lastCachedIndex = i;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// 2. Fragment Batch Insertion (O(1) Live DOM Reflow for Creations)
|
|
243
|
+
if (collectorFrag.childNodes.length > 0) {
|
|
244
|
+
parent.insertBefore(collectorFrag, anchorToken.nextSibling);
|
|
245
|
+
}
|
|
246
|
+
// 3. Bidirectional Swap Sync (O(K) isolated shifts instead of O(N) cascades)
|
|
247
|
+
if (requiresSwap) {
|
|
248
|
+
let currentSibling = anchorToken.nextSibling;
|
|
249
|
+
// We iterate through our guaranteed physical newOrderNodes list
|
|
250
|
+
for (let j = 0; j < newOrderNodes.length; j++) {
|
|
251
|
+
const targetNode = newOrderNodes[j];
|
|
252
|
+
if (targetNode !== currentSibling) {
|
|
253
|
+
// The physical live DOM is out of sync. Move targetNode to where it belongs immediately.
|
|
254
|
+
parent.insertBefore(targetNode, currentSibling);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
// Node is correctly positioned, simply advance the sliding logical pointer
|
|
258
|
+
currentSibling = currentSibling.nextSibling;
|
|
263
259
|
}
|
|
264
260
|
}
|
|
265
261
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const dx = oldRect.left - newRect.left;
|
|
276
|
-
const dy = oldRect.top - newRect.top;
|
|
277
|
-
// Only animate if moved
|
|
278
|
-
if (dx !== 0 || dy !== 0) {
|
|
279
|
-
const htmlEl = el;
|
|
280
|
-
// INVERT: Move it back to where it was instantly
|
|
281
|
-
htmlEl.style.transform = `translate(${dx}px, ${dy}px)`;
|
|
282
|
-
htmlEl.style.transition = 'none';
|
|
283
|
-
// PLAY: Animate to zero (new position)
|
|
284
|
-
requestAnimationFrame(() => {
|
|
285
|
-
// Force reflow
|
|
286
|
-
// void htmlEl.offsetWidth;
|
|
287
|
-
htmlEl.style.transition = 'transform 500ms cubic-bezier(0.25, 0.8, 0.25, 1)';
|
|
288
|
-
htmlEl.style.transform = '';
|
|
262
|
+
// 4. Cleanup Phase: Rapidly detach unmounted nodes
|
|
263
|
+
if (cache.size > newKeys.size) {
|
|
264
|
+
for (const [key, cached] of cache.entries()) {
|
|
265
|
+
if (!newKeys.has(key)) {
|
|
266
|
+
// Remove from DOM
|
|
267
|
+
cached.nodes.forEach((node) => {
|
|
268
|
+
if (node.parentNode === parent) {
|
|
269
|
+
parent.removeChild(node);
|
|
270
|
+
}
|
|
289
271
|
});
|
|
272
|
+
// Stop any targeted effects tied to these nodes
|
|
273
|
+
cached.effects.forEach((stop) => stop());
|
|
274
|
+
// Delete from cache tracking
|
|
275
|
+
cache.delete(key);
|
|
290
276
|
}
|
|
291
277
|
}
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
function hydrate(template, container) {
|
|
296
|
-
// In a string-based framework, hydration is often just "take over".
|
|
297
|
-
// For now, we'll verify if the server content matches (simple check)
|
|
298
|
-
// and then assume control. In a more advanced version, we'd attach listeners without re-rendering.
|
|
299
|
-
if (typeof template === 'string') {
|
|
300
|
-
if (container.innerHTML.trim() !== template.trim()) {
|
|
301
|
-
console.warn('Hydration Mismatch: Server rendered content differs from Client.');
|
|
302
|
-
container.innerHTML = template; // Fallback to full render
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
// console.log('Hydration Successful.');
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
container.innerHTML = '';
|
|
310
|
-
container.appendChild(template);
|
|
311
|
-
}
|
|
312
|
-
// Future: Attach event listeners here if we had a mechanism for it.
|
|
313
|
-
}
|
|
314
|
-
function renderToString(template) {
|
|
315
|
-
// SSR Function: returns the HTML string for the server to send.
|
|
316
|
-
// Can include additional sanitization or metadata injection here.
|
|
317
|
-
return template;
|
|
318
|
-
}
|
|
319
|
-
function sanitize(str) {
|
|
320
|
-
// Check if we are in a browser environment
|
|
321
|
-
if (typeof document !== 'undefined') {
|
|
322
|
-
const temp = document.createElement('div');
|
|
323
|
-
temp.textContent = str;
|
|
324
|
-
return temp.innerHTML;
|
|
325
|
-
}
|
|
326
|
-
// Simple SSR fallback sanitizer (rudimentary)
|
|
327
|
-
return str.replace(/&/g, "&")
|
|
328
|
-
.replace(/</g, "<")
|
|
329
|
-
.replace(/>/g, ">")
|
|
330
|
-
.replace(/"/g, """)
|
|
331
|
-
.replace(/'/g, "'");
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
;// ./src/core/vault.ts
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Mulan Vault: The World's First Native Persistent State Primitive.
|
|
339
|
-
*/
|
|
340
|
-
function persistent(key, initialValue, options = {}) {
|
|
341
|
-
const storage = options.storage || window.localStorage;
|
|
342
|
-
// 1. Load from Storage
|
|
343
|
-
const stored = storage.getItem(key);
|
|
344
|
-
let startVal = initialValue;
|
|
345
|
-
if (stored) {
|
|
346
|
-
try {
|
|
347
|
-
startVal = JSON.parse(stored);
|
|
348
|
-
}
|
|
349
|
-
catch (e) {
|
|
350
|
-
console.warn(`[Mulan Vault] Corrupt persistent data for key "${key}", resetting.`);
|
|
351
278
|
}
|
|
352
279
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const payload = isObject ? state : state.value;
|
|
360
|
-
const toSave = JSON.stringify(payload);
|
|
361
|
-
// Non-obfuscated persistence to satisfy security audits
|
|
362
|
-
storage.setItem(key, toSave);
|
|
363
|
-
}
|
|
364
|
-
catch (e) {
|
|
365
|
-
console.error(`[Mulan Vault] Failed to save key "${key}"`);
|
|
280
|
+
/**
|
|
281
|
+
* Reconciles a conditional block (mu-if) to an existing DOM parent segment.
|
|
282
|
+
*/
|
|
283
|
+
_reconcileIf(ifId, anchorToken, condition, renderBlock) {
|
|
284
|
+
if (!this._ifCaches.has(ifId)) {
|
|
285
|
+
this._ifCaches.set(ifId, { isMounted: false, nodes: [], effects: [] });
|
|
366
286
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (
|
|
374
|
-
|
|
287
|
+
let cached = this._ifCaches.get(ifId);
|
|
288
|
+
if (condition) {
|
|
289
|
+
// Should be mounted
|
|
290
|
+
if (!cached.isMounted) {
|
|
291
|
+
// We need to render and mount it
|
|
292
|
+
let nodesToMount;
|
|
293
|
+
if (cached.nodes.length === 0) {
|
|
294
|
+
// First time render
|
|
295
|
+
const { fragment, effects } = renderBlock();
|
|
296
|
+
nodesToMount = Array.from(fragment.childNodes);
|
|
297
|
+
cached.nodes = nodesToMount;
|
|
298
|
+
cached.effects = effects;
|
|
375
299
|
}
|
|
376
300
|
else {
|
|
377
|
-
|
|
301
|
+
// Re-mounting previously cached nodes
|
|
302
|
+
nodesToMount = cached.nodes;
|
|
378
303
|
}
|
|
304
|
+
cached.isMounted = true;
|
|
305
|
+
const parent = anchorToken.parentNode;
|
|
306
|
+
if (!parent)
|
|
307
|
+
return;
|
|
308
|
+
const targetSibling = anchorToken.nextSibling;
|
|
309
|
+
nodesToMount.forEach(node => {
|
|
310
|
+
parent.insertBefore(node, targetSibling);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
// Should NOT be mounted
|
|
316
|
+
if (cached.isMounted) {
|
|
317
|
+
// Unmount nodes but keep them in cache
|
|
318
|
+
cached.nodes.forEach(node => {
|
|
319
|
+
if (node.parentNode) {
|
|
320
|
+
node.parentNode.removeChild(node);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
cached.isMounted = false;
|
|
324
|
+
// Note: We deliberately do NOT destroy the effects here, they stay active in memory!
|
|
379
325
|
}
|
|
380
|
-
catch (e) { }
|
|
381
326
|
}
|
|
382
|
-
};
|
|
383
|
-
window.addEventListener('storage', sync);
|
|
384
|
-
// Explicit cleanup if provided by the environment (e.g. Mulan Hooks)
|
|
385
|
-
if (options.onCleanup) {
|
|
386
|
-
options.onCleanup(() => {
|
|
387
|
-
window.removeEventListener('storage', sync);
|
|
388
|
-
});
|
|
389
327
|
}
|
|
390
|
-
return state;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
;// ./src/core/hooks.ts
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
// Global context to track the current component instance
|
|
397
|
-
let currentInstance = null;
|
|
398
|
-
function setCurrentInstance(instance) {
|
|
399
|
-
currentInstance = instance;
|
|
400
328
|
}
|
|
329
|
+
exports.MuComponent = MuComponent;
|
|
330
|
+
// Helper to create functional components wrapped in the class system
|
|
331
|
+
// Helper to create functional components wrapped in the class system
|
|
332
|
+
// Supports both () => render and { setup() } signatures
|
|
333
|
+
function defineComponent(optionsOrSetup) {
|
|
334
|
+
return class UniversalComponent extends MuComponent {
|
|
335
|
+
constructor(container) {
|
|
336
|
+
super(container);
|
|
337
|
+
// setup() is called by super constructor
|
|
338
|
+
}
|
|
339
|
+
setup() {
|
|
340
|
+
let setupResult;
|
|
341
|
+
if (typeof optionsOrSetup === 'function') {
|
|
342
|
+
// It's a setup function returning render fn
|
|
343
|
+
setupResult = optionsOrSetup.call(this);
|
|
344
|
+
}
|
|
345
|
+
else if (typeof optionsOrSetup === 'object' && optionsOrSetup.setup) {
|
|
346
|
+
// It's an options object with setup()
|
|
347
|
+
setupResult = optionsOrSetup.setup.call(this);
|
|
348
|
+
}
|
|
349
|
+
// Handle result
|
|
350
|
+
if (typeof setupResult === 'function') {
|
|
351
|
+
// It's a render function
|
|
352
|
+
this.template = setupResult;
|
|
353
|
+
}
|
|
354
|
+
else if (setupResult && typeof setupResult === 'object') {
|
|
355
|
+
// It's bindings
|
|
356
|
+
Object.assign(this, setupResult);
|
|
357
|
+
// We assume template is assigned to prototype by compiler
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
template() {
|
|
361
|
+
return '';
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
exports.defineComponent = defineComponent;
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
/***/ },
|
|
369
|
+
|
|
370
|
+
/***/ 156
|
|
371
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
375
|
+
if (k2 === undefined) k2 = k;
|
|
376
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
377
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
378
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
379
|
+
}
|
|
380
|
+
Object.defineProperty(o, k2, desc);
|
|
381
|
+
}) : (function(o, m, k, k2) {
|
|
382
|
+
if (k2 === undefined) k2 = k;
|
|
383
|
+
o[k2] = m[k];
|
|
384
|
+
}));
|
|
385
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
386
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
387
|
+
}) : function(o, v) {
|
|
388
|
+
o["default"] = v;
|
|
389
|
+
});
|
|
390
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
391
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
392
|
+
};
|
|
393
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
394
|
+
if (mod && mod.__esModule) return mod;
|
|
395
|
+
var result = {};
|
|
396
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
397
|
+
__setModuleDefault(result, mod);
|
|
398
|
+
return result;
|
|
399
|
+
};
|
|
400
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
401
|
+
exports.MuStore = exports.Router = exports.MuRouter = exports.defineComponent = exports.Component = exports.MuComponent = void 0;
|
|
402
|
+
__exportStar(__webpack_require__(359), exports);
|
|
403
|
+
var component_1 = __webpack_require__(37);
|
|
404
|
+
Object.defineProperty(exports, "MuComponent", ({ enumerable: true, get: function () { return component_1.MuComponent; } }));
|
|
405
|
+
Object.defineProperty(exports, "Component", ({ enumerable: true, get: function () { return component_1.MuComponent; } }));
|
|
406
|
+
Object.defineProperty(exports, "defineComponent", ({ enumerable: true, get: function () { return component_1.defineComponent; } }));
|
|
407
|
+
__exportStar(__webpack_require__(619), exports);
|
|
408
|
+
var index_1 = __webpack_require__(580);
|
|
409
|
+
Object.defineProperty(exports, "MuRouter", ({ enumerable: true, get: function () { return index_1.MuRouter; } }));
|
|
410
|
+
Object.defineProperty(exports, "Router", ({ enumerable: true, get: function () { return index_1.MuRouter; } }));
|
|
411
|
+
var index_2 = __webpack_require__(482);
|
|
412
|
+
Object.defineProperty(exports, "MuStore", ({ enumerable: true, get: function () { return index_2.MuStore; } }));
|
|
413
|
+
__exportStar(__webpack_require__(500), exports);
|
|
414
|
+
__exportStar(__webpack_require__(166), exports);
|
|
415
|
+
__exportStar(__webpack_require__(598), exports);
|
|
416
|
+
__exportStar(__webpack_require__(234), exports);
|
|
417
|
+
__exportStar(__webpack_require__(679), exports);
|
|
418
|
+
__exportStar(__webpack_require__(172), exports);
|
|
419
|
+
__exportStar(__webpack_require__(615), exports);
|
|
420
|
+
__exportStar(__webpack_require__(382), exports);
|
|
421
|
+
__exportStar(__webpack_require__(678), exports);
|
|
422
|
+
// Global Mulan Object for non-module usage
|
|
423
|
+
const reactive_1 = __webpack_require__(359);
|
|
424
|
+
const component_2 = __webpack_require__(37);
|
|
425
|
+
const index_3 = __webpack_require__(580);
|
|
426
|
+
const index_4 = __webpack_require__(482);
|
|
427
|
+
const sanitizer_1 = __webpack_require__(500);
|
|
428
|
+
const Hooks = __importStar(__webpack_require__(166));
|
|
429
|
+
const Query = __importStar(__webpack_require__(598));
|
|
430
|
+
const renderer_1 = __webpack_require__(619);
|
|
431
|
+
const Quantum = __importStar(__webpack_require__(679));
|
|
432
|
+
const Surge = __importStar(__webpack_require__(172));
|
|
433
|
+
const InfinityList = __importStar(__webpack_require__(382));
|
|
434
|
+
const Mulan = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ reactive: reactive_1.reactive,
|
|
435
|
+
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,
|
|
436
|
+
// MULAN INSIGHT: Branded Logging
|
|
437
|
+
log: (msg, ...args) => {
|
|
438
|
+
console.log(`%c[MulanJS]%c ${msg}`, "color: #ff3e00; font-weight: bold; background: #222; padding: 2px 4px; border-radius: 3px;", "", ...args);
|
|
439
|
+
}, warn: (msg, ...args) => {
|
|
440
|
+
console.warn(`%c[MulanJS]%c ${msg}`, "color: #ffcc00; font-weight: bold; background: #222; padding: 2px 4px; border-radius: 3px;", "", ...args);
|
|
441
|
+
}, error: (msg, ...args) => {
|
|
442
|
+
console.error(`%c[MulanJS]%c ${msg}`, "color: #ff0000; font-weight: bold; background: #222; padding: 2px 4px; border-radius: 3px;", "", ...args);
|
|
443
|
+
} });
|
|
444
|
+
// Security: Freeze the object to prevent runtime tampering
|
|
445
|
+
Object.freeze(Mulan);
|
|
446
|
+
Object.freeze(Mulan.Security);
|
|
447
|
+
// MULAN INSIGHT: Initialize Global Registry
|
|
448
|
+
if (typeof window !== 'undefined') {
|
|
449
|
+
window.__MULAN_INSIGHT__ = window.__MULAN_INSIGHT__ || { components: new Map() };
|
|
450
|
+
// MULAN INSIGHT: HMR Support
|
|
451
|
+
window.__MULAN_REFRESH__ = () => {
|
|
452
|
+
var _a;
|
|
453
|
+
const components = (_a = window.__MULAN_INSIGHT__) === null || _a === void 0 ? void 0 : _a.components;
|
|
454
|
+
if (components) {
|
|
455
|
+
components.forEach((comp) => {
|
|
456
|
+
if (comp && typeof comp.update === 'function') {
|
|
457
|
+
// Force refresh
|
|
458
|
+
comp.update();
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
if (typeof window !== 'undefined') {
|
|
465
|
+
window.Mulan = Mulan;
|
|
466
|
+
}
|
|
467
|
+
exports["default"] = Mulan;
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
/***/ },
|
|
471
|
+
|
|
472
|
+
/***/ 166
|
|
473
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
477
|
+
exports.muHistory = exports.onMuPanic = exports.muThrottled = exports.muDebounced = exports.onMuVisibility = exports.muSuspense = exports.muVault = exports.muPulse = exports.muGeom = exports.onMuVoice = exports.onMuShake = exports.onMuResume = exports.onMuIdle = exports.onMuDestroy = exports.onMuMount = exports.onMuInit = exports.muEffect = exports.muMemo = exports.muState = exports.getCurrentInstance = exports.setCurrentInstance = void 0;
|
|
478
|
+
const reactive_1 = __webpack_require__(359);
|
|
479
|
+
const vault_1 = __webpack_require__(234);
|
|
480
|
+
// Global context to track the current component instance
|
|
481
|
+
let currentInstance = null;
|
|
482
|
+
function setCurrentInstance(instance) {
|
|
483
|
+
currentInstance = instance;
|
|
484
|
+
}
|
|
485
|
+
exports.setCurrentInstance = setCurrentInstance;
|
|
401
486
|
function getCurrentInstance() {
|
|
402
487
|
return currentInstance;
|
|
403
488
|
}
|
|
489
|
+
exports.getCurrentInstance = getCurrentInstance;
|
|
404
490
|
// --- Mulan Unique Reactivity Hooks ---
|
|
405
491
|
function muState(initialValue) {
|
|
406
492
|
if (typeof initialValue === 'object' && initialValue !== null) {
|
|
407
|
-
return reactive(initialValue);
|
|
493
|
+
return (0, reactive_1.reactive)(initialValue);
|
|
408
494
|
}
|
|
409
495
|
// Core reactive state container for primitives
|
|
410
|
-
return reactive({ value: initialValue });
|
|
496
|
+
return (0, reactive_1.reactive)({ value: initialValue });
|
|
411
497
|
}
|
|
498
|
+
exports.muState = muState;
|
|
412
499
|
function muMemo(computeFn) {
|
|
413
|
-
const signal = reactive({ value: undefined });
|
|
414
|
-
const stop = effect(() => {
|
|
500
|
+
const signal = (0, reactive_1.reactive)({ value: undefined });
|
|
501
|
+
const stop = (0, reactive_1.effect)(() => {
|
|
415
502
|
signal.value = computeFn();
|
|
416
503
|
});
|
|
417
504
|
const instance = getCurrentInstance();
|
|
@@ -422,8 +509,9 @@ function muMemo(computeFn) {
|
|
|
422
509
|
}
|
|
423
510
|
return signal;
|
|
424
511
|
}
|
|
512
|
+
exports.muMemo = muMemo;
|
|
425
513
|
function muEffect(fn) {
|
|
426
|
-
const stop = effect(fn);
|
|
514
|
+
const stop = (0, reactive_1.effect)(fn);
|
|
427
515
|
const instance = getCurrentInstance();
|
|
428
516
|
if (instance) {
|
|
429
517
|
if (!instance._effects)
|
|
@@ -431,6 +519,7 @@ function muEffect(fn) {
|
|
|
431
519
|
instance._effects.push(stop);
|
|
432
520
|
}
|
|
433
521
|
}
|
|
522
|
+
exports.muEffect = muEffect;
|
|
434
523
|
// --- The "Mulan Cycle" (Lifecycle) ---
|
|
435
524
|
function onMuInit(fn) {
|
|
436
525
|
const instance = getCurrentInstance();
|
|
@@ -445,6 +534,7 @@ function onMuInit(fn) {
|
|
|
445
534
|
console.warn('onMuInit called outside of component setup context.');
|
|
446
535
|
}
|
|
447
536
|
}
|
|
537
|
+
exports.onMuInit = onMuInit;
|
|
448
538
|
function onMuMount(fn) {
|
|
449
539
|
// New hook for when component is actually in DOM (simulated for now via update)
|
|
450
540
|
const instance = getCurrentInstance();
|
|
@@ -456,6 +546,7 @@ function onMuMount(fn) {
|
|
|
456
546
|
instance._hooks.onMuMount.push(fn);
|
|
457
547
|
}
|
|
458
548
|
}
|
|
549
|
+
exports.onMuMount = onMuMount;
|
|
459
550
|
function onMuDestroy(fn) {
|
|
460
551
|
const instance = getCurrentInstance();
|
|
461
552
|
if (instance) {
|
|
@@ -466,6 +557,7 @@ function onMuDestroy(fn) {
|
|
|
466
557
|
instance._hooks.onMuDestroy.push(fn);
|
|
467
558
|
}
|
|
468
559
|
}
|
|
560
|
+
exports.onMuDestroy = onMuDestroy;
|
|
469
561
|
/**
|
|
470
562
|
* onMuIdle - The "Environment Life" Hook.
|
|
471
563
|
* Executes heavy logic ONLY when the browser is taking a nap (idle).
|
|
@@ -494,6 +586,7 @@ function onMuIdle(fn) {
|
|
|
494
586
|
});
|
|
495
587
|
}
|
|
496
588
|
}
|
|
589
|
+
exports.onMuIdle = onMuIdle;
|
|
497
590
|
/**
|
|
498
591
|
* onMuResume - The "Tab Life" Hook.
|
|
499
592
|
* Executes when the user switches BACK to this tab.
|
|
@@ -508,6 +601,7 @@ function onMuResume(fn) {
|
|
|
508
601
|
document.addEventListener('visibilitychange', handler);
|
|
509
602
|
onMuDestroy(() => document.removeEventListener('visibilitychange', handler));
|
|
510
603
|
}
|
|
604
|
+
exports.onMuResume = onMuResume;
|
|
511
605
|
/**
|
|
512
606
|
* onMuShake - The "Physical Life" Hook.
|
|
513
607
|
* Executes when the device is shaken.
|
|
@@ -546,6 +640,7 @@ function onMuShake(fn) {
|
|
|
546
640
|
console.warn("[MulanJS] Device Motion not supported on this device.");
|
|
547
641
|
}
|
|
548
642
|
}
|
|
643
|
+
exports.onMuShake = onMuShake;
|
|
549
644
|
/**
|
|
550
645
|
* onMuVoice - The "Sound Life" Hook.
|
|
551
646
|
* Executes when a specific word is spoken.
|
|
@@ -581,6 +676,7 @@ function onMuVoice(command, fn) {
|
|
|
581
676
|
recognition.stop();
|
|
582
677
|
});
|
|
583
678
|
}
|
|
679
|
+
exports.onMuVoice = onMuVoice;
|
|
584
680
|
// --- "Outside The Box" Hooks (Mulan Exclusives) ---
|
|
585
681
|
/**
|
|
586
682
|
* muGeom - Tracks window or element dimensions reactively.
|
|
@@ -598,6 +694,7 @@ function muGeom() {
|
|
|
598
694
|
});
|
|
599
695
|
return dims;
|
|
600
696
|
}
|
|
697
|
+
exports.muGeom = muGeom;
|
|
601
698
|
/**
|
|
602
699
|
* muPulse - Reactive network status.
|
|
603
700
|
*/
|
|
@@ -613,13 +710,15 @@ function muPulse() {
|
|
|
613
710
|
});
|
|
614
711
|
return status;
|
|
615
712
|
}
|
|
713
|
+
exports.muPulse = muPulse;
|
|
616
714
|
/**
|
|
617
715
|
* muVault - Secure reactive LocalStorage wrapper.
|
|
618
716
|
* Powered by the Iron Fortress persistent primitive.
|
|
619
717
|
*/
|
|
620
718
|
function muVault(key, initial, options = {}) {
|
|
621
|
-
return persistent(key, initial, Object.assign(Object.assign({}, options), { onCleanup: (fn) => onMuDestroy(fn) }));
|
|
719
|
+
return (0, vault_1.persistent)(key, initial, Object.assign(Object.assign({}, options), { onCleanup: (fn) => onMuDestroy(fn) }));
|
|
622
720
|
}
|
|
721
|
+
exports.muVault = muVault;
|
|
623
722
|
// --- Next-Gen MulanJS Hooks ---
|
|
624
723
|
/**
|
|
625
724
|
* muSuspense - The Asynchronous Barrier.
|
|
@@ -643,6 +742,7 @@ function muSuspense(promiseFn) {
|
|
|
643
742
|
});
|
|
644
743
|
return state;
|
|
645
744
|
}
|
|
745
|
+
exports.muSuspense = muSuspense;
|
|
646
746
|
/**
|
|
647
747
|
* onMuVisibility - The Intersection Observer Hook.
|
|
648
748
|
* Triggers when the component enters/leaves the viewport.
|
|
@@ -664,6 +764,7 @@ function onMuVisibility(callback, options = { threshold: 0.1 }) {
|
|
|
664
764
|
});
|
|
665
765
|
});
|
|
666
766
|
}
|
|
767
|
+
exports.onMuVisibility = onMuVisibility;
|
|
667
768
|
/**
|
|
668
769
|
* muDebounced - High-performance debouncing built directly into a reactive signal.
|
|
669
770
|
*/
|
|
@@ -682,6 +783,7 @@ function muDebounced(initialValue, delayMs) {
|
|
|
682
783
|
}
|
|
683
784
|
};
|
|
684
785
|
}
|
|
786
|
+
exports.muDebounced = muDebounced;
|
|
685
787
|
/**
|
|
686
788
|
* muThrottled - High-performance throttling built directly into a reactive signal.
|
|
687
789
|
*/
|
|
@@ -701,6 +803,7 @@ function muThrottled(initialValue, delayMs) {
|
|
|
701
803
|
}
|
|
702
804
|
};
|
|
703
805
|
}
|
|
806
|
+
exports.muThrottled = muThrottled;
|
|
704
807
|
/**
|
|
705
808
|
* onMuPanic - The Iron Fortress Error Boundary.
|
|
706
809
|
* Catches unhandled exceptions within the component scope.
|
|
@@ -724,6 +827,7 @@ function onMuPanic(fallbackFn) {
|
|
|
724
827
|
window.removeEventListener('unhandledrejection', handler);
|
|
725
828
|
});
|
|
726
829
|
}
|
|
830
|
+
exports.onMuPanic = onMuPanic;
|
|
727
831
|
/**
|
|
728
832
|
* muHistory - State with built-in Undo/Redo tracking.
|
|
729
833
|
*/
|
|
@@ -762,638 +866,502 @@ function muHistory(initialValue) {
|
|
|
762
866
|
get future() { return historyTracker.log.slice(pointer.value + 1); }
|
|
763
867
|
};
|
|
764
868
|
}
|
|
869
|
+
exports.muHistory = muHistory;
|
|
765
870
|
|
|
766
|
-
;// ./src/core/component.ts
|
|
767
871
|
|
|
872
|
+
/***/ },
|
|
768
873
|
|
|
874
|
+
/***/ 172
|
|
875
|
+
(__unused_webpack_module, exports) {
|
|
769
876
|
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
global.__MULAN_INSIGHT__ = global.__MULAN_INSIGHT__ || { components: new Map() };
|
|
793
|
-
global.__MULAN_INSIGHT__.components.set(this.$uid, this);
|
|
794
|
-
}
|
|
795
|
-
// Setup context for hooks
|
|
796
|
-
setCurrentInstance(this);
|
|
797
|
-
this.setup();
|
|
798
|
-
setCurrentInstance(null);
|
|
799
|
-
}
|
|
800
|
-
// Optional setup method for class components wanting to use hooks
|
|
801
|
-
setup() { }
|
|
802
|
-
onMount() {
|
|
803
|
-
var _a, _c;
|
|
804
|
-
// Mulan Cycle: Init
|
|
805
|
-
(_a = this._hooks.onMuInit) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn());
|
|
806
|
-
// Mulan Cycle: Mount (Simulated immediately after init for now in this version)
|
|
807
|
-
(_c = this._hooks.onMuMount) === null || _c === void 0 ? void 0 : _c.forEach(fn => fn());
|
|
808
|
-
}
|
|
809
|
-
onUpdate() { }
|
|
810
|
-
onDestroy() {
|
|
811
|
-
var _a, _c;
|
|
812
|
-
if (this._isDestroyed)
|
|
813
|
-
return;
|
|
814
|
-
this._isDestroyed = true;
|
|
815
|
-
console.log(`[Mulan Cycle] Destroying component ${this.$uid} (${this.constructor.name})`);
|
|
816
|
-
// MULAN INSIGHT: Cleanup
|
|
817
|
-
if (typeof window !== 'undefined') {
|
|
818
|
-
const global = window;
|
|
819
|
-
(_a = global.__MULAN_INSIGHT__) === null || _a === void 0 ? void 0 : _a.components.delete(this.$uid);
|
|
820
|
-
}
|
|
821
|
-
// Mulan Cycle: Stop all effects to prevent leaks
|
|
822
|
-
console.log(`[Mulan Cycle] Stopping ${this._effects.length} effects for ${this.$uid}`);
|
|
823
|
-
this._effects.forEach(stop => stop());
|
|
824
|
-
this._effects = [];
|
|
825
|
-
console.log(`[Mulan Cycle] Stopping ${this._domEffects.length} DOM effects for ${this.$uid}`);
|
|
826
|
-
this._domEffects.forEach(stop => stop());
|
|
827
|
-
this._domEffects = [];
|
|
828
|
-
// Mulan Cycle: Destroy hooks
|
|
829
|
-
(_c = this._hooks.onMuDestroy) === null || _c === void 0 ? void 0 : _c.forEach(fn => fn());
|
|
830
|
-
}
|
|
831
|
-
// Helper for compiler to register property bindings
|
|
832
|
-
_b(id, prop, value) {
|
|
833
|
-
this._propsQueue.push([id, prop, value]);
|
|
834
|
-
return "";
|
|
835
|
-
}
|
|
836
|
-
// Helper for compiler to register event bindings
|
|
837
|
-
_e(id, type, handler) {
|
|
838
|
-
this._eventQueue.push([id, type, handler]);
|
|
839
|
-
return "";
|
|
840
|
-
}
|
|
841
|
-
// Manual binding helper for template literals
|
|
842
|
-
bind(handler, type = 'click') {
|
|
843
|
-
const id = 'ev_' + Math.random().toString(36).substr(2, 9);
|
|
844
|
-
this._e(id, type, handler);
|
|
845
|
-
return `data-mu-id="${id}"`;
|
|
846
|
-
}
|
|
847
|
-
mount() {
|
|
848
|
-
console.log(`[Mulan Cycle] Mounting component ${this.$uid}`);
|
|
849
|
-
// The main render effect (legacy strings fallback / macro structure)
|
|
850
|
-
const stop = effect(() => {
|
|
851
|
-
console.log(`[Mulan Reactivity] Triggering macro-update for ${this.$uid}`);
|
|
852
|
-
this.update();
|
|
853
|
-
});
|
|
854
|
-
this._effects.push(stop);
|
|
855
|
-
this.onMount();
|
|
856
|
-
}
|
|
857
|
-
// New helper for the compiler to register a fine-grained DOM property effect
|
|
858
|
-
_bindEffect(fn, targetNode) {
|
|
859
|
-
const stop = effect(fn, targetNode);
|
|
860
|
-
this._domEffects.push(stop);
|
|
861
|
-
return stop;
|
|
862
|
-
}
|
|
863
|
-
update() {
|
|
864
|
-
if (this._isDestroyed) {
|
|
865
|
-
console.warn(`[Mulan Warning] Update called on destroyed component ${this.$uid}. Blocking render.`);
|
|
866
|
-
return;
|
|
867
|
-
}
|
|
868
|
-
// Clear queues before render
|
|
869
|
-
this._propsQueue = [];
|
|
870
|
-
this._eventQueue = [];
|
|
871
|
-
const template = this.template();
|
|
872
|
-
// Render HTML
|
|
873
|
-
render(template, this.container);
|
|
874
|
-
// Flush Side Effects
|
|
875
|
-
this.flushProps();
|
|
876
|
-
this.flushEvents();
|
|
877
|
-
this.onUpdate();
|
|
878
|
-
}
|
|
879
|
-
flushProps() {
|
|
880
|
-
for (const [id, prop, value] of this._propsQueue) {
|
|
881
|
-
const el = this.container.querySelector(`[data-mu-id="${id}"]`);
|
|
882
|
-
if (el) {
|
|
883
|
-
// @ts-ignore
|
|
884
|
-
el[prop] = value;
|
|
877
|
+
|
|
878
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
879
|
+
exports.muSurge = exports.muBurst = void 0;
|
|
880
|
+
/**
|
|
881
|
+
* muBurst - Adaptive Non-blocking Iterator
|
|
882
|
+
* Processes large arrays in batches within a frame budget (typically 8-16ms)
|
|
883
|
+
* to keep the UI responsive while executing at near-native loop speeds.
|
|
884
|
+
*/
|
|
885
|
+
function muBurst(array, callback, options = {}) {
|
|
886
|
+
const { chunkSize = 1000, timeout = 8, onProgress } = options;
|
|
887
|
+
return new Promise((resolve) => {
|
|
888
|
+
let index = 0;
|
|
889
|
+
const total = array.length;
|
|
890
|
+
function process() {
|
|
891
|
+
const start = performance.now();
|
|
892
|
+
// Tight loop for high-speed processing
|
|
893
|
+
while (index < total && (performance.now() - start) < timeout) {
|
|
894
|
+
// Process in smaller bursts to allow more frequent time checks if needed
|
|
895
|
+
const endBurst = Math.min(index + chunkSize, total);
|
|
896
|
+
for (; index < endBurst; index++) {
|
|
897
|
+
callback(array[index], index);
|
|
898
|
+
}
|
|
885
899
|
}
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
el.addEventListener(type, handler.bind(this));
|
|
900
|
+
if (onProgress) {
|
|
901
|
+
onProgress((index / total) * 100);
|
|
902
|
+
}
|
|
903
|
+
if (index < total) {
|
|
904
|
+
requestAnimationFrame(process);
|
|
905
|
+
}
|
|
906
|
+
else {
|
|
907
|
+
resolve();
|
|
895
908
|
}
|
|
896
909
|
}
|
|
897
|
-
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
if (
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
// Track actual DOM nodes
|
|
933
|
-
const createdNodes = Array.from(fragment.childNodes);
|
|
934
|
-
cached = { nodes: createdNodes, effects, index: i }; // Store index for fast swap detection
|
|
935
|
-
cache.set(key, cached);
|
|
936
|
-
// Batch append to our in-memory fragment!
|
|
937
|
-
// This eliminates thousands of live DOM reflows on creation.
|
|
938
|
-
collectorFrag.appendChild(fragment);
|
|
939
|
-
newOrderNodes.push(...createdNodes);
|
|
940
|
-
}
|
|
941
|
-
else {
|
|
942
|
-
// Exists in cache
|
|
943
|
-
// Batch append to the in-memory array for index tracking
|
|
944
|
-
newOrderNodes.push(...cached.nodes);
|
|
945
|
-
// Fast-Path Swap Detection: If the cached index is physically out of numerical sequence,
|
|
946
|
-
// we know the array order was unsynchronized and needs reconciliation.
|
|
947
|
-
if (cached.index < lastCachedIndex) {
|
|
948
|
-
requiresSwap = true;
|
|
949
|
-
}
|
|
950
|
-
cached.index = i;
|
|
951
|
-
lastCachedIndex = i;
|
|
910
|
+
process();
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
exports.muBurst = muBurst;
|
|
914
|
+
/**
|
|
915
|
+
* muSurge - Truly Parallel Execution
|
|
916
|
+
* Distributes work across CPU cores using Web Workers.
|
|
917
|
+
* Logic must be serializable.
|
|
918
|
+
*/
|
|
919
|
+
function muSurge(array, taskFn, onProgress) {
|
|
920
|
+
const n = navigator.hardwareConcurrency || 4;
|
|
921
|
+
const chunkSize = Math.ceil(array.length / n);
|
|
922
|
+
const results = new Array(array.length);
|
|
923
|
+
let completedChunks = 0;
|
|
924
|
+
let completedItems = 0;
|
|
925
|
+
// Convert function to string if it isn't already
|
|
926
|
+
const fnStr = typeof taskFn === 'function' ? taskFn.toString() : taskFn;
|
|
927
|
+
const workerPart1 = `const taskFn = ${fnStr};`;
|
|
928
|
+
const workerPart2 = `self.onmessage = function(e) {`;
|
|
929
|
+
const workerPart3 = ` const { chunk, startIndex } = e.data;`;
|
|
930
|
+
const workerPart4 = ` try { const results = chunk.map(taskFn); self.postMessage({ results, startIndex }); }`;
|
|
931
|
+
const workerPart5 = ` catch (err) { self.postMessage({ error: err.message, startIndex }); }`;
|
|
932
|
+
const workerPart6 = `};`;
|
|
933
|
+
const workerCode = [workerPart1, workerPart2, workerPart3, workerPart4, workerPart5, workerPart6].join('\n');
|
|
934
|
+
const blob = new Blob([workerCode], { type: 'application/javascript' });
|
|
935
|
+
const workerUrl = URL.createObjectURL(blob);
|
|
936
|
+
return new Promise((resolve) => {
|
|
937
|
+
if (array.length === 0)
|
|
938
|
+
return resolve([]);
|
|
939
|
+
for (let i = 0; i < n; i++) {
|
|
940
|
+
const start = i * chunkSize;
|
|
941
|
+
const end = Math.min(start + chunkSize, array.length);
|
|
942
|
+
if (start >= end) {
|
|
943
|
+
completedChunks++;
|
|
944
|
+
continue;
|
|
952
945
|
}
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
let currentSibling = anchorToken.nextSibling;
|
|
961
|
-
// We iterate through our guaranteed physical newOrderNodes list
|
|
962
|
-
for (let j = 0; j < newOrderNodes.length; j++) {
|
|
963
|
-
const targetNode = newOrderNodes[j];
|
|
964
|
-
if (targetNode !== currentSibling) {
|
|
965
|
-
// The physical live DOM is out of sync. Move targetNode to where it belongs immediately.
|
|
966
|
-
parent.insertBefore(targetNode, currentSibling);
|
|
946
|
+
const chunk = array.slice(start, end);
|
|
947
|
+
const worker = new Worker(workerUrl);
|
|
948
|
+
worker.onmessage = (e) => {
|
|
949
|
+
const { results: chunkResults, startIndex } = e.data;
|
|
950
|
+
// Merge results back into main array
|
|
951
|
+
for (let j = 0; j < chunkResults.length; j++) {
|
|
952
|
+
results[startIndex + j] = chunkResults[j];
|
|
967
953
|
}
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
954
|
+
completedChunks++;
|
|
955
|
+
completedItems += chunkResults.length;
|
|
956
|
+
if (onProgress)
|
|
957
|
+
onProgress((completedItems / array.length) * 100);
|
|
958
|
+
worker.terminate();
|
|
959
|
+
if (completedChunks === n) {
|
|
960
|
+
URL.revokeObjectURL(workerUrl);
|
|
961
|
+
resolve(results);
|
|
971
962
|
}
|
|
972
|
-
}
|
|
963
|
+
};
|
|
964
|
+
worker.postMessage({ chunk, startIndex: start, fnStr });
|
|
973
965
|
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
exports.muSurge = muSurge;
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
/***/ },
|
|
972
|
+
|
|
973
|
+
/***/ 234
|
|
974
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
978
|
+
exports.persistent = void 0;
|
|
979
|
+
const hooks_1 = __webpack_require__(166);
|
|
980
|
+
const reactive_1 = __webpack_require__(359);
|
|
981
|
+
/**
|
|
982
|
+
* Mulan Vault: The World's First Native Persistent State Primitive.
|
|
983
|
+
*/
|
|
984
|
+
function persistent(key, initialValue, options = {}) {
|
|
985
|
+
const storage = options.storage || window.localStorage;
|
|
986
|
+
// 1. Load from Storage
|
|
987
|
+
const stored = storage.getItem(key);
|
|
988
|
+
let startVal = initialValue;
|
|
989
|
+
if (stored) {
|
|
990
|
+
try {
|
|
991
|
+
startVal = JSON.parse(stored);
|
|
992
|
+
}
|
|
993
|
+
catch (e) {
|
|
994
|
+
console.warn(`[Mulan Vault] Corrupt persistent data for key "${key}", resetting.`);
|
|
990
995
|
}
|
|
991
996
|
}
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
997
|
+
// 2. Create Reactive State (Follow muState pattern for consistency)
|
|
998
|
+
const isObject = typeof startVal === 'object' && startVal !== null;
|
|
999
|
+
const state = isObject ? (0, reactive_1.reactive)(startVal) : (0, reactive_1.reactive)({ value: startVal });
|
|
1000
|
+
// 3. Auto-Save on Change
|
|
1001
|
+
(0, hooks_1.muEffect)(() => {
|
|
1002
|
+
try {
|
|
1003
|
+
const payload = isObject ? state : state.value;
|
|
1004
|
+
const toSave = JSON.stringify(payload);
|
|
1005
|
+
// Non-obfuscated persistence to satisfy security audits
|
|
1006
|
+
storage.setItem(key, toSave);
|
|
998
1007
|
}
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
cached.effects = effects;
|
|
1008
|
+
catch (e) {
|
|
1009
|
+
console.error(`[Mulan Vault] Failed to save key "${key}"`);
|
|
1010
|
+
}
|
|
1011
|
+
});
|
|
1012
|
+
// 4. Sync across Tabs
|
|
1013
|
+
const sync = (e) => {
|
|
1014
|
+
if (e.key === key && e.newValue) {
|
|
1015
|
+
try {
|
|
1016
|
+
const newVal = JSON.parse(e.newValue);
|
|
1017
|
+
if (isObject) {
|
|
1018
|
+
Object.assign(state, newVal);
|
|
1011
1019
|
}
|
|
1012
1020
|
else {
|
|
1013
|
-
|
|
1014
|
-
nodesToMount = cached.nodes;
|
|
1021
|
+
state.value = newVal;
|
|
1015
1022
|
}
|
|
1016
|
-
cached.isMounted = true;
|
|
1017
|
-
const parent = anchorToken.parentNode;
|
|
1018
|
-
if (!parent)
|
|
1019
|
-
return;
|
|
1020
|
-
const targetSibling = anchorToken.nextSibling;
|
|
1021
|
-
nodesToMount.forEach(node => {
|
|
1022
|
-
parent.insertBefore(node, targetSibling);
|
|
1023
|
-
});
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
else {
|
|
1027
|
-
// Should NOT be mounted
|
|
1028
|
-
if (cached.isMounted) {
|
|
1029
|
-
// Unmount nodes but keep them in cache
|
|
1030
|
-
cached.nodes.forEach(node => {
|
|
1031
|
-
if (node.parentNode) {
|
|
1032
|
-
node.parentNode.removeChild(node);
|
|
1033
|
-
}
|
|
1034
|
-
});
|
|
1035
|
-
cached.isMounted = false;
|
|
1036
|
-
// Note: We deliberately do NOT destroy the effects here, they stay active in memory!
|
|
1037
1023
|
}
|
|
1024
|
+
catch (e) { }
|
|
1038
1025
|
}
|
|
1026
|
+
};
|
|
1027
|
+
window.addEventListener('storage', sync);
|
|
1028
|
+
// Explicit cleanup if provided by the environment (e.g. Mulan Hooks)
|
|
1029
|
+
if (options.onCleanup) {
|
|
1030
|
+
options.onCleanup(() => {
|
|
1031
|
+
window.removeEventListener('storage', sync);
|
|
1032
|
+
});
|
|
1039
1033
|
}
|
|
1034
|
+
return state;
|
|
1040
1035
|
}
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1036
|
+
exports.persistent = persistent;
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
/***/ },
|
|
1040
|
+
|
|
1041
|
+
/***/ 359
|
|
1042
|
+
(__unused_webpack_module, exports) {
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
// MulanJS 2.0: Signal-Powered Reactivity Engine
|
|
1046
|
+
// "Compatible Surface, World-Class Engine"
|
|
1047
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1048
|
+
exports.ref = exports.reactive = exports.effect = exports.Signal = exports.nextTick = exports.queueEffect = void 0;
|
|
1049
|
+
let activeEffect = null;
|
|
1050
|
+
let activeEffectRunner = null;
|
|
1051
|
+
const targetMap = new WeakMap();
|
|
1052
|
+
// --- Mulan Quantum Scheduler (Time-Slicing) ---
|
|
1053
|
+
// Assign unique IDs to effects for basic topological sorting (lower IDs run first)
|
|
1054
|
+
let effectIdCounter = 0;
|
|
1055
|
+
const pendingEffects = new Set();
|
|
1056
|
+
let isScheduling = false;
|
|
1057
|
+
const TIME_BUDGET = 8; // 8ms frame budget for 60FPS lock
|
|
1058
|
+
function runScheduler() {
|
|
1059
|
+
if (pendingEffects.size === 0) {
|
|
1060
|
+
isScheduling = false;
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
const start = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
|
1064
|
+
// Convert to array and sort to ensure parent effects run before children (Topological Push-Pull approximation)
|
|
1065
|
+
const sortedEffects = Array.from(pendingEffects).sort((a, b) => {
|
|
1066
|
+
return (a._id || 0) - (b._id || 0);
|
|
1067
|
+
});
|
|
1068
|
+
for (const fn of sortedEffects) {
|
|
1069
|
+
pendingEffects.delete(fn);
|
|
1070
|
+
fn();
|
|
1071
|
+
const now = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
|
1072
|
+
if (now - start > TIME_BUDGET) {
|
|
1073
|
+
break; // Yield to browser
|
|
1049
1074
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
else if (typeof optionsOrSetup === 'object' && optionsOrSetup.setup) {
|
|
1057
|
-
// It's an options object with setup()
|
|
1058
|
-
setupResult = optionsOrSetup.setup.call(this);
|
|
1059
|
-
}
|
|
1060
|
-
// Handle result
|
|
1061
|
-
if (typeof setupResult === 'function') {
|
|
1062
|
-
// It's a render function
|
|
1063
|
-
this.template = setupResult;
|
|
1064
|
-
}
|
|
1065
|
-
else if (setupResult && typeof setupResult === 'object') {
|
|
1066
|
-
// It's bindings
|
|
1067
|
-
Object.assign(this, setupResult);
|
|
1068
|
-
// We assume template is assigned to prototype by compiler
|
|
1069
|
-
}
|
|
1075
|
+
}
|
|
1076
|
+
if (pendingEffects.size > 0) {
|
|
1077
|
+
if (typeof MessageChannel !== 'undefined') {
|
|
1078
|
+
const channel = new MessageChannel();
|
|
1079
|
+
channel.port1.onmessage = runScheduler;
|
|
1080
|
+
channel.port2.postMessage(null);
|
|
1070
1081
|
}
|
|
1071
|
-
|
|
1072
|
-
|
|
1082
|
+
else {
|
|
1083
|
+
setTimeout(runScheduler, 0);
|
|
1073
1084
|
}
|
|
1074
|
-
}
|
|
1085
|
+
}
|
|
1086
|
+
else {
|
|
1087
|
+
isScheduling = false;
|
|
1088
|
+
}
|
|
1075
1089
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
let secure = input
|
|
1087
|
-
.replace(/&/g, "&")
|
|
1088
|
-
.replace(/</g, "<")
|
|
1089
|
-
.replace(/>/g, ">")
|
|
1090
|
-
.replace(/"/g, """)
|
|
1091
|
-
.replace(/'/g, "'");
|
|
1092
|
-
// 2. Remove dangerous events (extra layer if encoding fails)
|
|
1093
|
-
const dangerousEvents = ['onload', 'onclick', 'onerror', 'onmouseover', 'onfocus'];
|
|
1094
|
-
dangerousEvents.forEach(event => {
|
|
1095
|
-
const regex = new RegExp(event, 'gi');
|
|
1096
|
-
secure = secure.replace(regex, 'data-blocked-' + event);
|
|
1097
|
-
});
|
|
1098
|
-
return secure;
|
|
1090
|
+
function queueEffect(fn) {
|
|
1091
|
+
pendingEffects.add(fn);
|
|
1092
|
+
if (!isScheduling) {
|
|
1093
|
+
isScheduling = true;
|
|
1094
|
+
if (typeof Promise !== 'undefined') {
|
|
1095
|
+
Promise.resolve().then(runScheduler);
|
|
1096
|
+
}
|
|
1097
|
+
else {
|
|
1098
|
+
setTimeout(runScheduler, 0);
|
|
1099
|
+
}
|
|
1099
1100
|
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1101
|
+
}
|
|
1102
|
+
exports.queueEffect = queueEffect;
|
|
1103
|
+
function nextTick() {
|
|
1104
|
+
return Promise.resolve();
|
|
1105
|
+
}
|
|
1106
|
+
exports.nextTick = nextTick;
|
|
1107
|
+
// --- Signal Core (The Engine) ---
|
|
1108
|
+
class Signal {
|
|
1109
|
+
constructor(initialValue) {
|
|
1110
|
+
this._subscribers = new Set();
|
|
1111
|
+
this._value = initialValue;
|
|
1108
1112
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
|
|
1115
|
-
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
|
1116
|
-
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
|
|
1117
|
-
return !!pattern.test(url);
|
|
1113
|
+
get value() {
|
|
1114
|
+
if (activeEffectRunner) {
|
|
1115
|
+
this._subscribers.add(activeEffectRunner.run);
|
|
1116
|
+
}
|
|
1117
|
+
return this._value;
|
|
1118
1118
|
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1119
|
+
set value(newValue) {
|
|
1120
|
+
if (newValue !== this._value) {
|
|
1121
|
+
this._value = newValue;
|
|
1122
|
+
this.notify();
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
notify() {
|
|
1126
|
+
this._subscribers.forEach(fn => {
|
|
1127
|
+
if (fn._sync) {
|
|
1128
|
+
fn();
|
|
1129
|
+
}
|
|
1130
|
+
else {
|
|
1131
|
+
queueEffect(fn);
|
|
1132
|
+
}
|
|
1127
1133
|
});
|
|
1128
1134
|
}
|
|
1129
1135
|
}
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1136
|
+
exports.Signal = Signal;
|
|
1137
|
+
// --- Compatibility Layer (The Surface) ---
|
|
1138
|
+
function effect(fn, targetNode, options = {}) {
|
|
1139
|
+
let stopped = false;
|
|
1140
|
+
const id = ++effectIdCounter;
|
|
1141
|
+
const run = () => {
|
|
1142
|
+
if (stopped)
|
|
1143
|
+
return;
|
|
1144
|
+
const prevRunner = activeEffectRunner;
|
|
1145
|
+
activeEffectRunner = { run, node: targetNode, id };
|
|
1146
|
+
try {
|
|
1147
|
+
fn();
|
|
1148
|
+
}
|
|
1149
|
+
finally {
|
|
1150
|
+
activeEffectRunner = prevRunner;
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
// Attach ID for topological sorting
|
|
1154
|
+
run._id = id;
|
|
1155
|
+
run._sync = options.sync;
|
|
1156
|
+
run();
|
|
1157
|
+
return () => {
|
|
1158
|
+
stopped = true;
|
|
1159
|
+
pendingEffects.delete(run);
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
exports.effect = effect;
|
|
1163
|
+
function track(target, key) {
|
|
1164
|
+
if (activeEffectRunner) {
|
|
1165
|
+
let depsMap = targetMap.get(target);
|
|
1166
|
+
if (!depsMap) {
|
|
1167
|
+
targetMap.set(target, (depsMap = new Map()));
|
|
1168
|
+
}
|
|
1169
|
+
let dep = depsMap.get(key);
|
|
1170
|
+
if (!dep) {
|
|
1171
|
+
depsMap.set(key, (dep = new Set()));
|
|
1154
1172
|
}
|
|
1173
|
+
dep.add(activeEffectRunner.run);
|
|
1155
1174
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
if (typeof componentToRender === 'function') {
|
|
1170
|
-
// Class component SSR
|
|
1171
|
-
// We need a dummy container for the component to "render" into its own buffer
|
|
1172
|
-
// For simplicity in this string-based framework, we mock the container
|
|
1173
|
-
const mockContainer = { innerHTML: '' };
|
|
1174
|
-
const instance = new componentToRender(mockContainer);
|
|
1175
|
-
if (instance.setParams)
|
|
1176
|
-
instance.setParams(params);
|
|
1177
|
-
// Manually trigger mount logic without DOM effects if possible, or just template()
|
|
1178
|
-
// Ideally, we just want the template string.
|
|
1179
|
-
return instance.template();
|
|
1180
|
-
}
|
|
1181
|
-
else {
|
|
1182
|
-
return componentToRender;
|
|
1183
|
-
}
|
|
1175
|
+
}
|
|
1176
|
+
function trigger(target, key) {
|
|
1177
|
+
const depsMap = targetMap.get(target);
|
|
1178
|
+
if (!depsMap)
|
|
1179
|
+
return;
|
|
1180
|
+
const dep = depsMap.get(key);
|
|
1181
|
+
if (dep) {
|
|
1182
|
+
dep.forEach((fn) => {
|
|
1183
|
+
if (fn._sync) {
|
|
1184
|
+
fn(); // Run synchronously if explicitly requested (e.g. for muMemo)
|
|
1185
|
+
}
|
|
1186
|
+
else {
|
|
1187
|
+
queueEffect(fn); // Push to Quantum Scheduler
|
|
1184
1188
|
}
|
|
1185
|
-
return '<!-- 404 -->';
|
|
1186
1189
|
});
|
|
1187
1190
|
}
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
return
|
|
1199
|
-
});
|
|
1200
|
-
const match = new RegExp(`^${regexPath}$`).exec(hash);
|
|
1201
|
-
if (match) {
|
|
1202
|
-
const params = {};
|
|
1203
|
-
paramNames.forEach((name, i) => {
|
|
1204
|
-
// SECURE: Automatically sanitize all route parameters
|
|
1205
|
-
params[name] = Security.sanitize(match[i + 1]);
|
|
1206
|
-
});
|
|
1207
|
-
return { route: r, params };
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* Creates a reactive proxy object (Vue-compatible).
|
|
1194
|
+
* Now optimized to respect Mulan Cycle.
|
|
1195
|
+
*/
|
|
1196
|
+
function reactive(target) {
|
|
1197
|
+
return new Proxy(target, {
|
|
1198
|
+
get(obj, prop, receiver) {
|
|
1199
|
+
// IRON FORTRESS: Prototype Pollution Protection (Read)
|
|
1200
|
+
if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') {
|
|
1201
|
+
return undefined;
|
|
1208
1202
|
}
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1214
|
-
if (this.isServer)
|
|
1215
|
-
return;
|
|
1216
|
-
const currentRouteId = ++this.lastRouteId;
|
|
1217
|
-
const hash = window.location.hash.slice(1) || '/';
|
|
1218
|
-
const { route, params } = this.matchRoute(hash);
|
|
1219
|
-
// Security Check: Validate URL to prevent malicious hash injection
|
|
1220
|
-
if (hash !== '/' && !Security.validateUrl('http://dummy.com' + hash)) {
|
|
1221
|
-
console.error("Security Alert: Malformed URL detected.");
|
|
1222
|
-
return;
|
|
1203
|
+
track(obj, prop);
|
|
1204
|
+
const val = Reflect.get(obj, prop, receiver);
|
|
1205
|
+
if (val !== null && typeof val === 'object') {
|
|
1206
|
+
return reactive(val);
|
|
1223
1207
|
}
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
console.warn(`Navigation to ${hash} blocked by guard.`);
|
|
1232
|
-
// Ideally redirect or stay, here we just stop processing
|
|
1233
|
-
throw new Error('Navigation Blocked');
|
|
1234
|
-
}
|
|
1235
|
-
});
|
|
1236
|
-
}).catch(() => { return; }); // Stop execution if blocked
|
|
1208
|
+
return val;
|
|
1209
|
+
},
|
|
1210
|
+
set(obj, prop, value, receiver) {
|
|
1211
|
+
// IRON FORTRESS: Prototype Pollution Protection
|
|
1212
|
+
if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') {
|
|
1213
|
+
console.warn(`[Iron Fortress] Blocked attempt to modify dangerous property: ${String(prop)}`);
|
|
1214
|
+
return false;
|
|
1237
1215
|
}
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
});
|
|
1216
|
+
const result = Reflect.set(obj, prop, value, receiver);
|
|
1217
|
+
trigger(obj, prop);
|
|
1218
|
+
return result;
|
|
1219
|
+
},
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
exports.reactive = reactive;
|
|
1223
|
+
/**
|
|
1224
|
+
* Creates a standalone reactive reference.
|
|
1225
|
+
* Backed by the Mulan Signal Engine.
|
|
1226
|
+
*/
|
|
1227
|
+
function ref(value) {
|
|
1228
|
+
return new Signal(value);
|
|
1229
|
+
}
|
|
1230
|
+
exports.ref = ref;
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
/***/ },
|
|
1234
|
+
|
|
1235
|
+
/***/ 382
|
|
1236
|
+
(__unused_webpack_module, exports) {
|
|
1237
|
+
|
|
1238
|
+
|
|
1239
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1240
|
+
exports.MuInfinity = void 0;
|
|
1241
|
+
const MuInfinityBase = typeof HTMLElement !== 'undefined' ? HTMLElement : class {
|
|
1242
|
+
};
|
|
1243
|
+
class MuInfinity extends MuInfinityBase {
|
|
1244
|
+
constructor() {
|
|
1245
|
+
super();
|
|
1246
|
+
this._items = [];
|
|
1247
|
+
this._itemHeight = 50; // Default height
|
|
1248
|
+
this._template = '';
|
|
1249
|
+
this.attachShadow({ mode: 'open' });
|
|
1250
|
+
// Structure:
|
|
1251
|
+
// :host { overflow-y: auto; display: block; height: 100%; }
|
|
1252
|
+
// .spacer { height: totalHeight; position: relative; }
|
|
1253
|
+
// .content { position: absolute; top: padding; width: 100%; }
|
|
1254
|
+
this.shadowRoot.innerHTML = `
|
|
1255
|
+
<style>
|
|
1256
|
+
:host {
|
|
1257
|
+
display: block;
|
|
1258
|
+
overflow-y: auto;
|
|
1259
|
+
height: 100%;
|
|
1260
|
+
position: relative;
|
|
1261
|
+
}
|
|
1262
|
+
.spacer {
|
|
1263
|
+
position: relative;
|
|
1264
|
+
width: 100%;
|
|
1265
|
+
}
|
|
1266
|
+
.content {
|
|
1267
|
+
position: absolute;
|
|
1268
|
+
top: 0;
|
|
1269
|
+
left: 0;
|
|
1270
|
+
width: 100%;
|
|
1271
|
+
}
|
|
1272
|
+
</style>
|
|
1273
|
+
<div class="spacer">
|
|
1274
|
+
<div class="content"></div>
|
|
1275
|
+
</div>
|
|
1276
|
+
`;
|
|
1277
|
+
this.container = this.shadowRoot.host; // The host itself scrolls
|
|
1278
|
+
this.spacer = this.shadowRoot.querySelector('.spacer');
|
|
1279
|
+
this.content = this.shadowRoot.querySelector('.content');
|
|
1280
|
+
this.onScroll = this.onScroll.bind(this);
|
|
1304
1281
|
}
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1308
|
-
if (this.isServer)
|
|
1309
|
-
return;
|
|
1310
|
-
const { route } = this.matchRoute(path);
|
|
1311
|
-
if (route) {
|
|
1312
|
-
let componentToRender = route.component;
|
|
1313
|
-
// Check if it's a lazy-loaded function that hasn't been resolved yet
|
|
1314
|
-
if (typeof componentToRender === 'function' && !componentToRender.prototype) {
|
|
1315
|
-
// If it's already a resolved module (from previous prefetch), componentToRender might be the result.
|
|
1316
|
-
// But typically in our simple implementation, route.component stays as the function until we replace it.
|
|
1317
|
-
// To avoid double-fetching, we can check if it has a specific flag or property.
|
|
1318
|
-
// For this implementation, we'll just run it and let the browser cache the module request (standard ES Module behavior).
|
|
1319
|
-
try {
|
|
1320
|
-
// console.log(`[Chronos] Prefetching ${path}...`);
|
|
1321
|
-
yield componentToRender();
|
|
1322
|
-
// We don't need to do anything with the result here.
|
|
1323
|
-
// The browser's module cache will handle the speedup when the user actually navigates.
|
|
1324
|
-
}
|
|
1325
|
-
catch (e) {
|
|
1326
|
-
console.warn(`[Chronos] Failed to prefetch ${path}`, e);
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
});
|
|
1282
|
+
static get observedAttributes() {
|
|
1283
|
+
return ['item-height'];
|
|
1331
1284
|
}
|
|
1332
|
-
|
|
1333
|
-
if (
|
|
1334
|
-
this.
|
|
1285
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
1286
|
+
if (name === 'item-height') {
|
|
1287
|
+
this._itemHeight = parseInt(newValue, 10) || 50;
|
|
1288
|
+
this.renderVisible();
|
|
1335
1289
|
}
|
|
1336
|
-
|
|
1337
|
-
|
|
1290
|
+
}
|
|
1291
|
+
connectedCallback() {
|
|
1292
|
+
// Find the template provided by the user (Support both standard and branded tags)
|
|
1293
|
+
const templateTag = this.querySelector('template') || this.querySelector('mu-template');
|
|
1294
|
+
if (templateTag) {
|
|
1295
|
+
this._template = templateTag.innerHTML;
|
|
1338
1296
|
}
|
|
1297
|
+
this.addEventListener('scroll', this.onScroll);
|
|
1298
|
+
// Wait for next frame to get initial height if not set
|
|
1299
|
+
requestAnimationFrame(() => this.renderVisible());
|
|
1339
1300
|
}
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
const createRouter = (options) => {
|
|
1343
|
-
// Expose the router instance globally for <mu-link> to access
|
|
1344
|
-
const router = new MuRouter(options.routes, options.rootContainer);
|
|
1345
|
-
if (typeof window !== 'undefined') {
|
|
1346
|
-
window.__MULAN_ROUTER__ = router;
|
|
1301
|
+
disconnectedCallback() {
|
|
1302
|
+
this.removeEventListener('scroll', this.onScroll);
|
|
1347
1303
|
}
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
// Usage: <mu-link to="/about">About Us</mu-link>
|
|
1352
|
-
if (typeof window !== 'undefined' && !customElements.get('mu-link')) {
|
|
1353
|
-
class MuLink extends HTMLElement {
|
|
1354
|
-
constructor() {
|
|
1355
|
-
super();
|
|
1356
|
-
this.addEventListener('click', (e) => {
|
|
1357
|
-
e.preventDefault();
|
|
1358
|
-
const to = this.getAttribute('to');
|
|
1359
|
-
if (to) {
|
|
1360
|
-
// Update Hash for SPA Navigation
|
|
1361
|
-
window.location.hash = to;
|
|
1362
|
-
}
|
|
1363
|
-
});
|
|
1364
|
-
// [Chronos] Intelligent Pre-fetching
|
|
1365
|
-
this.addEventListener('mouseenter', () => {
|
|
1366
|
-
const to = this.getAttribute('to');
|
|
1367
|
-
if (to) {
|
|
1368
|
-
const router = window.__MULAN_ROUTER__;
|
|
1369
|
-
if (router && typeof router.prefetch === 'function') {
|
|
1370
|
-
router.prefetch(to);
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
});
|
|
1374
|
-
// [Chronos] Also prefetch on focus for keyboard users
|
|
1375
|
-
this.addEventListener('focus', () => {
|
|
1376
|
-
const to = this.getAttribute('to');
|
|
1377
|
-
if (to) {
|
|
1378
|
-
const router = window.__MULAN_ROUTER__;
|
|
1379
|
-
if (router && typeof router.prefetch === 'function') {
|
|
1380
|
-
router.prefetch(to);
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
});
|
|
1384
|
-
}
|
|
1385
|
-
connectedCallback() {
|
|
1386
|
-
this.style.cursor = 'pointer';
|
|
1387
|
-
this.style.color = 'var(--primary, #9C27B0)'; // Default to brand color if available
|
|
1388
|
-
this.style.textDecoration = 'none';
|
|
1389
|
-
}
|
|
1390
|
-
static get observedAttributes() { return ['to']; }
|
|
1304
|
+
set items(value) {
|
|
1305
|
+
this._items = value;
|
|
1306
|
+
this.renderVisible();
|
|
1391
1307
|
}
|
|
1392
|
-
|
|
1308
|
+
get items() { return this._items; }
|
|
1309
|
+
onScroll() {
|
|
1310
|
+
requestAnimationFrame(() => this.renderVisible());
|
|
1311
|
+
}
|
|
1312
|
+
renderVisible() {
|
|
1313
|
+
if (!this._items.length)
|
|
1314
|
+
return;
|
|
1315
|
+
const scrollTop = this.scrollTop;
|
|
1316
|
+
const hostHeight = this.clientHeight || 400; // Default fallback if not sized
|
|
1317
|
+
const totalHeight = this._items.length * this._itemHeight;
|
|
1318
|
+
this.spacer.style.height = `${totalHeight}px`;
|
|
1319
|
+
// Windowing Math
|
|
1320
|
+
const startIndex = Math.floor(scrollTop / this._itemHeight);
|
|
1321
|
+
const buffer = 5;
|
|
1322
|
+
const visibleCount = Math.ceil(hostHeight / this._itemHeight);
|
|
1323
|
+
const renderStart = Math.max(0, startIndex - buffer);
|
|
1324
|
+
const renderEnd = Math.min(this._items.length, startIndex + visibleCount + buffer);
|
|
1325
|
+
const startOffset = renderStart * this._itemHeight;
|
|
1326
|
+
this.content.style.transform = `translateY(${startOffset}px)`;
|
|
1327
|
+
// Render specific slice
|
|
1328
|
+
const visibleItems = this._items.slice(renderStart, renderEnd);
|
|
1329
|
+
// Simple string replacement template engine for the demo
|
|
1330
|
+
// In a real Mulan compilation, this would be an optimized ASTR render
|
|
1331
|
+
let html = '';
|
|
1332
|
+
visibleItems.forEach((item, index) => {
|
|
1333
|
+
const absoluteIndex = renderStart + index;
|
|
1334
|
+
// Basic mustache replacement {{ item.prop }}
|
|
1335
|
+
let rowHtml = this._template
|
|
1336
|
+
.replace(/{{\s*item\s*}}/g, String(item)) // {{ item }}
|
|
1337
|
+
.replace(/{{\s*index\s*}}/g, String(absoluteIndex)); // {{ index }}
|
|
1338
|
+
// Handle object properties: {{ item.name }}
|
|
1339
|
+
if (typeof item === 'object' && item !== null) {
|
|
1340
|
+
rowHtml = rowHtml.replace(/{{\s*item\.(\w+)\s*}}/g, (_, prop) => {
|
|
1341
|
+
return String(item[prop] || '');
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
html += `<div style="height: ${this._itemHeight}px; overflow: hidden;">${rowHtml}</div>`;
|
|
1345
|
+
});
|
|
1346
|
+
this.content.innerHTML = html;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
exports.MuInfinity = MuInfinity;
|
|
1350
|
+
// Register
|
|
1351
|
+
if (typeof customElements !== 'undefined' && !customElements.get('mu-infinity')) {
|
|
1352
|
+
customElements.define('mu-infinity', MuInfinity);
|
|
1393
1353
|
}
|
|
1394
1354
|
|
|
1395
|
-
;// ./src/store/index.ts
|
|
1396
1355
|
|
|
1356
|
+
/***/ },
|
|
1357
|
+
|
|
1358
|
+
/***/ 482
|
|
1359
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1363
|
+
exports.MuStore = void 0;
|
|
1364
|
+
const reactive_1 = __webpack_require__(359);
|
|
1397
1365
|
class MuStore {
|
|
1398
1366
|
constructor(initialState, options) {
|
|
1399
1367
|
this.subscribers = [];
|
|
@@ -1411,16 +1379,16 @@ class MuStore {
|
|
|
1411
1379
|
console.error("Failed to load state", e);
|
|
1412
1380
|
}
|
|
1413
1381
|
// Auto-save effect
|
|
1414
|
-
effect(() => {
|
|
1382
|
+
(0, reactive_1.effect)(() => {
|
|
1415
1383
|
localStorage.setItem(key, JSON.stringify(this.state));
|
|
1416
1384
|
});
|
|
1417
1385
|
}
|
|
1418
|
-
this.state = reactive(loadedState);
|
|
1386
|
+
this.state = (0, reactive_1.reactive)(loadedState);
|
|
1419
1387
|
}
|
|
1420
1388
|
// Subscribe to changes
|
|
1421
1389
|
subscribe(fn) {
|
|
1422
1390
|
this.subscribers.push(fn);
|
|
1423
|
-
effect(() => {
|
|
1391
|
+
(0, reactive_1.effect)(() => {
|
|
1424
1392
|
fn(this.state);
|
|
1425
1393
|
});
|
|
1426
1394
|
}
|
|
@@ -1435,556 +1403,476 @@ class MuStore {
|
|
|
1435
1403
|
}
|
|
1436
1404
|
}
|
|
1437
1405
|
}
|
|
1406
|
+
exports.MuStore = MuStore;
|
|
1438
1407
|
|
|
1439
|
-
;// ./src/core/query.ts
|
|
1440
|
-
var query_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1441
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1442
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1443
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1444
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1445
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1446
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1447
|
-
});
|
|
1448
|
-
};
|
|
1449
1408
|
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1409
|
+
/***/ },
|
|
1410
|
+
|
|
1411
|
+
/***/ 500
|
|
1412
|
+
(__unused_webpack_module, exports) {
|
|
1413
|
+
|
|
1414
|
+
|
|
1415
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1416
|
+
exports.Security = void 0;
|
|
1417
|
+
class Security {
|
|
1418
|
+
/**
|
|
1419
|
+
* IRON FORTRESS PROTOCOL
|
|
1420
|
+
* Strictly escapes all HTML entities to prevent XSS.
|
|
1421
|
+
* Use `mu-raw` attribute in templates to bypass this for trusted content.
|
|
1422
|
+
*/
|
|
1423
|
+
static sanitize(input) {
|
|
1424
|
+
// 1. Basic entity encoding
|
|
1425
|
+
let secure = input
|
|
1426
|
+
.replace(/&/g, "&")
|
|
1427
|
+
.replace(/</g, "<")
|
|
1428
|
+
.replace(/>/g, ">")
|
|
1429
|
+
.replace(/"/g, """)
|
|
1430
|
+
.replace(/'/g, "'");
|
|
1431
|
+
// 2. Remove dangerous events (extra layer if encoding fails)
|
|
1432
|
+
const dangerousEvents = ['onload', 'onclick', 'onerror', 'onmouseover', 'onfocus'];
|
|
1433
|
+
dangerousEvents.forEach(event => {
|
|
1434
|
+
const regex = new RegExp(event, 'gi');
|
|
1435
|
+
secure = secure.replace(regex, 'data-blocked-' + event);
|
|
1436
|
+
});
|
|
1437
|
+
return secure;
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* Generates a strict Content Security Policy header value.
|
|
1441
|
+
* @param options Configuration for allowed sources
|
|
1442
|
+
*/
|
|
1443
|
+
static generateCSP(options = {}) {
|
|
1444
|
+
const scriptSrc = ["'self'", ...(options.scriptSrc || [])].join(" ");
|
|
1445
|
+
const styleSrc = ["'self'", "'unsafe-inline'", ...(options.styleSrc || [])].join(" ");
|
|
1446
|
+
return `default-src 'self'; script-src ${scriptSrc}; style-src ${styleSrc}; object-src 'none'; base-uri 'self';`;
|
|
1447
|
+
}
|
|
1448
|
+
static validateUrl(url) {
|
|
1449
|
+
// Basic URL validation
|
|
1450
|
+
const pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
|
|
1451
|
+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
|
|
1452
|
+
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
|
|
1453
|
+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
|
|
1454
|
+
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
|
1455
|
+
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
|
|
1456
|
+
return !!pattern.test(url);
|
|
1457
|
+
}
|
|
1458
|
+
/**
|
|
1459
|
+
* Prevents XSS by sanitizing common input fields on blur.
|
|
1460
|
+
* Can be used as a utility in forms.
|
|
1461
|
+
*/
|
|
1462
|
+
static preventXSS(inputElement) {
|
|
1463
|
+
inputElement.addEventListener('blur', (e) => {
|
|
1464
|
+
const target = e.target;
|
|
1465
|
+
target.value = Security.sanitize(target.value);
|
|
1475
1466
|
});
|
|
1476
1467
|
}
|
|
1477
|
-
return {
|
|
1478
|
-
get data() { return state.data; },
|
|
1479
|
-
get isLoading() { return state.isLoading; },
|
|
1480
|
-
get error() { return state.error; },
|
|
1481
|
-
refetch: execute
|
|
1482
|
-
};
|
|
1483
|
-
}
|
|
1484
|
-
function useMutation(mutationFn) {
|
|
1485
|
-
const state = reactive({
|
|
1486
|
-
data: null,
|
|
1487
|
-
isLoading: false,
|
|
1488
|
-
error: null
|
|
1489
|
-
});
|
|
1490
|
-
const mutate = (args) => query_awaiter(this, void 0, void 0, function* () {
|
|
1491
|
-
state.isLoading = true;
|
|
1492
|
-
state.error = null;
|
|
1493
|
-
try {
|
|
1494
|
-
const result = yield mutationFn(args);
|
|
1495
|
-
state.data = result;
|
|
1496
|
-
return result;
|
|
1497
|
-
}
|
|
1498
|
-
catch (err) {
|
|
1499
|
-
state.error = err;
|
|
1500
|
-
throw err;
|
|
1501
|
-
}
|
|
1502
|
-
finally {
|
|
1503
|
-
state.isLoading = false;
|
|
1504
|
-
}
|
|
1505
|
-
});
|
|
1506
|
-
return {
|
|
1507
|
-
get data() { return state.data; },
|
|
1508
|
-
get isLoading() { return state.isLoading; },
|
|
1509
|
-
get error() { return state.error; },
|
|
1510
|
-
mutate
|
|
1511
|
-
};
|
|
1512
1468
|
}
|
|
1469
|
+
exports.Security = Security;
|
|
1513
1470
|
|
|
1514
|
-
;// ./src/core/quantum.ts
|
|
1515
1471
|
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
function
|
|
1528
|
-
|
|
1529
|
-
const amplitudes = new Array(numStates).fill(0).map((_, i) => ({
|
|
1530
|
-
re: i === 0 ? 1 : 0,
|
|
1531
|
-
im: 0
|
|
1532
|
-
}));
|
|
1533
|
-
return muState({
|
|
1534
|
-
value: {
|
|
1535
|
-
size: n,
|
|
1536
|
-
amplitudes
|
|
1537
|
-
}
|
|
1472
|
+
/***/ },
|
|
1473
|
+
|
|
1474
|
+
/***/ 580
|
|
1475
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
1476
|
+
|
|
1477
|
+
|
|
1478
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1479
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1480
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1481
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1482
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1483
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1484
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1538
1485
|
});
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1486
|
+
};
|
|
1487
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1488
|
+
exports.createRouter = exports.MuRouter = void 0;
|
|
1489
|
+
const renderer_1 = __webpack_require__(619);
|
|
1490
|
+
const sanitizer_1 = __webpack_require__(500);
|
|
1491
|
+
class MuRouter {
|
|
1492
|
+
constructor(routes, rootContainer = null) {
|
|
1493
|
+
this.currentPath = '';
|
|
1494
|
+
this.currentComponent = null;
|
|
1495
|
+
this.lastRouteId = 0;
|
|
1496
|
+
this.routes = routes;
|
|
1497
|
+
this.rootContainer = rootContainer;
|
|
1498
|
+
this.isServer = rootContainer === null; // If no container, assume server/headless mode
|
|
1499
|
+
if (!this.isServer) {
|
|
1500
|
+
window.addEventListener('hashchange', this.handleRoute.bind(this));
|
|
1501
|
+
this.handleRoute(); // Initial load
|
|
1502
|
+
}
|
|
1547
1503
|
}
|
|
1548
|
-
//
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1504
|
+
// SSR Method: Simulate a route visit on the server
|
|
1505
|
+
serverLookup(path) {
|
|
1506
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1507
|
+
this.currentPath = path;
|
|
1508
|
+
const { route, params } = this.matchRoute(path);
|
|
1509
|
+
if (route) {
|
|
1510
|
+
// Run guards/resolvers here if needed
|
|
1511
|
+
let componentToRender = route.component;
|
|
1512
|
+
// Support Lazy Loading
|
|
1513
|
+
if (typeof componentToRender === 'function' && !componentToRender.prototype) {
|
|
1514
|
+
const module = yield componentToRender();
|
|
1515
|
+
componentToRender = module.default || module;
|
|
1516
|
+
}
|
|
1517
|
+
if (typeof componentToRender === 'function') {
|
|
1518
|
+
// Class component SSR
|
|
1519
|
+
// We need a dummy container for the component to "render" into its own buffer
|
|
1520
|
+
// For simplicity in this string-based framework, we mock the container
|
|
1521
|
+
const mockContainer = { innerHTML: '' };
|
|
1522
|
+
const instance = new componentToRender(mockContainer);
|
|
1523
|
+
if (instance.setParams)
|
|
1524
|
+
instance.setParams(params);
|
|
1525
|
+
// Manually trigger mount logic without DOM effects if possible, or just template()
|
|
1526
|
+
// Ideally, we just want the template string.
|
|
1527
|
+
return instance.template();
|
|
1528
|
+
}
|
|
1529
|
+
else {
|
|
1530
|
+
return componentToRender;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
return '<!-- 404 -->';
|
|
1569
1534
|
});
|
|
1570
1535
|
}
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
// Iterate only half to avoid double swapping
|
|
1592
|
-
for (let i = 0; i < amplitudes.length; i++) {
|
|
1593
|
-
// Check active controls for SWAP too
|
|
1594
|
-
if (activeControls.length > 0 && !checkControl(i, activeControls))
|
|
1595
|
-
continue;
|
|
1596
|
-
const bit1 = (i >> t1) & 1;
|
|
1597
|
-
const bit2 = (i >> t2) & 1;
|
|
1598
|
-
if (bit1 !== bit2) {
|
|
1599
|
-
// Determine the swap partner index
|
|
1600
|
-
// If i has (0,1), partner has (1,0) at those positions
|
|
1601
|
-
const partner = i ^ (1 << t1) ^ (1 << t2);
|
|
1602
|
-
if (i < partner) {
|
|
1603
|
-
const temp = newAmps[i];
|
|
1604
|
-
newAmps[i] = newAmps[partner];
|
|
1605
|
-
newAmps[partner] = temp;
|
|
1606
|
-
}
|
|
1536
|
+
matchRoute(hash) {
|
|
1537
|
+
// Simple exact match first
|
|
1538
|
+
let route = this.routes.find((r) => r.path === hash);
|
|
1539
|
+
if (route)
|
|
1540
|
+
return { route, params: {} };
|
|
1541
|
+
// Regex match for params e.g. /user/:id
|
|
1542
|
+
for (const r of this.routes) {
|
|
1543
|
+
const paramNames = [];
|
|
1544
|
+
const regexPath = r.path.replace(/:([^/]+)/g, (_, key) => {
|
|
1545
|
+
paramNames.push(key);
|
|
1546
|
+
return '([^/]+)';
|
|
1547
|
+
});
|
|
1548
|
+
const match = new RegExp(`^${regexPath}$`).exec(hash);
|
|
1549
|
+
if (match) {
|
|
1550
|
+
const params = {};
|
|
1551
|
+
paramNames.forEach((name, i) => {
|
|
1552
|
+
// SECURE: Automatically sanitize all route parameters
|
|
1553
|
+
params[name] = sanitizer_1.Security.sanitize(match[i + 1]);
|
|
1554
|
+
});
|
|
1555
|
+
return { route: r, params };
|
|
1607
1556
|
}
|
|
1608
1557
|
}
|
|
1609
|
-
|
|
1610
|
-
return;
|
|
1558
|
+
return { route: undefined, params: {} };
|
|
1611
1559
|
}
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
// Check
|
|
1620
|
-
if (!
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1560
|
+
handleRoute() {
|
|
1561
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1562
|
+
if (this.isServer)
|
|
1563
|
+
return;
|
|
1564
|
+
const currentRouteId = ++this.lastRouteId;
|
|
1565
|
+
const hash = window.location.hash.slice(1) || '/';
|
|
1566
|
+
const { route, params } = this.matchRoute(hash);
|
|
1567
|
+
// Security Check: Validate URL to prevent malicious hash injection
|
|
1568
|
+
if (hash !== '/' && !sanitizer_1.Security.validateUrl('http://dummy.com' + hash)) {
|
|
1569
|
+
console.error("Security Alert: Malformed URL detected.");
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
1572
|
+
// Navigation Guard (Middleware)
|
|
1573
|
+
if (route === null || route === void 0 ? void 0 : route.beforeEnter) {
|
|
1574
|
+
yield new Promise((resolve) => {
|
|
1575
|
+
route.beforeEnter(hash, this.currentPath, (allow) => {
|
|
1576
|
+
if (allow)
|
|
1577
|
+
resolve();
|
|
1578
|
+
else {
|
|
1579
|
+
console.warn(`Navigation to ${hash} blocked by guard.`);
|
|
1580
|
+
// Ideally redirect or stay, here we just stop processing
|
|
1581
|
+
throw new Error('Navigation Blocked');
|
|
1582
|
+
}
|
|
1583
|
+
});
|
|
1584
|
+
}).catch(() => { return; }); // Stop execution if blocked
|
|
1585
|
+
}
|
|
1586
|
+
this.currentPath = hash;
|
|
1587
|
+
if (route) {
|
|
1588
|
+
if (route.title) {
|
|
1589
|
+
document.title = route.title;
|
|
1590
|
+
}
|
|
1591
|
+
else if (route.meta && route.meta.title) {
|
|
1592
|
+
// Fallback to meta.title if used
|
|
1593
|
+
document.title = route.meta.title;
|
|
1594
|
+
}
|
|
1595
|
+
if (this.rootContainer) {
|
|
1596
|
+
// Mulan Cycle: Destroy previous component before rendering new one
|
|
1597
|
+
if (this.currentComponent) {
|
|
1598
|
+
console.log(`[Router] Navigation from ${this.currentPath} to ${hash}. Destroying previous component.`);
|
|
1599
|
+
if (this.currentComponent.onDestroy) {
|
|
1600
|
+
this.currentComponent.onDestroy();
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
this.rootContainer.innerHTML = ''; // Clear previous content
|
|
1604
|
+
}
|
|
1605
|
+
let componentToRender = route.component;
|
|
1606
|
+
// Support Lazy Loading
|
|
1607
|
+
if (typeof componentToRender === 'function' && !componentToRender.prototype) {
|
|
1608
|
+
try {
|
|
1609
|
+
const module = yield componentToRender();
|
|
1610
|
+
if (currentRouteId !== this.lastRouteId) {
|
|
1611
|
+
console.log(`[Router] Navigation to ${hash} interrupted by newer navigation. Abandoning.`);
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1614
|
+
componentToRender = module.default || module;
|
|
1615
|
+
}
|
|
1616
|
+
catch (e) {
|
|
1617
|
+
console.error("Failed to lazy load component", e);
|
|
1618
|
+
return;
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
if (typeof componentToRender === 'function') {
|
|
1622
|
+
// It's a class component
|
|
1623
|
+
if (this.rootContainer) {
|
|
1624
|
+
const instance = new componentToRender(this.rootContainer);
|
|
1625
|
+
this.currentComponent = instance;
|
|
1626
|
+
// Inject params if the component accepts them
|
|
1627
|
+
if (instance.setParams) {
|
|
1628
|
+
instance.setParams(params);
|
|
1629
|
+
}
|
|
1630
|
+
instance.mount();
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
else if (typeof componentToRender === 'object' && componentToRender.template) {
|
|
1634
|
+
// Object Component (Simple SFC without script or Options API)
|
|
1635
|
+
const html = componentToRender.template();
|
|
1636
|
+
if (this.rootContainer)
|
|
1637
|
+
(0, renderer_1.render)(html, this.rootContainer);
|
|
1638
|
+
this.currentComponent = null;
|
|
1639
|
+
}
|
|
1640
|
+
else {
|
|
1641
|
+
// Simple HTML string/template
|
|
1642
|
+
if (this.rootContainer)
|
|
1643
|
+
(0, renderer_1.render)(componentToRender, this.rootContainer);
|
|
1644
|
+
this.currentComponent = null; // String templates don't have lifecycle instances
|
|
1645
|
+
}
|
|
1629
1646
|
}
|
|
1630
1647
|
else {
|
|
1631
|
-
|
|
1632
|
-
|
|
1648
|
+
if (this.rootContainer)
|
|
1649
|
+
(0, renderer_1.render)('<div style="text-align:center; padding:50px;"><h1>404</h1><p>Page Not Found</p></div>', this.rootContainer);
|
|
1633
1650
|
}
|
|
1634
|
-
|
|
1635
|
-
processed.add(pairedIndex);
|
|
1636
|
-
}
|
|
1651
|
+
});
|
|
1637
1652
|
}
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
if (
|
|
1642
|
-
|
|
1643
|
-
const
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1653
|
+
// [Chronos] Prefetch a route's component code in the background
|
|
1654
|
+
prefetch(path) {
|
|
1655
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1656
|
+
if (this.isServer)
|
|
1657
|
+
return;
|
|
1658
|
+
const { route } = this.matchRoute(path);
|
|
1659
|
+
if (route) {
|
|
1660
|
+
let componentToRender = route.component;
|
|
1661
|
+
// Check if it's a lazy-loaded function that hasn't been resolved yet
|
|
1662
|
+
if (typeof componentToRender === 'function' && !componentToRender.prototype) {
|
|
1663
|
+
// If it's already a resolved module (from previous prefetch), componentToRender might be the result.
|
|
1664
|
+
// But typically in our simple implementation, route.component stays as the function until we replace it.
|
|
1665
|
+
// To avoid double-fetching, we can check if it has a specific flag or property.
|
|
1666
|
+
// For this implementation, we'll just run it and let the browser cache the module request (standard ES Module behavior).
|
|
1667
|
+
try {
|
|
1668
|
+
// console.log(`[Chronos] Prefetching ${path}...`);
|
|
1669
|
+
yield componentToRender();
|
|
1670
|
+
// We don't need to do anything with the result here.
|
|
1671
|
+
// The browser's module cache will handle the speedup when the user actually navigates.
|
|
1672
|
+
}
|
|
1673
|
+
catch (e) {
|
|
1674
|
+
console.warn(`[Chronos] Failed to prefetch ${path}`, e);
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1649
1677
|
}
|
|
1650
|
-
}
|
|
1678
|
+
});
|
|
1651
1679
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
if (!checkControl(i, effectiveControl))
|
|
1656
|
-
continue;
|
|
1657
|
-
const targetBit = (i >> target) & 1;
|
|
1658
|
-
// Z Gate acts on |1>
|
|
1659
|
-
if (targetBit === 1) {
|
|
1660
|
-
newAmps[i] = { re: -amplitudes[i].re, im: -amplitudes[i].im };
|
|
1661
|
-
}
|
|
1680
|
+
navigate(path) {
|
|
1681
|
+
if (this.isServer) {
|
|
1682
|
+
this.currentPath = path;
|
|
1662
1683
|
}
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
// Y: |0> -> i|1>, |1> -> -i|0>
|
|
1666
|
-
for (let i = 0; i < amplitudes.length; i++) {
|
|
1667
|
-
if (!checkControl(i, effectiveControl))
|
|
1668
|
-
continue;
|
|
1669
|
-
const targetBit = (i >> target) & 1;
|
|
1670
|
-
const pairedIndex = targetBit ? (i & ~(1 << target)) : (i | (1 << target));
|
|
1671
|
-
if (i < pairedIndex) {
|
|
1672
|
-
// We process pairs (i, pairedIndex) where i has 0 at target, paired has 1
|
|
1673
|
-
const a = newAmps[i]; // Coeff of |0>
|
|
1674
|
-
const b = newAmps[pairedIndex]; // Coeff of |1>
|
|
1675
|
-
// New |0> = -i * Old |1>
|
|
1676
|
-
newAmps[i] = { re: b.im, im: -b.re };
|
|
1677
|
-
// New |1> = i * Old |0>
|
|
1678
|
-
newAmps[pairedIndex] = { re: -a.im, im: a.re };
|
|
1679
|
-
}
|
|
1684
|
+
else {
|
|
1685
|
+
window.location.hash = path;
|
|
1680
1686
|
}
|
|
1681
1687
|
}
|
|
1682
|
-
updateState(reg, Object.assign(Object.assign({}, state), { amplitudes: newAmps }));
|
|
1683
1688
|
}
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1689
|
+
exports.MuRouter = MuRouter;
|
|
1690
|
+
// --- Factory for Easy Usage ---
|
|
1691
|
+
const createRouter = (options) => {
|
|
1692
|
+
// Expose the router instance globally for <mu-link> to access
|
|
1693
|
+
const router = new MuRouter(options.routes, options.rootContainer);
|
|
1694
|
+
if (typeof window !== 'undefined') {
|
|
1695
|
+
window.__MULAN_ROUTER__ = router;
|
|
1696
|
+
}
|
|
1697
|
+
return router;
|
|
1698
|
+
};
|
|
1699
|
+
exports.createRouter = createRouter;
|
|
1700
|
+
// --- Web Component: <mu-link> ---
|
|
1701
|
+
// Usage: <mu-link to="/about">About Us</mu-link>
|
|
1702
|
+
const MuLinkBase = typeof HTMLElement !== 'undefined' ? HTMLElement : class {
|
|
1703
|
+
};
|
|
1704
|
+
if (typeof window !== 'undefined' && !customElements.get('mu-link')) {
|
|
1705
|
+
class MuLink extends MuLinkBase {
|
|
1706
|
+
constructor() {
|
|
1707
|
+
super();
|
|
1708
|
+
this.addEventListener('click', (e) => {
|
|
1709
|
+
e.preventDefault();
|
|
1710
|
+
const to = this.getAttribute('to');
|
|
1711
|
+
if (to) {
|
|
1712
|
+
// Update Hash for SPA Navigation
|
|
1713
|
+
window.location.hash = to;
|
|
1714
|
+
}
|
|
1715
|
+
});
|
|
1716
|
+
// [Chronos] Intelligent Pre-fetching
|
|
1717
|
+
this.addEventListener('mouseenter', () => {
|
|
1718
|
+
const to = this.getAttribute('to');
|
|
1719
|
+
if (to) {
|
|
1720
|
+
const router = window.__MULAN_ROUTER__;
|
|
1721
|
+
if (router && typeof router.prefetch === 'function') {
|
|
1722
|
+
router.prefetch(to);
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
});
|
|
1726
|
+
// [Chronos] Also prefetch on focus for keyboard users
|
|
1727
|
+
this.addEventListener('focus', () => {
|
|
1728
|
+
const to = this.getAttribute('to');
|
|
1729
|
+
if (to) {
|
|
1730
|
+
const router = window.__MULAN_ROUTER__;
|
|
1731
|
+
if (router && typeof router.prefetch === 'function') {
|
|
1732
|
+
router.prefetch(to);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
});
|
|
1705
1736
|
}
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1737
|
+
connectedCallback() {
|
|
1738
|
+
this.style.cursor = 'pointer';
|
|
1739
|
+
this.style.color = 'var(--primary, #9C27B0)'; // Default to brand color if available
|
|
1740
|
+
this.style.textDecoration = 'none';
|
|
1710
1741
|
}
|
|
1742
|
+
static get observedAttributes() { return ['to']; }
|
|
1711
1743
|
}
|
|
1712
|
-
|
|
1713
|
-
muGate(reg, 'Z', targetQubit, controls);
|
|
1714
|
-
// 3. Uncompute (Restore 0s)
|
|
1715
|
-
for (let i = 0; i < n; i++) {
|
|
1716
|
-
const bit = (targetState >> i) & 1;
|
|
1717
|
-
if (bit === 0)
|
|
1718
|
-
muGate(reg, 'X', i);
|
|
1719
|
-
}
|
|
1720
|
-
// --- GROVER DIFFUSER (Amplification) ---
|
|
1721
|
-
// This flips the probability amplitudes around the mean, boosting the target state.
|
|
1722
|
-
// 1. Apply H to all
|
|
1723
|
-
for (let i = 0; i < n; i++)
|
|
1724
|
-
muGate(reg, 'H', i);
|
|
1725
|
-
// 2. Apply X to all
|
|
1726
|
-
for (let i = 0; i < n; i++)
|
|
1727
|
-
muGate(reg, 'X', i);
|
|
1728
|
-
// 3. Multi-Controlled Z (Reflection about |0...0>)
|
|
1729
|
-
// We want to flip phase of |11...1> state after X transformation (which corresponds to |00...0> original)
|
|
1730
|
-
// Target is last qubit, controls are 0 to n-2
|
|
1731
|
-
const diffControls = [];
|
|
1732
|
-
for (let i = 0; i < n - 1; i++)
|
|
1733
|
-
diffControls.push(i);
|
|
1734
|
-
muGate(reg, 'Z', n - 1, diffControls);
|
|
1735
|
-
// 4. Uncompute X
|
|
1736
|
-
for (let i = 0; i < n; i++)
|
|
1737
|
-
muGate(reg, 'X', i);
|
|
1738
|
-
// 5. Uncompute H
|
|
1739
|
-
for (let i = 0; i < n; i++)
|
|
1740
|
-
muGate(reg, 'H', i);
|
|
1741
|
-
}
|
|
1742
|
-
function muEntangle(reg, i, j) {
|
|
1743
|
-
muGate(reg, 'H', i);
|
|
1744
|
-
muGate(reg, 'CNOT', j, i);
|
|
1745
|
-
}
|
|
1746
|
-
/**
|
|
1747
|
-
* Quantum Teleportation Protocol
|
|
1748
|
-
* Transfers the state of `msgIdx` to `targetIdx` using `ancillaIdx` as a resource.
|
|
1749
|
-
* @param reg Register
|
|
1750
|
-
* @param msgIdx The qubit containing the state to teleport (Alice)
|
|
1751
|
-
* @param ancillaIdx The helper qubit (Alice's half of entanglement)
|
|
1752
|
-
* @param targetIdx The destination qubit (Bob)
|
|
1753
|
-
*/
|
|
1754
|
-
function muTeleport(reg, msgIdx, ancillaIdx, targetIdx) {
|
|
1755
|
-
// 1. Create Bell Pair (Entanglement) between Ancilla and Target
|
|
1756
|
-
// Represents the shared link between Alice and Bob
|
|
1757
|
-
muEntangle(reg, ancillaIdx, targetIdx);
|
|
1758
|
-
// 2. Bell Measurement on Message + Ancilla (Alice's side)
|
|
1759
|
-
muGate(reg, 'CNOT', ancillaIdx, msgIdx); // Control: msg, Target: ancilla
|
|
1760
|
-
muGate(reg, 'H', msgIdx);
|
|
1761
|
-
// 3. Measure Alice's qubits (This collapses them)
|
|
1762
|
-
const m1 = muMeasure(reg, msgIdx); // Measures "Z" component
|
|
1763
|
-
const m2 = muMeasure(reg, ancillaIdx); // Measures "X" component
|
|
1764
|
-
// 4. Classical Communication & Correction (Bob's side)
|
|
1765
|
-
// Apply corrections to Target based on measurements
|
|
1766
|
-
if (m2 === 1)
|
|
1767
|
-
muGate(reg, 'X', targetIdx);
|
|
1768
|
-
if (m1 === 1)
|
|
1769
|
-
muGate(reg, 'Z', targetIdx);
|
|
1744
|
+
customElements.define('mu-link', MuLink);
|
|
1770
1745
|
}
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1746
|
+
|
|
1747
|
+
|
|
1748
|
+
/***/ },
|
|
1749
|
+
|
|
1750
|
+
/***/ 598
|
|
1751
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
1752
|
+
|
|
1753
|
+
|
|
1754
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1755
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1756
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1757
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1758
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1759
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1760
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1761
|
+
});
|
|
1762
|
+
};
|
|
1763
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1764
|
+
exports.useMutation = exports.useQuery = void 0;
|
|
1765
|
+
const reactive_1 = __webpack_require__(359);
|
|
1766
|
+
function useQuery(queryFn, options = { enabled: true }) {
|
|
1767
|
+
const state = (0, reactive_1.reactive)({
|
|
1768
|
+
data: null,
|
|
1769
|
+
isLoading: false,
|
|
1770
|
+
error: null
|
|
1771
|
+
});
|
|
1772
|
+
const execute = () => __awaiter(this, void 0, void 0, function* () {
|
|
1773
|
+
state.isLoading = true;
|
|
1774
|
+
state.error = null;
|
|
1775
|
+
try {
|
|
1776
|
+
const result = yield queryFn();
|
|
1777
|
+
state.data = result;
|
|
1786
1778
|
}
|
|
1779
|
+
catch (err) {
|
|
1780
|
+
state.error = err;
|
|
1781
|
+
}
|
|
1782
|
+
finally {
|
|
1783
|
+
state.isLoading = false;
|
|
1784
|
+
}
|
|
1785
|
+
});
|
|
1786
|
+
if (options.enabled) {
|
|
1787
|
+
// Run automatically
|
|
1788
|
+
(0, reactive_1.effect)(() => {
|
|
1789
|
+
// Basic effect wrapper to allow reactivity if queryFn relies on signals
|
|
1790
|
+
execute();
|
|
1791
|
+
});
|
|
1787
1792
|
}
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1793
|
+
return {
|
|
1794
|
+
get data() { return state.data; },
|
|
1795
|
+
get isLoading() { return state.isLoading; },
|
|
1796
|
+
get error() { return state.error; },
|
|
1797
|
+
refetch: execute
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
exports.useQuery = useQuery;
|
|
1801
|
+
function useMutation(mutationFn) {
|
|
1802
|
+
const state = (0, reactive_1.reactive)({
|
|
1803
|
+
data: null,
|
|
1804
|
+
isLoading: false,
|
|
1805
|
+
error: null
|
|
1806
|
+
});
|
|
1807
|
+
const mutate = (args) => __awaiter(this, void 0, void 0, function* () {
|
|
1808
|
+
state.isLoading = true;
|
|
1809
|
+
state.error = null;
|
|
1810
|
+
try {
|
|
1811
|
+
const result = yield mutationFn(args);
|
|
1812
|
+
state.data = result;
|
|
1813
|
+
return result;
|
|
1797
1814
|
}
|
|
1798
|
-
|
|
1799
|
-
|
|
1815
|
+
catch (err) {
|
|
1816
|
+
state.error = err;
|
|
1817
|
+
throw err;
|
|
1818
|
+
}
|
|
1819
|
+
finally {
|
|
1820
|
+
state.isLoading = false;
|
|
1800
1821
|
}
|
|
1801
1822
|
});
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1823
|
+
return {
|
|
1824
|
+
get data() { return state.data; },
|
|
1825
|
+
get isLoading() { return state.isLoading; },
|
|
1826
|
+
get error() { return state.error; },
|
|
1827
|
+
mutate
|
|
1828
|
+
};
|
|
1808
1829
|
}
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1830
|
+
exports.useMutation = useMutation;
|
|
1831
|
+
|
|
1832
|
+
|
|
1833
|
+
/***/ },
|
|
1834
|
+
|
|
1835
|
+
/***/ 615
|
|
1836
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
1837
|
+
|
|
1838
|
+
|
|
1839
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1840
|
+
exports.MuBlochSphereElement = void 0;
|
|
1841
|
+
const reactive_1 = __webpack_require__(359);
|
|
1842
|
+
const MuBlochBase = typeof HTMLElement !== 'undefined' ? HTMLElement : class {
|
|
1843
|
+
};
|
|
1844
|
+
class MuBlochSphereElement extends MuBlochBase {
|
|
1845
|
+
static get observedAttributes() {
|
|
1846
|
+
return ['size'];
|
|
1820
1847
|
}
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
* Enables "Quantum If/Else".
|
|
1828
|
-
*/
|
|
1829
|
-
function muControl(reg, controlQubit, inverse, block) {
|
|
1830
|
-
// 1. Setup Context
|
|
1831
|
-
if (inverse) {
|
|
1832
|
-
muGate(reg, 'X', controlQubit); // Flip 0 to 1 to activate
|
|
1848
|
+
constructor() {
|
|
1849
|
+
super();
|
|
1850
|
+
this._arrow = null;
|
|
1851
|
+
this._container = null;
|
|
1852
|
+
this._disposeEffect = null;
|
|
1853
|
+
this.attachShadow({ mode: 'open' });
|
|
1833
1854
|
}
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
block();
|
|
1855
|
+
connectedCallback() {
|
|
1856
|
+
this.render();
|
|
1837
1857
|
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
muGate(reg, 'X', controlQubit);
|
|
1858
|
+
disconnectedCallback() {
|
|
1859
|
+
if (this._disposeEffect) {
|
|
1860
|
+
this._disposeEffect();
|
|
1861
|
+
this._disposeEffect = null;
|
|
1843
1862
|
}
|
|
1844
1863
|
}
|
|
1845
|
-
}
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
* Because the register can be in a superposition of states (e.g. |0> + |1>),
|
|
1850
|
-
* MULTIPLE branches can execute effectively simultaneously on different subspaces.
|
|
1851
|
-
*
|
|
1852
|
-
* @param reg Quantum Register
|
|
1853
|
-
* @param controlQubit The qubit controlling the switch (Single control for v1)
|
|
1854
|
-
* @param cases Object mapping state (0 or 1) to a function executing quantum operations
|
|
1855
|
-
*/
|
|
1856
|
-
function muSwitch(reg, controlQubit, cases) {
|
|
1857
|
-
if (cases[0]) {
|
|
1858
|
-
muControl(reg, controlQubit, true, cases[0]);
|
|
1864
|
+
// Property setter for 'qubit' (passed as .qubit="${q}" in Mulan)
|
|
1865
|
+
set qubit(val) {
|
|
1866
|
+
this._qubit = val;
|
|
1867
|
+
this.initReactivity();
|
|
1859
1868
|
}
|
|
1860
|
-
|
|
1861
|
-
|
|
1869
|
+
get qubit() {
|
|
1870
|
+
return this._qubit;
|
|
1862
1871
|
}
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
* muBurst - Adaptive Non-blocking Iterator
|
|
1868
|
-
* Processes large arrays in batches within a frame budget (typically 8-16ms)
|
|
1869
|
-
* to keep the UI responsive while executing at near-native loop speeds.
|
|
1870
|
-
*/
|
|
1871
|
-
function muBurst(array, callback, options = {}) {
|
|
1872
|
-
const { chunkSize = 1000, timeout = 8, onProgress } = options;
|
|
1873
|
-
return new Promise((resolve) => {
|
|
1874
|
-
let index = 0;
|
|
1875
|
-
const total = array.length;
|
|
1876
|
-
function process() {
|
|
1877
|
-
const start = performance.now();
|
|
1878
|
-
// Tight loop for high-speed processing
|
|
1879
|
-
while (index < total && (performance.now() - start) < timeout) {
|
|
1880
|
-
// Process in smaller bursts to allow more frequent time checks if needed
|
|
1881
|
-
const endBurst = Math.min(index + chunkSize, total);
|
|
1882
|
-
for (; index < endBurst; index++) {
|
|
1883
|
-
callback(array[index], index);
|
|
1884
|
-
}
|
|
1885
|
-
}
|
|
1886
|
-
if (onProgress) {
|
|
1887
|
-
onProgress((index / total) * 100);
|
|
1888
|
-
}
|
|
1889
|
-
if (index < total) {
|
|
1890
|
-
requestAnimationFrame(process);
|
|
1891
|
-
}
|
|
1892
|
-
else {
|
|
1893
|
-
resolve();
|
|
1894
|
-
}
|
|
1895
|
-
}
|
|
1896
|
-
process();
|
|
1897
|
-
});
|
|
1898
|
-
}
|
|
1899
|
-
/**
|
|
1900
|
-
* muSurge - Truly Parallel Execution
|
|
1901
|
-
* Distributes work across CPU cores using Web Workers.
|
|
1902
|
-
* Logic must be serializable.
|
|
1903
|
-
*/
|
|
1904
|
-
function muSurge(array, taskFn, onProgress) {
|
|
1905
|
-
const n = navigator.hardwareConcurrency || 4;
|
|
1906
|
-
const chunkSize = Math.ceil(array.length / n);
|
|
1907
|
-
const results = new Array(array.length);
|
|
1908
|
-
let completedChunks = 0;
|
|
1909
|
-
let completedItems = 0;
|
|
1910
|
-
// Convert function to string if it isn't already
|
|
1911
|
-
const fnStr = typeof taskFn === 'function' ? taskFn.toString() : taskFn;
|
|
1912
|
-
const workerPart1 = `const taskFn = ${fnStr};`;
|
|
1913
|
-
const workerPart2 = `self.onmessage = function(e) {`;
|
|
1914
|
-
const workerPart3 = ` const { chunk, startIndex } = e.data;`;
|
|
1915
|
-
const workerPart4 = ` try { const results = chunk.map(taskFn); self.postMessage({ results, startIndex }); }`;
|
|
1916
|
-
const workerPart5 = ` catch (err) { self.postMessage({ error: err.message, startIndex }); }`;
|
|
1917
|
-
const workerPart6 = `};`;
|
|
1918
|
-
const workerCode = [workerPart1, workerPart2, workerPart3, workerPart4, workerPart5, workerPart6].join('\n');
|
|
1919
|
-
const blob = new Blob([workerCode], { type: 'application/javascript' });
|
|
1920
|
-
const workerUrl = URL.createObjectURL(blob);
|
|
1921
|
-
return new Promise((resolve) => {
|
|
1922
|
-
if (array.length === 0)
|
|
1923
|
-
return resolve([]);
|
|
1924
|
-
for (let i = 0; i < n; i++) {
|
|
1925
|
-
const start = i * chunkSize;
|
|
1926
|
-
const end = Math.min(start + chunkSize, array.length);
|
|
1927
|
-
if (start >= end) {
|
|
1928
|
-
completedChunks++;
|
|
1929
|
-
continue;
|
|
1930
|
-
}
|
|
1931
|
-
const chunk = array.slice(start, end);
|
|
1932
|
-
const worker = new Worker(workerUrl);
|
|
1933
|
-
worker.onmessage = (e) => {
|
|
1934
|
-
const { results: chunkResults, startIndex } = e.data;
|
|
1935
|
-
// Merge results back into main array
|
|
1936
|
-
for (let j = 0; j < chunkResults.length; j++) {
|
|
1937
|
-
results[startIndex + j] = chunkResults[j];
|
|
1938
|
-
}
|
|
1939
|
-
completedChunks++;
|
|
1940
|
-
completedItems += chunkResults.length;
|
|
1941
|
-
if (onProgress)
|
|
1942
|
-
onProgress((completedItems / array.length) * 100);
|
|
1943
|
-
worker.terminate();
|
|
1944
|
-
if (completedChunks === n) {
|
|
1945
|
-
URL.revokeObjectURL(workerUrl);
|
|
1946
|
-
resolve(results);
|
|
1947
|
-
}
|
|
1948
|
-
};
|
|
1949
|
-
worker.postMessage({ chunk, startIndex: start, fnStr });
|
|
1950
|
-
}
|
|
1951
|
-
});
|
|
1952
|
-
}
|
|
1953
|
-
|
|
1954
|
-
;// ./src/components/bloch-sphere.ts
|
|
1955
|
-
|
|
1956
|
-
class MuBlochSphereElement extends HTMLElement {
|
|
1957
|
-
static get observedAttributes() {
|
|
1958
|
-
return ['size'];
|
|
1959
|
-
}
|
|
1960
|
-
constructor() {
|
|
1961
|
-
super();
|
|
1962
|
-
this._arrow = null;
|
|
1963
|
-
this._container = null;
|
|
1964
|
-
this._disposeEffect = null;
|
|
1965
|
-
this.attachShadow({ mode: 'open' });
|
|
1966
|
-
}
|
|
1967
|
-
connectedCallback() {
|
|
1968
|
-
this.render();
|
|
1969
|
-
}
|
|
1970
|
-
disconnectedCallback() {
|
|
1971
|
-
if (this._disposeEffect) {
|
|
1972
|
-
this._disposeEffect();
|
|
1973
|
-
this._disposeEffect = null;
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
// Property setter for 'qubit' (passed as .qubit="${q}" in Mulan)
|
|
1977
|
-
set qubit(val) {
|
|
1978
|
-
this._qubit = val;
|
|
1979
|
-
this.initReactivity();
|
|
1980
|
-
}
|
|
1981
|
-
get qubit() {
|
|
1982
|
-
return this._qubit;
|
|
1983
|
-
}
|
|
1984
|
-
attributeChangedCallback(name, oldValue, newValue) {
|
|
1985
|
-
if (name === 'size' && this._container) {
|
|
1986
|
-
this._container.style.width = newValue + 'px';
|
|
1987
|
-
this._container.style.height = newValue + 'px';
|
|
1872
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
1873
|
+
if (name === 'size' && this._container) {
|
|
1874
|
+
this._container.style.width = newValue + 'px';
|
|
1875
|
+
this._container.style.height = newValue + 'px';
|
|
1988
1876
|
}
|
|
1989
1877
|
}
|
|
1990
1878
|
initReactivity() {
|
|
@@ -1993,7 +1881,7 @@ class MuBlochSphereElement extends HTMLElement {
|
|
|
1993
1881
|
if (!this._qubit)
|
|
1994
1882
|
return;
|
|
1995
1883
|
// MulanJS Effect: Run whenever the qubit state changes
|
|
1996
|
-
this._disposeEffect = effect(() => {
|
|
1884
|
+
this._disposeEffect = (0, reactive_1.effect)(() => {
|
|
1997
1885
|
const state = this._qubit.value; // Access reactive proxy
|
|
1998
1886
|
if (!state || !state.amplitudes)
|
|
1999
1887
|
return;
|
|
@@ -2200,184 +2088,603 @@ class MuBlochSphereElement extends HTMLElement {
|
|
|
2200
2088
|
this.initReactivity();
|
|
2201
2089
|
}
|
|
2202
2090
|
}
|
|
2091
|
+
exports.MuBlochSphereElement = MuBlochSphereElement;
|
|
2203
2092
|
// Register the custom element
|
|
2204
2093
|
if (typeof customElements !== 'undefined') {
|
|
2205
2094
|
customElements.define('mu-bloch-sphere', MuBlochSphereElement);
|
|
2206
2095
|
}
|
|
2207
2096
|
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
.
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
position: absolute;
|
|
2234
|
-
top: 0;
|
|
2235
|
-
left: 0;
|
|
2236
|
-
width: 100%;
|
|
2237
|
-
}
|
|
2238
|
-
</style>
|
|
2239
|
-
<div class="spacer">
|
|
2240
|
-
<div class="content"></div>
|
|
2241
|
-
</div>
|
|
2242
|
-
`;
|
|
2243
|
-
this.container = this.shadowRoot.host; // The host itself scrolls
|
|
2244
|
-
this.spacer = this.shadowRoot.querySelector('.spacer');
|
|
2245
|
-
this.content = this.shadowRoot.querySelector('.content');
|
|
2246
|
-
this.onScroll = this.onScroll.bind(this);
|
|
2097
|
+
|
|
2098
|
+
/***/ },
|
|
2099
|
+
|
|
2100
|
+
/***/ 619
|
|
2101
|
+
(__unused_webpack_module, exports) {
|
|
2102
|
+
|
|
2103
|
+
|
|
2104
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
2105
|
+
exports.sanitize = exports.hydrate = exports.render = void 0;
|
|
2106
|
+
function render(template, container) {
|
|
2107
|
+
// Focus Preservation (The "Mulan Glance" Technique)
|
|
2108
|
+
let focusedId = null;
|
|
2109
|
+
let selectionStart = null;
|
|
2110
|
+
let selectionEnd = null;
|
|
2111
|
+
let preservedValue = null;
|
|
2112
|
+
if (document.activeElement && container.contains(document.activeElement)) {
|
|
2113
|
+
const el = document.activeElement;
|
|
2114
|
+
if (el.hasAttribute('data-mu-id')) {
|
|
2115
|
+
focusedId = el.getAttribute('data-mu-id');
|
|
2116
|
+
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
|
|
2117
|
+
selectionStart = el.selectionStart;
|
|
2118
|
+
selectionEnd = el.selectionEnd;
|
|
2119
|
+
preservedValue = el.value;
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2247
2122
|
}
|
|
2248
|
-
|
|
2249
|
-
|
|
2123
|
+
// [Anima] 1. Pre-Update: Snapshot positions of animated elements
|
|
2124
|
+
const animationSnapshots = new Map();
|
|
2125
|
+
// Only query if we might have animations to save perf
|
|
2126
|
+
if (typeof template === 'string' && template.includes('mu-animate')) {
|
|
2127
|
+
const animatedEls = container.querySelectorAll('[mu-animate]');
|
|
2128
|
+
animatedEls.forEach(el => {
|
|
2129
|
+
const key = el.getAttribute('mu-key') || el.id;
|
|
2130
|
+
if (key) {
|
|
2131
|
+
animationSnapshots.set(key, el.getBoundingClientRect());
|
|
2132
|
+
}
|
|
2133
|
+
});
|
|
2134
|
+
}
|
|
2135
|
+
if (typeof template === 'string') {
|
|
2136
|
+
container.innerHTML = template;
|
|
2137
|
+
}
|
|
2138
|
+
else {
|
|
2139
|
+
container.innerHTML = '';
|
|
2140
|
+
container.appendChild(template);
|
|
2141
|
+
}
|
|
2142
|
+
// Restore Focus and Value
|
|
2143
|
+
if (focusedId) {
|
|
2144
|
+
const el = container.querySelector(`[data-mu-id="${focusedId}"]`);
|
|
2145
|
+
if (el) {
|
|
2146
|
+
// Restore value first to ensure cursor positioning works correctly
|
|
2147
|
+
if (preservedValue !== null && (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement)) {
|
|
2148
|
+
el.value = preservedValue;
|
|
2149
|
+
}
|
|
2150
|
+
el.focus();
|
|
2151
|
+
if ((el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) && selectionStart !== null) {
|
|
2152
|
+
try {
|
|
2153
|
+
el.setSelectionRange(selectionStart, selectionEnd);
|
|
2154
|
+
}
|
|
2155
|
+
catch (e) {
|
|
2156
|
+
// input types that don't support selection (e.g. number/email) might throw
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
// [Anima] 2. Post-Update: FLIP (First, Last, Invert, Play)
|
|
2162
|
+
if (animationSnapshots.size > 0) {
|
|
2163
|
+
const newAnimatedEls = container.querySelectorAll('[mu-animate]');
|
|
2164
|
+
newAnimatedEls.forEach(el => {
|
|
2165
|
+
const key = el.getAttribute('mu-key') || el.id;
|
|
2166
|
+
if (key && animationSnapshots.has(key)) {
|
|
2167
|
+
const oldRect = animationSnapshots.get(key);
|
|
2168
|
+
const newRect = el.getBoundingClientRect();
|
|
2169
|
+
const dx = oldRect.left - newRect.left;
|
|
2170
|
+
const dy = oldRect.top - newRect.top;
|
|
2171
|
+
// Only animate if moved
|
|
2172
|
+
if (dx !== 0 || dy !== 0) {
|
|
2173
|
+
const htmlEl = el;
|
|
2174
|
+
// INVERT: Move it back to where it was instantly
|
|
2175
|
+
htmlEl.style.transform = `translate(${dx}px, ${dy}px)`;
|
|
2176
|
+
htmlEl.style.transition = 'none';
|
|
2177
|
+
// PLAY: Animate to zero (new position)
|
|
2178
|
+
requestAnimationFrame(() => {
|
|
2179
|
+
// Force reflow
|
|
2180
|
+
// void htmlEl.offsetWidth;
|
|
2181
|
+
htmlEl.style.transition = 'transform 500ms cubic-bezier(0.25, 0.8, 0.25, 1)';
|
|
2182
|
+
htmlEl.style.transform = '';
|
|
2183
|
+
});
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
});
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
exports.render = render;
|
|
2190
|
+
function hydrate(template, container) {
|
|
2191
|
+
// In a string-based framework, hydration is often just "take over".
|
|
2192
|
+
// For now, we'll verify if the server content matches (simple check)
|
|
2193
|
+
// and then assume control. In a more advanced version, we'd attach listeners without re-rendering.
|
|
2194
|
+
if (typeof template === 'string') {
|
|
2195
|
+
if (container.innerHTML.trim() !== template.trim()) {
|
|
2196
|
+
console.warn('Hydration Mismatch: Server rendered content differs from Client.');
|
|
2197
|
+
container.innerHTML = template; // Fallback to full render
|
|
2198
|
+
}
|
|
2199
|
+
else {
|
|
2200
|
+
// console.log('Hydration Successful.');
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
else {
|
|
2204
|
+
container.innerHTML = '';
|
|
2205
|
+
container.appendChild(template);
|
|
2206
|
+
}
|
|
2207
|
+
// Future: Attach event listeners here if we had a mechanism for it.
|
|
2208
|
+
}
|
|
2209
|
+
exports.hydrate = hydrate;
|
|
2210
|
+
function sanitize(str) {
|
|
2211
|
+
// Check if we are in a browser environment
|
|
2212
|
+
if (typeof document !== 'undefined') {
|
|
2213
|
+
const temp = document.createElement('div');
|
|
2214
|
+
temp.textContent = str;
|
|
2215
|
+
return temp.innerHTML;
|
|
2216
|
+
}
|
|
2217
|
+
// Simple SSR fallback sanitizer (rudimentary)
|
|
2218
|
+
return str.replace(/&/g, "&")
|
|
2219
|
+
.replace(/</g, "<")
|
|
2220
|
+
.replace(/>/g, ">")
|
|
2221
|
+
.replace(/"/g, """)
|
|
2222
|
+
.replace(/'/g, "'");
|
|
2223
|
+
}
|
|
2224
|
+
exports.sanitize = sanitize;
|
|
2225
|
+
|
|
2226
|
+
|
|
2227
|
+
/***/ },
|
|
2228
|
+
|
|
2229
|
+
/***/ 678
|
|
2230
|
+
(__unused_webpack_module, exports) {
|
|
2231
|
+
|
|
2232
|
+
|
|
2233
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
2234
|
+
exports.renderToString = void 0;
|
|
2235
|
+
/**
|
|
2236
|
+
* Renders a Mulan component to a static HTML string with a resumability envelope.
|
|
2237
|
+
*/
|
|
2238
|
+
function renderToString(ComponentClass, props = {}) {
|
|
2239
|
+
// 1. Initialize component in a virtual container (not used for DOM)
|
|
2240
|
+
// On server, we mock the container or just pass a dummy object
|
|
2241
|
+
const dummyContainer = {
|
|
2242
|
+
querySelector: () => null,
|
|
2243
|
+
querySelectorAll: () => [],
|
|
2244
|
+
appendChild: () => { },
|
|
2245
|
+
removeChild: () => { },
|
|
2246
|
+
getAttribute: () => null
|
|
2247
|
+
};
|
|
2248
|
+
const instance = new ComponentClass(dummyContainer);
|
|
2249
|
+
// Pass props
|
|
2250
|
+
Object.assign(instance, props);
|
|
2251
|
+
// 2. Render to HTML
|
|
2252
|
+
if (typeof instance.renderToString !== 'function') {
|
|
2253
|
+
throw new Error(`Component ${ComponentClass.name} was not compiled for SSR.`);
|
|
2254
|
+
}
|
|
2255
|
+
const html = instance.renderToString();
|
|
2256
|
+
// 3. Extract State for Resumability
|
|
2257
|
+
// We only want to serialize data that was exposed in setup()
|
|
2258
|
+
// For now, we'll serialize any property on the instance that isn't internal
|
|
2259
|
+
const state = {};
|
|
2260
|
+
for (const key in instance) {
|
|
2261
|
+
if (key.startsWith('_') || key === 'container' || key === 'state' || typeof instance[key] === 'function')
|
|
2262
|
+
continue;
|
|
2263
|
+
const value = instance[key];
|
|
2264
|
+
// Handle signals specifically
|
|
2265
|
+
if (value && typeof value === 'object' && 'value' in value) {
|
|
2266
|
+
state[key] = value.value;
|
|
2267
|
+
}
|
|
2268
|
+
else {
|
|
2269
|
+
state[key] = value;
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
// 4. Construct Resumability Envelope
|
|
2273
|
+
const stateScript = `<script type="mulan/state" data-mu-uid="${instance.$uid}">${JSON.stringify(state)}</script>`;
|
|
2274
|
+
const envelope = `<div data-mu-root="${instance.$uid}">${html}${stateScript}</div>`;
|
|
2275
|
+
return {
|
|
2276
|
+
html,
|
|
2277
|
+
state,
|
|
2278
|
+
envelope
|
|
2279
|
+
};
|
|
2280
|
+
}
|
|
2281
|
+
exports.renderToString = renderToString;
|
|
2282
|
+
|
|
2283
|
+
|
|
2284
|
+
/***/ },
|
|
2285
|
+
|
|
2286
|
+
/***/ 679
|
|
2287
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
2288
|
+
|
|
2289
|
+
|
|
2290
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
2291
|
+
exports.muSwitch = exports.muControl = exports.muParallel = exports.muMeasure = exports.muTeleport = exports.muEntangle = exports.muSearch = exports.muGate = exports.muQubit = exports.muRegister = exports.activeControls = void 0;
|
|
2292
|
+
const hooks_1 = __webpack_require__(166);
|
|
2293
|
+
/**
|
|
2294
|
+
* Mulan Quantum (ASTR-Q+) Core
|
|
2295
|
+
* Advanced Simulation Engine for multi-qubit registers and entanglement.
|
|
2296
|
+
*/
|
|
2297
|
+
// -- GLOBAL CONTEXT FOR QUANTUM CONTROL --
|
|
2298
|
+
// Defined at top to ensure visibility for muGate
|
|
2299
|
+
exports.activeControls = [];
|
|
2300
|
+
/**
|
|
2301
|
+
* Creates a quantum register of size n.
|
|
2302
|
+
* State vector will have 2^n amplitudes.
|
|
2303
|
+
*/
|
|
2304
|
+
function muRegister(n) {
|
|
2305
|
+
const numStates = Math.pow(2, n);
|
|
2306
|
+
const amplitudes = new Array(numStates).fill(0).map((_, i) => ({
|
|
2307
|
+
re: i === 0 ? 1 : 0,
|
|
2308
|
+
im: 0
|
|
2309
|
+
}));
|
|
2310
|
+
return (0, hooks_1.muState)({
|
|
2311
|
+
value: {
|
|
2312
|
+
size: n,
|
|
2313
|
+
amplitudes
|
|
2314
|
+
}
|
|
2315
|
+
});
|
|
2316
|
+
}
|
|
2317
|
+
exports.muRegister = muRegister;
|
|
2318
|
+
/**
|
|
2319
|
+
* Backward compatible muQubit (Single Qubit Register)
|
|
2320
|
+
*/
|
|
2321
|
+
function muQubit(initial = 0) {
|
|
2322
|
+
const q = muRegister(1);
|
|
2323
|
+
if (initial === 1) {
|
|
2324
|
+
muGate(q, 'X', 0);
|
|
2325
|
+
}
|
|
2326
|
+
// Add compatibility properties for Phase 1 components
|
|
2327
|
+
// These properties are getters that dynamically access the amplitudes array
|
|
2328
|
+
Object.defineProperty(q.value, 'alpha', { get: () => q.value.amplitudes[0] });
|
|
2329
|
+
Object.defineProperty(q.value, 'beta', { get: () => q.value.amplitudes[1] });
|
|
2330
|
+
return q;
|
|
2331
|
+
}
|
|
2332
|
+
exports.muQubit = muQubit;
|
|
2333
|
+
/**
|
|
2334
|
+
* Internal helper to update register state while maintaining compatibility
|
|
2335
|
+
*/
|
|
2336
|
+
function updateState(reg, newState) {
|
|
2337
|
+
if (newState.size === 1) {
|
|
2338
|
+
// Re-inject compatibility getters for muQubit users
|
|
2339
|
+
Object.defineProperty(newState, 'alpha', {
|
|
2340
|
+
get: () => newState.amplitudes[0],
|
|
2341
|
+
configurable: true,
|
|
2342
|
+
enumerable: true
|
|
2343
|
+
});
|
|
2344
|
+
Object.defineProperty(newState, 'beta', {
|
|
2345
|
+
get: () => newState.amplitudes[1],
|
|
2346
|
+
configurable: true,
|
|
2347
|
+
enumerable: true
|
|
2348
|
+
});
|
|
2349
|
+
}
|
|
2350
|
+
reg.value = newState;
|
|
2351
|
+
}
|
|
2352
|
+
function muGate(reg, type, target = 0, control) {
|
|
2353
|
+
const state = reg.value;
|
|
2354
|
+
const n = state.size;
|
|
2355
|
+
const amplitudes = state.amplitudes;
|
|
2356
|
+
const newAmps = amplitudes.map(a => (Object.assign({}, a)));
|
|
2357
|
+
// Prepare Effective Control (Explicit Arguments + Global Context)
|
|
2358
|
+
const effectiveControl = [...(control === undefined ? [] : (Array.isArray(control) ? control : [control])), ...exports.activeControls];
|
|
2359
|
+
// Helper: Check if all control bits are 1
|
|
2360
|
+
const checkControl = (index, ctrl) => {
|
|
2361
|
+
if (ctrl === undefined || (Array.isArray(ctrl) && ctrl.length === 0))
|
|
2362
|
+
return true;
|
|
2363
|
+
const ctrls = Array.isArray(ctrl) ? ctrl : [ctrl];
|
|
2364
|
+
return ctrls.every(c => ((index >> c) & 1) === 1);
|
|
2365
|
+
};
|
|
2366
|
+
// SWAP Gate (Unique case: affects 2 targets)
|
|
2367
|
+
if (type === 'SWAP') {
|
|
2368
|
+
const t1 = target;
|
|
2369
|
+
const t2 = control; // SWAP uses control arg as second target
|
|
2370
|
+
// Iterate only half to avoid double swapping
|
|
2371
|
+
for (let i = 0; i < amplitudes.length; i++) {
|
|
2372
|
+
// Check active controls for SWAP too
|
|
2373
|
+
if (exports.activeControls.length > 0 && !checkControl(i, exports.activeControls))
|
|
2374
|
+
continue;
|
|
2375
|
+
const bit1 = (i >> t1) & 1;
|
|
2376
|
+
const bit2 = (i >> t2) & 1;
|
|
2377
|
+
if (bit1 !== bit2) {
|
|
2378
|
+
// Determine the swap partner index
|
|
2379
|
+
// If i has (0,1), partner has (1,0) at those positions
|
|
2380
|
+
const partner = i ^ (1 << t1) ^ (1 << t2);
|
|
2381
|
+
if (i < partner) {
|
|
2382
|
+
const temp = newAmps[i];
|
|
2383
|
+
newAmps[i] = newAmps[partner];
|
|
2384
|
+
newAmps[partner] = temp;
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
updateState(reg, Object.assign(Object.assign({}, state), { amplitudes: newAmps }));
|
|
2389
|
+
return;
|
|
2390
|
+
}
|
|
2391
|
+
// Standard Single-Qubit & Controlled Gates
|
|
2392
|
+
if (type === 'H') {
|
|
2393
|
+
const s = 1 / Math.sqrt(2);
|
|
2394
|
+
const processed = new Set();
|
|
2395
|
+
for (let i = 0; i < state.amplitudes.length; i++) {
|
|
2396
|
+
if (processed.has(i))
|
|
2397
|
+
continue;
|
|
2398
|
+
// Check Controls first
|
|
2399
|
+
if (!checkControl(i, effectiveControl))
|
|
2400
|
+
continue;
|
|
2401
|
+
const targetBit = (i >> target) & 1;
|
|
2402
|
+
const pairedIndex = targetBit ? (i & ~(1 << target)) : (i | (1 << target));
|
|
2403
|
+
const a = state.amplitudes[i];
|
|
2404
|
+
const b = state.amplitudes[pairedIndex];
|
|
2405
|
+
if (targetBit === 0) {
|
|
2406
|
+
newAmps[i] = { re: s * (a.re + b.re), im: s * (a.im + b.im) };
|
|
2407
|
+
newAmps[pairedIndex] = { re: s * (a.re - b.re), im: s * (a.im - b.im) };
|
|
2408
|
+
}
|
|
2409
|
+
else {
|
|
2410
|
+
newAmps[pairedIndex] = { re: s * (b.re + a.re), im: s * (b.im + a.im) };
|
|
2411
|
+
newAmps[i] = { re: s * (b.re - a.re), im: s * (b.im - a.im) };
|
|
2412
|
+
}
|
|
2413
|
+
processed.add(i);
|
|
2414
|
+
processed.add(pairedIndex);
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
else if (type === 'X' || type === 'CNOT') {
|
|
2418
|
+
// CNOT is just Controlled-X
|
|
2419
|
+
for (let i = 0; i < amplitudes.length; i++) {
|
|
2420
|
+
if (!checkControl(i, effectiveControl))
|
|
2421
|
+
continue;
|
|
2422
|
+
const targetBit = (i >> target) & 1;
|
|
2423
|
+
const pairedIndex = targetBit ? (i & ~(1 << target)) : (i | (1 << target));
|
|
2424
|
+
if (i < pairedIndex) {
|
|
2425
|
+
const temp = newAmps[i];
|
|
2426
|
+
newAmps[i] = newAmps[pairedIndex];
|
|
2427
|
+
newAmps[pairedIndex] = temp;
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
else if (type === 'Z' || type === 'CZ') {
|
|
2432
|
+
// Z and CZ are Phase Flips
|
|
2433
|
+
for (let i = 0; i < amplitudes.length; i++) {
|
|
2434
|
+
if (!checkControl(i, effectiveControl))
|
|
2435
|
+
continue;
|
|
2436
|
+
const targetBit = (i >> target) & 1;
|
|
2437
|
+
// Z Gate acts on |1>
|
|
2438
|
+
if (targetBit === 1) {
|
|
2439
|
+
newAmps[i] = { re: -amplitudes[i].re, im: -amplitudes[i].im };
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
else if (type === 'Y') {
|
|
2444
|
+
// Y: |0> -> i|1>, |1> -> -i|0>
|
|
2445
|
+
for (let i = 0; i < amplitudes.length; i++) {
|
|
2446
|
+
if (!checkControl(i, effectiveControl))
|
|
2447
|
+
continue;
|
|
2448
|
+
const targetBit = (i >> target) & 1;
|
|
2449
|
+
const pairedIndex = targetBit ? (i & ~(1 << target)) : (i | (1 << target));
|
|
2450
|
+
if (i < pairedIndex) {
|
|
2451
|
+
// We process pairs (i, pairedIndex) where i has 0 at target, paired has 1
|
|
2452
|
+
const a = newAmps[i]; // Coeff of |0>
|
|
2453
|
+
const b = newAmps[pairedIndex]; // Coeff of |1>
|
|
2454
|
+
// New |0> = -i * Old |1>
|
|
2455
|
+
newAmps[i] = { re: b.im, im: -b.re };
|
|
2456
|
+
// New |1> = i * Old |0>
|
|
2457
|
+
newAmps[pairedIndex] = { re: -a.im, im: a.re };
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
updateState(reg, Object.assign(Object.assign({}, state), { amplitudes: newAmps }));
|
|
2462
|
+
}
|
|
2463
|
+
exports.muGate = muGate;
|
|
2464
|
+
/**
|
|
2465
|
+
* Mulan Search Logic (Grover's Operator)
|
|
2466
|
+
* Automatically constructs a multi-controlled Phase Flip (Z) for a specific target state.
|
|
2467
|
+
* This is the core of the "Quantum Switch" or "Quantum Search" capability.
|
|
2468
|
+
* @param reg Quantum Register
|
|
2469
|
+
* @param targetState The integer state to "search" and mark (e.g. 2 for |10>)
|
|
2470
|
+
*/
|
|
2471
|
+
function muSearch(reg, targetState) {
|
|
2472
|
+
const n = reg.value.size;
|
|
2473
|
+
const controls = [];
|
|
2474
|
+
// 1. Identify which bits are 0 and need wrapping with X gates
|
|
2475
|
+
// Logic: To mark |010>, we want C-C-Z to trigger on 111.
|
|
2476
|
+
// So we apply X to bits that are 0, then C-C-Z, then X again.
|
|
2477
|
+
// We treat the last bit as the 'target' for the Z gate, rest as controls
|
|
2478
|
+
const targetQubit = n - 1;
|
|
2479
|
+
for (let i = 0; i < n; i++) {
|
|
2480
|
+
const bit = (targetState >> i) & 1;
|
|
2481
|
+
if (i === targetQubit) {
|
|
2482
|
+
// If target bit logic requires 0, we flip it to 1 for the Z gate to work
|
|
2483
|
+
if (bit === 0)
|
|
2484
|
+
muGate(reg, 'X', i);
|
|
2485
|
+
}
|
|
2486
|
+
else {
|
|
2487
|
+
controls.push(i);
|
|
2488
|
+
if (bit === 0)
|
|
2489
|
+
muGate(reg, 'X', i);
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
// 2. Apply Multi-Controlled Z
|
|
2493
|
+
muGate(reg, 'Z', targetQubit, controls);
|
|
2494
|
+
// 3. Uncompute (Restore 0s)
|
|
2495
|
+
for (let i = 0; i < n; i++) {
|
|
2496
|
+
const bit = (targetState >> i) & 1;
|
|
2497
|
+
if (bit === 0)
|
|
2498
|
+
muGate(reg, 'X', i);
|
|
2250
2499
|
}
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2500
|
+
// --- GROVER DIFFUSER (Amplification) ---
|
|
2501
|
+
// This flips the probability amplitudes around the mean, boosting the target state.
|
|
2502
|
+
// 1. Apply H to all
|
|
2503
|
+
for (let i = 0; i < n; i++)
|
|
2504
|
+
muGate(reg, 'H', i);
|
|
2505
|
+
// 2. Apply X to all
|
|
2506
|
+
for (let i = 0; i < n; i++)
|
|
2507
|
+
muGate(reg, 'X', i);
|
|
2508
|
+
// 3. Multi-Controlled Z (Reflection about |0...0>)
|
|
2509
|
+
// We want to flip phase of |11...1> state after X transformation (which corresponds to |00...0> original)
|
|
2510
|
+
// Target is last qubit, controls are 0 to n-2
|
|
2511
|
+
const diffControls = [];
|
|
2512
|
+
for (let i = 0; i < n - 1; i++)
|
|
2513
|
+
diffControls.push(i);
|
|
2514
|
+
muGate(reg, 'Z', n - 1, diffControls);
|
|
2515
|
+
// 4. Uncompute X
|
|
2516
|
+
for (let i = 0; i < n; i++)
|
|
2517
|
+
muGate(reg, 'X', i);
|
|
2518
|
+
// 5. Uncompute H
|
|
2519
|
+
for (let i = 0; i < n; i++)
|
|
2520
|
+
muGate(reg, 'H', i);
|
|
2521
|
+
}
|
|
2522
|
+
exports.muSearch = muSearch;
|
|
2523
|
+
function muEntangle(reg, i, j) {
|
|
2524
|
+
muGate(reg, 'H', i);
|
|
2525
|
+
muGate(reg, 'CNOT', j, i);
|
|
2526
|
+
}
|
|
2527
|
+
exports.muEntangle = muEntangle;
|
|
2528
|
+
/**
|
|
2529
|
+
* Quantum Teleportation Protocol
|
|
2530
|
+
* Transfers the state of `msgIdx` to `targetIdx` using `ancillaIdx` as a resource.
|
|
2531
|
+
* @param reg Register
|
|
2532
|
+
* @param msgIdx The qubit containing the state to teleport (Alice)
|
|
2533
|
+
* @param ancillaIdx The helper qubit (Alice's half of entanglement)
|
|
2534
|
+
* @param targetIdx The destination qubit (Bob)
|
|
2535
|
+
*/
|
|
2536
|
+
function muTeleport(reg, msgIdx, ancillaIdx, targetIdx) {
|
|
2537
|
+
// 1. Create Bell Pair (Entanglement) between Ancilla and Target
|
|
2538
|
+
// Represents the shared link between Alice and Bob
|
|
2539
|
+
muEntangle(reg, ancillaIdx, targetIdx);
|
|
2540
|
+
// 2. Bell Measurement on Message + Ancilla (Alice's side)
|
|
2541
|
+
muGate(reg, 'CNOT', ancillaIdx, msgIdx); // Control: msg, Target: ancilla
|
|
2542
|
+
muGate(reg, 'H', msgIdx);
|
|
2543
|
+
// 3. Measure Alice's qubits (This collapses them)
|
|
2544
|
+
const m1 = muMeasure(reg, msgIdx); // Measures "Z" component
|
|
2545
|
+
const m2 = muMeasure(reg, ancillaIdx); // Measures "X" component
|
|
2546
|
+
// 4. Classical Communication & Correction (Bob's side)
|
|
2547
|
+
// Apply corrections to Target based on measurements
|
|
2548
|
+
if (m2 === 1)
|
|
2549
|
+
muGate(reg, 'X', targetIdx);
|
|
2550
|
+
if (m1 === 1)
|
|
2551
|
+
muGate(reg, 'Z', targetIdx);
|
|
2552
|
+
}
|
|
2553
|
+
exports.muTeleport = muTeleport;
|
|
2554
|
+
/**
|
|
2555
|
+
* Measures a specific qubit in the register, collapsing the superposition.
|
|
2556
|
+
* @param reg Quantum Register
|
|
2557
|
+
* @param target Index of qubit to measure
|
|
2558
|
+
* @returns 0 or 1
|
|
2559
|
+
*/
|
|
2560
|
+
function muMeasure(reg, target = 0) {
|
|
2561
|
+
const state = reg.value;
|
|
2562
|
+
const amplitudes = state.amplitudes;
|
|
2563
|
+
let prob0 = 0;
|
|
2564
|
+
// 1. Calculate Probability of |0>
|
|
2565
|
+
for (let i = 0; i < amplitudes.length; i++) {
|
|
2566
|
+
if (((i >> target) & 1) === 0) {
|
|
2567
|
+
const a = amplitudes[i];
|
|
2568
|
+
prob0 += (a.re * a.re) + (a.im * a.im);
|
|
2255
2569
|
}
|
|
2256
2570
|
}
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2571
|
+
// 2. Determine Outcome
|
|
2572
|
+
const result = Math.random() < prob0 ? 0 : 1;
|
|
2573
|
+
const resultProb = result === 0 ? prob0 : (1 - prob0);
|
|
2574
|
+
const normFactor = resultProb > 0 ? (1 / Math.sqrt(resultProb)) : 0;
|
|
2575
|
+
// 3. Collapse the State (Wavefunction Collapse)
|
|
2576
|
+
const newAmps = amplitudes.map((a, i) => {
|
|
2577
|
+
const bit = (i >> target) & 1;
|
|
2578
|
+
if (bit !== result) {
|
|
2579
|
+
return { re: 0, im: 0 };
|
|
2262
2580
|
}
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
}
|
|
2267
|
-
|
|
2268
|
-
|
|
2581
|
+
else {
|
|
2582
|
+
return { re: a.re * normFactor, im: a.im * normFactor };
|
|
2583
|
+
}
|
|
2584
|
+
});
|
|
2585
|
+
// We need to call updateState to ensure reactivity if specialized getters exist
|
|
2586
|
+
// But since this file has updateState internal, we can just call it.
|
|
2587
|
+
// However, the internal updateState function needs to be in scope.
|
|
2588
|
+
// It is defined at line 60. So we are good.
|
|
2589
|
+
updateState(reg, Object.assign(Object.assign({}, state), { amplitudes: newAmps }));
|
|
2590
|
+
return result;
|
|
2591
|
+
}
|
|
2592
|
+
exports.muMeasure = muMeasure;
|
|
2593
|
+
/**
|
|
2594
|
+
* Quantum Loop: Parallel Execution
|
|
2595
|
+
* Applies a gate to multiple qubits "simultaneously" (in simulation steps).
|
|
2596
|
+
* Ideal for initialization (Hadamard Transform) or global operations.
|
|
2597
|
+
* @param reg Quantum Register
|
|
2598
|
+
* @param qubits Array of qubit indices
|
|
2599
|
+
* @param gate Gate type to apply (e.g. 'H', 'X')
|
|
2600
|
+
*/
|
|
2601
|
+
function muParallel(reg, qubits, gate) {
|
|
2602
|
+
if (gate === 'SWAP') {
|
|
2603
|
+
throw new Error("SWAP cannot be applied in parallel (requires pairs).");
|
|
2269
2604
|
}
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2605
|
+
// In a real quantum computer, these happen at t=0.
|
|
2606
|
+
// Here, we loop, but logical time is constant.
|
|
2607
|
+
qubits.forEach(q => muGate(reg, gate, q));
|
|
2608
|
+
}
|
|
2609
|
+
exports.muParallel = muParallel;
|
|
2610
|
+
/**
|
|
2611
|
+
* Applies a block of operations controlled by specific qubits.
|
|
2612
|
+
* Enables "Quantum If/Else".
|
|
2613
|
+
*/
|
|
2614
|
+
function muControl(reg, controlQubit, inverse, block) {
|
|
2615
|
+
// 1. Setup Context
|
|
2616
|
+
if (inverse) {
|
|
2617
|
+
muGate(reg, 'X', controlQubit); // Flip 0 to 1 to activate
|
|
2273
2618
|
}
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2619
|
+
exports.activeControls.push(controlQubit);
|
|
2620
|
+
try {
|
|
2621
|
+
block();
|
|
2277
2622
|
}
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
this.spacer.style.height = `${totalHeight}px`;
|
|
2285
|
-
// Windowing Math
|
|
2286
|
-
const startIndex = Math.floor(scrollTop / this._itemHeight);
|
|
2287
|
-
const buffer = 5;
|
|
2288
|
-
const visibleCount = Math.ceil(hostHeight / this._itemHeight);
|
|
2289
|
-
const renderStart = Math.max(0, startIndex - buffer);
|
|
2290
|
-
const renderEnd = Math.min(this._items.length, startIndex + visibleCount + buffer);
|
|
2291
|
-
const startOffset = renderStart * this._itemHeight;
|
|
2292
|
-
this.content.style.transform = `translateY(${startOffset}px)`;
|
|
2293
|
-
// Render specific slice
|
|
2294
|
-
const visibleItems = this._items.slice(renderStart, renderEnd);
|
|
2295
|
-
// Simple string replacement template engine for the demo
|
|
2296
|
-
// In a real Mulan compilation, this would be an optimized ASTR render
|
|
2297
|
-
let html = '';
|
|
2298
|
-
visibleItems.forEach((item, index) => {
|
|
2299
|
-
const absoluteIndex = renderStart + index;
|
|
2300
|
-
// Basic mustache replacement {{ item.prop }}
|
|
2301
|
-
let rowHtml = this._template
|
|
2302
|
-
.replace(/{{\s*item\s*}}/g, String(item)) // {{ item }}
|
|
2303
|
-
.replace(/{{\s*index\s*}}/g, String(absoluteIndex)); // {{ index }}
|
|
2304
|
-
// Handle object properties: {{ item.name }}
|
|
2305
|
-
if (typeof item === 'object' && item !== null) {
|
|
2306
|
-
rowHtml = rowHtml.replace(/{{\s*item\.(\w+)\s*}}/g, (_, prop) => {
|
|
2307
|
-
return String(item[prop] || '');
|
|
2308
|
-
});
|
|
2309
|
-
}
|
|
2310
|
-
html += `<div style="height: ${this._itemHeight}px; overflow: hidden;">${rowHtml}</div>`;
|
|
2311
|
-
});
|
|
2312
|
-
this.content.innerHTML = html;
|
|
2623
|
+
finally {
|
|
2624
|
+
exports.activeControls.pop();
|
|
2625
|
+
// Uncompute (Restore 0)
|
|
2626
|
+
if (inverse) {
|
|
2627
|
+
muGate(reg, 'X', controlQubit);
|
|
2628
|
+
}
|
|
2313
2629
|
}
|
|
2314
2630
|
}
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2631
|
+
exports.muControl = muControl;
|
|
2632
|
+
/**
|
|
2633
|
+
* Quantum Switch: conditional Logic on Superposition
|
|
2634
|
+
* Executes different logic branches based on the state of control qubits.
|
|
2635
|
+
* Because the register can be in a superposition of states (e.g. |0> + |1>),
|
|
2636
|
+
* MULTIPLE branches can execute effectively simultaneously on different subspaces.
|
|
2637
|
+
*
|
|
2638
|
+
* @param reg Quantum Register
|
|
2639
|
+
* @param controlQubit The qubit controlling the switch (Single control for v1)
|
|
2640
|
+
* @param cases Object mapping state (0 or 1) to a function executing quantum operations
|
|
2641
|
+
*/
|
|
2642
|
+
function muSwitch(reg, controlQubit, cases) {
|
|
2643
|
+
if (cases[0]) {
|
|
2644
|
+
muControl(reg, controlQubit, true, cases[0]);
|
|
2645
|
+
}
|
|
2646
|
+
if (cases[1]) {
|
|
2647
|
+
muControl(reg, controlQubit, false, cases[1]);
|
|
2648
|
+
}
|
|
2318
2649
|
}
|
|
2650
|
+
exports.muSwitch = muSwitch;
|
|
2319
2651
|
|
|
2320
|
-
;// ./src/index.ts
|
|
2321
2652
|
|
|
2653
|
+
/***/ }
|
|
2322
2654
|
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
Object.freeze(Mulan);
|
|
2358
|
-
Object.freeze(Mulan.Security);
|
|
2359
|
-
// MULAN INSIGHT: Initialize Global Registry
|
|
2360
|
-
if (typeof window !== 'undefined') {
|
|
2361
|
-
window.__MULAN_INSIGHT__ = window.__MULAN_INSIGHT__ || { components: new Map() };
|
|
2362
|
-
// MULAN INSIGHT: HMR Support
|
|
2363
|
-
window.__MULAN_REFRESH__ = () => {
|
|
2364
|
-
var _a;
|
|
2365
|
-
const components = (_a = window.__MULAN_INSIGHT__) === null || _a === void 0 ? void 0 : _a.components;
|
|
2366
|
-
if (components) {
|
|
2367
|
-
components.forEach((comp) => {
|
|
2368
|
-
if (comp && typeof comp.update === 'function') {
|
|
2369
|
-
// Force refresh
|
|
2370
|
-
comp.update();
|
|
2371
|
-
}
|
|
2372
|
-
});
|
|
2373
|
-
}
|
|
2374
|
-
};
|
|
2375
|
-
}
|
|
2376
|
-
if (typeof window !== 'undefined') {
|
|
2377
|
-
window.Mulan = Mulan;
|
|
2378
|
-
}
|
|
2379
|
-
/* harmony default export */ const src = (Mulan);
|
|
2380
|
-
|
|
2381
|
-
export { MuComponent as Component, MuBlochSphereElement, MuComponent, MuInfinity, MuRouter, MuStore, MuRouter as Router, Security, Signal, activeControls, src as default, defineComponent, effect, getCurrentInstance, hydrate, muBurst, muControl, muDebounced, muEffect, muEntangle, muGate, muGeom, muHistory, muMeasure, muMemo, muParallel, muPulse, muQubit, muRegister, muSearch, muState, muSurge, muSuspense, muSwitch, muTeleport, muThrottled, muVault, onMuDestroy, onMuIdle, onMuInit, onMuMount, onMuPanic, onMuResume, onMuShake, onMuVisibility, onMuVoice, persistent, reactive, ref, render, renderToString, sanitize, setCurrentInstance, useMutation, useQuery };
|
|
2655
|
+
/******/ });
|
|
2656
|
+
/************************************************************************/
|
|
2657
|
+
/******/ // The module cache
|
|
2658
|
+
/******/ var __webpack_module_cache__ = {};
|
|
2659
|
+
/******/
|
|
2660
|
+
/******/ // The require function
|
|
2661
|
+
/******/ function __webpack_require__(moduleId) {
|
|
2662
|
+
/******/ // Check if module is in cache
|
|
2663
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
2664
|
+
/******/ if (cachedModule !== undefined) {
|
|
2665
|
+
/******/ return cachedModule.exports;
|
|
2666
|
+
/******/ }
|
|
2667
|
+
/******/ // Create a new module (and put it into the cache)
|
|
2668
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
2669
|
+
/******/ // no module.id needed
|
|
2670
|
+
/******/ // no module.loaded needed
|
|
2671
|
+
/******/ exports: {}
|
|
2672
|
+
/******/ };
|
|
2673
|
+
/******/
|
|
2674
|
+
/******/ // Execute the module function
|
|
2675
|
+
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
2676
|
+
/******/
|
|
2677
|
+
/******/ // Return the exports of the module
|
|
2678
|
+
/******/ return module.exports;
|
|
2679
|
+
/******/ }
|
|
2680
|
+
/******/
|
|
2681
|
+
/************************************************************************/
|
|
2682
|
+
/******/
|
|
2683
|
+
/******/ // startup
|
|
2684
|
+
/******/ // Load entry module and return exports
|
|
2685
|
+
/******/ // This entry module is referenced by other modules so it can't be inlined
|
|
2686
|
+
/******/ var __webpack_exports__ = __webpack_require__(156);
|
|
2687
|
+
/******/ export { __webpack_exports__ as default };
|
|
2688
|
+
/******/
|
|
2382
2689
|
|
|
2383
2690
|
//# sourceMappingURL=mulan.esm.js.map
|