plainscript-lang 1.0.3 → 1.0.35

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 (74) hide show
  1. package/README.md +29 -0
  2. package/compiler/cli.js +1 -1
  3. package/compiler/dependency-detector.js +6 -2
  4. package/compiler/generator.js +422 -51
  5. package/compiler/parser.js +40 -2
  6. package/compiler/version.js +1 -1
  7. package/docs/CAPABILITY_GAP_AUDIT.md +9 -3
  8. package/docs/PLAINSCRIPT-SPEC.md +135 -3
  9. package/docs/index.html +27 -26
  10. package/docs/logo-pln.jpg +0 -0
  11. package/docs/visualization-example.svg +32 -0
  12. package/docs/website/script.js +130 -1
  13. package/docs/website/style.css +211 -47
  14. package/examples/ai-providers.pln +1 -1
  15. package/examples/arrays.pln +1 -1
  16. package/examples/async-errors.pln +1 -1
  17. package/examples/auth-api.pln +1 -1
  18. package/examples/auth-sessions.pln +1 -1
  19. package/examples/basics.pln +1 -1
  20. package/examples/bots.pln +1 -1
  21. package/examples/cache-and-jobs.pln +1 -1
  22. package/examples/cache-schedule.pln +1 -1
  23. package/examples/collections.pln +1 -1
  24. package/examples/concurrency.pln +1 -1
  25. package/examples/conditions.pln +1 -1
  26. package/examples/database.pln +1 -1
  27. package/examples/day2.pln +1 -1
  28. package/examples/day3.pln +1 -1
  29. package/examples/deployment.pln +1 -1
  30. package/examples/email-send.pln +1 -1
  31. package/examples/error-handling.pln +1 -1
  32. package/examples/expressions.pln +1 -1
  33. package/examples/file-uploads.pln +1 -1
  34. package/examples/files-and-config.pln +1 -1
  35. package/examples/files.pln +1 -1
  36. package/examples/football-backend/app.pln +1 -1
  37. package/examples/functions.pln +1 -1
  38. package/examples/hello.pln +1 -1
  39. package/examples/http-client.pln +1 -1
  40. package/examples/http.pln +1 -1
  41. package/examples/id-verification/app.pln +1 -1
  42. package/examples/json.pln +1 -1
  43. package/examples/loops.pln +1 -1
  44. package/examples/modules/app.pln +1 -1
  45. package/examples/modules/main.pln +1 -1
  46. package/examples/modules/math.pln +1 -1
  47. package/examples/mongo.pln +1 -1
  48. package/examples/objects.pln +1 -1
  49. package/examples/ocr.pln +1 -1
  50. package/examples/packages.pln +1 -1
  51. package/examples/record-kinds.pln +1 -1
  52. package/examples/records.pln +1 -1
  53. package/examples/rest-api-fetch.pln +1 -1
  54. package/examples/rest-api.pln +1 -1
  55. package/examples/scheduled-tasks.pln +1 -1
  56. package/examples/search-and-filter.pln +1 -1
  57. package/examples/server.pln +1 -1
  58. package/examples/sessions-and-cookies.pln +1 -1
  59. package/examples/sqlite.pln +1 -1
  60. package/examples/start.pln +1 -1
  61. package/examples/stdlib.pln +1 -1
  62. package/examples/string-verbs.pln +1 -1
  63. package/examples/telegram-ai-bot.pln +1 -1
  64. package/examples/telegram-bot.pln +1 -1
  65. package/examples/testing.pln +1 -1
  66. package/examples/visualization.pln +12 -0
  67. package/examples/web-api.pln +1 -1
  68. package/examples/web-app.pln +1 -1
  69. package/examples/websocket-server.pln +1 -1
  70. package/examples/websocket.pln +1 -1
  71. package/examples/whatsapp-bot/pairing.pln +24 -2
  72. package/examples/whatsapp-bot/qr.pln +18 -2
  73. package/package.json +2 -1
  74. package/docs/logo.jpg +0 -0
@@ -686,6 +686,23 @@ function parse(tokens) {
686
686
  return parseWhatsAppBot();
687
687
  }
688
688
 
689
+ // v2.1.1 — pair whatsapp "<phone>": starts an on-demand WhatsApp pairing
690
+ // session for the given phone number. Used by hybrid bots where a
691
+ // Telegram command triggers a WhatsApp pairing flow.
692
+ // Accepts a string literal (validated at compile time) or any expression
693
+ // (e.g. a variable filled by regex matches[1]).
694
+ if (token.value === 'pair' &&
695
+ peekAt(1).type === TOKEN.IDENTIFIER && peekAt(1).value === 'whatsapp') {
696
+ advance(); // pair
697
+ advance(); // whatsapp
698
+ if (peek().type === TOKEN.STRING) {
699
+ const phone = advance().value;
700
+ return { type: 'WhatsAppPairStatement', phone: { type: 'StringLiteral', value: phone } };
701
+ }
702
+ const phoneExpr = parseExpression();
703
+ return { type: 'WhatsAppPairStatement', phone: phoneExpr };
704
+ }
705
+
689
706
  // v2.1.1 — log message: prints the normalized message record inside an
