/**
* The three page-level components, rendered at build time.
*
* Each was a Vue single-file component. What they mostly were is a template over a copy
* table — `v-for` across `home-copy.ts` and `demo-copy.ts`, both of which are plain data
* and stay exactly where they are. A template over static data does not need a framework
* or a runtime; it needs to be run once, at build time, which is what happens here.
*
* The behaviour that *is* real — clipboard, theme selection, the
* glass sliders, icon copy — moves to `client/home.ts` as progressive enhancement. So the
* markup is in the server-rendered HTML, indexable and correct with no JavaScript, and
* the script only adds motion and interaction on top.
*
* Markdown pages write `` and the engine's component hook matches it as
* an html token, so the tag stays ordinary markup and the page stays readable as prose.
*/
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { homeCopy } from './langs/home-copy.ts';
import { renderPackageFacts } from './package-facts.ts';
import { renderDesignIllustrations } from './design-illustrations.ts';
import { demoCopy } from './langs/demo-copy.ts';
import { localeHref } from './langs/locales.ts';
import type { LocaleDef } from './config.ts';
import { currentLinkBase, currentLocale } from './render-context.ts';
import { resolveLinkFrom } from './links.ts';
import { publicUrl } from './urls.ts';
import { designSectionLink } from './design-reference.ts';
import { GLASS_MATERIALS } from 'ranui/glass';
const DESIGN_DIR = join(dirname(fileURLToPath(import.meta.url)), '..', '..', '..', 'design');
/** The guide sections the home example demonstrates. */
const EXAMPLE_SECTIONS = ['Interaction', 'Words'] as const;
/** The component hooks the markdown renderer is configured with. */
export const componentRenderers = {
HomeCinematic: () => renderHome(currentLocale()),
PackageFacts: (attrs: string) => renderPackageFacts(attrs),
GlassPlayground: () => renderGlassPlayground(currentLocale()),
IconGallery: () => renderIconGallery(currentLocale()),
Loading: () => renderLoadingGallery(),
DesignIllustrations: () => renderDesignIllustrations(currentLocale()),
};
export const resolveCurrentLink = (href: string): string => resolveLinkFrom(currentLinkBase())(href);
const esc = (s: string): string =>
s.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');
const ICONS: Record = {
ui: '',
utils:
'',
article:
'',
bridge:
'',
gpu: '',
vdom: '',
totp: '',
mime: '',
player:
'',
droplet:
'',
radar:
'',
sigma:
'',
scratch:
'',
};
const icon = (kind: string): string => ICONS[kind] ?? '';
const ARROW =
'';
const ARROW_SM = ARROW.replace(/width="18" height="18"/, 'width="15" height="15"');
const COPY_ICON =
'' +
'';
/**
* The install snippet and the two code cells are written out rather than highlighted.
* They are four lines of illustrative markup, not source anyone runs, and shipping shiki
* across every home page to colour them would cost more than they are worth.
*/
const SNIPPET_INSTALL = `$ npm i ranui ranuts// register the <r-*> elements onceimport'ranui'import { debounce } from'ranuts'`;
const SNIPPET_USE = `<!-- Vue, React, or plain HTML --><r-buttontype="primary">Save</r-button><r-progresspercent="66"></r-progress>`;
export const renderHome = (locale: LocaleDef): string => {
const t = homeCopy(locale.dir);
const href = (path: string): string => publicUrl(localeHref(path, locale));
// Languages that opt out of word splitting — the CJK headlines and Persian — render as
// one segment: word units either do not exist there or are not worth reordering an
// RTL line for.
const words = t.splitWords ? t.headline.split(/\s+/) : [t.headline];
const head = (title: string, id: string): string => `
${esc(title)}
`;
return (
`
` +
// ── 1. positioning: what ran is, one action, the facts, and a working example ──
`
` +
`
` +
// Real spaces between the word boxes, so the heading's text reads as words to crawlers too.
words.map((w) => `${esc(w)}`).join(' ') +
`
` +
// The live panel holds real ranui elements. They are inert until the client bundle
// upgrades them; `home.css` reserves labelled `:not(:defined)` shells (and hides
// light-DOM options) so the card does not flash or jump — same idea as the playground.
// A working example, not a gallery of variants: one small task with every state a
// reader can reach — empty, invalid, sending, sent, failed and retried. The markup
// is complete without script; `client/home.ts` adds the behaviour.
`
` +
`
${esc(t.liveLabel)}
` +
// A group, not a
` +
`
` +
t.stats
.map(
(s) =>
`
${esc(s.label)}
` +
`
${esc(s.num)}
`,
)
.join('') +
`
` +
// ── 2. live proof: what the library looks like, composed into small states ──
`` +
head(t.proofTitle, 'home-proof') +
renderProof(t.proof) +
`` +
// ── 3. choose a pillar ──
`` +
head(t.chooseTitle, 'home-choose') +
`
`
);
};
const PROOF_STEP_STATES = ['success', 'running', 'idle'] as const;
/**
* Three small states composed from real `r-*` elements. Every visible word is light-DOM
* text beside the elements, so with no script the captions, file name and steps still
* read; only the controls themselves wait for the bundle.
*/
const renderProof = (p: ReturnType['proof']): string =>
`
` +
`${esc(p.states[0])}` +
`
quarterly-report.pdf64%
` +
`` +
// A specimen, not a control: the button shows how ranui renders it but takes no focus.
`${esc(p.cancel)}` +
`${esc(p.states[1])}` +
`` +
p.steps
.map(
(step, i) =>
`
` +
`` +
// The same clear glass as the playground: default tint, no rim, so the backdrop it bends
// stays visible. Nothing here loops. The label carries its own backing (home.css), so the
// pane does not have to be milked over to keep it readable.
`${esc(p.glass)}` +
`
` +
`<r-glass>
` +
`` +
`
`;
// ── Glass playground ────────────────────────────────────────────────────────
/** Geometry the stage starts with; everything optical comes from the `regular` material. */
const GLASS_START = { width: 340, radius: 28 } as const;
const GLASS_OPTICS = [
{ key: 'blur', min: 0, max: 40, step: 1, unit: 'px' },
{ key: 'saturate', min: 100, max: 260, step: 5, unit: '%' },
{ key: 'displace', min: 0, max: 120, step: 1, unit: 'px' },
{ key: 'bevel', min: 4, max: 80, step: 1, unit: 'px' },
{ key: 'dispersion', min: 0, max: 100, step: 5, unit: '%' },
] as const;
const GLASS_SHAPE = [
{ key: 'radius', min: 0, max: 60, step: 1, unit: 'px' },
{ key: 'width', min: 200, max: 520, step: 10, unit: 'px' },
{ key: 'specular', min: 0, max: 200, step: 5, unit: '%' },
] as const;
const GLASS_SCENES = ['aurora', 'paper', 'grid'] as const;
type Slider = { key: string; min: number; max: number; step: number; unit: string };
/**
* A range control drawn as a field: label left, value right, the filled part shows the value.
* The value text is hidden from assistive technology: the range announces its own value,
* and inside the label it would become part of the name ("blur16px").
*/
const rangeField = (s: Slider, value: number): string => {
const fill = ((value - s.min) / (s.max - s.min)) * 100;
return (
``
);
};
const selectField = (key: string, options: readonly string[], value: string): string =>
``;
const switchField = (key: string): string =>
``;
const group = (legend: string, body: string): string =>
``;
/**
* Control labels are attribute names, so they are not translated. The rule the docs
* follow: only chrome a reader is *told* in their own language gets translated, and
* `blur` is the name of a `` attribute, not prose. The group headings and the
* backdrop pictures' names are prose and are translated.
*/
export const renderGlassPlayground = (locale: LocaleDef): string => {
const t = demoCopy(locale.dir).glass;
const m = GLASS_MATERIALS.regular;
const code = `\n …\n`;
const scene = (name: (typeof GLASS_SCENES)[number], index: number): string =>
``;
return (
`
` +
`
` +
`` +
// The element is in the markup with its defaults already applied, so a reader with
// no JavaScript still sees the effect — just not the controls moving it.
`` +
`
`
);
};
// ── Icon gallery ────────────────────────────────────────────────────────────
/** The showcase set, all registered by `theme/register-icons.ts`. */
const GALLERY_ICONS = [
'add-user',
'book',
'check-circle',
'close-circle',
'eye-close',
'eye',
'info-circle',
'loading',
'lock',
'message',
'power-off',
'setting',
'team',
'unlock',
'user',
'more',
'plus',
'search',
'menu',
'sort',
] as const;
/**
* Rendered at build time rather than upgraded from an empty element, which keeps all
* twenty cells in the server-rendered HTML. Turning this into a client-side component
* would have traded that away for nothing — the grid is a constant list.
*/
export const renderIconGallery = (locale: LocaleDef): string => {
const t = demoCopy(locale.dir).icons;
return (
`