plainscript-lang 1.0.3 → 1.0.36

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 (93) hide show
  1. package/README.md +836 -188
  2. package/compiler/cli.js +68 -4
  3. package/compiler/dependency-detector.js +6 -2
  4. package/compiler/generator.js +737 -51
  5. package/compiler/lexer.js +12 -0
  6. package/compiler/parser.js +184 -14
  7. package/compiler/version.js +1 -1
  8. package/docs/CAPABILITY_GAP_AUDIT.md +32 -5
  9. package/docs/GAME-PROMPT.md +915 -0
  10. package/docs/PLAINSCRIPT-SPEC.md +264 -3
  11. package/docs/index.html +41 -33
  12. package/docs/logo-pln.jpg +0 -0
  13. package/docs/visualization-example.svg +32 -0
  14. package/docs/website/script.js +130 -1
  15. package/docs/website/style.css +253 -122
  16. package/examples/ai-providers.pln +1 -1
  17. package/examples/arrays.pln +1 -1
  18. package/examples/async-errors.pln +1 -1
  19. package/examples/auth-api.pln +1 -1
  20. package/examples/auth-sessions.pln +1 -1
  21. package/examples/basics.pln +1 -1
  22. package/examples/bots.pln +1 -1
  23. package/examples/browser-interactive/README.md +29 -0
  24. package/examples/browser-interactive/public/index.html +83 -0
  25. package/examples/browser-interactive/public/interactive.js +27 -0
  26. package/examples/browser-interactive/src/interactive.pln +34 -0
  27. package/examples/cache-and-jobs.pln +1 -1
  28. package/examples/cache-schedule.pln +1 -1
  29. package/examples/canvas-game/README.md +34 -0
  30. package/examples/canvas-game/public/game.js +131 -0
  31. package/examples/canvas-game/public/index.html +48 -0
  32. package/examples/canvas-game/src/game.pln +139 -0
  33. package/examples/collections.pln +1 -1
  34. package/examples/concurrency.pln +1 -1
  35. package/examples/conditions.pln +1 -1
  36. package/examples/database.pln +1 -1
  37. package/examples/day2.pln +1 -1
  38. package/examples/day3.pln +1 -1
  39. package/examples/deployment.pln +1 -1
  40. package/examples/email-send.pln +1 -1
  41. package/examples/error-handling.pln +1 -1
  42. package/examples/expressions.pln +1 -1
  43. package/examples/file-uploads.pln +1 -1
  44. package/examples/files-and-config.pln +1 -1
  45. package/examples/files.pln +1 -1
  46. package/examples/football-backend/app.pln +1 -1
  47. package/examples/functions.pln +1 -1
  48. package/examples/hello.pln +1 -1
  49. package/examples/http-client.pln +1 -1
  50. package/examples/http.pln +1 -1
  51. package/examples/id-verification/app.pln +1 -1
  52. package/examples/javascript-library/README.md +54 -0
  53. package/examples/javascript-library/package-lock.json +21 -0
  54. package/examples/javascript-library/package.json +8 -0
  55. package/examples/javascript-library/public/config.json +4 -0
  56. package/examples/javascript-library/public/index.html +40 -0
  57. package/examples/javascript-library/src/interop.pln +53 -0
  58. package/examples/json.pln +1 -1
  59. package/examples/loops.pln +1 -1
  60. package/examples/modules/app.pln +1 -1
  61. package/examples/modules/main.pln +1 -1
  62. package/examples/modules/math.pln +1 -1
  63. package/examples/mongo.pln +1 -1
  64. package/examples/objects.pln +1 -1
  65. package/examples/ocr.pln +1 -1
  66. package/examples/packages.pln +1 -1
  67. package/examples/record-kinds.pln +1 -1
  68. package/examples/records.pln +1 -1
  69. package/examples/rest-api-fetch.pln +1 -1
  70. package/examples/rest-api.pln +1 -1
  71. package/examples/scheduled-tasks.pln +1 -1
  72. package/examples/search-and-filter.pln +1 -1
  73. package/examples/server.pln +1 -1
  74. package/examples/sessions-and-cookies.pln +1 -1
  75. package/examples/sqlite.pln +1 -1
  76. package/examples/start.pln +1 -1
  77. package/examples/stdlib.pln +1 -1
  78. package/examples/string-verbs.pln +1 -1
  79. package/examples/telegram-ai-bot.pln +1 -1
  80. package/examples/telegram-bot.pln +1 -1
  81. package/examples/testing.pln +1 -1
  82. package/examples/three-dimensional/README.md +51 -0
  83. package/examples/three-dimensional/public/index.html +33 -0
  84. package/examples/three-dimensional/src/scene.pln +34 -0
  85. package/examples/visualization.pln +12 -0
  86. package/examples/web-api.pln +1 -1
  87. package/examples/web-app.pln +1 -1
  88. package/examples/websocket-server.pln +1 -1
  89. package/examples/websocket.pln +1 -1
  90. package/examples/whatsapp-bot/pairing.pln +24 -2
  91. package/examples/whatsapp-bot/qr.pln +18 -2
  92. package/package.json +5 -3
  93. package/docs/logo.jpg +0 -0
