Spaces:
Running
Running
Upload 22 files
Browse files- SETUP.html +547 -0
- favicon.svg +8 -0
- index.html +40 -17
- js/admin.js +650 -0
- js/app.js +181 -0
- js/auth.js +575 -0
- js/cloud.js +930 -0
- js/components.js +317 -0
- js/config.js +10 -0
- js/copy.js +69 -0
- js/engine.js +266 -0
- js/marking.js +544 -0
- js/pricing.js +187 -0
- js/runtime.js +16 -0
- js/screens-extra.js +517 -0
- js/screens.js +743 -0
- js/store.js +143 -0
- schema.sql +271 -0
- styles.css +432 -0
- vendor/htm.js +1 -0
- vendor/react-dom.js +0 -0
- vendor/react.js +31 -0
SETUP.html
ADDED
|
@@ -0,0 +1,547 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en-GB">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 6 |
+
<title>Setting up Explication — the picture guide</title>
|
| 7 |
+
<style>
|
| 8 |
+
:root {
|
| 9 |
+
--ink:#111114; --secondary:#56575e; --faint:#8c8d95; --hairline:#e8e8ec;
|
| 10 |
+
--accent:#1b6b4f; --accent-soft:#edf5f0; --accent-deep:#124a37;
|
| 11 |
+
--warning:#a9662f; --warning-soft:#f9eee0; --danger:#a3403f; --danger-soft:#f9e7e5;
|
| 12 |
+
--surface:#fff; --sunken:#f4f4f7; --deep:#f7f7f9;
|
| 13 |
+
--serif:"Iowan Old Style","Palatino Linotype",Palatino,Georgia,serif;
|
| 14 |
+
--sans:-apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe UI",Roboto,Helvetica,Arial,sans-serif;
|
| 15 |
+
--mono:ui-monospace,SFMono-Regular,Menlo,monospace;
|
| 16 |
+
}
|
| 17 |
+
*{box-sizing:border-box}
|
| 18 |
+
body{margin:0;font-family:var(--sans);color:var(--ink);background:#fff;font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased}
|
| 19 |
+
a{color:var(--accent)}
|
| 20 |
+
.wrap{max-width:960px;margin:0 auto;padding:0 22px 90px}
|
| 21 |
+
header.hero{padding:54px 0 4px;border-bottom:1px solid var(--hairline);background:linear-gradient(180deg,#f3f8f4, #fff)}
|
| 22 |
+
header.hero .wrap{padding-bottom:28px}
|
| 23 |
+
.badge{display:inline-flex;align-items:center;gap:6px;background:#fff;border:1px solid #dde8e0;color:var(--accent-deep);border-radius:999px;padding:5px 11px;font-size:10.5px;font-weight:700;letter-spacing:.04em;text-transform:uppercase}
|
| 24 |
+
h1{font-family:var(--serif);font-size:44px;line-height:1.05;letter-spacing:-.03em;margin:14px 0 0;max-width:700px}
|
| 25 |
+
.lede{font-size:15px;color:var(--secondary);max-width:620px;margin:12px 0 0;line-height:1.6}
|
| 26 |
+
.meta{display:flex;gap:16px;flex-wrap:wrap;margin-top:16px;font-size:11.5px;color:var(--faint);font-weight:600}
|
| 27 |
+
.meta span{display:inline-flex;align-items:center;gap:5px}
|
| 28 |
+
.dot{width:6px;height:6px;border-radius:50%;background:var(--accent)}
|
| 29 |
+
|
| 30 |
+
.step{margin-top:34px;border-top:1px solid var(--hairline);padding-top:26px}
|
| 31 |
+
.step:first-of-type{border-top:0;margin-top:0;padding-top:0}
|
| 32 |
+
.step-head{display:flex;gap:14px;align-items:flex-start}
|
| 33 |
+
.num{flex:0 0 34px;height:34px;border-radius:50%;background:var(--ink);color:#fff;display:grid;place-items:center;font-weight:700;font-size:14px}
|
| 34 |
+
.step h2{font-family:var(--serif);font-size:24px;letter-spacing:-.02em;margin:0;line-height:1.2}
|
| 35 |
+
.step .why{color:var(--secondary);font-size:13px;margin:5px 0 0;max-width:640px;line-height:1.55}
|
| 36 |
+
.body{padding-left:48px;margin-top:16px}
|
| 37 |
+
|
| 38 |
+
.window{border:1px solid var(--hairline);border-radius:12px;overflow:hidden;background:#fff;box-shadow:0 8px 26px rgba(11,12,14,.06)}
|
| 39 |
+
.chrome{display:flex;align-items:center;gap:6px;padding:8px 10px;background:var(--deep);border-bottom:1px solid var(--hairline)}
|
| 40 |
+
.chrome i{width:8px;height:8px;border-radius:50%;background:#d9d9df;display:block}
|
| 41 |
+
.chrome .url{margin-left:8px;font-family:var(--mono);font-size:10px;color:var(--faint);background:#fff;border:1px solid var(--hairline);border-radius:6px;padding:3px 8px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
|
| 42 |
+
.pane{display:flex;min-height:120px}
|
| 43 |
+
.rail{flex:0 0 168px;border-right:1px solid var(--hairline);padding:12px;background:#fbfbfc}
|
| 44 |
+
.rail .item{display:flex;align-items:center;gap:7px;font-size:11px;color:var(--secondary);padding:6px 7px;border-radius:7px;margin-bottom:2px}
|
| 45 |
+
.rail .item.on{background:var(--accent-soft);color:var(--accent-deep);font-weight:700}
|
| 46 |
+
.rail .item .ic{width:14px;height:14px;border-radius:4px;border:1px solid #cfcfd6;display:grid;place-items:center;font-size:8px;font-weight:700;color:var(--faint);background:#fff}
|
| 47 |
+
.canvas{flex:1;padding:16px;min-width:0}
|
| 48 |
+
.canvas h4{margin:0 0 4px;font-size:13px}
|
| 49 |
+
.canvas p{margin:0;font-size:11.5px;color:var(--secondary)}
|
| 50 |
+
.field{border:1px solid var(--hairline);border-radius:8px;padding:8px 10px;font-size:11.5px;color:var(--ink);background:#fff;display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:8px}
|
| 51 |
+
.field .lab{color:var(--faint);font-size:10px;display:block;margin-bottom:2px}
|
| 52 |
+
.field code{font-family:var(--mono);font-size:10.5px;color:var(--secondary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:340px}
|
| 53 |
+
.btn{display:inline-flex;align-items:center;gap:6px;background:var(--ink);color:#fff;border:0;border-radius:7px;padding:7px 11px;font-size:11.5px;font-weight:600}
|
| 54 |
+
.btn.green{background:var(--accent)}
|
| 55 |
+
.btn.ghost{background:#fff;color:var(--ink);border:1px solid var(--hairline)}
|
| 56 |
+
.row{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-top:10px}
|
| 57 |
+
.toggle{width:30px;height:17px;border-radius:999px;background:var(--accent);position:relative;display:inline-block;flex:0 0 30px}
|
| 58 |
+
.toggle::after{content:"";position:absolute;right:2px;top:2px;width:13px;height:13px;border-radius:50%;background:#fff}
|
| 59 |
+
.listline{display:flex;align-items:center;justify-content:space-between;gap:10px;border-top:1px solid var(--hairline);padding:9px 0;font-size:11.5px}
|
| 60 |
+
.listline:first-child{border-top:0}
|
| 61 |
+
.pin{display:inline-grid;place-items:center;width:17px;height:17px;border-radius:50%;background:var(--ink);color:#fff;font-size:9.5px;font-weight:700;vertical-align:middle;margin-right:4px}
|
| 62 |
+
|
| 63 |
+
.do{margin-top:12px;background:var(--accent-soft);border:1px solid #d9eae1;border-radius:10px;padding:12px 14px;font-size:12.5px;color:var(--accent-deep);line-height:1.6}
|
| 64 |
+
.do b{font-weight:700}
|
| 65 |
+
.warn{margin-top:12px;background:var(--warning-soft);border:1px solid #f0dcc5;border-radius:10px;padding:12px 14px;font-size:12.5px;color:#7d4a1f;line-height:1.6}
|
| 66 |
+
.tip{margin-top:10px;font-size:11.5px;color:var(--faint)}
|
| 67 |
+
code.inline{font-family:var(--mono);font-size:11.5px;background:var(--deep);border:1px solid var(--hairline);border-radius:5px;padding:1px 5px}
|
| 68 |
+
.copy{font-family:var(--sans);cursor:pointer}
|
| 69 |
+
|
| 70 |
+
table.where{width:100%;border-collapse:collapse;margin-top:10px;font-size:12px}
|
| 71 |
+
table.where th{text-align:left;font-size:9.5px;letter-spacing:.07em;text-transform:uppercase;color:var(--faint);font-weight:700;padding:0 0 6px}
|
| 72 |
+
table.where td{padding:8px 10px 8px 0;border-top:1px solid var(--hairline);vertical-align:top;color:var(--secondary)}
|
| 73 |
+
table.where td:first-child{color:var(--ink);font-weight:600;width:38%}
|
| 74 |
+
|
| 75 |
+
footer{margin-top:44px;border-top:1px solid var(--hairline);padding-top:18px;font-size:11.5px;color:var(--faint)}
|
| 76 |
+
@media (max-width:720px){
|
| 77 |
+
h1{font-size:33px}.body{padding-left:0}.pane{flex-direction:column}.rail{flex:none;border-right:0;border-bottom:1px solid var(--hairline)}
|
| 78 |
+
.field code{max-width:180px}
|
| 79 |
+
}
|
| 80 |
+
</style>
|
| 81 |
+
</head>
|
| 82 |
+
<body>
|
| 83 |
+
<header class="hero">
|
| 84 |
+
<div class="wrap">
|
| 85 |
+
<span class="badge">● Explication setup</span>
|
| 86 |
+
<h1>From an empty folder to taking payments.</h1>
|
| 87 |
+
<p class="lede">Nine screens for the website, then one for the iPhone app. Each tells you exactly where to click, what to copy and where to paste it. No terminal, no code, no guessing.</p>
|
| 88 |
+
<div class="meta"><span><i class="dot"></i> About 20 minutes</span><span><i class="dot"></i> Free tiers are enough</span><span><i class="dot"></i> Test mode first, real money later</span></div>
|
| 89 |
+
</div>
|
| 90 |
+
</header>
|
| 91 |
+
|
| 92 |
+
<div class="wrap">
|
| 93 |
+
|
| 94 |
+
<section class="step">
|
| 95 |
+
<div class="step-head">
|
| 96 |
+
<div class="num">1</div>
|
| 97 |
+
<div>
|
| 98 |
+
<h2>Make a Supabase project</h2>
|
| 99 |
+
<p class="why">Supabase is the free service that holds the accounts, the plans and the page wording. One project is all you need.</p>
|
| 100 |
+
</div>
|
| 101 |
+
</div>
|
| 102 |
+
<div class="body">
|
| 103 |
+
<div class="window">
|
| 104 |
+
<div class="chrome"><i></i><i></i><i></i><span class="url">supabase.com/dashboard</span></div>
|
| 105 |
+
<div class="pane">
|
| 106 |
+
<div class="rail">
|
| 107 |
+
<div class="item on"><span class="ic">+</span> New project</div>
|
| 108 |
+
<div class="item"><span class="ic">▦</span> All projects</div>
|
| 109 |
+
<div class="item"><span class="ic">?</span> Help</div>
|
| 110 |
+
</div>
|
| 111 |
+
<div class="canvas">
|
| 112 |
+
<h4>Create a new project</h4>
|
| 113 |
+
<p>Free. Pick the region closest to you.</p>
|
| 114 |
+
<div class="field"><span><span class="lab">Name</span><code>explication</code></span></div>
|
| 115 |
+
<div class="field"><span><span class="lab">Database password</span><code>••••••••••••</code></span><span class="pin">1</span></div>
|
| 116 |
+
<div class="field"><span><span class="lab">Region</span><code>Europe (London)</code></span></div>
|
| 117 |
+
<div class="row"><button class="btn green">Create new project</button></div>
|
| 118 |
+
</div>
|
| 119 |
+
</div>
|
| 120 |
+
</div>
|
| 121 |
+
<div class="do"><b>Do this:</b> go to <a href="https://supabase.com/dashboard" target="_blank" rel="noreferrer">supabase.com/dashboard</a>, sign in, click <b>New project</b>. Name it <b>explication</b>, save the database password somewhere safe <span class="pin">1</span> (you will not need it in this guide), pick the closest region, and press <b>Create new project</b>. Wait about two minutes while it builds.</div>
|
| 122 |
+
</div>
|
| 123 |
+
</section>
|
| 124 |
+
|
| 125 |
+
<section class="step">
|
| 126 |
+
<div class="step-head">
|
| 127 |
+
<div class="num">2</div>
|
| 128 |
+
<div>
|
| 129 |
+
<h2>Paste in the database file</h2>
|
| 130 |
+
<p class="why">This creates every table the site needs, fills in the seven plans, and locks all editing to your developer email.</p>
|
| 131 |
+
</div>
|
| 132 |
+
</div>
|
| 133 |
+
<div class="body">
|
| 134 |
+
<div class="window">
|
| 135 |
+
<div class="chrome"><i></i><i></i><i></i><span class="url">supabase.com → your project → SQL Editor</span></div>
|
| 136 |
+
<div class="pane">
|
| 137 |
+
<div class="rail">
|
| 138 |
+
<div class="item"><span class="ic">▦</span> Table editor</div>
|
| 139 |
+
<div class="item on"><span class="ic">>_</span> SQL Editor</div>
|
| 140 |
+
<div class="item"><span class="ic">⚿</span> Authentication</div>
|
| 141 |
+
<div class="item"><span class="ic">⚙</span> Project Settings</div>
|
| 142 |
+
</div>
|
| 143 |
+
<div class="canvas">
|
| 144 |
+
<h4>New query</h4>
|
| 145 |
+
<p>Paste the whole file, then press Run.</p>
|
| 146 |
+
<div class="field" style="min-height:74px;align-items:flex-start"><code style="white-space:pre-line;max-width:100%">create extension if not exists pgcrypto;<br/>create table public.explication_plans ( … );</code></div>
|
| 147 |
+
<div class="row"><button class="btn green">▷ Run</button><button class="btn ghost">Save</button><span class="pin">2</span></div>
|
| 148 |
+
</div>
|
| 149 |
+
</div>
|
| 150 |
+
</div>
|
| 151 |
+
<div class="do">
|
| 152 |
+
<b>Do this:</b> in the left sidebar click <b>SQL Editor</b> <span class="pin">2</span>, then <b>New query</b>.
|
| 153 |
+
Click the button below to copy the file, paste it into the big box, and press <b>Run</b>.
|
| 154 |
+
You should see <code class="inline">Success. No rows returned</code>.
|
| 155 |
+
<div class="row"><button class="btn copy" data-copy-sql="1">Copy the database file</button><span class="tip" id="copy-sql-note"></span></div>
|
| 156 |
+
</div>
|
| 157 |
+
<div class="warn">If you later change the plans, come back here and run the same file again — it updates the shop front in place without wiping anything.</div>
|
| 158 |
+
</div>
|
| 159 |
+
</section>
|
| 160 |
+
|
| 161 |
+
<section class="step">
|
| 162 |
+
<div class="step-head">
|
| 163 |
+
<div class="num">3</div>
|
| 164 |
+
<div>
|
| 165 |
+
<h2>Turn on email sign-in</h2>
|
| 166 |
+
<p class="why">Students sign in with an email and password. While you are testing, switch confirmation off so you can sign in instantly.</p>
|
| 167 |
+
</div>
|
| 168 |
+
</div>
|
| 169 |
+
<div class="body">
|
| 170 |
+
<div class="window">
|
| 171 |
+
<div class="chrome"><i></i><i></i><i></i><span class="url">supabase.com → Authentication → Providers</span></div>
|
| 172 |
+
<div class="pane">
|
| 173 |
+
<div class="rail">
|
| 174 |
+
<div class="item on"><span class="ic">⚿</span> Providers</div>
|
| 175 |
+
<div class="item"><span class="ic">@</span> Emails</div>
|
| 176 |
+
<div class="item"><span class="ic">↗</span> URL Configuration</div>
|
| 177 |
+
</div>
|
| 178 |
+
<div class="canvas">
|
| 179 |
+
<h4>Email</h4>
|
| 180 |
+
<p>The simplest way in.</p>
|
| 181 |
+
<div class="listline"><span>Enable email provider</span><span class="toggle"></span></div>
|
| 182 |
+
<div class="listline"><span>Confirm email <em style="color:var(--faint)">(off while testing)</em></span><span class="toggle" style="background:#dfe0e6"></span></div>
|
| 183 |
+
<div class="row"><button class="btn">Save</button><span class="pin">3</span></div>
|
| 184 |
+
</div>
|
| 185 |
+
</div>
|
| 186 |
+
</div>
|
| 187 |
+
<div class="do"> <b>Do this:</b> click <b>Authentication → Providers</b> <span class="pin">3</span>, open <b>Email</b>, make sure it is <b>enabled</b>. Turn <b>Confirm email</b> off for now — turn it back on before real students arrive. Press <b>Save</b>.<br><br>The branded email templates are in <code class="inline">emails/auth-emails.html</code> — one paste-ready block per email — with subject lines in <code class="inline">emails/auth-emails.txt</code>. Those templates only reach real students once a real sender is connected: that is <b>Make email actually arrive</b>, after step 9.</div>
|
| 188 |
+
</div>
|
| 189 |
+
</section>
|
| 190 |
+
|
| 191 |
+
<section class="step">
|
| 192 |
+
<div class="step-head">
|
| 193 |
+
<div class="num">4</div>
|
| 194 |
+
<div>
|
| 195 |
+
<h2>Copy two values into the site</h2>
|
| 196 |
+
<p class="why">The site needs the project's address and its public key. Nothing secret goes in the browser.</p>
|
| 197 |
+
</div>
|
| 198 |
+
</div>
|
| 199 |
+
<div class="body">
|
| 200 |
+
<div class="window">
|
| 201 |
+
<div class="chrome"><i></i><i></i><i></i><span class="url">supabase.com → Project Settings → API</span></div>
|
| 202 |
+
<div class="pane">
|
| 203 |
+
<div class="rail">
|
| 204 |
+
<div class="item"><span class="ic">⚙</span> General</div>
|
| 205 |
+
<div class="item on"><span class="ic">⚙</span> API</div>
|
| 206 |
+
<div class="item"><span class="ic">⚿</span> Database</div>
|
| 207 |
+
</div>
|
| 208 |
+
<div class="canvas">
|
| 209 |
+
<h4>Project API keys</h4>
|
| 210 |
+
<p>Copy these two. Ignore <b>service_role</b> for ever.</p>
|
| 211 |
+
<div class="field"><span><span class="lab">Project URL</span><code>https://abcdefgh.supabase.co</code></span><button class="btn ghost copy" data-copy="0">Copy</button></div>
|
| 212 |
+
<div class="field"><span><span class="lab">anon public</span><code>eyJhbGciOiJIUzI1NiIs…</code></span><button class="btn ghost copy" data-copy="1">Copy</button></div>
|
| 213 |
+
</div>
|
| 214 |
+
</div>
|
| 215 |
+
</div>
|
| 216 |
+
<div class="do"><b>Do this:</b> in Supabase click <b>Project Settings → API</b>. Copy <b>Project URL</b> and the <b>anon public</b> key. Then open the Explication site, click <b>Connect Supabase</b> on the green bar, paste one into each box, and press <b>Connect this site</b>.</div>
|
| 217 |
+
<div class="warn"><b>Never</b> paste the <b>service_role</b> key into the site. If it ever leaks, rotate it in the same screen.</div>
|
| 218 |
+
<div class="tip">Want every visitor to skip this step? Open <code class="inline">js/config.js</code> in the Explication Web folder and paste the same two values there.</div>
|
| 219 |
+
</div>
|
| 220 |
+
</section>
|
| 221 |
+
|
| 222 |
+
<section class="step">
|
| 223 |
+
<div class="step-head">
|
| 224 |
+
<div class="num">5</div>
|
| 225 |
+
<div>
|
| 226 |
+
<h2>Make yourself the developer</h2>
|
| 227 |
+
<p class="why">One address gets the console: <b>lucas.owen13@icloud.com</b>. Nobody else, ever.</p>
|
| 228 |
+
</div>
|
| 229 |
+
</div>
|
| 230 |
+
<div class="body">
|
| 231 |
+
<div class="window">
|
| 232 |
+
<div class="chrome"><i></i><i></i><i></i><span class="url">your site → Account</span></div>
|
| 233 |
+
<div class="pane">
|
| 234 |
+
<div class="canvas">
|
| 235 |
+
<h4>Create account</h4>
|
| 236 |
+
<div class="field"><span><span class="lab">Email</span><code>lucas.owen13@icloud.com</code></span></div>
|
| 237 |
+
<div class="field"><span><span class="lab">Password</span><code>••••••••</code></span></div>
|
| 238 |
+
<div class="row"><button class="btn green">Create account</button><span class="pin">4</span></div>
|
| 239 |
+
</div>
|
| 240 |
+
</div>
|
| 241 |
+
</div>
|
| 242 |
+
<div class="do"><b>Do this:</b> on the site click <b>Account → Create account</b> <span class="pin">4</span> and use exactly <b>lucas.owen13@icloud.com</b>. Sign in. A <b>Developer</b> item appears in the sidebar — that is your console.</div>
|
| 243 |
+
<div class="warn">Using any other address gives a normal account with no console. That is the point: the database itself refuses edits from everyone else.</div>
|
| 244 |
+
</div>
|
| 245 |
+
</section>
|
| 246 |
+
|
| 247 |
+
<section class="step">
|
| 248 |
+
<div class="step-head">
|
| 249 |
+
<div class="num">6</div>
|
| 250 |
+
<div>
|
| 251 |
+
<h2>Give a model its API key</h2>
|
| 252 |
+
<p class="why">Offline models and students' own keys work without this. This is only if you want to host the big models yourself.</p>
|
| 253 |
+
</div>
|
| 254 |
+
</div>
|
| 255 |
+
<div class="body">
|
| 256 |
+
<div class="window">
|
| 257 |
+
<div class="chrome"><i></i><i></i><i></i><span class="url">your site → Developer → Models & keys</span></div>
|
| 258 |
+
<div class="pane">
|
| 259 |
+
<div class="canvas">
|
| 260 |
+
<h4>Qwen2.5 7B</h4>
|
| 261 |
+
<div class="field"><span><span class="lab">Endpoint base URL</span><code>https://openrouter.ai/api/v1</code></span></div>
|
| 262 |
+
<div class="field"><span><span class="lab">Model name at the host</span><code>qwen/qwen-2.5-7b-instruct</code></span></div>
|
| 263 |
+
<div class="field"><span><span class="lab">API key</span><code>sk-or-v1-…</code></span><span class="pin">5</span></div>
|
| 264 |
+
<div class="row"><button class="btn green">Save model</button></div>
|
| 265 |
+
</div>
|
| 266 |
+
</div>
|
| 267 |
+
</div>
|
| 268 |
+
<div class="do"><b>Do this:</b> in your model provider's dashboard create an API key. On the site open <b>Developer → Models & keys</b>, edit a model, paste the endpoint and the key <span class="pin">5</span>, and press <b>Save model</b>. Repeat per model.</div>
|
| 269 |
+
<div class="tip">The key is write-only: it goes into a table no browser can read, and only the site's server function uses it.</div>
|
| 270 |
+
</div>
|
| 271 |
+
</section>
|
| 272 |
+
|
| 273 |
+
<section class="step">
|
| 274 |
+
<div class="step-head">
|
| 275 |
+
<div class="num">7</div>
|
| 276 |
+
<div>
|
| 277 |
+
<h2>Make a Stripe payment link for one plan</h2>
|
| 278 |
+
<p class="why">This is the simple route: no keys, no webhooks. Stripe hosts the checkout page, the site just sends people there.</p>
|
| 279 |
+
</div>
|
| 280 |
+
</div>
|
| 281 |
+
<div class="body">
|
| 282 |
+
<div class="window">
|
| 283 |
+
<div class="chrome"><i></i><i></i><i></i><span class="url">dashboard.stripe.com → Products</span></div>
|
| 284 |
+
<div class="pane">
|
| 285 |
+
<div class="rail">
|
| 286 |
+
<div class="item on"><span class="ic">▦</span> Products</div>
|
| 287 |
+
<div class="item"><span class="ic">↗</span> Payment links</div>
|
| 288 |
+
<div class="item"><span class="ic">◍</span> Test mode</div>
|
| 289 |
+
</div>
|
| 290 |
+
<div class="canvas">
|
| 291 |
+
<h4>Add a product</h4>
|
| 292 |
+
<p>Name it like the plan. One price, then create the link.</p>
|
| 293 |
+
<div class="field"><span><span class="lab">Name</span><code>Student</code></span></div>
|
| 294 |
+
<div class="field"><span><span class="lab">Price</span><code>£4.00 · monthly · recurring</code></span><span class="pin">6</span></div>
|
| 295 |
+
<div class="row"><button class="btn green">Create payment link</button><span class="pin">7</span></div>
|
| 296 |
+
</div>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
<div class="do">
|
| 300 |
+
<b>Do this:</b> in Stripe flip <b>Test mode</b> on (top right). Go to <b>Products → Add product</b>, name it <b>Student</b>, add a price of <b>£4.00</b>, <b>monthly</b>, recurring <span class="pin">6</span>. Save, then press <b>Create payment link</b> <span class="pin">7</span> and copy the link.
|
| 301 |
+
On the site open <b>Developer → Plans → Edit</b> on Student, paste it into <b>Stripe payment link</b>, and save. Repeat for the other six — the table below has every name, price and type.
|
| 302 |
+
</div>
|
| 303 |
+
<table class="where">
|
| 304 |
+
<tr><th>Product name</th><th>Price in Stripe</th><th>Type</th></tr>
|
| 305 |
+
<tr><td>Paragraph Lite</td><td>£4.00</td><td>One-off</td></tr>
|
| 306 |
+
<tr><td>Model Library</td><td>£14.00</td><td>One-off</td></tr>
|
| 307 |
+
<tr><td>Exam Season</td><td>£24.00</td><td>One-off</td></tr>
|
| 308 |
+
<tr><td>AI Booster</td><td>£6.00</td><td>One-off</td></tr>
|
| 309 |
+
<tr><td>Student</td><td>£4.00</td><td>Monthly, recurring</td></tr>
|
| 310 |
+
<tr><td>Scholar</td><td>£9.00</td><td>Monthly, recurring</td></tr>
|
| 311 |
+
<tr><td>Examiner</td><td>£19.00</td><td>Monthly, recurring</td></tr>
|
| 312 |
+
</table>
|
| 313 |
+
<div class="tip">Test mode and live mode have different links. Keep test links while you practise, then swap them for live ones before launch.</div>
|
| 314 |
+
</div>
|
| 315 |
+
</section>
|
| 316 |
+
|
| 317 |
+
<section class="step">
|
| 318 |
+
<div class="step-head">
|
| 319 |
+
<div class="num">8</div>
|
| 320 |
+
<div>
|
| 321 |
+
<h2>Try it, then give yourself the plan</h2>
|
| 322 |
+
<p class="why">With payment links, Stripe takes the money but the site does not hear about it automatically. You approve the buyer by hand — one click.</p>
|
| 323 |
+
</div>
|
| 324 |
+
</div>
|
| 325 |
+
<div class="body">
|
| 326 |
+
<div class="window">
|
| 327 |
+
<div class="chrome"><i></i><i></i><i></i><span class="url">your site → Developer → People</span></div>
|
| 328 |
+
<div class="pane">
|
| 329 |
+
<div class="canvas">
|
| 330 |
+
<h4>Give someone a plan</h4>
|
| 331 |
+
<div class="field"><span><span class="lab">Buyer's email</span><code>lucas.owen13@icloud.com</code></span></div>
|
| 332 |
+
<div class="field"><span><span class="lab">Plan</span><code>Student · £4.00</code></span></div>
|
| 333 |
+
<div class="row"><button class="btn green">Grant access</button><span class="pin">8</span></div>
|
| 334 |
+
</div>
|
| 335 |
+
</div>
|
| 336 |
+
</div>
|
| 337 |
+
<div class="do"><b>Do this:</b> buy your own plan with test card <code class="inline">4242 4242 4242 4242</code>, any future date, any CVC. Then on the site open <b>Developer → People</b>, type the buyer's email, pick the plan and press <b>Grant access</b> <span class="pin">8</span>. The plan shows on their Account page immediately.</div>
|
| 338 |
+
<div class="warn">Want purchases to unlock themselves? That is the optional checkout-function route in <code class="inline">supabase/SETUP.md</code>, step 3. It needs five terminal commands. Everything works without it — you just approve each sale.</div>
|
| 339 |
+
</div>
|
| 340 |
+
</section>
|
| 341 |
+
|
| 342 |
+
<section class="step">
|
| 343 |
+
<div class="step-head">
|
| 344 |
+
<div class="num">9</div>
|
| 345 |
+
<div>
|
| 346 |
+
<h2>Publish it</h2>
|
| 347 |
+
<p class="why">Any static host works. Supabase stays the backend, so there is nothing to run.</p>
|
| 348 |
+
</div>
|
| 349 |
+
</div>
|
| 350 |
+
<div class="body">
|
| 351 |
+
<div class="do">
|
| 352 |
+
<b>Before you upload:</b> open <code class="inline">js/config.js</code> in a text editor and paste your Project URL and anon key into the two empty quotes (the same two values from step 4). That is what makes the plans, wording and prices identical for every visitor — without it, each visitor is asked to connect their own project.
|
| 353 |
+
<b>Then:</b> upload the <b>dist</b> folder — it is the upload copy of the site, with the Supabase function files left out so hosts do not think a build is needed. On Cloudflare go to <b>Workers & Pages → Create → Upload and deploy</b>; on Netlify drag it onto <a href="https://app.netlify.com/drop" target="_blank" rel="noreferrer">app.netlify.com/drop</a>. You get an address like <code class="inline">explication.netlify.app</code> or <code class="inline">explication.you.workers.dev</code>.
|
| 354 |
+
Go back to Supabase → <b>Authentication → URL Configuration</b> and add that address to <b>Redirect URLs</b>.
|
| 355 |
+
Finally set the same address in the Mac app (see <code class="inline">supabase/SETUP.md</code>). The iPhone app sells through the App Store instead — the next screen covers it.
|
| 356 |
+
</div>
|
| 357 |
+
<div class="warn">Local files (<code class="inline">file://</code>) cannot sign in. Always open the site through <code class="inline">Start Explication.command</code> or the published address.</div>
|
| 358 |
+
</div>
|
| 359 |
+
</section>
|
| 360 |
+
|
| 361 |
+
<section class="step">
|
| 362 |
+
<div class="step-head">
|
| 363 |
+
<div class="num">◎</div>
|
| 364 |
+
<div>
|
| 365 |
+
<h2>The iPhone app: Supabase and the App Store</h2>
|
| 366 |
+
<p class="why">The app reads the same plan table from Supabase, and sells through Apple's in-app purchase instead of sending anyone to the website.</p>
|
| 367 |
+
</div>
|
| 368 |
+
</div>
|
| 369 |
+
<div class="body">
|
| 370 |
+
<div class="do">
|
| 371 |
+
<b>Supabase is already connected.</b> The app ships with your Project URL and anon key in <code class="inline">Explication/Core/Cloud/SupabaseCatalog.swift</code> — the same two values from step 4. Its Plans screen reads <code class="inline">explication_plans</code> (only <code class="inline">active</code> rows, ordered by <code class="inline">sort</code>), so names, prices and copy match the site automatically. It never writes, and the anon key is safe to ship: the row-level security policies in <code class="inline">schema.sql</code> allow reads only.
|
| 372 |
+
</div>
|
| 373 |
+
<div class="do">
|
| 374 |
+
<b>Purchases use StoreKit, not the website.</b> Create one product per plan in <b>App Store Connect → My Apps → Explication → Monetization</b>. The identifiers must match exactly, including the capital letters.
|
| 375 |
+
</div>
|
| 376 |
+
<table class="where">
|
| 377 |
+
<tr><th>Plan</th><th>Product ID</th><th>Type</th><th>Price</th></tr>
|
| 378 |
+
<tr><td>Paragraph Lite</td><td><code class="inline">app.explication.coach.paragraphLite</code></td><td>Non-consumable</td><td>£4.00</td></tr>
|
| 379 |
+
<tr><td>Model Library</td><td><code class="inline">app.explication.coach.modelLibrary</code></td><td>Non-consumable</td><td>£14.00</td></tr>
|
| 380 |
+
<tr><td>Exam Season</td><td><code class="inline">app.explication.coach.examSeason</code></td><td>Non-consumable</td><td>£24.00</td></tr>
|
| 381 |
+
<tr><td>AI Booster</td><td><code class="inline">app.explication.coach.aiBooster</code></td><td>Consumable</td><td>£6.00</td></tr>
|
| 382 |
+
<tr><td>Student</td><td><code class="inline">app.explication.coach.student</code></td><td>Auto-renewable subscription</td><td>£4.00 / month</td></tr>
|
| 383 |
+
<tr><td>Scholar</td><td><code class="inline">app.explication.coach.scholar</code></td><td>Auto-renewable subscription</td><td>£9.00 / month</td></tr>
|
| 384 |
+
<tr><td>Examiner</td><td><code class="inline">app.explication.coach.examiner</code></td><td>Auto-renewable subscription</td><td>£19.00 / month</td></tr>
|
| 385 |
+
</table>
|
| 386 |
+
<div class="do">
|
| 387 |
+
<b>Do this:</b> for the three memberships, make one subscription group called <b>Explication</b> and add the three durations inside it. Give every product a display name, a description in at least one language and a review screenshot — Apple will not put a product on sale without them. Sign <b>Agreements, Tax, and Banking → Paid Apps</b> first, or every product stays unavailable.
|
| 388 |
+
</div>
|
| 389 |
+
<div class="do">
|
| 390 |
+
<b>Then just build it.</b> Double-click <code class="inline">Install on iPhone.command</code> in the project folder with the iPhone plugged in, unlocked and trusted. It builds, signs with your existing development profile and installs. In Xcode you can also open <code class="inline">Explication.xcodeproj</code>, pick the iPhone and press Run.
|
| 391 |
+
</div>
|
| 392 |
+
<div class="warn">Until the products exist in App Store Connect, the Plans screen says the App Store has none for this build — that is expected, not a bug. StoreKit shows Apple's local price once they are live. Website Stripe purchases and App Store purchases are separate: a plan bought on the website does not unlock in the app, and the other way round.</div>
|
| 393 |
+
</div>
|
| 394 |
+
</section>
|
| 395 |
+
|
| 396 |
+
<section class="step">
|
| 397 |
+
<div class="step-head">
|
| 398 |
+
<div class="num">✉</div>
|
| 399 |
+
<div>
|
| 400 |
+
<h2>Make email actually arrive</h2>
|
| 401 |
+
<p class="why">Supabase's built-in sender only delivers to your own team and allows a couple of messages an hour. Real students need a real sender. Three jobs, three services: Resend sends, Cloudflare receives, Apple Mail reads it.</p>
|
| 402 |
+
</div>
|
| 403 |
+
</div>
|
| 404 |
+
<div class="body">
|
| 405 |
+
<div class="do">
|
| 406 |
+
<b>A · Sending: Resend.</b> You need a domain you own — buy one at Cloudflare → <b>Domain Registration</b> (about £8–10 a year) if you do not have one. Then sign up at <a href="https://resend.com" target="_blank" rel="noreferrer">resend.com</a>; the free plan is 3,000 emails a month, 100 a day.<br><br>
|
| 407 |
+
<b>1.</b> Resend → <b>Domains → Add domain</b> → type the domain → pick a region → <b>Add</b>.<br>
|
| 408 |
+
<b>2.</b> It lists three or four DNS records. In Cloudflare open the domain → <b>DNS → Records</b> and add each one exactly as shown. Leave the proxy switch <b>off</b> (grey cloud, “DNS only”) — a proxied MX or TXT record will not verify. Then press <b>Verify</b> in Resend; usually a few minutes.<br>
|
| 409 |
+
<b>3.</b> Resend → <b>API Keys → Create API key</b>, permission <b>Sending access</b>, and copy the <code class="inline">re_…</code> value. It is shown once.
|
| 410 |
+
</div>
|
| 411 |
+
<div class="window">
|
| 412 |
+
<div class="chrome"><i></i><i></i><i></i><span class="url">supabase.com → Authentication → Emails → SMTP Settings</span></div>
|
| 413 |
+
<div class="pane">
|
| 414 |
+
<div class="canvas">
|
| 415 |
+
<h4>Enable custom SMTP</h4>
|
| 416 |
+
<p>Six values. Only the sender is yours.</p>
|
| 417 |
+
<div class="field"><span><span class="lab">Sender email</span><code>no-reply@yourdomain.com</code></span></div>
|
| 418 |
+
<div class="field"><span><span class="lab">Sender name</span><code>Explication</code></span></div>
|
| 419 |
+
<div class="field"><span><span class="lab">Host</span><code>smtp.resend.com</code></span></div>
|
| 420 |
+
<div class="field"><span><span class="lab">Port</span><code>465</code></span></div>
|
| 421 |
+
<div class="field"><span><span class="lab">Username</span><code>resend</code></span></div>
|
| 422 |
+
<div class="field"><span><span class="lab">Password</span><code>re_… (your API key)</code></span></div>
|
| 423 |
+
<div class="row"><button class="btn green">Save</button></div>
|
| 424 |
+
</div>
|
| 425 |
+
</div>
|
| 426 |
+
</div>
|
| 427 |
+
<div class="do" style="margin-top:12px">
|
| 428 |
+
<b>4.</b> In Supabase open <b>Authentication → Emails → SMTP Settings</b>, turn on <b>Enable custom SMTP</b> and paste the six values above. The username really is the word <code class="inline">resend</code>, and the password is the API key, not your Resend login.<br>
|
| 429 |
+
<b>5.</b> Trigger a password reset from the site. It should arrive from <code class="inline">no-reply@yourdomain.com</code> within seconds, and Resend → <b>Emails</b> shows whether it was delivered. Supabase starts you at 30 messages an hour — raise it in <b>Authentication → Rate Limits</b> once it works. The branded templates from step 3 are what gets sent; nothing else to change.
|
| 430 |
+
</div>
|
| 431 |
+
<div class="tip">If Resend offers a DMARC record as well, add it: it is one TXT record at <code class="inline">_dmarc</code> and it keeps your mail out of spam folders.</div>
|
| 432 |
+
<div class="do">
|
| 433 |
+
<b>B · Receiving: Cloudflare Email Routing.</b> Free, and receiving only — Cloudflare has no inbox and no SMTP server, so it can never be the thing that sends.<br><br>
|
| 434 |
+
<b>1.</b> The domain has to be on Cloudflare, using Cloudflare's nameservers.<br>
|
| 435 |
+
<b>2.</b> Dashboard → <b>Email → Email Routing → Onboard domain → Add records and enable</b>. That adds the MX, SPF and DKIM records for you.<br>
|
| 436 |
+
<b>3.</b> <b>Destination addresses</b> → add your iCloud address → open the verification email → verify.<br>
|
| 437 |
+
<b>4.</b> <b>Routing rules → Custom addresses → Create address</b>: <code class="inline">hello</code> (or <code class="inline">support</code>) → action <b>Send to</b> → your iCloud address → <b>Save</b>.<br>
|
| 438 |
+
<b>5.</b> Email it from another account. It should land in iCloud within seconds, and the original address stays hidden.
|
| 439 |
+
</div>
|
| 440 |
+
<div class="warn">Never switch Email Routing on for a domain that already receives mail somewhere else — Google, Microsoft, or iCloud+. It replaces the MX records, so that other inbox stops getting mail. One receiver per domain.</div>
|
| 441 |
+
<div class="do">
|
| 442 |
+
<b>C · Reading it: Apple Mail.</b> On the iPhone: <b>Settings → Apps → Mail → Accounts → Add Account → iCloud</b>. On the Mac: <b>Mail → Settings → Accounts → +</b> → iCloud.<br><br>
|
| 443 |
+
Mail sent to <code class="inline">hello@yourdomain.com</code> is forwarded into that iCloud inbox, so it arrives like any other message. Replies go out from your iCloud address unless you do D.
|
| 444 |
+
</div>
|
| 445 |
+
<div class="do">
|
| 446 |
+
<b>D · Replying as hello@yourdomain.com (optional).</b> Two honest routes.<br><br>
|
| 447 |
+
<b>iCloud+ custom domain</b> — paid with iCloud+ (about 79p a month): <b>Settings → Apple Account → iCloud → Custom Email Domain</b> → use a domain you own. Apple then hosts the mailbox, Apple Mail sends and receives natively as <code class="inline">hello@yourdomain.com</code>, and Cloudflare is only DNS. It takes over the MX records, so switch Cloudflare Email Routing off for that domain first — and then part B is not needed at all.<br><br>
|
| 448 |
+
<b>Send-as through Resend</b> — free, fine for the occasional reply: <b>Mail → Settings → Accounts → your iCloud account → Account Information → Edit Email Addresses</b> → add <code class="inline">hello@yourdomain.com</code>. Then <b>Server Settings → Outgoing Mail Server → Edit SMTP Server List</b> → add <code class="inline">smtp.resend.com</code>, port <code class="inline">465</code>, user <code class="inline">resend</code>, your API key, TLS on. It sends, but Resend is not a mailbox: there is no Sent folder on a server and the message is logged as app mail. Good enough to answer a student; not a replacement for a real inbox.
|
| 449 |
+
</div>
|
| 450 |
+
<table class="where">
|
| 451 |
+
<tr><th>Job</th><th>Who does it</th><th>Cost</th></tr>
|
| 452 |
+
<tr><td>Send sign-in and password emails</td><td>Resend → Supabase custom SMTP</td><td>Free to 3,000 a month</td></tr>
|
| 453 |
+
<tr><td>Receive mail at your domain</td><td>Cloudflare Email Routing → forwards to iCloud</td><td>Free</td></tr>
|
| 454 |
+
<tr><td>Read it and reply</td><td>Apple Mail, on the iCloud account</td><td>Free</td></tr>
|
| 455 |
+
<tr><td>Reply <i>as</i> your domain, natively</td><td>iCloud+ custom domain (replaces Email Routing)</td><td>iCloud+ subscription</td></tr>
|
| 456 |
+
</table>
|
| 457 |
+
<div class="warn">Resend cannot receive email. Never point MX records at Resend, and never put the <code class="inline">re_…</code> key in the website — it belongs only in Supabase's SMTP settings.</div>
|
| 458 |
+
</div>
|
| 459 |
+
</section>
|
| 460 |
+
|
| 461 |
+
<section class="step">
|
| 462 |
+
<div class="step-head">
|
| 463 |
+
<div class="num">☰</div>
|
| 464 |
+
<div>
|
| 465 |
+
<h2>Where everything lives</h2>
|
| 466 |
+
<p class="why">One table to come back to when you forget.</p>
|
| 467 |
+
</div>
|
| 468 |
+
</div>
|
| 469 |
+
<div class="body">
|
| 470 |
+
<table class="where">
|
| 471 |
+
<tr><th>What you want to change</th><th>Where to click</th></tr>
|
| 472 |
+
<tr><td>Prices, plan names, wording of a plan</td><td>Site → <b>Developer → Plans → Edit</b></td></tr>
|
| 473 |
+
<tr><td>Any sentence on any page</td><td>Site → <b>Developer → Wording → edit mode</b>, then click the words</td></tr>
|
| 474 |
+
<tr><td>Model keys and endpoints</td><td>Site → <b>Developer → Models & keys</b></td></tr>
|
| 475 |
+
<tr><td>Payment links</td><td>Site → <b>Developer → Plans</b> → Stripe payment link field</td></tr>
|
| 476 |
+
<tr><td>Who has a plan</td><td>Site → <b>Developer → People</b></td></tr>
|
| 477 |
+
<tr><td>Stripe keys (advanced)</td><td>Supabase → <b>Edge Functions → Secrets</b></td></tr>
|
| 478 |
+
<tr><td>The project address and key</td><td>Supabase → <b>Project Settings → API</b>; site → <b>Developer → Supabase</b></td></tr>
|
| 479 |
+
<tr><td>Emails students receive</td><td>Supabase → <b>Authentication → Emails</b></td></tr>
|
| 480 |
+
<tr><td>Which address students see as the sender</td><td>Supabase → <b>Authentication → Emails → SMTP Settings</b></td></tr>
|
| 481 |
+
<tr><td>Mail sent to hello@yourdomain</td><td>Cloudflare → <b>Email → Email Routing</b></td></tr>
|
| 482 |
+
</table>
|
| 483 |
+
</div>
|
| 484 |
+
</section>
|
| 485 |
+
|
| 486 |
+
<section class="step">
|
| 487 |
+
<div class="step-head">
|
| 488 |
+
<div class="num">?</div>
|
| 489 |
+
<div>
|
| 490 |
+
<h2>If something looks wrong</h2>
|
| 491 |
+
<p class="why">The four things that actually go wrong.</p>
|
| 492 |
+
</div>
|
| 493 |
+
</div>
|
| 494 |
+
<div class="body">
|
| 495 |
+
<table class="where">
|
| 496 |
+
<tr><th>Symptom</th><th>Fix</th></tr>
|
| 497 |
+
<tr><td>No developer console in the sidebar</td><td>You are signed in as a different email. Sign out, sign in as lucas.owen13@icloud.com.</td></tr>
|
| 498 |
+
<tr><td>"Supabase could not be reached"</td><td>Project URL or anon key pasted wrong. Developer → Supabase → paste again from Project Settings → API.</td></tr>
|
| 499 |
+
<tr><td>Plans page is empty</td><td>Step 2 did not run. Supabase → SQL Editor → paste the file → Run.</td></tr>
|
| 500 |
+
<tr><td>"This plan has no Stripe payment link yet"</td><td>Add the link to that plan in Developer → Plans, or you are in live mode with a test link.</td></tr>
|
| 501 |
+
<tr><td>Sign-up says "check your email" but nothing arrives</td><td>Confirmation is on and Supabase's built-in sender only reaches your own team. Connect Resend (last section), or turn Confirm email off in Authentication → Providers → Email.</td></tr>
|
| 502 |
+
</table>
|
| 503 |
+
</div>
|
| 504 |
+
</section>
|
| 505 |
+
|
| 506 |
+
<footer>
|
| 507 |
+
Explication · the full technical version, including webhooks and edge functions, is in <code class="inline">supabase/SETUP.md</code>.
|
| 508 |
+
</footer>
|
| 509 |
+
</div>
|
| 510 |
+
|
| 511 |
+
<script>
|
| 512 |
+
const sqlButton = document.querySelector("[data-copy-sql]");
|
| 513 |
+
const sqlNote = document.getElementById("copy-sql-note");
|
| 514 |
+
if (sqlButton) {
|
| 515 |
+
sqlButton.addEventListener("click", async () => {
|
| 516 |
+
try {
|
| 517 |
+
let text = "";
|
| 518 |
+
for (const path of ["schema.sql", "supabase/schema.sql"]) {
|
| 519 |
+
const res = await fetch(path);
|
| 520 |
+
if (res.ok) {
|
| 521 |
+
text = await res.text();
|
| 522 |
+
break;
|
| 523 |
+
}
|
| 524 |
+
}
|
| 525 |
+
if (!text) throw new Error("schema not found");
|
| 526 |
+
await navigator.clipboard.writeText(text);
|
| 527 |
+
sqlButton.textContent = "Copied — now paste it into Supabase";
|
| 528 |
+
sqlNote.textContent = "Includes the tables and all seven plans.";
|
| 529 |
+
setTimeout(() => { sqlButton.textContent = "Copy the database file"; }, 4000);
|
| 530 |
+
} catch (error) {
|
| 531 |
+
sqlNote.textContent = "Could not copy. Open supabase/schema.sql and copy it by hand.";
|
| 532 |
+
}
|
| 533 |
+
});
|
| 534 |
+
}
|
| 535 |
+
|
| 536 |
+
document.querySelectorAll(".copy[data-copy]").forEach((button) => {
|
| 537 |
+
button.addEventListener("click", () => {
|
| 538 |
+
const field = button.closest(".field");
|
| 539 |
+
const value = field ? field.querySelector("code").textContent : "";
|
| 540 |
+
navigator.clipboard.writeText(value).catch(() => {});
|
| 541 |
+
button.textContent = "Copied";
|
| 542 |
+
setTimeout(() => { button.textContent = "Copy"; }, 2000);
|
| 543 |
+
});
|
| 544 |
+
});
|
| 545 |
+
</script>
|
| 546 |
+
</body>
|
| 547 |
+
</html>
|
favicon.svg
ADDED
|
|
index.html
CHANGED
|
@@ -1,19 +1,42 @@
|
|
| 1 |
<!doctype html>
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
<!doctype html>
|
| 2 |
+
<html lang="en-GB">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
| 6 |
+
<meta name="theme-color" content="#ffffff" />
|
| 7 |
+
<title>Explication — GCSE English Literature</title>
|
| 8 |
+
<meta name="description" content="A private GCSE English Literature writing coach: mark a paragraph, build an essay, review a poem. Works in your browser." />
|
| 9 |
+
<meta name="keywords" content="GCSE English Literature, English Literature revision, GCSE revision, poetry analysis, essay writing, exam practice, study guide, secondary education, English, AQA, Edexcel, Eduqas, OCR" />
|
| 10 |
+
<meta name="author" content="Explication" />
|
| 11 |
+
<meta property="og:type" content="website" />
|
| 12 |
+
<meta property="og:site_name" content="Explication" />
|
| 13 |
+
<meta property="og:title" content="Explication — GCSE English Literature" />
|
| 14 |
+
<meta property="og:description" content="Mark a paragraph, build an essay, review a poem. A GCSE English Literature study coach that works in your browser." />
|
| 15 |
+
<meta name="twitter:card" content="summary" />
|
| 16 |
+
<meta name="twitter:title" content="Explication — GCSE English Literature" />
|
| 17 |
+
<meta name="twitter:description" content="Mark a paragraph, build an essay, review a poem. A GCSE English Literature study coach that works in your browser." />
|
| 18 |
+
<script type="application/ld+json">
|
| 19 |
+
{
|
| 20 |
+
"@context": "https://schema.org",
|
| 21 |
+
"@type": "SoftwareApplication",
|
| 22 |
+
"name": "Explication",
|
| 23 |
+
"applicationCategory": "EducationalApplication",
|
| 24 |
+
"operatingSystem": "Web",
|
| 25 |
+
"inLanguage": "en-GB",
|
| 26 |
+
"description": "A GCSE English Literature writing coach for marking paragraphs, building essays and reviewing poetry.",
|
| 27 |
+
"audience": { "@type": "EducationalAudience", "educationalRole": "student" },
|
| 28 |
+
"about": ["GCSE English Literature", "Essay writing", "Poetry analysis", "Revision", "Secondary education"]
|
| 29 |
+
}
|
| 30 |
+
</script>
|
| 31 |
+
<link rel="icon" href="favicon.svg" type="image/svg+xml" />
|
| 32 |
+
<link rel="stylesheet" href="styles.css" />
|
| 33 |
+
</head>
|
| 34 |
+
<body>
|
| 35 |
+
<div id="root"></div>
|
| 36 |
+
<script src="vendor/react.js"></script>
|
| 37 |
+
<script src="vendor/react-dom.js"></script>
|
| 38 |
+
<script src="vendor/htm.js"></script>
|
| 39 |
+
<script src="js/config.js"></script>
|
| 40 |
+
<script type="module" src="js/app.js"></script>
|
| 41 |
+
</body>
|
| 42 |
</html>
|
js/admin.js
ADDED
|
@@ -0,0 +1,650 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { html, useEffect, useState } from "./runtime.js";
|
| 2 |
+
import { useCloud, money, DEVELOPER_EMAIL, DEFAULT_MODELS } from "./cloud.js";
|
| 3 |
+
import { useEditMode } from "./copy.js";
|
| 4 |
+
import { Icon, Notice, Pill } from "./components.js";
|
| 5 |
+
|
| 6 |
+
// ---------------------------------------------------------------------------
|
| 7 |
+
// Small form pieces
|
| 8 |
+
// ---------------------------------------------------------------------------
|
| 9 |
+
|
| 10 |
+
function Head({ kicker, title, subtitle, right }) {
|
| 11 |
+
return html`<div class="row between" style=${{ alignItems: "flex-start", gap: "16px" }}>
|
| 12 |
+
<div>
|
| 13 |
+
<div class="eyebrow">${kicker}</div>
|
| 14 |
+
<h1 class="page-title">${title}</h1>
|
| 15 |
+
${subtitle && html`<p class="subtitle">${subtitle}</p>`}
|
| 16 |
+
</div>
|
| 17 |
+
${right}
|
| 18 |
+
</div>`;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
function Field({ label, hint, children }) {
|
| 22 |
+
return html`<div class="field">
|
| 23 |
+
<label>${label}${hint && html` <span class="hint">${hint}</span>`}</label>
|
| 24 |
+
${children}
|
| 25 |
+
</div>`;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
function Text({ label, hint, value, onChange, placeholder, type = "text", mono = false }) {
|
| 29 |
+
return html`<${Field} label=${label} hint=${hint}>
|
| 30 |
+
<input class=${"input" + (mono ? " mono" : "")} type=${type} value=${value == null ? "" : value}
|
| 31 |
+
onInput=${(e) => onChange(e.target.value)} placeholder=${placeholder || ""} spellCheck=${false} />
|
| 32 |
+
<//>`;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
function Area({ label, hint, value, onChange, placeholder, rows = 3 }) {
|
| 36 |
+
return html`<${Field} label=${label} hint=${hint}>
|
| 37 |
+
<textarea class="textarea plain" style=${{ minHeight: rows * 26 + "px" }} value=${value == null ? "" : value}
|
| 38 |
+
onInput=${(e) => onChange(e.target.value)} placeholder=${placeholder || ""} spellCheck=${false}></textarea>
|
| 39 |
+
<//>`;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
function Select({ label, hint, value, onChange, options }) {
|
| 43 |
+
return html`<${Field} label=${label} hint=${hint}>
|
| 44 |
+
<select class="select" value=${value} onChange=${(e) => onChange(e.target.value)}>
|
| 45 |
+
${options.map((o) => html`<option key=${o.value} value=${o.value}>${o.label}</option>`)}
|
| 46 |
+
</select>
|
| 47 |
+
<//>`;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
function Check({ label, hint, checked, onChange }) {
|
| 51 |
+
return html`<label class="check-row">
|
| 52 |
+
<input type="checkbox" checked=${!!checked} onChange=${(e) => onChange(e.target.checked)} />
|
| 53 |
+
<span><strong>${label}</strong>${hint && html`<span class="tiny faint" style=${{ display: "block" }}>${hint}</span>`}</span>
|
| 54 |
+
</label>`;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
function Stat({ label, value, note }) {
|
| 58 |
+
return html`<div class="stat"><div class="head">${label}</div><div class="value">${value}</div><div class="note">${note}</div></div>`;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
// ---------------------------------------------------------------------------
|
| 62 |
+
// Plans
|
| 63 |
+
// ---------------------------------------------------------------------------
|
| 64 |
+
|
| 65 |
+
const BLANK_PLAN = {
|
| 66 |
+
id: "",
|
| 67 |
+
name: "",
|
| 68 |
+
kind: "subscription",
|
| 69 |
+
price_cents: 0,
|
| 70 |
+
currency: "GBP",
|
| 71 |
+
interval: "month",
|
| 72 |
+
blurb: "",
|
| 73 |
+
features: [],
|
| 74 |
+
cost_limit_cents: 0,
|
| 75 |
+
download_tier: 0,
|
| 76 |
+
byok: true,
|
| 77 |
+
stripe_price_id: "",
|
| 78 |
+
stripe_payment_link: "",
|
| 79 |
+
active: true,
|
| 80 |
+
sort: 0
|
| 81 |
+
};
|
| 82 |
+
|
| 83 |
+
function PlanEditor({ plan, onDone }) {
|
| 84 |
+
const cloud = useCloud();
|
| 85 |
+
const [draft, setDraft] = useState(plan || BLANK_PLAN);
|
| 86 |
+
const [price, setPrice] = useState(((plan || BLANK_PLAN).price_cents / 100).toFixed(2));
|
| 87 |
+
const [limit, setLimit] = useState(((plan || BLANK_PLAN).cost_limit_cents / 100).toFixed(2));
|
| 88 |
+
const [features, setFeatures] = useState((plan && plan.features ? plan.features : []).join("\n"));
|
| 89 |
+
const [error, setError] = useState("");
|
| 90 |
+
const [busy, setBusy] = useState(false);
|
| 91 |
+
const set = (patch) => setDraft((d) => ({ ...d, ...patch }));
|
| 92 |
+
|
| 93 |
+
const save = async () => {
|
| 94 |
+
setError("");
|
| 95 |
+
const id = (draft.id || draft.name || "").trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
| 96 |
+
if (!draft.name.trim()) return setError("Give the plan a name.");
|
| 97 |
+
if (!id) return setError("Give the plan an identifier, for example scholar.");
|
| 98 |
+
setBusy(true);
|
| 99 |
+
try {
|
| 100 |
+
await cloud.upsertPlan({
|
| 101 |
+
...draft,
|
| 102 |
+
id,
|
| 103 |
+
price_cents: Math.round((Number(price) || 0) * 100),
|
| 104 |
+
cost_limit_cents: Math.round((Number(limit) || 0) * 100),
|
| 105 |
+
interval: draft.kind === "subscription" ? draft.interval || "month" : null,
|
| 106 |
+
features: features.split("\n").map((f) => f.trim()).filter(Boolean),
|
| 107 |
+
sort: Number(draft.sort) || 0
|
| 108 |
+
});
|
| 109 |
+
cloud.flash("Plan saved.");
|
| 110 |
+
onDone();
|
| 111 |
+
} catch (err) {
|
| 112 |
+
setError(err && err.message ? err.message : "Could not save the plan.");
|
| 113 |
+
}
|
| 114 |
+
setBusy(false);
|
| 115 |
+
};
|
| 116 |
+
|
| 117 |
+
// A plan's identity is its id; keep it stable once it exists.
|
| 118 |
+
const lockedId = !!(plan && plan.id);
|
| 119 |
+
|
| 120 |
+
return html`<div class="card fade-in" style=${{ marginTop: "10px" }}>
|
| 121 |
+
<div class="row between"><strong>${lockedId ? "Edit " + plan.name : "New plan"}</strong>
|
| 122 |
+
<button class="btn small ghost" onClick=${onDone}>Close</button>
|
| 123 |
+
</div>
|
| 124 |
+
<div class="grid two" style=${{ marginTop: "10px" }}>
|
| 125 |
+
<${Text} label="Name" value=${draft.name} onChange=${(v) => set({ name: v, id: lockedId ? draft.id : draft.id || "" })} placeholder="Scholar" />
|
| 126 |
+
<${Text} label="Identifier" hint="used in links" value=${draft.id} onChange=${(v) => !lockedId && set({ id: v })} placeholder="scholar" mono=${true} />
|
| 127 |
+
<${Select} label="Type" value=${draft.kind} onChange=${(v) => set({ kind: v })}
|
| 128 |
+
options=${[{ value: "subscription", label: "Subscription" }, { value: "one_time", label: "One-off purchase" }]} />
|
| 129 |
+
${draft.kind === "subscription"
|
| 130 |
+
? html`<${Select} label="Billing period" value=${draft.interval || "month"} onChange=${(v) => set({ interval: v })}
|
| 131 |
+
options=${[{ value: "month", label: "Monthly" }, { value: "year", label: "Yearly" }]} />`
|
| 132 |
+
: html`<${Text} label="Sort order" value=${draft.sort} onChange=${(v) => set({ sort: Number(v) || 0 })} type="number" />`}
|
| 133 |
+
<${Text} label="Price" hint="in pounds" value=${price} onChange=${setPrice} type="number" />
|
| 134 |
+
<${Text} label="Included AI allowance" hint="pounds included in the price" value=${limit} onChange=${setLimit} type="number" />
|
| 135 |
+
<${Text} label="Download tier" hint="0–4 models unlocked" value=${draft.download_tier} onChange=${(v) => set({ download_tier: Number(v) || 0 })} type="number" />
|
| 136 |
+
<${Text} label="Sort order" value=${draft.sort} onChange=${(v) => set({ sort: Number(v) || 0 })} type="number" />
|
| 137 |
+
</div>
|
| 138 |
+
<div style=${{ marginTop: "10px" }}>
|
| 139 |
+
<${Area} label="Short description" value=${draft.blurb} onChange=${(v) => set({ blurb: v })} rows=${2} />
|
| 140 |
+
</div>
|
| 141 |
+
<div style=${{ marginTop: "10px" }}>
|
| 142 |
+
<${Area} label="Features" hint="one per line" value=${features} onChange=${setFeatures} rows=${4} />
|
| 143 |
+
</div>
|
| 144 |
+
<div class="grid two" style=${{ marginTop: "10px" }}>
|
| 145 |
+
<${Text} label="Stripe price ID" hint="price_…" value=${draft.stripe_price_id} onChange=${(v) => set({ stripe_price_id: v })} mono=${true} />
|
| 146 |
+
<${Text} label="Stripe payment link" hint="for one-off links" value=${draft.stripe_payment_link} onChange=${(v) => set({ stripe_payment_link: v })} mono=${true} />
|
| 147 |
+
</div>
|
| 148 |
+
<div class="row wrap" style=${{ marginTop: "10px" }}>
|
| 149 |
+
<${Check} label="Published" checked=${draft.active} onChange=${(v) => set({ active: v })} />
|
| 150 |
+
<${Check} label="Allow BYOK" checked=${draft.byok} onChange=${(v) => set({ byok: v })} />
|
| 151 |
+
</div>
|
| 152 |
+
${error && html`<div style=${{ marginTop: "10px" }}><${Notice} kind="error">${error}<//></div>`}
|
| 153 |
+
<div class="row" style=${{ marginTop: "12px" }}>
|
| 154 |
+
<button class="btn primary small" onClick=${save} disabled=${busy}>${busy ? html`<span class="spin"></span>` : "Save plan"}</button>
|
| 155 |
+
<button class="btn small ghost" onClick=${onDone}>Cancel</button>
|
| 156 |
+
</div>
|
| 157 |
+
</div>`;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
function PlansTab() {
|
| 161 |
+
const cloud = useCloud();
|
| 162 |
+
const [editing, setEditing] = useState(null);
|
| 163 |
+
const [confirm, setConfirm] = useState("");
|
| 164 |
+
|
| 165 |
+
return html`<div>
|
| 166 |
+
<div class="row between">
|
| 167 |
+
<div class="tiny faint">Plans appear on the plans page the moment they are published.</div>
|
| 168 |
+
<button class="btn primary small" onClick=${() => setEditing(BLANK_PLAN)}><${Icon} name="plus" size=${12} /> New plan</button>
|
| 169 |
+
</div>
|
| 170 |
+
${editing && html`<${PlanEditor} plan=${editing === BLANK_PLAN ? null : editing} onDone=${() => setEditing(null)} />`}
|
| 171 |
+
<div class="card" style=${{ marginTop: "12px" }}>
|
| 172 |
+
<div class="list">
|
| 173 |
+
${cloud.plans.length === 0 && html`<div class="empty">No plans yet.</div>`}
|
| 174 |
+
${cloud.plans.map(
|
| 175 |
+
(p) => html`<div class="list-row" key=${p.id}>
|
| 176 |
+
<div class="main">
|
| 177 |
+
<div class="t">${p.name} <span class="pill ${p.kind === "subscription" ? "green" : "neutral"}" style=${{ marginLeft: "6px" }}>${p.kind === "subscription" ? "Subscription" : "One-off"}</span>
|
| 178 |
+
${p.active === false && html`<span class="pill danger" style=${{ marginLeft: "6px" }}>Hidden</span>`}</div>
|
| 179 |
+
<div class="s">${money(p.price_cents, p.currency)} ${p.kind === "subscription" ? "per " + (p.interval || "month") : "once"} · ${p.cost_limit_cents ? money(p.cost_limit_cents, p.currency) + " model usage" : "no hosted usage"} · ${p.download_tier} download${p.download_tier === 1 ? "" : "s"}</div>
|
| 180 |
+
</div>
|
| 181 |
+
<button class="btn small" onClick=${() => setEditing(p)}>Edit</button>
|
| 182 |
+
${confirm === p.id
|
| 183 |
+
? html`<span class="row"><button class="btn small" onClick=${() => setConfirm("")}>Keep</button>
|
| 184 |
+
<button class="btn small danger" onClick=${async () => { await cloud.deletePlan(p.id); setConfirm(""); }}>Delete</button></span>`
|
| 185 |
+
: html`<button class="icon-btn" title="Delete" onClick=${() => setConfirm(p.id)}><${Icon} name="trash" size=${13} /></button>`}
|
| 186 |
+
</div>`
|
| 187 |
+
)}
|
| 188 |
+
</div>
|
| 189 |
+
</div>
|
| 190 |
+
</div>`;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
// ---------------------------------------------------------------------------
|
| 194 |
+
// Models
|
| 195 |
+
// ---------------------------------------------------------------------------
|
| 196 |
+
|
| 197 |
+
const BLANK_MODEL = {
|
| 198 |
+
id: "",
|
| 199 |
+
name: "",
|
| 200 |
+
host: "",
|
| 201 |
+
endpoint_url: "",
|
| 202 |
+
model_name: "",
|
| 203 |
+
cost_in_per_million: 0,
|
| 204 |
+
cost_out_per_million: 0,
|
| 205 |
+
min_tier: 1,
|
| 206 |
+
download_size: "",
|
| 207 |
+
note: "",
|
| 208 |
+
enabled: true,
|
| 209 |
+
sort: 0
|
| 210 |
+
};
|
| 211 |
+
|
| 212 |
+
function ModelEditor({ model, onDone }) {
|
| 213 |
+
const cloud = useCloud();
|
| 214 |
+
const [draft, setDraft] = useState(model || BLANK_MODEL);
|
| 215 |
+
const [apiKey, setApiKey] = useState("");
|
| 216 |
+
const [error, setError] = useState("");
|
| 217 |
+
const [saved, setSaved] = useState(false);
|
| 218 |
+
const [busy, setBusy] = useState(false);
|
| 219 |
+
const set = (patch) => setDraft((d) => ({ ...d, ...patch }));
|
| 220 |
+
|
| 221 |
+
const save = async () => {
|
| 222 |
+
setError("");
|
| 223 |
+
setBusy(true);
|
| 224 |
+
try {
|
| 225 |
+
const id = (draft.id || draft.model_name || draft.name || "").trim();
|
| 226 |
+
if (!draft.name.trim() || !id) throw new Error("The model needs a name and an identifier.");
|
| 227 |
+
await cloud.upsertModel({
|
| 228 |
+
...draft,
|
| 229 |
+
id,
|
| 230 |
+
cost_in_per_million: Number(draft.cost_in_per_million) || 0,
|
| 231 |
+
cost_out_per_million: Number(draft.cost_out_per_million) || 0,
|
| 232 |
+
min_tier: Number(draft.min_tier) || 0,
|
| 233 |
+
sort: Number(draft.sort) || 0
|
| 234 |
+
});
|
| 235 |
+
if (apiKey.trim()) {
|
| 236 |
+
await cloud.saveModelKey(id, apiKey.trim());
|
| 237 |
+
setApiKey("");
|
| 238 |
+
}
|
| 239 |
+
cloud.flash("Model saved.");
|
| 240 |
+
setSaved(true);
|
| 241 |
+
setTimeout(() => setSaved(false), 2000);
|
| 242 |
+
onDone();
|
| 243 |
+
} catch (err) {
|
| 244 |
+
setError(err && err.message ? err.message : "Could not save the model.");
|
| 245 |
+
}
|
| 246 |
+
setBusy(false);
|
| 247 |
+
};
|
| 248 |
+
|
| 249 |
+
return html`<div class="card fade-in" style=${{ marginTop: "10px" }}>
|
| 250 |
+
<div class="row between"><strong>${model ? "Edit " + model.name : "New model"}</strong>
|
| 251 |
+
<button class="btn small ghost" onClick=${onDone}>Close</button>
|
| 252 |
+
</div>
|
| 253 |
+
<div class="grid two" style=${{ marginTop: "10px" }}>
|
| 254 |
+
<${Text} label="Display name" value=${draft.name} onChange=${(v) => set({ name: v })} placeholder="Qwen2.5 7B" />
|
| 255 |
+
<${Text} label="Identifier" value=${draft.id} onChange=${(v) => set({ id: v })} placeholder="Qwen2.5-7B-Instruct-q4f16_1-MLC" mono=${true} />
|
| 256 |
+
<${Text} label="Host" hint="shown to students" value=${draft.host} onChange=${(v) => set({ host: v })} placeholder="OpenRouter" />
|
| 257 |
+
<${Text} label="Model name at the host" value=${draft.model_name} onChange=${(v) => set({ model_name: v })} placeholder="qwen/qwen-2.5-7b-instruct" mono=${true} />
|
| 258 |
+
<${Text} label="Endpoint base URL" hint="OpenAI-compatible" value=${draft.endpoint_url} onChange=${(v) => set({ endpoint_url: v })} placeholder="https://openrouter.ai/api/v1" mono=${true} />
|
| 259 |
+
<${Text} label="API key" hint="stored write-only" value=${apiKey} onChange=${setApiKey} placeholder=${model && model.id ? "Paste a new key to replace" : "sk-…"} type="password" />
|
| 260 |
+
<${Text} label="Input cost" hint="per million tokens" value=${draft.cost_in_per_million} onChange=${(v) => set({ cost_in_per_million: v })} type="number" />
|
| 261 |
+
<${Text} label="Output cost" hint="per million tokens" value=${draft.cost_out_per_million} onChange=${(v) => set({ cost_out_per_million: v })} type="number" />
|
| 262 |
+
<${Text} label="Minimum download tier" hint="0–4" value=${draft.min_tier} onChange=${(v) => set({ min_tier: Number(v) || 0 })} type="number" />
|
| 263 |
+
<${Text} label="Download size" value=${draft.download_size} onChange=${(v) => set({ download_size: v })} placeholder="~4.5 GB" />
|
| 264 |
+
</div>
|
| 265 |
+
<div style=${{ marginTop: "10px" }}">
|
| 266 |
+
<${Area} label="Note" value=${draft.note} onChange=${(v) => set({ note: v })} rows=${2} placeholder="What this model is good for." />
|
| 267 |
+
</div>
|
| 268 |
+
${error && html`<div style=${{ marginTop: "10px" }}><${Notice} kind="error">${error}<//></div>`}
|
| 269 |
+
<div class="row" style=${{ marginTop: "12px" }}>
|
| 270 |
+
<button class="btn primary small" onClick=${save} disabled=${busy}>${busy ? html`<span class="spin"></span>` : saved ? "Saved" : "Save model"}</button>
|
| 271 |
+
<${Check} label="Enabled" checked=${draft.enabled} onChange=${(v) => set({ enabled: v })} />
|
| 272 |
+
</div>
|
| 273 |
+
<div class="tiny faint" style=${{ marginTop: "8px" }}>
|
| 274 |
+
The key is used only by the hosted model function on Supabase. It is never sent to a browser.
|
| 275 |
+
</div>
|
| 276 |
+
</div>`;
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
function ModelsTab() {
|
| 280 |
+
const cloud = useCloud();
|
| 281 |
+
const [editing, setEditing] = useState(null);
|
| 282 |
+
const [confirm, setConfirm] = useState("");
|
| 283 |
+
|
| 284 |
+
return html`<div>
|
| 285 |
+
<div class="row between wrap">
|
| 286 |
+
<div class="tiny faint" style=${{ maxWidth: "560px" }}>
|
| 287 |
+
Each model has its own host, endpoint and key. Students download the ones their plan unlocks; the rest run through the hosted function using these keys.
|
| 288 |
+
</div>
|
| 289 |
+
<button class="btn primary small" onClick=${() => setEditing(BLANK_MODEL)}><${Icon} name="plus" size=${12} /> New model</button>
|
| 290 |
+
</div>
|
| 291 |
+
${editing && html`<${ModelEditor} model=${editing === BLANK_MODEL ? null : editing} onDone=${() => setEditing(null)} />`}
|
| 292 |
+
<div class="card" style=${{ marginTop: "12px" }}>
|
| 293 |
+
<div class="list">
|
| 294 |
+
${cloud.models.map(
|
| 295 |
+
(m) => html`<div class="list-row" key=${m.id}>
|
| 296 |
+
<div class="main">
|
| 297 |
+
<div class="t">${m.name} ${m.enabled === false && html`<span class="pill danger" style=${{ marginLeft: "6px" }}>Off</span>`}</div>
|
| 298 |
+
<div class="s">${m.host || "Browser"} · tier ${m.min_tier} · ${m.download_size || "no download"} · ${m.cost_in_per_million || 0}/${m.cost_out_per_million || 0} per M tokens</div>
|
| 299 |
+
</div>
|
| 300 |
+
<button class="btn small" onClick=${() => setEditing(m)}>Edit</button>
|
| 301 |
+
${confirm === m.id
|
| 302 |
+
? html`<span class="row"><button class="btn small" onClick=${() => setConfirm("")}>Keep</button>
|
| 303 |
+
<button class="btn small danger" onClick=${async () => { await cloud.deleteModel(m.id); setConfirm(""); }}>Delete</button></span>`
|
| 304 |
+
: html`<button class="icon-btn" title="Delete" onClick=${() => setConfirm(m.id)}><${Icon} name="trash" size=${13} /></button>`}
|
| 305 |
+
</div>`
|
| 306 |
+
)}
|
| 307 |
+
${cloud.models.length === 0 && html`<div class="empty">No models yet. <button class="btn link small" onClick=${() => setEditing(BLANK_MODEL)}>Add one</button></div>`}
|
| 308 |
+
</div>
|
| 309 |
+
</div>
|
| 310 |
+
</div>`;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
// ---------------------------------------------------------------------------
|
| 314 |
+
// Wording / edit mode
|
| 315 |
+
// ---------------------------------------------------------------------------
|
| 316 |
+
|
| 317 |
+
function WordingTab() {
|
| 318 |
+
const cloud = useCloud();
|
| 319 |
+
const { editing, setEditing } = useEditMode();
|
| 320 |
+
const keys = Object.keys(cloud.content || {}).sort();
|
| 321 |
+
|
| 322 |
+
return html`<div>
|
| 323 |
+
<div class="card">
|
| 324 |
+
<div class="row between wrap">
|
| 325 |
+
<div style=${{ maxWidth: "560px" }}>
|
| 326 |
+
<div style=${{ fontWeight: 600 }}>Edit mode</div>
|
| 327 |
+
<div class="tiny faint" style=${{ marginTop: "3px", lineHeight: 1.55 }}>
|
| 328 |
+
Turn it on, then open any page and click the writing. Every change is saved and shown to everyone, in every browser.
|
| 329 |
+
</div>
|
| 330 |
+
</div>
|
| 331 |
+
<button class=${"btn small " + (editing ? "green" : "primary")} onClick=${() => setEditing(!editing)}>
|
| 332 |
+
${editing ? "Editing — click Done when finished" : "Turn on edit mode"}
|
| 333 |
+
</button>
|
| 334 |
+
</div>
|
| 335 |
+
</div>
|
| 336 |
+
|
| 337 |
+
<div class="section-head"><h2 class="section-title">Changed wording</h2></div>
|
| 338 |
+
<div class="card">
|
| 339 |
+
${keys.length === 0
|
| 340 |
+
? html`<div class="empty">Nothing has been reworded yet. Turn on edit mode and click a heading on the Today or Plans page.</div>`
|
| 341 |
+
: html`<div class="list">
|
| 342 |
+
${keys.map(
|
| 343 |
+
(key) => html`<div class="list-row" key=${key} style=${{ alignItems: "flex-start" }}>
|
| 344 |
+
<div class="main">
|
| 345 |
+
<div class="t mono" style=${{ fontSize: "11px" }}>${key}</div>
|
| 346 |
+
<div class="s" style=${{ whiteSpace: "pre-wrap" }}>${cloud.content[key]}</div>
|
| 347 |
+
</div>
|
| 348 |
+
<button class="btn small" onClick=${async () => { await cloud.clearContent(key); cloud.flash("Reverted to the original wording."); }}>Reset</button>
|
| 349 |
+
</div>`
|
| 350 |
+
)}
|
| 351 |
+
</div>`}
|
| 352 |
+
</div>
|
| 353 |
+
|
| 354 |
+
<div class="card" style=${{ marginTop: "12px" }}>
|
| 355 |
+
<div class="tiny faint" style=${{ lineHeight: 1.6 }}>
|
| 356 |
+
Every edit is stored by key, so it survives a refresh and reaches every visitor. Only the developer account can change it — row-level security in Supabase enforces that even if someone opens the developer page.
|
| 357 |
+
</div>
|
| 358 |
+
</div>
|
| 359 |
+
</div>`;
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
// ---------------------------------------------------------------------------
|
| 363 |
+
// Stripe
|
| 364 |
+
// ---------------------------------------------------------------------------
|
| 365 |
+
|
| 366 |
+
function StripeTab() {
|
| 367 |
+
const cloud = useCloud();
|
| 368 |
+
const [publishable, setPublishable] = useState(cloud.settings.stripe_publishable_key || "");
|
| 369 |
+
const [mode, setMode] = useState(cloud.settings.stripe_mode || "payment_links");
|
| 370 |
+
const [fn, setFn] = useState(cloud.settings.checkout_function || "stripe-checkout");
|
| 371 |
+
const [busy, setBusy] = useState(false);
|
| 372 |
+
const [saved, setSaved] = useState(false);
|
| 373 |
+
|
| 374 |
+
const save = async () => {
|
| 375 |
+
setBusy(true);
|
| 376 |
+
try {
|
| 377 |
+
await cloud.setSettings({ stripe_publishable_key: publishable.trim(), stripe_mode: mode, checkout_function: fn.trim() || "stripe-checkout" });
|
| 378 |
+
setSaved(true);
|
| 379 |
+
setTimeout(() => setSaved(false), 2000);
|
| 380 |
+
} catch (err) {
|
| 381 |
+
cloud.flash(err && err.message ? err.message : "Could not save.");
|
| 382 |
+
}
|
| 383 |
+
setBusy(false);
|
| 384 |
+
};
|
| 385 |
+
|
| 386 |
+
return html`<div>
|
| 387 |
+
<div class="card">
|
| 388 |
+
<div class="section-title" style=${{ marginBottom: "10px" }}>Payments</div>
|
| 389 |
+
<div class="grid two">
|
| 390 |
+
<${Select} label="Checkout mode" value=${mode} onChange=${setMode}
|
| 391 |
+
options=${[
|
| 392 |
+
{ value: "payment_links", label: "Stripe payment links" },
|
| 393 |
+
{ value: "function", label: "Supabase checkout function" }
|
| 394 |
+
]} />
|
| 395 |
+
<${Text} label="Publishable key" hint="pk_live_… or pk_test_…" value=${publishable} onChange=${setPublishable} mono=${true} />
|
| 396 |
+
</div>
|
| 397 |
+
${mode === "function"
|
| 398 |
+
? html`<div style=${{ marginTop: "10px" }}>
|
| 399 |
+
<${Text} label="Checkout function" hint="deployed in Supabase" value=${fn} onChange=${setFn} mono=${true} />
|
| 400 |
+
</div>`
|
| 401 |
+
: html`<div class="tiny faint" style=${{ marginTop: "10px", lineHeight: 1.6 }}>
|
| 402 |
+
Add a payment link to each plan in Plans. The link gets the buyer's account attached automatically, so a webhook can grant access.
|
| 403 |
+
</div>`}
|
| 404 |
+
<div class="row" style=${{ marginTop: "12px" }}>
|
| 405 |
+
<button class="btn primary small" onClick=${save} disabled=${busy}>${busy ? html`<span class="spin"></span>` : saved ? "Saved" : "Save payment settings"}</button>
|
| 406 |
+
</div>
|
| 407 |
+
</div>
|
| 408 |
+
|
| 409 |
+
<div class="card" style=${{ marginTop: "12px" }}>
|
| 410 |
+
<div class="section-title" style=${{ marginBottom: "8px" }}>Where the secret key goes</div>
|
| 411 |
+
<div class="tiny muted" style=${{ lineHeight: 1.7 }}>
|
| 412 |
+
Never in this page. Put <span class="mono">STRIPE_SECRET_KEY</span> and <span class="mono">STRIPE_WEBHOOK_SECRET</span> in Supabase → Edge Functions → Secrets, deploy <span class="mono">stripe-checkout</span> and <span class="mono">stripe-webhook</span>, then point a Stripe webhook at <span class="mono">https://YOUR-PROJECT.supabase.co/functions/v1/stripe-webhook</span>. Steps are in <span class="mono">supabase/SETUP.md</span>.
|
| 413 |
+
</div>
|
| 414 |
+
<div class="divider"></div>
|
| 415 |
+
<div class="tiny muted" style=${{ lineHeight: 1.7 }}>
|
| 416 |
+
Prices come from the plans table, so you can change a price here without touching Stripe — or map a Stripe price ID to each plan and let Stripe hold the price.
|
| 417 |
+
</div>
|
| 418 |
+
</div>
|
| 419 |
+
</div>`;
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
// ---------------------------------------------------------------------------
|
| 423 |
+
// Supabase + people
|
| 424 |
+
// ---------------------------------------------------------------------------
|
| 425 |
+
|
| 426 |
+
function SupabaseTab() {
|
| 427 |
+
const cloud = useCloud();
|
| 428 |
+
const [url, setUrl] = useState(cloud.config.url);
|
| 429 |
+
const [key, setKey] = useState(cloud.config.anonKey);
|
| 430 |
+
const [confirm, setConfirm] = useState(false);
|
| 431 |
+
const [error, setError] = useState("");
|
| 432 |
+
|
| 433 |
+
const apply = () => {
|
| 434 |
+
setError("");
|
| 435 |
+
const clean = url.trim().replace(/\/+$/, "");
|
| 436 |
+
if (!/^https?:\/\/.+/.test(clean) || key.trim().length < 20) {
|
| 437 |
+
setError("Both values are needed. The URL looks like https://yourproject.supabase.co and the key starts with eyJ.");
|
| 438 |
+
return;
|
| 439 |
+
}
|
| 440 |
+
cloud.connect({ url: clean, anonKey: key.trim() });
|
| 441 |
+
cloud.flash("Connection updated.");
|
| 442 |
+
};
|
| 443 |
+
|
| 444 |
+
return html`<div>
|
| 445 |
+
<div class="card">
|
| 446 |
+
<div class="row between wrap">
|
| 447 |
+
<div>
|
| 448 |
+
<div style=${{ fontWeight: 600 }}>Project</div>
|
| 449 |
+
<div class="tiny faint mono" style=${{ marginTop: "3px" }}>${cloud.configured ? cloud.config.url : "not connected"}</div>
|
| 450 |
+
</div>
|
| 451 |
+
<${Pill} tone=${cloud.configured ? "green" : "warn"}>${cloud.configured ? "Connected" : "Preview mode"}</${Pill}>
|
| 452 |
+
</div>
|
| 453 |
+
<div class="grid two" style=${{ marginTop: "12px" }}>
|
| 454 |
+
<${Text} label="Project URL" value=${url} onChange=${setUrl} placeholder="https://abcdefgh.supabase.co" mono=${true} />
|
| 455 |
+
<${Field} label="Anon public key" hint="safe to publish">
|
| 456 |
+
<textarea class="textarea plain" style=${{ minHeight: "64px" }} value=${key} onInput=${(e) => setKey(e.target.value)} placeholder="eyJhbGciOi…"></textarea>
|
| 457 |
+
<//>
|
| 458 |
+
</div>
|
| 459 |
+
${error && html`<div style=${{ marginTop: "8px" }}><${Notice} kind="error">${error}<//></div>`}
|
| 460 |
+
<div class="row wrap" style=${{ marginTop: "10px" }}>
|
| 461 |
+
<button class="btn primary small" onClick=${apply}>Save connection</button>
|
| 462 |
+
<a class="btn small" href="SETUP.html" target="_blank" rel="noreferrer">Open the picture guide</a>
|
| 463 |
+
</div>
|
| 464 |
+
<div class="tiny faint" style=${{ marginTop: "8px", lineHeight: 1.6 }}>
|
| 465 |
+
This is the same connection first-run visitors see. Once it is saved, the setup prompt disappears from the site permanently — it lives here from then on.
|
| 466 |
+
</div>
|
| 467 |
+
</div>
|
| 468 |
+
|
| 469 |
+
<div class="card" style=${{ marginTop: "12px" }}>
|
| 470 |
+
<div class="row between wrap">
|
| 471 |
+
<div style=${{ maxWidth: "520px" }}>
|
| 472 |
+
<div style=${{ fontWeight: 600 }}>Disconnect</div>
|
| 473 |
+
<div class="tiny faint" style=${{ marginTop: "3px", lineHeight: 1.55 }}>
|
| 474 |
+
Removes the connection from this browser and returns the site to preview mode. Nothing is deleted in Supabase.
|
| 475 |
+
</div>
|
| 476 |
+
</div>
|
| 477 |
+
${confirm
|
| 478 |
+
? html`<span class="row"><button class="btn small" onClick=${() => setConfirm(false)}>Keep it</button>
|
| 479 |
+
<button class="btn small danger" onClick=${() => { cloud.disconnect(); setConfirm(false); }}>Disconnect</button></span>`
|
| 480 |
+
: html`<button class="btn small danger" onClick=${() => setConfirm(true)}>Disconnect</button>`}
|
| 481 |
+
</div>
|
| 482 |
+
</div>
|
| 483 |
+
</div>`;
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
function PeopleTab() {
|
| 487 |
+
const cloud = useCloud();
|
| 488 |
+
const [email, setEmail] = useState("");
|
| 489 |
+
const [planId, setPlanId] = useState(cloud.plans[0] ? cloud.plans[0].id : "");
|
| 490 |
+
const [error, setError] = useState("");
|
| 491 |
+
const [busy, setBusy] = useState(false);
|
| 492 |
+
|
| 493 |
+
const grant = async () => {
|
| 494 |
+
setError("");
|
| 495 |
+
if (!/^\S+@\S+\.\S+$/.test(email.trim())) return setError("Type the buyer's email.");
|
| 496 |
+
if (!planId) return setError("Pick a plan.");
|
| 497 |
+
setBusy(true);
|
| 498 |
+
try {
|
| 499 |
+
await cloud.grantPlan(email.trim(), planId);
|
| 500 |
+
cloud.flash("Access granted to " + email.trim() + ".");
|
| 501 |
+
setEmail("");
|
| 502 |
+
} catch (err) {
|
| 503 |
+
setError(err && err.message ? err.message : "Could not grant access.");
|
| 504 |
+
}
|
| 505 |
+
setBusy(false);
|
| 506 |
+
};
|
| 507 |
+
|
| 508 |
+
return html`<div>
|
| 509 |
+
<div class="card">
|
| 510 |
+
<div class="section-title" style=${{ marginBottom: "8px" }}>Give someone a plan</div>
|
| 511 |
+
<div class="tiny faint" style=${{ marginBottom: "10px", lineHeight: 1.55 }}>
|
| 512 |
+
For payments taken outside Stripe, or to fix a webhook that missed. The plan stays until you revoke it.
|
| 513 |
+
</div>
|
| 514 |
+
<div class="grid two">
|
| 515 |
+
<${Text} label="Buyer's email" value=${email} onChange=${setEmail} placeholder="student@example.com" />
|
| 516 |
+
<${Select} label="Plan" value=${planId} onChange=${setPlanId}
|
| 517 |
+
options=${cloud.plans.map((p) => ({ value: p.id, label: p.name + " · " + money(p.price_cents, p.currency) }))} />
|
| 518 |
+
</div>
|
| 519 |
+
${error && html`<div style=${{ marginTop: "8px" }}><${Notice} kind="error">${error}<//></div>`}
|
| 520 |
+
<button class="btn primary small" style=${{ marginTop: "10px" }} onClick=${grant} disabled=${busy}>${busy ? html`<span class="spin"></span>` : "Grant access"}</button>
|
| 521 |
+
</div>
|
| 522 |
+
|
| 523 |
+
<div class="section-head"><h2 class="section-title">Access</h2></div>
|
| 524 |
+
<div class="card">
|
| 525 |
+
${cloud.entitlements.length === 0
|
| 526 |
+
? html`<div class="empty">No plans have been granted yet.</div>`
|
| 527 |
+
: html`<div class="list">
|
| 528 |
+
${cloud.entitlements.map(
|
| 529 |
+
(e) => html`<div class="list-row" key=${e.id}>
|
| 530 |
+
<div class="main">
|
| 531 |
+
<div class="t">${e.email || e.user_id || "—"} <span class="pill neutral" style=${{ marginLeft: "6px" }}>${e.plan_id}</span>
|
| 532 |
+
${e.revoked && html`<span class="pill danger" style=${{ marginLeft: "6px" }}>Revoked</span>`}</div>
|
| 533 |
+
<div class="s">${e.source || "grant"} · ${new Date(e.granted_at || Date.now()).toLocaleDateString("en-GB")}${e.expires_at ? " → " + new Date(e.expires_at).toLocaleDateString("en-GB") : ""}</div>
|
| 534 |
+
</div>
|
| 535 |
+
${!e.revoked && html`<button class="btn small danger" onClick=${() => cloud.revokeGrant(e.id)}>Revoke</button>`}
|
| 536 |
+
</div>`
|
| 537 |
+
)}
|
| 538 |
+
</div>`}
|
| 539 |
+
</div>
|
| 540 |
+
|
| 541 |
+
<div class="section-head"><h2 class="section-title">Recent model spend</h2></div>
|
| 542 |
+
<div class="card">
|
| 543 |
+
${cloud.usage.length === 0
|
| 544 |
+
? html`<div class="empty">No hosted model calls have been recorded yet.</div>`
|
| 545 |
+
: html`<div class="list">
|
| 546 |
+
${cloud.usage.slice(0, 12).map(
|
| 547 |
+
(u) => html`<div class="list-row" key=${u.id}>
|
| 548 |
+
<div class="main"><div class="t">${u.model_id}</div>
|
| 549 |
+
<div class="s">${new Date(u.created_at || Date.now()).toLocaleString("en-GB")} · ${u.tokens_in || 0} in / ${u.tokens_out || 0} out</div></div>
|
| 550 |
+
<span class="pill neutral">${money(u.cost_cents)}</span>
|
| 551 |
+
</div>`
|
| 552 |
+
)}
|
| 553 |
+
</div>`}
|
| 554 |
+
</div>
|
| 555 |
+
</div>`;
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
// ---------------------------------------------------------------------------
|
| 559 |
+
// Console
|
| 560 |
+
// ---------------------------------------------------------------------------
|
| 561 |
+
|
| 562 |
+
const TABS = [
|
| 563 |
+
{ id: "overview", label: "Overview" },
|
| 564 |
+
{ id: "plans", label: "Plans" },
|
| 565 |
+
{ id: "models", label: "Models & keys" },
|
| 566 |
+
{ id: "wording", label: "Wording" },
|
| 567 |
+
{ id: "stripe", label: "Stripe" },
|
| 568 |
+
{ id: "people", label: "People" },
|
| 569 |
+
{ id: "supabase", label: "Supabase" }
|
| 570 |
+
];
|
| 571 |
+
|
| 572 |
+
export function Developer() {
|
| 573 |
+
const cloud = useCloud();
|
| 574 |
+
const [tab, setTab] = useState("overview");
|
| 575 |
+
const { editing, setEditing } = useEditMode();
|
| 576 |
+
|
| 577 |
+
if (!cloud.isDev) {
|
| 578 |
+
return html`<main class="page narrow">
|
| 579 |
+
<${Head} kicker="Developer" title="This area is not yours." subtitle=${cloud.configured ? "Only " + DEVELOPER_EMAIL + " can change plans, prices, models or wording." : "Connect Supabase first."} />
|
| 580 |
+
<div class="card" style=${{ marginTop: "16px" }}>
|
| 581 |
+
${cloud.configured
|
| 582 |
+
? html`<${Notice} kind="warn">Signed in${cloud.user ? " as " + cloud.user.email : " as a guest"}. The developer console belongs to ${DEVELOPER_EMAIL}.<//>`
|
| 583 |
+
: html`<${Notice} kind="info">This copy is not connected to Supabase yet, so there is no developer account to check against. Connect it to lock this page down.<//>`}
|
| 584 |
+
<div class="row" style=${{ marginTop: "10px" }}>
|
| 585 |
+
<a class="btn small" href="#/account">Account</a>
|
| 586 |
+
<a class="btn small" href="#/pricing">Plans</a>
|
| 587 |
+
</div>
|
| 588 |
+
</div>
|
| 589 |
+
</main>`;
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
+
return html`<main class="page">
|
| 593 |
+
<${Head} kicker="Developer" title="Console"
|
| 594 |
+
subtitle=${cloud.configured ? "Signed in as " + cloud.user.email : "Preview mode — changes stay in this browser until Supabase is connected."}
|
| 595 |
+
right=${cloud.configured ? html`<${Pill} tone="green">Developer<//>` : html`<${Pill} tone="warn">Preview<//>`} />
|
| 596 |
+
|
| 597 |
+
<div class="tabs" style=${{ marginTop: "16px" }}>
|
| 598 |
+
${TABS.map((t) => html`<button key=${t.id} class=${"tab" + (tab === t.id ? " active" : "")} onClick=${() => setTab(t.id)}>${t.label}</button>`)}
|
| 599 |
+
</div>
|
| 600 |
+
|
| 601 |
+
<div style=${{ marginTop: "14px" }}>
|
| 602 |
+
${tab === "overview" &&
|
| 603 |
+
html`<div>
|
| 604 |
+
<div class="grid four">
|
| 605 |
+
<${Stat} label="Plans" value=${cloud.plans.length} note=${cloud.plans.filter((p) => p.active !== false).length + " published"} />
|
| 606 |
+
<${Stat} label="Models" value=${cloud.models.length} note=${cloud.models.filter((m) => m.enabled !== false).length + " enabled"} />
|
| 607 |
+
<${Stat} label="People" value=${cloud.entitlements.filter((e) => !e.revoked).length} note="with access" />
|
| 608 |
+
<${Stat} label="Spend" value=${money(cloud.usage.reduce((s, u) => s + Number(u.cost_cents || 0), 0))} note="recent model usage" />
|
| 609 |
+
</div>
|
| 610 |
+
|
| 611 |
+
<div class="grid two" style=${{ marginTop: "12px" }}>
|
| 612 |
+
<div class="card">
|
| 613 |
+
<div class="section-title" style=${{ marginBottom: "8px" }}>Payments</div>
|
| 614 |
+
<div class="row between"><span class="tiny muted">Mode</span><span class="tiny mono">${cloud.settings.stripe_mode}</span></div>
|
| 615 |
+
<div class="row between" style=${{ marginTop: "6px" }}><span class="tiny muted">Publishable key</span><span class="tiny mono">${cloud.settings.stripe_publishable_key ? "set" : "missing"}</span></div>
|
| 616 |
+
<div class="row between" style=${{ marginTop: "6px" }}><span class="tiny muted">Plans with a link or price</span><span class="tiny mono">${cloud.plans.filter((p) => p.stripe_payment_link || p.stripe_price_id).length}/${cloud.plans.length}</span></div>
|
| 617 |
+
<button class="btn small" style=${{ marginTop: "10px" }} onClick=${() => setTab("stripe")}>Open Stripe settings</button>
|
| 618 |
+
</div>
|
| 619 |
+
<div class="card">
|
| 620 |
+
<div class="section-title" style=${{ marginBottom: "8px" }}>The page itself</div>
|
| 621 |
+
<div class="tiny muted" style=${{ lineHeight: 1.6 }}>Change any wording a visitor reads, without editing code. Turn edit mode on, then click the text.</div>
|
| 622 |
+
<div class="row" style=${{ marginTop: "10px" }}>
|
| 623 |
+
<button class=${"btn small " + (editing ? "green" : "primary")} onClick=${() => setEditing(!editing)}>${editing ? "Editing" : "Turn on edit mode"}</button>
|
| 624 |
+
<button class="btn small" onClick=${() => setTab("wording")}>Changed wording</button>
|
| 625 |
+
</div>
|
| 626 |
+
</div>
|
| 627 |
+
</div>
|
| 628 |
+
|
| 629 |
+
${!cloud.configured &&
|
| 630 |
+
html`<div class="card" style=${{ marginTop: "12px" }}>
|
| 631 |
+
<div class="row between wrap">
|
| 632 |
+
<div style=${{ maxWidth: "560px" }}>
|
| 633 |
+
<div style=${{ fontWeight: 600 }}>Connect Supabase to share any of this</div>
|
| 634 |
+
<div class="tiny faint" style=${{ marginTop: "3px", lineHeight: 1.55 }}>
|
| 635 |
+
In preview mode plans, models and wording live in this browser only. Connecting a project puts logins and shared content in place.
|
| 636 |
+
</div>
|
| 637 |
+
</div>
|
| 638 |
+
<a class="btn primary small" href="#/connect">Connect Supabase</a>
|
| 639 |
+
</div>
|
| 640 |
+
</div>`}
|
| 641 |
+
</div>`}
|
| 642 |
+
${tab === "plans" && html`<${PlansTab} />`}
|
| 643 |
+
${tab === "models" && html`<${ModelsTab} />`}
|
| 644 |
+
${tab === "wording" && html`<${WordingTab} />`}
|
| 645 |
+
${tab === "stripe" && html`<${StripeTab} />`}
|
| 646 |
+
${tab === "people" && html`<${PeopleTab} />`}
|
| 647 |
+
${tab === "supabase" && html`<${SupabaseTab} />`}
|
| 648 |
+
</div>
|
| 649 |
+
</main>`;
|
| 650 |
+
}
|
js/app.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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React, ReactDOM, html, useEffect, useState } from "./runtime.js";
|
| 2 |
+
import { AppProvider, useApp } from "./store.js";
|
| 3 |
+
import { EngineProvider } from "./engine.js";
|
| 4 |
+
import { CloudProvider, useCloud } from "./cloud.js";
|
| 5 |
+
import { EditModeProvider, useEditMode } from "./copy.js";
|
| 6 |
+
import { Sidebar, Drawer, TopBar, SECTIONS, Icon } from "./components.js";
|
| 7 |
+
import { Dashboard, Chat, Coach, Essay, Poetry, Improve } from "./screens.js";
|
| 8 |
+
import { ModelAnswers, MockExam, ProcessLog, Settings } from "./screens-extra.js";
|
| 9 |
+
import { Pricing } from "./pricing.js";
|
| 10 |
+
import { Account, Connect, Welcome, NewPassword, LinkProblem } from "./auth.js";
|
| 11 |
+
import { Developer } from "./admin.js";
|
| 12 |
+
|
| 13 |
+
// Screens that exist but are not in the sidebar: reachable by link, never listed.
|
| 14 |
+
const HIDDEN_ROUTES = ["connect", "welcome", "new-password", "link-problem"];
|
| 15 |
+
|
| 16 |
+
function isRoute(id) {
|
| 17 |
+
return SECTIONS.some((s) => s.id === id) || HIDDEN_ROUTES.includes(id);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
function currentSection() {
|
| 21 |
+
const raw = (window.location.hash || "").replace(/^#\/?/, "");
|
| 22 |
+
return isRoute(raw) ? raw : "dashboard";
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
// Supabase comes back from an email link with the session, or an error, in the
|
| 26 |
+
// address itself (#access_token=…&type=signup). Read that once at startup,
|
| 27 |
+
// before the router touches the URL, so a confirmed sign-up gets its own
|
| 28 |
+
// landing screen instead of being dropped straight on the dashboard.
|
| 29 |
+
function readArrival() {
|
| 30 |
+
const raw = (window.location.hash || "") + "&" + (window.location.search || "");
|
| 31 |
+
if (/(?:^|[?&#])error=/.test(raw)) return "error";
|
| 32 |
+
const type = (raw.match(/(?:^|[?&#])type=([a-z_]+)/) || [])[1] || "";
|
| 33 |
+
if (["signup", "magiclink", "email_change", "recovery", "invite"].includes(type)) return type;
|
| 34 |
+
if (/access_token=/.test(raw) || /[?&]code=/.test(raw)) return "session";
|
| 35 |
+
return "";
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
const ARRIVAL = readArrival();
|
| 39 |
+
const ARRIVAL_ROUTE =
|
| 40 |
+
ARRIVAL === "error"
|
| 41 |
+
? "link-problem"
|
| 42 |
+
: ARRIVAL === "recovery" || ARRIVAL === "invite"
|
| 43 |
+
? "new-password"
|
| 44 |
+
: ARRIVAL
|
| 45 |
+
? "welcome"
|
| 46 |
+
: "";
|
| 47 |
+
|
| 48 |
+
function SetupBanner({ onConnect, onDismiss }) {
|
| 49 |
+
return html`<div class="setup-banner">
|
| 50 |
+
<${Icon} name="sparkle" size=${15} />
|
| 51 |
+
<div class="setup-copy">
|
| 52 |
+
<strong>This copy of Explication has no accounts yet.</strong>
|
| 53 |
+
<span> Connect Supabase to add sign-in, plans and shared page edits. Until then everything uses this browser.</span>
|
| 54 |
+
</div>
|
| 55 |
+
<button class="btn small primary" onClick=${onConnect}>Connect Supabase</button>
|
| 56 |
+
<button class="icon-btn" onClick=${onDismiss} aria-label="Dismiss"><${Icon} name="x" size=${14} /></button>
|
| 57 |
+
</div>`;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
function EditBar({ onDone, onSettings }) {
|
| 61 |
+
return html`<div class="edit-bar">
|
| 62 |
+
<span class="dot-live"></span>
|
| 63 |
+
<span><strong>Edit mode.</strong> Click any highlighted wording to change it for everyone.</span>
|
| 64 |
+
<button class="btn small" onClick=${onSettings}>Changed wording</button>
|
| 65 |
+
<button class="btn small primary" onClick=${onDone}>Done</button>
|
| 66 |
+
</div>`;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
function Shell() {
|
| 70 |
+
const cloud = useCloud();
|
| 71 |
+
const [section, setSection] = useState(() => ARRIVAL_ROUTE || currentSection());
|
| 72 |
+
const [arrival, setArrival] = useState(ARRIVAL_ROUTE);
|
| 73 |
+
const [drawer, setDrawer] = useState(false);
|
| 74 |
+
const { editing, setEditing } = useEditMode();
|
| 75 |
+
const [dismissed, setDismissed] = useState(() => {
|
| 76 |
+
try {
|
| 77 |
+
return localStorage.getItem("explication.setup.dismissed") === "1";
|
| 78 |
+
} catch {
|
| 79 |
+
return false;
|
| 80 |
+
}
|
| 81 |
+
});
|
| 82 |
+
|
| 83 |
+
const navigate = (id) => {
|
| 84 |
+
if (!isRoute(id)) id = "dashboard";
|
| 85 |
+
setArrival("");
|
| 86 |
+
setSection(id);
|
| 87 |
+
if (window.location.hash !== "#/" + id) window.location.hash = "#/" + id;
|
| 88 |
+
window.scrollTo({ top: 0, behavior: "instant" });
|
| 89 |
+
};
|
| 90 |
+
|
| 91 |
+
useEffect(() => {
|
| 92 |
+
const onHash = () => {
|
| 93 |
+
const hash = window.location.hash || "";
|
| 94 |
+
// Supabase wipes its token from the address once it has read it, which
|
| 95 |
+
// fires a hashchange with no route. Keep the arrival screen on show.
|
| 96 |
+
if (arrival && !hash.startsWith("#/")) return;
|
| 97 |
+
if (arrival) setArrival("");
|
| 98 |
+
setSection(currentSection());
|
| 99 |
+
};
|
| 100 |
+
window.addEventListener("hashchange", onHash);
|
| 101 |
+
if (!arrival && !window.location.hash) window.location.hash = "#/dashboard";
|
| 102 |
+
return () => window.removeEventListener("hashchange", onHash);
|
| 103 |
+
}, [arrival]);
|
| 104 |
+
|
| 105 |
+
// A first-run visitor who has already been to the setup screen is not asked again.
|
| 106 |
+
const showSetup = !cloud.configured && !dismissed && section !== "connect" && !arrival;
|
| 107 |
+
|
| 108 |
+
const dismissSetup = () => {
|
| 109 |
+
setDismissed(true);
|
| 110 |
+
try {
|
| 111 |
+
localStorage.setItem("explication.setup.dismissed", "1");
|
| 112 |
+
} catch {
|
| 113 |
+
// ignore
|
| 114 |
+
}
|
| 115 |
+
};
|
| 116 |
+
|
| 117 |
+
const screen = (() => {
|
| 118 |
+
switch (section) {
|
| 119 |
+
case "chat":
|
| 120 |
+
return html`<${Chat} />`;
|
| 121 |
+
case "coach":
|
| 122 |
+
return html`<${Coach} />`;
|
| 123 |
+
case "essay":
|
| 124 |
+
return html`<${Essay} />`;
|
| 125 |
+
case "poetry":
|
| 126 |
+
return html`<${Poetry} />`;
|
| 127 |
+
case "improve":
|
| 128 |
+
return html`<${Improve} />`;
|
| 129 |
+
case "modelAnswer":
|
| 130 |
+
return html`<${ModelAnswers} />`;
|
| 131 |
+
case "mockExam":
|
| 132 |
+
return html`<${MockExam} />`;
|
| 133 |
+
case "process":
|
| 134 |
+
return html`<${ProcessLog} />`;
|
| 135 |
+
case "settings":
|
| 136 |
+
return html`<${Settings} />`;
|
| 137 |
+
case "pricing":
|
| 138 |
+
return html`<${Pricing} />`;
|
| 139 |
+
case "account":
|
| 140 |
+
return html`<${Account} onDone=${() => navigate("dashboard")} />`;
|
| 141 |
+
case "connect":
|
| 142 |
+
return html`<${Connect} />`;
|
| 143 |
+
case "welcome":
|
| 144 |
+
return html`<${Welcome} kind=${ARRIVAL} onDone=${() => navigate("dashboard")} />`;
|
| 145 |
+
case "new-password":
|
| 146 |
+
return html`<${NewPassword} kind=${ARRIVAL} onDone=${() => navigate("account")} />`;
|
| 147 |
+
case "link-problem":
|
| 148 |
+
return html`<${LinkProblem} onDone=${() => navigate("account")} />`;
|
| 149 |
+
case "developer":
|
| 150 |
+
return html`<${Developer} />`;
|
| 151 |
+
default:
|
| 152 |
+
return html`<${Dashboard} onNavigate=${navigate} />`;
|
| 153 |
+
}
|
| 154 |
+
})();
|
| 155 |
+
|
| 156 |
+
return html`<div class="app">
|
| 157 |
+
<${Sidebar} current=${section} onNavigate=${navigate} />
|
| 158 |
+
<div class="main">
|
| 159 |
+
${showSetup && html`<${SetupBanner} onConnect=${() => navigate("connect")} onDismiss=${dismissSetup} />`}
|
| 160 |
+
<${TopBar} section=${section} onMenu=${() => setDrawer(true)} onNavigate=${navigate} />
|
| 161 |
+
${screen}
|
| 162 |
+
</div>
|
| 163 |
+
${drawer && html`<${Drawer} current=${section} onNavigate=${navigate} onClose=${() => setDrawer(false)} />`}
|
| 164 |
+
${editing && html`<${EditBar} onDone=${() => setEditing(false)} onSettings=${() => navigate("developer")} />`}
|
| 165 |
+
</div>`;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
function Root() {
|
| 169 |
+
return html`<${CloudProvider}>
|
| 170 |
+
<${AppProvider}>
|
| 171 |
+
<${EngineProvider}>
|
| 172 |
+
<${EditModeProvider}>
|
| 173 |
+
<${Shell} />
|
| 174 |
+
<//>
|
| 175 |
+
<//>
|
| 176 |
+
<//>
|
| 177 |
+
<//>`;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
const root = ReactDOM.createRoot(document.getElementById("root"));
|
| 181 |
+
root.render(html`<${Root} />`);
|
js/auth.js
ADDED
|
@@ -0,0 +1,575 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { html, useState } from "./runtime.js";
|
| 2 |
+
import { useCloud, money, planPeriod, DEVELOPER_EMAIL } from "./cloud.js";
|
| 3 |
+
import { Notice, Pill, Icon } from "./components.js";
|
| 4 |
+
|
| 5 |
+
function Shell({ children }) {
|
| 6 |
+
return html`<main class="page narrow">${children}</main>`;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
// ---------------------------------------------------------------------------
|
| 10 |
+
// Sign in / create account
|
| 11 |
+
// ---------------------------------------------------------------------------
|
| 12 |
+
|
| 13 |
+
export function SignIn({ onDone }) {
|
| 14 |
+
const cloud = useCloud();
|
| 15 |
+
const [mode, setMode] = useState("signin");
|
| 16 |
+
const [email, setEmail] = useState("");
|
| 17 |
+
const [password, setPassword] = useState("");
|
| 18 |
+
const [busy, setBusy] = useState(false);
|
| 19 |
+
const [message, setMessage] = useState("");
|
| 20 |
+
const [error, setError] = useState("");
|
| 21 |
+
const [showCode, setShowCode] = useState(false);
|
| 22 |
+
const [code, setCode] = useState("");
|
| 23 |
+
|
| 24 |
+
if (!cloud.configured) {
|
| 25 |
+
return html`<${Shell}>
|
| 26 |
+
<div class="eyebrow">Account</div>
|
| 27 |
+
<h1 class="page-title">Explication has no accounts yet.</h1>
|
| 28 |
+
<p class="subtitle">Logins run on Supabase. Connect a Supabase project and this page becomes a normal sign-in screen.</p>
|
| 29 |
+
<div class="card" style=${{ marginTop: "16px" }}>
|
| 30 |
+
<${Notice} kind="warn">No Supabase project is connected to this copy of the site.<//>
|
| 31 |
+
<div class="row" style=${{ marginTop: "12px" }}>
|
| 32 |
+
<a class="btn primary small" href="#/connect">Connect Supabase</a>
|
| 33 |
+
<span class="tiny faint">${DEVELOPER_EMAIL} can do this.</span>
|
| 34 |
+
</div>
|
| 35 |
+
</div>
|
| 36 |
+
<//>`;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
if (cloud.user) {
|
| 40 |
+
return html`<${Account} onDone=${onDone} />`;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
const submit = async (event) => {
|
| 44 |
+
event.preventDefault();
|
| 45 |
+
setError("");
|
| 46 |
+
setMessage("");
|
| 47 |
+
setBusy(true);
|
| 48 |
+
try {
|
| 49 |
+
if (mode === "signin") await cloud.signIn(email.trim(), password);
|
| 50 |
+
else {
|
| 51 |
+
const result = await cloud.signUp(email.trim(), password);
|
| 52 |
+
if (result && result.session) setMessage("Account created. You are signed in.");
|
| 53 |
+
else setMessage("Account created. Check your email — the link signs you straight in, or paste the six-digit code below.");
|
| 54 |
+
}
|
| 55 |
+
} catch (err) {
|
| 56 |
+
setError(err && err.message ? err.message : "That did not work.");
|
| 57 |
+
}
|
| 58 |
+
setBusy(false);
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
const sendLink = async () => {
|
| 62 |
+
setError("");
|
| 63 |
+
setMessage("");
|
| 64 |
+
if (!email.trim()) {
|
| 65 |
+
setError("Type your email first.");
|
| 66 |
+
return;
|
| 67 |
+
}
|
| 68 |
+
setBusy(true);
|
| 69 |
+
try {
|
| 70 |
+
await cloud.magicLink(email.trim());
|
| 71 |
+
setMessage("A sign-in link is on its way to " + email.trim() + ".");
|
| 72 |
+
} catch (err) {
|
| 73 |
+
setError(err && err.message ? err.message : "The link could not be sent.");
|
| 74 |
+
}
|
| 75 |
+
setBusy(false);
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
const forgot = async () => {
|
| 79 |
+
setError("");
|
| 80 |
+
setMessage("");
|
| 81 |
+
if (!email.trim()) {
|
| 82 |
+
setError("Type your email first, then press Forgot password.");
|
| 83 |
+
return;
|
| 84 |
+
}
|
| 85 |
+
setBusy(true);
|
| 86 |
+
try {
|
| 87 |
+
await cloud.resetPassword(email.trim());
|
| 88 |
+
setMessage("If " + email.trim() + " has an account, a reset link is on its way. It signs you in so you can choose a new password.");
|
| 89 |
+
} catch (err) {
|
| 90 |
+
setError(err && err.message ? err.message : "The reset email could not be sent.");
|
| 91 |
+
}
|
| 92 |
+
setBusy(false);
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
const submitCode = async (event) => {
|
| 96 |
+
event.preventDefault();
|
| 97 |
+
setError("");
|
| 98 |
+
setMessage("");
|
| 99 |
+
if (!email.trim()) {
|
| 100 |
+
setError("Type your email first, then the code.");
|
| 101 |
+
return;
|
| 102 |
+
}
|
| 103 |
+
if (!/^\d{6}$/.test(code.trim())) {
|
| 104 |
+
setError("The code is six digits.");
|
| 105 |
+
return;
|
| 106 |
+
}
|
| 107 |
+
setBusy(true);
|
| 108 |
+
try {
|
| 109 |
+
await cloud.verifyCode(email.trim(), code.trim());
|
| 110 |
+
setMessage("Code accepted. You're signed in.");
|
| 111 |
+
} catch (err) {
|
| 112 |
+
setError(err && err.message ? err.message : "That code did not work.");
|
| 113 |
+
}
|
| 114 |
+
setBusy(false);
|
| 115 |
+
};
|
| 116 |
+
|
| 117 |
+
return html`<${Shell}>
|
| 118 |
+
<div class="eyebrow">Account</div>
|
| 119 |
+
<h1 class="page-title">${mode === "signin" ? "Welcome back." : "Make an account."}</h1>
|
| 120 |
+
<p class="subtitle">
|
| 121 |
+
An account keeps your plan, your model budget and any downloads you own. Your writing still stays in this browser.
|
| 122 |
+
</p>
|
| 123 |
+
|
| 124 |
+
<div class="card" style=${{ marginTop: "18px", maxWidth: "440px" }}>
|
| 125 |
+
<div class="row" style=${{ marginBottom: "12px" }}>
|
| 126 |
+
<button class=${"btn small " + (mode === "signin" ? "primary" : "ghost")} onClick=${() => setMode("signin")}>Sign in</button>
|
| 127 |
+
<button class=${"btn small " + (mode === "signup" ? "primary" : "ghost")} onClick=${() => setMode("signup")}>Create account</button>
|
| 128 |
+
</div>
|
| 129 |
+
<form onSubmit=${submit} class="stack">
|
| 130 |
+
<div class="field">
|
| 131 |
+
<label>Email</label>
|
| 132 |
+
<input class="input" type="email" value=${email} onInput=${(e) => setEmail(e.target.value)} autocomplete="email" placeholder="you@example.com" required />
|
| 133 |
+
</div>
|
| 134 |
+
<div class="field">
|
| 135 |
+
<label>Password</label>
|
| 136 |
+
<input class="input" type="password" value=${password} onInput=${(e) => setPassword(e.target.value)} autocomplete=${mode === "signin" ? "current-password" : "new-password"} placeholder="At least 6 characters" required />
|
| 137 |
+
</div>
|
| 138 |
+
${mode === "signin" && html`<div class="row" style=${{ justifyContent: "flex-end", marginTop: "-4px" }}>
|
| 139 |
+
<button class="btn link small" type="button" onClick=${forgot} disabled=${busy}>Forgot password?</button>
|
| 140 |
+
</div>`}
|
| 141 |
+
${error && html`<${Notice} kind="error">${error}<//>`}
|
| 142 |
+
${message && html`<${Notice} kind="info">${message}<//>`}
|
| 143 |
+
<button class="btn primary" type="submit" disabled=${busy}>
|
| 144 |
+
${busy ? html`<span class="spin"></span>` : html`<${Icon} name="lock" size=${13} />`} ${mode === "signin" ? "Sign in" : "Create account"}
|
| 145 |
+
</button>
|
| 146 |
+
</form>
|
| 147 |
+
<div class="divider"></div>
|
| 148 |
+
<div class="row between wrap">
|
| 149 |
+
<span class="tiny faint">No password? Send a one-time link instead.</span>
|
| 150 |
+
<button class="btn small" onClick=${sendLink} disabled=${busy}>Email me a link</button>
|
| 151 |
+
</div>
|
| 152 |
+
<div class="divider"></div>
|
| 153 |
+
<div class="row between wrap">
|
| 154 |
+
<span class="tiny faint">Got a six-digit code in the email?</span>
|
| 155 |
+
<button class="btn small" onClick=${() => setShowCode(!showCode)}>${showCode ? "Hide" : "Use a code"}</button>
|
| 156 |
+
</div>
|
| 157 |
+
${showCode && html`<form onSubmit=${submitCode} class="stack" style=${{ marginTop: "10px" }}>
|
| 158 |
+
<div class="field">
|
| 159 |
+
<label>Six-digit code</label>
|
| 160 |
+
<input class="input" type="text" inputmode="numeric" maxlength="6" value=${code} onInput=${(e) => setCode(e.target.value.replace(/[^0-9]/g, ""))} placeholder="123456" autocomplete="one-time-code" />
|
| 161 |
+
</div>
|
| 162 |
+
<button class="btn primary" type="submit" disabled=${busy}>Verify code</button>
|
| 163 |
+
</form>`}
|
| 164 |
+
</div>
|
| 165 |
+
|
| 166 |
+
<p class="tiny faint" style=${{ marginTop: "12px" }}>
|
| 167 |
+
Plans and purchases are attached to this account. You can use every marking tool without one.
|
| 168 |
+
</p>
|
| 169 |
+
<//>`;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
// ---------------------------------------------------------------------------
|
| 173 |
+
// Account / plan
|
| 174 |
+
// ---------------------------------------------------------------------------
|
| 175 |
+
|
| 176 |
+
function BudgetBar({ budget, plan }) {
|
| 177 |
+
if (!plan) return null;
|
| 178 |
+
if (!plan.cost_limit_cents) {
|
| 179 |
+
return html` <div class="tiny faint" style=${{ marginTop: "6px" }}>
|
| 180 |
+
This pack is all offline: download the models and they are yours, with no allowance to run down.
|
| 181 |
+
</div>`;
|
| 182 |
+
}
|
| 183 |
+
const pct = budget.limit ? Math.min(100, Math.round((budget.spent / budget.limit) * 100)) : 0;
|
| 184 |
+
return html`<div style=${{ marginTop: "8px" }}>
|
| 185 |
+
<div class="row between tiny">
|
| 186 |
+
<span class="muted">Included AI this period</span>
|
| 187 |
+
<span class="faint">${100 - pct}% left</span>
|
| 188 |
+
</div>
|
| 189 |
+
<div class="bar" style=${{ marginTop: "5px" }}><i style=${{ width: pct + "%" }}></i></div>
|
| 190 |
+
<div class="tiny faint" style=${{ marginTop: "4px" }}>Your included AI tops up with your plan. Offline models and your own key never touch it.</div>
|
| 191 |
+
</div>`;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
export function Account({ onDone }) {
|
| 195 |
+
const cloud = useCloud();
|
| 196 |
+
const [busy, setBusy] = useState(false);
|
| 197 |
+
|
| 198 |
+
if (!cloud.user) {
|
| 199 |
+
return html`<${SignIn} />`;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
const plan = cloud.plan;
|
| 203 |
+
const signedOut = async () => {
|
| 204 |
+
setBusy(true);
|
| 205 |
+
await cloud.signOut();
|
| 206 |
+
setBusy(false);
|
| 207 |
+
if (onDone) onDone();
|
| 208 |
+
};
|
| 209 |
+
|
| 210 |
+
return html`<${Shell}>
|
| 211 |
+
<div class="row between" style=${{ alignItems: "flex-start" }}>
|
| 212 |
+
<div>
|
| 213 |
+
<div class="eyebrow">Account</div>
|
| 214 |
+
<h1 class="page-title">${cloud.user.email}</h1>
|
| 215 |
+
<p class="subtitle">${cloud.isDev ? "This address is the developer account for this site." : "Your plan, budget and downloads live here."}</p>
|
| 216 |
+
</div>
|
| 217 |
+
<button class="btn small" onClick=${signedOut} disabled=${busy}>Sign out</button>
|
| 218 |
+
</div>
|
| 219 |
+
|
| 220 |
+
<div class="section-head"><h2 class="section-title">Your plan</h2>
|
| 221 |
+
<a class="btn link small" href="#/pricing">${plan ? "Change plan" : "See plans"}</a>
|
| 222 |
+
</div>
|
| 223 |
+
<div class="card">
|
| 224 |
+
${plan
|
| 225 |
+
? html`<div class="row between wrap">
|
| 226 |
+
<div>
|
| 227 |
+
<div class="row"><span style=${{ fontWeight: 600, fontSize: "15px" }}>${plan.name}</span>
|
| 228 |
+
<${Pill} tone=${plan.kind === "subscription" ? "green" : "neutral"}>${plan.kind === "one_time" ? "One-off" : "Subscription"}<//>
|
| 229 |
+
</div>
|
| 230 |
+
<div class="tiny faint" style=${{ marginTop: "2px" }}>${money(plan.price_cents, plan.currency)} ${planPeriod(plan)}</div>
|
| 231 |
+
</div>
|
| 232 |
+
<span class="tiny faint">${cloud.entitlement && cloud.entitlement.expires_at ? "Renews " + new Date(cloud.entitlement.expires_at).toLocaleDateString("en-GB") : "Active"}</span>
|
| 233 |
+
</div>
|
| 234 |
+
<${BudgetBar} budget=${cloud.budget} plan=${plan} />`
|
| 235 |
+
: html`<div class="row between wrap">
|
| 236 |
+
<div>
|
| 237 |
+
<div style=${{ fontWeight: 600 }}>No plan yet</div>
|
| 238 |
+
<div class="tiny faint" style=${{ marginTop: "2px" }}>Rule-based marking, chat setup and BYOK work without one.</div>
|
| 239 |
+
</div>
|
| 240 |
+
<a class="btn primary small" href="#/pricing">Choose a plan</a>
|
| 241 |
+
</div>`}
|
| 242 |
+
</div>
|
| 243 |
+
|
| 244 |
+
<div class="section-head"><h2 class="section-title">Bring your own key</h2></div>
|
| 245 |
+
<div class="card">
|
| 246 |
+
<div class="row between wrap">
|
| 247 |
+
<div style=${{ maxWidth: "520px" }}>
|
| 248 |
+
<div style=${{ fontWeight: 600 }}>Your provider, your bill</div>
|
| 249 |
+
<div class="tiny faint" style=${{ marginTop: "3px", lineHeight: 1.55 }}>
|
| 250 |
+
Add an OpenAI-compatible endpoint in Settings and every hosted feature runs on your own key. It never touches your included allowance, so you can keep going as long as you like.
|
| 251 |
+
</div>
|
| 252 |
+
</div>
|
| 253 |
+
<a class="btn small" href="#/settings">Open Settings</a>
|
| 254 |
+
</div>
|
| 255 |
+
</div>
|
| 256 |
+
|
| 257 |
+
${cloud.isDev &&
|
| 258 |
+
html`<div class="section-head"><h2 class="section-title">Developer</h2></div>
|
| 259 |
+
<div class="card">
|
| 260 |
+
<div class="row between wrap">
|
| 261 |
+
<div style=${{ maxWidth: "520px" }}>
|
| 262 |
+
<div style=${{ fontWeight: 600 }}>Developer console</div>
|
| 263 |
+
<div class="tiny faint" style=${{ marginTop: "3px", lineHeight: 1.55 }}>Plans and prices, Stripe, models and keys, page wording, and who has access.</div>
|
| 264 |
+
</div>
|
| 265 |
+
<a class="btn primary small" href="#/developer">Open developer console</a>
|
| 266 |
+
</div>
|
| 267 |
+
</div>`}
|
| 268 |
+
<//>`;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
// ---------------------------------------------------------------------------
|
| 272 |
+
// Landing screens for email links
|
| 273 |
+
// ---------------------------------------------------------------------------
|
| 274 |
+
|
| 275 |
+
const WELCOME_COPY = {
|
| 276 |
+
signup: {
|
| 277 |
+
eyebrow: "Account confirmed",
|
| 278 |
+
title: "You're in.",
|
| 279 |
+
body: "Your email is confirmed and you're signed in. Your plan, budget and downloads stay with this account."
|
| 280 |
+
},
|
| 281 |
+
magiclink: {
|
| 282 |
+
eyebrow: "Signed in",
|
| 283 |
+
title: "You're signed in.",
|
| 284 |
+
body: "The link worked — no password needed."
|
| 285 |
+
},
|
| 286 |
+
email_change: {
|
| 287 |
+
eyebrow: "Address updated",
|
| 288 |
+
title: "That's your new address.",
|
| 289 |
+
body: "Your sign-in address has changed, and you're already signed in with it."
|
| 290 |
+
},
|
| 291 |
+
session: {
|
| 292 |
+
eyebrow: "Signed in",
|
| 293 |
+
title: "You're in.",
|
| 294 |
+
body: "The link worked and you're signed in."
|
| 295 |
+
}
|
| 296 |
+
};
|
| 297 |
+
|
| 298 |
+
function CentredCard({ children }) {
|
| 299 |
+
return html`<div class="card" style=${{ maxWidth: "460px", margin: "7vh auto 0", textAlign: "center", padding: "28px 26px" }}>${children}</div>`;
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
function Tick({ tone = "good" }) {
|
| 303 |
+
const good = tone === "good";
|
| 304 |
+
return html`<div style=${{
|
| 305 |
+
width: "56px", height: "56px", borderRadius: "50%",
|
| 306 |
+
background: good ? "var(--accent-soft)" : "var(--warning-soft)",
|
| 307 |
+
color: good ? "var(--accent-deep)" : "#7d4a1f",
|
| 308 |
+
display: "grid", placeItems: "center", margin: "0 auto 14px"
|
| 309 |
+
}}><${Icon} name=${good ? "check" : "x"} size=${26} stroke=${2.2} /></div>`;
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
function Waiting() {
|
| 313 |
+
return html`<${CentredCard}>
|
| 314 |
+
<span class="spin" style=${{ margin: "0 auto 14px" }}></span>
|
| 315 |
+
<div style=${{ fontWeight: 600, fontSize: "15px" }}>Signing you in…</div>
|
| 316 |
+
<p class="tiny faint" style=${{ marginTop: "4px" }}>Reading the link and setting up your session.</p>
|
| 317 |
+
<//>`;
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
// Where a confirmed sign-up, magic link or email change lands.
|
| 321 |
+
export function Welcome({ kind, onDone }) {
|
| 322 |
+
const cloud = useCloud();
|
| 323 |
+
const copy = WELCOME_COPY[kind] || WELCOME_COPY.magiclink;
|
| 324 |
+
|
| 325 |
+
if (!cloud.ready) {
|
| 326 |
+
return html`<${Shell}><${Waiting} /><//>`;
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
if (!cloud.configured) {
|
| 330 |
+
return html`<${Shell}>
|
| 331 |
+
<${CentredCard}>
|
| 332 |
+
<${Tick} tone="bad" />
|
| 333 |
+
<h1 class="page-title" style=${{ fontSize: "26px" }}>No accounts yet.</h1>
|
| 334 |
+
<p class="subtitle">This copy of the site has no Supabase project, so there is no account to confirm.</p>
|
| 335 |
+
<div class="row" style=${{ justifyContent: "center", marginTop: "16px" }}>
|
| 336 |
+
<a class="btn primary" href="#/connect">Connect Supabase</a>
|
| 337 |
+
</div>
|
| 338 |
+
<//>
|
| 339 |
+
<//>`;
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
if (!cloud.user) {
|
| 343 |
+
return html`<${Shell}>
|
| 344 |
+
<${CentredCard}>
|
| 345 |
+
<${Tick} tone="bad" />
|
| 346 |
+
<h1 class="page-title" style=${{ fontSize: "26px" }}>That link didn't sign you in.</h1>
|
| 347 |
+
<p class="subtitle">Email links work once and expire after an hour. Sign in with your password, or send yourself a fresh one from the sign-in page.</p>
|
| 348 |
+
<div class="row" style=${{ justifyContent: "center", marginTop: "16px" }}>
|
| 349 |
+
<button class="btn primary" onClick=${onDone}>Go to sign in</button>
|
| 350 |
+
</div>
|
| 351 |
+
<//>
|
| 352 |
+
<//>`;
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
return html`<${Shell}>
|
| 356 |
+
<${CentredCard}>
|
| 357 |
+
<${Tick} />
|
| 358 |
+
<div class="eyebrow">${copy.eyebrow}</div>
|
| 359 |
+
<h1 class="page-title" style=${{ fontSize: "30px", marginTop: "4px" }}>${copy.title}</h1>
|
| 360 |
+
<p class="subtitle">${copy.body}</p>
|
| 361 |
+
<p class="tiny faint" style=${{ marginTop: "8px" }}>Signed in as ${cloud.user.email}</p>
|
| 362 |
+
<div class="row" style=${{ justifyContent: "center", marginTop: "16px" }}>
|
| 363 |
+
<button class="btn primary" onClick=${onDone}>Start marking</button>
|
| 364 |
+
</div>
|
| 365 |
+
<p class="tiny faint" style=${{ marginTop: "14px" }}><a href="#/pricing">See the plans</a></p>
|
| 366 |
+
<//>
|
| 367 |
+
<//>`;
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
// Where a password-reset or invite link lands. The link has already signed the
|
| 371 |
+
// person in; this screen is the missing step that sets the password.
|
| 372 |
+
export function NewPassword({ kind, onDone }) {
|
| 373 |
+
const cloud = useCloud();
|
| 374 |
+
const [password, setPassword] = useState("");
|
| 375 |
+
const [again, setAgain] = useState("");
|
| 376 |
+
const [busy, setBusy] = useState(false);
|
| 377 |
+
const [done, setDone] = useState(false);
|
| 378 |
+
const [error, setError] = useState("");
|
| 379 |
+
|
| 380 |
+
const submit = async (event) => {
|
| 381 |
+
event.preventDefault();
|
| 382 |
+
setError("");
|
| 383 |
+
if (password.length < 6) {
|
| 384 |
+
setError("Use at least six characters.");
|
| 385 |
+
return;
|
| 386 |
+
}
|
| 387 |
+
if (password !== again) {
|
| 388 |
+
setError("The two passwords don't match.");
|
| 389 |
+
return;
|
| 390 |
+
}
|
| 391 |
+
setBusy(true);
|
| 392 |
+
try {
|
| 393 |
+
await cloud.updatePassword(password);
|
| 394 |
+
setDone(true);
|
| 395 |
+
} catch (err) {
|
| 396 |
+
setError(err && err.message ? err.message : "The password could not be changed.");
|
| 397 |
+
}
|
| 398 |
+
setBusy(false);
|
| 399 |
+
};
|
| 400 |
+
|
| 401 |
+
if (!cloud.ready) {
|
| 402 |
+
return html`<${Shell}><${Waiting} /><//>`;
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
if (!cloud.configured) {
|
| 406 |
+
return html`<${Shell}>
|
| 407 |
+
<${CentredCard}>
|
| 408 |
+
<${Tick} tone="bad" />
|
| 409 |
+
<h1 class="page-title" style=${{ fontSize: "26px" }}>No accounts yet.</h1>
|
| 410 |
+
<p class="subtitle">This copy of the site has no Supabase project, so there is no password to change.</p>
|
| 411 |
+
<div class="row" style=${{ justifyContent: "center", marginTop: "16px" }}>
|
| 412 |
+
<a class="btn primary" href="#/connect">Connect Supabase</a>
|
| 413 |
+
</div>
|
| 414 |
+
<//>
|
| 415 |
+
<//>`;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
if (!cloud.user) {
|
| 419 |
+
return html`<${Shell}>
|
| 420 |
+
<${CentredCard}>
|
| 421 |
+
<${Tick} tone="bad" />
|
| 422 |
+
<h1 class="page-title" style=${{ fontSize: "26px" }}>This link has expired.</h1>
|
| 423 |
+
<p class="subtitle">Password links work once and last an hour. Ask for a new one from the sign-in page.</p>
|
| 424 |
+
<div class="row" style=${{ justifyContent: "center", marginTop: "16px" }}>
|
| 425 |
+
<button class="btn primary" onClick=${onDone}>Back to sign in</button>
|
| 426 |
+
</div>
|
| 427 |
+
<//>
|
| 428 |
+
<//>`;
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
if (done) {
|
| 432 |
+
return html`<${Shell}>
|
| 433 |
+
<${CentredCard}>
|
| 434 |
+
<${Tick} />
|
| 435 |
+
<div class="eyebrow">Password changed</div>
|
| 436 |
+
<h1 class="page-title" style=${{ fontSize: "28px", marginTop: "4px" }}>You're all set.</h1>
|
| 437 |
+
<p class="subtitle">Use your new password the next time you sign in.</p>
|
| 438 |
+
<div class="row" style=${{ justifyContent: "center", marginTop: "16px" }}>
|
| 439 |
+
<button class="btn primary" onClick=${onDone}>Go to my account</button>
|
| 440 |
+
</div>
|
| 441 |
+
<//>
|
| 442 |
+
<//>`;
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
return html`<${Shell}>
|
| 446 |
+
<${CentredCard}>
|
| 447 |
+
<div class="eyebrow">${kind === "invite" ? "Welcome" : "Password reset"}</div>
|
| 448 |
+
<h1 class="page-title" style=${{ fontSize: "28px", marginTop: "4px" }}>${kind === "invite" ? "Choose a password." : "Choose a new password."}</h1>
|
| 449 |
+
<p class="subtitle">${kind === "invite" ? "Set a password for " + cloud.user.email + " and you're in." : "You're signed in as " + cloud.user.email + ". Pick something you'll remember."}</p>
|
| 450 |
+
<form onSubmit=${submit} class="stack" style=${{ marginTop: "16px", textAlign: "left" }}>
|
| 451 |
+
<div class="field">
|
| 452 |
+
<label>New password</label>
|
| 453 |
+
<input class="input" type="password" value=${password} onInput=${(e) => setPassword(e.target.value)} autocomplete="new-password" placeholder="At least 6 characters" required />
|
| 454 |
+
</div>
|
| 455 |
+
<div class="field">
|
| 456 |
+
<label>One more time</label>
|
| 457 |
+
<input class="input" type="password" value=${again} onInput=${(e) => setAgain(e.target.value)} autocomplete="new-password" placeholder="Same password" required />
|
| 458 |
+
</div>
|
| 459 |
+
${error && html`<${Notice} kind="error">${error}<//>`}
|
| 460 |
+
<button class="btn primary" type="submit" disabled=${busy}>
|
| 461 |
+
${busy ? html`<span class="spin"></span>` : html`<${Icon} name="lock" size=${13} />`} Save password
|
| 462 |
+
</button>
|
| 463 |
+
</form>
|
| 464 |
+
<//>
|
| 465 |
+
<//>`;
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
// When Supabase itself reports the link is bad or used.
|
| 469 |
+
export function LinkProblem({ onDone }) {
|
| 470 |
+
return html`<${Shell}>
|
| 471 |
+
<${CentredCard}>
|
| 472 |
+
<${Tick} tone="bad" />
|
| 473 |
+
<h1 class="page-title" style=${{ fontSize: "26px" }}>That link has expired.</h1>
|
| 474 |
+
<p class="subtitle">Email links work once and last an hour. Ask for a fresh one from the sign-in page — it takes a moment.</p>
|
| 475 |
+
<div class="row" style=${{ justifyContent: "center", marginTop: "16px" }}>
|
| 476 |
+
<button class="btn primary" onClick=${onDone}>Back to sign in</button>
|
| 477 |
+
</div>
|
| 478 |
+
<//>
|
| 479 |
+
<//>`;
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
// ---------------------------------------------------------------------------
|
| 483 |
+
// Connect Supabase
|
| 484 |
+
// ---------------------------------------------------------------------------
|
| 485 |
+
|
| 486 |
+
export function Connect() {
|
| 487 |
+
const cloud = useCloud();
|
| 488 |
+
const [url, setUrl] = useState(cloud.configured ? cloud.config.url : "");
|
| 489 |
+
const [anonKey, setAnonKey] = useState(cloud.configured ? cloud.config.anonKey : "");
|
| 490 |
+
const [error, setError] = useState("");
|
| 491 |
+
const [done, setDone] = useState(false);
|
| 492 |
+
const [copied, setCopied] = useState(false);
|
| 493 |
+
|
| 494 |
+
const connect = async (event) => {
|
| 495 |
+
event.preventDefault();
|
| 496 |
+
setError("");
|
| 497 |
+
const clean = url.trim().replace(/\/+$/, "");
|
| 498 |
+
if (!/^https?:\/\/.+/.test(clean)) {
|
| 499 |
+
setError("The project URL looks like https://yourproject.supabase.co");
|
| 500 |
+
return;
|
| 501 |
+
}
|
| 502 |
+
if (anonKey.trim().length < 20) {
|
| 503 |
+
setError("Paste the anon public key from Supabase → Project Settings → API.");
|
| 504 |
+
return;
|
| 505 |
+
}
|
| 506 |
+
cloud.connect({ url: clean, anonKey: anonKey.trim() });
|
| 507 |
+
setDone(true);
|
| 508 |
+
};
|
| 509 |
+
|
| 510 |
+
const copySchema = async () => {
|
| 511 |
+
try {
|
| 512 |
+
const res = await fetch("supabase/schema.sql");
|
| 513 |
+
const text = await res.text();
|
| 514 |
+
await navigator.clipboard.writeText(text);
|
| 515 |
+
setCopied(true);
|
| 516 |
+
setTimeout(() => setCopied(false), 2400);
|
| 517 |
+
} catch {
|
| 518 |
+
setError("Could not copy the schema. Open supabase/schema.sql in the folder instead.");
|
| 519 |
+
}
|
| 520 |
+
};
|
| 521 |
+
|
| 522 |
+
if (done || (cloud.configured && !error)) {
|
| 523 |
+
return html`<${Shell}>
|
| 524 |
+
<div class="eyebrow">Connected</div>
|
| 525 |
+
<h1 class="page-title">Supabase is connected.</h1>
|
| 526 |
+
<p class="subtitle">
|
| 527 |
+
This browser now reads accounts, plans, models and page wording from ${cloud.config.url}.
|
| 528 |
+
</p>
|
| 529 |
+
<div class="card" style=${{ marginTop: "16px" }}>
|
| 530 |
+
<div class="row" style=${{ marginBottom: "8px" }}><${Pill} tone="green">Connected</${Pill}><span class="tiny faint mono">${cloud.config.url}</span></div>
|
| 531 |
+
<${Notice} kind="info">
|
| 532 |
+
Two things left in the Supabase dashboard: run the SQL in <span class="mono">supabase/schema.sql</span> in the SQL editor, then paste the same URL and key into <span class="mono">js/config.js</span> so every visitor gets them automatically.
|
| 533 |
+
<//>
|
| 534 |
+
<div class="row wrap" style=${{ marginTop: "10px" }}>
|
| 535 |
+
<button class="btn small" onClick=${copySchema}>${copied ? "Copied" : "Copy schema SQL"}</button>
|
| 536 |
+
<a class="btn small primary" href="SETUP.html" target="_blank" rel="noreferrer">Open the picture guide</a>
|
| 537 |
+
<a class="btn small" href="#/pricing">See the plans page</a>
|
| 538 |
+
<a class="btn small" href="#/developer">Developer console</a>
|
| 539 |
+
</div>
|
| 540 |
+
</div>
|
| 541 |
+
<p class="tiny faint" style=${{ marginTop: "12px" }}>
|
| 542 |
+
This setup screen disappears from the site once a project is connected. It stays available in Developer → Supabase.
|
| 543 |
+
</p>
|
| 544 |
+
<//>`;
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
return html`<${Shell}>
|
| 548 |
+
<div class="eyebrow">Setup</div>
|
| 549 |
+
<h1 class="page-title">Connect Supabase.</h1>
|
| 550 |
+
<p class="subtitle">
|
| 551 |
+
Supabase holds the accounts, the plans, the shared page wording and the model budgets. Create a free project, then paste two values from Project Settings → API.
|
| 552 |
+
</p>
|
| 553 |
+
<div class="card" style=${{ marginTop: "16px", maxWidth: "560px" }}>
|
| 554 |
+
<form class="stack" onSubmit=${connect}>
|
| 555 |
+
<div class="field">
|
| 556 |
+
<label>Project URL</label>
|
| 557 |
+
<input class="input" value=${url} onInput=${(e) => setUrl(e.target.value)} placeholder="https://abcdefgh.supabase.co" />
|
| 558 |
+
</div>
|
| 559 |
+
<div class="field">
|
| 560 |
+
<label>Anon public key</label>
|
| 561 |
+
<textarea class="textarea plain" style=${{ minHeight: "84px" }} value=${anonKey} onInput=${(e) => setAnonKey(e.target.value)} placeholder="eyJhbGciOi…"></textarea>
|
| 562 |
+
</div>
|
| 563 |
+
${error && html`<${Notice} kind="error">${error}<//>`}
|
| 564 |
+
<button class="btn primary" type="submit">Connect this site</button>
|
| 565 |
+
</form>
|
| 566 |
+
<div class="divider"></div>
|
| 567 |
+
<div class="tiny faint" style=${{ lineHeight: 1.6 }}>
|
| 568 |
+
Only the anon public key goes in the browser. It is safe to publish: row-level security in the schema stops anyone but ${DEVELOPER_EMAIL} from changing plans, models or wording. Never paste the service_role key here.
|
| 569 |
+
</div>
|
| 570 |
+
</div>
|
| 571 |
+
<p class="tiny faint" style=${{ marginTop: "12px" }}>
|
| 572 |
+
Full instructions: <a href="SETUP.html" target="_blank" rel="noreferrer">the picture guide</a>.
|
| 573 |
+
</p>
|
| 574 |
+
<//>`;
|
| 575 |
+
}
|
js/cloud.js
ADDED
|
@@ -0,0 +1,930 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { createContext, html, useCallback, useContext, useEffect, useMemo, useRef, useState } from "./runtime.js";
|
| 2 |
+
|
| 3 |
+
// ---------------------------------------------------------------------------
|
| 4 |
+
// Account, shared content, plans, models and money.
|
| 5 |
+
//
|
| 6 |
+
// Everything shared between visitors lives in Supabase. If no project is
|
| 7 |
+
// connected yet the app runs in "preview" mode: the developer screens still
|
| 8 |
+
// work, but changes stay in this browser. That lets you set the site up,
|
| 9 |
+
// try it, then connect Supabase and publish the same edits to everyone.
|
| 10 |
+
// ---------------------------------------------------------------------------
|
| 11 |
+
|
| 12 |
+
export const DEVELOPER_EMAIL = "lucas.owen13@icloud.com";
|
| 13 |
+
|
| 14 |
+
const CONFIG_KEY = "explication.cloud.config.v1";
|
| 15 |
+
const PREVIEW_KEY = "explication.cloud.preview.v1";
|
| 16 |
+
const SDK_URL = "https://esm.sh/@supabase/supabase-js@2.45.4";
|
| 17 |
+
|
| 18 |
+
const T = {
|
| 19 |
+
settings: "explication_settings",
|
| 20 |
+
plans: "explication_plans",
|
| 21 |
+
models: "explication_models",
|
| 22 |
+
secrets: "explication_model_secrets",
|
| 23 |
+
content: "explication_content",
|
| 24 |
+
entitlements: "explication_entitlements",
|
| 25 |
+
usage: "explication_usage"
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
// ---------------------------------------------------------------------------
|
| 29 |
+
// Config
|
| 30 |
+
// ---------------------------------------------------------------------------
|
| 31 |
+
|
| 32 |
+
export function readConfig() {
|
| 33 |
+
let saved = {};
|
| 34 |
+
try {
|
| 35 |
+
saved = JSON.parse(localStorage.getItem(CONFIG_KEY) || "null") || {};
|
| 36 |
+
} catch {
|
| 37 |
+
saved = {};
|
| 38 |
+
}
|
| 39 |
+
const fromFile = (typeof window !== "undefined" && window.EXPLICATION_CONFIG) || {};
|
| 40 |
+
const url = String(saved.url || fromFile.supabaseUrl || "").trim().replace(/\/+$/, "");
|
| 41 |
+
const anonKey = String(saved.anonKey || fromFile.supabaseAnonKey || "").trim();
|
| 42 |
+
return { url, anonKey, developerEmail: DEVELOPER_EMAIL, ready: !!url && !!anonKey };
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
export function saveConfig({ url, anonKey }) {
|
| 46 |
+
const clean = { url: String(url || "").trim().replace(/\/+$/, ""), anonKey: String(anonKey || "").trim() };
|
| 47 |
+
localStorage.setItem(CONFIG_KEY, JSON.stringify(clean));
|
| 48 |
+
return clean;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
export function forgetConfig() {
|
| 52 |
+
localStorage.removeItem(CONFIG_KEY);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
// Where Supabase sends people back to after an email link. It must not include
|
| 56 |
+
// the app's #/route: Supabase appends the session to this address itself, and
|
| 57 |
+
// a second # would bury the tokens inside the route.
|
| 58 |
+
function appRedirect() {
|
| 59 |
+
if (typeof window === "undefined") return undefined;
|
| 60 |
+
return window.location.origin + window.location.pathname.replace(/\/+$/, "");
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
let sdkPromise = null;
|
| 64 |
+
let sdkKey = "";
|
| 65 |
+
async function loadSdk(config) {
|
| 66 |
+
const key = config.url + "|" + config.anonKey;
|
| 67 |
+
if (sdkPromise && sdkKey === key) return sdkPromise;
|
| 68 |
+
sdkKey = key;
|
| 69 |
+
sdkPromise = import(SDK_URL).then((mod) => mod.createClient(config.url, config.anonKey, {
|
| 70 |
+
auth: { persistSession: true, autoRefreshToken: true }
|
| 71 |
+
}));
|
| 72 |
+
return sdkPromise;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
// ---------------------------------------------------------------------------
|
| 76 |
+
// Preview data (used until Supabase is connected)
|
| 77 |
+
// ---------------------------------------------------------------------------
|
| 78 |
+
|
| 79 |
+
export const DEFAULT_PLANS = [
|
| 80 |
+
{
|
| 81 |
+
id: "paragraph-lite",
|
| 82 |
+
name: "Paragraph Lite",
|
| 83 |
+
kind: "one_time",
|
| 84 |
+
price_cents: 400,
|
| 85 |
+
currency: "GBP",
|
| 86 |
+
interval: null,
|
| 87 |
+
blurb: "The little model that started it all, yours to keep. Download it once and mark paragraphs on the bus, on the train, anywhere.",
|
| 88 |
+
features: [
|
| 89 |
+
"Paragraph Lite model, yours for good",
|
| 90 |
+
"Runs fully offline after one download",
|
| 91 |
+
"Every marking tool, forever",
|
| 92 |
+
"Use your own AI key if you have one"
|
| 93 |
+
],
|
| 94 |
+
cost_limit_cents: 0,
|
| 95 |
+
download_tier: 1,
|
| 96 |
+
byok: true,
|
| 97 |
+
stripe_price_id: "",
|
| 98 |
+
stripe_payment_link: "",
|
| 99 |
+
active: true,
|
| 100 |
+
sort: 1
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
id: "model-library",
|
| 104 |
+
name: "Model Library",
|
| 105 |
+
kind: "one_time",
|
| 106 |
+
price_cents: 1400,
|
| 107 |
+
currency: "GBP",
|
| 108 |
+
interval: null,
|
| 109 |
+
blurb: "All four models in one go: the quick one, the strong one, and the two in between. Nothing else to buy.",
|
| 110 |
+
features: [
|
| 111 |
+
"All four offline models unlocked",
|
| 112 |
+
"Download on every device you own",
|
| 113 |
+
"Works on a plane, offline, forever",
|
| 114 |
+
"Free updates when new models arrive"
|
| 115 |
+
],
|
| 116 |
+
cost_limit_cents: 0,
|
| 117 |
+
download_tier: 4,
|
| 118 |
+
byok: true,
|
| 119 |
+
stripe_price_id: "",
|
| 120 |
+
stripe_payment_link: "",
|
| 121 |
+
active: true,
|
| 122 |
+
sort: 2
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
id: "exam-season",
|
| 126 |
+
name: "Exam Season",
|
| 127 |
+
kind: "one_time",
|
| 128 |
+
price_cents: 2400,
|
| 129 |
+
currency: "GBP",
|
| 130 |
+
interval: null,
|
| 131 |
+
blurb: "Everything unlocked for the run-up to the exams, including a pot of hosted AI for the nights you want the big models.",
|
| 132 |
+
features: [
|
| 133 |
+
"All four offline models",
|
| 134 |
+
"Priority access to the hosted models",
|
| 135 |
+
"One payment, nothing renews"
|
| 136 |
+
],
|
| 137 |
+
cost_limit_cents: 600,
|
| 138 |
+
download_tier: 4,
|
| 139 |
+
byok: true,
|
| 140 |
+
stripe_price_id: "",
|
| 141 |
+
stripe_payment_link: "",
|
| 142 |
+
active: true,
|
| 143 |
+
sort: 3
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
id: "ai-booster",
|
| 147 |
+
name: "AI Booster",
|
| 148 |
+
kind: "one_time",
|
| 149 |
+
price_cents: 600,
|
| 150 |
+
currency: "GBP",
|
| 151 |
+
interval: null,
|
| 152 |
+
blurb: "Already have a membership? Drop another pot of hosted AI into your account and keep the big models coming.",
|
| 153 |
+
features: [
|
| 154 |
+
"Stacks with any plan you already have",
|
| 155 |
+
"Never expires",
|
| 156 |
+
"No subscription, no renewal"
|
| 157 |
+
],
|
| 158 |
+
cost_limit_cents: 500,
|
| 159 |
+
download_tier: 0,
|
| 160 |
+
byok: true,
|
| 161 |
+
stripe_price_id: "",
|
| 162 |
+
stripe_payment_link: "",
|
| 163 |
+
active: true,
|
| 164 |
+
sort: 4
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
id: "student",
|
| 168 |
+
name: "Student",
|
| 169 |
+
kind: "subscription",
|
| 170 |
+
price_cents: 400,
|
| 171 |
+
currency: "GBP",
|
| 172 |
+
interval: "month",
|
| 173 |
+
blurb: "The whole shelf of hosted models, plus two offline downloads. About the price of a coffee a month.",
|
| 174 |
+
features: [
|
| 175 |
+
"Every hosted model, including the big ones",
|
| 176 |
+
"Download Lite and 1.5B for offline use",
|
| 177 |
+
"Use your own key and keep it free of limits"
|
| 178 |
+
],
|
| 179 |
+
cost_limit_cents: 120,
|
| 180 |
+
download_tier: 2,
|
| 181 |
+
byok: true,
|
| 182 |
+
stripe_price_id: "",
|
| 183 |
+
stripe_payment_link: "",
|
| 184 |
+
active: true,
|
| 185 |
+
sort: 5
|
| 186 |
+
},
|
| 187 |
+
{
|
| 188 |
+
id: "scholar",
|
| 189 |
+
name: "Scholar",
|
| 190 |
+
kind: "subscription",
|
| 191 |
+
price_cents: 900,
|
| 192 |
+
currency: "GBP",
|
| 193 |
+
interval: "month",
|
| 194 |
+
blurb: "For long essays and heavy revision weeks: more AI, more downloads, and the 3B model offline.",
|
| 195 |
+
features: [
|
| 196 |
+
"Everything in Student",
|
| 197 |
+
"Download the 3B model as well",
|
| 198 |
+
"Priority when the hosted models are busy"
|
| 199 |
+
],
|
| 200 |
+
cost_limit_cents: 400,
|
| 201 |
+
download_tier: 3,
|
| 202 |
+
byok: true,
|
| 203 |
+
stripe_price_id: "",
|
| 204 |
+
stripe_payment_link: "",
|
| 205 |
+
active: true,
|
| 206 |
+
sort: 6
|
| 207 |
+
},
|
| 208 |
+
{
|
| 209 |
+
id: "examiner",
|
| 210 |
+
name: "Examiner",
|
| 211 |
+
kind: "subscription",
|
| 212 |
+
price_cents: 1900,
|
| 213 |
+
currency: "GBP",
|
| 214 |
+
interval: "month",
|
| 215 |
+
blurb: "The full shelf, the biggest budget and every model offline. For the year it really matters.",
|
| 216 |
+
features: [
|
| 217 |
+
"Everything in Scholar",
|
| 218 |
+
"Download all four models, including 7B",
|
| 219 |
+
"Early access to new models and marking prompts"
|
| 220 |
+
],
|
| 221 |
+
cost_limit_cents: 1000,
|
| 222 |
+
download_tier: 4,
|
| 223 |
+
byok: true,
|
| 224 |
+
stripe_price_id: "",
|
| 225 |
+
stripe_payment_link: "",
|
| 226 |
+
active: true,
|
| 227 |
+
sort: 7
|
| 228 |
+
}
|
| 229 |
+
];
|
| 230 |
+
|
| 231 |
+
export const DEFAULT_MODELS = [
|
| 232 |
+
{
|
| 233 |
+
id: "Qwen2.5-0.5B-Instruct-q4f16_1-MLC",
|
| 234 |
+
name: "Paragraph Lite",
|
| 235 |
+
host: "Browser (WebGPU)",
|
| 236 |
+
endpoint_url: "",
|
| 237 |
+
model_name: "Qwen2.5 0.5B Instruct",
|
| 238 |
+
cost_in_per_million: 0,
|
| 239 |
+
cost_out_per_million: 0,
|
| 240 |
+
min_tier: 1,
|
| 241 |
+
download_size: "~0.4 GB",
|
| 242 |
+
note: "Quickest to load. Enough for short feedback.",
|
| 243 |
+
enabled: true,
|
| 244 |
+
sort: 1
|
| 245 |
+
},
|
| 246 |
+
{
|
| 247 |
+
id: "Qwen2.5-1.5B-Instruct-q4f16_1-MLC",
|
| 248 |
+
name: "Qwen2.5 1.5B",
|
| 249 |
+
host: "Browser (WebGPU)",
|
| 250 |
+
endpoint_url: "",
|
| 251 |
+
model_name: "Qwen2.5 1.5B Instruct",
|
| 252 |
+
cost_in_per_million: 0,
|
| 253 |
+
cost_out_per_million: 0,
|
| 254 |
+
min_tier: 2,
|
| 255 |
+
download_size: "~1.1 GB",
|
| 256 |
+
note: "The default when WebGPU is available.",
|
| 257 |
+
enabled: true,
|
| 258 |
+
sort: 2
|
| 259 |
+
},
|
| 260 |
+
{
|
| 261 |
+
id: "Qwen2.5-3B-Instruct-q4f16_1-MLC",
|
| 262 |
+
name: "Qwen2.5 3B",
|
| 263 |
+
host: "Browser (WebGPU)",
|
| 264 |
+
endpoint_url: "",
|
| 265 |
+
model_name: "Qwen2.5 3B Instruct",
|
| 266 |
+
cost_in_per_million: 0,
|
| 267 |
+
cost_out_per_million: 0,
|
| 268 |
+
min_tier: 3,
|
| 269 |
+
download_size: "~2.0 GB",
|
| 270 |
+
note: "Better analysis; needs a stronger GPU.",
|
| 271 |
+
enabled: true,
|
| 272 |
+
sort: 3
|
| 273 |
+
},
|
| 274 |
+
{
|
| 275 |
+
id: "Qwen2.5-7B-Instruct-q4f16_1-MLC",
|
| 276 |
+
name: "Qwen2.5 7B",
|
| 277 |
+
host: "Browser (WebGPU)",
|
| 278 |
+
endpoint_url: "",
|
| 279 |
+
model_name: "Qwen2.5 7B Instruct",
|
| 280 |
+
cost_in_per_million: 0,
|
| 281 |
+
cost_out_per_million: 0,
|
| 282 |
+
min_tier: 4,
|
| 283 |
+
download_size: "~4.5 GB",
|
| 284 |
+
note: "Best feedback here, but only on a capable GPU.",
|
| 285 |
+
enabled: true,
|
| 286 |
+
sort: 4
|
| 287 |
+
}
|
| 288 |
+
];
|
| 289 |
+
|
| 290 |
+
export const DEFAULT_SETTINGS = {
|
| 291 |
+
stripe_publishable_key: "",
|
| 292 |
+
stripe_mode: "payment_links",
|
| 293 |
+
checkout_function: "stripe-checkout",
|
| 294 |
+
currency: "GBP",
|
| 295 |
+
support_email: DEVELOPER_EMAIL
|
| 296 |
+
};
|
| 297 |
+
|
| 298 |
+
function previewDefaults() {
|
| 299 |
+
return { plans: DEFAULT_PLANS, models: DEFAULT_MODELS, content: {}, settings: DEFAULT_SETTINGS, entitlements: [], usage: [] };
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
function readPreview() {
|
| 303 |
+
try {
|
| 304 |
+
const raw = JSON.parse(localStorage.getItem(PREVIEW_KEY) || "null");
|
| 305 |
+
if (!raw) return previewDefaults();
|
| 306 |
+
return { ...previewDefaults(), ...raw };
|
| 307 |
+
} catch {
|
| 308 |
+
return previewDefaults();
|
| 309 |
+
}
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
function writePreview(next) {
|
| 313 |
+
try {
|
| 314 |
+
localStorage.setItem(PREVIEW_KEY, JSON.stringify(next));
|
| 315 |
+
} catch {
|
| 316 |
+
// ignore quota
|
| 317 |
+
}
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
// ---------------------------------------------------------------------------
|
| 321 |
+
// Money helpers
|
| 322 |
+
// ---------------------------------------------------------------------------
|
| 323 |
+
|
| 324 |
+
export function money(cents, currency = "GBP") {
|
| 325 |
+
try {
|
| 326 |
+
return new Intl.NumberFormat("en-GB", { style: "currency", currency: currency || "GBP" }).format((Number(cents) || 0) / 100);
|
| 327 |
+
} catch {
|
| 328 |
+
return `£${((Number(cents) || 0) / 100).toFixed(2)}`;
|
| 329 |
+
}
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
export function planPeriod(plan) {
|
| 333 |
+
if (!plan) return "";
|
| 334 |
+
if (plan.kind === "one_time") return "one-off";
|
| 335 |
+
return `per ${plan.interval || "month"}`;
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
export function isDeveloper(user) {
|
| 339 |
+
return !!user && String(user.email || "").toLowerCase() === DEVELOPER_EMAIL;
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
// ---------------------------------------------------------------------------
|
| 343 |
+
// Provider
|
| 344 |
+
// ---------------------------------------------------------------------------
|
| 345 |
+
|
| 346 |
+
const CloudContext = createContext(null);
|
| 347 |
+
|
| 348 |
+
export function CloudProvider({ children }) {
|
| 349 |
+
const [config, setConfig] = useState(readConfig);
|
| 350 |
+
const [client, setClient] = useState(null);
|
| 351 |
+
const [user, setUser] = useState(null);
|
| 352 |
+
const [ready, setReady] = useState(false);
|
| 353 |
+
const [error, setError] = useState("");
|
| 354 |
+
const [preview, setPreview] = useState(() => readPreview());
|
| 355 |
+
const [cloud, setCloud] = useState({
|
| 356 |
+
settings: { ...DEFAULT_SETTINGS },
|
| 357 |
+
plans: [],
|
| 358 |
+
models: [],
|
| 359 |
+
content: {},
|
| 360 |
+
entitlements: [],
|
| 361 |
+
usage: []
|
| 362 |
+
});
|
| 363 |
+
const [busy, setBusy] = useState(false);
|
| 364 |
+
const [notice, setNotice] = useState("");
|
| 365 |
+
const mounted = useRef(true);
|
| 366 |
+
|
| 367 |
+
useEffect(() => {
|
| 368 |
+
mounted.current = true;
|
| 369 |
+
return () => {
|
| 370 |
+
mounted.current = false;
|
| 371 |
+
};
|
| 372 |
+
}, []);
|
| 373 |
+
|
| 374 |
+
const flash = useCallback((message) => {
|
| 375 |
+
if (!mounted.current) return;
|
| 376 |
+
setNotice(message);
|
| 377 |
+
setTimeout(() => mounted.current && setNotice(""), 2600);
|
| 378 |
+
}, []);
|
| 379 |
+
|
| 380 |
+
const refresh = useCallback(
|
| 381 |
+
async (sb, currentUser) => {
|
| 382 |
+
if (!sb) return;
|
| 383 |
+
const who = currentUser === undefined ? user : currentUser;
|
| 384 |
+
try {
|
| 385 |
+
const [settingsRes, plansRes, modelsRes, contentRes] = await Promise.all([
|
| 386 |
+
sb.from(T.settings).select("*").eq("id", 1).maybeSingle(),
|
| 387 |
+
sb.from(T.plans).select("*").order("sort", { ascending: true }),
|
| 388 |
+
sb.from(T.models).select("*").order("sort", { ascending: true }),
|
| 389 |
+
sb.from(T.content).select("*")
|
| 390 |
+
]);
|
| 391 |
+
const map = {};
|
| 392 |
+
(contentRes.data || []).forEach((row) => {
|
| 393 |
+
map[row.key] = row.value;
|
| 394 |
+
});
|
| 395 |
+
let entitlements = [];
|
| 396 |
+
let usage = [];
|
| 397 |
+
if (who) {
|
| 398 |
+
const [entRes, useRes] = await Promise.all([
|
| 399 |
+
sb.from(T.entitlements).select("*").order("granted_at", { ascending: false }),
|
| 400 |
+
sb.from(T.usage).select("*").order("created_at", { ascending: false }).limit(2000)
|
| 401 |
+
]);
|
| 402 |
+
entitlements = entRes.data || [];
|
| 403 |
+
usage = useRes.data || [];
|
| 404 |
+
}
|
| 405 |
+
if (!mounted.current) return;
|
| 406 |
+
setCloud({
|
| 407 |
+
settings: { ...DEFAULT_SETTINGS, ...(settingsRes.data || {}) },
|
| 408 |
+
plans: plansRes.data || [],
|
| 409 |
+
models: modelsRes.data || [],
|
| 410 |
+
content: map,
|
| 411 |
+
entitlements,
|
| 412 |
+
usage
|
| 413 |
+
});
|
| 414 |
+
setError("");
|
| 415 |
+
} catch (err) {
|
| 416 |
+
if (mounted.current) setError(err && err.message ? err.message : "Could not read the shared settings.");
|
| 417 |
+
}
|
| 418 |
+
},
|
| 419 |
+
[user]
|
| 420 |
+
);
|
| 421 |
+
|
| 422 |
+
useEffect(() => {
|
| 423 |
+
let cancelled = false;
|
| 424 |
+
if (!config.ready) {
|
| 425 |
+
setReady(true);
|
| 426 |
+
setClient(null);
|
| 427 |
+
setUser(null);
|
| 428 |
+
return () => {
|
| 429 |
+
cancelled = true;
|
| 430 |
+
};
|
| 431 |
+
}
|
| 432 |
+
(async () => {
|
| 433 |
+
setReady(false);
|
| 434 |
+
try {
|
| 435 |
+
const sb = await loadSdk(config);
|
| 436 |
+
if (cancelled) return;
|
| 437 |
+
setClient(sb);
|
| 438 |
+
const { data } = await sb.auth.getSession();
|
| 439 |
+
const sessionUser = data && data.session ? data.session.user : null;
|
| 440 |
+
if (cancelled) return;
|
| 441 |
+
setUser(sessionUser);
|
| 442 |
+
await refresh(sb, sessionUser);
|
| 443 |
+
sb.auth.onAuthStateChange((_event, session) => {
|
| 444 |
+
const nextUser = session ? session.user : null;
|
| 445 |
+
setUser(nextUser);
|
| 446 |
+
refresh(sb, nextUser);
|
| 447 |
+
});
|
| 448 |
+
} catch (err) {
|
| 449 |
+
if (!cancelled) setError("Supabase could not be reached. Check the project URL and public key in Developer settings.");
|
| 450 |
+
} finally {
|
| 451 |
+
if (!cancelled) setReady(true);
|
| 452 |
+
}
|
| 453 |
+
})();
|
| 454 |
+
return () => {
|
| 455 |
+
cancelled = true;
|
| 456 |
+
};
|
| 457 |
+
}, [config.ready, config.url, config.anonKey]);
|
| 458 |
+
|
| 459 |
+
// Preview-mode writes keep working with no backend.
|
| 460 |
+
const previewWrite = useCallback((mutate) => {
|
| 461 |
+
setPreview((current) => {
|
| 462 |
+
const next = mutate({ ...current });
|
| 463 |
+
writePreview(next);
|
| 464 |
+
return next;
|
| 465 |
+
});
|
| 466 |
+
}, []);
|
| 467 |
+
|
| 468 |
+
const entitlements = config.ready ? cloud.entitlements : preview.entitlements;
|
| 469 |
+
const usage = config.ready ? cloud.usage : preview.usage;
|
| 470 |
+
|
| 471 |
+
const activeEntitlements = useMemo(() => {
|
| 472 |
+
const now = Date.now();
|
| 473 |
+
return entitlements.filter((e) => {
|
| 474 |
+
if (e.revoked) return false;
|
| 475 |
+
if (e.expires_at && new Date(e.expires_at).getTime() < now) return false;
|
| 476 |
+
return true;
|
| 477 |
+
});
|
| 478 |
+
}, [entitlements]);
|
| 479 |
+
|
| 480 |
+
const activeEntitlement = activeEntitlements[0] || null;
|
| 481 |
+
|
| 482 |
+
const plans = config.ready ? cloud.plans : preview.plans;
|
| 483 |
+
const models = config.ready ? cloud.models : preview.models;
|
| 484 |
+
|
| 485 |
+
// Purchases stack: the best download tier wins and the included AI adds up.
|
| 486 |
+
const plan = useMemo(() => {
|
| 487 |
+
const owned = activeEntitlements.map((e) => plans.find((p) => p.id === e.plan_id)).filter(Boolean);
|
| 488 |
+
return (
|
| 489 |
+
owned.sort(
|
| 490 |
+
(a, b) => Number(b.download_tier || 0) - Number(a.download_tier || 0) || Number(b.cost_limit_cents || 0) - Number(a.cost_limit_cents || 0)
|
| 491 |
+
)[0] || null
|
| 492 |
+
);
|
| 493 |
+
}, [plans, activeEntitlements]);
|
| 494 |
+
|
| 495 |
+
const budget = useMemo(() => {
|
| 496 |
+
const owned = activeEntitlements.map((e) => plans.find((p) => p.id === e.plan_id)).filter(Boolean);
|
| 497 |
+
const limit = owned.reduce((sum, p) => sum + Number(p.cost_limit_cents || 0), 0);
|
| 498 |
+
if (!limit) return { limit: 0, spent: 0, remaining: 0, unlimited: false };
|
| 499 |
+
const hasSub = owned.some((p) => p.kind === "subscription");
|
| 500 |
+
const since = hasSub ? new Date(new Date().getFullYear(), new Date().getMonth(), 1).getTime() : 0;
|
| 501 |
+
const spent = usage
|
| 502 |
+
.filter((u) => new Date(u.created_at || 0).getTime() >= since)
|
| 503 |
+
.reduce((sum, u) => sum + Number(u.cost_cents || 0), 0);
|
| 504 |
+
return { limit, spent, remaining: Math.max(0, limit - spent), unlimited: false };
|
| 505 |
+
}, [plans, activeEntitlements, usage]);
|
| 506 |
+
|
| 507 |
+
const isDev = config.ready ? isDeveloper(user) : true;
|
| 508 |
+
|
| 509 |
+
const signIn = useCallback(
|
| 510 |
+
async (email, password) => {
|
| 511 |
+
if (!client) throw new Error("Connect Supabase first.");
|
| 512 |
+
const { error: err } = await client.auth.signInWithPassword({ email, password });
|
| 513 |
+
if (err) throw err;
|
| 514 |
+
},
|
| 515 |
+
[client]
|
| 516 |
+
);
|
| 517 |
+
|
| 518 |
+
const signUp = useCallback(
|
| 519 |
+
async (email, password) => {
|
| 520 |
+
if (!client) throw new Error("Connect Supabase first.");
|
| 521 |
+
const { data, error: err } = await client.auth.signUp({ email, password, options: { emailRedirectTo: appRedirect() } });
|
| 522 |
+
if (err) throw err;
|
| 523 |
+
return data;
|
| 524 |
+
},
|
| 525 |
+
[client]
|
| 526 |
+
);
|
| 527 |
+
|
| 528 |
+
const magicLink = useCallback(
|
| 529 |
+
async (email) => {
|
| 530 |
+
if (!client) throw new Error("Connect Supabase first.");
|
| 531 |
+
const { error: err } = await client.auth.signInWithOtp({ email, options: { emailRedirectTo: appRedirect() } });
|
| 532 |
+
if (err) throw err;
|
| 533 |
+
},
|
| 534 |
+
[client]
|
| 535 |
+
);
|
| 536 |
+
|
| 537 |
+
const resetPassword = useCallback(
|
| 538 |
+
async (email) => {
|
| 539 |
+
if (!client) throw new Error("Connect Supabase first.");
|
| 540 |
+
const { error: err } = await client.auth.resetPasswordForEmail(email, { redirectTo: appRedirect() });
|
| 541 |
+
if (err) throw err;
|
| 542 |
+
},
|
| 543 |
+
[client]
|
| 544 |
+
);
|
| 545 |
+
|
| 546 |
+
// Used by the screen a recovery or invite link lands on. The link itself has
|
| 547 |
+
// already signed the person in, so this only sets the new password.
|
| 548 |
+
const updatePassword = useCallback(
|
| 549 |
+
async (password) => {
|
| 550 |
+
if (!client) throw new Error("Connect Supabase first.");
|
| 551 |
+
const { error: err } = await client.auth.updateUser({ password });
|
| 552 |
+
if (err) throw err;
|
| 553 |
+
},
|
| 554 |
+
[client]
|
| 555 |
+
);
|
| 556 |
+
|
| 557 |
+
// The six-digit code printed in the sign-in emails. Supabase labels the token
|
| 558 |
+
// by the flow that produced it, so try the likely types in order and keep the
|
| 559 |
+
// last refusal.
|
| 560 |
+
const verifyCode = useCallback(
|
| 561 |
+
async (email, token) => {
|
| 562 |
+
if (!client) throw new Error("Connect Supabase first.");
|
| 563 |
+
const types = ["signup", "invite", "recovery", "email", "magiclink"];
|
| 564 |
+
let lastError = null;
|
| 565 |
+
for (const type of types) {
|
| 566 |
+
const { data, error: err } = await client.auth.verifyOtp({ email, token, type });
|
| 567 |
+
if (!err && data && data.session) return data;
|
| 568 |
+
lastError = err;
|
| 569 |
+
}
|
| 570 |
+
throw lastError || new Error("That code did not work.");
|
| 571 |
+
},
|
| 572 |
+
[client]
|
| 573 |
+
);
|
| 574 |
+
|
| 575 |
+
const signOut = useCallback(async () => {
|
| 576 |
+
if (client) await client.auth.signOut();
|
| 577 |
+
setUser(null);
|
| 578 |
+
}, [client]);
|
| 579 |
+
|
| 580 |
+
const connect = useCallback(async ({ url, anonKey }) => {
|
| 581 |
+
saveConfig({ url, anonKey });
|
| 582 |
+
setConfig(readConfig());
|
| 583 |
+
}, []);
|
| 584 |
+
|
| 585 |
+
const disconnect = useCallback(async () => {
|
| 586 |
+
forgetConfig();
|
| 587 |
+
setCloud({ settings: { ...DEFAULT_SETTINGS }, plans: [], models: [], content: {}, entitlements: [], usage: [] });
|
| 588 |
+
setConfig(readConfig());
|
| 589 |
+
}, []);
|
| 590 |
+
|
| 591 |
+
// ---- writes -------------------------------------------------------------
|
| 592 |
+
|
| 593 |
+
const upsertPlan = useCallback(
|
| 594 |
+
async (next) => {
|
| 595 |
+
if (!config.ready) {
|
| 596 |
+
previewWrite((data) => ({ ...data, plans: [...data.plans.filter((p) => p.id !== next.id), next].sort((a, b) => (a.sort || 0) - (b.sort || 0)) }));
|
| 597 |
+
return;
|
| 598 |
+
}
|
| 599 |
+
const { error: err } = await client.from(T.plans).upsert(next);
|
| 600 |
+
if (err) throw err;
|
| 601 |
+
await refresh(client);
|
| 602 |
+
},
|
| 603 |
+
[config.ready, client, previewWrite, refresh]
|
| 604 |
+
);
|
| 605 |
+
|
| 606 |
+
const deletePlan = useCallback(
|
| 607 |
+
async (id) => {
|
| 608 |
+
if (!config.ready) {
|
| 609 |
+
previewWrite((data) => ({ ...data, plans: data.plans.filter((p) => p.id !== id) }));
|
| 610 |
+
return;
|
| 611 |
+
}
|
| 612 |
+
const { error: err } = await client.from(T.plans).delete().eq("id", id);
|
| 613 |
+
if (err) throw err;
|
| 614 |
+
await refresh(client);
|
| 615 |
+
},
|
| 616 |
+
[config.ready, client, previewWrite, refresh]
|
| 617 |
+
);
|
| 618 |
+
|
| 619 |
+
const upsertModel = useCallback(
|
| 620 |
+
async (next) => {
|
| 621 |
+
if (!config.ready) {
|
| 622 |
+
previewWrite((data) => ({ ...data, models: [...data.models.filter((m) => m.id !== next.id), next].sort((a, b) => (a.sort || 0) - (b.sort || 0)) }));
|
| 623 |
+
return;
|
| 624 |
+
}
|
| 625 |
+
const { error: err } = await client.from(T.models).upsert(next);
|
| 626 |
+
if (err) throw err;
|
| 627 |
+
await refresh(client);
|
| 628 |
+
},
|
| 629 |
+
[config.ready, client, previewWrite, refresh]
|
| 630 |
+
);
|
| 631 |
+
|
| 632 |
+
const deleteModel = useCallback(
|
| 633 |
+
async (id) => {
|
| 634 |
+
if (!config.ready) {
|
| 635 |
+
previewWrite((data) => ({ ...data, models: data.models.filter((m) => m.id !== id) }));
|
| 636 |
+
return;
|
| 637 |
+
}
|
| 638 |
+
const { error: err } = await client.from(T.models).delete().eq("id", id);
|
| 639 |
+
if (err) throw err;
|
| 640 |
+
await refresh(client);
|
| 641 |
+
},
|
| 642 |
+
[config.ready, client, previewWrite, refresh]
|
| 643 |
+
);
|
| 644 |
+
|
| 645 |
+
const saveModelKey = useCallback(
|
| 646 |
+
async (modelId, apiKey) => {
|
| 647 |
+
if (!config.ready) {
|
| 648 |
+
previewWrite((data) => ({ ...data, secrets: { ...(data.secrets || {}), [modelId]: apiKey } }));
|
| 649 |
+
return;
|
| 650 |
+
}
|
| 651 |
+
const { error: err } = await client.from(T.secrets).upsert({ model_id: modelId, api_key: apiKey, updated_at: new Date().toISOString() });
|
| 652 |
+
if (err) throw err;
|
| 653 |
+
},
|
| 654 |
+
[config.ready, client, previewWrite]
|
| 655 |
+
);
|
| 656 |
+
|
| 657 |
+
const setContent = useCallback(
|
| 658 |
+
async (key, value) => {
|
| 659 |
+
const clean = String(value == null ? "" : value);
|
| 660 |
+
if (!config.ready) {
|
| 661 |
+
previewWrite((data) => ({ ...data, content: { ...data.content, [key]: clean } }));
|
| 662 |
+
return;
|
| 663 |
+
}
|
| 664 |
+
const { error: err } = await client
|
| 665 |
+
.from(T.content)
|
| 666 |
+
.upsert({ key, value: clean, updated_at: new Date().toISOString(), updated_by: (user && user.email) || "" });
|
| 667 |
+
if (err) throw err;
|
| 668 |
+
setCloud((c) => ({ ...c, content: { ...c.content, [key]: clean } }));
|
| 669 |
+
},
|
| 670 |
+
[config.ready, client, previewWrite, user]
|
| 671 |
+
);
|
| 672 |
+
|
| 673 |
+
const clearContent = useCallback(
|
| 674 |
+
async (key) => {
|
| 675 |
+
if (!config.ready) {
|
| 676 |
+
previewWrite((data) => {
|
| 677 |
+
const content = { ...data.content };
|
| 678 |
+
delete content[key];
|
| 679 |
+
return { ...data, content };
|
| 680 |
+
});
|
| 681 |
+
return;
|
| 682 |
+
}
|
| 683 |
+
const { error: err } = await client.from(T.content).delete().eq("key", key);
|
| 684 |
+
if (err) throw err;
|
| 685 |
+
setCloud((c) => {
|
| 686 |
+
const content = { ...c.content };
|
| 687 |
+
delete content[key];
|
| 688 |
+
return { ...c, content };
|
| 689 |
+
});
|
| 690 |
+
},
|
| 691 |
+
[config.ready, client, previewWrite]
|
| 692 |
+
);
|
| 693 |
+
|
| 694 |
+
const setSettings = useCallback(
|
| 695 |
+
async (patch) => {
|
| 696 |
+
if (!config.ready) {
|
| 697 |
+
previewWrite((data) => ({ ...data, settings: { ...data.settings, ...patch } }));
|
| 698 |
+
return;
|
| 699 |
+
}
|
| 700 |
+
const { error: err } = await client.from(T.settings).upsert({ id: 1, ...patch, updated_at: new Date().toISOString() });
|
| 701 |
+
if (err) throw err;
|
| 702 |
+
setCloud((c) => ({ ...c, settings: { ...c.settings, ...patch } }));
|
| 703 |
+
},
|
| 704 |
+
[config.ready, client, previewWrite]
|
| 705 |
+
);
|
| 706 |
+
|
| 707 |
+
const grantPlan = useCallback(
|
| 708 |
+
async (email, planId, months = 1) => {
|
| 709 |
+
if (!config.ready) {
|
| 710 |
+
previewWrite((data) => ({
|
| 711 |
+
...data,
|
| 712 |
+
entitlements: [
|
| 713 |
+
{ id: "preview-" + Date.now(), email, plan_id: planId, source: "grant", granted_at: new Date().toISOString(), expires_at: null, revoked: false },
|
| 714 |
+
...data.entitlements
|
| 715 |
+
]
|
| 716 |
+
}));
|
| 717 |
+
return;
|
| 718 |
+
}
|
| 719 |
+
const { error: err } = await client.from(T.entitlements).insert({
|
| 720 |
+
email: String(email || "").toLowerCase(),
|
| 721 |
+
plan_id: planId,
|
| 722 |
+
source: "grant",
|
| 723 |
+
expires_at: null
|
| 724 |
+
});
|
| 725 |
+
if (err) throw err;
|
| 726 |
+
await refresh(client);
|
| 727 |
+
},
|
| 728 |
+
[config.ready, client, previewWrite, refresh]
|
| 729 |
+
);
|
| 730 |
+
|
| 731 |
+
const revokeGrant = useCallback(
|
| 732 |
+
async (id) => {
|
| 733 |
+
if (!config.ready) {
|
| 734 |
+
previewWrite((data) => ({ ...data, entitlements: data.entitlements.map((e) => (e.id === id ? { ...e, revoked: true } : e)) }));
|
| 735 |
+
return;
|
| 736 |
+
}
|
| 737 |
+
const { error: err } = await client.from(T.entitlements).update({ revoked: true }).eq("id", id);
|
| 738 |
+
if (err) throw err;
|
| 739 |
+
await refresh(client);
|
| 740 |
+
},
|
| 741 |
+
[config.ready, client, previewWrite, refresh]
|
| 742 |
+
);
|
| 743 |
+
|
| 744 |
+
const startCheckout = useCallback(
|
| 745 |
+
async (chosen) => {
|
| 746 |
+
if (!chosen) throw new Error("Pick a plan first.");
|
| 747 |
+
if (!user) throw new Error("Sign in first, so the purchase can be attached to your account.");
|
| 748 |
+
const settings = config.ready ? cloud.settings : preview.settings;
|
| 749 |
+
if (settings.stripe_mode === "payment_links") {
|
| 750 |
+
if (!chosen.stripe_payment_link) throw new Error("This plan has no Stripe payment link yet. The developer needs to add one in Developer settings.");
|
| 751 |
+
const url = new URL(chosen.stripe_payment_link);
|
| 752 |
+
url.searchParams.set("client_reference_id", user.id);
|
| 753 |
+
if (user.email) url.searchParams.set("prefilled_email", user.email);
|
| 754 |
+
window.location.href = url.toString();
|
| 755 |
+
return { redirect: true };
|
| 756 |
+
}
|
| 757 |
+
const fn = settings.checkout_function || "stripe-checkout";
|
| 758 |
+
const { data, error: err } = await client.functions.invoke(fn, {
|
| 759 |
+
body: { plan_id: chosen.id, origin: window.location.origin }
|
| 760 |
+
});
|
| 761 |
+
if (err) throw err;
|
| 762 |
+
if (data && data.url) {
|
| 763 |
+
window.location.href = data.url;
|
| 764 |
+
return { redirect: true };
|
| 765 |
+
}
|
| 766 |
+
throw new Error("The checkout function did not return a URL.");
|
| 767 |
+
},
|
| 768 |
+
[user, client, config.ready, cloud.settings, preview.settings]
|
| 769 |
+
);
|
| 770 |
+
|
| 771 |
+
const hostedChat = useCallback(
|
| 772 |
+
async (model, messages, onToken) => {
|
| 773 |
+
if (!config.ready) throw new Error("Hosted models need Supabase. Connect it in Developer settings.");
|
| 774 |
+
if (!user) throw new Error("Sign in to use the hosted models.");
|
| 775 |
+
const { data: sessionData } = await client.auth.getSession();
|
| 776 |
+
const token = sessionData && sessionData.session ? sessionData.session.access_token : "";
|
| 777 |
+
const base = config.url;
|
| 778 |
+
const res = await fetch(`${base}/functions/v1/ai`, {
|
| 779 |
+
method: "POST",
|
| 780 |
+
headers: {
|
| 781 |
+
"Content-Type": "application/json",
|
| 782 |
+
Authorization: `Bearer ${token}`,
|
| 783 |
+
apikey: config.anonKey
|
| 784 |
+
},
|
| 785 |
+
body: JSON.stringify({ model_id: model.id, messages, stream: true })
|
| 786 |
+
});
|
| 787 |
+
if (res.status === 402) {
|
| 788 |
+
const info = await res.json().catch(() => ({}));
|
| 789 |
+
throw new Error(info.message || "You have used your included model budget for this period.");
|
| 790 |
+
}
|
| 791 |
+
if (!res.ok) {
|
| 792 |
+
const text = await res.text().catch(() => "");
|
| 793 |
+
throw new Error(text || `The hosted model returned ${res.status}.`);
|
| 794 |
+
}
|
| 795 |
+
if (!res.body) {
|
| 796 |
+
const data = await res.json();
|
| 797 |
+
const text = (data && data.text) || "";
|
| 798 |
+
onToken && onToken(text);
|
| 799 |
+
return text;
|
| 800 |
+
}
|
| 801 |
+
const reader = res.body.getReader();
|
| 802 |
+
const decoder = new TextDecoder();
|
| 803 |
+
let buffer = "";
|
| 804 |
+
let full = "";
|
| 805 |
+
while (true) {
|
| 806 |
+
const { value, done } = await reader.read();
|
| 807 |
+
if (done) break;
|
| 808 |
+
buffer += decoder.decode(value, { stream: true });
|
| 809 |
+
const lines = buffer.split("\n");
|
| 810 |
+
buffer = lines.pop() || "";
|
| 811 |
+
for (const line of lines) {
|
| 812 |
+
const trimmed = line.trim();
|
| 813 |
+
if (!trimmed.startsWith("data:")) continue;
|
| 814 |
+
const payload = trimmed.slice(5).trim();
|
| 815 |
+
if (payload === "[DONE]") continue;
|
| 816 |
+
try {
|
| 817 |
+
const json = JSON.parse(payload);
|
| 818 |
+
const delta = (json.choices && json.choices[0] && json.choices[0].delta && json.choices[0].delta.content) || "";
|
| 819 |
+
if (delta) {
|
| 820 |
+
full += delta;
|
| 821 |
+
onToken && onToken(full);
|
| 822 |
+
}
|
| 823 |
+
} catch {
|
| 824 |
+
// wait for the rest of the line
|
| 825 |
+
}
|
| 826 |
+
}
|
| 827 |
+
}
|
| 828 |
+
return full;
|
| 829 |
+
},
|
| 830 |
+
[config, client, user]
|
| 831 |
+
);
|
| 832 |
+
|
| 833 |
+
const value = useMemo(
|
| 834 |
+
() => ({
|
| 835 |
+
config,
|
| 836 |
+
configured: config.ready,
|
| 837 |
+
mode: config.ready ? "cloud" : "preview",
|
| 838 |
+
client,
|
| 839 |
+
user,
|
| 840 |
+
isDev,
|
| 841 |
+
ready,
|
| 842 |
+
error,
|
| 843 |
+
notice,
|
| 844 |
+
flash,
|
| 845 |
+
settings: config.ready ? cloud.settings : preview.settings,
|
| 846 |
+
plans,
|
| 847 |
+
models,
|
| 848 |
+
content: config.ready ? cloud.content : preview.content,
|
| 849 |
+
entitlements,
|
| 850 |
+
usage,
|
| 851 |
+
plan,
|
| 852 |
+
entitlement: activeEntitlement,
|
| 853 |
+
budget,
|
| 854 |
+
signIn,
|
| 855 |
+
signUp,
|
| 856 |
+
magicLink,
|
| 857 |
+
resetPassword,
|
| 858 |
+
updatePassword,
|
| 859 |
+
verifyCode,
|
| 860 |
+
signOut,
|
| 861 |
+
connect,
|
| 862 |
+
disconnect,
|
| 863 |
+
upsertPlan,
|
| 864 |
+
deletePlan,
|
| 865 |
+
upsertModel,
|
| 866 |
+
deleteModel,
|
| 867 |
+
saveModelKey,
|
| 868 |
+
setContent,
|
| 869 |
+
clearContent,
|
| 870 |
+
setSettings,
|
| 871 |
+
grantPlan,
|
| 872 |
+
revokeGrant,
|
| 873 |
+
startCheckout,
|
| 874 |
+
hostedChat,
|
| 875 |
+
refresh: () => refresh(client),
|
| 876 |
+
canDownload: (tier) => Number(tier || 0) <= 1 || (!!plan && Number(plan.download_tier || 0) >= Number(tier || 0)),
|
| 877 |
+
canHost: (model) => !!model && budget.limit > 0 && budget.remaining > 0
|
| 878 |
+
}),
|
| 879 |
+
[
|
| 880 |
+
config,
|
| 881 |
+
client,
|
| 882 |
+
user,
|
| 883 |
+
isDev,
|
| 884 |
+
ready,
|
| 885 |
+
error,
|
| 886 |
+
notice,
|
| 887 |
+
flash,
|
| 888 |
+
cloud,
|
| 889 |
+
preview,
|
| 890 |
+
plans,
|
| 891 |
+
models,
|
| 892 |
+
entitlements,
|
| 893 |
+
usage,
|
| 894 |
+
plan,
|
| 895 |
+
activeEntitlement,
|
| 896 |
+
activeEntitlements,
|
| 897 |
+
budget,
|
| 898 |
+
signIn,
|
| 899 |
+
signUp,
|
| 900 |
+
magicLink,
|
| 901 |
+
resetPassword,
|
| 902 |
+
updatePassword,
|
| 903 |
+
verifyCode,
|
| 904 |
+
signOut,
|
| 905 |
+
connect,
|
| 906 |
+
disconnect,
|
| 907 |
+
upsertPlan,
|
| 908 |
+
deletePlan,
|
| 909 |
+
upsertModel,
|
| 910 |
+
deleteModel,
|
| 911 |
+
saveModelKey,
|
| 912 |
+
setContent,
|
| 913 |
+
clearContent,
|
| 914 |
+
setSettings,
|
| 915 |
+
grantPlan,
|
| 916 |
+
revokeGrant,
|
| 917 |
+
startCheckout,
|
| 918 |
+
hostedChat,
|
| 919 |
+
refresh
|
| 920 |
+
]
|
| 921 |
+
);
|
| 922 |
+
|
| 923 |
+
return html`<${CloudContext.Provider} value=${value}>${children}<//>`;
|
| 924 |
+
}
|
| 925 |
+
|
| 926 |
+
export function useCloud() {
|
| 927 |
+
const value = useContext(CloudContext);
|
| 928 |
+
if (!value) throw new Error("useCloud must be used inside CloudProvider");
|
| 929 |
+
return value;
|
| 930 |
+
}
|
js/components.js
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { React, html, useEffect, useState } from "./runtime.js";
|
| 2 |
+
import { useApp } from "./store.js";
|
| 3 |
+
import { useEngine } from "./engine.js";
|
| 4 |
+
import { useCloud } from "./cloud.js";
|
| 5 |
+
import { levelTitle, wordCount } from "./marking.js";
|
| 6 |
+
|
| 7 |
+
// ---------------------------------------------------------------------------
|
| 8 |
+
// Icons
|
| 9 |
+
// ---------------------------------------------------------------------------
|
| 10 |
+
|
| 11 |
+
const PATHS = {
|
| 12 |
+
home: ["M3 10.5 12 3l9 7.5V20a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z"],
|
| 13 |
+
chat: ["M21 11.5a8.4 8.4 0 0 1-8.5 8.5H7l-4 3v-7.2A8.5 8.5 0 1 1 21 11.5z"],
|
| 14 |
+
pen: ["M12 20h9", "M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z"],
|
| 15 |
+
book: ["M4 19.5A2.5 2.5 0 0 1 6.5 17H20", "M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"],
|
| 16 |
+
feather: ["M20 4a6.5 6.5 0 0 0-9.2 0L4 10.8V20h9.2L20 13.2A6.5 6.5 0 0 0 20 4z", "M4 20 15 9"],
|
| 17 |
+
sparkle: ["M12 3l1.9 4.6L18.5 9.5l-4.6 1.9L12 16l-1.9-4.6L5.5 9.5l4.6-1.9z", "M19 16l.7 1.8L21.5 19l-1.8.7L19 21.5l-.7-1.8L16.5 19l1.8-.7z"],
|
| 18 |
+
file: ["M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z", "M14 2v6h6", "M8 13h8", "M8 17h5"],
|
| 19 |
+
clock: ["M12 22a10 10 0 1 0 0-20 10 10 0 0 0 0 20z", "M12 6v6l4 2"],
|
| 20 |
+
list: ["M8 6h13", "M8 12h13", "M8 18h13", "M3 6h.01", "M3 12h.01", "M3 18h.01"],
|
| 21 |
+
settings: ["M12 15.5a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7z", "M19.4 15a1.7 1.7 0 0 0 .3 1.9l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.9-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1-1.5 1.7 1.7 0 0 0-1.9.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.9 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1 1.7 1.7 0 0 0-.3-1.9l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.9.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.9-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.9V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z"],
|
| 22 |
+
menu: ["M3 6h18", "M3 12h18", "M3 18h18"],
|
| 23 |
+
plus: ["M12 5v14", "M5 12h14"],
|
| 24 |
+
up: ["M12 19V5", "M5 12l7-7 7 7"],
|
| 25 |
+
down: ["M12 5v14", "M19 12l-7 7-7-7"],
|
| 26 |
+
download: ["M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4", "M7 10l5 5 5-5", "M12 15V3"],
|
| 27 |
+
check: ["M20 6 9 17l-5-5"],
|
| 28 |
+
x: ["M18 6 6 18", "M6 6l12 12"],
|
| 29 |
+
lock: ["M5 11h14v10H5z", "M8 11V7a4 4 0 0 1 8 0v4"],
|
| 30 |
+
refresh: ["M21 12a9 9 0 1 1-2.6-6.4", "M21 3v6h-6"],
|
| 31 |
+
chevron: ["M9 6l6 6-6 6"],
|
| 32 |
+
camera: ["M3 7h3l2-3h8l2 3h3v13H3z", "M12 17a4 4 0 1 0 0-8 4 4 0 0 0 0 8z"],
|
| 33 |
+
external: ["M14 3h7v7", "M21 3l-9 9", "M21 14v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5"],
|
| 34 |
+
trash: ["M3 6h18", "M8 6V4h8v2", "M19 6l-1 14H6L5 6"],
|
| 35 |
+
user: ["M20 21v-1a7 7 0 0 0-14 0v1", "M12 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8z"],
|
| 36 |
+
tag: ["M20.6 13.4 12 22l-9-9V4h9z", "M7.5 7.5h.01"],
|
| 37 |
+
code: ["M16 18l6-6-6-6", "M8 6l-6 6 6 6"]
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
export function Icon({ name, size = 16, stroke = 1.8 }) {
|
| 41 |
+
const paths = PATHS[name] || PATHS.file;
|
| 42 |
+
return html`<svg
|
| 43 |
+
width=${size}
|
| 44 |
+
height=${size}
|
| 45 |
+
viewBox="0 0 24 24"
|
| 46 |
+
fill="none"
|
| 47 |
+
stroke="currentColor"
|
| 48 |
+
stroke-width=${stroke}
|
| 49 |
+
stroke-linecap="round"
|
| 50 |
+
stroke-linejoin="round"
|
| 51 |
+
aria-hidden="true"
|
| 52 |
+
>${paths.map((d, i) => html`<path key=${i} d=${d}></path>`)}</svg>`;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
// ---------------------------------------------------------------------------
|
| 56 |
+
// Brand
|
| 57 |
+
// ---------------------------------------------------------------------------
|
| 58 |
+
|
| 59 |
+
export function Mark({ size = 32 }) {
|
| 60 |
+
return html`<div class="mark" style=${{ width: size + "px", height: size + "px" }} aria-label="Explication">
|
| 61 |
+
<div class="mark-lines"><span></span><span></span><span></span></div>
|
| 62 |
+
</div>`;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
export function Brand({ small = false }) {
|
| 66 |
+
return html`<div class="brand">
|
| 67 |
+
<${Mark} size=${small ? 28 : 32} />
|
| 68 |
+
<div>
|
| 69 |
+
<div class="brand-name" style=${{ fontSize: small ? "17px" : "19px" }}>Explication</div>
|
| 70 |
+
${!small && html`<div class="brand-sub">GCSE English Literature</div>`}
|
| 71 |
+
</div>
|
| 72 |
+
</div>`;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
// ---------------------------------------------------------------------------
|
| 76 |
+
// Navigation
|
| 77 |
+
// ---------------------------------------------------------------------------
|
| 78 |
+
|
| 79 |
+
export const SECTIONS = [
|
| 80 |
+
{ id: "dashboard", title: "Today", group: "Progress", icon: "home" },
|
| 81 |
+
{ id: "chat", title: "Chat", group: "Write", icon: "chat" },
|
| 82 |
+
{ id: "coach", title: "Paragraph coach", group: "Write", icon: "pen" },
|
| 83 |
+
{ id: "essay", title: "Essay", group: "Write", icon: "book" },
|
| 84 |
+
{ id: "improve", title: "Improve", group: "Write", icon: "sparkle" },
|
| 85 |
+
{ id: "poetry", title: "Unseen poetry", group: "Study", icon: "feather" },
|
| 86 |
+
{ id: "modelAnswer", title: "Model answers", group: "Study", icon: "file" },
|
| 87 |
+
{ id: "mockExam", title: "Mock exam", group: "Study", icon: "clock" },
|
| 88 |
+
{ id: "process", title: "Process log", group: "Study", icon: "list" },
|
| 89 |
+
{ id: "settings", title: "Settings", group: "Tools", icon: "settings" },
|
| 90 |
+
{ id: "pricing", title: "Plans", group: "Account", icon: "tag" },
|
| 91 |
+
{ id: "account", title: "Account", group: "Account", icon: "user" },
|
| 92 |
+
{ id: "developer", title: "Developer", group: "Account", icon: "code" }
|
| 93 |
+
];
|
| 94 |
+
|
| 95 |
+
const GROUPS = ["Progress", "Write", "Study", "Tools", "Account"];
|
| 96 |
+
|
| 97 |
+
function NavList({ current, onNavigate }) {
|
| 98 |
+
const app = useApp();
|
| 99 |
+
const cloud = useCloud();
|
| 100 |
+
return html`<div class="nav">
|
| 101 |
+
${GROUPS.map(
|
| 102 |
+
(group) => html`<div class="nav-group" key=${group}>
|
| 103 |
+
<div class="nav-label">${group}</div>
|
| 104 |
+
${SECTIONS.filter((s) => s.group === group && (s.id !== "developer" || cloud.isDev)).map(
|
| 105 |
+
(s) => html`<button
|
| 106 |
+
key=${s.id}
|
| 107 |
+
class=${"nav-row" + (current === s.id ? " active" : "")}
|
| 108 |
+
onClick=${() => onNavigate(s.id)}
|
| 109 |
+
>
|
| 110 |
+
<${Icon} name=${s.icon} />
|
| 111 |
+
<span>${s.title}</span>
|
| 112 |
+
${current === s.id && html`<i class="dot"></i>`}
|
| 113 |
+
</button>`
|
| 114 |
+
)}
|
| 115 |
+
</div>`
|
| 116 |
+
)}
|
| 117 |
+
<div class="side-card">
|
| 118 |
+
<div class="row">
|
| 119 |
+
<span class="mini-label">Review</span>
|
| 120 |
+
<${Icon} name="lock" size=${11} />
|
| 121 |
+
</div>
|
| 122 |
+
<div class="name">Rule-based · offline</div>
|
| 123 |
+
<div class="meta">Marks in this browser. No upload.</div>
|
| 124 |
+
</div>
|
| 125 |
+
<div class="side-foot">
|
| 126 |
+
<${Icon} name="lock" size=${12} />
|
| 127 |
+
<span>Your drafts stay in this browser. An account is only for plans and downloads.</span>
|
| 128 |
+
</div>
|
| 129 |
+
</div>`;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
export function Sidebar({ current, onNavigate }) {
|
| 133 |
+
return html`<aside class="sidebar">
|
| 134 |
+
<div class="sidebar-head">
|
| 135 |
+
<${Brand} />
|
| 136 |
+
<button class="side-cta" onClick=${() => onNavigate("coach")}>
|
| 137 |
+
<${Icon} name="plus" size=${15} /> New feedback
|
| 138 |
+
</button>
|
| 139 |
+
</div>
|
| 140 |
+
<${NavList} current=${current} onNavigate=${onNavigate} />
|
| 141 |
+
</aside>`;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
export function Drawer({ current, onNavigate, onClose }) {
|
| 145 |
+
useEffect(() => {
|
| 146 |
+
const onKey = (e) => e.key === "Escape" && onClose();
|
| 147 |
+
window.addEventListener("keydown", onKey);
|
| 148 |
+
return () => window.removeEventListener("keydown", onKey);
|
| 149 |
+
}, [onClose]);
|
| 150 |
+
return html`<${React.Fragment}>
|
| 151 |
+
<div class="scrim" onClick=${onClose}></div>
|
| 152 |
+
<div class="drawer">
|
| 153 |
+
<div class="sidebar-head">
|
| 154 |
+
<div class="row between">
|
| 155 |
+
<${Brand} small=${true} />
|
| 156 |
+
<button class="icon-btn" onClick=${onClose} aria-label="Close menu"><${Icon} name="x" /></button>
|
| 157 |
+
</div>
|
| 158 |
+
<button class="side-cta" onClick=${() => { onNavigate("coach"); onClose(); }}>
|
| 159 |
+
<${Icon} name="plus" size=${15} /> New feedback
|
| 160 |
+
</button>
|
| 161 |
+
</div>
|
| 162 |
+
<${NavList} current=${current} onNavigate=${(id) => { onNavigate(id); onClose(); }} />
|
| 163 |
+
</div>
|
| 164 |
+
<//>`;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
export function TopBar({ section, onMenu, onNavigate }) {
|
| 168 |
+
const app = useApp();
|
| 169 |
+
const engine = useEngine();
|
| 170 |
+
const cloud = useCloud();
|
| 171 |
+
const title = (SECTIONS.find((s) => s.id === section) || SECTIONS[0]).title;
|
| 172 |
+
return html`<header class="topbar">
|
| 173 |
+
<button class="icon-btn menu-btn" onClick=${onMenu} aria-label="Open menu"><${Icon} name="menu" size=${18} /></button>
|
| 174 |
+
<h1>${title}</h1>
|
| 175 |
+
<div class="spacer"></div>
|
| 176 |
+
<span class="pill green" title="Credits">✦ ${app.credits}</span>
|
| 177 |
+
<button class="status-pill ${engine.canGenerate ? "ready" : ""}" onClick=${() => onNavigate("settings")} title="Model status">
|
| 178 |
+
<i class="dot"></i>${engine.canGenerate ? "Model ready" : "Rules"}
|
| 179 |
+
</button>
|
| 180 |
+
${cloud.user
|
| 181 |
+
? html`<button class="account-chip" onClick=${() => onNavigate("account")} title=${cloud.user.email}>
|
| 182 |
+
<span class="avatar">${String(cloud.user.email || "?").slice(0, 1).toUpperCase()}</span>
|
| 183 |
+
<span class="who">${cloud.plan ? cloud.plan.name : "No plan"}</span>
|
| 184 |
+
</button>`
|
| 185 |
+
: html`<button class="btn small" onClick=${() => onNavigate("account")}>Sign in</button>`}
|
| 186 |
+
<button class="icon-btn" onClick=${() => onNavigate("coach")} aria-label="New feedback"><${Icon} name="plus" size=${17} /></button>
|
| 187 |
+
</header>`;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
// ---------------------------------------------------------------------------
|
| 191 |
+
// Small pieces
|
| 192 |
+
// ---------------------------------------------------------------------------
|
| 193 |
+
|
| 194 |
+
export function Notice({ kind = "info", children }) {
|
| 195 |
+
return html`<div class=${"notice " + kind}><${Icon} name=${kind === "error" ? "x" : "lock"} size=${12} /> <div>${children}</div></div>`;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
export function Pill({ children, tone = "neutral" }) {
|
| 199 |
+
return html`<span class=${"pill " + tone}>${children}</span>`;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
export function ScoreRing({ total, max }) {
|
| 203 |
+
const pct = max ? Math.round((total / max) * 100) : 0;
|
| 204 |
+
return html`<div class="ring" style=${{ "--pct": pct }}>
|
| 205 |
+
<div class="num">${total}</div>
|
| 206 |
+
<div class="den">/${max}</div>
|
| 207 |
+
</div>`;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
export function CriterionList({ criteria }) {
|
| 211 |
+
return html`<div>
|
| 212 |
+
${criteria.map(
|
| 213 |
+
(c) => html`<div class="criterion" key=${c.id}>
|
| 214 |
+
<div class="head">
|
| 215 |
+
<span class="name">${c.title}</span>
|
| 216 |
+
<span class="score">${c.score}/${c.max}</span>
|
| 217 |
+
</div>
|
| 218 |
+
<div class="bar"><i style=${{ width: (c.max ? (c.score / c.max) * 100 : 0) + "%" }}></i></div>
|
| 219 |
+
${c.note && html`<div class="note">${c.note}</div>`}
|
| 220 |
+
</div>`
|
| 221 |
+
)}
|
| 222 |
+
</div>`;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
export function FeedbackPanel({ feedback, onSave, saved }) {
|
| 226 |
+
if (!feedback) {
|
| 227 |
+
return html`<div class="card empty">
|
| 228 |
+
<${Mark} size=${36} />
|
| 229 |
+
<div style=${{ fontSize: "12px", maxWidth: "280px", margin: "0 auto", lineHeight: 1.55 }}>
|
| 230 |
+
Mark your writing and the feedback appears here: a mark for every criterion, then one thing to change.
|
| 231 |
+
</div>
|
| 232 |
+
</div>`;
|
| 233 |
+
}
|
| 234 |
+
return html`<div class="card fade-in">
|
| 235 |
+
<div class="row between" style=${{ alignItems: "flex-start" }}>
|
| 236 |
+
<div class="score-card">
|
| 237 |
+
<${ScoreRing} total=${feedback.total} max=${feedback.max} />
|
| 238 |
+
<div>
|
| 239 |
+
<div class="eyebrow">${feedback.engine === "model" ? "Model mark" : "Offline review"}</div>
|
| 240 |
+
<div style=${{ fontFamily: "var(--serif)", fontSize: "18px", fontWeight: 600, marginTop: "2px" }}>
|
| 241 |
+
${feedback.total >= feedback.max * 0.8 ? "Strong work." : feedback.total >= feedback.max * 0.55 ? "Solid, with room to sharpen." : "A start to build on."}
|
| 242 |
+
</div>
|
| 243 |
+
<div class="tiny faint">${feedback.criteria.reduce((s, c) => s + c.max, 0)} marks available</div>
|
| 244 |
+
</div>
|
| 245 |
+
</div>
|
| 246 |
+
${onSave &&
|
| 247 |
+
html`<button class="btn small" onClick=${onSave} disabled=${saved}>
|
| 248 |
+
<${Icon} name="check" size=${12} /> ${saved ? "Saved" : "Save"}
|
| 249 |
+
</button>`}
|
| 250 |
+
</div>
|
| 251 |
+
|
| 252 |
+
<div class="divider"></div>
|
| 253 |
+
<${CriterionList} criteria=${feedback.criteria} />
|
| 254 |
+
|
| 255 |
+
${feedback.strengths.length > 0 &&
|
| 256 |
+
html`<div class="stack" style=${{ marginTop: "12px" }}>
|
| 257 |
+
<div class="callout green"><strong>What works.</strong> ${feedback.strengths.join(" ")}</div>
|
| 258 |
+
</div>`}
|
| 259 |
+
|
| 260 |
+
${feedback.improvements.length > 0 &&
|
| 261 |
+
html`<div class="stack" style=${{ marginTop: "8px" }}>
|
| 262 |
+
<div class="callout amber"><strong>Next. </strong>${feedback.improvements.join(" ")}</div>
|
| 263 |
+
</div>`}
|
| 264 |
+
|
| 265 |
+
${feedback.nextStep && html`<div class="callout blue" style=${{ marginTop: "8px" }}><strong>Do this once. </strong>${feedback.nextStep}</div>`}
|
| 266 |
+
|
| 267 |
+
${feedback.quotes && feedback.quotes.length > 0 &&
|
| 268 |
+
html`<div style=${{ marginTop: "14px" }}>
|
| 269 |
+
<div class="eyebrow" style=${{ marginBottom: "6px" }}>Quotations checked</div>
|
| 270 |
+
<div class="stack">
|
| 271 |
+
${feedback.quotes.map(
|
| 272 |
+
(q, i) => html`<div class="row" key=${i} style=${{ alignItems: "flex-start", fontSize: "11px" }}>
|
| 273 |
+
<span class="pill ${q.inExtract === false ? "warn" : "green"}">${q.inExtract === false ? "Check" : q.inExtract === true ? "Found" : "No extract"}</span>
|
| 274 |
+
<span class="muted" style=${{ flex: 1 }}>“${q.text}” ${q.note ? "— " + q.note : ""}</span>
|
| 275 |
+
</div>`
|
| 276 |
+
)}
|
| 277 |
+
</div>
|
| 278 |
+
</div>`}
|
| 279 |
+
</div>`;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
// ---------------------------------------------------------------------------
|
| 283 |
+
// Hooks
|
| 284 |
+
// ---------------------------------------------------------------------------
|
| 285 |
+
|
| 286 |
+
export function usePersistent(key, initial) {
|
| 287 |
+
const [value, setValue] = useState(() => {
|
| 288 |
+
try {
|
| 289 |
+
const raw = localStorage.getItem(key);
|
| 290 |
+
return raw ? JSON.parse(raw) : initial;
|
| 291 |
+
} catch {
|
| 292 |
+
return initial;
|
| 293 |
+
}
|
| 294 |
+
});
|
| 295 |
+
useEffect(() => {
|
| 296 |
+
try {
|
| 297 |
+
localStorage.setItem(key, JSON.stringify(value));
|
| 298 |
+
} catch {
|
| 299 |
+
// ignore
|
| 300 |
+
}
|
| 301 |
+
}, [key, value]);
|
| 302 |
+
return [value, setValue];
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
export function download(filename, text, type = "text/markdown") {
|
| 306 |
+
const blob = new Blob([text], { type });
|
| 307 |
+
const url = URL.createObjectURL(blob);
|
| 308 |
+
const a = document.createElement("a");
|
| 309 |
+
a.href = url;
|
| 310 |
+
a.download = filename;
|
| 311 |
+
document.body.appendChild(a);
|
| 312 |
+
a.click();
|
| 313 |
+
a.remove();
|
| 314 |
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
export { wordCount, levelTitle };
|
js/config.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Deployment-wide defaults. The server address and public key entered in the
|
| 2 |
+
// in-app setup screen are stored in this browser too; values here apply to
|
| 3 |
+
// every visitor of this copy of the site.
|
| 4 |
+
//
|
| 5 |
+
// Fill these in before you share the folder, or leave them empty and use the
|
| 6 |
+
// "Connect Supabase" screen on first open.
|
| 7 |
+
window.EXPLICATION_CONFIG = {
|
| 8 |
+
supabaseUrl: "https://jjybpqlrdmioiccejnti.supabase.co",
|
| 9 |
+
supabaseAnonKey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImpqeWJwcWxyZG1pb2ljY2VqbnRpIiwicm9sZSI6ImFub24iLCJpYXQiOjE3OTU1NDg3MTMsImV4cCI6MjExMTEyNDcxM30.h8nSMsKH0Oee5jiLJD_1GyLiAd4tsB9xT683d5gUMGA"
|
| 10 |
+
};
|
js/copy.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { createContext, html, useContext, useMemo, useRef, useState } from "./runtime.js";
|
| 2 |
+
import { useCloud } from "./cloud.js";
|
| 3 |
+
|
| 4 |
+
// ---------------------------------------------------------------------------
|
| 5 |
+
// Editable copy.
|
| 6 |
+
//
|
| 7 |
+
// Wrap any wording on the page in <Copy id="...">. When the developer turns
|
| 8 |
+
// edit mode on, each wrapped phrase becomes editable in place; saving writes
|
| 9 |
+
// the new wording to Supabase, so every visitor sees it. A key that has never
|
| 10 |
+
// been edited falls back to the wording written in the code.
|
| 11 |
+
// ---------------------------------------------------------------------------
|
| 12 |
+
|
| 13 |
+
const EditContext = createContext({ editing: false, setEditing: () => {} });
|
| 14 |
+
|
| 15 |
+
export function EditModeProvider({ children }) {
|
| 16 |
+
const [editing, setEditing] = useState(false);
|
| 17 |
+
const value = useMemo(() => ({ editing, setEditing }), [editing]);
|
| 18 |
+
return html`<${EditContext.Provider} value=${value}>${children}<//>`;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
export function useEditMode() {
|
| 22 |
+
return useContext(EditContext);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
function toText(children) {
|
| 26 |
+
if (typeof children === "string") return children;
|
| 27 |
+
if (Array.isArray(children)) return children.map(toText).join("");
|
| 28 |
+
if (children == null || children === false) return "";
|
| 29 |
+
return String(children);
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
export function useCopyValue(id, fallback) {
|
| 33 |
+
const cloud = useCloud();
|
| 34 |
+
const saved = cloud.content[id];
|
| 35 |
+
return saved != null && saved !== "" ? saved : fallback;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
export function Copy({ id, as = "span", className = "", children }) {
|
| 39 |
+
const cloud = useCloud();
|
| 40 |
+
const { editing } = useEditMode();
|
| 41 |
+
const fallback = toText(children);
|
| 42 |
+
const saved = cloud.content[id];
|
| 43 |
+
const value = saved != null && saved !== "" ? saved : fallback;
|
| 44 |
+
const ref = useRef(null);
|
| 45 |
+
|
| 46 |
+
const onBlur = async (event) => {
|
| 47 |
+
if (!editing) return;
|
| 48 |
+
const text = (event.currentTarget.innerText || "").replace(/\s+/g, " ").trim();
|
| 49 |
+
if (!text || text === value) return;
|
| 50 |
+
try {
|
| 51 |
+
await cloud.setContent(id, text);
|
| 52 |
+
cloud.flash("Saved — everyone will see this.");
|
| 53 |
+
} catch (err) {
|
| 54 |
+
cloud.flash(err && err.message ? err.message : "Could not save that change.");
|
| 55 |
+
}
|
| 56 |
+
};
|
| 57 |
+
|
| 58 |
+
const Tag = as;
|
| 59 |
+
return html`<${Tag}
|
| 60 |
+
ref=${ref}
|
| 61 |
+
className=${className + (editing ? " edit-target" : "")}
|
| 62 |
+
contentEditable=${editing ? "true" : undefined}
|
| 63 |
+
suppressContentEditableWarning=${true}
|
| 64 |
+
onBlur=${onBlur}
|
| 65 |
+
spellCheck=${false}
|
| 66 |
+
data-copy=${id}
|
| 67 |
+
title=${editing ? "Type to change this wording. It saves for everyone." : undefined}
|
| 68 |
+
>${value}<//>`;
|
| 69 |
+
}
|
js/engine.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, html } from "./runtime.js";
|
| 2 |
+
import { useCloud } from "./cloud.js";
|
| 3 |
+
|
| 4 |
+
export const WEB_MODELS = [
|
| 5 |
+
{
|
| 6 |
+
id: "Qwen2.5-0.5B-Instruct-q4f16_1-MLC",
|
| 7 |
+
name: "Qwen2.5 0.5B",
|
| 8 |
+
size: "~0.4 GB",
|
| 9 |
+
note: "Quickest to load. Enough for short feedback."
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
id: "Qwen2.5-1.5B-Instruct-q4f16_1-MLC",
|
| 13 |
+
name: "Qwen2.5 1.5B",
|
| 14 |
+
size: "~1.1 GB",
|
| 15 |
+
note: "The default when WebGPU is available."
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
id: "Qwen2.5-3B-Instruct-q4f16_1-MLC",
|
| 19 |
+
name: "Qwen2.5 3B",
|
| 20 |
+
size: "~2.0 GB",
|
| 21 |
+
note: "Better analysis; needs a stronger GPU."
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
id: "Qwen2.5-7B-Instruct-q4f16_1-MLC",
|
| 25 |
+
name: "Qwen2.5 7B",
|
| 26 |
+
size: "~4.5 GB",
|
| 27 |
+
note: "Best feedback here, but only on a capable GPU."
|
| 28 |
+
}
|
| 29 |
+
];
|
| 30 |
+
|
| 31 |
+
const EngineContext = createContext(null);
|
| 32 |
+
|
| 33 |
+
function readEndpoint(key) {
|
| 34 |
+
try {
|
| 35 |
+
return localStorage.getItem(key) || "";
|
| 36 |
+
} catch {
|
| 37 |
+
return "";
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
export function EngineProvider({ children }) {
|
| 42 |
+
const cloud = useCloud();
|
| 43 |
+
const [status, setStatus] = useState("idle"); // idle | loading | ready | error
|
| 44 |
+
const [progress, setProgress] = useState(0);
|
| 45 |
+
const [progressText, setProgressText] = useState("");
|
| 46 |
+
const [error, setError] = useState("");
|
| 47 |
+
const [loadedModel, setLoadedModel] = useState("");
|
| 48 |
+
const engineRef = useRef(null);
|
| 49 |
+
const webgpu = typeof navigator !== "undefined" && !!navigator.gpu;
|
| 50 |
+
|
| 51 |
+
// The developer's hosted models (paid for with the plan's budget), chosen here.
|
| 52 |
+
const [hostedId, setHostedId] = useState(() => readEndpoint("explication.hosted.model"));
|
| 53 |
+
const setHostedModel = useCallback((id) => {
|
| 54 |
+
try {
|
| 55 |
+
localStorage.setItem("explication.hosted.model", id || "");
|
| 56 |
+
} catch {
|
| 57 |
+
// ignore
|
| 58 |
+
}
|
| 59 |
+
setHostedId(id || "");
|
| 60 |
+
}, []);
|
| 61 |
+
const hosted = useMemo(
|
| 62 |
+
() => cloud.models.find((m) => m.id === hostedId && m.enabled !== false) || null,
|
| 63 |
+
[cloud.models, hostedId]
|
| 64 |
+
);
|
| 65 |
+
const hostedReady = !!hosted && !!hosted.endpoint_url && cloud.canHost(hosted);
|
| 66 |
+
|
| 67 |
+
const unload = useCallback(async () => {
|
| 68 |
+
try {
|
| 69 |
+
if (engineRef.current && engineRef.current.unload) await engineRef.current.unload();
|
| 70 |
+
} catch {
|
| 71 |
+
// ignore
|
| 72 |
+
}
|
| 73 |
+
engineRef.current = null;
|
| 74 |
+
setLoadedModel("");
|
| 75 |
+
setStatus("idle");
|
| 76 |
+
setProgress(0);
|
| 77 |
+
setProgressText("");
|
| 78 |
+
}, []);
|
| 79 |
+
|
| 80 |
+
const load = useCallback(async (modelId) => {
|
| 81 |
+
const chosen = cloud.models.find((m) => m.id === modelId);
|
| 82 |
+
if (chosen && !cloud.canDownload(chosen.min_tier)) {
|
| 83 |
+
setStatus("error");
|
| 84 |
+
setError(`${chosen.name} needs a plan that includes it. See Plans, or keep using the free model.`);
|
| 85 |
+
return;
|
| 86 |
+
}
|
| 87 |
+
if (!navigator.gpu) {
|
| 88 |
+
setStatus("error");
|
| 89 |
+
setError("This browser has no WebGPU, so it cannot run a model locally. Connect an OpenAI-compatible endpoint in Settings instead.");
|
| 90 |
+
return;
|
| 91 |
+
}
|
| 92 |
+
setStatus("loading");
|
| 93 |
+
setError("");
|
| 94 |
+
setProgress(0);
|
| 95 |
+
setProgressText("Preparing the model…");
|
| 96 |
+
try {
|
| 97 |
+
const webllm = await import("https://esm.sh/@mlc-ai/web-llm@0.2.88");
|
| 98 |
+
const engine = await webllm.CreateMLCEngine(modelId, {
|
| 99 |
+
initProgressCallback: (report) => {
|
| 100 |
+
setProgressText(report.text || "Loading…");
|
| 101 |
+
const match = /(\d+)%/.exec(report.text || "");
|
| 102 |
+
if (match) setProgress(Number(match[1]) / 100);
|
| 103 |
+
}
|
| 104 |
+
});
|
| 105 |
+
engineRef.current = engine;
|
| 106 |
+
setLoadedModel(modelId);
|
| 107 |
+
setStatus("ready");
|
| 108 |
+
setProgress(1);
|
| 109 |
+
setProgressText("Model ready.");
|
| 110 |
+
} catch (err) {
|
| 111 |
+
setStatus("error");
|
| 112 |
+
setError(err && err.message ? err.message : "The model could not be loaded.");
|
| 113 |
+
}
|
| 114 |
+
}, [cloud.models, cloud.plan]);
|
| 115 |
+
|
| 116 |
+
const [endpoint, setEndpointState] = useState(() => ({
|
| 117 |
+
baseUrl: readEndpoint("explication.endpoint.baseUrl").trim(),
|
| 118 |
+
model: readEndpoint("explication.endpoint.model").trim(),
|
| 119 |
+
key: readEndpoint("explication.endpoint.key").trim()
|
| 120 |
+
}));
|
| 121 |
+
|
| 122 |
+
const setEndpoint = useCallback((next) => {
|
| 123 |
+
const clean = {
|
| 124 |
+
baseUrl: (next.baseUrl || "").trim(),
|
| 125 |
+
model: (next.model || "").trim(),
|
| 126 |
+
key: (next.key || "").trim()
|
| 127 |
+
};
|
| 128 |
+
try {
|
| 129 |
+
localStorage.setItem("explication.endpoint.baseUrl", clean.baseUrl);
|
| 130 |
+
localStorage.setItem("explication.endpoint.model", clean.model);
|
| 131 |
+
localStorage.setItem("explication.endpoint.key", clean.key);
|
| 132 |
+
} catch {
|
| 133 |
+
// ignore quota errors
|
| 134 |
+
}
|
| 135 |
+
setEndpointState(clean);
|
| 136 |
+
}, []);
|
| 137 |
+
|
| 138 |
+
const hasEndpoint = !!endpoint.baseUrl && !!endpoint.model;
|
| 139 |
+
|
| 140 |
+
/**
|
| 141 |
+
* Streams a reply. Returns the full text.
|
| 142 |
+
*/
|
| 143 |
+
const chat = useCallback(
|
| 144 |
+
async (messages, onToken) => {
|
| 145 |
+
if (hasEndpoint) {
|
| 146 |
+
const base = endpoint.baseUrl.replace(/\/+$/, "");
|
| 147 |
+
const res = await fetch(`${base}/chat/completions`, {
|
| 148 |
+
method: "POST",
|
| 149 |
+
headers: {
|
| 150 |
+
"Content-Type": "application/json",
|
| 151 |
+
...(endpoint.key ? { Authorization: `Bearer ${endpoint.key}` } : {})
|
| 152 |
+
},
|
| 153 |
+
body: JSON.stringify({ model: endpoint.model, messages, stream: true, temperature: 0.4 })
|
| 154 |
+
});
|
| 155 |
+
if (!res.ok) throw new Error(`The endpoint returned ${res.status}. Check the URL, model and key in Settings.`);
|
| 156 |
+
if (!res.body) {
|
| 157 |
+
const data = await res.json();
|
| 158 |
+
const text = data?.choices?.[0]?.message?.content || "";
|
| 159 |
+
if (onToken) onToken(text);
|
| 160 |
+
return text;
|
| 161 |
+
}
|
| 162 |
+
const reader = res.body.getReader();
|
| 163 |
+
const decoder = new TextDecoder();
|
| 164 |
+
let buffer = "";
|
| 165 |
+
let full = "";
|
| 166 |
+
while (true) {
|
| 167 |
+
const { value, done } = await reader.read();
|
| 168 |
+
if (done) break;
|
| 169 |
+
buffer += decoder.decode(value, { stream: true });
|
| 170 |
+
const lines = buffer.split("\n");
|
| 171 |
+
buffer = lines.pop() || "";
|
| 172 |
+
for (const line of lines) {
|
| 173 |
+
const trimmed = line.trim();
|
| 174 |
+
if (!trimmed.startsWith("data:")) continue;
|
| 175 |
+
const payload = trimmed.slice(5).trim();
|
| 176 |
+
if (payload === "[DONE]") continue;
|
| 177 |
+
try {
|
| 178 |
+
const json = JSON.parse(payload);
|
| 179 |
+
const delta = json?.choices?.[0]?.delta?.content || "";
|
| 180 |
+
if (delta) {
|
| 181 |
+
full += delta;
|
| 182 |
+
onToken && onToken(full);
|
| 183 |
+
}
|
| 184 |
+
} catch {
|
| 185 |
+
// A partial SSE line; wait for the next chunk.
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
return full;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
if (hostedReady) {
|
| 193 |
+
return cloud.hostedChat(hosted, messages, onToken);
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
if (!engineRef.current) {
|
| 197 |
+
throw new Error("No model is loaded. Open Settings to load a browser model, connect an endpoint or pick a hosted model.");
|
| 198 |
+
}
|
| 199 |
+
const stream = await engineRef.current.chat.completions.create({
|
| 200 |
+
messages,
|
| 201 |
+
temperature: 0.4,
|
| 202 |
+
stream: true
|
| 203 |
+
});
|
| 204 |
+
let full = "";
|
| 205 |
+
for await (const chunk of stream) {
|
| 206 |
+
const delta = chunk?.choices?.[0]?.delta?.content || "";
|
| 207 |
+
if (delta) {
|
| 208 |
+
full += delta;
|
| 209 |
+
onToken && onToken(full);
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
return full;
|
| 213 |
+
},
|
| 214 |
+
[hasEndpoint, endpoint, hostedReady, hosted, cloud]
|
| 215 |
+
);
|
| 216 |
+
|
| 217 |
+
const value = useMemo(
|
| 218 |
+
() => ({
|
| 219 |
+
status,
|
| 220 |
+
progress,
|
| 221 |
+
progressText,
|
| 222 |
+
error,
|
| 223 |
+
loadedModel,
|
| 224 |
+
webgpu,
|
| 225 |
+
endpoint,
|
| 226 |
+
hasEndpoint,
|
| 227 |
+
models: cloud.models,
|
| 228 |
+
hosted,
|
| 229 |
+
hostedId,
|
| 230 |
+
hostedReady,
|
| 231 |
+
setHostedModel,
|
| 232 |
+
canGenerate: hasEndpoint || status === "ready" || hostedReady,
|
| 233 |
+
load,
|
| 234 |
+
unload,
|
| 235 |
+
chat,
|
| 236 |
+
setEndpoint
|
| 237 |
+
}),
|
| 238 |
+
[
|
| 239 |
+
status,
|
| 240 |
+
progress,
|
| 241 |
+
progressText,
|
| 242 |
+
error,
|
| 243 |
+
loadedModel,
|
| 244 |
+
webgpu,
|
| 245 |
+
endpoint,
|
| 246 |
+
hasEndpoint,
|
| 247 |
+
cloud.models,
|
| 248 |
+
hosted,
|
| 249 |
+
hostedId,
|
| 250 |
+
hostedReady,
|
| 251 |
+
setHostedModel,
|
| 252 |
+
load,
|
| 253 |
+
unload,
|
| 254 |
+
chat,
|
| 255 |
+
setEndpoint
|
| 256 |
+
]
|
| 257 |
+
);
|
| 258 |
+
|
| 259 |
+
return html`<${EngineContext.Provider} value=${value}>${children}<//>`;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
export function useEngine() {
|
| 263 |
+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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Rubric, credits and the deterministic reviewer.
|
| 2 |
+
// The reviewer is rule-based and runs with no model, so every tool works
|
| 3 |
+
// offline. When a model is connected, marking.js can also build the JSON prompt
|
| 4 |
+
// used by the AI marker.
|
| 5 |
+
|
| 6 |
+
export const PARAGRAPH_RUBRIC = [
|
| 7 |
+
{
|
| 8 |
+
id: "point",
|
| 9 |
+
title: "Point",
|
| 10 |
+
max: 2,
|
| 11 |
+
guidance:
|
| 12 |
+
"A clear, focused answer to the question that uses the text's terms. 2 = precise and relevant; 1 = general or partly off-question; 0 = missing."
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
id: "evidence",
|
| 16 |
+
title: "Evidence",
|
| 17 |
+
max: 2,
|
| 18 |
+
guidance:
|
| 19 |
+
"A short, accurate quotation embedded in the sentence. 2 = accurate, concise and well chosen; 1 = present but vague, long or loosely used; 0 = none. A quotation missing from a partial extract is not penalised."
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
id: "method",
|
| 23 |
+
title: "Method",
|
| 24 |
+
max: 2,
|
| 25 |
+
guidance:
|
| 26 |
+
"Names a technique or a deliberate authorial choice (word class, imagery, structure, form). 2 = precise terminology; 1 = vague reference to language; 0 = none."
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
id: "effect",
|
| 30 |
+
title: "Effect",
|
| 31 |
+
max: 3,
|
| 32 |
+
guidance:
|
| 33 |
+
"Explains how the method shapes the reader's response, with a developed 'because'. 3 = layered, alternative reading; 2 = clear effect explained; 1 = asserted effect; 0 = none."
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
id: "link",
|
| 37 |
+
title: "Link",
|
| 38 |
+
max: 1,
|
| 39 |
+
guidance:
|
| 40 |
+
"Ties the paragraph back to the question or the text's wider ideas. 1 = explicit link; 0 = missing."
|
| 41 |
+
}
|
| 42 |
+
];
|
| 43 |
+
|
| 44 |
+
export const ESSAY_RUBRICS = {
|
| 45 |
+
introduction: [
|
| 46 |
+
{ id: "focus", title: "Focus", max: 2, guidance: "Directly answers the question with a shaped line of argument." },
|
| 47 |
+
{ id: "thesis", title: "Thesis", max: 2, guidance: "A clear overall argument that the essay will prove." }
|
| 48 |
+
],
|
| 49 |
+
body_1: [
|
| 50 |
+
{ id: "point", title: "Point", max: 2, guidance: "A topic sentence that advances the argument." },
|
| 51 |
+
{ id: "evidence", title: "Evidence", max: 2, guidance: "Up to three short, accurate quotations, embedded." },
|
| 52 |
+
{ id: "analysis", title: "Analysis", max: 2, guidance: "Method and effect developed together." }
|
| 53 |
+
],
|
| 54 |
+
body_2: [
|
| 55 |
+
{ id: "point", title: "Point", max: 2, guidance: "A topic sentence that advances the argument." },
|
| 56 |
+
{ id: "evidence", title: "Evidence", max: 2, guidance: "Up to three short, accurate quotations, embedded." },
|
| 57 |
+
{ id: "analysis", title: "Analysis", max: 2, guidance: "Method and effect developed together." }
|
| 58 |
+
],
|
| 59 |
+
body_3: [
|
| 60 |
+
{ id: "point", title: "Point", max: 2, guidance: "A topic sentence that advances the argument." },
|
| 61 |
+
{ id: "evidence", title: "Evidence", max: 2, guidance: "Up to three short, accurate quotations, embedded." },
|
| 62 |
+
{ id: "analysis", title: "Analysis", max: 2, guidance: "Method and effect developed together." }
|
| 63 |
+
],
|
| 64 |
+
conclusion: [
|
| 65 |
+
{ id: "return", title: "Return to question", max: 2, guidance: "Answers the question again, now that the evidence is in." },
|
| 66 |
+
{ id: "significance", title: "Wider significance", max: 2, guidance: "Connects to context, the whole text or a lasting idea." }
|
| 67 |
+
],
|
| 68 |
+
cohesion: [
|
| 69 |
+
{ id: "structure", title: "Structure", max: 2, guidance: "Paragraphs build in a deliberate order and signpost the argument." },
|
| 70 |
+
{ id: "thread", title: "Thread of argument", max: 2, guidance: "The same argument is developed throughout, not restated." }
|
| 71 |
+
]
|
| 72 |
+
};
|
| 73 |
+
|
| 74 |
+
export const ESSAY_PART_META = [
|
| 75 |
+
{ id: "introduction", title: "Introduction", short: "Intro" },
|
| 76 |
+
{ id: "body_1", title: "Body paragraph 1", short: "Body 1" },
|
| 77 |
+
{ id: "body_2", title: "Body paragraph 2", short: "Body 2" },
|
| 78 |
+
{ id: "body_3", title: "Body paragraph 3", short: "Body 3" },
|
| 79 |
+
{ id: "conclusion", title: "Conclusion", short: "Conclusion" },
|
| 80 |
+
{ id: "cohesion", title: "Cohesion (whole essay)", short: "Cohesion" }
|
| 81 |
+
];
|
| 82 |
+
|
| 83 |
+
export const CREDIT_COSTS = {
|
| 84 |
+
paragraphWriting: 20,
|
| 85 |
+
modelAnswer: 20,
|
| 86 |
+
essayDeep: 30,
|
| 87 |
+
mockExam: 40
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
export function creditsForParagraph(score) {
|
| 91 |
+
if (score >= 10) return 50;
|
| 92 |
+
if (score === 9) return 30;
|
| 93 |
+
if (score >= 7) return 15;
|
| 94 |
+
if (score >= 5) return 5;
|
| 95 |
+
return 0;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
export function creditsForEssay(score) {
|
| 99 |
+
if (score >= 29) return 200;
|
| 100 |
+
if (score >= 26) return 120;
|
| 101 |
+
if (score >= 21) return 60;
|
| 102 |
+
if (score >= 15) return 20;
|
| 103 |
+
return 0;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
export function streakMultiplier(days) {
|
| 107 |
+
if (days >= 14) return 1.4;
|
| 108 |
+
if (days >= 7) return 1.25;
|
| 109 |
+
if (days >= 3) return 1.1;
|
| 110 |
+
return 1;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
export function awardCredits(base, streakDays) {
|
| 114 |
+
if (base <= 0) return 0;
|
| 115 |
+
return Math.round(base * streakMultiplier(streakDays));
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
export function levelFor(totalEarned) {
|
| 119 |
+
if (totalEarned <= 0) return 1;
|
| 120 |
+
return Math.min(10, 1 + Math.floor(totalEarned / 150));
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
export function levelProgress(totalEarned) {
|
| 124 |
+
const level = levelFor(totalEarned);
|
| 125 |
+
if (level >= 10) return 1;
|
| 126 |
+
return (totalEarned - (level - 1) * 150) / 150;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
export function levelTitle(level) {
|
| 130 |
+
return (
|
| 131 |
+
[
|
| 132 |
+
"Starting out",
|
| 133 |
+
"Finding your voice",
|
| 134 |
+
"Close reader",
|
| 135 |
+
"Confident analyst",
|
| 136 |
+
"Sharp critic",
|
| 137 |
+
"Precise writer",
|
| 138 |
+
"Independent thinker",
|
| 139 |
+
"Grade 8 habit",
|
| 140 |
+
"Grade 9 habit",
|
| 141 |
+
"Examiner's eye"
|
| 142 |
+
][Math.min(9, Math.max(0, level - 1))]
|
| 143 |
+
);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
const DAY = 86400000;
|
| 147 |
+
|
| 148 |
+
export function streakLength(isoDays) {
|
| 149 |
+
if (!isoDays || isoDays.length === 0) return 0;
|
| 150 |
+
const days = [...new Set(isoDays)].sort().reverse();
|
| 151 |
+
const today = new Date();
|
| 152 |
+
const start = new Date(today.getFullYear(), today.getMonth(), today.getDate()).getTime();
|
| 153 |
+
const latest = new Date(days[0] + "T00:00:00").getTime();
|
| 154 |
+
if (latest !== start && latest !== start - DAY) return 0;
|
| 155 |
+
let streak = 0;
|
| 156 |
+
let expected = latest;
|
| 157 |
+
for (const iso of days) {
|
| 158 |
+
const t = new Date(iso + "T00:00:00").getTime();
|
| 159 |
+
if (t === expected) {
|
| 160 |
+
streak += 1;
|
| 161 |
+
expected -= DAY;
|
| 162 |
+
} else if (t < expected) break;
|
| 163 |
+
}
|
| 164 |
+
return streak;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
// ---------------------------------------------------------------------------
|
| 168 |
+
// Texts
|
| 169 |
+
// ---------------------------------------------------------------------------
|
| 170 |
+
|
| 171 |
+
export const TEXTS = [
|
| 172 |
+
{ id: "macbeth", title: "Macbeth", author: "William Shakespeare", kind: "Play" },
|
| 173 |
+
{ id: "christmas-carol", title: "A Christmas Carol", author: "Charles Dickens", kind: "Novel" },
|
| 174 |
+
{ id: "inspector-calls", title: "An Inspector Calls", author: "J. B. Priestley", kind: "Play" },
|
| 175 |
+
{ id: "jekyll-hyde", title: "Jekyll and Hyde", author: "R. L. Stevenson", kind: "Novel" },
|
| 176 |
+
{ id: "lord-flies", title: "Lord of the Flies", author: "William Golding", kind: "Novel" },
|
| 177 |
+
{ id: "power-conflict", title: "Power & Conflict poems", author: "AQA anthology", kind: "Poetry" },
|
| 178 |
+
{ id: "other", title: "Another text", author: "", kind: "Text" }
|
| 179 |
+
];
|
| 180 |
+
|
| 181 |
+
export const SUGGESTED_QUESTIONS = [
|
| 182 |
+
"How does Shakespeare present ambition in Macbeth?",
|
| 183 |
+
"How does Dickens present Scrooge as an outsider?",
|
| 184 |
+
"How does Priestley use the Inspector to challenge the Birlings?",
|
| 185 |
+
"How does Stevenson present duality in Jekyll and Hyde?",
|
| 186 |
+
"How does the writer use structure to build tension?"
|
| 187 |
+
];
|
| 188 |
+
|
| 189 |
+
// ---------------------------------------------------------------------------
|
| 190 |
+
// Text analysis
|
| 191 |
+
// ---------------------------------------------------------------------------
|
| 192 |
+
|
| 193 |
+
const DOUBLE_QUOTE = /[“"]([^”"]{2,220})[”"]/g;
|
| 194 |
+
const SINGLE_QUOTE = /(?:^|[\s(])[‘']([^’']{8,220})[’'](?=[\s.,;:!?)]|$)/g;
|
| 195 |
+
|
| 196 |
+
export function wordCount(text) {
|
| 197 |
+
return text.trim() ? text.trim().split(/\s+/).length : 0;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
export function sentenceList(text) {
|
| 201 |
+
return text
|
| 202 |
+
.replace(/\s+/g, " ")
|
| 203 |
+
.split(/(?<=[.!?])\s+/)
|
| 204 |
+
.map((s) => s.trim())
|
| 205 |
+
.filter(Boolean);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
export function normalise(text) {
|
| 209 |
+
return " " + text
|
| 210 |
+
.toLowerCase()
|
| 211 |
+
.replace(/[’‘]/g, "'")
|
| 212 |
+
.replace(/[“”]/g, '"')
|
| 213 |
+
.replace(/[^a-z0-9' ]+/g, " ")
|
| 214 |
+
.replace(/\s+/g, " ")
|
| 215 |
+
.trim() + " ";
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
const TECHNIQUES = [
|
| 219 |
+
"metaphor", "simile", "personification", "imagery", "semantic field", "juxtaposition",
|
| 220 |
+
"contrast", "repetition", "alliteration", "sibilance", "onomatopoeia", "hyperbole",
|
| 221 |
+
"oxymoron", "symbolism", "motif", "foreshadow", "dramatic irony", "soliloquy",
|
| 222 |
+
"stage direction", "aside", "enjambment", "caesura", "stanza", "rhyme", "rhythm",
|
| 223 |
+
"iambic", "short sentence", "long sentence", "listing", "rule of three",
|
| 224 |
+
"rhetorical question", "direct address", "dialect", "colloquial", "satire", "form",
|
| 225 |
+
"structure", "verb", "noun", "adjective", "adverb", "connotation", "tone", "voice"
|
| 226 |
+
];
|
| 227 |
+
|
| 228 |
+
const EFFECT_VERBS = [
|
| 229 |
+
"suggests", "suggesting", "conveys", "conveying", "creates", "creating", "implies",
|
| 230 |
+
"implying", "highlights", "emphasises", "emphasizes", "reveals", "revealing",
|
| 231 |
+
"reflects", "evokes", "illustrates", "demonstrates", "underscores", "presents",
|
| 232 |
+
"portrays", "exposes", "critiques", "challenges", "reinforces", "foreshadows",
|
| 233 |
+
"makes the reader", "allows the reader", "shows the reader"
|
| 234 |
+
];
|
| 235 |
+
|
| 236 |
+
const CAUSAL = ["because", "which", "therefore", "as a result", "so that", "in order to", "this creates", "allowing", "enabling", "meaning"];
|
| 237 |
+
|
| 238 |
+
const LINK_PHRASES = ["therefore", "overall", "this shows", "this suggests", "the wider", "context", "audience", "reader", "the text", "the play", "the novel"];
|
| 239 |
+
|
| 240 |
+
function findTechniques(lower) {
|
| 241 |
+
return TECHNIQUES.filter((t) => lower.includes(t));
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
function findEffectVerbs(lower) {
|
| 245 |
+
return EFFECT_VERBS.filter((v) => lower.includes(v));
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
function questionWords(question) {
|
| 249 |
+
const stop = new Set(["how", "does", "the", "and", "in", "of", "to", "a", "an", "is", "are", "what", "why", "writer", "present", "use", "using", "explain"]);
|
| 250 |
+
return question
|
| 251 |
+
.toLowerCase()
|
| 252 |
+
.replace(/[^a-z0-9 ]+/g, " ")
|
| 253 |
+
.split(/\s+/)
|
| 254 |
+
.filter((w) => w.length > 2 && !stop.has(w));
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
function overlap(text, words) {
|
| 258 |
+
const lower = " " + text.toLowerCase() + " ";
|
| 259 |
+
return words.filter((w) => lower.includes(w)).length;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
export function extractQuotes(text) {
|
| 263 |
+
const found = [];
|
| 264 |
+
let match;
|
| 265 |
+
DOUBLE_QUOTE.lastIndex = 0;
|
| 266 |
+
while ((match = DOUBLE_QUOTE.exec(text)) !== null) found.push(match[1].trim());
|
| 267 |
+
SINGLE_QUOTE.lastIndex = 0;
|
| 268 |
+
while ((match = SINGLE_QUOTE.exec(text)) !== null) found.push(match[1].trim());
|
| 269 |
+
return found.filter((q) => q.length > 1);
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
export function checkQuotes(text, extract) {
|
| 273 |
+
const quotes = extractQuotes(text);
|
| 274 |
+
const haystack = extract && extract.trim() ? normalise(extract) : null;
|
| 275 |
+
return quotes.map((q) => {
|
| 276 |
+
const words = wordCount(q);
|
| 277 |
+
const inExtract = haystack ? haystack.includes(normalise(q).trim()) : null;
|
| 278 |
+
let note = null;
|
| 279 |
+
if (words > 12) note = "Long quotation — trim it to a few words and embed it in your sentence.";
|
| 280 |
+
else if (inExtract === false) note = "Not found in the extract you pasted. It may be from another part of the text — check your copy.";
|
| 281 |
+
return { text: q, words, inExtract, note };
|
| 282 |
+
});
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
// ---------------------------------------------------------------------------
|
| 286 |
+
// Scoring
|
| 287 |
+
// ---------------------------------------------------------------------------
|
| 288 |
+
|
| 289 |
+
function clamp(n, min, max) {
|
| 290 |
+
return Math.max(min, Math.min(max, n));
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
function scoreCriterion(id, ctx) {
|
| 294 |
+
switch (id) {
|
| 295 |
+
case "point":
|
| 296 |
+
case "focus": {
|
| 297 |
+
if (ctx.words >= 45 && ctx.overlap >= 2) return 2;
|
| 298 |
+
if (ctx.words >= 20 && (ctx.overlap >= 1 || ctx.linkHit)) return 1;
|
| 299 |
+
return 0;
|
| 300 |
+
}
|
| 301 |
+
case "thesis": {
|
| 302 |
+
if (/(this essay will|i will argue|i will show|the essay will|argue that|thesis)/.test(ctx.lower) && ctx.words >= 25) return 2;
|
| 303 |
+
if (ctx.overlap >= 2 && ctx.words >= 35) return 1;
|
| 304 |
+
return 0;
|
| 305 |
+
}
|
| 306 |
+
case "evidence": {
|
| 307 |
+
if (ctx.quotes.length >= 2 && ctx.quotes.some((q) => q.words <= 12)) return 2;
|
| 308 |
+
if (ctx.quotes.length >= 1) return 1;
|
| 309 |
+
return 0;
|
| 310 |
+
}
|
| 311 |
+
case "method": {
|
| 312 |
+
if (ctx.techniques.length >= 2) return 2;
|
| 313 |
+
if (ctx.techniques.length === 1) return 1;
|
| 314 |
+
return 0;
|
| 315 |
+
}
|
| 316 |
+
case "analysis": {
|
| 317 |
+
if (ctx.techniques.length >= 1 && ctx.effectVerbs.length >= 1 && ctx.hasBecause) return 2;
|
| 318 |
+
if (ctx.techniques.length >= 1 || ctx.effectVerbs.length >= 1) return 1;
|
| 319 |
+
return 0;
|
| 320 |
+
}
|
| 321 |
+
case "effect": {
|
| 322 |
+
if (ctx.effectVerbs.length >= 2 && ctx.hasBecause && ctx.sentences >= 4) return 3;
|
| 323 |
+
if (ctx.effectVerbs.length >= 1 && (ctx.hasBecause || ctx.effectVerbs.length >= 2)) return 2;
|
| 324 |
+
if (ctx.effectVerbs.length >= 1 || ctx.hasBecause) return 1;
|
| 325 |
+
return 0;
|
| 326 |
+
}
|
| 327 |
+
case "link": {
|
| 328 |
+
if (ctx.lastSentenceOverlap >= 1 || (ctx.linkHit && ctx.overlap >= 1)) return 1;
|
| 329 |
+
return 0;
|
| 330 |
+
}
|
| 331 |
+
case "return": {
|
| 332 |
+
if (ctx.lastSentenceOverlap >= 2) return 2;
|
| 333 |
+
if (ctx.lastSentenceOverlap >= 1 || ctx.linkHit) return 1;
|
| 334 |
+
return 0;
|
| 335 |
+
}
|
| 336 |
+
case "significance": {
|
| 337 |
+
if (/(context|society|audience|victorian|edwardian|shakespeare|priestley|dickens|stevenson|golding|modern|today)/.test(ctx.lower) && ctx.overlap >= 1) return 2;
|
| 338 |
+
if (/(context|society|audience|victorian|edwardian|shakespeare|priestley|dickens|stevenson|golding|modern|today)/.test(ctx.lower)) return 1;
|
| 339 |
+
return 0;
|
| 340 |
+
}
|
| 341 |
+
case "structure": {
|
| 342 |
+
if (ctx.paragraphs >= 3 && /(firstly|secondly|finally|however|therefore|in contrast|moreover)/.test(ctx.lower)) return 2;
|
| 343 |
+
if (ctx.paragraphs >= 2) return 1;
|
| 344 |
+
return 0;
|
| 345 |
+
}
|
| 346 |
+
case "thread": {
|
| 347 |
+
if (ctx.repeatedTerms >= 2 && ctx.paragraphs >= 3) return 2;
|
| 348 |
+
if (ctx.repeatedTerms >= 1) return 1;
|
| 349 |
+
return 0;
|
| 350 |
+
}
|
| 351 |
+
default:
|
| 352 |
+
return 0;
|
| 353 |
+
}
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
function noteFor(id, ctx, score, max) {
|
| 357 |
+
const full = score === max;
|
| 358 |
+
switch (id) {
|
| 359 |
+
case "point":
|
| 360 |
+
case "focus":
|
| 361 |
+
return full
|
| 362 |
+
? "Focused on the question and using the text's own terms."
|
| 363 |
+
: ctx.overlap === 0
|
| 364 |
+
? "The opening does not pick up the question's key words. Name the character, relationship or idea you are answering about."
|
| 365 |
+
: "Sharpen the opening so it answers the exact question, not the text in general.";
|
| 366 |
+
case "thesis":
|
| 367 |
+
return full
|
| 368 |
+
? "A clear overall argument is promised."
|
| 369 |
+
: "Add one sentence that says what the whole essay will prove: 'This essay will argue that…'.";
|
| 370 |
+
case "evidence":
|
| 371 |
+
if (ctx.quotes.length === 0) return "No quotation. Choose two or three words and embed them in your own sentence.";
|
| 372 |
+
if (ctx.quotes.length === 1) return "One quotation found. A second short one would let you compare or develop the point.";
|
| 373 |
+
return full ? "Short quotations, ready to analyse." : "Trim the longest quotation: the best evidence is usually two to five words.";
|
| 374 |
+
case "method":
|
| 375 |
+
if (full) return "Precise technique named: " + ctx.techniques.slice(0, 2).join(", ") + ".";
|
| 376 |
+
if (ctx.techniques.length === 1) return "One technique named (" + ctx.techniques[0] + "). Name a second choice — structure, form or a word class.";
|
| 377 |
+
return "Name the writer's method exactly: metaphor, personification, a short sentence, a stage direction…";
|
| 378 |
+
case "analysis":
|
| 379 |
+
if (full) return "Method and effect are working together.";
|
| 380 |
+
return "Link the technique to its effect in the same sentence: 'The … suggests … because ���'.";
|
| 381 |
+
case "effect":
|
| 382 |
+
if (full) return "Developed effect with a reason — exactly what examiners reward.";
|
| 383 |
+
if (ctx.effectVerbs.length === 0) return "The effect is not explained yet. Add what the reader feels or understands, and why.";
|
| 384 |
+
return "Push the effect further with 'because…', or offer an alternative reading.";
|
| 385 |
+
case "link":
|
| 386 |
+
return full ? "Tied back to the question." : "End by returning to the question's key words, or to the text's wider idea.";
|
| 387 |
+
case "return":
|
| 388 |
+
return full ? "Returns to the question with the evidence behind it." : "Answer the question again in your final sentence, now that the evidence is in.";
|
| 389 |
+
case "significance":
|
| 390 |
+
return full ? "Connects the detail to context or the whole text." : "Add one sentence on why this matters beyond the quotation — context, the whole text, or the reader.";
|
| 391 |
+
case "structure":
|
| 392 |
+
return full ? "The argument is signposted and ordered." : "Signpost the argument: 'Firstly… However… Finally…'.";
|
| 393 |
+
case "thread":
|
| 394 |
+
return full ? "The same argument is developed across the essay." : "Repeat one key term across paragraphs so the argument feels continuous.";
|
| 395 |
+
default:
|
| 396 |
+
return "";
|
| 397 |
+
}
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
export function reviewText({ text, question = "", extract = "", rubric, title = "" }) {
|
| 401 |
+
const clean = text.trim();
|
| 402 |
+
const words = wordCount(clean);
|
| 403 |
+
const sentences = sentenceList(clean);
|
| 404 |
+
const lower = " " + clean.toLowerCase() + " ";
|
| 405 |
+
const quotes = checkQuotes(clean, extract);
|
| 406 |
+
const techniques = findTechniques(lower);
|
| 407 |
+
const effectVerbs = findEffectVerbs(lower);
|
| 408 |
+
const qWords = questionWords(question);
|
| 409 |
+
const questionOverlap = overlap(clean, qWords);
|
| 410 |
+
const lastSentence = sentences[sentences.length - 1] || "";
|
| 411 |
+
const lastSentenceOverlap = overlap(lastSentence, qWords);
|
| 412 |
+
const paragraphs = clean.split(/\n\s*\n/).filter((p) => p.trim().length > 0).length || (words > 0 ? 1 : 0);
|
| 413 |
+
const terms = qWords.filter((w) => (lower.match(new RegExp("\\b" + w + "\\b", "g")) || []).length >= 2);
|
| 414 |
+
const ctx = {
|
| 415 |
+
text: clean,
|
| 416 |
+
lower,
|
| 417 |
+
words,
|
| 418 |
+
sentences: sentences.length,
|
| 419 |
+
quotes,
|
| 420 |
+
techniques,
|
| 421 |
+
effectVerbs,
|
| 422 |
+
hasBecause: CAUSAL.some((c) => lower.includes(c)),
|
| 423 |
+
linkHit: LINK_PHRASES.some((p) => lower.includes(p)),
|
| 424 |
+
overlap: questionOverlap,
|
| 425 |
+
lastSentenceOverlap,
|
| 426 |
+
paragraphs,
|
| 427 |
+
repeatedTerms: terms.length
|
| 428 |
+
};
|
| 429 |
+
|
| 430 |
+
const criteria = rubric.map((c) => {
|
| 431 |
+
const raw = scoreCriterion(c.id, ctx);
|
| 432 |
+
const score = clamp(raw, 0, c.max);
|
| 433 |
+
return { ...c, score, note: noteFor(c.id, ctx, score, c.max) };
|
| 434 |
+
});
|
| 435 |
+
|
| 436 |
+
const total = criteria.reduce((sum, c) => sum + c.score, 0);
|
| 437 |
+
const max = criteria.reduce((sum, c) => sum + c.max, 0);
|
| 438 |
+
const sorted = [...criteria].sort((a, b) => b.score / b.max - a.score / a.max);
|
| 439 |
+
const best = sorted[0];
|
| 440 |
+
const worst = sorted[sorted.length - 1];
|
| 441 |
+
|
| 442 |
+
const strengths = [];
|
| 443 |
+
if (quotes.length) strengths.push("You used " + quotes.length + " quotation" + (quotes.length === 1 ? "" : "s") + ": " + quotes.slice(0, 2).map((q) => "“" + q.text + "”").join(", ") + ".");
|
| 444 |
+
if (techniques.length) strengths.push("Named method" + (techniques.length === 1 ? "" : "s") + ": " + techniques.slice(0, 3).join(", ") + ".");
|
| 445 |
+
if (ctx.hasBecause) strengths.push("You explained a cause, not just an effect — that is where analysis starts.");
|
| 446 |
+
if (best && best.score > 0 && strengths.length < 2) strengths.push(best.title + ": " + best.note);
|
| 447 |
+
if (strengths.length === 0) strengths.push("You have made a start. The first step is one clear point in your own words.");
|
| 448 |
+
|
| 449 |
+
const allFull = criteria.every((c) => c.score === c.max);
|
| 450 |
+
const improvements = allFull ? [] : [worst.title + ": " + worst.note];
|
| 451 |
+
if (quotes.some((q) => q.words > 12)) improvements.push("Trim long quotations to the few words that carry the meaning.");
|
| 452 |
+
if (!ctx.hasBecause && words > 30) improvements.push("Add one 'because…' to turn an asserted effect into an explanation.");
|
| 453 |
+
|
| 454 |
+
const nextStep = allFull
|
| 455 |
+
? "Full marks here. Keep this paragraph as a model, then try the same question on a second extract or build it into a full essay."
|
| 456 |
+
: worst.id === "evidence"
|
| 457 |
+
? "Write the next version with two short quotations, each embedded in a sentence of your own."
|
| 458 |
+
: worst.id === "method"
|
| 459 |
+
? "Rewrite one sentence to name the exact technique, then say what it makes the reader feel."
|
| 460 |
+
: worst.id === "effect"
|
| 461 |
+
? "Take your strongest quotation and add: 'This suggests … because …'."
|
| 462 |
+
: "Rewrite the weakest sentence to answer the question directly, then re-mark it.";
|
| 463 |
+
|
| 464 |
+
return {
|
| 465 |
+
total,
|
| 466 |
+
max,
|
| 467 |
+
criteria,
|
| 468 |
+
strengths,
|
| 469 |
+
improvements: improvements.slice(0, 3),
|
| 470 |
+
nextStep,
|
| 471 |
+
quotes,
|
| 472 |
+
techniques,
|
| 473 |
+
engine: "offline",
|
| 474 |
+
title
|
| 475 |
+
};
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
export function reviewParagraph(args) {
|
| 479 |
+
return reviewText({ ...args, rubric: PARAGRAPH_RUBRIC });
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
export function reviewEssayPart(part, args) {
|
| 483 |
+
return reviewText({ ...args, rubric: ESSAY_RUBRICS[part] || PARAGRAPH_RUBRIC });
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
export function combineEssay(parts) {
|
| 487 |
+
const total = parts.reduce((sum, p) => sum + (p ? p.total : 0), 0);
|
| 488 |
+
const max = parts.reduce((sum, p) => sum + (p ? p.max : 0), 0);
|
| 489 |
+
return { total, max };
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
// ---------------------------------------------------------------------------
|
| 493 |
+
// Model prompt + response parsing
|
| 494 |
+
// ---------------------------------------------------------------------------
|
| 495 |
+
|
| 496 |
+
export function buildMarkingMessages({ text, question, extract, rubric, textTitle, mode }) {
|
| 497 |
+
const system = [
|
| 498 |
+
"You are Explication, a GCSE English Literature writing coach for students in England.",
|
| 499 |
+
"You mark the student's own writing against the rubric, name what works, then name the single highest-impact improvement.",
|
| 500 |
+
"Reply in British English, address the student as 'you'.",
|
| 501 |
+
"Return ONE JSON object only, with this shape:",
|
| 502 |
+
'{"scores":{"<criterionId>":0},"strengths":["..."],"improvements":["..."],"nextStep":"...","quoteNotes":["..."]}',
|
| 503 |
+
"Scores must be whole numbers no higher than each criterion's maximum.",
|
| 504 |
+
"Do not write the student's paragraph for them."
|
| 505 |
+
].join(" ");
|
| 506 |
+
const rubricText = rubric.map((c) => `${c.id} (0-${c.max}): ${c.title}. ${c.guidance}`).join("\n");
|
| 507 |
+
const user = [
|
| 508 |
+
`Mode: ${mode || "paragraph"}`,
|
| 509 |
+
textTitle ? `Text: ${textTitle}` : "",
|
| 510 |
+
question ? `Question: ${question}` : "",
|
| 511 |
+
`Rubric:\n${rubricText}`,
|
| 512 |
+
extract ? `Extract the student supplied:\n"""${extract.slice(0, 4000)}"""` : "No extract supplied.",
|
| 513 |
+
`Student writing:\n"""${text}"""`
|
| 514 |
+
].filter(Boolean).join("\n\n");
|
| 515 |
+
return [
|
| 516 |
+
{ role: "system", content: system },
|
| 517 |
+
{ role: "user", content: user }
|
| 518 |
+
];
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
export function parseMarkingReply(raw, rubric) {
|
| 522 |
+
const start = raw.indexOf("{");
|
| 523 |
+
const end = raw.lastIndexOf("}");
|
| 524 |
+
if (start === -1 || end === -1) throw new Error("The model did not return JSON.");
|
| 525 |
+
const data = JSON.parse(raw.slice(start, end + 1));
|
| 526 |
+
const scores = data.scores || {};
|
| 527 |
+
const criteria = rubric.map((c) => {
|
| 528 |
+
const value = Number(scores[c.id]);
|
| 529 |
+
const score = clamp(Number.isFinite(value) ? Math.round(value) : 0, 0, c.max);
|
| 530 |
+
return { ...c, score, note: "" };
|
| 531 |
+
});
|
| 532 |
+
const total = criteria.reduce((sum, c) => sum + c.score, 0);
|
| 533 |
+
return {
|
| 534 |
+
total,
|
| 535 |
+
max: rubric.reduce((sum, c) => sum + c.max, 0),
|
| 536 |
+
criteria,
|
| 537 |
+
strengths: Array.isArray(data.strengths) ? data.strengths.slice(0, 4).map(String) : [],
|
| 538 |
+
improvements: Array.isArray(data.improvements) ? data.improvements.slice(0, 3).map(String) : [],
|
| 539 |
+
nextStep: typeof data.nextStep === "string" ? data.nextStep : "",
|
| 540 |
+
quotes: [],
|
| 541 |
+
techniques: [],
|
| 542 |
+
engine: "model"
|
| 543 |
+
};
|
| 544 |
+
}
|
js/pricing.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { html, useState } from "./runtime.js";
|
| 2 |
+
import { useCloud, money, planPeriod } from "./cloud.js";
|
| 3 |
+
import { Copy } from "./copy.js";
|
| 4 |
+
import { Icon, Notice, Pill } from "./components.js";
|
| 5 |
+
|
| 6 |
+
const RIBBONS = {
|
| 7 |
+
"model-library": "Best value",
|
| 8 |
+
student: "Most popular",
|
| 9 |
+
"exam-season": "Everything included"
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
const DAY_LINES = {
|
| 13 |
+
student: "that is about 13p a day",
|
| 14 |
+
scholar: "that is about 30p a day",
|
| 15 |
+
examiner: "that is about 63p a day"
|
| 16 |
+
};
|
| 17 |
+
|
| 18 |
+
// How much AI a plan includes, in plain language. Never show the money
|
| 19 |
+
// allowance on the shop front: it reads as a poor deal next to the price.
|
| 20 |
+
const ALLOWANCES = {
|
| 21 |
+
"paragraph-lite": "Fully offline — nothing to run out of",
|
| 22 |
+
"model-library": "Fully offline — nothing to run out of",
|
| 23 |
+
"exam-season": "5× the AI of Student, included",
|
| 24 |
+
"ai-booster": "+4× the AI of Student",
|
| 25 |
+
student: "A generous AI allowance every month",
|
| 26 |
+
scholar: "3× the AI of Student",
|
| 27 |
+
examiner: "8× the AI of Student"
|
| 28 |
+
};
|
| 29 |
+
|
| 30 |
+
function allowanceLine(plan) {
|
| 31 |
+
if (ALLOWANCES[plan.id]) return ALLOWANCES[plan.id];
|
| 32 |
+
if (!plan.cost_limit_cents) return "Fully offline — nothing to run out of";
|
| 33 |
+
return "A generous AI allowance";
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
function PlanCard({ plan, current, onBuy, busy, signedIn }) {
|
| 37 |
+
const isSub = plan.kind === "subscription";
|
| 38 |
+
const ribbon = RIBBONS[plan.id];
|
| 39 |
+
const cta = current ? "Already yours" : signedIn ? (isSub ? "Join " + plan.name : "Get " + plan.name) : "Sign in to continue";
|
| 40 |
+
return html`<div class=${"card plan-card" + (current ? " current" : "") + (ribbon === "Most popular" ? " featured" : "")}>
|
| 41 |
+
${ribbon && html`<span class="plan-ribbon">${ribbon}</span>`}
|
| 42 |
+
<div class="plan-top">
|
| 43 |
+
<span class="plan-name">${plan.name}</span>
|
| 44 |
+
${isSub && html`<span class="pill neutral">Membership</span>`}
|
| 45 |
+
${!isSub && html`<span class="pill green">One payment</span>`}
|
| 46 |
+
</div>
|
| 47 |
+
<div class="plan-price">
|
| 48 |
+
${money(plan.price_cents, plan.currency).replace(".00", "")}
|
| 49 |
+
<span class="plan-period">${isSub ? "/ " + (plan.interval || "month") : "once"}</span>
|
| 50 |
+
</div>
|
| 51 |
+
<div class="plan-subline">${isSub ? DAY_LINES[plan.id] || "cancel any time" : "no renewal, ever"}</div>
|
| 52 |
+
|
| 53 |
+
<p class="plan-blurb">${plan.blurb}</p>
|
| 54 |
+
|
| 55 |
+
<div class="plan-limit">
|
| 56 |
+
<${Icon} name="sparkle" size=${12} />
|
| 57 |
+
<span>${allowanceLine(plan)}</span>
|
| 58 |
+
</div>
|
| 59 |
+
|
| 60 |
+
<ul class="plan-features">
|
| 61 |
+
${(plan.features || []).map((f, i) => html`<li key=${i}><${Icon} name="check" size=${12} /> <span>${f}</span></li>`)}
|
| 62 |
+
</ul>
|
| 63 |
+
|
| 64 |
+
<button class=${"btn plan-cta " + (isSub ? "primary" : "green")} onClick=${() => onBuy(plan)} disabled=${busy || current}>
|
| 65 |
+
${busy ? html`<span class="spin"></span>` : current ? html`<${Icon} name="check" size=${13} />` : ""} ${cta}
|
| 66 |
+
</button>
|
| 67 |
+
<div class="plan-foot">${isSub ? "Cancel any time. Access runs to the end of the month you paid for." : "One payment. Nothing renews."}</div>
|
| 68 |
+
</div>`;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
function Group({ title, note, plans, cloud, buy, busy }) {
|
| 72 |
+
return html`<div style=${{ marginTop: "20px" }}>
|
| 73 |
+
<div class="section-head" style=${{ alignItems: "baseline" }}>
|
| 74 |
+
<h2 class="section-title">${title}</h2>
|
| 75 |
+
<span class="tiny faint">${note}</span>
|
| 76 |
+
</div>
|
| 77 |
+
<div class="plan-grid">
|
| 78 |
+
${plans.map(
|
| 79 |
+
(plan) => html`<${PlanCard} key=${plan.id} plan=${plan} current=${!!cloud.plan && cloud.plan.id === plan.id} onBuy=${buy} busy=${busy === plan.id} signedIn=${!!cloud.user} />`
|
| 80 |
+
)}
|
| 81 |
+
</div>
|
| 82 |
+
</div>`;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
export function Pricing() {
|
| 86 |
+
const cloud = useCloud();
|
| 87 |
+
const [busy, setBusy] = useState("");
|
| 88 |
+
const [error, setError] = useState("");
|
| 89 |
+
|
| 90 |
+
const plans = cloud.plans.filter((p) => p.active !== false).sort((a, b) => (a.sort || 0) - (b.sort || 0));
|
| 91 |
+
const oneOff = plans.filter((p) => p.kind === "one_time");
|
| 92 |
+
const subs = plans.filter((p) => p.kind === "subscription");
|
| 93 |
+
|
| 94 |
+
const buy = async (plan) => {
|
| 95 |
+
setError("");
|
| 96 |
+
if (!cloud.user) {
|
| 97 |
+
window.location.hash = "#/account";
|
| 98 |
+
return;
|
| 99 |
+
}
|
| 100 |
+
setBusy(plan.id);
|
| 101 |
+
try {
|
| 102 |
+
await cloud.startCheckout(plan);
|
| 103 |
+
} catch (err) {
|
| 104 |
+
setError(err && err.message ? err.message : "Checkout could not start.");
|
| 105 |
+
setBusy("");
|
| 106 |
+
}
|
| 107 |
+
};
|
| 108 |
+
|
| 109 |
+
return html`<main class="page">
|
| 110 |
+
<section class="price-hero">
|
| 111 |
+
<div class="deal-pill"><${Icon} name="sparkle" size=${12} /> Every plan includes the full marking engine</div>
|
| 112 |
+
<h1 class="price-title"><${Copy} id="pricing.title">Get the marks. Keep the change.</${Copy}></h1>
|
| 113 |
+
<p class="price-lede">
|
| 114 |
+
<${Copy} id="pricing.subtitle">Marking is free, forever. When you want the bigger models for the long essays, pick a pack once — or a membership you can leave whenever you like.</${Copy}>
|
| 115 |
+
</p>
|
| 116 |
+
<div class="price-chips">
|
| 117 |
+
<span><${Icon} name="check" size=${12} /> No card to start</span>
|
| 118 |
+
<span><${Icon} name="check" size=${12} /> One-off options</span>
|
| 119 |
+
<span><${Icon} name="check" size=${12} /> Cancel in two taps</span>
|
| 120 |
+
<span><${Icon} name="check" size=${12} /> Works offline</span>
|
| 121 |
+
</div>
|
| 122 |
+
</section>
|
| 123 |
+
|
| 124 |
+
${!cloud.configured &&
|
| 125 |
+
html`<div style=${{ marginTop: "14px" }}>
|
| 126 |
+
<${Notice} kind="warn">This is the preview shop front — connect Supabase and Stripe in the developer console to take real payments.<//>
|
| 127 |
+
</div>`}
|
| 128 |
+
${error && html`<div style=${{ marginTop: "14px" }}><${Notice} kind="error">${error}<//></div>`}
|
| 129 |
+
|
| 130 |
+
<div class="free-strip">
|
| 131 |
+
<div>
|
| 132 |
+
<div class="free-strip-title">Everything a student actually needs is free.</div>
|
| 133 |
+
<div class="free-strip-body">Paragraph, essay, poetry and mock-exam marking · the full process log · exports · your own AI key</div>
|
| 134 |
+
</div>
|
| 135 |
+
<a class="btn small" href="#/coach">Start marking</a>
|
| 136 |
+
</div>
|
| 137 |
+
|
| 138 |
+
<${Group} title="Pay once, keep forever" note="No renewal. No card kept on file." plans=${oneOff} cloud=${cloud} buy=${buy} busy=${busy} />
|
| 139 |
+
<${Group} title="Memberships" note="For the terms when you want the whole shelf." plans=${subs} cloud=${cloud} buy=${buy} busy=${busy} />
|
| 140 |
+
|
| 141 |
+
<div class="grid three" style=${{ marginTop: "26px" }}>
|
| 142 |
+
<div class="card value-card">
|
| 143 |
+
<div class="value-icon"><${Icon} name="book" size=${17} /></div>
|
| 144 |
+
<div class="value-title">Marked the way examiners mark</div>
|
| 145 |
+
<div class="value-body">Every paragraph is scored against the real AQA criteria, with the one change that lifts the grade next.</div>
|
| 146 |
+
</div>
|
| 147 |
+
<div class="card value-card">
|
| 148 |
+
<div class="value-icon"><${Icon} name="lock" size=${17} /></div>
|
| 149 |
+
<div class="value-title">Your writing stays yours</div>
|
| 150 |
+
<div class="value-body">Drafts live on your device. Offline models mean you can revise on a train with no signal at all.</div>
|
| 151 |
+
</div>
|
| 152 |
+
<div class="card value-card">
|
| 153 |
+
<div class="value-icon"><${Icon} name="sparkle" size=${17} /></div>
|
| 154 |
+
<div class="value-title">Less than a tutor, by a mile</div>
|
| 155 |
+
<div class="value-body">One hour with a tutor costs more than a whole year here. Buy once, or pay monthly and leave whenever.</div>
|
| 156 |
+
</div>
|
| 157 |
+
</div>
|
| 158 |
+
|
| 159 |
+
<div class="section-head" style=${{ marginTop: "26px" }}><h2 class="section-title">Good questions</h2></div>
|
| 160 |
+
<div class="card faq">
|
| 161 |
+
<details>
|
| 162 |
+
<summary>Do I need a plan to use Explication?</summary>
|
| 163 |
+
<p>No. Paragraph, essay, poetry and mock-exam marking, the process log and every export are free and always will be. Plans add the AI models.</p>
|
| 164 |
+
</details>
|
| 165 |
+
<details>
|
| 166 |
+
<summary>What is hosted AI?</summary>
|
| 167 |
+
<p>The bigger models run for you, so you do not need a powerful laptop. Each month (or each one-off pack) comes with an allowance of AI usage. When it runs out, the free tools and any offline models keep working.</p>
|
| 168 |
+
</details>
|
| 169 |
+
<details>
|
| 170 |
+
<summary>Can I cancel?</summary>
|
| 171 |
+
<p>Any time, in two taps from your account. You keep access until the end of the month you paid for, and nothing renews after that.</p>
|
| 172 |
+
</details>
|
| 173 |
+
<details>
|
| 174 |
+
<summary>What if I run out mid-term?</summary>
|
| 175 |
+
<p>Add an AI Booster once, or put in your own key from any AI provider and keep going without touching your allowance.</p>
|
| 176 |
+
</details>
|
| 177 |
+
<details>
|
| 178 |
+
<summary>Do downloads work without internet?</summary>
|
| 179 |
+
<p>Yes. Download a model once and it runs entirely on your device — on the bus, on a plane, in a hall with the Wi-Fi switched off.</p>
|
| 180 |
+
</details>
|
| 181 |
+
</div>
|
| 182 |
+
|
| 183 |
+
<p class="tiny faint" style=${{ marginTop: "16px" }}>
|
| 184 |
+
Prices in ${cloud.settings.currency || "GBP"}, including VAT where it applies. Cancel any time; access runs to the end of the period you paid for.
|
| 185 |
+
</p>
|
| 186 |
+
</main>`;
|
| 187 |
+
}
|
js/runtime.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const React = window.React;
|
| 2 |
+
const ReactDOM = window.ReactDOM;
|
| 3 |
+
const html = window.htm.bind(React.createElement);
|
| 4 |
+
|
| 5 |
+
export { React, ReactDOM, html };
|
| 6 |
+
export const {
|
| 7 |
+
useState,
|
| 8 |
+
useEffect,
|
| 9 |
+
useRef,
|
| 10 |
+
useMemo,
|
| 11 |
+
useCallback,
|
| 12 |
+
useReducer,
|
| 13 |
+
createContext,
|
| 14 |
+
useContext,
|
| 15 |
+
Fragment
|
| 16 |
+
} = React;
|
js/screens-extra.js
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { React, html, useEffect, useMemo, useState } from "./runtime.js";
|
| 2 |
+
import { useApp } from "./store.js";
|
| 3 |
+
import { useEngine } from "./engine.js";
|
| 4 |
+
import { useCloud, money } from "./cloud.js";
|
| 5 |
+
import { Notice, Pill, FeedbackPanel, Icon, Mark, usePersistent, download, SECTIONS } from "./components.js";
|
| 6 |
+
import {
|
| 7 |
+
CREDIT_COSTS,
|
| 8 |
+
PARAGRAPH_RUBRIC,
|
| 9 |
+
SUGGESTED_QUESTIONS,
|
| 10 |
+
TEXTS,
|
| 11 |
+
reviewText,
|
| 12 |
+
wordCount
|
| 13 |
+
} from "./marking.js";
|
| 14 |
+
|
| 15 |
+
function PageHead({ kicker, title, subtitle, right }) {
|
| 16 |
+
return html`<div class="row between" style=${{ alignItems: "flex-start", gap: "16px" }}>
|
| 17 |
+
<div>
|
| 18 |
+
<div class="eyebrow">${kicker}</div>
|
| 19 |
+
<h1 class="page-title">${title}</h1>
|
| 20 |
+
${subtitle && html`<p class="subtitle">${subtitle}</p>`}
|
| 21 |
+
</div>
|
| 22 |
+
${right}
|
| 23 |
+
</div>`;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
// ---------------------------------------------------------------------------
|
| 27 |
+
// Model answers
|
| 28 |
+
// ---------------------------------------------------------------------------
|
| 29 |
+
|
| 30 |
+
export function ModelAnswers() {
|
| 31 |
+
const app = useApp();
|
| 32 |
+
const engine = useEngine();
|
| 33 |
+
const [textId, setTextId] = usePersistent("explication.modelAnswer.textId", "macbeth");
|
| 34 |
+
const [question, setQuestion] = usePersistent("explication.modelAnswer.question", "How does Shakespeare present ambition in Macbeth?");
|
| 35 |
+
const [answer, setAnswer] = usePersistent("explication.modelAnswer.answer", "");
|
| 36 |
+
const [busy, setBusy] = useState(false);
|
| 37 |
+
const [error, setError] = useState("");
|
| 38 |
+
const text = TEXTS.find((t) => t.id === textId) || TEXTS[0];
|
| 39 |
+
|
| 40 |
+
const generate = async () => {
|
| 41 |
+
setError("");
|
| 42 |
+
if (!engine.canGenerate) {
|
| 43 |
+
setError("A model answer needs a model. Open Settings to load one or connect an endpoint.");
|
| 44 |
+
return;
|
| 45 |
+
}
|
| 46 |
+
if (app.credits < CREDIT_COSTS.modelAnswer) {
|
| 47 |
+
setError("This costs " + CREDIT_COSTS.modelAnswer + " credits. Mark a paragraph to earn more.");
|
| 48 |
+
return;
|
| 49 |
+
}
|
| 50 |
+
app.spend(CREDIT_COSTS.modelAnswer);
|
| 51 |
+
setBusy(true);
|
| 52 |
+
setAnswer("");
|
| 53 |
+
try {
|
| 54 |
+
const result = await engine.chat(
|
| 55 |
+
[
|
| 56 |
+
{
|
| 57 |
+
role: "system",
|
| 58 |
+
content: [
|
| 59 |
+
"You are an experienced GCSE English Literature examiner writing a model answer for study.",
|
| 60 |
+
"Write one developed paragraph, 150-220 words, in British English, at grade 8-9 standard.",
|
| 61 |
+
"Use one short embedded quotation from the named text; never invent a quotation.",
|
| 62 |
+
"Name the method, explain the effect, and finish by returning to the question.",
|
| 63 |
+
"Return only the paragraph."
|
| 64 |
+
].join(" ")
|
| 65 |
+
},
|
| 66 |
+
{ role: "user", content: `Text: ${text.title}\nQuestion: ${question}` }
|
| 67 |
+
],
|
| 68 |
+
setAnswer
|
| 69 |
+
);
|
| 70 |
+
if (result && result.trim()) setAnswer(result.trim());
|
| 71 |
+
} catch (err) {
|
| 72 |
+
setError(err && err.message ? err.message : "The model answer could not be written.");
|
| 73 |
+
app.addCredits(CREDIT_COSTS.modelAnswer);
|
| 74 |
+
}
|
| 75 |
+
setBusy(false);
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
return html`<main class="page narrow">
|
| 79 |
+
<${PageHead} kicker="Model answers" title="See what a strong answer looks like."
|
| 80 |
+
subtitle="A model answer is a worked example, not your work. It is always labelled, and it costs credits because a model writes it."
|
| 81 |
+
right=${html`<${Pill} tone="warn">${CREDIT_COSTS.modelAnswer} credits<//>`} />
|
| 82 |
+
|
| 83 |
+
<div class="card" style=${{ marginTop: "18px" }}>
|
| 84 |
+
<div class="grid two">
|
| 85 |
+
<div class="field">
|
| 86 |
+
<label>Text</label>
|
| 87 |
+
<select class="select" value=${textId} onChange=${(e) => setTextId(e.target.value)}>
|
| 88 |
+
${TEXTS.map((t) => html`<option key=${t.id} value=${t.id}>${t.title}</option>`)}
|
| 89 |
+
</select>
|
| 90 |
+
</div>
|
| 91 |
+
<div class="field">
|
| 92 |
+
<label>Question</label>
|
| 93 |
+
<input class="input" list="answer-questions" value=${question} onInput=${(e) => setQuestion(e.target.value)} />
|
| 94 |
+
<datalist id="answer-questions">${SUGGESTED_QUESTIONS.map((q) => html`<option key=${q} value=${q}></option>`)}</datalist>
|
| 95 |
+
</div>
|
| 96 |
+
</div>
|
| 97 |
+
${!engine.canGenerate && html`<div style=${{ marginTop: "10px" }}><${Notice} kind="warn">No model is connected. <a href="#/settings">Open Settings</a> to load a browser model or add an endpoint.<//></div>`}
|
| 98 |
+
${error && html`<div style=${{ marginTop: "10px" }}><${Notice} kind="error">${error}<//></div>`}
|
| 99 |
+
<div class="row between" style=${{ marginTop: "12px" }}>
|
| 100 |
+
<span class="tiny faint">${app.credits} credits available</span>
|
| 101 |
+
<button class="btn primary" onClick=${generate} disabled=${busy || !engine.canGenerate}>
|
| 102 |
+
${busy ? html`<span class="spin"></span> Writing…` : html`<${Icon} name="sparkle" size=${13} /> Generate model answer`}
|
| 103 |
+
</button>
|
| 104 |
+
</div>
|
| 105 |
+
</div>
|
| 106 |
+
|
| 107 |
+
${answer &&
|
| 108 |
+
html`<div class="card" style=${{ marginTop: "12px", background: "var(--warning-soft)", borderColor: "#f0dcc5" }}>
|
| 109 |
+
<div class="row between">
|
| 110 |
+
<span class="eyebrow" style=${{ color: "var(--warning)" }}>AI-written model answer</span>
|
| 111 |
+
<span class="tiny" style=${{ color: "var(--warning)" }}>${wordCount(answer)} words</span>
|
| 112 |
+
</div>
|
| 113 |
+
<p style=${{ fontFamily: "var(--serif)", fontSize: "16px", lineHeight: 1.7, margin: "10px 0 0", whiteSpace: "pre-wrap" }}>${answer}</p>
|
| 114 |
+
<div class="divider" style=${{ background: "#eedcc8" }}></div>
|
| 115 |
+
<div class="tiny" style=${{ color: "var(--warning)" }}>Study material only — do not submit this as your own work.</div>
|
| 116 |
+
</div>`}
|
| 117 |
+
</main>`;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
// ---------------------------------------------------------------------------
|
| 121 |
+
// Mock exam
|
| 122 |
+
// ---------------------------------------------------------------------------
|
| 123 |
+
|
| 124 |
+
const EXAM_SECONDS = 25 * 60;
|
| 125 |
+
|
| 126 |
+
export function MockExam() {
|
| 127 |
+
const app = useApp();
|
| 128 |
+
const [textId, setTextId] = usePersistent("explication.mock.textId", "macbeth");
|
| 129 |
+
const [question, setQuestion] = usePersistent("explication.mock.question", "How does Shakespeare present ambition in Macbeth?");
|
| 130 |
+
const [extract, setExtract] = usePersistent("explication.mock.extract", "");
|
| 131 |
+
const [answer, setAnswer] = usePersistent("explication.mock.answer", "");
|
| 132 |
+
const [remaining, setRemaining] = useState(EXAM_SECONDS);
|
| 133 |
+
const [running, setRunning] = useState(false);
|
| 134 |
+
const [feedback, setFeedback] = useState(null);
|
| 135 |
+
const [error, setError] = useState("");
|
| 136 |
+
const text = TEXTS.find((t) => t.id === textId) || TEXTS[0];
|
| 137 |
+
|
| 138 |
+
useEffect(() => {
|
| 139 |
+
if (!running) return;
|
| 140 |
+
const timer = setInterval(() => {
|
| 141 |
+
setRemaining((r) => {
|
| 142 |
+
if (r <= 1) {
|
| 143 |
+
setRunning(false);
|
| 144 |
+
return 0;
|
| 145 |
+
}
|
| 146 |
+
return r - 1;
|
| 147 |
+
});
|
| 148 |
+
}, 1000);
|
| 149 |
+
return () => clearInterval(timer);
|
| 150 |
+
}, [running]);
|
| 151 |
+
|
| 152 |
+
const time = `${String(Math.floor(remaining / 60)).padStart(2, "0")}:${String(remaining % 60).padStart(2, "0")}`;
|
| 153 |
+
|
| 154 |
+
const mark = () => {
|
| 155 |
+
setError("");
|
| 156 |
+
if (wordCount(answer) < 20) {
|
| 157 |
+
setError("Write at least a couple of sentences before marking.");
|
| 158 |
+
return;
|
| 159 |
+
}
|
| 160 |
+
if (app.credits < CREDIT_COSTS.mockExam) {
|
| 161 |
+
setError("A marked mock exam costs " + CREDIT_COSTS.mockExam + " credits. Mark a paragraph to earn more.");
|
| 162 |
+
return;
|
| 163 |
+
}
|
| 164 |
+
app.spend(CREDIT_COSTS.mockExam);
|
| 165 |
+
setRunning(false);
|
| 166 |
+
const result = reviewText({ text: answer, question, extract, rubric: PARAGRAPH_RUBRIC, title: text.title });
|
| 167 |
+
setFeedback(result);
|
| 168 |
+
app.recordDraft({
|
| 169 |
+
mode: "Mock exam",
|
| 170 |
+
title: text.title,
|
| 171 |
+
question,
|
| 172 |
+
extract,
|
| 173 |
+
text: answer,
|
| 174 |
+
score: result.total,
|
| 175 |
+
max: result.max,
|
| 176 |
+
feedback: result,
|
| 177 |
+
summary: "Timed mock exam"
|
| 178 |
+
});
|
| 179 |
+
};
|
| 180 |
+
|
| 181 |
+
return html`<main class="page narrow">
|
| 182 |
+
<${PageHead} kicker="Mock exam" title="Sit the paper, then mark it."
|
| 183 |
+
subtitle="Twenty-five minutes, one question, one paragraph. Marking costs credits, exactly as it does in the app."
|
| 184 |
+
right=${html`<span class="pill ${remaining === 0 ? "danger" : running ? "warn" : "neutral"}" style=${{ fontFamily: "var(--mono)", fontSize: "13px" }}>${time}</span>`} />
|
| 185 |
+
|
| 186 |
+
<div class="card" style=${{ marginTop: "18px" }}>
|
| 187 |
+
<div class="grid two">
|
| 188 |
+
<div class="field"><label>Text</label>
|
| 189 |
+
<select class="select" value=${textId} onChange=${(e) => setTextId(e.target.value)}>
|
| 190 |
+
${TEXTS.map((t) => html`<option key=${t.id} value=${t.id}>${t.title}</option>`)}
|
| 191 |
+
</select>
|
| 192 |
+
</div>
|
| 193 |
+
<div class="field"><label>Question</label>
|
| 194 |
+
<input class="input" list="mock-questions" value=${question} onInput=${(e) => setQuestion(e.target.value)} />
|
| 195 |
+
<datalist id="mock-questions">${SUGGESTED_QUESTIONS.map((q) => html`<option key=${q} value=${q}></option>`)}</datalist>
|
| 196 |
+
</div>
|
| 197 |
+
</div>
|
| 198 |
+
<div class="field" style=${{ marginTop: "10px" }}>
|
| 199 |
+
<label>Extract <span class="hint">optional</span></label>
|
| 200 |
+
<textarea class="textarea" style=${{ minHeight: "70px" }} value=${extract} onInput=${(e) => setExtract(e.target.value)} placeholder="Paste the passage the question refers to."></textarea>
|
| 201 |
+
</div>
|
| 202 |
+
<div class="row between wrap" style=${{ marginTop: "10px" }}>
|
| 203 |
+
<div class="row">
|
| 204 |
+
<button class="btn small" onClick=${() => setRunning((v) => !v)} disabled=${remaining === 0}>
|
| 205 |
+
<${Icon} name=${running ? "clock" : "clock"} size=${12} /> ${running ? "Pause" : "Start timer"}
|
| 206 |
+
</button>
|
| 207 |
+
<button class="btn small ghost" onClick=${() => { setRunning(false); setRemaining(EXAM_SECONDS); }}>Reset</button>
|
| 208 |
+
<span class="tiny faint">25 minutes</span>
|
| 209 |
+
</div>
|
| 210 |
+
<span class="tiny faint">${wordCount(answer)} words</span>
|
| 211 |
+
</div>
|
| 212 |
+
</div>
|
| 213 |
+
|
| 214 |
+
<div class="card" style=${{ marginTop: "12px" }}>
|
| 215 |
+
<textarea class="textarea" style=${{ minHeight: "280px", border: 0, padding: 0, boxShadow: "none" }} value=${answer} onInput=${(e) => setAnswer(e.target.value)} placeholder="Write your answer here. No notes, no interruptions."></textarea>
|
| 216 |
+
</div>
|
| 217 |
+
|
| 218 |
+
${error && html`<div style=${{ marginTop: "10px" }}><${Notice} kind="error">${error}<//></div>`}
|
| 219 |
+
<div class="row between" style=${{ marginTop: "10px" }}>
|
| 220 |
+
<span class="tiny faint">${app.credits} credits · marking costs ${CREDIT_COSTS.mockExam}</span>
|
| 221 |
+
<button class="btn primary" onClick=${mark}><${Icon} name="check" size=${13} /> Finish and mark</button>
|
| 222 |
+
</div>
|
| 223 |
+
|
| 224 |
+
${feedback && html`<div style=${{ marginTop: "12px" }}><${FeedbackPanel} feedback=${feedback} /><//>`}
|
| 225 |
+
</main>`;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
// ---------------------------------------------------------------------------
|
| 229 |
+
// Process log
|
| 230 |
+
// ---------------------------------------------------------------------------
|
| 231 |
+
|
| 232 |
+
export function ProcessLog() {
|
| 233 |
+
const app = useApp();
|
| 234 |
+
const [open, setOpen] = useState(null);
|
| 235 |
+
const [confirmClear, setConfirmClear] = useState(false);
|
| 236 |
+
const drafts = app.drafts;
|
| 237 |
+
|
| 238 |
+
const exportMarkdown = () => {
|
| 239 |
+
const lines = ["# My writing process — Explication", "", `Exported ${new Date().toLocaleString("en-GB")}`, ""];
|
| 240 |
+
for (const d of [...drafts].reverse()) {
|
| 241 |
+
lines.push(`## ${d.title || "Untitled"} — ${d.score}/${d.max}`);
|
| 242 |
+
lines.push(`_${new Date(d.at).toLocaleDateString("en-GB")} · ${d.mode}${d.question ? " · " + d.question : ""}_`);
|
| 243 |
+
lines.push("");
|
| 244 |
+
lines.push(d.text);
|
| 245 |
+
if (d.feedback && d.feedback.nextStep) {
|
| 246 |
+
lines.push("");
|
| 247 |
+
lines.push(`**Next step:** ${d.feedback.nextStep}`);
|
| 248 |
+
}
|
| 249 |
+
lines.push("");
|
| 250 |
+
}
|
| 251 |
+
lines.push("Exported from Explication. Nothing left this browser.");
|
| 252 |
+
download("explication-writing-process.md", lines.join("\n"));
|
| 253 |
+
};
|
| 254 |
+
|
| 255 |
+
const exportJson = () => {
|
| 256 |
+
download("explication-data.json", JSON.stringify({ settings: app.settings, drafts, credits: app.credits, totalEarned: app.totalEarned, days: app.days }, null, 2), "application/json");
|
| 257 |
+
};
|
| 258 |
+
|
| 259 |
+
return html`<main class="page narrow">
|
| 260 |
+
<${PageHead} kicker="Process log" title="How the writing has changed."
|
| 261 |
+
subtitle="Every marked piece, kept privately in this browser. Read the next steps again before your next attempt."
|
| 262 |
+
right=${html`<button class="btn small" onClick=${exportMarkdown} disabled=${drafts.length === 0}><${Icon} name="download" size=${12} /> Export</button>`} />
|
| 263 |
+
|
| 264 |
+
<div class="grid three" style=${{ marginTop: "18px" }}>
|
| 265 |
+
<div class="stat"><div class="head">Marked</div><div class="value">${drafts.length}</div><div class="note">Pieces</div></div>
|
| 266 |
+
<div class="stat"><div class="head">Average</div><div class="value">${app.average}%</div><div class="note">Across recent work</div></div>
|
| 267 |
+
<div class="stat"><div class="head">Earned</div><div class="value">${app.totalEarned}</div><div class="note">Credits in total</div></div>
|
| 268 |
+
</div>
|
| 269 |
+
|
| 270 |
+
<div class="section-head"><h2 class="section-title">History</h2>
|
| 271 |
+
${drafts.length > 0 && html`<button class="btn link small" onClick=${() => setConfirmClear(true)}>Clear</button>`}
|
| 272 |
+
</div>
|
| 273 |
+
|
| 274 |
+
${confirmClear &&
|
| 275 |
+
html`<div class="callout red" style=${{ marginBottom: "10px", display: "flex", justifyContent: "space-between", gap: "10px", alignItems: "center" }}>
|
| 276 |
+
<span>Delete all ${drafts.length} marked pieces? This cannot be undone.</span>
|
| 277 |
+
<span class="row">
|
| 278 |
+
<button class="btn small" onClick=${() => setConfirmClear(false)}>Keep</button>
|
| 279 |
+
<button class="btn small danger" onClick=${() => { app.resetProgress(); setConfirmClear(false); }}>Delete</button>
|
| 280 |
+
</span>
|
| 281 |
+
</div>`}
|
| 282 |
+
|
| 283 |
+
<div class="card">
|
| 284 |
+
${drafts.length === 0
|
| 285 |
+
? html`<div class="empty"><${Mark} size=${34} /><div style=${{ fontSize: "12px" }}>Mark your first paragraph and it will appear here.</div></div>`
|
| 286 |
+
: html`<div class="list">
|
| 287 |
+
${drafts.map(
|
| 288 |
+
(d) => html`<div key=${d.id}>
|
| 289 |
+
<button class="list-row" style=${{ width: "100%", background: "transparent", border: 0, textAlign: "left", borderTop: "1px solid var(--hairline)" }}
|
| 290 |
+
onClick=${() => setOpen(open === d.id ? null : d.id)}>
|
| 291 |
+
<div class="main">
|
| 292 |
+
<div class="t">${d.title || "Untitled"}${d.question ? " · " + d.question : ""}</div>
|
| 293 |
+
<div class="s">${new Date(d.at).toLocaleDateString("en-GB", { day: "numeric", month: "short", year: "numeric" })} · ${d.mode} · ${wordCount(d.text)} words · +${d.earned || 0} cr</div>
|
| 294 |
+
</div>
|
| 295 |
+
<span class=${"pill " + (d.score / d.max >= 0.7 ? "green" : "neutral")}>${d.score}/${d.max}</span>
|
| 296 |
+
<${Icon} name="chevron" size=${13} />
|
| 297 |
+
</button>
|
| 298 |
+
${open === d.id &&
|
| 299 |
+
html`<div style=${{ padding: "0 0 14px" }}>
|
| 300 |
+
<div class="callout" style=${{ background: "var(--deep)", borderColor: "var(--hairline)", fontFamily: "var(--serif)", fontSize: "14px", whiteSpace: "pre-wrap", lineHeight: 1.65 }}>${d.text}</div>
|
| 301 |
+
${d.feedback && d.feedback.nextStep && html`<div class="callout blue" style=${{ marginTop: "8px" }}><strong>Next step. </strong>${d.feedback.nextStep}</div>`}
|
| 302 |
+
<div class="row" style=${{ marginTop: "8px" }}>
|
| 303 |
+
<button class="btn small ghost danger" onClick=${() => app.deleteDraft(d.id)}><${Icon} name="trash" size=${11} /> Delete this entry</button>
|
| 304 |
+
</div>
|
| 305 |
+
</div>`}
|
| 306 |
+
</div>`
|
| 307 |
+
)}
|
| 308 |
+
</div>`}
|
| 309 |
+
</div>
|
| 310 |
+
|
| 311 |
+
<div class="row" style=${{ marginTop: "12px" }}>
|
| 312 |
+
<button class="btn small" onClick=${exportJson}><${Icon} name="download" size=${12} /> Export data</button>
|
| 313 |
+
<span class="tiny faint">Your writing never leaves this browser.</span>
|
| 314 |
+
</div>
|
| 315 |
+
</main>`;
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
// ---------------------------------------------------------------------------
|
| 319 |
+
// Settings
|
| 320 |
+
// ---------------------------------------------------------------------------
|
| 321 |
+
|
| 322 |
+
export function Settings() {
|
| 323 |
+
const app = useApp();
|
| 324 |
+
const engine = useEngine();
|
| 325 |
+
const cloud = useCloud();
|
| 326 |
+
const [chosenId, setChosenId] = useState("");
|
| 327 |
+
const selectedModel =
|
| 328 |
+
cloud.models.find((m) => m.id === chosenId) || cloud.models.find((m) => Number(m.min_tier || 0) <= 1) || cloud.models[0] || null;
|
| 329 |
+
const modelId = selectedModel ? selectedModel.id : "";
|
| 330 |
+
const downloadAllowed = selectedModel ? cloud.canDownload(selectedModel.min_tier) : false;
|
| 331 |
+
const [baseUrl, setBaseUrl] = useState(engine.endpoint.baseUrl);
|
| 332 |
+
const [endpointModel, setEndpointModel] = useState(engine.endpoint.model);
|
| 333 |
+
const [key, setKey] = useState(engine.endpoint.key);
|
| 334 |
+
const [saved, setSaved] = useState(false);
|
| 335 |
+
const [confirmReset, setConfirmReset] = useState(false);
|
| 336 |
+
|
| 337 |
+
const saveEndpoint = () => {
|
| 338 |
+
engine.setEndpoint({ baseUrl, model: endpointModel, key });
|
| 339 |
+
setSaved(true);
|
| 340 |
+
setTimeout(() => setSaved(false), 2000);
|
| 341 |
+
};
|
| 342 |
+
|
| 343 |
+
return html`<main class="page narrow">
|
| 344 |
+
<${PageHead} kicker="Settings" title="How Explication works here."
|
| 345 |
+
subtitle="Your name, your exam board and the model behind the feedback. Everything is stored locally in this browser." />
|
| 346 |
+
|
| 347 |
+
<div class="section-head"><h2 class="section-title">You</h2></div>
|
| 348 |
+
<div class="card">
|
| 349 |
+
<div class="grid two">
|
| 350 |
+
<div class="field"><label>Name <span class="hint">optional</span></label>
|
| 351 |
+
<input class="input" value=${app.settings.name} onInput=${(e) => app.setSettings({ name: e.target.value })} placeholder="What should the coach call you?" />
|
| 352 |
+
</div>
|
| 353 |
+
<div class="field"><label>Year group</label>
|
| 354 |
+
<select class="select" value=${app.settings.yearGroup} onChange=${(e) => app.setSettings({ yearGroup: e.target.value })}>
|
| 355 |
+
${["Year 9", "Year 10", "Year 11", "Year 12", "Year 13"].map((y) => html`<option key=${y} value=${y}>${y}</option>`)}
|
| 356 |
+
</select>
|
| 357 |
+
</div>
|
| 358 |
+
<div class="field"><label>Exam board</label>
|
| 359 |
+
<select class="select" value=${app.settings.board} onChange=${(e) => app.setSettings({ board: e.target.value })}>
|
| 360 |
+
${["AQA", "Edexcel", "OCR", "WJEC", "CCEA"].map((b) => html`<option key=${b} value=${b}>${b}</option>`)}
|
| 361 |
+
</select>
|
| 362 |
+
</div>
|
| 363 |
+
<div class="field"><label>Credits</label><input class="input" value=${`${app.credits} available · ${app.totalEarned} earned`} disabled /></div>
|
| 364 |
+
</div>
|
| 365 |
+
</div>
|
| 366 |
+
|
| 367 |
+
<div class="section-head"><h2 class="section-title">Marking</h2></div>
|
| 368 |
+
<div class="card">
|
| 369 |
+
<div class="row between">
|
| 370 |
+
<div>
|
| 371 |
+
<div style=${{ fontWeight: 600 }}>Rule-based review</div>
|
| 372 |
+
<div class="tiny faint" style=${{ maxWidth: "520px", marginTop: "3px", lineHeight: 1.55 }}>
|
| 373 |
+
Paragraph, essay, poetry, improve and mock-exam marking all run here: the rubric, quotation checking and the next-step guidance work with no model and no network.
|
| 374 |
+
</div>
|
| 375 |
+
</div>
|
| 376 |
+
<${Pill} tone="green">Always on</${Pill}>
|
| 377 |
+
</div>
|
| 378 |
+
<div class="divider"></div>
|
| 379 |
+
<div class="row between">
|
| 380 |
+
<div>
|
| 381 |
+
<div style=${{ fontWeight: 600 }}>Browser model <span class="tiny faint">WebGPU</span></div>
|
| 382 |
+
<div class="tiny faint" style=${{ marginTop: "3px" }}>
|
| 383 |
+
${engine.webgpu ? "This browser can run a model locally. The weights download once, then work offline." : "This browser does not expose WebGPU, so a local model cannot run here. Use an endpoint below, or keep using rule-based review."}
|
| 384 |
+
</div>
|
| 385 |
+
</div>
|
| 386 |
+
<${Pill} tone=${engine.webgpu ? "green" : "neutral"}>${engine.webgpu ? "Available" : "Unavailable"}</${Pill}>
|
| 387 |
+
</div>
|
| 388 |
+
${engine.webgpu &&
|
| 389 |
+
html`<div class="row wrap" style=${{ marginTop: "10px" }}>
|
| 390 |
+
<select class="select" style=${{ maxWidth: "300px" }} value=${modelId} onChange=${(e) => setChosenId(e.target.value)}>
|
| 391 |
+
${cloud.models.filter((m) => m.enabled !== false).map(
|
| 392 |
+
(m) => html`<option key=${m.id} value=${m.id}>${m.name} · ${m.download_size}${cloud.canDownload(m.min_tier) ? "" : " · needs a plan"}</option>`
|
| 393 |
+
)}
|
| 394 |
+
</select>
|
| 395 |
+
<button class="btn" onClick=${() => engine.load(modelId)} disabled=${engine.status === "loading" || !downloadAllowed}>
|
| 396 |
+
${engine.status === "loading" ? html`<span class="spin"></span>` : html`<${Icon} name=${downloadAllowed ? "download" : "lock"} size=${13} />`} ${engine.status === "ready" ? "Reload" : "Load model"}
|
| 397 |
+
</button>
|
| 398 |
+
${engine.status === "ready" && html`<button class="btn ghost" onClick=${engine.unload}>Unload</button>`}
|
| 399 |
+
</div>
|
| 400 |
+
${!downloadAllowed &&
|
| 401 |
+
html`<div class="tiny" style=${{ marginTop: "6px", color: "var(--warning)" }}>
|
| 402 |
+
${selectedModel ? selectedModel.name : "This model"} is part of a paid plan. <a href="#/pricing">See plans</a>
|
| 403 |
+
</div>`}`}
|
| 404 |
+
${engine.status === "loading" &&
|
| 405 |
+
html`<div style=${{ marginTop: "10px" }}>
|
| 406 |
+
<div class="bar"><i style=${{ width: Math.round(engine.progress * 100) + "%" }}></i></div>
|
| 407 |
+
<div class="tiny faint" style=${{ marginTop: "4px" }}>${engine.progressText || "Loading…"}</div>
|
| 408 |
+
</div>`}
|
| 409 |
+
${engine.error && html`<div style=${{ marginTop: "10px" }}><${Notice} kind="error">${engine.error}<//></div>`}
|
| 410 |
+
|
| 411 |
+
<div class="divider"></div>
|
| 412 |
+
<div style=${{ fontWeight: 600 }}>Your OpenAI-compatible endpoint</div>
|
| 413 |
+
<div class="tiny faint" style=${{ marginTop: "3px" }}>
|
| 414 |
+
Optional. Bring any endpoint that speaks <span class="mono">POST /chat/completions</span>. The key is kept in this browser only and sent only to that URL.
|
| 415 |
+
</div>
|
| 416 |
+
<div class="grid two" style=${{ marginTop: "10px" }}>
|
| 417 |
+
<div class="field"><label>Base URL</label><input class="input" value=${baseUrl} onInput=${(e) => setBaseUrl(e.target.value)} placeholder="http://127.0.0.1:11434/v1" /></div>
|
| 418 |
+
<div class="field"><label>Model</label><input class="input" value=${endpointModel} onInput=${(e) => setEndpointModel(e.target.value)} placeholder="qwen2.5:7b" /></div>
|
| 419 |
+
</div>
|
| 420 |
+
<div class="field" style=${{ marginTop: "10px" }}><label>API key <span class="hint">optional</span></label>
|
| 421 |
+
<input class="input" type="password" value=${key} onInput=${(e) => setKey(e.target.value)} placeholder="sk-…" autocomplete="off" />
|
| 422 |
+
</div>
|
| 423 |
+
<div class="row between" style=${{ marginTop: "10px" }}>
|
| 424 |
+
<span class="tiny faint">${engine.hasEndpoint ? "Connected: " + engine.endpoint.model : "No endpoint connected yet."}</span>
|
| 425 |
+
<button class="btn primary small" onClick=${saveEndpoint}>${saved ? "Saved" : "Save endpoint"}</button>
|
| 426 |
+
</div>
|
| 427 |
+
</div>
|
| 428 |
+
|
| 429 |
+
<div class="section-head"><h2 class="section-title">Hosted models</h2>
|
| 430 |
+
<a class="btn link small" href="#/pricing">See plans</a>
|
| 431 |
+
</div>
|
| 432 |
+
<div class="card">
|
| 433 |
+
${!cloud.configured
|
| 434 |
+
? html`<div class="row between wrap">
|
| 435 |
+
<div style=${{ maxWidth: "520px" }}>
|
| 436 |
+
<div style=${{ fontWeight: 600 }}>Not connected</div>
|
| 437 |
+
<div class="tiny faint" style=${{ marginTop: "3px", lineHeight: 1.55 }}>
|
| 438 |
+
Hosted models run on the site owner's API keys and are metered against a plan's budget. Connect Supabase and choose a plan to use them.
|
| 439 |
+
</div>
|
| 440 |
+
</div>
|
| 441 |
+
<a class="btn small" href="#/connect">Connect Supabase</a>
|
| 442 |
+
</div>`
|
| 443 |
+
: !cloud.user
|
| 444 |
+
? html`<div class="row between wrap">
|
| 445 |
+
<div style=${{ maxWidth: "520px" }}>
|
| 446 |
+
<div style=${{ fontWeight: 600 }}>Sign in to use hosted models</div>
|
| 447 |
+
<div class="tiny faint" style=${{ marginTop: "3px" }}>Your plan's included budget is attached to your account.</div>
|
| 448 |
+
</div>
|
| 449 |
+
<a class="btn small" href="#/account">Sign in</a>
|
| 450 |
+
</div>`
|
| 451 |
+
: !cloud.plan
|
| 452 |
+
? html`<div class="row between wrap">
|
| 453 |
+
<div style=${{ maxWidth: "520px" }}>
|
| 454 |
+
<div style=${{ fontWeight: 600 }}>No plan on this account</div>
|
| 455 |
+
<div class="tiny faint" style=${{ marginTop: "3px" }}>A subscription includes hosted model usage. You can keep using your own key or the free offline model.</div>
|
| 456 |
+
</div>
|
| 457 |
+
<a class="btn small primary" href="#/pricing">Choose a plan</a>
|
| 458 |
+
</div>`
|
| 459 |
+
: html`<div>
|
| 460 |
+
<div class="row between wrap">
|
| 461 |
+
<div>
|
| 462 |
+
<div style=${{ fontWeight: 600 }}>${cloud.plan.name}</div>
|
| 463 |
+
<div class="tiny faint" style=${{ marginTop: "2px" }}>
|
| 464 |
+
${cloud.budget.limit ? Math.max(0, Math.round((cloud.budget.remaining / cloud.budget.limit) * 100)) + "% of your included AI left this period" : "No hosted AI included"}
|
| 465 |
+
</div>
|
| 466 |
+
</div>
|
| 467 |
+
<a class="btn small" href="#/account">Manage</a>
|
| 468 |
+
</div>
|
| 469 |
+
${cloud.budget.limit > 0 &&
|
| 470 |
+
html`<div class="row wrap" style=${{ marginTop: "10px" }}>
|
| 471 |
+
<select class="select" style=${{ maxWidth: "320px" }} value=${engine.hostedId} onChange=${(e) => engine.setHostedModel(e.target.value)}>
|
| 472 |
+
<option value="">Use the offline model instead</option>
|
| 473 |
+
${cloud.models
|
| 474 |
+
.filter((m) => m.enabled !== false && m.endpoint_url)
|
| 475 |
+
.map((m) => html`<option key=${m.id} value=${m.id}>${m.name} · ${m.host || "hosted"}</option>`)}
|
| 476 |
+
</select>
|
| 477 |
+
<span class="tiny faint">${engine.hostedReady ? "In use when no personal endpoint is set." : ""}</span>
|
| 478 |
+
</div>`}
|
| 479 |
+
</div>`}
|
| 480 |
+
</div>
|
| 481 |
+
|
| 482 |
+
<div class="section-head"><h2 class="section-title">Data</h2></div>
|
| 483 |
+
<div class="card">
|
| 484 |
+
<div class="row between wrap">
|
| 485 |
+
<div>
|
| 486 |
+
<div style=${{ fontWeight: 600 }}>Export</div>
|
| 487 |
+
<div class="tiny faint">Download your drafts, settings and credits as JSON.</div>
|
| 488 |
+
</div>
|
| 489 |
+
<button class="btn small" onClick=${() => download("explication-data.json", JSON.stringify({ settings: app.settings, drafts: app.drafts, credits: app.credits, totalEarned: app.totalEarned, days: app.days }, null, 2), "application/json")}>Export data</button>
|
| 490 |
+
</div>
|
| 491 |
+
<div class="divider"></div>
|
| 492 |
+
<div class="row between wrap">
|
| 493 |
+
<div>
|
| 494 |
+
<div style=${{ fontWeight: 600 }}>Reset progress</div>
|
| 495 |
+
<div class="tiny faint">Clears drafts, credits and streaks. Settings are kept.</div>
|
| 496 |
+
</div>
|
| 497 |
+
${confirmReset
|
| 498 |
+
? html`<span class="row"><button class="btn small" onClick=${() => setConfirmReset(false)}>Cancel</button><button class="btn small danger" onClick=${() => { app.resetProgress(); setConfirmReset(false); }}>Reset</button></span>`
|
| 499 |
+
: html`<button class="btn small danger" onClick=${() => setConfirmReset(true)}>Reset</button>`}
|
| 500 |
+
</div>
|
| 501 |
+
</div>
|
| 502 |
+
|
| 503 |
+
<div class="section-head"><h2 class="section-title">About</h2></div>
|
| 504 |
+
<div class="card">
|
| 505 |
+
<div class="row" style=${{ gap: "12px" }}>
|
| 506 |
+
<${Mark} size=${40} />
|
| 507 |
+
<div>
|
| 508 |
+
<div style=${{ fontWeight: 600 }}>Explication for the web</div>
|
| 509 |
+
<div class="tiny faint">Version 1.0 · GCSE English Literature · British English</div>
|
| 510 |
+
</div>
|
| 511 |
+
</div>
|
| 512 |
+
<p class="tiny faint" style=${{ marginTop: "10px", lineHeight: 1.6 }}>
|
| 513 |
+
The same rubric, credit economy, quotation checking and process log as the Mac and iOS app. On the web the marking runs as a deterministic review; connect a model for chat, model answers and rewritten suggestions. No account, no analytics, no uploads.
|
| 514 |
+
</p>
|
| 515 |
+
</div>
|
| 516 |
+
</main>`;
|
| 517 |
+
}
|
js/screens.js
ADDED
|
@@ -0,0 +1,743 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { React, html, useEffect, useMemo, useRef, useState } from "./runtime.js";
|
| 2 |
+
import { useApp } from "./store.js";
|
| 3 |
+
import { useEngine, WEB_MODELS } from "./engine.js";
|
| 4 |
+
import { Copy } from "./copy.js";
|
| 5 |
+
import {
|
| 6 |
+
Mark,
|
| 7 |
+
FeedbackPanel,
|
| 8 |
+
Notice,
|
| 9 |
+
Pill,
|
| 10 |
+
ScoreRing,
|
| 11 |
+
CriterionList,
|
| 12 |
+
usePersistent,
|
| 13 |
+
download,
|
| 14 |
+
Icon,
|
| 15 |
+
SECTIONS
|
| 16 |
+
} from "./components.js";
|
| 17 |
+
import {
|
| 18 |
+
CREDIT_COSTS,
|
| 19 |
+
ESSAY_PART_META,
|
| 20 |
+
ESSAY_RUBRICS,
|
| 21 |
+
PARAGRAPH_RUBRIC,
|
| 22 |
+
SUGGESTED_QUESTIONS,
|
| 23 |
+
TEXTS,
|
| 24 |
+
awardCredits,
|
| 25 |
+
checkQuotes,
|
| 26 |
+
combineEssay,
|
| 27 |
+
creditsForEssay,
|
| 28 |
+
levelTitle,
|
| 29 |
+
reviewEssayPart,
|
| 30 |
+
reviewParagraph,
|
| 31 |
+
reviewText,
|
| 32 |
+
sentenceList,
|
| 33 |
+
wordCount,
|
| 34 |
+
buildMarkingMessages,
|
| 35 |
+
parseMarkingReply
|
| 36 |
+
} from "./marking.js";
|
| 37 |
+
|
| 38 |
+
// ---------------------------------------------------------------------------
|
| 39 |
+
// Shared pieces
|
| 40 |
+
// ---------------------------------------------------------------------------
|
| 41 |
+
|
| 42 |
+
function PageHead({ kicker, title, subtitle, right }) {
|
| 43 |
+
return html`<div class="row between" style=${{ alignItems: "flex-start", gap: "16px" }}>
|
| 44 |
+
<div>
|
| 45 |
+
<div class="eyebrow">${kicker}</div>
|
| 46 |
+
<h1 class="page-title">${title}</h1>
|
| 47 |
+
${subtitle && html`<p class="subtitle">${subtitle}</p>`}
|
| 48 |
+
</div>
|
| 49 |
+
${right}
|
| 50 |
+
</div>`;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
function WordCounter({ text }) {
|
| 54 |
+
return html`<span class="count">${wordCount(text)} words</span>`;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
function QuestionField({ value, onChange, placeholder }) {
|
| 58 |
+
return html`<div class="field">
|
| 59 |
+
<label>Question <span class="hint">optional</span></label>
|
| 60 |
+
<input class="input" list="question-ideas" value=${value} onInput=${(e) => onChange(e.target.value)} placeholder=${placeholder} />
|
| 61 |
+
<datalist id="question-ideas">
|
| 62 |
+
${SUGGESTED_QUESTIONS.map((q) => html`<option key=${q} value=${q}></option>`)}
|
| 63 |
+
</datalist>
|
| 64 |
+
</div>`;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
function TextPicker({ value, onChange }) {
|
| 68 |
+
return html`<div class="field">
|
| 69 |
+
<label>Text</label>
|
| 70 |
+
<select class="select" value=${value} onChange=${(e) => onChange(e.target.value)}>
|
| 71 |
+
${TEXTS.map((t) => html`<option key=${t.id} value=${t.id}>${t.title}${t.author ? " · " + t.author : ""}</option>`)}
|
| 72 |
+
</select>
|
| 73 |
+
</div>`;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
function EngineHint({ compact = false }) {
|
| 77 |
+
const engine = useEngine();
|
| 78 |
+
if (engine.canGenerate) {
|
| 79 |
+
return html`<${Notice} kind="info">Model connected — ${engine.hasEndpoint ? "using your endpoint." : "running in this browser."} Chat and model answers are available.<//>`;
|
| 80 |
+
}
|
| 81 |
+
return html`<${Notice} kind="warn">
|
| 82 |
+
AI chat and model answers need a model. ${engine.webgpu ? "Load a browser model" : "This browser has no WebGPU"}${" "}
|
| 83 |
+
<a href="#/settings">in Settings</a> or connect an OpenAI-compatible endpoint. The marking tools below work without one.
|
| 84 |
+
<//>`;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
// ---------------------------------------------------------------------------
|
| 88 |
+
// Dashboard
|
| 89 |
+
// ---------------------------------------------------------------------------
|
| 90 |
+
|
| 91 |
+
export function Dashboard({ onNavigate }) {
|
| 92 |
+
const app = useApp();
|
| 93 |
+
const engine = useEngine();
|
| 94 |
+
const hour = new Date().getHours();
|
| 95 |
+
const greeting = hour < 12 ? "Good morning." : hour < 18 ? "Good afternoon." : "Good evening.";
|
| 96 |
+
const date = new Date().toLocaleDateString("en-GB", { weekday: "long", day: "numeric", month: "long" });
|
| 97 |
+
const recent = app.drafts.slice(0, 5);
|
| 98 |
+
const practice = [
|
| 99 |
+
{ id: "essay", title: "Essay", text: "Five parts, thirty marks, one argument." },
|
| 100 |
+
{ id: "poetry", title: "Unseen poetry", text: "Paste the poem. Check every quotation." },
|
| 101 |
+
{ id: "improve", title: "Improve", text: "One sentence at a time." },
|
| 102 |
+
{ id: "mockExam", title: "Mock exam", text: "Sit a timed paper, then mark it." }
|
| 103 |
+
];
|
| 104 |
+
|
| 105 |
+
return html`<main class="page">
|
| 106 |
+
<div class="eyebrow">${date.toUpperCase()}</div>
|
| 107 |
+
<h1 class="display">${greeting}</h1>
|
| 108 |
+
<p class="subtitle">
|
| 109 |
+
${app.settings.name ? app.settings.name + ", a" : "A"} quiet place to practise the paragraph, then see exactly what to improve.
|
| 110 |
+
</p>
|
| 111 |
+
|
| 112 |
+
<div class="card hero" style=${{ marginTop: "18px" }}>
|
| 113 |
+
<div style=${{ maxWidth: "520px" }}>
|
| 114 |
+
<h2 class="card-title"><${Copy} id="dashboard.hero.title">Your writing, marked offline.</${Copy}></h2>
|
| 115 |
+
<p class="subtitle" style=${{ margin: "0 0 14px" }}>
|
| 116 |
+
<${Copy} id="dashboard.hero.body">Paste a paragraph, add the extract if you have one, and get a mark out of ten against the GCSE criteria — with the single next change that matters.</${Copy}>
|
| 117 |
+
</p>
|
| 118 |
+
<div class="row wrap">
|
| 119 |
+
<button class="btn primary" onClick=${() => onNavigate("coach")}><${Icon} name="pen" size=${14} /> New feedback</button>
|
| 120 |
+
<button class="btn" onClick=${() => onNavigate("chat")}><${Icon} name="chat" size=${14} /> Talk it through</button>
|
| 121 |
+
</div>
|
| 122 |
+
</div>
|
| 123 |
+
<${Mark} size=${64} />
|
| 124 |
+
</div>
|
| 125 |
+
|
| 126 |
+
<div class="grid four" style=${{ marginTop: "12px" }}>
|
| 127 |
+
<div class="stat"><div class="head">Credits <span>✦</span></div><div class="value">${app.credits}</div><div class="note">Earned by marking</div></div>
|
| 128 |
+
<div class="stat"><div class="head">Streak</div><div class="value">${app.streak} <span style=${{ fontSize: "13px", color: "var(--faint)" }}>days</span></div><div class="note">Consecutive marked days</div></div>
|
| 129 |
+
<div class="stat"><div class="head">Level</div><div class="value">${app.level}</div><div class="note">${levelTitle(app.level)}</div></div>
|
| 130 |
+
<div class="stat"><div class="head">Average</div><div class="value">${app.average}%</div><div class="note">Last ${Math.min(20, app.drafts.length)} marked pieces</div></div>
|
| 131 |
+
</div>
|
| 132 |
+
|
| 133 |
+
<div class="card" style=${{ marginTop: "12px" }}>
|
| 134 |
+
<div class="row between wrap" style=${{ alignItems: "flex-start" }}>
|
| 135 |
+
<div style=${{ maxWidth: "560px" }}>
|
| 136 |
+
<div class="row" style=${{ gap: "7px" }}><i style=${{ width: 6, height: 6, borderRadius: "50%", background: engine.canGenerate ? "var(--success)" : "var(--warning)" }}></i>
|
| 137 |
+
<span class="mini-label" style=${{ color: "var(--secondary)" }}>${engine.canGenerate ? "Model connected" : "Rule-based review"}</span>
|
| 138 |
+
</div>
|
| 139 |
+
<div style=${{ fontWeight: 600, marginTop: "6px" }}>${engine.hasEndpoint ? "Your endpoint" : engine.status === "ready" ? "Browser model" : "Marks in this browser"}</div>
|
| 140 |
+
<div class="tiny faint" style=${{ marginTop: "2px", lineHeight: 1.5 }}>
|
| 141 |
+
${engine.canGenerate
|
| 142 |
+
? "Chat, model answers and AI suggestions are available. Marking still checks the rubric point by point."
|
| 143 |
+
: "Every mark is computed here from your words, quotations and technique — no upload, no account. Connect a model for chat and model answers."}
|
| 144 |
+
</div>
|
| 145 |
+
</div>
|
| 146 |
+
<button class="btn small" onClick=${() => onNavigate("settings")}>Model settings</button>
|
| 147 |
+
</div>
|
| 148 |
+
</div>
|
| 149 |
+
|
| 150 |
+
<div class="section-head"><h2 class="section-title"><${Copy} id="dashboard.practice.title">Other ways to practise</${Copy}></h2></div>
|
| 151 |
+
<div class="grid four">
|
| 152 |
+
${practice.map(
|
| 153 |
+
(p) => html`<button key=${p.id} class="card flat" style=${{ textAlign: "left" }} onClick=${() => onNavigate(p.id)}>
|
| 154 |
+
<div style=${{ fontFamily: "var(--serif)", fontSize: "15px", fontWeight: 600 }}>${p.title}</div>
|
| 155 |
+
<div class="tiny faint" style=${{ marginTop: "4px", lineHeight: 1.5 }}>${p.text}</div>
|
| 156 |
+
<div class="tiny" style=${{ color: "var(--accent)", marginTop: "9px", fontWeight: 600 }}>Open →</div>
|
| 157 |
+
</button>`
|
| 158 |
+
)}
|
| 159 |
+
</div>
|
| 160 |
+
|
| 161 |
+
<div class="section-head">
|
| 162 |
+
<h2 class="section-title">Recent</h2>
|
| 163 |
+
${recent.length > 0 && html`<button class="btn link small" onClick=${() => onNavigate("process")}>Process log</button>`}
|
| 164 |
+
</div>
|
| 165 |
+
<div class="card">
|
| 166 |
+
${recent.length === 0
|
| 167 |
+
? html`<div class="empty"><${Mark} size=${34} /><div style=${{ fontSize: "12px" }}>Your first marked piece will appear here.</div></div>`
|
| 168 |
+
: html`<div class="list">
|
| 169 |
+
${recent.map(
|
| 170 |
+
(d) => html`<div class="list-row" key=${d.id}>
|
| 171 |
+
<div class="main">
|
| 172 |
+
<div class="t">${d.title || "Untitled"}${d.question ? " · " + d.question : ""}</div>
|
| 173 |
+
<div class="s">${new Date(d.at).toLocaleDateString("en-GB", { day: "numeric", month: "short" })} · ${d.mode} · ${wordCount(d.text)} words</div>
|
| 174 |
+
</div>
|
| 175 |
+
<span class="pill green">${d.score}/${d.max}</span>
|
| 176 |
+
</div>`
|
| 177 |
+
)}
|
| 178 |
+
</div>`}
|
| 179 |
+
</div>
|
| 180 |
+
</main>`;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
// ---------------------------------------------------------------------------
|
| 184 |
+
// Chat
|
| 185 |
+
// ---------------------------------------------------------------------------
|
| 186 |
+
|
| 187 |
+
const CHAT_SYSTEM = [
|
| 188 |
+
"You are Explication, a GCSE English Literature writing coach for students in England.",
|
| 189 |
+
"You are in a normal conversation. Answer questions about texts, techniques, marks and revision in British English.",
|
| 190 |
+
"Address the student as 'you'. Be precise, warm and brief: at most 140 words unless asked for more.",
|
| 191 |
+
"Never write the student's paragraph or essay for them in chat. If they ask for finished work, explain that the paid 'Write paragraph' action produces a clearly labelled study draft instead."
|
| 192 |
+
].join(" ");
|
| 193 |
+
|
| 194 |
+
export function Chat() {
|
| 195 |
+
const app = useApp();
|
| 196 |
+
const engine = useEngine();
|
| 197 |
+
const [input, setInput] = useState("");
|
| 198 |
+
const [busy, setBusy] = useState(false);
|
| 199 |
+
const [streaming, setStreaming] = useState("");
|
| 200 |
+
const [error, setError] = useState("");
|
| 201 |
+
const [pending, setPending] = useState(false);
|
| 202 |
+
const [showExtract, setShowExtract] = useState(false);
|
| 203 |
+
const endRef = useRef(null);
|
| 204 |
+
|
| 205 |
+
useEffect(() => {
|
| 206 |
+
if (endRef.current) endRef.current.scrollIntoView({ behavior: "smooth", block: "end" });
|
| 207 |
+
}, [app.chat.length, streaming]);
|
| 208 |
+
|
| 209 |
+
const send = async () => {
|
| 210 |
+
const text = input.trim();
|
| 211 |
+
if (!text || busy) return;
|
| 212 |
+
if (!engine.canGenerate) {
|
| 213 |
+
setError("Chatting needs a model. Open Settings to load a browser model or connect an endpoint. The marking tools work without one.");
|
| 214 |
+
return;
|
| 215 |
+
}
|
| 216 |
+
setError("");
|
| 217 |
+
setInput("");
|
| 218 |
+
setBusy(true);
|
| 219 |
+
setStreaming("");
|
| 220 |
+
app.addChat({ role: "student", text });
|
| 221 |
+
try {
|
| 222 |
+
const history = app.chat.slice(-8).map((m) => ({
|
| 223 |
+
role: m.role === "student" ? "user" : "assistant",
|
| 224 |
+
content: m.text
|
| 225 |
+
}));
|
| 226 |
+
const messages = [
|
| 227 |
+
{ role: "system", content: CHAT_SYSTEM },
|
| 228 |
+
...(app.chatExtract.trim()
|
| 229 |
+
? [{ role: "system", content: "The student is working with this extract:\n" + app.chatExtract.slice(0, 4000) }]
|
| 230 |
+
: []),
|
| 231 |
+
...history,
|
| 232 |
+
{ role: "user", content: text }
|
| 233 |
+
];
|
| 234 |
+
const full = await engine.chat(messages, setStreaming);
|
| 235 |
+
app.addChat({ role: "assistant", text: full || "(No reply.)" });
|
| 236 |
+
} catch (err) {
|
| 237 |
+
setError(err && err.message ? err.message : "The model could not reply.");
|
| 238 |
+
}
|
| 239 |
+
setStreaming("");
|
| 240 |
+
setBusy(false);
|
| 241 |
+
};
|
| 242 |
+
|
| 243 |
+
const writeParagraph = async () => {
|
| 244 |
+
if (!engine.canGenerate || app.credits < CREDIT_COSTS.paragraphWriting) return;
|
| 245 |
+
const topic = input.trim() || "the extract and question we are discussing";
|
| 246 |
+
setPending(false);
|
| 247 |
+
setError("");
|
| 248 |
+
setBusy(true);
|
| 249 |
+
setStreaming("");
|
| 250 |
+
app.spend(CREDIT_COSTS.paragraphWriting);
|
| 251 |
+
app.addChat({ role: "student", text: "Write a study paragraph about: " + topic });
|
| 252 |
+
try {
|
| 253 |
+
const messages = [
|
| 254 |
+
{
|
| 255 |
+
role: "system",
|
| 256 |
+
content:
|
| 257 |
+
"You write a single model GCSE English Literature paragraph for study, clearly labelled as AI-written. 120-180 words, British English. Embed one or two short quotations only if an extract is supplied; never invent quotations. Return only the paragraph."
|
| 258 |
+
},
|
| 259 |
+
{
|
| 260 |
+
role: "user",
|
| 261 |
+
content: (app.chatExtract ? "Extract:\n" + app.chatExtract + "\n\n" : "") + "Topic: " + topic
|
| 262 |
+
}
|
| 263 |
+
];
|
| 264 |
+
const full = await engine.chat(messages, setStreaming);
|
| 265 |
+
app.addChat({ role: "draft", text: full || "(No draft.)" });
|
| 266 |
+
} catch (err) {
|
| 267 |
+
setError(err && err.message ? err.message : "The draft could not be written.");
|
| 268 |
+
app.addCredits(CREDIT_COSTS.paragraphWriting);
|
| 269 |
+
}
|
| 270 |
+
setStreaming("");
|
| 271 |
+
setBusy(false);
|
| 272 |
+
};
|
| 273 |
+
|
| 274 |
+
return html`<main class="chat-wrap">
|
| 275 |
+
<div class="transcript">
|
| 276 |
+
<div class="transcript-inner">
|
| 277 |
+
${!engine.canGenerate && html`<${EngineHint} />`}
|
| 278 |
+
${error && html`<${Notice} kind="error">${error}<//>`}
|
| 279 |
+
${app.chat.length === 0 &&
|
| 280 |
+
html`<div class="card" style=${{ marginTop: "6px" }}>
|
| 281 |
+
<div class="row" style=${{ gap: "10px", marginBottom: "10px" }}><${Mark} size=${38} />
|
| 282 |
+
<div><div class="eyebrow">Paragraph, in conversation</div>
|
| 283 |
+
<div style=${{ fontFamily: "var(--serif)", fontSize: "21px", fontWeight: 600 }}>Ask me anything.</div></div>
|
| 284 |
+
</div>
|
| 285 |
+
<p class="subtitle" style=${{ margin: 0 }}>
|
| 286 |
+
Ask about a character, a technique, your marks or how to revise. Chatting is free. Asking for a finished paragraph costs ${CREDIT_COSTS.paragraphWriting} credits and is always labelled AI-written.
|
| 287 |
+
</p>
|
| 288 |
+
<div class="row wrap" style=${{ marginTop: "12px" }}>
|
| 289 |
+
${[
|
| 290 |
+
"What does a semantic field actually mean?",
|
| 291 |
+
"How should I revise Macbeth's ambition?",
|
| 292 |
+
"Why did I lose effect marks?"
|
| 293 |
+
].map(
|
| 294 |
+
(q) => html`<button key=${q} class="btn small" onClick=${() => setInput(q)}>${q}</button>`
|
| 295 |
+
)}
|
| 296 |
+
</div>
|
| 297 |
+
</div>`}
|
| 298 |
+
${app.chat.map(
|
| 299 |
+
(m) => html`<div class=${"msg " + (m.role === "student" ? "student" : "")} key=${m.id}>
|
| 300 |
+
${m.role !== "student" && html`<${Mark} size=${24} />`}
|
| 301 |
+
<div>
|
| 302 |
+
<div class="who">${m.role === "student" ? "You" : m.role === "draft" ? "AI-written study draft" : "Explication"}</div>
|
| 303 |
+
<div class="bubble" style=${m.role === "draft" ? { background: "var(--warning-soft)", borderColor: "#f0dcc5" } : {}}>${m.text}</div>
|
| 304 |
+
${m.role === "draft" && html`<div class="tiny" style=${{ color: "var(--warning)", marginTop: "4px" }}>Study material only — do not submit this as your own work.</div>`}
|
| 305 |
+
</div>
|
| 306 |
+
</div>`
|
| 307 |
+
)}
|
| 308 |
+
${streaming &&
|
| 309 |
+
html`<div class="msg"><${Mark} size=${24} />
|
| 310 |
+
<div><div class="who">Explication</div><div class="bubble">${streaming}</div></div>
|
| 311 |
+
</div>`}
|
| 312 |
+
${busy && !streaming && html`<div class="msg"><${Mark} size=${24} /><div class="bubble"><span class="spin"></span></div></div>`}
|
| 313 |
+
<div ref=${endRef}></div>
|
| 314 |
+
</div>
|
| 315 |
+
</div>
|
| 316 |
+
|
| 317 |
+
<div class="composer-dock">
|
| 318 |
+
<div class="composer">
|
| 319 |
+
${showExtract &&
|
| 320 |
+
html`<div style=${{ padding: "4px 4px 8px" }}>
|
| 321 |
+
<div class="field">
|
| 322 |
+
<label>Extract <span class="hint">optional · quotations are checked against it</span></label>
|
| 323 |
+
<textarea class="textarea plain" style=${{ minHeight: "80px", fontFamily: "var(--serif)" }} value=${app.chatExtract} onInput=${(e) => app.setChatExtract(e.target.value)} placeholder="Paste the passage you are working on."></textarea>
|
| 324 |
+
</div>
|
| 325 |
+
</div>`}
|
| 326 |
+
${pending &&
|
| 327 |
+
html`<div class="callout amber" style=${{ margin: "4px 4px 8px", display: "flex", gap: "10px", alignItems: "center", justifyContent: "space-between" }}>
|
| 328 |
+
<span>Spend ${CREDIT_COSTS.paragraphWriting} credits on a labelled AI paragraph?</span>
|
| 329 |
+
<span class="row"><button class="btn small" onClick=${() => setPending(false)}>Cancel</button><button class="btn small primary" onClick=${writeParagraph}>Spend</button></span>
|
| 330 |
+
</div>`}
|
| 331 |
+
<div class="row">
|
| 332 |
+
<button class="icon-btn ${showExtract ? "active" : ""}" title="Extract" onClick=${() => setShowExtract((v) => !v)}><${Icon} name="file" size=${15} /></button>
|
| 333 |
+
<textarea
|
| 334 |
+
value=${input}
|
| 335 |
+
onInput=${(e) => setInput(e.target.value)}
|
| 336 |
+
onKeyDown=${(e) => {
|
| 337 |
+
if (e.key === "Enter" && !e.shiftKey) {
|
| 338 |
+
e.preventDefault();
|
| 339 |
+
send();
|
| 340 |
+
}
|
| 341 |
+
}}
|
| 342 |
+
placeholder=${engine.canGenerate ? "Message Explication — ask about a text, a technique or your writing…" : "Connect a model in Settings to chat."}
|
| 343 |
+
rows="1"
|
| 344 |
+
disabled=${busy}
|
| 345 |
+
></textarea>
|
| 346 |
+
<button class="send" onClick=${send} disabled=${!input.trim() || busy || !engine.canGenerate} aria-label="Send"><${Icon} name="up" size=${15} /></button>
|
| 347 |
+
</div>
|
| 348 |
+
<div class="foot">
|
| 349 |
+
<div class="row" style=${{ gap: "8px" }}>
|
| 350 |
+
<button class="btn small ghost" onClick=${() => (app.credits >= CREDIT_COSTS.paragraphWriting ? setPending(true) : null)} disabled=${!engine.canGenerate || busy}>
|
| 351 |
+
<${Icon} name="sparkle" size=${11} /> Write paragraph · ${CREDIT_COSTS.paragraphWriting} cr
|
| 352 |
+
</button>
|
| 353 |
+
<span class="tiny faint">${app.credits} credits</span>
|
| 354 |
+
</div>
|
| 355 |
+
<div class="row" style=${{ gap: "8px" }}>
|
| 356 |
+
${app.chat.length > 0 && html`<button class="btn small ghost" onClick=${app.clearChat}>New chat</button>`}
|
| 357 |
+
<span class="tiny faint"><span class="kbd">↵</span> send</span>
|
| 358 |
+
</div>
|
| 359 |
+
</div>
|
| 360 |
+
</div>
|
| 361 |
+
</div>
|
| 362 |
+
</main>`;
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
// ---------------------------------------------------------------------------
|
| 366 |
+
// Paragraph coach + poetry workspace
|
| 367 |
+
// ---------------------------------------------------------------------------
|
| 368 |
+
|
| 369 |
+
function Workspace({ mode, kicker, title, subtitle, supportsExtract, poemMode = false, writingLabel, writingPlaceholder, marksLabel }) {
|
| 370 |
+
const app = useApp();
|
| 371 |
+
const [textId, setTextId] = usePersistent("explication." + mode + ".textId", poemMode ? "power-conflict" : "macbeth");
|
| 372 |
+
const [question, setQuestion] = usePersistent("explication." + mode + ".question", "");
|
| 373 |
+
const [extract, setExtract] = usePersistent("explication." + mode + ".extract", "");
|
| 374 |
+
const [draft, setDraft] = usePersistent("explication." + mode + ".draft", "");
|
| 375 |
+
const [feedback, setFeedback] = useState(null);
|
| 376 |
+
const [showExtract, setShowExtract] = useState(false);
|
| 377 |
+
const [error, setError] = useState("");
|
| 378 |
+
const text = TEXTS.find((t) => t.id === textId) || TEXTS[0];
|
| 379 |
+
|
| 380 |
+
const mark = () => {
|
| 381 |
+
setError("");
|
| 382 |
+
if (wordCount(draft) < 8) {
|
| 383 |
+
setError("Write at least a sentence before marking.");
|
| 384 |
+
return;
|
| 385 |
+
}
|
| 386 |
+
const result = reviewText({
|
| 387 |
+
text: draft,
|
| 388 |
+
question,
|
| 389 |
+
extract: poemMode ? extract : supportsExtract && showExtract ? extract : extract,
|
| 390 |
+
rubric: PARAGRAPH_RUBRIC,
|
| 391 |
+
title: text.title
|
| 392 |
+
});
|
| 393 |
+
setFeedback(result);
|
| 394 |
+
app.recordDraft({
|
| 395 |
+
mode: mode === "coach" ? "Paragraph coach" : "Unseen poetry",
|
| 396 |
+
title: text.title,
|
| 397 |
+
question,
|
| 398 |
+
extract,
|
| 399 |
+
text: draft,
|
| 400 |
+
score: result.total,
|
| 401 |
+
max: result.max,
|
| 402 |
+
feedback: result,
|
| 403 |
+
summary: result.nextStep
|
| 404 |
+
});
|
| 405 |
+
};
|
| 406 |
+
|
| 407 |
+
return html`<main class="page">
|
| 408 |
+
<${PageHead} kicker=${kicker} title=${title} subtitle=${subtitle}
|
| 409 |
+
right=${html`<div class="row"><${Pill} tone="green">${marksLabel || "Marked /10"}<//></div>`} />
|
| 410 |
+
|
| 411 |
+
<div class="grid split" style=${{ marginTop: "18px" }}>
|
| 412 |
+
<div class="stack" style=${{ gap: "12px" }}>
|
| 413 |
+
<div class="card">
|
| 414 |
+
<div class="stack">
|
| 415 |
+
<${TextPicker} value=${textId} onChange=${setTextId} />
|
| 416 |
+
<${QuestionField} value=${question} onChange=${setQuestion} placeholder="How does the writer present…" />
|
| 417 |
+
${poemMode &&
|
| 418 |
+
html`<div class="field">
|
| 419 |
+
<label>Poem <span class="hint">paste the whole text</span></label>
|
| 420 |
+
<textarea class="textarea" style=${{ minHeight: "150px" }} value=${extract} onInput=${(e) => setExtract(e.target.value)} placeholder="Paste every stanza. Quotations are checked against this text."></textarea>
|
| 421 |
+
</div>`}
|
| 422 |
+
${!poemMode && supportsExtract &&
|
| 423 |
+
html`<div class="field">
|
| 424 |
+
<label>Extract <span class="hint">optional</span></label>
|
| 425 |
+
${showExtract
|
| 426 |
+
? html`<textarea class="textarea" style=${{ minHeight: "110px" }} value=${extract} onInput=${(e) => setExtract(e.target.value)} placeholder="Paste the passage. Any quotation is checked against it."></textarea>`
|
| 427 |
+
: html`<button class="btn small" style=${{ alignSelf: "flex-start" }} onClick=${() => setShowExtract(true)}><${Icon} name="plus" size=${12} /> Add the extract</button>`}
|
| 428 |
+
</div>`}
|
| 429 |
+
</div>
|
| 430 |
+
</div>
|
| 431 |
+
|
| 432 |
+
<div class="card">
|
| 433 |
+
<div class="row between" style=${{ marginBottom: "7px" }}>
|
| 434 |
+
<label style=${{ fontSize: "11px", fontWeight: 600, color: "var(--secondary)" }}>${writingLabel}</label>
|
| 435 |
+
<${WordCounter} text=${draft} />
|
| 436 |
+
</div>
|
| 437 |
+
<textarea class="textarea" style=${{ minHeight: "210px" }} value=${draft} onInput=${(e) => setDraft(e.target.value)} placeholder=${writingPlaceholder}></textarea>
|
| 438 |
+
${error && html`<div style=${{ marginTop: "8px" }}><${Notice} kind="error">${error}<//></div>`}
|
| 439 |
+
<div class="row between" style=${{ marginTop: "10px" }}>
|
| 440 |
+
<button class="btn ghost small" onClick=${() => { setDraft(""); setFeedback(null); }}>Clear</button>
|
| 441 |
+
<button class="btn primary" onClick=${mark}><${Icon} name="check" size=${13} /> Mark my writing</button>
|
| 442 |
+
</div>
|
| 443 |
+
<div class="tiny faint" style=${{ marginTop: "6px" }}>Marking is free and earns credits. Nothing leaves this browser.</div>
|
| 444 |
+
</div>
|
| 445 |
+
</div>
|
| 446 |
+
|
| 447 |
+
<div>
|
| 448 |
+
<${FeedbackPanel} feedback=${feedback} />
|
| 449 |
+
${!feedback &&
|
| 450 |
+
html`<div class="card" style=${{ marginTop: "12px" }}>
|
| 451 |
+
<div class="eyebrow">How it is marked</div>
|
| 452 |
+
<div class="stack" style=${{ marginTop: "8px", gap: "8px" }}>
|
| 453 |
+
${PARAGRAPH_RUBRIC.map(
|
| 454 |
+
(c) => html`<div key=${c.id} class="row" style=${{ alignItems: "flex-start", gap: "8px" }}>
|
| 455 |
+
<span class="pill neutral" style=${{ minWidth: "26px", justifyContent: "center" }}>${c.max}</span>
|
| 456 |
+
<div><div style=${{ fontSize: "11.5px", fontWeight: 600 }}>${c.title}</div>
|
| 457 |
+
<div class="tiny faint" style=${{ lineHeight: 1.45 }}>${c.guidance.split(".")[0]}.</div></div>
|
| 458 |
+
</div>`
|
| 459 |
+
)}
|
| 460 |
+
</div>
|
| 461 |
+
</div>`}
|
| 462 |
+
</div>
|
| 463 |
+
</div>
|
| 464 |
+
</main>`;
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
export function Coach() {
|
| 468 |
+
return html`<${Workspace}
|
| 469 |
+
mode="coach"
|
| 470 |
+
kicker="Paragraph coach"
|
| 471 |
+
title="One paragraph, marked properly."
|
| 472 |
+
subtitle="Write one analytical paragraph about a text you are studying. You get a mark out of ten against the GCSE criteria, and the single change that would raise it most."
|
| 473 |
+
supportsExtract=${true}
|
| 474 |
+
writingLabel="Your paragraph"
|
| 475 |
+
writingPlaceholder="Write one paragraph here. Embed a short quotation if you can."
|
| 476 |
+
marksLabel="Marked /10"
|
| 477 |
+
/>`;
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
export function Poetry() {
|
| 481 |
+
return html`<${Workspace}
|
| 482 |
+
mode="poetry"
|
| 483 |
+
kicker="Unseen poetry"
|
| 484 |
+
title="Read the poem, then write."
|
| 485 |
+
subtitle="Paste the whole poem, then write one analytical paragraph. Because the app has the entire text, a quotation that is not in it is a real error."
|
| 486 |
+
poemMode=${true}
|
| 487 |
+
writingLabel="Your paragraph"
|
| 488 |
+
writingPlaceholder="Write one paragraph about the poem: a method, a quotation, and what it makes the reader feel."
|
| 489 |
+
marksLabel="Marked /10"
|
| 490 |
+
/>`;
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
// ---------------------------------------------------------------------------
|
| 494 |
+
// Essay
|
| 495 |
+
// ---------------------------------------------------------------------------
|
| 496 |
+
|
| 497 |
+
export function Essay() {
|
| 498 |
+
const app = useApp();
|
| 499 |
+
const [textId, setTextId] = usePersistent("explication.essay.textId", "macbeth");
|
| 500 |
+
const [question, setQuestion] = usePersistent("explication.essay.question", "");
|
| 501 |
+
const [extract, setExtract] = usePersistent("explication.essay.extract", "");
|
| 502 |
+
const [parts, setParts] = usePersistent("explication.essay.parts", {});
|
| 503 |
+
const [feedbacks, setFeedbacks] = usePersistent("explication.essay.feedbacks", {});
|
| 504 |
+
const [active, setActive] = useState("introduction");
|
| 505 |
+
const [error, setError] = useState("");
|
| 506 |
+
const text = TEXTS.find((t) => t.id === textId) || TEXTS[0];
|
| 507 |
+
|
| 508 |
+
const currentText = parts[active] || "";
|
| 509 |
+
const currentFeedback = feedbacks[active] || null;
|
| 510 |
+
|
| 511 |
+
const markPart = (id) => {
|
| 512 |
+
const body = parts[id] || "";
|
| 513 |
+
if (wordCount(body) < 8) {
|
| 514 |
+
setError("Write this part before marking it.");
|
| 515 |
+
return;
|
| 516 |
+
}
|
| 517 |
+
setError("");
|
| 518 |
+
const rubric = id === "cohesion" ? ESSAY_RUBRICS.cohesion : ESSAY_RUBRICS[id];
|
| 519 |
+
const source = id === "cohesion" ? ESSAY_PART_META.filter((p) => p.id !== "cohesion").map((p) => parts[p.id] || "").join("\n\n") : body;
|
| 520 |
+
const result = reviewText({ text: source, question, extract, rubric, title: text.title });
|
| 521 |
+
setFeedbacks((f) => ({ ...f, [id]: result }));
|
| 522 |
+
};
|
| 523 |
+
|
| 524 |
+
const markAll = () => {
|
| 525 |
+
const next = { ...feedbacks };
|
| 526 |
+
let marked = 0;
|
| 527 |
+
for (const meta of ESSAY_PART_META) {
|
| 528 |
+
const body = parts[meta.id] || "";
|
| 529 |
+
if (meta.id === "cohesion") {
|
| 530 |
+
const source = ESSAY_PART_META.filter((p) => p.id !== "cohesion").map((p) => parts[p.id] || "").join("\n\n");
|
| 531 |
+
if (wordCount(source) >= 20) {
|
| 532 |
+
next.cohesion = reviewText({ text: source, question, extract, rubric: ESSAY_RUBRICS.cohesion, title: text.title });
|
| 533 |
+
}
|
| 534 |
+
continue;
|
| 535 |
+
}
|
| 536 |
+
if (wordCount(body) >= 8) {
|
| 537 |
+
next[meta.id] = reviewText({ text: body, question, extract, rubric: ESSAY_RUBRICS[meta.id], title: text.title });
|
| 538 |
+
marked += 1;
|
| 539 |
+
}
|
| 540 |
+
}
|
| 541 |
+
setFeedbacks(next);
|
| 542 |
+
setError(marked === 0 ? "Write at least one part first." : "");
|
| 543 |
+
};
|
| 544 |
+
|
| 545 |
+
const totals = combineEssay(ESSAY_PART_META.map((m) => feedbacks[m.id]).filter(Boolean));
|
| 546 |
+
|
| 547 |
+
const saveEssay = () => {
|
| 548 |
+
if (totals.max < 30) {
|
| 549 |
+
setError("Mark every part, including cohesion, before saving the essay.");
|
| 550 |
+
return;
|
| 551 |
+
}
|
| 552 |
+
const fullText = ESSAY_PART_META.map((m) => (parts[m.id] || "").trim()).filter(Boolean).join("\n\n");
|
| 553 |
+
app.recordDraft({
|
| 554 |
+
mode: "Essay",
|
| 555 |
+
title: text.title,
|
| 556 |
+
question,
|
| 557 |
+
extract,
|
| 558 |
+
text: fullText,
|
| 559 |
+
score: totals.total,
|
| 560 |
+
max: totals.max,
|
| 561 |
+
feedback: { total: totals.total, max: totals.max, criteria: [], strengths: [], improvements: [], nextStep: "", quotes: [] },
|
| 562 |
+
summary: "Full essay"
|
| 563 |
+
});
|
| 564 |
+
setError("");
|
| 565 |
+
};
|
| 566 |
+
|
| 567 |
+
return html`<main class="page">
|
| 568 |
+
<${PageHead} kicker="Essay" title="Build the argument, part by part."
|
| 569 |
+
subtitle="Mark each part on its own criteria, then the whole essay for cohesion. The marks add up to thirty — the same shape as the exam."
|
| 570 |
+
right=${html`<div class="row"><span class="pill neutral">${totals.total}/${totals.max || 30}</span></div>`} />
|
| 571 |
+
|
| 572 |
+
<div class="card" style=${{ marginTop: "18px" }}>
|
| 573 |
+
<div class="grid two">
|
| 574 |
+
<${TextPicker} value=${textId} onChange=${setTextId} />
|
| 575 |
+
<${QuestionField} value=${question} onChange=${setQuestion} placeholder="How does the writer present…" />
|
| 576 |
+
</div>
|
| 577 |
+
<div class="field" style=${{ marginTop: "10px" }}>
|
| 578 |
+
<label>Extract <span class="hint">optional · quotations are checked against it</span></label>
|
| 579 |
+
<textarea class="textarea" style=${{ minHeight: "80px" }} value=${extract} onInput=${(e) => setExtract(e.target.value)} placeholder="Paste the passage if the question gives you one."></textarea>
|
| 580 |
+
</div>
|
| 581 |
+
</div>
|
| 582 |
+
|
| 583 |
+
<div class="row wrap" style=${{ marginTop: "14px", gap: "6px" }}>
|
| 584 |
+
${ESSAY_PART_META.map(
|
| 585 |
+
(m) => html`<button key=${m.id}
|
| 586 |
+
class=${"btn small" + (active === m.id ? " primary" : "")}
|
| 587 |
+
onClick=${() => setActive(m.id)}>
|
| 588 |
+
${m.short}
|
| 589 |
+
${feedbacks[m.id] && html`<span style=${{ opacity: .7 }}>${feedbacks[m.id].total}/${feedbacks[m.id].max}</span>`}
|
| 590 |
+
</button>`
|
| 591 |
+
)}
|
| 592 |
+
</div>
|
| 593 |
+
|
| 594 |
+
<div class="grid split" style=${{ marginTop: "14px" }}>
|
| 595 |
+
<div class="card">
|
| 596 |
+
<div class="row between" style=${{ marginBottom: "7px" }}>
|
| 597 |
+
<label style=${{ fontSize: "11px", fontWeight: 600, color: "var(--secondary)" }}>
|
| 598 |
+
${ESSAY_PART_META.find((m) => m.id === active).title}
|
| 599 |
+
</label>
|
| 600 |
+
<${WordCounter} text=${currentText} />
|
| 601 |
+
</div>
|
| 602 |
+
<textarea class="textarea" style=${{ minHeight: "240px" }}
|
| 603 |
+
value=${currentText}
|
| 604 |
+
onInput=${(e) => setParts((p) => ({ ...p, [active]: e.target.value }))}
|
| 605 |
+
placeholder=${active === "cohesion"
|
| 606 |
+
? "Cohesion is marked from the parts you have written — no separate text needed."
|
| 607 |
+
: active === "introduction"
|
| 608 |
+
? "Open with a shaped line of argument that answers the question."
|
| 609 |
+
: active === "conclusion"
|
| 610 |
+
? "Return to the question, then say why it matters beyond this text."
|
| 611 |
+
: "One topic sentence, evidence, then method and effect developed together."}></textarea>
|
| 612 |
+
${error && html`<div style=${{ marginTop: "8px" }}><${Notice} kind="error">${error}<//></div>`}
|
| 613 |
+
<div class="row between" style=${{ marginTop: "10px" }}>
|
| 614 |
+
<div class="row">
|
| 615 |
+
<button class="btn ghost small" onClick=${markAll}>Mark all parts</button>
|
| 616 |
+
<button class="btn ghost small" onClick=${saveEssay} disabled=${totals.max < 30}>Save essay</button>
|
| 617 |
+
</div>
|
| 618 |
+
<button class="btn primary" onClick=${() => markPart(active)}><${Icon} name="check" size=${13} /> Mark this part</button>
|
| 619 |
+
</div>
|
| 620 |
+
</div>
|
| 621 |
+
|
| 622 |
+
<div>
|
| 623 |
+
<${FeedbackPanel} feedback=${currentFeedback} />
|
| 624 |
+
${totals.max > 0 &&
|
| 625 |
+
html`<div class="card" style=${{ marginTop: "12px" }}>
|
| 626 |
+
<div class="row between"><span class="eyebrow">Whole essay</span><span class="pill green">${totals.total}/${totals.max}</span></div>
|
| 627 |
+
<div class="bar" style=${{ marginTop: "9px", height: "6px" }}><i style=${{ width: (totals.total / Math.max(totals.max, 30)) * 100 + "%" }}></i></div>
|
| 628 |
+
<div class="tiny faint" style=${{ marginTop: "6px" }}>
|
| 629 |
+
Parts marked: ${ESSAY_PART_META.filter((m) => feedbacks[m.id]).length} of 6.
|
| 630 |
+
${totals.max === 30 && " Save the essay to earn credits on the full mark."}
|
| 631 |
+
</div>
|
| 632 |
+
</div>`}
|
| 633 |
+
</div>
|
| 634 |
+
</div>
|
| 635 |
+
</main>`;
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
// ---------------------------------------------------------------------------
|
| 639 |
+
// Improve
|
| 640 |
+
// ---------------------------------------------------------------------------
|
| 641 |
+
|
| 642 |
+
export function Improve() {
|
| 643 |
+
const app = useApp();
|
| 644 |
+
const engine = useEngine();
|
| 645 |
+
const [sentence, setSentence] = usePersistent("explication.improve.sentence", "");
|
| 646 |
+
const [feedback, setFeedback] = useState(null);
|
| 647 |
+
const [suggestion, setSuggestion] = useState("");
|
| 648 |
+
const [busy, setBusy] = useState(false);
|
| 649 |
+
const [error, setError] = useState("");
|
| 650 |
+
|
| 651 |
+
const analyse = () => {
|
| 652 |
+
if (wordCount(sentence) < 4) {
|
| 653 |
+
setError("Paste one sentence first.");
|
| 654 |
+
return;
|
| 655 |
+
}
|
| 656 |
+
setError("");
|
| 657 |
+
setFeedback(reviewText({ text: sentence, rubric: PARAGRAPH_RUBRIC, title: "Improve" }));
|
| 658 |
+
};
|
| 659 |
+
|
| 660 |
+
const askForSuggestion = async () => {
|
| 661 |
+
if (!engine.canGenerate) {
|
| 662 |
+
setError("A stronger version needs a model. Open Settings to connect one.");
|
| 663 |
+
return;
|
| 664 |
+
}
|
| 665 |
+
setError("");
|
| 666 |
+
setBusy(true);
|
| 667 |
+
setSuggestion("");
|
| 668 |
+
try {
|
| 669 |
+
const result = await engine.chat(
|
| 670 |
+
[
|
| 671 |
+
{
|
| 672 |
+
role: "system",
|
| 673 |
+
content:
|
| 674 |
+
"You are a GCSE English Literature coach. Improve ONE sentence the student wrote. Return only the improved sentence, no explanation, no quotation marks."
|
| 675 |
+
},
|
| 676 |
+
{ role: "user", content: sentence }
|
| 677 |
+
],
|
| 678 |
+
setSuggestion
|
| 679 |
+
);
|
| 680 |
+
setSuggestion(result.trim());
|
| 681 |
+
} catch (err) {
|
| 682 |
+
setError(err && err.message ? err.message : "The model could not reply.");
|
| 683 |
+
}
|
| 684 |
+
setBusy(false);
|
| 685 |
+
};
|
| 686 |
+
|
| 687 |
+
const techniques = feedback ? feedback.techniques : [];
|
| 688 |
+
|
| 689 |
+
const tree = html`<main class="page narrow">
|
| 690 |
+
<${PageHead} kicker="Improve" title="One sentence at a time."
|
| 691 |
+
subtitle="Pick a sentence from your own draft. The review names what it is doing, then you rewrite it stronger. A finished suggestion is available when a model is connected."
|
| 692 |
+
right=${html`<span class="pill neutral">Free review</span>`} />
|
| 693 |
+
|
| 694 |
+
<div class="card" style=${{ marginTop: "18px" }}>
|
| 695 |
+
<div class="field">
|
| 696 |
+
<label>Your sentence <span class="hint">${wordCount(sentence)} words</span></label>
|
| 697 |
+
<textarea class="textarea" style=${{ minHeight: "90px" }} value=${sentence} onInput=${(e) => setSentence(e.target.value)} placeholder="He is very angry and shouts at her."></textarea>
|
| 698 |
+
</div>
|
| 699 |
+
<div class="row between" style=${{ marginTop: "10px" }}>
|
| 700 |
+
<button class="btn ghost small" onClick=${() => { setSentence(""); setFeedback(null); setSuggestion(""); }}>Clear</button>
|
| 701 |
+
<button class="btn primary" onClick=${analyse}><${Icon} name="sparkle" size=${13} /> Review the sentence</button>
|
| 702 |
+
</div>
|
| 703 |
+
${error && html`<div style=${{ marginTop: "8px" }}><${Notice} kind="error">${error}<//></div>`}
|
| 704 |
+
</div>
|
| 705 |
+
|
| 706 |
+
${feedback &&
|
| 707 |
+
html`<div class="grid two" style=${{ marginTop: "12px" }}>
|
| 708 |
+
<div class="card">
|
| 709 |
+
<div class="eyebrow">What the sentence is doing</div>
|
| 710 |
+
<div class="stack" style=${{ marginTop: "8px" }}>
|
| 711 |
+
<div class="row wrap" style=${{ gap: "5px" }}>
|
| 712 |
+
${techniques.length > 0
|
| 713 |
+
? techniques.map((t, i) => html`<span key=${t + i} class="pill green">${t}</span>`)
|
| 714 |
+
: html`<span class="pill neutral">No technique named</span>`}
|
| 715 |
+
</div>
|
| 716 |
+
<div class="tiny muted" style=${{ lineHeight: 1.6 }}>
|
| 717 |
+
${techniques.length > 0
|
| 718 |
+
? "You name a method. Now say what it makes the reader feel, and why."
|
| 719 |
+
: "This is telling, not showing. Name the method (verb choice, imagery, a short sentence) before you explain the effect."}
|
| 720 |
+
</div>
|
| 721 |
+
<div class="divider"></div>
|
| 722 |
+
<div class="row between"><span class="tiny faint">Sentences</span><span class="tiny">${sentenceList(sentence).length}</span></div>
|
| 723 |
+
<div class="row between"><span class="tiny faint">Words</span><span class="tiny">${wordCount(sentence)}</span></div>
|
| 724 |
+
</div>
|
| 725 |
+
</div>
|
| 726 |
+
|
| 727 |
+
<div class="card">
|
| 728 |
+
<div class="row between">
|
| 729 |
+
<div class="eyebrow">A stronger version</div>
|
| 730 |
+
<${Pill} tone=${engine.canGenerate ? "green" : "neutral"}>${engine.canGenerate ? "AI suggestion" : "Needs a model"}<//>
|
| 731 |
+
</div>
|
| 732 |
+
${suggestion
|
| 733 |
+
? html`<div class="callout green" style=${{ marginTop: "9px", fontFamily: "var(--serif)", fontSize: "14px" }}>${suggestion}</div>
|
| 734 |
+
<div class="tiny faint" style=${{ marginTop: "7px" }}>Study suggestion only — rewrite it in your own voice.</div>`
|
| 735 |
+
: html`<p class="tiny faint" style=${{ marginTop: "9px", lineHeight: 1.6 }}>Ask for one rewritten sentence. It is a suggestion, not your own work, and it never replaces your attempt.</p>`}
|
| 736 |
+
<button class="btn" style=${{ marginTop: "10px" }} onClick=${askForSuggestion} disabled=${busy || !engine.canGenerate}>
|
| 737 |
+
${busy ? html`<span class="spin"></span>` : html`<${Icon} name="sparkle" size=${13} />`} ${suggestion ? "Try another" : "Suggest a stronger sentence"}
|
| 738 |
+
</button>
|
| 739 |
+
</div>
|
| 740 |
+
</div>`}
|
| 741 |
+
</main>`;
|
| 742 |
+
return tree;
|
| 743 |
+
}
|
js/store.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { createContext, useContext, useEffect, useMemo, useState, html } from "./runtime.js";
|
| 2 |
+
import { awardCredits, creditsForEssay, creditsForParagraph, levelFor, levelProgress, streakLength } from "./marking.js";
|
| 3 |
+
|
| 4 |
+
const KEY = "explication.web.v1";
|
| 5 |
+
|
| 6 |
+
const DEFAULT_SETTINGS = {
|
| 7 |
+
name: "",
|
| 8 |
+
yearGroup: "Year 11",
|
| 9 |
+
board: "AQA",
|
| 10 |
+
endpointBaseUrl: "",
|
| 11 |
+
endpointModel: "",
|
| 12 |
+
endpointKey: "",
|
| 13 |
+
modelId: "Qwen2.5-1.5B-Instruct-q4f16_1-MLC"
|
| 14 |
+
};
|
| 15 |
+
|
| 16 |
+
function defaults() {
|
| 17 |
+
return {
|
| 18 |
+
settings: { ...DEFAULT_SETTINGS },
|
| 19 |
+
credits: 40,
|
| 20 |
+
totalEarned: 40,
|
| 21 |
+
days: [],
|
| 22 |
+
drafts: [],
|
| 23 |
+
chat: [],
|
| 24 |
+
chatExtract: "",
|
| 25 |
+
modelAnswer: ""
|
| 26 |
+
};
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
function load() {
|
| 30 |
+
try {
|
| 31 |
+
const raw = localStorage.getItem(KEY);
|
| 32 |
+
if (!raw) return defaults();
|
| 33 |
+
const parsed = JSON.parse(raw);
|
| 34 |
+
return {
|
| 35 |
+
...defaults(),
|
| 36 |
+
...parsed,
|
| 37 |
+
settings: { ...DEFAULT_SETTINGS, ...(parsed.settings || {}) },
|
| 38 |
+
drafts: Array.isArray(parsed.drafts) ? parsed.drafts : [],
|
| 39 |
+
chat: Array.isArray(parsed.chat) ? parsed.chat : [],
|
| 40 |
+
days: Array.isArray(parsed.days) ? parsed.days : []
|
| 41 |
+
};
|
| 42 |
+
} catch {
|
| 43 |
+
return defaults();
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
function todayISO() {
|
| 48 |
+
const d = new Date();
|
| 49 |
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
let counter = 0;
|
| 53 |
+
function id() {
|
| 54 |
+
counter += 1;
|
| 55 |
+
return `${Date.now().toString(36)}-${counter}`;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
const AppContext = createContext(null);
|
| 59 |
+
|
| 60 |
+
export function AppProvider({ children }) {
|
| 61 |
+
const [state, setState] = useState(load);
|
| 62 |
+
|
| 63 |
+
useEffect(() => {
|
| 64 |
+
try {
|
| 65 |
+
localStorage.setItem(KEY, JSON.stringify(state));
|
| 66 |
+
} catch {
|
| 67 |
+
// A full localStorage should not break the app in the middle of a mark.
|
| 68 |
+
}
|
| 69 |
+
}, [state]);
|
| 70 |
+
|
| 71 |
+
const api = useMemo(() => {
|
| 72 |
+
const streak = streakLength(state.days);
|
| 73 |
+
const level = levelFor(state.totalEarned);
|
| 74 |
+
const marked = state.drafts.filter((d) => d.max > 0);
|
| 75 |
+
const average = marked.length
|
| 76 |
+
? Math.round((marked.slice(0, 20).reduce((sum, d) => sum + d.score / d.max, 0) / Math.min(20, marked.length)) * 100)
|
| 77 |
+
: 0;
|
| 78 |
+
|
| 79 |
+
return {
|
| 80 |
+
...state,
|
| 81 |
+
streak,
|
| 82 |
+
level,
|
| 83 |
+
levelProgress: levelProgress(state.totalEarned),
|
| 84 |
+
average,
|
| 85 |
+
setSettings(patch) {
|
| 86 |
+
setState((s) => ({ ...s, settings: { ...s.settings, ...patch } }));
|
| 87 |
+
},
|
| 88 |
+
spend(amount) {
|
| 89 |
+
setState((s) => ({ ...s, credits: Math.max(0, s.credits - amount) }));
|
| 90 |
+
},
|
| 91 |
+
addCredits(amount) {
|
| 92 |
+
if (amount <= 0) return;
|
| 93 |
+
setState((s) => ({ ...s, credits: s.credits + amount, totalEarned: s.totalEarned + amount }));
|
| 94 |
+
},
|
| 95 |
+
recordDraft(draft) {
|
| 96 |
+
const base =
|
| 97 |
+
draft.max === 30 || draft.max === 10 ? (draft.max === 30 ? creditsForEssay(draft.score) : creditsForParagraph(draft.score)) : 0;
|
| 98 |
+
setState((s) => {
|
| 99 |
+
const days = Array.from(new Set([...s.days, todayISO()]));
|
| 100 |
+
const mult = awardCredits(base, streakLength(days));
|
| 101 |
+
return {
|
| 102 |
+
...s,
|
| 103 |
+
days,
|
| 104 |
+
credits: s.credits + mult,
|
| 105 |
+
totalEarned: s.totalEarned + mult,
|
| 106 |
+
drafts: [{ ...draft, id: id(), at: new Date().toISOString(), earned: mult }, ...s.drafts].slice(0, 200)
|
| 107 |
+
};
|
| 108 |
+
});
|
| 109 |
+
},
|
| 110 |
+
deleteDraft(draftId) {
|
| 111 |
+
setState((s) => ({ ...s, drafts: s.drafts.filter((d) => d.id !== draftId) }));
|
| 112 |
+
},
|
| 113 |
+
addChat(message) {
|
| 114 |
+
setState((s) => ({ ...s, chat: [...s.chat, { ...message, id: id(), at: Date.now() }] }));
|
| 115 |
+
},
|
| 116 |
+
setChatChatter(updater) {
|
| 117 |
+
setState((s) => ({ ...s, chat: typeof updater === "function" ? updater(s.chat) : updater }));
|
| 118 |
+
},
|
| 119 |
+
clearChat() {
|
| 120 |
+
setState((s) => ({ ...s, chat: [] }));
|
| 121 |
+
},
|
| 122 |
+
setChatExtract(text) {
|
| 123 |
+
setState((s) => ({ ...s, chatExtract: text }));
|
| 124 |
+
},
|
| 125 |
+
setModelAnswer(text) {
|
| 126 |
+
setState((s) => ({ ...s, modelAnswer: text }));
|
| 127 |
+
},
|
| 128 |
+
resetProgress() {
|
| 129 |
+
setState((s) => ({ ...defaults(), settings: s.settings }));
|
| 130 |
+
}
|
| 131 |
+
};
|
| 132 |
+
}, [state]);
|
| 133 |
+
|
| 134 |
+
return html`<${AppContext.Provider} value=${api}>${children}<//>`;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
export function useApp() {
|
| 138 |
+
const value = useContext(AppContext);
|
| 139 |
+
if (!value) throw new Error("useApp must be used inside AppProvider");
|
| 140 |
+
return value;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
export { todayISO };
|
schema.sql
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-- Explication — accounts, plans, models, shared wording and spend.
|
| 2 |
+
-- Paste this into Supabase → SQL Editor → New query → Run.
|
| 3 |
+
--
|
| 4 |
+
-- One address is the developer: lucas.owen13@icloud.com. Every write to plans,
|
| 5 |
+
-- models, API keys and page wording is restricted to that account here, in the
|
| 6 |
+
-- database, so the rule holds even if someone opens the developer page.
|
| 7 |
+
|
| 8 |
+
create extension if not exists pgcrypto;
|
| 9 |
+
|
| 10 |
+
-- ---------------------------------------------------------------------------
|
| 11 |
+
-- Who is the developer
|
| 12 |
+
-- ---------------------------------------------------------------------------
|
| 13 |
+
|
| 14 |
+
create or replace function public.explication_is_dev()
|
| 15 |
+
returns boolean
|
| 16 |
+
language sql
|
| 17 |
+
stable
|
| 18 |
+
as $$
|
| 19 |
+
select coalesce(lower(auth.jwt() ->> 'email'), '') = 'lucas.owen13@icloud.com'
|
| 20 |
+
$$;
|
| 21 |
+
|
| 22 |
+
-- ---------------------------------------------------------------------------
|
| 23 |
+
-- Tables
|
| 24 |
+
-- ---------------------------------------------------------------------------
|
| 25 |
+
|
| 26 |
+
create table if not exists public.explication_settings (
|
| 27 |
+
id integer primary key default 1 check (id = 1),
|
| 28 |
+
stripe_publishable_key text not null default '',
|
| 29 |
+
stripe_mode text not null default 'payment_links' check (stripe_mode in ('payment_links', 'function')),
|
| 30 |
+
checkout_function text not null default 'stripe-checkout',
|
| 31 |
+
currency text not null default 'GBP',
|
| 32 |
+
support_email text not null default 'lucas.owen13@icloud.com',
|
| 33 |
+
updated_at timestamptz not null default now()
|
| 34 |
+
);
|
| 35 |
+
|
| 36 |
+
create table if not exists public.explication_plans (
|
| 37 |
+
id text primary key,
|
| 38 |
+
name text not null,
|
| 39 |
+
kind text not null check (kind in ('one_time', 'subscription')),
|
| 40 |
+
price_cents integer not null default 0,
|
| 41 |
+
currency text not null default 'GBP',
|
| 42 |
+
interval text check (interval is null or interval in ('month', 'year')),
|
| 43 |
+
blurb text not null default '',
|
| 44 |
+
features jsonb not null default '[]'::jsonb,
|
| 45 |
+
cost_limit_cents integer not null default 0,
|
| 46 |
+
download_tier integer not null default 0,
|
| 47 |
+
byok boolean not null default true,
|
| 48 |
+
stripe_price_id text not null default '',
|
| 49 |
+
stripe_payment_link text not null default '',
|
| 50 |
+
active boolean not null default true,
|
| 51 |
+
sort integer not null default 0,
|
| 52 |
+
updated_at timestamptz not null default now()
|
| 53 |
+
);
|
| 54 |
+
|
| 55 |
+
create table if not exists public.explication_models (
|
| 56 |
+
id text primary key,
|
| 57 |
+
name text not null,
|
| 58 |
+
host text not null default '',
|
| 59 |
+
endpoint_url text not null default '',
|
| 60 |
+
model_name text not null default '',
|
| 61 |
+
cost_in_per_million numeric not null default 0,
|
| 62 |
+
cost_out_per_million numeric not null default 0,
|
| 63 |
+
min_tier integer not null default 0,
|
| 64 |
+
download_size text not null default '',
|
| 65 |
+
note text not null default '',
|
| 66 |
+
enabled boolean not null default true,
|
| 67 |
+
sort integer not null default 0,
|
| 68 |
+
updated_at timestamptz not null default now()
|
| 69 |
+
);
|
| 70 |
+
|
| 71 |
+
-- Hosted model keys. Read and write by the developer only; the AI function
|
| 72 |
+
-- reads them with the service role, so they never reach a browser.
|
| 73 |
+
create table if not exists public.explication_model_secrets (
|
| 74 |
+
model_id text primary key references public.explication_models(id) on delete cascade,
|
| 75 |
+
api_key text not null,
|
| 76 |
+
updated_at timestamptz not null default now()
|
| 77 |
+
);
|
| 78 |
+
|
| 79 |
+
-- Page wording overridden by the developer, by key.
|
| 80 |
+
create table if not exists public.explication_content (
|
| 81 |
+
key text primary key,
|
| 82 |
+
value text not null,
|
| 83 |
+
updated_at timestamptz not null default now(),
|
| 84 |
+
updated_by text
|
| 85 |
+
);
|
| 86 |
+
|
| 87 |
+
create table if not exists public.explication_entitlements (
|
| 88 |
+
id uuid primary key default gen_random_uuid(),
|
| 89 |
+
user_id uuid references auth.users(id) on delete cascade,
|
| 90 |
+
email text,
|
| 91 |
+
plan_id text references public.explication_plans(id) on delete set null,
|
| 92 |
+
source text not null default 'grant',
|
| 93 |
+
granted_at timestamptz not null default now(),
|
| 94 |
+
expires_at timestamptz,
|
| 95 |
+
revoked boolean not null default false,
|
| 96 |
+
stripe_customer_id text,
|
| 97 |
+
stripe_subscription_id text
|
| 98 |
+
);
|
| 99 |
+
|
| 100 |
+
create index if not exists explication_entitlements_user on public.explication_entitlements (user_id);
|
| 101 |
+
create index if not exists explication_entitlements_email on public.explication_entitlements (lower(email));
|
| 102 |
+
|
| 103 |
+
create table if not exists public.explication_usage (
|
| 104 |
+
id uuid primary key default gen_random_uuid(),
|
| 105 |
+
user_id uuid references auth.users(id) on delete cascade,
|
| 106 |
+
model_id text,
|
| 107 |
+
cost_cents numeric not null default 0,
|
| 108 |
+
tokens_in integer not null default 0,
|
| 109 |
+
tokens_out integer not null default 0,
|
| 110 |
+
created_at timestamptz not null default now()
|
| 111 |
+
);
|
| 112 |
+
|
| 113 |
+
create index if not exists explication_usage_user on public.explication_usage (user_id, created_at desc);
|
| 114 |
+
|
| 115 |
+
-- ---------------------------------------------------------------------------
|
| 116 |
+
-- Row-level security
|
| 117 |
+
-- ---------------------------------------------------------------------------
|
| 118 |
+
|
| 119 |
+
alter table public.explication_settings enable row level security;
|
| 120 |
+
alter table public.explication_plans enable row level security;
|
| 121 |
+
alter table public.explication_models enable row level security;
|
| 122 |
+
alter table public.explication_model_secrets enable row level security;
|
| 123 |
+
alter table public.explication_content enable row level security;
|
| 124 |
+
alter table public.explication_entitlements enable row level security;
|
| 125 |
+
alter table public.explication_usage enable row level security;
|
| 126 |
+
|
| 127 |
+
drop policy if exists settings_read on public.explication_settings;
|
| 128 |
+
create policy settings_read on public.explication_settings for select using (true);
|
| 129 |
+
drop policy if exists settings_write on public.explication_settings;
|
| 130 |
+
create policy settings_write on public.explication_settings for all
|
| 131 |
+
using (public.explication_is_dev()) with check (public.explication_is_dev());
|
| 132 |
+
|
| 133 |
+
drop policy if exists plans_read on public.explication_plans;
|
| 134 |
+
create policy plans_read on public.explication_plans for select using (active or public.explication_is_dev());
|
| 135 |
+
drop policy if exists plans_write on public.explication_plans;
|
| 136 |
+
create policy plans_write on public.explication_plans for all
|
| 137 |
+
using (public.explication_is_dev()) with check (public.explication_is_dev());
|
| 138 |
+
|
| 139 |
+
drop policy if exists models_read on public.explication_models;
|
| 140 |
+
create policy models_read on public.explication_models for select using (enabled or public.explication_is_dev());
|
| 141 |
+
drop policy if exists models_write on public.explication_models;
|
| 142 |
+
create policy models_write on public.explication_models for all
|
| 143 |
+
using (public.explication_is_dev()) with check (public.explication_is_dev());
|
| 144 |
+
|
| 145 |
+
drop policy if exists secrets_dev on public.explication_model_secrets;
|
| 146 |
+
create policy secrets_dev on public.explication_model_secrets for all
|
| 147 |
+
using (public.explication_is_dev()) with check (public.explication_is_dev());
|
| 148 |
+
|
| 149 |
+
drop policy if exists content_read on public.explication_content;
|
| 150 |
+
create policy content_read on public.explication_content for select using (true);
|
| 151 |
+
drop policy if exists content_write on public.explication_content;
|
| 152 |
+
create policy content_write on public.explication_content for all
|
| 153 |
+
using (public.explication_is_dev()) with check (public.explication_is_dev());
|
| 154 |
+
|
| 155 |
+
drop policy if exists entitlements_read on public.explication_entitlements;
|
| 156 |
+
create policy entitlements_read on public.explication_entitlements for select using (
|
| 157 |
+
public.explication_is_dev()
|
| 158 |
+
or user_id = auth.uid()
|
| 159 |
+
or lower(coalesce(email, '')) = lower(coalesce(auth.jwt() ->> 'email', ''))
|
| 160 |
+
);
|
| 161 |
+
drop policy if exists entitlements_write on public.explication_entitlements;
|
| 162 |
+
create policy entitlements_write on public.explication_entitlements for all
|
| 163 |
+
using (public.explication_is_dev()) with check (public.explication_is_dev());
|
| 164 |
+
|
| 165 |
+
drop policy if exists usage_read on public.explication_usage;
|
| 166 |
+
create policy usage_read on public.explication_usage for select using (
|
| 167 |
+
public.explication_is_dev() or user_id = auth.uid()
|
| 168 |
+
);
|
| 169 |
+
|
| 170 |
+
-- Usage rows are written only by the AI function with the service role,
|
| 171 |
+
-- which bypasses row-level security. No insert policy on purpose.
|
| 172 |
+
|
| 173 |
+
-- ---------------------------------------------------------------------------
|
| 174 |
+
-- Seed: settings, plans and models
|
| 175 |
+
-- ---------------------------------------------------------------------------
|
| 176 |
+
|
| 177 |
+
insert into public.explication_settings (id) values (1) on conflict (id) do nothing;
|
| 178 |
+
|
| 179 |
+
insert into public.explication_plans
|
| 180 |
+
(id, name, kind, price_cents, currency, interval, blurb, features, cost_limit_cents, download_tier, byok, sort)
|
| 181 |
+
values
|
| 182 |
+
('paragraph-lite', 'Paragraph Lite', 'one_time', 400, 'GBP', null,
|
| 183 |
+
'Buy the smallest model once and keep it. Nothing you do here costs the site another penny.',
|
| 184 |
+
'["Paragraph Lite model, yours to keep","Download it and run it offline","All rule-based marking and the process log","Bring your own API key for any hosted model"]'::jsonb,
|
| 185 |
+
0, 1, true, 1),
|
| 186 |
+
('student', 'Student', 'subscription', 400, 'GBP', 'month',
|
| 187 |
+
'Every model hosted here, with £1.20 of model usage included each month.',
|
| 188 |
+
'["Every hosted model, including 3B and 7B","£1.20 of model usage per month","Download Lite and 1.5B for offline use","Bring your own key and pay your provider directly"]'::jsonb,
|
| 189 |
+
120, 2, true, 2),
|
| 190 |
+
('scholar', 'Scholar', 'subscription', 900, 'GBP', 'month',
|
| 191 |
+
'More room for long essays, with £3.50 of model usage each month.',
|
| 192 |
+
'["Everything in Student","£3.50 of model usage per month","Download the 3B model as well","Priority when the hosted models are busy"]'::jsonb,
|
| 193 |
+
350, 3, true, 3),
|
| 194 |
+
('examiner', 'Examiner', 'subscription', 1900, 'GBP', 'month',
|
| 195 |
+
'The whole catalogue, £9 of model usage a month, and the best offline model.',
|
| 196 |
+
'["Everything in Scholar","£9.00 of model usage per month","Download all four models, including 7B","Early access to new models and marking prompts"]'::jsonb,
|
| 197 |
+
900, 4, true, 4)
|
| 198 |
+
on conflict (id) do nothing;
|
| 199 |
+
|
| 200 |
+
insert into public.explication_models
|
| 201 |
+
(id, name, host, endpoint_url, model_name, cost_in_per_million, cost_out_per_million, min_tier, download_size, note, sort)
|
| 202 |
+
values
|
| 203 |
+
('Qwen2.5-0.5B-Instruct-q4f16_1-MLC', 'Paragraph Lite', 'Browser (WebGPU)', '', 'Qwen2.5 0.5B Instruct', 0, 0, 1, '~0.4 GB', 'Quickest to load. Enough for short feedback.', 1),
|
| 204 |
+
('Qwen2.5-1.5B-Instruct-q4f16_1-MLC', 'Qwen2.5 1.5B', 'Browser (WebGPU)', '', 'Qwen2.5 1.5B Instruct', 0, 0, 2, '~1.1 GB', 'The default when WebGPU is available.', 2),
|
| 205 |
+
('Qwen2.5-3B-Instruct-q4f16_1-MLC', 'Qwen2.5 3B', 'Browser (WebGPU)', '', 'Qwen2.5 3B Instruct', 0, 0, 3, '~2.0 GB', 'Better analysis; needs a stronger GPU.', 3),
|
| 206 |
+
('Qwen2.5-7B-Instruct-q4f16_1-MLC', 'Qwen2.5 7B', 'Browser (WebGPU)', '', 'Qwen2.5 7B Instruct', 0, 0, 4, '~4.5 GB', 'Best feedback here, but only on a capable GPU.', 4)
|
| 207 |
+
on conflict (id) do nothing;
|
| 208 |
+
|
| 209 |
+
-- ---------------------------------------------------------------------------
|
| 210 |
+
-- The current offer. Safe to run again: it updates the shop front in place.
|
| 211 |
+
-- ---------------------------------------------------------------------------
|
| 212 |
+
|
| 213 |
+
insert into public.explication_plans
|
| 214 |
+
(id, name, kind, price_cents, currency, interval, blurb, features, cost_limit_cents, download_tier, byok, sort, active)
|
| 215 |
+
values
|
| 216 |
+
('paragraph-lite', 'Paragraph Lite', 'one_time', 400, 'GBP', null,
|
| 217 |
+
'The little model that started it all, yours to keep. Download it once and mark paragraphs on the bus, on the train, anywhere.',
|
| 218 |
+
'["Paragraph Lite model, yours for good","Runs fully offline after one download","Every marking tool, forever","Use your own AI key if you have one"]'::jsonb,
|
| 219 |
+
0, 1, true, 1, true),
|
| 220 |
+
('model-library', 'Model Library', 'one_time', 1400, 'GBP', null,
|
| 221 |
+
'All four models in one go: the quick one, the strong one, and the two in between. Nothing else to buy.',
|
| 222 |
+
'["All four offline models unlocked","Download on every device you own","Works on a plane, offline, forever","Free updates when new models arrive"]'::jsonb,
|
| 223 |
+
0, 4, true, 2, true),
|
| 224 |
+
('exam-season', 'Exam Season', 'one_time', 2400, 'GBP', null,
|
| 225 |
+
'Everything unlocked for the run-up to the exams, including a pot of hosted AI for the nights you want the big models.',
|
| 226 |
+
'["All four offline models","Priority access to the hosted models","One payment, nothing renews"]'::jsonb,
|
| 227 |
+
600, 4, true, 3, true),
|
| 228 |
+
('ai-booster', 'AI Booster', 'one_time', 600, 'GBP', null,
|
| 229 |
+
'Already have a membership? Drop another pot of hosted AI into your account and keep the big models coming.',
|
| 230 |
+
'["Stacks with any plan you already have","Never expires","No subscription, no renewal"]'::jsonb,
|
| 231 |
+
500, 0, true, 4, true),
|
| 232 |
+
('student', 'Student', 'subscription', 400, 'GBP', 'month',
|
| 233 |
+
'The whole shelf of hosted models, plus two offline downloads. About the price of a coffee a month.',
|
| 234 |
+
'["Every hosted model, including the big ones","Download Lite and 1.5B for offline use","Use your own key and keep it free of limits"]'::jsonb,
|
| 235 |
+
120, 2, true, 5, true),
|
| 236 |
+
('scholar', 'Scholar', 'subscription', 900, 'GBP', 'month',
|
| 237 |
+
'For long essays and heavy revision weeks: more AI, more downloads, and the 3B model offline.',
|
| 238 |
+
'["Everything in Student","Download the 3B model as well","Priority when the hosted models are busy"]'::jsonb,
|
| 239 |
+
400, 3, true, 6, true),
|
| 240 |
+
('examiner', 'Examiner', 'subscription', 1900, 'GBP', 'month',
|
| 241 |
+
'The full shelf, the biggest budget and every model offline. For the year it really matters.',
|
| 242 |
+
'["Everything in Scholar","Download all four models, including 7B","Early access to new models and marking prompts"]'::jsonb,
|
| 243 |
+
1000, 4, true, 7, true)
|
| 244 |
+
on conflict (id) do update set
|
| 245 |
+
name = excluded.name,
|
| 246 |
+
kind = excluded.kind,
|
| 247 |
+
price_cents = excluded.price_cents,
|
| 248 |
+
interval = excluded.interval,
|
| 249 |
+
blurb = excluded.blurb,
|
| 250 |
+
features = excluded.features,
|
| 251 |
+
cost_limit_cents = excluded.cost_limit_cents,
|
| 252 |
+
download_tier = excluded.download_tier,
|
| 253 |
+
byok = excluded.byok,
|
| 254 |
+
sort = excluded.sort,
|
| 255 |
+
active = excluded.active,
|
| 256 |
+
updated_at = now();
|
| 257 |
+
|
| 258 |
+
-- ---------------------------------------------------------------------------
|
| 259 |
+
-- Grants
|
| 260 |
+
-- ---------------------------------------------------------------------------
|
| 261 |
+
-- Supabase's API roles need table privileges before row-level security can do
|
| 262 |
+
-- its job. Without these, the REST API answers 401/42501 even though the
|
| 263 |
+
-- policies are right.
|
| 264 |
+
|
| 265 |
+
grant usage on schema public to anon, authenticated, service_role;
|
| 266 |
+
grant all on all tables in schema public to anon, authenticated, service_role;
|
| 267 |
+
grant all on all sequences in schema public to anon, authenticated, service_role;
|
| 268 |
+
grant all on all functions in schema public to anon, authenticated, service_role;
|
| 269 |
+
alter default privileges in schema public grant all on tables to anon, authenticated, service_role;
|
| 270 |
+
alter default privileges in schema public grant all on sequences to anon, authenticated, service_role;
|
| 271 |
+
alter default privileges in schema public grant all on functions to anon, authenticated, service_role;
|
styles.css
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
:root {
|
| 2 |
+
--ink: #111114;
|
| 3 |
+
--secondary: #56575e;
|
| 4 |
+
--faint: #8c8d95;
|
| 5 |
+
--hairline: #e8e8ec;
|
| 6 |
+
--accent: #1b6b4f;
|
| 7 |
+
--accent-soft: #edf5f0;
|
| 8 |
+
--accent-deep: #124a37;
|
| 9 |
+
--surface: #ffffff;
|
| 10 |
+
--sunken: #f4f4f7;
|
| 11 |
+
--deep: #f7f7f9;
|
| 12 |
+
--warning: #a9662f;
|
| 13 |
+
--warning-soft: #f9eee0;
|
| 14 |
+
--danger: #a3403f;
|
| 15 |
+
--danger-soft: #f9e7e5;
|
| 16 |
+
--success: #2e7350;
|
| 17 |
+
--success-soft: #eaf3ec;
|
| 18 |
+
--shadow: 0 10px 30px rgba(11, 12, 14, 0.06);
|
| 19 |
+
--serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
|
| 20 |
+
--sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
| 21 |
+
--mono: ui-monospace, SFMono-Regular, Menlo, monospace;
|
| 22 |
+
--radius: 14px;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
* { box-sizing: border-box; }
|
| 26 |
+
html, body { margin: 0; padding: 0; }
|
| 27 |
+
body {
|
| 28 |
+
font-family: var(--sans);
|
| 29 |
+
color: var(--ink);
|
| 30 |
+
background: #fff;
|
| 31 |
+
-webkit-font-smoothing: antialiased;
|
| 32 |
+
font-size: 14px;
|
| 33 |
+
line-height: 1.45;
|
| 34 |
+
}
|
| 35 |
+
button, input, textarea, select { font: inherit; color: inherit; }
|
| 36 |
+
button { cursor: pointer; }
|
| 37 |
+
a { color: var(--accent); text-decoration: none; }
|
| 38 |
+
::selection { background: #d9eae1; }
|
| 39 |
+
|
| 40 |
+
.app { min-height: 100vh; display: flex; background: #fff; }
|
| 41 |
+
|
| 42 |
+
/* ---------- Sidebar ---------- */
|
| 43 |
+
.sidebar {
|
| 44 |
+
width: 286px;
|
| 45 |
+
flex: 0 0 286px;
|
| 46 |
+
border-right: 1px solid var(--hairline);
|
| 47 |
+
background: var(--surface);
|
| 48 |
+
height: 100vh;
|
| 49 |
+
position: sticky;
|
| 50 |
+
top: 0;
|
| 51 |
+
display: flex;
|
| 52 |
+
flex-direction: column;
|
| 53 |
+
overflow-y: auto;
|
| 54 |
+
}
|
| 55 |
+
.sidebar-head { padding: 18px 18px 14px; }
|
| 56 |
+
.brand { display: flex; align-items: center; gap: 10px; }
|
| 57 |
+
.brand-name { font-family: var(--serif); font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
|
| 58 |
+
.brand-sub { font-size: 9.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); margin-top: -1px; }
|
| 59 |
+
|
| 60 |
+
.mark {
|
| 61 |
+
width: 32px; height: 32px; border-radius: 7px; background: #fff; position: relative;
|
| 62 |
+
border: 1px solid rgba(0,0,0,.07); box-shadow: 0 4px 10px rgba(0,0,0,.12);
|
| 63 |
+
display: flex; align-items: center; gap: 2.4px; padding-left: 7px;
|
| 64 |
+
}
|
| 65 |
+
.mark::before { content: ""; width: 2.7px; height: 17px; border-radius: 3px; background: var(--accent); }
|
| 66 |
+
.mark span { display: block; width: 12px; height: 2.4px; border-radius: 3px; background: var(--ink); }
|
| 67 |
+
.mark span:nth-child(2) { width: 9px; }
|
| 68 |
+
.mark span:nth-child(3) { width: 6px; background: rgba(17,17,20,.55); }
|
| 69 |
+
.mark-lines { display: flex; flex-direction: column; gap: 3px; }
|
| 70 |
+
.mark.small { width: 28px; height: 28px; padding-left: 6px; }
|
| 71 |
+
|
| 72 |
+
.side-cta {
|
| 73 |
+
display: flex; align-items: center; gap: 8px; width: 100%;
|
| 74 |
+
background: var(--ink); color: #fff; border: 0; border-radius: 10px;
|
| 75 |
+
padding: 10px 12px; font-weight: 600; font-size: 13px; margin-top: 16px;
|
| 76 |
+
}
|
| 77 |
+
.side-cta:hover { background: #24242a; }
|
| 78 |
+
.nav { padding: 4px 10px 28px; }
|
| 79 |
+
.nav-group { margin-top: 14px; }
|
| 80 |
+
.nav-label { font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); padding: 0 10px 6px; }
|
| 81 |
+
.nav-row {
|
| 82 |
+
display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
|
| 83 |
+
border: 0; background: transparent; color: var(--secondary); border-radius: 8px;
|
| 84 |
+
padding: 7px 10px; font-size: 12.5px;
|
| 85 |
+
}
|
| 86 |
+
.nav-row:hover { background: var(--sunken); color: var(--ink); }
|
| 87 |
+
.nav-row.active { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
|
| 88 |
+
.nav-row .dot { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); margin-left: auto; }
|
| 89 |
+
.nav-row svg { width: 15px; height: 15px; opacity: .8; }
|
| 90 |
+
.nav-row.active svg { opacity: 1; color: var(--accent); }
|
| 91 |
+
|
| 92 |
+
.side-card { margin: 8px 10px 0; border: 1px solid var(--hairline); background: var(--deep); border-radius: 11px; padding: 11px; text-align: left; }
|
| 93 |
+
.side-card .row { display: flex; align-items: center; justify-content: space-between; }
|
| 94 |
+
.mini-label { font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); font-weight: 700; }
|
| 95 |
+
.side-card .name { font-size: 12px; font-weight: 600; margin-top: 5px; }
|
| 96 |
+
.side-card .meta { font-size: 10.5px; color: var(--secondary); margin-top: 2px; }
|
| 97 |
+
.side-foot { margin-top: auto; padding: 16px 18px 20px; font-size: 9.5px; color: var(--faint); display: flex; gap: 7px; line-height: 1.4; }
|
| 98 |
+
|
| 99 |
+
/* ---------- Main ---------- */
|
| 100 |
+
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
|
| 101 |
+
.topbar {
|
| 102 |
+
height: 52px; flex: 0 0 52px; display: flex; align-items: center; gap: 9px;
|
| 103 |
+
padding: 0 14px; border-bottom: 1px solid var(--hairline);
|
| 104 |
+
background: rgba(255,255,255,.96); position: sticky; top: 0; z-index: 20;
|
| 105 |
+
backdrop-filter: saturate(1.4) blur(8px);
|
| 106 |
+
}
|
| 107 |
+
.topbar h1 { font-family: var(--serif); font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
|
| 108 |
+
.topbar .spacer { flex: 1; }
|
| 109 |
+
.menu-btn { display: none; }
|
| 110 |
+
|
| 111 |
+
.pill {
|
| 112 |
+
display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px;
|
| 113 |
+
font-size: 10.5px; font-weight: 600; white-space: nowrap;
|
| 114 |
+
}
|
| 115 |
+
.pill.green { background: var(--accent-soft); color: var(--accent); }
|
| 116 |
+
.pill.neutral { background: var(--deep); color: var(--secondary); border: 1px solid var(--hairline); }
|
| 117 |
+
.pill.warn { background: var(--warning-soft); color: var(--warning); }
|
| 118 |
+
.pill.danger { background: var(--danger-soft); color: var(--danger); }
|
| 119 |
+
.status-pill { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 999px; background: var(--deep); font-size: 10px; color: var(--secondary); border: 1px solid transparent; }
|
| 120 |
+
.status-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--warning); }
|
| 121 |
+
.status-pill.ready .dot { background: var(--success); }
|
| 122 |
+
|
| 123 |
+
.icon-btn {
|
| 124 |
+
display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
|
| 125 |
+
border: 0; background: transparent; border-radius: 8px; color: var(--secondary);
|
| 126 |
+
}
|
| 127 |
+
.icon-btn:hover { background: var(--sunken); color: var(--ink); }
|
| 128 |
+
.icon-btn.active { background: var(--accent-soft); color: var(--accent); }
|
| 129 |
+
.icon-btn svg { width: 16px; height: 16px; }
|
| 130 |
+
|
| 131 |
+
.page { width: 100%; max-width: 1040px; margin: 0 auto; padding: 26px 26px 80px; }
|
| 132 |
+
.page.narrow { max-width: 860px; }
|
| 133 |
+
|
| 134 |
+
/* ---------- Type ---------- */
|
| 135 |
+
.eyebrow { font-size: 10px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--faint); }
|
| 136 |
+
.display { font-family: var(--serif); font-size: 32px; line-height: 1.12; letter-spacing: -.02em; margin: 6px 0 0; font-weight: 600; }
|
| 137 |
+
.page-title { font-family: var(--serif); font-size: 24px; line-height: 1.15; letter-spacing: -.015em; margin: 3px 0 0; font-weight: 600; }
|
| 138 |
+
.subtitle { color: var(--secondary); font-size: 12.5px; margin: 7px 0 0; max-width: 640px; line-height: 1.55; }
|
| 139 |
+
.muted { color: var(--secondary); }
|
| 140 |
+
.faint { color: var(--faint); }
|
| 141 |
+
.tiny { font-size: 11px; }
|
| 142 |
+
.mono { font-family: var(--mono); }
|
| 143 |
+
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 26px 0 10px; }
|
| 144 |
+
.section-title { font-family: var(--serif); font-size: 17px; font-weight: 600; margin: 0; }
|
| 145 |
+
|
| 146 |
+
/* ---------- Cards ---------- */
|
| 147 |
+
.card {
|
| 148 |
+
background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius);
|
| 149 |
+
padding: 16px; box-shadow: 0 3px 10px rgba(11,12,14,.03);
|
| 150 |
+
}
|
| 151 |
+
.card.soft { background: var(--deep); }
|
| 152 |
+
.card.flat { box-shadow: none; }
|
| 153 |
+
.card.hero { padding: 20px; display: flex; gap: 18px; align-items: flex-start; justify-content: space-between; }
|
| 154 |
+
.card-title { font-family: var(--serif); font-size: 21px; line-height: 1.15; margin: 0 0 6px; font-weight: 600; letter-spacing: -.01em; }
|
| 155 |
+
.grid { display: grid; gap: 12px; }
|
| 156 |
+
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
| 157 |
+
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
| 158 |
+
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
| 159 |
+
.grid.split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
|
| 160 |
+
.row { display: flex; align-items: center; gap: 8px; }
|
| 161 |
+
.row.wrap { flex-wrap: wrap; }
|
| 162 |
+
.row.between { justify-content: space-between; }
|
| 163 |
+
.stack { display: flex; flex-direction: column; gap: 10px; }
|
| 164 |
+
|
| 165 |
+
.stat { padding: 13px; border: 1px solid var(--hairline); border-radius: 12px; background: #fff; }
|
| 166 |
+
.stat .head { display: flex; align-items: center; justify-content: space-between; color: var(--faint); font-size: 9.5px; letter-spacing: .07em; text-transform: uppercase; font-weight: 700; }
|
| 167 |
+
.stat .value { font-size: 25px; font-weight: 600; margin-top: 7px; letter-spacing: -.02em; }
|
| 168 |
+
.stat .note { font-size: 10.5px; color: var(--faint); margin-top: 2px; }
|
| 169 |
+
|
| 170 |
+
/* ---------- Buttons ---------- */
|
| 171 |
+
.btn {
|
| 172 |
+
display: inline-flex; align-items: center; justify-content: center; gap: 6px;
|
| 173 |
+
border: 1px solid var(--hairline); background: #fff; color: var(--ink);
|
| 174 |
+
border-radius: 10px; padding: 9px 13px; font-size: 12.5px; font-weight: 600;
|
| 175 |
+
white-space: nowrap; transition: background .12s, opacity .12s, transform .06s;
|
| 176 |
+
}
|
| 177 |
+
.btn:hover { background: var(--deep); }
|
| 178 |
+
.btn:active { transform: translateY(1px); }
|
| 179 |
+
.btn:disabled { opacity: .45; cursor: not-allowed; }
|
| 180 |
+
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.14); }
|
| 181 |
+
.btn.primary:hover { background: #24242a; }
|
| 182 |
+
.btn.green { background: var(--accent); border-color: var(--accent); color: #fff; }
|
| 183 |
+
.btn.green:hover { background: var(--accent-deep); }
|
| 184 |
+
.btn.ghost { background: transparent; border-color: transparent; color: var(--secondary); }
|
| 185 |
+
.btn.ghost:hover { background: var(--sunken); color: var(--ink); }
|
| 186 |
+
.btn.small { padding: 6px 10px; font-size: 11.5px; border-radius: 8px; }
|
| 187 |
+
.btn.link { border: 0; background: transparent; padding: 0; color: var(--accent); font-weight: 600; }
|
| 188 |
+
.btn.danger { color: var(--danger); border-color: #f0d4d2; }
|
| 189 |
+
|
| 190 |
+
/* ---------- Forms ---------- */
|
| 191 |
+
.field { display: flex; flex-direction: column; gap: 6px; }
|
| 192 |
+
.field > label { font-size: 11px; font-weight: 600; color: var(--secondary); display: flex; justify-content: space-between; gap: 8px; }
|
| 193 |
+
.field .hint { font-size: 10px; color: var(--faint); font-weight: 400; }
|
| 194 |
+
.input, .textarea, .select {
|
| 195 |
+
width: 100%; border: 1px solid var(--hairline); background: #fff; border-radius: 10px;
|
| 196 |
+
padding: 10px 11px; font-size: 13px; outline: none; transition: border-color .12s, box-shadow .12s;
|
| 197 |
+
}
|
| 198 |
+
.textarea { resize: vertical; min-height: 120px; line-height: 1.62; font-family: var(--serif); font-size: 14.5px; }
|
| 199 |
+
.input:focus, .textarea:focus, .select:focus { border-color: rgba(27,107,79,.45); box-shadow: 0 0 0 3px rgba(27,107,79,.09); }
|
| 200 |
+
.textarea.plain { font-family: var(--sans); font-size: 13px; }
|
| 201 |
+
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--faint) 50%), linear-gradient(135deg, var(--faint) 50%, transparent 50%); background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
|
| 202 |
+
.count { font-size: 10px; color: var(--faint); font-variant-numeric: tabular-nums; }
|
| 203 |
+
|
| 204 |
+
/* ---------- Feedback ---------- */
|
| 205 |
+
.score-card { display: flex; gap: 16px; align-items: center; }
|
| 206 |
+
.ring {
|
| 207 |
+
--pct: 0; width: 74px; height: 74px; border-radius: 50%; flex: 0 0 74px;
|
| 208 |
+
background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--sunken) 0);
|
| 209 |
+
display: grid; place-items: center; position: relative;
|
| 210 |
+
}
|
| 211 |
+
.ring::after { content: ""; position: absolute; inset: 7px; background: #fff; border-radius: 50%; }
|
| 212 |
+
.ring .num { position: relative; z-index: 1; font-family: var(--serif); font-size: 22px; font-weight: 600; }
|
| 213 |
+
.ring .den { position: relative; z-index: 1; font-size: 9px; color: var(--faint); margin-top: -2px; }
|
| 214 |
+
|
| 215 |
+
.criterion { border-top: 1px solid var(--hairline); padding: 10px 0; }
|
| 216 |
+
.criterion:first-child { border-top: 0; }
|
| 217 |
+
.criterion .head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
|
| 218 |
+
.criterion .name { font-size: 12px; font-weight: 600; }
|
| 219 |
+
.criterion .score { font-family: var(--mono); font-size: 11px; color: var(--secondary); }
|
| 220 |
+
.bar { height: 4px; background: var(--sunken); border-radius: 3px; overflow: hidden; margin: 6px 0 5px; }
|
| 221 |
+
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
|
| 222 |
+
.criterion .note { font-size: 10.5px; color: var(--secondary); line-height: 1.5; }
|
| 223 |
+
|
| 224 |
+
.callout { border-radius: 11px; padding: 11px 12px; font-size: 11.5px; line-height: 1.55; border: 1px solid; }
|
| 225 |
+
.callout.green { background: var(--success-soft); border-color: #d5e7da; color: #245a3e; }
|
| 226 |
+
.callout.amber { background: var(--warning-soft); border-color: #f0dcc5; color: #7d4a1f; }
|
| 227 |
+
.callout.red { background: var(--danger-soft); border-color: #f0d4d2; color: #8a3534; }
|
| 228 |
+
.callout.blue { background: #eef3f9; border-color: #d9e3ef; color: #2b4c6f; }
|
| 229 |
+
|
| 230 |
+
/* ---------- Chat ---------- */
|
| 231 |
+
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 52px); }
|
| 232 |
+
.transcript { flex: 1; overflow-y: auto; padding: 22px 20px 150px; }
|
| 233 |
+
.transcript-inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
|
| 234 |
+
.msg { display: flex; gap: 9px; align-items: flex-start; }
|
| 235 |
+
.msg .bubble { border: 1px solid var(--hairline); background: #fff; border-radius: 14px; padding: 12px 14px; font-family: var(--serif); font-size: 15px; line-height: 1.6; white-space: pre-wrap; max-width: 92%; }
|
| 236 |
+
.msg.student { justify-content: flex-end; }
|
| 237 |
+
.msg.student .bubble { background: var(--accent-soft); border-color: rgba(27,107,79,.14); font-family: var(--sans); font-size: 13.5px; }
|
| 238 |
+
.msg .who { font-size: 9px; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); font-weight: 700; margin-bottom: 4px; }
|
| 239 |
+
.composer-dock { position: fixed; left: 286px; right: 0; bottom: 0; z-index: 15; padding: 10px 20px calc(14px + env(safe-area-inset-bottom)); background: linear-gradient(to top, #fff 72%, rgba(255,255,255,0)); }
|
| 240 |
+
.composer { max-width: 760px; margin: 0 auto; border: 1px solid var(--hairline); background: #fff; border-radius: 16px; padding: 10px; box-shadow: var(--shadow); }
|
| 241 |
+
.composer .row { align-items: flex-end; }
|
| 242 |
+
.composer textarea { border: 0; outline: none; resize: none; min-height: 46px; max-height: 150px; padding: 8px 6px; font-size: 13.5px; flex: 1; }
|
| 243 |
+
.composer .foot { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 0; }
|
| 244 |
+
.send { width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--ink); color: #fff; display: grid; place-items: center; }
|
| 245 |
+
.send:disabled { background: var(--hairline); color: var(--faint); }
|
| 246 |
+
|
| 247 |
+
/* ---------- Tables / lists ---------- */
|
| 248 |
+
.list { display: flex; flex-direction: column; }
|
| 249 |
+
.list-row { display: flex; align-items: center; gap: 10px; padding: 11px 2px; border-top: 1px solid var(--hairline); }
|
| 250 |
+
.list-row:first-child { border-top: 0; }
|
| 251 |
+
.list-row .main { flex: 1; min-width: 0; }
|
| 252 |
+
.list-row .t { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
| 253 |
+
.list-row .s { font-size: 10.5px; color: var(--faint); margin-top: 2px; }
|
| 254 |
+
|
| 255 |
+
.empty { text-align: center; padding: 40px 20px; color: var(--faint); }
|
| 256 |
+
.empty .mark { margin: 0 auto 12px; }
|
| 257 |
+
|
| 258 |
+
/* ---------- Notices ---------- */
|
| 259 |
+
.notice { border-radius: 10px; padding: 10px 12px; font-size: 11.5px; display: flex; gap: 8px; align-items: flex-start; }
|
| 260 |
+
.notice.error { background: var(--danger-soft); color: var(--danger); }
|
| 261 |
+
.notice.info { background: var(--accent-soft); color: var(--accent-deep); }
|
| 262 |
+
.notice.warn { background: var(--warning-soft); color: var(--warning); }
|
| 263 |
+
|
| 264 |
+
/* ---------- Drawer ---------- */
|
| 265 |
+
.scrim { position: fixed; inset: 0; background: rgba(11,12,14,.24); z-index: 40; }
|
| 266 |
+
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(320px, 86vw); background: #fff; z-index: 41; box-shadow: 20px 0 50px rgba(0,0,0,.18); display: flex; flex-direction: column; overflow-y: auto; }
|
| 267 |
+
|
| 268 |
+
/* ---------- Responsive ---------- */
|
| 269 |
+
@media (max-width: 900px) {
|
| 270 |
+
.sidebar { display: none; }
|
| 271 |
+
.menu-btn { display: inline-flex; }
|
| 272 |
+
.page { padding: 18px 16px 70px; }
|
| 273 |
+
.grid.split, .grid.two { grid-template-columns: 1fr; }
|
| 274 |
+
.grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
| 275 |
+
.grid.three { grid-template-columns: 1fr; }
|
| 276 |
+
.display { font-size: 27px; }
|
| 277 |
+
.card.hero { flex-direction: column; }
|
| 278 |
+
.chat-wrap { height: calc(100vh - 52px); }
|
| 279 |
+
.transcript { padding: 16px 14px 160px; }
|
| 280 |
+
.composer-dock { left: 0; padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); }
|
| 281 |
+
}
|
| 282 |
+
@media (max-width: 520px) {
|
| 283 |
+
.grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
| 284 |
+
.topbar h1 { font-size: 14px; }
|
| 285 |
+
.toolbar .label { display: none; }
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
/* ---------- Print ---------- */
|
| 289 |
+
@media print {
|
| 290 |
+
.sidebar, .topbar, .composer-dock, .no-print { display: none !important; }
|
| 291 |
+
.page { max-width: none; padding: 0; }
|
| 292 |
+
.card { break-inside: avoid; box-shadow: none; }
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
/* ---------- Small helpers ---------- */
|
| 296 |
+
.divider { height: 1px; background: var(--hairline); margin: 14px 0; }
|
| 297 |
+
.kbd { font-family: var(--mono); font-size: 10px; border: 1px solid var(--hairline); border-bottom-width: 2px; border-radius: 5px; padding: 1px 4px; color: var(--secondary); background: var(--deep); }
|
| 298 |
+
.hide { display: none !important; }
|
| 299 |
+
.scroll-x { overflow-x: auto; }
|
| 300 |
+
.spin { width: 14px; height: 14px; border: 2px solid var(--hairline); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
|
| 301 |
+
@keyframes spin { to { transform: rotate(360deg); } }
|
| 302 |
+
.fade-in { animation: fade .18s ease-out; }
|
| 303 |
+
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
|
| 304 |
+
|
| 305 |
+
/* ---------- Accounts, plans, developer ---------- */
|
| 306 |
+
.setup-banner {
|
| 307 |
+
display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
|
| 308 |
+
padding: 10px 14px; background: var(--accent-soft); border-bottom: 1px solid #d9eae1;
|
| 309 |
+
color: var(--accent-deep); font-size: 12px;
|
| 310 |
+
}
|
| 311 |
+
.setup-banner .setup-copy { flex: 1; min-width: 220px; line-height: 1.45; }
|
| 312 |
+
.setup-banner strong { font-weight: 700; }
|
| 313 |
+
.edit-bar {
|
| 314 |
+
position: fixed; left: 50%; transform: translateX(-50%); bottom: 18px; z-index: 60;
|
| 315 |
+
display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
|
| 316 |
+
max-width: min(680px, calc(100vw - 24px)); padding: 10px 14px;
|
| 317 |
+
background: var(--ink); color: #fff; border-radius: 12px; font-size: 12px;
|
| 318 |
+
box-shadow: 0 16px 40px rgba(0,0,0,.28);
|
| 319 |
+
}
|
| 320 |
+
.edit-bar .btn { border-color: rgba(255,255,255,.24); background: transparent; color: #fff; }
|
| 321 |
+
.edit-bar .btn.primary { background: #fff; color: var(--ink); border-color: #fff; }
|
| 322 |
+
.edit-bar .btn:hover { background: rgba(255,255,255,.12); }
|
| 323 |
+
.edit-bar .btn.primary:hover { background: #f2f2f5; }
|
| 324 |
+
.dot-live { width: 7px; height: 7px; border-radius: 50%; background: #6ddba0; box-shadow: 0 0 0 3px rgba(109,219,160,.24); }
|
| 325 |
+
.edit-target { outline: 1px dashed rgba(27,107,79,.45); outline-offset: 3px; border-radius: 4px; cursor: text; }
|
| 326 |
+
.edit-target:hover { background: rgba(27,107,79,.06); }
|
| 327 |
+
.edit-target:focus { outline: 2px solid rgba(27,107,79,.55); background: rgba(27,107,79,.04); }
|
| 328 |
+
|
| 329 |
+
.account-chip {
|
| 330 |
+
display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--hairline);
|
| 331 |
+
background: #fff; border-radius: 999px; padding: 4px 9px 4px 4px; font-size: 11px; color: var(--secondary);
|
| 332 |
+
}
|
| 333 |
+
.account-chip:hover { background: var(--deep); }
|
| 334 |
+
.account-chip .avatar {
|
| 335 |
+
width: 20px; height: 20px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
|
| 336 |
+
display: grid; place-items: center; font-size: 10px; font-weight: 700;
|
| 337 |
+
}
|
| 338 |
+
.account-chip .who { font-weight: 600; }
|
| 339 |
+
|
| 340 |
+
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-top: 16px; }
|
| 341 |
+
.plan-card { display: flex; flex-direction: column; }
|
| 342 |
+
.plan-card.current { border-color: rgba(27,107,79,.35); box-shadow: 0 6px 22px rgba(27,107,79,.08); }
|
| 343 |
+
.plan-name { font-family: var(--serif); font-size: 18px; font-weight: 600; letter-spacing: -.01em; }
|
| 344 |
+
.plan-price { font-size: 26px; font-weight: 600; letter-spacing: -.02em; margin-top: 8px; }
|
| 345 |
+
.plan-period { font-size: 12px; font-weight: 500; color: var(--faint); letter-spacing: 0; margin-left: 2px; }
|
| 346 |
+
.plan-blurb { font-size: 11.5px; color: var(--secondary); line-height: 1.55; margin: 10px 0 0; min-height: 36px; }
|
| 347 |
+
.plan-limit {
|
| 348 |
+
display: flex; align-items: center; gap: 6px; margin-top: 10px; padding: 6px 8px;
|
| 349 |
+
background: var(--deep); border-radius: 8px; font-size: 10.5px; color: var(--secondary);
|
| 350 |
+
}
|
| 351 |
+
.plan-limit svg { color: var(--accent); }
|
| 352 |
+
.plan-features { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
|
| 353 |
+
.plan-features li { display: flex; gap: 7px; align-items: flex-start; font-size: 11.5px; line-height: 1.45; color: var(--secondary); }
|
| 354 |
+
.plan-features li svg { flex: 0 0 12px; margin-top: 2px; color: var(--accent); }
|
| 355 |
+
.plan-features li.muted svg { color: var(--faint); }
|
| 356 |
+
.plan-cta { margin-top: auto; width: 100%; margin-top: 16px; }
|
| 357 |
+
|
| 358 |
+
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; border-bottom: 1px solid var(--hairline); }
|
| 359 |
+
.tab {
|
| 360 |
+
border: 0; background: transparent; padding: 8px 10px; border-radius: 8px 8px 0 0;
|
| 361 |
+
font-size: 12px; font-weight: 600; color: var(--secondary); white-space: nowrap;
|
| 362 |
+
}
|
| 363 |
+
.tab:hover { background: var(--deep); color: var(--ink); }
|
| 364 |
+
.tab.active { color: var(--accent); background: var(--accent-soft); }
|
| 365 |
+
|
| 366 |
+
.check-row { display: flex; align-items: flex-start; gap: 8px; font-size: 12px; cursor: pointer; }
|
| 367 |
+
.check-row input { margin-top: 2px; accent-color: var(--accent); }
|
| 368 |
+
|
| 369 |
+
/* ---------- Plans page ---------- */
|
| 370 |
+
.price-hero {
|
| 371 |
+
position: relative; overflow: hidden; border-radius: 20px; padding: 34px 30px;
|
| 372 |
+
background: linear-gradient(135deg, #f2f8f3 0%, #fbf7ef 58%, #f5efe6 100%);
|
| 373 |
+
border: 1px solid #e4ebe5;
|
| 374 |
+
}
|
| 375 |
+
.price-hero::after {
|
| 376 |
+
content: ""; position: absolute; width: 340px; height: 340px; border-radius: 50%;
|
| 377 |
+
right: -110px; top: -140px; background: radial-gradient(circle at center, rgba(27,107,79,.14), transparent 70%);
|
| 378 |
+
}
|
| 379 |
+
.deal-pill {
|
| 380 |
+
display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid #dde8e0;
|
| 381 |
+
color: var(--accent-deep); border-radius: 999px; padding: 5px 11px;
|
| 382 |
+
font-size: 10.5px; font-weight: 700; letter-spacing: .02em; position: relative; z-index: 1;
|
| 383 |
+
}
|
| 384 |
+
.price-title {
|
| 385 |
+
font-family: var(--serif); font-size: 46px; line-height: 1.04; letter-spacing: -.03em;
|
| 386 |
+
margin: 14px 0 0; max-width: 650px; position: relative; z-index: 1;
|
| 387 |
+
}
|
| 388 |
+
.price-lede { font-size: 14px; color: var(--secondary); max-width: 560px; line-height: 1.62; margin: 13px 0 0; position: relative; z-index: 1; }
|
| 389 |
+
.price-chips { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 18px; font-size: 11.5px; color: var(--accent-deep); font-weight: 600; position: relative; z-index: 1; }
|
| 390 |
+
.price-chips span { display: inline-flex; align-items: center; gap: 5px; }
|
| 391 |
+
.price-chips svg { color: var(--accent); }
|
| 392 |
+
|
| 393 |
+
.free-strip {
|
| 394 |
+
margin-top: 20px; display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
|
| 395 |
+
padding: 15px 18px; border-radius: 14px; border: 1px dashed #cfdcd4; background: #fbfdfb;
|
| 396 |
+
}
|
| 397 |
+
.free-strip-title { font-weight: 700; font-size: 13px; }
|
| 398 |
+
.free-strip-body { font-size: 11.5px; color: var(--secondary); margin-top: 3px; }
|
| 399 |
+
|
| 400 |
+
.plan-card { position: relative; padding-top: 18px; }
|
| 401 |
+
.plan-card.featured { border-color: rgba(27,107,79,.48); box-shadow: 0 18px 44px rgba(27,107,79,.11); }
|
| 402 |
+
.plan-ribbon {
|
| 403 |
+
position: absolute; top: 0; left: 18px; transform: translateY(-50%);
|
| 404 |
+
background: var(--ink); color: #fff; font-size: 9px; letter-spacing: .09em; text-transform: uppercase;
|
| 405 |
+
font-weight: 700; padding: 4px 9px; border-radius: 999px; white-space: nowrap;
|
| 406 |
+
}
|
| 407 |
+
.plan-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
| 408 |
+
.plan-price { font-size: 31px; margin-top: 10px; }
|
| 409 |
+
.plan-subline { font-size: 10.5px; color: var(--faint); margin-top: 1px; }
|
| 410 |
+
.plan-foot { font-size: 10px; color: var(--faint); text-align: center; margin-top: 8px; line-height: 1.4; }
|
| 411 |
+
|
| 412 |
+
.value-card { padding: 18px; }
|
| 413 |
+
.value-icon {
|
| 414 |
+
width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); color: var(--accent);
|
| 415 |
+
display: grid; place-items: center; margin-bottom: 10px;
|
| 416 |
+
}
|
| 417 |
+
.value-title { font-family: var(--serif); font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
|
| 418 |
+
.value-body { font-size: 11.5px; color: var(--secondary); line-height: 1.55; margin-top: 5px; }
|
| 419 |
+
|
| 420 |
+
.faq { padding: 6px 18px; }
|
| 421 |
+
.faq details { border-top: 1px solid var(--hairline); padding: 11px 0; }
|
| 422 |
+
.faq details:first-of-type { border-top: 0; }
|
| 423 |
+
.faq summary { cursor: pointer; font-weight: 600; font-size: 12.5px; display: flex; justify-content: space-between; gap: 12px; list-style: none; }
|
| 424 |
+
.faq summary::-webkit-details-marker { display: none; }
|
| 425 |
+
.faq summary::after { content: "+"; color: var(--faint); font-weight: 400; }
|
| 426 |
+
.faq details[open] summary::after { content: "–"; }
|
| 427 |
+
.faq p { font-size: 12px; color: var(--secondary); line-height: 1.62; margin: 8px 0 0; max-width: 740px; }
|
| 428 |
+
@media (max-width: 900px) {
|
| 429 |
+
.price-hero { padding: 24px 20px; }
|
| 430 |
+
.price-title { font-size: 33px; }
|
| 431 |
+
.price-lede { font-size: 13px; }
|
| 432 |
+
}
|
vendor/htm.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.htm=e()}(this,function(){var n=function(e,t,u,s){var r;t[0]=0;for(var p=1;p<t.length;p++){var h=t[p++],o=t[p]?(t[0]|=h?1:2,u[t[p++]]):t[++p];3===h?s[0]=o:4===h?s[1]=Object.assign(s[1]||{},o):5===h?(s[1]=s[1]||{})[t[++p]]=o:6===h?s[1][t[++p]]+=o+"":h?(r=e.apply(o,n(e,o,u,["",null])),s.push(r),o[0]?t[0]|=2:(t[p-2]=0,t[p]=r)):s.push(o)}return s},e=new Map;return function(t){var u=e.get(this);return u||(u=new Map,e.set(this,u)),(u=n(this,u.get(t)||(u.set(t,u=function(n){for(var e,t,u=1,s="",r="",p=[0],h=function(n){1===u&&(n||(s=s.replace(/^\s*\n\s*|\s*\n\s*$/g,"")))?p.push(0,n,s):3===u&&(n||s)?(p.push(3,n,s),u=2):2===u&&"..."===s&&n?p.push(4,n,0):2===u&&s&&!n?p.push(5,0,!0,s):u>=5&&((s||!n&&5===u)&&(p.push(u,0,s,t),u=6),n&&(p.push(u,n,0,t),u=6)),s=""},o=0;o<n.length;o++){o&&(1===u&&h(),h(o));for(var f=0;f<n[o].length;f++)e=n[o][f],1===u?"<"===e?(h(),p=[p],u=3):s+=e:4===u?"--"===s&&">"===e?(u=1,s=""):s=e+s[0]:r?e===r?r="":s+=e:'"'===e||"'"===e?r=e:">"===e?(h(),u=1):u&&("="===e?(u=5,t=s,s=""):"/"===e&&(u<5||">"===n[o][f+1])?(h(),3===u&&(p=p[0]),u=p,(p=p[0]).push(2,0,u),u=0):" "===e||"\t"===e||"\n"===e||"\r"===e?(h(),u=2):s+=e),3===u&&"!--"===s&&(u=4,p=p[0])}return h(),p}(t)),u),arguments,[])).length>1?u:u[0]}});
|
vendor/react-dom.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
vendor/react.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @license React
|
| 3 |
+
* react.production.min.js
|
| 4 |
+
*
|
| 5 |
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
| 6 |
+
*
|
| 7 |
+
* This source code is licensed under the MIT license found in the
|
| 8 |
+
* LICENSE file in the root directory of this source tree.
|
| 9 |
+
*/
|
| 10 |
+
(function(){'use strict';(function(c,x){"object"===typeof exports&&"undefined"!==typeof module?x(exports):"function"===typeof define&&define.amd?define(["exports"],x):(c=c||self,x(c.React={}))})(this,function(c){function x(a){if(null===a||"object"!==typeof a)return null;a=V&&a[V]||a["@@iterator"];return"function"===typeof a?a:null}function w(a,b,e){this.props=a;this.context=b;this.refs=W;this.updater=e||X}function Y(){}function K(a,b,e){this.props=a;this.context=b;this.refs=W;this.updater=e||X}function Z(a,b,
|
| 11 |
+
e){var m,d={},c=null,h=null;if(null!=b)for(m in void 0!==b.ref&&(h=b.ref),void 0!==b.key&&(c=""+b.key),b)aa.call(b,m)&&!ba.hasOwnProperty(m)&&(d[m]=b[m]);var l=arguments.length-2;if(1===l)d.children=e;else if(1<l){for(var f=Array(l),k=0;k<l;k++)f[k]=arguments[k+2];d.children=f}if(a&&a.defaultProps)for(m in l=a.defaultProps,l)void 0===d[m]&&(d[m]=l[m]);return{$$typeof:y,type:a,key:c,ref:h,props:d,_owner:L.current}}function oa(a,b){return{$$typeof:y,type:a.type,key:b,ref:a.ref,props:a.props,_owner:a._owner}}
|
| 12 |
+
function M(a){return"object"===typeof a&&null!==a&&a.$$typeof===y}function pa(a){var b={"=":"=0",":":"=2"};return"$"+a.replace(/[=:]/g,function(a){return b[a]})}function N(a,b){return"object"===typeof a&&null!==a&&null!=a.key?pa(""+a.key):b.toString(36)}function B(a,b,e,m,d){var c=typeof a;if("undefined"===c||"boolean"===c)a=null;var h=!1;if(null===a)h=!0;else switch(c){case "string":case "number":h=!0;break;case "object":switch(a.$$typeof){case y:case qa:h=!0}}if(h)return h=a,d=d(h),a=""===m?"."+
|
| 13 |
+
N(h,0):m,ca(d)?(e="",null!=a&&(e=a.replace(da,"$&/")+"/"),B(d,b,e,"",function(a){return a})):null!=d&&(M(d)&&(d=oa(d,e+(!d.key||h&&h.key===d.key?"":(""+d.key).replace(da,"$&/")+"/")+a)),b.push(d)),1;h=0;m=""===m?".":m+":";if(ca(a))for(var l=0;l<a.length;l++){c=a[l];var f=m+N(c,l);h+=B(c,b,e,f,d)}else if(f=x(a),"function"===typeof f)for(a=f.call(a),l=0;!(c=a.next()).done;)c=c.value,f=m+N(c,l++),h+=B(c,b,e,f,d);else if("object"===c)throw b=String(a),Error("Objects are not valid as a React child (found: "+
|
| 14 |
+
("[object Object]"===b?"object with keys {"+Object.keys(a).join(", ")+"}":b)+"). If you meant to render a collection of children, use an array instead.");return h}function C(a,b,e){if(null==a)return a;var c=[],d=0;B(a,c,"","",function(a){return b.call(e,a,d++)});return c}function ra(a){if(-1===a._status){var b=a._result;b=b();b.then(function(b){if(0===a._status||-1===a._status)a._status=1,a._result=b},function(b){if(0===a._status||-1===a._status)a._status=2,a._result=b});-1===a._status&&(a._status=
|
| 15 |
+
0,a._result=b)}if(1===a._status)return a._result.default;throw a._result;}function O(a,b){var e=a.length;a.push(b);a:for(;0<e;){var c=e-1>>>1,d=a[c];if(0<D(d,b))a[c]=b,a[e]=d,e=c;else break a}}function p(a){return 0===a.length?null:a[0]}function E(a){if(0===a.length)return null;var b=a[0],e=a.pop();if(e!==b){a[0]=e;a:for(var c=0,d=a.length,k=d>>>1;c<k;){var h=2*(c+1)-1,l=a[h],f=h+1,g=a[f];if(0>D(l,e))f<d&&0>D(g,l)?(a[c]=g,a[f]=e,c=f):(a[c]=l,a[h]=e,c=h);else if(f<d&&0>D(g,e))a[c]=g,a[f]=e,c=f;else break a}}return b}
|
| 16 |
+
function D(a,b){var c=a.sortIndex-b.sortIndex;return 0!==c?c:a.id-b.id}function P(a){for(var b=p(r);null!==b;){if(null===b.callback)E(r);else if(b.startTime<=a)E(r),b.sortIndex=b.expirationTime,O(q,b);else break;b=p(r)}}function Q(a){z=!1;P(a);if(!u)if(null!==p(q))u=!0,R(S);else{var b=p(r);null!==b&&T(Q,b.startTime-a)}}function S(a,b){u=!1;z&&(z=!1,ea(A),A=-1);F=!0;var c=k;try{P(b);for(n=p(q);null!==n&&(!(n.expirationTime>b)||a&&!fa());){var m=n.callback;if("function"===typeof m){n.callback=null;
|
| 17 |
+
k=n.priorityLevel;var d=m(n.expirationTime<=b);b=v();"function"===typeof d?n.callback=d:n===p(q)&&E(q);P(b)}else E(q);n=p(q)}if(null!==n)var g=!0;else{var h=p(r);null!==h&&T(Q,h.startTime-b);g=!1}return g}finally{n=null,k=c,F=!1}}function fa(){return v()-ha<ia?!1:!0}function R(a){G=a;H||(H=!0,I())}function T(a,b){A=ja(function(){a(v())},b)}function ka(a){throw Error("act(...) is not supported in production builds of React.");}var y=Symbol.for("react.element"),qa=Symbol.for("react.portal"),sa=Symbol.for("react.fragment"),
|
| 18 |
+
ta=Symbol.for("react.strict_mode"),ua=Symbol.for("react.profiler"),va=Symbol.for("react.provider"),wa=Symbol.for("react.context"),xa=Symbol.for("react.forward_ref"),ya=Symbol.for("react.suspense"),za=Symbol.for("react.memo"),Aa=Symbol.for("react.lazy"),V=Symbol.iterator,X={isMounted:function(a){return!1},enqueueForceUpdate:function(a,b,c){},enqueueReplaceState:function(a,b,c,m){},enqueueSetState:function(a,b,c,m){}},la=Object.assign,W={};w.prototype.isReactComponent={};w.prototype.setState=function(a,
|
| 19 |
+
b){if("object"!==typeof a&&"function"!==typeof a&&null!=a)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,a,b,"setState")};w.prototype.forceUpdate=function(a){this.updater.enqueueForceUpdate(this,a,"forceUpdate")};Y.prototype=w.prototype;var t=K.prototype=new Y;t.constructor=K;la(t,w.prototype);t.isPureReactComponent=!0;var ca=Array.isArray,aa=Object.prototype.hasOwnProperty,L={current:null},
|
| 20 |
+
ba={key:!0,ref:!0,__self:!0,__source:!0},da=/\/+/g,g={current:null},J={transition:null};if("object"===typeof performance&&"function"===typeof performance.now){var Ba=performance;var v=function(){return Ba.now()}}else{var ma=Date,Ca=ma.now();v=function(){return ma.now()-Ca}}var q=[],r=[],Da=1,n=null,k=3,F=!1,u=!1,z=!1,ja="function"===typeof setTimeout?setTimeout:null,ea="function"===typeof clearTimeout?clearTimeout:null,na="undefined"!==typeof setImmediate?setImmediate:null;"undefined"!==typeof navigator&&
|
| 21 |
+
void 0!==navigator.scheduling&&void 0!==navigator.scheduling.isInputPending&&navigator.scheduling.isInputPending.bind(navigator.scheduling);var H=!1,G=null,A=-1,ia=5,ha=-1,U=function(){if(null!==G){var a=v();ha=a;var b=!0;try{b=G(!0,a)}finally{b?I():(H=!1,G=null)}}else H=!1};if("function"===typeof na)var I=function(){na(U)};else if("undefined"!==typeof MessageChannel){t=new MessageChannel;var Ea=t.port2;t.port1.onmessage=U;I=function(){Ea.postMessage(null)}}else I=function(){ja(U,0)};t={ReactCurrentDispatcher:g,
|
| 22 |
+
ReactCurrentOwner:L,ReactCurrentBatchConfig:J,Scheduler:{__proto__:null,unstable_ImmediatePriority:1,unstable_UserBlockingPriority:2,unstable_NormalPriority:3,unstable_IdlePriority:5,unstable_LowPriority:4,unstable_runWithPriority:function(a,b){switch(a){case 1:case 2:case 3:case 4:case 5:break;default:a=3}var c=k;k=a;try{return b()}finally{k=c}},unstable_next:function(a){switch(k){case 1:case 2:case 3:var b=3;break;default:b=k}var c=k;k=b;try{return a()}finally{k=c}},unstable_scheduleCallback:function(a,
|
| 23 |
+
b,c){var e=v();"object"===typeof c&&null!==c?(c=c.delay,c="number"===typeof c&&0<c?e+c:e):c=e;switch(a){case 1:var d=-1;break;case 2:d=250;break;case 5:d=1073741823;break;case 4:d=1E4;break;default:d=5E3}d=c+d;a={id:Da++,callback:b,priorityLevel:a,startTime:c,expirationTime:d,sortIndex:-1};c>e?(a.sortIndex=c,O(r,a),null===p(q)&&a===p(r)&&(z?(ea(A),A=-1):z=!0,T(Q,c-e))):(a.sortIndex=d,O(q,a),u||F||(u=!0,R(S)));return a},unstable_cancelCallback:function(a){a.callback=null},unstable_wrapCallback:function(a){var b=
|
| 24 |
+
k;return function(){var c=k;k=b;try{return a.apply(this,arguments)}finally{k=c}}},unstable_getCurrentPriorityLevel:function(){return k},unstable_shouldYield:fa,unstable_requestPaint:function(){},unstable_continueExecution:function(){u||F||(u=!0,R(S))},unstable_pauseExecution:function(){},unstable_getFirstCallbackNode:function(){return p(q)},get unstable_now(){return v},unstable_forceFrameRate:function(a){0>a||125<a?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):
|
| 25 |
+
ia=0<a?Math.floor(1E3/a):5},unstable_Profiling:null}};c.Children={map:C,forEach:function(a,b,c){C(a,function(){b.apply(this,arguments)},c)},count:function(a){var b=0;C(a,function(){b++});return b},toArray:function(a){return C(a,function(a){return a})||[]},only:function(a){if(!M(a))throw Error("React.Children.only expected to receive a single React element child.");return a}};c.Component=w;c.Fragment=sa;c.Profiler=ua;c.PureComponent=K;c.StrictMode=ta;c.Suspense=ya;c.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=
|
| 26 |
+
t;c.act=ka;c.cloneElement=function(a,b,c){if(null===a||void 0===a)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+a+".");var e=la({},a.props),d=a.key,k=a.ref,h=a._owner;if(null!=b){void 0!==b.ref&&(k=b.ref,h=L.current);void 0!==b.key&&(d=""+b.key);if(a.type&&a.type.defaultProps)var l=a.type.defaultProps;for(f in b)aa.call(b,f)&&!ba.hasOwnProperty(f)&&(e[f]=void 0===b[f]&&void 0!==l?l[f]:b[f])}var f=arguments.length-2;if(1===f)e.children=c;else if(1<f){l=
|
| 27 |
+
Array(f);for(var g=0;g<f;g++)l[g]=arguments[g+2];e.children=l}return{$$typeof:y,type:a.type,key:d,ref:k,props:e,_owner:h}};c.createContext=function(a){a={$$typeof:wa,_currentValue:a,_currentValue2:a,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null};a.Provider={$$typeof:va,_context:a};return a.Consumer=a};c.createElement=Z;c.createFactory=function(a){var b=Z.bind(null,a);b.type=a;return b};c.createRef=function(){return{current:null}};c.forwardRef=function(a){return{$$typeof:xa,
|
| 28 |
+
render:a}};c.isValidElement=M;c.lazy=function(a){return{$$typeof:Aa,_payload:{_status:-1,_result:a},_init:ra}};c.memo=function(a,b){return{$$typeof:za,type:a,compare:void 0===b?null:b}};c.startTransition=function(a,b){b=J.transition;J.transition={};try{a()}finally{J.transition=b}};c.unstable_act=ka;c.useCallback=function(a,b){return g.current.useCallback(a,b)};c.useContext=function(a){return g.current.useContext(a)};c.useDebugValue=function(a,b){};c.useDeferredValue=function(a){return g.current.useDeferredValue(a)};
|
| 29 |
+
c.useEffect=function(a,b){return g.current.useEffect(a,b)};c.useId=function(){return g.current.useId()};c.useImperativeHandle=function(a,b,c){return g.current.useImperativeHandle(a,b,c)};c.useInsertionEffect=function(a,b){return g.current.useInsertionEffect(a,b)};c.useLayoutEffect=function(a,b){return g.current.useLayoutEffect(a,b)};c.useMemo=function(a,b){return g.current.useMemo(a,b)};c.useReducer=function(a,b,c){return g.current.useReducer(a,b,c)};c.useRef=function(a){return g.current.useRef(a)};
|
| 30 |
+
c.useState=function(a){return g.current.useState(a)};c.useSyncExternalStore=function(a,b,c){return g.current.useSyncExternalStore(a,b,c)};c.useTransition=function(){return g.current.useTransition()};c.version="18.3.1"});
|
| 31 |
+
})();
|