create-bearminion 1.5.0 → 1.7.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +5 -3
  3. package/package.json +2 -2
  4. package/template/.env.example +18 -0
  5. package/template/README.md +8 -2
  6. package/template/astro.config.ts +25 -0
  7. package/template/package.json +1 -1
  8. package/template/src/components/atoms/Typography.astro +5 -2
  9. package/template/src/components/sections/SectionList.astro +6 -3
  10. package/template/src/components/sections/contact/Contact.astro +45 -46
  11. package/template/src/components/sections/contact/definition.ts +2 -2
  12. package/template/src/components/sections/contact/form.ts +296 -0
  13. package/template/src/components/sections/definitions.ts +4 -2
  14. package/template/src/components/sections/gallery/Gallery.astro +128 -0
  15. package/template/src/components/sections/gallery/Gallery.stories.ts +24 -0
  16. package/template/src/components/sections/gallery/definition.ts +59 -0
  17. package/template/src/components/sections/gallery/lightbox.ts +159 -0
  18. package/template/src/components/sections/gallery/wireframe.ts +12 -0
  19. package/template/src/components/sections/media/Media.astro +1 -0
  20. package/template/src/components/sections/media/MediaPlayer.astro +29 -1
  21. package/template/src/components/sections/media/definition.ts +6 -1
  22. package/template/src/components/sections/media/source.ts +3 -33
  23. package/template/src/components/sections/registry.ts +4 -2
  24. package/template/src/components/sections/text/Text.astro +43 -0
  25. package/template/src/components/sections/text/Text.stories.ts +17 -0
  26. package/template/src/components/sections/text/definition.ts +36 -0
  27. package/template/src/components/sections/text/wireframe.ts +12 -0
  28. package/template/src/layouts/Base.astro +17 -0
  29. package/template/src/lib/contact-form.ts +97 -0
  30. package/template/src/lib/content-model.ts +5 -1
  31. package/template/src/lib/form-check.ts +38 -0
  32. package/template/src/lib/migrations.ts +44 -0
  33. package/template/src/styles/global.css +243 -0
  34. package/template/src/components/sections/video/Video.astro +0 -78
  35. package/template/src/components/sections/video/Video.stories.ts +0 -17
  36. package/template/src/components/sections/video/VideoFrame.astro +0 -60
  37. package/template/src/components/sections/video/definition.ts +0 -58
  38. package/template/src/components/sections/video/wireframe.ts +0 -9
@@ -0,0 +1,44 @@
1
+ import type { ContentMigration } from 'bearminion'
2
+
3
+ type Record_ = Record<string, unknown>
4
+ const isRecord = (value: unknown): value is Record_ => typeof value === 'object' && value !== null && !Array.isArray(value)
5
+
6
+ /** The old Video section's layouts, as the Media section names them. */
7
+ const VARIANT: Record<string, string> = { framed: 'centered', wide: 'wide', split: 'split' }
8
+
9
+ /** A Video section is a Media section of kind `video`: its `intro` is the Media `body`, and an empty placeholder frame is no link. */
10
+ export function videoToMedia(section: Record_): Record_ {
11
+ const { intro, video, playback, ...rest } = isRecord(section.props) ? section.props : ({} as Record_)
12
+ const props: Record_ = { ...rest, kind: 'video' }
13
+ if (intro !== undefined) props.body = intro
14
+ if (typeof video === 'string' && video !== 'placeholder') props.video = video
15
+ if (playback === 'loop') props.playback = 'loop'
16
+ const variant = typeof section.variant === 'string' ? (VARIANT[section.variant] ?? 'centered') : 'centered'
17
+ return { ...section, type: 'media', variant, props }
18
+ }
19
+
20
+ /** Version 1 to 2: the Video section is folded into Media. */
21
+ export const migrateVideoToMedia: ContentMigration = (document, kind) => {
22
+ if (kind !== 'page' || !Array.isArray(document.sections)) return document
23
+ return {
24
+ ...document,
25
+ sections: document.sections.map((section) => (isRecord(section) && section.type === 'video' ? videoToMedia(section) : section)),
26
+ }
27
+ }
28
+
29
+ /** Form settings the Contact section used to keep in the content file. The form now posts to `/api/contact`; the rest lives in code and the environment. */
30
+ const CONTACT_FORM_SETTINGS = ['action', 'turnstile', 'format'] as const
31
+
32
+ /** Version 2 to 3: a Contact section no longer stores its endpoint, Turnstile key or format. */
33
+ export const migrateContactFormSettings: ContentMigration = (document, kind) => {
34
+ if (kind !== 'page' || !Array.isArray(document.sections)) return document
35
+ return {
36
+ ...document,
37
+ sections: document.sections.map((section) => {
38
+ if (!isRecord(section) || section.type !== 'contact' || !isRecord(section.props)) return section
39
+ const props = { ...section.props }
40
+ for (const key of CONTACT_FORM_SETTINGS) delete props[key]
41
+ return { ...section, props }
42
+ }),
43
+ }
44
+ }
@@ -229,6 +229,31 @@
229
229
  color: var(--fg);