@@ -1,4 +1,4 @@
1
- # PlainScript 1.0.3 language specification
1
+ # PlainScript 1.0.36 language specification
2
2
 
3
3
  This reference covers the syntax implemented by `compiler/lexer.js` and
4
4
  `compiler/parser.js`. The runtime it generates lives in
@@ -303,13 +303,273 @@ Inside a Telegram handler, `message`, `text`, `args`, `matches`, `chat`,
303
303
  `reply "text"`; provider-backed replies can use `chatWith` before `reply`.
304
304
  `telegramCall(method, params)` calls any Telegram Bot API method.
305
305
 
306
- WhatsApp uses `whatsapp bot ... done`, with `auth`, `login qr`, `login
307
- pairing`, and `on message` clauses. OCR uses:
306
+ ### WhatsApp
307
+
308
+ WhatsApp bots are declared with a `whatsapp bot ... done` block. The block
309
+ accepts the following clauses:
310
+
311
+ | Clause | Purpose |
312
+ |--------|---------|
313
+ | `auth "<folder>"` | Path where session credentials persist across restarts. |
314
+ | `use baileys "<pkg>"` | Optional. Override the Baileys package (default: `@qwerty-xcv/baileys`). |
315
+ | `login qr` | Authenticate by scanning a QR code in the terminal. |
316
+ | `login pairing "<phone>"` | Authenticate by entering a phone number (digits only, no `+`). The argument may also be an expression such as `env("WHATSAPP_PHONE")`. |
317
+ | `on message ... done` | Handler that fires for every incoming message. |
318
+
319
+ Inside `on message` the incoming record is bound to `message`. Useful fields
320
+ include `message.text`, `message.type`, `message.mtype`, `message.caption`,
321
+ `message.buttonId`, `message.chat`, `message.sender`, `message.name`,
322
+ `message.id`, `message.time`, and `message.isGroup`.
323
+
324
+ **Pairing login example:**
325
+
326
+ ```plainscript
327
+ whatsapp bot
328
+ auth "plain-script-whatsapp"
329
+ use baileys "@qwerty-xcv/baileys"
330
+ login pairing "2348012345678"
331
+ on message
332
+ if message.text is "/start"
333
+ reply "Welcome!"
334
+ done
335
+ if message.text is "/help"
336
+ reply "Available commands:\n/start\n/help"
337
+ done
338
+ done
339
+ done
340
+ ```
341
+
342
+ **QR login example:**
343
+
344
+ ```plainscript
345
+ whatsapp bot
346
+ auth "plain-script-whatsapp"
347
+ login qr
348
+ on message
349
+ if message.text is "/start"
350
+ reply "Welcome"
351
+ done
352
+ if message.type is "image"
353
+ download "media/photo.jpg"
354
+ reply "Saved your photo!"
355
+ done
356
+ if message.type is "button"
357
+ reply "You chose: " + message.buttonId
358
+ done
359
+ done
360
+ done
361
+ ```
362
+
363
+ #### Sending different message types
364
+
365
+ Inside `on message` you can branch on `message.type` to handle text, images,
366
+ documents, buttons, lists, and more. The following helpers are available:
367
+
368
+ | Statement | Effect |
369
+ |-----------|--------|
370
+ | `reply <value>` | Send a plain-text reply. |
371
+ | `reply <value> with buttons ... done` | Send interactive buttons. |
372
+ | `download "<path>"` | Save incoming media (image, audio, document …) to disk. |
373
+ | `log message` | Print the full message record for debugging. |
374
+
375
+ `message.type` values include `"text"`, `"image"`, `"video"`, `"audio"`,
376
+ `"document"`, `"sticker"`, `"button"`, `"list"`, `"template-button"`,
377
+ `"reaction"`, `"contact"`, `"contacts"`, `"location"`, `"live-location"`,
378
+ `"poll"`, `"group-invite"`, and `"other"`.
379
+
380
+ **Full example — media, buttons, and list replies:**
381
+
382
+ ```plainscript
383
+ whatsapp bot
384
+ auth "plain-script-whatsapp"
385
+ use baileys "@qwerty-xcv/baileys"
386
+ login pairing env("WHATSAPP_PHONE")
387
+ on message
388
+ log message
389
+ if message.text is "/menu"
390
+ reply "Choose a topic" with buttons
391
+ "Hours" -> "hours"
392
+ "Pricing" -> "pricing"
393
+ "Human" -> "human"
394
+ done
395
+ done
396
+ if message.type is "image"
397
+ download "downloads/photo.jpg"
398
+ reply "Got your picture. We saved it for the team."
399
+ done
400
+ if message.type is "document"
401
+ download "downloads/file.bin"
402
+ reply "We received your document."
403
+ done
404
+ if message.type is "button"
405
+ reply "You chose: " + message.buttonId
406
+ done
407
+ if message.type is "list"
408
+ reply "You picked: " + message.buttonId
409
+ done
410
+ done
411
+ done
412
+ ```
413
+
414
+ OCR uses:
308
415
 
