visualci-gallery 0.0.0-stage → 0.2.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/README.md CHANGED
@@ -1,3 +1,59 @@
1
- # Temporary Holding Version
1
+ # visualci-gallery
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A screenshots page from a VisualCI [public gallery](https://visualci.com/docs/gallery/) manifest. No framework, no
4
+ dependencies. The markup is the [gallery contract](../contract/SPEC.md), so a page a server rendered (the Astro
5
+ component, the Ruby gem, the Python package) hydrates the same way.
6
+
7
+ The guide, with a script tag, a bundler and rendering at build time: https://visualci.com/docs/gallery/js/
8
+
9
+ ## In the browser
10
+
11
+ ```html
12
+ <link rel="stylesheet" href="visualci-gallery/gallery.css">
13
+ <div id="screenshots"></div>
14
+ <script type="module">
15
+ import { mount } from "visualci-gallery";
16
+ mount(document.getElementById("screenshots"), {
17
+ manifest: "https://app.visualci.com/g/acme/web.json",
18
+ screens: { overview: { title: "Overview", caption: "Everything at a glance." } },
19
+ order: ["overview"],
20
+ });
21
+ </script>
22
+ ```
23
+
24
+ On markup a server rendered, call `hydrate(element)` instead. Without a bundler, `dist/gallery.iife.js` (ES5, one
25
+ file) sets `window.VisualCIGallery` with the same functions.
26
+
27
+ ## At build time
28
+
29
+ ```ts
30
+ import { load, render } from "visualci-gallery/render";
31
+
32
+ const html = render(await load({ manifest: "https://app.visualci.com/g/acme/web.json", title: "Screenshots" }));
33
+ ```
34
+
35
+ `load` throws when the manifest can't be read or has nothing to show, so the build fails instead of shipping an empty
36
+ page.
37
+
38
+ ## Options
39
+
40
+ `title` (default "Screenshots"; `null` for no heading), `headingLevel` (2), `id` ("vg", for two galleries on one
41
+ page), `screens` (`{key: {title, caption}}`), `order` (screen keys), `groups` (`{name: {title, size, fit}}`: `size` for shots whose names give no width, `fit: "contain"` to show a group whole, such as an app's windows), `groupOrder`,
42
+ `credit` (true), `layout` ("grid", or "strip": one row that scrolls sideways), `themeSwitch` (true; false follows
43
+ `<html data-theme>`), `seeAll` (`{href, text}`), `preload` (true: preloads the images a reader is likely to look at
44
+ next; false turns it off; `{fold, count, bytes, parallel}` sets its caps, the rest keeping their defaults 250, 500,
45
+ 50000000, 4). `load` and `mount` also take `manifest`, `timeout`, `attempts` and
46
+ `fetch`. [SPEC.md](../contract/SPEC.md) has the details, including how screenshot names pair
47
+ (`<screen>-<light|dark>[-<width>]` or `<screen>/<width>-<light|dark>`).
48
+
49
+ ## Styling
50
+
51
+ `gallery.css` is the default look. Set the `--vg-*` variables (`--vg-ink`, `--vg-muted`, `--vg-paper`,
52
+ `--vg-paper-2`, `--vg-rule`, `--vg-accent`, the radii, `--vg-shadow`, sizes and type) to match your site, on `.vg`
53
+ or any element around it. `gallery.css` declares its defaults on the root with no specificity, so your values win
54
+ whichever stylesheet loads first.
55
+
56
+ ## Development
57
+
58
+ `pnpm build && pnpm test` (after `pnpm install` in `clients/gallery`, the workspace). The tests check the contract's golden fixtures; `UPDATE_GOLDEN=1 pnpm test` rewrites them
59
+ (review the diff).
@@ -0,0 +1,434 @@
1
+ /* visualci-gallery's default look. Each site keeps its own through the --vg-* variables: set them on .vg or any
2
+ * element around it to the site's colours, radii and type. The defaults sit on the root at no specificity, so any
3
+ * value a site sets wins, and they follow the text colour and the page's color-scheme (a custom property's
4
+ * currentColor is resolved where it's used).
5
+ *
6
+ * Each card holds every variant of its screen; only the chosen theme and size show (hidden lazy images never load).
7
+ * Before the script runs, the theme follows <html data-theme>, else the reader's setting. */
8
+ :where(:root) {
9
+ --vg-ink: currentColor;
10
+ --vg-ink-2: currentColor;
11
+ --vg-muted: color-mix(in srgb, currentColor 65%, transparent);
12
+ --vg-paper: Canvas;
13
+ --vg-paper-2: color-mix(in srgb, currentColor 5%, Canvas);
14
+ --vg-rule: color-mix(in srgb, currentColor 16%, transparent);
15
+ --vg-accent: LinkText;
16
+ --vg-radius-sm: 4px;
17
+ --vg-radius-md: 8px;
18
+ --vg-radius-lg: 12px;
19
+ --vg-shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 8px 24px rgb(0 0 0 / 0.08);
20
+ --vg-backdrop: rgb(0 0 0 / 0.6);
21
+ /* The strip's scroll buttons, over a screenshot. */
22
+ --vg-float-shadow: 0 0 0 1px rgb(0 0 0 / 0.08), 0 2px 10px rgb(0 0 0 / 0.3);
23
+ --vg-rule-width: 1px;
24
+ --vg-gap: 1.5rem;
25
+ --vg-card-min: 22rem;
26
+ --vg-phone-card-min: 9.5rem;
27
+ --vg-desktop-ratio: 1440 / 900;
28
+ --vg-phone-ratio: 390 / 844;
29
+ --vg-contain-padding: 7%;
30
+ --vg-contain-shadow: drop-shadow(0 0.5rem 1rem rgb(0 0 0 / 0.18));
31
+ --vg-title-size: 2rem;
32
+ --vg-group-title-size: 1.5rem;
33
+ --vg-card-title-size: 1.125rem;
34
+ --vg-small: 0.875rem;
35
+ --vg-duration: 150ms;
36
+ --vg-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
37
+ }
38
+ .vg {
39
+ display: block;
40
+ min-width: 0;
41
+ }
42
+ .vg *,
43
+ .vg *::before,
44
+ .vg *::after {
45
+ box-sizing: border-box;
46
+ }
47
+ .vg :where(h1, h2, h3, h4, h5, h6, p, ul, li) {
48
+ margin: 0;
49
+ }
50
+ /* A host page's article styles (`.content h2 { margin: … }`, `.content ul { padding-left: … }`, `.content li + li`)
51
+ * outrank an element reset, so each of the gallery's own elements is set again by class, inside .vg. */
52
+ .vg .vg-title,
53
+ .vg .vg-group-title,
54
+ .vg .vg-card,
55
+ .vg .vg-card-title,
56
+ .vg .vg-caption,
57
+ .vg .vg-box-title,
58
+ .vg .vg-see-all,
59
+ .vg .vg-credit {
60
+ margin: 0;
61
+ padding: 0;
62
+ }
63
+ .vg .vg-grid {
64
+ margin: 0;
65
+ padding: 0;
66
+ list-style: none;
67
+ }
68
+ /* Long names break rather than push the page sideways. */
69
+ .vg :where(.vg-title, .vg-group-title, .vg-card-title, .vg-caption, .vg-box-title, [role="tab"]) {
70
+ overflow-wrap: anywhere;
71
+ }
72
+
73
+ .vg .vg-title {
74
+ font-size: var(--vg-title-size);
75
+ font-weight: 650;
76
+ margin-bottom: calc(var(--vg-gap) * 1.33);
77
+ }
78
+
79
+ .vg-tabs {
80
+ display: flex;
81
+ flex-wrap: wrap;
82
+ gap: 0.25rem;
83
+ border-bottom: var(--vg-rule-width) solid var(--vg-rule);
84
+ margin-bottom: calc(var(--vg-gap) * 1.33);
85
+ }
86
+ .vg-tabs [role="tab"] {
87
+ font: inherit;
88
+ font-weight: 600;
89
+ color: var(--vg-muted);
90
+ background: none;
91
+ border: 0;
92
+ border-bottom: 2px solid transparent;
93
+ padding: 0.5rem 1rem;
94
+ margin-bottom: calc(-1 * var(--vg-rule-width));
95
+ cursor: pointer;
96
+ }
97
+ .vg-tabs [role="tab"]:hover {
98
+ color: var(--vg-ink);
99
+ }
100
+ .vg-tabs [role="tab"][aria-selected="true"] {
101
+ color: var(--vg-ink);
102
+ border-bottom-color: var(--vg-accent);
103
+ }
104
+
105
+ .vg-bar,
106
+ .vg-box-bar {
107
+ display: flex;
108
+ flex-wrap: wrap;
109
+ align-items: center;
110
+ justify-content: space-between;
111
+ gap: 0.75rem 1.5rem;
112
+ }
113
+ .vg-bar {
114
+ margin-bottom: calc(var(--vg-gap) * 1.33);
115
+ }
116
+ .vg-group-title {
117
+ font-size: var(--vg-group-title-size);
118
+ font-weight: 600;
119
+ }
120
+ .vg-controls {
121
+ display: flex;
122
+ flex-wrap: wrap;
123
+ align-items: center;
124
+ gap: 0.5rem;
125
+ }
126
+ .vg-seg {
127
+ display: inline-flex;
128
+ padding: 2px;
129
+ border: var(--vg-rule-width) solid var(--vg-rule);
130
+ border-radius: 999px;
131
+ background: var(--vg-paper-2);
132
+ }
133
+ .vg-seg[hidden],
134
+ .vg-seg button[hidden] {
135
+ display: none;
136
+ }
137
+ .vg-seg button,
138
+ .vg-icon {
139
+ font: inherit;
140
+ font-size: var(--vg-small);
141
+ font-weight: 500;
142
+ color: var(--vg-ink-2);
143
+ background: none;
144
+ border: 0;
145
+ border-radius: 999px;
146
+ padding: 0.25rem 1rem;
147
+ cursor: pointer;
148
+ min-height: 2.25rem;
149
+ }
150
+ .vg-seg button[aria-pressed="true"] {
151
+ background: var(--vg-paper);
152
+ color: var(--vg-ink);
153
+ box-shadow: 0 0 0 var(--vg-rule-width) var(--vg-rule);
154
+ }
155
+ .vg-icon {
156
+ font-size: 1.25rem;
157
+ line-height: 1;
158
+ min-width: 2.25rem;
159
+ padding: 0;
160
+ border: var(--vg-rule-width) solid var(--vg-rule);
161
+ }
162
+ .vg-seg button:focus-visible,
163
+ .vg-icon:focus-visible,
164
+ .vg-thumb:focus-visible,
165
+ .vg-tabs [role="tab"]:focus-visible,
166
+ .vg-credit a:focus-visible,
167
+ .vg-see-all a:focus-visible {
168
+ outline: 2px solid var(--vg-accent);
169
+ outline-offset: 2px;
170
+ }
171
+
172
+ .vg-grid {
173
+ list-style: none;
174
+ padding: 0;
175
+ display: grid;
176
+ gap: calc(var(--vg-gap) * 1.33) var(--vg-gap);
177
+ grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--vg-card-min)), 1fr));
178
+ }
179
+ .vg[data-vg-size="phone"] .vg-grid {
180
+ grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--vg-phone-card-min)), 1fr));
181
+ gap: var(--vg-gap) calc(var(--vg-gap) * 0.67);
182
+ }
183
+ .vg-card {
184
+ min-width: 0;
185
+ }
186
+ .vg-thumb {
187
+ display: block;
188
+ color: inherit;
189
+ text-decoration: none;
190
+ width: 100%;
191
+ padding: 0;
192
+ border: var(--vg-rule-width) solid var(--vg-rule);
193
+ border-radius: var(--vg-radius-md);
194
+ background: var(--vg-paper-2);
195
+ overflow: hidden;
196
+ cursor: zoom-in;
197
+ aspect-ratio: var(--vg-desktop-ratio);
198
+ box-shadow: var(--vg-shadow);
199
+ transition: transform var(--vg-duration) var(--vg-ease);
200
+ }
201
+ .vg[data-vg-size="phone"] .vg-thumb {
202
+ aspect-ratio: var(--vg-phone-ratio);
203
+ }
204
+ .vg-thumb:hover {
205
+ transform: translateY(-2px);
206
+ }
207
+ .vg .vg-card-title {
208
+ margin-top: 0.75rem;
209
+ font-size: var(--vg-card-title-size);
210
+ font-weight: 600;
211
+ color: var(--vg-ink);
212
+ }
213
+ .vg .vg-caption {
214
+ margin-top: 0.25rem;
215
+ font-size: var(--vg-small);
216
+ color: var(--vg-muted);
217
+ }
218
+ .vg[data-vg-size="phone"] .vg-caption {
219
+ display: none;
220
+ }
221
+
222
+ /* Which variant shows. */
223
+ .vg-img {
224
+ display: none;
225
+ width: 100%;
226
+ height: 100%;
227
+ object-fit: cover;
228
+ object-position: top;
229
+ }
230
+ /* A group shown whole (a Mac app's windows): centred in its card with room around it. */
231
+ .vg-card[data-vg-fit="contain"] .vg-img {
232
+ object-fit: contain;
233
+ object-position: center;
234
+ padding: var(--vg-contain-padding);
235
+ box-sizing: border-box;
236
+ filter: var(--vg-contain-shadow);
237
+ }
238
+ .vg-missing {
239
+ place-items: center;
240
+ padding: 1rem;
241
+ font-size: var(--vg-small);
242
+ color: var(--vg-muted);
243
+ text-align: center;
244
+ }
245
+ /* A screen with no shot at this size isn't shown at it. */
246
+ .vg[data-vg-size="desktop"] .vg-card:not([data-vg-sizes~="desktop"]),
247
+ .vg[data-vg-size="phone"] .vg-card:not([data-vg-sizes~="phone"]) {
248
+ display: none;
249
+ }
250
+ .vg[data-vg-size="desktop"] .vg-img[data-vg-size="desktop"],
251
+ .vg[data-vg-size="phone"] .vg-img[data-vg-size="phone"] {
252
+ display: block;
253
+ }
254
+ .vg[data-vg-size="desktop"] .vg-missing[data-vg-size="desktop"],
255
+ .vg[data-vg-size="phone"] .vg-missing[data-vg-size="phone"] {
256
+ display: grid;
257
+ }
258
+ .vg[data-vg-theme="light"] .vg-img:not([data-vg-theme~="light"]),
259
+ .vg[data-vg-theme="dark"] .vg-img:not([data-vg-theme~="dark"]) {
260
+ display: none;
261
+ }
262
+ /* Before the script runs: the page's <html data-theme> when it's set, else the reader's setting. */
263
+ :root[data-theme="light"] .vg:not([data-vg-theme]) .vg-img:not([data-vg-theme~="light"]),
264
+ :root[data-theme="dark"] .vg:not([data-vg-theme]) .vg-img:not([data-vg-theme~="dark"]) {
265
+ display: none;
266
+ }
267
+ @media not all and (prefers-color-scheme: dark) {
268
+ :root:not([data-theme="light"]):not([data-theme="dark"]) .vg:not([data-vg-theme]) .vg-img:not([data-vg-theme~="light"]) {
269
+ display: none;
270
+ }
271
+ }
272
+ @media (prefers-color-scheme: dark) {
273
+ :root:not([data-theme="light"]):not([data-theme="dark"]) .vg:not([data-vg-theme]) .vg-img:not([data-vg-theme~="dark"]) {
274
+ display: none;
275
+ }
276
+ }
277
+
278
+ /* The strip: one row that scrolls sideways, snapping to each card, with a button at each end. */
279
+ .vg-strip {
280
+ position: relative;
281
+ min-width: 0;
282
+ }
283
+ .vg .vg-track {
284
+ display: grid;
285
+ grid-auto-flow: column;
286
+ grid-auto-columns: var(--vg-strip-card, min(22.5rem, 80%));
287
+ grid-template-columns: none;
288
+ overflow-x: auto;
289
+ overscroll-behavior-x: contain;
290
+ scroll-snap-type: x mandatory;
291
+ scroll-padding-inline: 0.25rem;
292
+ padding: 0.25rem 0.25rem 0.75rem;
293
+ scrollbar-width: thin;
294
+ }
295
+ .vg[data-vg-size="phone"] .vg-track {
296
+ grid-auto-columns: var(--vg-strip-phone-card, min(11rem, 45%));
297
+ grid-template-columns: none;
298
+ }
299
+ .vg-track .vg-card {
300
+ scroll-snap-align: start;
301
+ }
302
+ .vg-strip .vg-icon {
303
+ position: absolute;
304
+ top: calc(50% - 1.5rem);
305
+ z-index: 1;
306
+ background: var(--vg-paper);
307
+ box-shadow: var(--vg-float-shadow);
308
+ }
309
+ .vg-strip-prev {
310
+ left: 0.25rem;
311
+ }
312
+ .vg-strip-next {
313
+ right: 0.25rem;
314
+ }
315
+ .vg-strip .vg-icon:disabled {
316
+ visibility: hidden;
317
+ }
318
+ .vg .vg-see-all {
319
+ margin-top: 1rem;
320
+ text-align: center;
321
+ }
322
+ .vg-see-all a {
323
+ color: var(--vg-accent);
324
+ font-weight: 500;
325
+ }
326
+
327
+ .vg .vg-credit {
328
+ margin-top: calc(var(--vg-gap) * 2);
329
+ font-size: var(--vg-small);
330
+ color: var(--vg-muted);
331
+ text-align: center;
332
+ }
333
+ .vg-credit a {
334
+ color: inherit;
335
+ }
336
+
337
+ .vg-error {
338
+ margin: 2rem 0;
339
+ color: var(--vg-muted);
340
+ text-align: center;
341
+ }
342
+
343
+ /* The full-size view: the screen's whole image inside the dialog. */
344
+ .vg-box {
345
+ width: min(100vw - 2rem, 92rem);
346
+ max-width: none;
347
+ max-height: calc(100dvh - 2rem);
348
+ padding: 0;
349
+ border: var(--vg-rule-width) solid var(--vg-rule);
350
+ border-radius: var(--vg-radius-lg);
351
+ background: var(--vg-paper);
352
+ color: var(--vg-ink-2);
353
+ box-shadow: var(--vg-shadow);
354
+ }
355
+ .vg-box[open] {
356
+ display: flex;
357
+ flex-direction: column;
358
+ }
359
+ .vg-box::backdrop {
360
+ background: var(--vg-backdrop);
361
+ }
362
+ .vg-box-bar {
363
+ padding: 0.75rem 1rem;
364
+ border-bottom: var(--vg-rule-width) solid var(--vg-rule);
365
+ }
366
+ .vg-box-title {
367
+ flex: 1;
368
+ font-size: 1.25rem;
369
+ font-weight: 600;
370
+ color: var(--vg-ink);
371
+ }
372
+ /* On a narrow screen the header is two rows: the title with ‹ › × beside it, then the switches. */
373
+ @media (max-width: 40rem) {
374
+ .vg-box-bar {
375
+ column-gap: 0.5rem;
376
+ }
377
+ .vg-box-bar .vg-controls {
378
+ display: contents;
379
+ }
380
+ .vg-box-bar .vg-icon {
381
+ order: 1;
382
+ }
383
+ .vg-box-bar:has(.vg-seg:not([hidden]))::after {
384
+ content: "";
385
+ order: 2;
386
+ flex-basis: 100%;
387
+ }
388
+ .vg-box-bar .vg-seg {
389
+ order: 3;
390
+ }
391
+ }
392
+ .vg-box-view {
393
+ overflow: auto;
394
+ overscroll-behavior: contain;
395
+ padding: 1rem;
396
+ background: var(--vg-paper-2);
397
+ min-height: 0;
398
+ flex: 1;
399
+ }
400
+ .vg-box-view img {
401
+ display: block;
402
+ margin: 0 auto;
403
+ max-width: 100%;
404
+ height: auto;
405
+ border-radius: var(--vg-radius-sm);
406
+ border: var(--vg-rule-width) solid var(--vg-rule);
407
+ }
408
+ .vg-box-view[data-vg-size="phone"] img {
409
+ max-width: min(100%, 390px);
410
+ }
411
+ /* A shot of one screen (a phone's, a window) fits the view whole; a full-page capture scrolls. */
412
+ .vg-box[data-vg-fit] {
413
+ height: calc(100dvh - 2rem);
414
+ }
415
+ .vg-box-view[data-vg-fit] {
416
+ display: flex;
417
+ align-items: center;
418
+ justify-content: center;
419
+ }
420
+ .vg-box-view[data-vg-fit] img {
421
+ width: auto;
422
+ max-height: 100%;
423
+ object-fit: contain;
424
+ }
425
+ .vg-box-view .vg-missing {
426
+ display: grid;
427
+ min-height: 12rem;
428
+ }
429
+
430
+ @media (prefers-reduced-motion: reduce) {
431
+ .vg-thumb {
432
+ transition: none;
433
+ }
434
+ }