230
230
  white-space: nowrap;
231
231
  }
232
+ /* Headings in long-form text (the Text section). Sized for reading, below the section heading. */
233
+ [data-rich-headings="true"] h2,
234
+ [data-rich-headings="true"] h3 {
235
+ color: var(--fg);
236
+ font-weight: 600;
237
+ text-wrap: balance;
238
+ }
239
+ [data-rich-headings="true"] h2 {
240
+ margin: 1.75em 0 0.5em;
241
+ font-size: 1.625em;
242
+ line-height: 1.15;
243
+ letter-spacing: -0.03em;
244
+ }
245
+ [data-rich-headings="true"] h3 {
246
+ margin: 1.5em 0 0.4em;
247
+ font-size: 1.25em;
248
+ line-height: 1.25;
249
+ letter-spacing: -0.02em;
250
+ }
251
+ [data-rich-headings="true"] > :first-child {
252
+ margin-top: 0;
253
+ }
254
+ [data-rich-headings="true"] :is(h2, h3) + p {
255
+ margin-top: 0;
256
+ }
232
257
  blockquote[data-field-kind="rich"]::before {
233
258
  content: "“";
234
259
  }
@@ -306,6 +331,88 @@
306
331
  outline: none;
307
332
  box-shadow: inset 0 0 0 2px var(--link);
308
333
  }
334
+ /* Colour alone never says a field is wrong: it gets a heavier edge and a message in words. */
335
+ .bm-field[aria-invalid="true"] {
336
+ box-shadow: inset 0 0 0 2px var(--fg);
337
+ }
338
+ .bm-underline[aria-invalid="true"] {
339
+ border-bottom: 2px solid var(--fg);
340
+ }
341
+ .bm-form-error {
342
+ border-inline-start: 2px solid var(--fg);
343
+ padding-inline-start: 0.75rem;
344
+ font-size: 0.8125rem;
345
+ font-weight: 500;
346
+ line-height: 1.4;
347
+ }
348
+ .bm-form-error[hidden] {
349
+ display: none;
350
+ }
351
+ /* Shown by the form script after a send. Without JavaScript the page's own :target rules show them (Base.astro). */
352
+ [data-contact-success],
353
+ [data-contact-failed] {
354
+ display: none;
355
+ }
356
+ [data-contact-success][data-shown] {
357
+ display: block;
358
+ }
359
+ /* A failed send stays on screen until the visitor closes it. */
360
+ .bm-toasts {
361
+ position: fixed;
362
+ inset: auto 1rem 1rem 1rem;
363
+ z-index: 2000;
364
+ width: auto;
365
+ height: auto;
366
+ margin: 0;
367
+ border: 0;
368
+ padding: 0;
369
+ overflow: visible;
370
+ background: transparent;
371
+ color: inherit;
372
+ display: flex;
373
+ flex-direction: column;
374
+ align-items: flex-end;
375
+ gap: 0.5rem;
376
+ pointer-events: none;
377
+ }
378
+ .bm-toast {
379
+ pointer-events: auto;
380
+ display: flex;
381
+ align-items: flex-start;
382
+ gap: 0.75rem;
383
+ max-width: min(26rem, 100%);
384
+ border-radius: var(--radius-field);
385
+ background: var(--fg);
386
+ padding: 0.875rem 0.5rem 0.875rem 1rem;
387
+ color: var(--bg);
388
+ font-size: 0.875rem;
389
+ font-weight: 500;
390
+ line-height: 1.45;
391
+ box-shadow: 0 0.5rem 2rem oklch(0 0 0 / 0.25);
392
+ }
393
+ .bm-toast-text {
394
+ flex: 1;
395
+ margin-block: 0.125rem;
396
+ }
397
+ .bm-toast-close {
398
+ flex: none;
399
+ display: grid;
400
+ place-items: center;
401
+ width: 2rem;
402
+ height: 2rem;
403
+ border-radius: var(--radius-chip);
404
+ font-size: 1.25rem;
405
+ line-height: 1;
406
+ color: inherit;
407
+ cursor: pointer;
408
+ }
409
+ .bm-toast-close:hover {
410
+ background: color-mix(in oklch, currentColor 18%, transparent);
411
+ }
412
+ .bm-toast-close:focus-visible {
413
+ outline: 2px solid var(--bg);
414
+ outline-offset: -2px;
415
+ }
309
416
  .bm-underline {
310
417
  width: 100%;
311
418
  border: 0;
@@ -320,6 +427,142 @@
320
427
  outline: none;
321
428
  border-bottom-color: var(--fg);
322
429
  }
