baraqex 1.0.32 → 1.0.34
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/baraqex.js +28 -27
- package/dist/server/index.d.ts +3 -6
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +8 -125
- package/dist/server/index.js.map +1 -1
- package/package.json +8 -2
- package/templates/fullstack-app/src/pages/index.js +0 -0
- package/templates/fullstack-template/src/pages/index.js +193 -48
- package/templates/ssr-template/package-lock.json +5080 -0
- package/templates/ssr-template/package.json +8 -14
- package/templates/ssr-template/src/App.tsx +7 -19
- package/templates/ssr-template/src/client.tsx +1 -21
- package/templates/ssr-template/src/server.ts +14 -183
- package/templates/ssr-template/tsconfig.json +6 -15
- package/templates/ssr-template/tsconfig.server.json +5 -18
- package/templates/ssr-template/vite.config.ts +0 -0
- package/templates/wasm/build-wasm.js +228 -0
- package/templates/wasm/esbuild.config.js +63 -0
- package/templates/wasm/go/main.go +256 -0
- package/templates/wasm/go/wasm_exec.js +0 -0
- package/templates/wasm/index.html +97 -0
- package/templates/wasm/jsx-shim.js +9 -0
- package/templates/wasm/package-lock.json +4848 -0
- package/templates/wasm/package.json +27 -0
- package/templates/wasm/public/example.wasm +0 -0
- package/templates/wasm/public/wasm_exec.js +572 -0
- package/templates/wasm/src/App.tsx +519 -0
- package/templates/wasm/src/client.tsx +220 -0
- package/templates/wasm/src/index.html +14 -0
- package/templates/wasm/src/index.tsx +21 -0
- package/templates/wasm/src/main.tsx +5 -0
- package/templates/wasm/src/server.ts +145 -0
- package/templates/wasm/src/wasm-loader.ts +119 -0
- package/templates/wasm/tsconfig.json +21 -0
- package/templates/wasm/tsconfig.node.json +13 -0
- package/templates/wasm/tsconfig.server.json +23 -0
- package/templates/wasm/vite.config.ts +73 -0
- package/templates/wasm/wasm-loader.js +103 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASM Loader for Frontend Hamroun Go WASM integration
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
let wasmInstance = null;
|
|
6
|
+
let wasmReady = false;
|
|
7
|
+
|
|
8
|
+
export async function loadGoWasm(wasmPath, options = {}) {
|
|
9
|
+
if (wasmReady) {
|
|
10
|
+
return wasmInstance;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
console.log('🔄 Loading Go WASM module from:', wasmPath);
|
|
15
|
+
|
|
16
|
+
// Load the Go WASM runtime
|
|
17
|
+
if (!window.Go) {
|
|
18
|
+
await loadWasmExecJs();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Create Go instance
|
|
22
|
+
const go = new window.Go();
|
|
23
|
+
|
|
24
|
+
// Fetch and instantiate WASM
|
|
25
|
+
const wasmModule = await WebAssembly.instantiateStreaming(
|
|
26
|
+
fetch(wasmPath),
|
|
27
|
+
go.importObject
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
// Run the Go program
|
|
31
|
+
go.run(wasmModule.instance);
|
|
32
|
+
|
|
33
|
+
wasmInstance = {
|
|
34
|
+
instance: wasmModule.instance,
|
|
35
|
+
module: wasmModule.module,
|
|
36
|
+
go: go
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
wasmReady = true;
|
|
40
|
+
|
|
41
|
+
console.log('✅ Go WASM module loaded successfully!');
|
|
42
|
+
|
|
43
|
+
if (options.onLoad) {
|
|
44
|
+
options.onLoad(wasmInstance);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return wasmInstance;
|
|
48
|
+
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error('❌ Failed to load Go WASM module:', error);
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function loadWasmExecJs() {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
const script = document.createElement('script');
|
|
58
|
+
script.src = '/wasm_exec.js';
|
|
59
|
+
script.onload = resolve;
|
|
60
|
+
script.onerror = () => reject(new Error('Failed to load wasm_exec.js'));
|
|
61
|
+
document.head.appendChild(script);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function isWasmReady() {
|
|
66
|
+
return wasmReady;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function getWasmInstance() {
|
|
70
|
+
return wasmInstance;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Utility functions for calling Go functions safely
|
|
74
|
+
export function callGoFunction(functionName, ...args) {
|
|
75
|
+
if (!wasmReady) {
|
|
76
|
+
throw new Error('WASM module not ready');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (typeof window[functionName] !== 'function') {
|
|
80
|
+
throw new Error(`Go function '${functionName}' not found`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return window[functionName](...args);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function waitForWasm(timeout = 10000) {
|
|
87
|
+
if (wasmReady) return wasmInstance;
|
|
88
|
+
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
const checkInterval = setInterval(() => {
|
|
91
|
+
if (wasmReady) {
|
|
92
|
+
clearInterval(checkInterval);
|
|
93
|
+
clearTimeout(timeoutId);
|
|
94
|
+
resolve(wasmInstance);
|
|
95
|
+
}
|
|
96
|
+
}, 100);
|
|
97
|
+
|
|
98
|
+
const timeoutId = setTimeout(() => {
|
|
99
|
+
clearInterval(checkInterval);
|
|
100
|
+
reject(new Error('WASM loading timeout'));
|
|
101
|
+
}, timeout);
|
|
102
|
+
});
|
|
103
|
+
}
|