frontend-hamroun 1.2.80 → 1.2.82

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.
Files changed (104) hide show
  1. package/bin/cli.js +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +1 -0
  4. package/dist/index.js.map +1 -1
  5. package/package.json +1 -1
  6. package/templates/basic-app/src/App.jsx +16 -0
  7. package/templates/basic-app/src/client.jsx +5 -0
  8. package/templates/basic-app/src/components/Counter.jsx +13 -0
  9. package/templates/basic-app/src/jsx-shim.js +3 -0
  10. package/templates/basic-app/src/jsx-shim.ts +7 -0
  11. package/templates/basic-app/src/main.jsx +98 -0
  12. package/templates/basic-app/src/server.js +47 -0
  13. package/templates/complete-app/api/hello.js +0 -0
  14. package/templates/complete-app/lib/frontend-hamroun.js +182 -0
  15. package/templates/complete-app/package.json +18 -0
  16. package/templates/complete-app/pages/about.js +119 -0
  17. package/templates/complete-app/pages/about.jsx +0 -0
  18. package/templates/complete-app/pages/index.js +157 -0
  19. package/templates/complete-app/pages/index.jsx +0 -0
  20. package/templates/complete-app/pages/wasm-demo.js +290 -0
  21. package/templates/complete-app/pages/wasm-demo.jsx +0 -0
  22. package/templates/complete-app/public/client.js +89 -0
  23. package/templates/complete-app/public/index.html +118 -0
  24. package/templates/complete-app/public/styles.css +76 -0
  25. package/templates/complete-app/server.js +226 -0
  26. package/templates/complete-app/src/App.tsx +59 -0
  27. package/templates/complete-app/src/client.tsx +18 -0
  28. package/templates/complete-app/src/server.ts +218 -0
  29. package/templates/complete-app/tsconfig.json +22 -0
  30. package/templates/complete-app/tsconfig.server.json +19 -0
  31. package/templates/{ssr-template → complete-app}/vite.config.js +16 -5
  32. package/templates/complete-app/vite.config.ts +30 -0
  33. package/templates/complete-app/wasm/build.bat +0 -0
  34. package/templates/complete-app/wasm/build.sh +0 -0
  35. package/templates/complete-app/wasm/example.go +0 -0
  36. package/templates/fullstack-app/build/main.css +874 -874
  37. package/templates/fullstack-app/build/main.css.map +7 -7
  38. package/templates/fullstack-app/build/main.js +996 -967
  39. package/templates/fullstack-app/build/main.js.map +7 -7
  40. package/templates/fullstack-app/package-lock.json +6301 -0
  41. package/templates/fullstack-app/public/styles.css +768 -768
  42. package/templates/go/example.go +154 -99
  43. package/templates/ssr-template/esbuild.config.js +33 -0
  44. package/templates/ssr-template/jsx-shim.js +1 -0
  45. package/templates/ssr-template/package.json +22 -16
  46. package/templates/ssr-template/src/App.tsx +12 -52
  47. package/templates/ssr-template/src/client.tsx +3 -17
  48. package/templates/ssr-template/src/server.ts +21 -204
  49. package/templates/ssr-template/tsconfig.json +10 -13
  50. package/templates/ssr-template/tsconfig.server.json +6 -14
  51. package/templates/wasm/build-wasm.js +228 -0
  52. package/templates/wasm/esbuild.config.js +63 -0
  53. package/templates/wasm/go/main.go +256 -0
  54. package/templates/wasm/go/wasm_exec.js +0 -0
  55. package/templates/wasm/index.html +97 -0
  56. package/templates/wasm/jsx-shim.js +9 -0
  57. package/templates/wasm/package-lock.json +5307 -0
  58. package/templates/wasm/package.json +42 -0
  59. package/templates/wasm/public/example.wasm +0 -0
  60. package/templates/{go-wasm-app/public/wasm → wasm/public}/wasm_exec.js +561 -561
  61. package/templates/wasm/src/App.tsx +564 -0
  62. package/templates/wasm/src/client.tsx +220 -0
  63. package/templates/wasm/src/index.tsx +21 -0
  64. package/templates/wasm/src/server.ts +145 -0
  65. package/templates/wasm/tsconfig.json +21 -0
  66. package/templates/wasm/tsconfig.node.json +13 -0
  67. package/templates/wasm/tsconfig.server.json +23 -0
  68. package/templates/wasm/vite.config.ts +56 -0
  69. package/templates/wasm/wasm-loader.js +103 -0
  70. package/templates/basic-app/bun.lock +0 -196
  71. package/templates/basic-app/docs/rapport_pfe.aux +0 -27
  72. package/templates/basic-app/docs/rapport_pfe.out +0 -10
  73. package/templates/basic-app/docs/rapport_pfe.pdf +0 -0
  74. package/templates/basic-app/docs/rapport_pfe.tex +0 -68
  75. package/templates/basic-app/docs/rapport_pfe.toc +0 -14
  76. package/templates/basic-app/package-lock.json +0 -4185
  77. package/templates/go-wasm-app/README.md +0 -38
  78. package/templates/go-wasm-app/babel.config.js +0 -15
  79. package/templates/go-wasm-app/build-client.js +0 -49
  80. package/templates/go-wasm-app/build-wasm.js +0 -237
  81. package/templates/go-wasm-app/package.json +0 -23
  82. package/templates/go-wasm-app/public/index.html +0 -128
  83. package/templates/go-wasm-app/public/styles.css +0 -197
  84. package/templates/go-wasm-app/public/wasm/example.wasm +0 -0
  85. package/templates/go-wasm-app/public/wasm/wasm_exec_node.js +0 -39
  86. package/templates/go-wasm-app/server.js +0 -521
  87. package/templates/go-wasm-app/src/App.jsx +0 -38
  88. package/templates/go-wasm-app/src/app.js +0 -153
  89. package/templates/go-wasm-app/src/client.js +0 -57
  90. package/templates/go-wasm-app/src/components/Footer.jsx +0 -13
  91. package/templates/go-wasm-app/src/components/Header.jsx +0 -19
  92. package/templates/go-wasm-app/src/components/WasmDemo.jsx +0 -120
  93. package/templates/go-wasm-app/src/main.jsx +0 -12
  94. package/templates/go-wasm-app/src/wasm/example.go +0 -75
  95. package/templates/go-wasm-app/tsconfig.server.json +0 -18
  96. package/templates/go-wasm-app/vite.config.js +0 -34
  97. package/templates/ssr-template/package-lock.json +0 -2478
  98. package/templates/ssr-template/public/index.html +0 -47
  99. package/templates/ssr-template/server.js +0 -369
  100. /package/templates/{ssr-template → complete-app}/client.js +0 -0
  101. /package/templates/{ssr-template → complete-app}/readme.md +0 -0
  102. /package/templates/{ssr-template → complete-app}/server.ts +0 -0
  103. /package/templates/{ssr-template → complete-app}/src/client.ts +0 -0
  104. /package/templates/{ssr-template → complete-app}/src/pages/index.tsx +0 -0