430
+ /* The gallery lightbox: a native <dialog> over the whole screen, one picture at a time. */
431
+ .bm-lightbox {
432
+ /* 100%, not 100vw: vw counts the page scrollbar, which pushed the close button off the right edge. */
433
+ width: 100%;
434
+ max-width: none;
435
+ height: 100%;
436
+ max-height: none;
437
+ overscroll-behavior: contain;
438
+ margin: 0;
439
+ padding: 0;
440
+ border: 0;
441
+ background: rgb(0 0 0 / 0.94);
442
+ color: #fff;
443
+ overflow: hidden;
444
+ }
445
+ .bm-lightbox::backdrop {
446
+ background: rgb(0 0 0 / 0.94);
447
+ }
448
+ .bm-lightbox[open] {
449
+ display: block;
450
+ }
451
+ /* The page behind does not scroll while a picture is open. */
452
+ html:has(.bm-lightbox[open]) {
453
+ overflow: hidden;
454
+ }
455
+ .bm-lightbox-stage {
456
+ position: relative;
457
+ display: grid;
458
+ place-items: center;
459
+ width: 100%;
460
+ height: 100%;
461
+ padding: clamp(3.5rem, 8vh, 5rem) clamp(1rem, 9vw, 6.5rem);
462
+ touch-action: pan-y;
463
+ }
464
+ /* The picture takes whatever height the caption leaves, so a tall picture and a long caption both stay whole. */
465
+ .bm-lightbox-figure {
466
+ display: grid;
467
+ grid-template-rows: minmax(0, 1fr) auto;
468
+ justify-items: center;
469
+ gap: 0.875rem;
470
+ width: 100%;
471
+ height: 100%;
472
+ min-height: 0;
473
+ margin: 0;
474
+ }
475
+ .bm-lightbox-image {
476
+ display: block;
477
+ align-self: center;
478
+ max-width: 100%;
479
+ max-height: 100%;
480
+ min-height: 0;
481
+ width: auto;
482
+ height: auto;
483
+ object-fit: contain;
484
+ border-radius: 8px;
485
+ transition: opacity 0.2s ease;
486
+ }
487
+ .bm-lightbox[data-loading] .bm-lightbox-image {
488
+ opacity: 0;
489
+ }
490
+ .bm-lightbox-caption {
491
+ width: min(100%, 46rem);
492
+ font-size: 0.9375rem;
493
+ line-height: 1.5;
494
+ text-align: center;
495
+ color: rgb(255 255 255 / 0.82);
496
+ text-wrap: pretty;
497
+ max-height: 7.5rem;
498
+ overflow-y: auto;
499
+ }
500
+ .bm-lightbox-counter {
501
+ position: absolute;
502
+ top: 1.375rem;
503
+ left: 1.25rem;
504
+ font-family: var(--font-mono);
505
+ font-size: 0.75rem;
506
+ letter-spacing: 0.06em;
507
+ color: rgb(255 255 255 / 0.7);
508
+ }
509
+ .bm-lightbox-close,
510
+ .bm-lightbox-nav {
511
+ position: absolute;
512
+ display: grid;
513
+ place-items: center;
514
+ width: 2.75rem;
515
+ height: 2.75rem;
516
+ border-radius: 9999px;
517
+ background: rgb(255 255 255 / 0.12);
518
+ color: #fff;
519
+ cursor: pointer;
520
+ transition: background-color 0.15s ease;
521
+ }
522
+ .bm-lightbox-icon {
523
+ display: block;
524
+ width: 1.25rem;
525
+ height: 1.25rem;
526
+ fill: none;
527
+ stroke: currentColor;
528
+ stroke-width: 2;
529
+ stroke-linecap: round;
530
+ stroke-linejoin: round;
531
+ }
532
+ .bm-lightbox-close:hover,
533
+ .bm-lightbox-nav:hover {
534
+ background: rgb(255 255 255 / 0.24);
535
+ }
536
+ .bm-lightbox-close:focus-visible,
537
+ .bm-lightbox-nav:focus-visible {
538
+ outline: 2px solid #fff;
539
+ outline-offset: 2px;
540
+ }
541
+ .bm-lightbox-close {
542
+ top: 0.875rem;
543
+ right: 0.875rem;
544
+ }
545
+ .bm-lightbox-nav {
546
+ top: 50%;
547
+ translate: 0 -50%;
548
+ }
549
+ .bm-lightbox-prev {
550
+ left: 0.875rem;
551
+ }
552
+ .bm-lightbox-next {
553
+ right: 0.875rem;
554
+ }
555
+ .bm-lightbox[data-single] .bm-lightbox-nav,
556
+ .bm-lightbox[data-single] .bm-lightbox-counter {
557
+ display: none;
558
+ }
559
+ @media (prefers-reduced-motion: reduce) {
560
+ .bm-lightbox-image,
561
+ .bm-lightbox-close,
562
+ .bm-lightbox-nav {
563
+ transition: none;
564
+ }
565
+ }
323
566
  .bm-marquee-mask {
324
567
  mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
325
568
  }
