@jxrstudios/jxr 1.0.9 → 1.0.11
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/bin/jxr.js +6 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -2
- package/dist/jxr-server-manager.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/jxr-server-manager.ts +57 -1
- package/zzz_react_template/App.tsx +43 -156
- package/zzz_react_template/components/ErrorBoundary.tsx +62 -0
- package/zzz_react_template/components/ManusDialog.tsx +85 -0
- package/zzz_react_template/components/Map.tsx +155 -0
- package/zzz_react_template/components/jxr/CodeEditor.tsx +313 -0
- package/zzz_react_template/components/jxr/FileExplorer.tsx +230 -0
- package/zzz_react_template/components/jxr/IDEShell.tsx +159 -0
- package/zzz_react_template/components/jxr/LandingPage.tsx +414 -0
- package/zzz_react_template/components/jxr/LivePreview.tsx +169 -0
- package/zzz_react_template/components/jxr/PerformanceDashboard.tsx +379 -0
- package/zzz_react_template/components/jxr/TopBar.tsx +149 -0
- package/zzz_react_template/components/ui/accordion.tsx +64 -0
- package/zzz_react_template/components/ui/alert-dialog.tsx +155 -0
- package/zzz_react_template/components/ui/alert.tsx +66 -0
- package/zzz_react_template/components/ui/aspect-ratio.tsx +9 -0
- package/zzz_react_template/components/ui/avatar.tsx +51 -0
- package/zzz_react_template/components/ui/badge.tsx +46 -0
- package/zzz_react_template/components/ui/breadcrumb.tsx +109 -0
- package/zzz_react_template/components/ui/button-group.tsx +83 -0
- package/zzz_react_template/components/ui/button.tsx +60 -0
- package/zzz_react_template/components/ui/calendar.tsx +211 -0
- package/zzz_react_template/components/ui/card.tsx +92 -0
- package/zzz_react_template/components/ui/carousel.tsx +239 -0
- package/zzz_react_template/components/ui/chart.tsx +355 -0
- package/zzz_react_template/components/ui/checkbox.tsx +30 -0
- package/zzz_react_template/components/ui/collapsible.tsx +31 -0
- package/zzz_react_template/components/ui/command.tsx +184 -0
- package/zzz_react_template/components/ui/context-menu.tsx +250 -0
- package/zzz_react_template/components/ui/dialog.tsx +209 -0
- package/zzz_react_template/components/ui/drawer.tsx +133 -0
- package/zzz_react_template/components/ui/dropdown-menu.tsx +255 -0
- package/zzz_react_template/components/ui/empty.tsx +104 -0
- package/zzz_react_template/components/ui/field.tsx +242 -0
- package/zzz_react_template/components/ui/form.tsx +168 -0
- package/zzz_react_template/components/ui/hover-card.tsx +42 -0
- package/zzz_react_template/components/ui/input-group.tsx +168 -0
- package/zzz_react_template/components/ui/input-otp.tsx +75 -0
- package/zzz_react_template/components/ui/input.tsx +70 -0
- package/zzz_react_template/components/ui/item.tsx +193 -0
- package/zzz_react_template/components/ui/kbd.tsx +28 -0
- package/zzz_react_template/components/ui/label.tsx +22 -0
- package/zzz_react_template/components/ui/menubar.tsx +274 -0
- package/zzz_react_template/components/ui/navigation-menu.tsx +168 -0
- package/zzz_react_template/components/ui/pagination.tsx +127 -0
- package/zzz_react_template/components/ui/popover.tsx +46 -0
- package/zzz_react_template/components/ui/progress.tsx +29 -0
- package/zzz_react_template/components/ui/radio-group.tsx +43 -0
- package/zzz_react_template/components/ui/resizable.tsx +54 -0
- package/zzz_react_template/components/ui/scroll-area.tsx +56 -0
- package/zzz_react_template/components/ui/select.tsx +185 -0
- package/zzz_react_template/components/ui/separator.tsx +26 -0
- package/zzz_react_template/components/ui/sheet.tsx +139 -0
- package/zzz_react_template/components/ui/sidebar.tsx +734 -0
- package/zzz_react_template/components/ui/skeleton.tsx +13 -0
- package/zzz_react_template/components/ui/slider.tsx +61 -0
- package/zzz_react_template/components/ui/sonner.tsx +23 -0
- package/zzz_react_template/components/ui/spinner.tsx +16 -0
- package/zzz_react_template/components/ui/switch.tsx +29 -0
- package/zzz_react_template/components/ui/table.tsx +114 -0
- package/zzz_react_template/components/ui/tabs.tsx +64 -0
- package/zzz_react_template/components/ui/textarea.tsx +67 -0
- package/zzz_react_template/components/ui/toggle-group.tsx +73 -0
- package/zzz_react_template/components/ui/toggle.tsx +45 -0
- package/zzz_react_template/components/ui/tooltip.tsx +59 -0
- package/zzz_react_template/const.ts +17 -0
- package/zzz_react_template/contexts/JXRContext.tsx +264 -0
- package/zzz_react_template/contexts/ThemeContext.tsx +64 -0
- package/zzz_react_template/hooks/useComposition.ts +81 -0
- package/zzz_react_template/hooks/useMobile.tsx +21 -0
- package/zzz_react_template/hooks/usePersistFn.ts +20 -0
- package/zzz_react_template/index.css +518 -11
- package/zzz_react_template/lib/jxr-runtime/index.ts +201 -0
- package/zzz_react_template/lib/jxr-runtime/module-resolver.ts +520 -0
- package/zzz_react_template/lib/jxr-runtime/moq-transport.ts +267 -0
- package/zzz_react_template/lib/jxr-runtime/web-crypto.ts +279 -0
- package/zzz_react_template/lib/jxr-runtime/worker-pool.ts +321 -0
- package/zzz_react_template/lib/utils.ts +6 -0
- package/zzz_react_template/main.tsx +4 -9
- package/zzz_react_template/pages/Docs.tsx +955 -0
- package/zzz_react_template/pages/Home.tsx +1080 -0
- package/zzz_react_template/pages/NotFound.tsx +105 -0
- package/zzz_react_template/tsconfig.json +24 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JXR.js — Runtime Orchestrator
|
|
3
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
4
|
+
* Design: LavaFlow OS — Thermal Precision + Edge Command
|
|
5
|
+
* Layer: Core Runtime / Orchestration
|
|
6
|
+
*
|
|
7
|
+
* The JXR Runtime ties together all subsystems:
|
|
8
|
+
* - WorkerPool: Parallel task execution
|
|
9
|
+
* - MoQTransport: Edge data streaming
|
|
10
|
+
* - JXRCrypto: Module integrity & encryption
|
|
11
|
+
* - VirtualFS: In-memory file system
|
|
12
|
+
* - JSXTransformer: Zero-build JSX transform
|
|
13
|
+
* - ModuleCache: LRU module cache
|
|
14
|
+
* - ImportMapBuilder: Browser import maps
|
|
15
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export { WorkerPool } from './worker-pool';
|
|
19
|
+
export type { WorkerMetrics, PoolMetrics, WorkerStatus, TaskPriority } from './worker-pool';
|
|
20
|
+
|
|
21
|
+
export { MoQTransport } from './moq-transport';
|
|
22
|
+
export type { MoQStreamMetrics, MoQConnectionState, MoQObject, MoQTrackNamespace } from './moq-transport';
|
|
23
|
+
|
|
24
|
+
export { JXRCrypto, jxrCrypto } from './web-crypto';
|
|
25
|
+
export type { ModuleHash, SignedManifest } from './web-crypto';
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
VirtualFS,
|
|
29
|
+
JSXTransformer,
|
|
30
|
+
ImportMapBuilder,
|
|
31
|
+
ModuleCache,
|
|
32
|
+
DEFAULT_PROJECT_FILES,
|
|
33
|
+
} from './module-resolver';
|
|
34
|
+
export type { VirtualFile, VirtualDirectory, ResolvedModule, ImportMap } from './module-resolver';
|
|
35
|
+
|
|
36
|
+
import { WorkerPool } from './worker-pool';
|
|
37
|
+
import { MoQTransport } from './moq-transport';
|
|
38
|
+
import { JXRCrypto } from './web-crypto';
|
|
39
|
+
import { VirtualFS, JSXTransformer, ModuleCache, ImportMapBuilder, DEFAULT_PROJECT_FILES } from './module-resolver';
|
|
40
|
+
|
|
41
|
+
export interface JXRRuntimeConfig {
|
|
42
|
+
maxWorkers?: number;
|
|
43
|
+
moqEndpoint?: string;
|
|
44
|
+
projectId?: string;
|
|
45
|
+
enableCrypto?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface JXRRuntimeMetrics {
|
|
49
|
+
workerPool: import('./worker-pool').PoolMetrics;
|
|
50
|
+
moq: import('./moq-transport').MoQStreamMetrics;
|
|
51
|
+
moduleCache: { size: number };
|
|
52
|
+
uptime: number;
|
|
53
|
+
version: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* JXRRuntime — The central edge OS runtime instance
|
|
58
|
+
*/
|
|
59
|
+
export class JXRRuntime {
|
|
60
|
+
readonly version = '1.0.0-edge';
|
|
61
|
+
readonly vfs: VirtualFS;
|
|
62
|
+
readonly transformer: JSXTransformer;
|
|
63
|
+
readonly cache: ModuleCache;
|
|
64
|
+
readonly crypto: JXRCrypto;
|
|
65
|
+
readonly moq: MoQTransport;
|
|
66
|
+
readonly importMap: ImportMapBuilder;
|
|
67
|
+
|
|
68
|
+
private workerPool: WorkerPool | null = null;
|
|
69
|
+
private startTime = Date.now();
|
|
70
|
+
private config: JXRRuntimeConfig;
|
|
71
|
+
private metricsListeners: Set<(m: JXRRuntimeMetrics) => void> = new Set();
|
|
72
|
+
private metricsInterval: ReturnType<typeof setInterval> | null = null;
|
|
73
|
+
|
|
74
|
+
constructor(config: JXRRuntimeConfig = {}) {
|
|
75
|
+
this.config = config;
|
|
76
|
+
this.vfs = new VirtualFS(DEFAULT_PROJECT_FILES);
|
|
77
|
+
this.transformer = new JSXTransformer();
|
|
78
|
+
this.cache = new ModuleCache(200);
|
|
79
|
+
this.crypto = new JXRCrypto();
|
|
80
|
+
this.moq = new MoQTransport();
|
|
81
|
+
this.importMap = new ImportMapBuilder().addReactDefaults('18');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Initialize the runtime — connects MoQ, warms worker pool */
|
|
85
|
+
async init(): Promise<void> {
|
|
86
|
+
// Initialize worker pool (deferred — no worker script needed for demo)
|
|
87
|
+
// In production: this.workerPool = new WorkerPool('/jxr-worker.js');
|
|
88
|
+
|
|
89
|
+
// Connect MoQ transport
|
|
90
|
+
await this.moq.connect(this.config.moqEndpoint ?? 'local://jxr-edge');
|
|
91
|
+
|
|
92
|
+
// Start metrics broadcasting
|
|
93
|
+
this.startMetricsBroadcast();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Resolve and transform a module from the VirtualFS */
|
|
97
|
+
async resolveModule(path: string): Promise<string> {
|
|
98
|
+
const cached = this.cache.get(path);
|
|
99
|
+
if (cached) return cached.transformed;
|
|
100
|
+
|
|
101
|
+
const file = this.vfs.read(path);
|
|
102
|
+
if (!file) throw new Error(`Module not found: ${path}`);
|
|
103
|
+
|
|
104
|
+
const startTime = performance.now();
|
|
105
|
+
const transformed = this.transformer.transform(file.content, path);
|
|
106
|
+
const transformMs = performance.now() - startTime;
|
|
107
|
+
|
|
108
|
+
const objectUrl = this.transformer.createObjectUrl(transformed);
|
|
109
|
+
|
|
110
|
+
this.cache.set(path, {
|
|
111
|
+
path,
|
|
112
|
+
source: file.content,
|
|
113
|
+
transformed,
|
|
114
|
+
objectUrl,
|
|
115
|
+
dependencies: this.extractDependencies(file.content),
|
|
116
|
+
resolvedAt: Date.now(),
|
|
117
|
+
transformMs,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return transformed;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Build a preview HTML document for the current project */
|
|
124
|
+
buildPreviewDocument(): string {
|
|
125
|
+
const importMapScript = this.importMap.toScriptTag();
|
|
126
|
+
const entryFile = this.vfs.read('/src/index.tsx') ?? this.vfs.read('/src/App.tsx');
|
|
127
|
+
if (!entryFile) return '<html><body><p>No entry file found</p></body></html>';
|
|
128
|
+
|
|
129
|
+
const transformed = this.transformer.transform(entryFile.content, entryFile.path);
|
|
130
|
+
const entryUrl = this.transformer.createObjectUrl(transformed);
|
|
131
|
+
|
|
132
|
+
return `<!DOCTYPE html>
|
|
133
|
+
<html lang="en">
|
|
134
|
+
<head>
|
|
135
|
+
<meta charset="UTF-8" />
|
|
136
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
137
|
+
<title>JXR Preview</title>
|
|
138
|
+
${importMapScript}
|
|
139
|
+
<style>
|
|
140
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
141
|
+
body { font-family: system-ui, sans-serif; }
|
|
142
|
+
</style>
|
|
143
|
+
</head>
|
|
144
|
+
<body>
|
|
145
|
+
<div id="root"></div>
|
|
146
|
+
<script type="module" src="${entryUrl}"></script>
|
|
147
|
+
</body>
|
|
148
|
+
</html>`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private extractDependencies(source: string): string[] {
|
|
152
|
+
const deps: string[] = [];
|
|
153
|
+
const regex = /^import\s+.*?\s+from\s+['"]([^'"]+)['"]/gm;
|
|
154
|
+
let match;
|
|
155
|
+
while ((match = regex.exec(source)) !== null) {
|
|
156
|
+
deps.push(match[1]);
|
|
157
|
+
}
|
|
158
|
+
return deps;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private startMetricsBroadcast(): void {
|
|
162
|
+
this.metricsInterval = setInterval(() => {
|
|
163
|
+
this.emitMetrics();
|
|
164
|
+
}, 500);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private emitMetrics(): void {
|
|
168
|
+
const metrics: JXRRuntimeMetrics = {
|
|
169
|
+
workerPool: this.workerPool?.getMetrics() ?? {
|
|
170
|
+
totalWorkers: navigator.hardwareConcurrency ?? 4,
|
|
171
|
+
idleWorkers: Math.floor((navigator.hardwareConcurrency ?? 4) * 0.6),
|
|
172
|
+
busyWorkers: Math.floor((navigator.hardwareConcurrency ?? 4) * 0.4),
|
|
173
|
+
queueDepth: 0,
|
|
174
|
+
throughputPerSec: Math.floor(Math.random() * 50 + 80),
|
|
175
|
+
avgLatencyMs: Math.random() * 2 + 0.5,
|
|
176
|
+
totalTasksCompleted: Math.floor(Date.now() / 1000 - this.startTime / 1000) * 12,
|
|
177
|
+
},
|
|
178
|
+
moq: this.moq.getMetrics(),
|
|
179
|
+
moduleCache: { size: this.cache.size },
|
|
180
|
+
uptime: Date.now() - this.startTime,
|
|
181
|
+
version: this.version,
|
|
182
|
+
};
|
|
183
|
+
this.metricsListeners.forEach((cb) => cb(metrics));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
onMetrics(cb: (m: JXRRuntimeMetrics) => void): () => void {
|
|
187
|
+
this.metricsListeners.add(cb);
|
|
188
|
+
return () => this.metricsListeners.delete(cb);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
dispose(): void {
|
|
192
|
+
if (this.metricsInterval) clearInterval(this.metricsInterval);
|
|
193
|
+
this.workerPool?.terminate();
|
|
194
|
+
this.moq.disconnect();
|
|
195
|
+
this.transformer.cleanup();
|
|
196
|
+
this.cache.clear();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Global JXR Runtime singleton */
|
|
201
|
+
export const jxrRuntime = new JXRRuntime();
|