690
707
  // "on message" handler. Generation rejects it everywhere else with a
691
708
  // teaching error.
@@ -696,6 +713,15 @@ function parse(tokens) {
696
713
  return { type: 'WhatsAppLogStatement' };
697
714
  }
698
715
 
716
+ // v2.14 — download "<path>": saves the current message's media (image,
717
+ // video, audio, document, sticker, …) to a file, inside an "on message"
718
+ // handler. Generation rejects it everywhere else with a teaching error.
719
+ if (token.value === 'download' && peekAt(1).type === TOKEN.STRING) {
720
+ advance(); // download
721
+ const filePath = advance().value;
722
+ return { type: 'WhatsAppDownloadStatement', filePath };
723
+ }
724
+
699
725
  // v2.1.0 — broadcast <expr>: sends to every connected socket.
700
726
  if (token.value === 'broadcast') {
701
727
  advance(); // broadcast
@@ -3431,6 +3457,7 @@ function parseAsk() {
3431
3457
 
3432
3458
  let authFolder = null;
3433
3459
  let login = null;
3460
+ let baileysModule = null;
3434
3461
  const handlers = [];
3435
3462
 
3436
3463
  while (peek().type !== TOKEN.DONE) {
@@ -3441,6 +3468,16 @@ function parseAsk() {
3441
3468
  ));
3442
3469
  }
3443
3470
 
3471
+ // use baileys "<pkg>" — override the Baileys implementation package.
3472
+ // Default is @qwerty-xcv/baileys. Accepts any require-able package name,
3473
+ // so developers can pin a fork or the upstream @whiskeysockets/baileys.
3474
+ if (peek().type === TOKEN.USE && peekAt(1).value === 'baileys' && peekAt(2).type === TOKEN.STRING) {
3475
+ advance(); // use
3476
+ advance(); // baileys
3477
+ baileysModule = advance().value;
3478
+ continue;
3479
+ }
3480
+
3444
3481
  // auth "<folder>" — where WhatsApp session credentials persist.
3445
3482
  if (peek().type === TOKEN.IDENTIFIER && peek().value === 'auth' &&
3446
3483
  peekAt(1).type === TOKEN.STRING) {
@@ -3495,7 +3532,7 @@ function parseAsk() {
3495
3532
  }
3496
3533
 
3497
3534
  throw new Error(makeError(
3498
- 'A "whatsapp bot" block may only contain an "auth", a "login", and "on message" statements.\n\nExample:\n whatsapp bot\n auth "session"\n login qr\n\n on message\n log message\n done\n done',
3535
+ 'A "whatsapp bot" block may only contain an "auth", a "login", a "use baileys", and "on message" statements.\n\nExample:\n whatsapp bot\n auth "session"\n use baileys "@qwerty-xcv/baileys"\n login qr\n\n on message\n log message\n done\n done',
3499
3536
  peek()
3500
3537
  ));
3501
3538
  }
@@ -3504,8 +3541,9 @@ function parseAsk() {
3504
3541
  return {
3505
3542
  type: 'WhatsAppBotStatement',
3506
3543
  authFolder: authFolder || 'plainscript-whatsapp-auth',
3507
- login: login || { mode: 'qr' },
3544
+ login: login,
3508
3545
  handlers,
3546
+ baileysModule,
3509
3547
  };
3510
3548
  }
3511
3549
 
@@ -1,6 +1,6 @@
1
1
  // Single source of truth for the compiler version.
2
2
  // Consumed by cli.js help/version output.
3
3
 
4
- const VERSION = '1.0.3';
4
+ const VERSION = '1.0.35';
5
5
 
6
6
  module.exports = { VERSION };
@@ -1,4 +1,4 @@
1
- # PlainScript 1.0.3 Capability Audit
1
+ # PlainScript 1.0.35 Capability Audit
2
2
 
3
3
  This audit is based on what the compiler actually supports right now.
4
4
  If `plainscript check` validates it, it's listed here.
@@ -18,6 +18,7 @@ If `plainscript check` validates it, it's listed here.
18
18
  | For and while loops | Implemented | `for each ... done`, `while ... done` |
19
19
  | Match and switch | Implemented | `match value against ... done` |
20
20
  | Loop control | Implemented | `break`, `continue` |
21
+ | String verbs | Implemented | `lowercase`, `uppercase`, `split`, `join`, `trim`, `capitalize words` |
21
22
  | Classes and `new` | Implemented | JavaScript-compatible class forms |
22
23
 
23
24
  ## Modules and Runtime
@@ -51,13 +52,18 @@ If `plainscript check` validates it, it's listed here.
51
52
  | SQLite | Implemented | native and WebAssembly drivers |
52
53
  | PostgreSQL generation | Implemented | `postgres connection` |
53
54
  | SQL parameter binding | Implemented | `{variable}` placeholders |
55
+ | MongoDB | Implemented | `mongo connection`, insert, select, update, delete |
56
+ | MongoDB insert | Implemented | `insert into ... done` |
57
+ | MongoDB select | Implemented | `select from ... done` |
58
+ | MongoDB update | Implemented | `update ... set ... done` |
59
+ | MongoDB delete | Implemented | `delete from ... done` |
54
60
  | Email | Implemented | `mail transport`, `send mail` |
55
61
  | Schedules and jobs | Implemented | `every`, `schedule`, `run background` |
56
62
  | WebSockets | Implemented | `websocket server` |
57
63
  | Redis/in-memory cache | Implemented | `cache`, `cacheGet`, `cacheSet` |
58
64
  | Telegram bots | Implemented | `bot`, message/callback handlers |
59
65
  | AI providers | Implemented | `chat`, `chatWith`, `embedText`, provider presets |
60
- | WhatsApp bots | Implemented | `whatsapp bot` |
66
+ | WhatsApp bots | Implemented | `whatsapp bot` (pairing/QR, message types, media download, custom Baileys) |
61
67
  | OCR | Implemented | `ocr path of file as text` |
62
68
 
63
69
  ## Canonical Examples
@@ -99,6 +105,6 @@ find examples -name '*.pln' -exec node compiler/cli.js check {} \;
99
105
 
100
106
  ## Version Info
101
107
 
102
- The release label for this repo is `1.0.3`. It covers the compiler,
108
+ The release label for this repo is `1.0.35`. It covers the compiler,
103
109
  package metadata, website, and editor tooling. Third-party dependency
104
110
  versions are not tied to this label.
@@ -1,4 +1,4 @@
1
- # PlainScript 1.0.3 language specification
1
+ # PlainScript 1.0.35 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,145 @@ 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
+
313
445
  ## Native tests
314
446
 
315
447
  ```plainscript
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.35 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.35</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=Roboto+Mono:wght@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.35</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,7 +40,7 @@
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>
43
+ <p class="hero-badge" data-reveal>1.0.35: Node.js programming for everyone</p>
52
44
  <h1 class="hero-title">Code that reads like plain English.</h1>
53
45
  <p class="hero-lead">Write what you want in plain words. PlainScript turns it into JavaScript — simple, readable, and easy to check.</p>
54
46
  <div class="hero-actions">
@@ -111,7 +103,7 @@ npm start</code></pre>
111
103
  <div class="container">
112
104
  <p class="section-tag" data-reveal>Feature library</p>
113
105
  <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>
106
+ <p class="section-lead">These snippets use the PlainScript 1.0.35 grammar.</p>
115
107
  <div class="library-toolbar" data-reveal>
116
108
  <label class="sr-only" for="lib-search">Search examples</label>
117
109
  <input id="lib-search" class="lib-search-input" type="search" placeholder="Search examples">
@@ -125,13 +117,22 @@ npm start</code></pre>
125
117
  <section class="section">
126
118
  <div class="container split">
127
119
  <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>
120
+ <div data-reveal>
121
+ <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>
122
+ <div class="reference-actions" aria-label="PlainScript resources">
123
+ <a class="button button-reference" href="https://www.npmjs.com/package/plainscript-lang" target="_blank" rel="noopener noreferrer">NPM package</a>
124
+ <a class="button button-reference" href="https://github.com/ayoistooslick/plainscript" target="_blank" rel="noopener noreferrer">GitHub repo</a>
125
+ <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>
126
+ <a class="button button-reference" href="https://ayoistooslick.github.io/plainscript/" target="_blank" rel="noopener noreferrer">Documentation website</a>
127
+ </div>
128
+ <p>Validate a file with <code>node compiler/cli.js check path/to/file.pln</code>.</p>
129
+ </div>
129
130
  </div>
130
131
  </section>
131
132
  </main>
132
133
 
133
134
  <footer class="site-footer">
134
- <div class="container footer-bottom"><span>PlainScript</span><span>1.0.3</span></div>
135
+ <div class="container footer-bottom"><span>PlainScript</span><span>1.0.35</span></div>
135
136
  </footer>
136
137
 
137
138
  <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;