visualci-gallery 0.2.2 → 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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/assets/javascripts/visualci_gallery.js +1280 -466
- data/app/assets/stylesheets/visualci_gallery.css +93 -25
- data/lib/visualci/gallery/renderer.rb +141 -55
- data/lib/visualci/gallery/version.rb +1 -1
- data/lib/visualci/gallery.rb +254 -77
- metadata +1 -1
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* value a site sets wins, and they follow the text colour and the page's color-scheme (a custom property's
|
|
4
4
|
* currentColor is resolved where it's used).
|
|
5
5
|
*
|
|
6
|
-
* Each card holds every variant of its screen; only the
|
|
7
|
-
* Before the script runs, the theme follows <html data-theme>, else the reader's setting
|
|
6
|
+
* Each card holds every variant of its screen; only the one marked data-vg-shown="" shows (hidden lazy images never
|
|
7
|
+
* load). Before the script runs, the theme follows <html data-theme>, else the reader's setting, between the images
|
|
8
|
+
* marked "light" and "dark". A tab of portrait screens (phones) is marked data-vg-shape="portrait". */
|
|
8
9
|
:where(:root) {
|
|
9
10
|
--vg-ink: currentColor;
|
|
10
11
|
--vg-ink-2: currentColor;
|
|
@@ -165,6 +166,79 @@
|
|
|
165
166
|
padding: 0;
|
|
166
167
|
border: var(--vg-rule-width) solid var(--vg-rule);
|
|
167
168
|
}
|
|
169
|
+
/* Four values or more: a select-only combobox, a pill like the switches that opens a list under it. */
|
|
170
|
+
.vg-combo {
|
|
171
|
+
position: relative;
|
|
172
|
+
display: inline-flex;
|
|
173
|
+
}
|
|
174
|
+
.vg-combo[hidden],
|
|
175
|
+
.vg-combo-list[hidden],
|
|
176
|
+
.vg-combo-list [role="option"][hidden] {
|
|
177
|
+
display: none;
|
|
178
|
+
}
|
|
179
|
+
.vg[data-vg] .vg-combo-button {
|
|
180
|
+
font: inherit;
|
|
181
|
+
font-size: var(--vg-small);
|
|
182
|
+
font-weight: 500;
|
|
183
|
+
color: var(--vg-ink);
|
|
184
|
+
background: var(--vg-paper-2);
|
|
185
|
+
border: var(--vg-rule-width) solid var(--vg-rule);
|
|
186
|
+
border-radius: 999px;
|
|
187
|
+
padding: 0.25rem 2.25rem 0.25rem 1rem;
|
|
188
|
+
min-height: 2.25rem;
|
|
189
|
+
cursor: pointer;
|
|
190
|
+
position: relative;
|
|
191
|
+
text-align: start;
|
|
192
|
+
}
|
|
193
|
+
.vg[data-vg] .vg-combo-button::after {
|
|
194
|
+
content: "";
|
|
195
|
+
position: absolute;
|
|
196
|
+
right: 1rem;
|
|
197
|
+
top: 50%;
|
|
198
|
+
width: 0.4rem;
|
|
199
|
+
height: 0.4rem;
|
|
200
|
+
border-right: 1.5px solid currentColor;
|
|
201
|
+
border-bottom: 1.5px solid currentColor;
|
|
202
|
+
transform: translateY(-70%) rotate(45deg);
|
|
203
|
+
}
|
|
204
|
+
.vg[data-vg] .vg-combo-list {
|
|
205
|
+
position: absolute;
|
|
206
|
+
z-index: 3;
|
|
207
|
+
top: calc(100% + 0.25rem);
|
|
208
|
+
right: 0;
|
|
209
|
+
min-width: 100%;
|
|
210
|
+
max-height: 18rem;
|
|
211
|
+
overflow-y: auto;
|
|
212
|
+
margin: 0;
|
|
213
|
+
padding: 0.25rem;
|
|
214
|
+
list-style: none;
|
|
215
|
+
background: var(--vg-paper);
|
|
216
|
+
border: var(--vg-rule-width) solid var(--vg-rule);
|
|
217
|
+
border-radius: var(--vg-radius-md);
|
|
218
|
+
box-shadow: var(--vg-shadow);
|
|
219
|
+
}
|
|
220
|
+
.vg[data-vg] .vg-combo-list [role="option"] {
|
|
221
|
+
margin: 0;
|
|
222
|
+
padding: 0.375rem 0.75rem;
|
|
223
|
+
border-radius: var(--vg-radius-sm);
|
|
224
|
+
font-size: var(--vg-small);
|
|
225
|
+
color: var(--vg-ink-2);
|
|
226
|
+
white-space: nowrap;
|
|
227
|
+
cursor: pointer;
|
|
228
|
+
}
|
|
229
|
+
.vg[data-vg] .vg-combo-list [role="option"][aria-selected="true"] {
|
|
230
|
+
color: var(--vg-ink);
|
|
231
|
+
font-weight: 600;
|
|
232
|
+
}
|
|
233
|
+
.vg[data-vg] .vg-combo-list .vg-active,
|
|
234
|
+
.vg[data-vg] .vg-combo-list [role="option"]:hover {
|
|
235
|
+
background: var(--vg-paper-2);
|
|
236
|
+
}
|
|
237
|
+
.vg[data-vg] .vg-combo-list .vg-active {
|
|
238
|
+
outline: 2px solid var(--vg-accent);
|
|
239
|
+
outline-offset: -2px;
|
|
240
|
+
}
|
|
241
|
+
.vg-combo-button:focus-visible,
|
|
168
242
|
.vg-seg button:focus-visible,
|
|
169
243
|
.vg-icon:focus-visible,
|
|
170
244
|
.vg-thumb:focus-visible,
|
|
@@ -182,7 +256,7 @@
|
|
|
182
256
|
gap: calc(var(--vg-gap) * 1.33) var(--vg-gap);
|
|
183
257
|
grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--vg-card-min)), 1fr));
|
|
184
258
|
}
|
|
185
|
-
.vg[data-vg-
|
|
259
|
+
.vg-panel[data-vg-shape="portrait"] .vg-grid {
|
|
186
260
|
grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--vg-phone-card-min)), 1fr));
|
|
187
261
|
gap: var(--vg-gap) calc(var(--vg-gap) * 0.67);
|
|
188
262
|
}
|
|
@@ -204,7 +278,7 @@
|
|
|
204
278
|
box-shadow: var(--vg-shadow);
|
|
205
279
|
transition: transform var(--vg-duration) var(--vg-ease);
|
|
206
280
|
}
|
|
207
|
-
.vg[data-vg-
|
|
281
|
+
.vg-panel[data-vg-shape="portrait"] .vg-thumb {
|
|
208
282
|
aspect-ratio: var(--vg-phone-ratio);
|
|
209
283
|
}
|
|
210
284
|
.vg-thumb:hover {
|
|
@@ -221,12 +295,12 @@
|
|
|
221
295
|
font-size: var(--vg-small);
|
|
222
296
|
color: var(--vg-muted);
|
|
223
297
|
}
|
|
224
|
-
.vg[data-vg-
|
|
298
|
+
.vg-panel[data-vg-shape="portrait"] .vg-caption {
|
|
225
299
|
display: none;
|
|
226
300
|
}
|
|
227
301
|
|
|
228
302
|
/* Which variant shows. */
|
|
229
|
-
.vg-img {
|
|
303
|
+
.vg[data-vg] .vg-img {
|
|
230
304
|
display: none;
|
|
231
305
|
width: 100%;
|
|
232
306
|
height: 100%;
|
|
@@ -248,35 +322,28 @@
|
|
|
248
322
|
color: var(--vg-muted);
|
|
249
323
|
text-align: center;
|
|
250
324
|
}
|
|
251
|
-
|
|
252
|
-
.vg[data-vg-size="desktop"] .vg-card:not([data-vg-sizes~="desktop"]),
|
|
253
|
-
.vg[data-vg-size="phone"] .vg-card:not([data-vg-sizes~="phone"]) {
|
|
254
|
-
display: none;
|
|
255
|
-
}
|
|
256
|
-
.vg[data-vg-size="desktop"] .vg-img[data-vg-size="desktop"],
|
|
257
|
-
.vg[data-vg-size="phone"] .vg-img[data-vg-size="phone"] {
|
|
325
|
+
.vg[data-vg] .vg-img[data-vg-shown] {
|
|
258
326
|
display: block;
|
|
259
327
|
}
|
|
260
|
-
.vg[data-vg
|
|
261
|
-
.vg[data-vg-size="phone"] .vg-missing[data-vg-size="phone"] {
|
|
328
|
+
.vg[data-vg] .vg-missing[data-vg-shown] {
|
|
262
329
|
display: grid;
|
|
263
330
|
}
|
|
264
|
-
|
|
265
|
-
.vg[data-vg
|
|
331
|
+
/* A card with no shot for the chosen value of a "hide" dimension (a desktop-only screen at Phone) isn't shown. */
|
|
332
|
+
.vg[data-vg] .vg-card[data-vg-off] {
|
|
266
333
|
display: none;
|
|
267
334
|
}
|
|
268
335
|
/* Before the script runs: the page's <html data-theme> when it's set, else the reader's setting. */
|
|
269
|
-
:root[data-theme="light"] .vg:not([data-vg-theme]) .vg-img:not([data-vg-
|
|
270
|
-
:root[data-theme="dark"] .vg:not([data-vg-theme]) .vg-img:not([data-vg-
|
|
336
|
+
:root[data-theme="light"] .vg:not([data-vg-theme]) .vg-img[data-vg-shown]:not([data-vg-shown=""]):not([data-vg-shown~="light"]),
|
|
337
|
+
:root[data-theme="dark"] .vg:not([data-vg-theme]) .vg-img[data-vg-shown]:not([data-vg-shown=""]):not([data-vg-shown~="dark"]) {
|
|
271
338
|
display: none;
|
|
272
339
|
}
|
|
273
340
|
@media not all and (prefers-color-scheme: dark) {
|
|
274
|
-
:root:not([data-theme="light"]):not([data-theme="dark"]) .vg:not([data-vg-theme]) .vg-img:not([data-vg-
|
|
341
|
+
:root:not([data-theme="light"]):not([data-theme="dark"]) .vg:not([data-vg-theme]) .vg-img[data-vg-shown]:not([data-vg-shown=""]):not([data-vg-shown~="light"]) {
|
|
275
342
|
display: none;
|
|
276
343
|
}
|
|
277
344
|
}
|
|
278
345
|
@media (prefers-color-scheme: dark) {
|
|
279
|
-
:root:not([data-theme="light"]):not([data-theme="dark"]) .vg:not([data-vg-theme]) .vg-img:not([data-vg-
|
|
346
|
+
:root:not([data-theme="light"]):not([data-theme="dark"]) .vg:not([data-vg-theme]) .vg-img[data-vg-shown]:not([data-vg-shown=""]):not([data-vg-shown~="dark"]) {
|
|
280
347
|
display: none;
|
|
281
348
|
}
|
|
282
349
|
}
|
|
@@ -298,7 +365,7 @@
|
|
|
298
365
|
padding: 0.25rem 0.25rem 0.75rem;
|
|
299
366
|
scrollbar-width: thin;
|
|
300
367
|
}
|
|
301
|
-
.vg[data-vg-
|
|
368
|
+
.vg-panel[data-vg-shape="portrait"] .vg-track {
|
|
302
369
|
grid-auto-columns: var(--vg-strip-phone-card, min(11rem, 45%));
|
|
303
370
|
grid-template-columns: none;
|
|
304
371
|
}
|
|
@@ -386,12 +453,13 @@
|
|
|
386
453
|
.vg-box-bar .vg-icon {
|
|
387
454
|
order: 1;
|
|
388
455
|
}
|
|
389
|
-
.vg-box-bar:has(.vg-seg:not([hidden]))::after {
|
|
456
|
+
.vg-box-bar:has(.vg-seg:not([hidden]), .vg-combo:not([hidden]))::after {
|
|
390
457
|
content: "";
|
|
391
458
|
order: 2;
|
|
392
459
|
flex-basis: 100%;
|
|
393
460
|
}
|
|
394
|
-
.vg-box-bar .vg-seg
|
|
461
|
+
.vg-box-bar .vg-seg,
|
|
462
|
+
.vg-box-bar .vg-combo {
|
|
395
463
|
order: 3;
|
|
396
464
|
}
|
|
397
465
|
}
|
|
@@ -411,7 +479,7 @@
|
|
|
411
479
|
border-radius: var(--vg-radius-sm);
|
|
412
480
|
border: var(--vg-rule-width) solid var(--vg-rule);
|
|
413
481
|
}
|
|
414
|
-
.vg-box-view[data-vg-
|
|
482
|
+
.vg-box-view[data-vg-shape="portrait"] img {
|
|
415
483
|
max-width: min(100%, 390px);
|
|
416
484
|
}
|
|
417
485
|
/* A shot of one screen (a phone's, a window) fits the view whole; a full-page capture scrolls. */
|
|
@@ -6,17 +6,21 @@ module VisualCI
|
|
|
6
6
|
class Renderer
|
|
7
7
|
def initialize(model)
|
|
8
8
|
@m = model
|
|
9
|
+
@dims = model['dimensions']
|
|
9
10
|
@id = Gallery.escape(model['id'])
|
|
10
11
|
@below = model['title'].nil? ? 0 : 1
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
def call
|
|
14
15
|
out = []
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
choice = start_choice
|
|
17
|
+
dims = @dims.map { |d| "#{d['key']}:#{d['missing']}:#{d['values'].map { |v| v['key'] }.join(',')}" }.join(' ')
|
|
18
|
+
portrait = size_dimension['values'].select { |v| v['shape'] == 'portrait' }.map { |v| v['key'] }.join(' ')
|
|
19
|
+
out << %(<section class="vg" data-vg data-vg-layout="#{@m['layout']}" aria-label="#{esc(@m['label'])}" data-vg-dims="#{dims}") +
|
|
20
|
+
(portrait.empty? ? '' : %( data-vg-portrait="#{portrait}")) +
|
|
21
|
+
(@m['themeSwitch'] ? '' : ' data-vg-theme-source="page"') + preload_attr + '>'
|
|
18
22
|
out << "<#{h(0)} class=\"vg-title\">#{esc(@m['title'])}</#{h(0)}>" unless @m['title'].nil?
|
|
19
|
-
@m['layout'] == 'strip' ? strip(out) : grid(out)
|
|
23
|
+
@m['layout'] == 'strip' ? strip(choice, out) : grid(choice, out)
|
|
20
24
|
if (see = @m['seeAll'])
|
|
21
25
|
out << %(<p class="vg-see-all"><a href="#{esc(see['href'])}">#{esc(see['text'])}</a></p>)
|
|
22
26
|
end
|
|
@@ -25,9 +29,7 @@ module VisualCI
|
|
|
25
29
|
end
|
|
26
30
|
out << %(<dialog class="vg-box" aria-labelledby="#{@id}-box-title">)
|
|
27
31
|
out << %(<div class="vg-box-bar"><#{h(@below)} class="vg-box-title" id="#{@id}-box-title"></#{h(@below)}>) +
|
|
28
|
-
'<div class="vg-controls">' +
|
|
29
|
-
(@m['themeSwitch'] ? themes : '') +
|
|
30
|
-
(@m['layout'] == 'grid' ? sizes(%w[desktop phone], ' vg-box-sizes') : '') +
|
|
32
|
+
'<div class="vg-controls">' + box_switches +
|
|
31
33
|
'<button type="button" class="vg-icon" data-vg-step="-1" aria-label="Previous screen">‹</button>' \
|
|
32
34
|
'<button type="button" class="vg-icon" data-vg-step="1" aria-label="Next screen">›</button>' \
|
|
33
35
|
'</div>' \
|
|
@@ -45,17 +47,44 @@ module VisualCI
|
|
|
45
47
|
|
|
46
48
|
def h(offset) = "h#{[@m['headingLevel'] + offset, 6].min}"
|
|
47
49
|
|
|
48
|
-
def
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
def size_dimension = @dims.find { |d| d['key'] == 'size' }
|
|
51
|
+
|
|
52
|
+
def shape_of(size) = size_dimension['values'].find { |v| v['key'] == size }['shape'] || 'landscape'
|
|
53
|
+
|
|
54
|
+
def combo_of(values) = @dims.map { |d| values[d['key']] }.join('.')
|
|
55
|
+
|
|
56
|
+
# A dimension's switch: segmented buttons for two or three values, a select-only combobox for more.
|
|
57
|
+
def dim_switch(d, keys, place, current)
|
|
58
|
+
label = ->(k) { esc(d['values'].find { |v| v['key'] == k }['label']) }
|
|
59
|
+
name = esc(d['label'])
|
|
60
|
+
if keys.length <= 3
|
|
61
|
+
return %(<div class="vg-seg" role="group" aria-label="#{name}" data-vg-dim="#{d['key']}">) +
|
|
62
|
+
keys.map { |k| %(<button type="button" data-vg-set="#{k}" aria-pressed="false">#{label.call(k)}</button>) }.join +
|
|
63
|
+
'</div>'
|
|
64
|
+
end
|
|
65
|
+
# "--" can't occur in a slug or a key, so these ids never meet another.
|
|
66
|
+
list = "#{@id}-#{place}--#{d['key']}"
|
|
67
|
+
%(<div class="vg-combo" data-vg-dim="#{d['key']}">) +
|
|
68
|
+
%(<button type="button" class="vg-combo-button" role="combobox" aria-label="#{name}" aria-haspopup="listbox" aria-expanded="false" aria-controls="#{list}">#{label.call(current)}</button>) +
|
|
69
|
+
%(<ul class="vg-combo-list" role="listbox" id="#{list}" aria-label="#{name}" hidden>) +
|
|
70
|
+
keys.map { |k| %(<li role="option" id="#{list}--#{k}" data-vg-set="#{k}" aria-selected="false">#{label.call(k)}</li>) }.join +
|
|
71
|
+
'</ul></div>'
|
|
53
72
|
end
|
|
54
73
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
74
|
+
# A switch for each dimension with two or more of `values` (not the theme's without its switch).
|
|
75
|
+
def switches(values, place, current)
|
|
76
|
+
@dims.select { |d| values[d['key']].length > 1 && (d['key'] != 'theme' || @m['themeSwitch']) }
|
|
77
|
+
.map { |d| dim_switch(d, values[d['key']], place, current[d['key']]) }.join
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# The full-size view's switches (the grid's): every value any group has.
|
|
81
|
+
def box_switches
|
|
82
|
+
return '' unless @m['layout'] == 'grid'
|
|
83
|
+
|
|
84
|
+
all = @dims.to_h do |d|
|
|
85
|
+
[d['key'], d['values'].map { |v| v['key'] }.select { |k| @m['groups'].any? { |g| g['values'][d['key']].include?(k) } }]
|
|
86
|
+
end
|
|
87
|
+
switches(all, 'box', all.transform_values(&:first))
|
|
59
88
|
end
|
|
60
89
|
|
|
61
90
|
# Preloading with the defaults needs no attribute; off, or with caps of the site's own, says so.
|
|
@@ -77,44 +106,101 @@ module VisualCI
|
|
|
77
106
|
(v['url2x'] && !v['bytes2x'].nil? ? %( data-vg-2x-bytes="#{v['bytes2x']}") : '')
|
|
78
107
|
end
|
|
79
108
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
109
|
+
# The starting choice: the first group's first value of each dimension (the grid), or the first value any group
|
|
110
|
+
# has (the strip).
|
|
111
|
+
def start_choice
|
|
112
|
+
@dims.to_h do |d|
|
|
113
|
+
[d['key'],
|
|
114
|
+
if @m['layout'] == 'strip'
|
|
115
|
+
d['values'].find { |v| @m['groups'].any? { |g| g['values'][d['key']].include?(v['key']) } }['key']
|
|
116
|
+
else
|
|
117
|
+
@m['groups'][0]['values'][d['key']][0]
|
|
118
|
+
end]
|
|
119
|
+
end
|
|
88
120
|
end
|
|
89
121
|
|
|
90
|
-
|
|
122
|
+
# A group's start: the choice's value of each dimension when the group has it, else the group's first.
|
|
123
|
+
def group_choice(g, choice)
|
|
124
|
+
@dims.to_h do |d|
|
|
125
|
+
have = g['values'][d['key']]
|
|
126
|
+
[d['key'], have.include?(choice[d['key']]) ? choice[d['key']] : have[0]]
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# A card's combination for a choice: its own first value of each dimension (but a "hide" one, where the card is
|
|
131
|
+
# off) it lacks the chosen one of. A strip's card can lack an "error" dimension's value its group doesn't have.
|
|
132
|
+
def card_combo(sc, choice)
|
|
133
|
+
lacks = ->(d) { d['missing'] != 'hide' && sc['variants'].none? { |v| v['values'][d['key']] == choice[d['key']] } }
|
|
134
|
+
out = @dims.to_h { |d| [d['key'], lacks.call(d) ? sc['variants'][0]['values'][d['key']] : choice[d['key']]] }
|
|
135
|
+
# The card's first value must also go with the rest of the combination: take it from a variant that has the
|
|
136
|
+
# rest.
|
|
137
|
+
@dims.each do |d|
|
|
138
|
+
next unless lacks.call(d)
|
|
139
|
+
|
|
140
|
+
match = sc['variants'].find { |v| @dims.all? { |e| e['key'] == d['key'] || v['values'][e['key']] == out[e['key']] } }
|
|
141
|
+
out[d['key']] = match['values'][d['key']] if match
|
|
142
|
+
end
|
|
143
|
+
out
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Off for a choice: some "hide" dimension's chosen value isn't among the card's.
|
|
147
|
+
def card_off?(sc, choice)
|
|
148
|
+
@dims.any? { |d| d['missing'] == 'hide' && sc['variants'].none? { |v| v['values'][d['key']] == choice[d['key']] } }
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# One card: a link to its image for the choice (which hydrate() turns into the full-size view), the images, its
|
|
152
|
+
# title and caption.
|
|
153
|
+
def card(g, sc, choice, variants, heading, caption)
|
|
91
154
|
imgs = []
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
next if at.empty?
|
|
97
|
-
|
|
98
|
-
shown << size
|
|
99
|
-
first ||= at[0]
|
|
100
|
-
# Every size has both themes (the model refuses a screen without); the same image for both is shown once.
|
|
101
|
-
if at[0]['url'] == at[1]['url'] && at[0]['url2x'] == at[1]['url2x'] &&
|
|
102
|
-
at[0]['thumb']&.dig('url') == at[1]['thumb']&.dig('url')
|
|
103
|
-
imgs << image(sc['title'], at[0], %w[light dark])
|
|
104
|
-
else
|
|
105
|
-
at.each { |v| imgs << image(sc['title'], v, [v['theme']]) }
|
|
155
|
+
variants.each do |v|
|
|
156
|
+
same = imgs.find do |i|
|
|
157
|
+
f = i[0]
|
|
158
|
+
f['url'] == v['url'] && f['url2x'] == v['url2x'] && f['thumb']&.dig('url') == v['thumb']&.dig('url')
|
|
106
159
|
end
|
|
160
|
+
same ? same << v : imgs << [v]
|
|
107
161
|
end
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
162
|
+
combo = card_combo(sc, choice)
|
|
163
|
+
holds = ->(i, c) { i.any? { |v| combo_of(v['values']) == combo_of(c) } }
|
|
164
|
+
first = imgs.find { |i| holds.call(i, combo) } || imgs[0]
|
|
165
|
+
themes = g['values']['theme']
|
|
166
|
+
follows = themes.include?('light') && themes.include?('dark')
|
|
167
|
+
shown = lambda do |i|
|
|
168
|
+
next(holds.call(i, combo) ? '' : nil) unless follows
|
|
169
|
+
|
|
170
|
+
marks = %w[light dark].select { |t| holds.call(i, card_combo(sc, choice.merge('theme' => t))) }
|
|
171
|
+
marks.empty? ? nil : marks.join(' ')
|
|
172
|
+
end
|
|
173
|
+
%(<li class="vg-card" data-vg-screen="#{esc(sc['key'])}") +
|
|
174
|
+
(card_off?(sc, choice) ? ' data-vg-off' : '') +
|
|
175
|
+
(g['fit'] == 'contain' ? ' data-vg-fit="contain"' : '') + '>' +
|
|
176
|
+
%(<a class="vg-thumb" href="#{esc(first[0]['url'])}" data-vg-open aria-label="#{esc(sc['title'])}: view full size">) +
|
|
177
|
+
imgs.map { |i| image(g, sc['title'], i, shown.call(i)) }.join + '</a>' +
|
|
112
178
|
%(<#{heading} class="vg-card-title">#{esc(sc['title'])}</#{heading}>) +
|
|
113
179
|
(caption && !sc['caption'].nil? ? %(<p class="vg-caption">#{esc(sc['caption'])}</p>) : '') +
|
|
114
180
|
'</li>'
|
|
115
181
|
end
|
|
116
182
|
|
|
117
|
-
|
|
183
|
+
# An image, for the combinations its variants are; its alt text names the values that differ within the group.
|
|
184
|
+
def image(g, title, variants, shown)
|
|
185
|
+
v = variants[0]
|
|
186
|
+
parts = [title]
|
|
187
|
+
@dims.each do |d|
|
|
188
|
+
next if g['values'][d['key']].length < 2
|
|
189
|
+
|
|
190
|
+
parts << d['values'].select { |x| variants.any? { |w| w['values'][d['key']] == x['key'] } }
|
|
191
|
+
.map { |x| x['label'] }.join(' and ')
|
|
192
|
+
end
|
|
193
|
+
thumb = v['thumb']
|
|
194
|
+
%(<img class="vg-img" data-vg-for="#{variants.map { |w| combo_of(w['values']) }.join(' ')}") +
|
|
195
|
+
(shown.nil? ? '' : %( data-vg-shown="#{shown}")) +
|
|
196
|
+
%( src="#{esc(thumb ? thumb['url'] : v['url'])}") +
|
|
197
|
+
(thumb ? %( data-src-full="#{esc(v['url'])}") : '') +
|
|
198
|
+
(v['url2x'] ? %( data-src-2x="#{esc(v['url2x'])}") : '') +
|
|
199
|
+
bytes_attrs(v) +
|
|
200
|
+
%( width="#{v['width']}" height="#{v['height']}" alt="#{esc(parts.join(', '))}" loading="lazy" decoding="async">)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def grid(choice, out)
|
|
118
204
|
groups = @m['groups']
|
|
119
205
|
tabs = groups.length > 1
|
|
120
206
|
if tabs
|
|
@@ -126,31 +212,31 @@ module VisualCI
|
|
|
126
212
|
out << '</div>'
|
|
127
213
|
end
|
|
128
214
|
groups.each_with_index do |g, i|
|
|
129
|
-
|
|
215
|
+
start = group_choice(g, choice)
|
|
216
|
+
out << %(<div class="vg-panel" id="#{@id}-panel-#{g['slug']}" data-vg-shape="#{shape_of(start['size'])}") +
|
|
130
217
|
(tabs ? %( role="tabpanel" aria-labelledby="#{@id}-tab-#{g['slug']}") : '') +
|
|
131
218
|
(i.positive? ? ' hidden' : '') + '>'
|
|
132
|
-
controls = (
|
|
219
|
+
controls = switches(g['values'], "panel-#{g['slug']}", start)
|
|
133
220
|
out << %(<div class="vg-bar"><#{h(@below)} class="vg-group-title">#{esc(g['title'])}</#{h(@below)}>) +
|
|
134
221
|
(controls.empty? ? '' : %(<div class="vg-controls">#{controls}</div>)) + '</div>'
|
|
135
222
|
out << '<ul class="vg-grid">'
|
|
136
|
-
g['screens'].each { |sc| out << card(sc,
|
|
223
|
+
g['screens'].each { |sc| out << card(g, sc, start, sc['variants'], h(@below + 1), true) }
|
|
137
224
|
out << '</ul>'
|
|
138
225
|
out << '</div>'
|
|
139
226
|
end
|
|
140
227
|
end
|
|
141
228
|
|
|
142
|
-
def
|
|
143
|
-
@
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
def strip(out)
|
|
147
|
-
size = strip_size
|
|
148
|
-
out << %(<div class="vg-panel" id="#{@id}-strip" data-vg-sizes="#{size}">)
|
|
229
|
+
def strip(choice, out)
|
|
230
|
+
out << %(<div class="vg-panel" id="#{@id}-strip" data-vg-shape="#{shape_of(choice['size'])}">)
|
|
149
231
|
out << '<div class="vg-strip"><button type="button" class="vg-icon vg-strip-prev" data-vg-scroll="-1" aria-label="Scroll back">‹</button>'
|
|
150
232
|
out << '<ul class="vg-grid vg-track">'
|
|
151
233
|
@m['groups'].each do |g|
|
|
152
234
|
g['screens'].each do |sc|
|
|
153
|
-
|
|
235
|
+
next if card_off?(sc, choice)
|
|
236
|
+
|
|
237
|
+
combo = card_combo(sc, choice)
|
|
238
|
+
variants = sc['variants'].select { |v| @dims.all? { |d| d['key'] == 'theme' || v['values'][d['key']] == combo[d['key']] } }
|
|
239
|
+
out << card(g, sc, choice, variants, h(@below), false)
|
|
154
240
|
end
|
|
155
241
|
end
|
|
156
242
|
out << '</ul>'
|