@@ -0,0 +1,256 @@
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "strings"
6
+ "syscall/js"
7
+ )
8
+
9
+ // Global variable to hold JS values for complex data exchange
10
+ var jsGlobal = js.Global()
11
+
12
+ // Hello function - greeting with name
13
+ func goHello(this js.Value, args []js.Value) interface{} {
14
+ if len(args) != 1 {
15
+ return js.ValueOf("Error: goHello requires exactly 1 argument")
16
+ }
17
+
18
+ name := args[0].String()
19
+ result := fmt.Sprintf("Hello, %s from Go WASM!", name)
20
+
21
+ fmt.Printf("Go WASM: goHello('%s') = '%s'\n", name, result)
22
+ return js.ValueOf(result)
23
+ }
24
+
25
+ // Add function - simple arithmetic
26
+ func goAdd(this js.Value, args []js.Value) interface{} {
27
+ if len(args) != 2 {
28
+ return js.ValueOf("Error: goAdd requires exactly 2 arguments")
29
+ }
30
+
31
+ a := args[0].Float()
32
+ b := args[1].Float()
33
+ result := a + b
34
+
35
+ fmt.Printf("Go WASM: goAdd(%f, %f) = %f\n", a, b, result)
36
+ return js.ValueOf(result)
37
+ }
38
+
39
+ // Multiply function - simple arithmetic
40
+ func goMultiply(this js.Value, args []js.Value) interface{} {
41
+ if len(args) != 2 {
42
+ return js.ValueOf("Error: goMultiply requires exactly 2 arguments")
43
+ }
44
+
45
+ a := args[0].Float()
46
+ b := args[1].Float()
47
+ result := a * b
48
+
49
+ fmt.Printf("Go WASM: goMultiply(%f, %f) = %f\n", a, b, result)
50
+ return js.ValueOf(result)
51
+ }
52
+
53
+ // Fibonacci function - recursive computation
54
+ func goFibonacci(this js.Value, args []js.Value) interface{} {
55
+ if len(args) != 1 {
56
+ return js.ValueOf("Error: goFibonacci requires exactly 1 argument")
57
+ }
58
+
59
+ n := int(args[0].Float())
60
+ if n < 0 {
61
+ return js.ValueOf("Error: goFibonacci requires non-negative number")
62
+ }
63
+
64
+ result := fibonacciCalc(n)
65
+ fmt.Printf("Go WASM: goFibonacci(%d) = %d\n", n, result)
66
+ return js.ValueOf(result)
67
+ }
68
+
69
+ // Prime check function
70
+ func goIsPrime(this js.Value, args []js.Value) interface{} {
71
+ if len(args) != 1 {
72
+ return js.ValueOf("Error: goIsPrime requires exactly 1 argument")
73
+ }
74
+
75
+ n := int(args[0].Float())
76
+ if n < 2 {
77
+ return js.ValueOf(false)
78
+ }
79
+ if n == 2 {
80
+ return js.ValueOf(true)
81
+ }
82
+ if n%2 == 0 {
83
+ return js.ValueOf(false)
84
+ }
85
+
86
+ for i := 3; i*i <= n; i += 2 {
87
+ if n%i == 0 {
88
+ return js.ValueOf(false)
89
+ }
90
+ }
91
+
92
+ fmt.Printf("Go WASM: goIsPrime(%d) = %t\n", n, true)
93
+ return js.ValueOf(true)
94
+ }
95
+
96
+ // Helper function for fibonacci calculation
97
+ func fibonacciCalc(n int) int {
98
+ if n <= 1 {
99
+ return n
100
+ }
101
+
102
+ a, b := 0, 1
103
+ for i := 2; i <= n; i++ {
104
+ a, b = b, a+b
105
+ }
106
+ return b
107
+ }
108
+
109
+ // Process array function - demonstrates array handling
110
+ func goProcessArray(this js.Value, args []js.Value) interface{} {
111
+ if len(args) != 1 {
112
+ return js.ValueOf("Error: goProcessArray requires exactly 1 argument")
113
+ }
114
+
115
+ jsArray := args[0]
116
+ if jsArray.Type() != js.TypeObject {
117
+ return js.ValueOf("Error: argument must be an array")
118
+ }
119
+
120
+ length := jsArray.Get("length").Int()
121
+ goSlice := make([]int, length)
122
+
123
+ // Convert JS array to Go slice
124
+ for i := 0; i < length; i++ {
125
+ goSlice[i] = int(jsArray.Index(i).Float())
126
+ }
127
+
128
+ // Process the slice (double each element and add index)
129
+ processedSlice := make([]interface{}, length)
130
+ for i, val := range goSlice {
131
+ processedSlice[i] = (val * 2) + i
132
+ }
133
+
134
+ fmt.Printf("Go WASM: goProcessArray([%s]) = [", strings.Trim(fmt.Sprint(goSlice), "[]"))
135
+ for i, val := range processedSlice {
136
+ if i > 0 {
137
+ fmt.Printf(" ")
138
+ }
139
+ fmt.Printf("%v", val)
140
+ }
141
+ fmt.Printf("]\n")
142
+
143
+ // Convert back to JS array
144
+ result := jsGlobal.Get("Array").New(length)
145
+ for i, val := range processedSlice {
146
+ result.SetIndex(i, val)
147
+ }
148
+
149
+ return result
150
+ }
151
+
152
+ // Calculate PI using series approximation
153
+ func goCalculatePI(this js.Value, args []js.Value) interface{} {
154
+ if len(args) != 1 {
155
+ return js.ValueOf("Error: goCalculatePI requires exactly 1 argument")
156
+ }
157
+
158
+ iterations := int(args[0].Float())
159
+ pi := 0.0
160
+
161
+ for i := 0; i < iterations; i++ {
162
+ term := 1.0 / float64(2*i+1)
163
+ if i%2 == 1 {
164
+ term = -term
165
+ }
166
+ pi += term
167
+ }
168
+
169
+ result := pi * 4
170
+ fmt.Printf("Go WASM: goCalculatePI(%d iterations) = %f\n", iterations, result)
171
+ return js.ValueOf(result)
172
+ }
173
+
174
+ // Performance benchmark function
175
+ func goPerformanceBenchmark(this js.Value, args []js.Value) interface{} {
176
+ if len(args) != 1 {
177
+ return js.ValueOf("Error: goPerformanceBenchmark requires exactly 1 argument")
178
+ }
179
+
180
+ iterations := int(args[0].Float())
181
+
182
+ // Simple computational benchmark
183
+ sum := 0
184
+ for i := 0; i < iterations; i++ {
185
+ sum += i * i
186
+ }
187
+
188
+ // Convert Go map to JS object
189
+ jsResult := jsGlobal.Get("Object").New()
190
+ jsResult.Set("iterations", js.ValueOf(iterations))
191
+ jsResult.Set("result", js.ValueOf(sum))
192
+ jsResult.Set("message", js.ValueOf(fmt.Sprintf("Completed %d iterations in Go WASM", iterations)))
193
+
194
+ fmt.Printf("Go WASM: goPerformanceBenchmark(%d) = %d\n", iterations, sum)
195
+ return jsResult
196
+ }
197
+
198
+ // String utilities function
199
+ func goStringUtils(this js.Value, args []js.Value) interface{} {
200
+ if len(args) != 1 {
201
+ return js.ValueOf("Error: goStringUtils requires exactly 1 argument")
202
+ }
203
+
204
+ input := args[0].String()
205
+
206
+ // Create result object with various string operations
207
+ result := jsGlobal.Get("Object").New()
208
+ result.Set("original", js.ValueOf(input))
209
+ result.Set("uppercase", js.ValueOf(strings.ToUpper(input)))
210
+ result.Set("lowercase", js.ValueOf(strings.ToLower(input)))
211
+ result.Set("reversed", js.ValueOf(reverseString(input)))
212
+ result.Set("length", js.ValueOf(len(input)))
213
+ result.Set("wordCount", js.ValueOf(len(strings.Fields(input))))
214
+
215
+ fmt.Printf("Go WASM: goStringUtils('%s') completed\n", input)
216
+ return result
217
+ }
218
+
219
+ // Helper function to reverse a string
220
+ func reverseString(s string) string {
221
+ runes := []rune(s)
222
+ for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
223
+ runes[i], runes[j] = runes[j], runes[i]
224
+ }
225
+ return string(runes)
226
+ }
227
+
228
+ // Initialize and register functions
229
+ func main() {
230
+ fmt.Println("🚀 Go WASM module initializing...")
231
+
232
+ // Register all functions to the global JS scope with "go" prefix
233
+ jsGlobal.Set("goHello", js.FuncOf(goHello))
234
+ jsGlobal.Set("goAdd", js.FuncOf(goAdd))
235
+ jsGlobal.Set("goMultiply", js.FuncOf(goMultiply))
236
+ jsGlobal.Set("goFibonacci", js.FuncOf(goFibonacci))
237
+ jsGlobal.Set("goIsPrime", js.FuncOf(goIsPrime))
238
+ jsGlobal.Set("goProcessArray", js.FuncOf(goProcessArray))
239
+ jsGlobal.Set("goCalculatePI", js.FuncOf(goCalculatePI))
240
+ jsGlobal.Set("goPerformanceBenchmark", js.FuncOf(goPerformanceBenchmark))
241
+ jsGlobal.Set("goStringUtils", js.FuncOf(goStringUtils))
242
+
243
+ fmt.Println("✅ Go WASM functions registered:")
244
+ fmt.Println(" • goHello(name) - Greeting function")
245
+ fmt.Println(" • goAdd(a, b) - Addition")
246
+ fmt.Println(" • goMultiply(a, b) - Multiplication")
247
+ fmt.Println(" • goFibonacci(n) - Fibonacci sequence")
248
+ fmt.Println(" • goIsPrime(n) - Prime number check")
249
+ fmt.Println(" • goProcessArray(arr) - Array processing")
250
+ fmt.Println(" • goCalculatePI(iterations) - PI calculation")
251
+ fmt.Println(" • goPerformanceBenchmark(n) - Performance testing")
252
+ fmt.Println(" • goStringUtils(str) - String utilities")
253
+
254
+ // Keep the program running
255
+ select {}
256
+ }
File without changes
@@ -0,0 +1,97 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Frontend Hamroun + Go WASM</title>
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
11
+ }
12
+
13
+ .loading-fallback {
14
+ display: flex;
15
+ justify-content: center;
16
+ align-items: center;
17
+ min-height: 100vh;
18
+ flex-direction: column;
19
+ background: #f7f7f7;
20
+ }
21
+
22
+ .loading-spinner {
23
+ width: 40px;
24
+ height: 40px;
25
+ border: 4px solid #f3f3f3;
26
+ border-top: 4px solid #007acc;
27
+ border-radius: 50%;
28
+ animation: spin 1s linear infinite;
29
+ margin-bottom: 20px;
30
+ }
31
+
32
+ @keyframes spin {
33
+ 0% { transform: rotate(0deg); }
34
+ 100% { transform: rotate(360deg); }
35
+ }
36
+ </style>
37
+ </head>
38
+ <body>
39
+ <div id="app">
40
+ <div class="loading-fallback">
41
+ <div class="loading-spinner"></div>
42
+ <h2>Loading Frontend Hamroun + WASM...</h2>
43
+ <p>Initializing application and WebAssembly runtime...</p>
44
+ </div>
45
+ </div>
46
+
47
+ <!-- Go WASM Runtime -->
48
+ <script src="/wasm_exec.js"></script>
49
+
50
+ <!-- Application -->
51
+ <script type="module">
52
+ import { jsx, render } from 'frontend-hamroun';
53
+ import App from './src/App.tsx';
54
+
55
+ // Wait for WASM runtime to be available
56
+ function waitForGo() {
57
+ return new Promise((resolve) => {
58
+ if (window.Go) {
59
+ resolve();
60
+ } else {
61
+ setTimeout(() => waitForGo().then(resolve), 50);
62
+ }
63
+ });
64
+ }
65
+
66
+ async function startApp() {
67
+ try {
68
+ // Wait for Go WASM runtime
69
+ await waitForGo();
70
+
71
+ // Render the app
72
+ const appElement = jsx(App, {});
73
+ render(appElement, document.getElementById('app'));
74
+ } catch (error) {
75
+ console.error('Failed to start app:', error);
76
+ document.getElementById('app').innerHTML = `
77
+ <div class="loading-fallback">
78
+ <h2 style="color: #dc2626;">Application Error</h2>
79
+ <p>Failed to initialize the application. Check the console for more details.</p>
80
+ <button onclick="window.location.reload()" style="
81
+ background: #007acc;
82
+ color: white;
83
+ border: none;
84
+ padding: 10px 20px;
85
+ border-radius: 5px;
86
+ cursor: pointer;
87
+ margin-top: 10px;
88
+ ">Reload Page</button>
89
+ </div>
90
+ `;
91
+ }
92
+ }
93
+
94
+ startApp();
95
+ </script>
96
+ </body>
97
+ </html>
@@ -0,0 +1,9 @@
1
+ // JSX Runtime shim for Frontend Hamroun
2
+ import { jsx, jsxs, Fragment } from 'frontend-hamroun';
3
+
4
+ // Make JSX runtime available globally
5
+ globalThis.jsx = jsx;
6
+ globalThis.jsxs = jsxs;
7
+ globalThis.Fragment = Fragment;
8
+
9
+ export { jsx, jsxs, Fragment };