@@ -1,78 +0,0 @@
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 VideoFrame from './VideoFrame.astro'
7
-
8
- interface Props {
9
- section: Extract<Section, { type: 'video' }>
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 loop = props.playback === 'loop'
19
- const hasHeader = Boolean(props.eyebrow || props.heading || props.intro)
20
- // The empty frame is an editor hint. A built site leaves it out rather than show visitors an instruction.
21
- const showFrame = props.video !== 'placeholder' || import.meta.env.DEV
22
- ---
23
-
24
- <SectionShell id={section.id} anchor={section.anchor} type={section.type} variant={section.variant} tone={section.tone} motion={reveal}>
25
- {
26
- section.variant === 'framed' && (
27
- <div class="section-container flex flex-col items-center gap-10">
28
- {hasHeader && (
29
- <SectionHeader eyebrow={props.eyebrow} heading={props.heading} marks={props.marks} intro={props.intro} align="center" field={field} />
30
- )}
31
- {showFrame && (<figure class="w-full max-w-5xl">
32
- <VideoFrame src={props.video} poster={props.poster} label={props.label} loop={loop} class="shadow-[0_30px_80px_-40px_rgb(0_0_0/0.45)]" />
33
- {props.caption && (
34
- <Typography as="p" size="sm" color="muted" class="mt-3 text-center" data-field={field('caption')}>
35
- {props.caption}
36
- </Typography>
37
- )}
38
- </figure>)}
39
- </div>
40
- )
41
- }
42
- {
43
- section.variant === 'wide' && (
44
- <div class="flex flex-col gap-10">
45
- {hasHeader && (
46
- <div class="section-container">
47
- <SectionHeader eyebrow={props.eyebrow} heading={props.heading} marks={props.marks} intro={props.intro} field={field} />
48
- </div>
49
- )}
50
- {showFrame && (<figure>
51
- <VideoFrame src={props.video} poster={props.poster} label={props.label} loop={loop} roundedClass="rounded-none" />
52
- {props.caption && (
53
- <div class="section-container">
54
- <Typography as="p" size="sm" color="muted" class="mt-3" data-field={field('caption')}>
55
- {props.caption}
56
- </Typography>
57
- </div>
58
- )}
59
- </figure>)}
60
- </div>
61
- )
62
- }
63
- {
64
- section.variant === 'split' && (
65
- <div class="section-container grid items-center gap-12 @min-[860px]:grid-cols-[minmax(0,2fr)_minmax(0,3fr)]">
66
- {hasHeader && <SectionHeader eyebrow={props.eyebrow} heading={props.heading} marks={props.marks} intro={props.intro} field={field} />}
67
- {showFrame && (<figure class:list={[!hasHeader && '@min-[860px]:col-span-2']}>
68
- <VideoFrame src={props.video} poster={props.poster} label={props.label} loop={loop} />
69
- {props.caption && (
70
- <Typography as="p" size="sm" color="muted" class="mt-3" data-field={field('caption')}>
71
- {props.caption}
72
- </Typography>
73
- )}
74
- </figure>)}
75
- </div>
76
- )
77
- }
78
- </SectionShell>
@@ -1,17 +0,0 @@
1
- import { sectionArgTypes } from '../../../stories/options'
2
- import { video } from './definition'
3
- import Video from './Video.astro'
4
-
5
- /** The sample pages hold no video, so the stories use the section's defaults: an empty frame until a file is linked. */
6
- const section = { id: 'video', type: 'video', variant: 'framed', tone: 'base', props: video.defaults } as const
7
-
8
- export default {
9
- title: 'Sections/Video',
10
- component: Video,
11
- parameters: { layout: 'fullscreen' },
12
- argTypes: sectionArgTypes('video'),
13
- }
14
-
15
- export const Framed = { args: { section, index: 0 } }
16
- export const Wide = { args: { section: { ...section, variant: 'wide' }, index: 0 } }
17
- export const Split = { args: { section: { ...section, variant: 'split' }, index: 0 } }
@@ -1,60 +0,0 @@
1
- ---
2
- import type { Image } from 'bearminion'
3
- import { imageUrl } from '../../../lib/image-url'
4
- import { cn } from '../../../lib/cn'
5
-
6
- interface Props {
7
- /** A video file URL, or `placeholder` for an empty frame. */
8
- src: string
9
- poster?: Image
10
- label?: string
11
- loop: boolean
12
- roundedClass?: string
13
- class?: string
14
- }
15
-
16
- const { src, poster, label, loop, roundedClass = 'rounded-card-lg', class: className } = Astro.props
17
- const placeholder = src === 'placeholder'
18
-
19
- const posterSrc = await imageUrl(poster)
20
- // A looping video starts muted and without controls once the page script sees it on screen. Until then, and without
21
- // JavaScript or with reduced motion, it keeps its controls so it can still be played.
22
- const playback = loop ? { muted: true, loop: true, controls: true, 'data-video-loop': '' } : { controls: true }
23
- ---
24
-
25
- <div class={cn('relative overflow-hidden bg-surface', placeholder && 'placeholder-stripes aspect-video', roundedClass, className)}>
26
- {
27
- placeholder ? (
28
- <div class="absolute inset-0 flex flex-col items-center justify-center gap-3 p-6 text-center">
29
- <span class="flex size-14 items-center justify-center rounded-full bg-fg text-bg" aria-hidden="true">
30
- <svg viewBox="0 0 16 16" class="ms-0.5 size-5" fill="currentColor"><path d="M4 2.5v11l9-5.5z" /></svg>
31
- </span>
32
- <span class="font-mono text-[0.6875rem] tracking-[0.04em] text-muted">Add a video link in the section settings</span>
33
- </div>
34
- ) : (
35
- <video class="block h-auto w-full" src={src} poster={posterSrc} preload="metadata" playsinline aria-label={label} {...playback} />
36
- )
37
- }
38
- </div>
39
-
40
- <script>
41
- /** Looping videos play while at least a quarter of them is on screen, and not at all with reduced motion. */
42
- function bindLoopingVideos() {
43
- const reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches
44
- for (const video of document.querySelectorAll<HTMLVideoElement>('video[data-video-loop]')) {
45
- if (video.dataset.bound === 'true') continue
46
- video.dataset.bound = 'true'
47
- if (reduced) continue
48
- video.controls = false
49
- new IntersectionObserver(
50
- ([entry]) => {
51
- if (entry?.isIntersecting) void video.play().catch(() => (video.controls = true))
52
- else video.pause()
53
- },
54
- { threshold: 0.25 },
55
- ).observe(video)
56
- }
57
- }
58
- bindLoopingVideos()
59
- document.addEventListener('bearminion:preview', bindLoopingVideos)
60
- </script>
@@ -1,58 +0,0 @@
1
- import { z } from 'zod'
2
- import { defineSection, imageSchema, richTextSchema, textSchema, withEmphasis } from 'bearminion'
3
- import { VIDEO_FILE } from '../media/source'
4
- import { accent, eyebrow, heading } from '../shared'
5
- import { videoWireframe } from './wireframe'
6
-
7
- export const videoVariants = ['framed', 'wide', 'split'] as const
8
-
9
- /** `controls`: the visitor presses play. `loop`: plays silently and on repeat while it is on screen, like a moving image. */
10
- export const videoPlayback = ['controls', 'loop'] as const
11
-
12
- /**
13
- * A video file the browser can play: a path in the site's `public/` folder (`/videos/demo.webm`) or an `https://` link
14
- * to the file. `placeholder` shows an empty frame. A page link such as YouTube does not play in a video element.
15
- */
16
- export const videoSourceSchema = z
17
- .string()
18
- .min(1)
19
- .refine((value) => value === 'placeholder' || VIDEO_FILE.test(value), {
20
- message:
21
- 'Use a link to a video file ending in .mp4 or .webm, or a path in public/ such as /videos/demo.webm. YouTube and similar page links do not play here.',
22
- })
23
-
24
- export const videoSchema = withEmphasis({
25
- eyebrow,
26
- heading,
27
- intro: richTextSchema.optional(),
28
- video: videoSourceSchema,
29
- /** What the video shows, read out by screen readers. */
30
- label: textSchema.optional(),
31
- /** Shown before the video plays and while it loads. */
32
- poster: imageSchema.optional(),
33
- caption: textSchema.optional(),
34
- playback: z.enum(videoPlayback).default('controls'),
35
- })
36
-
37
- export type VideoProps = z.infer<typeof videoSchema>
38
-
39
- export const video = defineSection({
40
- type: 'video',
41
- label: 'Video',
42
- description: 'A video with a heading, a poster image and a caption.',
43
- schema: videoSchema,
44
- defaults: {
45
- eyebrow: 'Watch',
46
- heading: 'See it in action.',
47
- marks: accent('See it in action.', 'in action.'),
48
- intro: 'A short video says more than a page of text. Link an .mp4 or .webm file and add a poster image to show before it plays.',
49
- video: 'placeholder',
50
- label: 'Product walkthrough',
51
- playback: 'controls',
52
- },
53
- variants: videoVariants,
54
- defaultVariant: 'framed',
55
- options: [{ name: 'playback', label: 'Playback', type: 'enum', choices: videoPlayback, default: 'controls' }],
56
- optional: { props: ['eyebrow', 'heading', 'intro', 'label', 'poster', 'caption'] },
57
- wireframe: videoWireframe,
58
- })
@@ -1,9 +0,0 @@
1
- import { defineWireframe } from 'bearminion'
2
-
3
- /** Add section picker thumbnail: [left %, top %, width %, height %, kind]. */
4
- export const videoWireframe = defineWireframe([
5
- [30, 10, 40, 8, 'title'],
6
- [24, 22, 52, 4, 'text'],
7
- [12, 32, 76, 58, 'dark'],
8
- [45, 54, 10, 14, 'light'],
9
- ])