Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

chore(cli): remove unused XLE/XLO playground dev tool (#3206)

Cindy Zhang595445cf615e
diff --git a/packages/cli/playground/index.html b/packages/cli/playground/index.html
deleted file mode 100644
index 1d1740dced..0000000000
--- a/packages/cli/playground/index.html
+++ /dev/null
@@ -1,286 +0,0 @@
-<!doctype html>
-<!-- Copyright (c) Meta Platforms, Inc. and affiliates. -->
-<html lang="en">
-<head>
-<meta charset="utf-8" />
-<meta name="viewport" content="width=device-width, initial-scale=1" />
-<title>XLE / XLO playground</title>
-<style>
- :root { color-scheme: light dark; --bg:#fff; --fg:#1c1e21; --muted:#65676b; --line:#dadde1; --panel:#f5f6f7; --ok:#1a7f37; --err:#cf222e; --warn:#9a6700; --accent:#0866ff; }
- @media (prefers-color-scheme: dark) { :root { --bg:#18191a; --fg:#e4e6eb; --muted:#b0b3b8; --line:#3a3b3c; --panel:#242526; --accent:#4b9bff; } }
- * { box-sizing: border-box; }
- body { margin:0; font:14px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif; background:var(--bg); color:var(--fg); }
- header { padding:14px 20px; border-bottom:1px solid var(--line); display:flex; align-items:baseline; gap:12px; }
- header h1 { font-size:16px; margin:0; }
- header span { color:var(--muted); font-size:12px; }
- main { display:grid; grid-template-columns:1fr 1fr; gap:0; height:calc(100vh - 53px); }
- .col { display:flex; flex-direction:column; min-width:0; }
- .col + .col { border-left:1px solid var(--line); }
- .bar { padding:10px 16px; border-bottom:1px solid var(--line); display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
- .bar label { font-size:12px; color:var(--muted); }
- select, button { font:inherit; padding:4px 10px; border-radius:6px; border:1px solid var(--line); background:var(--panel); color:var(--fg); cursor:pointer; }
- button.primary { background:var(--accent); color:#fff; border-color:transparent; }
- button:disabled { opacity:.5; cursor:not-allowed; }
- textarea { flex:0 0 200px; resize:vertical; border:0; border-bottom:1px solid var(--line); padding:14px 16px; font:13px/1.6 ui-monospace,SFMono-Regular,Menlo,monospace; background:var(--bg); color:var(--fg); outline:none; tab-size:2; }
- .status { padding:8px 16px; font-size:12px; display:flex; gap:8px; align-items:center; border-bottom:1px solid var(--line); }
- .pill { padding:2px 8px; border-radius:999px; font-weight:600; font-size:11px; }
- .pill.ok { background:color-mix(in srgb,var(--ok) 18%,transparent); color:var(--ok); }
- .pill.err { background:color-mix(in srgb,var(--err) 18%,transparent); color:var(--err); }
- .pill.warn { background:color-mix(in srgb,var(--warn) 20%,transparent); color:var(--warn); }
- .scroll { flex:1; overflow:auto; }
- pre { margin:0; padding:14px 16px; font:12px/1.55 ui-monospace,SFMono-Regular,Menlo,monospace; white-space:pre; }
- .err-list { padding:10px 16px; }
- .err-row { color:var(--err); font:12px/1.5 ui-monospace,monospace; padding:4px 0; border-bottom:1px dashed var(--line); }
- .err-row b { color:var(--accent); font-weight:600; }
- .section-label { padding:8px 16px 2px; font-size:11px; text-transform:uppercase; letter-spacing:.04em; color:var(--muted); border-top:1px solid var(--line); }
- .metrics { display:flex; gap:8px; padding:8px 16px; border-bottom:1px solid var(--line); }
- .metric { flex:1; border:1px solid var(--line); border-radius:6px; padding:6px 8px; background:var(--panel); }
- .metric .m-label { font-size:11px; color:var(--muted); }
- .metric .m-val { font-size:15px; font-weight:600; font-variant-numeric:tabular-nums; }
- .metric .m-sub { font-size:11px; color:var(--muted); }
- .ex-head { display:flex; align-items:center; gap:8px; padding:8px 16px 4px; }
- .ex-head .section-label { border:0; padding:0; flex-shrink:0; }
- .search { flex:1; padding:4px 8px; border:1px solid var(--line); border-radius:6px; background:var(--bg); color:var(--fg); font:inherit; font-size:12px; }
- .browser { margin:0 16px 10px; border:1px solid var(--line); border-radius:6px; max-height:260px; overflow-y:auto; }
- .ex-cat { position:sticky; top:0; background:var(--panel); padding:3px 10px; font-size:10px; text-transform:uppercase; letter-spacing:.05em; color:var(--muted); border-bottom:1px solid var(--line); }
- .ex-item { display:flex; justify-content:space-between; align-items:center; gap:8px; width:100%; text-align:left; border:0; border-bottom:1px solid var(--line); background:transparent; color:var(--fg); cursor:pointer; padding:5px 10px; }
- .ex-item:hover { background:var(--panel); }
- .ex-item.active { background:color-mix(in srgb,var(--accent) 14%,transparent); }
- .ex-item .ex-label { font-size:12px; font-weight:600; }
- .ex-item .ex-expr { font-family:ui-monospace,monospace; font-size:10px; color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
- .ex-item .ex-tok { flex-shrink:0; font-size:10px; color:var(--muted); font-variant-numeric:tabular-nums; }
- .ex-col { min-width:0; display:flex; flex-direction:column; }
-</style>
-</head>
-<body>
-<header>
- <h1>XLE / XLO playground</h1>
- <span>compressed layout expressions → validated XDS TSX · standalone (no build)</span>
-</header>
-<main>
- <div class="col">
- <div class="bar">
- <label for="surface">Surface</label>
- <select id="surface">
- <option value="auto">Auto</option>
- <option value="compact">Compact (XLE)</option>
- <option value="outline">Outline (XLO)</option>
- </select>
- <button id="expand" class="primary">Expand →</button>
- </div>
- <textarea id="src" spellcheck="false"></textarea>
- <div class="status" id="status"><span class="pill warn">loading…</span></div>
- <div class="metrics" id="metrics"></div>
- <div class="err-list" id="errors"></div>
- <div class="ex-head">
- <span class="section-label">Examples</span>
- <input id="search" class="search" type="search" placeholder="Search examples…" />
- </div>
- <div class="browser" id="examples"></div>
- <div class="section-label">Canonical compact</div>
- <div class="scroll"><pre id="compact"></pre></div>
- <div class="section-label">Canonical outline</div>
- <div class="scroll"><pre id="outline"></pre></div>
- </div>
- <div class="col">
- <div class="bar"><label>Expanded TSX</label></div>
- <div class="scroll"><pre id="code">Press “Expand →”.</pre></div>
- </div>
-</main>
-
-<script type="module">
-import {checkExpression, expandExpression} from '/xle/browser.mjs';
-
-const EXAMPLES = [
- ["Pages", "Analytics dashboard", "A[cp6 @topNav=TN @sideNav=SN] > L > LC > V[g6] > (H[j=between a=center] > Hd\"Analytics\"[level=2] + (H[g2] > B\"Export\" + B.primary\"New report\")) + (G[c4 g4] > (C[p6] > V[g1] > Tx.lg\"\\$42k\" + Tx[t=supporting]\"Revenue\")*4) + (G[c{min:340} g4] > C{card-callout} + C{card-callout}) + (C[p0] > T[striped] > (TR>THC\"Order\"+THC\"Customer\"+THC\"Status\"+THC\"Total\") + (TR>TC\"#10$\"+TC\"Acme Inc\"+(TC>Bd.success\"Paid\")+TC\"\\$120\")*5)"],
- ["Pages", "Settings page", "A[cp6 @topNav=TN @sideNav=SN] > L > LC > S[p6] > V[g6] > Hd\"Settings\"[level=2] + (C[p6] > V[g4] > Hd\"Profile\"[level=4] + (F > TI\"Name\"[req] + TI\"Email\"[t=email req]) + B.primary\"Save\") + (C[p6] > V[g4] > Hd\"Notifications\"[level=4] + (H[j=between a=center] > Tx\"Email alerts\" + SW\"Email alerts\") + (H[j=between a=center] > Tx\"Push\" + SW\"Push\"))"],
- ["Pages", "Order detail", "A[cp6 @topNav=TN] > L > LC > V[g6] > (H[j=between a=center] > (V[g1] > Hd\"Order #1042\"[level=2] + Tx[t=supporting]\"Created today\") + Bd.success\"Paid\") + (G[c{min:280} g6] > (C[p6] > V[g4] > Hd\"Items\"[level=4] + (T > (TR>THC\"Item\"+THC\"Qty\") + (TR>TC\"Widget\"+TC\"2\")*3)) + (C[p6] > V[g3] > Hd\"Customer\"[level=4] + (ML > MLI\"Name\":\"Acme\" + MLI\"Email\":\"[email protected]\" + MLI\"Plan\":\"Pro\")))"],
- ["Pages", "Users table page", "A[cp6 @topNav=TN @sideNav=SN] > L > LC > V[g4] > (Tbar\"Users\" > B\"Filter\" + B\"Export\" + B.primary\"Invite\") + (C[p0] > T[striped] > (TR>THC\"Name\"+THC\"Role\"+THC\"Status\") + (TR>TC\"Person $\"+TC\"Engineer\"+(TC>Bd.success\"Active\"))*8) + (H[j=end] > PG[variant=count])"],
- ["Pages", "Pricing page", "S[p8] > V[g8] > (Ctr > V[g2] > Hd\"Pricing\"[level=1] + Tx[t=supporting]\"Pick a plan that fits\") + (G[c3 g6] > (C[p6] > V[g4] > Hd\"Pro\"[level=3] + Tx.lg\"\\$29/mo\" + (UL > LI\"Feature one\" + LI\"Feature two\" + LI\"Feature three\") + B.primary\"Choose Pro\")*3)"],
- ["Pages", "Login split", "G[c2 h=\"100dvh\"] > (S[p8 v=muted] > Ctr > V[g2] > Hd\"Acme\"[level=1] + Tx[t=supporting]\"Welcome back\") + (Ctr > C[w=360 p8] > V[g6] > (F > TI\"Email\"[t=email req] + TI\"Password\"[t=password req]) + (H[j=between a=center] > CB\"Remember me\" + Lk[href=\"/forgot\"]\"Forgot?\") + B.primary\"Sign in\")"],
- ["Pages", "Profile header", "C[p6] > H[j=between a=center] > (H[g4 a=center] > Av + (V[g1] > Hd\"Jane Doe\"[level=3] + Tx[t=supporting]\"Product Designer\")) + (H[g2] > B\"Message\" + B.primary\"Follow\")"],
- ["Pages", "Kanban board", "G[c3 g4] > (C[p4] > V[g3] > (H[j=between a=center] > Hd\"To Do\"[level=5] + Bd\"3\") + (V[g2] > (C[p3] > Tx\"Task item\")*3))*3"],
- ["Pages", "Dashboard with sidebar nav", "A[cp0 @sideNav=(SN > (SNS\"Main\" > SNI\"Dashboard\" + SNI\"Reports\" + SNI\"Settings\"))] > L > LC > S[p6] > V[g6] > Hd\"Dashboard\"[level=2] + (G[c4 g4] > (C[p6] > V[g1] > Tx.lg\"128\" + Tx[t=supporting]\"Metric\")*4)"],
- ["Pages", "Feed with composer", "Ctr > C[w=560 p0] > V > (C[p4] > V[g3] > (H[g2 a=center] > Av + Tx\"Share an update\") + (H[j=end] > B.primary\"Post\")) + D + (V[g0] > (C[p4] > V[g2] > (H[g2 a=center] > Av + (V[g0.5] > Tx\"User $\" + Tx[t=supporting]\"2h ago\")) + Tx\"A post body goes here.\")*3)"],
- ["Pages", "Two-column form", "A[cp6 @topNav=TN] > L > LC > S[p6] > C[p6] > V[g4] > Hd\"New employee\"[level=3] + (G[c2 g4] > TI\"First name\"[req] + TI\"Last name\"[req] + TI\"Email\"[t=email req] + TI\"Phone\" + (RL\"Department\" > RLI\"Engineering\" + RLI\"Design\") + (CL\"Access\" > CLI\"Admin\" + CLI\"Billing\")) + (H[j=end g2] > B\"Cancel\" + B.primary\"Create\")"],
- ["Pages", "Stats + chart + activity", "V[g6] > (G[c3 g4] > (C[p6] > V[g1] > Tx.lg\"\\$12k\" + Tx[t=supporting]\"This week\")*3) + (G[c{min:320} g6] > C{card-callout} + (C[p6] > V[g3] > Hd\"Recent activity\"[level=4] + (UL > LI\"Event one\" + LI\"Event two\" + LI\"Event three\")))"],
- ["Pages", "Confirm dialog flow", "V[g4] > (Tbar\"Document\" > B\"Share\" + B.destructive\"Delete\"[opens=#del]) + (C[p6] > Tx\"Document body content\") ;; AD#del\"Delete this document?\""],
- ["Pages", "Outline settings (XLO)", "AppShell cp=6\n topNav: TN\n sideNav: SN\n Layout > LayoutContent\n Section p=6\n VStack g=6\n Heading \"Settings\" level=2\n Card p=6\n VStack g=4\n Heading \"Profile\" level=4\n FormLayout\n TextInput \"Name\" req\n TextInput \"Email\" t=email req\n Button.primary \"Save\"\n Card p=6\n VStack g=4\n Heading \"Danger zone\" level=4\n Button.destructive \"Delete account\" opens=#del\n\noverlays:\n AlertDialog#del \"Delete your account?\""],
- ["Pages", "Outline product page (XLO)", "Section p=8\n Grid c={min:320} g=8\n Card p=0\n Center h=240\n Text t=supporting \"Image\"\n VStack g=4\n Heading \"Product name\" level=1\n Text.lg \"\\$129\"\n Text t=supporting \"A short product description goes here.\"\n HStack g=2\n Button.primary \"Add to cart\"\n Button \"Save\""],
- ["Layout", "Centered box", "Ctr[h=\"100dvh\"] > C[w=400 p8] > Tx\"Hello world\""],
- ["Layout", "App shell", "A[cp6 @topNav=TN @sideNav=SN] > L > LC > S[p6] > Tx\"Page content\""],
- ["Layout", "App shell + header", "A[cp4 @topNav=TN] > L > LH\"Page header\" + LC > S[p4] > Tx\"Body\""],
- ["Layout", "Vertical stack", "V[g4] > Tx\"One\" + Tx\"Two\" + Tx\"Three\""],
- ["Layout", "Spread row", "H[j=between a=center] > Tx.lg\"Title\" + B.primary\"Action\""],
- ["Layout", "Grid 4-up", "G[c4 g4] > C[p6]*4"],
- ["Layout", "Responsive grid", "G[c{min:320} g4] > C{card-callout}*3"],
- ["Layout", "Section muted", "S[p6 v=muted] > Tx\"Muted section\""],
- ["Layout", "Nested stacks", "V[g6] > (H[j=between] > Tx.lg\"Header\" + B\"Edit\") + (G[c3 g4] > C[p4]*3)"],
- ["Layout", "Layout regions", "L > LH\"Header\" + LC > S[p4] > Tx\"Body\""],
- ["Layout", "Divider between", "V[g4] > Tx\"Above\" + D + Tx\"Below\""],
- ["Layout", "Fill stack item", "H[g4] > Tx\"Fixed\" + (SI[size=fill] > Tx\"Grows\")"],
- ["Layout", "Toolbar + content", "V[g4] > (Tbar\"Actions\" > B\"Filter\" + B.primary\"New\") + S[p4] > Tx\"Below toolbar\""],
- ["Cards", "Titled card", "C[p6] > V[g2] > Hd\"Card title\"[level=3] + Tx[t=supporting]\"Supporting copy\""],
- ["Cards", "KPI tile", "C[p6] > V[g1] > Tx.lg\"1,284\" + Tx[t=supporting]\"Active users\""],
- ["Cards", "KPI grid", "G[c4 g4] > (C[p6] > V[g1] > Tx.lg\"\\$42k\" + Tx[t=supporting]\"Revenue\")*4"],
- ["Cards", "Clickable card", "CC[p6] > H[j=between a=center] > Tx\"Open project\" + Ic[icon=arrow-right]"],
- ["Cards", "Card grid", "G[c3 g4] > (C[p6] > V[g2] > Hd\"A\"[level=4] + Tx\"text\")*3"],
- ["Cards", "Callout block", "S[p6] > C{card-callout}"],
- ["Cards", "Badge row", "H[g2] > Bd.success\"Active\" + Bd.warning\"Pending\" + Bd.error\"Failed\" + Bd.info\"New\""],
- ["Cards", "Avatar row", "H[g2 a=center] > Av + (V[g0.5] > Tx\"Jane Doe\" + Tx[t=supporting]\"Admin\")"],
- ["Cards", "Metadata list", "C[p6] > ML > MLI\"Status\":\"Active\" + MLI\"Owner\":\"Jane\" + MLI\"Region\":\"us-east\""],
- ["Content", "List", "UL > LI\"First item\" + LI\"Second item\" + LI\"Third item\""],
- ["Content", "Kbd hint", "H[g2 a=center] > Tx\"Press\" + K\"mod+k\" + Tx\"to search\""],
- ["Content", "Headings scale", "V[g3] > Hd\"H1\"[level=1] + Hd\"H2\"[level=2] + Hd\"H3\"[level=3]"],
- ["Content", "Text + link", "H[g1] > Tx\"Read\" + Lk[href=\"/docs\"]\"the docs\""],
- ["Content", "Tokens", "H[g2] > Tk\"react\" + Tk\"typescript\" + Tk\"stylex\""],
- ["Tables", "Simple table", "C[p0] > T[striped] > (TR > THC\"Name\" + THC\"Email\") + (TR > TC\"Alice\" + TC\"[email protected]\")*5"],
- ["Tables", "Table + status cell", "T > (TR > THC\"Service\" + THC\"Status\") + (TR > TC\"api-gateway\" + (TC > Bd.success\"Up\"))*4"],
- ["Tables", "Dense table", "T[density=compact dividers=rows] > (TR > THC\"ID\" + THC\"Value\") + (TR > TC\"row-$\" + TC\"\\$12.00\")*6"],
- ["Tables", "Table in card", "C[p0] > T[striped] > (TR>THC\"Item\"+THC\"Qty\") + (TR>TC\"Widget\"+TC\"3\")*3"],
- ["Forms", "Login form", "Ctr[h=\"100dvh\"] > C[w=400 p8] > V[g6] > (F > TI\"Email\"[t=email req] + TI\"Password\"[t=password req]) + B.primary\"Sign in\""],
- ["Forms", "Field set", "F > TI\"Full name\"[req] + TI\"Email\"[t=email req] + TA\"Bio\" + B.primary\"Save\""],
- ["Forms", "Inline controls", "H[j=between a=center] > CB\"Remember me\" + Lk[href=\"/forgot\"]\"Forgot password?\""],
- ["Forms", "Number + switch", "V[g4] > NI\"Quantity\" + (H[j=between a=center] > Tx\"Notifications\" + SW\"Enable notifications\")"],
- ["Forms", "Two column form", "G[c2 g4] > TI\"First name\"[req] + TI\"Last name\"[req] + TI\"Email\"[t=email req] + TI\"Phone\""],
- ["Forms", "Checkbox list", "CL\"Permissions\" > CLI\"Read\" + CLI\"Write\" + CLI\"Admin\""],
- ["Forms", "Radio list", "RL\"Plan\" > RLI\"Free\" + RLI\"Pro\" + RLI\"Enterprise\""],
- ["Forms", "Slider", "V[g4] > SL\"Volume\" + SL\"Brightness\""],
- ["Forms", "Date input", "F > DI\"Start date\" + DI\"End date\""],
- ["Forms", "Search field", "TI\"Search\"[t=text]"],
- ["Nav", "Tabs", "TL > Tab\"Overview\"! + Tab\"Activity\" + Tab\"Settings\""],
- ["Nav", "Breadcrumbs", "BC > BCI\"Home\"[href=\"/\"] + BCI\"Projects\"[href=\"/projects\"] + BCI\"Detail\""],
- ["Nav", "Segmented control", "SG > SGI\"Day\" + SGI\"Week\" + SGI\"Month\""],
- ["Nav", "Top nav", "TN > TNH\"Acme\" + TNI\"Docs\" + TNI\"Pricing\""],
- ["Nav", "Side nav", "SN > (SNS\"Main\" > SNI\"Dashboard\" + SNI\"Reports\") + (SNS\"Settings\" > SNI\"Profile\")"],
- ["Nav", "Pagination", "PG[variant=count]"],
- ["Nav", "Tabs + content", "V[g4] > (TL > Tab\"All\"! + Tab\"Active\") + S[p4] > Tx\"Tab body\""],
- ["Feedback", "Success banner", "Bn.success\"Changes saved successfully\""],
- ["Feedback", "Empty state", "ES\"No results found\"[description=\"Try adjusting your filters\"]"],
- ["Feedback", "Spinner", "Ctr[h=200] > Sp"],
- ["Feedback", "Progress bar", "V[g4] > PB[value=60] + PB[value=90]"],
- ["Feedback", "Skeletons", "V[g2] > Sk*4"],
- ["Feedback", "Delete dialog", "V > B.destructive\"Delete\"[opens=#confirm] ;; AD#confirm\"Delete this item?\""],
- ["Feedback", "Status dots", "V[g2] > (H[g2 a=center] > SD.success + Tx\"Operational\") + (H[g2 a=center] > SD.error + Tx\"Outage\")"],
- ["Feedback", "Toolbar actions", "Tbar\"Actions\" > B\"Filter\" + B\"Export\" + B.primary\"New\""],
- ["Blocks", "Splice block", "S[p6] > C{card-callout}"],
- ["Blocks", "Block grid", "G[c2 g4] > {card-callout}*2"],
- ["Blocks", "Standalone block", "{card-callout}"],
- ["Outline", "Outline app shell", "AppShell cp=6\n topNav: TN\n Layout > LayoutContent\n Section p=6\n Grid cols=4 gap=4\n Card p=6 x4"],
- ["Outline", "Outline form", "Center h=\"100dvh\"\n Card w=400 p=8\n VStack g=6\n FormLayout\n TextInput \"Email\" t=email req\n TextInput \"Password\" t=password req\n Button.primary \"Sign in\""],
- ["Outline", "Outline dashboard", "Section p=6\n VStack g=6\n HStack j=between a=center\n Heading \"Dashboard\" level=2\n Button.primary \"New\"\n Grid c=4 g=4\n Card {card-callout} x4"],
- ["Outline", "Outline table", "Card p=0\n Table striped\n TableRow\n TableHeaderCell \"Name\"\n TableHeaderCell \"Role\"\n repeat 4:\n TableRow\n TableCell \"Person\"\n TableCell \"Engineer\""],
- ["Outline", "Outline with overlay", "VStack g=4\n Button.destructive \"Delete\" opens=#confirm\n\noverlays:\n AlertDialog#confirm \"Delete this item?\""],
- ["Outline", "Outline tabs", "VStack g=4\n TabList\n Tab \"Overview\" !\n Tab \"Activity\"\n Tab \"Settings\"\n Section p=4\n Text \"Tab content\""],
- ["Chat", "Chat layout", "ChL > ChML > ChS\"Today\" + (ChM > ChB\"Hello there\") + (ChM > ChB\"Hi, how can I help?\")"],
-];
-
-const $ = id => document.getElementById(id);
-const data = await fetch('/registry.json').then(r => r.json());
-const REG = data.registry, BLOCKS = data.blocks;
-
-const escapeHtml = s => String(s).replace(/[&<>]/g, c => ({'&':'&amp;','<':'&lt;','>':'&gt;'}[c]));
-
-// Tokenization is fully client-side: import the bundled tokenizer module the
-// server emits (gpt-tokenizer o200k_base, esbuild-bundled; heuristic fallback).
-const {countTokens: tok, ENCODER} = await import('/vendor/tokenizer.mjs');
-
-function metricsHtml(inTok, inChars, outTok, outChars) {
- const ratio = inTok > 0 && outTok > 0 ? (outTok / inTok).toFixed(1) + '×' : '—';
- const cell = (label, val, sub) =>
- `<div class="metric"><div class="m-label">${label}</div><div class="m-val">${val}</div><div class="m-sub">${sub}</div></div>`;
- return cell('XLE input · ' + ENCODER, inTok + ' tok', inChars + ' chars') +
- cell('Output TSX · ' + ENCODER, outTok ? outTok + ' tok' : '—', outChars ? outChars + ' chars' : '—') +
- cell('Expansion', ratio, 'output ÷ input');
-}
-
-function paintMetrics(expr, code) {
- $('metrics').innerHTML = metricsHtml(tok(expr), expr.length, code ? tok(code) : 0, code ? code.length : 0);
-}
-
-function render() {
- const expr = $('src').value;
- // Always auto-detect: a compact expression never "fails" under an Outline view.
- const r = checkExpression(expr, REG, {blocks: BLOCKS, form: 'auto'});
- const status = $('status'), errors = $('errors');
- status.innerHTML = '';
- errors.innerHTML = '';
- if (r.ok && r.valid) {
- status.innerHTML = `<span class="pill ok">Valid · ${r.form}</span>` +
- (r.warnings.length ? `<span class="pill warn">${r.warnings.length} warning</span>` : '');
- $('compact').textContent = r.compact;
- $('outline').textContent = r.outline;
- $('expand').disabled = false;
- const code = doExpand(); // live "rendered source"
- paintMetrics(expr, code);
- } else {
- status.innerHTML = `<span class="pill err">${r.errors.length} error${r.errors.length===1?'':'s'}</span>`;
- errors.innerHTML = r.errors.map(e =>
- `<div class="err-row">${escapeHtml(e.formatted)}${e.suggestions?.length ? ` <b>→ ${escapeHtml(e.suggestions.join(', '))}</b>` : ''}</div>`
- ).join('');
- $('compact').textContent = '';
- $('outline').textContent = '';
- $('code').textContent = '';
- $('expand').disabled = true;
- paintMetrics(expr, '');
- }
-}
-
-function doExpand() {
- const r = expandExpression($('src').value, REG, {blocks: BLOCKS, form: 'auto', name: 'PlaygroundLayout'});
- const code = r.ok ? r.code : r.errors.map(e => e.formatted).join('\n');
- $('code').textContent = code;
- return r.ok ? code : '';
-}
-
-// Switching surface converts the current expression to that dialect.
-function switchSurface() {
- const v = $('surface').value;
- if (v !== 'auto') {
- const c = checkExpression($('src').value, REG, {blocks: BLOCKS, form: 'auto'});
- if (c.ok && c.valid) $('src').value = v === 'compact' ? c.compact : c.outline;
- }
- render();
-}
-
-// Searchable, categorized example browser.
-let activeLabel = EXAMPLES[0][1];
-function renderBrowser(query) {
- const q = (query || '').trim().toLowerCase();
- const match = ([cat, label, expr]) =>
- !q || label.toLowerCase().includes(q) || cat.toLowerCase().includes(q) || expr.toLowerCase().includes(q);
- const cats = [...new Set(EXAMPLES.map(e => e[0]))];
- let html = '';
- for (const cat of cats) {
- const rows = EXAMPLES.map((e, i) => [e, i]).filter(([e]) => e[0] === cat && match(e));
- if (!rows.length) continue;
- html += `<div class="ex-cat">${escapeHtml(cat)}</div>`;
- for (const [e, i] of rows) {
- const active = e[1] === activeLabel ? ' active' : '';
- html += `<button class="ex-item${active}" data-i="${i}"><span class="ex-col"><span class="ex-label">${escapeHtml(e[1])}</span><span class="ex-expr">${escapeHtml(e[2].replace(/\n/g, ' ⏎ '))}</span></span><span class="ex-tok">${tok(e[2])} tok</span></button>`;
- }
- }
- $('examples').innerHTML = html || '<div class="ex-cat">No matches</div>';
-}
-
-$('examples').addEventListener('click', e => {
- const btn = e.target.closest('.ex-item');
- if (!btn) return;
- const ex = EXAMPLES[btn.dataset.i];
- activeLabel = ex[1];
- $('src').value = ex[2];
- $('surface').value = 'auto'; // examples carry their own surface
- render();
- renderBrowser($('search').value);
-});
-$('search').addEventListener('input', e => renderBrowser(e.target.value));
-$('src').addEventListener('input', render);
-$('surface').addEventListener('change', switchSurface);
-$('expand').addEventListener('click', doExpand);
-
-renderBrowser('');
-$('src').value = EXAMPLES[0][2];
-render();
-</script>
-</body>
-</html>
diff --git a/packages/cli/playground/serve.mjs b/packages/cli/playground/serve.mjs
deleted file mode 100644
index 302b6a26a2..0000000000
--- a/packages/cli/playground/serve.mjs
+++ /dev/null
@@ -1,129 +0,0 @@
-#!/usr/bin/env node
-// Copyright (c) Meta Platforms, Inc. and affiliates.
-
-/**
- * Standalone, zero-dependency XLE/XLO playground.
- *
- * The docsite playground (apps/docsite) is the production home, but it needs
- * the full Next/Monaco/StyleX toolchain. This is a dependency-free way to
- * exercise the layout language in a browser — handy offline, in CI smoke
- * checks, or for a quick demo. It serves the pure browser barrel as native
- * ESM and builds the registry on the fly with the same code the CLI uses, so
- * it never goes stale.
- *
- * node packages/cli/playground/serve.mjs [--port 4321]
- *
- * Routes:
- * GET / the playground page
- * GET /registry.json buildRegistry() + serializeRegistry() + blocks
- * GET /xle/<file>.mjs the pure lib/xle modules + string-utils
- *
- * @position dev tool — no build step; imports lib/xle directly
- */
-
-import {createServer} from 'node:http';
-import {readFileSync} from 'node:fs';
-import {join, dirname} from 'node:path';
-import {fileURLToPath} from 'node:url';
-
-const __dirname = dirname(fileURLToPath(import.meta.url));
-const CLI_SRC = join(__dirname, '..', 'src');
-const REPO = join(__dirname, '..', '..', '..');
-
-const portArg = process.argv.indexOf('--port');
-const PORT = portArg !== -1 ? Number(process.argv[portArg + 1]) : 4321;
-
-const {buildRegistry, serializeRegistry} = await import(join(CLI_SRC, 'lib/xle/registry.mjs'));
-const {discoverTemplates} = await import(join(CLI_SRC, 'api/template.mjs'));
-
-function send(res, status, type, body) {
- res.writeHead(status, {'content-type': type, 'cache-control': 'no-store'});
- res.end(body);
-}
-
-// Tokenization runs CLIENT-SIDE. The browser can't import gpt-tokenizer's
-// package graph directly, so we esbuild-bundle the o200k_base encoding into a
-// single self-contained ESM module the page imports. If esbuild or the
-// package isn't available, we serve a heuristic module so counting still
-// works offline — same module shape either way.
-const HEURISTIC_MODULE =
- "export const ENCODER = 'est.';\n" +
- "export const countTokens = s => (String(s).match(/\\w+|[^\\s\\w]/g) || []).length;\n";
-let tokenizerModule = null;
-async function getTokenizerModule() {
- if (tokenizerModule != null) return tokenizerModule;
- try {
- const esbuild = await import('esbuild');
- const out = await esbuild.build({
- stdin: {
- contents:
- "import {countTokens as c} from 'gpt-tokenizer/encoding/o200k_base';\n" +
- "export const ENCODER = 'o200k_base';\n" +
- "export const countTokens = s => c(String(s));\n",
- resolveDir: REPO,
- loader: 'js',
- },
- bundle: true,
- format: 'esm',
- platform: 'browser',
- write: false,
- legalComments: 'none',
- logLevel: 'silent',
- });
- tokenizerModule = out.outputFiles[0].text;
- } catch {
- tokenizerModule = HEURISTIC_MODULE;
- }
- return tokenizerModule;
-}
-
-const server = createServer(async (req, res) => {
- try {
- const url = new URL(req.url, `http://localhost:${PORT}`);
- const path = url.pathname;
-
- if (path === '/') {
- return send(res, 200, 'text/html; charset=utf-8', readFileSync(join(__dirname, 'index.html')));
- }
-
- if (path === '/registry.json') {
- const registry = await buildRegistry({cwd: REPO});
- let blocks = [];
- try {
- const all = await discoverTemplates(REPO);
- blocks = all.filter(t => t.type === 'block').map(b => ({dirName: b.dirName, description: b.description || ''}));
- } catch {
- /* blocks optional */
- }
- return send(res, 200, 'application/json', JSON.stringify({registry: serializeRegistry(registry), blocks}));
- }
-
- if (path === '/vendor/tokenizer.mjs') {
- return send(res, 200, 'text/javascript; charset=utf-8', await getTokenizerModule());
- }
-
- if (path.startsWith('/xle/')) {
- // Serve the pure language modules (+ levenshtein from lib/) as ESM.
- const file = path.slice('/xle/'.length);
- const abs = file === 'levenshtein.mjs'
- ? join(CLI_SRC, 'lib/levenshtein.mjs')
- : join(CLI_SRC, 'lib/xle', file);
- if (!abs.startsWith(CLI_SRC) || !file.endsWith('.mjs')) {
- return send(res, 403, 'text/plain', 'forbidden');
- }
- // validate.mjs imports '../levenshtein.mjs' — rewrite to a flat /xle path.
- const body = readFileSync(abs, 'utf-8').replace(/from '\.\.\/levenshtein\.mjs'/g, "from './levenshtein.mjs'");
- return send(res, 200, 'text/javascript; charset=utf-8', body);
- }
-
- send(res, 404, 'text/plain', 'not found');
- } catch (e) {
- // Log details server-side; don't leak stack traces to the client.
- console.error('[xle-playground]', e);
- send(res, 500, 'text/plain', 'Internal error — see the server console.');
- }
-});
-
-server.listen(PORT, () => {
- console.log(`XLE/XLO playground → http://localhost:${PORT}`);
-});