309
416
  ```plainscript
310
417
  ocr path of file as text
311
418
  ```
312
419
 
420
+ ## Images and visualizations
421
+
422
+ The standard library creates dependency-free SVG images:
423
+
424
+ ```plainscript
425
+ remember labels as ["Jan", "Feb", "Mar"]
426
+ remember values as [12, 18, 27]
427
+ remember chart as barChart("Monthly signups", labels, values)
428
+ saveImage("signups.svg", chart)
429
+ ```
430
+
431
+ The available helpers are:
432
+
433
+ | Function | Result |
434
+ | --- | --- |
435
+ | `svgImage(width, height, markup, options)` | An SVG image string containing custom markup. |
436
+ | `barChart(title, labels, values, options)` | An SVG bar chart. |
437
+ | `lineChart(title, labels, values, options)` | An SVG line chart. |
438
+ | `saveImage(path, image)` | Writes an SVG image string to disk and returns the path. |
439
+ | `imageDataUri(image)` | Converts an SVG image string to a browser data URI. |
440
+
441
+ Chart options may include `width`, `height`, `background`, `foreground`,
442
+ `grid`, `accent`, and `muted`. Image values are strings, so they can also be
443
+ returned from a route or inserted into HTML.
444
+
445
+ ## Browser and games
446
+
447
+ PlainScript compiles to Plain JavaScript that runs in modern browsers. A
448
+ `web app` can serve the page itself, or you compile a `.pln` to `game.js` and
449
+ serve it with any static host. The tested workflows are:
450
+
451
+ 1. **Static**, served by PlainScript — `web app` + `serve folder "public"` +
452
+ a `reply file` route that returns `index.html`:
453
+
454
+ ```plainscript
455
+ web app
456
+ serve folder "public"
457
+ route get "/"
458
+ reply file "public/index.html"
459
+ done
460
+ start 8000
461
+ ```
462
+
463
+ 2. **Static**, any host — `node compiler/cli.js build game.pln -o public/game.js`
464
+ and include `<script src="game.js">` after the canvas and any CDN globals.
465
+
466
+ Canvas apps use the same value/property interop as everything else — canvas
467
+ state is assigned with `becomes`, then a draw call runs:
468
+
469
+ ```plainscript
470
+ remember canvas as document.getElementById("game")
471
+ remember ctx as canvas.getContext("2d")
472
+ ctx.fillStyle becomes "#0d1117"
473
+ ctx.fillRect(0, 0, 320, 240)
474
+ ```
475
+
476
+ Animation is `requestAnimationFrame`. Two native loop forms: `every frame`
477
+ (timing-agnostic) and an explicit rAF callback with delta seconds for
478
+ frame-rate-independent movement — see `docs/GAME-PROMPT.md` for the canonical
479
+ `dt` idiom. Input uses the DOM event form; `when <target> "<event>" happens`
480
+ becomes `addEventListener`, and reading a key map uses a boolean comparison:
481
+
482
+ ```plainscript
483
+ remember keys as {}
484
+ when document "keydown" happens as ke
485
+ keys[ke.key] becomes true
486
+ done
487
+ when document "keyup" happens as ke
488
+ keys[ke.key] becomes false
489
+ done
490
+
491
+ if keys["ArrowLeft"] is true
492
+ player.x becomes player.x - 4
493
+ done
494
+ ```
495
+
496
+ Browser builtins are either direct helpers or auto-awaited promises — no
497
+ `await` is written for the loaders:
498
+
499
+ - `select("canvas")` / `selectAll(".card")` / `parseHTML("<div>...</div>")`
500
+ - `loadImage(url)` → `Image`; `loadAudio(url)` → `Audio` element
501
+ - `fetchJson(url)` → `{ok, status, data, text, parseError}`; `fetchBytes(url)`
502
+ → `{ok, status, data: Uint8Array}`
503
+ - `readDataUrl(file)` → a `data:` URL string for a `File` (from
504
+ `droppedFiles(event)` or a file input)
505
+ - `audioContext()` + `playTone(frequency, seconds, options)` — start from a
506
+ user-gesture handler (`ctx.resume()`)
507
+ - `localPoint(event, canvas)` maps client to canvas coordinates
508
+ - `gamepads()` returns connected pads; `droppedFiles(event)` reads drag-drop
509
+ - WebSockets: client side uses `new WebSocket(url)` with `when ws "message"
510
+ happens`, and `webSocketSend(ws, value)` sends strings as-is or
511
+ JSON-stringifies anything else
512
+ - Persistence is direct interop: `localStorage.getItem(...)` /
513
+ `setItem` plus `jsonEncode` / `jsonDecode` (JSON is a builtin data type)
514
+
515
+ WebGL runs through the WebGL2 canvas API (`webglContext(canvas)`, `glShader`,
516
+ `glProgram`, `glBuffer` — all protected by teaching errors) or a library such
517
+ as Three.js constructed interop-style with `new`. WebGPU is available via its
518
+ canvas API.
519
+ A detailed, expanding guide for browser games lives in
520
+ `docs/GAME-PROMPT.md`.
521
+
522
+ ## JavaScript interop
523
+
524
+ `.pln` files are JavaScript; any JS API is reachable without sugar. Importing
525
+ uses `use` (bare npm name, bound lowercase) or `bring name from "pkg"`:
526
+
527
+ ```plainscript
528
+ use matter
529
+ bring THREE from "three"
530
+ remember engine as matter.Engine.create()
531
+ remember scene as new THREE.Scene()
532
+ ```
533
+
534
+ Call anything — member chains need no special syntax, and there is no wrapper
535
+ around values:
536
+
537
+ ```plainscript
538
+ crypto.createHash("sha256").update("abc").digest("hex")
539
+ mesh.scale.set(2, 2, 2)
540
+ ```
541
+
542
+ Construct with `new Type(args)` — as a statement, in `remember`, as an
543
+ argument, or bare without parens (`new Enemy`). A `make` function reference is
544
+ a first-class value — pass it as a callback:
545
+
546
+ ```plainscript
547
+ make fitWindow()
548
+ camera.aspect becomes window.innerWidth / window.innerHeight
549
+ camera.updateProjectionMatrix()
550
+ done
551
+ window.addEventListener("resize", fitWindow)
552
+ ```
553
+
554
+ Promises are awaited with `await` / `wait for`; errors follow the `try` /
555
+ `recover as err` / `finally` idiom, never `.then` chaining:
556
+
557
+ ```plainscript
558
+ try
559
+ remember response as await fetch("/api/state")
560
+ remember data as await response.json()
561
+ show data
562
+ recover as err
563
+ show message of err
564
+ done
565
+ ```
566
+
567
+ Typed arrays construct and index like anything else
568
+ (`new Uint8Array(64)`, `buffer[0] becomes 255`). The generated file adds
569
+ `require()` only for `use`/`bring`, and ends with a guarded `module.exports`
570
+ tail so the same output works as a browser `<script>` and under Node. The
571
+ comprehensive guide is `docs/GAME-PROMPT.md`.
572
+
313
573
  ## Native tests
