create-kitcms 0.0.0-stage → 0.1.1

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 (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -2
  3. package/bin/create.js +5 -0
  4. package/dist/args.d.ts +15 -0
  5. package/dist/args.js +72 -0
  6. package/dist/index.d.ts +30 -0
  7. package/dist/index.js +161 -0
  8. package/dist/scaffold.d.ts +31 -0
  9. package/dist/scaffold.js +109 -0
  10. package/dist/wrangler.d.ts +2 -0
  11. package/dist/wrangler.js +7 -0
  12. package/package.json +34 -3
  13. package/templates/blank/.dev.vars.example +1 -0
  14. package/templates/blank/README.md +39 -0
  15. package/templates/blank/_gitignore +7 -0
  16. package/templates/blank/package.json +37 -0
  17. package/templates/blank/pnpm-workspace.yaml +3 -0
  18. package/templates/blank/src/app.d.ts +22 -0
  19. package/templates/blank/src/app.html +11 -0
  20. package/templates/blank/src/hooks.server.ts +4 -0
  21. package/templates/blank/src/kitcms.admin.ts +14 -0
  22. package/templates/blank/src/kitcms.config.ts +32 -0
  23. package/templates/blank/src/kitcms.rpc.ts +6 -0
  24. package/templates/blank/src/lib/index.ts +1 -0
  25. package/templates/blank/src/routes/(kitcms)/admin/[...path]/+page.server.ts +2 -0
  26. package/templates/blank/src/routes/(kitcms)/admin/[...path]/+page.svelte +9 -0
  27. package/templates/blank/src/routes/(kitcms)/api/[...path]/+server.ts +2 -0
  28. package/templates/blank/src/routes/+page.server.ts +7 -0
  29. package/templates/blank/src/routes/+page.svelte +19 -0
  30. package/templates/blank/tsconfig.json +11 -0
  31. package/templates/blank/vite.config.ts +8 -0
  32. package/templates/blank/wrangler.jsonc +28 -0
  33. package/templates/website/.dev.vars.example +1 -0
  34. package/templates/website/README.md +105 -0
  35. package/templates/website/_gitignore +7 -0
  36. package/templates/website/package.json +42 -0
  37. package/templates/website/pnpm-workspace.yaml +3 -0
  38. package/templates/website/src/app.css +23 -0
  39. package/templates/website/src/app.d.ts +22 -0
  40. package/templates/website/src/app.html +11 -0
  41. package/templates/website/src/hooks.server.ts +4 -0
  42. package/templates/website/src/kitcms.admin.ts +19 -0
  43. package/templates/website/src/kitcms.config.ts +269 -0
  44. package/templates/website/src/kitcms.rpc.ts +6 -0
  45. package/templates/website/src/kitcms.seed.ts +232 -0
  46. package/templates/website/src/lib/Img.svelte +62 -0
  47. package/templates/website/src/lib/Link.svelte +10 -0
  48. package/templates/website/src/lib/PageView.svelte +30 -0
  49. package/templates/website/src/lib/PostList.svelte +169 -0
  50. package/templates/website/src/lib/RichText.svelte +13 -0
  51. package/templates/website/src/lib/Seo.svelte +31 -0
  52. package/templates/website/src/lib/blocks/AdminPreview.svelte +59 -0
  53. package/templates/website/src/lib/blocks/Cta.svelte +86 -0
  54. package/templates/website/src/lib/blocks/Features.svelte +147 -0
  55. package/templates/website/src/lib/blocks/Gallery.svelte +122 -0
  56. package/templates/website/src/lib/blocks/Hero.svelte +151 -0
  57. package/templates/website/src/lib/blocks/LatestPosts.svelte +36 -0
  58. package/templates/website/src/lib/blocks/RenderBlocks.svelte +38 -0
  59. package/templates/website/src/lib/blocks/ResolveMedia.svelte +27 -0
  60. package/templates/website/src/lib/blocks/RichTextBlock.svelte +47 -0
  61. package/templates/website/src/lib/blocks/TeamGrid.svelte +159 -0
  62. package/templates/website/src/lib/blocks/types.ts +47 -0
  63. package/templates/website/src/lib/content.ts +31 -0
  64. package/templates/website/src/lib/designs.ts +79 -0
  65. package/templates/website/src/lib/format.ts +3 -0
  66. package/templates/website/src/lib/icons.ts +13 -0
  67. package/templates/website/src/lib/image.ts +29 -0
  68. package/templates/website/src/lib/index.ts +1 -0
  69. package/templates/website/src/lib/media.ts +32 -0
  70. package/templates/website/src/lib/shell/Footer.svelte +146 -0
  71. package/templates/website/src/lib/shell/Header.svelte +121 -0
  72. package/templates/website/src/lib/shell/MobileMenu.svelte +142 -0
  73. package/templates/website/src/lib/shell/shell.ts +52 -0
  74. package/templates/website/src/lib/site.css +329 -0
  75. package/templates/website/src/routes/(kitcms)/admin/[...path]/+page.server.ts +2 -0
  76. package/templates/website/src/routes/(kitcms)/admin/[...path]/+page.svelte +9 -0
  77. package/templates/website/src/routes/(kitcms)/api/[...path]/+server.ts +2 -0
  78. package/templates/website/src/routes/(site)/+error.svelte +23 -0
  79. package/templates/website/src/routes/(site)/+layout.server.ts +12 -0
  80. package/templates/website/src/routes/(site)/+layout.svelte +63 -0
  81. package/templates/website/src/routes/(site)/+page.server.ts +7 -0
  82. package/templates/website/src/routes/(site)/+page.svelte +33 -0
  83. package/templates/website/src/routes/(site)/[slug]/+page.server.ts +11 -0
  84. package/templates/website/src/routes/(site)/[slug]/+page.svelte +9 -0
  85. package/templates/website/src/routes/(site)/blog/+page.server.ts +20 -0
  86. package/templates/website/src/routes/(site)/blog/+page.svelte +66 -0
  87. package/templates/website/src/routes/(site)/blog/[slug]/+page.server.ts +11 -0
  88. package/templates/website/src/routes/(site)/blog/[slug]/+page.svelte +231 -0
  89. package/templates/website/src/routes/(site)/legal/[slug]/+page.server.ts +8 -0
  90. package/templates/website/src/routes/(site)/legal/[slug]/+page.svelte +23 -0
  91. package/templates/website/tsconfig.json +11 -0
  92. package/templates/website/vite.config.ts +8 -0
  93. package/templates/website/wrangler.jsonc +28 -0
@@ -0,0 +1,169 @@
1
+ <script lang="ts">
2
+ // Posts as a list, in three designs. A "Journal": text rows with a small picture. B "Cards": a
3
+ // grid with large covers. C "Index": a compact table, date then title. Used by the `latestPosts`
4
+ // block and the blog list.
5
+ import { resolve } from '$app/paths';
6
+ import type { PostSummary } from './blocks/types';
7
+ import type { DesignId } from './designs';
8
+ import { formatDate } from './format';
9
+ import Img from './Img.svelte';
10
+ import { asDoc, asMedia } from './media';
11
+
12
+ type Post = PostSummary & { tags?: unknown[] | null };
13
+ let { posts, design = 'a' }: { posts: Post[]; design?: DesignId } = $props();
14
+
15
+ const tagNames = (post: Post) =>
16
+ (post.tags ?? []).flatMap((t) => {
17
+ const d = asDoc<{ id: string; name: string }>(t);
18
+ return d ? [d.name] : [];
19
+ });
20
+ </script>
21
+
22
+ <ul class="list" data-design={design}>
23
+ {#each posts as post (post.id)}
24
+ {@const cover = asMedia(post.cover)}
25
+ <li>
26
+ <a href={resolve('/(site)/blog/[slug]', { slug: post.slug })}>
27
+ {#if design === 'b'}
28
+ <div class="cover">
29
+ {#if cover}
30
+ <Img media={cover} ratio={16 / 10} widths={[400, 800, 1200]} sizes="(min-width: 64rem) 30vw, (min-width: 40rem) 45vw, 100vw" />
31
+ {:else}
32
+ <div class="empty-img ph"></div>
33
+ {/if}
34
+ </div>
35
+ {/if}
36
+ <div class="text">
37
+ <p class="meta small muted">
38
+ <time datetime={post.publishedAt ?? undefined}>{formatDate(post.publishedAt)}</time>
39
+ {#each tagNames(post) as name (name)}<span class="tag">{name}</span>{/each}
40
+ </p>
41
+ <h3>{post.title}</h3>
42
+ {#if post.excerpt && design !== 'c'}<p class="excerpt muted">{post.excerpt}</p>{/if}
43
+ </div>
44
+ {#if design === 'a' && cover}
45
+ <div class="thumb">
46
+ <Img media={cover} ratio={1} widths={[160, 320]} sizes="7rem" />
47
+ </div>
48
+ {/if}
49
+ </a>
50
+ </li>
51
+ {:else}
52
+ <li class="muted">No posts yet.</li>
53
+ {/each}
54
+ </ul>
55
+
56
+ <style>
57
+ .list {
58
+ list-style: none;
59
+ margin: 0;
60
+ padding: 0;
61
+ display: grid;
62
+ gap: var(--s-5);
63
+ }
64
+ a {
65
+ display: flex;
66
+ gap: var(--s-3);
67
+ color: inherit;
68
+ text-decoration: none;
69
+ }
70
+ a:hover h3 {
71
+ text-decoration: underline;
72
+ text-decoration-thickness: 2px;
73
+ text-underline-offset: 0.2em;
74
+ }
75
+ h3 {
76
+ margin: 0.15em 0 0.25em;
77
+ font-size: 1.3rem;
78
+ }
79
+ p {
80
+ margin: 0;
81
+ }
82
+ .meta {
83
+ display: flex;
84
+ flex-wrap: wrap;
85
+ align-items: center;
86
+ gap: 0.25rem 0.6rem;
87
+ }
88
+ .excerpt {
89
+ max-width: 38rem;
90
+ }
91
+ .thumb {
92
+ flex: none;
93
+ width: 5.5rem;
94
+ margin-left: auto;
95
+ }
96
+ .thumb :global(img),
97
+ .cover :global(img),
98
+ .ph {
99
+ border-radius: var(--radius);
100
+ }
101
+ .ph {
102
+ aspect-ratio: 16 / 10;
103
+ }
104
+
105
+ /* A: rows */
106
+ .list[data-design='a'] {
107
+ --font-display: var(--font-serif);
108
+ gap: var(--s-4);
109
+ }
110
+ .list[data-design='a'] h3 {
111
+ font-weight: 600;
112
+ font-size: 1.4rem;
113
+ }
114
+
115
+ /* B: cards */
116
+ .list[data-design='b'] a {
117
+ flex-direction: column;
118
+ gap: var(--s-2);
119
+ }
120
+
121
+ /* C: index */
122
+ .list[data-design='c'] {
123
+ gap: 0.35rem;
124
+ }
125
+ .list[data-design='c'] li {
126
+ padding: var(--s-3);
127
+ background: var(--surface);
128
+ border-radius: 0.25rem;
129
+ }
130
+ .list[data-design='c'] a {
131
+ flex-direction: column;
132
+ gap: 0;
133
+ }
134
+ .list[data-design='c'] .meta {
135
+ order: -1;
136
+ }
137
+ .list[data-design='c'] h3 {
138
+ margin: 0;
139
+ }
140
+
141
+ @media (min-width: 40rem) {
142
+ .list[data-design='b'] {
143
+ grid-template-columns: repeat(2, 1fr);
144
+ gap: var(--s-5) var(--s-4);
145
+ }
146
+ .thumb {
147
+ width: 7rem;
148
+ }
149
+ }
150
+ @media (min-width: 48rem) {
151
+ .list[data-design='c'] .text {
152
+ display: grid;
153
+ grid-template-columns: 14rem 1fr;
154
+ gap: var(--s-4);
155
+ align-items: baseline;
156
+ }
157
+ .list[data-design='c'] .text .meta {
158
+ order: 0;
159
+ }
160
+ .list[data-design='c'] h3 {
161
+ font-size: 1.5rem;
162
+ }
163
+ }
164
+ @media (min-width: 64rem) {
165
+ .list[data-design='b'] {
166
+ grid-template-columns: repeat(3, 1fr);
167
+ }
168
+ }
169
+ </style>
@@ -0,0 +1,13 @@
1
+ <script lang="ts">
2
+ import { toHTML } from '@kitcms/core/richtext';
3
+ import type { RichTextDoc } from '@kitcms/core';
4
+
5
+ let { doc }: { doc: RichTextDoc | null | undefined } = $props();
6
+ const html = $derived(toHTML(doc));
7
+ </script>
8
+
9
+ {#if html}
10
+ <!-- Safe: toHTML escapes every text and attribute value and only emits allow-listed link schemes. -->
11
+ <!-- eslint-disable-next-line svelte/no-at-html-tags -->
12
+ <div class="prose">{@html html}</div>
13
+ {/if}
@@ -0,0 +1,31 @@
1
+ <script lang="ts">
2
+ import { page } from '$app/state';
3
+ import type { Media } from './media';
4
+
5
+ interface Props {
6
+ title?: string | null;
7
+ description?: string | null;
8
+ image?: Media | null;
9
+ siteName?: string | null;
10
+ type?: 'website' | 'article';
11
+ }
12
+ let { title, description, image, siteName, type = 'website' }: Props = $props();
13
+
14
+ const fullTitle = $derived(
15
+ title && siteName && title !== siteName ? `${title} | ${siteName}` : (title ?? siteName ?? ''),
16
+ );
17
+ // Open Graph wants an absolute URL.
18
+ const ogImage = $derived(image ? new URL(image.url, page.url.href).href : null);
19
+ </script>
20
+
21
+ <svelte:head>
22
+ <title>{fullTitle}</title>
23
+ {#if description}<meta name="description" content={description} />{/if}
24
+ <meta property="og:title" content={title ?? siteName ?? ''} />
25
+ {#if description}<meta property="og:description" content={description} />{/if}
26
+ <meta property="og:type" content={type} />
27
+ <meta property="og:url" content={page.url.href} />
28
+ {#if siteName}<meta property="og:site_name" content={siteName} />{/if}
29
+ {#if ogImage}<meta property="og:image" content={ogImage} />{/if}
30
+ <meta name="twitter:card" content={ogImage ? 'summary_large_image' : 'summary'} />
31
+ </svelte:head>
@@ -0,0 +1,59 @@
1
+ <script lang="ts">
2
+ // The admin's live preview for every block (registered per block in `src/kitcms.admin.ts`).
3
+ // It renders the real block components from the live form values. Upload fields hold ids there,
4
+ // so it resolves them to media docs first (`ResolveMedia`).
5
+ import type { BlockPreviewProps } from '@kitcms/ui';
6
+ import Cta from './Cta.svelte';
7
+ import Features from './Features.svelte';
8
+ import Gallery from './Gallery.svelte';
9
+ import Hero from './Hero.svelte';
10
+ import LatestPosts from './LatestPosts.svelte';
11
+ import ResolveMedia from './ResolveMedia.svelte';
12
+ import RichTextBlock from './RichTextBlock.svelte';
13
+ import TeamGrid from './TeamGrid.svelte';
14
+ import type { Media } from '../media';
15
+ import type { BlockOf } from './types';
16
+
17
+ let { block }: BlockPreviewProps = $props();
18
+
19
+ const idOf = (v: unknown): string | null => (typeof v === 'string' && v ? v : null);
20
+ // Upload ids this block shows.
21
+ const ids = $derived.by(() => {
22
+ if (block.blockType === 'hero') return [idOf(block.image)].filter((x) => x !== null);
23
+ if (block.blockType === 'gallery' && Array.isArray(block.images))
24
+ return block.images.map(idOf).filter((x) => x !== null);
25
+ return [];
26
+ });
27
+
28
+ let resolved = $state.raw<Record<string, Media | null>>({});
29
+ const onresolve = (id: string, media: Media | null) => {
30
+ if (resolved[id] !== media) resolved = { ...resolved, [id]: media };
31
+ };
32
+
33
+ // The block with ids swapped for the resolved media docs.
34
+ const view = $derived({
35
+ ...block,
36
+ image: (idOf(block.image) && resolved[idOf(block.image)!]) || null,
37
+ images: ids.map((id) => resolved[id]).filter((m): m is Media => Boolean(m)),
38
+ } as unknown as BlockOf<'hero'> & BlockOf<'gallery'>);
39
+ </script>
40
+
41
+ {#each ids as id (id)}
42
+ <ResolveMedia {id} {onresolve} />
43
+ {/each}
44
+
45
+ {#if block.blockType === 'hero'}
46
+ <Hero block={view} />
47
+ {:else if block.blockType === 'richText'}
48
+ <RichTextBlock block={block as unknown as BlockOf<'richText'>} />
49
+ {:else if block.blockType === 'features'}
50
+ <Features block={block as unknown as BlockOf<'features'>} />
51
+ {:else if block.blockType === 'gallery'}
52
+ <Gallery block={view} />
53
+ {:else if block.blockType === 'cta'}
54
+ <Cta block={block as unknown as BlockOf<'cta'>} />
55
+ {:else if block.blockType === 'teamGrid'}
56
+ <TeamGrid block={block as unknown as BlockOf<'teamGrid'>} />
57
+ {:else if block.blockType === 'latestPosts'}
58
+ <LatestPosts block={block as unknown as BlockOf<'latestPosts'>} />
59
+ {/if}
@@ -0,0 +1,86 @@
1
+ <script lang="ts">
2
+ import '../site.css';
3
+ import type { DesignId } from '../designs';
4
+ import Link from '../Link.svelte';
5
+ import type { BlockOf } from './types';
6
+
7
+ // A "Editorial": big heading on the left, text and button on the right. B "Immersive": a
8
+ // full-width field of the accent colour. C "Structured": a tinted panel.
9
+ let { block, design = 'a' }: { block: BlockOf<'cta'>; design?: DesignId } = $props();
10
+ const button = $derived(block.buttonLabel && block.buttonHref);
11
+ </script>
12
+
13
+ <section class="section" data-design={design}>
14
+ <div class="container">
15
+ <div class="panel">
16
+ <h2>{block.heading ?? ''}</h2>
17
+ <div class="side">
18
+ {#if block.text}<p class="lead">{block.text}</p>{/if}
19
+ {#if button}
20
+ <Link href={block.buttonHref!} class={['btn', design === 'b' && 'inverse']}>{block.buttonLabel}</Link>
21
+ {/if}
22
+ </div>
23
+ </div>
24
+ </div>
25
+ </section>
26
+
27
+ <style>
28
+ .panel {
29
+ display: grid;
30
+ gap: var(--s-3);
31
+ }
32
+ h2 {
33
+ margin: 0;
34
+ }
35
+ .side p {
36
+ margin-bottom: var(--s-3);
37
+ color: var(--muted);
38
+ }
39
+
40
+ /* A */
41
+ .section[data-design='a'] {
42
+ --font-display: var(--font-serif);
43
+ }
44
+ .section[data-design='a'] h2 {
45
+ font-weight: 600;
46
+ font-size: clamp(2rem, 1.2rem + 3.4vw, 3.75rem);
47
+ }
48
+
49
+ /* B: full-bleed field */
50
+ .section[data-design='b'] {
51
+ background: var(--accent);
52
+ color: var(--accent-ink);
53
+ --focus: var(--accent-ink);
54
+ }
55
+ .section[data-design='b'] .panel {
56
+ text-align: center;
57
+ justify-items: center;
58
+ gap: var(--s-4);
59
+ }
60
+ .section[data-design='b'] .side p {
61
+ color: inherit;
62
+ opacity: 0.92;
63
+ max-width: 34rem;
64
+ }
65
+
66
+ /* C: panel */
67
+ .section[data-design='c'] .panel {
68
+ padding: var(--s-5) var(--s-4);
69
+ background: var(--surface);
70
+ border-radius: var(--radius);
71
+ }
72
+
73
+ @media (min-width: 56rem) {
74
+ .section[data-design='a'] .panel {
75
+ grid-template-columns: 7fr 5fr;
76
+ gap: var(--s-6);
77
+ align-items: end;
78
+ }
79
+ .section[data-design='c'] .panel {
80
+ grid-template-columns: 1fr 1fr;
81
+ align-items: center;
82
+ gap: var(--s-6);
83
+ padding: var(--s-6);
84
+ }
85
+ }
86
+ </style>
@@ -0,0 +1,147 @@
1
+ <script lang="ts">
2
+ import '../site.css';
3
+ import type { DesignId } from '../designs';
4
+ import { ICON_PATHS } from '../icons';
5
+ import type { BlockOf } from './types';
6
+
7
+ // A "Editorial": the title beside a plain list. B "Immersive": rounded cards with a round icon.
8
+ // C "Structured": a grid of square tiles.
9
+ let { block, design = 'a' }: { block: BlockOf<'features'>; design?: DesignId } = $props();
10
+ </script>
11
+
12
+ <section class="section" data-design={design}>
13
+ <div class="container wrap">
14
+ {#if block.title}<h2>{block.title}</h2>{/if}
15
+ <ul class="items">
16
+ {#each block.items ?? [] as item (item.id)}
17
+ <li>
18
+ {#if item.icon}
19
+ <span class="icon">
20
+ <svg viewBox="0 0 24 24" width="26" height="26" aria-hidden="true">
21
+ <path d={ICON_PATHS[item.icon]} />
22
+ </svg>
23
+ </span>
24
+ {/if}
25
+ <div>
26
+ <h3>{item.title ?? ''}</h3>
27
+ {#if item.text}<p class="text">{item.text}</p>{/if}
28
+ </div>
29
+ </li>
30
+ {/each}
31
+ </ul>
32
+ </div>
33
+ </section>
34
+
35
+ <style>
36
+ .section[data-design='a'] {
37
+ --font-display: var(--font-serif);
38
+ }
39
+ .section[data-design='a'] h2 {
40
+ font-weight: 600;
41
+ }
42
+ .items {
43
+ list-style: none;
44
+ margin: 0;
45
+ padding: 0;
46
+ display: grid;
47
+ gap: var(--s-4);
48
+ }
49
+ li {
50
+ display: flex;
51
+ gap: var(--s-3);
52
+ }
53
+ h3 {
54
+ margin: 0 0 0.25em;
55
+ }
56
+ .text {
57
+ margin: 0;
58
+ color: var(--muted);
59
+ }
60
+ svg {
61
+ fill: none;
62
+ stroke: currentColor;
63
+ stroke-width: 1.7;
64
+ stroke-linecap: round;
65
+ stroke-linejoin: round;
66
+ flex: none;
67
+ }
68
+ .icon {
69
+ color: var(--accent);
70
+ line-height: 0;
71
+ padding-top: 0.15rem;
72
+ }
73
+
74
+ /* B: cards */
75
+ .section[data-design='b'] h2 {
76
+ text-align: center;
77
+ margin-bottom: var(--s-5);
78
+ }
79
+ .section[data-design='b'] .items {
80
+ gap: var(--s-3);
81
+ }
82
+ .section[data-design='b'] li {
83
+ flex-direction: column;
84
+ padding: var(--s-4);
85
+ background: var(--surface);
86
+ border-radius: calc(var(--radius) * 2);
87
+ }
88
+ .section[data-design='b'] .icon {
89
+ display: grid;
90
+ place-items: center;
91
+ width: 3rem;
92
+ height: 3rem;
93
+ padding: 0;
94
+ border-radius: 50%;
95
+ background: var(--accent);
96
+ color: var(--accent-ink);
97
+ }
98
+
99
+ /* C: tiles */
100
+ .section[data-design='c'] h2 {
101
+ margin-bottom: var(--s-4);
102
+ }
103
+ .section[data-design='c'] .items {
104
+ gap: 0.5rem;
105
+ }
106
+ .section[data-design='c'] li {
107
+ flex-direction: column;
108
+ gap: var(--s-4);
109
+ padding: var(--s-4);
110
+ min-height: 11rem;
111
+ background: var(--surface);
112
+ border-radius: 0.25rem;
113
+ }
114
+ .section[data-design='c'] .icon {
115
+ order: 2;
116
+ margin-top: auto;
117
+ }
118
+ .section[data-design='c'] li > div {
119
+ order: 1;
120
+ }
121
+
122
+ @media (min-width: 40rem) {
123
+ .section[data-design='b'] .items,
124
+ .section[data-design='c'] .items {
125
+ grid-template-columns: repeat(2, 1fr);
126
+ }
127
+ }
128
+ @media (min-width: 64rem) {
129
+ .section[data-design='a'] .wrap {
130
+ display: grid;
131
+ grid-template-columns: 4fr 8fr;
132
+ gap: var(--s-6);
133
+ align-items: start;
134
+ }
135
+ .section[data-design='a'] h2 {
136
+ position: sticky;
137
+ top: calc(var(--header-h) + var(--s-3));
138
+ }
139
+ .section[data-design='a'] .items {
140
+ gap: var(--s-5);
141
+ }
142
+ .section[data-design='b'] .items,
143
+ .section[data-design='c'] .items {
144
+ grid-template-columns: repeat(3, 1fr);
145
+ }
146
+ }
147
+ </style>
@@ -0,0 +1,122 @@
1
+ <script lang="ts">
2
+ import '../site.css';
3
+ import type { DesignId } from '../designs';
4
+ import Img from '../Img.svelte';
5
+ import { asMediaList } from '../media';
6
+ import type { BlockOf } from './types';
7
+
8
+ // A "Editorial": pictures at uneven sizes on a 12-column grid. B "Immersive": an edge-to-edge
9
+ // grid with hairline gaps. C "Structured": equal tiles with their captions.
10
+ let { block, design = 'a' }: { block: BlockOf<'gallery'>; design?: DesignId } = $props();
11
+ const images = $derived(asMediaList(block.images));
12
+ // A: the shape of each picture, repeating.
13
+ const RATIOS = [3 / 2, 4 / 5, 1, 3 / 2, 4 / 5, 3 / 2];
14
+ </script>
15
+
16
+ <section class="section" data-design={design}>
17
+ <div class:container={design !== 'b'}>
18
+ {#if images.length}
19
+ <ul class="grid">
20
+ {#each images as media, i (media.id)}
21
+ <li>
22
+ <figure>
23
+ <Img
24
+ {media}
25
+ ratio={design === 'a' ? RATIOS[i % RATIOS.length] : design === 'b' ? 1 : 4 / 3}
26
+ widths={[400, 800, 1200]}
27
+ sizes={design === 'b'
28
+ ? '(min-width: 48rem) 33vw, 50vw'
29
+ : '(min-width: 48rem) 40vw, 100vw'}
30
+ />
31
+ {#if design === 'c' && media.alt}<figcaption class="small muted">{media.alt}</figcaption>{/if}
32
+ </figure>
33
+ </li>
34
+ {/each}
35
+ </ul>
36
+ {:else}
37
+ <p class="placeholder container">Gallery: add images to see them here.</p>
38
+ {/if}
39
+ </div>
40
+ </section>
41
+
42
+ <style>
43
+ .section {
44
+ padding-block: var(--s-6);
45
+ }
46
+ .section[data-design='b'] {
47
+ padding-block: 0;
48
+ }
49
+ .grid {
50
+ list-style: none;
51
+ margin: 0;
52
+ padding: 0;
53
+ display: grid;
54
+ gap: var(--s-2);
55
+ grid-template-columns: 1fr;
56
+ }
57
+ figure {
58
+ margin: 0;
59
+ }
60
+ li :global(img) {
61
+ border-radius: var(--radius);
62
+ }
63
+ figcaption {
64
+ margin-top: 0.4rem;
65
+ }
66
+
67
+ /* B */
68
+ .section[data-design='b'] .grid {
69
+ gap: 0.25rem;
70
+ grid-template-columns: repeat(2, 1fr);
71
+ }
72
+ .section[data-design='b'] li :global(img) {
73
+ border-radius: 0;
74
+ }
75
+ .section[data-design='b'] .placeholder {
76
+ margin: var(--s-5) var(--gutter);
77
+ }
78
+
79
+ /* C */
80
+ .section[data-design='c'] .grid {
81
+ grid-template-columns: repeat(2, 1fr);
82
+ gap: var(--s-3) var(--s-2);
83
+ }
84
+ .section[data-design='c'] li :global(img) {
85
+ border-radius: 0.25rem;
86
+ }
87
+
88
+ @media (min-width: 48rem) {
89
+ .section[data-design='a'] .grid {
90
+ grid-template-columns: repeat(12, 1fr);
91
+ gap: var(--s-5) var(--s-4);
92
+ align-items: start;
93
+ }
94
+ .section[data-design='a'] li {
95
+ grid-column: span 6;
96
+ }
97
+ .section[data-design='a'] li:nth-child(4n + 1) {
98
+ grid-column: 1 / span 7;
99
+ }
100
+ .section[data-design='a'] li:nth-child(4n + 2) {
101
+ grid-column: 8 / span 5;
102
+ margin-top: var(--s-6);
103
+ }
104
+ .section[data-design='a'] li:nth-child(4n + 3) {
105
+ grid-column: 2 / span 5;
106
+ }
107
+ .section[data-design='a'] li:nth-child(4n) {
108
+ grid-column: 7 / span 6;
109
+ }
110
+ .section[data-design='b'] .grid {
111
+ grid-template-columns: repeat(3, 1fr);
112
+ }
113
+ .section[data-design='c'] .grid {
114
+ grid-template-columns: repeat(3, 1fr);
115
+ }
116
+ }
117
+ @media (min-width: 72rem) {
118
+ .section[data-design='c'] .grid {
119
+ grid-template-columns: repeat(4, 1fr);
120
+ }
121
+ }
122
+ </style>