frontend-hamroun 1.2.70 → 1.2.72

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.
@@ -0,0 +1,57 @@
1
+ import { hydrate } from 'frontend-hamroun';
2
+ import App from './App.jsx';
3
+
4
+ // Get initial state from server
5
+ const initialState = window.__INITIAL_STATE__ || {
6
+ path: window.location.pathname,
7
+ ssrRendered: false,
8
+ wasmAvailable: false
9
+ };
10
+
11
+ // Simple client-side script for hydration
12
+ console.log('Client-side script loaded');
13
+ console.log('Initial state:', window.__INITIAL_STATE__);
14
+
15
+ // Wait for DOMContentLoaded to ensure the DOM is ready
16
+ document.addEventListener('DOMContentLoaded', () => {
17
+ // Hydrate the application
18
+ hydrate(<App initialState={initialState} />, document.getElementById('root'));
19
+ console.log('Client-side hydration complete');
20
+
21
+ if (window.__INITIAL_STATE__) {
22
+ console.log('Hydrating with initial state:', window.__INITIAL_STATE__);
23
+
24
+ // For now, we'll just display a message that we've loaded on the client
25
+ const root = document.getElementById('root');
26
+
27
+ // Add a "Client Hydrated" indicator
28
+ const clientIndicator = document.createElement('div');
29
+ clientIndicator.className = 'client-indicator';
30
+ clientIndicator.textContent = 'Client-Side Hydration Active';
31
+ clientIndicator.style.backgroundColor = '#4caf50';
32
+ clientIndicator.style.color = 'white';
33
+ clientIndicator.style.padding = '10px';
34
+ clientIndicator.style.borderRadius = '4px';
35
+ clientIndicator.style.margin = '10px 0';
36
+ clientIndicator.style.textAlign = 'center';
37
+
38
+ root.appendChild(clientIndicator);
39
+
40
+ // Load WASM if needed
41
+ if (typeof window.Go !== 'undefined') {
42
+ console.log('Go WASM runtime detected, initializing WASM module');
43
+
44
+ // This will be replaced with proper WASM loading in a future step
45
+ const wasmInfo = document.createElement('div');
46
+ wasmInfo.textContent = 'WASM runtime loaded successfully';
47
+ wasmInfo.style.backgroundColor = '#2196f3';
48
+ wasmInfo.style.color = 'white';
49
+ wasmInfo.style.padding = '10px';
50
+ wasmInfo.style.borderRadius = '4px';
51
+ wasmInfo.style.margin = '10px 0';
52
+ wasmInfo.style.textAlign = 'center';
53
+
54
+ root.appendChild(wasmInfo);
55
+ }
56
+ }
57
+ });
@@ -0,0 +1,75 @@
1
+ //go:build js && wasm
2
+ // +build js,wasm
3
+
4
+ package main
5
+
6
+ import (
7
+ "encoding/json"
8
+ "fmt"
9
+ "syscall/js"
10
+ )
11
+
12
+ // Example Go function to be called from JavaScript
13
+ func add(this js.Value, args []js.Value) interface{} {
14
+ if len(args) != 2 {
15
+ return js.ValueOf("Error: Expected two arguments")
16
+ }
17
+
18
+ a := args[0].Int()
19
+ b := args[1].Int()
20
+ return js.ValueOf(a + b)
21
+ }
22
+
23
+ // Process complex data in Go
24
+ func processData(this js.Value, args []js.Value) interface{} {
25
+ if len(args) == 0 {
26
+ return js.ValueOf("Error: Expected at least one argument")
27
+ }
28
+
29
+ // Get input data
30
+ data := args[0]
31
+ if data.Type() != js.TypeObject {
32
+ return js.ValueOf("Error: Expected JSON object")
33
+ }
34
+
35
+ // Convert JS object to Go map
36
+ jsonStr := js.Global().Get("JSON").Call("stringify", data).String()
37
+ var inputMap map[string]interface{}
38
+ if err := json.Unmarshal([]byte(jsonStr), &inputMap); err != nil {
39
+ return js.ValueOf(fmt.Sprintf("Error parsing JSON: %s", err.Error()))
40
+ }
41
+
42
+ // Add new fields
43
+ inputMap["processed"] = true
44
+ inputMap["processor"] = "Go WASM"
45
+
46
+ // Add some computed fields
47
+ if values, ok := inputMap["values"].([]interface{}); ok {
48
+ sum := 0.0
49
+ for _, v := range values {
50
+ if num, ok := v.(float64); ok {
51
+ sum += num
52
+ }
53
+ }
54
+ inputMap["sum"] = sum
55
+ }
56
+
57
+ // Convert back to JS
58
+ resultJSON, err := json.Marshal(inputMap)
59
+ if err != nil {
60
+ return js.ValueOf(fmt.Sprintf("Error generating JSON: %s", err.Error()))
61
+ }
62
+
63
+ return js.ValueOf(string(resultJSON))
64
+ }
65
+
66
+ func main() {
67
+ fmt.Println("Go WASM Module initialized")
68
+
69
+ // Register functions to be callable from JavaScript
70
+ js.Global().Set("goAdd", js.FuncOf(add))
71
+ js.Global().Set("goProcessData", js.FuncOf(processData))
72
+
73
+ // Keep the program running
74
+ <-make(chan bool)
75
+ }
@@ -4,8 +4,9 @@ import { resolve } from 'path';
4
4
  export default defineConfig({
5
5
  // Configure JSX
6
6
  esbuild: {
7
- jsxFactory: 'jsx',
8
- jsxFragment: 'Fragment'
7
+ jsxFactory: 'createElement',
8
+ jsxFragment: 'Fragment',
9
+ jsxInject: `import { createElement, Fragment } from 'frontend-hamroun'`
9
10
  },
10
11
 
11
12
  // Configure build
@@ -14,12 +15,17 @@ export default defineConfig({
14
15
  emptyOutDir: true,
15
16
  rollupOptions: {
16
17
  input: {
17
- main: resolve(__dirname, 'public/index.html')
18
+ client: resolve(__dirname, 'src/client.js')
19
+ },
20
+ output: {
21
+ entryFileNames: 'assets/[name].js',
22
+ chunkFileNames: 'assets/[name]-[hash].js',
23
+ assetFileNames: 'assets/[name]-[hash].[ext]'
18
24
  }
19
25
  }
20
26
  },
21
27
 
22
- // Resolve aliases
28
+ // Resolve aliases for better imports
23
29
  resolve: {
24
30
  alias: {
25
31
  '@': resolve(__dirname, 'src')