314
574
 
315
575
  ```plainscript
@@ -325,6 +585,7 @@ Assertions are `equals`, `is`, `contains`, and `raises`.
325
585
  ```text
326
586
  plainscript check [target]
327
587
  plainscript build [file.pln]
588
+ plainscript build <file.pln> -o <output.js>
328
589
  plainscript run <file.pln>
329
590
  plainscript start
330
591
  plainscript fmt <file.pln>
package/docs/index.html CHANGED
@@ -3,26 +3,13 @@
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <meta name="description" content="PlainScript 1.0.3 language reference and examples">
6
+ <meta name="description" content="PlainScript 1.0.36 language reference and examples">
7
7
  <meta name="theme-color" content="#070c16">
8
- <title>PlainScript 1.0.3</title>
9
- <script>
10
- // Force desktop rendering on small screens: lay out at a desktop width and
11
- // let the browser scale it down, so mobile users see the full site right
12
- // away instead of having to pinch-zoom out.
13
- (function () {
14
- var isMobile = /Android|iPhone|iPod|iPad|Mobile|Windows Phone/i.test(navigator.userAgent);
15
- if (isMobile) {
16
- var vp = document.querySelector('meta[name="viewport"]');
17
- if (vp) {
18
- var layoutWidth = 1400;
19
- var deviceWidth = window.screen.width || document.documentElement.clientWidth;
20
- var scale = Math.min(deviceWidth / layoutWidth, 1).toFixed(5);
21
- vp.setAttribute('content', 'width=' + layoutWidth + ', initial-scale=' + scale + ', maximum-scale=5');
22
- }
23
- }
24
- })();
25
- </script>
8
+ <title>PlainScript 1.0.36</title>
9
+
10
+ <link rel="preconnect" href="https://fonts.googleapis.com">
11
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
12
+ <link href="https://fonts.googleapis.com/css2?family=Newsreader:opsz,wght@6..72,400;6..72,500&family=Public+Sans:wght@400;500&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
26
13
  <link rel="stylesheet" href="website/style.css">
