|
| 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>RayforceDB Minimal Example</title> |
| 7 | + <style> |
| 8 | + body { |
| 9 | + font-family: system-ui, sans-serif; |
| 10 | + max-width: 800px; |
| 11 | + margin: 2rem auto; |
| 12 | + padding: 0 1rem; |
| 13 | + background: #1a1a2e; |
| 14 | + color: #eee; |
| 15 | + } |
| 16 | + h1 { color: #e9a033; } |
| 17 | + pre { |
| 18 | + background: #0d0d1a; |
| 19 | + padding: 1rem; |
| 20 | + border-radius: 8px; |
| 21 | + overflow-x: auto; |
| 22 | + } |
| 23 | + code { color: #4ec9b0; } |
| 24 | + .result { color: #9cdcfe; } |
| 25 | + button { |
| 26 | + background: #e9a033; |
| 27 | + color: #1a1a2e; |
| 28 | + border: none; |
| 29 | + padding: 0.5rem 1rem; |
| 30 | + border-radius: 4px; |
| 31 | + cursor: pointer; |
| 32 | + font-weight: bold; |
| 33 | + } |
| 34 | + button:hover { background: #f0b85a; } |
| 35 | + #output { |
| 36 | + margin-top: 1rem; |
| 37 | + padding: 1rem; |
| 38 | + background: #0d0d1a; |
| 39 | + border-radius: 8px; |
| 40 | + min-height: 100px; |
| 41 | + } |
| 42 | + </style> |
| 43 | +</head> |
| 44 | +<body> |
| 45 | + <h1>⚡ RayforceDB via CDN</h1> |
| 46 | + <p>Using <code>https://unpkg.com/rayforce-wasm</code></p> |
| 47 | + |
| 48 | + <button onclick="runDemo()">Run Demo</button> |
| 49 | + |
| 50 | + <div id="output">Click "Run Demo" to start...</div> |
| 51 | + |
| 52 | + <!-- Load RayforceDB from CDN --> |
| 53 | + <script type="module"> |
| 54 | + import createRayforce from 'https://unpkg.com/rayforce-wasm@0.1.0/dist/rayforce.js'; |
| 55 | + |
| 56 | + window.runDemo = async function() { |
| 57 | + const output = document.getElementById('output'); |
| 58 | + output.innerHTML = 'Loading WASM...'; |
| 59 | + |
| 60 | + try { |
| 61 | + // Initialize RayforceDB |
| 62 | + const rf = await createRayforce(); |
| 63 | + |
| 64 | + // Helper to evaluate and format result |
| 65 | + const evaluate = (expr) => { |
| 66 | + const result = rf._eval_str(expr); |
| 67 | + return rf.UTF8ToString(rf._strof_obj(result)); |
| 68 | + }; |
| 69 | + |
| 70 | + let results = []; |
| 71 | + |
| 72 | + // 1. Simple evaluation |
| 73 | + results.push('📊 <b>Evaluate expressions:</b>'); |
| 74 | + results.push(`(sum [1 2 3 4 5]) = ${evaluate('(sum [1 2 3 4 5])')}`); |
| 75 | + results.push(`(avg [10 20 30]) = ${evaluate('(avg [10 20 30])')}`); |
| 76 | + results.push(`(til 10) = ${evaluate('(til 10)')}`); |
| 77 | + |
| 78 | + // 2. Vector operations |
| 79 | + results.push(''); |
| 80 | + results.push('🔢 <b>Vector operations:</b>'); |
| 81 | + results.push(`(* [1 2 3] [4 5 6]) = ${evaluate('(* [1 2 3] [4 5 6])')}`); |
| 82 | + results.push(`(reverse [1 2 3 4 5]) = ${evaluate('(reverse [1 2 3 4 5])')}`); |
| 83 | + |
| 84 | + // 3. Lambda |
| 85 | + results.push(''); |
| 86 | + results.push('λ <b>Lambda functions:</b>'); |
| 87 | + results.push(`((fn [x] (* x x)) 7) = ${evaluate('((fn [x] (* x x)) 7)')}`); |
| 88 | + |
| 89 | + output.innerHTML = '<pre>' + results.join('\n') + '</pre>'; |
| 90 | + |
| 91 | + } catch (err) { |
| 92 | + output.innerHTML = `<pre style="color: #ff6b6b;">Error: ${err.message}</pre>`; |
| 93 | + } |
| 94 | + }; |
| 95 | + </script> |
| 96 | +</body> |
| 97 | +</html> |
0 commit comments