bearminion 1.7.0 → 1.9.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 +20 -0
- package/dist/astro.d.ts +2 -2
- package/dist/astro.js +17 -5
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +819 -0
- package/dist/content.d.ts +1 -1
- package/dist/content.js +2 -2
- package/dist/hash-BeBymBO1.js +59 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/marks-DPBilumg.js +174 -0
- package/dist/marks.js +1 -174
- package/dist/{options-BeJQnsZM.d.ts → options-4HWVEj9O.d.ts} +7 -1
- package/dist/{page-BfI9cD8g.d.ts → page-CA4iyFDS.d.ts} +7 -7
- package/dist/{page-NOFVEqn1.js → page-X-WnOu7-.js} +1 -1
- package/dist/{preview--S1QUrMM.js → preview-B_88I5Jm.js} +1 -1
- package/dist/{reload-BPkPoQ-P.js → reload-Dkp3xC0l.js} +1 -1
- package/dist/rich-text-70hddxMC.js +403 -0
- package/dist/rich-text.js +1 -403
- package/dist/sections-manifest-CO9QfJPG.js +97 -0
- package/dist/{theme-DFjHjgFO.js → theme-Dv7_7B56.js} +2 -2
- package/dist/ui/mount.js +20 -7
- package/package.json +7 -1
- package/registry/default/files/src/components/atoms/Button.astro +64 -0
- package/registry/default/files/src/components/atoms/Emphasis.astro +24 -0
- package/registry/default/files/src/components/atoms/Image.astro +78 -0
- package/registry/default/files/src/components/atoms/Typography.astro +53 -0
- package/registry/default/files/src/components/atoms/button.ts +31 -0
- package/registry/default/files/src/components/atoms/image.ts +34 -0
- package/registry/default/files/src/components/atoms/options.ts +39 -0
- package/registry/default/files/src/components/atoms/typography.ts +64 -0
- package/registry/default/files/src/components/molecules/CommandLine.astro +109 -0
- package/registry/default/files/src/components/molecules/MediaFrame.astro +71 -0
- package/registry/default/files/src/components/molecules/Pill.astro +24 -0
- package/registry/default/files/src/components/molecules/SectionHeader.astro +63 -0
- package/registry/default/files/src/components/molecules/SectionShell.astro +33 -0
- package/registry/default/files/src/components/sections/contact/Contact.astro +231 -0
- package/registry/default/files/src/components/sections/contact/definition.ts +52 -0
- package/registry/default/files/src/components/sections/contact/form.ts +313 -0
- package/registry/default/files/src/components/sections/contact/wireframe.ts +15 -0
- package/registry/default/files/src/components/sections/cta/Cta.astro +206 -0
- package/registry/default/files/src/components/sections/cta/definition.ts +49 -0
- package/registry/default/files/src/components/sections/cta/wireframe.ts +9 -0
- package/registry/default/files/src/components/sections/faq/Faq.astro +136 -0
- package/registry/default/files/src/components/sections/faq/definition.ts +54 -0
- package/registry/default/files/src/components/sections/faq/wireframe.ts +19 -0
- package/registry/default/files/src/components/sections/features/Features.astro +146 -0
- package/registry/default/files/src/components/sections/features/definition.ts +54 -0
- package/registry/default/files/src/components/sections/features/wireframe.ts +19 -0
- package/registry/default/files/src/components/sections/gallery/Gallery.astro +128 -0
- package/registry/default/files/src/components/sections/gallery/definition.ts +59 -0
- package/registry/default/files/src/components/sections/gallery/lightbox.ts +159 -0
- package/registry/default/files/src/components/sections/gallery/wireframe.ts +12 -0
- package/registry/default/files/src/components/sections/hero/Hero.astro +185 -0
- package/registry/default/files/src/components/sections/hero/HeroBadge.astro +26 -0
- package/registry/default/files/src/components/sections/hero/definition.ts +74 -0
- package/registry/default/files/src/components/sections/hero/wireframe.ts +12 -0
- package/registry/default/files/src/components/sections/logo-strip/LogoStrip.astro +107 -0
- package/registry/default/files/src/components/sections/logo-strip/definition.ts +30 -0
- package/registry/default/files/src/components/sections/logo-strip/wireframe.ts +11 -0
- package/registry/default/files/src/components/sections/media/Media.astro +118 -0
- package/registry/default/files/src/components/sections/media/MediaPlayer.astro +176 -0
- package/registry/default/files/src/components/sections/media/definition.ts +77 -0
- package/registry/default/files/src/components/sections/media/source.ts +3 -0
- package/registry/default/files/src/components/sections/media/wireframe.ts +9 -0
- package/registry/default/files/src/components/sections/pricing/Pricing.astro +210 -0
- package/registry/default/files/src/components/sections/pricing/definition.ts +62 -0
- package/registry/default/files/src/components/sections/pricing/wireframe.ts +18 -0
- package/registry/default/files/src/components/sections/shared.ts +13 -0
- package/registry/default/files/src/components/sections/stats/Stats.astro +110 -0
- package/registry/default/files/src/components/sections/stats/definition.ts +41 -0
- package/registry/default/files/src/components/sections/stats/wireframe.ts +15 -0
- package/registry/default/files/src/components/sections/steps/Steps.astro +139 -0
- package/registry/default/files/src/components/sections/steps/definition.ts +62 -0
- package/registry/default/files/src/components/sections/steps/icons.ts +27 -0
- package/registry/default/files/src/components/sections/steps/wireframe.ts +16 -0
- package/registry/default/files/src/components/sections/testimonials/Testimonials.astro +172 -0
- package/registry/default/files/src/components/sections/testimonials/definition.ts +42 -0
- package/registry/default/files/src/components/sections/testimonials/wireframe.ts +21 -0
- package/registry/default/files/src/components/sections/text/Text.astro +43 -0
- package/registry/default/files/src/components/sections/text/definition.ts +36 -0
- package/registry/default/files/src/components/sections/text/wireframe.ts +12 -0
- package/registry/default/files/src/components/sections/text-image/TextImage.astro +107 -0
- package/registry/default/files/src/components/sections/text-image/definition.ts +39 -0
- package/registry/default/files/src/components/sections/text-image/wireframe.ts +12 -0
- package/registry/default/files/src/lib/assets.ts +13 -0
- package/registry/default/files/src/lib/cn.ts +6 -0
- package/registry/default/files/src/lib/contact-form.ts +97 -0
- package/registry/default/files/src/lib/hidden-text.ts +32 -0
- package/registry/default/files/src/lib/image-url.ts +38 -0
- package/registry/default/files/src/lib/link-attrs.ts +74 -0
- package/registry/default/registry.json +670 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { defineSection, imageSchema, linkSchema, richTextSchema, textSchema, withEmphasis } from 'bearminion'
|
|
3
|
+
import { accent, eyebrow, heading } from '../shared'
|
|
4
|
+
import { heroWireframe } from './wireframe'
|
|
5
|
+
|
|
6
|
+
export const heroVariants = ['split', 'centered', 'editorial'] as const
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* How the install command shows. `off` hides it. `action` is a pill in the button row that takes the secondary
|
|
10
|
+
* button's place, `chip` a smaller pill under the buttons, `terminal` a dark block under the buttons.
|
|
11
|
+
*/
|
|
12
|
+
export const heroCodeStyles = ['off', 'action', 'chip', 'terminal'] as const
|
|
13
|
+
|
|
14
|
+
/** A linked pill with a short tag, such as "1.2 · Available now". It takes the eyebrow's place in split and centered. */
|
|
15
|
+
export const heroBadgeSchema = z
|
|
16
|
+
.object({
|
|
17
|
+
tag: textSchema.optional(),
|
|
18
|
+
text: textSchema,
|
|
19
|
+
href: z.string().min(1),
|
|
20
|
+
})
|
|
21
|
+
.strict()
|
|
22
|
+
|
|
23
|
+
export const heroSchema = withEmphasis({
|
|
24
|
+
eyebrow,
|
|
25
|
+
heading,
|
|
26
|
+
sub: richTextSchema.optional(),
|
|
27
|
+
badge: heroBadgeSchema.optional(),
|
|
28
|
+
primary: linkSchema.optional(),
|
|
29
|
+
secondary: linkSchema.optional(),
|
|
30
|
+
/** Off hides the primary button and keeps it in the file, for a page whose only action is the command. */
|
|
31
|
+
button: z.boolean().default(true),
|
|
32
|
+
/** The shell command the Copy button copies, such as `npm create bearminion@latest`. */
|
|
33
|
+
command: textSchema.optional(),
|
|
34
|
+
code: z.enum(heroCodeStyles).default('off'),
|
|
35
|
+
/** A soft light in the accent color behind the heading. It follows the tone and the site palette. */
|
|
36
|
+
glow: z.boolean().default(false),
|
|
37
|
+
image: imageSchema.optional(),
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
export type HeroProps = z.infer<typeof heroSchema>
|
|
41
|
+
|
|
42
|
+
export const hero = defineSection({
|
|
43
|
+
type: 'hero',
|
|
44
|
+
label: 'Hero',
|
|
45
|
+
description: 'Opening heading, intro, buttons and an image.',
|
|
46
|
+
schema: heroSchema,
|
|
47
|
+
defaults: {
|
|
48
|
+
eyebrow: 'Your tagline',
|
|
49
|
+
heading: 'Say what you do in one line.',
|
|
50
|
+
marks: accent('Say what you do in one line.', 'one line.'),
|
|
51
|
+
sub: 'Use this paragraph to say who it is for and what they get. Keep it to two sentences.',
|
|
52
|
+
primary: { label: 'Primary action', href: '#' },
|
|
53
|
+
secondary: { label: 'Secondary action', href: '#' },
|
|
54
|
+
button: true,
|
|
55
|
+
command: 'npm create astro@latest',
|
|
56
|
+
code: 'off',
|
|
57
|
+
glow: false,
|
|
58
|
+
},
|
|
59
|
+
variants: heroVariants,
|
|
60
|
+
defaultVariant: 'split',
|
|
61
|
+
options: [
|
|
62
|
+
{ name: 'button', label: 'Primary button', type: 'boolean', default: true },
|
|
63
|
+
{ name: 'code', label: 'Install command', type: 'enum', choices: heroCodeStyles, default: 'off' },
|
|
64
|
+
{ name: 'glow', label: 'Background glow', type: 'boolean', default: false },
|
|
65
|
+
],
|
|
66
|
+
optional: { props: ['eyebrow', 'heading', 'sub', 'badge', 'primary', 'secondary', 'command', 'image'] },
|
|
67
|
+
showWhen: {
|
|
68
|
+
badge: { variant: ['split', 'centered'] },
|
|
69
|
+
primary: { button: true },
|
|
70
|
+
secondary: { code: ['off', 'chip', 'terminal'] },
|
|
71
|
+
command: { code: ['action', 'chip', 'terminal'] },
|
|
72
|
+
},
|
|
73
|
+
wireframe: heroWireframe,
|
|
74
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineWireframe } from 'bearminion'
|
|
2
|
+
|
|
3
|
+
/** Add section picker thumbnail: [left %, top %, width %, height %, kind]. */
|
|
4
|
+
export const heroWireframe = defineWireframe([
|
|
5
|
+
[8, 18, 22, 6, 'text'],
|
|
6
|
+
[8, 30, 40, 9, 'title'],
|
|
7
|
+
[8, 43, 30, 9, 'title'],
|
|
8
|
+
[8, 58, 36, 5, 'text'],
|
|
9
|
+
[8, 72, 16, 10, 'button'],
|
|
10
|
+
[26, 72, 14, 10, 'outline'],
|
|
11
|
+
[56, 14, 36, 72, 'block'],
|
|
12
|
+
])
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { Section } from '../definitions'
|
|
3
|
+
import Image from '../../atoms/Image.astro'
|
|
4
|
+
import { isRemote, resolveLocalAsset } from '../../../lib/assets'
|
|
5
|
+
import SectionShell from '../../molecules/SectionShell.astro'
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
section: Extract<Section, { type: 'logoStrip' }>
|
|
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
|
+
|
|
18
|
+
function showImage(src: string) {
|
|
19
|
+
if (src === 'placeholder') return false
|
|
20
|
+
if (isRemote(src)) return true
|
|
21
|
+
if (src.replace(/^\//, '').startsWith('src/assets/') && !resolveLocalAsset(src)) {
|
|
22
|
+
throw new Error(`No file in src/assets for image path "${src}". Restore the file, or choose another image in the editor and save.`)
|
|
23
|
+
}
|
|
24
|
+
return Boolean(resolveLocalAsset(src))
|
|
25
|
+
}
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
<SectionShell id={section.id} anchor={section.anchor} type={section.type} variant={section.variant} tone={section.tone} motion={reveal} reveal="16">
|
|
29
|
+
{
|
|
30
|
+
section.variant === 'row' && (
|
|
31
|
+
<div class="mx-auto flex max-w-[80rem] flex-wrap items-center gap-8 px-[clamp(1.25rem,4cqi,3rem)] py-10">
|
|
32
|
+
{props.label && (
|
|
33
|
+
<p class="max-w-[13rem] flex-[0_1_13rem] font-mono text-[0.75rem] tracking-[0.04em] text-muted uppercase" data-field={field('label')}>
|
|
34
|
+
{props.label}
|
|
35
|
+
</p>
|
|
36
|
+
)}
|
|
37
|
+
<ul class="flex min-w-[min(100%,30rem)] flex-[1_1_30rem] flex-wrap items-center justify-between gap-x-6 gap-y-4">
|
|
38
|
+
{props.logos.map((logo, logoIndex) => (
|
|
39
|
+
<li class="flex h-9 min-w-[7.5rem] items-center justify-center" data-field={field(`logos.${logoIndex}.alt`)}>
|
|
40
|
+
{showImage(logo.src) ? (
|
|
41
|
+
<Image src={logo.src} alt={logo.alt} class="h-9 w-auto" widths={[120, 240]} sizes="120px" />
|
|
42
|
+
) : (
|
|
43
|
+
<span class="font-mono text-[0.75rem] tracking-[0.08em] text-muted uppercase">
|
|
44
|
+
{logo.alt}
|
|
45
|
+
</span>
|
|
46
|
+
)}
|
|
47
|
+
</li>
|
|
48
|
+
))}
|
|
49
|
+
</ul>
|
|
50
|
+
</div>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
{
|
|
54
|
+
section.variant === 'grid' && (
|
|
55
|
+
<div class="mx-auto max-w-[80rem] px-[clamp(1.25rem,4cqi,3rem)] py-12">
|
|
56
|
+
{props.label && (
|
|
57
|
+
<p class="mb-8 text-center font-mono text-[0.75rem] tracking-[0.08em] text-muted uppercase" data-field={field('label')}>
|
|
58
|
+
{props.label}
|
|
59
|
+
</p>
|
|
60
|
+
)}
|
|
61
|
+
<ul class="grid grid-cols-[repeat(auto-fit,minmax(min(100%,10rem),1fr))] gap-px bg-[var(--line)] ring-line">
|
|
62
|
+
{props.logos.map((logo, logoIndex) => (
|
|
63
|
+
<li class="flex h-20 items-center justify-center bg-bg transition-colors hover:bg-surface" data-field={field(`logos.${logoIndex}.alt`)}>
|
|
64
|
+
{showImage(logo.src) ? (
|
|
65
|
+
<Image src={logo.src} alt={logo.alt} class="h-9 w-auto" widths={[120, 240]} sizes="120px" />
|
|
66
|
+
) : (
|
|
67
|
+
<span class="font-mono text-[0.75rem] tracking-[0.08em] text-muted uppercase">
|
|
68
|
+
{logo.alt}
|
|
69
|
+
</span>
|
|
70
|
+
)}
|
|
71
|
+
</li>
|
|
72
|
+
))}
|
|
73
|
+
</ul>
|
|
74
|
+
</div>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
{
|
|
78
|
+
section.variant === 'marquee' && (
|
|
79
|
+
<div class="mx-auto max-w-[80rem] px-[clamp(1.25rem,4cqi,3rem)] py-12">
|
|
80
|
+
{props.label && (
|
|
81
|
+
<p class="mb-8 text-center font-mono text-[0.75rem] tracking-[0.08em] text-muted uppercase" data-field={field('label')}>
|
|
82
|
+
{props.label}
|
|
83
|
+
</p>
|
|
84
|
+
)}
|
|
85
|
+
<div class="bm-marquee-mask overflow-hidden">
|
|
86
|
+
<ul class="bm-marquee flex w-max items-center">
|
|
87
|
+
{[...props.logos, ...props.logos].map((logo, logoIndex) => (
|
|
88
|
+
<li
|
|
89
|
+
class="flex h-9 w-40 shrink-0 items-center justify-center"
|
|
90
|
+
aria-hidden={logoIndex >= props.logos.length ? 'true' : undefined}
|
|
91
|
+
data-field={field(`logos.${logoIndex % props.logos.length}.alt`)}
|
|
92
|
+
>
|
|
93
|
+
{showImage(logo.src) ? (
|
|
94
|
+
<Image src={logo.src} alt={logoIndex >= props.logos.length ? '' : logo.alt} class="h-9 w-auto" widths={[120, 240]} sizes="120px" />
|
|
95
|
+
) : (
|
|
96
|
+
<span class="font-mono text-[0.75rem] tracking-[0.08em] text-muted uppercase">
|
|
97
|
+
{logo.alt}
|
|
98
|
+
</span>
|
|
99
|
+
)}
|
|
100
|
+
</li>
|
|
101
|
+
))}
|
|
102
|
+
</ul>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
</SectionShell>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { defineSection, imageSchema, textSchema } from 'bearminion'
|
|
3
|
+
import { logoStripWireframe } from './wireframe'
|
|
4
|
+
|
|
5
|
+
export const logoStripVariants = ['row', 'grid', 'marquee'] as const
|
|
6
|
+
|
|
7
|
+
export const logoStripSchema = z
|
|
8
|
+
.object({
|
|
9
|
+
label: textSchema.optional(),
|
|
10
|
+
logos: z.array(imageSchema).min(1),
|
|
11
|
+
})
|
|
12
|
+
.strict()
|
|
13
|
+
|
|
14
|
+
export type LogoStripProps = z.infer<typeof logoStripSchema>
|
|
15
|
+
|
|
16
|
+
export const logoStrip = defineSection({
|
|
17
|
+
type: 'logoStrip',
|
|
18
|
+
label: 'Logo strip',
|
|
19
|
+
description: 'A row of customer or partner logos.',
|
|
20
|
+
schema: logoStripSchema,
|
|
21
|
+
defaults: {
|
|
22
|
+
label: 'Trusted by teams like yours',
|
|
23
|
+
logos: [1, 2, 3, 4, 5, 6].map((n) => ({ src: 'placeholder', alt: `Partner logo ${n}` })),
|
|
24
|
+
},
|
|
25
|
+
variants: logoStripVariants,
|
|
26
|
+
defaultVariant: 'row',
|
|
27
|
+
optional: { props: ['label'] },
|
|
28
|
+
counts: { logos: { recommended: 6 } },
|
|
29
|
+
wireframe: logoStripWireframe,
|
|
30
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineWireframe } from 'bearminion'
|
|
2
|
+
|
|
3
|
+
/** Add section picker thumbnail: [left %, top %, width %, height %, kind]. */
|
|
4
|
+
export const logoStripWireframe = defineWireframe([
|
|
5
|
+
[20, 22, 60, 5, 'text'],
|
|
6
|
+
[6, 46, 14, 14, 'block'],
|
|
7
|
+
[24, 46, 14, 14, 'block'],
|
|
8
|
+
[42, 46, 14, 14, 'block'],
|
|
9
|
+
[60, 46, 14, 14, 'block'],
|
|
10
|
+
[78, 46, 14, 14, 'block'],
|
|
11
|
+
])
|
|
@@ -0,0 +1,118 @@
|
|
|
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 MediaPlayer from './MediaPlayer.astro'
|
|
7
|
+
import { parseMediaSource } from './source'
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
section: Extract<Section, { type: 'media' }>
|
|
11
|
+
index: number
|
|
12
|
+
motion?: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const { section, index, motion = true } = Astro.props
|
|
16
|
+
const props = section.props
|
|
17
|
+
const field = (path: string) => `sections.${index}.props.${path}`
|
|
18
|
+
const reveal = section.motion ?? motion
|
|
19
|
+
const intro = props.intro && Boolean(props.eyebrow || props.heading || props.body)
|
|
20
|
+
const filled = props.kind === 'video' ? Boolean(props.video && parseMediaSource(props.video)) : Boolean(props.image?.src && props.image.src !== 'placeholder' && !props.image.hidden)
|
|
21
|
+
// A built site leaves out an empty frame, and with no heading either, the whole section.
|
|
22
|
+
const showFrame = filled || import.meta.env.DEV
|
|
23
|
+
const rendered = showFrame || intro
|
|
24
|
+
const player = {
|
|
25
|
+
kind: props.kind,
|
|
26
|
+
aspect: props.aspect,
|
|
27
|
+
video: props.video,
|
|
28
|
+
poster: props.poster,
|
|
29
|
+
image: props.image,
|
|
30
|
+
label: props.label,
|
|
31
|
+
playback: props.playback,
|
|
32
|
+
imageField: field('image.alt'),
|
|
33
|
+
// The first two sections are usually on screen at load, where a lazy cover would hold back the largest paint.
|
|
34
|
+
eager: index <= 1,
|
|
35
|
+
}
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
{rendered && (<SectionShell id={section.id} anchor={section.anchor} type={section.type} variant={section.variant} tone={section.tone} motion={reveal}>
|
|
39
|
+
{
|
|
40
|
+
section.variant === 'centered' && (
|
|
41
|
+
<div
|
|
42
|
+
class:list={[
|
|
43
|
+
'mx-auto flex max-w-[80rem] flex-col items-center gap-5 px-[clamp(1.25rem,4cqi,3rem)] pb-[clamp(4rem,2rem+6cqi,8rem)] text-center',
|
|
44
|
+
intro && 'pt-[clamp(4rem,2rem+6cqi,8rem)]',
|
|
45
|
+
]}
|
|
46
|
+
>
|
|
47
|
+
{intro && (
|
|
48
|
+
<SectionHeader
|
|
49
|
+
eyebrow={props.eyebrow}
|
|
50
|
+
heading={props.heading}
|
|
51
|
+
marks={props.marks}
|
|
52
|
+
intro={props.body}
|
|
53
|
+
introField="body"
|
|
54
|
+
align="center"
|
|
55
|
+
size="h2-md"
|
|
56
|
+
field={field}
|
|
57
|
+
headingClass="max-w-[20ch]"
|
|
58
|
+
class="gap-5"
|
|
59
|
+
/>
|
|
60
|
+
)}
|
|
61
|
+
{showFrame && (<figure class:list={['flex w-full flex-col gap-3', intro ? 'mt-[clamp(1.5rem,3cqi,2.5rem)] max-w-[56rem]' : 'max-w-[68rem]']}>
|
|
62
|
+
<MediaPlayer {...player} />
|
|
63
|
+
{props.caption && (
|
|
64
|
+
<Typography as="figcaption" size="small" color="muted" data-field={field('caption')}>
|
|
65
|
+
{props.caption}
|
|
66
|
+
</Typography>
|
|
67
|
+
)}
|
|
68
|
+
</figure>)}
|
|
69
|
+
</div>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
{
|
|
73
|
+
section.variant === 'wide' && (
|
|
74
|
+
<div class="section-container flex flex-col gap-[clamp(2rem,4cqi,3.5rem)]">
|
|
75
|
+
{intro && (
|
|
76
|
+
<div class="flex flex-wrap items-end justify-between gap-x-12 gap-y-5">
|
|
77
|
+
<SectionHeader eyebrow={props.eyebrow} heading={props.heading} marks={props.marks} size="h2-md" field={field} headingClass="max-w-[16ch]" class="flex-[1_1_24rem] gap-5" />
|
|
78
|
+
{props.body && <Typography as="p" size="lead" color="muted" data-field={field('body')} class="flex-[0_1_26rem]" markdown={props.body} />}
|
|
79
|
+
</div>
|
|
80
|
+
)}
|
|
81
|
+
{showFrame && (<figure class="flex flex-col gap-3">
|
|
82
|
+
<MediaPlayer {...player} />
|
|
83
|
+
{props.caption && (
|
|
84
|
+
<Typography as="figcaption" size="small" color="muted" data-field={field('caption')}>
|
|
85
|
+
{props.caption}
|
|
86
|
+
</Typography>
|
|
87
|
+
)}
|
|
88
|
+
</figure>)}
|
|
89
|
+
</div>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
{
|
|
93
|
+
section.variant === 'split' && (
|
|
94
|
+
<div class="section-container grid grid-cols-[repeat(auto-fit,minmax(min(100%,22rem),1fr))] items-center gap-[clamp(2.5rem,5cqi,5rem)]">
|
|
95
|
+
{intro && (
|
|
96
|
+
<SectionHeader
|
|
97
|
+
eyebrow={props.eyebrow}
|
|
98
|
+
heading={props.heading}
|
|
99
|
+
marks={props.marks}
|
|
100
|
+
intro={props.body}
|
|
101
|
+
introField="body"
|
|
102
|
+
size="h2-md"
|
|
103
|
+
field={field}
|
|
104
|
+
class="gap-5"
|
|
105
|
+
/>
|
|
106
|
+
)}
|
|
107
|
+
{showFrame && (<figure class:list={['flex flex-col gap-3', !intro && 'col-span-full']}>
|
|
108
|
+
<MediaPlayer {...player} />
|
|
109
|
+
{props.caption && (
|
|
110
|
+
<Typography as="figcaption" size="small" color="muted" data-field={field('caption')}>
|
|
111
|
+
{props.caption}
|
|
112
|
+
</Typography>
|
|
113
|
+
)}
|
|
114
|
+
</figure>)}
|
|
115
|
+
</div>
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
</SectionShell>)}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { Image } from 'bearminion'
|
|
3
|
+
import { imageSrcset, imageUrl } from '../../../lib/image-url'
|
|
4
|
+
import { cn } from '../../../lib/cn'
|
|
5
|
+
import MediaFrame from '../../molecules/MediaFrame.astro'
|
|
6
|
+
import type { MediaProps } from './definition'
|
|
7
|
+
import { parseMediaSource } from './source'
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
kind: MediaProps['kind']
|
|
11
|
+
aspect: MediaProps['aspect']
|
|
12
|
+
video?: string
|
|
13
|
+
poster?: Image
|
|
14
|
+
image?: Image
|
|
15
|
+
label?: string
|
|
16
|
+
playback?: MediaProps['playback']
|
|
17
|
+
/** `data-field` path for the image, so a click on the frame opens the image picker. */
|
|
18
|
+
imageField: string
|
|
19
|
+
/** Near the top of the page: the cover loads at once instead of lazily, since it is likely the largest thing on screen. */
|
|
20
|
+
eager?: boolean
|
|
21
|
+
class?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const { kind, aspect, video, poster, image, label, playback = 'controls', imageField, eager = false, class: className } = Astro.props
|
|
25
|
+
const ASPECT = { '16:9': 'aspect-video', '4:3': 'aspect-[4/3]', '21:9': 'aspect-[21/9]', '1:1': 'aspect-square' } as const
|
|
26
|
+
const frame = cn(
|
|
27
|
+
'relative w-full min-h-48 overflow-hidden rounded-[clamp(1rem,2cqi,1.5rem)] bg-surface shadow-[inset_0_0_0_1px_var(--line),0_40px_80px_-48px_oklch(0.2_0.02_255/0.35)]',
|
|
28
|
+
ASPECT[aspect],
|
|
29
|
+
className,
|
|
30
|
+
)
|
|
31
|
+
const source = kind === 'video' && video ? parseMediaSource(video) : null
|
|
32
|
+
const hasImage = kind === 'image' && Boolean(image?.src) && image?.src !== 'placeholder' && !image?.hidden
|
|
33
|
+
const empty = kind === 'video' ? !source : !hasImage
|
|
34
|
+
const cover = source ? ((await imageUrl(poster)) ?? (source.kind === 'youtube' ? source.thumbnail : undefined)) : undefined
|
|
35
|
+
const coverSrcset = source ? await imageSrcset(poster) : undefined
|
|
36
|
+
// The frame is at most 68rem wide and the full width of a phone.
|
|
37
|
+
const coverSizes = '(min-width: 72rem) 68rem, 100vw'
|
|
38
|
+
const name = label || 'Video'
|
|
39
|
+
// A video file on loop starts muted and without controls once the page script sees it on screen. Until then, and without
|
|
40
|
+
// JavaScript or with reduced motion, it keeps its controls so it can still be played.
|
|
41
|
+
const looping = source?.kind === 'file' && playback === 'loop'
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
empty ? (
|
|
46
|
+
// The empty frame is an editor hint, so a built site leaves it out.
|
|
47
|
+
import.meta.env.DEV && (
|
|
48
|
+
<div class={cn(frame, 'placeholder-stripes flex flex-col items-center justify-center gap-4 p-6 text-center')} data-field={kind === 'image' ? imageField : undefined}>
|
|
49
|
+
{kind === 'video' && (
|
|
50
|
+
<span class="flex size-14 items-center justify-center rounded-full bg-fg text-bg" aria-hidden="true">
|
|
51
|
+
<svg viewBox="0 0 24 24" class="ms-0.5 size-[18px]" fill="currentColor"><path d="M8 5.5v13l11-6.5z" /></svg>
|
|
52
|
+
</span>
|
|
53
|
+
)}
|
|
54
|
+
<span class="font-mono text-[0.75rem] tracking-[0.02em] text-muted">
|
|
55
|
+
{kind === 'video' ? 'Add a video link in the section settings' : 'Add an image in the section settings'}
|
|
56
|
+
</span>
|
|
57
|
+
</div>
|
|
58
|
+
)
|
|
59
|
+
) : kind === 'image' && image ? (
|
|
60
|
+
<MediaFrame
|
|
61
|
+
src={image.src}
|
|
62
|
+
alt={image.alt}
|
|
63
|
+
fit={image.fit === 'auto' ? 'cover' : image.fit}
|
|
64
|
+
position={image.position}
|
|
65
|
+
aspectClass={cn(ASPECT[aspect], 'min-h-48 w-full p-0')}
|
|
66
|
+
roundedClass="rounded-[clamp(1rem,2cqi,1.5rem)]"
|
|
67
|
+
class="shadow-[inset_0_0_0_1px_var(--line),0_40px_80px_-48px_oklch(0.2_0.02_255/0.35)]"
|
|
68
|
+
data-field={imageField}
|
|
69
|
+
/>
|
|
70
|
+
) : looping && source?.kind === 'file' ? (
|
|
71
|
+
<div class={frame}>
|
|
72
|
+
<video class="absolute inset-0 size-full object-cover" src={source.src} poster={cover} preload="metadata" playsinline muted loop controls aria-label={name} data-video-loop />
|
|
73
|
+
</div>
|
|
74
|
+
) : (
|
|
75
|
+
source && (
|
|
76
|
+
<div
|
|
77
|
+
class={frame}
|
|
78
|
+
data-media-player
|
|
79
|
+
data-kind={source.kind}
|
|
80
|
+
data-src={source.kind === 'file' ? source.src : source.embed}
|
|
81
|
+
data-label={name}
|
|
82
|
+
data-poster={source.kind === 'file' ? cover : undefined}
|
|
83
|
+
>
|
|
84
|
+
{cover && (
|
|
85
|
+
<img
|
|
86
|
+
src={cover}
|
|
87
|
+
srcset={coverSrcset}
|
|
88
|
+
sizes={coverSrcset ? coverSizes : undefined}
|
|
89
|
+
alt=""
|
|
90
|
+
class="absolute inset-0 size-full object-cover"
|
|
91
|
+
loading={eager ? 'eager' : 'lazy'}
|
|
92
|
+
decoding="async"
|
|
93
|
+
/>
|
|
94
|
+
)}
|
|
95
|
+
<button
|
|
96
|
+
type="button"
|
|
97
|
+
class="group absolute inset-0 grid cursor-pointer place-items-center bg-[oklch(0.15_0.01_255/0.12)] transition-colors hover:bg-[oklch(0.15_0.01_255/0.22)] focus-visible:outline-2 focus-visible:outline-offset-[-4px] focus-visible:outline-accent"
|
|
98
|
+
aria-label={`Play video: ${name}`}
|
|
99
|
+
data-media-play
|
|
100
|
+
>
|
|
101
|
+
<span class="grid size-16 place-items-center rounded-full bg-fg text-bg shadow-[0_12px_32px_-12px_oklch(0.15_0.02_255/0.6)] transition-transform group-hover:scale-105">
|
|
102
|
+
<svg viewBox="0 0 24 24" class="ms-0.5 size-5" fill="currentColor" aria-hidden="true"><path d="M8 5.5v13l11-6.5z" /></svg>
|
|
103
|
+
</span>
|
|
104
|
+
</button>
|
|
105
|
+
</div>
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
<script>
|
|
111
|
+
/**
|
|
112
|
+
* Nothing is loaded from YouTube, Vimeo or the video file until the visitor presses play. Then the button and cover
|
|
113
|
+
* are swapped for the player, which starts at once.
|
|
114
|
+
*/
|
|
115
|
+
function play(frame: HTMLElement) {
|
|
116
|
+
const src = frame.dataset.src
|
|
117
|
+
if (!src) return
|
|
118
|
+
const label = frame.dataset.label ?? 'Video'
|
|
119
|
+
let player: HTMLElement
|
|
120
|
+
if (frame.dataset.kind === 'file') {
|
|
121
|
+
const video = document.createElement('video')
|
|
122
|
+
video.src = src
|
|
123
|
+
if (frame.dataset.poster) video.poster = frame.dataset.poster
|
|
124
|
+
video.controls = true
|
|
125
|
+
video.autoplay = true
|
|
126
|
+
video.playsInline = true
|
|
127
|
+
video.setAttribute('aria-label', label)
|
|
128
|
+
video.className = 'absolute inset-0 size-full bg-black object-contain'
|
|
129
|
+
player = video
|
|
130
|
+
} else {
|
|
131
|
+
const iframe = document.createElement('iframe')
|
|
132
|
+
iframe.src = src
|
|
133
|
+
iframe.title = label
|
|
134
|
+
iframe.allow = 'autoplay; fullscreen; picture-in-picture; encrypted-media'
|
|
135
|
+
iframe.allowFullscreen = true
|
|
136
|
+
iframe.referrerPolicy = 'strict-origin-when-cross-origin'
|
|
137
|
+
iframe.className = 'absolute inset-0 size-full border-0'
|
|
138
|
+
player = iframe
|
|
139
|
+
}
|
|
140
|
+
frame.replaceChildren(player)
|
|
141
|
+
player.focus()
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function bindMediaPlayers() {
|
|
145
|
+
for (const button of document.querySelectorAll<HTMLButtonElement>('[data-media-play]')) {
|
|
146
|
+
if (button.dataset.bound === 'true') continue
|
|
147
|
+
button.dataset.bound = 'true'
|
|
148
|
+
button.addEventListener('click', () => {
|
|
149
|
+
const frame = button.closest<HTMLElement>('[data-media-player]')
|
|
150
|
+
if (frame) play(frame)
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
bindMediaPlayers()
|
|
155
|
+
document.addEventListener('bearminion:preview', bindMediaPlayers)
|
|
156
|
+
|
|
157
|
+
/** Looping videos play while at least a quarter of them is on screen, and not at all with reduced motion. */
|
|
158
|
+
function bindLoopingVideos() {
|
|
159
|
+
const reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
160
|
+
for (const video of document.querySelectorAll<HTMLVideoElement>('video[data-video-loop]')) {
|
|
161
|
+
if (video.dataset.bound === 'true') continue
|
|
162
|
+
video.dataset.bound = 'true'
|
|
163
|
+
if (reduced) continue
|
|
164
|
+
video.controls = false
|
|
165
|
+
new IntersectionObserver(
|
|
166
|
+
([entry]) => {
|
|
167
|
+
if (entry?.isIntersecting) void video.play().catch(() => (video.controls = true))
|
|
168
|
+
else video.pause()
|
|
169
|
+
},
|
|
170
|
+
{ threshold: 0.25 },
|
|
171
|
+
).observe(video)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
bindLoopingVideos()
|
|
175
|
+
document.addEventListener('bearminion:preview', bindLoopingVideos)
|
|
176
|
+
</script>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { defineSection, imageSchema, richTextSchema, textSchema, withEmphasis } from 'bearminion'
|
|
3
|
+
import { accent, eyebrow, heading } from '../shared'
|
|
4
|
+
import { parseMediaSource } from './source'
|
|
5
|
+
import { mediaWireframe } from './wireframe'
|
|
6
|
+
|
|
7
|
+
export const mediaVariants = ['centered', 'wide', 'split'] as const
|
|
8
|
+
export const mediaKinds = ['video', 'image'] as const
|
|
9
|
+
/** `controls`: the visitor presses play. `loop`: a video file plays silently on repeat while it is on screen, like a moving image. */
|
|
10
|
+
export const mediaPlayback = ['controls', 'loop'] as const
|
|
11
|
+
export const mediaAspects = ['16:9', '4:3', '21:9', '1:1'] as const
|
|
12
|
+
|
|
13
|
+
/** A YouTube or Vimeo link, a path in `public/` such as `/videos/demo.webm`, or an `https://` link to a video file. */
|
|
14
|
+
export const mediaVideoSchema = z
|
|
15
|
+
.string()
|
|
16
|
+
.min(1)
|
|
17
|
+
.refine((value) => parseMediaSource(value) !== null, {
|
|
18
|
+
message: 'Use a YouTube or Vimeo link, a link to a video file ending in .mp4 or .webm, or a path in public/ such as /videos/demo.webm.',
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export const mediaSchema = withEmphasis({
|
|
22
|
+
eyebrow,
|
|
23
|
+
heading,
|
|
24
|
+
body: richTextSchema.optional(),
|
|
25
|
+
/** `video` plays the link in `video`; `image` shows `image`. */
|
|
26
|
+
kind: z.enum(mediaKinds).default('video'),
|
|
27
|
+
aspect: z.enum(mediaAspects).default('16:9'),
|
|
28
|
+
/** Off: no eyebrow, heading or body, and in the centered layout a wider frame with no top padding. */
|
|
29
|
+
intro: z.boolean().default(true),
|
|
30
|
+
video: mediaVideoSchema.optional(),
|
|
31
|
+
/** Shown before the video plays. Without one, a YouTube video shows its own thumbnail. */
|
|
32
|
+
poster: imageSchema.optional(),
|
|
33
|
+
image: imageSchema.optional(),
|
|
34
|
+
/** What the video shows, read out by screen readers. An image uses its own alt text. */
|
|
35
|
+
label: textSchema.optional(),
|
|
36
|
+
caption: textSchema.optional(),
|
|
37
|
+
playback: z.enum(mediaPlayback).default('controls'),
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
export type MediaProps = z.infer<typeof mediaSchema>
|
|
41
|
+
|
|
42
|
+
export const media = defineSection({
|
|
43
|
+
type: 'media',
|
|
44
|
+
label: 'Media',
|
|
45
|
+
description: 'One video or image under a heading. YouTube, Vimeo or a video file, with a poster and a caption.',
|
|
46
|
+
schema: mediaSchema,
|
|
47
|
+
defaults: {
|
|
48
|
+
eyebrow: 'Demo',
|
|
49
|
+
heading: 'See it in action.',
|
|
50
|
+
marks: accent('See it in action.', 'in action.'),
|
|
51
|
+
body: 'Paste a YouTube or Vimeo link, or a link to a video file. Nothing loads until the visitor presses play.',
|
|
52
|
+
kind: 'video',
|
|
53
|
+
aspect: '16:9',
|
|
54
|
+
intro: true,
|
|
55
|
+
label: 'Product walkthrough',
|
|
56
|
+
playback: 'controls',
|
|
57
|
+
},
|
|
58
|
+
variants: mediaVariants,
|
|
59
|
+
defaultVariant: 'centered',
|
|
60
|
+
options: [
|
|
61
|
+
{ name: 'kind', label: 'Type', type: 'enum', choices: mediaKinds, default: 'video' },
|
|
62
|
+
{ name: 'aspect', label: 'Shape', type: 'enum', choices: mediaAspects, default: '16:9' },
|
|
63
|
+
{ name: 'playback', label: 'Video playback', type: 'enum', choices: mediaPlayback, default: 'controls' },
|
|
64
|
+
{ name: 'intro', label: 'Show heading', type: 'boolean', default: true },
|
|
65
|
+
],
|
|
66
|
+
optional: { props: ['eyebrow', 'heading', 'body', 'video', 'poster', 'image', 'label', 'caption'] },
|
|
67
|
+
showWhen: {
|
|
68
|
+
eyebrow: { intro: true },
|
|
69
|
+
heading: { intro: true },
|
|
70
|
+
body: { intro: true },
|
|
71
|
+
video: { kind: 'video' },
|
|
72
|
+
poster: { kind: 'video' },
|
|
73
|
+
label: { kind: 'video' },
|
|
74
|
+
image: { kind: 'image' },
|
|
75
|
+
},
|
|
76
|
+
wireframe: mediaWireframe,
|
|
77
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineWireframe } from 'bearminion'
|
|
2
|
+
|
|
3
|
+
/** Add section picker thumbnail: [left %, top %, width %, height %, kind]. */
|
|
4
|
+
export const mediaWireframe = defineWireframe([
|
|
5
|
+
[32, 8, 36, 7, 'title'],
|
|
6
|
+
[26, 19, 48, 4, 'text'],
|
|
7
|
+
[14, 30, 72, 60, 'figure'],
|
|
8
|
+
[44, 52, 12, 16, 'dark'],
|
|
9
|
+
])
|