visualci-gallery 0.0.0-stage → 0.1.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.
@@ -0,0 +1,17 @@
1
+ import type { Size, Theme } from "./model.js";
2
+ export interface Gallery {
3
+ /** The gallery's element (the contract's `section.vg`). */
4
+ root: HTMLElement;
5
+ setTheme(theme: Theme): void;
6
+ setSize(size: Size): void;
7
+ /** Opens the full-size view of a screen by its key. */
8
+ open(key: string): void;
9
+ close(): void;
10
+ /** Removes the listeners hydrate() added. */
11
+ destroy(): void;
12
+ }
13
+ /** The gallery already hydrated on this element, if any. */
14
+ export declare function hydratedGallery(root: HTMLElement): Gallery | undefined;
15
+ /** Hydrates a gallery's markup: `el` is the contract's `section.vg`, or an element holding one. Hydrating twice
16
+ * returns the first. */
17
+ export declare function hydrate(el: HTMLElement): Gallery;
@@ -0,0 +1,328 @@
1
+ // Brings the contract's markup to life (contract/SPEC.md, "Behaviour"): one theme and one size for the whole gallery
2
+ // and its full-size view, tabs, the strip's scroll buttons, and the full-size view itself, a native <dialog> with
3
+ // previous and next. It reads only the markup, so it works the same on HTML a server rendered and on HTML mount()
4
+ // rendered. Without <dialog> (Safari before 15.4) each card stays a link to its image.
5
+ //
6
+ // Every attribute it reads or sets starts with data-vg-, so a site's own [data-theme] rules never reach the gallery.
7
+ const hydrated = new WeakMap();
8
+ function pageTheme() {
9
+ const set = document.documentElement.getAttribute("data-theme");
10
+ if (set === "light" || set === "dark")
11
+ return set;
12
+ return matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
13
+ }
14
+ function canOpen() {
15
+ return typeof HTMLDialogElement === "function" && typeof HTMLDialogElement.prototype.showModal === "function";
16
+ }
17
+ function reducedMotion() {
18
+ return matchMedia("(prefers-reduced-motion: reduce)").matches;
19
+ }
20
+ /** An image that can't load shows its description instead, in the same place. */
21
+ function watch(img) {
22
+ const fail = () => {
23
+ const span = document.createElement("span");
24
+ span.className = "vg-img vg-missing";
25
+ span.setAttribute("data-vg-size", img.getAttribute("data-vg-size") ?? "");
26
+ span.setAttribute("data-vg-theme", img.getAttribute("data-vg-theme") ?? "");
27
+ span.textContent = img.alt;
28
+ img.replaceWith(span);
29
+ };
30
+ if (img.complete && img.getAttribute("src") && img.naturalWidth === 0)
31
+ fail();
32
+ else
33
+ img.addEventListener("error", fail, { once: true });
34
+ }
35
+ const listOf = (value) => (value ?? "").split(" ").filter(Boolean);
36
+ const toArray = (list) => Array.prototype.slice.call(list);
37
+ /** The gallery already hydrated on this element, if any. */
38
+ export function hydratedGallery(root) {
39
+ return hydrated.get(root);
40
+ }
41
+ /** Hydrates a gallery's markup: `el` is the contract's `section.vg`, or an element holding one. Hydrating twice
42
+ * returns the first. */
43
+ export function hydrate(el) {
44
+ const found = el.matches("[data-vg]") ? el : el.querySelector("[data-vg]");
45
+ if (!found)
46
+ throw new Error("hydrate: no gallery markup ([data-vg]) in this element");
47
+ const root = found;
48
+ const existing = hydrated.get(root);
49
+ if (existing)
50
+ return existing;
51
+ const box = root.querySelector(".vg-box");
52
+ const view = box.querySelector(".vg-box-view");
53
+ const boxTitle = box.querySelector(".vg-box-title");
54
+ const all = (selector) => toArray(root.querySelectorAll(selector));
55
+ const tabs = all('[role="tab"]');
56
+ const track = root.querySelector(".vg-track");
57
+ const followsPage = root.getAttribute("data-vg-theme-source") === "page";
58
+ let current = null;
59
+ let opener = null;
60
+ const theme = () => root.getAttribute("data-vg-theme") ?? "light";
61
+ const size = () => root.getAttribute("data-vg-size") ?? "desktop";
62
+ const panel = () => root.querySelector(".vg-panel:not([hidden])");
63
+ const panelOf = (t) => all(".vg-panel").find((p) => p.id === t.getAttribute("aria-controls")) ?? null;
64
+ const cardOf = (key, within) => toArray(within.querySelectorAll("[data-vg-screen]")).find((c) => c.getAttribute("data-vg-screen") === key) ?? null;
65
+ const sizesOf = (el) => listOf(el?.getAttribute("data-vg-sizes"));
66
+ /** The card's image for the gallery's theme and size. */
67
+ const shownIn = (card) => card.querySelector(`.vg-img[data-vg-size="${size()}"][data-vg-theme~="${theme()}"]`);
68
+ function sync() {
69
+ // Each card links to the image it shows, so a middle click or a browser without <dialog> opens that one.
70
+ for (const card of all(".vg-card")) {
71
+ const src = shownIn(card)?.getAttribute("src");
72
+ const link = card.querySelector("a.vg-thumb");
73
+ if (link && src)
74
+ link.setAttribute("href", src);
75
+ }
76
+ if (box.open && current)
77
+ show(current);
78
+ }
79
+ function set(key, value) {
80
+ root.setAttribute(`data-vg-${key}`, value);
81
+ for (const b of all(`[data-vg-set-${key}]`)) {
82
+ b.setAttribute("aria-pressed", String(b.getAttribute(`data-vg-set-${key}`) === value));
83
+ }
84
+ sync();
85
+ }
86
+ // The size the reader chose (phone to begin with on a narrow screen). A tab without it shows the size it has,
87
+ // without changing the choice, so the next tab is back at the chosen size.
88
+ let chosen = matchMedia("(max-width: 47.99rem)").matches ? "phone" : "desktop";
89
+ function fit() {
90
+ const sizes = sizesOf(panel());
91
+ set("size", sizes.length === 0 || sizes.indexOf(chosen) !== -1 ? chosen : sizes[0]);
92
+ }
93
+ function select(tab, focus = false) {
94
+ for (const t of tabs) {
95
+ const on = t === tab;
96
+ t.setAttribute("aria-selected", String(on));
97
+ t.tabIndex = on ? 0 : -1;
98
+ const p = panelOf(t);
99
+ if (p)
100
+ p.hidden = !on;
101
+ }
102
+ if (focus)
103
+ tab.focus();
104
+ fit();
105
+ }
106
+ /** The cards the full-size view steps through: the shown panel's, at the gallery's size. */
107
+ function cards() {
108
+ return all(".vg-panel:not([hidden]) .vg-card").filter((c) => sizesOf(c).indexOf(size()) !== -1);
109
+ }
110
+ function show(card) {
111
+ current = card;
112
+ boxTitle.textContent = card.querySelector(".vg-card-title")?.textContent ?? "";
113
+ // The view's size buttons: only the sizes this screen has, so switching never shows nothing.
114
+ const sizes = sizesOf(card);
115
+ const boxSizes = box.querySelector(".vg-box-sizes");
116
+ if (boxSizes) {
117
+ boxSizes.hidden = sizes.length < 2;
118
+ for (const b of toArray(boxSizes.querySelectorAll("[data-vg-set-size]"))) {
119
+ b.hidden = sizes.indexOf(b.getAttribute("data-vg-set-size")) === -1;
120
+ }
121
+ }
122
+ const shown = shownIn(card);
123
+ view.setAttribute("data-vg-size", size());
124
+ // One screen's worth fits the view whole: a window (a group shown whole), a phone screen at most 2.4 times as
125
+ // tall as it is wide, or a desktop one at most 0.8 times. A taller full-page capture scrolls. The dialog carries
126
+ // the mark too, so its height is set without :has().
127
+ const tall = Number(shown?.getAttribute("height")) / Number(shown?.getAttribute("width"));
128
+ const whole = shown instanceof HTMLImageElement &&
129
+ (card.getAttribute("data-vg-fit") === "contain" || tall <= (size() === "phone" ? 2.4 : 0.8));
130
+ for (const el of [box, view]) {
131
+ if (whole)
132
+ el.setAttribute("data-vg-fit", "");
133
+ else
134
+ el.removeAttribute("data-vg-fit");
135
+ }
136
+ // A new element each time: reusing one keeps the previous picture on screen until the new one loads.
137
+ view.replaceChildren();
138
+ if (shown instanceof HTMLImageElement) {
139
+ const big = document.createElement("img");
140
+ const src = shown.getAttribute("src") ?? "";
141
+ big.alt = shown.alt;
142
+ // The image's own size from the markup (its .width is the thumbnail's rendered width).
143
+ big.setAttribute("width", shown.getAttribute("width") ?? "");
144
+ big.setAttribute("height", shown.getAttribute("height") ?? "");
145
+ big.decoding = "async";
146
+ const x2 = shown.getAttribute("data-src-2x");
147
+ if (x2) {
148
+ big.srcset = `${src} 1x, ${x2} 2x`;
149
+ // A 2x copy that can't load: the 1x one.
150
+ big.addEventListener("error", () => big.removeAttribute("srcset"), { once: true });
151
+ }
152
+ big.src = src;
153
+ view.append(big);
154
+ }
155
+ else if (shown) {
156
+ view.append(shown.cloneNode(true));
157
+ }
158
+ view.scrollTop = 0;
159
+ }
160
+ function open(card) {
161
+ // A screen without the gallery's size (opened by key) shows the size it has.
162
+ const sizes = sizesOf(card);
163
+ if (sizes.length && sizes.indexOf(size()) === -1)
164
+ set("size", sizes[0]);
165
+ opener = card.querySelector("[data-vg-open]");
166
+ show(card);
167
+ if (!box.open) {
168
+ box.showModal();
169
+ lockPage();
170
+ }
171
+ }
172
+ // The page behind the open view doesn't scroll. A page that had a scrollbar keeps its gutter, so it doesn't shift
173
+ // sideways; a short page gets none.
174
+ let unlock = null;
175
+ function lockPage() {
176
+ if (unlock)
177
+ return;
178
+ const html = document.documentElement;
179
+ const before = [html.style.overflow, html.style.getPropertyValue("scrollbar-gutter")];
180
+ if (html.scrollHeight > html.clientHeight)
181
+ html.style.setProperty("scrollbar-gutter", "stable");
182
+ html.style.overflow = "hidden";
183
+ unlock = () => {
184
+ html.style.overflow = before[0];
185
+ if (before[1])
186
+ html.style.setProperty("scrollbar-gutter", before[1]);
187
+ else
188
+ html.style.removeProperty("scrollbar-gutter");
189
+ unlock = null;
190
+ };
191
+ }
192
+ function step(by) {
193
+ const list = cards();
194
+ if (!current || list.length === 0)
195
+ return;
196
+ const i = list.indexOf(current);
197
+ // From a screen that isn't in the list (it lacks this size): the first or the last.
198
+ const next = i === -1 ? (by > 0 ? 0 : list.length - 1) : (i + by + list.length) % list.length;
199
+ show(list[next]);
200
+ }
201
+ function edges() {
202
+ if (!track)
203
+ return;
204
+ const prev = root.querySelector('[data-vg-scroll="-1"]');
205
+ const next = root.querySelector('[data-vg-scroll="1"]');
206
+ if (prev)
207
+ prev.disabled = track.scrollLeft <= 1;
208
+ if (next)
209
+ next.disabled = track.scrollLeft + track.clientWidth >= track.scrollWidth - 1;
210
+ }
211
+ const onClick = (e) => {
212
+ const target = e.target;
213
+ if (target === box)
214
+ return box.close(); // the dimmed backdrop, outside the dialog's box
215
+ const link = target.closest("a[data-vg-open]");
216
+ if (link && root.contains(link)) {
217
+ if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || !canOpen())
218
+ return;
219
+ e.preventDefault();
220
+ open(link.closest(".vg-card"));
221
+ return;
222
+ }
223
+ const b = target.closest("button");
224
+ if (!b || !root.contains(b))
225
+ return;
226
+ const setTheme = b.getAttribute("data-vg-set-theme");
227
+ const setSize = b.getAttribute("data-vg-set-size");
228
+ const stepBy = b.getAttribute("data-vg-step");
229
+ const scroll = b.getAttribute("data-vg-scroll");
230
+ if (setTheme)
231
+ set("theme", setTheme);
232
+ else if (setSize) {
233
+ chosen = setSize;
234
+ set("size", setSize);
235
+ }
236
+ else if (stepBy)
237
+ step(Number(stepBy));
238
+ else if (scroll && track) {
239
+ track.scrollBy({ left: Number(scroll) * track.clientWidth * 0.9, behavior: reducedMotion() ? "auto" : "smooth" });
240
+ }
241
+ else if (b.hasAttribute("data-vg-close"))
242
+ box.close();
243
+ else if (b.getAttribute("role") === "tab")
244
+ select(b);
245
+ };
246
+ const onKey = (e) => {
247
+ const target = e.target;
248
+ if (box.open && box.contains(target)) {
249
+ if (e.key === "ArrowRight")
250
+ step(1);
251
+ else if (e.key === "ArrowLeft")
252
+ step(-1);
253
+ return;
254
+ }
255
+ if (target.getAttribute("role") !== "tab")
256
+ return;
257
+ const i = tabs.indexOf(target);
258
+ const next = e.key === "ArrowRight" ? i + 1 : e.key === "ArrowLeft" ? i - 1 : e.key === "Home" ? 0 : e.key === "End" ? tabs.length - 1 : null;
259
+ if (next === null || i === -1)
260
+ return;
261
+ e.preventDefault();
262
+ select(tabs[(next + tabs.length) % tabs.length], true);
263
+ };
264
+ const onClose = () => {
265
+ unlock?.();
266
+ current = null;
267
+ view.replaceChildren();
268
+ if (opener?.isConnected)
269
+ opener.focus();
270
+ opener = null;
271
+ };
272
+ // A gallery without theme buttons follows the page: <html data-theme> as it changes, else the reader's setting.
273
+ const scheme = matchMedia("(prefers-color-scheme: dark)");
274
+ const onScheme = () => set("theme", pageTheme());
275
+ let observer = null;
276
+ if (followsPage) {
277
+ observer = new MutationObserver(onScheme);
278
+ observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
279
+ scheme.addEventListener?.("change", onScheme);
280
+ }
281
+ // The strip's buttons follow its width too (a rotated phone, a gallery that was hidden when it hydrated).
282
+ const resize = track && typeof ResizeObserver === "function" ? new ResizeObserver(edges) : null;
283
+ if (track && resize)
284
+ resize.observe(track);
285
+ root.addEventListener("click", onClick);
286
+ root.addEventListener("keydown", onKey);
287
+ box.addEventListener("close", onClose);
288
+ track?.addEventListener("scroll", edges, { passive: true });
289
+ for (const img of all("img.vg-img"))
290
+ watch(img);
291
+ set("theme", pageTheme());
292
+ fit();
293
+ edges();
294
+ const gallery = {
295
+ root,
296
+ setTheme: (t) => set("theme", t),
297
+ setSize: (s) => {
298
+ chosen = s;
299
+ fit();
300
+ },
301
+ open: (key) => {
302
+ for (const t of tabs) {
303
+ const p = panelOf(t);
304
+ if (p && cardOf(key, p))
305
+ select(t);
306
+ }
307
+ const shownPanel = panel();
308
+ const card = shownPanel ? cardOf(key, shownPanel) : null;
309
+ if (!card)
310
+ throw new Error(`no screen "${key}" in this gallery`);
311
+ open(card);
312
+ },
313
+ close: () => box.close(),
314
+ destroy: () => {
315
+ unlock?.();
316
+ root.removeEventListener("click", onClick);
317
+ root.removeEventListener("keydown", onKey);
318
+ box.removeEventListener("close", onClose);
319
+ track?.removeEventListener("scroll", edges);
320
+ observer?.disconnect();
321
+ resize?.disconnect();
322
+ scheme.removeEventListener?.("change", onScheme);
323
+ hydrated.delete(root);
324
+ },
325
+ };
326
+ hydrated.set(root, gallery);
327
+ return gallery;
328
+ }
@@ -0,0 +1,10 @@
1
+ import { type Gallery } from "./hydrate.js";
2
+ import { type LoadOptions } from "./load.js";
3
+ export { buildModel, parseShot, humanize, slugify, DEFAULT_TITLE } from "./model.js";
4
+ export type { Manifest, ManifestGroup, ManifestItem, Model, Group, Screen, Variant, Options, Size, Theme } from "./model.js";
5
+ export { render, escapeHtml } from "./render.js";
6
+ export { hydrate, type Gallery } from "./hydrate.js";
7
+ export { load, type LoadOptions } from "./load.js";
8
+ /** Renders the gallery into an empty element and hydrates it. When the manifest can't be read, the element says so
9
+ * and the promise rejects. */
10
+ export declare function mount(el: HTMLElement, options: LoadOptions): Promise<Gallery>;
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ // visualci-gallery: a screenshots page from VisualCI's public gallery (https://visualci.com/docs/gallery/).
2
+ //
3
+ // mount(el, { manifest }) fetches the manifest, renders the gallery into an empty element and hydrates it.
4
+ // hydrate(el) brings markup a server rendered (the Astro component, the Ruby gem, the Python package)
5
+ // to life.
6
+ // load(options) the manifest's model, for rendering at build time: it throws when the manifest can't be
7
+ // read or has nothing to show, so a static site's build fails instead of shipping an empty
8
+ // page.
9
+ import { render } from "./render.js";
10
+ import { hydrate, hydratedGallery } from "./hydrate.js";
11
+ import { load } from "./load.js";
12
+ export { buildModel, parseShot, humanize, slugify, DEFAULT_TITLE } from "./model.js";
13
+ export { render, escapeHtml } from "./render.js";
14
+ export { hydrate } from "./hydrate.js";
15
+ export { load } from "./load.js";
16
+ /** Renders the gallery into an empty element and hydrates it. When the manifest can't be read, the element says so
17
+ * and the promise rejects. */
18
+ export async function mount(el, options) {
19
+ let model;
20
+ try {
21
+ model = await load(options);
22
+ }
23
+ catch (e) {
24
+ const p = document.createElement("p");
25
+ p.className = "vg-error";
26
+ p.textContent = "The screenshots couldn't be loaded.";
27
+ el.replaceChildren(p);
28
+ throw e;
29
+ }
30
+ // Mounting again replaces the gallery: the old one's listeners go first.
31
+ const old = el.querySelector("[data-vg]");
32
+ if (old)
33
+ hydratedGallery(old)?.destroy();
34
+ el.innerHTML = render(model);
35
+ return hydrate(el);
36
+ }
package/dist/load.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { type Model, type Options } from "./model.js";
2
+ export interface LoadOptions extends Options {
3
+ /** The manifest's URL: `https://app.visualci.com/g/<org>/<project>.json`. */
4
+ manifest: string;
5
+ /** How long to wait for it, in milliseconds. Default 20000. */
6
+ timeout?: number;
7
+ /** How many times to try. Default 3. */
8
+ attempts?: number;
9
+ /** A fetch to use in place of the global one. */
10
+ fetch?: typeof fetch;
11
+ }
12
+ /** Fetches the manifest and builds its model. Throws, naming the URL, when it can't be read or shows nothing. */
13
+ export declare function load(options: LoadOptions): Promise<Model>;
package/dist/load.js ADDED
@@ -0,0 +1,40 @@
1
+ // Reading the manifest: shared by mount() in the browser and by build-time renderers (the Astro component).
2
+ import { buildModel } from "./model.js";
3
+ /** A signal that aborts after `ms` (AbortSignal.timeout is missing before Safari 16). */
4
+ function timeout(ms) {
5
+ if (typeof AbortSignal.timeout === "function")
6
+ return AbortSignal.timeout(ms);
7
+ const controller = new AbortController();
8
+ setTimeout(() => controller.abort(), ms);
9
+ return controller.signal;
10
+ }
11
+ /** Fetches the manifest and builds its model. Throws, naming the URL, when it can't be read or shows nothing. */
12
+ export async function load(options) {
13
+ const get = options.fetch ?? fetch;
14
+ const attempts = Math.max(1, options.attempts ?? 3);
15
+ let last;
16
+ let manifest;
17
+ for (let attempt = 1; attempt <= attempts; attempt++) {
18
+ try {
19
+ const res = await get(options.manifest, { signal: timeout(options.timeout ?? 20000) });
20
+ if (!res.ok)
21
+ throw new Error(`HTTP ${res.status}`);
22
+ manifest = (await res.json());
23
+ break;
24
+ }
25
+ catch (e) {
26
+ last = e;
27
+ if (attempt < attempts)
28
+ await new Promise((r) => setTimeout(r, attempt * 1000));
29
+ }
30
+ }
31
+ if (manifest === undefined) {
32
+ throw new Error(`The screenshots gallery couldn't read ${options.manifest}: ${last instanceof Error ? last.message : String(last)}`);
33
+ }
34
+ try {
35
+ return buildModel(manifest, options);
36
+ }
37
+ catch (e) {
38
+ throw new Error(`The screenshots gallery can't show ${options.manifest}: ${e instanceof Error ? e.message : String(e)}`);
39
+ }
40
+ }
@@ -0,0 +1,127 @@
1
+ export type Theme = "light" | "dark";
2
+ export type Size = "desktop" | "phone";
3
+ /** VisualCI's public gallery manifest (https://visualci.com/docs/gallery/). */
4
+ export interface Manifest {
5
+ project?: string;
6
+ groups: ManifestGroup[];
7
+ }
8
+ export interface ManifestGroup {
9
+ name: string;
10
+ title?: string | null;
11
+ items: ManifestItem[];
12
+ }
13
+ export interface ManifestItem {
14
+ name: string;
15
+ url: string;
16
+ width: number;
17
+ height: number;
18
+ platform?: string;
19
+ sha256?: string;
20
+ since?: string;
21
+ }
22
+ export interface ScreenOptions {
23
+ title?: string;
24
+ caption?: string;
25
+ }
26
+ export interface GroupOptions {
27
+ title?: string;
28
+ /** The size of a shot whose name gives no width, over the image's shape (`desktop` for a Mac app's windows). */
29
+ size?: Size;
30
+ /** "cover" (default): the image fills its card, cropped at the bottom. "contain": shown whole and centred, for
31
+ * windows. */
32
+ fit?: Fit;
33
+ }
34
+ export type Fit = "cover" | "contain";
35
+ /** What a site can set. Every field is optional and JSON-shaped, so the server renderers take the same options. */
36
+ export interface Options {
37
+ /** The gallery's heading and accessible name. Default "Screenshots"; null keeps the name but shows no heading. */
38
+ title?: string | null;
39
+ /** The level of the gallery's heading (2 by default); groups and cards take the levels below it. */
40
+ headingLevel?: number;
41
+ /** The prefix of every id in the markup, for more than one gallery on a page. Default "vg". */
42
+ id?: string;
43
+ /** Titles and captions by screen key (`ios/usage`, `overview`). */
44
+ screens?: Record<string, ScreenOptions>;
45
+ /** Screen keys in the order they show; the rest follow by key. */
46
+ order?: string[];
47
+ /** By group name: its title (over the manifest's), the size of shots whose names give no width, and how its images
48
+ * fit their cards. */
49
+ groups?: Record<string, GroupOptions>;
50
+ /** Group names in the order they show; the rest follow in the manifest's order. */
51
+ groupOrder?: string[];
52
+ /** The "Screenshots by VisualCI" line. Default true. */
53
+ credit?: boolean;
54
+ /** "grid" (default): tabs per group, a grid of cards. "strip": every screen in one row that scrolls sideways, for
55
+ * a homepage band. */
56
+ layout?: Layout;
57
+ /** Light and Dark buttons. Default true for the grid; the strip never has them. Without them the gallery follows
58
+ * the page: `<html data-theme>`, else the reader's setting. */
59
+ themeSwitch?: boolean;
60
+ /** A link under the gallery, such as the strip's link to the full page. */
61
+ seeAll?: {
62
+ href: string;
63
+ text?: string;
64
+ } | null;
65
+ }
66
+ export type Layout = "grid" | "strip";
67
+ export interface Variant {
68
+ size: Size;
69
+ theme: Theme;
70
+ url: string;
71
+ url2x: string | null;
72
+ width: number;
73
+ height: number;
74
+ }
75
+ export interface Screen {
76
+ key: string;
77
+ title: string;
78
+ caption: string | null;
79
+ variants: Variant[];
80
+ }
81
+ export interface Group {
82
+ name: string;
83
+ title: string;
84
+ slug: string;
85
+ fit: Fit;
86
+ sizes: Size[];
87
+ screens: Screen[];
88
+ }
89
+ export interface Model {
90
+ layout: Layout;
91
+ themeSwitch: boolean;
92
+ seeAll: {
93
+ href: string;
94
+ text: string;
95
+ } | null;
96
+ title: string | null;
97
+ label: string;
98
+ headingLevel: number;
99
+ id: string;
100
+ credit: boolean;
101
+ groups: Group[];
102
+ }
103
+ export declare const DEFAULT_TITLE = "Screenshots";
104
+ export declare const SEE_ALL_TEXT = "See all screenshots";
105
+ export interface Shot {
106
+ /** The screen's key: the name without its theme, width and 2x parts. */
107
+ key: string;
108
+ /** null when the name says nothing: the shot stands for both themes. */
109
+ theme: Theme | null;
110
+ size: Size;
111
+ x2: boolean;
112
+ /** The CSS width the name gives (`-1440`), or null. */
113
+ cssWidth: number | null;
114
+ }
115
+ /** How a manifest name pairs: `<screen>-<theme>[-<width>][-2x]`, or `<screen>/<width>-<theme>[-2x]`. A name in
116
+ * neither shape is a screen of its own, in both themes. Under 768 wide is a phone; with no width, a portrait image
117
+ * is a phone and a landscape one a desktop, unless `size` says. */
118
+ export declare function parseShot(name: string, width: number, height: number, size?: Size): Shot;
119
+ /** `billing/free` → "Billing, free". */
120
+ export declare function humanize(segments: string[]): string;
121
+ /** A group's name as an id: ASCII lower case, runs of anything else as one hyphen. */
122
+ export declare function slugify(name: string): string;
123
+ /** A width or height: a whole number from 1 to MAX_SIZE, so the density maths stays exact in every language. */
124
+ export declare const MAX_SIZE = 1000000;
125
+ /** The manifest as the gallery shows it (contract/SPEC.md). Throws when it or the options are invalid, or nothing in
126
+ * it can be shown. */
127
+ export declare function buildModel(manifest: Manifest, options?: Options): Model;