27
14
  </head>
28
15
  <body>
@@ -32,11 +19,16 @@
32
19
  <header class="site-nav" id="site-nav">
33
20
  <div class="container nav-inner">
34
21
  <a class="nav-logo" href="#">
35
- <span class="nav-logo-mark" aria-hidden="true">&gt;_</span>
22
+ <img class="nav-logo-image" src="logo-pln.jpg" alt="">
36
23
  <span>PlainScript</span>
37
- <span class="logo-ver">1.0.3</span>
24
+ <span class="logo-ver">1.0.36</span>
38
25
  </a>
39
- <nav class="nav-links" aria-label="Primary navigation">
26
+ <button class="nav-toggle" id="nav-toggle" aria-label="Toggle navigation" aria-expanded="false" aria-controls="nav-links">
27
+ <span class="nav-toggle-bar"></span>
28
+ <span class="nav-toggle-bar"></span>
29
+ <span class="nav-toggle-bar"></span>
30
+ </button>
31
+ <nav class="nav-links" id="nav-links" aria-label="Primary navigation">
40
32
  <a href="#quickstart">Quick start</a>
41
33
  <a href="#language">Language</a>
42
34
  <a href="#capabilities">Capabilities</a>
@@ -48,17 +40,24 @@
48
40
  <main>
49
41
  <section class="hero">
50
42
  <div class="container hero-content">
51
- <p class="hero-badge" data-reveal>1.0.3: Node.js programming for everyone</p>
52
- <h1 class="hero-title">Code that reads like plain English.</h1>
53
- <p class="hero-lead">Write what you want in plain words. PlainScript turns it into JavaScript — simple, readable, and easy to check.</p>
54
- <div class="hero-actions">
55
- <a class="button button-primary" href="#quickstart">Start building</a>
56
- <a class="button button-secondary" href="#library">Browse examples</a>
57
- </div>
58
- <pre class="code-window"><code>remember name as "Ada"
43
+ <div class="hero-grid">
44
+ <div class="hero-headline-block">
45
+ <p class="hero-badge" data-reveal>an intent-oriented language for node.js</p>
46
+ <h1 class="hero-title"><span class="kw">remember</span> the sentence <span class="kw">as</span> the program.<br><span class="kw">show</span> the result <span class="kw">when</span> the meaning is clear.</h1>
47
+ <p class="hero-lead">Write what you want in plain words. PlainScript checks it, then turns it into readable JavaScript — no boilerplate, no hidden steps.</p>
48
+ <div class="hero-actions">
49
+ <span class="hero-install-label">install</span>
50
+ <a class="button" href="#quickstart">npx plainscript new hello</a>
51
+ </div>
52
+ </div>
53
+ <div class="hero-panel">
54
+ <p class="hero-panel-label">terminal</p>
55
+ <pre class="code-window"><code>remember name as "Ada"
59
56
  if name contains "A"
60
57
  show `Hello, ${name}!`
61
58
  done</code></pre>
59
+ </div>
60
+ </div>
62
61
  </div>
63
62
  </section>
64
63
 
@@ -111,7 +110,7 @@ npm start</code></pre>
111
110
  <div class="container">
112
111
  <p class="section-tag" data-reveal>Feature library</p>
113
112
  <h2 class="section-title" data-reveal>Examples you can try today.</h2>
114
- <p class="section-lead">These snippets use the PlainScript 1.0.3 grammar.</p>
113
+ <p class="section-lead">These snippets use the PlainScript 1.0.36 grammar.</p>
115
114
  <div class="library-toolbar" data-reveal>
116
115
  <label class="sr-only" for="lib-search">Search examples</label>
117
116
  <input id="lib-search" class="lib-search-input" type="search" placeholder="Search examples">
@@ -125,13 +124,22 @@ npm start</code></pre>
125
124
  <section class="section">
126
125
  <div class="container split">
127
126
  <div data-reveal><p class="section-tag">Reference</p><h2 class="section-title">The compiler is the source of truth.</h2></div>
