import { html } from '@webjsdev/core'; import { cn } from '#lib/utils/cn.ts'; import { buttonClass } from '#modules/ui/components/button.ts'; import { nativeSelectClass, nativeSelectIconClass, nativeSelectWrapperClass } from '#modules/ui/components/native-select.ts'; import { drawerDescriptionClass, drawerFooterClass, drawerHeaderClass, drawerTitleClass } from '#modules/ui/components/drawer.ts'; import { CheckIcon, ChevronDownIcon, CopyIcon } from './icons.ts'; import type { TypesetParams } from './params.ts'; import { DEFAULT_FONT_SOURCE, FONT_SOURCES, IMPORT_CSS, TYPESET_DOCS_URL, fontSteps, presetCode, promptText, usageCode, type FontSource, } from './docs.ts'; /** * The typeset builder's Docs / Prompt panel, shadcn/ui's TypesetDocsPanel and * TypesetGetCodeDrawer (apps/v4/app/(app)/(typeset)/components/docs-panel.tsx * and get-code-drawer.tsx, #1666), as server markup in the base-nova look. * The text is modules/ui/typeset/docs.ts. * * Every code sample carries `data-typeset-code=""`, and * rewrites those when a choice changes, from the same * docs.ts functions, so the samples follow the preview with no reload. That * is also why they are plain
 blocks rather than : shadcn's
 * DocsCode is unhighlighted, and a block whose text the element replaces has
 * no highlighting to keep in step. Each takes `tabindex="0"`, since it
 * scrolls (the site's code-block rule).
 *
 * shadcn's framework select becomes a font-source select (see docs.ts for
 * why). Both sources' steps are rendered and the select shows one. With
 * JavaScript off the default shows.
 */

//  moves its class onto the element it renders, so the host itself
// is a plain block and breaks the flex column that lets the panel scroll.
// The container makes the host a flex column too.
const TABS_HOST = '[&_ui-tabs]:flex [&_ui-tabs]:min-h-0 [&_ui-tabs]:flex-1 [&_ui-tabs]:flex-col';

function code(key: string, text: string, className = '') {
  return html`
${text}
`; } const prose = (text: unknown) => html`

${text}

`; function section(step: number, title: string, body: unknown) { return html`

${step}. ${title}

${body}
`; } // A copy button, shadcn's outline `sm` with the copy icon swapping to a check // for two seconds. `href`, when given, makes it a link that works with no // script (the stylesheet opens), and the element copies instead. function copyButton(label: string, kind: 'css' | 'prompt', href?: string) { const cls = cn(buttonClass({ variant: 'outline', size: 'sm' }), 'group/copy w-fit no-underline'); const body = html`${CopyIcon('')}${label}`; return href ? html`${body}` : html``; } function fontStepsFor(params: TypesetParams, source: FontSource, shown: boolean) { return html`
${fontSteps(params, source).map((step, i) => html`${prose(step.prose)}${code(`font-${source}-${i}`, step.code)}`)}
`; } /** The tabs, shared by the xl panel and the Get Code drawer. */ export function docsContent(params: TypesetParams, origin: string) { return html`
Docs Prompt
${ChevronDownIcon(nativeSelectIconClass())}
${section(1, 'Create typeset.css', html` ${prose(html`Copy the stylesheet into public/typeset.css, then import it in public/input.css:`)} ${copyButton('Copy typeset.css', 'css', '/ui/typeset.css')} ${code('import', IMPORT_CSS)}`)} ${section(2, 'Add the fonts', html` ${FONT_SOURCES.map((option) => fontStepsFor(params, option.value, option.value === DEFAULT_FONT_SOURCE))}`)} ${section(3, 'Create your custom typeset', code('preset', presetCode(params)))} ${section(4, 'Wrap your content', code('usage', usageCode(params)))} ${prose('One prompt with your picks baked in. Copy it and paste it into your coding agent.')} ${code('prompt', promptText(params, DEFAULT_FONT_SOURCE, origin), 'max-h-102 scroll-fade overflow-y-auto whitespace-pre-wrap')} ${copyButton('Copy Prompt', 'prompt')}
`; } /** * shadcn's "Read the docs". This site has no typeset docs page yet, and the * stylesheet is shadcn's unchanged, so shadcn's page is the true reference. * (Asking modules/ui/docs/nav.ts would ship this page to the browser: the * elision analyser reads that module as client work.) */ function readTheDocs() { return html`Read the docs`; } /** The right-hand panel, from xl up. */ export function docsPanel(params: TypesetParams, origin: string) { return html``; } /** Below xl the panel moves into a drawer, opened from the customizer's Get Code button. */ export function getCodeDrawer(params: TypesetParams, origin: string, triggerClass: string) { return html`

Get Code

Install typeset with the values you picked.

${docsContent(params, origin)}
`; }