-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
481 lines (451 loc) · 27 KB
/
Copy pathindex.html
File metadata and controls
481 lines (451 loc) · 27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weave Playground</title>
<link rel="manifest" href="manifest.json">
<meta name="theme-color" content="#6ee7b7">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="description" content="Write Weave — a simple scripting language that compiles to JavaScript">
<style>
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
:root{
--bg:#0f1117;--surf:#1a1d27;--surf2:#20243a;--border:#2a2e48;
--text:#dde1f5;--muted:#6b7099;--green:#6ee7b7;--purple:#818cf8;
--yellow:#fbbf24;--pink:#f472b6;--red:#f87171;--blue:#60a5fa;
--mono:'JetBrains Mono','Fira Code','Cascadia Code','Courier New',monospace;
}
body{background:var(--bg);color:var(--text);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;height:100dvh;display:flex;flex-direction:column;overflow:hidden}
header{display:flex;align-items:center;gap:10px;padding:0 14px;height:50px;background:var(--surf);border-bottom:1px solid var(--border);flex-shrink:0}
.logo{font-size:17px;font-weight:700;color:var(--green);letter-spacing:-.3px;display:flex;align-items:center;gap:5px;white-space:nowrap}
.version{font-size:10px;color:var(--muted);font-weight:400}
.nav-tabs{display:flex;gap:4px;margin-left:10px}
.nav-tab{background:none;border:1px solid transparent;color:var(--muted);padding:4px 12px;border-radius:5px;font-size:12px;cursor:pointer;font-family:inherit;transition:all .12s}
.nav-tab:hover{color:var(--text);border-color:var(--border)}
.nav-tab.active{background:var(--surf2);border-color:var(--purple);color:var(--purple)}
.example-tabs{display:flex;gap:4px;margin-left:4px}
.ex{background:none;border:1px solid var(--border);color:var(--muted);padding:4px 9px;border-radius:5px;font-size:11px;cursor:pointer;transition:all .12s;font-family:inherit}
.ex:hover,.ex.active{border-color:var(--green);color:var(--green);background:#052e1622}
.install-btn{margin-left:auto;display:none;align-items:center;gap:5px;background:var(--surf2);border:1px solid var(--border);color:var(--green);padding:4px 11px;border-radius:6px;font-size:11px;cursor:pointer;font-family:inherit;transition:all .12s;white-space:nowrap}
.install-btn:hover{border-color:var(--green)}
.install-btn.visible{display:flex}
#view-editor,#view-tutorial{flex:1;overflow:hidden;display:none;flex-direction:column}
#view-editor.active,#view-tutorial.active{display:flex}
.editor-layout{flex:1;display:grid;grid-template-columns:1fr 1fr;overflow:hidden}
.pane{display:flex;flex-direction:column;overflow:hidden;border-right:1px solid var(--border)}
.pane:last-child{border-right:none}
.pane-bar{display:flex;align-items:center;gap:8px;padding:0 14px;height:36px;background:var(--surf);border-bottom:1px solid var(--border);flex-shrink:0}
.pane-label{font-size:10px;font-weight:600;text-transform:uppercase;letter-spacing:.1em;color:var(--muted)}
.pill{font-size:10px;padding:2px 7px;border-radius:9px;font-weight:600}
.pill-g{background:#052e16;color:var(--green)}
.pill-p{background:#1e1b4b;color:var(--purple)}
.run-btn{margin-left:auto;background:var(--green);color:#052e16;border:none;padding:4px 13px;border-radius:5px;font-size:11px;font-weight:700;cursor:pointer;font-family:inherit;transition:opacity .12s}
.run-btn:hover{opacity:.82}
.editor-wrap{flex:1;position:relative;overflow:hidden}
textarea{position:absolute;inset:0;width:100%;height:100%;background:transparent;border:none;outline:none;resize:none;font-family:var(--mono);font-size:13px;line-height:1.75;color:var(--text);padding:14px 16px;tab-size:2;caret-color:var(--green)}
.output{flex:1;overflow-y:auto;padding:14px 16px;font-family:var(--mono);font-size:12.5px;line-height:1.75}
.out-line{display:block}
.kw{color:var(--purple)}.str{color:var(--yellow)}.fn{color:var(--green)}.cm{color:#4b5563}.nm{color:var(--pink)}
footer{height:24px;display:flex;align-items:center;gap:16px;padding:0 14px;background:var(--surf);border-top:1px solid var(--border);flex-shrink:0}
.stat{display:flex;align-items:center;gap:5px;font-size:10px;color:var(--muted)}
.dot{width:5px;height:5px;border-radius:50%}
.dot-g{background:var(--green)}.dot-p{background:var(--purple)}
.sheet-toggle{margin-left:auto;background:none;border:none;color:var(--muted);font-size:10px;cursor:pointer;font-family:inherit;padding:2px 6px;border-radius:4px;transition:color .12s}
.sheet-toggle:hover{color:var(--text)}
.cheatsheet{position:fixed;right:14px;bottom:34px;width:270px;background:var(--surf2);border:1px solid var(--border);border-radius:10px;padding:12px 14px;font-size:11px;line-height:1.8;display:none;z-index:200;box-shadow:0 8px 32px #00000077}
.cheatsheet.open{display:block}
.cheatsheet h3{font-size:10px;color:var(--muted);text-transform:uppercase;letter-spacing:.08em;margin-bottom:8px;font-weight:600}
.cheatsheet code{font-family:var(--mono);color:var(--green);background:#052e1622;padding:1px 4px;border-radius:3px;font-size:10.5px}
.cheatsheet .crow{display:flex;justify-content:space-between;gap:8px;padding:2px 0;border-bottom:1px solid var(--border)}
.cheatsheet .crow:last-child{border-bottom:none}
.cheatsheet .desc{color:var(--muted);font-size:10px}
/* TUTORIAL */
#view-tutorial{flex-direction:row}
.tut-sidebar{width:210px;flex-shrink:0;background:var(--surf);border-right:1px solid var(--border);display:flex;flex-direction:column;overflow:hidden}
.tut-sidebar-head{padding:14px 14px 10px;border-bottom:1px solid var(--border);flex-shrink:0}
.tut-sidebar-head h2{font-size:12px;font-weight:700;color:var(--green);margin-bottom:2px;text-transform:uppercase;letter-spacing:.06em}
.tut-sidebar-head p{font-size:10px;color:var(--muted)}
.tut-steps{flex:1;overflow-y:auto;padding:6px 0}
.tut-step-btn{display:flex;align-items:center;gap:9px;width:100%;padding:7px 12px;background:none;border:none;text-align:left;cursor:pointer;font-family:inherit;transition:background .1s;border-left:3px solid transparent}
.tut-step-btn:hover{background:var(--surf2)}
.tut-step-btn.active{background:var(--surf2);border-left-color:var(--green)}
.tut-step-btn.done .step-num{background:var(--green);color:#052e16;border-color:var(--green)}
.step-num{width:20px;height:20px;border-radius:50%;background:var(--surf2);border:1px solid var(--border);font-size:9px;font-weight:700;display:flex;align-items:center;justify-content:center;color:var(--muted);flex-shrink:0;transition:all .15s}
.tut-step-btn.active .step-num{background:var(--purple);border-color:var(--purple);color:#fff}
.step-info{flex:1;min-width:0}
.step-name{font-size:11px;color:var(--text);font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.step-sub{font-size:9.5px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.tut-prog-bar{height:3px;background:var(--border);flex-shrink:0}
.tut-prog-fill{height:100%;background:var(--green);transition:width .4s ease}
.tut-body{flex:1;display:grid;grid-template-columns:1fr 1fr;overflow:hidden}
.tut-left{display:flex;flex-direction:column;overflow:hidden;border-right:1px solid var(--border)}
.tut-right{display:flex;flex-direction:column;overflow:hidden}
.npc-box{flex-shrink:0;padding:14px 16px;border-bottom:1px solid var(--border);background:var(--surf)}
.npc-head{display:flex;align-items:center;gap:9px;margin-bottom:9px}
.npc-avatar{width:34px;height:34px;border-radius:50%;background:linear-gradient(135deg,#052e16,#064e3b);border:2px solid var(--green);display:flex;align-items:center;justify-content:center;font-size:17px;flex-shrink:0}
.npc-name{font-size:11px;font-weight:700;color:var(--green)}
.npc-title{font-size:9.5px;color:var(--muted)}
.npc-text{font-size:12.5px;line-height:1.6;color:var(--text);min-height:56px}
.npc-cursor{display:inline-block;width:2px;height:12px;background:var(--green);margin-left:2px;vertical-align:middle;animation:blink 1s step-end infinite}
@keyframes blink{0%,100%{opacity:1}50%{opacity:0}}
.task-card{flex-shrink:0;margin:10px 14px 0;padding:9px 12px;background:var(--surf2);border:1px solid var(--border);border-radius:7px;border-left:3px solid var(--yellow)}
.task-card-label{font-size:9px;text-transform:uppercase;letter-spacing:.1em;color:var(--yellow);font-weight:700;margin-bottom:3px}
.task-card-text{font-size:11.5px;color:var(--text);line-height:1.5}
.hint-box{flex-shrink:0;margin:8px 14px 0;padding:7px 11px;background:#1e1b4b33;border:1px solid #818cf833;border-radius:6px}
.hint-label{font-size:9px;text-transform:uppercase;letter-spacing:.1em;color:var(--muted);font-weight:700;display:block;margin-bottom:3px}
.hint-code{font-family:var(--mono);font-size:11px;color:var(--purple);white-space:pre;line-height:1.6}
.success-bar{display:none;flex-shrink:0;margin:8px 14px;padding:9px 12px;background:#052e16;border:1px solid var(--green);border-radius:7px;font-size:11.5px;color:var(--green);align-items:center;gap:9px}
.success-bar.show{display:flex}
.success-bar span{flex:1}
.next-btn{background:var(--green);color:#052e16;border:none;padding:4px 12px;border-radius:5px;font-size:11px;font-weight:700;cursor:pointer;font-family:inherit;white-space:nowrap}
.tut-editor-bar{display:flex;align-items:center;gap:8px;padding:0 14px;height:32px;background:var(--surf);border-top:1px solid var(--border);border-bottom:1px solid var(--border);flex-shrink:0;margin-top:8px}
.tut-wrap{flex:1;position:relative;overflow:hidden}
.tut-wrap textarea{font-size:12.5px;padding:10px 14px}
.tut-out-bar{display:flex;align-items:center;gap:8px;padding:0 14px;height:32px;background:var(--surf);border-bottom:1px solid var(--border);flex-shrink:0}
.tut-output{flex:1;overflow-y:auto;padding:12px 14px;font-family:var(--mono);font-size:12px;line-height:1.75}
.completion{display:none;flex:1;flex-direction:column;align-items:center;justify-content:center;gap:14px;padding:40px;text-align:center}
.completion.show{display:flex}
.comp-emoji{font-size:60px}
.completion h2{font-size:20px;font-weight:700;color:var(--green)}
.completion p{font-size:13px;color:var(--muted);max-width:360px;line-height:1.7}
.to-editor{background:var(--green);color:#052e16;border:none;padding:9px 22px;border-radius:7px;font-size:13px;font-weight:700;cursor:pointer;font-family:inherit;margin-top:6px}
</style>
</head>
<body>
<header>
<div class="logo">🌿 Weave <span class="version">v0.3.0</span></div>
<div class="nav-tabs">
<button class="nav-tab active" id="tab-editor" onclick="switchView('editor')">Editor</button>
<button class="nav-tab" id="tab-tutorial" onclick="switchView('tutorial')">▶ Tutorial</button>
</div>
<div class="example-tabs" id="etabs">
<button class="ex active" onclick="loadEx('hello',this)">Hello</button>
<button class="ex" onclick="loadEx('dom',this)">Webpage</button>
<button class="ex" onclick="loadEx('ping',this)">Ping</button>
<button class="ex" onclick="loadEx('data',this)">Load Data</button>
<button class="ex" onclick="loadEx('logic',this)">Logic</button>
<button class="ex" onclick="loadEx('blank',this)">Blank</button>
</div>
<button class="install-btn" id="install-btn" onclick="installApp()">⬇ Install</button>
</header>
<!-- EDITOR -->
<div id="view-editor" class="active">
<div class="editor-layout">
<div class="pane">
<div class="pane-bar">
<span class="pane-label">Weave</span>
<span class="pill pill-g">.web</span>
<button class="run-btn" onclick="compile()">▶ Compile</button>
</div>
<div class="editor-wrap">
<textarea id="src" spellcheck="false" autocorrect="off" autocapitalize="off" oninput="compile()" placeholder="Write Weave here..."></textarea>
</div>
</div>
<div class="pane">
<div class="pane-bar">
<span class="pane-label">JavaScript output</span>
<span class="pill pill-p">.js</span>
</div>
<div class="output" id="out"></div>
</div>
</div>
<footer>
<div class="stat"><div class="dot dot-g"></div><span id="s-in">0 lines</span></div>
<div class="stat"><div class="dot dot-p"></div><span id="s-out">0 lines out</span></div>
<button class="sheet-toggle" onclick="toggleSheet()">? cheat sheet</button>
</footer>
</div>
<!-- TUTORIAL -->
<div id="view-tutorial">
<div class="tut-sidebar">
<div class="tut-sidebar-head">
<h2>🎮 Weave Quest</h2>
<p>Learn one command at a time</p>
</div>
<div class="tut-steps" id="tut-steps"></div>
<div class="tut-prog-bar"><div class="tut-prog-fill" id="tut-prog"></div></div>
</div>
<div class="tut-body" id="tut-body">
<div class="tut-left">
<div class="npc-box">
<div class="npc-head">
<div class="npc-avatar">🧙</div>
<div>
<div class="npc-name">Wren the Compiler</div>
<div class="npc-title">Ancient Guide to Weave</div>
</div>
</div>
<div class="npc-text" id="npc-text"><span class="npc-cursor"></span></div>
</div>
<div class="task-card">
<div class="task-card-label">📋 Your task</div>
<div class="task-card-text" id="task-text">—</div>
</div>
<div class="hint-box">
<span class="hint-label">💡 Hint</span>
<span class="hint-code" id="hint-text"></span>
</div>
<div class="success-bar" id="success-bar">
<span id="success-text">✅ Perfect!</span>
<button class="next-btn" onclick="nextStep()">Next →</button>
</div>
<div class="tut-editor-bar">
<span class="pane-label">Your code</span>
<span class="pill pill-g">.web</span>
<button class="run-btn" onclick="tutCompile()">▶ Run</button>
</div>
<div class="tut-wrap">
<textarea id="tut-src" spellcheck="false" autocorrect="off" autocapitalize="off" oninput="tutCompile()" placeholder="Type your Weave here..."></textarea>
</div>
</div>
<div class="tut-right">
<div class="tut-out-bar">
<span class="pane-label">JavaScript output</span>
<span class="pill pill-p">.js</span>
</div>
<div class="tut-output" id="tut-out"></div>
</div>
</div>
<div class="completion" id="tut-complete">
<div class="comp-emoji">🏆</div>
<h2>Quest Complete!</h2>
<p>You've learned every core command — say, put, on, load, ping, task, and variables. You're ready to build real things with Weave.</p>
<button class="to-editor" onclick="switchView('editor')">Open the Editor →</button>
</div>
</div>
<div class="cheatsheet" id="sheet">
<h3>Weave reference</h3>
<div class="crow"><code>say(value)</code><span class="desc">print to console</span></div>
<div class="crow"><code>put(val,"#id")</code><span class="desc">put text on page</span></div>
<div class="crow"><code>on("#id","click",fn)</code><span class="desc">listen for click</span></div>
<div class="crow"><code>load("url")</code><span class="desc">fetch JSON data</span></div>
<div class="crow"><code>ping("url")</code><span class="desc">check if URL is alive</span></div>
<div class="crow"><code>task name(args){}</code><span class="desc">define a task</span></div>
<div class="crow"><code>let x = value</code><span class="desc">store a value</span></div>
<div class="crow"><code>// comment</code><span class="desc">note to yourself</span></div>
</div>
<script>
// COMPILER
function compileLine(line){
const t=line.trim();
if(!t||t.startsWith('//'))return line;
if(/^task\s+\w+\s*\(/.test(t))return line.replace(/\btask\b/,'function');
if(/\bsay\s*\(/.test(t))return line.replace(/\bsay\s*\(/g,'console.log(');
if(/\bping\s*\(\s*["']/.test(t))return line.replace(/\bping\s*\(\s*["'](.+?)["']\s*\)/g,"await fetch('$1',{method:'HEAD'}).then(r=>r.ok).catch(()=>false)");
const put=t.match(/^put\s*\(\s*(.+?)\s*,\s*["'](.+?)["']\s*\)$/);
if(put){const ind=line.match(/^(\s*)/)[1];return`${ind}document.querySelector("${put[2]}").textContent=${put[1]};`;}
const on=t.match(/^on\s*\(\s*["'](.+?)["']\s*,\s*["'](.+?)["']\s*,\s*(.+?)\s*\)$/);
if(on){const ind=line.match(/^(\s*)/)[1];return`${ind}document.querySelector("${on[1]}").addEventListener("${on[2]}",${on[3]});`;}
if(/\bload\s*\(\s*["']/.test(t))return line.replace(/\bload\s*\(\s*["'](.+?)["']\s*\)/g,"await fetch('$1').then(r=>r.json())");
return line;
}
function compileSource(src){return src.split('\n').map(compileLine).join('\n');}
// HIGHLIGHT
function esc(s){return s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');}
function highlight(line){
if(!line.trim())return'';
let h=esc(line);
if(h.trim().startsWith('//'))return`<span class="cm">${h}</span>`;
h=h.replace(/('[^]*?'|"[^]*?")/g,'<span class="str">$1</span>');
h=h.replace(/\b(const|let|function|return|async|await|if|else|for|while|of|in)\b/g,'<span class="kw">$1</span>');
h=h.replace(/\b(console\.log|document\.querySelector|addEventListener|fetch)\b/g,'<span class="fn">$1</span>');
h=h.replace(/\b(\d+)\b/g,'<span class="nm">$1</span>');
return h;
}
function renderOutput(src,elId){
const out=compileSource(src);
document.getElementById(elId).innerHTML=out.split('\n').map(l=>`<span class="out-line">${highlight(l)||' '}</span>`).join('\n');
return out;
}
// EDITOR EXAMPLES
const EX={
hello:`// Hello World in Weave\n\nlet name = "world"\nsay("Hello, " + name + "!")\n\ntask greet(person) {\n return "Hey, " + person + "!"\n}\n\nsay(greet("Claude"))`,
dom:`// Talking to a webpage\n\nlet score = 0\n\nput("Click the button!", "#message")\non("#btn", "click", addPoint)\n\ntask addPoint() {\n score = score + 1\n put(score, "#score")\n if (score >= 10) {\n put("You win!", "#message")\n }\n}`,
ping:`// Check if a server is alive\n\ntask checkSite() {\n let alive = ping("https://example.com")\n if (alive) {\n say("Site is UP!")\n put("🟢 Online", "#status")\n } else {\n say("Site is down.")\n put("🔴 Offline", "#status")\n }\n}\n\ncheckSite()`,
data:`// Load data from the internet\n\ntask loadUser() {\n let user = load("https://jsonplaceholder.typicode.com/users/1")\n say(user.name)\n say(user.email)\n put(user.name, "#username")\n}\n\nloadUser()`,
logic:`// Logic and loops\n\nlet nums = [1,2,3,4,5]\n\nfor (let n of nums) {\n if (n % 2 === 0) {\n say(n + " is even")\n } else {\n say(n + " is odd")\n }\n}\n\ntask biggest(a,b) {\n if (a > b) { return a }\n return b\n}\n\nsay("Biggest: " + biggest(42, 17))`,
blank:`// Start writing Weave...\n\n`
};
function loadEx(k,btn){
document.querySelectorAll('.ex').forEach(b=>b.classList.remove('active'));
if(btn)btn.classList.add('active');
document.getElementById('src').value=EX[k];
compile();
}
function compile(){
const src=document.getElementById('src').value;
const out=renderOutput(src,'out');
const il=src.split('\n').filter(l=>l.trim()).length;
const ol=out.split('\n').filter(l=>l.trim()).length;
document.getElementById('s-in').textContent=`${il} line${il!==1?'s':''}`;
document.getElementById('s-out').textContent=`${ol} line${ol!==1?'s':''} out`;
}
// VIEW SWITCH
function switchView(v){
document.getElementById('view-editor').classList.toggle('active',v==='editor');
document.getElementById('view-tutorial').classList.toggle('active',v==='tutorial');
document.getElementById('tab-editor').classList.toggle('active',v==='editor');
document.getElementById('tab-tutorial').classList.toggle('active',v==='tutorial');
document.getElementById('etabs').style.display=v==='editor'?'flex':'none';
if(v==='tutorial')renderStep(tutStep);
}
// TUTORIAL
const STEPS=[
{
name:'Welcome',sub:'Meet Wren',
npc:"Welcome, new programmer! I'm Wren — your guide through Weave.\n\nWeave is a language where you just say what you want, and it happens. No weird rules. No ceremony.\n\nLet's start with the most basic thing: printing a message. Copy the hint below exactly and hit Run.",
task:'Write your very first line of Weave. Copy the hint exactly.',
hint:'say("Hello, Weave!")',
check:s=>s.includes('say(')&&(s.includes('Hello')||s.includes('"')),
win:'🎉 It ran! say() prints anything you put inside the brackets.'
},
{
name:'Variables',sub:'Store values with let',
npc:"Great work!\n\nNow let's store some information. A variable is just a label for a value — like a named sticky note.\n\nYou make one with the word \"let\". Then you can use that label anywhere.",
task:'Create a variable with your name in it. Then say it.',
hint:'let name = "Your Name"\nsay(name)',
check:s=>s.includes('let ')&&s.includes('say('),
win:'✅ Variables work! "let" stores any value so you can use it later.'
},
{
name:'Tasks',sub:'Reusable blocks of code',
npc:"Variables store data. Tasks store actions.\n\nA task is a named block of steps you can run anytime — just by calling its name with ().\n\nDefine a task, then call it. You can call it as many times as you want.",
task:'Write a task called "greet" that says "Hello!" — then call it.',
hint:'task greet() {\n say("Hello!")\n}\n\ngreet()',
check:s=>s.includes('task ')&&/\w+\s*\(\s*\)/.test(s)&&s.includes('say('),
win:'🛠️ Tasks mastered! Call them once, call them a hundred times.'
},
{
name:'put()',sub:'Write text onto a webpage',
npc:"say() is great for testing in the console.\n\nBut when you build a real webpage, you want text to appear ON the page itself. That's put().\n\nIt takes two things: what to show, and where to put it. The \"where\" is a CSS ID like \"#box\".",
task:'Use put() to put a message at the selector "#output".',
hint:'put("I built this!", "#output")',
check:s=>s.includes('put(')&&s.includes('#'),
win:'📄 put() works! In a real page, "#output" points to an HTML element.'
},
{
name:'on()',sub:'Listen for clicks and events',
npc:"put() puts things on the page. on() makes the page react.\n\non() watches an element and runs a task when something happens — like a click.\n\nThree things: what to watch, what event, and what task to run.",
task:'Use on() to run a task called "handleClick" when "#btn" is clicked.',
hint:'task handleClick() {\n say("Clicked!")\n}\n\non("#btn", "click", handleClick)',
check:s=>s.includes('on(')&&s.includes('click')&&s.includes('task '),
win:'👆 on() connected! Your code now responds to what users do.'
},
{
name:'load()',sub:'Fetch live data from the web',
npc:"Now for something powerful — pulling live data from the internet.\n\nload() fetches data from a URL and hands it back to you as an object you can read.\n\nWrap it in a task so it runs cleanly. Try the URL in the hint — it's a free test API.",
task:'Write a task that loads data from the hint URL and says something from it.',
hint:'task getData() {\n let data = load("https://jsonplaceholder.typicode.com/todos/1")\n say(data.title)\n}\n\ngetData()',
check:s=>s.includes('load(')&&s.includes('task '),
win:'🌐 load() works! You just pulled live data from the internet.'
},
{
name:'ping()',sub:'Check if a URL is alive',
npc:"Sometimes you don't need the data — you just need to know if a server is up.\n\nping() sends a quick knock on a URL's door. It gives back true if it answers, false if it doesn't.\n\nPair it with if/else to do something based on the result.",
task:'Write a task that pings a URL and says whether it\'s up or down.',
hint:'task checkSite() {\n let alive = ping("https://example.com")\n if (alive) {\n say("Site is UP!")\n } else {\n say("Site is DOWN.")\n }\n}\n\ncheckSite()',
check:s=>s.includes('ping(')&&s.includes('if'),
win:'📡 ping() done! You can now monitor any URL from your code.'
},
{
name:'Final boss',sub:'Put it all together',
npc:"You've learned everything Weave has to offer.\n\nNow make something with it. Anything. Use at least three different commands — mix and match.\n\nThere's no right answer here. This is yours.",
task:'Write a program using at least 3 different commands: say, put, on, load, ping, or task.',
hint:'// One idea — mix freely:\nlet name = "World"\nsay("Hello, " + name)\ntask greet() { say("You did it!") }\ngreet()',
check:s=>{
const cmds=['say(','put(','on(','load(','ping(','task '];
return cmds.filter(c=>s.includes(c)).length>=3;
},
win:'🏆 QUEST COMPLETE! You are now a Weave programmer. Go build something real.'
}
];
let tutStep=0;
let typingTimer=null;
function buildSidebar(){
document.getElementById('tut-steps').innerHTML=STEPS.map((s,i)=>`
<button class="tut-step-btn" id="tstep-${i}" onclick="goStep(${i})">
<div class="step-num">${i+1}</div>
<div class="step-info">
<div class="step-name">${s.name}</div>
<div class="step-sub">${s.sub}</div>
</div>
</button>`).join('');
}
function goStep(i){tutStep=i;renderStep(i);}
function renderStep(i){
const step=STEPS[i];
if(!step){showCompletion();return;}
document.querySelectorAll('.tut-step-btn').forEach((b,j)=>b.classList.toggle('active',j===i));
document.getElementById('tut-prog').style.width=((i/STEPS.length)*100)+'%';
document.getElementById('success-bar').classList.remove('show');
document.getElementById('task-text').textContent=step.task;
document.getElementById('hint-text').textContent=step.hint;
document.getElementById('tut-src').value='';
document.getElementById('tut-out').innerHTML='';
typeWriter(step.npc);
}
function typeWriter(text){
clearTimeout(typingTimer);
const el=document.getElementById('npc-text');
el.innerHTML='<span class="npc-cursor"></span>';
let i=0;
function tick(){
if(i<=text.length){
el.innerHTML=text.slice(0,i).replace(/\n/g,'<br>')+'<span class="npc-cursor"></span>';
i++;
typingTimer=setTimeout(tick,i<30?0:16);
}
}
tick();
}
function tutCompile(){
const src=document.getElementById('tut-src').value;
renderOutput(src,'tut-out');
const step=STEPS[tutStep];
if(step&&step.check(src)){
document.getElementById('success-text').textContent=step.win;
document.getElementById('success-bar').classList.add('show');
const btn=document.getElementById(`tstep-${tutStep}`);
if(btn)btn.classList.add('done');
document.getElementById('tut-prog').style.width=(((tutStep+1)/STEPS.length)*100)+'%';
}
}
function nextStep(){tutStep++;renderStep(tutStep);}
function showCompletion(){
document.getElementById('tut-body').style.display='none';
document.getElementById('tut-complete').classList.add('show');
document.getElementById('tut-prog').style.width='100%';
}
// CHEATSHEET
let sheetOpen=false;
function toggleSheet(){
sheetOpen=!sheetOpen;
document.getElementById('sheet').classList.toggle('open',sheetOpen);
}
document.addEventListener('click',e=>{
if(sheetOpen&&!e.target.closest('.cheatsheet')&&!e.target.closest('.sheet-toggle')){
sheetOpen=false;
document.getElementById('sheet').classList.remove('open');
}
});
// PWA
let deferredPrompt;
window.addEventListener('beforeinstallprompt',e=>{
e.preventDefault();deferredPrompt=e;
document.getElementById('install-btn').classList.add('visible');
});
async function installApp(){
if(!deferredPrompt)return;
deferredPrompt.prompt();
const{outcome}=await deferredPrompt.userChoice;
if(outcome==='accepted')document.getElementById('install-btn').classList.remove('visible');
deferredPrompt=null;
}
if('serviceWorker'in navigator)navigator.serviceWorker.register('sw.js').catch(()=>{});
// INIT
buildSidebar();
loadEx('hello');
</script>
</body>
</html>