/** * 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 once import 'ranui' import { debounce } from 'ranuts'`; const SNIPPET_USE = `<!-- Vue, React, or plain HTML --> <r-button type="primary">Save</r-button> <r-progress percent="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(' ') + `

` + `

${esc(t.subtitle)}

` + `
` + // 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
: the request is simulated, and a real form would submit itself // on Enter (its controls are form-associated) and put the email in the URL. `
` + `

${esc(t.example.title)}

` + `` + `` + ['viewer', 'editor', 'admin'] .map((value, i) => `${esc(t.example.roles[i]!)}`) .join('') + `` + `
` + `${esc(t.example.simulate)}` + `${esc(t.example.submit)}` + `
` + `

` + `
` + `
${esc(t.example.rules)}` + EXAMPLE_SECTIONS.map((heading) => { const { link, label } = designSectionLink(DESIGN_DIR, heading, locale); return `${esc(label)}`; }).join('') + `
` + `

${esc(t.liveNote)}

` + `
` + 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') + `` + `` + `
` + // ── 4. capabilities beyond the usual set ── `
` + head(t.capsTitle, 'home-caps') + `
` + t.caps .map( (col) => `
` + `${esc(col.lib)}${esc(col.tag)}
` + `
`, ) .join('') + `
` + // ── 5. install ── `
` + head(t.startTitle, 'home-start') + `

${esc(t.startDesc)}

` + `
npm i ranui ranuts` + `
` + `
` + `
${esc(t.startStep1)}
${SNIPPET_INSTALL}
` + `
${esc(t.startStep2)}
${SNIPPET_USE}
` + `
` ); }; 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) => `
  1. ` + `${esc(step)}
  2. `, ) .join('') + `
` + `
` + `
${esc(p.states[2])}
` + `
` + `
` + `
` + `
` + // 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 => `
${esc(legend)}
${body}
`; /** * 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. `` + `
${esc(t.cardTitle)}
` + `
${esc(t.cardSub)}
` + `
` + `` + group(t.sections.material, selectField('material', Object.keys(GLASS_MATERIALS), 'regular')) + group(t.sections.optics, GLASS_OPTICS.map((s) => rangeField(s, m[s.key])).join('')) + group( t.sections.light, rangeField(GLASS_SHAPE[0], GLASS_START.radius) + rangeField(GLASS_SHAPE[1], GLASS_START.width) + rangeField(GLASS_SHAPE[2], m.specular) + selectField('tone', ['auto', 'dark', 'light'], 'auto') + ['rim', 'sheen', 'interactive'].map(switchField).join(''), ) + group( t.sections.backdrop, switchField('backdrop') + `
${GLASS_SCENES.map(scene).join('')}` + `
`, ) + `
` + `` + `
${esc(code)}
` ); }; // ── 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 ( `` ); }; // ── Loading gallery ───────────────────────────────────────────────────────── /** Every animation `` ships, in the order the component defines them. */ const LOADING_NAMES = [ 'stretch', 'rotate', 'double-bounce', 'cube', 'dot', 'triple-bounce', 'scale-out', 'circle', 'circle-line', 'square', 'pulse', 'solar', 'cube-fold', 'circle-fold', 'cube-grid', 'circle-turn', 'circle-rotate', 'circle-spin', 'dot-bar', 'dot-circle', 'line', 'dot-pulse', 'line-scale', 'text', 'cube-dim', 'dot-line', 'arc', 'drop', 'pacman', ] as const; /** * Was a Vue single-file component in `vue/`, imported by eight pages through a * `