frontend-hamroun 1.2.84 → 1.2.85
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/package.json +1 -1
- package/templates/basic-app/build.d.ts +2 -0
- package/templates/basic-app/build.d.ts.map +1 -0
- package/templates/basic-app/dev.d.ts +2 -0
- package/templates/basic-app/dev.d.ts.map +1 -0
- package/templates/basic-app/esbuild.config.d.ts +2 -0
- package/templates/basic-app/esbuild.config.d.ts.map +1 -0
- package/templates/basic-app/postcss.config.d.ts +8 -0
- package/templates/basic-app/postcss.config.d.ts.map +1 -0
- package/templates/basic-app/server.d.ts +2 -0
- package/templates/basic-app/server.d.ts.map +1 -0
- package/templates/basic-app/src/App.d.ts +2 -0
- package/templates/basic-app/src/App.d.ts.map +1 -0
- package/templates/basic-app/src/App.js +148 -0
- package/templates/basic-app/src/client.d.ts +2 -0
- package/templates/basic-app/src/client.d.ts.map +1 -0
- package/templates/basic-app/src/client.js +6 -0
- package/templates/basic-app/src/components/Counter.d.ts +4 -0
- package/templates/basic-app/src/components/Counter.d.ts.map +1 -0
- package/templates/basic-app/src/components/Counter.js +9 -0
- package/templates/basic-app/src/jsx-shim.d.ts +8 -0
- package/templates/basic-app/src/jsx-shim.d.ts.map +1 -0
- package/templates/basic-app/src/main.d.ts +2 -0
- package/templates/basic-app/src/main.d.ts.map +1 -0
- package/templates/basic-app/src/main.js +57 -0
- package/templates/basic-app/src/server.d.ts +2 -0
- package/templates/basic-app/src/server.d.ts.map +1 -0
- package/templates/basic-app/tailwind.config.d.ts +9 -0
- package/templates/basic-app/tailwind.config.d.ts.map +1 -0
- package/templates/basic-app/vite.config.d.ts +3 -0
- package/templates/basic-app/vite.config.d.ts.map +1 -0
- package/templates/basic-app/vite.config.js +7 -0
- package/templates/complete-app/api/hello.d.ts +1 -0
- package/templates/complete-app/api/hello.d.ts.map +1 -0
- package/templates/complete-app/client.d.ts +2 -0
- package/templates/complete-app/client.d.ts.map +1 -0
- package/templates/complete-app/lib/frontend-hamroun.d.ts +18 -0
- package/templates/complete-app/lib/frontend-hamroun.d.ts.map +1 -0
- package/templates/complete-app/pages/about.d.ts +7 -0
- package/templates/complete-app/pages/about.d.ts.map +1 -0
- package/templates/complete-app/pages/index.d.ts +7 -0
- package/templates/complete-app/pages/index.d.ts.map +1 -0
- package/templates/complete-app/pages/wasm-demo.d.ts +7 -0
- package/templates/complete-app/pages/wasm-demo.d.ts.map +1 -0
- package/templates/complete-app/public/client.d.ts +17 -0
- package/templates/complete-app/public/client.d.ts.map +1 -0
- package/templates/complete-app/server.d.ts +2 -0
- package/templates/complete-app/server.d.ts.map +1 -0
- package/templates/complete-app/server.js +236 -218
- package/templates/complete-app/src/App.d.ts +2 -0
- package/templates/complete-app/src/App.d.ts.map +1 -0
- package/templates/complete-app/src/App.js +27 -0
- package/templates/complete-app/src/client.d.ts +2 -0
- package/templates/complete-app/src/client.d.ts.map +1 -0
- package/templates/complete-app/src/client.js +52 -0
- package/templates/complete-app/src/pages/index.d.ts +2 -0
- package/templates/complete-app/src/pages/index.d.ts.map +1 -0
- package/templates/complete-app/src/pages/index.js +19 -0
- package/templates/complete-app/src/server.d.ts +2 -0
- package/templates/complete-app/src/server.d.ts.map +1 -0
- package/templates/complete-app/src/server.js +192 -0
- package/templates/complete-app/vite.config.d.ts +3 -0
- package/templates/complete-app/vite.config.d.ts.map +1 -0
- package/templates/complete-app/vite.config.js +29 -57
- package/templates/fullstack-app/api/hello.d.ts +4 -0
- package/templates/fullstack-app/api/hello.d.ts.map +1 -0
- package/templates/fullstack-app/api/hello.js +14 -11
- package/templates/fullstack-app/api/users/[id].d.ts +5 -0
- package/templates/fullstack-app/api/users/[id].d.ts.map +1 -0
- package/templates/fullstack-app/api/users/[id].js +52 -0
- package/templates/fullstack-app/api/users/index.d.ts +4 -0
- package/templates/fullstack-app/api/users/index.d.ts.map +1 -0
- package/templates/fullstack-app/api/users/index.js +25 -0
- package/templates/fullstack-app/build/main.d.ts +211 -0
- package/templates/fullstack-app/build/main.d.ts.map +1 -0
- package/templates/fullstack-app/build.d.ts +2 -0
- package/templates/fullstack-app/build.d.ts.map +1 -0
- package/templates/fullstack-app/build.js +190 -0
- package/templates/fullstack-app/postcss.config.d.ts +5 -0
- package/templates/fullstack-app/postcss.config.d.ts.map +1 -0
- package/templates/fullstack-app/process-tailwind.d.ts +2 -0
- package/templates/fullstack-app/process-tailwind.d.ts.map +1 -0
- package/templates/fullstack-app/public/route-handler.d.ts +1 -0
- package/templates/fullstack-app/public/route-handler.d.ts.map +1 -0
- package/templates/fullstack-app/server.d.ts +2 -0
- package/templates/fullstack-app/server.d.ts.map +1 -0
- package/templates/fullstack-app/server.js +428 -266
- package/templates/fullstack-app/src/client.d.ts +2 -0
- package/templates/fullstack-app/src/client.d.ts.map +1 -0
- package/templates/fullstack-app/src/components/ClientHome.d.ts +1 -0
- package/templates/fullstack-app/src/components/ClientHome.d.ts.map +1 -0
- package/templates/fullstack-app/src/components/ClientHome.js +1 -0
- package/templates/fullstack-app/src/components/ErrorBoundary.d.ts +7 -0
- package/templates/fullstack-app/src/components/ErrorBoundary.d.ts.map +1 -0
- package/templates/fullstack-app/src/components/ErrorBoundary.js +12 -0
- package/templates/fullstack-app/src/components/Layout.d.ts +7 -0
- package/templates/fullstack-app/src/components/Layout.d.ts.map +1 -0
- package/templates/fullstack-app/src/components/Layout.js +4 -0
- package/templates/fullstack-app/src/components/StateDemo.d.ts +2 -0
- package/templates/fullstack-app/src/components/StateDemo.d.ts.map +1 -0
- package/templates/fullstack-app/src/components/StateDemo.js +86 -0
- package/templates/fullstack-app/src/components/UserList.d.ts +11 -0
- package/templates/fullstack-app/src/components/UserList.d.ts.map +1 -0
- package/templates/fullstack-app/src/components/UserList.js +7 -0
- package/templates/fullstack-app/src/config.d.ts +29 -0
- package/templates/fullstack-app/src/config.d.ts.map +1 -0
- package/templates/fullstack-app/src/config.js +36 -0
- package/templates/fullstack-app/src/data/api.d.ts +35 -0
- package/templates/fullstack-app/src/data/api.d.ts.map +1 -0
- package/templates/fullstack-app/src/data/api.js +173 -0
- package/templates/fullstack-app/src/main.d.ts +7 -0
- package/templates/fullstack-app/src/main.d.ts.map +1 -0
- package/templates/fullstack-app/src/main.js +130 -0
- package/templates/fullstack-app/src/middleware.d.ts +10 -0
- package/templates/fullstack-app/src/middleware.d.ts.map +1 -0
- package/templates/fullstack-app/src/middleware.js +14 -0
- package/templates/fullstack-app/src/pages/404.d.ts +4 -0
- package/templates/fullstack-app/src/pages/404.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/404.js +4 -0
- package/templates/fullstack-app/src/pages/[id].d.ts +1 -0
- package/templates/fullstack-app/src/pages/[id].d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/[id].js +1 -0
- package/templates/fullstack-app/src/pages/_app.d.ts +6 -0
- package/templates/fullstack-app/src/pages/_app.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/_app.js +6 -0
- package/templates/fullstack-app/src/pages/_document.d.ts +7 -0
- package/templates/fullstack-app/src/pages/_document.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/_document.js +4 -0
- package/templates/fullstack-app/src/pages/_error.d.ts +4 -0
- package/templates/fullstack-app/src/pages/_error.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/_error.js +8 -0
- package/templates/fullstack-app/src/pages/about/index.d.ts +5 -0
- package/templates/fullstack-app/src/pages/about/index.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/about/index.js +6 -0
- package/templates/fullstack-app/src/pages/about.d.ts +10 -0
- package/templates/fullstack-app/src/pages/about.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/about.js +21 -0
- package/templates/fullstack-app/src/pages/api/users/[id].d.ts +6 -0
- package/templates/fullstack-app/src/pages/api/users/[id].d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/api/users/[id].js +51 -0
- package/templates/fullstack-app/src/pages/api/users/index.d.ts +4 -0
- package/templates/fullstack-app/src/pages/api/users/index.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/api/users/index.js +33 -0
- package/templates/fullstack-app/src/pages/index.d.ts +21 -0
- package/templates/fullstack-app/src/pages/index.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/index.js +66 -0
- package/templates/fullstack-app/src/pages/users/[id].d.ts +38 -0
- package/templates/fullstack-app/src/pages/users/[id].d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/users/[id].js +79 -0
- package/templates/fullstack-app/src/pages/users.d.ts +14 -0
- package/templates/fullstack-app/src/pages/users.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/users.js +14 -0
- package/templates/fullstack-app/src/pages/wasm-demo.d.ts +1 -0
- package/templates/fullstack-app/src/pages/wasm-demo.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/wasm-demo.js +2 -0
- package/templates/fullstack-app/src/router.d.ts +22 -0
- package/templates/fullstack-app/src/router.d.ts.map +1 -0
- package/templates/fullstack-app/src/router.js +210 -0
- package/templates/fullstack-app/tailwind.config.d.ts +3 -0
- package/templates/fullstack-app/tailwind.config.d.ts.map +1 -0
- package/templates/fullstack-app/vite.config.d.ts +3 -0
- package/templates/fullstack-app/vite.config.d.ts.map +1 -0
- package/templates/ssr-template/dist/client/assets/main-D-VH3xOb.d.ts +2 -0
- package/templates/ssr-template/dist/client/assets/main-D-VH3xOb.d.ts.map +1 -0
- package/templates/ssr-template/dist/client.d.ts +85 -0
- package/templates/ssr-template/dist/client.d.ts.map +1 -0
- package/templates/ssr-template/dist/server.d.ts +2 -0
- package/templates/ssr-template/dist/server.d.ts.map +1 -0
- package/templates/ssr-template/esbuild.config.d.ts +2 -0
- package/templates/ssr-template/esbuild.config.d.ts.map +1 -0
- package/templates/ssr-template/jsx-shim.d.ts +2 -0
- package/templates/ssr-template/jsx-shim.d.ts.map +1 -0
- package/templates/ssr-template/src/App.d.ts +2 -0
- package/templates/ssr-template/src/App.d.ts.map +1 -0
- package/templates/ssr-template/src/App.js +625 -0
- package/templates/ssr-template/src/client.d.ts +2 -0
- package/templates/ssr-template/src/client.d.ts.map +1 -0
- package/templates/ssr-template/src/client.js +3 -0
- package/templates/ssr-template/src/server.d.ts +2 -0
- package/templates/ssr-template/src/server.d.ts.map +1 -0
- package/templates/ssr-template/src/server.js +29 -0
- package/templates/ssr-template/vite.config.d.ts +3 -0
- package/templates/ssr-template/vite.config.d.ts.map +1 -0
- package/templates/ssr-template/vite.config.js +30 -0
- package/templates/wasm/build-wasm.d.ts +2 -0
- package/templates/wasm/build-wasm.d.ts.map +1 -0
- package/templates/wasm/dist/assets/index-BNqTDBdE.d.ts +30 -0
- package/templates/wasm/dist/assets/index-BNqTDBdE.d.ts.map +1 -0
- package/templates/wasm/dist/wasm_exec.d.ts +1 -0
- package/templates/wasm/dist/wasm_exec.d.ts.map +1 -0
- package/templates/wasm/esbuild.config.d.ts +2 -0
- package/templates/wasm/esbuild.config.d.ts.map +1 -0
- package/templates/wasm/go/wasm_exec.d.ts +1 -0
- package/templates/wasm/go/wasm_exec.d.ts.map +1 -0
- package/templates/wasm/jsx-shim.d.ts +5 -0
- package/templates/wasm/jsx-shim.d.ts.map +1 -0
- package/templates/wasm/public/wasm_exec.d.ts +1 -0
- package/templates/wasm/public/wasm_exec.d.ts.map +1 -0
- package/templates/wasm/src/App.d.ts +2 -0
- package/templates/wasm/src/App.d.ts.map +1 -0
- package/templates/wasm/src/App.js +381 -0
- package/templates/wasm/src/client.d.ts +2 -0
- package/templates/wasm/src/client.d.ts.map +1 -0
- package/templates/wasm/src/client.js +210 -0
- package/templates/wasm/src/index.d.ts +2 -0
- package/templates/wasm/src/index.d.ts.map +1 -0
- package/templates/wasm/src/index.js +20 -0
- package/templates/wasm/src/server.d.ts +2 -0
- package/templates/wasm/src/server.d.ts.map +1 -0
- package/templates/wasm/src/server.js +131 -0
- package/templates/wasm/vite.config.d.ts +3 -0
- package/templates/wasm/vite.config.d.ts.map +1 -0
- package/templates/wasm/vite.config.js +36 -0
- package/templates/wasm/wasm-loader.d.ts +6 -0
- package/templates/wasm/wasm-loader.d.ts.map +1 -0
@@ -0,0 +1,210 @@
|
|
1
|
+
import { jsx, render } from 'frontend-hamroun';
|
2
|
+
import { loadGoWasm } from '../wasm-loader.js';
|
3
|
+
// WASM Demo Component
|
4
|
+
function WasmDemo() {
|
5
|
+
const [wasmReady, setWasmReady] = useState(false);
|
6
|
+
const [result, setResult] = useState('');
|
7
|
+
const [input1, setInput1] = useState('5');
|
8
|
+
const [input2, setInput2] = useState('3');
|
9
|
+
const [fibInput, setFibInput] = useState('10');
|
10
|
+
useEffect(() => {
|
11
|
+
loadWasm();
|
12
|
+
}, []);
|
13
|
+
const loadWasm = async () => {
|
14
|
+
try {
|
15
|
+
await loadGoWasm('/example.wasm');
|
16
|
+
setWasmReady(true);
|
17
|
+
setResult('✅ Go WASM module loaded successfully!');
|
18
|
+
}
|
19
|
+
catch (error) {
|
20
|
+
setResult(`❌ Failed to load WASM: ${error.message}`);
|
21
|
+
}
|
22
|
+
};
|
23
|
+
const testAdd = () => {
|
24
|
+
if (!wasmReady)
|
25
|
+
return;
|
26
|
+
try {
|
27
|
+
const num1 = parseFloat(input1);
|
28
|
+
const num2 = parseFloat(input2);
|
29
|
+
const result = window.add(num1, num2);
|
30
|
+
setResult(`Add result: ${num1} + ${num2} = ${result}`);
|
31
|
+
}
|
32
|
+
catch (error) {
|
33
|
+
setResult(`Error: ${error.message}`);
|
34
|
+
}
|
35
|
+
};
|
36
|
+
const testFibonacci = () => {
|
37
|
+
if (!wasmReady)
|
38
|
+
return;
|
39
|
+
try {
|
40
|
+
const n = parseInt(fibInput);
|
41
|
+
const result = window.fibonacci(n);
|
42
|
+
setResult(`Fibonacci(${n}) = ${result}`);
|
43
|
+
}
|
44
|
+
catch (error) {
|
45
|
+
setResult(`Error: ${error.message}`);
|
46
|
+
}
|
47
|
+
};
|
48
|
+
const testProcessArray = () => {
|
49
|
+
if (!wasmReady)
|
50
|
+
return;
|
51
|
+
try {
|
52
|
+
const testArray = [1, 2, 3, 4, 5];
|
53
|
+
const result = window.processArray(testArray);
|
54
|
+
const resultArray = Array.from(result);
|
55
|
+
setResult(`Process array [${testArray.join(', ')}] = [${resultArray.join(', ')}]`);
|
56
|
+
}
|
57
|
+
catch (error) {
|
58
|
+
setResult(`Error: ${error.message}`);
|
59
|
+
}
|
60
|
+
};
|
61
|
+
const testFormatMessage = () => {
|
62
|
+
if (!wasmReady)
|
63
|
+
return;
|
64
|
+
try {
|
65
|
+
const message = 'Hello from JavaScript!';
|
66
|
+
const result = window.formatMessage(message);
|
67
|
+
setResult(`Formatted: ${result}`);
|
68
|
+
}
|
69
|
+
catch (error) {
|
70
|
+
setResult(`Error: ${error.message}`);
|
71
|
+
}
|
72
|
+
};
|
73
|
+
const testPerformance = () => {
|
74
|
+
if (!wasmReady)
|
75
|
+
return;
|
76
|
+
try {
|
77
|
+
const iterations = 100000;
|
78
|
+
const startTime = performance.now();
|
79
|
+
const result = window.performanceBenchmark(iterations);
|
80
|
+
const endTime = performance.now();
|
81
|
+
setResult(`Performance test: ${result.message}\n` +
|
82
|
+
`Result: ${result.result}\n` +
|
83
|
+
`Time: ${(endTime - startTime).toFixed(2)}ms`);
|
84
|
+
}
|
85
|
+
catch (error) {
|
86
|
+
setResult(`Error: ${error.message}`);
|
87
|
+
}
|
88
|
+
};
|
89
|
+
const testTypeDemo = () => {
|
90
|
+
if (!wasmReady)
|
91
|
+
return;
|
92
|
+
try {
|
93
|
+
const result = window.typeDemo();
|
94
|
+
setResult(`Type demo results:\n` +
|
95
|
+
`String: ${result.string}\n` +
|
96
|
+
`Number: ${result.number}\n` +
|
97
|
+
`Boolean: ${result.boolean}\n` +
|
98
|
+
`Array: [${Array.from(result.array).join(', ')}]`);
|
99
|
+
}
|
100
|
+
catch (error) {
|
101
|
+
setResult(`Error: ${error.message}`);
|
102
|
+
}
|
103
|
+
};
|
104
|
+
return jsx('div', {
|
105
|
+
className: 'wasm-demo',
|
106
|
+
children: [
|
107
|
+
jsx('h1', { children: '🚀 Frontend Hamroun + Go WASM Demo' }),
|
108
|
+
jsx('div', {
|
109
|
+
className: 'status',
|
110
|
+
children: jsx('p', {
|
111
|
+
className: wasmReady ? 'ready' : 'loading',
|
112
|
+
children: wasmReady ? '✅ WASM Ready' : '⏳ Loading WASM...'
|
113
|
+
})
|
114
|
+
}),
|
115
|
+
jsx('div', {
|
116
|
+
className: 'controls',
|
117
|
+
children: [
|
118
|
+
jsx('h2', { children: '🧮 Arithmetic Operations' }),
|
119
|
+
jsx('div', {
|
120
|
+
className: 'input-group',
|
121
|
+
children: [
|
122
|
+
jsx('input', {
|
123
|
+
type: 'number',
|
124
|
+
value: input1,
|
125
|
+
onChange: (e) => setInput1(e.target.value),
|
126
|
+
placeholder: 'First number'
|
127
|
+
}),
|
128
|
+
jsx('span', { children: ' + ' }),
|
129
|
+
jsx('input', {
|
130
|
+
type: 'number',
|
131
|
+
value: input2,
|
132
|
+
onChange: (e) => setInput2(e.target.value),
|
133
|
+
placeholder: 'Second number'
|
134
|
+
}),
|
135
|
+
jsx('button', {
|
136
|
+
onClick: testAdd,
|
137
|
+
disabled: !wasmReady,
|
138
|
+
children: 'Calculate'
|
139
|
+
})
|
140
|
+
]
|
141
|
+
}),
|
142
|
+
jsx('h2', { children: '🔢 Fibonacci Sequence' }),
|
143
|
+
jsx('div', {
|
144
|
+
className: 'input-group',
|
145
|
+
children: [
|
146
|
+
jsx('input', {
|
147
|
+
type: 'number',
|
148
|
+
value: fibInput,
|
149
|
+
onChange: (e) => setFibInput(e.target.value),
|
150
|
+
placeholder: 'Fibonacci number'
|
151
|
+
}),
|
152
|
+
jsx('button', {
|
153
|
+
onClick: testFibonacci,
|
154
|
+
disabled: !wasmReady,
|
155
|
+
children: 'Calculate Fibonacci'
|
156
|
+
})
|
157
|
+
]
|
158
|
+
}),
|
159
|
+
jsx('h2', { children: '🔧 Advanced Functions' }),
|
160
|
+
jsx('div', {
|
161
|
+
className: 'button-group',
|
162
|
+
children: [
|
163
|
+
jsx('button', {
|
164
|
+
onClick: testProcessArray,
|
165
|
+
disabled: !wasmReady,
|
166
|
+
children: 'Process Array'
|
167
|
+
}),
|
168
|
+
jsx('button', {
|
169
|
+
onClick: testFormatMessage,
|
170
|
+
disabled: !wasmReady,
|
171
|
+
children: 'Format Message'
|
172
|
+
}),
|
173
|
+
jsx('button', {
|
174
|
+
onClick: testPerformance,
|
175
|
+
disabled: !wasmReady,
|
176
|
+
children: 'Performance Test'
|
177
|
+
}),
|
178
|
+
jsx('button', {
|
179
|
+
onClick: testTypeDemo,
|
180
|
+
disabled: !wasmReady,
|
181
|
+
children: 'Type Demo'
|
182
|
+
})
|
183
|
+
]
|
184
|
+
})
|
185
|
+
]
|
186
|
+
}),
|
187
|
+
jsx('div', {
|
188
|
+
className: 'result',
|
189
|
+
children: [
|
190
|
+
jsx('h3', { children: '📋 Result:' }),
|
191
|
+
jsx('pre', { children: result })
|
192
|
+
]
|
193
|
+
})
|
194
|
+
]
|
195
|
+
});
|
196
|
+
}
|
197
|
+
// App Component
|
198
|
+
function App() {
|
199
|
+
return jsx('div', {
|
200
|
+
className: 'app',
|
201
|
+
children: jsx(WasmDemo, {})
|
202
|
+
});
|
203
|
+
}
|
204
|
+
// Render the app
|
205
|
+
const appElement = document.getElementById('app');
|
206
|
+
if (appElement) {
|
207
|
+
render(jsx(App, {}), appElement);
|
208
|
+
}
|
209
|
+
// Import statements for hooks
|
210
|
+
import { useState, useEffect } from 'frontend-hamroun';
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":""}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { jsx, render } from 'frontend-hamroun';
|
2
|
+
import App from './App.tsx';
|
3
|
+
// Simple render without infinite loops
|
4
|
+
function startApp() {
|
5
|
+
const appElement = jsx(App, {});
|
6
|
+
const rootElement = document.getElementById('app');
|
7
|
+
if (rootElement) {
|
8
|
+
render(appElement, rootElement);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
console.error('Root element not found');
|
12
|
+
}
|
13
|
+
}
|
14
|
+
// Start when DOM is ready
|
15
|
+
if (document.readyState === 'loading') {
|
16
|
+
document.addEventListener('DOMContentLoaded', startApp);
|
17
|
+
}
|
18
|
+
else {
|
19
|
+
startApp();
|
20
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["server.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,131 @@
|
|
1
|
+
import { createServer } from 'frontend-hamroun';
|
2
|
+
import { loadGoWasmFromFile } from 'frontend-hamroun';
|
3
|
+
import path from 'path';
|
4
|
+
import { fileURLToPath } from 'url';
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
6
|
+
const __dirname = path.dirname(__filename);
|
7
|
+
// Create server instance
|
8
|
+
const server = createServer({
|
9
|
+
port: 3000,
|
10
|
+
staticDir: './public',
|
11
|
+
pagesDir: './src/pages',
|
12
|
+
apiDir: './src/api'
|
13
|
+
});
|
14
|
+
// Server-side WASM integration example
|
15
|
+
async function initServerWasm() {
|
16
|
+
try {
|
17
|
+
console.log('🔄 Initializing server-side Go WASM...');
|
18
|
+
const wasmPath = path.join(__dirname, '..', 'public', 'example.wasm');
|
19
|
+
const wasmInstance = await loadGoWasmFromFile(wasmPath, {
|
20
|
+
debug: true,
|
21
|
+
onLoad: (instance) => {
|
22
|
+
console.log('✅ Go WASM loaded on server side');
|
23
|
+
// Test server-side WASM functions
|
24
|
+
try {
|
25
|
+
if (instance.functions.add) {
|
26
|
+
const result = instance.functions.add(5, 3);
|
27
|
+
console.log('Server WASM test - add(5, 3):', result);
|
28
|
+
}
|
29
|
+
if (instance.functions.fibonacci) {
|
30
|
+
const fibResult = instance.functions.fibonacci(10);
|
31
|
+
console.log('Server WASM test - fibonacci(10):', fibResult);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
catch (error) {
|
35
|
+
console.log('Server WASM test functions not available:', error.message);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
});
|
39
|
+
// Make WASM instance available to API routes
|
40
|
+
server.getExpressApp().locals.wasm = wasmInstance;
|
41
|
+
}
|
42
|
+
catch (error) {
|
43
|
+
console.error('❌ Failed to initialize server-side WASM:', error);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
// API route example using server-side WASM
|
47
|
+
server.getExpressApp().get('/api/wasm/compute', async (req, res) => {
|
48
|
+
try {
|
49
|
+
const { operation, a, b } = req.query;
|
50
|
+
const wasmInstance = req.app.locals.wasm;
|
51
|
+
if (!wasmInstance) {
|
52
|
+
return res.status(500).json({ error: 'WASM not initialized' });
|
53
|
+
}
|
54
|
+
let result;
|
55
|
+
switch (operation) {
|
56
|
+
case 'add':
|
57
|
+
if (wasmInstance.functions.add) {
|
58
|
+
result = wasmInstance.functions.add(Number(a), Number(b));
|
59
|
+
}
|
60
|
+
else {
|
61
|
+
throw new Error('Add function not available');
|
62
|
+
}
|
63
|
+
break;
|
64
|
+
case 'fibonacci':
|
65
|
+
if (wasmInstance.functions.fibonacci) {
|
66
|
+
result = wasmInstance.functions.fibonacci(Number(a));
|
67
|
+
}
|
68
|
+
else {
|
69
|
+
throw new Error('Fibonacci function not available');
|
70
|
+
}
|
71
|
+
break;
|
72
|
+
default:
|
73
|
+
throw new Error('Unknown operation');
|
74
|
+
}
|
75
|
+
res.json({
|
76
|
+
success: true,
|
77
|
+
operation,
|
78
|
+
result,
|
79
|
+
serverTime: new Date().toISOString()
|
80
|
+
});
|
81
|
+
}
|
82
|
+
catch (error) {
|
83
|
+
res.status(400).json({
|
84
|
+
success: false,
|
85
|
+
error: error.message
|
86
|
+
});
|
87
|
+
}
|
88
|
+
});
|
89
|
+
// Health check endpoint
|
90
|
+
server.getExpressApp().get('/api/health', (req, res) => {
|
91
|
+
res.json({
|
92
|
+
status: 'healthy',
|
93
|
+
wasm: !!req.app.locals.wasm,
|
94
|
+
timestamp: new Date().toISOString()
|
95
|
+
});
|
96
|
+
});
|
97
|
+
// Start server
|
98
|
+
async function startServer() {
|
99
|
+
try {
|
100
|
+
// Initialize WASM first
|
101
|
+
await initServerWasm();
|
102
|
+
// Start the server
|
103
|
+
await server.start();
|
104
|
+
console.log('🚀 Server started successfully!');
|
105
|
+
console.log('📋 Available endpoints:');
|
106
|
+
console.log(' • http://localhost:3000 - Main app');
|
107
|
+
console.log(' • http://localhost:3000/api/health - Health check');
|
108
|
+
console.log(' • http://localhost:3000/api/wasm/compute - WASM compute API');
|
109
|
+
console.log('');
|
110
|
+
console.log('💡 Example API calls:');
|
111
|
+
console.log(' • /api/wasm/compute?operation=add&a=5&b=3');
|
112
|
+
console.log(' • /api/wasm/compute?operation=fibonacci&a=10');
|
113
|
+
}
|
114
|
+
catch (error) {
|
115
|
+
console.error('❌ Failed to start server:', error);
|
116
|
+
process.exit(1);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
// Graceful shutdown
|
120
|
+
process.on('SIGTERM', async () => {
|
121
|
+
console.log('🛑 Received SIGTERM, shutting down gracefully...');
|
122
|
+
await server.stop();
|
123
|
+
process.exit(0);
|
124
|
+
});
|
125
|
+
process.on('SIGINT', async () => {
|
126
|
+
console.log('🛑 Received SIGINT, shutting down gracefully...');
|
127
|
+
await server.stop();
|
128
|
+
process.exit(0);
|
129
|
+
});
|
130
|
+
// Start the server
|
131
|
+
startServer();
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"vite.config.d.ts","sourceRoot":"","sources":["vite.config.ts"],"names":[],"mappings":";AAGA,wBAkCG"}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { defineConfig } from 'vite';
|
2
|
+
export default defineConfig({
|
3
|
+
esbuild: {
|
4
|
+
jsx: 'transform',
|
5
|
+
jsxFactory: 'jsx',
|
6
|
+
jsxFragment: 'Fragment',
|
7
|
+
jsxImportSource: 'frontend-hamroun',
|
8
|
+
},
|
9
|
+
optimizeDeps: {
|
10
|
+
include: ['frontend-hamroun'],
|
11
|
+
exclude: []
|
12
|
+
},
|
13
|
+
server: {
|
14
|
+
fs: {
|
15
|
+
allow: ['..', '../..']
|
16
|
+
},
|
17
|
+
headers: {
|
18
|
+
'Cross-Origin-Embedder-Policy': 'require-corp',
|
19
|
+
'Cross-Origin-Opener-Policy': 'same-origin'
|
20
|
+
}
|
21
|
+
},
|
22
|
+
build: {
|
23
|
+
target: 'esnext',
|
24
|
+
rollupOptions: {
|
25
|
+
output: {
|
26
|
+
format: 'es'
|
27
|
+
}
|
28
|
+
}
|
29
|
+
},
|
30
|
+
resolve: {
|
31
|
+
alias: {
|
32
|
+
'frontend-hamroun/jsx-dev-runtime': 'frontend-hamroun',
|
33
|
+
'frontend-hamroun/jsx-runtime': 'frontend-hamroun'
|
34
|
+
}
|
35
|
+
}
|
36
|
+
});
|
@@ -0,0 +1,6 @@
|
|
1
|
+
export function loadGoWasm(wasmPath: any, options?: {}): Promise<any>;
|
2
|
+
export function isWasmReady(): boolean;
|
3
|
+
export function getWasmInstance(): any;
|
4
|
+
export function callGoFunction(functionName: any, ...args: any[]): any;
|
5
|
+
export function waitForWasm(timeout?: number): Promise<any>;
|
6
|
+
//# sourceMappingURL=wasm-loader.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"wasm-loader.d.ts","sourceRoot":"","sources":["wasm-loader.js"],"names":[],"mappings":"AAOA,sEA6CC;AAYD,uCAEC;AAED,uCAEC;AAGD,uEAUC;AAED,4DAiBC"}
|