128
- <div data-reveal><p>Read the <a href="PLAINSCRIPT-SPEC.md">language specification</a> and the <a href="../knowledge.md">AI coding specification</a>. The repository's <code>examples/</code> directory has runnable examples.</p><p>Validate a file with <code>node compiler/cli.js check path/to/file.pln</code>.</p></div>
127
+ <div data-reveal>
128
+ <p>Read the language specification and the <a href="https://github.com/ayoistooslick/plainscript/blob/main/knowledge.md" target="_blank" rel="noopener noreferrer">AI coding specification</a>. The repository's <code>examples/</code> directory has runnable examples.</p>
129
+ <div class="reference-actions" aria-label="PlainScript resources">
130
+ <a class="button button-reference" href="https://www.npmjs.com/package/plainscript-lang" target="_blank" rel="noopener noreferrer">NPM package</a>
131
+ <a class="button button-reference" href="https://github.com/ayoistooslick/plainscript" target="_blank" rel="noopener noreferrer">GitHub repo</a>
132
+ <a class="button button-reference" href="https://github.com/ayoistooslick/plainscript/blob/main/docs/PLAINSCRIPT-SPEC.md" target="_blank" rel="noopener noreferrer">Language specification</a>
133
+ <a class="button button-reference" href="https://ayoistooslick.github.io/plainscript/" target="_blank" rel="noopener noreferrer">Documentation website</a>
134
+ </div>
135
+ <p>Validate a file with <code>node compiler/cli.js check path/to/file.pln</code>.</p>
136
+ </div>
129
137
  </div>
130
138
  </section>
131
139
  </main>
132
140
 
133
141
  <footer class="site-footer">
134
- <div class="container footer-bottom"><span>PlainScript</span><span>1.0.3</span></div>
142
+ <div class="container footer-bottom"><span>PlainScript</span><span>1.0.36</span></div>
135
143
  </footer>
136
144
 
137
145
  <script src="https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js"></script>
Binary file
@@ -0,0 +1,32 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="720" height="420" viewBox="0 0 720 420" role="img" aria-labelledby="title desc">
2
+ <title id="title">Monthly signups</title>
3
+ <desc id="desc">A bar chart showing signups increasing from January through April.</desc>
4
+ <rect width="720" height="420" fill="#071b10"/>
5
+ <text x="360" y="34" fill="#e6f1e7" font-family="Arial, sans-serif" font-size="20" text-anchor="middle" font-weight="700">Monthly signups</text>
6
+ <g stroke="#284734" stroke-width="1">
7
+ <line x1="62" y1="362" x2="696" y2="362"/>
8
+ <line x1="62" y1="288.5" x2="696" y2="288.5"/>
9
+ <line x1="62" y1="215" x2="696" y2="215"/>
10
+ <line x1="62" y1="141.5" x2="696" y2="141.5"/>
11
+ <line x1="62" y1="68" x2="696" y2="68"/>
12
+ </g>
13
+ <g fill="#8da99a" font-family="Arial, sans-serif" font-size="11" text-anchor="end">
14
+ <text x="52" y="366">0</text>
15
+ <text x="52" y="292.5">9</text>
16
+ <text x="52" y="219">18</text>
17
+ <text x="52" y="145.5">27</text>
18
+ <text x="52" y="72">36</text>
19
+ </g>
20
+ <g fill="#40c463">
21
+ <rect x="95.813" y="264" width="111.8" height="98" rx="5"/>
22
+ <rect x="254.313" y="215" width="111.8" height="147" rx="5"/>
23
+ <rect x="412.813" y="141.5" width="111.8" height="220.5" rx="5"/>
24
+ <rect x="571.313" y="76.167" width="111.8" height="285.833" rx="5"/>
25
+ </g>
26
+ <g fill="#8da99a" font-family="Arial, sans-serif" font-size="12" text-anchor="middle">
27
+ <text x="151.7" y="396">Jan</text>
28
+ <text x="310.2" y="396">Feb</text>
29
+ <text x="468.7" y="396">Mar</text>
30
+ <text x="627.2" y="396">Apr</text>
31
+ </g>
32
+ </svg>
@@ -8,7 +8,20 @@
8
8
  const canvas = document.getElementById("bg-canvas");
9
9
  if (!canvas || !window.WebGLRenderingContext) return;
10
10
 
11
- const renderer = new THREE.WebGLRenderer({ canvas, alpha: true, antialias: true });
11
+ let context;
12
+ try {
13
+ context = canvas.getContext("webgl", { alpha: true, antialias: true });
14
+ } catch (error) {
15
+ return;
16
+ }
17
+ if (!context) return;
18
+
19
+ let renderer;
20
+ try {
21
+ renderer = new THREE.WebGLRenderer({ canvas, context, alpha: true, antialias: true });
22
+ } catch (error) {
23
+ return;
24
+ }
12
25
  renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
