commit
e092cb029c
252 files changed
+35037
No files matched your search
@@ -0,0 +1,50 @@
|
||||
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/** The language reference on the home page, rendered from core/reference.ts. */
|
||||
import { el, add } from './dom.js';
|
||||
import { REFERENCE, type RefLanguage, type RefSection } from '#core/common/reference.js';
|
||||
import { SERVICES } from '#core/services/index.js';
|
||||
|
||||
function highlighted(lang: RefLanguage['id'], text: string): HTMLElement {
|
||||
const tok = SERVICES[lang]?.tokenize;
|
||||
const pre = el('pre', { class: 'ref-code' });
|
||||
text.split('\n').forEach((line, i) => {
|
||||
if (i) add(pre, '\n');
|
||||
for (const t of tok ? tok(line) : [{ text: line, cls: '' }]) add(pre, t.cls ? el('span', { class: t.cls }, t.text) : t.text);
|
||||
});
|
||||
return pre;
|
||||
}
|
||||
|
||||
function section(lang: RefLanguage['id'], s: RefSection): HTMLElement {
|
||||
const [c1, c2, c3] = s.columns || ['Term', 'Meaning', ''];
|
||||
const hasThird = s.entries.some((e) => e.example || e.note);
|
||||
const table = el('table', { class: 'ref-table' },
|
||||
el('thead', {}, el('tr', {}, el('th', {}, c1), el('th', {}, c2), hasThird ? el('th', {}, c3 || '') : null)));
|
||||
const tb = el('tbody');
|
||||
for (const e of s.entries) {
|
||||
add(tb, el('tr', {},
|
||||
el('td', { class: 'ref-term' }, el('code', {}, e.term)),
|
||||
el('td', { class: 'ref-meaning' }, e.meaning),
|
||||
hasThird ? el('td', { class: 'ref-extra' }, e.example ? highlighted(lang, e.example) : null, e.note ? el('span', { class: 'muted small' + (e.example ? ' ref-prints' : '') }, e.example ? `prints ${e.note}` : e.note) : null) : null));
|
||||
}
|
||||
add(table, tb);
|
||||
return el('section', { class: 'ref-section', id: s.id }, el('h4', {}, s.title), s.intro ? el('p', { class: 'muted small' }, s.intro) : null, table);
|
||||
}
|
||||
|
||||
export function referenceView(): HTMLElement {
|
||||
const root = el('section', { class: 'reference', id: 'reference' });
|
||||
add(root, el('h2', {}, 'Language reference'), el('p', { class: 'muted' }, 'Everything each pane reads, generated from the same tables the editors use for highlighting and hover help, so the reference and the tool cannot drift apart. Hover any word in an editor to see its entry.'));
|
||||
const nav = el('nav', { class: 'ref-nav', 'aria-label': 'Reference' });
|
||||
for (const L of REFERENCE) add(nav, el('a', { href: `#ref-${L.id}` }, L.title));
|
||||
add(root, nav);
|
||||
for (const L of REFERENCE) {
|
||||
const det = el('details', { class: 'ref-lang', id: `ref-${L.id}` }, el('summary', {}, el('h3', {}, L.title), el('span', { class: 'muted' }, L.blurb)));
|
||||
const body = el('div', { class: 'ref-body' });
|
||||
const toc = el('div', { class: 'ref-toc' }, ...L.sections.map((s) => el('a', { href: `#${s.id}`, onClick: (e: Event) => { e.preventDefault(); det.open = true; document.getElementById(s.id)?.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }, s.title)));
|
||||
add(body, toc);
|
||||
for (const s of L.sections) add(body, section(L.id, s));
|
||||
add(det, body);
|
||||
add(root, det);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
Reference in new issue
Block a user