visualci-gallery 0.2.1 → 0.3.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.
@@ -75,14 +75,14 @@ var VisualCIGallery = (function () {
75
75
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
76
76
  var __defNormalProp = function (obj, key, value) { return key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value: value }) : obj[key] = value; };
77
77
  var __spreadValues = function (a, b) {
78
- var e_1, _w;
78
+ var e_1, _v;
79
79
  for (var prop in b || (b = {}))
80
80
  if (__hasOwnProp.call(b, prop))
81
81
  __defNormalProp(a, prop, b[prop]);
82
82
  if (__getOwnPropSymbols)
83
83
  try {
84
- for (var _x = __values(__getOwnPropSymbols(b)), _y = _x.next(); !_y.done; _y = _x.next()) {
85
- var prop = _y.value;
84
+ for (var _w = __values(__getOwnPropSymbols(b)), _x = _w.next(); !_x.done; _x = _w.next()) {
85
+ var prop = _x.value;
86
86
  if (__propIsEnum.call(b, prop))
87
87
  __defNormalProp(a, prop, b[prop]);
88
88
  }
@@ -90,7 +90,7 @@ var VisualCIGallery = (function () {
90
90
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
91
91
  finally {
92
92
  try {
93
- if (_y && !_y.done && (_w = _x.return)) _w.call(_x);
93
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
94
94
  }
95
95
  finally { if (e_1) throw e_1.error; }
96
96
  }
@@ -102,22 +102,22 @@ var VisualCIGallery = (function () {
102
102
  __defProp(target, name, { get: all[name], enumerable: true });
103
103
  };
104
104
  var __copyProps = function (to, from, except, desc) {
105
- var e_2, _w;
105
+ var e_2, _v;
106
106
  if (from && typeof from === "object" || typeof from === "function") {
107
107
  var _loop_1 = function (key) {
108
108
  if (!__hasOwnProp.call(to, key) && key !== except)
109
109
  __defProp(to, key, { get: function () { return from[key]; }, enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
110
110
  };
111
111
  try {
112
- for (var _x = __values(__getOwnPropNames(from)), _y = _x.next(); !_y.done; _y = _x.next()) {
113
- var key = _y.value;
112
+ for (var _w = __values(__getOwnPropNames(from)), _x = _w.next(); !_x.done; _x = _w.next()) {
113
+ var key = _x.value;
114
114
  _loop_1(key);
115
115
  }
116
116
  }
117
117
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
118
118
  finally {
119
119
  try {
120
- if (_y && !_y.done && (_w = _x.return)) _w.call(_x);
120
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
121
121
  }
122
122
  finally { if (e_2) throw e_2.error; }
123
123
  }
@@ -144,67 +144,131 @@ var VisualCIGallery = (function () {
144
144
  function escapeHtml(s) {
145
145
  return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
146
146
  }
147
- var SIZE_LABEL = { desktop: "Desktop", phone: "Phone" };
148
- function themeSwitch() {
149
- return '<div class="vg-seg" role="group" aria-label="Theme"><button type="button" data-vg-set-theme="light" aria-pressed="false">Light</button><button type="button" data-vg-set-theme="dark" aria-pressed="false">Dark</button></div>';
147
+ function dimSwitch(d, keys, place, current, id) {
148
+ var label = function (k) { return escapeHtml(d.values.find(function (v) { return v.key === k; }).label); };
149
+ var name = escapeHtml(d.label);
150
+ if (keys.length <= 3) {
151
+ return "<div class=\"vg-seg\" role=\"group\" aria-label=\"".concat(name, "\" data-vg-dim=\"").concat(d.key, "\">") + keys.map(function (k) { return "<button type=\"button\" data-vg-set=\"".concat(k, "\" aria-pressed=\"false\">").concat(label(k), "</button>"); }).join("") + "</div>";
152
+ }
153
+ var list = "".concat(id, "-").concat(place, "--").concat(d.key);
154
+ return "<div class=\"vg-combo\" data-vg-dim=\"".concat(d.key, "\"><button type=\"button\" class=\"vg-combo-button\" role=\"combobox\" aria-label=\"").concat(name, "\" aria-haspopup=\"listbox\" aria-expanded=\"false\" aria-controls=\"").concat(list, "\">").concat(label(current), "</button><ul class=\"vg-combo-list\" role=\"listbox\" id=\"").concat(list, "\" aria-label=\"").concat(name, "\" hidden>") + keys.map(function (k) { return "<li role=\"option\" id=\"".concat(list, "--").concat(k, "\" data-vg-set=\"").concat(k, "\" aria-selected=\"false\">").concat(label(k), "</li>"); }).join("") + "</ul></div>";
150
155
  }
151
- function sizeSwitch(sizes, extra) {
152
- if (extra === void 0) { extra = ""; }
153
- return "<div class=\"vg-seg".concat(extra, "\" role=\"group\" aria-label=\"Screen size\">") + sizes.map(function (s) { return "<button type=\"button\" data-vg-set-size=\"".concat(s, "\" aria-pressed=\"false\">").concat(SIZE_LABEL[s], "</button>"); }).join("") + "</div>";
156
+ function switches(model, values, place, current, id) {
157
+ return model.dimensions.filter(function (d) { return values[d.key].length > 1 && (d.key !== "theme" || model.themeSwitch); }).map(function (d) { return dimSwitch(d, values[d.key], place, current[d.key], id); }).join("");
154
158
  }
155
159
  function bytesAttrs(v) {
156
160
  var shown = v.thumb ? v.thumb.bytes : v.bytes;
157
161
  return (shown !== null ? " data-vg-bytes=\"".concat(shown, "\"") : "") + (v.thumb && v.bytes !== null ? " data-vg-full-bytes=\"".concat(v.bytes, "\"") : "") + (v.url2x && v.bytes2x !== null ? " data-vg-2x-bytes=\"".concat(v.bytes2x, "\"") : "");
158
162
  }
159
- function image(title, v, themes) {
160
- var alt = "".concat(title, ", ").concat(SIZE_LABEL[v.size].toLowerCase(), ", ").concat(themes.join(" and "));
161
- return "<img class=\"vg-img\" data-vg-size=\"".concat(v.size, "\" data-vg-theme=\"").concat(themes.join(" "), "\" src=\"").concat(escapeHtml(v.thumb ? v.thumb.url : v.url), "\"") + (v.thumb ? " data-src-full=\"".concat(escapeHtml(v.url), "\"") : "") + (v.url2x ? " data-src-2x=\"".concat(escapeHtml(v.url2x), "\"") : "") + bytesAttrs(v) + " width=\"".concat(v.width, "\" height=\"").concat(v.height, "\" alt=\"").concat(escapeHtml(alt), "\" loading=\"lazy\" decoding=\"async\">");
162
- }
163
- function card(sc, sizes, heading, caption, fit) {
164
- var e_3, _w;
165
- var _a, _b;
166
- var imgs = [];
167
- var shown = [];
168
- var first = null;
169
- var _loop_2 = function (size) {
170
- var e_4, _x;
171
- var at = sc.variants.filter(function (v) { return v.size === size; });
172
- if (at.length === 0)
163
+ var comboOf = function (model, values) { return model.dimensions.map(function (d) { return values[d.key]; }).join("."); };
164
+ function cardCombo(model, sc, choice) {
165
+ var e_3, _v, e_4, _w;
166
+ var out = {};
167
+ var _loop_2 = function (d) {
168
+ var has = sc.variants.some(function (v) { return v.values[d.key] === choice[d.key]; });
169
+ out[d.key] = !has && d.missing !== "hide" ? sc.variants[0].values[d.key] : choice[d.key];
170
+ };
171
+ try {
172
+ for (var _x = __values(model.dimensions), _y = _x.next(); !_y.done; _y = _x.next()) {
173
+ var d = _y.value;
174
+ _loop_2(d);
175
+ }
176
+ }
177
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
178
+ finally {
179
+ try {
180
+ if (_y && !_y.done && (_v = _x.return)) _v.call(_x);
181
+ }
182
+ finally { if (e_3) throw e_3.error; }
183
+ }
184
+ var _loop_3 = function (d) {
185
+ if (d.missing === "hide" || sc.variants.some(function (v) { return v.values[d.key] === choice[d.key]; }))
173
186
  return "continue";
174
- shown.push(size);
175
- first != null ? first : first = at[0];
176
- if (at[0].url === at[1].url && at[0].url2x === at[1].url2x && ((_a = at[0].thumb) == null ? void 0 : _a.url) === ((_b = at[1].thumb) == null ? void 0 : _b.url)) {
177
- imgs.push(image(sc.title, at[0], ["light", "dark"]));
187
+ var match = sc.variants.find(function (v) { return model.dimensions.every(function (e) { return e.key === d.key || v.values[e.key] === out[e.key]; }); });
188
+ if (match)
189
+ out[d.key] = match.values[d.key];
190
+ };
191
+ try {
192
+ for (var _z = __values(model.dimensions), _0 = _z.next(); !_0.done; _0 = _z.next()) {
193
+ var d = _0.value;
194
+ _loop_3(d);
178
195
  }
196
+ }
197
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
198
+ finally {
199
+ try {
200
+ if (_0 && !_0.done && (_w = _z.return)) _w.call(_z);
201
+ }
202
+ finally { if (e_4) throw e_4.error; }
203
+ }
204
+ return out;
205
+ }
206
+ function cardOff(model, sc, choice) {
207
+ return model.dimensions.some(function (d) { return d.missing === "hide" && !sc.variants.some(function (v) { return v.values[d.key] === choice[d.key]; }); });
208
+ }
209
+ function card(model, g, sc, choice, variants, heading, caption, fit) {
210
+ var e_5, _v;
211
+ var _a;
212
+ var imgs = [];
213
+ var _loop_4 = function (v) {
214
+ var same = imgs.find(function (i) {
215
+ var _a2, _b;
216
+ return i.variants[0].url === v.url && i.variants[0].url2x === v.url2x && ((_a2 = i.variants[0].thumb) == null ? void 0 : _a2.url) === ((_b = v.thumb) == null ? void 0 : _b.url);
217
+ });
218
+ if (same)
219
+ same.variants.push(v);
179
220
  else
180
- try {
181
- for (var at_1 = (e_4 = void 0, __values(at)), at_1_1 = at_1.next(); !at_1_1.done; at_1_1 = at_1.next()) {
182
- var v = at_1_1.value;
183
- imgs.push(image(sc.title, v, [v.theme]));
184
- }
185
- }
186
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
187
- finally {
188
- try {
189
- if (at_1_1 && !at_1_1.done && (_x = at_1.return)) _x.call(at_1);
190
- }
191
- finally { if (e_4) throw e_4.error; }
192
- }
221
+ imgs.push({ variants: [v] });
193
222
  };
194
223
  try {
195
- for (var sizes_1 = __values(sizes), sizes_1_1 = sizes_1.next(); !sizes_1_1.done; sizes_1_1 = sizes_1.next()) {
196
- var size = sizes_1_1.value;
197
- _loop_2(size);
224
+ for (var variants_1 = __values(variants), variants_1_1 = variants_1.next(); !variants_1_1.done; variants_1_1 = variants_1.next()) {
225
+ var v = variants_1_1.value;
226
+ _loop_4(v);
198
227
  }
199
228
  }
200
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
229
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
201
230
  finally {
202
231
  try {
203
- if (sizes_1_1 && !sizes_1_1.done && (_w = sizes_1.return)) _w.call(sizes_1);
232
+ if (variants_1_1 && !variants_1_1.done && (_v = variants_1.return)) _v.call(variants_1);
204
233
  }
205
- finally { if (e_3) throw e_3.error; }
234
+ finally { if (e_5) throw e_5.error; }
235
+ }
236
+ var combo = cardCombo(model, sc, choice);
237
+ var holds = function (i, c) { return i.variants.some(function (v) { return comboOf(model, v.values) === comboOf(model, c); }); };
238
+ var first = (_a = imgs.find(function (i) { return holds(i, combo); })) != null ? _a : imgs[0];
239
+ var themes = g.values.theme;
240
+ var follows = themes.includes("light") && themes.includes("dark");
241
+ var shown = function (i) {
242
+ if (!follows)
243
+ return holds(i, combo) ? "" : null;
244
+ var marks = ["light", "dark"].filter(function (t) { return holds(i, cardCombo(model, sc, __spreadProps(__spreadValues({}, choice), { theme: t }))); });
245
+ return marks.length > 0 ? marks.join(" ") : null;
246
+ };
247
+ return "<li class=\"vg-card\" data-vg-screen=\"".concat(escapeHtml(sc.key), "\"") + (cardOff(model, sc, choice) ? " data-vg-off" : "") + (fit === "contain" ? ' data-vg-fit="contain"' : "") + "><a class=\"vg-thumb\" href=\"".concat(escapeHtml(first.variants[0].url), "\" data-vg-open aria-label=\"").concat(escapeHtml(sc.title), ": view full size\">") + imgs.map(function (i) { return image(model, g, sc.title, i, shown(i)); }).join("") + "</a><".concat(heading, " class=\"vg-card-title\">").concat(escapeHtml(sc.title), "</").concat(heading, ">") + (caption && sc.caption !== null ? "<p class=\"vg-caption\">".concat(escapeHtml(sc.caption), "</p>") : "") + "</li>";
248
+ }
249
+ function image(model, g, title, i, shown) {
250
+ var e_6, _v;
251
+ var v = i.variants[0];
252
+ var parts = [title];
253
+ var _loop_5 = function (d) {
254
+ if (g.values[d.key].length < 2)
255
+ return "continue";
256
+ parts.push(d.values.filter(function (x) { return i.variants.some(function (w) { return w.values[d.key] === x.key; }); }).map(function (x) { return x.label; }).join(" and "));
257
+ };
258
+ try {
259
+ for (var _w = __values(model.dimensions), _x = _w.next(); !_x.done; _x = _w.next()) {
260
+ var d = _x.value;
261
+ _loop_5(d);
262
+ }
263
+ }
264
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
265
+ finally {
266
+ try {
267
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
268
+ }
269
+ finally { if (e_6) throw e_6.error; }
206
270
  }
207
- return "<li class=\"vg-card\" data-vg-screen=\"".concat(escapeHtml(sc.key), "\" data-vg-sizes=\"").concat(shown.join(" "), "\"") + (fit === "contain" ? ' data-vg-fit="contain"' : "") + "><a class=\"vg-thumb\" href=\"".concat(escapeHtml(first.url), "\" data-vg-open aria-label=\"").concat(escapeHtml(sc.title), ": view full size\">") + imgs.join("") + "</a><".concat(heading, " class=\"vg-card-title\">").concat(escapeHtml(sc.title), "</").concat(heading, ">") + (caption && sc.caption !== null ? "<p class=\"vg-caption\">".concat(escapeHtml(sc.caption), "</p>") : "") + "</li>";
271
+ return "<img class=\"vg-img\" data-vg-for=\"".concat(i.variants.map(function (w) { return comboOf(model, w.values); }).join(" "), "\"") + (shown !== null ? " data-vg-shown=\"".concat(shown, "\"") : "") + " src=\"".concat(escapeHtml(v.thumb ? v.thumb.url : v.url), "\"") + (v.thumb ? " data-src-full=\"".concat(escapeHtml(v.url), "\"") : "") + (v.url2x ? " data-src-2x=\"".concat(escapeHtml(v.url2x), "\"") : "") + bytesAttrs(v) + " width=\"".concat(v.width, "\" height=\"").concat(v.height, "\" alt=\"").concat(escapeHtml(parts.join(", ")), "\" loading=\"lazy\" decoding=\"async\">");
208
272
  }
209
273
  function preloadAttr(p) {
210
274
  if (p === null)
@@ -213,33 +277,102 @@ var VisualCIGallery = (function () {
213
277
  return ' data-vg-preload="off"';
214
278
  return " data-vg-preload=\"fold=".concat(p.fold, " count=").concat(p.count, " bytes=").concat(p.bytes, " parallel=").concat(p.parallel, "\"");
215
279
  }
280
+ function startChoice(model) {
281
+ var e_7, _v;
282
+ var out = {};
283
+ var _loop_6 = function (d) {
284
+ out[d.key] = model.layout === "strip" ? d.values.find(function (v) { return model.groups.some(function (g) { return g.values[d.key].includes(v.key); }); }).key : model.groups[0].values[d.key][0];
285
+ };
286
+ try {
287
+ for (var _w = __values(model.dimensions), _x = _w.next(); !_x.done; _x = _w.next()) {
288
+ var d = _x.value;
289
+ _loop_6(d);
290
+ }
291
+ }
292
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
293
+ finally {
294
+ try {
295
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
296
+ }
297
+ finally { if (e_7) throw e_7.error; }
298
+ }
299
+ return out;
300
+ }
301
+ function groupChoice(model, g, choice) {
302
+ var e_8, _v;
303
+ var out = {};
304
+ try {
305
+ for (var _w = __values(model.dimensions), _x = _w.next(); !_x.done; _x = _w.next()) {
306
+ var d = _x.value;
307
+ out[d.key] = g.values[d.key].includes(choice[d.key]) ? choice[d.key] : g.values[d.key][0];
308
+ }
309
+ }
310
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
311
+ finally {
312
+ try {
313
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
314
+ }
315
+ finally { if (e_8) throw e_8.error; }
316
+ }
317
+ return out;
318
+ }
319
+ var shapeOf = function (model, size) {
320
+ var _a;
321
+ return (_a = model.dimensions.find(function (d) { return d.key === "size"; }).values.find(function (v) { return v.key === size; }).shape) != null ? _a : "landscape";
322
+ };
216
323
  function render(model) {
324
+ var e_9, _v;
217
325
  var id = escapeHtml(model.id);
218
326
  var h = function (offset) { return "h".concat(Math.min(model.headingLevel + offset, 6)); };
219
327
  var below = model.title === null ? 0 : 1;
220
328
  var out = [];
221
- var size = model.layout === "strip" ? stripSize(model) : model.groups[0].sizes[0];
222
- out.push("<section class=\"vg\" data-vg data-vg-layout=\"".concat(model.layout, "\" aria-label=\"").concat(escapeHtml(model.label), "\" data-vg-size=\"").concat(size, "\"") + (model.themeSwitch ? "" : ' data-vg-theme-source="page"') + preloadAttr(model.preload) + ">");
329
+ var choice = startChoice(model);
330
+ var dims = model.dimensions.map(function (d) { return "".concat(d.key, ":").concat(d.missing, ":").concat(d.values.map(function (v) { return v.key; }).join(",")); }).join(" ");
331
+ var portrait = model.dimensions.find(function (d) { return d.key === "size"; }).values.filter(function (v) { return v.shape === "portrait"; }).map(function (v) { return v.key; }).join(" ");
332
+ out.push("<section class=\"vg\" data-vg data-vg-layout=\"".concat(model.layout, "\" aria-label=\"").concat(escapeHtml(model.label), "\" data-vg-dims=\"").concat(dims, "\"") + (portrait ? " data-vg-portrait=\"".concat(portrait, "\"") : "") + (model.themeSwitch ? "" : ' data-vg-theme-source="page"') + preloadAttr(model.preload) + ">");
223
333
  if (model.title !== null)
224
334
  out.push("<".concat(h(0), " class=\"vg-title\">").concat(escapeHtml(model.title), "</").concat(h(0), ">"));
225
335
  if (model.layout === "strip")
226
- strip(model, id, h(below), out);
336
+ strip(model, id, choice, h(below), out);
227
337
  else
228
- grid(model, id, h(below), h(below + 1), out);
338
+ grid(model, id, choice, h(below), h(below + 1), out);
229
339
  if (model.seeAll) {
230
340
  out.push("<p class=\"vg-see-all\"><a href=\"".concat(escapeHtml(model.seeAll.href), "\">").concat(escapeHtml(model.seeAll.text), "</a></p>"));
231
341
  }
232
342
  if (model.credit) {
233
343
  out.push('<p class="vg-credit">Screenshots by <a href="https://visualci.com">VisualCI</a></p>');
234
344
  }
345
+ var boxSwitches = "";
346
+ if (model.layout === "grid") {
347
+ var all = {};
348
+ var firsts = {};
349
+ var _loop_7 = function (d) {
350
+ all[d.key] = d.values.map(function (v) { return v.key; }).filter(function (k) { return model.groups.some(function (g) { return g.values[d.key].includes(k); }); });
351
+ firsts[d.key] = all[d.key][0];
352
+ };
353
+ try {
354
+ for (var _w = __values(model.dimensions), _x = _w.next(); !_x.done; _x = _w.next()) {
355
+ var d = _x.value;
356
+ _loop_7(d);
357
+ }
358
+ }
359
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
360
+ finally {
361
+ try {
362
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
363
+ }
364
+ finally { if (e_9) throw e_9.error; }
365
+ }
366
+ boxSwitches = switches(model, all, "box", firsts, id);
367
+ }
235
368
  out.push("<dialog class=\"vg-box\" aria-labelledby=\"".concat(id, "-box-title\">"));
236
- out.push("<div class=\"vg-box-bar\"><".concat(h(below), " class=\"vg-box-title\" id=\"").concat(id, "-box-title\"></").concat(h(below), "><div class=\"vg-controls\">") + (model.themeSwitch ? themeSwitch() : "") + (model.layout === "grid" ? sizeSwitch(["desktop", "phone"], " vg-box-sizes") : "") + '<button type="button" class="vg-icon" data-vg-step="-1" aria-label="Previous screen">\u2039</button><button type="button" class="vg-icon" data-vg-step="1" aria-label="Next screen">\u203A</button></div><button type="button" class="vg-icon" data-vg-close aria-label="Close">\xD7</button></div>');
369
+ out.push("<div class=\"vg-box-bar\"><".concat(h(below), " class=\"vg-box-title\" id=\"").concat(id, "-box-title\"></").concat(h(below), "><div class=\"vg-controls\">") + boxSwitches + '<button type="button" class="vg-icon" data-vg-step="-1" aria-label="Previous screen">\u2039</button><button type="button" class="vg-icon" data-vg-step="1" aria-label="Next screen">\u203A</button></div><button type="button" class="vg-icon" data-vg-close aria-label="Close">\xD7</button></div>');
237
370
  out.push('<div class="vg-box-view"></div>');
238
371
  out.push("</dialog>");
239
372
  out.push("</section>");
240
373
  return out.join("\n") + "\n";
241
374
  }
242
- function grid(model, id, gh, ch, out) {
375
+ function grid(model, id, choice, gh, ch, out) {
243
376
  var tabs = model.groups.length > 1;
244
377
  if (tabs) {
245
378
  out.push("<div class=\"vg-tabs\" role=\"tablist\" aria-label=\"".concat(escapeHtml(model.label), "\">"));
@@ -249,62 +382,65 @@ var VisualCIGallery = (function () {
249
382
  out.push("</div>");
250
383
  }
251
384
  model.groups.forEach(function (g, i) {
252
- var e_5, _w;
253
- out.push("<div class=\"vg-panel\" id=\"".concat(id, "-panel-").concat(g.slug, "\" data-vg-sizes=\"").concat(g.sizes.join(" "), "\"") + (tabs ? " role=\"tabpanel\" aria-labelledby=\"".concat(id, "-tab-").concat(g.slug, "\"") : "") + (i > 0 ? " hidden" : "") + ">");
254
- var controls = (model.themeSwitch ? themeSwitch() : "") + (g.sizes.length > 1 ? sizeSwitch(g.sizes) : "");
385
+ var e_10, _v;
386
+ var start = groupChoice(model, g, choice);
387
+ out.push("<div class=\"vg-panel\" id=\"".concat(id, "-panel-").concat(g.slug, "\" data-vg-shape=\"").concat(shapeOf(model, start.size), "\"") + (tabs ? " role=\"tabpanel\" aria-labelledby=\"".concat(id, "-tab-").concat(g.slug, "\"") : "") + (i > 0 ? " hidden" : "") + ">");
388
+ var controls = switches(model, g.values, "panel-".concat(g.slug), start, id);
255
389
  out.push("<div class=\"vg-bar\"><".concat(gh, " class=\"vg-group-title\">").concat(escapeHtml(g.title), "</").concat(gh, ">") + (controls ? "<div class=\"vg-controls\">".concat(controls, "</div>") : "") + "</div>");
256
390
  out.push('<ul class="vg-grid">');
257
391
  try {
258
- for (var _x = __values(g.screens), _y = _x.next(); !_y.done; _y = _x.next()) {
259
- var sc = _y.value;
260
- out.push(card(sc, g.sizes, ch, true, g.fit));
392
+ for (var _w = __values(g.screens), _x = _w.next(); !_x.done; _x = _w.next()) {
393
+ var sc = _x.value;
394
+ out.push(card(model, g, sc, start, sc.variants, ch, true, g.fit));
261
395
  }
262
396
  }
263
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
397
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
264
398
  finally {
265
399
  try {
266
- if (_y && !_y.done && (_w = _x.return)) _w.call(_x);
400
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
267
401
  }
268
- finally { if (e_5) throw e_5.error; }
402
+ finally { if (e_10) throw e_10.error; }
269
403
  }
270
404
  out.push("</ul>");
271
405
  out.push("</div>");
272
406
  });
273
407
  }
274
- function stripSize(model) {
275
- return model.groups.some(function (g) { return g.sizes.includes("desktop"); }) ? "desktop" : "phone";
276
- }
277
- function strip(model, id, ch, out) {
278
- var e_6, _w, e_7, _x;
279
- var size = stripSize(model);
280
- out.push("<div class=\"vg-panel\" id=\"".concat(id, "-strip\" data-vg-sizes=\"").concat(size, "\">"));
408
+ function strip(model, id, choice, ch, out) {
409
+ var e_11, _v, e_12, _w;
410
+ out.push("<div class=\"vg-panel\" id=\"".concat(id, "-strip\" data-vg-shape=\"").concat(shapeOf(model, choice.size), "\">"));
281
411
  out.push('<div class="vg-strip"><button type="button" class="vg-icon vg-strip-prev" data-vg-scroll="-1" aria-label="Scroll back">\u2039</button>');
282
412
  out.push('<ul class="vg-grid vg-track">');
283
413
  try {
284
- for (var _y = __values(model.groups), _z = _y.next(); !_z.done; _z = _y.next()) {
285
- var g = _z.value;
414
+ for (var _x = __values(model.groups), _y = _x.next(); !_y.done; _y = _x.next()) {
415
+ var g = _y.value;
416
+ var _loop_8 = function (sc) {
417
+ if (cardOff(model, sc, choice))
418
+ return "continue";
419
+ var combo = cardCombo(model, sc, choice);
420
+ var variants = sc.variants.filter(function (v) { return model.dimensions.every(function (d) { return d.key === "theme" || v.values[d.key] === combo[d.key]; }); });
421
+ out.push(card(model, g, sc, choice, variants, ch, false, g.fit));
422
+ };
286
423
  try {
287
- for (var _0 = (e_7 = void 0, __values(g.screens)), _1 = _0.next(); !_1.done; _1 = _0.next()) {
288
- var sc = _1.value;
289
- if (sc.variants.some(function (v) { return v.size === size; }))
290
- out.push(card(sc, [size], ch, false, g.fit));
424
+ for (var _z = (e_12 = void 0, __values(g.screens)), _0 = _z.next(); !_0.done; _0 = _z.next()) {
425
+ var sc = _0.value;
426
+ _loop_8(sc);
291
427
  }
292
428
  }
293
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
429
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
294
430
  finally {
295
431
  try {
296
- if (_1 && !_1.done && (_x = _0.return)) _x.call(_0);
432
+ if (_0 && !_0.done && (_w = _z.return)) _w.call(_z);
297
433
  }
298
- finally { if (e_7) throw e_7.error; }
434
+ finally { if (e_12) throw e_12.error; }
299
435
  }
300
436
  }
301
437
  }
302
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
438
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
303
439
  finally {
304
440
  try {
305
- if (_z && !_z.done && (_w = _y.return)) _w.call(_y);
441
+ if (_y && !_y.done && (_v = _x.return)) _v.call(_x);
306
442
  }
307
- finally { if (e_6) throw e_6.error; }
443
+ finally { if (e_11) throw e_11.error; }
308
444
  }
309
445
  out.push("</ul>");
310
446
  out.push('<button type="button" class="vg-icon vg-strip-next" data-vg-scroll="1" aria-label="Scroll forward">\u203A</button></div>');
@@ -315,28 +451,110 @@ var VisualCIGallery = (function () {
315
451
  var PRELOAD_KEYS = ["fold", "count", "bytes", "parallel"];
316
452
  var MAX_CAP = 1e12;
317
453
  var DEFAULT_TITLE = "Screenshots";
318
- var SIZES = ["desktop", "phone"];
319
- var THEMES = ["light", "dark"];
454
+ var DEFAULT_DIMENSIONS = [
455
+ {
456
+ key: "theme",
457
+ label: "Theme",
458
+ missing: "error",
459
+ values: [
460
+ { key: "light", label: "Light", below: null, shape: null },
461
+ { key: "dark", label: "Dark", below: null, shape: null }
462
+ ]
463
+ },
464
+ {
465
+ key: "size",
466
+ label: "Screen size",
467
+ missing: "hide",
468
+ values: [
469
+ { key: "desktop", label: "Desktop", below: null, shape: null },
470
+ { key: "phone", label: "Phone", below: 768, shape: null }
471
+ ]
472
+ }
473
+ ];
320
474
  var EXTENSION = /\.(?:[pP][nN][gG]|[jJ][pP][eE]?[gG]|[wW][eE][bB][pP])$/;
321
- var WIDTH_THEME = /^([0-9]+)-(light|dark)(-2x)?$/;
322
- var SCREEN_THEME = /^([\s\S]+?)-(light|dark)(?:-([0-9]+))?(-2x)?$/;
475
+ var KEY = /^[a-z0-9]+(-[a-z0-9]+)*$/;
476
+ var DIGITS = /^[0-9]+$/;
323
477
  var SEE_ALL_TEXT = "See all screenshots";
324
- function parseShot(name, width, height, size) {
325
- var parts = name.replace(EXTENSION, "").split("/");
478
+ function parseShot(name, dimensions) {
479
+ var e_13, _v, e_14, _w;
480
+ if (dimensions === void 0) { dimensions = DEFAULT_DIMENSIONS; }
481
+ var base = name.replace(EXTENSION, "");
482
+ var parts = base.split("/");
326
483
  var last = parts.pop();
327
484
  var folder = parts.join("/");
328
- var sized = function (w) { return w !== void 0 ? Number(w) < 768 ? "phone" : "desktop" : size != null ? size : height > width ? "phone" : "desktop"; };
329
- var css = function (w) { return w !== void 0 ? Number(w) : null; };
330
- var m = WIDTH_THEME.exec(last);
331
- if (m && folder) {
332
- return { key: folder, theme: m[2], size: sized(m[1]), x2: !!m[3], cssWidth: css(m[1]) };
333
- }
334
- m = SCREEN_THEME.exec(last);
335
- if (m) {
336
- var key = folder ? "".concat(folder, "/").concat(m[1]) : m[1];
337
- return { key: key, theme: m[2], size: sized(m[3]), x2: !!m[4], cssWidth: css(m[3]) };
338
- }
339
- return { key: folder ? "".concat(folder, "/").concat(last) : last, theme: null, size: sized(void 0), x2: false, cssWidth: null };
485
+ var owner = /* @__PURE__ */ new Map();
486
+ try {
487
+ for (var dimensions_1 = __values(dimensions), dimensions_1_1 = dimensions_1.next(); !dimensions_1_1.done; dimensions_1_1 = dimensions_1.next()) {
488
+ var d = dimensions_1_1.value;
489
+ try {
490
+ for (var _x = (e_14 = void 0, __values(d.values)), _y = _x.next(); !_y.done; _y = _x.next()) {
491
+ var v = _y.value;
492
+ owner.set(v.key, d.key);
493
+ }
494
+ }
495
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
496
+ finally {
497
+ try {
498
+ if (_y && !_y.done && (_w = _x.return)) _w.call(_x);
499
+ }
500
+ finally { if (e_14) throw e_14.error; }
501
+ }
502
+ }
503
+ }
504
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
505
+ finally {
506
+ try {
507
+ if (dimensions_1_1 && !dimensions_1_1.done && (_v = dimensions_1.return)) _v.call(dimensions_1);
508
+ }
509
+ finally { if (e_13) throw e_13.error; }
510
+ }
511
+ var tokens = last.split("-");
512
+ var x2 = false;
513
+ if (tokens.length > 0 && tokens[tokens.length - 1] === "2x") {
514
+ tokens.pop();
515
+ x2 = true;
516
+ }
517
+ var values = {};
518
+ var cssWidth = null;
519
+ var named = false;
520
+ for (;;) {
521
+ var peeled = false;
522
+ for (var n = tokens.length; n >= 1; n--) {
523
+ var candidate = tokens.slice(tokens.length - n).join("-");
524
+ var dim = owner.get(candidate);
525
+ if (dim !== void 0 && !Object.prototype.hasOwnProperty.call(values, dim)) {
526
+ values[dim] = candidate;
527
+ tokens.splice(tokens.length - n, n);
528
+ named = peeled = true;
529
+ break;
530
+ }
531
+ }
532
+ if (peeled)
533
+ continue;
534
+ if (cssWidth === null && tokens.length > 0 && DIGITS.test(tokens[tokens.length - 1])) {
535
+ cssWidth = Number(tokens.pop());
536
+ continue;
537
+ }
538
+ break;
539
+ }
540
+ var widthOnly = cssWidth !== null && tokens.length === 0 && folder !== "";
541
+ if (!named && !widthOnly || tokens.length === 0 && folder === "")
542
+ return { key: base, values: {}, x2: false, cssWidth: null };
543
+ var rest = tokens.join("-");
544
+ var key = tokens.length === 0 ? folder : folder ? "".concat(folder, "/").concat(rest) : rest;
545
+ return { key: key, values: values, x2: x2, cssWidth: cssWidth };
546
+ }
547
+ function sizeOf(shot, sizes, width, height, groupSize) {
548
+ var _a, _b;
549
+ if (Object.prototype.hasOwnProperty.call(shot.values, "size"))
550
+ return shot.values.size;
551
+ var open = sizes.find(function (v) { return v.below === null; }).key;
552
+ var bounded = sizes.filter(function (v) { return v.below !== null; }).sort(function (a, b) { return a.below - b.below; });
553
+ if (shot.cssWidth !== null)
554
+ return (_b = (_a = bounded.find(function (v) { return shot.cssWidth < v.below; })) == null ? void 0 : _a.key) != null ? _b : open;
555
+ if (groupSize !== void 0)
556
+ return groupSize;
557
+ return height > width && bounded.length > 0 ? bounded[0].key : open;
340
558
  }
341
559
  function humanize(segments) {
342
560
  var text = segments.map(function (s) { return s.replace(/[-_]+/g, " ").replace(/^ +| +$/g, ""); }).join(", ");
@@ -350,26 +568,26 @@ var VisualCIGallery = (function () {
350
568
  return name.replace(/[A-Z]/g, function (c) { return c.toLowerCase(); }).replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "group";
351
569
  }
352
570
  function commonFolder(keys) {
353
- var e_8, _w;
571
+ var e_15, _v;
354
572
  var folders = keys.map(function (k) { return k.split("/").slice(0, -1); });
355
573
  if (folders.length === 0)
356
574
  return [];
357
575
  var common = folders[0];
358
576
  try {
359
- for (var _x = __values(folders.slice(1)), _y = _x.next(); !_y.done; _y = _x.next()) {
360
- var f = _y.value;
577
+ for (var _w = __values(folders.slice(1)), _x = _w.next(); !_x.done; _x = _w.next()) {
578
+ var f = _x.value;
361
579
  var i = 0;
362
580
  while (i < common.length && i < f.length && common[i] === f[i])
363
581
  i++;
364
582
  common = common.slice(0, i);
365
583
  }
366
584
  }
367
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
585
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
368
586
  finally {
369
587
  try {
370
- if (_y && !_y.done && (_w = _x.return)) _w.call(_x);
588
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
371
589
  }
372
- finally { if (e_8) throw e_8.error; }
590
+ finally { if (e_15) throw e_15.error; }
373
591
  }
374
592
  return common;
375
593
  }
@@ -409,8 +627,8 @@ var VisualCIGallery = (function () {
409
627
  var isString = function (v) { return typeof v === "string"; };
410
628
  var isBytes = function (v) { return typeof v === "number" && Number.isInteger(v) && v >= 0 && v <= 1e12; };
411
629
  var isStrings = function (v) { return Array.isArray(v) && v.every(isString); };
412
- var isTexts = function (keys) { return function (v) { return isObject(v) && Object.values(v).every(function (entry) { return isObject(entry) && Object.entries(entry).every(function (_w) {
413
- var _x = __read(_w, 2), k = _x[0], x = _x[1];
630
+ var isTexts = function (keys) { return function (v) { return isObject(v) && Object.values(v).every(function (entry) { return isObject(entry) && Object.entries(entry).every(function (_v) {
631
+ var _w = __read(_v, 2), k = _w[0], x = _w[1];
414
632
  return keys.includes(k) && (x === null || isString(x));
415
633
  }); }); }; };
416
634
  function checkManifest(manifest) {
@@ -443,9 +661,9 @@ var VisualCIGallery = (function () {
443
661
  });
444
662
  }
445
663
  function buildModel(manifest, options) {
446
- var e_9, _w;
664
+ var e_16, _v;
447
665
  if (options === void 0) { options = {}; }
448
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
666
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
449
667
  checkManifest(manifest);
450
668
  if (!isObject(options))
451
669
  fail("gallery options must be an object");
@@ -454,19 +672,21 @@ var VisualCIGallery = (function () {
454
672
  var headingLevel = Math.min(Math.max(level, 1), 4);
455
673
  var title = o.title === void 0 ? DEFAULT_TITLE : (_b = opt(o.title, isString, "title")) != null ? _b : null;
456
674
  var id = (_c = opt(o.id, function (v) { return isString(v) && ID.test(v); }, "id")) != null ? _c : "vg";
675
+ var dimensions = resolveDimensions(opt(o.dimensions, checkDimensions, "dimensions"));
676
+ var sizeValues = dimensions.find(function (d) { return d.key === "size"; }).values;
457
677
  var screensOpt = (_d = opt(o.screens, isTexts(["title", "caption"]), "screens")) != null ? _d : {};
458
- var groupsOpt = (_e = opt(o.groups, function (v) { return isObject(v) && Object.values(v).every(function (entry) { return isObject(entry) && Object.entries(entry).every(function (_w) {
459
- var _x = __read(_w, 2), k = _x[0], x = _x[1];
460
- return k === "title" && (x === null || isString(x)) || k === "size" && (x === null || SIZES.includes(x)) || k === "fit" && (x === null || x === "cover" || x === "contain");
678
+ var groupsOpt = (_e = opt(o.groups, function (v) { return isObject(v) && Object.values(v).every(function (entry) { return isObject(entry) && Object.entries(entry).every(function (_v) {
679
+ var _w = __read(_v, 2), k = _w[0], x = _w[1];
680
+ return k === "title" && (x === null || isString(x)) || k === "size" && (x === null || sizeValues.some(function (v2) { return v2.key === x; })) || k === "fit" && (x === null || x === "cover" || x === "contain");
461
681
  }); }); }, "groups")) != null ? _e : {};
462
682
  var order2 = opt(o.order, isStrings, "order");
463
683
  var groupOrder = opt(o.groupOrder, isStrings, "groupOrder");
464
- var credit = (_f = opt(o.credit, function (v) { return typeof v === "boolean"; }, "credit")) != null ? _f : true;
684
+ var credit = (_f = opt(o.credit, function (v) { return typeof v === "boolean"; }, "credit")) != null ? _f : false;
465
685
  var themeSwitchOpt = (_g = opt(o.themeSwitch, function (v) { return typeof v === "boolean"; }, "themeSwitch")) != null ? _g : true;
466
686
  var layout = (_h = opt(o.layout, function (v) { return v === "grid" || v === "strip"; }, "layout")) != null ? _h : "grid";
467
687
  var seeAllOpt = opt(o.seeAll, function (v) { return isObject(v) && isString(v.href) && safeHref(v.href) && (v.text === void 0 || v.text === null || isString(v.text)); }, "seeAll");
468
- var preloadOpt = opt(o.preload, function (v) { return typeof v === "boolean" || isObject(v) && Object.entries(v).every(function (_w) {
469
- var _x = __read(_w, 2), k = _x[0], x = _x[1];
688
+ var preloadOpt = opt(o.preload, function (v) { return typeof v === "boolean" || isObject(v) && Object.entries(v).every(function (_v) {
689
+ var _w = __read(_v, 2), k = _w[0], x = _w[1];
470
690
  return PRELOAD_KEYS.includes(k) && (x === null || typeof x === "number" && Number.isInteger(x) && x >= (k === "parallel" ? 1 : 0) && x <= (k === "parallel" ? 8 : MAX_CAP));
471
691
  }); }, "preload");
472
692
  var preload = preloadOpt === void 0 || preloadOpt === true ? null : preloadOpt === false ? "off" : {
@@ -477,107 +697,144 @@ var VisualCIGallery = (function () {
477
697
  };
478
698
  var slugs = /* @__PURE__ */ new Set();
479
699
  var groups = [];
480
- var _loop_3 = function (g) {
481
- var e_10, _z, e_11, _0, e_12, _1, e_13, _2;
700
+ var _loop_9 = function (g) {
701
+ var e_17, _y, e_18, _z, e_19, _0;
482
702
  var groupSet = Object.prototype.hasOwnProperty.call(groupsOpt, g.name) ? groupsOpt[g.name] : void 0;
483
- var screens = /* @__PURE__ */ new Map();
703
+ var shots = g.items.map(function (item) {
704
+ var _a2;
705
+ var shot = parseShot(item.name, dimensions);
706
+ var values2 = __spreadProps(__spreadValues({}, shot.values), { size: sizeOf(shot, sizeValues, item.width, item.height, (_a2 = groupSet == null ? void 0 : groupSet.size) != null ? _a2 : void 0) });
707
+ return { item: item, shot: __spreadProps(__spreadValues({}, shot), { values: values2 }) };
708
+ });
709
+ var named = {};
710
+ var _loop_10 = function (d) {
711
+ var keys = d.values.map(function (v) { return v.key; }).filter(function (k) { return shots.some(function (_v) {
712
+ var shot = _v.shot;
713
+ return shot.values[d.key] === k;
714
+ }); });
715
+ named[d.key] = keys.length > 0 ? keys : [d.values[0].key];
716
+ };
484
717
  try {
485
- for (var _3 = (e_10 = void 0, __values(g.items)), _4 = _3.next(); !_4.done; _4 = _3.next()) {
486
- var item = _4.value;
487
- var shot = parseShot(item.name, item.width, item.height, (_m = groupSet == null ? void 0 : groupSet.size) != null ? _m : void 0);
488
- var variants = (_n = screens.get(shot.key)) != null ? _n : /* @__PURE__ */ new Map();
489
- screens.set(shot.key, variants);
490
- try {
491
- for (var _5 = (e_11 = void 0, __values(shot.theme ? [shot.theme] : THEMES)), _6 = _5.next(); !_6.done; _6 = _5.next()) {
492
- var theme = _6.value;
493
- var vid = "".concat(shot.size, "-").concat(theme);
494
- var v = (_o = variants.get(vid)) != null ? _o : {
495
- size: shot.size,
496
- theme: theme,
497
- url: "",
498
- url2x: null,
499
- width: 0,
500
- height: 0,
501
- bytes: null,
502
- bytes2x: null,
503
- thumb: null
504
- };
505
- if (shot.x2) {
506
- if (v.url2x === null) {
507
- v.url2x = item.url;
508
- v.bytes2x = (_p = item.bytes) != null ? _p : null;
509
- }
510
- }
511
- else if (v.url === "") {
512
- var scaled = shot.cssWidth !== null && item.width > shot.cssWidth;
513
- var width = scaled ? shot.cssWidth : item.width;
514
- var height = scaled ? Math.floor((2 * item.height * shot.cssWidth + item.width) / (2 * item.width)) : item.height;
515
- var t = item.thumb;
516
- var thumb2 = t ? { url: t.url, width: t.width, height: t.height, bytes: (_q = t.bytes) != null ? _q : null } : null;
517
- Object.assign(v, { url: item.url, width: width, height: height, bytes: (_r = item.bytes) != null ? _r : null, thumb: thumb2 });
518
- }
519
- variants.set(vid, v);
718
+ for (var dimensions_2 = (e_17 = void 0, __values(dimensions)), dimensions_2_1 = dimensions_2.next(); !dimensions_2_1.done; dimensions_2_1 = dimensions_2.next()) {
719
+ var d = dimensions_2_1.value;
720
+ _loop_10(d);
721
+ }
722
+ }
723
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
724
+ finally {
725
+ try {
726
+ if (dimensions_2_1 && !dimensions_2_1.done && (_y = dimensions_2.return)) _y.call(dimensions_2);
727
+ }
728
+ finally { if (e_17) throw e_17.error; }
729
+ }
730
+ var screens = /* @__PURE__ */ new Map();
731
+ var _loop_11 = function (item, shot) {
732
+ var e_20, _2;
733
+ var variants = (_m = screens.get(shot.key)) != null ? _m : /* @__PURE__ */ new Map();
734
+ screens.set(shot.key, variants);
735
+ var own = function (d) { return Object.prototype.hasOwnProperty.call(shot.values, d.key); };
736
+ var _loop_13 = function (values2) {
737
+ var vid = dimensions.map(function (d) { return values2[d.key]; }).join(".");
738
+ var v = (_n = variants.get(vid)) != null ? _n : { values: values2, url: "", url2x: null, width: 0, height: 0, bytes: null, bytes2x: null, thumb: null };
739
+ if (shot.x2) {
740
+ if (v.url2x === null) {
741
+ v.url2x = item.url;
742
+ v.bytes2x = (_o = item.bytes) != null ? _o : null;
520
743
  }
521
744
  }
522
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
523
- finally {
524
- try {
525
- if (_6 && !_6.done && (_0 = _5.return)) _0.call(_5);
526
- }
527
- finally { if (e_11) throw e_11.error; }
745
+ else if (v.url === "") {
746
+ var scaled = shot.cssWidth !== null && item.width > shot.cssWidth;
747
+ var width = scaled ? shot.cssWidth : item.width;
748
+ var height = scaled ? Math.floor((2 * item.height * shot.cssWidth + item.width) / (2 * item.width)) : item.height;
749
+ var t = item.thumb;
750
+ var thumb2 = t ? { url: t.url, width: t.width, height: t.height, bytes: (_p = t.bytes) != null ? _p : null } : null;
751
+ Object.assign(v, { url: item.url, width: width, height: height, bytes: (_q = item.bytes) != null ? _q : null, thumb: thumb2 });
752
+ }
753
+ variants.set(vid, v);
754
+ };
755
+ try {
756
+ for (var _3 = (e_20 = void 0, __values(combinations(dimensions, function (d) { return own(d) ? [shot.values[d.key]] : named[d.key]; }))), _4 = _3.next(); !_4.done; _4 = _3.next()) {
757
+ var values2 = _4.value;
758
+ _loop_13(values2);
528
759
  }
529
760
  }
761
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
762
+ finally {
763
+ try {
764
+ if (_4 && !_4.done && (_2 = _3.return)) _2.call(_3);
765
+ }
766
+ finally { if (e_20) throw e_20.error; }
767
+ }
768
+ };
769
+ try {
770
+ for (var shots_1 = (e_18 = void 0, __values(shots)), shots_1_1 = shots_1.next(); !shots_1_1.done; shots_1_1 = shots_1.next()) {
771
+ var _1 = shots_1_1.value, item = _1.item, shot = _1.shot;
772
+ _loop_11(item, shot);
773
+ }
530
774
  }
531
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
775
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
532
776
  finally {
533
777
  try {
534
- if (_4 && !_4.done && (_z = _3.return)) _z.call(_3);
778
+ if (shots_1_1 && !shots_1_1.done && (_z = shots_1.return)) _z.call(shots_1);
535
779
  }
536
- finally { if (e_10) throw e_10.error; }
780
+ finally { if (e_18) throw e_18.error; }
537
781
  }
538
- var kept = Array.from(screens).map(function (_w) {
539
- var _x = __read(_w, 2), key = _x[0], variants = _x[1];
540
- return ({
541
- key: key,
542
- variants: Array.from(variants.values()).filter(function (v) { return v.url !== ""; }).sort(function (a, b) { return SIZES.indexOf(a.size) - SIZES.indexOf(b.size) || THEMES.indexOf(a.theme) - THEMES.indexOf(b.theme); })
543
- });
782
+ var rankOf = function (v) { return dimensions.map(function (d) { return d.values.findIndex(function (x) { return x.key === v.values[d.key]; }); }); };
783
+ var byValues = function (a, b) {
784
+ var x = rankOf(a);
785
+ var y = rankOf(b);
786
+ for (var i = 0; i < x.length; i++)
787
+ if (x[i] !== y[i])
788
+ return x[i] - y[i];
789
+ return 0;
790
+ };
791
+ var kept = Array.from(screens).map(function (_v) {
792
+ var _w = __read(_v, 2), key = _w[0], variants = _w[1];
793
+ return ({ key: key, variants: Array.from(variants.values()).filter(function (v) { return v.url !== ""; }).sort(byValues) });
544
794
  }).filter(function (sc) { return sc.variants.length > 0; });
545
- try {
546
- for (var kept_1 = (e_12 = void 0, __values(kept)), kept_1_1 = kept_1.next(); !kept_1_1.done; kept_1_1 = kept_1.next()) {
547
- var sc = kept_1_1.value;
548
- var _loop_4 = function (v) {
549
- if (!sc.variants.some(function (o2) { return o2.size === v.size && o2.theme !== v.theme; })) {
550
- fail("gallery screen ".concat(sc.key, " in group ").concat(g.name, " has a ").concat(v.theme, " ").concat(v.size, " screenshot but no ").concat(v.theme === "light" ? "dark" : "light", " one"));
551
- }
552
- };
553
- try {
554
- for (var _7 = (e_13 = void 0, __values(sc.variants)), _8 = _7.next(); !_8.done; _8 = _7.next()) {
555
- var v = _8.value;
556
- _loop_4(v);
557
- }
795
+ if (kept.length === 0)
796
+ return "continue";
797
+ var values = valuesOf(dimensions, kept.flatMap(function (sc) { return sc.variants; }));
798
+ var _loop_12 = function (sc) {
799
+ var e_21, _5;
800
+ var own = valuesOf(dimensions, sc.variants);
801
+ var have = new Set(sc.variants.map(function (v) { return dimensions.map(function (d) { return v.values[d.key]; }).join("."); }));
802
+ var _loop_14 = function (combo) {
803
+ var keys = dimensions.map(function (d) { return combo[d.key]; });
804
+ if (!have.has(keys.join(".")))
805
+ fail("gallery screen ".concat(sc.key, " in group ").concat(g.name, " has no ").concat(keys.join(" "), " screenshot"));
806
+ };
807
+ try {
808
+ for (var _6 = (e_21 = void 0, __values(combinations(dimensions, function (d) { return d.missing === "error" ? values[d.key] : own[d.key]; }))), _7 = _6.next(); !_7.done; _7 = _6.next()) {
809
+ var combo = _7.value;
810
+ _loop_14(combo);
558
811
  }
559
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
560
- finally {
561
- try {
562
- if (_8 && !_8.done && (_2 = _7.return)) _2.call(_7);
563
- }
564
- finally { if (e_13) throw e_13.error; }
812
+ }
813
+ catch (e_21_1) { e_21 = { error: e_21_1 }; }
814
+ finally {
815
+ try {
816
+ if (_7 && !_7.done && (_5 = _6.return)) _5.call(_6);
565
817
  }
818
+ finally { if (e_21) throw e_21.error; }
819
+ }
820
+ };
821
+ try {
822
+ for (var kept_1 = (e_19 = void 0, __values(kept)), kept_1_1 = kept_1.next(); !kept_1_1.done; kept_1_1 = kept_1.next()) {
823
+ var sc = kept_1_1.value;
824
+ _loop_12(sc);
566
825
  }
567
826
  }
568
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
827
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
569
828
  finally {
570
829
  try {
571
- if (kept_1_1 && !kept_1_1.done && (_1 = kept_1.return)) _1.call(kept_1);
830
+ if (kept_1_1 && !kept_1_1.done && (_0 = kept_1.return)) _0.call(kept_1);
572
831
  }
573
- finally { if (e_12) throw e_12.error; }
832
+ finally { if (e_19) throw e_19.error; }
574
833
  }
575
- if (kept.length === 0)
576
- return "continue";
577
834
  var prefix = commonFolder(kept.map(function (sc) { return sc.key; })).length;
578
835
  var rank = rankBy(order2);
579
- var list = kept.map(function (_w) {
580
- var key = _w.key, variants = _w.variants;
836
+ var list = kept.map(function (_v) {
837
+ var key = _v.key, variants = _v.variants;
581
838
  var _a2, _b2;
582
839
  var set = Object.prototype.hasOwnProperty.call(screensOpt, key) ? screensOpt[key] : void 0;
583
840
  return {
@@ -593,25 +850,25 @@ var VisualCIGallery = (function () {
593
850
  slugs.add(slug);
594
851
  groups.push({
595
852
  name: g.name,
596
- title: (_t = (_s = groupSet == null ? void 0 : groupSet.title) != null ? _s : g.title) != null ? _t : g.name,
853
+ title: (_s = (_r = groupSet == null ? void 0 : groupSet.title) != null ? _r : g.title) != null ? _s : g.name,
597
854
  slug: slug,
598
- fit: (_u = groupSet == null ? void 0 : groupSet.fit) != null ? _u : "cover",
599
- sizes: SIZES.filter(function (sz) { return list.some(function (sc) { return sc.variants.some(function (v) { return v.size === sz; }); }); }),
855
+ fit: (_t = groupSet == null ? void 0 : groupSet.fit) != null ? _t : "cover",
856
+ values: values,
600
857
  screens: list
601
858
  });
602
859
  };
603
860
  try {
604
- for (var _x = __values(manifest.groups), _y = _x.next(); !_y.done; _y = _x.next()) {
605
- var g = _y.value;
606
- _loop_3(g);
861
+ for (var _w = __values(manifest.groups), _x = _w.next(); !_x.done; _x = _w.next()) {
862
+ var g = _x.value;
863
+ _loop_9(g);
607
864
  }
608
865
  }
609
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
866
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
610
867
  finally {
611
868
  try {
612
- if (_y && !_y.done && (_w = _x.return)) _w.call(_x);
869
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
613
870
  }
614
- finally { if (e_9) throw e_9.error; }
871
+ finally { if (e_16) throw e_16.error; }
615
872
  }
616
873
  if (groups.length === 0)
617
874
  fail("the gallery manifest has no screenshots to show");
@@ -620,23 +877,213 @@ var VisualCIGallery = (function () {
620
877
  return {
621
878
  layout: layout,
622
879
  themeSwitch: layout === "grid" && themeSwitchOpt,
623
- seeAll: seeAllOpt ? { href: seeAllOpt.href, text: (_v = seeAllOpt.text) != null ? _v : SEE_ALL_TEXT } : null,
880
+ seeAll: seeAllOpt ? { href: seeAllOpt.href, text: (_u = seeAllOpt.text) != null ? _u : SEE_ALL_TEXT } : null,
624
881
  title: title,
625
882
  label: title != null ? title : DEFAULT_TITLE,
626
883
  headingLevel: headingLevel,
627
884
  id: id,
628
885
  credit: credit,
629
886
  preload: preload,
887
+ dimensions: withShapes(dimensions, groups),
630
888
  groups: groups
631
889
  };
632
890
  }
891
+ function combinations(dimensions, valuesFor) {
892
+ var e_22, _v;
893
+ var out = [{}];
894
+ var _loop_15 = function (d) {
895
+ out = out.flatMap(function (c) { return valuesFor(d).map(function (k) {
896
+ var _v;
897
+ return __spreadProps(__spreadValues({}, c), (_v = {}, _v[d.key] = k, _v));
898
+ }); });
899
+ };
900
+ try {
901
+ for (var dimensions_3 = __values(dimensions), dimensions_3_1 = dimensions_3.next(); !dimensions_3_1.done; dimensions_3_1 = dimensions_3.next()) {
902
+ var d = dimensions_3_1.value;
903
+ _loop_15(d);
904
+ }
905
+ }
906
+ catch (e_22_1) { e_22 = { error: e_22_1 }; }
907
+ finally {
908
+ try {
909
+ if (dimensions_3_1 && !dimensions_3_1.done && (_v = dimensions_3.return)) _v.call(dimensions_3);
910
+ }
911
+ finally { if (e_22) throw e_22.error; }
912
+ }
913
+ return out;
914
+ }
915
+ function valuesOf(dimensions, variants) {
916
+ var e_23, _v;
917
+ var out = {};
918
+ var _loop_16 = function (d) {
919
+ out[d.key] = d.values.map(function (v) { return v.key; }).filter(function (k) { return variants.some(function (v) { return v.values[d.key] === k; }); });
920
+ };
921
+ try {
922
+ for (var dimensions_4 = __values(dimensions), dimensions_4_1 = dimensions_4.next(); !dimensions_4_1.done; dimensions_4_1 = dimensions_4.next()) {
923
+ var d = dimensions_4_1.value;
924
+ _loop_16(d);
925
+ }
926
+ }
927
+ catch (e_23_1) { e_23 = { error: e_23_1 }; }
928
+ finally {
929
+ try {
930
+ if (dimensions_4_1 && !dimensions_4_1.done && (_v = dimensions_4.return)) _v.call(dimensions_4);
931
+ }
932
+ finally { if (e_23) throw e_23.error; }
933
+ }
934
+ return out;
935
+ }
936
+ function withShapes(dimensions, groups) {
937
+ var variants = groups.flatMap(function (g) { return g.screens.flatMap(function (sc) { return sc.variants; }); });
938
+ return dimensions.map(function (d) { return d.key !== "size" ? d : __spreadProps(__spreadValues({}, d), {
939
+ values: d.values.map(function (v) {
940
+ var at = variants.filter(function (x) { return x.values.size === v.key; });
941
+ var tall = at.filter(function (x) { return x.height > x.width; }).length;
942
+ return __spreadProps(__spreadValues({}, v), { shape: tall > at.length - tall ? "portrait" : "landscape" });
943
+ })
944
+ }); });
945
+ }
946
+ var MISSING = ["error", "hide", "first"];
947
+ function checkDimensions(list) {
948
+ var e_24, _v, e_25, _w, e_26, _x;
949
+ if (!Array.isArray(list))
950
+ return false;
951
+ var keys = /* @__PURE__ */ new Set();
952
+ var valueKeys = /* @__PURE__ */ new Set();
953
+ var valueKey = function (k) { return isString(k) && KEY.test(k) && !DIGITS.test(k) && !/(^|-)2x$/.test(k); };
954
+ try {
955
+ for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
956
+ var d = list_1_1.value;
957
+ if (!isObject(d) || !Object.keys(d).every(function (k) { return ["key", "label", "missing", "values"].includes(k); }))
958
+ return false;
959
+ if (!isString(d.key) || !KEY.test(d.key) || keys.has(d.key))
960
+ return false;
961
+ keys.add(d.key);
962
+ var builtIn = d.key === "theme" || d.key === "size";
963
+ if (d.label !== void 0 && d.label !== null && !isString(d.label))
964
+ return false;
965
+ if (d.missing !== void 0 && d.missing !== null && !MISSING.includes(d.missing))
966
+ return false;
967
+ if (d.values === void 0 || d.values === null) {
968
+ if (!builtIn)
969
+ return false;
970
+ continue;
971
+ }
972
+ if (!Array.isArray(d.values) || d.values.length === 0)
973
+ return false;
974
+ try {
975
+ for (var _y = (e_25 = void 0, __values(d.values)), _z = _y.next(); !_z.done; _z = _y.next()) {
976
+ var v = _z.value;
977
+ if (!isObject(v) || !Object.keys(v).every(function (k) { return ["key", "label", "below"].includes(k); }))
978
+ return false;
979
+ if (!valueKey(v.key) || valueKeys.has(v.key))
980
+ return false;
981
+ valueKeys.add(v.key);
982
+ if (v.label !== void 0 && v.label !== null && !isString(v.label))
983
+ return false;
984
+ if (v.below !== void 0 && v.below !== null && (d.key !== "size" || !isSize(v.below)))
985
+ return false;
986
+ }
987
+ }
988
+ catch (e_25_1) { e_25 = { error: e_25_1 }; }
989
+ finally {
990
+ try {
991
+ if (_z && !_z.done && (_w = _y.return)) _w.call(_y);
992
+ }
993
+ finally { if (e_25) throw e_25.error; }
994
+ }
995
+ if (d.key === "size" && !d.values.some(function (v) { return !isObject(v) || v.below === void 0 || v.below === null; }))
996
+ return false;
997
+ }
998
+ }
999
+ catch (e_24_1) { e_24 = { error: e_24_1 }; }
1000
+ finally {
1001
+ try {
1002
+ if (list_1_1 && !list_1_1.done && (_v = list_1.return)) _v.call(list_1);
1003
+ }
1004
+ finally { if (e_24) throw e_24.error; }
1005
+ }
1006
+ var _loop_17 = function (d) {
1007
+ var e_27, _0;
1008
+ if (list.some(function (x) { return isObject(x) && x.key === d.key && Array.isArray(x.values); }))
1009
+ return "continue";
1010
+ try {
1011
+ for (var _1 = (e_27 = void 0, __values(d.values)), _2 = _1.next(); !_2.done; _2 = _1.next()) {
1012
+ var v = _2.value;
1013
+ if (valueKeys.has(v.key))
1014
+ return { value: false };
1015
+ valueKeys.add(v.key);
1016
+ }
1017
+ }
1018
+ catch (e_27_1) { e_27 = { error: e_27_1 }; }
1019
+ finally {
1020
+ try {
1021
+ if (_2 && !_2.done && (_0 = _1.return)) _0.call(_1);
1022
+ }
1023
+ finally { if (e_27) throw e_27.error; }
1024
+ }
1025
+ };
1026
+ try {
1027
+ for (var DEFAULT_DIMENSIONS_1 = __values(DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS_1_1 = DEFAULT_DIMENSIONS_1.next(); !DEFAULT_DIMENSIONS_1_1.done; DEFAULT_DIMENSIONS_1_1 = DEFAULT_DIMENSIONS_1.next()) {
1028
+ var d = DEFAULT_DIMENSIONS_1_1.value;
1029
+ var state_1 = _loop_17(d);
1030
+ if (typeof state_1 === "object")
1031
+ return state_1.value;
1032
+ }
1033
+ }
1034
+ catch (e_26_1) { e_26 = { error: e_26_1 }; }
1035
+ finally {
1036
+ try {
1037
+ if (DEFAULT_DIMENSIONS_1_1 && !DEFAULT_DIMENSIONS_1_1.done && (_x = DEFAULT_DIMENSIONS_1.return)) _x.call(DEFAULT_DIMENSIONS_1);
1038
+ }
1039
+ finally { if (e_26) throw e_26.error; }
1040
+ }
1041
+ return true;
1042
+ }
1043
+ function resolveDimensions(list) {
1044
+ var e_28, _v;
1045
+ var given = list != null ? list : [];
1046
+ var resolve = function (d, base) {
1047
+ var _a, _b, _c, _d;
1048
+ return {
1049
+ key: d.key,
1050
+ label: (_b = (_a = d.label) != null ? _a : base == null ? void 0 : base.label) != null ? _b : d.key,
1051
+ missing: (_d = (_c = d.missing) != null ? _c : base == null ? void 0 : base.missing) != null ? _d : "first",
1052
+ values: d.values ? d.values.map(function (v) {
1053
+ var _a2, _b2;
1054
+ return { key: v.key, label: (_a2 = v.label) != null ? _a2 : v.key, below: (_b2 = v.below) != null ? _b2 : null, shape: null };
1055
+ }) : base.values.map(function (v) { return __spreadValues({}, v); })
1056
+ };
1057
+ };
1058
+ var out = DEFAULT_DIMENSIONS.map(function (base) {
1059
+ var d = given.find(function (x) { return x.key === base.key; });
1060
+ return d ? resolve(d, base) : __spreadProps(__spreadValues({}, base), { values: base.values.map(function (v) { return __spreadValues({}, v); }) });
1061
+ });
1062
+ var _loop_18 = function (d) {
1063
+ if (!DEFAULT_DIMENSIONS.some(function (base) { return base.key === d.key; }))
1064
+ out.push(resolve(d, void 0));
1065
+ };
1066
+ try {
1067
+ for (var given_1 = __values(given), given_1_1 = given_1.next(); !given_1_1.done; given_1_1 = given_1.next()) {
1068
+ var d = given_1_1.value;
1069
+ _loop_18(d);
1070
+ }
1071
+ }
1072
+ catch (e_28_1) { e_28 = { error: e_28_1 }; }
1073
+ finally {
1074
+ try {
1075
+ if (given_1_1 && !given_1_1.done && (_v = given_1.return)) _v.call(given_1);
1076
+ }
1077
+ finally { if (e_28) throw e_28.error; }
1078
+ }
1079
+ return out;
1080
+ }
633
1081
  // src/preload.ts
634
1082
  var DEFAULT_CAPS = __spreadValues({}, PRELOAD_DEFAULTS);
635
1083
  var SLOW_PARALLEL = 2;
636
1084
  function estimateBytes(width, height) {
637
1085
  return Math.round(width * height * 0.1);
638
1086
  }
639
- var other = function (t) { return t === "light" ? "dark" : "light"; };
640
1087
  function thumb(img, always) {
641
1088
  return { url: img.url, bytes: img.bytes, always: always };
642
1089
  }
@@ -650,7 +1097,7 @@ var VisualCIGallery = (function () {
650
1097
  return out;
651
1098
  }
652
1099
  function order(tabs, current) {
653
- var e_14, _w, e_15, _x;
1100
+ var e_29, _v, e_30, _w;
654
1101
  var shown = tabs[current];
655
1102
  if (!shown)
656
1103
  return [];
@@ -670,12 +1117,12 @@ var VisualCIGallery = (function () {
670
1117
  tabs[t].cards.slice(0, tabs[t].fold).forEach(function (card2) { return out.push({ card: card2, fold: false }); });
671
1118
  }
672
1119
  }
673
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
1120
+ catch (e_29_1) { e_29 = { error: e_29_1 }; }
674
1121
  finally {
675
1122
  try {
676
- if (rest_1_1 && !rest_1_1.done && (_w = rest_1.return)) _w.call(rest_1);
1123
+ if (rest_1_1 && !rest_1_1.done && (_v = rest_1.return)) _v.call(rest_1);
677
1124
  }
678
- finally { if (e_14) throw e_14.error; }
1125
+ finally { if (e_29) throw e_29.error; }
679
1126
  }
680
1127
  try {
681
1128
  for (var rest_2 = __values(rest), rest_2_1 = rest_2.next(); !rest_2_1.done; rest_2_1 = rest_2.next()) {
@@ -683,99 +1130,102 @@ var VisualCIGallery = (function () {
683
1130
  tabs[t].cards.slice(tabs[t].fold).forEach(function (card2) { return out.push({ card: card2, fold: false }); });
684
1131
  }
685
1132
  }
686
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
1133
+ catch (e_30_1) { e_30 = { error: e_30_1 }; }
687
1134
  finally {
688
1135
  try {
689
- if (rest_2_1 && !rest_2_1.done && (_x = rest_2.return)) _x.call(rest_2);
1136
+ if (rest_2_1 && !rest_2_1.done && (_w = rest_2.return)) _w.call(rest_2);
690
1137
  }
691
- finally { if (e_15) throw e_15.error; }
1138
+ finally { if (e_30) throw e_30.error; }
692
1139
  }
693
1140
  return out;
694
1141
  }
695
1142
  function plan(input) {
696
- var e_16, _w, e_17, _x, e_18, _y, e_19, _z, e_20, _0;
697
- var _a;
1143
+ var e_31, _v, e_32, _w, e_33, _x, e_34, _y, e_35, _z;
1144
+ var _a, _b;
698
1145
  var tabs = input.tabs, current = input.current, theme = input.theme, caps = input.caps, mode = input.mode, hiDpi = input.hiDpi;
699
1146
  var seq = order(tabs, current);
700
1147
  var candidates = [];
701
1148
  if (mode === "light") {
702
- var shown = tabs[current];
703
- if (shown)
704
- try {
705
- for (var _1 = __values(shown.cards), _2 = _1.next(); !_2.done; _2 = _1.next()) {
706
- var card2 = _2.value;
707
- candidates.push(thumb(card2[theme], false));
708
- }
709
- }
710
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
711
- finally {
712
- try {
713
- if (_2 && !_2.done && (_w = _1.return)) _w.call(_1);
714
- }
715
- finally { if (e_16) throw e_16.error; }
716
- }
717
- shown == null ? void 0 : shown.cards.slice(0, shown.fold).forEach(function (_, i) { return candidates[i].always = true; });
1149
+ var shown_1 = tabs[current];
1150
+ if (shown_1)
1151
+ shown_1.cards.forEach(function (card2, i) { return card2[theme] && candidates.push(thumb(card2[theme], i < shown_1.fold)); });
718
1152
  }
719
1153
  else {
1154
+ var rest = ((_a = input.themes) != null ? _a : ["light", "dark"]).filter(function (t) { return t !== theme; });
720
1155
  try {
721
1156
  for (var seq_1 = __values(seq), seq_1_1 = seq_1.next(); !seq_1_1.done; seq_1_1 = seq_1.next()) {
722
1157
  var s = seq_1_1.value;
723
- candidates.push(thumb(s.card[theme], s.fold));
1158
+ if (s.card[theme])
1159
+ candidates.push(thumb(s.card[theme], s.fold));
724
1160
  }
725
1161
  }
726
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
1162
+ catch (e_31_1) { e_31 = { error: e_31_1 }; }
727
1163
  finally {
728
1164
  try {
729
- if (seq_1_1 && !seq_1_1.done && (_x = seq_1.return)) _x.call(seq_1);
1165
+ if (seq_1_1 && !seq_1_1.done && (_v = seq_1.return)) _v.call(seq_1);
730
1166
  }
731
- finally { if (e_17) throw e_17.error; }
1167
+ finally { if (e_31) throw e_31.error; }
732
1168
  }
733
1169
  try {
734
- for (var seq_2 = __values(seq), seq_2_1 = seq_2.next(); !seq_2_1.done; seq_2_1 = seq_2.next()) {
735
- var s = seq_2_1.value;
736
- candidates.push(thumb(s.card[other(theme)], false));
1170
+ for (var rest_3 = __values(rest), rest_3_1 = rest_3.next(); !rest_3_1.done; rest_3_1 = rest_3.next()) {
1171
+ var t = rest_3_1.value;
1172
+ try {
1173
+ for (var seq_2 = (e_33 = void 0, __values(seq)), seq_2_1 = seq_2.next(); !seq_2_1.done; seq_2_1 = seq_2.next()) {
1174
+ var s = seq_2_1.value;
1175
+ if (s.card[t])
1176
+ candidates.push(thumb(s.card[t], false));
1177
+ }
1178
+ }
1179
+ catch (e_33_1) { e_33 = { error: e_33_1 }; }
1180
+ finally {
1181
+ try {
1182
+ if (seq_2_1 && !seq_2_1.done && (_x = seq_2.return)) _x.call(seq_2);
1183
+ }
1184
+ finally { if (e_33) throw e_33.error; }
1185
+ }
737
1186
  }
738
1187
  }
739
- catch (e_18_1) { e_18 = { error: e_18_1 }; }
1188
+ catch (e_32_1) { e_32 = { error: e_32_1 }; }
740
1189
  finally {
741
1190
  try {
742
- if (seq_2_1 && !seq_2_1.done && (_y = seq_2.return)) _y.call(seq_2);
1191
+ if (rest_3_1 && !rest_3_1.done && (_w = rest_3.return)) _w.call(rest_3);
743
1192
  }
744
- finally { if (e_18) throw e_18.error; }
1193
+ finally { if (e_32) throw e_32.error; }
745
1194
  }
746
1195
  try {
747
- for (var _3 = __values([theme, other(theme)]), _4 = _3.next(); !_4.done; _4 = _3.next()) {
748
- var t = _4.value;
1196
+ for (var _0 = __values([theme].concat(rest)), _1 = _0.next(); !_1.done; _1 = _0.next()) {
1197
+ var t = _1.value;
749
1198
  try {
750
- for (var seq_3 = (e_20 = void 0, __values(seq)), seq_3_1 = seq_3.next(); !seq_3_1.done; seq_3_1 = seq_3.next()) {
1199
+ for (var seq_3 = (e_35 = void 0, __values(seq)), seq_3_1 = seq_3.next(); !seq_3_1.done; seq_3_1 = seq_3.next()) {
751
1200
  var s = seq_3_1.value;
752
- candidates.push(fullOf(s.card[t], hiDpi));
1201
+ if (s.card[t])
1202
+ candidates.push(fullOf(s.card[t], hiDpi));
753
1203
  }
754
1204
  }
755
- catch (e_20_1) { e_20 = { error: e_20_1 }; }
1205
+ catch (e_35_1) { e_35 = { error: e_35_1 }; }
756
1206
  finally {
757
1207
  try {
758
- if (seq_3_1 && !seq_3_1.done && (_0 = seq_3.return)) _0.call(seq_3);
1208
+ if (seq_3_1 && !seq_3_1.done && (_z = seq_3.return)) _z.call(seq_3);
759
1209
  }
760
- finally { if (e_20) throw e_20.error; }
1210
+ finally { if (e_35) throw e_35.error; }
761
1211
  }
762
1212
  }
763
1213
  }
764
- catch (e_19_1) { e_19 = { error: e_19_1 }; }
1214
+ catch (e_34_1) { e_34 = { error: e_34_1 }; }
765
1215
  finally {
766
1216
  try {
767
- if (_4 && !_4.done && (_z = _3.return)) _z.call(_3);
1217
+ if (_1 && !_1.done && (_y = _0.return)) _y.call(_0);
768
1218
  }
769
- finally { if (e_19) throw e_19.error; }
1219
+ finally { if (e_34) throw e_34.error; }
770
1220
  }
771
1221
  }
772
- var spent = (_a = input.spent) != null ? _a : { count: 0, bytes: 0 };
1222
+ var spent = (_b = input.spent) != null ? _b : { count: 0, bytes: 0 };
773
1223
  var left = __spreadProps(__spreadValues({}, caps), { count: caps.count - spent.count, bytes: caps.bytes - spent.bytes });
774
1224
  var done = input.done;
775
1225
  return capped(done ? candidates.filter(function (c) { return !done.has(c.url); }) : candidates, left);
776
1226
  }
777
1227
  function capped(items, caps) {
778
- var e_21, _w;
1228
+ var e_36, _v;
779
1229
  var seen = /* @__PURE__ */ new Set();
780
1230
  var out = [];
781
1231
  var always = 0;
@@ -800,43 +1250,44 @@ var VisualCIGallery = (function () {
800
1250
  out.push(it);
801
1251
  }
802
1252
  }
803
- catch (e_21_1) { e_21 = { error: e_21_1 }; }
1253
+ catch (e_36_1) { e_36 = { error: e_36_1 }; }
804
1254
  finally {
805
1255
  try {
806
- if (items_1_1 && !items_1_1.done && (_w = items_1.return)) _w.call(items_1);
1256
+ if (items_1_1 && !items_1_1.done && (_v = items_1.return)) _v.call(items_1);
807
1257
  }
808
- finally { if (e_21) throw e_21.error; }
1258
+ finally { if (e_36) throw e_36.error; }
809
1259
  }
810
1260
  return out;
811
1261
  }
812
1262
  function tabItems(tab, theme, foldOnly) {
813
1263
  if (foldOnly === void 0) { foldOnly = false; }
814
1264
  var cards = foldOnly ? tab.cards.slice(0, tab.fold) : tab.cards;
815
- return cards.map(function (c) { return thumb(c[theme], true); });
1265
+ return cards.filter(function (c) { return c[theme]; }).map(function (c) { return thumb(c[theme], true); });
816
1266
  }
817
1267
  function neighbours(cards, i, theme, hiDpi) {
818
- var e_22, _w;
1268
+ var e_37, _v;
819
1269
  var n = cards.length;
820
1270
  if (n < 2)
821
1271
  return [];
822
1272
  var seen = /* @__PURE__ */ new Set([i]);
823
1273
  var out = [];
824
1274
  try {
825
- for (var _x = __values([1, 2, -1, -2]), _y = _x.next(); !_y.done; _y = _x.next()) {
826
- var by = _y.value;
1275
+ for (var _w = __values([1, 2, -1, -2]), _x = _w.next(); !_x.done; _x = _w.next()) {
1276
+ var by = _x.value;
827
1277
  var j = ((i + by) % n + n) % n;
828
1278
  if (seen.has(j))
829
1279
  continue;
830
1280
  seen.add(j);
831
- out.push(__spreadProps(__spreadValues({}, fullOf(cards[j][theme], hiDpi)), { always: true }));
1281
+ if (cards[j][theme])
1282
+ out.push(__spreadProps(__spreadValues({}, fullOf(cards[j][theme], hiDpi)), { always: true }));
832
1283
  }
833
1284
  }
834
- catch (e_22_1) { e_22 = { error: e_22_1 }; }
1285
+ catch (e_37_1) { e_37 = { error: e_37_1 }; }
835
1286
  finally {
836
1287
  try {
837
- if (_y && !_y.done && (_w = _x.return)) _w.call(_x);
1288
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
838
1289
  }
839
- finally { if (e_22) throw e_22.error; }
1290
+ finally { if (e_37) throw e_37.error; }
840
1291
  }
841
1292
  return out;
842
1293
  }
@@ -867,22 +1318,22 @@ var VisualCIGallery = (function () {
867
1318
  }
868
1319
  /** Replaces the background queue. Background requests still running that the new plan doesn't want are dropped. */
869
1320
  Preloader.prototype.setPlan = function (items) {
870
- var e_23, _w;
1321
+ var e_38, _v;
871
1322
  this.queue = items.slice();
872
1323
  var wanted = new Set(items.map(function (i) { return i.url; }));
873
1324
  try {
874
- for (var _x = __values(this.running.values()), _y = _x.next(); !_y.done; _y = _x.next()) {
875
- var r = _y.value;
1325
+ for (var _w = __values(this.running.values()), _x = _w.next(); !_x.done; _x = _w.next()) {
1326
+ var r = _x.value;
876
1327
  if (!r.front && !wanted.has(r.item.url))
877
1328
  this.drop(r);
878
1329
  }
879
1330
  }
880
- catch (e_23_1) { e_23 = { error: e_23_1 }; }
1331
+ catch (e_38_1) { e_38 = { error: e_38_1 }; }
881
1332
  finally {
882
1333
  try {
883
- if (_y && !_y.done && (_w = _x.return)) _w.call(_x);
1334
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
884
1335
  }
885
- finally { if (e_23) throw e_23.error; }
1336
+ finally { if (e_38) throw e_38.error; }
886
1337
  }
887
1338
  this.schedule();
888
1339
  this.maybeRecheck();
@@ -890,7 +1341,7 @@ var VisualCIGallery = (function () {
890
1341
  /** Puts what the reader did (or is about to do) ahead of everything, replacing the last jump. To make room, the
891
1342
  * background requests running are dropped first, then the old jump's. */
892
1343
  Preloader.prototype.jump = function (items, high) {
893
- var e_24, _w;
1344
+ var e_39, _v;
894
1345
  var _this = this;
895
1346
  this.front = items.filter(function (i) { return !_this.finished.has(i.url); }).map(function (item) { return ({ item: item, high: high }); });
896
1347
  var wanted = new Set(this.front.map(function (f) { return f.item.url; }));
@@ -909,19 +1360,19 @@ var VisualCIGallery = (function () {
909
1360
  free++;
910
1361
  }
911
1362
  }
912
- catch (e_24_1) { e_24 = { error: e_24_1 }; }
1363
+ catch (e_39_1) { e_39 = { error: e_39_1 }; }
913
1364
  finally {
914
1365
  try {
915
- if (victims_1_1 && !victims_1_1.done && (_w = victims_1.return)) _w.call(victims_1);
1366
+ if (victims_1_1 && !victims_1_1.done && (_v = victims_1.return)) _v.call(victims_1);
916
1367
  }
917
- finally { if (e_24) throw e_24.error; }
1368
+ finally { if (e_39) throw e_39.error; }
918
1369
  }
919
1370
  this.queue = back.concat(this.queue);
920
1371
  this.pump();
921
1372
  };
922
1373
  /** Adds a likely next step (a tab the pointer is over) after the current jump, without dropping anything. */
923
1374
  Preloader.prototype.hint = function (items) {
924
- var e_25, _w;
1375
+ var e_40, _v;
925
1376
  var queued = new Set(this.front.map(function (f) { return f.item.url; }));
926
1377
  try {
927
1378
  for (var items_2 = __values(items), items_2_1 = items_2.next(); !items_2_1.done; items_2_1 = items_2.next()) {
@@ -930,12 +1381,12 @@ var VisualCIGallery = (function () {
930
1381
  this.front.push({ item: item, high: false });
931
1382
  }
932
1383
  }
933
- catch (e_25_1) { e_25 = { error: e_25_1 }; }
1384
+ catch (e_40_1) { e_40 = { error: e_40_1 }; }
934
1385
  finally {
935
1386
  try {
936
- if (items_2_1 && !items_2_1.done && (_w = items_2.return)) _w.call(items_2);
1387
+ if (items_2_1 && !items_2_1.done && (_v = items_2.return)) _v.call(items_2);
937
1388
  }
938
- finally { if (e_25) throw e_25.error; }
1389
+ finally { if (e_40) throw e_40.error; }
939
1390
  }
940
1391
  this.pump();
941
1392
  };
@@ -951,20 +1402,20 @@ var VisualCIGallery = (function () {
951
1402
  return Array.from(this.running.keys());
952
1403
  };
953
1404
  Preloader.prototype.stop = function () {
954
- var e_26, _w;
1405
+ var e_41, _v;
955
1406
  this.stopped = true;
956
1407
  try {
957
- for (var _x = __values(this.running.values()), _y = _x.next(); !_y.done; _y = _x.next()) {
958
- var r = _y.value;
1408
+ for (var _w = __values(this.running.values()), _x = _w.next(); !_x.done; _x = _w.next()) {
1409
+ var r = _x.value;
959
1410
  r.req.cancel();
960
1411
  }
961
1412
  }
962
- catch (e_26_1) { e_26 = { error: e_26_1 }; }
1413
+ catch (e_41_1) { e_41 = { error: e_41_1 }; }
963
1414
  finally {
964
1415
  try {
965
- if (_y && !_y.done && (_w = _x.return)) _w.call(_x);
1416
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
966
1417
  }
967
- finally { if (e_26) throw e_26.error; }
1418
+ finally { if (e_41) throw e_41.error; }
968
1419
  }
969
1420
  this.running.clear();
970
1421
  this.queue = [];
@@ -1003,7 +1454,7 @@ var VisualCIGallery = (function () {
1003
1454
  };
1004
1455
  Preloader.prototype.pump = function () {
1005
1456
  var _this = this;
1006
- var _loop_5 = function () {
1457
+ var _loop_19 = function () {
1007
1458
  var n = this_1.next();
1008
1459
  if (!n)
1009
1460
  return { value: void 0 };
@@ -1030,9 +1481,9 @@ var VisualCIGallery = (function () {
1030
1481
  };
1031
1482
  var this_1 = this;
1032
1483
  while (!this.stopped && this.running.size < this.parallel()) {
1033
- var state_1 = _loop_5();
1034
- if (typeof state_1 === "object")
1035
- return state_1.value;
1484
+ var state_2 = _loop_19();
1485
+ if (typeof state_2 === "object")
1486
+ return state_2.value;
1036
1487
  }
1037
1488
  };
1038
1489
  /** The rate over the latest finished requests: their bytes over the time from the first start to the last end, so
@@ -1083,7 +1534,7 @@ var VisualCIGallery = (function () {
1083
1534
  // src/hydrate.ts
1084
1535
  var hydrated = /* @__PURE__ */ new WeakMap();
1085
1536
  function preloadCaps(root, option) {
1086
- var e_27, _w;
1537
+ var e_42, _v;
1087
1538
  if (option === false)
1088
1539
  return null;
1089
1540
  if (typeof option === "object" && option !== null)
@@ -1097,19 +1548,19 @@ var VisualCIGallery = (function () {
1097
1548
  return null;
1098
1549
  var caps = __spreadValues({}, DEFAULT_CAPS);
1099
1550
  try {
1100
- for (var _x = __values(attr.split(" ")), _y = _x.next(); !_y.done; _y = _x.next()) {
1101
- var pair = _y.value;
1102
- var _z = __read(pair.split("="), 2), k = _z[0], v = _z[1];
1551
+ for (var _w = __values(attr.split(" ")), _x = _w.next(); !_x.done; _x = _w.next()) {
1552
+ var pair = _x.value;
1553
+ var _y = __read(pair.split("="), 2), k = _y[0], v = _y[1];
1103
1554
  if (k in caps && /^\d+$/.test(v != null ? v : ""))
1104
1555
  caps[k] = Number(v);
1105
1556
  }
1106
1557
  }
1107
- catch (e_27_1) { e_27 = { error: e_27_1 }; }
1558
+ catch (e_42_1) { e_42 = { error: e_42_1 }; }
1108
1559
  finally {
1109
1560
  try {
1110
- if (_y && !_y.done && (_w = _x.return)) _w.call(_x);
1561
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
1111
1562
  }
1112
- finally { if (e_27) throw e_27.error; }
1563
+ finally { if (e_42) throw e_42.error; }
1113
1564
  }
1114
1565
  return sane(caps);
1115
1566
  }
@@ -1117,21 +1568,21 @@ var VisualCIGallery = (function () {
1117
1568
  return __spreadProps(__spreadValues({}, caps), { parallel: Math.min(Math.max(Math.floor(caps.parallel) || 1, 1), 8) });
1118
1569
  }
1119
1570
  function definedOnly(o) {
1120
- var e_28, _w;
1571
+ var e_43, _v;
1121
1572
  var out = {};
1122
1573
  try {
1123
- for (var _x = __values(Object.entries(o)), _y = _x.next(); !_y.done; _y = _x.next()) {
1124
- var _z = __read(_y.value, 2), k = _z[0], v = _z[1];
1574
+ for (var _w = __values(Object.entries(o)), _x = _w.next(); !_x.done; _x = _w.next()) {
1575
+ var _y = __read(_x.value, 2), k = _y[0], v = _y[1];
1125
1576
  if (typeof v === "number")
1126
1577
  out[k] = v;
1127
1578
  }
1128
1579
  }
1129
- catch (e_28_1) { e_28 = { error: e_28_1 }; }
1580
+ catch (e_43_1) { e_43 = { error: e_43_1 }; }
1130
1581
  finally {
1131
1582
  try {
1132
- if (_y && !_y.done && (_w = _x.return)) _w.call(_x);
1583
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
1133
1584
  }
1134
- finally { if (e_28) throw e_28.error; }
1585
+ finally { if (e_43) throw e_43.error; }
1135
1586
  }
1136
1587
  return out;
1137
1588
  }
@@ -1189,12 +1640,6 @@ var VisualCIGallery = (function () {
1189
1640
  }
1190
1641
  };
1191
1642
  }
1192
- function pageTheme() {
1193
- var set = document.documentElement.getAttribute("data-theme");
1194
- if (set === "light" || set === "dark")
1195
- return set;
1196
- return matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
1197
- }
1198
1643
  function canOpen() {
1199
1644
  return typeof HTMLDialogElement === "function" && typeof HTMLDialogElement.prototype.showModal === "function";
1200
1645
  }
@@ -1203,11 +1648,24 @@ var VisualCIGallery = (function () {
1203
1648
  }
1204
1649
  function watch(img) {
1205
1650
  var fail2 = function () {
1206
- var _a, _b;
1651
+ var e_44, _v;
1207
1652
  var span = document.createElement("span");
1208
1653
  span.className = "vg-img vg-missing";
1209
- span.setAttribute("data-vg-size", (_a = img.getAttribute("data-vg-size")) != null ? _a : "");
1210
- span.setAttribute("data-vg-theme", (_b = img.getAttribute("data-vg-theme")) != null ? _b : "");
1654
+ try {
1655
+ for (var _w = __values(["data-vg-for", "data-vg-shown"]), _x = _w.next(); !_x.done; _x = _w.next()) {
1656
+ var name = _x.value;
1657
+ var v = img.getAttribute(name);
1658
+ if (v !== null)
1659
+ span.setAttribute(name, v);
1660
+ }
1661
+ }
1662
+ catch (e_44_1) { e_44 = { error: e_44_1 }; }
1663
+ finally {
1664
+ try {
1665
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
1666
+ }
1667
+ finally { if (e_44) throw e_44.error; }
1668
+ }
1211
1669
  span.textContent = img.alt;
1212
1670
  img.replaceWith(span);
1213
1671
  };
@@ -1222,9 +1680,9 @@ var VisualCIGallery = (function () {
1222
1680
  return hydrated.get(root);
1223
1681
  }
1224
1682
  function hydrate(el, options) {
1225
- var e_29, _w;
1683
+ var e_45, _v, e_46, _w;
1226
1684
  if (options === void 0) { options = {}; }
1227
- var _a, _b;
1685
+ var _a, _b, _c, _d, _e, _f;
1228
1686
  var found = el.matches("[data-vg]") ? el : el.querySelector("[data-vg]");
1229
1687
  if (!found)
1230
1688
  throw new Error("hydrate: no gallery markup ([data-vg]) in this element");
@@ -1241,14 +1699,135 @@ var VisualCIGallery = (function () {
1241
1699
  var followsPage = root.getAttribute("data-vg-theme-source") === "page";
1242
1700
  var current = null;
1243
1701
  var opener = null;
1244
- var theme = function () {
1702
+ var dims = listOf(root.getAttribute("data-vg-dims")).map(function (d) {
1703
+ var _v = __read(d.split(":"), 3), key = _v[0], missing = _v[1], values2 = _v[2];
1704
+ return { key: key, missing: missing, values: (values2 != null ? values2 : "").split(",").filter(Boolean) };
1705
+ });
1706
+ var portrait = listOf(root.getAttribute("data-vg-portrait"));
1707
+ var comboOf2 = function (c) { return dims.map(function (d) { return c[d.key]; }).join("."); };
1708
+ var parse = function (combo) {
1709
+ var keys = combo.split(".");
1710
+ var out = {};
1711
+ dims.forEach(function (d, i) { return out[d.key] = keys[i]; });
1712
+ return out;
1713
+ };
1714
+ var imagesOf = function (el2) { return toArray(el2.querySelectorAll(".vg-img")); };
1715
+ var combosOf = function (img) { return listOf(img.getAttribute("data-vg-for")); };
1716
+ function valuesIn(el2) {
1717
+ var e_47, _v;
1718
+ var seen = imagesOf(el2).flatMap(function (i) { return combosOf(i).map(parse); });
1719
+ var out = {};
1720
+ var _loop_20 = function (d) {
1721
+ out[d.key] = d.values.filter(function (v) { return seen.some(function (c) { return c[d.key] === v; }); });
1722
+ };
1723
+ try {
1724
+ for (var dims_2 = __values(dims), dims_2_1 = dims_2.next(); !dims_2_1.done; dims_2_1 = dims_2.next()) {
1725
+ var d = dims_2_1.value;
1726
+ _loop_20(d);
1727
+ }
1728
+ }
1729
+ catch (e_47_1) { e_47 = { error: e_47_1 }; }
1730
+ finally {
1731
+ try {
1732
+ if (dims_2_1 && !dims_2_1.done && (_v = dims_2.return)) _v.call(dims_2);
1733
+ }
1734
+ finally { if (e_47) throw e_47.error; }
1735
+ }
1736
+ return out;
1737
+ }
1738
+ var valuesCache = /* @__PURE__ */ new Map();
1739
+ var values = function (el2) {
1740
+ var v = valuesCache.get(el2);
1741
+ if (!v)
1742
+ valuesCache.set(el2, v = valuesIn(el2));
1743
+ return v;
1744
+ };
1745
+ function effective(el2, choice2) {
1746
+ var e_48, _v;
1747
+ var own = values(el2);
1748
+ var out = {};
1749
+ try {
1750
+ for (var dims_3 = __values(dims), dims_3_1 = dims_3.next(); !dims_3_1.done; dims_3_1 = dims_3.next()) {
1751
+ var d = dims_3_1.value;
1752
+ out[d.key] = own[d.key].indexOf(choice2[d.key]) !== -1 || own[d.key].length === 0 ? choice2[d.key] : own[d.key][0];
1753
+ }
1754
+ }
1755
+ catch (e_48_1) { e_48 = { error: e_48_1 }; }
1756
+ finally {
1757
+ try {
1758
+ if (dims_3_1 && !dims_3_1.done && (_v = dims_3.return)) _v.call(dims_3);
1759
+ }
1760
+ finally { if (e_48) throw e_48.error; }
1761
+ }
1762
+ return out;
1763
+ }
1764
+ function cardCombo2(card2, c) {
1765
+ var e_49, _v;
1766
+ var own = values(card2);
1767
+ var combos = imagesOf(card2).flatMap(function (i) { return combosOf(i).map(parse); });
1768
+ var out = __spreadValues({}, c);
1769
+ var _loop_21 = function (d) {
1770
+ if (d.missing === "hide" || own[d.key].indexOf(c[d.key]) !== -1)
1771
+ return "continue";
1772
+ var match = combos.find(function (x) { return dims.every(function (e) { return e.key === d.key || x[e.key] === out[e.key]; }); });
1773
+ out[d.key] = match ? match[d.key] : own[d.key][0];
1774
+ };
1775
+ try {
1776
+ for (var dims_4 = __values(dims), dims_4_1 = dims_4.next(); !dims_4_1.done; dims_4_1 = dims_4.next()) {
1777
+ var d = dims_4_1.value;
1778
+ _loop_21(d);
1779
+ }
1780
+ }
1781
+ catch (e_49_1) { e_49 = { error: e_49_1 }; }
1782
+ finally {
1783
+ try {
1784
+ if (dims_4_1 && !dims_4_1.done && (_v = dims_4.return)) _v.call(dims_4);
1785
+ }
1786
+ finally { if (e_49) throw e_49.error; }
1787
+ }
1788
+ return out;
1789
+ }
1790
+ var isOff = function (card2, c) { return dims.some(function (d) { return d.missing === "hide" && values(card2)[d.key].indexOf(c[d.key]) === -1; }); };
1791
+ var imageFor = function (card2, c) {
1245
1792
  var _a2;
1246
- return (_a2 = root.getAttribute("data-vg-theme")) != null ? _a2 : "light";
1793
+ var want = comboOf2(cardCombo2(card2, c));
1794
+ return (_a2 = imagesOf(card2).find(function (i) { return combosOf(i).indexOf(want) !== -1; })) != null ? _a2 : null;
1247
1795
  };
1248
- var size = function () {
1796
+ var shapeOf2 = function (sz) { return portrait.indexOf(sz) !== -1 ? "portrait" : "landscape"; };
1797
+ var firstPanel = root.querySelector(".vg-panel");
1798
+ var everything = valuesIn(root);
1799
+ var choice = {};
1800
+ try {
1801
+ for (var dims_1 = __values(dims), dims_1_1 = dims_1.next(); !dims_1_1.done; dims_1_1 = dims_1.next()) {
1802
+ var d = dims_1_1.value;
1803
+ var own = firstPanel ? values(firstPanel)[d.key] : [];
1804
+ choice[d.key] = (_b = (_a = own[0]) != null ? _a : everything[d.key][0]) != null ? _b : d.values[0];
1805
+ }
1806
+ }
1807
+ catch (e_45_1) { e_45 = { error: e_45_1 }; }
1808
+ finally {
1809
+ try {
1810
+ if (dims_1_1 && !dims_1_1.done && (_v = dims_1.return)) _v.call(dims_1);
1811
+ }
1812
+ finally { if (e_45) throw e_45.error; }
1813
+ }
1814
+ var themeFrom = function (t) {
1249
1815
  var _a2;
1250
- return (_a2 = root.getAttribute("data-vg-size")) != null ? _a2 : "desktop";
1816
+ return ((_a2 = everything.theme) != null ? _a2 : []).indexOf(t) !== -1 ? t : null;
1251
1817
  };
1818
+ function pageChoice() {
1819
+ var set2 = document.documentElement.getAttribute("data-theme");
1820
+ if (set2 && themeFrom(set2))
1821
+ return set2;
1822
+ return themeFrom(matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
1823
+ }
1824
+ if (everything.theme)
1825
+ choice.theme = (_c = pageChoice()) != null ? _c : choice.theme;
1826
+ if (matchMedia("(max-width: 47.99rem)").matches) {
1827
+ var narrow = ((_d = everything.size) != null ? _d : []).filter(function (v) { return portrait.indexOf(v) !== -1; }).pop();
1828
+ if (narrow)
1829
+ choice.size = narrow;
1830
+ }
1252
1831
  var panel = function () { return root.querySelector(".vg-panel:not([hidden])"); };
1253
1832
  var panelOf = function (t) {
1254
1833
  var _a2;
@@ -1258,59 +1837,129 @@ var VisualCIGallery = (function () {
1258
1837
  var _a2;
1259
1838
  return (_a2 = toArray(within.querySelectorAll("[data-vg-screen]")).find(function (c) { return c.getAttribute("data-vg-screen") === key; })) != null ? _a2 : null;
1260
1839
  };
1261
- var sizesOf = function (el2) { return listOf(el2 == null ? void 0 : el2.getAttribute("data-vg-sizes")); };
1262
- var shownIn = function (card2) { return card2.querySelector(".vg-img[data-vg-size=\"".concat(size(), "\"][data-vg-theme~=\"").concat(theme(), "\"]")); };
1263
- function sync() {
1264
- var e_30, _w;
1265
- var _a2;
1840
+ var theme = function () {
1841
+ var p = panel();
1842
+ return p ? effective(p, choice).theme : choice.theme;
1843
+ };
1844
+ function showSwitch(sw, value, offer) {
1845
+ var e_50, _v;
1846
+ var options2 = toArray(sw.querySelectorAll("[data-vg-set]"));
1847
+ var visible = 0;
1266
1848
  try {
1267
- for (var _x = __values(all(".vg-card")), _y = _x.next(); !_y.done; _y = _x.next()) {
1268
- var card2 = _y.value;
1269
- var img = shownIn(card2);
1270
- var src = (_a2 = img == null ? void 0 : img.getAttribute("data-src-full")) != null ? _a2 : img == null ? void 0 : img.getAttribute("src");
1271
- var link = card2.querySelector("a.vg-thumb");
1272
- if (link && src)
1273
- link.setAttribute("href", src);
1849
+ for (var options2_1 = __values(options2), options2_1_1 = options2_1.next(); !options2_1_1.done; options2_1_1 = options2_1.next()) {
1850
+ var o = options2_1_1.value;
1851
+ var v = o.getAttribute("data-vg-set");
1852
+ var on = v === value;
1853
+ if (o.getAttribute("role") === "option")
1854
+ o.setAttribute("aria-selected", String(on));
1855
+ else
1856
+ o.setAttribute("aria-pressed", String(on));
1857
+ if (offer)
1858
+ o.hidden = offer.indexOf(v) === -1;
1859
+ if (!o.hidden)
1860
+ visible++;
1861
+ if (on) {
1862
+ var button = sw.querySelector(".vg-combo-button");
1863
+ if (button)
1864
+ button.textContent = o.textContent;
1865
+ }
1274
1866
  }
1275
1867
  }
1276
- catch (e_30_1) { e_30 = { error: e_30_1 }; }
1868
+ catch (e_50_1) { e_50 = { error: e_50_1 }; }
1277
1869
  finally {
1278
1870
  try {
1279
- if (_y && !_y.done && (_w = _x.return)) _w.call(_x);
1871
+ if (options2_1_1 && !options2_1_1.done && (_v = options2_1.return)) _v.call(options2_1);
1280
1872
  }
1281
- finally { if (e_30) throw e_30.error; }
1873
+ finally { if (e_50) throw e_50.error; }
1282
1874
  }
1283
- if (box.open && current)
1284
- show(current);
1875
+ if (offer)
1876
+ sw.hidden = visible < 2;
1285
1877
  }
1286
- function set(key, value) {
1287
- var e_31, _w;
1288
- root.setAttribute("data-vg-".concat(key), value);
1878
+ function sync() {
1879
+ var e_51, _v, e_52, _w, e_53, _x, e_54, _y;
1880
+ var _a2;
1289
1881
  try {
1290
- for (var _x = __values(all("[data-vg-set-".concat(key, "]"))), _y = _x.next(); !_y.done; _y = _x.next()) {
1291
- var b = _y.value;
1292
- b.setAttribute("aria-pressed", String(b.getAttribute("data-vg-set-".concat(key)) === value));
1882
+ for (var _z = __values(all(".vg-panel")), _0 = _z.next(); !_0.done; _0 = _z.next()) {
1883
+ var p2 = _0.value;
1884
+ var eff = effective(p2, choice);
1885
+ p2.setAttribute("data-vg-shape", shapeOf2(eff.size));
1886
+ try {
1887
+ for (var _1 = (e_52 = void 0, __values(toArray(p2.querySelectorAll(".vg-card")))), _2 = _1.next(); !_2.done; _2 = _1.next()) {
1888
+ var card2 = _2.value;
1889
+ if (isOff(card2, eff))
1890
+ card2.setAttribute("data-vg-off", "");
1891
+ else
1892
+ card2.removeAttribute("data-vg-off");
1893
+ var img = imageFor(card2, eff);
1894
+ try {
1895
+ for (var _3 = (e_53 = void 0, __values(imagesOf(card2))), _4 = _3.next(); !_4.done; _4 = _3.next()) {
1896
+ var i = _4.value;
1897
+ if (i === img)
1898
+ i.setAttribute("data-vg-shown", "");
1899
+ else
1900
+ i.removeAttribute("data-vg-shown");
1901
+ }
1902
+ }
1903
+ catch (e_53_1) { e_53 = { error: e_53_1 }; }
1904
+ finally {
1905
+ try {
1906
+ if (_4 && !_4.done && (_x = _3.return)) _x.call(_3);
1907
+ }
1908
+ finally { if (e_53) throw e_53.error; }
1909
+ }
1910
+ var src = (_a2 = img == null ? void 0 : img.getAttribute("data-src-full")) != null ? _a2 : img == null ? void 0 : img.getAttribute("src");
1911
+ var link = card2.querySelector("a.vg-thumb");
1912
+ if (link && src)
1913
+ link.setAttribute("href", src);
1914
+ }
1915
+ }
1916
+ catch (e_52_1) { e_52 = { error: e_52_1 }; }
1917
+ finally {
1918
+ try {
1919
+ if (_2 && !_2.done && (_w = _1.return)) _w.call(_1);
1920
+ }
1921
+ finally { if (e_52) throw e_52.error; }
1922
+ }
1923
+ try {
1924
+ for (var _5 = (e_54 = void 0, __values(toArray(p2.querySelectorAll(".vg-bar [data-vg-dim]")))), _6 = _5.next(); !_6.done; _6 = _5.next()) {
1925
+ var sw = _6.value;
1926
+ showSwitch(sw, eff[sw.getAttribute("data-vg-dim")], null);
1927
+ }
1928
+ }
1929
+ catch (e_54_1) { e_54 = { error: e_54_1 }; }
1930
+ finally {
1931
+ try {
1932
+ if (_6 && !_6.done && (_y = _5.return)) _y.call(_5);
1933
+ }
1934
+ finally { if (e_54) throw e_54.error; }
1935
+ }
1293
1936
  }
1294
1937
  }
1295
- catch (e_31_1) { e_31 = { error: e_31_1 }; }
1938
+ catch (e_51_1) { e_51 = { error: e_51_1 }; }
1296
1939
  finally {
1297
1940
  try {
1298
- if (_y && !_y.done && (_w = _x.return)) _w.call(_x);
1941
+ if (_0 && !_0.done && (_v = _z.return)) _v.call(_z);
1299
1942
  }
1300
- finally { if (e_31) throw e_31.error; }
1943
+ finally { if (e_51) throw e_51.error; }
1301
1944
  }
1945
+ root.setAttribute("data-vg-theme", theme());
1946
+ var p = panel();
1947
+ if (choice.size !== void 0)
1948
+ root.setAttribute("data-vg-size", p ? effective(p, choice).size : choice.size);
1949
+ if (box.open && current)
1950
+ show(current);
1951
+ }
1952
+ function set(key, value) {
1953
+ if (!dims.some(function (d) { return d.key === key; }))
1954
+ return;
1955
+ choice[key] = value;
1302
1956
  sync();
1303
1957
  if (!selecting)
1304
1958
  replan();
1305
1959
  }
1306
- var chosen = matchMedia("(max-width: 47.99rem)").matches ? "phone" : "desktop";
1307
- function fit() {
1308
- var sizes = sizesOf(panel());
1309
- set("size", sizes.length === 0 || sizes.indexOf(chosen) !== -1 ? chosen : sizes[0]);
1310
- }
1311
1960
  var selecting = false;
1312
1961
  function select(tab, focus) {
1313
- var e_32, _w;
1962
+ var e_55, _v;
1314
1963
  if (focus === void 0) { focus = false; }
1315
1964
  var changed = tab.getAttribute("aria-selected") !== "true";
1316
1965
  selecting = true;
@@ -1325,16 +1974,16 @@ var VisualCIGallery = (function () {
1325
1974
  p.hidden = !on;
1326
1975
  }
1327
1976
  }
1328
- catch (e_32_1) { e_32 = { error: e_32_1 }; }
1977
+ catch (e_55_1) { e_55 = { error: e_55_1 }; }
1329
1978
  finally {
1330
1979
  try {
1331
- if (tabs_1_1 && !tabs_1_1.done && (_w = tabs_1.return)) _w.call(tabs_1);
1980
+ if (tabs_1_1 && !tabs_1_1.done && (_v = tabs_1.return)) _v.call(tabs_1);
1332
1981
  }
1333
- finally { if (e_32) throw e_32.error; }
1982
+ finally { if (e_55) throw e_55.error; }
1334
1983
  }
1335
1984
  if (focus)
1336
1985
  tab.focus();
1337
- fit();
1986
+ sync();
1338
1987
  selecting = false;
1339
1988
  if (preloader && changed) {
1340
1989
  var t = planTabs();
@@ -1343,58 +1992,58 @@ var VisualCIGallery = (function () {
1343
1992
  replan();
1344
1993
  }
1345
1994
  function cards() {
1346
- return all(".vg-panel:not([hidden]) .vg-card").filter(function (c) { return sizesOf(c).indexOf(size()) !== -1; });
1995
+ return all(".vg-panel:not([hidden]) .vg-card").filter(function (c) { return !c.hasAttribute("data-vg-off"); });
1347
1996
  }
1997
+ var boxChoice = function (card2) { return effective(card2, choice); };
1348
1998
  function show(card2) {
1349
- var e_33, _w, e_34, _x;
1350
- var _a2, _b2, _c, _d, _e, _f;
1999
+ var e_56, _v, e_57, _w;
2000
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g;
1351
2001
  current = card2;
1352
2002
  boxTitle.textContent = (_b2 = (_a2 = card2.querySelector(".vg-card-title")) == null ? void 0 : _a2.textContent) != null ? _b2 : "";
1353
- var sizes = sizesOf(card2);
1354
- var boxSizes = box.querySelector(".vg-box-sizes");
1355
- if (boxSizes) {
1356
- boxSizes.hidden = sizes.length < 2;
1357
- try {
1358
- for (var _y = __values(toArray(boxSizes.querySelectorAll("[data-vg-set-size]"))), _z = _y.next(); !_z.done; _z = _y.next()) {
1359
- var b = _z.value;
1360
- b.hidden = sizes.indexOf(b.getAttribute("data-vg-set-size")) === -1;
1361
- }
2003
+ var eff = boxChoice(card2);
2004
+ var own = values(card2);
2005
+ try {
2006
+ for (var _x = __values(toArray(box.querySelectorAll("[data-vg-dim]"))), _y = _x.next(); !_y.done; _y = _x.next()) {
2007
+ var sw = _y.value;
2008
+ var key = sw.getAttribute("data-vg-dim");
2009
+ showSwitch(sw, eff[key], (_c2 = own[key]) != null ? _c2 : []);
1362
2010
  }
1363
- catch (e_33_1) { e_33 = { error: e_33_1 }; }
1364
- finally {
1365
- try {
1366
- if (_z && !_z.done && (_w = _y.return)) _w.call(_y);
1367
- }
1368
- finally { if (e_33) throw e_33.error; }
2011
+ }
2012
+ catch (e_56_1) { e_56 = { error: e_56_1 }; }
2013
+ finally {
2014
+ try {
2015
+ if (_y && !_y.done && (_v = _x.return)) _v.call(_x);
1369
2016
  }
2017
+ finally { if (e_56) throw e_56.error; }
1370
2018
  }
1371
- var shown = shownIn(card2);
1372
- view.setAttribute("data-vg-size", size());
2019
+ var shown = imageFor(card2, eff);
2020
+ var shape = shapeOf2(eff.size);
2021
+ view.setAttribute("data-vg-shape", shape);
1373
2022
  var tall = Number(shown == null ? void 0 : shown.getAttribute("height")) / Number(shown == null ? void 0 : shown.getAttribute("width"));
1374
- var whole = shown instanceof HTMLImageElement && (card2.getAttribute("data-vg-fit") === "contain" || tall <= (size() === "phone" ? 2.4 : 0.8));
2023
+ var whole = shown instanceof HTMLImageElement && (card2.getAttribute("data-vg-fit") === "contain" || tall <= (shape === "portrait" ? 2.4 : 0.8));
1375
2024
  try {
1376
- for (var _0 = __values([box, view]), _1 = _0.next(); !_1.done; _1 = _0.next()) {
1377
- var el2 = _1.value;
2025
+ for (var _z = __values([box, view]), _0 = _z.next(); !_0.done; _0 = _z.next()) {
2026
+ var el2 = _0.value;
1378
2027
  if (whole)
1379
2028
  el2.setAttribute("data-vg-fit", "");
1380
2029
  else
1381
2030
  el2.removeAttribute("data-vg-fit");
1382
2031
  }
1383
2032
  }
1384
- catch (e_34_1) { e_34 = { error: e_34_1 }; }
2033
+ catch (e_57_1) { e_57 = { error: e_57_1 }; }
1385
2034
  finally {
1386
2035
  try {
1387
- if (_1 && !_1.done && (_x = _0.return)) _x.call(_0);
2036
+ if (_0 && !_0.done && (_w = _z.return)) _w.call(_z);
1388
2037
  }
1389
- finally { if (e_34) throw e_34.error; }
2038
+ finally { if (e_57) throw e_57.error; }
1390
2039
  }
1391
2040
  view.replaceChildren();
1392
2041
  if (shown instanceof HTMLImageElement) {
1393
2042
  var big_1 = document.createElement("img");
1394
- var src = (_d = (_c = shown.getAttribute("data-src-full")) != null ? _c : shown.getAttribute("src")) != null ? _d : "";
2043
+ var src = (_e2 = (_d2 = shown.getAttribute("data-src-full")) != null ? _d2 : shown.getAttribute("src")) != null ? _e2 : "";
1395
2044
  big_1.alt = shown.alt;
1396
- big_1.setAttribute("width", (_e = shown.getAttribute("width")) != null ? _e : "");
1397
- big_1.setAttribute("height", (_f = shown.getAttribute("height")) != null ? _f : "");
2045
+ big_1.setAttribute("width", (_f2 = shown.getAttribute("width")) != null ? _f2 : "");
2046
+ big_1.setAttribute("height", (_g = shown.getAttribute("height")) != null ? _g : "");
1398
2047
  big_1.decoding = "async";
1399
2048
  var x2 = shown.getAttribute("data-src-2x");
1400
2049
  if (x2) {
@@ -1409,16 +2058,18 @@ var VisualCIGallery = (function () {
1409
2058
  }
1410
2059
  view.scrollTop = 0;
1411
2060
  if (preloader && !light()) {
1412
- var list = cards();
1413
- var i = list.indexOf(card2);
1414
- if (i !== -1)
1415
- preloader.jump(neighbours(list.map(planCard), i, theme(), hiDpi()).filter(function (n) { return n.url !== ""; }), false);
2061
+ var list_2 = cards();
2062
+ var i_1 = list_2.indexOf(card2);
2063
+ if (i_1 !== -1) {
2064
+ var p = panel();
2065
+ var effPanel_1 = p ? effective(p, choice) : eff;
2066
+ var near_1 = function (j) { return [1, 2, -1, -2].some(function (by) { return ((i_1 + by) % list_2.length + list_2.length) % list_2.length === j; }); };
2067
+ var planned = list_2.map(function (c, j) { return near_1(j) ? planCard(c, effPanel_1) : {}; });
2068
+ preloader.jump(neighbours(planned, i_1, theme(), hiDpi()).filter(function (n) { return n.url !== ""; }), false);
2069
+ }
1416
2070
  }
1417
2071
  }
1418
2072
  function open(card2) {
1419
- var sizes = sizesOf(card2);
1420
- if (sizes.length && sizes.indexOf(size()) === -1)
1421
- set("size", sizes[0]);
1422
2073
  opener = card2.querySelector("[data-vg-open]");
1423
2074
  show(card2);
1424
2075
  if (!box.open) {
@@ -1470,7 +2121,7 @@ var VisualCIGallery = (function () {
1470
2121
  return v !== null && /^\d+$/.test(v) ? Number(v) : null;
1471
2122
  };
1472
2123
  function planImage(img) {
1473
- var _a2, _b2, _c, _d;
2124
+ var _a2, _b2, _c2, _d2;
1474
2125
  var width = Number(img.getAttribute("width")) || 1;
1475
2126
  var height = Number(img.getAttribute("height")) || 1;
1476
2127
  var behind = img.getAttribute("data-src-full");
@@ -1483,51 +2134,63 @@ var VisualCIGallery = (function () {
1483
2134
  width: width,
1484
2135
  height: height,
1485
2136
  bytes: (_b2 = num(img, "data-vg-bytes")) != null ? _b2 : behind ? estimateBytes(tw, Math.round(height * tw / width)) : estimateBytes(width, height),
1486
- fullBytes: use2x ? (_c = num(img, "data-vg-2x-bytes")) != null ? _c : estimateBytes(width * 2, height * 2) : (_d = num(img, "data-vg-full-bytes")) != null ? _d : estimateBytes(width, height)
2137
+ fullBytes: use2x ? (_c2 = num(img, "data-vg-2x-bytes")) != null ? _c2 : estimateBytes(width * 2, height * 2) : (_d2 = num(img, "data-vg-full-bytes")) != null ? _d2 : estimateBytes(width, height)
1487
2138
  };
1488
2139
  }
1489
- var planCardAt = function (card2, sz) {
1490
- var imgs = toArray(card2.querySelectorAll("img.vg-img[data-vg-size=\"".concat(sz, "\"]")));
1491
- var light2 = imgs.find(function (i) { return listOf(i.getAttribute("data-vg-theme")).indexOf("light") !== -1; });
1492
- var dark = imgs.find(function (i) { return listOf(i.getAttribute("data-vg-theme")).indexOf("dark") !== -1; });
1493
- return light2 && dark ? { light: planImage(light2), dark: planImage(dark) } : null;
1494
- };
1495
- var planCard = function (card2) {
1496
- var _a2;
1497
- return (_a2 = planCardAt(card2, size())) != null ? _a2 : { light: blank, dark: blank };
1498
- };
1499
- var blank = { url: "", full: null, width: 1, height: 1, bytes: 0, fullBytes: 0 };
2140
+ function planCard(card2, eff) {
2141
+ var e_58, _v;
2142
+ var _a2, _b2;
2143
+ var out = {};
2144
+ var own = (_a2 = values(card2).theme) != null ? _a2 : [];
2145
+ try {
2146
+ for (var _w = __values((_b2 = everything.theme) != null ? _b2 : []), _x = _w.next(); !_x.done; _x = _w.next()) {
2147
+ var t = _x.value;
2148
+ if (own.indexOf(t) === -1)
2149
+ continue;
2150
+ var img = imageFor(card2, __spreadProps(__spreadValues({}, eff), { theme: t }));
2151
+ if (img instanceof HTMLImageElement)
2152
+ out[t] = planImage(img);
2153
+ }
2154
+ }
2155
+ catch (e_58_1) { e_58 = { error: e_58_1 }; }
2156
+ finally {
2157
+ try {
2158
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
2159
+ }
2160
+ finally { if (e_58) throw e_58.error; }
2161
+ }
2162
+ return out;
2163
+ }
1500
2164
  function planTabs() {
1501
2165
  var panels = tabs.length ? tabs.map(panelOf) : all(".vg-panel");
1502
2166
  var shown = panel();
1503
2167
  var current2 = Math.max(0, panels.indexOf(shown));
1504
- var sizeOf = function (p) {
1505
- var sizes = sizesOf(p);
1506
- return sizes.length === 0 || sizes.indexOf(chosen) !== -1 ? chosen : sizes[0];
1507
- };
1508
- var shownSize = size();
1509
2168
  var fold = 0;
2169
+ var shownShape = shown ? shapeOf2(effective(shown, choice).size) : "landscape";
1510
2170
  var tabsOut = panels.map(function (p, i) {
1511
- var sz = i === current2 ? shownSize : sizeOf(p);
1512
- var els = p ? toArray(p.querySelectorAll(".vg-card")).filter(function (c) { return sizesOf(c).indexOf(sz) !== -1; }) : [];
1513
- var pairs = els.map(function (el2) { return ({ el: el2, card: planCardAt(el2, sz) }); }).filter(function (x) { return x.card !== null; });
2171
+ if (!p)
2172
+ return { shape: shownShape, cards: [] };
2173
+ var eff = effective(p, choice);
2174
+ var els = toArray(p.querySelectorAll(".vg-card")).filter(function (c) { return !isOff(c, eff); });
2175
+ var pairs = els.map(function (el2) { return ({ el: el2, card: planCard(el2, eff) }); }).filter(function (x) { return Object.keys(x.card).length > 0; });
1514
2176
  if (i === current2) {
1515
- fold = pairs.filter(function (_w) {
1516
- var el2 = _w.el;
2177
+ fold = pairs.filter(function (_v) {
2178
+ var el2 = _v.el;
1517
2179
  var r = el2.getBoundingClientRect();
1518
2180
  return r.bottom > 0 && r.top < innerHeight && r.right > 0 && r.left < innerWidth;
1519
2181
  }).length;
1520
2182
  }
1521
- return { sz: sz, cards: pairs.map(function (x) { return x.card; }) };
2183
+ return { shape: shapeOf2(eff.size), cards: pairs.map(function (x) { return x.card; }) };
1522
2184
  });
1523
2185
  var out = tabsOut.map(function (t, i) {
1524
- var f = i === current2 ? fold : t.sz === shownSize ? fold : t.sz === "phone" ? fold * 2 : Math.ceil(fold / 2);
2186
+ var f = i === current2 || t.shape === shownShape ? fold : t.shape === "portrait" ? fold * 2 : Math.ceil(fold / 2);
1525
2187
  return { cards: t.cards, fold: Math.min(f, t.cards.length) };
1526
2188
  });
1527
2189
  return { tabs: out, current: current2 };
1528
2190
  }
1529
2191
  var light = function () { return lowData() || !!(preloader == null ? void 0 : preloader.slow); };
1530
2192
  function replan() {
2193
+ var _a2;
1531
2194
  if (!preloader || !caps)
1532
2195
  return;
1533
2196
  var t = planTabs();
@@ -1535,6 +2198,7 @@ var VisualCIGallery = (function () {
1535
2198
  tabs: t.tabs,
1536
2199
  current: t.current,
1537
2200
  theme: theme(),
2201
+ themes: (_a2 = everything.theme) != null ? _a2 : [],
1538
2202
  caps: caps,
1539
2203
  mode: light() ? "light" : "full",
1540
2204
  hiDpi: hiDpi(),
@@ -1553,7 +2217,7 @@ var VisualCIGallery = (function () {
1553
2217
  preloader.hint(tabItems(t.tabs[i], theme(), true));
1554
2218
  };
1555
2219
  var destroyed = false;
1556
- var env = (_a = options.env) != null ? _a : browserEnv();
2220
+ var env = (_e = options.env) != null ? _e : browserEnv();
1557
2221
  var start = function () {
1558
2222
  if (destroyed || !caps || preloader)
1559
2223
  return;
@@ -1562,6 +2226,7 @@ var VisualCIGallery = (function () {
1562
2226
  };
1563
2227
  var onLoad = function () { return env.idle(start); };
1564
2228
  var onClick = function (e) {
2229
+ var _a2;
1565
2230
  var target = e.target;
1566
2231
  if (target === box)
1567
2232
  return box.close();
@@ -1573,19 +2238,22 @@ var VisualCIGallery = (function () {
1573
2238
  open(link.closest(".vg-card"));
1574
2239
  return;
1575
2240
  }
2241
+ var option = target.closest('[role="option"]');
2242
+ if (option && root.contains(option)) {
2243
+ choose(option);
2244
+ return;
2245
+ }
1576
2246
  var b = target.closest("button");
1577
2247
  if (!b || !root.contains(b))
1578
2248
  return;
1579
- var setTheme = b.getAttribute("data-vg-set-theme");
1580
- var setSize = b.getAttribute("data-vg-set-size");
2249
+ var dim = (_a2 = b.closest("[data-vg-dim]")) == null ? void 0 : _a2.getAttribute("data-vg-dim");
2250
+ var value = b.getAttribute("data-vg-set");
1581
2251
  var stepBy = b.getAttribute("data-vg-step");
1582
2252
  var scroll = b.getAttribute("data-vg-scroll");
1583
- if (setTheme)
1584
- set("theme", setTheme);
1585
- else if (setSize) {
1586
- chosen = setSize;
1587
- set("size", setSize);
1588
- }
2253
+ if (b.classList.contains("vg-combo-button"))
2254
+ toggleCombo(b);
2255
+ else if (dim && value)
2256
+ set(dim, value);
1589
2257
  else if (stepBy)
1590
2258
  step(Number(stepBy));
1591
2259
  else if (scroll && track) {
@@ -1596,8 +2264,145 @@ var VisualCIGallery = (function () {
1596
2264
  else if (b.getAttribute("role") === "tab")
1597
2265
  select(b);
1598
2266
  };
2267
+ var openCombo = null;
2268
+ var typed = "";
2269
+ var typedAt = 0;
2270
+ var listOf2 = function (button) { return button.parentElement.querySelector(".vg-combo-list"); };
2271
+ var optionsOf = function (button) { return toArray(listOf2(button).querySelectorAll('[role="option"]')).filter(function (o) { return !o.hidden; }); };
2272
+ function activate(button, option) {
2273
+ var e_59, _v;
2274
+ var _a2;
2275
+ if (!option)
2276
+ return;
2277
+ try {
2278
+ for (var _w = __values(optionsOf(button)), _x = _w.next(); !_x.done; _x = _w.next()) {
2279
+ var o = _x.value;
2280
+ o.classList.toggle("vg-active", o === option);
2281
+ }
2282
+ }
2283
+ catch (e_59_1) { e_59 = { error: e_59_1 }; }
2284
+ finally {
2285
+ try {
2286
+ if (_x && !_x.done && (_v = _w.return)) _v.call(_w);
2287
+ }
2288
+ finally { if (e_59) throw e_59.error; }
2289
+ }
2290
+ button.setAttribute("aria-activedescendant", option.id);
2291
+ (_a2 = option.scrollIntoView) == null ? void 0 : _a2.call(option, { block: "nearest" });
2292
+ }
2293
+ var activeOf = function (button) { return optionsOf(button).find(function (o) { return o.classList.contains("vg-active"); }); };
2294
+ function openList(button, at) {
2295
+ if (at === void 0) { at = "chosen"; }
2296
+ closeCombo();
2297
+ var list = listOf2(button);
2298
+ list.hidden = false;
2299
+ button.setAttribute("aria-expanded", "true");
2300
+ openCombo = button;
2301
+ var opts = optionsOf(button);
2302
+ var chosenOpt = opts.find(function (o) { return o.getAttribute("aria-selected") === "true"; });
2303
+ activate(button, at === "first" ? opts[0] : at === "last" ? opts[opts.length - 1] : chosenOpt != null ? chosenOpt : opts[0]);
2304
+ }
2305
+ function closeCombo() {
2306
+ if (!openCombo)
2307
+ return;
2308
+ listOf2(openCombo).hidden = true;
2309
+ openCombo.setAttribute("aria-expanded", "false");
2310
+ openCombo.removeAttribute("aria-activedescendant");
2311
+ openCombo = null;
2312
+ }
2313
+ function toggleCombo(button) {
2314
+ if (openCombo === button)
2315
+ closeCombo();
2316
+ else
2317
+ openList(button);
2318
+ }
2319
+ function choose(option) {
2320
+ var _a2, _b2;
2321
+ var dim = (_a2 = option.closest("[data-vg-dim]")) == null ? void 0 : _a2.getAttribute("data-vg-dim");
2322
+ var value = option.getAttribute("data-vg-set");
2323
+ var button = (_b2 = option.closest(".vg-combo")) == null ? void 0 : _b2.querySelector(".vg-combo-button");
2324
+ closeCombo();
2325
+ if (dim && value)
2326
+ set(dim, value);
2327
+ button == null ? void 0 : button.focus();
2328
+ }
2329
+ function comboKey(e, button) {
2330
+ var _a2;
2331
+ var isOpen = openCombo === button;
2332
+ var opts = optionsOf(button);
2333
+ var active = activeOf(button);
2334
+ var i = active ? opts.indexOf(active) : -1;
2335
+ if (!isOpen) {
2336
+ if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown")
2337
+ openList(button);
2338
+ else if (e.key === "ArrowUp")
2339
+ openList(button, "first");
2340
+ else if (e.key === "Home")
2341
+ openList(button, "first");
2342
+ else if (e.key === "End")
2343
+ openList(button, "last");
2344
+ else
2345
+ return false;
2346
+ return true;
2347
+ }
2348
+ if (e.key === "ArrowDown")
2349
+ activate(button, opts[Math.min(i + 1, opts.length - 1)]);
2350
+ else if (e.key === "ArrowUp")
2351
+ activate(button, opts[Math.max(i - 1, 0)]);
2352
+ else if (e.key === "Home")
2353
+ activate(button, opts[0]);
2354
+ else if (e.key === "End")
2355
+ activate(button, opts[opts.length - 1]);
2356
+ else if (e.key === "Enter" || e.key === " ") {
2357
+ if (active)
2358
+ choose(active);
2359
+ }
2360
+ else if (e.key === "Escape")
2361
+ closeCombo();
2362
+ else if (e.key === "Tab") {
2363
+ if (active) {
2364
+ var dim = (_a2 = active.closest("[data-vg-dim]")) == null ? void 0 : _a2.getAttribute("data-vg-dim");
2365
+ var value = active.getAttribute("data-vg-set");
2366
+ closeCombo();
2367
+ if (dim && value)
2368
+ set(dim, value);
2369
+ }
2370
+ return false;
2371
+ }
2372
+ else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
2373
+ var now = Date.now();
2374
+ typed = now - typedAt > 500 ? e.key.toLowerCase() : typed + e.key.toLowerCase();
2375
+ typedAt = now;
2376
+ var from = typed.length === 1 ? i + 1 : Math.max(i, 0);
2377
+ var order2 = opts.slice(from).concat(opts.slice(0, from));
2378
+ activate(button, order2.find(function (o) {
2379
+ var _a3;
2380
+ return ((_a3 = o.textContent) != null ? _a3 : "").toLowerCase().startsWith(typed);
2381
+ }));
2382
+ }
2383
+ else
2384
+ return false;
2385
+ return true;
2386
+ }
2387
+ var onKeyUp = function (e) {
2388
+ var _a2;
2389
+ if (e.key === " " && ((_a2 = e.target.classList) == null ? void 0 : _a2.contains("vg-combo-button")))
2390
+ e.preventDefault();
2391
+ };
2392
+ var onOutside = function (e) {
2393
+ if (openCombo && !openCombo.parentElement.contains(e.target))
2394
+ closeCombo();
2395
+ };
1599
2396
  var onKey = function (e) {
2397
+ var _a2;
1600
2398
  var target = e.target;
2399
+ if ((_a2 = target.classList) == null ? void 0 : _a2.contains("vg-combo-button")) {
2400
+ if (comboKey(e, target)) {
2401
+ e.preventDefault();
2402
+ e.stopPropagation();
2403
+ }
2404
+ return;
2405
+ }
1601
2406
  if (box.open && box.contains(target)) {
1602
2407
  if (e.key === "ArrowRight")
1603
2408
  step(1);
@@ -1615,6 +2420,7 @@ var VisualCIGallery = (function () {
1615
2420
  select(tabs[(next + tabs.length) % tabs.length], true);
1616
2421
  };
1617
2422
  var onClose = function () {
2423
+ closeCombo();
1618
2424
  unlock == null ? void 0 : unlock();
1619
2425
  current = null;
1620
2426
  view.replaceChildren();
@@ -1623,17 +2429,22 @@ var VisualCIGallery = (function () {
1623
2429
  opener = null;
1624
2430
  };
1625
2431
  var scheme = matchMedia("(prefers-color-scheme: dark)");
1626
- var onScheme = function () { return set("theme", pageTheme()); };
2432
+ var onScheme = function () {
2433
+ var t = pageChoice();
2434
+ if (t)
2435
+ set("theme", t);
2436
+ };
1627
2437
  var observer = null;
1628
2438
  if (followsPage) {
1629
2439
  observer = new MutationObserver(onScheme);
1630
2440
  observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
1631
- (_b = scheme.addEventListener) == null ? void 0 : _b.call(scheme, "change", onScheme);
2441
+ (_f = scheme.addEventListener) == null ? void 0 : _f.call(scheme, "change", onScheme);
1632
2442
  }
1633
2443
  var resize = track && typeof ResizeObserver === "function" ? new ResizeObserver(edges) : null;
1634
2444
  if (track && resize)
1635
2445
  resize.observe(track);
1636
2446
  root.addEventListener("click", onClick);
2447
+ document.addEventListener("pointerdown", onOutside);
1637
2448
  if (caps) {
1638
2449
  root.addEventListener("pointerover", onIntent);
1639
2450
  root.addEventListener("focusin", onIntent);
@@ -1643,6 +2454,7 @@ var VisualCIGallery = (function () {
1643
2454
  addEventListener("load", onLoad, { once: true });
1644
2455
  }
1645
2456
  root.addEventListener("keydown", onKey);
2457
+ root.addEventListener("keyup", onKeyUp);
1646
2458
  box.addEventListener("close", onClose);
1647
2459
  track == null ? void 0 : track.addEventListener("scroll", edges, { passive: true });
1648
2460
  try {
@@ -1651,25 +2463,22 @@ var VisualCIGallery = (function () {
1651
2463
  watch(img);
1652
2464
  }
1653
2465
  }
1654
- catch (e_29_1) { e_29 = { error: e_29_1 }; }
2466
+ catch (e_46_1) { e_46 = { error: e_46_1 }; }
1655
2467
  finally {
1656
2468
  try {
1657
2469
  if (_y && !_y.done && (_w = _x.return)) _w.call(_x);
1658
2470
  }
1659
- finally { if (e_29) throw e_29.error; }
2471
+ finally { if (e_46) throw e_46.error; }
1660
2472
  }
1661
- set("theme", pageTheme());
1662
- fit();
2473
+ sync();
1663
2474
  edges();
1664
2475
  var gallery = {
1665
2476
  root: root,
2477
+ set: set,
1666
2478
  setTheme: function (t) { return set("theme", t); },
1667
- setSize: function (s) {
1668
- chosen = s;
1669
- fit();
1670
- },
2479
+ setSize: function (s) { return set("size", s); },
1671
2480
  open: function (key) {
1672
- var e_35, _w;
2481
+ var e_60, _v;
1673
2482
  try {
1674
2483
  for (var tabs_2 = __values(tabs), tabs_2_1 = tabs_2.next(); !tabs_2_1.done; tabs_2_1 = tabs_2.next()) {
1675
2484
  var t = tabs_2_1.value;
@@ -1678,12 +2487,12 @@ var VisualCIGallery = (function () {
1678
2487
  select(t);
1679
2488
  }
1680
2489
  }
1681
- catch (e_35_1) { e_35 = { error: e_35_1 }; }
2490
+ catch (e_60_1) { e_60 = { error: e_60_1 }; }
1682
2491
  finally {
1683
2492
  try {
1684
- if (tabs_2_1 && !tabs_2_1.done && (_w = tabs_2.return)) _w.call(tabs_2);
2493
+ if (tabs_2_1 && !tabs_2_1.done && (_v = tabs_2.return)) _v.call(tabs_2);
1685
2494
  }
1686
- finally { if (e_35) throw e_35.error; }
2495
+ finally { if (e_60) throw e_60.error; }
1687
2496
  }
1688
2497
  var shownPanel = panel();
1689
2498
  var card2 = shownPanel ? cardOf(key, shownPanel) : null;
@@ -1694,8 +2503,12 @@ var VisualCIGallery = (function () {
1694
2503
  close: function () { return box.close(); },
1695
2504
  destroy: function () {
1696
2505
  var _a2;
2506
+ closeCombo();
2507
+ if (box.open)
2508
+ box.close();
1697
2509
  unlock == null ? void 0 : unlock();
1698
2510
  root.removeEventListener("click", onClick);
2511
+ document.removeEventListener("pointerdown", onOutside);
1699
2512
  root.removeEventListener("pointerover", onIntent);
1700
2513
  root.removeEventListener("focusin", onIntent);
1701
2514
  removeEventListener("load", onLoad);
@@ -1703,6 +2516,7 @@ var VisualCIGallery = (function () {
1703
2516
  preloader == null ? void 0 : preloader.stop();
1704
2517
  preloader = null;
1705
2518
  root.removeEventListener("keydown", onKey);
2519
+ root.removeEventListener("keyup", onKeyUp);
1706
2520
  box.removeEventListener("close", onClose);
1707
2521
  track == null ? void 0 : track.removeEventListener("scroll", edges);
1708
2522
  observer == null ? void 0 : observer.disconnect();
@@ -1724,50 +2538,50 @@ var VisualCIGallery = (function () {
1724
2538
  }
1725
2539
  function load(options) {
1726
2540
  return __awaiter(this, void 0, void 0, function () {
1727
- var _a, _b, _c, get, attempts, last, manifest, _loop_6, attempt, state_2;
1728
- return __generator(this, function (_w) {
1729
- switch (_w.label) {
2541
+ var _a, _b, _c, get, attempts, last, manifest, _loop_22, attempt, state_3;
2542
+ return __generator(this, function (_v) {
2543
+ switch (_v.label) {
1730
2544
  case 0:
1731
2545
  get = (_a = options.fetch) != null ? _a : fetch;
1732
2546
  attempts = Math.max(1, (_b = options.attempts) != null ? _b : 3);
1733
- _loop_6 = function (attempt) {
1734
- var res, e_36;
1735
- return __generator(this, function (_x) {
1736
- switch (_x.label) {
2547
+ _loop_22 = function (attempt) {
2548
+ var res, e_61;
2549
+ return __generator(this, function (_w) {
2550
+ switch (_w.label) {
1737
2551
  case 0:
1738
- _x.trys.push([0, 3, , 6]);
2552
+ _w.trys.push([0, 3, , 6]);
1739
2553
  return [4 /*yield*/, get(options.manifest, { signal: timeout((_c = options.timeout) != null ? _c : 2e4) })];
1740
2554
  case 1:
1741
- res = _x.sent();
2555
+ res = _w.sent();
1742
2556
  if (!res.ok)
1743
2557
  throw new Error("HTTP ".concat(res.status));
1744
2558
  return [4 /*yield*/, res.json()];
1745
2559
  case 2:
1746
- manifest = _x.sent();
2560
+ manifest = _w.sent();
1747
2561
  return [2 /*return*/, "break"];
1748
2562
  case 3:
1749
- e_36 = _x.sent();
1750
- last = e_36;
2563
+ e_61 = _w.sent();
2564
+ last = e_61;
1751
2565
  if (!(attempt < attempts)) return [3 /*break*/, 5];
1752
2566
  return [4 /*yield*/, new Promise(function (r) { return setTimeout(r, attempt * 1e3); })];
1753
2567
  case 4:
1754
- _x.sent();
1755
- _x.label = 5;
2568
+ _w.sent();
2569
+ _w.label = 5;
1756
2570
  case 5: return [3 /*break*/, 6];
1757
2571
  case 6: return [2 /*return*/];
1758
2572
  }
1759
2573
  });
1760
2574
  };
1761
2575
  attempt = 1;
1762
- _w.label = 1;
2576
+ _v.label = 1;
1763
2577
  case 1:
1764
2578
  if (!(attempt <= attempts)) return [3 /*break*/, 4];
1765
- return [5 /*yield**/, _loop_6(attempt)];
2579
+ return [5 /*yield**/, _loop_22(attempt)];
1766
2580
  case 2:
1767
- state_2 = _w.sent();
1768
- if (state_2 === "break")
2581
+ state_3 = _v.sent();
2582
+ if (state_3 === "break")
1769
2583
  return [3 /*break*/, 4];
1770
- _w.label = 3;
2584
+ _v.label = 3;
1771
2585
  case 3:
1772
2586
  attempt++;
1773
2587
  return [3 /*break*/, 1];
@@ -1789,22 +2603,22 @@ var VisualCIGallery = (function () {
1789
2603
  // src/index.ts
1790
2604
  function mount(el, options) {
1791
2605
  return __awaiter(this, void 0, void 0, function () {
1792
- var _a, model, e_37, p, old;
1793
- return __generator(this, function (_w) {
1794
- switch (_w.label) {
2606
+ var _a, model, e_62, p, old;
2607
+ return __generator(this, function (_v) {
2608
+ switch (_v.label) {
1795
2609
  case 0:
1796
- _w.trys.push([0, 2, , 3]);
2610
+ _v.trys.push([0, 2, , 3]);
1797
2611
  return [4 /*yield*/, load(options)];
1798
2612
  case 1:
1799
- model = _w.sent();
2613
+ model = _v.sent();
1800
2614
  return [3 /*break*/, 3];
1801
2615
  case 2:
1802
- e_37 = _w.sent();
2616
+ e_62 = _v.sent();
1803
2617
  p = document.createElement("p");
1804
2618
  p.className = "vg-error";
1805
2619
  p.textContent = "The screenshots couldn't be loaded.";
1806
2620
  el.replaceChildren(p);
1807
- throw e_37;
2621
+ throw e_62;
1808
2622
  case 3:
1809
2623
  old = el.querySelector("[data-vg]");
1810
2624
  if (old)