13
26
 
14
27
  const scene = new THREE.Scene();
@@ -147,6 +160,120 @@
147
160
  window.addEventListener("scroll", onScroll, { passive: true });
148
161
  onScroll();
149
162
 
163
+ // Mobile nav toggle
164
+ const navToggle = document.getElementById("nav-toggle");
165
+ const navLinks = document.getElementById("nav-links");
166
+ if (navToggle && navLinks) {
167
+ navToggle.addEventListener("click", () => {
168
+ const expanded = navToggle.getAttribute("aria-expanded") === "true";
169
+ navToggle.setAttribute("aria-expanded", String(!expanded));
170
+ navLinks.classList.toggle("is-open", !expanded);
171
+ });
172
+ navLinks.querySelectorAll("a").forEach((link) => {
173
+ link.addEventListener("click", () => {
174
+ navToggle.setAttribute("aria-expanded", "false");
175
+ navLinks.classList.remove("is-open");
176
+ });
177
+ });
178
+ }
179
+
180
+ // ── Copy controls for every code block ─────────────────────────────────
181
+ const syntaxGroups = {
182
+ declaration: new Set(["remember", "let", "make", "define", "function", "use", "import", "export", "database", "postgres", "record", "list", "create", "websocket", "bot", "whatsapp", "ocr"]),
183
+ web: new Set(["web", "route", "start", "listen", "reply", "respond", "serve", "allow", "cors", "status", "redirect", "param", "query", "header", "upload", "uploads"]),
184
+ database: new Set(["database", "postgres", "query", "insert", "update", "delete", "execute", "transaction", "native", "wasm"]),
185
+ error: new Set(["try", "recover", "finally", "retry", "throw", "raise", "raises", "catch", "catches"]),
186
+ test: new Set(["test", "check", "equals", "contains", "raises"]),
187
+ comparison: new Set(["contains", "starts", "ends", "between", "is", "same", "different", "more", "fewer", "at", "least", "most"]),
188
+ keyword: new Set(["if", "otherwise", "else", "for", "each", "every", "index", "from", "to", "while", "in", "when", "on", "done", "give", "return", "yield", "break", "continue", "with", "and", "or", "not", "field", "instanceof", "show", "print", "display", "accept", "require", "enable", "limit", "cache", "schedule", "background", "socket", "message", "broadcast", "send"])
189
+ };
190
+
191
+ function escapeHtml(value) {
192
+ return value.replace(/[&<>"']/g, (character) => ({
193
+ "&": "&amp;",
194
+ "<": "&lt;",
195
+ ">": "&gt;",
196
+ '"': "&quot;",
197
+ "'": "&#39;"
198
+ }[character]));
199
+ }
200
+
201
+ function highlightPlainScript(source) {
202
+ const tokenPattern = /\/\/[^\n]*|"(?:\\.|[^"\\])*"|`(?:\\.|[^`\\])*`|\b\d+(?:\.\d+)?n?\b|\b[A-Za-z_][A-Za-z0-9_]*\b|\?\?|\?\.|\*\*|->|===|!==|==|!=|<=|>=|[+\-*\/%=<>]/g;
203
+ let highlighted = "";
204
+ let lastIndex = 0;
205
+ let match;
206
+
207
+ while ((match = tokenPattern.exec(source))) {
208
+ highlighted += escapeHtml(source.slice(lastIndex, match.index));
209
+ const token = match[0];
210
+ let className = "";
211
+ if (token.startsWith("//")) className = "comment";
212
+ else if (token.startsWith('"')) className = "string";
213
+ else if (token.startsWith("`")) className = "template";
214
+ else if (/^\d/.test(token)) className = "number";
215
+ else if (/^(true|false|null|undefined)$/.test(token)) className = "constant";
216
+ else if (/^(?:\?\?|\?\.|\*\*|->|===|!==|==|!=|<=|>=|[+\-*\/%=<>])$/.test(token)) className = token === "=" ? "assignment" : "operator";
217
+ else if (syntaxGroups.database.has(token)) className = "database";
218
+ else if (syntaxGroups.comparison.has(token)) className = "comparison";
219
+ else if (syntaxGroups.declaration.has(token)) className = "declaration";
220
+ else if (syntaxGroups.web.has(token)) className = "web";
221
+ else if (syntaxGroups.error.has(token)) className = "error";
222
+ else if (syntaxGroups.test.has(token)) className = "test";
223
+ else if (syntaxGroups.keyword.has(token)) className = "keyword";
224
+ else if (/\s*\(/.test(source.slice(match.index + token.length))) className = "function";
225
+ if (token === "becomes") className = "assignment";
226
+ highlighted += className ? `<span class="code-token code-token--${className}">${escapeHtml(token)}</span>` : escapeHtml(token);
227
+ lastIndex = match.index + token.length;
228
+ }
229
+ return highlighted + escapeHtml(source.slice(lastIndex));
230
+ }
231
+
232
+ function enhanceCodeBlock(pre) {
233
+ if (!pre || pre.querySelector(".copy-button")) return;
234
+ const code = pre.querySelector("code");
235
+ if (!code) return;
236
+ code.innerHTML = highlightPlainScript(code.textContent);
237
+
238
+ const copyButton = document.createElement("button");
239
+ copyButton.type = "button";
240
+ copyButton.className = "copy-button";
241
+ copyButton.textContent = "Copy";
242
+ copyButton.setAttribute("aria-label", "Copy code to clipboard");
243
+ copyButton.addEventListener("click", async () => {
244
+ const originalLabel = "Copy";
245
+ let copied = false;
246
+ try {
247
+ if (navigator.clipboard && window.isSecureContext) {
248
+ await navigator.clipboard.writeText(code.textContent);
249
+ copied = true;
250
+ } else {
251
+ const selection = window.getSelection();
252
+ const range = document.createRange();
253
+ range.selectNodeContents(code);
254
+ selection.removeAllRanges();
255
+ selection.addRange(range);
256
+ copied = document.execCommand("copy");
257
+ selection.removeAllRanges();
258
+ }
259
+ } catch (error) {
260
+ copied = false;
261
+ }
262
+ if (!copied) return;
263
+ copyButton.textContent = "Copied";
264
+ copyButton.classList.add("is-copied");
265
+ copyButton.setAttribute("aria-label", "Code copied to clipboard");
266
+ window.setTimeout(() => {
267
+ copyButton.textContent = originalLabel;
268
+ copyButton.classList.remove("is-copied");
269
+ copyButton.setAttribute("aria-label", "Copy code to clipboard");
270
+ }, 1600);
271
+ });
272
+ pre.appendChild(copyButton);
273
+ }
274
+
275
+ document.querySelectorAll("pre").forEach(enhanceCodeBlock);
276
+
150
277
  // ── Feature library (search + filter) ─────────────────────────────────
