bearminion 1.22.0 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +1 -1
- package/dist/hosted-overlay.js +1 -1
- package/dist/ui/mount.js +1 -1
- package/package.json +1 -1
- package/registry/default/files/src/components/sections/changelog/Changelog.astro +94 -0
- package/registry/default/files/src/components/sections/changelog/definition.ts +91 -0
- package/registry/default/files/src/components/sections/changelog/wireframe.ts +25 -0
- package/registry/default/files/src/components/sections/code-tabs/CodeTabs.astro +166 -0
- package/registry/default/files/src/components/sections/code-tabs/code.ts +27 -0
- package/registry/default/files/src/components/sections/code-tabs/definition.ts +87 -0
- package/registry/default/files/src/components/sections/code-tabs/wireframe.ts +18 -0
- package/registry/default/files/src/components/sections/compare/Compare.astro +93 -0
- package/registry/default/files/src/components/sections/compare/definition.ts +84 -0
- package/registry/default/files/src/components/sections/compare/wireframe.ts +24 -0
- package/registry/default/files/src/components/sections/features/Features.astro +45 -0
- package/registry/default/files/src/components/sections/features/definition.ts +2 -2
- package/registry/default/files/src/components/sections/steps/Steps.astro +126 -0
- package/registry/default/files/src/components/sections/steps/definition.ts +27 -6
- package/registry/default/registry.json +135 -7
package/dist/ui/mount.js
CHANGED
|
@@ -796,7 +796,7 @@ function imageObjectPath(path) {
|
|
|
796
796
|
function isButtonLinkPath(path) {
|
|
797
797
|
return /(?:^|\.)(?:primary|secondary|cta|signIn|link|actions\.\d+)(?:\.label)?$/.test(path);
|
|
798
798
|
}
|
|
799
|
-
const multiline = /(?:^|\.)(?:body|intro|description|quote|note|thanks|blurb|sub|text|a)$/;
|
|
799
|
+
const multiline = /(?:^|\.)(?:body|intro|description|quote|note|thanks|blurb|sub|text|code|a)$/;
|
|
800
800
|
function isMultilineField(path) {
|
|
801
801
|
return multiline.test(path);
|
|
802
802
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { anchorAttrs } from '../../../lib/link-attrs'
|
|
3
|
+
import type { Section } from '../definitions'
|
|
4
|
+
import Typography from '../../atoms/Typography.astro'
|
|
5
|
+
import SectionHeader from '../../molecules/SectionHeader.astro'
|
|
6
|
+
import SectionShell from '../../molecules/SectionShell.astro'
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
section: Extract<Section, { type: 'changelog' }>
|
|
10
|
+
index: number
|
|
11
|
+
motion?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { section, index, motion = true } = Astro.props
|
|
15
|
+
const props = section.props
|
|
16
|
+
const field = (path: string) => `sections.${index}.props.${path}`
|
|
17
|
+
const reveal = section.motion ?? motion
|
|
18
|
+
const cards = section.variant === 'cards'
|
|
19
|
+
const linkClass = 'inline-flex items-center gap-1.5 font-medium text-link underline-offset-4 hover:underline focus-visible:outline-2 focus-visible:outline-offset-3 focus-visible:outline-link'
|
|
20
|
+
/** The first release is the latest: its version chip takes the accent color. */
|
|
21
|
+
const chip = (latest: boolean) =>
|
|
22
|
+
latest ? 'rounded-full bg-accent px-2.5 py-1 font-medium text-on' : 'rounded-full bg-[color-mix(in_oklch,var(--fg)_8%,transparent)] px-2.5 py-1 text-fg'
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
<SectionShell id={section.id} anchor={section.anchor} type={section.type} variant={section.variant} tone={section.tone} motion={reveal}>
|
|
26
|
+
<div class="section-container">
|
|
27
|
+
<div class="flex flex-wrap items-end justify-between gap-x-12 gap-y-5">
|
|
28
|
+
<div class="flex flex-[1_1_28rem] flex-col gap-5">
|
|
29
|
+
<SectionHeader eyebrow={props.eyebrow} heading={props.heading} marks={props.marks} size="h2-md" field={field} headingClass="max-w-[16ch]" />
|
|
30
|
+
{props.body && <Typography as="p" size="lead" color="muted" class="max-w-xl" data-field={field('body')} markdown={props.body} />}
|
|
31
|
+
</div>
|
|
32
|
+
{
|
|
33
|
+
props.link && (
|
|
34
|
+
<a {...anchorAttrs(props.link)} class={linkClass}>
|
|
35
|
+
<span data-field={field('link.label')}>{props.link.label}</span> <span aria-hidden="true">→</span>
|
|
36
|
+
</a>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<ol class:list={['mt-[clamp(2.5rem,4cqi,4rem)]', cards ? 'grid grid-cols-[repeat(auto-fit,minmax(min(100%,20rem),1fr))] gap-4' : 'flex flex-col']}>
|
|
42
|
+
{props.releases.map((release, releaseIndex) => {
|
|
43
|
+
const at = (path: string) => field(`releases.${releaseIndex}.${path}`)
|
|
44
|
+
const meta = (
|
|
45
|
+
<div class:list={['flex items-center gap-3 font-mono text-[0.75rem]', cards && 'justify-between']}>
|
|
46
|
+
<span class={chip(releaseIndex === 0)} data-field={at('version')}>{release.version}</span>
|
|
47
|
+
{(release.ref || release.date) && (
|
|
48
|
+
<span class="flex gap-3 text-muted">
|
|
49
|
+
{release.date && <span data-field={at('date')}>{release.date}</span>}
|
|
50
|
+
{release.ref && <span data-field={at('ref')}>{release.ref}</span>}
|
|
51
|
+
</span>
|
|
52
|
+
)}
|
|
53
|
+
</div>
|
|
54
|
+
)
|
|
55
|
+
const body = (
|
|
56
|
+
<>
|
|
57
|
+
<h3 class="text-[1.5rem] leading-[1.1] font-semibold tracking-[-0.03em] text-balance" data-field={at('title')}>{release.title}</h3>
|
|
58
|
+
<ul class="flex flex-1 flex-col gap-3">
|
|
59
|
+
{release.items.map((item, itemIndex) => (
|
|
60
|
+
<li class="grid grid-cols-[1rem_minmax(0,1fr)] gap-2 text-[0.9375rem] leading-[1.5]">
|
|
61
|
+
<span class="font-mono text-link" aria-hidden="true">+</span>
|
|
62
|
+
<Typography as="span" size="body" color="muted" data-field={at(`items.${itemIndex}`)} markdown={item} />
|
|
63
|
+
</li>
|
|
64
|
+
))}
|
|
65
|
+
</ul>
|
|
66
|
+
</>
|
|
67
|
+
)
|
|
68
|
+
return cards ? (
|
|
69
|
+
<li class="flex flex-col gap-5 rounded-card-lg bg-surface p-6 ring-line">
|
|
70
|
+
{meta}
|
|
71
|
+
{body}
|
|
72
|
+
{release.link && (
|
|
73
|
+
<a {...anchorAttrs(release.link)} class:list={[linkClass, 'border-t border-line pt-4 text-[0.9375rem]']}>
|
|
74
|
+
<span data-field={at('link.label')}>{release.link.label}</span> <span aria-hidden="true">→</span>
|
|
75
|
+
</a>
|
|
76
|
+
)}
|
|
77
|
+
</li>
|
|
78
|
+
) : (
|
|
79
|
+
<li class="grid gap-x-12 gap-y-4 border-t border-line py-8 @min-[760px]:grid-cols-[12rem_minmax(0,1fr)]">
|
|
80
|
+
<div class="flex flex-col items-start gap-3">{meta}</div>
|
|
81
|
+
<div class="flex max-w-2xl flex-col gap-4">
|
|
82
|
+
{body}
|
|
83
|
+
{release.link && (
|
|
84
|
+
<a {...anchorAttrs(release.link)} class:list={[linkClass, 'text-[0.9375rem]']}>
|
|
85
|
+
<span data-field={at('link.label')}>{release.link.label}</span> <span aria-hidden="true">→</span>
|
|
86
|
+
</a>
|
|
87
|
+
)}
|
|
88
|
+
</div>
|
|
89
|
+
</li>
|
|
90
|
+
)
|
|
91
|
+
})}
|
|
92
|
+
</ol>
|
|
93
|
+
</div>
|
|
94
|
+
</SectionShell>
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { defineSection, linkSchema, richTextSchema, textSchema, withEmphasis, type CountRule } from 'bearminion'
|
|
3
|
+
import { accent, eyebrow, heading } from '../shared'
|
|
4
|
+
import { changelogWireframe } from './wireframe'
|
|
5
|
+
|
|
6
|
+
export const changelogVariants = ['cards', 'timeline'] as const
|
|
7
|
+
|
|
8
|
+
/** The latest releases, newest first. */
|
|
9
|
+
export const changelogCounts = {
|
|
10
|
+
releases: { recommended: 3, min: 1, max: 6 },
|
|
11
|
+
} as const satisfies Record<string, CountRule>
|
|
12
|
+
|
|
13
|
+
/** One to six changes per release. */
|
|
14
|
+
const ITEMS = { min: 1, max: 6 } as const
|
|
15
|
+
|
|
16
|
+
export const releaseSchema = z
|
|
17
|
+
.object({
|
|
18
|
+
/** The version, such as `1.4` or `v2.0.1`. The first release is shown as the latest. */
|
|
19
|
+
version: textSchema,
|
|
20
|
+
/** When it shipped, as you want it written: `12 March 2026`, `March`. */
|
|
21
|
+
date: textSchema.optional(),
|
|
22
|
+
/** A short commit hash or tag, shown beside the version. */
|
|
23
|
+
ref: textSchema.optional(),
|
|
24
|
+
title: textSchema,
|
|
25
|
+
/** What changed, one line each. Text in backticks shows as code. */
|
|
26
|
+
items: z.array(richTextSchema).min(ITEMS.min).max(ITEMS.max),
|
|
27
|
+
/** Where the full notes are, such as the release on GitHub. */
|
|
28
|
+
link: linkSchema.optional(),
|
|
29
|
+
})
|
|
30
|
+
.strict()
|
|
31
|
+
|
|
32
|
+
export const changelogSchema = withEmphasis({
|
|
33
|
+
eyebrow,
|
|
34
|
+
heading,
|
|
35
|
+
body: richTextSchema.optional(),
|
|
36
|
+
/** A link beside the heading to every release. */
|
|
37
|
+
link: linkSchema.optional(),
|
|
38
|
+
releases: z.array(releaseSchema).min(changelogCounts.releases.min).max(changelogCounts.releases.max),
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
export type Release = z.infer<typeof releaseSchema>
|
|
42
|
+
export type ChangelogProps = z.infer<typeof changelogSchema>
|
|
43
|
+
|
|
44
|
+
export const changelog = defineSection({
|
|
45
|
+
type: 'changelog',
|
|
46
|
+
label: 'Changelog',
|
|
47
|
+
description: 'The latest releases, each with what changed.',
|
|
48
|
+
schema: changelogSchema,
|
|
49
|
+
defaults: {
|
|
50
|
+
eyebrow: 'Changelog',
|
|
51
|
+
heading: 'What shipped lately.',
|
|
52
|
+
marks: accent('What shipped lately.', 'lately.'),
|
|
53
|
+
link: { label: 'All releases', href: '#' },
|
|
54
|
+
releases: [
|
|
55
|
+
{
|
|
56
|
+
version: '2.1',
|
|
57
|
+
date: 'This month',
|
|
58
|
+
title: 'Name the headline change',
|
|
59
|
+
items: [
|
|
60
|
+
'Say what a reader can do now that they could not before.',
|
|
61
|
+
'One line per change, starting with the benefit.',
|
|
62
|
+
'Name a command or setting in `backticks`.',
|
|
63
|
+
],
|
|
64
|
+
link: { label: 'Read more', href: '#' },
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
version: '2.0',
|
|
68
|
+
date: 'Last month',
|
|
69
|
+
title: 'A bigger release',
|
|
70
|
+
items: [
|
|
71
|
+
'Lead with what changed for the reader.',
|
|
72
|
+
'Say what they have to do, if anything.',
|
|
73
|
+
'Leave the internals for the full notes.',
|
|
74
|
+
],
|
|
75
|
+
link: { label: 'Read more', href: '#' },
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
version: '1.9',
|
|
79
|
+
date: 'Earlier',
|
|
80
|
+
title: 'A small fix, said plainly',
|
|
81
|
+
items: ['What was broken.', 'What works now.', 'Who it affected.'],
|
|
82
|
+
link: { label: 'Read more', href: '#' },
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
variants: changelogVariants,
|
|
87
|
+
defaultVariant: 'cards',
|
|
88
|
+
optional: { props: ['eyebrow', 'heading', 'body', 'link'], items: { releases: ['date', 'ref', 'link'] } },
|
|
89
|
+
counts: changelogCounts,
|
|
90
|
+
wireframe: changelogWireframe,
|
|
91
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineWireframe } from 'bearminion'
|
|
2
|
+
|
|
3
|
+
/** Add section picker thumbnail: [left %, top %, width %, height %, kind]. */
|
|
4
|
+
export const changelogWireframe = defineWireframe([
|
|
5
|
+
[8, 12, 34, 8, 'title'],
|
|
6
|
+
[74, 15, 18, 4, 'text'],
|
|
7
|
+
[8, 30, 26, 60, 'card'],
|
|
8
|
+
[37, 30, 26, 60, 'card'],
|
|
9
|
+
[66, 30, 26, 60, 'card'],
|
|
10
|
+
[11, 35, 7, 4, 'highlight'],
|
|
11
|
+
[40, 35, 7, 4, 'light'],
|
|
12
|
+
[69, 35, 7, 4, 'light'],
|
|
13
|
+
[11, 45, 18, 5, 'title'],
|
|
14
|
+
[40, 45, 18, 5, 'title'],
|
|
15
|
+
[69, 45, 18, 5, 'title'],
|
|
16
|
+
[11, 56, 20, 3, 'text'],
|
|
17
|
+
[11, 63, 18, 3, 'text'],
|
|
18
|
+
[11, 70, 20, 3, 'text'],
|
|
19
|
+
[40, 56, 20, 3, 'text'],
|
|
20
|
+
[40, 63, 16, 3, 'text'],
|
|
21
|
+
[40, 70, 19, 3, 'text'],
|
|
22
|
+
[69, 56, 18, 3, 'text'],
|
|
23
|
+
[69, 63, 20, 3, 'text'],
|
|
24
|
+
[69, 70, 15, 3, 'text'],
|
|
25
|
+
])
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { Section } from '../definitions'
|
|
3
|
+
import Typography from '../../atoms/Typography.astro'
|
|
4
|
+
import SectionHeader from '../../molecules/SectionHeader.astro'
|
|
5
|
+
import SectionShell from '../../molecules/SectionShell.astro'
|
|
6
|
+
import { codeLines } from './code'
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
section: Extract<Section, { type: 'codeTabs' }>
|
|
10
|
+
index: number
|
|
11
|
+
motion?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { section, index, motion = true } = Astro.props
|
|
15
|
+
const props = section.props
|
|
16
|
+
const field = (path: string) => `sections.${index}.props.${path}`
|
|
17
|
+
const reveal = section.motion ?? motion
|
|
18
|
+
const side = section.variant === 'side'
|
|
19
|
+
const points = props.points ?? []
|
|
20
|
+
/** Unique per section on the page, for the tab and panel ids. */
|
|
21
|
+
const key = `code-tabs-${section.id}`
|
|
22
|
+
const tabs = props.tabs.map((tab, tabIndex) => ({ ...tab, lines: codeLines(tab.code), id: `${key}-tab-${tabIndex}`, panel: `${key}-panel-${tabIndex}` }))
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
<SectionShell id={section.id} anchor={section.anchor} type={section.type} variant={section.variant} tone={section.tone} motion={reveal}>
|
|
26
|
+
<div class="section-container" data-code-tabs>
|
|
27
|
+
<SectionHeader
|
|
28
|
+
eyebrow={props.eyebrow}
|
|
29
|
+
heading={props.heading}
|
|
30
|
+
marks={props.marks}
|
|
31
|
+
size="h2-lg"
|
|
32
|
+
field={field}
|
|
33
|
+
headingClass="[&_.bm-em]:text-link"
|
|
34
|
+
class="max-w-[52rem]"
|
|
35
|
+
/>
|
|
36
|
+
{props.body && <Typography as="p" size="lead" color="muted" class="mt-5 max-w-xl" data-field={field('body')} markdown={props.body} />}
|
|
37
|
+
|
|
38
|
+
<div class:list={['mt-[clamp(3rem,5cqi,4.5rem)] flex gap-4', side ? 'flex-wrap items-stretch' : 'flex-col']}>
|
|
39
|
+
<div
|
|
40
|
+
role="tablist"
|
|
41
|
+
aria-label={props.heading ?? 'Code samples'}
|
|
42
|
+
class:list={[side ? 'flex flex-[1_1_18rem] flex-col' : 'flex gap-2 overflow-x-auto pb-1']}
|
|
43
|
+
>
|
|
44
|
+
{tabs.map((tab, tabIndex) => (
|
|
45
|
+
<button
|
|
46
|
+
type="button"
|
|
47
|
+
role="tab"
|
|
48
|
+
id={tab.id}
|
|
49
|
+
aria-controls={tab.panel}
|
|
50
|
+
aria-selected={tabIndex === 0 ? 'true' : 'false'}
|
|
51
|
+
tabindex={tabIndex === 0 ? 0 : -1}
|
|
52
|
+
data-code-tab={tabIndex}
|
|
53
|
+
class:list={[
|
|
54
|
+
'group text-left transition-colors focus-visible:outline-2 focus-visible:outline-offset-3 focus-visible:outline-link',
|
|
55
|
+
side
|
|
56
|
+
? 'border-t border-line py-5 pe-4 aria-selected:border-[color-mix(in_oklch,var(--fg)_50%,transparent)]'
|
|
57
|
+
: 'shrink-0 rounded-full px-4 py-2 ring-line aria-selected:bg-fg aria-selected:text-bg',
|
|
58
|
+
]}
|
|
59
|
+
>
|
|
60
|
+
<span class="flex items-center gap-2.5 text-[1.0625rem] font-semibold tracking-[-0.015em]">
|
|
61
|
+
{side && <span class="size-2 shrink-0 bg-line transition-colors group-aria-selected:bg-link" aria-hidden="true" />}
|
|
62
|
+
<span data-field={field(`tabs.${tabIndex}.title`)}>{tab.title}</span>
|
|
63
|
+
</span>
|
|
64
|
+
{side && tab.description && (
|
|
65
|
+
<Typography
|
|
66
|
+
as="span"
|
|
67
|
+
size="small"
|
|
68
|
+
color="muted"
|
|
69
|
+
class="mt-1.5 block ps-[1.125rem]"
|
|
70
|
+
data-field={field(`tabs.${tabIndex}.description`)}
|
|
71
|
+
markdown={tab.description}
|
|
72
|
+
/>
|
|
73
|
+
)}
|
|
74
|
+
</button>
|
|
75
|
+
))}
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
{/* Dark in every tone, like an editor window. */}
|
|
79
|
+
<div class:list={['min-w-0', side && 'flex-[2_1_30rem]']}>
|
|
80
|
+
{tabs.map((tab, tabIndex) => (
|
|
81
|
+
<figure
|
|
82
|
+
role="tabpanel"
|
|
83
|
+
id={tab.panel}
|
|
84
|
+
aria-labelledby={tab.id}
|
|
85
|
+
data-code-panel={tabIndex}
|
|
86
|
+
hidden={tabIndex !== 0}
|
|
87
|
+
class="flex h-full flex-col overflow-hidden rounded-[1.25rem] bg-[oklch(0.13_0.008_255)] text-[oklch(0.93_0.006_250)] shadow-[inset_0_0_0_1px_oklch(0.97_0.004_250/0.1)]"
|
|
88
|
+
>
|
|
89
|
+
<figcaption class="flex items-center gap-1.5 border-b border-[oklch(0.97_0.004_250/0.08)] px-[1.125rem] py-3.5 font-mono text-[0.75rem] text-[oklch(0.74_0.01_255)]">
|
|
90
|
+
<span class="size-[0.5625rem] rounded-full bg-[oklch(0.97_0.004_250/0.16)]" aria-hidden="true" />
|
|
91
|
+
<span class="size-[0.5625rem] rounded-full bg-[oklch(0.97_0.004_250/0.16)]" aria-hidden="true" />
|
|
92
|
+
<span class="size-[0.5625rem] rounded-full bg-[oklch(0.97_0.004_250/0.16)]" aria-hidden="true" />
|
|
93
|
+
{tab.file && <span class="ms-2" data-field={field(`tabs.${tabIndex}.file`)}>{tab.file}</span>}
|
|
94
|
+
</figcaption>
|
|
95
|
+
{/* tabindex: a panel that scrolls sideways is reachable from the keyboard. */}
|
|
96
|
+
<pre
|
|
97
|
+
tabindex="0"
|
|
98
|
+
class="flex-1 overflow-x-auto overflow-y-hidden px-5 pt-5 pb-6 font-mono text-[clamp(0.75rem,0.72rem+0.15cqi,0.8125rem)] leading-[1.8] [scrollbar-color:oklch(0.97_0.004_250/0.2)_transparent] [color-scheme:dark] focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-[oklch(0.87_0.2_145)]"
|
|
99
|
+
><code>{tab.lines.map((line) => (
|
|
100
|
+
<span class="block whitespace-pre"><span class="inline-block w-8 text-[oklch(0.97_0.004_250/0.22)] select-none" aria-hidden="true">{line.n}</span>{line.code || ' '}{line.note && <span class="text-[oklch(0.87_0.2_145/0.75)]">{line.note}</span>}</span>
|
|
101
|
+
))}</code></pre>
|
|
102
|
+
</figure>
|
|
103
|
+
))}
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
{points.length > 0 && (
|
|
108
|
+
<ul class="mt-[clamp(3rem,5cqi,4.5rem)] grid grid-cols-[repeat(auto-fill,minmax(min(100%,20rem),1fr))] gap-x-[clamp(1.5rem,3cqi,3rem)] gap-y-10">
|
|
109
|
+
{points.map((point, pointIndex) => (
|
|
110
|
+
<li class="flex flex-col gap-2.5 border-t border-line pt-5">
|
|
111
|
+
<span class="font-mono text-[0.75rem] text-link">{String(pointIndex + 1).padStart(2, '0')}</span>
|
|
112
|
+
<h3 class="text-[1.25rem] font-semibold tracking-[-0.02em]" data-field={field(`points.${pointIndex}.title`)}>{point.title}</h3>
|
|
113
|
+
{point.description && (
|
|
114
|
+
<Typography as="p" size="body" color="muted" data-field={field(`points.${pointIndex}.description`)} markdown={point.description} />
|
|
115
|
+
)}
|
|
116
|
+
</li>
|
|
117
|
+
))}
|
|
118
|
+
</ul>
|
|
119
|
+
)}
|
|
120
|
+
</div>
|
|
121
|
+
</SectionShell>
|
|
122
|
+
|
|
123
|
+
<script>
|
|
124
|
+
/** Tabs as the ARIA pattern has them: a click or Enter picks one, the arrow keys, Home and End move between them. */
|
|
125
|
+
function bindCodeTabs() {
|
|
126
|
+
for (const root of document.querySelectorAll<HTMLElement>('[data-code-tabs]')) {
|
|
127
|
+
if (root.dataset.bound === 'true') continue
|
|
128
|
+
root.dataset.bound = 'true'
|
|
129
|
+
const tabs = [...root.querySelectorAll<HTMLButtonElement>('[data-code-tab]')]
|
|
130
|
+
const panels = [...root.querySelectorAll<HTMLElement>('[data-code-panel]')]
|
|
131
|
+
const pick = (next: number, focus = false) => {
|
|
132
|
+
tabs.forEach((tab, tabIndex) => {
|
|
133
|
+
const on = tabIndex === next
|
|
134
|
+
tab.setAttribute('aria-selected', String(on))
|
|
135
|
+
tab.tabIndex = on ? 0 : -1
|
|
136
|
+
if (on && focus) tab.focus()
|
|
137
|
+
})
|
|
138
|
+
panels.forEach((panel, panelIndex) => {
|
|
139
|
+
panel.hidden = panelIndex !== next
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
tabs.forEach((tab, tabIndex) => {
|
|
143
|
+
tab.addEventListener('click', () => pick(tabIndex))
|
|
144
|
+
tab.addEventListener('keydown', (event) => {
|
|
145
|
+
// While the editor edits the tab's title, the keys are the text's.
|
|
146
|
+
if (event.target instanceof HTMLElement && event.target.isContentEditable) return
|
|
147
|
+
const last = tabs.length - 1
|
|
148
|
+
const moves: Record<string, number> = {
|
|
149
|
+
ArrowDown: tabIndex === last ? 0 : tabIndex + 1,
|
|
150
|
+
ArrowRight: tabIndex === last ? 0 : tabIndex + 1,
|
|
151
|
+
ArrowUp: tabIndex === 0 ? last : tabIndex - 1,
|
|
152
|
+
ArrowLeft: tabIndex === 0 ? last : tabIndex - 1,
|
|
153
|
+
Home: 0,
|
|
154
|
+
End: last,
|
|
155
|
+
}
|
|
156
|
+
const next = moves[event.key]
|
|
157
|
+
if (next === undefined) return
|
|
158
|
+
event.preventDefault()
|
|
159
|
+
pick(next, true)
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
bindCodeTabs()
|
|
165
|
+
document.addEventListener('bearminion:preview', bindCodeTabs)
|
|
166
|
+
</script>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** One line of a code sample: its number, the code, and a trailing comment drawn apart. */
|
|
2
|
+
export interface CodeLine {
|
|
3
|
+
n: number
|
|
4
|
+
code: string
|
|
5
|
+
note: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Splits a sample into lines and pulls a trailing comment off each: a line that starts with `//` or `#` is all
|
|
10
|
+
* comment, and otherwise ` // note` or ` # note` (two spaces first, so `a#b` and URLs stay code) ends the code.
|
|
11
|
+
*/
|
|
12
|
+
export function codeLines(source: string): CodeLine[] {
|
|
13
|
+
return source
|
|
14
|
+
.replace(/\r\n?/g, '\n')
|
|
15
|
+
.split('\n')
|
|
16
|
+
.map((line, index) => {
|
|
17
|
+
const trimmed = line.trimStart()
|
|
18
|
+
let at = -1
|
|
19
|
+
if (trimmed.startsWith('//') || trimmed.startsWith('# ')) at = line.length - trimmed.length
|
|
20
|
+
else {
|
|
21
|
+
const slash = line.indexOf(' // ')
|
|
22
|
+
const hash = line.indexOf(' # ')
|
|
23
|
+
at = [slash, hash].filter((value) => value > -1).sort((a, b) => a - b)[0] ?? -1
|
|
24
|
+
}
|
|
25
|
+
return { n: index + 1, code: at > -1 ? line.slice(0, at) : line, note: at > -1 ? line.slice(at) : '' }
|
|
26
|
+
})
|
|
27
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { defineSection, richTextSchema, textSchema, withEmphasis, type CountRule } from 'bearminion'
|
|
3
|
+
import { accent, eyebrow, heading } from '../shared'
|
|
4
|
+
import { codeTabsWireframe } from './wireframe'
|
|
5
|
+
|
|
6
|
+
export const codeTabsVariants = ['side', 'top'] as const
|
|
7
|
+
|
|
8
|
+
/** Two to six tabs, and up to six short points under them. */
|
|
9
|
+
export const codeTabsCounts = {
|
|
10
|
+
tabs: { recommended: '3 or 4', min: 2, max: 6 },
|
|
11
|
+
points: { recommended: '3 or 6', min: 0, max: 6 },
|
|
12
|
+
} as const satisfies Record<string, CountRule>
|
|
13
|
+
|
|
14
|
+
export const codeTabSchema = z
|
|
15
|
+
.object({
|
|
16
|
+
title: textSchema,
|
|
17
|
+
/** One sentence under the title. Text in backticks shows as code. */
|
|
18
|
+
description: richTextSchema.optional(),
|
|
19
|
+
/** The file name over the code, such as `src/lib/content-model.ts`, or `terminal`. */
|
|
20
|
+
file: textSchema.optional(),
|
|
21
|
+
/** The code, as it is: line breaks and spaces are kept. A trailing `// note` or ` # note` is drawn as a comment. */
|
|
22
|
+
code: z.string().min(1),
|
|
23
|
+
})
|
|
24
|
+
.strict()
|
|
25
|
+
|
|
26
|
+
export const codePointSchema = z
|
|
27
|
+
.object({
|
|
28
|
+
title: textSchema,
|
|
29
|
+
/** A sentence or two. Text in backticks shows as code. */
|
|
30
|
+
description: richTextSchema.optional(),
|
|
31
|
+
})
|
|
32
|
+
.strict()
|
|
33
|
+
|
|
34
|
+
export const codeTabsSchema = withEmphasis({
|
|
35
|
+
eyebrow,
|
|
36
|
+
heading,
|
|
37
|
+
body: richTextSchema.optional(),
|
|
38
|
+
tabs: z.array(codeTabSchema).min(codeTabsCounts.tabs.min).max(codeTabsCounts.tabs.max),
|
|
39
|
+
points: z.array(codePointSchema).max(codeTabsCounts.points.max).optional(),
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
export type CodeTab = z.infer<typeof codeTabSchema>
|
|
43
|
+
export type CodePoint = z.infer<typeof codePointSchema>
|
|
44
|
+
export type CodeTabsProps = z.infer<typeof codeTabsSchema>
|
|
45
|
+
|
|
46
|
+
export const codeTabs = defineSection({
|
|
47
|
+
type: 'codeTabs',
|
|
48
|
+
label: 'Code tabs',
|
|
49
|
+
description: 'Code samples in tabs, with numbered points under them.',
|
|
50
|
+
schema: codeTabsSchema,
|
|
51
|
+
defaults: {
|
|
52
|
+
eyebrow: 'For developers',
|
|
53
|
+
heading: 'Show the code, not a diagram.',
|
|
54
|
+
marks: accent('Show the code, not a diagram.', 'not a diagram.'),
|
|
55
|
+
body: 'One tab per idea. Keep each sample short enough to read without scrolling.',
|
|
56
|
+
tabs: [
|
|
57
|
+
{
|
|
58
|
+
title: 'Install it',
|
|
59
|
+
description: 'The one command a reader runs first.',
|
|
60
|
+
file: 'terminal',
|
|
61
|
+
code: '$ npm install example # one dependency\n$ npx example init # writes example.config.ts',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
title: 'Configure it',
|
|
65
|
+
description: 'The smallest config that works.',
|
|
66
|
+
file: 'example.config.ts',
|
|
67
|
+
code: "import { defineConfig } from 'example'\n\nexport default defineConfig({\n name: 'my-site',\n output: 'static', // or 'server'\n})",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
title: 'Use it',
|
|
71
|
+
description: 'What the reader writes every day.',
|
|
72
|
+
file: 'src/main.ts',
|
|
73
|
+
code: "import { run } from 'example'\n\nawait run() // that is all",
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
points: [
|
|
77
|
+
{ title: 'Small on purpose', description: 'Say what the reader does not have to learn.' },
|
|
78
|
+
{ title: 'Typed end to end', description: 'Name the guarantee, such as `strict` types.' },
|
|
79
|
+
{ title: 'Yours to change', description: 'Say where the code lives and who owns it.' },
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
variants: codeTabsVariants,
|
|
83
|
+
defaultVariant: 'side',
|
|
84
|
+
optional: { props: ['eyebrow', 'heading', 'body', 'points'], items: { tabs: ['description', 'file'], points: ['description'] } },
|
|
85
|
+
counts: codeTabsCounts,
|
|
86
|
+
wireframe: codeTabsWireframe,
|
|
87
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineWireframe } from 'bearminion'
|
|
2
|
+
|
|
3
|
+
/** Add section picker thumbnail: [left %, top %, width %, height %, kind]. */
|
|
4
|
+
export const codeTabsWireframe = defineWireframe([
|
|
5
|
+
[0, 0, 100, 100, 'dark'],
|
|
6
|
+
[8, 10, 34, 7, 'light'],
|
|
7
|
+
[8, 30, 26, 6, 'light'],
|
|
8
|
+
[8, 42, 22, 4, 'text'],
|
|
9
|
+
[8, 52, 26, 4, 'text'],
|
|
10
|
+
[8, 62, 20, 4, 'text'],
|
|
11
|
+
[40, 28, 52, 44, 'block'],
|
|
12
|
+
[44, 34, 30, 3, 'text'],
|
|
13
|
+
[44, 42, 38, 3, 'text'],
|
|
14
|
+
[44, 50, 24, 3, 'text'],
|
|
15
|
+
[8, 82, 24, 4, 'light'],
|
|
16
|
+
[38, 82, 24, 4, 'light'],
|
|
17
|
+
[68, 82, 24, 4, 'light'],
|
|
18
|
+
])
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { Section } from '../definitions'
|
|
3
|
+
import Typography from '../../atoms/Typography.astro'
|
|
4
|
+
import SectionHeader from '../../molecules/SectionHeader.astro'
|
|
5
|
+
import SectionShell from '../../molecules/SectionShell.astro'
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
section: Extract<Section, { type: 'compare' }>
|
|
9
|
+
index: number
|
|
10
|
+
motion?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const { section, index, motion = true } = Astro.props
|
|
14
|
+
const props = section.props
|
|
15
|
+
const field = (path: string) => `sections.${index}.props.${path}`
|
|
16
|
+
const reveal = section.motion ?? motion
|
|
17
|
+
const centered = section.variant === 'centered'
|
|
18
|
+
const lastColumn = props.columns.length - 1
|
|
19
|
+
/** The tint under a highlighted column's cells. */
|
|
20
|
+
const tint = 'bg-[color-mix(in_oklch,var(--accent)_14%,transparent)]'
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
<SectionShell id={section.id} anchor={section.anchor} type={section.type} variant={section.variant} tone={section.tone} motion={reveal}>
|
|
24
|
+
<div class="section-container">
|
|
25
|
+
{
|
|
26
|
+
centered ? (
|
|
27
|
+
<div class="mx-auto flex max-w-3xl flex-col items-center gap-5 text-center">
|
|
28
|
+
<SectionHeader eyebrow={props.eyebrow} heading={props.heading} marks={props.marks} align="center" size="h2-md" field={field} headingClass="max-w-[18ch]" />
|
|
29
|
+
{props.body && <Typography as="p" size="lead" color="muted" class="max-w-xl" data-field={field('body')} markdown={props.body} />}
|
|
30
|
+
</div>
|
|
31
|
+
) : (
|
|
32
|
+
<div class="grid items-end gap-6 @min-[760px]:grid-cols-[minmax(0,1fr)_minmax(0,1fr)] @min-[760px]:gap-12">
|
|
33
|
+
<SectionHeader eyebrow={props.eyebrow} heading={props.heading} marks={props.marks} size="h2-md" field={field} headingClass="max-w-[18ch]" />
|
|
34
|
+
{props.body && <Typography as="p" size="lead" color="muted" data-field={field('body')} markdown={props.body} />}
|
|
35
|
+
</div>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
{/* Scrolls sideways on a narrow screen rather than squeezing the cells; tabindex lets the keyboard scroll it. */}
|
|
40
|
+
<div class="mt-[clamp(2.5rem,4cqi,4rem)] overflow-x-auto rounded-card-lg ring-line" tabindex="0" role="region" aria-label={props.heading ?? 'Comparison'}>
|
|
41
|
+
<table class="w-full min-w-[46rem] border-collapse text-left text-[0.9375rem]">
|
|
42
|
+
<thead>
|
|
43
|
+
<tr>
|
|
44
|
+
<td class="px-5 py-[1.125rem]" />
|
|
45
|
+
{props.columns.map((column, columnIndex) => (
|
|
46
|
+
<th
|
|
47
|
+
scope="col"
|
|
48
|
+
class:list={[
|
|
49
|
+
'px-5 py-[1.125rem] align-bottom',
|
|
50
|
+
column.highlight ? 'bg-accent font-bold text-on' : 'font-semibold',
|
|
51
|
+
column.highlight && columnIndex === lastColumn && 'rounded-se-card-lg',
|
|
52
|
+
]}
|
|
53
|
+
data-field={field(`columns.${columnIndex}.label`)}
|
|
54
|
+
>
|
|
55
|
+
{column.label}
|
|
56
|
+
</th>
|
|
57
|
+
))}
|
|
58
|
+
</tr>
|
|
59
|
+
</thead>
|
|
60
|
+
<tbody>
|
|
61
|
+
{props.rows.map((row, rowIndex) => (
|
|
62
|
+
<tr class="border-t border-line">
|
|
63
|
+
<th scope="row" class="px-5 py-4 font-mono text-[0.75rem] font-medium whitespace-nowrap text-muted" data-field={field(`rows.${rowIndex}.label`)}>
|
|
64
|
+
{row.label}
|
|
65
|
+
</th>
|
|
66
|
+
{props.columns.map((column, columnIndex) => (
|
|
67
|
+
<td
|
|
68
|
+
class:list={['px-5 py-4', column.highlight ? ['font-semibold', tint] : 'text-muted']}
|
|
69
|
+
data-field={row.values[columnIndex] === undefined ? undefined : field(`rows.${rowIndex}.values.${columnIndex}`)}
|
|
70
|
+
>
|
|
71
|
+
{row.values[columnIndex] ?? ''}
|
|
72
|
+
</td>
|
|
73
|
+
))}
|
|
74
|
+
</tr>
|
|
75
|
+
))}
|
|
76
|
+
</tbody>
|
|
77
|
+
</table>
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
{
|
|
81
|
+
props.note && (
|
|
82
|
+
<Typography
|
|
83
|
+
as="p"
|
|
84
|
+
size="body"
|
|
85
|
+
color="muted"
|
|
86
|
+
class={centered ? 'mx-auto mt-6 max-w-[40rem] text-center' : 'mt-6 max-w-[40rem]'}
|
|
87
|
+
data-field={field('note')}
|
|
88
|
+
markdown={props.note}
|
|
89
|
+
/>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
</div>
|
|
93
|
+
</SectionShell>
|