@mulanjs/mulanjs 1.0.1-dev.20260220123726 → 1.0.1-dev.20260220131258
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/mulan.esm.js +1643 -1933
- package/dist/mulan.esm.js.map +1 -0
- package/dist/mulan.js +2022 -177
- package/dist/mulan.js.map +1 -0
- package/package.json +13 -2
package/dist/mulan.esm.js
CHANGED
|
@@ -1,585 +1,377 @@
|
|
|
1
|
-
/******/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
/******/ // The require scope
|
|
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__ = {};
|
|
14
35
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
muEffect: () => (muEffect),
|
|
42
|
+
muGeom: () => (muGeom),
|
|
43
|
+
muMemo: () => (muMemo),
|
|
44
|
+
muPulse: () => (muPulse),
|
|
45
|
+
muState: () => (muState),
|
|
46
|
+
muVault: () => (muVault),
|
|
47
|
+
onMuDestroy: () => (onMuDestroy),
|
|
48
|
+
onMuIdle: () => (onMuIdle),
|
|
49
|
+
onMuInit: () => (onMuInit),
|
|
50
|
+
onMuMount: () => (onMuMount),
|
|
51
|
+
onMuResume: () => (onMuResume),
|
|
52
|
+
onMuShake: () => (onMuShake),
|
|
53
|
+
onMuVoice: () => (onMuVoice),
|
|
54
|
+
setCurrentInstance: () => (setCurrentInstance)
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// NAMESPACE OBJECT: ./src/core/query.ts
|
|
58
|
+
var query_namespaceObject = {};
|
|
59
|
+
__webpack_require__.r(query_namespaceObject);
|
|
60
|
+
__webpack_require__.d(query_namespaceObject, {
|
|
61
|
+
useMutation: () => (useMutation),
|
|
62
|
+
useQuery: () => (useQuery)
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// NAMESPACE OBJECT: ./src/core/quantum.ts
|
|
66
|
+
var quantum_namespaceObject = {};
|
|
67
|
+
__webpack_require__.r(quantum_namespaceObject);
|
|
68
|
+
__webpack_require__.d(quantum_namespaceObject, {
|
|
69
|
+
activeControls: () => (activeControls),
|
|
70
|
+
muControl: () => (muControl),
|
|
71
|
+
muEntangle: () => (muEntangle),
|
|
72
|
+
muGate: () => (muGate),
|
|
73
|
+
muMeasure: () => (muMeasure),
|
|
74
|
+
muParallel: () => (muParallel),
|
|
75
|
+
muQubit: () => (muQubit),
|
|
76
|
+
muRegister: () => (muRegister),
|
|
77
|
+
muSearch: () => (muSearch),
|
|
78
|
+
muSwitch: () => (muSwitch),
|
|
79
|
+
muTeleport: () => (muTeleport)
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// NAMESPACE OBJECT: ./src/core/surge.ts
|
|
83
|
+
var surge_namespaceObject = {};
|
|
84
|
+
__webpack_require__.r(surge_namespaceObject);
|
|
85
|
+
__webpack_require__.d(surge_namespaceObject, {
|
|
86
|
+
muBurst: () => (muBurst),
|
|
87
|
+
muSurge: () => (muSurge)
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// NAMESPACE OBJECT: ./src/components/infinity-list.ts
|
|
91
|
+
var infinity_list_namespaceObject = {};
|
|
92
|
+
__webpack_require__.r(infinity_list_namespaceObject);
|
|
93
|
+
__webpack_require__.d(infinity_list_namespaceObject, {
|
|
94
|
+
MuInfinity: () => (MuInfinity)
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
;// ./src/core/reactive.ts
|
|
98
|
+
// MulanJS 2.0: Signal-Powered Reactivity Engine
|
|
99
|
+
// "Compatible Surface, World-Class Engine"
|
|
100
|
+
let activeEffect = null;
|
|
101
|
+
const targetMap = new WeakMap();
|
|
102
|
+
// --- Signal Core (The Engine) ---
|
|
103
|
+
class Signal {
|
|
104
|
+
constructor(initialValue) {
|
|
105
|
+
this._subscribers = new Set();
|
|
106
|
+
this._value = initialValue;
|
|
25
107
|
}
|
|
26
|
-
|
|
27
|
-
|
|
108
|
+
get value() {
|
|
109
|
+
if (activeEffect) {
|
|
110
|
+
this._subscribers.add(activeEffect);
|
|
111
|
+
}
|
|
112
|
+
return this._value;
|
|
28
113
|
}
|
|
29
|
-
|
|
30
|
-
if (this.
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
114
|
+
set value(newValue) {
|
|
115
|
+
if (newValue !== this._value) {
|
|
116
|
+
this._value = newValue;
|
|
117
|
+
this.notify();
|
|
33
118
|
}
|
|
34
119
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this._qubit = val;
|
|
38
|
-
this.initReactivity();
|
|
120
|
+
notify() {
|
|
121
|
+
this._subscribers.forEach(fn => fn());
|
|
39
122
|
}
|
|
40
|
-
|
|
41
|
-
|
|
123
|
+
}
|
|
124
|
+
// --- Compatibility Layer (The Surface) ---
|
|
125
|
+
function effect(fn) {
|
|
126
|
+
let stopped = false;
|
|
127
|
+
const run = () => {
|
|
128
|
+
if (stopped)
|
|
129
|
+
return;
|
|
130
|
+
const prev = activeEffect;
|
|
131
|
+
activeEffect = run;
|
|
132
|
+
try {
|
|
133
|
+
fn();
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
activeEffect = prev;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
run();
|
|
140
|
+
return () => {
|
|
141
|
+
stopped = true;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function track(target, key) {
|
|
145
|
+
if (activeEffect) {
|
|
146
|
+
let depsMap = targetMap.get(target);
|
|
147
|
+
if (!depsMap) {
|
|
148
|
+
targetMap.set(target, (depsMap = new Map()));
|
|
149
|
+
}
|
|
150
|
+
let dep = depsMap.get(key);
|
|
151
|
+
if (!dep) {
|
|
152
|
+
depsMap.set(key, (dep = new Set()));
|
|
153
|
+
}
|
|
154
|
+
dep.add(activeEffect);
|
|
42
155
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
156
|
+
}
|
|
157
|
+
function trigger(target, key) {
|
|
158
|
+
const depsMap = targetMap.get(target);
|
|
159
|
+
if (!depsMap)
|
|
160
|
+
return;
|
|
161
|
+
const dep = depsMap.get(key);
|
|
162
|
+
if (dep) {
|
|
163
|
+
dep.forEach((fn) => fn());
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Creates a reactive proxy object (Vue-compatible).
|
|
168
|
+
* Now optimized to respect Mulan Cycle.
|
|
169
|
+
*/
|
|
170
|
+
function reactive(target) {
|
|
171
|
+
return new Proxy(target, {
|
|
172
|
+
get(obj, prop, receiver) {
|
|
173
|
+
// IRON FORTRESS: Prototype Pollution Protection (Read)
|
|
174
|
+
if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
track(obj, prop);
|
|
178
|
+
const val = Reflect.get(obj, prop, receiver);
|
|
179
|
+
if (val !== null && typeof val === 'object') {
|
|
180
|
+
return reactive(val);
|
|
181
|
+
}
|
|
182
|
+
return val;
|
|
183
|
+
},
|
|
184
|
+
set(obj, prop, value, receiver) {
|
|
185
|
+
// IRON FORTRESS: Prototype Pollution Protection
|
|
186
|
+
if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') {
|
|
187
|
+
console.warn(`[Iron Fortress] Blocked attempt to modify dangerous property: ${String(prop)}`);
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
const result = Reflect.set(obj, prop, value, receiver);
|
|
191
|
+
trigger(obj, prop);
|
|
192
|
+
return result;
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Creates a standalone reactive reference.
|
|
198
|
+
* Backed by the Mulan Signal Engine.
|
|
199
|
+
*/
|
|
200
|
+
function ref(value) {
|
|
201
|
+
return new Signal(value);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
;// ./src/core/renderer.ts
|
|
205
|
+
function render(template, container) {
|
|
206
|
+
// Focus Preservation (The "Mulan Glance" Technique)
|
|
207
|
+
let focusedId = null;
|
|
208
|
+
let selectionStart = null;
|
|
209
|
+
let selectionEnd = null;
|
|
210
|
+
let preservedValue = null;
|
|
211
|
+
if (document.activeElement && container.contains(document.activeElement)) {
|
|
212
|
+
const el = document.activeElement;
|
|
213
|
+
if (el.hasAttribute('data-mu-id')) {
|
|
214
|
+
focusedId = el.getAttribute('data-mu-id');
|
|
215
|
+
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
|
|
216
|
+
selectionStart = el.selectionStart;
|
|
217
|
+
selectionEnd = el.selectionEnd;
|
|
218
|
+
preservedValue = el.value;
|
|
219
|
+
}
|
|
47
220
|
}
|
|
48
221
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return;
|
|
59
|
-
// Assume Single Qubit for Visualizer (Index 0 if passed a register)
|
|
60
|
-
// If passed a register, we visualize the first qubit's logical projection (partial trace simplified)
|
|
61
|
-
// Or assume input IS a specific qubit projection?
|
|
62
|
-
// For simplified demo, we assume the register is size 1 OR we visualize Q0 of the register.
|
|
63
|
-
const amps = state.amplitudes;
|
|
64
|
-
// Support 1-qubit visualization from N-qubit register requires partial trace.
|
|
65
|
-
// For now, let's assume the user passes a 1-qubit register OR we visualize index 0.
|
|
66
|
-
// |psi> = a|0> + b|1>
|
|
67
|
-
// a = amps[0] (re, im)
|
|
68
|
-
// b = amps[1] (re, im)
|
|
69
|
-
// Dealing with multi-qubit registers (naive projection for visualization):
|
|
70
|
-
// We sum up probabilities for 0xxxx vs 1xxxx to get Z-axis.
|
|
71
|
-
// This is "marginal probability".
|
|
72
|
-
let p0 = 0;
|
|
73
|
-
let p1 = 0;
|
|
74
|
-
// Calculate Probabilities
|
|
75
|
-
for (let i = 0; i < amps.length; i++) {
|
|
76
|
-
const mag = amps[i].re * amps[i].re + amps[i].im * amps[i].im;
|
|
77
|
-
if ((i & 1) === 0)
|
|
78
|
-
p0 += mag;
|
|
79
|
-
else
|
|
80
|
-
p1 += mag;
|
|
222
|
+
// [Anima] 1. Pre-Update: Snapshot positions of animated elements
|
|
223
|
+
const animationSnapshots = new Map();
|
|
224
|
+
// Only query if we might have animations to save perf
|
|
225
|
+
if (template.includes('mu-animate')) {
|
|
226
|
+
const animatedEls = container.querySelectorAll('[mu-animate]');
|
|
227
|
+
animatedEls.forEach(el => {
|
|
228
|
+
const key = el.getAttribute('mu-key') || el.id;
|
|
229
|
+
if (key) {
|
|
230
|
+
animationSnapshots.set(key, el.getBoundingClientRect());
|
|
81
231
|
}
|
|
82
|
-
// Theta from Z-projection
|
|
83
|
-
// P0 = cos^2(theta/2) -> theta = 2 * acos(sqrt(P0))
|
|
84
|
-
const theta = 2 * Math.acos(Math.min(1, Math.sqrt(p0)));
|
|
85
|
-
// Phi?
|
|
86
|
-
// Phase is relative phase between |0> and |1>.
|
|
87
|
-
// We can look at the phase of the '1' component relative to '0'.
|
|
88
|
-
// Simple approach: Look at amps[1] phase vs amps[0] phase.
|
|
89
|
-
// But with entanglement, pure state phase is tricky.
|
|
90
|
-
// Let's implement full density matrix if needed, but for now:
|
|
91
|
-
// naive: atan2(amps[1].im, amps[1].re) - atan2(amps[0].im, amps[0].re)
|
|
92
|
-
// We use the first pair (0 and 1) as proxy if multiple.
|
|
93
|
-
const a0 = amps[0];
|
|
94
|
-
const a1 = amps[1]; // Valid for N>=1
|
|
95
|
-
const phase0 = Math.atan2(a0.im, a0.re);
|
|
96
|
-
const phase1 = Math.atan2(a1.im, a1.re);
|
|
97
|
-
let phi = phase1 - phase0;
|
|
98
|
-
// Update Arrow
|
|
99
|
-
this.updateArrow(theta, phi);
|
|
100
232
|
});
|
|
101
233
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// rotateY(phi) ? No, phi rotates around Z-axis (Vertical).
|
|
122
|
-
// theta rotates from Z-axis down.
|
|
123
|
-
// CSS:
|
|
124
|
-
// rotateY(phi) -> Rotates around Vertical axis.
|
|
125
|
-
// rotateZ(theta) -> Rotates "down" from up?
|
|
126
|
-
// Let's simplify:
|
|
127
|
-
// transform: rotateY(${phi}rad) rotateZ(${theta}rad)
|
|
128
|
-
// Note: CSS rotations order matters.
|
|
129
|
-
const degTheta = theta * (180 / Math.PI);
|
|
130
|
-
const degPhi = phi * (180 / Math.PI);
|
|
131
|
-
// Adjustment for visual alignment
|
|
132
|
-
this._arrow.style.transform = `rotateY(${degPhi}deg) rotateZ(${degTheta}deg)`;
|
|
133
|
-
// Color based on state
|
|
134
|
-
const isSuperposition = Math.abs(theta - Math.PI / 2) < 0.1;
|
|
135
|
-
this._arrow.style.backgroundColor = isSuperposition ? '#00ffff' : '#ff00ff';
|
|
234
|
+
container.innerHTML = template;
|
|
235
|
+
// Restore Focus and Value
|
|
236
|
+
if (focusedId) {
|
|
237
|
+
const el = container.querySelector(`[data-mu-id="${focusedId}"]`);
|
|
238
|
+
if (el) {
|
|
239
|
+
// Restore value first to ensure cursor positioning works correctly
|
|
240
|
+
if (preservedValue !== null && (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement)) {
|
|
241
|
+
el.value = preservedValue;
|
|
242
|
+
}
|
|
243
|
+
el.focus();
|
|
244
|
+
if ((el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) && selectionStart !== null) {
|
|
245
|
+
try {
|
|
246
|
+
el.setSelectionRange(selectionStart, selectionEnd);
|
|
247
|
+
}
|
|
248
|
+
catch (e) {
|
|
249
|
+
// input types that don't support selection (e.g. number/email) might throw
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
136
253
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
transform
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
/* Equator Ring */
|
|
165
|
-
.equator {
|
|
166
|
-
position: absolute;
|
|
167
|
-
top: 50%;
|
|
168
|
-
left: 0;
|
|
169
|
-
width: 100%;
|
|
170
|
-
height: 100%;
|
|
171
|
-
border: 1px dashed rgba(255, 255, 255, 0.3);
|
|
172
|
-
border-radius: 50%;
|
|
173
|
-
transform: rotateX(90deg);
|
|
174
|
-
pointer-events: none;
|
|
175
|
-
}
|
|
176
|
-
/* Axis Lines */
|
|
177
|
-
.axis {
|
|
178
|
-
position: absolute;
|
|
179
|
-
background: rgba(255, 255, 255, 0.1);
|
|
180
|
-
}
|
|
181
|
-
.z-axis { width: 2px; height: 100%; left: 50%; top: 0; }
|
|
182
|
-
|
|
183
|
-
/* The Quantum Arrow */
|
|
184
|
-
.arrow-container {
|
|
185
|
-
position: absolute;
|
|
186
|
-
top: 50%;
|
|
187
|
-
left: 50%;
|
|
188
|
-
width: 0;
|
|
189
|
-
height: 0;
|
|
190
|
-
transform-style: preserve-3d;
|
|
191
|
-
transform: rotateX(15deg) rotateY(15deg); /* Match sphere tilt */
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
.arrow-pivot {
|
|
195
|
-
position: absolute;
|
|
196
|
-
top: 0;
|
|
197
|
-
left: 0;
|
|
198
|
-
width: 4px;
|
|
199
|
-
height: 50%; /* Length of radius */
|
|
200
|
-
/* Pivot logic: we want to rotate around the center point */
|
|
201
|
-
/* CSS Default transform-origin is 50% 50% */
|
|
202
|
-
/* We construct the arrow such that it points UP from center */
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
.arrow-rod {
|
|
206
|
-
width: 4px;
|
|
207
|
-
height: ${parseInt(size) / 2 - 10}px;
|
|
208
|
-
background: #ff00ff;
|
|
209
|
-
position: absolute;
|
|
210
|
-
bottom: 0;
|
|
211
|
-
left: -2px;
|
|
212
|
-
transform-origin: bottom center;
|
|
213
|
-
transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), background-color 0.3s;
|
|
214
|
-
border-radius: 2px;
|
|
215
|
-
box-shadow: 0 0 10px currentColor;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
.arrow-head {
|
|
219
|
-
width: 0;
|
|
220
|
-
height: 0;
|
|
221
|
-
border-left: 6px solid transparent;
|
|
222
|
-
border-right: 6px solid transparent;
|
|
223
|
-
border-bottom: 12px solid #ff00ff;
|
|
224
|
-
position: absolute;
|
|
225
|
-
top: -10px;
|
|
226
|
-
left: -6px;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
.label {
|
|
230
|
-
position: absolute;
|
|
231
|
-
color: #aaa;
|
|
232
|
-
font-family: monospace;
|
|
233
|
-
font-size: 10px;
|
|
234
|
-
}
|
|
235
|
-
.label-0 { top: 5px; left: 50%; transform: translateX(-50%); }
|
|
236
|
-
.label-1 { bottom: 5px; left: 50%; transform: translateX(-50%); }
|
|
237
|
-
</style>
|
|
238
|
-
|
|
239
|
-
<div class="sphere-container">
|
|
240
|
-
<div class="sphere">
|
|
241
|
-
<div class="equator"></div>
|
|
242
|
-
<div class="axis z-axis"></div>
|
|
243
|
-
<div class="label label-0">|0></div>
|
|
244
|
-
<div class="label label-1">|1></div>
|
|
245
|
-
</div>
|
|
246
|
-
|
|
247
|
-
<div class="arrow-container">
|
|
248
|
-
<!-- The rod is the actual rotating element -->
|
|
249
|
-
<div class="arrow-rod">
|
|
250
|
-
<div class="arrow-head"></div>
|
|
251
|
-
</div>
|
|
252
|
-
</div>
|
|
253
|
-
</div>
|
|
254
|
-
`;
|
|
255
|
-
this._container = this.shadowRoot.querySelector('.sphere-container');
|
|
256
|
-
this._arrow = this.shadowRoot.querySelector('.arrow-rod');
|
|
257
|
-
// Re-init reactivity if qubit was set before render
|
|
258
|
-
if (this._qubit)
|
|
259
|
-
this.initReactivity();
|
|
254
|
+
// [Anima] 2. Post-Update: FLIP (First, Last, Invert, Play)
|
|
255
|
+
if (animationSnapshots.size > 0) {
|
|
256
|
+
const newAnimatedEls = container.querySelectorAll('[mu-animate]');
|
|
257
|
+
newAnimatedEls.forEach(el => {
|
|
258
|
+
const key = el.getAttribute('mu-key') || el.id;
|
|
259
|
+
if (key && animationSnapshots.has(key)) {
|
|
260
|
+
const oldRect = animationSnapshots.get(key);
|
|
261
|
+
const newRect = el.getBoundingClientRect();
|
|
262
|
+
const dx = oldRect.left - newRect.left;
|
|
263
|
+
const dy = oldRect.top - newRect.top;
|
|
264
|
+
// Only animate if moved
|
|
265
|
+
if (dx !== 0 || dy !== 0) {
|
|
266
|
+
const htmlEl = el;
|
|
267
|
+
// INVERT: Move it back to where it was instantly
|
|
268
|
+
htmlEl.style.transform = `translate(${dx}px, ${dy}px)`;
|
|
269
|
+
htmlEl.style.transition = 'none';
|
|
270
|
+
// PLAY: Animate to zero (new position)
|
|
271
|
+
requestAnimationFrame(() => {
|
|
272
|
+
// Force reflow
|
|
273
|
+
// void htmlEl.offsetWidth;
|
|
274
|
+
htmlEl.style.transition = 'transform 500ms cubic-bezier(0.25, 0.8, 0.25, 1)';
|
|
275
|
+
htmlEl.style.transform = '';
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
});
|
|
260
280
|
}
|
|
261
281
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
282
|
+
function hydrate(template, container) {
|
|
283
|
+
// In a string-based framework, hydration is often just "take over".
|
|
284
|
+
// For now, we'll verify if the server content matches (simple check)
|
|
285
|
+
// and then assume control. In a more advanced version, we'd attach listeners without re-rendering.
|
|
286
|
+
if (container.innerHTML.trim() !== template.trim()) {
|
|
287
|
+
console.warn('Hydration Mismatch: Server rendered content differs from Client.');
|
|
288
|
+
container.innerHTML = template; // Fallback to full render
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
// console.log('Hydration Successful.');
|
|
292
|
+
}
|
|
293
|
+
// Future: Attach event listeners here if we had a mechanism for it.
|
|
294
|
+
}
|
|
295
|
+
function renderToString(template) {
|
|
296
|
+
// SSR Function: returns the HTML string for the server to send.
|
|
297
|
+
// Can include additional sanitization or metadata injection here.
|
|
298
|
+
return template;
|
|
299
|
+
}
|
|
300
|
+
function sanitize(str) {
|
|
301
|
+
// Check if we are in a browser environment
|
|
302
|
+
if (typeof document !== 'undefined') {
|
|
303
|
+
const temp = document.createElement('div');
|
|
304
|
+
temp.textContent = str;
|
|
305
|
+
return temp.innerHTML;
|
|
306
|
+
}
|
|
307
|
+
// Simple SSR fallback sanitizer (rudimentary)
|
|
308
|
+
return str.replace(/&/g, "&")
|
|
309
|
+
.replace(/</g, "<")
|
|
310
|
+
.replace(/>/g, ">")
|
|
311
|
+
.replace(/"/g, """)
|
|
312
|
+
.replace(/'/g, "'");
|
|
265
313
|
}
|
|
266
314
|
|
|
315
|
+
;// ./src/core/vault.ts
|
|
267
316
|
|
|
268
|
-
/***/ },
|
|
269
|
-
|
|
270
|
-
/***/ "./src/components/infinity-list.ts"
|
|
271
|
-
/*!*****************************************!*\
|
|
272
|
-
!*** ./src/components/infinity-list.ts ***!
|
|
273
|
-
\*****************************************/
|
|
274
|
-
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
275
317
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
// Structure:
|
|
288
|
-
// :host { overflow-y: auto; display: block; height: 100%; }
|
|
289
|
-
// .spacer { height: totalHeight; position: relative; }
|
|
290
|
-
// .content { position: absolute; top: padding; width: 100%; }
|
|
291
|
-
this.shadowRoot.innerHTML = `
|
|
292
|
-
<style>
|
|
293
|
-
:host {
|
|
294
|
-
display: block;
|
|
295
|
-
overflow-y: auto;
|
|
296
|
-
height: 100%;
|
|
297
|
-
position: relative;
|
|
298
|
-
}
|
|
299
|
-
.spacer {
|
|
300
|
-
position: relative;
|
|
301
|
-
width: 100%;
|
|
302
|
-
}
|
|
303
|
-
.content {
|
|
304
|
-
position: absolute;
|
|
305
|
-
top: 0;
|
|
306
|
-
left: 0;
|
|
307
|
-
width: 100%;
|
|
308
|
-
}
|
|
309
|
-
</style>
|
|
310
|
-
<div class="spacer">
|
|
311
|
-
<div class="content"></div>
|
|
312
|
-
</div>
|
|
313
|
-
`;
|
|
314
|
-
this.container = this.shadowRoot.host; // The host itself scrolls
|
|
315
|
-
this.spacer = this.shadowRoot.querySelector('.spacer');
|
|
316
|
-
this.content = this.shadowRoot.querySelector('.content');
|
|
317
|
-
this.onScroll = this.onScroll.bind(this);
|
|
318
|
-
}
|
|
319
|
-
static get observedAttributes() {
|
|
320
|
-
return ['item-height'];
|
|
321
|
-
}
|
|
322
|
-
attributeChangedCallback(name, oldValue, newValue) {
|
|
323
|
-
if (name === 'item-height') {
|
|
324
|
-
this._itemHeight = parseInt(newValue, 10) || 50;
|
|
325
|
-
this.renderVisible();
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
connectedCallback() {
|
|
329
|
-
// Find the template provided by the user (Support both standard and branded tags)
|
|
330
|
-
const templateTag = this.querySelector('template') || this.querySelector('mu-template');
|
|
331
|
-
if (templateTag) {
|
|
332
|
-
this._template = templateTag.innerHTML;
|
|
333
|
-
}
|
|
334
|
-
this.addEventListener('scroll', this.onScroll);
|
|
335
|
-
// Wait for next frame to get initial height if not set
|
|
336
|
-
requestAnimationFrame(() => this.renderVisible());
|
|
337
|
-
}
|
|
338
|
-
disconnectedCallback() {
|
|
339
|
-
this.removeEventListener('scroll', this.onScroll);
|
|
340
|
-
}
|
|
341
|
-
set items(value) {
|
|
342
|
-
this._items = value;
|
|
343
|
-
this.renderVisible();
|
|
344
|
-
}
|
|
345
|
-
get items() { return this._items; }
|
|
346
|
-
onScroll() {
|
|
347
|
-
requestAnimationFrame(() => this.renderVisible());
|
|
348
|
-
}
|
|
349
|
-
renderVisible() {
|
|
350
|
-
if (!this._items.length)
|
|
351
|
-
return;
|
|
352
|
-
const scrollTop = this.scrollTop;
|
|
353
|
-
const hostHeight = this.clientHeight || 400; // Default fallback if not sized
|
|
354
|
-
const totalHeight = this._items.length * this._itemHeight;
|
|
355
|
-
this.spacer.style.height = `${totalHeight}px`;
|
|
356
|
-
// Windowing Math
|
|
357
|
-
const startIndex = Math.floor(scrollTop / this._itemHeight);
|
|
358
|
-
const buffer = 5;
|
|
359
|
-
const visibleCount = Math.ceil(hostHeight / this._itemHeight);
|
|
360
|
-
const renderStart = Math.max(0, startIndex - buffer);
|
|
361
|
-
const renderEnd = Math.min(this._items.length, startIndex + visibleCount + buffer);
|
|
362
|
-
const startOffset = renderStart * this._itemHeight;
|
|
363
|
-
this.content.style.transform = `translateY(${startOffset}px)`;
|
|
364
|
-
// Render specific slice
|
|
365
|
-
const visibleItems = this._items.slice(renderStart, renderEnd);
|
|
366
|
-
// Simple string replacement template engine for the demo
|
|
367
|
-
// In a real Mulan compilation, this would be an optimized ASTR render
|
|
368
|
-
let html = '';
|
|
369
|
-
visibleItems.forEach((item, index) => {
|
|
370
|
-
const absoluteIndex = renderStart + index;
|
|
371
|
-
// Basic mustache replacement {{ item.prop }}
|
|
372
|
-
let rowHtml = this._template
|
|
373
|
-
.replace(/{{\s*item\s*}}/g, String(item)) // {{ item }}
|
|
374
|
-
.replace(/{{\s*index\s*}}/g, String(absoluteIndex)); // {{ index }}
|
|
375
|
-
// Handle object properties: {{ item.name }}
|
|
376
|
-
if (typeof item === 'object' && item !== null) {
|
|
377
|
-
rowHtml = rowHtml.replace(/{{\s*item\.(\w+)\s*}}/g, (_, prop) => {
|
|
378
|
-
return String(item[prop] || '');
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
html += `<div style="height: ${this._itemHeight}px; overflow: hidden;">${rowHtml}</div>`;
|
|
382
|
-
});
|
|
383
|
-
this.content.innerHTML = html;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
// Register
|
|
387
|
-
if (typeof customElements !== 'undefined' && !customElements.get('mu-infinity')) {
|
|
388
|
-
customElements.define('mu-infinity', MuInfinity);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
/***/ },
|
|
393
|
-
|
|
394
|
-
/***/ "./src/core/component.ts"
|
|
395
|
-
/*!*******************************!*\
|
|
396
|
-
!*** ./src/core/component.ts ***!
|
|
397
|
-
\*******************************/
|
|
398
|
-
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
399
|
-
|
|
400
|
-
__webpack_require__.r(__webpack_exports__);
|
|
401
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
402
|
-
/* harmony export */ MuComponent: () => (/* binding */ MuComponent),
|
|
403
|
-
/* harmony export */ defineComponent: () => (/* binding */ defineComponent)
|
|
404
|
-
/* harmony export */ });
|
|
405
|
-
/* harmony import */ var _renderer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./renderer */ "./src/core/renderer.ts");
|
|
406
|
-
/* harmony import */ var _hooks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./hooks */ "./src/core/hooks.ts");
|
|
407
|
-
/* harmony import */ var _reactive__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./reactive */ "./src/core/reactive.ts");
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
// Or a simple component that returns an object of state/methods used by template?
|
|
412
|
-
// For Mulan 2.0, let's say functional component returns a template string render function explicitly.
|
|
413
|
-
class MuComponent {
|
|
414
|
-
constructor(container) {
|
|
415
|
-
this._hooks = {};
|
|
416
|
-
this._effects = [];
|
|
417
|
-
this._isDestroyed = false;
|
|
418
|
-
this._propsQueue = [];
|
|
419
|
-
this._eventQueue = [];
|
|
420
|
-
this.container = container;
|
|
421
|
-
this.state = {};
|
|
422
|
-
this.$uid = 'mu_' + Math.random().toString(36).substr(2, 9);
|
|
423
|
-
// MULAN INSIGHT: Global Registry for Debugging
|
|
424
|
-
if (typeof window !== 'undefined') {
|
|
425
|
-
const global = window;
|
|
426
|
-
global.__MULAN_INSIGHT__ = global.__MULAN_INSIGHT__ || { components: new Map() };
|
|
427
|
-
global.__MULAN_INSIGHT__.components.set(this.$uid, this);
|
|
428
|
-
}
|
|
429
|
-
// Setup context for hooks
|
|
430
|
-
(0,_hooks__WEBPACK_IMPORTED_MODULE_1__.setCurrentInstance)(this);
|
|
431
|
-
this.setup();
|
|
432
|
-
(0,_hooks__WEBPACK_IMPORTED_MODULE_1__.setCurrentInstance)(null);
|
|
433
|
-
}
|
|
434
|
-
// Optional setup method for class components wanting to use hooks
|
|
435
|
-
setup() { }
|
|
436
|
-
onMount() {
|
|
437
|
-
var _a, _c;
|
|
438
|
-
// Mulan Cycle: Init
|
|
439
|
-
(_a = this._hooks.onMuInit) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn());
|
|
440
|
-
// Mulan Cycle: Mount (Simulated immediately after init for now in this version)
|
|
441
|
-
(_c = this._hooks.onMuMount) === null || _c === void 0 ? void 0 : _c.forEach(fn => fn());
|
|
442
|
-
}
|
|
443
|
-
onUpdate() { }
|
|
444
|
-
onDestroy() {
|
|
445
|
-
var _a, _c;
|
|
446
|
-
if (this._isDestroyed)
|
|
447
|
-
return;
|
|
448
|
-
this._isDestroyed = true;
|
|
449
|
-
console.log(`[Mulan Cycle] Destroying component ${this.$uid} (${this.constructor.name})`);
|
|
450
|
-
// MULAN INSIGHT: Cleanup
|
|
451
|
-
if (typeof window !== 'undefined') {
|
|
452
|
-
const global = window;
|
|
453
|
-
(_a = global.__MULAN_INSIGHT__) === null || _a === void 0 ? void 0 : _a.components.delete(this.$uid);
|
|
454
|
-
}
|
|
455
|
-
// Mulan Cycle: Stop all effects to prevent leaks
|
|
456
|
-
console.log(`[Mulan Cycle] Stopping ${this._effects.length} effects for ${this.$uid}`);
|
|
457
|
-
this._effects.forEach(stop => stop());
|
|
458
|
-
this._effects = [];
|
|
459
|
-
// Mulan Cycle: Destroy hooks
|
|
460
|
-
(_c = this._hooks.onMuDestroy) === null || _c === void 0 ? void 0 : _c.forEach(fn => fn());
|
|
461
|
-
}
|
|
462
|
-
// Helper for compiler to register property bindings
|
|
463
|
-
_b(id, prop, value) {
|
|
464
|
-
this._propsQueue.push([id, prop, value]);
|
|
465
|
-
return "";
|
|
466
|
-
}
|
|
467
|
-
// Helper for compiler to register event bindings
|
|
468
|
-
_e(id, type, handler) {
|
|
469
|
-
this._eventQueue.push([id, type, handler]);
|
|
470
|
-
return "";
|
|
471
|
-
}
|
|
472
|
-
mount() {
|
|
473
|
-
console.log(`[Mulan Cycle] Mounting component ${this.$uid}`);
|
|
474
|
-
const stop = (0,_reactive__WEBPACK_IMPORTED_MODULE_2__.effect)(() => {
|
|
475
|
-
console.log(`[Mulan Reactivity] Triggering update for ${this.$uid}`);
|
|
476
|
-
this.update();
|
|
477
|
-
});
|
|
478
|
-
this._effects.push(stop);
|
|
479
|
-
this.onMount();
|
|
480
|
-
}
|
|
481
|
-
update() {
|
|
482
|
-
if (this._isDestroyed) {
|
|
483
|
-
console.warn(`[Mulan Warning] Update called on destroyed component ${this.$uid}. Blocking render.`);
|
|
484
|
-
return;
|
|
318
|
+
/**
|
|
319
|
+
* Mulan Vault: The World's First Native Persistent State Primitive.
|
|
320
|
+
*/
|
|
321
|
+
function persistent(key, initialValue, options = {}) {
|
|
322
|
+
const storage = options.storage || window.localStorage;
|
|
323
|
+
// 1. Load from Storage
|
|
324
|
+
const stored = storage.getItem(key);
|
|
325
|
+
let startVal = initialValue;
|
|
326
|
+
if (stored) {
|
|
327
|
+
try {
|
|
328
|
+
startVal = JSON.parse(stored);
|
|
485
329
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
this._eventQueue = [];
|
|
489
|
-
const template = this.template();
|
|
490
|
-
// Render HTML
|
|
491
|
-
(0,_renderer__WEBPACK_IMPORTED_MODULE_0__.render)(template, this.container);
|
|
492
|
-
// Flush Side Effects
|
|
493
|
-
this.flushProps();
|
|
494
|
-
this.flushEvents();
|
|
495
|
-
this.onUpdate();
|
|
496
|
-
}
|
|
497
|
-
flushProps() {
|
|
498
|
-
for (const [id, prop, value] of this._propsQueue) {
|
|
499
|
-
const el = this.container.querySelector(`[data-mu-id="${id}"]`);
|
|
500
|
-
if (el) {
|
|
501
|
-
// @ts-ignore
|
|
502
|
-
el[prop] = value;
|
|
503
|
-
}
|
|
330
|
+
catch (e) {
|
|
331
|
+
console.warn(`[Mulan Vault] Corrupt persistent data for key "${key}", resetting.`);
|
|
504
332
|
}
|
|
505
|
-
this._propsQueue = [];
|
|
506
333
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
334
|
+
// 2. Create Reactive State (Follow muState pattern for consistency)
|
|
335
|
+
const isObject = typeof startVal === 'object' && startVal !== null;
|
|
336
|
+
const state = isObject ? reactive(startVal) : reactive({ value: startVal });
|
|
337
|
+
// 3. Auto-Save on Change
|
|
338
|
+
muEffect(() => {
|
|
339
|
+
try {
|
|
340
|
+
const payload = isObject ? state : state.value;
|
|
341
|
+
const toSave = JSON.stringify(payload);
|
|
342
|
+
// Non-obfuscated persistence to satisfy security audits
|
|
343
|
+
storage.setItem(key, toSave);
|
|
514
344
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
}
|
|
518
|
-
// Helper to create functional components wrapped in the class system
|
|
519
|
-
// Helper to create functional components wrapped in the class system
|
|
520
|
-
// Supports both () => render and { setup() } signatures
|
|
521
|
-
function defineComponent(optionsOrSetup) {
|
|
522
|
-
return class UniversalComponent extends MuComponent {
|
|
523
|
-
constructor(container) {
|
|
524
|
-
super(container);
|
|
525
|
-
// setup() is called by super constructor
|
|
345
|
+
catch (e) {
|
|
346
|
+
console.error(`[Mulan Vault] Failed to save key "${key}"`);
|
|
526
347
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
// It's a render function
|
|
540
|
-
this.template = setupResult;
|
|
541
|
-
}
|
|
542
|
-
else if (setupResult && typeof setupResult === 'object') {
|
|
543
|
-
// It's bindings
|
|
544
|
-
Object.assign(this, setupResult);
|
|
545
|
-
// We assume template is assigned to prototype by compiler
|
|
348
|
+
});
|
|
349
|
+
// 4. Sync across Tabs
|
|
350
|
+
const sync = (e) => {
|
|
351
|
+
if (e.key === key && e.newValue) {
|
|
352
|
+
try {
|
|
353
|
+
const newVal = JSON.parse(e.newValue);
|
|
354
|
+
if (isObject) {
|
|
355
|
+
Object.assign(state, newVal);
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
state.value = newVal;
|
|
359
|
+
}
|
|
546
360
|
}
|
|
547
|
-
|
|
548
|
-
template() {
|
|
549
|
-
return '';
|
|
361
|
+
catch (e) { }
|
|
550
362
|
}
|
|
551
363
|
};
|
|
364
|
+
window.addEventListener('storage', sync);
|
|
365
|
+
// Explicit cleanup if provided by the environment (e.g. Mulan Hooks)
|
|
366
|
+
if (options.onCleanup) {
|
|
367
|
+
options.onCleanup(() => {
|
|
368
|
+
window.removeEventListener('storage', sync);
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
return state;
|
|
552
372
|
}
|
|
553
373
|
|
|
554
|
-
|
|
555
|
-
/***/ },
|
|
556
|
-
|
|
557
|
-
/***/ "./src/core/hooks.ts"
|
|
558
|
-
/*!***************************!*\
|
|
559
|
-
!*** ./src/core/hooks.ts ***!
|
|
560
|
-
\***************************/
|
|
561
|
-
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
562
|
-
|
|
563
|
-
__webpack_require__.r(__webpack_exports__);
|
|
564
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
565
|
-
/* harmony export */ getCurrentInstance: () => (/* binding */ getCurrentInstance),
|
|
566
|
-
/* harmony export */ muEffect: () => (/* binding */ muEffect),
|
|
567
|
-
/* harmony export */ muGeom: () => (/* binding */ muGeom),
|
|
568
|
-
/* harmony export */ muMemo: () => (/* binding */ muMemo),
|
|
569
|
-
/* harmony export */ muPulse: () => (/* binding */ muPulse),
|
|
570
|
-
/* harmony export */ muState: () => (/* binding */ muState),
|
|
571
|
-
/* harmony export */ muVault: () => (/* binding */ muVault),
|
|
572
|
-
/* harmony export */ onMuDestroy: () => (/* binding */ onMuDestroy),
|
|
573
|
-
/* harmony export */ onMuIdle: () => (/* binding */ onMuIdle),
|
|
574
|
-
/* harmony export */ onMuInit: () => (/* binding */ onMuInit),
|
|
575
|
-
/* harmony export */ onMuMount: () => (/* binding */ onMuMount),
|
|
576
|
-
/* harmony export */ onMuResume: () => (/* binding */ onMuResume),
|
|
577
|
-
/* harmony export */ onMuShake: () => (/* binding */ onMuShake),
|
|
578
|
-
/* harmony export */ onMuVoice: () => (/* binding */ onMuVoice),
|
|
579
|
-
/* harmony export */ setCurrentInstance: () => (/* binding */ setCurrentInstance)
|
|
580
|
-
/* harmony export */ });
|
|
581
|
-
/* harmony import */ var _reactive__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./reactive */ "./src/core/reactive.ts");
|
|
582
|
-
/* harmony import */ var _vault__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./vault */ "./src/core/vault.ts");
|
|
374
|
+
;// ./src/core/hooks.ts
|
|
583
375
|
|
|
584
376
|
|
|
585
377
|
// Global context to track the current component instance
|
|
@@ -593,14 +385,14 @@ function getCurrentInstance() {
|
|
|
593
385
|
// --- Mulan Unique Reactivity Hooks ---
|
|
594
386
|
function muState(initialValue) {
|
|
595
387
|
if (typeof initialValue === 'object' && initialValue !== null) {
|
|
596
|
-
return
|
|
388
|
+
return reactive(initialValue);
|
|
597
389
|
}
|
|
598
390
|
// Core reactive state container for primitives
|
|
599
|
-
return
|
|
391
|
+
return reactive({ value: initialValue });
|
|
600
392
|
}
|
|
601
393
|
function muMemo(computeFn) {
|
|
602
|
-
const signal =
|
|
603
|
-
const stop =
|
|
394
|
+
const signal = reactive({ value: undefined });
|
|
395
|
+
const stop = effect(() => {
|
|
604
396
|
signal.value = computeFn();
|
|
605
397
|
});
|
|
606
398
|
const instance = getCurrentInstance();
|
|
@@ -612,7 +404,7 @@ function muMemo(computeFn) {
|
|
|
612
404
|
return signal;
|
|
613
405
|
}
|
|
614
406
|
function muEffect(fn) {
|
|
615
|
-
const stop =
|
|
407
|
+
const stop = effect(fn);
|
|
616
408
|
const instance = getCurrentInstance();
|
|
617
409
|
if (instance) {
|
|
618
410
|
if (!instance._effects)
|
|
@@ -807,398 +599,211 @@ function muPulse() {
|
|
|
807
599
|
* Powered by the Iron Fortress persistent primitive.
|
|
808
600
|
*/
|
|
809
601
|
function muVault(key, initial, options = {}) {
|
|
810
|
-
return
|
|
602
|
+
return persistent(key, initial, Object.assign(Object.assign({}, options), { onCleanup: (fn) => onMuDestroy(fn) }));
|
|
811
603
|
}
|
|
812
604
|
|
|
605
|
+
;// ./src/core/component.ts
|
|
813
606
|
|
|
814
|
-
/***/ },
|
|
815
|
-
|
|
816
|
-
/***/ "./src/core/quantum.ts"
|
|
817
|
-
/*!*****************************!*\
|
|
818
|
-
!*** ./src/core/quantum.ts ***!
|
|
819
|
-
\*****************************/
|
|
820
|
-
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
821
607
|
|
|
822
|
-
__webpack_require__.r(__webpack_exports__);
|
|
823
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
824
|
-
/* harmony export */ activeControls: () => (/* binding */ activeControls),
|
|
825
|
-
/* harmony export */ muControl: () => (/* binding */ muControl),
|
|
826
|
-
/* harmony export */ muEntangle: () => (/* binding */ muEntangle),
|
|
827
|
-
/* harmony export */ muGate: () => (/* binding */ muGate),
|
|
828
|
-
/* harmony export */ muMeasure: () => (/* binding */ muMeasure),
|
|
829
|
-
/* harmony export */ muParallel: () => (/* binding */ muParallel),
|
|
830
|
-
/* harmony export */ muQubit: () => (/* binding */ muQubit),
|
|
831
|
-
/* harmony export */ muRegister: () => (/* binding */ muRegister),
|
|
832
|
-
/* harmony export */ muSearch: () => (/* binding */ muSearch),
|
|
833
|
-
/* harmony export */ muSwitch: () => (/* binding */ muSwitch),
|
|
834
|
-
/* harmony export */ muTeleport: () => (/* binding */ muTeleport)
|
|
835
|
-
/* harmony export */ });
|
|
836
|
-
/* harmony import */ var _hooks__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./hooks */ "./src/core/hooks.ts");
|
|
837
608
|
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
return (0,_hooks__WEBPACK_IMPORTED_MODULE_0__.muState)({
|
|
856
|
-
value: {
|
|
857
|
-
size: n,
|
|
858
|
-
amplitudes
|
|
609
|
+
// Or a simple component that returns an object of state/methods used by template?
|
|
610
|
+
// For Mulan 2.0, let's say functional component returns a template string render function explicitly.
|
|
611
|
+
class MuComponent {
|
|
612
|
+
constructor(container) {
|
|
613
|
+
this._hooks = {};
|
|
614
|
+
this._effects = [];
|
|
615
|
+
this._isDestroyed = false;
|
|
616
|
+
this._propsQueue = [];
|
|
617
|
+
this._eventQueue = [];
|
|
618
|
+
this.container = container;
|
|
619
|
+
this.state = {};
|
|
620
|
+
this.$uid = 'mu_' + Math.random().toString(36).substr(2, 9);
|
|
621
|
+
// MULAN INSIGHT: Global Registry for Debugging
|
|
622
|
+
if (typeof window !== 'undefined') {
|
|
623
|
+
const global = window;
|
|
624
|
+
global.__MULAN_INSIGHT__ = global.__MULAN_INSIGHT__ || { components: new Map() };
|
|
625
|
+
global.__MULAN_INSIGHT__.components.set(this.$uid, this);
|
|
859
626
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
*/
|
|
865
|
-
function muQubit(initial = 0) {
|
|
866
|
-
const q = muRegister(1);
|
|
867
|
-
if (initial === 1) {
|
|
868
|
-
muGate(q, 'X', 0);
|
|
627
|
+
// Setup context for hooks
|
|
628
|
+
setCurrentInstance(this);
|
|
629
|
+
this.setup();
|
|
630
|
+
setCurrentInstance(null);
|
|
869
631
|
}
|
|
870
|
-
//
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
*/
|
|
879
|
-
function updateState(reg, newState) {
|
|
880
|
-
if (newState.size === 1) {
|
|
881
|
-
// Re-inject compatibility getters for muQubit users
|
|
882
|
-
Object.defineProperty(newState, 'alpha', {
|
|
883
|
-
get: () => newState.amplitudes[0],
|
|
884
|
-
configurable: true,
|
|
885
|
-
enumerable: true
|
|
886
|
-
});
|
|
887
|
-
Object.defineProperty(newState, 'beta', {
|
|
888
|
-
get: () => newState.amplitudes[1],
|
|
889
|
-
configurable: true,
|
|
890
|
-
enumerable: true
|
|
891
|
-
});
|
|
632
|
+
// Optional setup method for class components wanting to use hooks
|
|
633
|
+
setup() { }
|
|
634
|
+
onMount() {
|
|
635
|
+
var _a, _c;
|
|
636
|
+
// Mulan Cycle: Init
|
|
637
|
+
(_a = this._hooks.onMuInit) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn());
|
|
638
|
+
// Mulan Cycle: Mount (Simulated immediately after init for now in this version)
|
|
639
|
+
(_c = this._hooks.onMuMount) === null || _c === void 0 ? void 0 : _c.forEach(fn => fn());
|
|
892
640
|
}
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
if (ctrl === undefined || (Array.isArray(ctrl) && ctrl.length === 0))
|
|
905
|
-
return true;
|
|
906
|
-
const ctrls = Array.isArray(ctrl) ? ctrl : [ctrl];
|
|
907
|
-
return ctrls.every(c => ((index >> c) & 1) === 1);
|
|
908
|
-
};
|
|
909
|
-
// SWAP Gate (Unique case: affects 2 targets)
|
|
910
|
-
if (type === 'SWAP') {
|
|
911
|
-
const t1 = target;
|
|
912
|
-
const t2 = control; // SWAP uses control arg as second target
|
|
913
|
-
// Iterate only half to avoid double swapping
|
|
914
|
-
for (let i = 0; i < amplitudes.length; i++) {
|
|
915
|
-
// Check active controls for SWAP too
|
|
916
|
-
if (activeControls.length > 0 && !checkControl(i, activeControls))
|
|
917
|
-
continue;
|
|
918
|
-
const bit1 = (i >> t1) & 1;
|
|
919
|
-
const bit2 = (i >> t2) & 1;
|
|
920
|
-
if (bit1 !== bit2) {
|
|
921
|
-
// Determine the swap partner index
|
|
922
|
-
// If i has (0,1), partner has (1,0) at those positions
|
|
923
|
-
const partner = i ^ (1 << t1) ^ (1 << t2);
|
|
924
|
-
if (i < partner) {
|
|
925
|
-
const temp = newAmps[i];
|
|
926
|
-
newAmps[i] = newAmps[partner];
|
|
927
|
-
newAmps[partner] = temp;
|
|
928
|
-
}
|
|
929
|
-
}
|
|
641
|
+
onUpdate() { }
|
|
642
|
+
onDestroy() {
|
|
643
|
+
var _a, _c;
|
|
644
|
+
if (this._isDestroyed)
|
|
645
|
+
return;
|
|
646
|
+
this._isDestroyed = true;
|
|
647
|
+
console.log(`[Mulan Cycle] Destroying component ${this.$uid} (${this.constructor.name})`);
|
|
648
|
+
// MULAN INSIGHT: Cleanup
|
|
649
|
+
if (typeof window !== 'undefined') {
|
|
650
|
+
const global = window;
|
|
651
|
+
(_a = global.__MULAN_INSIGHT__) === null || _a === void 0 ? void 0 : _a.components.delete(this.$uid);
|
|
930
652
|
}
|
|
931
|
-
|
|
932
|
-
|
|
653
|
+
// Mulan Cycle: Stop all effects to prevent leaks
|
|
654
|
+
console.log(`[Mulan Cycle] Stopping ${this._effects.length} effects for ${this.$uid}`);
|
|
655
|
+
this._effects.forEach(stop => stop());
|
|
656
|
+
this._effects = [];
|
|
657
|
+
// Mulan Cycle: Destroy hooks
|
|
658
|
+
(_c = this._hooks.onMuDestroy) === null || _c === void 0 ? void 0 : _c.forEach(fn => fn());
|
|
933
659
|
}
|
|
934
|
-
//
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
for (let i = 0; i < state.amplitudes.length; i++) {
|
|
939
|
-
if (processed.has(i))
|
|
940
|
-
continue;
|
|
941
|
-
// Check Controls first
|
|
942
|
-
if (!checkControl(i, effectiveControl))
|
|
943
|
-
continue;
|
|
944
|
-
const targetBit = (i >> target) & 1;
|
|
945
|
-
const pairedIndex = targetBit ? (i & ~(1 << target)) : (i | (1 << target));
|
|
946
|
-
const a = state.amplitudes[i];
|
|
947
|
-
const b = state.amplitudes[pairedIndex];
|
|
948
|
-
if (targetBit === 0) {
|
|
949
|
-
newAmps[i] = { re: s * (a.re + b.re), im: s * (a.im + b.im) };
|
|
950
|
-
newAmps[pairedIndex] = { re: s * (a.re - b.re), im: s * (a.im - b.im) };
|
|
951
|
-
}
|
|
952
|
-
else {
|
|
953
|
-
newAmps[pairedIndex] = { re: s * (b.re + a.re), im: s * (b.im + a.im) };
|
|
954
|
-
newAmps[i] = { re: s * (b.re - a.re), im: s * (b.im - a.im) };
|
|
955
|
-
}
|
|
956
|
-
processed.add(i);
|
|
957
|
-
processed.add(pairedIndex);
|
|
958
|
-
}
|
|
660
|
+
// Helper for compiler to register property bindings
|
|
661
|
+
_b(id, prop, value) {
|
|
662
|
+
this._propsQueue.push([id, prop, value]);
|
|
663
|
+
return "";
|
|
959
664
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
665
|
+
// Helper for compiler to register event bindings
|
|
666
|
+
_e(id, type, handler) {
|
|
667
|
+
this._eventQueue.push([id, type, handler]);
|
|
668
|
+
return "";
|
|
669
|
+
}
|
|
670
|
+
mount() {
|
|
671
|
+
console.log(`[Mulan Cycle] Mounting component ${this.$uid}`);
|
|
672
|
+
const stop = effect(() => {
|
|
673
|
+
console.log(`[Mulan Reactivity] Triggering update for ${this.$uid}`);
|
|
674
|
+
this.update();
|
|
675
|
+
});
|
|
676
|
+
this._effects.push(stop);
|
|
677
|
+
this.onMount();
|
|
678
|
+
}
|
|
679
|
+
update() {
|
|
680
|
+
if (this._isDestroyed) {
|
|
681
|
+
console.warn(`[Mulan Warning] Update called on destroyed component ${this.$uid}. Blocking render.`);
|
|
682
|
+
return;
|
|
972
683
|
}
|
|
684
|
+
// Clear queues before render
|
|
685
|
+
this._propsQueue = [];
|
|
686
|
+
this._eventQueue = [];
|
|
687
|
+
const template = this.template();
|
|
688
|
+
// Render HTML
|
|
689
|
+
render(template, this.container);
|
|
690
|
+
// Flush Side Effects
|
|
691
|
+
this.flushProps();
|
|
692
|
+
this.flushEvents();
|
|
693
|
+
this.onUpdate();
|
|
973
694
|
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
if (
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
// Z Gate acts on |1>
|
|
981
|
-
if (targetBit === 1) {
|
|
982
|
-
newAmps[i] = { re: -amplitudes[i].re, im: -amplitudes[i].im };
|
|
695
|
+
flushProps() {
|
|
696
|
+
for (const [id, prop, value] of this._propsQueue) {
|
|
697
|
+
const el = this.container.querySelector(`[data-mu-id="${id}"]`);
|
|
698
|
+
if (el) {
|
|
699
|
+
// @ts-ignore
|
|
700
|
+
el[prop] = value;
|
|
983
701
|
}
|
|
984
702
|
}
|
|
703
|
+
this._propsQueue = [];
|
|
985
704
|
}
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
if (
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
const pairedIndex = targetBit ? (i & ~(1 << target)) : (i | (1 << target));
|
|
993
|
-
if (i < pairedIndex) {
|
|
994
|
-
// We process pairs (i, pairedIndex) where i has 0 at target, paired has 1
|
|
995
|
-
const a = newAmps[i]; // Coeff of |0>
|
|
996
|
-
const b = newAmps[pairedIndex]; // Coeff of |1>
|
|
997
|
-
// New |0> = -i * Old |1>
|
|
998
|
-
newAmps[i] = { re: b.im, im: -b.re };
|
|
999
|
-
// New |1> = i * Old |0>
|
|
1000
|
-
newAmps[pairedIndex] = { re: -a.im, im: a.re };
|
|
705
|
+
flushEvents() {
|
|
706
|
+
for (const [id, type, handler] of this._eventQueue) {
|
|
707
|
+
const el = this.container.querySelector(`[data-mu-id="${id}"]`);
|
|
708
|
+
if (el) {
|
|
709
|
+
// Bind handler to this component instance to ensure 'this' works in methods
|
|
710
|
+
el.addEventListener(type, handler.bind(this));
|
|
1001
711
|
}
|
|
1002
712
|
}
|
|
713
|
+
this._eventQueue = [];
|
|
1003
714
|
}
|
|
1004
|
-
updateState(reg, Object.assign(Object.assign({}, state), { amplitudes: newAmps }));
|
|
1005
715
|
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
const n = reg.value.size;
|
|
1015
|
-
const controls = [];
|
|
1016
|
-
// 1. Identify which bits are 0 and need wrapping with X gates
|
|
1017
|
-
// Logic: To mark |010>, we want C-C-Z to trigger on 111.
|
|
1018
|
-
// So we apply X to bits that are 0, then C-C-Z, then X again.
|
|
1019
|
-
// We treat the last bit as the 'target' for the Z gate, rest as controls
|
|
1020
|
-
const targetQubit = n - 1;
|
|
1021
|
-
for (let i = 0; i < n; i++) {
|
|
1022
|
-
const bit = (targetState >> i) & 1;
|
|
1023
|
-
if (i === targetQubit) {
|
|
1024
|
-
// If target bit logic requires 0, we flip it to 1 for the Z gate to work
|
|
1025
|
-
if (bit === 0)
|
|
1026
|
-
muGate(reg, 'X', i);
|
|
1027
|
-
}
|
|
1028
|
-
else {
|
|
1029
|
-
controls.push(i);
|
|
1030
|
-
if (bit === 0)
|
|
1031
|
-
muGate(reg, 'X', i);
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
// 2. Apply Multi-Controlled Z
|
|
1035
|
-
muGate(reg, 'Z', targetQubit, controls);
|
|
1036
|
-
// 3. Uncompute (Restore 0s)
|
|
1037
|
-
for (let i = 0; i < n; i++) {
|
|
1038
|
-
const bit = (targetState >> i) & 1;
|
|
1039
|
-
if (bit === 0)
|
|
1040
|
-
muGate(reg, 'X', i);
|
|
1041
|
-
}
|
|
1042
|
-
// --- GROVER DIFFUSER (Amplification) ---
|
|
1043
|
-
// This flips the probability amplitudes around the mean, boosting the target state.
|
|
1044
|
-
// 1. Apply H to all
|
|
1045
|
-
for (let i = 0; i < n; i++)
|
|
1046
|
-
muGate(reg, 'H', i);
|
|
1047
|
-
// 2. Apply X to all
|
|
1048
|
-
for (let i = 0; i < n; i++)
|
|
1049
|
-
muGate(reg, 'X', i);
|
|
1050
|
-
// 3. Multi-Controlled Z (Reflection about |0...0>)
|
|
1051
|
-
// We want to flip phase of |11...1> state after X transformation (which corresponds to |00...0> original)
|
|
1052
|
-
// Target is last qubit, controls are 0 to n-2
|
|
1053
|
-
const diffControls = [];
|
|
1054
|
-
for (let i = 0; i < n - 1; i++)
|
|
1055
|
-
diffControls.push(i);
|
|
1056
|
-
muGate(reg, 'Z', n - 1, diffControls);
|
|
1057
|
-
// 4. Uncompute X
|
|
1058
|
-
for (let i = 0; i < n; i++)
|
|
1059
|
-
muGate(reg, 'X', i);
|
|
1060
|
-
// 5. Uncompute H
|
|
1061
|
-
for (let i = 0; i < n; i++)
|
|
1062
|
-
muGate(reg, 'H', i);
|
|
1063
|
-
}
|
|
1064
|
-
function muEntangle(reg, i, j) {
|
|
1065
|
-
muGate(reg, 'H', i);
|
|
1066
|
-
muGate(reg, 'CNOT', j, i);
|
|
1067
|
-
}
|
|
1068
|
-
/**
|
|
1069
|
-
* Quantum Teleportation Protocol
|
|
1070
|
-
* Transfers the state of `msgIdx` to `targetIdx` using `ancillaIdx` as a resource.
|
|
1071
|
-
* @param reg Register
|
|
1072
|
-
* @param msgIdx The qubit containing the state to teleport (Alice)
|
|
1073
|
-
* @param ancillaIdx The helper qubit (Alice's half of entanglement)
|
|
1074
|
-
* @param targetIdx The destination qubit (Bob)
|
|
1075
|
-
*/
|
|
1076
|
-
function muTeleport(reg, msgIdx, ancillaIdx, targetIdx) {
|
|
1077
|
-
// 1. Create Bell Pair (Entanglement) between Ancilla and Target
|
|
1078
|
-
// Represents the shared link between Alice and Bob
|
|
1079
|
-
muEntangle(reg, ancillaIdx, targetIdx);
|
|
1080
|
-
// 2. Bell Measurement on Message + Ancilla (Alice's side)
|
|
1081
|
-
muGate(reg, 'CNOT', ancillaIdx, msgIdx); // Control: msg, Target: ancilla
|
|
1082
|
-
muGate(reg, 'H', msgIdx);
|
|
1083
|
-
// 3. Measure Alice's qubits (This collapses them)
|
|
1084
|
-
const m1 = muMeasure(reg, msgIdx); // Measures "Z" component
|
|
1085
|
-
const m2 = muMeasure(reg, ancillaIdx); // Measures "X" component
|
|
1086
|
-
// 4. Classical Communication & Correction (Bob's side)
|
|
1087
|
-
// Apply corrections to Target based on measurements
|
|
1088
|
-
if (m2 === 1)
|
|
1089
|
-
muGate(reg, 'X', targetIdx);
|
|
1090
|
-
if (m1 === 1)
|
|
1091
|
-
muGate(reg, 'Z', targetIdx);
|
|
1092
|
-
}
|
|
1093
|
-
/**
|
|
1094
|
-
* Measures a specific qubit in the register, collapsing the superposition.
|
|
1095
|
-
* @param reg Quantum Register
|
|
1096
|
-
* @param target Index of qubit to measure
|
|
1097
|
-
* @returns 0 or 1
|
|
1098
|
-
*/
|
|
1099
|
-
function muMeasure(reg, target = 0) {
|
|
1100
|
-
const state = reg.value;
|
|
1101
|
-
const amplitudes = state.amplitudes;
|
|
1102
|
-
let prob0 = 0;
|
|
1103
|
-
// 1. Calculate Probability of |0>
|
|
1104
|
-
for (let i = 0; i < amplitudes.length; i++) {
|
|
1105
|
-
if (((i >> target) & 1) === 0) {
|
|
1106
|
-
const a = amplitudes[i];
|
|
1107
|
-
prob0 += (a.re * a.re) + (a.im * a.im);
|
|
716
|
+
// Helper to create functional components wrapped in the class system
|
|
717
|
+
// Helper to create functional components wrapped in the class system
|
|
718
|
+
// Supports both () => render and { setup() } signatures
|
|
719
|
+
function defineComponent(optionsOrSetup) {
|
|
720
|
+
return class UniversalComponent extends MuComponent {
|
|
721
|
+
constructor(container) {
|
|
722
|
+
super(container);
|
|
723
|
+
// setup() is called by super constructor
|
|
1108
724
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
725
|
+
setup() {
|
|
726
|
+
let setupResult;
|
|
727
|
+
if (typeof optionsOrSetup === 'function') {
|
|
728
|
+
// It's a setup function returning render fn
|
|
729
|
+
setupResult = optionsOrSetup.call(this);
|
|
730
|
+
}
|
|
731
|
+
else if (typeof optionsOrSetup === 'object' && optionsOrSetup.setup) {
|
|
732
|
+
// It's an options object with setup()
|
|
733
|
+
setupResult = optionsOrSetup.setup.call(this);
|
|
734
|
+
}
|
|
735
|
+
// Handle result
|
|
736
|
+
if (typeof setupResult === 'function') {
|
|
737
|
+
// It's a render function
|
|
738
|
+
this.template = setupResult;
|
|
739
|
+
}
|
|
740
|
+
else if (setupResult && typeof setupResult === 'object') {
|
|
741
|
+
// It's bindings
|
|
742
|
+
Object.assign(this, setupResult);
|
|
743
|
+
// We assume template is assigned to prototype by compiler
|
|
744
|
+
}
|
|
1119
745
|
}
|
|
1120
|
-
|
|
1121
|
-
return
|
|
746
|
+
template() {
|
|
747
|
+
return '';
|
|
1122
748
|
}
|
|
1123
|
-
}
|
|
1124
|
-
// We need to call updateState to ensure reactivity if specialized getters exist
|
|
1125
|
-
// But since this file has updateState internal, we can just call it.
|
|
1126
|
-
// However, the internal updateState function needs to be in scope.
|
|
1127
|
-
// It is defined at line 60. So we are good.
|
|
1128
|
-
updateState(reg, Object.assign(Object.assign({}, state), { amplitudes: newAmps }));
|
|
1129
|
-
return result;
|
|
1130
|
-
}
|
|
1131
|
-
/**
|
|
1132
|
-
* Quantum Loop: Parallel Execution
|
|
1133
|
-
* Applies a gate to multiple qubits "simultaneously" (in simulation steps).
|
|
1134
|
-
* Ideal for initialization (Hadamard Transform) or global operations.
|
|
1135
|
-
* @param reg Quantum Register
|
|
1136
|
-
* @param qubits Array of qubit indices
|
|
1137
|
-
* @param gate Gate type to apply (e.g. 'H', 'X')
|
|
1138
|
-
*/
|
|
1139
|
-
function muParallel(reg, qubits, gate) {
|
|
1140
|
-
if (gate === 'SWAP') {
|
|
1141
|
-
throw new Error("SWAP cannot be applied in parallel (requires pairs).");
|
|
1142
|
-
}
|
|
1143
|
-
// In a real quantum computer, these happen at t=0.
|
|
1144
|
-
// Here, we loop, but logical time is constant.
|
|
1145
|
-
qubits.forEach(q => muGate(reg, gate, q));
|
|
749
|
+
};
|
|
1146
750
|
}
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
751
|
+
|
|
752
|
+
;// ./src/security/sanitizer.ts
|
|
753
|
+
class Security {
|
|
754
|
+
/**
|
|
755
|
+
* IRON FORTRESS PROTOCOL
|
|
756
|
+
* Strictly escapes all HTML entities to prevent XSS.
|
|
757
|
+
* Use `mu-raw` attribute in templates to bypass this for trusted content.
|
|
758
|
+
*/
|
|
759
|
+
static sanitize(input) {
|
|
760
|
+
// 1. Basic entity encoding
|
|
761
|
+
let secure = input
|
|
762
|
+
.replace(/&/g, "&")
|
|
763
|
+
.replace(/</g, "<")
|
|
764
|
+
.replace(/>/g, ">")
|
|
765
|
+
.replace(/"/g, """)
|
|
766
|
+
.replace(/'/g, "'");
|
|
767
|
+
// 2. Remove dangerous events (extra layer if encoding fails)
|
|
768
|
+
const dangerousEvents = ['onload', 'onclick', 'onerror', 'onmouseover', 'onfocus'];
|
|
769
|
+
dangerousEvents.forEach(event => {
|
|
770
|
+
const regex = new RegExp(event, 'gi');
|
|
771
|
+
secure = secure.replace(regex, 'data-blocked-' + event);
|
|
772
|
+
});
|
|
773
|
+
return secure;
|
|
1159
774
|
}
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
775
|
+
/**
|
|
776
|
+
* Generates a strict Content Security Policy header value.
|
|
777
|
+
* @param options Configuration for allowed sources
|
|
778
|
+
*/
|
|
779
|
+
static generateCSP(options = {}) {
|
|
780
|
+
const scriptSrc = ["'self'", ...(options.scriptSrc || [])].join(" ");
|
|
781
|
+
const styleSrc = ["'self'", "'unsafe-inline'", ...(options.styleSrc || [])].join(" ");
|
|
782
|
+
return `default-src 'self'; script-src ${scriptSrc}; style-src ${styleSrc}; object-src 'none'; base-uri 'self';`;
|
|
1166
783
|
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
* @param cases Object mapping state (0 or 1) to a function executing quantum operations
|
|
1177
|
-
*/
|
|
1178
|
-
function muSwitch(reg, controlQubit, cases) {
|
|
1179
|
-
if (cases[0]) {
|
|
1180
|
-
muControl(reg, controlQubit, true, cases[0]);
|
|
784
|
+
static validateUrl(url) {
|
|
785
|
+
// Basic URL validation
|
|
786
|
+
const pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
|
|
787
|
+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
|
|
788
|
+
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
|
|
789
|
+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
|
|
790
|
+
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
|
791
|
+
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
|
|
792
|
+
return !!pattern.test(url);
|
|
1181
793
|
}
|
|
1182
|
-
|
|
1183
|
-
|
|
794
|
+
/**
|
|
795
|
+
* Prevents XSS by sanitizing common input fields on blur.
|
|
796
|
+
* Can be used as a utility in forms.
|
|
797
|
+
*/
|
|
798
|
+
static preventXSS(inputElement) {
|
|
799
|
+
inputElement.addEventListener('blur', (e) => {
|
|
800
|
+
const target = e.target;
|
|
801
|
+
target.value = Security.sanitize(target.value);
|
|
802
|
+
});
|
|
1184
803
|
}
|
|
1185
804
|
}
|
|
1186
805
|
|
|
1187
|
-
|
|
1188
|
-
/***/ },
|
|
1189
|
-
|
|
1190
|
-
/***/ "./src/core/query.ts"
|
|
1191
|
-
/*!***************************!*\
|
|
1192
|
-
!*** ./src/core/query.ts ***!
|
|
1193
|
-
\***************************/
|
|
1194
|
-
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
1195
|
-
|
|
1196
|
-
__webpack_require__.r(__webpack_exports__);
|
|
1197
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1198
|
-
/* harmony export */ useMutation: () => (/* binding */ useMutation),
|
|
1199
|
-
/* harmony export */ useQuery: () => (/* binding */ useQuery)
|
|
1200
|
-
/* harmony export */ });
|
|
1201
|
-
/* harmony import */ var _reactive__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./reactive */ "./src/core/reactive.ts");
|
|
806
|
+
;// ./src/router/index.ts
|
|
1202
807
|
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1203
808
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1204
809
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -1209,1031 +814,1185 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
|
|
|
1209
814
|
});
|
|
1210
815
|
};
|
|
1211
816
|
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
817
|
+
|
|
818
|
+
class MuRouter {
|
|
819
|
+
constructor(routes, rootContainer = null) {
|
|
820
|
+
this.currentPath = '';
|
|
821
|
+
this.currentComponent = null;
|
|
822
|
+
this.lastRouteId = 0;
|
|
823
|
+
this.routes = routes;
|
|
824
|
+
this.rootContainer = rootContainer;
|
|
825
|
+
this.isServer = rootContainer === null; // If no container, assume server/headless mode
|
|
826
|
+
if (!this.isServer) {
|
|
827
|
+
window.addEventListener('hashchange', this.handleRoute.bind(this));
|
|
828
|
+
this.handleRoute(); // Initial load
|
|
1224
829
|
}
|
|
1225
|
-
catch (err) {
|
|
1226
|
-
state.error = err;
|
|
1227
|
-
}
|
|
1228
|
-
finally {
|
|
1229
|
-
state.isLoading = false;
|
|
1230
|
-
}
|
|
1231
|
-
});
|
|
1232
|
-
if (options.enabled) {
|
|
1233
|
-
// Run automatically
|
|
1234
|
-
(0,_reactive__WEBPACK_IMPORTED_MODULE_0__.effect)(() => {
|
|
1235
|
-
// Basic effect wrapper to allow reactivity if queryFn relies on signals
|
|
1236
|
-
execute();
|
|
1237
|
-
});
|
|
1238
830
|
}
|
|
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
|
-
get isLoading() { return state.isLoading; },
|
|
1271
|
-
get error() { return state.error; },
|
|
1272
|
-
mutate
|
|
1273
|
-
};
|
|
1274
|
-
}
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
/***/ },
|
|
1278
|
-
|
|
1279
|
-
/***/ "./src/core/reactive.ts"
|
|
1280
|
-
/*!******************************!*\
|
|
1281
|
-
!*** ./src/core/reactive.ts ***!
|
|
1282
|
-
\******************************/
|
|
1283
|
-
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
1284
|
-
|
|
1285
|
-
__webpack_require__.r(__webpack_exports__);
|
|
1286
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1287
|
-
/* harmony export */ Signal: () => (/* binding */ Signal),
|
|
1288
|
-
/* harmony export */ effect: () => (/* binding */ effect),
|
|
1289
|
-
/* harmony export */ reactive: () => (/* binding */ reactive),
|
|
1290
|
-
/* harmony export */ ref: () => (/* binding */ ref)
|
|
1291
|
-
/* harmony export */ });
|
|
1292
|
-
// MulanJS 2.0: Signal-Powered Reactivity Engine
|
|
1293
|
-
// "Compatible Surface, World-Class Engine"
|
|
1294
|
-
let activeEffect = null;
|
|
1295
|
-
const targetMap = new WeakMap();
|
|
1296
|
-
// --- Signal Core (The Engine) ---
|
|
1297
|
-
class Signal {
|
|
1298
|
-
constructor(initialValue) {
|
|
1299
|
-
this._subscribers = new Set();
|
|
1300
|
-
this._value = initialValue;
|
|
831
|
+
// SSR Method: Simulate a route visit on the server
|
|
832
|
+
serverLookup(path) {
|
|
833
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
834
|
+
this.currentPath = path;
|
|
835
|
+
const { route, params } = this.matchRoute(path);
|
|
836
|
+
if (route) {
|
|
837
|
+
// Run guards/resolvers here if needed
|
|
838
|
+
let componentToRender = route.component;
|
|
839
|
+
// Support Lazy Loading
|
|
840
|
+
if (typeof componentToRender === 'function' && !componentToRender.prototype) {
|
|
841
|
+
const module = yield componentToRender();
|
|
842
|
+
componentToRender = module.default || module;
|
|
843
|
+
}
|
|
844
|
+
if (typeof componentToRender === 'function') {
|
|
845
|
+
// Class component SSR
|
|
846
|
+
// We need a dummy container for the component to "render" into its own buffer
|
|
847
|
+
// For simplicity in this string-based framework, we mock the container
|
|
848
|
+
const mockContainer = { innerHTML: '' };
|
|
849
|
+
const instance = new componentToRender(mockContainer);
|
|
850
|
+
if (instance.setParams)
|
|
851
|
+
instance.setParams(params);
|
|
852
|
+
// Manually trigger mount logic without DOM effects if possible, or just template()
|
|
853
|
+
// Ideally, we just want the template string.
|
|
854
|
+
return instance.template();
|
|
855
|
+
}
|
|
856
|
+
else {
|
|
857
|
+
return componentToRender;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
return '<!-- 404 -->';
|
|
861
|
+
});
|
|
1301
862
|
}
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
863
|
+
matchRoute(hash) {
|
|
864
|
+
// Simple exact match first
|
|
865
|
+
let route = this.routes.find((r) => r.path === hash);
|
|
866
|
+
if (route)
|
|
867
|
+
return { route, params: {} };
|
|
868
|
+
// Regex match for params e.g. /user/:id
|
|
869
|
+
for (const r of this.routes) {
|
|
870
|
+
const paramNames = [];
|
|
871
|
+
const regexPath = r.path.replace(/:([^/]+)/g, (_, key) => {
|
|
872
|
+
paramNames.push(key);
|
|
873
|
+
return '([^/]+)';
|
|
874
|
+
});
|
|
875
|
+
const match = new RegExp(`^${regexPath}$`).exec(hash);
|
|
876
|
+
if (match) {
|
|
877
|
+
const params = {};
|
|
878
|
+
paramNames.forEach((name, i) => {
|
|
879
|
+
// SECURE: Automatically sanitize all route parameters
|
|
880
|
+
params[name] = Security.sanitize(match[i + 1]);
|
|
881
|
+
});
|
|
882
|
+
return { route: r, params };
|
|
883
|
+
}
|
|
1305
884
|
}
|
|
1306
|
-
return
|
|
885
|
+
return { route: undefined, params: {} };
|
|
1307
886
|
}
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
this.
|
|
1311
|
-
|
|
1312
|
-
|
|
887
|
+
handleRoute() {
|
|
888
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
889
|
+
if (this.isServer)
|
|
890
|
+
return;
|
|
891
|
+
const currentRouteId = ++this.lastRouteId;
|
|
892
|
+
const hash = window.location.hash.slice(1) || '/';
|
|
893
|
+
const { route, params } = this.matchRoute(hash);
|
|
894
|
+
// Security Check: Validate URL to prevent malicious hash injection
|
|
895
|
+
if (hash !== '/' && !Security.validateUrl('http://dummy.com' + hash)) {
|
|
896
|
+
console.error("Security Alert: Malformed URL detected.");
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
// Navigation Guard (Middleware)
|
|
900
|
+
if (route === null || route === void 0 ? void 0 : route.beforeEnter) {
|
|
901
|
+
yield new Promise((resolve) => {
|
|
902
|
+
route.beforeEnter(hash, this.currentPath, (allow) => {
|
|
903
|
+
if (allow)
|
|
904
|
+
resolve();
|
|
905
|
+
else {
|
|
906
|
+
console.warn(`Navigation to ${hash} blocked by guard.`);
|
|
907
|
+
// Ideally redirect or stay, here we just stop processing
|
|
908
|
+
throw new Error('Navigation Blocked');
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
}).catch(() => { return; }); // Stop execution if blocked
|
|
912
|
+
}
|
|
913
|
+
this.currentPath = hash;
|
|
914
|
+
if (route) {
|
|
915
|
+
if (route.title) {
|
|
916
|
+
document.title = route.title;
|
|
917
|
+
}
|
|
918
|
+
else if (route.meta && route.meta.title) {
|
|
919
|
+
// Fallback to meta.title if used
|
|
920
|
+
document.title = route.meta.title;
|
|
921
|
+
}
|
|
922
|
+
if (this.rootContainer) {
|
|
923
|
+
// Mulan Cycle: Destroy previous component before rendering new one
|
|
924
|
+
if (this.currentComponent) {
|
|
925
|
+
console.log(`[Router] Navigation from ${this.currentPath} to ${hash}. Destroying previous component.`);
|
|
926
|
+
if (this.currentComponent.onDestroy) {
|
|
927
|
+
this.currentComponent.onDestroy();
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
this.rootContainer.innerHTML = ''; // Clear previous content
|
|
931
|
+
}
|
|
932
|
+
let componentToRender = route.component;
|
|
933
|
+
// Support Lazy Loading
|
|
934
|
+
if (typeof componentToRender === 'function' && !componentToRender.prototype) {
|
|
935
|
+
try {
|
|
936
|
+
const module = yield componentToRender();
|
|
937
|
+
if (currentRouteId !== this.lastRouteId) {
|
|
938
|
+
console.log(`[Router] Navigation to ${hash} interrupted by newer navigation. Abandoning.`);
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
componentToRender = module.default || module;
|
|
942
|
+
}
|
|
943
|
+
catch (e) {
|
|
944
|
+
console.error("Failed to lazy load component", e);
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
if (typeof componentToRender === 'function') {
|
|
949
|
+
// It's a class component
|
|
950
|
+
if (this.rootContainer) {
|
|
951
|
+
const instance = new componentToRender(this.rootContainer);
|
|
952
|
+
this.currentComponent = instance;
|
|
953
|
+
// Inject params if the component accepts them
|
|
954
|
+
if (instance.setParams) {
|
|
955
|
+
instance.setParams(params);
|
|
956
|
+
}
|
|
957
|
+
instance.mount();
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
else if (typeof componentToRender === 'object' && componentToRender.template) {
|
|
961
|
+
// Object Component (Simple SFC without script or Options API)
|
|
962
|
+
const html = componentToRender.template();
|
|
963
|
+
if (this.rootContainer)
|
|
964
|
+
render(html, this.rootContainer);
|
|
965
|
+
this.currentComponent = null;
|
|
966
|
+
}
|
|
967
|
+
else {
|
|
968
|
+
// Simple HTML string/template
|
|
969
|
+
if (this.rootContainer)
|
|
970
|
+
render(componentToRender, this.rootContainer);
|
|
971
|
+
this.currentComponent = null; // String templates don't have lifecycle instances
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
else {
|
|
975
|
+
if (this.rootContainer)
|
|
976
|
+
render('<div style="text-align:center; padding:50px;"><h1>404</h1><p>Page Not Found</p></div>', this.rootContainer);
|
|
977
|
+
}
|
|
978
|
+
});
|
|
1313
979
|
}
|
|
1314
|
-
|
|
1315
|
-
|
|
980
|
+
// [Chronos] Prefetch a route's component code in the background
|
|
981
|
+
prefetch(path) {
|
|
982
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
983
|
+
if (this.isServer)
|
|
984
|
+
return;
|
|
985
|
+
const { route } = this.matchRoute(path);
|
|
986
|
+
if (route) {
|
|
987
|
+
let componentToRender = route.component;
|
|
988
|
+
// Check if it's a lazy-loaded function that hasn't been resolved yet
|
|
989
|
+
if (typeof componentToRender === 'function' && !componentToRender.prototype) {
|
|
990
|
+
// If it's already a resolved module (from previous prefetch), componentToRender might be the result.
|
|
991
|
+
// But typically in our simple implementation, route.component stays as the function until we replace it.
|
|
992
|
+
// To avoid double-fetching, we can check if it has a specific flag or property.
|
|
993
|
+
// For this implementation, we'll just run it and let the browser cache the module request (standard ES Module behavior).
|
|
994
|
+
try {
|
|
995
|
+
// console.log(`[Chronos] Prefetching ${path}...`);
|
|
996
|
+
yield componentToRender();
|
|
997
|
+
// We don't need to do anything with the result here.
|
|
998
|
+
// The browser's module cache will handle the speedup when the user actually navigates.
|
|
999
|
+
}
|
|
1000
|
+
catch (e) {
|
|
1001
|
+
console.warn(`[Chronos] Failed to prefetch ${path}`, e);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1316
1006
|
}
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
let stopped = false;
|
|
1321
|
-
const run = () => {
|
|
1322
|
-
if (stopped)
|
|
1323
|
-
return;
|
|
1324
|
-
const prev = activeEffect;
|
|
1325
|
-
activeEffect = run;
|
|
1326
|
-
try {
|
|
1327
|
-
fn();
|
|
1007
|
+
navigate(path) {
|
|
1008
|
+
if (this.isServer) {
|
|
1009
|
+
this.currentPath = path;
|
|
1328
1010
|
}
|
|
1329
|
-
|
|
1330
|
-
|
|
1011
|
+
else {
|
|
1012
|
+
window.location.hash = path;
|
|
1331
1013
|
}
|
|
1332
|
-
}
|
|
1333
|
-
run();
|
|
1334
|
-
return () => {
|
|
1335
|
-
stopped = true;
|
|
1336
|
-
};
|
|
1014
|
+
}
|
|
1337
1015
|
}
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1016
|
+
// --- Factory for Easy Usage ---
|
|
1017
|
+
const createRouter = (options) => {
|
|
1018
|
+
// Expose the router instance globally for <mu-link> to access
|
|
1019
|
+
const router = new MuRouter(options.routes, options.rootContainer);
|
|
1020
|
+
if (typeof window !== 'undefined') {
|
|
1021
|
+
window.__MULAN_ROUTER__ = router;
|
|
1022
|
+
}
|
|
1023
|
+
return router;
|
|
1024
|
+
};
|
|
1025
|
+
// --- Web Component: <mu-link> ---
|
|
1026
|
+
// Usage: <mu-link to="/about">About Us</mu-link>
|
|
1027
|
+
if (typeof window !== 'undefined' && !customElements.get('mu-link')) {
|
|
1028
|
+
class MuLink extends HTMLElement {
|
|
1029
|
+
constructor() {
|
|
1030
|
+
super();
|
|
1031
|
+
this.addEventListener('click', (e) => {
|
|
1032
|
+
e.preventDefault();
|
|
1033
|
+
const to = this.getAttribute('to');
|
|
1034
|
+
if (to) {
|
|
1035
|
+
// Update Hash for SPA Navigation
|
|
1036
|
+
window.location.hash = to;
|
|
1037
|
+
}
|
|
1038
|
+
});
|
|
1039
|
+
// [Chronos] Intelligent Pre-fetching
|
|
1040
|
+
this.addEventListener('mouseenter', () => {
|
|
1041
|
+
const to = this.getAttribute('to');
|
|
1042
|
+
if (to) {
|
|
1043
|
+
const router = window.__MULAN_ROUTER__;
|
|
1044
|
+
if (router && typeof router.prefetch === 'function') {
|
|
1045
|
+
router.prefetch(to);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
1049
|
+
// [Chronos] Also prefetch on focus for keyboard users
|
|
1050
|
+
this.addEventListener('focus', () => {
|
|
1051
|
+
const to = this.getAttribute('to');
|
|
1052
|
+
if (to) {
|
|
1053
|
+
const router = window.__MULAN_ROUTER__;
|
|
1054
|
+
if (router && typeof router.prefetch === 'function') {
|
|
1055
|
+
router.prefetch(to);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
});
|
|
1343
1059
|
}
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1060
|
+
connectedCallback() {
|
|
1061
|
+
this.style.cursor = 'pointer';
|
|
1062
|
+
this.style.color = 'var(--primary, #9C27B0)'; // Default to brand color if available
|
|
1063
|
+
this.style.textDecoration = 'none';
|
|
1347
1064
|
}
|
|
1348
|
-
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
function trigger(target, key) {
|
|
1352
|
-
const depsMap = targetMap.get(target);
|
|
1353
|
-
if (!depsMap)
|
|
1354
|
-
return;
|
|
1355
|
-
const dep = depsMap.get(key);
|
|
1356
|
-
if (dep) {
|
|
1357
|
-
dep.forEach((fn) => fn());
|
|
1065
|
+
static get observedAttributes() { return ['to']; }
|
|
1358
1066
|
}
|
|
1067
|
+
customElements.define('mu-link', MuLink);
|
|
1359
1068
|
}
|
|
1360
|
-
/**
|
|
1361
|
-
* Creates a reactive proxy object (Vue-compatible).
|
|
1362
|
-
* Now optimized to respect Mulan Cycle.
|
|
1363
|
-
*/
|
|
1364
|
-
function reactive(target) {
|
|
1365
|
-
return new Proxy(target, {
|
|
1366
|
-
get(obj, prop, receiver) {
|
|
1367
|
-
// IRON FORTRESS: Prototype Pollution Protection (Read)
|
|
1368
|
-
if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') {
|
|
1369
|
-
return undefined;
|
|
1370
|
-
}
|
|
1371
|
-
track(obj, prop);
|
|
1372
|
-
const val = Reflect.get(obj, prop, receiver);
|
|
1373
|
-
if (val !== null && typeof val === 'object') {
|
|
1374
|
-
return reactive(val);
|
|
1375
|
-
}
|
|
1376
|
-
return val;
|
|
1377
|
-
},
|
|
1378
|
-
set(obj, prop, value, receiver) {
|
|
1379
|
-
// IRON FORTRESS: Prototype Pollution Protection
|
|
1380
|
-
if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') {
|
|
1381
|
-
console.warn(`[Iron Fortress] Blocked attempt to modify dangerous property: ${String(prop)}`);
|
|
1382
|
-
return false;
|
|
1383
|
-
}
|
|
1384
|
-
const result = Reflect.set(obj, prop, value, receiver);
|
|
1385
|
-
trigger(obj, prop);
|
|
1386
|
-
return result;
|
|
1387
|
-
},
|
|
1388
|
-
});
|
|
1389
|
-
}
|
|
1390
|
-
/**
|
|
1391
|
-
* Creates a standalone reactive reference.
|
|
1392
|
-
* Backed by the Mulan Signal Engine.
|
|
1393
|
-
*/
|
|
1394
|
-
function ref(value) {
|
|
1395
|
-
return new Signal(value);
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
1069
|
|
|
1399
|
-
|
|
1070
|
+
;// ./src/store/index.ts
|
|
1400
1071
|
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
/* harmony export */ sanitize: () => (/* binding */ sanitize)
|
|
1413
|
-
/* harmony export */ });
|
|
1414
|
-
function render(template, container) {
|
|
1415
|
-
// Focus Preservation (The "Mulan Glance" Technique)
|
|
1416
|
-
let focusedId = null;
|
|
1417
|
-
let selectionStart = null;
|
|
1418
|
-
let selectionEnd = null;
|
|
1419
|
-
let preservedValue = null;
|
|
1420
|
-
if (document.activeElement && container.contains(document.activeElement)) {
|
|
1421
|
-
const el = document.activeElement;
|
|
1422
|
-
if (el.hasAttribute('data-mu-id')) {
|
|
1423
|
-
focusedId = el.getAttribute('data-mu-id');
|
|
1424
|
-
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
|
|
1425
|
-
selectionStart = el.selectionStart;
|
|
1426
|
-
selectionEnd = el.selectionEnd;
|
|
1427
|
-
preservedValue = el.value;
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
// [Anima] 1. Pre-Update: Snapshot positions of animated elements
|
|
1432
|
-
const animationSnapshots = new Map();
|
|
1433
|
-
// Only query if we might have animations to save perf
|
|
1434
|
-
if (template.includes('mu-animate')) {
|
|
1435
|
-
const animatedEls = container.querySelectorAll('[mu-animate]');
|
|
1436
|
-
animatedEls.forEach(el => {
|
|
1437
|
-
const key = el.getAttribute('mu-key') || el.id;
|
|
1438
|
-
if (key) {
|
|
1439
|
-
animationSnapshots.set(key, el.getBoundingClientRect());
|
|
1440
|
-
}
|
|
1441
|
-
});
|
|
1442
|
-
}
|
|
1443
|
-
container.innerHTML = template;
|
|
1444
|
-
// Restore Focus and Value
|
|
1445
|
-
if (focusedId) {
|
|
1446
|
-
const el = container.querySelector(`[data-mu-id="${focusedId}"]`);
|
|
1447
|
-
if (el) {
|
|
1448
|
-
// Restore value first to ensure cursor positioning works correctly
|
|
1449
|
-
if (preservedValue !== null && (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement)) {
|
|
1450
|
-
el.value = preservedValue;
|
|
1451
|
-
}
|
|
1452
|
-
el.focus();
|
|
1453
|
-
if ((el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) && selectionStart !== null) {
|
|
1454
|
-
try {
|
|
1455
|
-
el.setSelectionRange(selectionStart, selectionEnd);
|
|
1456
|
-
}
|
|
1457
|
-
catch (e) {
|
|
1458
|
-
// input types that don't support selection (e.g. number/email) might throw
|
|
1072
|
+
class MuStore {
|
|
1073
|
+
constructor(initialState, options) {
|
|
1074
|
+
this.subscribers = [];
|
|
1075
|
+
// Load from local storage if persist is true
|
|
1076
|
+
let loadedState = initialState;
|
|
1077
|
+
if (options === null || options === void 0 ? void 0 : options.persist) {
|
|
1078
|
+
const key = options.key || 'mulan-store';
|
|
1079
|
+
try {
|
|
1080
|
+
const stored = localStorage.getItem(key);
|
|
1081
|
+
if (stored) {
|
|
1082
|
+
loadedState = Object.assign(Object.assign({}, initialState), JSON.parse(stored));
|
|
1459
1083
|
}
|
|
1460
1084
|
}
|
|
1085
|
+
catch (e) {
|
|
1086
|
+
console.error("Failed to load state", e);
|
|
1087
|
+
}
|
|
1088
|
+
// Auto-save effect
|
|
1089
|
+
effect(() => {
|
|
1090
|
+
localStorage.setItem(key, JSON.stringify(this.state));
|
|
1091
|
+
});
|
|
1461
1092
|
}
|
|
1093
|
+
this.state = reactive(loadedState);
|
|
1462
1094
|
}
|
|
1463
|
-
//
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
if (key && animationSnapshots.has(key)) {
|
|
1469
|
-
const oldRect = animationSnapshots.get(key);
|
|
1470
|
-
const newRect = el.getBoundingClientRect();
|
|
1471
|
-
const dx = oldRect.left - newRect.left;
|
|
1472
|
-
const dy = oldRect.top - newRect.top;
|
|
1473
|
-
// Only animate if moved
|
|
1474
|
-
if (dx !== 0 || dy !== 0) {
|
|
1475
|
-
const htmlEl = el;
|
|
1476
|
-
// INVERT: Move it back to where it was instantly
|
|
1477
|
-
htmlEl.style.transform = `translate(${dx}px, ${dy}px)`;
|
|
1478
|
-
htmlEl.style.transition = 'none';
|
|
1479
|
-
// PLAY: Animate to zero (new position)
|
|
1480
|
-
requestAnimationFrame(() => {
|
|
1481
|
-
// Force reflow
|
|
1482
|
-
// void htmlEl.offsetWidth;
|
|
1483
|
-
htmlEl.style.transition = 'transform 500ms cubic-bezier(0.25, 0.8, 0.25, 1)';
|
|
1484
|
-
htmlEl.style.transform = '';
|
|
1485
|
-
});
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1095
|
+
// Subscribe to changes
|
|
1096
|
+
subscribe(fn) {
|
|
1097
|
+
this.subscribers.push(fn);
|
|
1098
|
+
effect(() => {
|
|
1099
|
+
fn(this.state);
|
|
1488
1100
|
});
|
|
1489
1101
|
}
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
else {
|
|
1500
|
-
// console.log('Hydration Successful.');
|
|
1501
|
-
}
|
|
1502
|
-
// Future: Attach event listeners here if we had a mechanism for it.
|
|
1503
|
-
}
|
|
1504
|
-
function renderToString(template) {
|
|
1505
|
-
// SSR Function: returns the HTML string for the server to send.
|
|
1506
|
-
// Can include additional sanitization or metadata injection here.
|
|
1507
|
-
return template;
|
|
1508
|
-
}
|
|
1509
|
-
function sanitize(str) {
|
|
1510
|
-
// Check if we are in a browser environment
|
|
1511
|
-
if (typeof document !== 'undefined') {
|
|
1512
|
-
const temp = document.createElement('div');
|
|
1513
|
-
temp.textContent = str;
|
|
1514
|
-
return temp.innerHTML;
|
|
1102
|
+
// Action dispatcher pattern
|
|
1103
|
+
dispatch(action) {
|
|
1104
|
+
const result = action(this.state);
|
|
1105
|
+
if (result instanceof Promise) {
|
|
1106
|
+
result.then(() => {
|
|
1107
|
+
// Optional: Notify subscribers of async completion if needed manually?
|
|
1108
|
+
// But reactive() handles updates automatically.
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1515
1111
|
}
|
|
1516
|
-
// Simple SSR fallback sanitizer (rudimentary)
|
|
1517
|
-
return str.replace(/&/g, "&")
|
|
1518
|
-
.replace(/</g, "<")
|
|
1519
|
-
.replace(/>/g, ">")
|
|
1520
|
-
.replace(/"/g, """)
|
|
1521
|
-
.replace(/'/g, "'");
|
|
1522
1112
|
}
|
|
1523
1113
|
|
|
1114
|
+
;// ./src/core/query.ts
|
|
1115
|
+
var query_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1116
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1117
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1118
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1119
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1120
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1121
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1122
|
+
});
|
|
1123
|
+
};
|
|
1524
1124
|
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
\***************************/
|
|
1531
|
-
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
1532
|
-
|
|
1533
|
-
__webpack_require__.r(__webpack_exports__);
|
|
1534
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1535
|
-
/* harmony export */ muBurst: () => (/* binding */ muBurst),
|
|
1536
|
-
/* harmony export */ muSurge: () => (/* binding */ muSurge)
|
|
1537
|
-
/* harmony export */ });
|
|
1538
|
-
/**
|
|
1539
|
-
* muBurst - Adaptive Non-blocking Iterator
|
|
1540
|
-
* Processes large arrays in batches within a frame budget (typically 8-16ms)
|
|
1541
|
-
* to keep the UI responsive while executing at near-native loop speeds.
|
|
1542
|
-
*/
|
|
1543
|
-
function muBurst(array, callback, options = {}) {
|
|
1544
|
-
const { chunkSize = 1000, timeout = 8, onProgress } = options;
|
|
1545
|
-
return new Promise((resolve) => {
|
|
1546
|
-
let index = 0;
|
|
1547
|
-
const total = array.length;
|
|
1548
|
-
function process() {
|
|
1549
|
-
const start = performance.now();
|
|
1550
|
-
// Tight loop for high-speed processing
|
|
1551
|
-
while (index < total && (performance.now() - start) < timeout) {
|
|
1552
|
-
// Process in smaller bursts to allow more frequent time checks if needed
|
|
1553
|
-
const endBurst = Math.min(index + chunkSize, total);
|
|
1554
|
-
for (; index < endBurst; index++) {
|
|
1555
|
-
callback(array[index], index);
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
if (onProgress) {
|
|
1559
|
-
onProgress((index / total) * 100);
|
|
1560
|
-
}
|
|
1561
|
-
if (index < total) {
|
|
1562
|
-
requestAnimationFrame(process);
|
|
1563
|
-
}
|
|
1564
|
-
else {
|
|
1565
|
-
resolve();
|
|
1566
|
-
}
|
|
1567
|
-
}
|
|
1568
|
-
process();
|
|
1569
|
-
});
|
|
1570
|
-
}
|
|
1571
|
-
/**
|
|
1572
|
-
* muSurge - Truly Parallel Execution
|
|
1573
|
-
* Distributes work across CPU cores using Web Workers.
|
|
1574
|
-
* Logic must be serializable.
|
|
1575
|
-
*/
|
|
1576
|
-
function muSurge(array, taskFn, onProgress) {
|
|
1577
|
-
const n = navigator.hardwareConcurrency || 4;
|
|
1578
|
-
const chunkSize = Math.ceil(array.length / n);
|
|
1579
|
-
const results = new Array(array.length);
|
|
1580
|
-
let completedChunks = 0;
|
|
1581
|
-
let completedItems = 0;
|
|
1582
|
-
// Convert function to string if it isn't already
|
|
1583
|
-
const fnStr = typeof taskFn === 'function' ? taskFn.toString() : taskFn;
|
|
1584
|
-
const workerPart1 = `const taskFn = ${fnStr};`;
|
|
1585
|
-
const workerPart2 = `self.onmessage = function(e) {`;
|
|
1586
|
-
const workerPart3 = ` const { chunk, startIndex } = e.data;`;
|
|
1587
|
-
const workerPart4 = ` try { const results = chunk.map(taskFn); self.postMessage({ results, startIndex }); }`;
|
|
1588
|
-
const workerPart5 = ` catch (err) { self.postMessage({ error: err.message, startIndex }); }`;
|
|
1589
|
-
const workerPart6 = `};`;
|
|
1590
|
-
const workerCode = [workerPart1, workerPart2, workerPart3, workerPart4, workerPart5, workerPart6].join('\n');
|
|
1591
|
-
const blob = new Blob([workerCode], { type: 'application/javascript' });
|
|
1592
|
-
const workerUrl = URL.createObjectURL(blob);
|
|
1593
|
-
return new Promise((resolve) => {
|
|
1594
|
-
if (array.length === 0)
|
|
1595
|
-
return resolve([]);
|
|
1596
|
-
for (let i = 0; i < n; i++) {
|
|
1597
|
-
const start = i * chunkSize;
|
|
1598
|
-
const end = Math.min(start + chunkSize, array.length);
|
|
1599
|
-
if (start >= end) {
|
|
1600
|
-
completedChunks++;
|
|
1601
|
-
continue;
|
|
1602
|
-
}
|
|
1603
|
-
const chunk = array.slice(start, end);
|
|
1604
|
-
const worker = new Worker(workerUrl);
|
|
1605
|
-
worker.onmessage = (e) => {
|
|
1606
|
-
const { results: chunkResults, startIndex } = e.data;
|
|
1607
|
-
// Merge results back into main array
|
|
1608
|
-
for (let j = 0; j < chunkResults.length; j++) {
|
|
1609
|
-
results[startIndex + j] = chunkResults[j];
|
|
1610
|
-
}
|
|
1611
|
-
completedChunks++;
|
|
1612
|
-
completedItems += chunkResults.length;
|
|
1613
|
-
if (onProgress)
|
|
1614
|
-
onProgress((completedItems / array.length) * 100);
|
|
1615
|
-
worker.terminate();
|
|
1616
|
-
if (completedChunks === n) {
|
|
1617
|
-
URL.revokeObjectURL(workerUrl);
|
|
1618
|
-
resolve(results);
|
|
1619
|
-
}
|
|
1620
|
-
};
|
|
1621
|
-
worker.postMessage({ chunk, startIndex: start, fnStr });
|
|
1622
|
-
}
|
|
1125
|
+
function useQuery(queryFn, options = { enabled: true }) {
|
|
1126
|
+
const state = reactive({
|
|
1127
|
+
data: null,
|
|
1128
|
+
isLoading: false,
|
|
1129
|
+
error: null
|
|
1623
1130
|
});
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
/***/ },
|
|
1628
|
-
|
|
1629
|
-
/***/ "./src/core/vault.ts"
|
|
1630
|
-
/*!***************************!*\
|
|
1631
|
-
!*** ./src/core/vault.ts ***!
|
|
1632
|
-
\***************************/
|
|
1633
|
-
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
1634
|
-
|
|
1635
|
-
__webpack_require__.r(__webpack_exports__);
|
|
1636
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1637
|
-
/* harmony export */ persistent: () => (/* binding */ persistent)
|
|
1638
|
-
/* harmony export */ });
|
|
1639
|
-
/* harmony import */ var _hooks__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./hooks */ "./src/core/hooks.ts");
|
|
1640
|
-
/* harmony import */ var _reactive__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./reactive */ "./src/core/reactive.ts");
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
/**
|
|
1644
|
-
* Mulan Vault: The World's First Native Persistent State Primitive.
|
|
1645
|
-
*/
|
|
1646
|
-
function persistent(key, initialValue, options = {}) {
|
|
1647
|
-
const storage = options.storage || window.localStorage;
|
|
1648
|
-
// 1. Load from Storage
|
|
1649
|
-
const stored = storage.getItem(key);
|
|
1650
|
-
let startVal = initialValue;
|
|
1651
|
-
if (stored) {
|
|
1131
|
+
const execute = () => query_awaiter(this, void 0, void 0, function* () {
|
|
1132
|
+
state.isLoading = true;
|
|
1133
|
+
state.error = null;
|
|
1652
1134
|
try {
|
|
1653
|
-
|
|
1135
|
+
const result = yield queryFn();
|
|
1136
|
+
state.data = result;
|
|
1654
1137
|
}
|
|
1655
|
-
catch (
|
|
1656
|
-
|
|
1138
|
+
catch (err) {
|
|
1139
|
+
state.error = err;
|
|
1657
1140
|
}
|
|
1141
|
+
finally {
|
|
1142
|
+
state.isLoading = false;
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
if (options.enabled) {
|
|
1146
|
+
// Run automatically
|
|
1147
|
+
effect(() => {
|
|
1148
|
+
// Basic effect wrapper to allow reactivity if queryFn relies on signals
|
|
1149
|
+
execute();
|
|
1150
|
+
});
|
|
1658
1151
|
}
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1152
|
+
return {
|
|
1153
|
+
get data() { return state.data; },
|
|
1154
|
+
get isLoading() { return state.isLoading; },
|
|
1155
|
+
get error() { return state.error; },
|
|
1156
|
+
refetch: execute
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
function useMutation(mutationFn) {
|
|
1160
|
+
const state = reactive({
|
|
1161
|
+
data: null,
|
|
1162
|
+
isLoading: false,
|
|
1163
|
+
error: null
|
|
1164
|
+
});
|
|
1165
|
+
const mutate = (args) => query_awaiter(this, void 0, void 0, function* () {
|
|
1166
|
+
state.isLoading = true;
|
|
1167
|
+
state.error = null;
|
|
1664
1168
|
try {
|
|
1665
|
-
const
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
storage.setItem(key, toSave);
|
|
1169
|
+
const result = yield mutationFn(args);
|
|
1170
|
+
state.data = result;
|
|
1171
|
+
return result;
|
|
1669
1172
|
}
|
|
1670
|
-
catch (
|
|
1671
|
-
|
|
1173
|
+
catch (err) {
|
|
1174
|
+
state.error = err;
|
|
1175
|
+
throw err;
|
|
1672
1176
|
}
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
const sync = (e) => {
|
|
1676
|
-
if (e.key === key && e.newValue) {
|
|
1677
|
-
try {
|
|
1678
|
-
const newVal = JSON.parse(e.newValue);
|
|
1679
|
-
if (isObject) {
|
|
1680
|
-
Object.assign(state, newVal);
|
|
1681
|
-
}
|
|
1682
|
-
else {
|
|
1683
|
-
state.value = newVal;
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
catch (e) { }
|
|
1177
|
+
finally {
|
|
1178
|
+
state.isLoading = false;
|
|
1687
1179
|
}
|
|
1180
|
+
});
|
|
1181
|
+
return {
|
|
1182
|
+
get data() { return state.data; },
|
|
1183
|
+
get isLoading() { return state.isLoading; },
|
|
1184
|
+
get error() { return state.error; },
|
|
1185
|
+
mutate
|
|
1688
1186
|
};
|
|
1689
|
-
window.addEventListener('storage', sync);
|
|
1690
|
-
// Explicit cleanup if provided by the environment (e.g. Mulan Hooks)
|
|
1691
|
-
if (options.onCleanup) {
|
|
1692
|
-
options.onCleanup(() => {
|
|
1693
|
-
window.removeEventListener('storage', sync);
|
|
1694
|
-
});
|
|
1695
|
-
}
|
|
1696
|
-
return state;
|
|
1697
1187
|
}
|
|
1698
1188
|
|
|
1189
|
+
;// ./src/core/quantum.ts
|
|
1699
1190
|
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
return
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1722
|
-
});
|
|
1723
|
-
};
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
class MuRouter {
|
|
1727
|
-
constructor(routes, rootContainer = null) {
|
|
1728
|
-
this.currentPath = '';
|
|
1729
|
-
this.currentComponent = null;
|
|
1730
|
-
this.lastRouteId = 0;
|
|
1731
|
-
this.routes = routes;
|
|
1732
|
-
this.rootContainer = rootContainer;
|
|
1733
|
-
this.isServer = rootContainer === null; // If no container, assume server/headless mode
|
|
1734
|
-
if (!this.isServer) {
|
|
1735
|
-
window.addEventListener('hashchange', this.handleRoute.bind(this));
|
|
1736
|
-
this.handleRoute(); // Initial load
|
|
1191
|
+
/**
|
|
1192
|
+
* Mulan Quantum (ASTR-Q+) Core
|
|
1193
|
+
* Advanced Simulation Engine for multi-qubit registers and entanglement.
|
|
1194
|
+
*/
|
|
1195
|
+
// -- GLOBAL CONTEXT FOR QUANTUM CONTROL --
|
|
1196
|
+
// Defined at top to ensure visibility for muGate
|
|
1197
|
+
let activeControls = [];
|
|
1198
|
+
/**
|
|
1199
|
+
* Creates a quantum register of size n.
|
|
1200
|
+
* State vector will have 2^n amplitudes.
|
|
1201
|
+
*/
|
|
1202
|
+
function muRegister(n) {
|
|
1203
|
+
const numStates = Math.pow(2, n);
|
|
1204
|
+
const amplitudes = new Array(numStates).fill(0).map((_, i) => ({
|
|
1205
|
+
re: i === 0 ? 1 : 0,
|
|
1206
|
+
im: 0
|
|
1207
|
+
}));
|
|
1208
|
+
return muState({
|
|
1209
|
+
value: {
|
|
1210
|
+
size: n,
|
|
1211
|
+
amplitudes
|
|
1737
1212
|
}
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Backward compatible muQubit (Single Qubit Register)
|
|
1217
|
+
*/
|
|
1218
|
+
function muQubit(initial = 0) {
|
|
1219
|
+
const q = muRegister(1);
|
|
1220
|
+
if (initial === 1) {
|
|
1221
|
+
muGate(q, 'X', 0);
|
|
1738
1222
|
}
|
|
1739
|
-
//
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
// Manually trigger mount logic without DOM effects if possible, or just template()
|
|
1761
|
-
// Ideally, we just want the template string.
|
|
1762
|
-
return instance.template();
|
|
1763
|
-
}
|
|
1764
|
-
else {
|
|
1765
|
-
return componentToRender;
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
|
-
return '<!-- 404 -->';
|
|
1223
|
+
// Add compatibility properties for Phase 1 components
|
|
1224
|
+
// These properties are getters that dynamically access the amplitudes array
|
|
1225
|
+
Object.defineProperty(q.value, 'alpha', { get: () => q.value.amplitudes[0] });
|
|
1226
|
+
Object.defineProperty(q.value, 'beta', { get: () => q.value.amplitudes[1] });
|
|
1227
|
+
return q;
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Internal helper to update register state while maintaining compatibility
|
|
1231
|
+
*/
|
|
1232
|
+
function updateState(reg, newState) {
|
|
1233
|
+
if (newState.size === 1) {
|
|
1234
|
+
// Re-inject compatibility getters for muQubit users
|
|
1235
|
+
Object.defineProperty(newState, 'alpha', {
|
|
1236
|
+
get: () => newState.amplitudes[0],
|
|
1237
|
+
configurable: true,
|
|
1238
|
+
enumerable: true
|
|
1239
|
+
});
|
|
1240
|
+
Object.defineProperty(newState, 'beta', {
|
|
1241
|
+
get: () => newState.amplitudes[1],
|
|
1242
|
+
configurable: true,
|
|
1243
|
+
enumerable: true
|
|
1769
1244
|
});
|
|
1770
1245
|
}
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1246
|
+
reg.value = newState;
|
|
1247
|
+
}
|
|
1248
|
+
function muGate(reg, type, target = 0, control) {
|
|
1249
|
+
const state = reg.value;
|
|
1250
|
+
const n = state.size;
|
|
1251
|
+
const amplitudes = state.amplitudes;
|
|
1252
|
+
const newAmps = amplitudes.map(a => (Object.assign({}, a)));
|
|
1253
|
+
// Prepare Effective Control (Explicit Arguments + Global Context)
|
|
1254
|
+
const effectiveControl = [...(control === undefined ? [] : (Array.isArray(control) ? control : [control])), ...activeControls];
|
|
1255
|
+
// Helper: Check if all control bits are 1
|
|
1256
|
+
const checkControl = (index, ctrl) => {
|
|
1257
|
+
if (ctrl === undefined || (Array.isArray(ctrl) && ctrl.length === 0))
|
|
1258
|
+
return true;
|
|
1259
|
+
const ctrls = Array.isArray(ctrl) ? ctrl : [ctrl];
|
|
1260
|
+
return ctrls.every(c => ((index >> c) & 1) === 1);
|
|
1261
|
+
};
|
|
1262
|
+
// SWAP Gate (Unique case: affects 2 targets)
|
|
1263
|
+
if (type === 'SWAP') {
|
|
1264
|
+
const t1 = target;
|
|
1265
|
+
const t2 = control; // SWAP uses control arg as second target
|
|
1266
|
+
// Iterate only half to avoid double swapping
|
|
1267
|
+
for (let i = 0; i < amplitudes.length; i++) {
|
|
1268
|
+
// Check active controls for SWAP too
|
|
1269
|
+
if (activeControls.length > 0 && !checkControl(i, activeControls))
|
|
1270
|
+
continue;
|
|
1271
|
+
const bit1 = (i >> t1) & 1;
|
|
1272
|
+
const bit2 = (i >> t2) & 1;
|
|
1273
|
+
if (bit1 !== bit2) {
|
|
1274
|
+
// Determine the swap partner index
|
|
1275
|
+
// If i has (0,1), partner has (1,0) at those positions
|
|
1276
|
+
const partner = i ^ (1 << t1) ^ (1 << t2);
|
|
1277
|
+
if (i < partner) {
|
|
1278
|
+
const temp = newAmps[i];
|
|
1279
|
+
newAmps[i] = newAmps[partner];
|
|
1280
|
+
newAmps[partner] = temp;
|
|
1281
|
+
}
|
|
1791
1282
|
}
|
|
1792
1283
|
}
|
|
1793
|
-
|
|
1284
|
+
updateState(reg, Object.assign(Object.assign({}, state), { amplitudes: newAmps }));
|
|
1285
|
+
return;
|
|
1794
1286
|
}
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
//
|
|
1803
|
-
if (
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
resolve();
|
|
1813
|
-
else {
|
|
1814
|
-
console.warn(`Navigation to ${hash} blocked by guard.`);
|
|
1815
|
-
// Ideally redirect or stay, here we just stop processing
|
|
1816
|
-
throw new Error('Navigation Blocked');
|
|
1817
|
-
}
|
|
1818
|
-
});
|
|
1819
|
-
}).catch(() => { return; }); // Stop execution if blocked
|
|
1820
|
-
}
|
|
1821
|
-
this.currentPath = hash;
|
|
1822
|
-
if (route) {
|
|
1823
|
-
if (route.title) {
|
|
1824
|
-
document.title = route.title;
|
|
1825
|
-
}
|
|
1826
|
-
else if (route.meta && route.meta.title) {
|
|
1827
|
-
// Fallback to meta.title if used
|
|
1828
|
-
document.title = route.meta.title;
|
|
1829
|
-
}
|
|
1830
|
-
if (this.rootContainer) {
|
|
1831
|
-
// Mulan Cycle: Destroy previous component before rendering new one
|
|
1832
|
-
if (this.currentComponent) {
|
|
1833
|
-
console.log(`[Router] Navigation from ${this.currentPath} to ${hash}. Destroying previous component.`);
|
|
1834
|
-
if (this.currentComponent.onDestroy) {
|
|
1835
|
-
this.currentComponent.onDestroy();
|
|
1836
|
-
}
|
|
1837
|
-
}
|
|
1838
|
-
this.rootContainer.innerHTML = ''; // Clear previous content
|
|
1839
|
-
}
|
|
1840
|
-
let componentToRender = route.component;
|
|
1841
|
-
// Support Lazy Loading
|
|
1842
|
-
if (typeof componentToRender === 'function' && !componentToRender.prototype) {
|
|
1843
|
-
try {
|
|
1844
|
-
const module = yield componentToRender();
|
|
1845
|
-
if (currentRouteId !== this.lastRouteId) {
|
|
1846
|
-
console.log(`[Router] Navigation to ${hash} interrupted by newer navigation. Abandoning.`);
|
|
1847
|
-
return;
|
|
1848
|
-
}
|
|
1849
|
-
componentToRender = module.default || module;
|
|
1850
|
-
}
|
|
1851
|
-
catch (e) {
|
|
1852
|
-
console.error("Failed to lazy load component", e);
|
|
1853
|
-
return;
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
if (typeof componentToRender === 'function') {
|
|
1857
|
-
// It's a class component
|
|
1858
|
-
if (this.rootContainer) {
|
|
1859
|
-
const instance = new componentToRender(this.rootContainer);
|
|
1860
|
-
this.currentComponent = instance;
|
|
1861
|
-
// Inject params if the component accepts them
|
|
1862
|
-
if (instance.setParams) {
|
|
1863
|
-
instance.setParams(params);
|
|
1864
|
-
}
|
|
1865
|
-
instance.mount();
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
else if (typeof componentToRender === 'object' && componentToRender.template) {
|
|
1869
|
-
// Object Component (Simple SFC without script or Options API)
|
|
1870
|
-
const html = componentToRender.template();
|
|
1871
|
-
if (this.rootContainer)
|
|
1872
|
-
(0,_core_renderer__WEBPACK_IMPORTED_MODULE_0__.render)(html, this.rootContainer);
|
|
1873
|
-
this.currentComponent = null;
|
|
1874
|
-
}
|
|
1875
|
-
else {
|
|
1876
|
-
// Simple HTML string/template
|
|
1877
|
-
if (this.rootContainer)
|
|
1878
|
-
(0,_core_renderer__WEBPACK_IMPORTED_MODULE_0__.render)(componentToRender, this.rootContainer);
|
|
1879
|
-
this.currentComponent = null; // String templates don't have lifecycle instances
|
|
1880
|
-
}
|
|
1287
|
+
// Standard Single-Qubit & Controlled Gates
|
|
1288
|
+
if (type === 'H') {
|
|
1289
|
+
const s = 1 / Math.sqrt(2);
|
|
1290
|
+
const processed = new Set();
|
|
1291
|
+
for (let i = 0; i < state.amplitudes.length; i++) {
|
|
1292
|
+
if (processed.has(i))
|
|
1293
|
+
continue;
|
|
1294
|
+
// Check Controls first
|
|
1295
|
+
if (!checkControl(i, effectiveControl))
|
|
1296
|
+
continue;
|
|
1297
|
+
const targetBit = (i >> target) & 1;
|
|
1298
|
+
const pairedIndex = targetBit ? (i & ~(1 << target)) : (i | (1 << target));
|
|
1299
|
+
const a = state.amplitudes[i];
|
|
1300
|
+
const b = state.amplitudes[pairedIndex];
|
|
1301
|
+
if (targetBit === 0) {
|
|
1302
|
+
newAmps[i] = { re: s * (a.re + b.re), im: s * (a.im + b.im) };
|
|
1303
|
+
newAmps[pairedIndex] = { re: s * (a.re - b.re), im: s * (a.im - b.im) };
|
|
1881
1304
|
}
|
|
1882
1305
|
else {
|
|
1883
|
-
|
|
1884
|
-
|
|
1306
|
+
newAmps[pairedIndex] = { re: s * (b.re + a.re), im: s * (b.im + a.im) };
|
|
1307
|
+
newAmps[i] = { re: s * (b.re - a.re), im: s * (b.im - a.im) };
|
|
1885
1308
|
}
|
|
1886
|
-
|
|
1309
|
+
processed.add(i);
|
|
1310
|
+
processed.add(pairedIndex);
|
|
1311
|
+
}
|
|
1887
1312
|
}
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
if (
|
|
1892
|
-
|
|
1893
|
-
const
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
// But typically in our simple implementation, route.component stays as the function until we replace it.
|
|
1900
|
-
// To avoid double-fetching, we can check if it has a specific flag or property.
|
|
1901
|
-
// For this implementation, we'll just run it and let the browser cache the module request (standard ES Module behavior).
|
|
1902
|
-
try {
|
|
1903
|
-
// console.log(`[Chronos] Prefetching ${path}...`);
|
|
1904
|
-
yield componentToRender();
|
|
1905
|
-
// We don't need to do anything with the result here.
|
|
1906
|
-
// The browser's module cache will handle the speedup when the user actually navigates.
|
|
1907
|
-
}
|
|
1908
|
-
catch (e) {
|
|
1909
|
-
console.warn(`[Chronos] Failed to prefetch ${path}`, e);
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1313
|
+
else if (type === 'X' || type === 'CNOT') {
|
|
1314
|
+
// CNOT is just Controlled-X
|
|
1315
|
+
for (let i = 0; i < amplitudes.length; i++) {
|
|
1316
|
+
if (!checkControl(i, effectiveControl))
|
|
1317
|
+
continue;
|
|
1318
|
+
const targetBit = (i >> target) & 1;
|
|
1319
|
+
const pairedIndex = targetBit ? (i & ~(1 << target)) : (i | (1 << target));
|
|
1320
|
+
if (i < pairedIndex) {
|
|
1321
|
+
const temp = newAmps[i];
|
|
1322
|
+
newAmps[i] = newAmps[pairedIndex];
|
|
1323
|
+
newAmps[pairedIndex] = temp;
|
|
1912
1324
|
}
|
|
1913
|
-
});
|
|
1914
|
-
}
|
|
1915
|
-
navigate(path) {
|
|
1916
|
-
if (this.isServer) {
|
|
1917
|
-
this.currentPath = path;
|
|
1918
1325
|
}
|
|
1919
|
-
|
|
1920
|
-
|
|
1326
|
+
}
|
|
1327
|
+
else if (type === 'Z' || type === 'CZ') {
|
|
1328
|
+
// Z and CZ are Phase Flips
|
|
1329
|
+
for (let i = 0; i < amplitudes.length; i++) {
|
|
1330
|
+
if (!checkControl(i, effectiveControl))
|
|
1331
|
+
continue;
|
|
1332
|
+
const targetBit = (i >> target) & 1;
|
|
1333
|
+
// Z Gate acts on |1>
|
|
1334
|
+
if (targetBit === 1) {
|
|
1335
|
+
newAmps[i] = { re: -amplitudes[i].re, im: -amplitudes[i].im };
|
|
1336
|
+
}
|
|
1921
1337
|
}
|
|
1922
1338
|
}
|
|
1923
|
-
|
|
1924
|
-
//
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1339
|
+
else if (type === 'Y') {
|
|
1340
|
+
// Y: |0> -> i|1>, |1> -> -i|0>
|
|
1341
|
+
for (let i = 0; i < amplitudes.length; i++) {
|
|
1342
|
+
if (!checkControl(i, effectiveControl))
|
|
1343
|
+
continue;
|
|
1344
|
+
const targetBit = (i >> target) & 1;
|
|
1345
|
+
const pairedIndex = targetBit ? (i & ~(1 << target)) : (i | (1 << target));
|
|
1346
|
+
if (i < pairedIndex) {
|
|
1347
|
+
// We process pairs (i, pairedIndex) where i has 0 at target, paired has 1
|
|
1348
|
+
const a = newAmps[i]; // Coeff of |0>
|
|
1349
|
+
const b = newAmps[pairedIndex]; // Coeff of |1>
|
|
1350
|
+
// New |0> = -i * Old |1>
|
|
1351
|
+
newAmps[i] = { re: b.im, im: -b.re };
|
|
1352
|
+
// New |1> = i * Old |0>
|
|
1353
|
+
newAmps[pairedIndex] = { re: -a.im, im: a.re };
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
updateState(reg, Object.assign(Object.assign({}, state), { amplitudes: newAmps }));
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* Mulan Search Logic (Grover's Operator)
|
|
1361
|
+
* Automatically constructs a multi-controlled Phase Flip (Z) for a specific target state.
|
|
1362
|
+
* This is the core of the "Quantum Switch" or "Quantum Search" capability.
|
|
1363
|
+
* @param reg Quantum Register
|
|
1364
|
+
* @param targetState The integer state to "search" and mark (e.g. 2 for |10>)
|
|
1365
|
+
*/
|
|
1366
|
+
function muSearch(reg, targetState) {
|
|
1367
|
+
const n = reg.value.size;
|
|
1368
|
+
const controls = [];
|
|
1369
|
+
// 1. Identify which bits are 0 and need wrapping with X gates
|
|
1370
|
+
// Logic: To mark |010>, we want C-C-Z to trigger on 111.
|
|
1371
|
+
// So we apply X to bits that are 0, then C-C-Z, then X again.
|
|
1372
|
+
// We treat the last bit as the 'target' for the Z gate, rest as controls
|
|
1373
|
+
const targetQubit = n - 1;
|
|
1374
|
+
for (let i = 0; i < n; i++) {
|
|
1375
|
+
const bit = (targetState >> i) & 1;
|
|
1376
|
+
if (i === targetQubit) {
|
|
1377
|
+
// If target bit logic requires 0, we flip it to 1 for the Z gate to work
|
|
1378
|
+
if (bit === 0)
|
|
1379
|
+
muGate(reg, 'X', i);
|
|
1380
|
+
}
|
|
1381
|
+
else {
|
|
1382
|
+
controls.push(i);
|
|
1383
|
+
if (bit === 0)
|
|
1384
|
+
muGate(reg, 'X', i);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
// 2. Apply Multi-Controlled Z
|
|
1388
|
+
muGate(reg, 'Z', targetQubit, controls);
|
|
1389
|
+
// 3. Uncompute (Restore 0s)
|
|
1390
|
+
for (let i = 0; i < n; i++) {
|
|
1391
|
+
const bit = (targetState >> i) & 1;
|
|
1392
|
+
if (bit === 0)
|
|
1393
|
+
muGate(reg, 'X', i);
|
|
1394
|
+
}
|
|
1395
|
+
// --- GROVER DIFFUSER (Amplification) ---
|
|
1396
|
+
// This flips the probability amplitudes around the mean, boosting the target state.
|
|
1397
|
+
// 1. Apply H to all
|
|
1398
|
+
for (let i = 0; i < n; i++)
|
|
1399
|
+
muGate(reg, 'H', i);
|
|
1400
|
+
// 2. Apply X to all
|
|
1401
|
+
for (let i = 0; i < n; i++)
|
|
1402
|
+
muGate(reg, 'X', i);
|
|
1403
|
+
// 3. Multi-Controlled Z (Reflection about |0...0>)
|
|
1404
|
+
// We want to flip phase of |11...1> state after X transformation (which corresponds to |00...0> original)
|
|
1405
|
+
// Target is last qubit, controls are 0 to n-2
|
|
1406
|
+
const diffControls = [];
|
|
1407
|
+
for (let i = 0; i < n - 1; i++)
|
|
1408
|
+
diffControls.push(i);
|
|
1409
|
+
muGate(reg, 'Z', n - 1, diffControls);
|
|
1410
|
+
// 4. Uncompute X
|
|
1411
|
+
for (let i = 0; i < n; i++)
|
|
1412
|
+
muGate(reg, 'X', i);
|
|
1413
|
+
// 5. Uncompute H
|
|
1414
|
+
for (let i = 0; i < n; i++)
|
|
1415
|
+
muGate(reg, 'H', i);
|
|
1416
|
+
}
|
|
1417
|
+
function muEntangle(reg, i, j) {
|
|
1418
|
+
muGate(reg, 'H', i);
|
|
1419
|
+
muGate(reg, 'CNOT', j, i);
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Quantum Teleportation Protocol
|
|
1423
|
+
* Transfers the state of `msgIdx` to `targetIdx` using `ancillaIdx` as a resource.
|
|
1424
|
+
* @param reg Register
|
|
1425
|
+
* @param msgIdx The qubit containing the state to teleport (Alice)
|
|
1426
|
+
* @param ancillaIdx The helper qubit (Alice's half of entanglement)
|
|
1427
|
+
* @param targetIdx The destination qubit (Bob)
|
|
1428
|
+
*/
|
|
1429
|
+
function muTeleport(reg, msgIdx, ancillaIdx, targetIdx) {
|
|
1430
|
+
// 1. Create Bell Pair (Entanglement) between Ancilla and Target
|
|
1431
|
+
// Represents the shared link between Alice and Bob
|
|
1432
|
+
muEntangle(reg, ancillaIdx, targetIdx);
|
|
1433
|
+
// 2. Bell Measurement on Message + Ancilla (Alice's side)
|
|
1434
|
+
muGate(reg, 'CNOT', ancillaIdx, msgIdx); // Control: msg, Target: ancilla
|
|
1435
|
+
muGate(reg, 'H', msgIdx);
|
|
1436
|
+
// 3. Measure Alice's qubits (This collapses them)
|
|
1437
|
+
const m1 = muMeasure(reg, msgIdx); // Measures "Z" component
|
|
1438
|
+
const m2 = muMeasure(reg, ancillaIdx); // Measures "X" component
|
|
1439
|
+
// 4. Classical Communication & Correction (Bob's side)
|
|
1440
|
+
// Apply corrections to Target based on measurements
|
|
1441
|
+
if (m2 === 1)
|
|
1442
|
+
muGate(reg, 'X', targetIdx);
|
|
1443
|
+
if (m1 === 1)
|
|
1444
|
+
muGate(reg, 'Z', targetIdx);
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* Measures a specific qubit in the register, collapsing the superposition.
|
|
1448
|
+
* @param reg Quantum Register
|
|
1449
|
+
* @param target Index of qubit to measure
|
|
1450
|
+
* @returns 0 or 1
|
|
1451
|
+
*/
|
|
1452
|
+
function muMeasure(reg, target = 0) {
|
|
1453
|
+
const state = reg.value;
|
|
1454
|
+
const amplitudes = state.amplitudes;
|
|
1455
|
+
let prob0 = 0;
|
|
1456
|
+
// 1. Calculate Probability of |0>
|
|
1457
|
+
for (let i = 0; i < amplitudes.length; i++) {
|
|
1458
|
+
if (((i >> target) & 1) === 0) {
|
|
1459
|
+
const a = amplitudes[i];
|
|
1460
|
+
prob0 += (a.re * a.re) + (a.im * a.im);
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
// 2. Determine Outcome
|
|
1464
|
+
const result = Math.random() < prob0 ? 0 : 1;
|
|
1465
|
+
const resultProb = result === 0 ? prob0 : (1 - prob0);
|
|
1466
|
+
const normFactor = resultProb > 0 ? (1 / Math.sqrt(resultProb)) : 0;
|
|
1467
|
+
// 3. Collapse the State (Wavefunction Collapse)
|
|
1468
|
+
const newAmps = amplitudes.map((a, i) => {
|
|
1469
|
+
const bit = (i >> target) & 1;
|
|
1470
|
+
if (bit !== result) {
|
|
1471
|
+
return { re: 0, im: 0 };
|
|
1472
|
+
}
|
|
1473
|
+
else {
|
|
1474
|
+
return { re: a.re * normFactor, im: a.im * normFactor };
|
|
1475
|
+
}
|
|
1476
|
+
});
|
|
1477
|
+
// We need to call updateState to ensure reactivity if specialized getters exist
|
|
1478
|
+
// But since this file has updateState internal, we can just call it.
|
|
1479
|
+
// However, the internal updateState function needs to be in scope.
|
|
1480
|
+
// It is defined at line 60. So we are good.
|
|
1481
|
+
updateState(reg, Object.assign(Object.assign({}, state), { amplitudes: newAmps }));
|
|
1482
|
+
return result;
|
|
1483
|
+
}
|
|
1484
|
+
/**
|
|
1485
|
+
* Quantum Loop: Parallel Execution
|
|
1486
|
+
* Applies a gate to multiple qubits "simultaneously" (in simulation steps).
|
|
1487
|
+
* Ideal for initialization (Hadamard Transform) or global operations.
|
|
1488
|
+
* @param reg Quantum Register
|
|
1489
|
+
* @param qubits Array of qubit indices
|
|
1490
|
+
* @param gate Gate type to apply (e.g. 'H', 'X')
|
|
1491
|
+
*/
|
|
1492
|
+
function muParallel(reg, qubits, gate) {
|
|
1493
|
+
if (gate === 'SWAP') {
|
|
1494
|
+
throw new Error("SWAP cannot be applied in parallel (requires pairs).");
|
|
1495
|
+
}
|
|
1496
|
+
// In a real quantum computer, these happen at t=0.
|
|
1497
|
+
// Here, we loop, but logical time is constant.
|
|
1498
|
+
qubits.forEach(q => muGate(reg, gate, q));
|
|
1499
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
* Applies a block of operations controlled by specific qubits.
|
|
1502
|
+
* Enables "Quantum If/Else".
|
|
1503
|
+
*/
|
|
1504
|
+
function muControl(reg, controlQubit, inverse, block) {
|
|
1505
|
+
// 1. Setup Context
|
|
1506
|
+
if (inverse) {
|
|
1507
|
+
muGate(reg, 'X', controlQubit); // Flip 0 to 1 to activate
|
|
1508
|
+
}
|
|
1509
|
+
activeControls.push(controlQubit);
|
|
1510
|
+
try {
|
|
1511
|
+
block();
|
|
1512
|
+
}
|
|
1513
|
+
finally {
|
|
1514
|
+
activeControls.pop();
|
|
1515
|
+
// Uncompute (Restore 0)
|
|
1516
|
+
if (inverse) {
|
|
1517
|
+
muGate(reg, 'X', controlQubit);
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
/**
|
|
1522
|
+
* Quantum Switch: conditional Logic on Superposition
|
|
1523
|
+
* Executes different logic branches based on the state of control qubits.
|
|
1524
|
+
* Because the register can be in a superposition of states (e.g. |0> + |1>),
|
|
1525
|
+
* MULTIPLE branches can execute effectively simultaneously on different subspaces.
|
|
1526
|
+
*
|
|
1527
|
+
* @param reg Quantum Register
|
|
1528
|
+
* @param controlQubit The qubit controlling the switch (Single control for v1)
|
|
1529
|
+
* @param cases Object mapping state (0 or 1) to a function executing quantum operations
|
|
1530
|
+
*/
|
|
1531
|
+
function muSwitch(reg, controlQubit, cases) {
|
|
1532
|
+
if (cases[0]) {
|
|
1533
|
+
muControl(reg, controlQubit, true, cases[0]);
|
|
1534
|
+
}
|
|
1535
|
+
if (cases[1]) {
|
|
1536
|
+
muControl(reg, controlQubit, false, cases[1]);
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
;// ./src/core/surge.ts
|
|
1541
|
+
/**
|
|
1542
|
+
* muBurst - Adaptive Non-blocking Iterator
|
|
1543
|
+
* Processes large arrays in batches within a frame budget (typically 8-16ms)
|
|
1544
|
+
* to keep the UI responsive while executing at near-native loop speeds.
|
|
1545
|
+
*/
|
|
1546
|
+
function muBurst(array, callback, options = {}) {
|
|
1547
|
+
const { chunkSize = 1000, timeout = 8, onProgress } = options;
|
|
1548
|
+
return new Promise((resolve) => {
|
|
1549
|
+
let index = 0;
|
|
1550
|
+
const total = array.length;
|
|
1551
|
+
function process() {
|
|
1552
|
+
const start = performance.now();
|
|
1553
|
+
// Tight loop for high-speed processing
|
|
1554
|
+
while (index < total && (performance.now() - start) < timeout) {
|
|
1555
|
+
// Process in smaller bursts to allow more frequent time checks if needed
|
|
1556
|
+
const endBurst = Math.min(index + chunkSize, total);
|
|
1557
|
+
for (; index < endBurst; index++) {
|
|
1558
|
+
callback(array[index], index);
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
if (onProgress) {
|
|
1562
|
+
onProgress((index / total) * 100);
|
|
1563
|
+
}
|
|
1564
|
+
if (index < total) {
|
|
1565
|
+
requestAnimationFrame(process);
|
|
1566
|
+
}
|
|
1567
|
+
else {
|
|
1568
|
+
resolve();
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
process();
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
/**
|
|
1575
|
+
* muSurge - Truly Parallel Execution
|
|
1576
|
+
* Distributes work across CPU cores using Web Workers.
|
|
1577
|
+
* Logic must be serializable.
|
|
1578
|
+
*/
|
|
1579
|
+
function muSurge(array, taskFn, onProgress) {
|
|
1580
|
+
const n = navigator.hardwareConcurrency || 4;
|
|
1581
|
+
const chunkSize = Math.ceil(array.length / n);
|
|
1582
|
+
const results = new Array(array.length);
|
|
1583
|
+
let completedChunks = 0;
|
|
1584
|
+
let completedItems = 0;
|
|
1585
|
+
// Convert function to string if it isn't already
|
|
1586
|
+
const fnStr = typeof taskFn === 'function' ? taskFn.toString() : taskFn;
|
|
1587
|
+
const workerPart1 = `const taskFn = ${fnStr};`;
|
|
1588
|
+
const workerPart2 = `self.onmessage = function(e) {`;
|
|
1589
|
+
const workerPart3 = ` const { chunk, startIndex } = e.data;`;
|
|
1590
|
+
const workerPart4 = ` try { const results = chunk.map(taskFn); self.postMessage({ results, startIndex }); }`;
|
|
1591
|
+
const workerPart5 = ` catch (err) { self.postMessage({ error: err.message, startIndex }); }`;
|
|
1592
|
+
const workerPart6 = `};`;
|
|
1593
|
+
const workerCode = [workerPart1, workerPart2, workerPart3, workerPart4, workerPart5, workerPart6].join('\n');
|
|
1594
|
+
const blob = new Blob([workerCode], { type: 'application/javascript' });
|
|
1595
|
+
const workerUrl = URL.createObjectURL(blob);
|
|
1596
|
+
return new Promise((resolve) => {
|
|
1597
|
+
if (array.length === 0)
|
|
1598
|
+
return resolve([]);
|
|
1599
|
+
for (let i = 0; i < n; i++) {
|
|
1600
|
+
const start = i * chunkSize;
|
|
1601
|
+
const end = Math.min(start + chunkSize, array.length);
|
|
1602
|
+
if (start >= end) {
|
|
1603
|
+
completedChunks++;
|
|
1604
|
+
continue;
|
|
1605
|
+
}
|
|
1606
|
+
const chunk = array.slice(start, end);
|
|
1607
|
+
const worker = new Worker(workerUrl);
|
|
1608
|
+
worker.onmessage = (e) => {
|
|
1609
|
+
const { results: chunkResults, startIndex } = e.data;
|
|
1610
|
+
// Merge results back into main array
|
|
1611
|
+
for (let j = 0; j < chunkResults.length; j++) {
|
|
1612
|
+
results[startIndex + j] = chunkResults[j];
|
|
1613
|
+
}
|
|
1614
|
+
completedChunks++;
|
|
1615
|
+
completedItems += chunkResults.length;
|
|
1616
|
+
if (onProgress)
|
|
1617
|
+
onProgress((completedItems / array.length) * 100);
|
|
1618
|
+
worker.terminate();
|
|
1619
|
+
if (completedChunks === n) {
|
|
1620
|
+
URL.revokeObjectURL(workerUrl);
|
|
1621
|
+
resolve(results);
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1624
|
+
worker.postMessage({ chunk, startIndex: start, fnStr });
|
|
1625
|
+
}
|
|
1626
|
+
});
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
;// ./src/components/bloch-sphere.ts
|
|
1630
|
+
|
|
1631
|
+
class MuBlochSphereElement extends HTMLElement {
|
|
1632
|
+
static get observedAttributes() {
|
|
1633
|
+
return ['size'];
|
|
1634
|
+
}
|
|
1635
|
+
constructor() {
|
|
1636
|
+
super();
|
|
1637
|
+
this._arrow = null;
|
|
1638
|
+
this._container = null;
|
|
1639
|
+
this._disposeEffect = null;
|
|
1640
|
+
this.attachShadow({ mode: 'open' });
|
|
1641
|
+
}
|
|
1642
|
+
connectedCallback() {
|
|
1643
|
+
this.render();
|
|
1644
|
+
}
|
|
1645
|
+
disconnectedCallback() {
|
|
1646
|
+
if (this._disposeEffect) {
|
|
1647
|
+
this._disposeEffect();
|
|
1648
|
+
this._disposeEffect = null;
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
// Property setter for 'qubit' (passed as .qubit="${q}" in Mulan)
|
|
1652
|
+
set qubit(val) {
|
|
1653
|
+
this._qubit = val;
|
|
1654
|
+
this.initReactivity();
|
|
1655
|
+
}
|
|
1656
|
+
get qubit() {
|
|
1657
|
+
return this._qubit;
|
|
1658
|
+
}
|
|
1659
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
1660
|
+
if (name === 'size' && this._container) {
|
|
1661
|
+
this._container.style.width = newValue + 'px';
|
|
1662
|
+
this._container.style.height = newValue + 'px';
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
initReactivity() {
|
|
1666
|
+
if (this._disposeEffect)
|
|
1667
|
+
this._disposeEffect();
|
|
1668
|
+
if (!this._qubit)
|
|
1669
|
+
return;
|
|
1670
|
+
// MulanJS Effect: Run whenever the qubit state changes
|
|
1671
|
+
this._disposeEffect = effect(() => {
|
|
1672
|
+
const state = this._qubit.value; // Access reactive proxy
|
|
1673
|
+
if (!state || !state.amplitudes)
|
|
1674
|
+
return;
|
|
1675
|
+
// Assume Single Qubit for Visualizer (Index 0 if passed a register)
|
|
1676
|
+
// If passed a register, we visualize the first qubit's logical projection (partial trace simplified)
|
|
1677
|
+
// Or assume input IS a specific qubit projection?
|
|
1678
|
+
// For simplified demo, we assume the register is size 1 OR we visualize Q0 of the register.
|
|
1679
|
+
const amps = state.amplitudes;
|
|
1680
|
+
// Support 1-qubit visualization from N-qubit register requires partial trace.
|
|
1681
|
+
// For now, let's assume the user passes a 1-qubit register OR we visualize index 0.
|
|
1682
|
+
// |psi> = a|0> + b|1>
|
|
1683
|
+
// a = amps[0] (re, im)
|
|
1684
|
+
// b = amps[1] (re, im)
|
|
1685
|
+
// Dealing with multi-qubit registers (naive projection for visualization):
|
|
1686
|
+
// We sum up probabilities for 0xxxx vs 1xxxx to get Z-axis.
|
|
1687
|
+
// This is "marginal probability".
|
|
1688
|
+
let p0 = 0;
|
|
1689
|
+
let p1 = 0;
|
|
1690
|
+
// Calculate Probabilities
|
|
1691
|
+
for (let i = 0; i < amps.length; i++) {
|
|
1692
|
+
const mag = amps[i].re * amps[i].re + amps[i].im * amps[i].im;
|
|
1693
|
+
if ((i & 1) === 0)
|
|
1694
|
+
p0 += mag;
|
|
1695
|
+
else
|
|
1696
|
+
p1 += mag;
|
|
1697
|
+
}
|
|
1698
|
+
// Theta from Z-projection
|
|
1699
|
+
// P0 = cos^2(theta/2) -> theta = 2 * acos(sqrt(P0))
|
|
1700
|
+
const theta = 2 * Math.acos(Math.min(1, Math.sqrt(p0)));
|
|
1701
|
+
// Phi?
|
|
1702
|
+
// Phase is relative phase between |0> and |1>.
|
|
1703
|
+
// We can look at the phase of the '1' component relative to '0'.
|
|
1704
|
+
// Simple approach: Look at amps[1] phase vs amps[0] phase.
|
|
1705
|
+
// But with entanglement, pure state phase is tricky.
|
|
1706
|
+
// Let's implement full density matrix if needed, but for now:
|
|
1707
|
+
// naive: atan2(amps[1].im, amps[1].re) - atan2(amps[0].im, amps[0].re)
|
|
1708
|
+
// We use the first pair (0 and 1) as proxy if multiple.
|
|
1709
|
+
const a0 = amps[0];
|
|
1710
|
+
const a1 = amps[1]; // Valid for N>=1
|
|
1711
|
+
const phase0 = Math.atan2(a0.im, a0.re);
|
|
1712
|
+
const phase1 = Math.atan2(a1.im, a1.re);
|
|
1713
|
+
let phi = phase1 - phase0;
|
|
1714
|
+
// Update Arrow
|
|
1715
|
+
this.updateArrow(theta, phi);
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
updateArrow(theta, phi) {
|
|
1719
|
+
if (!this._arrow)
|
|
1720
|
+
return;
|
|
1721
|
+
// Convert Quantum Coords (Theta, Phi) to CSS Transforms
|
|
1722
|
+
// Theta 0 = Top (|0>)
|
|
1723
|
+
// Theta PI = Bottom (|1>)
|
|
1724
|
+
// Theta PI/2 = Equator
|
|
1725
|
+
// CSS Rotate sequence:
|
|
1726
|
+
// 1. Start pointing UP (Y or Z axis in CSS?)
|
|
1727
|
+
// Let's say Arrow starts pointing UP (Y-).
|
|
1728
|
+
// Rotate Z by Phi (Azimuth)
|
|
1729
|
+
// Rotate X by Theta (Polar) - No, that's not standard Euler.
|
|
1730
|
+
// Standard Physics:
|
|
1731
|
+
// Z is Up (in Bloch), but CSS 3D Y is usually 'Down' or 'Up'.
|
|
1732
|
+
// Let's Map:
|
|
1733
|
+
// Bloch Z+ (|0>) -> CSS Y- (Top)
|
|
1734
|
+
// Bloch Z- (|1>) -> CSS Y+ (Bottom)
|
|
1735
|
+
// Bloch X+ (|+>) -> CSS Z+ (Front)
|
|
1736
|
+
// Transform:
|
|
1737
|
+
// rotateY(phi) ? No, phi rotates around Z-axis (Vertical).
|
|
1738
|
+
// theta rotates from Z-axis down.
|
|
1739
|
+
// CSS:
|
|
1740
|
+
// rotateY(phi) -> Rotates around Vertical axis.
|
|
1741
|
+
// rotateZ(theta) -> Rotates "down" from up?
|
|
1742
|
+
// Let's simplify:
|
|
1743
|
+
// transform: rotateY(${phi}rad) rotateZ(${theta}rad)
|
|
1744
|
+
// Note: CSS rotations order matters.
|
|
1745
|
+
const degTheta = theta * (180 / Math.PI);
|
|
1746
|
+
const degPhi = phi * (180 / Math.PI);
|
|
1747
|
+
// Adjustment for visual alignment
|
|
1748
|
+
this._arrow.style.transform = `rotateY(${degPhi}deg) rotateZ(${degTheta}deg)`;
|
|
1749
|
+
// Color based on state
|
|
1750
|
+
const isSuperposition = Math.abs(theta - Math.PI / 2) < 0.1;
|
|
1751
|
+
this._arrow.style.backgroundColor = isSuperposition ? '#00ffff' : '#ff00ff';
|
|
1752
|
+
}
|
|
1753
|
+
render() {
|
|
1754
|
+
if (!this.shadowRoot)
|
|
1755
|
+
return;
|
|
1756
|
+
const size = this.getAttribute('size') || '200';
|
|
1757
|
+
this.shadowRoot.innerHTML = `
|
|
1758
|
+
<style>
|
|
1759
|
+
:host {
|
|
1760
|
+
display: inline-block;
|
|
1761
|
+
perspective: 1000px;
|
|
1762
|
+
}
|
|
1763
|
+
.sphere-container {
|
|
1764
|
+
width: ${size}px;
|
|
1765
|
+
height: ${size}px;
|
|
1766
|
+
position: relative;
|
|
1767
|
+
transform-style: preserve-3d;
|
|
1768
|
+
margin: 0 auto;
|
|
1769
|
+
}
|
|
1770
|
+
.sphere {
|
|
1771
|
+
width: 100%;
|
|
1772
|
+
height: 100%;
|
|
1773
|
+
border-radius: 50%;
|
|
1774
|
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
1775
|
+
position: absolute;
|
|
1776
|
+
background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.1), rgba(0, 0, 0, 0.8));
|
|
1777
|
+
box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.05);
|
|
1778
|
+
transform: rotateX(15deg) rotateY(15deg); /* Initial tilt for view */
|
|
1779
|
+
}
|
|
1780
|
+
/* Equator Ring */
|
|
1781
|
+
.equator {
|
|
1782
|
+
position: absolute;
|
|
1783
|
+
top: 50%;
|
|
1784
|
+
left: 0;
|
|
1785
|
+
width: 100%;
|
|
1786
|
+
height: 100%;
|
|
1787
|
+
border: 1px dashed rgba(255, 255, 255, 0.3);
|
|
1788
|
+
border-radius: 50%;
|
|
1789
|
+
transform: rotateX(90deg);
|
|
1790
|
+
pointer-events: none;
|
|
1791
|
+
}
|
|
1792
|
+
/* Axis Lines */
|
|
1793
|
+
.axis {
|
|
1794
|
+
position: absolute;
|
|
1795
|
+
background: rgba(255, 255, 255, 0.1);
|
|
1796
|
+
}
|
|
1797
|
+
.z-axis { width: 2px; height: 100%; left: 50%; top: 0; }
|
|
1798
|
+
|
|
1799
|
+
/* The Quantum Arrow */
|
|
1800
|
+
.arrow-container {
|
|
1801
|
+
position: absolute;
|
|
1802
|
+
top: 50%;
|
|
1803
|
+
left: 50%;
|
|
1804
|
+
width: 0;
|
|
1805
|
+
height: 0;
|
|
1806
|
+
transform-style: preserve-3d;
|
|
1807
|
+
transform: rotateX(15deg) rotateY(15deg); /* Match sphere tilt */
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
.arrow-pivot {
|
|
1811
|
+
position: absolute;
|
|
1812
|
+
top: 0;
|
|
1813
|
+
left: 0;
|
|
1814
|
+
width: 4px;
|
|
1815
|
+
height: 50%; /* Length of radius */
|
|
1816
|
+
/* Pivot logic: we want to rotate around the center point */
|
|
1817
|
+
/* CSS Default transform-origin is 50% 50% */
|
|
1818
|
+
/* We construct the arrow such that it points UP from center */
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
.arrow-rod {
|
|
1822
|
+
width: 4px;
|
|
1823
|
+
height: ${parseInt(size) / 2 - 10}px;
|
|
1824
|
+
background: #ff00ff;
|
|
1825
|
+
position: absolute;
|
|
1826
|
+
bottom: 0;
|
|
1827
|
+
left: -2px;
|
|
1828
|
+
transform-origin: bottom center;
|
|
1829
|
+
transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), background-color 0.3s;
|
|
1830
|
+
border-radius: 2px;
|
|
1831
|
+
box-shadow: 0 0 10px currentColor;
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
.arrow-head {
|
|
1835
|
+
width: 0;
|
|
1836
|
+
height: 0;
|
|
1837
|
+
border-left: 6px solid transparent;
|
|
1838
|
+
border-right: 6px solid transparent;
|
|
1839
|
+
border-bottom: 12px solid #ff00ff;
|
|
1840
|
+
position: absolute;
|
|
1841
|
+
top: -10px;
|
|
1842
|
+
left: -6px;
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
.label {
|
|
1846
|
+
position: absolute;
|
|
1847
|
+
color: #aaa;
|
|
1848
|
+
font-family: monospace;
|
|
1849
|
+
font-size: 10px;
|
|
1850
|
+
}
|
|
1851
|
+
.label-0 { top: 5px; left: 50%; transform: translateX(-50%); }
|
|
1852
|
+
.label-1 { bottom: 5px; left: 50%; transform: translateX(-50%); }
|
|
1853
|
+
</style>
|
|
1854
|
+
|
|
1855
|
+
<div class="sphere-container">
|
|
1856
|
+
<div class="sphere">
|
|
1857
|
+
<div class="equator"></div>
|
|
1858
|
+
<div class="axis z-axis"></div>
|
|
1859
|
+
<div class="label label-0">|0></div>
|
|
1860
|
+
<div class="label label-1">|1></div>
|
|
1861
|
+
</div>
|
|
1862
|
+
|
|
1863
|
+
<div class="arrow-container">
|
|
1864
|
+
<!-- The rod is the actual rotating element -->
|
|
1865
|
+
<div class="arrow-rod">
|
|
1866
|
+
<div class="arrow-head"></div>
|
|
1867
|
+
</div>
|
|
1868
|
+
</div>
|
|
1869
|
+
</div>
|
|
1870
|
+
`;
|
|
1871
|
+
this._container = this.shadowRoot.querySelector('.sphere-container');
|
|
1872
|
+
this._arrow = this.shadowRoot.querySelector('.arrow-rod');
|
|
1873
|
+
// Re-init reactivity if qubit was set before render
|
|
1874
|
+
if (this._qubit)
|
|
1875
|
+
this.initReactivity();
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
// Register the custom element
|
|
1879
|
+
if (typeof customElements !== 'undefined') {
|
|
1880
|
+
customElements.define('mu-bloch-sphere', MuBlochSphereElement);
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
;// ./src/components/infinity-list.ts
|
|
1884
|
+
class MuInfinity extends HTMLElement {
|
|
1885
|
+
constructor() {
|
|
1886
|
+
super();
|
|
1887
|
+
this._items = [];
|
|
1888
|
+
this._itemHeight = 50; // Default height
|
|
1889
|
+
this._template = '';
|
|
1890
|
+
this.attachShadow({ mode: 'open' });
|
|
1891
|
+
// Structure:
|
|
1892
|
+
// :host { overflow-y: auto; display: block; height: 100%; }
|
|
1893
|
+
// .spacer { height: totalHeight; position: relative; }
|
|
1894
|
+
// .content { position: absolute; top: padding; width: 100%; }
|
|
1895
|
+
this.shadowRoot.innerHTML = `
|
|
1896
|
+
<style>
|
|
1897
|
+
:host {
|
|
1898
|
+
display: block;
|
|
1899
|
+
overflow-y: auto;
|
|
1900
|
+
height: 100%;
|
|
1901
|
+
position: relative;
|
|
1902
|
+
}
|
|
1903
|
+
.spacer {
|
|
1904
|
+
position: relative;
|
|
1905
|
+
width: 100%;
|
|
1906
|
+
}
|
|
1907
|
+
.content {
|
|
1908
|
+
position: absolute;
|
|
1909
|
+
top: 0;
|
|
1910
|
+
left: 0;
|
|
1911
|
+
width: 100%;
|
|
1912
|
+
}
|
|
1913
|
+
</style>
|
|
1914
|
+
<div class="spacer">
|
|
1915
|
+
<div class="content"></div>
|
|
1916
|
+
</div>
|
|
1917
|
+
`;
|
|
1918
|
+
this.container = this.shadowRoot.host; // The host itself scrolls
|
|
1919
|
+
this.spacer = this.shadowRoot.querySelector('.spacer');
|
|
1920
|
+
this.content = this.shadowRoot.querySelector('.content');
|
|
1921
|
+
this.onScroll = this.onScroll.bind(this);
|
|
1922
|
+
}
|
|
1923
|
+
static get observedAttributes() {
|
|
1924
|
+
return ['item-height'];
|
|
1930
1925
|
}
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
if (typeof window !== 'undefined' && !customElements.get('mu-link')) {
|
|
1936
|
-
class MuLink extends HTMLElement {
|
|
1937
|
-
constructor() {
|
|
1938
|
-
super();
|
|
1939
|
-
this.addEventListener('click', (e) => {
|
|
1940
|
-
e.preventDefault();
|
|
1941
|
-
const to = this.getAttribute('to');
|
|
1942
|
-
if (to) {
|
|
1943
|
-
// Update Hash for SPA Navigation
|
|
1944
|
-
window.location.hash = to;
|
|
1945
|
-
}
|
|
1946
|
-
});
|
|
1947
|
-
// [Chronos] Intelligent Pre-fetching
|
|
1948
|
-
this.addEventListener('mouseenter', () => {
|
|
1949
|
-
const to = this.getAttribute('to');
|
|
1950
|
-
if (to) {
|
|
1951
|
-
const router = window.__MULAN_ROUTER__;
|
|
1952
|
-
if (router && typeof router.prefetch === 'function') {
|
|
1953
|
-
router.prefetch(to);
|
|
1954
|
-
}
|
|
1955
|
-
}
|
|
1956
|
-
});
|
|
1957
|
-
// [Chronos] Also prefetch on focus for keyboard users
|
|
1958
|
-
this.addEventListener('focus', () => {
|
|
1959
|
-
const to = this.getAttribute('to');
|
|
1960
|
-
if (to) {
|
|
1961
|
-
const router = window.__MULAN_ROUTER__;
|
|
1962
|
-
if (router && typeof router.prefetch === 'function') {
|
|
1963
|
-
router.prefetch(to);
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
});
|
|
1967
|
-
}
|
|
1968
|
-
connectedCallback() {
|
|
1969
|
-
this.style.cursor = 'pointer';
|
|
1970
|
-
this.style.color = 'var(--primary, #9C27B0)'; // Default to brand color if available
|
|
1971
|
-
this.style.textDecoration = 'none';
|
|
1926
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
1927
|
+
if (name === 'item-height') {
|
|
1928
|
+
this._itemHeight = parseInt(newValue, 10) || 50;
|
|
1929
|
+
this.renderVisible();
|
|
1972
1930
|
}
|
|
1973
|
-
static get observedAttributes() { return ['to']; }
|
|
1974
1931
|
}
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
\***********************************/
|
|
1985
|
-
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
1986
|
-
|
|
1987
|
-
__webpack_require__.r(__webpack_exports__);
|
|
1988
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1989
|
-
/* harmony export */ Security: () => (/* binding */ Security)
|
|
1990
|
-
/* harmony export */ });
|
|
1991
|
-
class Security {
|
|
1992
|
-
/**
|
|
1993
|
-
* IRON FORTRESS PROTOCOL
|
|
1994
|
-
* Strictly escapes all HTML entities to prevent XSS.
|
|
1995
|
-
* Use `mu-raw` attribute in templates to bypass this for trusted content.
|
|
1996
|
-
*/
|
|
1997
|
-
static sanitize(input) {
|
|
1998
|
-
// 1. Basic entity encoding
|
|
1999
|
-
let secure = input
|
|
2000
|
-
.replace(/&/g, "&")
|
|
2001
|
-
.replace(/</g, "<")
|
|
2002
|
-
.replace(/>/g, ">")
|
|
2003
|
-
.replace(/"/g, """)
|
|
2004
|
-
.replace(/'/g, "'");
|
|
2005
|
-
// 2. Remove dangerous events (extra layer if encoding fails)
|
|
2006
|
-
const dangerousEvents = ['onload', 'onclick', 'onerror', 'onmouseover', 'onfocus'];
|
|
2007
|
-
dangerousEvents.forEach(event => {
|
|
2008
|
-
const regex = new RegExp(event, 'gi');
|
|
2009
|
-
secure = secure.replace(regex, 'data-blocked-' + event);
|
|
2010
|
-
});
|
|
2011
|
-
return secure;
|
|
1932
|
+
connectedCallback() {
|
|
1933
|
+
// Find the template provided by the user (Support both standard and branded tags)
|
|
1934
|
+
const templateTag = this.querySelector('template') || this.querySelector('mu-template');
|
|
1935
|
+
if (templateTag) {
|
|
1936
|
+
this._template = templateTag.innerHTML;
|
|
1937
|
+
}
|
|
1938
|
+
this.addEventListener('scroll', this.onScroll);
|
|
1939
|
+
// Wait for next frame to get initial height if not set
|
|
1940
|
+
requestAnimationFrame(() => this.renderVisible());
|
|
2012
1941
|
}
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
* @param options Configuration for allowed sources
|
|
2016
|
-
*/
|
|
2017
|
-
static generateCSP(options = {}) {
|
|
2018
|
-
const scriptSrc = ["'self'", ...(options.scriptSrc || [])].join(" ");
|
|
2019
|
-
const styleSrc = ["'self'", "'unsafe-inline'", ...(options.styleSrc || [])].join(" ");
|
|
2020
|
-
return `default-src 'self'; script-src ${scriptSrc}; style-src ${styleSrc}; object-src 'none'; base-uri 'self';`;
|
|
1942
|
+
disconnectedCallback() {
|
|
1943
|
+
this.removeEventListener('scroll', this.onScroll);
|
|
2021
1944
|
}
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
|
|
2026
|
-
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
|
|
2027
|
-
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
|
|
2028
|
-
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
|
2029
|
-
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
|
|
2030
|
-
return !!pattern.test(url);
|
|
1945
|
+
set items(value) {
|
|
1946
|
+
this._items = value;
|
|
1947
|
+
this.renderVisible();
|
|
2031
1948
|
}
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
*/
|
|
2036
|
-
static preventXSS(inputElement) {
|
|
2037
|
-
inputElement.addEventListener('blur', (e) => {
|
|
2038
|
-
const target = e.target;
|
|
2039
|
-
target.value = Security.sanitize(target.value);
|
|
2040
|
-
});
|
|
1949
|
+
get items() { return this._items; }
|
|
1950
|
+
onScroll() {
|
|
1951
|
+
requestAnimationFrame(() => this.renderVisible());
|
|
2041
1952
|
}
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
}
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
console.error("Failed to load state", e);
|
|
1953
|
+
renderVisible() {
|
|
1954
|
+
if (!this._items.length)
|
|
1955
|
+
return;
|
|
1956
|
+
const scrollTop = this.scrollTop;
|
|
1957
|
+
const hostHeight = this.clientHeight || 400; // Default fallback if not sized
|
|
1958
|
+
const totalHeight = this._items.length * this._itemHeight;
|
|
1959
|
+
this.spacer.style.height = `${totalHeight}px`;
|
|
1960
|
+
// Windowing Math
|
|
1961
|
+
const startIndex = Math.floor(scrollTop / this._itemHeight);
|
|
1962
|
+
const buffer = 5;
|
|
1963
|
+
const visibleCount = Math.ceil(hostHeight / this._itemHeight);
|
|
1964
|
+
const renderStart = Math.max(0, startIndex - buffer);
|
|
1965
|
+
const renderEnd = Math.min(this._items.length, startIndex + visibleCount + buffer);
|
|
1966
|
+
const startOffset = renderStart * this._itemHeight;
|
|
1967
|
+
this.content.style.transform = `translateY(${startOffset}px)`;
|
|
1968
|
+
// Render specific slice
|
|
1969
|
+
const visibleItems = this._items.slice(renderStart, renderEnd);
|
|
1970
|
+
// Simple string replacement template engine for the demo
|
|
1971
|
+
// In a real Mulan compilation, this would be an optimized ASTR render
|
|
1972
|
+
let html = '';
|
|
1973
|
+
visibleItems.forEach((item, index) => {
|
|
1974
|
+
const absoluteIndex = renderStart + index;
|
|
1975
|
+
// Basic mustache replacement {{ item.prop }}
|
|
1976
|
+
let rowHtml = this._template
|
|
1977
|
+
.replace(/{{\s*item\s*}}/g, String(item)) // {{ item }}
|
|
1978
|
+
.replace(/{{\s*index\s*}}/g, String(absoluteIndex)); // {{ index }}
|
|
1979
|
+
// Handle object properties: {{ item.name }}
|
|
1980
|
+
if (typeof item === 'object' && item !== null) {
|
|
1981
|
+
rowHtml = rowHtml.replace(/{{\s*item\.(\w+)\s*}}/g, (_, prop) => {
|
|
1982
|
+
return String(item[prop] || '');
|
|
1983
|
+
});
|
|
2074
1984
|
}
|
|
2075
|
-
|
|
2076
|
-
(0,_core_reactive__WEBPACK_IMPORTED_MODULE_0__.effect)(() => {
|
|
2077
|
-
localStorage.setItem(key, JSON.stringify(this.state));
|
|
2078
|
-
});
|
|
2079
|
-
}
|
|
2080
|
-
this.state = (0,_core_reactive__WEBPACK_IMPORTED_MODULE_0__.reactive)(loadedState);
|
|
2081
|
-
}
|
|
2082
|
-
// Subscribe to changes
|
|
2083
|
-
subscribe(fn) {
|
|
2084
|
-
this.subscribers.push(fn);
|
|
2085
|
-
(0,_core_reactive__WEBPACK_IMPORTED_MODULE_0__.effect)(() => {
|
|
2086
|
-
fn(this.state);
|
|
1985
|
+
html += `<div style="height: ${this._itemHeight}px; overflow: hidden;">${rowHtml}</div>`;
|
|
2087
1986
|
});
|
|
2088
|
-
|
|
2089
|
-
// Action dispatcher pattern
|
|
2090
|
-
dispatch(action) {
|
|
2091
|
-
const result = action(this.state);
|
|
2092
|
-
if (result instanceof Promise) {
|
|
2093
|
-
result.then(() => {
|
|
2094
|
-
// Optional: Notify subscribers of async completion if needed manually?
|
|
2095
|
-
// But reactive() handles updates automatically.
|
|
2096
|
-
});
|
|
2097
|
-
}
|
|
1987
|
+
this.content.innerHTML = html;
|
|
2098
1988
|
}
|
|
2099
1989
|
}
|
|
1990
|
+
// Register
|
|
1991
|
+
if (typeof customElements !== 'undefined' && !customElements.get('mu-infinity')) {
|
|
1992
|
+
customElements.define('mu-infinity', MuInfinity);
|
|
1993
|
+
}
|
|
2100
1994
|
|
|
2101
|
-
|
|
2102
|
-
/***/ }
|
|
2103
|
-
|
|
2104
|
-
/******/ });
|
|
2105
|
-
/************************************************************************/
|
|
2106
|
-
/******/ // The module cache
|
|
2107
|
-
/******/ var __webpack_module_cache__ = {};
|
|
2108
|
-
/******/
|
|
2109
|
-
/******/ // The require function
|
|
2110
|
-
/******/ function __webpack_require__(moduleId) {
|
|
2111
|
-
/******/ // Check if module is in cache
|
|
2112
|
-
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
2113
|
-
/******/ if (cachedModule !== undefined) {
|
|
2114
|
-
/******/ return cachedModule.exports;
|
|
2115
|
-
/******/ }
|
|
2116
|
-
/******/ // Check if module exists (development only)
|
|
2117
|
-
/******/ if (__webpack_modules__[moduleId] === undefined) {
|
|
2118
|
-
/******/ var e = new Error("Cannot find module '" + moduleId + "'");
|
|
2119
|
-
/******/ e.code = 'MODULE_NOT_FOUND';
|
|
2120
|
-
/******/ throw e;
|
|
2121
|
-
/******/ }
|
|
2122
|
-
/******/ // Create a new module (and put it into the cache)
|
|
2123
|
-
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
2124
|
-
/******/ // no module.id needed
|
|
2125
|
-
/******/ // no module.loaded needed
|
|
2126
|
-
/******/ exports: {}
|
|
2127
|
-
/******/ };
|
|
2128
|
-
/******/
|
|
2129
|
-
/******/ // Execute the module function
|
|
2130
|
-
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
2131
|
-
/******/
|
|
2132
|
-
/******/ // Return the exports of the module
|
|
2133
|
-
/******/ return module.exports;
|
|
2134
|
-
/******/ }
|
|
2135
|
-
/******/
|
|
2136
|
-
/************************************************************************/
|
|
2137
|
-
/******/ /* webpack/runtime/define property getters */
|
|
2138
|
-
/******/ (() => {
|
|
2139
|
-
/******/ // define getter functions for harmony exports
|
|
2140
|
-
/******/ __webpack_require__.d = (exports, definition) => {
|
|
2141
|
-
/******/ for(var key in definition) {
|
|
2142
|
-
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
2143
|
-
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
2144
|
-
/******/ }
|
|
2145
|
-
/******/ }
|
|
2146
|
-
/******/ };
|
|
2147
|
-
/******/ })();
|
|
2148
|
-
/******/
|
|
2149
|
-
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
2150
|
-
/******/ (() => {
|
|
2151
|
-
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
2152
|
-
/******/ })();
|
|
2153
|
-
/******/
|
|
2154
|
-
/******/ /* webpack/runtime/make namespace object */
|
|
2155
|
-
/******/ (() => {
|
|
2156
|
-
/******/ // define __esModule on exports
|
|
2157
|
-
/******/ __webpack_require__.r = (exports) => {
|
|
2158
|
-
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
2159
|
-
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2160
|
-
/******/ }
|
|
2161
|
-
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
2162
|
-
/******/ };
|
|
2163
|
-
/******/ })();
|
|
2164
|
-
/******/
|
|
2165
|
-
/************************************************************************/
|
|
2166
|
-
var __webpack_exports__ = {};
|
|
2167
|
-
// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
|
|
2168
|
-
(() => {
|
|
2169
|
-
/*!**********************!*\
|
|
2170
|
-
!*** ./src/index.ts ***!
|
|
2171
|
-
\**********************/
|
|
2172
|
-
__webpack_require__.r(__webpack_exports__);
|
|
2173
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
2174
|
-
/* harmony export */ Component: () => (/* reexport safe */ _core_component__WEBPACK_IMPORTED_MODULE_1__.MuComponent),
|
|
2175
|
-
/* harmony export */ MuBlochSphereElement: () => (/* reexport safe */ _components_bloch_sphere__WEBPACK_IMPORTED_MODULE_11__.MuBlochSphereElement),
|
|
2176
|
-
/* harmony export */ MuComponent: () => (/* reexport safe */ _core_component__WEBPACK_IMPORTED_MODULE_1__.MuComponent),
|
|
2177
|
-
/* harmony export */ MuInfinity: () => (/* reexport safe */ _components_infinity_list__WEBPACK_IMPORTED_MODULE_12__.MuInfinity),
|
|
2178
|
-
/* harmony export */ MuRouter: () => (/* reexport safe */ _router_index__WEBPACK_IMPORTED_MODULE_3__.MuRouter),
|
|
2179
|
-
/* harmony export */ MuStore: () => (/* reexport safe */ _store_index__WEBPACK_IMPORTED_MODULE_4__.MuStore),
|
|
2180
|
-
/* harmony export */ Router: () => (/* reexport safe */ _router_index__WEBPACK_IMPORTED_MODULE_3__.MuRouter),
|
|
2181
|
-
/* harmony export */ Security: () => (/* reexport safe */ _security_sanitizer__WEBPACK_IMPORTED_MODULE_5__.Security),
|
|
2182
|
-
/* harmony export */ Signal: () => (/* reexport safe */ _core_reactive__WEBPACK_IMPORTED_MODULE_0__.Signal),
|
|
2183
|
-
/* harmony export */ activeControls: () => (/* reexport safe */ _core_quantum__WEBPACK_IMPORTED_MODULE_9__.activeControls),
|
|
2184
|
-
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__),
|
|
2185
|
-
/* harmony export */ defineComponent: () => (/* reexport safe */ _core_component__WEBPACK_IMPORTED_MODULE_1__.defineComponent),
|
|
2186
|
-
/* harmony export */ effect: () => (/* reexport safe */ _core_reactive__WEBPACK_IMPORTED_MODULE_0__.effect),
|
|
2187
|
-
/* harmony export */ getCurrentInstance: () => (/* reexport safe */ _core_hooks__WEBPACK_IMPORTED_MODULE_6__.getCurrentInstance),
|
|
2188
|
-
/* harmony export */ hydrate: () => (/* reexport safe */ _core_renderer__WEBPACK_IMPORTED_MODULE_2__.hydrate),
|
|
2189
|
-
/* harmony export */ muBurst: () => (/* reexport safe */ _core_surge__WEBPACK_IMPORTED_MODULE_10__.muBurst),
|
|
2190
|
-
/* harmony export */ muControl: () => (/* reexport safe */ _core_quantum__WEBPACK_IMPORTED_MODULE_9__.muControl),
|
|
2191
|
-
/* harmony export */ muEffect: () => (/* reexport safe */ _core_hooks__WEBPACK_IMPORTED_MODULE_6__.muEffect),
|
|
2192
|
-
/* harmony export */ muEntangle: () => (/* reexport safe */ _core_quantum__WEBPACK_IMPORTED_MODULE_9__.muEntangle),
|
|
2193
|
-
/* harmony export */ muGate: () => (/* reexport safe */ _core_quantum__WEBPACK_IMPORTED_MODULE_9__.muGate),
|
|
2194
|
-
/* harmony export */ muGeom: () => (/* reexport safe */ _core_hooks__WEBPACK_IMPORTED_MODULE_6__.muGeom),
|
|
2195
|
-
/* harmony export */ muMeasure: () => (/* reexport safe */ _core_quantum__WEBPACK_IMPORTED_MODULE_9__.muMeasure),
|
|
2196
|
-
/* harmony export */ muMemo: () => (/* reexport safe */ _core_hooks__WEBPACK_IMPORTED_MODULE_6__.muMemo),
|
|
2197
|
-
/* harmony export */ muParallel: () => (/* reexport safe */ _core_quantum__WEBPACK_IMPORTED_MODULE_9__.muParallel),
|
|
2198
|
-
/* harmony export */ muPulse: () => (/* reexport safe */ _core_hooks__WEBPACK_IMPORTED_MODULE_6__.muPulse),
|
|
2199
|
-
/* harmony export */ muQubit: () => (/* reexport safe */ _core_quantum__WEBPACK_IMPORTED_MODULE_9__.muQubit),
|
|
2200
|
-
/* harmony export */ muRegister: () => (/* reexport safe */ _core_quantum__WEBPACK_IMPORTED_MODULE_9__.muRegister),
|
|
2201
|
-
/* harmony export */ muSearch: () => (/* reexport safe */ _core_quantum__WEBPACK_IMPORTED_MODULE_9__.muSearch),
|
|
2202
|
-
/* harmony export */ muState: () => (/* reexport safe */ _core_hooks__WEBPACK_IMPORTED_MODULE_6__.muState),
|
|
2203
|
-
/* harmony export */ muSurge: () => (/* reexport safe */ _core_surge__WEBPACK_IMPORTED_MODULE_10__.muSurge),
|
|
2204
|
-
/* harmony export */ muSwitch: () => (/* reexport safe */ _core_quantum__WEBPACK_IMPORTED_MODULE_9__.muSwitch),
|
|
2205
|
-
/* harmony export */ muTeleport: () => (/* reexport safe */ _core_quantum__WEBPACK_IMPORTED_MODULE_9__.muTeleport),
|
|
2206
|
-
/* harmony export */ muVault: () => (/* reexport safe */ _core_hooks__WEBPACK_IMPORTED_MODULE_6__.muVault),
|
|
2207
|
-
/* harmony export */ onMuDestroy: () => (/* reexport safe */ _core_hooks__WEBPACK_IMPORTED_MODULE_6__.onMuDestroy),
|
|
2208
|
-
/* harmony export */ onMuIdle: () => (/* reexport safe */ _core_hooks__WEBPACK_IMPORTED_MODULE_6__.onMuIdle),
|
|
2209
|
-
/* harmony export */ onMuInit: () => (/* reexport safe */ _core_hooks__WEBPACK_IMPORTED_MODULE_6__.onMuInit),
|
|
2210
|
-
/* harmony export */ onMuMount: () => (/* reexport safe */ _core_hooks__WEBPACK_IMPORTED_MODULE_6__.onMuMount),
|
|
2211
|
-
/* harmony export */ onMuResume: () => (/* reexport safe */ _core_hooks__WEBPACK_IMPORTED_MODULE_6__.onMuResume),
|
|
2212
|
-
/* harmony export */ onMuShake: () => (/* reexport safe */ _core_hooks__WEBPACK_IMPORTED_MODULE_6__.onMuShake),
|
|
2213
|
-
/* harmony export */ onMuVoice: () => (/* reexport safe */ _core_hooks__WEBPACK_IMPORTED_MODULE_6__.onMuVoice),
|
|
2214
|
-
/* harmony export */ persistent: () => (/* reexport safe */ _core_vault__WEBPACK_IMPORTED_MODULE_8__.persistent),
|
|
2215
|
-
/* harmony export */ reactive: () => (/* reexport safe */ _core_reactive__WEBPACK_IMPORTED_MODULE_0__.reactive),
|
|
2216
|
-
/* harmony export */ ref: () => (/* reexport safe */ _core_reactive__WEBPACK_IMPORTED_MODULE_0__.ref),
|
|
2217
|
-
/* harmony export */ render: () => (/* reexport safe */ _core_renderer__WEBPACK_IMPORTED_MODULE_2__.render),
|
|
2218
|
-
/* harmony export */ renderToString: () => (/* reexport safe */ _core_renderer__WEBPACK_IMPORTED_MODULE_2__.renderToString),
|
|
2219
|
-
/* harmony export */ sanitize: () => (/* reexport safe */ _core_renderer__WEBPACK_IMPORTED_MODULE_2__.sanitize),
|
|
2220
|
-
/* harmony export */ setCurrentInstance: () => (/* reexport safe */ _core_hooks__WEBPACK_IMPORTED_MODULE_6__.setCurrentInstance),
|
|
2221
|
-
/* harmony export */ useMutation: () => (/* reexport safe */ _core_query__WEBPACK_IMPORTED_MODULE_7__.useMutation),
|
|
2222
|
-
/* harmony export */ useQuery: () => (/* reexport safe */ _core_query__WEBPACK_IMPORTED_MODULE_7__.useQuery)
|
|
2223
|
-
/* harmony export */ });
|
|
2224
|
-
/* harmony import */ var _core_reactive__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./core/reactive */ "./src/core/reactive.ts");
|
|
2225
|
-
/* harmony import */ var _core_component__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./core/component */ "./src/core/component.ts");
|
|
2226
|
-
/* harmony import */ var _core_renderer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./core/renderer */ "./src/core/renderer.ts");
|
|
2227
|
-
/* harmony import */ var _router_index__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./router/index */ "./src/router/index.ts");
|
|
2228
|
-
/* harmony import */ var _store_index__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./store/index */ "./src/store/index.ts");
|
|
2229
|
-
/* harmony import */ var _security_sanitizer__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./security/sanitizer */ "./src/security/sanitizer.ts");
|
|
2230
|
-
/* harmony import */ var _core_hooks__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./core/hooks */ "./src/core/hooks.ts");
|
|
2231
|
-
/* harmony import */ var _core_query__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./core/query */ "./src/core/query.ts");
|
|
2232
|
-
/* harmony import */ var _core_vault__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./core/vault */ "./src/core/vault.ts");
|
|
2233
|
-
/* harmony import */ var _core_quantum__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./core/quantum */ "./src/core/quantum.ts");
|
|
2234
|
-
/* harmony import */ var _core_surge__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./core/surge */ "./src/core/surge.ts");
|
|
2235
|
-
/* harmony import */ var _components_bloch_sphere__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./components/bloch-sphere */ "./src/components/bloch-sphere.ts");
|
|
2236
|
-
/* harmony import */ var _components_infinity_list__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./components/infinity-list */ "./src/components/infinity-list.ts");
|
|
1995
|
+
;// ./src/index.ts
|
|
2237
1996
|
|
|
2238
1997
|
|
|
2239
1998
|
|
|
@@ -2259,8 +2018,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2259
2018
|
|
|
2260
2019
|
|
|
2261
2020
|
|
|
2262
|
-
const Mulan = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ reactive:
|
|
2263
|
-
effect:
|
|
2021
|
+
const Mulan = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ reactive: reactive,
|
|
2022
|
+
effect: effect, Component: MuComponent, defineComponent: defineComponent, Router: MuRouter, createRouter: createRouter, Store: MuStore, Security: Security }, hooks_namespaceObject), query_namespaceObject), quantum_namespaceObject), surge_namespaceObject), infinity_list_namespaceObject), { render: render,
|
|
2264
2023
|
// MULAN INSIGHT: Branded Logging
|
|
2265
2024
|
log: (msg, ...args) => {
|
|
2266
2025
|
console.log(`%c[MulanJS]%c ${msg}`, "color: #ff3e00; font-weight: bold; background: #222; padding: 2px 4px; border-radius: 3px;", "", ...args);
|
|
@@ -2292,57 +2051,8 @@ if (typeof window !== 'undefined') {
|
|
|
2292
2051
|
if (typeof window !== 'undefined') {
|
|
2293
2052
|
window.Mulan = Mulan;
|
|
2294
2053
|
}
|
|
2295
|
-
/* harmony default export */ const
|
|
2054
|
+
/* harmony default export */ const src = (Mulan);
|
|
2296
2055
|
|
|
2297
|
-
}
|
|
2056
|
+
export { MuComponent as Component, MuBlochSphereElement, MuComponent, MuInfinity, MuRouter, MuStore, MuRouter as Router, Security, Signal, activeControls, src as default, defineComponent, effect, getCurrentInstance, hydrate, muBurst, muControl, muEffect, muEntangle, muGate, muGeom, muMeasure, muMemo, muParallel, muPulse, muQubit, muRegister, muSearch, muState, muSurge, muSwitch, muTeleport, muVault, onMuDestroy, onMuIdle, onMuInit, onMuMount, onMuResume, onMuShake, onMuVoice, persistent, reactive, ref, render, renderToString, sanitize, setCurrentInstance, useMutation, useQuery };
|
|
2298
2057
|
|
|
2299
|
-
|
|
2300
|
-
const __webpack_exports__MuBlochSphereElement = __webpack_exports__.MuBlochSphereElement;
|
|
2301
|
-
const __webpack_exports__MuComponent = __webpack_exports__.MuComponent;
|
|
2302
|
-
const __webpack_exports__MuInfinity = __webpack_exports__.MuInfinity;
|
|
2303
|
-
const __webpack_exports__MuRouter = __webpack_exports__.MuRouter;
|
|
2304
|
-
const __webpack_exports__MuStore = __webpack_exports__.MuStore;
|
|
2305
|
-
const __webpack_exports__Router = __webpack_exports__.Router;
|
|
2306
|
-
const __webpack_exports__Security = __webpack_exports__.Security;
|
|
2307
|
-
const __webpack_exports__Signal = __webpack_exports__.Signal;
|
|
2308
|
-
const __webpack_exports__activeControls = __webpack_exports__.activeControls;
|
|
2309
|
-
const __webpack_exports__default = __webpack_exports__["default"];
|
|
2310
|
-
const __webpack_exports__defineComponent = __webpack_exports__.defineComponent;
|
|
2311
|
-
const __webpack_exports__effect = __webpack_exports__.effect;
|
|
2312
|
-
const __webpack_exports__getCurrentInstance = __webpack_exports__.getCurrentInstance;
|
|
2313
|
-
const __webpack_exports__hydrate = __webpack_exports__.hydrate;
|
|
2314
|
-
const __webpack_exports__muBurst = __webpack_exports__.muBurst;
|
|
2315
|
-
const __webpack_exports__muControl = __webpack_exports__.muControl;
|
|
2316
|
-
const __webpack_exports__muEffect = __webpack_exports__.muEffect;
|
|
2317
|
-
const __webpack_exports__muEntangle = __webpack_exports__.muEntangle;
|
|
2318
|
-
const __webpack_exports__muGate = __webpack_exports__.muGate;
|
|
2319
|
-
const __webpack_exports__muGeom = __webpack_exports__.muGeom;
|
|
2320
|
-
const __webpack_exports__muMeasure = __webpack_exports__.muMeasure;
|
|
2321
|
-
const __webpack_exports__muMemo = __webpack_exports__.muMemo;
|
|
2322
|
-
const __webpack_exports__muParallel = __webpack_exports__.muParallel;
|
|
2323
|
-
const __webpack_exports__muPulse = __webpack_exports__.muPulse;
|
|
2324
|
-
const __webpack_exports__muQubit = __webpack_exports__.muQubit;
|
|
2325
|
-
const __webpack_exports__muRegister = __webpack_exports__.muRegister;
|
|
2326
|
-
const __webpack_exports__muSearch = __webpack_exports__.muSearch;
|
|
2327
|
-
const __webpack_exports__muState = __webpack_exports__.muState;
|
|
2328
|
-
const __webpack_exports__muSurge = __webpack_exports__.muSurge;
|
|
2329
|
-
const __webpack_exports__muSwitch = __webpack_exports__.muSwitch;
|
|
2330
|
-
const __webpack_exports__muTeleport = __webpack_exports__.muTeleport;
|
|
2331
|
-
const __webpack_exports__muVault = __webpack_exports__.muVault;
|
|
2332
|
-
const __webpack_exports__onMuDestroy = __webpack_exports__.onMuDestroy;
|
|
2333
|
-
const __webpack_exports__onMuIdle = __webpack_exports__.onMuIdle;
|
|
2334
|
-
const __webpack_exports__onMuInit = __webpack_exports__.onMuInit;
|
|
2335
|
-
const __webpack_exports__onMuMount = __webpack_exports__.onMuMount;
|
|
2336
|
-
const __webpack_exports__onMuResume = __webpack_exports__.onMuResume;
|
|
2337
|
-
const __webpack_exports__onMuShake = __webpack_exports__.onMuShake;
|
|
2338
|
-
const __webpack_exports__onMuVoice = __webpack_exports__.onMuVoice;
|
|
2339
|
-
const __webpack_exports__persistent = __webpack_exports__.persistent;
|
|
2340
|
-
const __webpack_exports__reactive = __webpack_exports__.reactive;
|
|
2341
|
-
const __webpack_exports__ref = __webpack_exports__.ref;
|
|
2342
|
-
const __webpack_exports__render = __webpack_exports__.render;
|
|
2343
|
-
const __webpack_exports__renderToString = __webpack_exports__.renderToString;
|
|
2344
|
-
const __webpack_exports__sanitize = __webpack_exports__.sanitize;
|
|
2345
|
-
const __webpack_exports__setCurrentInstance = __webpack_exports__.setCurrentInstance;
|
|
2346
|
-
const __webpack_exports__useMutation = __webpack_exports__.useMutation;
|
|
2347
|
-
const __webpack_exports__useQuery = __webpack_exports__.useQuery;
|
|
2348
|
-
export { __webpack_exports__Component as Component, __webpack_exports__MuBlochSphereElement as MuBlochSphereElement, __webpack_exports__MuComponent as MuComponent, __webpack_exports__MuInfinity as MuInfinity, __webpack_exports__MuRouter as MuRouter, __webpack_exports__MuStore as MuStore, __webpack_exports__Router as Router, __webpack_exports__Security as Security, __webpack_exports__Signal as Signal, __webpack_exports__activeControls as activeControls, __webpack_exports__default as default, __webpack_exports__defineComponent as defineComponent, __webpack_exports__effect as effect, __webpack_exports__getCurrentInstance as getCurrentInstance, __webpack_exports__hydrate as hydrate, __webpack_exports__muBurst as muBurst, __webpack_exports__muControl as muControl, __webpack_exports__muEffect as muEffect, __webpack_exports__muEntangle as muEntangle, __webpack_exports__muGate as muGate, __webpack_exports__muGeom as muGeom, __webpack_exports__muMeasure as muMeasure, __webpack_exports__muMemo as muMemo, __webpack_exports__muParallel as muParallel, __webpack_exports__muPulse as muPulse, __webpack_exports__muQubit as muQubit, __webpack_exports__muRegister as muRegister, __webpack_exports__muSearch as muSearch, __webpack_exports__muState as muState, __webpack_exports__muSurge as muSurge, __webpack_exports__muSwitch as muSwitch, __webpack_exports__muTeleport as muTeleport, __webpack_exports__muVault as muVault, __webpack_exports__onMuDestroy as onMuDestroy, __webpack_exports__onMuIdle as onMuIdle, __webpack_exports__onMuInit as onMuInit, __webpack_exports__onMuMount as onMuMount, __webpack_exports__onMuResume as onMuResume, __webpack_exports__onMuShake as onMuShake, __webpack_exports__onMuVoice as onMuVoice, __webpack_exports__persistent as persistent, __webpack_exports__reactive as reactive, __webpack_exports__ref as ref, __webpack_exports__render as render, __webpack_exports__renderToString as renderToString, __webpack_exports__sanitize as sanitize, __webpack_exports__setCurrentInstance as setCurrentInstance, __webpack_exports__useMutation as useMutation, __webpack_exports__useQuery as useQuery };
|
|
2058
|
+
//# sourceMappingURL=mulan.esm.js.map
|