151
278
  const examples = [
152
279
  { category: "core", name: "Variables", description: "Store and update values.", source: 'remember name as "Ada"\nremember count as 3\ncount becomes count + 1\nshow `Hello, ${name}!`' },
@@ -166,6 +293,7 @@
166
293
  { category: "runtime", name: "WebSockets", description: "Chat and push updates live.", source: 'websocket server on 8080\n when socket connects\n send socket "connected"\n done\n when socket sends message\n broadcast message\n done\ndone' },
167
294
  { category: "runtime", name: "Cache", description: "Keep values ready with a TTL.", source: 'cache env("REDIS_URL")\ncacheSet("status", "ready", 60)\nremember status as cacheGet("status")' },
168
295
  { category: "integrations", name: "Telegram", description: "Build a Telegram bot.", source: 'bot env("TELEGRAM_BOT_TOKEN")\nwhen someone sends "/start"\n reply "Welcome"\ndone\nstart telegram bot' },
296
+ { category: "integrations", name: "WhatsApp", description: "Build a WhatsApp bot.", source: 'whatsapp bot\n auth "session"\n login pairing "2348012345678"\n on message\n if message.text is "/start"\n reply "Welcome!"\n done\n if message.type is "image"\n download "media/photo.jpg"\n reply "Saved your photo!"\n done\n done\ndone' },
169
297
  { category: "integrations", name: "Groq AI", description: "Get AI replies in your code.", source: 'remember answer as chatWith("groq", "llama-3.3-70b-versatile", "Hello")\nshow answer' },
170
298
  { category: "integrations", name: "OCR uploads", description: "Read text from uploaded images.", source: 'web app\naccept uploads limit "5 MB" allow list with "image/png" folder "uploads"\nroute post "/scan"\n remember file as upload("document")\n ocr path of file as text\n reply text\ndone' },
171
299
  { category: "tooling", name: "Native tests", description: "Check that your code works.", source: 'test "addition works"\n check add(2, 3) equals 5\ndone' },
@@ -208,6 +336,7 @@
208
336
  card.className = "library-card";
209
337
  card.innerHTML = `<div class="library-card-top"><span class="library-category">${item.category}</span><h3>${item.name}</h3><p>${item.description}</p></div><pre><code></code></pre>`;
210
338
  card.querySelector("code").textContent = item.source;
339
+ enhanceCodeBlock(card.querySelector("pre"));
211
340
  grid.appendChild(card);
212
341
  });
213
342
  empty.hidden = visible.length !== 0;