@pseudolux-ui/media-library 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1532 @@
1
+ <view>
2
+ <div class="wall" $ref="root" $class="{ names: state.names, picking: state.picking }">
3
+ <div class="px-row tally" $show="state.ready && !state.error">
4
+ <b class="count" aria-live="polite">{{ state.countLabel }}</b>
5
+ <span class="px-subtle" $show="state.countNote">{{ state.countNote }}</span>
6
+ <button class="px-btn px-btn-primary px-btn-sm describe" type="button" $show="state.needsCount && !state.picking" @click="describeShown">{{ state.needsLabel }}</button>
7
+ </div>
8
+
9
+ <div class="bin-note px-subtle" $show="state.binMode && state.ready && !state.error && state.tiles">Pictures here are hidden from pickers. Open one to restore it.</div>
10
+
11
+ <!-- The first page of a new question: the shape of what is coming. -->
12
+ <div class="mx-rows" $show="state.fresh" aria-busy="true" aria-label="Loading pictures">
13
+ <div class="mx-row" $for="row in state.skeleton" $key="row.key" $style="row.style">
14
+ <span class="px-skel skel" $for="one in row.items" $key="one.key" $style="one.style"></span>
15
+ </div>
16
+ </div>
17
+
18
+ <div class="px-empty empty" $show="state.empty" $role="state.error ? 'alert' : null">
19
+ <b>{{ state.emptyTitle }}</b>
20
+ <p class="px-muted" $show="state.emptyBody">{{ state.emptyBody }}</p>
21
+ <p class="px-subtle" $show="state.error">{{ state.error }}</p>
22
+ <div class="px-row">
23
+ <button class="px-btn px-btn-secondary px-btn-sm" type="button" $show="state.error" @click="reload">Try again</button>
24
+ <button class="px-btn px-btn-primary" type="button" $show="state.emptyUpload" @click="askUpload">Upload pictures</button>
25
+ <button class="px-btn px-btn-secondary px-btn-sm" type="button" $show="state.emptyMore" @click="lookFurther">Look further</button>
26
+ <button class="px-btn px-btn-ghost px-btn-sm" type="button" $show="state.emptyClear" @click="clearSentence">Clear</button>
27
+ </div>
28
+ </div>
29
+
30
+ <div class="sections" role="group" aria-label="Pictures" $ref="grid" $show="!state.fresh && state.tiles" @keydown="onKey">
31
+ <div class="section" role="group" $for="section in state.sections" $key="section.key" $aria-label="section.label || 'Pictures'">
32
+ <div class="date-h" $show="section.label">{{ section.label }}<span class="px-subtle date-n">{{ section.count }}</span></div>
33
+ <div class="mx-rows">
34
+ <div class="band" $for="row in section.rows" $key="row.key">
35
+ <div class="mx-row" $style="row.style">
36
+ <button
37
+ class="ph opens"
38
+ type="button"
39
+ $for="tile in row.items"
40
+ $key="tile.id"
41
+ $data-id="tile.id"
42
+ $aria-expanded="tile.id === state.peekId"
43
+ $aria-label="tile.aria"
44
+ $tabindex="tile.id === state.focusId ? 0 : -1"
45
+ $class="{ 'is-sel': tile.picked, 'is-open': tile.id === state.peekId, 'is-binned': tile.binned, 'is-failed': tile.failed }"
46
+ $style="tile.style"
47
+ @click="onTile($event, tile)"
48
+ @dblclick="edit(tile.id)"
49
+ >
50
+ <img class="pic" $if="!tile.failed" $src="tile.src" $data-id="tile.id" $style="tile.picStyle" alt="" loading="lazy" decoding="async" />
51
+ <span class="failed" $if="tile.failed">Couldn't load this one · <u>Try again</u></span>
52
+ <span class="dot" $show="tile.noAlt" title="Needs words"></span>
53
+ <span class="flag" $show="tile.flag" $class="{ 'is-danger': tile.flagDanger }" $title="tile.flagTitle">!</span>
54
+ <span class="lock" $show="tile.viewOnly" $title="tile.whyViewOnly"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" aria-hidden="true"><rect x="4" y="11" width="16" height="10" rx="2"></rect><path d="M8 11V7a4 4 0 0 1 8 0v4"></path></svg></span>
55
+ <span class="ck" aria-hidden="true" $title="tile.picked ? 'Unpick' : 'Pick'"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"></path></svg></span>
56
+ <span class="ov">{{ tile.label }}</span>
57
+ </button>
58
+ </div>
59
+ <PicturePeek $if="row.peek" $asset="state.peekAsset" $prev="state.peekPrev" $next="state.peekNext" $picked="state.peekPicked" $arrow="state.peekArrow" $picking="state.picking" />
60
+ </div>
61
+ </div>
62
+ </div>
63
+ </div>
64
+
65
+ <div class="more" $show="state.showMore && !state.fresh">
66
+ <span class="px-subtle" $show="state.loading" aria-live="polite">Loading more pictures…</span>
67
+ <button class="px-btn px-btn-secondary" type="button" $show="!state.loading && state.paused" @click="lookFurther">Look further</button>
68
+ <span class="px-subtle text-danger" role="alert" $show="state.moreError">{{ state.moreError }} <button class="px-btn px-btn-ghost px-btn-sm" type="button" @click="lookFurther">Try again</button></span>
69
+ </div>
70
+ <span class="sentinel" $ref="sentinel" aria-hidden="true"></span>
71
+
72
+ <!-- With anything picked: what can be done to all of them at once. -->
73
+ <div class="dock" role="toolbar" aria-label="Picked pictures" $show="state.pickedCount && !state.picking">
74
+ <b>{{ state.pickedLabel }}</b>
75
+ <button type="button" class="pri" $show="state.canLabel" @click="describePicked">Describe one by one</button>
76
+ <button type="button" $show="state.canLabel" $aria-expanded="state.labelling" @click="toggleLabelling">Label</button>
77
+ <button type="button" $show="state.canBin" @click="binPicked">{{ state.binMode ? 'Restore' : 'Bin' }}</button>
78
+ <button type="button" class="clear" aria-label="Clear picks" @click="clearPicked"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12"></path></svg></button>
79
+ <form class="dock-pop" $show="state.labelling" @submit="applyLabel">
80
+ <label class="dock-label" for="wall-label">Add a label to {{ state.pickedLabelTarget }}</label>
81
+ <input class="px-input" id="wall-label" type="text" $ref="labelInput" $model="state.labelText" autocomplete="off" />
82
+ <button class="px-btn px-btn-primary px-btn-sm" type="submit" $disabled="!state.labelText.trim() || state.working">Add</button>
83
+ </form>
84
+ <form class="dock-pop" $show="state.binning" @submit="confirmBin">
85
+ <label class="dock-label" for="wall-reason">Why are these going in the bin?</label>
86
+ <select class="px-select" id="wall-reason" $model="state.binReason">
87
+ <option value="Duplicate">Duplicate</option>
88
+ <option value="Poor quality">Poor quality</option>
89
+ <option value="Rights have ended">Rights have ended</option>
90
+ <option value="No longer needed">No longer needed</option>
91
+ </select>
92
+ <button class="px-btn px-btn-danger px-btn-sm" type="submit" $disabled="state.working">Move {{ state.pickedLabelTarget }} to the bin</button>
93
+ </form>
94
+ </div>
95
+
96
+ <!-- Space: the picture as large as the screen allows, for looking only. -->
97
+ <div class="scrim" $show="state.quickId" @click="quickBackdrop">
98
+ <div class="quick" role="dialog" aria-modal="true" $aria-label="'Quick look: ' + state.quick.label" tabindex="-1" $ref="quick">
99
+ <img class="quick-pic" $src="state.quick.src" $style="state.quick.style" alt="" />
100
+ <div class="quick-meta">
101
+ <div class="quick-words">
102
+ <b>{{ state.quick.label }}</b>
103
+ <span class="quick-alt">{{ state.quick.alt }}</span>
104
+ <span class="px-subtle">{{ state.quick.meta }}</span>
105
+ </div>
106
+ <div class="px-row">
107
+ <span class="px-badge px-badge-warn" $show="state.quick.noAlt">Needs words</span>
108
+ <button class="px-btn px-btn-primary px-btn-sm" type="button" @click="edit(state.quickId)">Open editor</button>
109
+ </div>
110
+ </div>
111
+ </div>
112
+ <div class="quick-hint" aria-hidden="true">
113
+ <span><span class="px-kbd">Space</span> close</span>
114
+ <span><span class="px-kbd">←</span> <span class="px-kbd">→</span> <span class="px-kbd">↑</span> <span class="px-kbd">↓</span> move through the pictures</span>
115
+ <span><span class="px-kbd">Enter</span> open editor</span>
116
+ <span><span class="px-kbd">X</span> pick</span>
117
+ </div>
118
+ </div>
119
+
120
+ <span class="sr-only" role="status">{{ state.announce }}</span>
121
+ </div>
122
+ </view>
123
+
124
+ <logic lang="ts">
125
+ import { reactive, onMounted, onUnmounted, onUpdate, shared, defineProps, defineRefs } from '@lightspeed-js/core'
126
+ import {
127
+ getLibrary,
128
+ describedFor,
129
+ defaultView,
130
+ cannotChange,
131
+ canWrite,
132
+ SELECTED,
133
+ CHANGED,
134
+ VIEW,
135
+ PRESETS,
136
+ SENTENCE,
137
+ WALL,
138
+ PICKED,
139
+ CAPABILITIES,
140
+ UPLOAD,
141
+ PEEK,
142
+ PATCHED,
143
+ SET,
144
+ RUN,
145
+ LINK,
146
+ COMMAND,
147
+ CHOSEN,
148
+ letterKeys,
149
+ previewUrl,
150
+ canDescribeView,
151
+ } from '../config.ts'
152
+ import { pixelsFor } from '../ladder.ts'
153
+ import { BLANK, fits, isSet, judgedHere } from '../sentence.ts'
154
+ import { flagsOf } from '../checks.ts'
155
+ import { TARGET_HEIGHT, GAP, aspectOf, byDate, justify, place, neighbour } from '../rows.ts'
156
+
157
+ /**
158
+ * Every picture the sentence describes, in rows at their own shape.
159
+ *
160
+ * Paged by cursor, and the next page is fetched as the end of the wall comes
161
+ * into view. Parts of the sentence the store cannot answer (shape, whether a
162
+ * picture has words, when it was added) are judged on what has loaded, so
163
+ * the wall keeps looking further while one of them is set, and says how far
164
+ * it has looked.
165
+ *
166
+ * `mode="bin"` shows the bin instead.
167
+ */
168
+ const props = defineProps({
169
+ mode: { default: 'library' },
170
+ /** Inside a picker: looking at a picture chooses it, and nothing is
171
+ * picked in bulk. */
172
+ pick: { default: false },
173
+ })
174
+
175
+ const refs = defineRefs()
176
+
177
+ const PAGE_SIZE = 60
178
+ // How many pages to fetch one after another without anybody asking. A narrow
179
+ // sentence over a large library would otherwise read all of it.
180
+ const BURST = 6
181
+
182
+ const state = reactive({
183
+ sections: [],
184
+ skeleton: [],
185
+ tiles: 0,
186
+ names: false,
187
+ picking: false,
188
+ size: 'M',
189
+ binMode: false,
190
+ loading: true,
191
+ fresh: true,
192
+ ready: false,
193
+ paused: false,
194
+ error: '',
195
+ moreError: '',
196
+ showMore: false,
197
+ countLabel: '',
198
+ countNote: '',
199
+ empty: false,
200
+ emptyTitle: '',
201
+ emptyBody: '',
202
+ emptyUpload: false,
203
+ emptyMore: false,
204
+ emptyClear: false,
205
+ focusId: '',
206
+ peekId: '',
207
+ peekAsset: null,
208
+ peekPrev: '',
209
+ peekNext: '',
210
+ peekPicked: false,
211
+ peekArrow: 80,
212
+ quickId: '',
213
+ quick: { label: '', src: '', style: '', alt: '', meta: '', noAlt: false },
214
+ needsCount: 0,
215
+ needsLabel: '',
216
+ pickedCount: 0,
217
+ pickedLabel: '',
218
+ pickedLabelTarget: '',
219
+ canLabel: false,
220
+ canBin: false,
221
+ labelling: false,
222
+ labelText: '',
223
+ binning: false,
224
+ binReason: 'Duplicate',
225
+ working: false,
226
+ announce: '',
227
+ })
228
+
229
+ const selected = shared(SELECTED)
230
+ const changed = shared(CHANGED)
231
+ const view = shared(VIEW)
232
+ const presets = shared(PRESETS)
233
+ const sentenceCell = shared(SENTENCE)
234
+ const wall = shared(WALL)
235
+ const pickedCell = shared(PICKED)
236
+ const capabilitiesCell = shared(CAPABILITIES)
237
+ const upload = shared(UPLOAD)
238
+ const peek = shared(PEEK)
239
+ const patched = shared(PATCHED)
240
+ const set = shared(SET)
241
+ const run = shared(RUN)
242
+ const link = shared(LINK)
243
+ const command = shared(COMMAND)
244
+ const chosen = shared(CHOSEN)
245
+
246
+ const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many)
247
+
248
+ // Not reactive: the listing as it arrived, and what has been worked out from
249
+ // it. Only what the template draws goes into `state`.
250
+ let assets = []
251
+ let shown = []
252
+ let placed = []
253
+ let picked = []
254
+ let cursor = ''
255
+ let canLoadMore = false
256
+ let canSearch = false
257
+ let capabilities = null
258
+ let width = 0
259
+ let burst = 0
260
+ let lastPickedId = ''
261
+ const failed = new Set()
262
+ // The widest file already asked for, per picture: a smaller row must not
263
+ // fetch a smaller file when the larger one is in the cache.
264
+ const asked = new Map()
265
+
266
+ const sentence = () => sentenceCell.value || BLANK
267
+ const activeView = () => sentence().group || defaultView() || undefined
268
+ const aboutHere = () => !canSearch
269
+
270
+ // The record as the store sent it, by id. A tile carries the alt text as the
271
+ // current view reads it, which is not what a change should start from.
272
+ const sources = new Map()
273
+
274
+ function present(asset) {
275
+ sources.set(asset.id, asset)
276
+ const current = activeView()
277
+ const seen = describedFor(asset, current)
278
+ const why = cannotChange(asset.tags)
279
+ const binned = Boolean(asset.deletedAt)
280
+ const key = current ? current.trim().toLowerCase() : ''
281
+ // Where the view has its own words for a picture, those are the ones shown,
282
+ // so those are the ones a quick edit changes.
283
+ const ownWords = Boolean(key && asset.views && asset.views[key] && asset.views[key].altText !== undefined)
284
+ return {
285
+ ...asset,
286
+ altView: ownWords && canDescribeView(current) ? current : '',
287
+ flags: binned ? [] : flagsOf(asset, (capabilities && capabilities.presets) || []),
288
+ label: asset.filename || asset.id,
289
+ altText: seen.altText || '',
290
+ aspect: aspectOf(asset),
291
+ binned,
292
+ noAlt: !seen.altText && !binned,
293
+ viewOnly: canWrite() && Boolean(why),
294
+ whyViewOnly: why,
295
+ }
296
+ }
297
+
298
+ // `fits` wants to know only whether there is a flag.
299
+ const judged = (one) => ({ ...one, flagged: one.flags.length > 0 })
300
+
301
+ function srcFor(tile, cssWidth) {
302
+ const dpr = (typeof window !== 'undefined' && window.devicePixelRatio) || 1
303
+ const want = Math.max(pixelsFor(cssWidth, dpr), asked.get(tile.id) || 0)
304
+ asked.set(tile.id, want)
305
+ return getLibrary().imageUrl(tile.id, { width: want, format: 'webp' })
306
+ }
307
+
308
+ function drawTile(tile, row) {
309
+ const cssWidth = tile.aspect * row.height
310
+ const colour = tile.palette && tile.palette[0] ? tile.palette[0].hex : ''
311
+ const isPicked = picked.includes(tile.id)
312
+ return {
313
+ id: tile.id,
314
+ label: tile.label,
315
+ noAlt: tile.noAlt,
316
+ flag: tile.flags.length > 0,
317
+ flagDanger: tile.flags.some((one) => one.tone === 'danger'),
318
+ flagTitle: tile.flags.map((one) => one.label + '. ' + one.detail).join(' '),
319
+ binned: tile.binned,
320
+ viewOnly: tile.viewOnly,
321
+ whyViewOnly: tile.whyViewOnly,
322
+ picked: isPicked,
323
+ failed: failed.has(tile.id),
324
+ src: srcFor(tile, cssWidth),
325
+ aria: [tile.label, isPicked ? 'picked' : '', tile.noAlt ? 'needs words' : '', ...tile.flags.map((one) => one.label.toLowerCase()), tile.viewOnly ? 'view only' : '', tile.binned ? 'in the bin' : ''].filter(Boolean).join(', '),
326
+ // A full row shares the space by shape; the last keeps each picture's own width.
327
+ style: (row.last ? 'flex: 0 0 ' + Math.round(cssWidth) + 'px' : 'flex: ' + tile.aspect + ' 1 0') + (colour ? '; background-color: ' + colour : ''),
328
+ picStyle: tile.focal ? 'object-position: ' + tile.focal.x + '% ' + tile.focal.y + '%' : '',
329
+ }
330
+ }
331
+
332
+ function layout() {
333
+ if (!width) return
334
+ const target = TARGET_HEIGHT[state.size] || TARGET_HEIGHT.M
335
+ // Sections by date only where the listing is in date order: a search may
336
+ // answer by relevance, and the bin by when things were binned.
337
+ const dated = !sentence().about && !state.binMode
338
+ const groups = dated ? byDate(shown, new Date()) : [{ key: 'all', label: '', items: shown }]
339
+ const every = []
340
+ state.sections = groups.map((group) => {
341
+ const rows = justify(group.items, width, target)
342
+ every.push(...rows)
343
+ return {
344
+ key: group.key,
345
+ label: group.label,
346
+ count: String(group.items.length),
347
+ rows: rows.map((row, index) => ({
348
+ key: group.key + ':' + index,
349
+ style: 'height: ' + row.height + 'px',
350
+ peek: Boolean(state.peekId) && row.items.some((tile) => tile.id === state.peekId),
351
+ items: row.items.map((tile) => drawTile(tile, row)),
352
+ })),
353
+ }
354
+ })
355
+ placed = place(every)
356
+ state.tiles = shown.length
357
+ describePeek()
358
+ }
359
+
360
+ function describePeek() {
361
+ const at = shown.findIndex((one) => one.id === state.peekId)
362
+ if (state.picking) {
363
+ const record = at < 0 ? null : sources.get(state.peekId) || null
364
+ const now = chosen.value
365
+ if ((now ? now.id : '') !== (record ? record.id : '') || (record && JSON.stringify(now) !== JSON.stringify(record))) {
366
+ chosen.value = record ? JSON.parse(JSON.stringify(record)) : null
367
+ }
368
+ }
369
+ if (at < 0) {
370
+ if (state.peekId) {
371
+ state.peekId = ''
372
+ peek.value = null
373
+ }
374
+ state.peekAsset = null
375
+ return
376
+ }
377
+ state.peekAsset = shown[at]
378
+ state.peekPrev = at > 0 ? shown[at - 1].id : ''
379
+ state.peekNext = at < shown.length - 1 ? shown[at + 1].id : ''
380
+ state.peekPicked = picked.includes(state.peekId)
381
+ const where = placed.find((one) => one.id === state.peekId)
382
+ state.peekArrow = where ? where.middle : 80
383
+ }
384
+
385
+ function skeleton() {
386
+ const target = TARGET_HEIGHT[state.size] || TARGET_HEIGHT.M
387
+ const aspects = [1.5, 0.75, 1.78, 1, 1.33, 0.8, 1.5, 2, 1.33, 0.75, 1.5, 1, 1.78, 1.33]
388
+ const rows = justify(aspects.map((aspect, index) => ({ id: 's' + index, aspect })), width || 1200, target)
389
+ state.skeleton = rows.map((row, index) => ({
390
+ key: index,
391
+ style: 'height: ' + row.height + 'px',
392
+ items: row.items.map((one) => ({ key: one.id, style: row.last ? 'flex: 0 0 ' + Math.round(one.aspect * row.height) + 'px' : 'flex: ' + one.aspect + ' 1 0' })),
393
+ }))
394
+ }
395
+
396
+ /** Whether what is loaded is all there is for this sentence. The store lists
397
+ * newest first, so once a picture from before the period has arrived,
398
+ * "added this week" has everything, unless the text reorders by relevance. */
399
+ function complete() {
400
+ if (!canLoadMore) return true
401
+ const s = sentence()
402
+ if (!s.when || s.about || s.shape || s.condition) return false
403
+ const last = assets[assets.length - 1]
404
+ return Boolean(last && last.createdAt && !fits({ createdAt: last.createdAt }, { ...BLANK, when: s.when }, new Date()))
405
+ }
406
+
407
+ function refresh() {
408
+ const s = sentence()
409
+ const now = new Date()
410
+ shown = state.binMode ? assets : assets.filter((one) => kept.has(one.id) || fits(judged(one), s, now, aboutHere()))
411
+ picked = picked.filter((id) => assets.some((one) => one.id === id))
412
+ layout()
413
+
414
+ const narrowed = !state.binMode && judgedHere(s, aboutHere())
415
+ const whole = complete()
416
+ state.showMore = !whole
417
+ const n = shown.length
418
+ const what = state.binMode ? plural(n, 'picture in the bin', 'pictures in the bin') : plural(n, 'picture', 'pictures')
419
+ state.countLabel = whole ? what : narrowed ? what + ' so far' : 'The newest ' + what
420
+ state.countNote = whole ? '' : narrowed ? 'Looked at the newest ' + assets.length + '.' : ''
421
+
422
+ if (!shown.some((one) => one.id === state.focusId)) state.focusId = shown.length ? shown[0].id : ''
423
+ set.value = { items: shown.map((one) => ({ id: one.id, label: one.label, noAlt: one.noAlt, record: sources.get(one.id) })) }
424
+ const needing = state.binMode || !canWrite() ? [] : shown.filter((one) => one.noAlt && !one.whyViewOnly)
425
+ state.needsCount = needing.length
426
+ state.needsLabel = needing.length === 1 ? 'Describe the 1 that needs words' : 'Describe the ' + needing.length + ' that need words'
427
+ publishPicked()
428
+ describeEmpty(n, narrowed, whole)
429
+ }
430
+
431
+ function describeEmpty(count, narrowed, whole) {
432
+ state.emptyUpload = false
433
+ state.emptyMore = false
434
+ state.emptyClear = false
435
+ state.emptyBody = ''
436
+
437
+ if (state.error) {
438
+ state.empty = true
439
+ state.emptyTitle = "Pictures didn't load"
440
+ state.emptyBody = "The library couldn't be reached. Pictures on your sites are not affected."
441
+ return
442
+ }
443
+ state.empty = state.ready && !state.fresh && !state.loading && count === 0
444
+ if (!state.empty) return
445
+
446
+ const s = sentence()
447
+ if (state.binMode) {
448
+ state.emptyTitle = 'The bin is empty'
449
+ } else if (isSet(s)) {
450
+ state.emptyTitle = whole ? 'Nothing fits that sentence.' : 'Nothing in the newest ' + assets.length + ' pictures fits that sentence.'
451
+ state.emptyBody = whole ? 'Choose a highlighted part to loosen it, or clear it.' : 'Look further to check older pictures, or loosen a highlighted part.'
452
+ state.emptyMore = !whole
453
+ state.emptyClear = true
454
+ } else {
455
+ state.emptyTitle = 'No pictures yet'
456
+ state.emptyUpload = Boolean(capabilities && capabilities.upload)
457
+ state.emptyBody = state.emptyUpload ? 'Drop files anywhere here, or choose them. Several at once is fine.' : ''
458
+ }
459
+ }
460
+
461
+ // --- asking the store ------------------------------------------------------------
462
+
463
+ let generation = 0
464
+ let inFlight = null
465
+ // Described while "need words" is set: it stays until the sentence changes,
466
+ // rather than vanishing from under the cursor.
467
+ const kept = new Set()
468
+
469
+ function query() {
470
+ const s = sentence()
471
+ return {
472
+ limit: PAGE_SIZE,
473
+ ...(s.about && canSearch ? { text: s.about } : {}),
474
+ ...(s.group ? { group: s.group } : {}),
475
+ ...(state.binMode ? { deleted: true } : {}),
476
+ }
477
+ }
478
+
479
+ async function fetchPage(append, quiet = false) {
480
+ const mine = ++generation
481
+ state.loading = true
482
+ state.error = ''
483
+ state.moreError = ''
484
+ if (!append && !quiet) {
485
+ state.fresh = true
486
+ state.empty = false
487
+ skeleton()
488
+ }
489
+
490
+ if (inFlight) inFlight.abort()
491
+ const controller = new AbortController()
492
+ inFlight = controller
493
+
494
+ try {
495
+ const page = await getLibrary().list(append && cursor ? { ...query(), cursor } : query(), { signal: controller.signal })
496
+ if (mine !== generation) return
497
+
498
+ capabilities = page.capabilities
499
+ capabilitiesCell.value = page.capabilities
500
+ presets.value = page.capabilities.presets || []
501
+ // The first answer says whether the store can search. If it cannot and
502
+ // the sentence has text, the text is judged here instead.
503
+ canSearch = Boolean(page.capabilities.text)
504
+ state.canLabel = Boolean(page.capabilities.describe) && canWrite() && !state.binMode
505
+ state.canBin = Boolean(page.capabilities.remove) && canWrite()
506
+
507
+ const rows = page.items.map(present)
508
+ assets = append ? assets.concat(rows) : rows
509
+ cursor = page.nextCursor || ''
510
+ canLoadMore = Boolean(page.nextCursor)
511
+ state.ready = true
512
+ } catch (err) {
513
+ if (err && err.name === 'AbortError') return
514
+ if (mine !== generation) return
515
+ const why = err && err.message ? err.message : 'No answer from the library.'
516
+ if (append) {
517
+ state.moreError = "The next pictures didn't load: " + why
518
+ } else {
519
+ state.error = why
520
+ assets = []
521
+ }
522
+ state.ready = true
523
+ } finally {
524
+ if (mine === generation) {
525
+ state.loading = false
526
+ state.fresh = false
527
+ refresh()
528
+ // The end of the wall may still be in view: a narrow sentence, or a
529
+ // tall screen. Keep going, up to the burst.
530
+ requestAnimationFrame(considerMore)
531
+ }
532
+ }
533
+ }
534
+
535
+ function reload(quiet = false) {
536
+ cursor = ''
537
+ burst = 0
538
+ state.paused = false
539
+ view.value = activeView() || null
540
+ fetchPage(false, quiet === true)
541
+ }
542
+
543
+ let sentinelSeen = false
544
+
545
+ function considerMore() {
546
+ if (!sentinelSeen || state.loading || !canLoadMore || state.error || state.moreError || complete()) return
547
+ if (burst >= BURST) {
548
+ state.paused = true
549
+ return
550
+ }
551
+ burst++
552
+ fetchPage(true)
553
+ }
554
+
555
+ function lookFurther() {
556
+ burst = 0
557
+ state.paused = false
558
+ state.moreError = ''
559
+ if (canLoadMore) fetchPage(true)
560
+ }
561
+
562
+ function clearSentence() {
563
+ sentenceCell.value = { ...BLANK }
564
+ }
565
+
566
+ function askUpload() {
567
+ upload.value = (upload.value || 0) + 1
568
+ }
569
+
570
+ // --- opening and picking -----------------------------------------------------------
571
+
572
+ function publishPicked() {
573
+ state.pickedCount = picked.length
574
+ state.pickedLabel = picked.length + ' picked'
575
+ state.pickedLabelTarget = plural(picked.length, 'picture', 'pictures')
576
+ if (!picked.length) {
577
+ state.labelling = false
578
+ state.binning = false
579
+ }
580
+ const current = pickedCell.value || []
581
+ if (current.length !== picked.length || current.some((id, index) => id !== picked[index])) pickedCell.value = picked.slice()
582
+ }
583
+
584
+ function repaint() {
585
+ layout()
586
+ publishPicked()
587
+ }
588
+
589
+ function togglePick(id, range) {
590
+ if (range && lastPickedId && lastPickedId !== id) {
591
+ const ids = shown.map((one) => one.id)
592
+ const from = ids.indexOf(lastPickedId)
593
+ const to = ids.indexOf(id)
594
+ if (from >= 0 && to >= 0) {
595
+ const between = ids.slice(Math.min(from, to), Math.max(from, to) + 1)
596
+ picked = picked.concat(between.filter((one) => !picked.includes(one)))
597
+ lastPickedId = id
598
+ repaint()
599
+ return
600
+ }
601
+ }
602
+ picked = picked.includes(id) ? picked.filter((one) => one !== id) : picked.concat([id])
603
+ lastPickedId = id
604
+ repaint()
605
+ }
606
+
607
+ function clearPicked() {
608
+ picked = []
609
+ repaint()
610
+ }
611
+
612
+ function showPeek(id) {
613
+ state.focusId = id
614
+ // In a picker the peek is the choice, so a second click keeps it.
615
+ peek.value = state.peekId === id && !state.picking ? null : id
616
+ }
617
+
618
+ function edit(id) {
619
+ const asset = assets.find((one) => one.id === id)
620
+ if (!asset) return
621
+ closeQuick()
622
+ // A plain copy: a cell holding another component's rows is a thread
623
+ // between two owners.
624
+ selected.value = JSON.parse(JSON.stringify(asset))
625
+ }
626
+
627
+ function showQuick(id) {
628
+ const asset = shown.find((one) => one.id === id)
629
+ if (!asset) return
630
+ const opening = !state.quickId
631
+ state.quickId = id
632
+ state.quick = {
633
+ label: asset.label,
634
+ src: previewUrl(id),
635
+ style: 'aspect-ratio: ' + (asset.width && asset.height ? asset.width + ' / ' + asset.height : '3 / 2'),
636
+ alt: asset.altText || (asset.binned ? '' : 'No alt text yet.'),
637
+ meta: [asset.width && asset.height ? asset.width + ' × ' + asset.height : '', (asset.tags || []).join(', ')].filter(Boolean).join(' · '),
638
+ noAlt: asset.noAlt,
639
+ }
640
+ if (opening) requestAnimationFrame(() => refs.quick && refs.quick.focus())
641
+ }
642
+
643
+ function closeQuick() {
644
+ if (!state.quickId) return
645
+ const id = state.quickId
646
+ state.quickId = ''
647
+ focusTile(id)
648
+ }
649
+
650
+ function quickBackdrop(event) {
651
+ if (event.target && event.target.classList && event.target.classList.contains('scrim')) closeQuick()
652
+ }
653
+
654
+ function retry(id) {
655
+ failed.delete(id)
656
+ asked.delete(id)
657
+ layout()
658
+ }
659
+
660
+ function onTile(event, tile) {
661
+ if (failed.has(tile.id)) return retry(tile.id)
662
+ if (state.picking) return showPeek(tile.id)
663
+ const onTick = event.target && event.target.closest && event.target.closest('.ck')
664
+ // With anything picked, a click anywhere on a picture picks: the wall is
665
+ // in picking mode until the picks are cleared.
666
+ if (onTick || event.shiftKey || event.metaKey || event.ctrlKey) {
667
+ state.focusId = tile.id
668
+ togglePick(tile.id, event.shiftKey)
669
+ return
670
+ }
671
+ showPeek(tile.id)
672
+ }
673
+
674
+ const MOVES = { ArrowRight: 'right', ArrowLeft: 'left', ArrowDown: 'down', ArrowUp: 'up', Home: 'home', End: 'end' }
675
+
676
+ function focusTile(id) {
677
+ state.focusId = id
678
+ requestAnimationFrame(() => {
679
+ const tile = refs.grid && refs.grid.querySelector('.ph[data-id="' + CSS.escape(id) + '"]')
680
+ if (tile) tile.focus()
681
+ })
682
+ }
683
+
684
+ // The key press that opened the quick look also reaches the document, where
685
+ // the same key would close it again.
686
+ let openedBy = null
687
+
688
+ function onKey(event) {
689
+ if (state.quickId) return
690
+ const tile = event.target && event.target.closest ? event.target.closest('.ph') : null
691
+ if (!tile) return
692
+ const id = tile.getAttribute('data-id')
693
+ const move = MOVES[event.key]
694
+ if (move) {
695
+ event.preventDefault()
696
+ const next = neighbour(placed, id, move)
697
+ if (next) focusTile(next)
698
+ return
699
+ }
700
+ if (event.key === ' ') {
701
+ event.preventDefault()
702
+ openedBy = event
703
+ showQuick(id)
704
+ return
705
+ }
706
+ if (event.key === 'Enter') {
707
+ event.preventDefault()
708
+ if (state.picking) showPeek(id)
709
+ else edit(id)
710
+ return
711
+ }
712
+ // Picking several, and what is done to them, belong to the library page.
713
+ if (state.picking) return
714
+ if (event.key === 'x' || event.key === 'X') {
715
+ event.preventDefault()
716
+ togglePick(id, event.shiftKey)
717
+ return
718
+ }
719
+ if ((event.metaKey || event.ctrlKey) && (event.key === 'a' || event.key === 'A')) {
720
+ event.preventDefault()
721
+ picked = shown.map((one) => one.id)
722
+ repaint()
723
+ state.announce = 'Picked all ' + plural(picked.length, 'picture', 'pictures') + ' shown'
724
+ return
725
+ }
726
+ if (letterKeys() && !event.metaKey && !event.ctrlKey && !event.altKey) {
727
+ const letter = event.key.toLowerCase()
728
+ if (letter === 'l' && event.shiftKey) {
729
+ event.preventDefault()
730
+ const asset = shown.find((one) => one.id === id)
731
+ if (asset && !asset.binned) link.value = JSON.parse(JSON.stringify(sources.get(id) || asset))
732
+ return
733
+ }
734
+ if (letter === 'l' && picked.length && state.canLabel) {
735
+ event.preventDefault()
736
+ toggleLabelling()
737
+ return
738
+ }
739
+ if (letter === 'd' && state.canLabel) {
740
+ event.preventDefault()
741
+ // The picked if any, else just this one.
742
+ startRun(shown.filter((one) => (picked.length ? picked.includes(one.id) : one.id === id)))
743
+ return
744
+ }
745
+ if ((event.key === 'Backspace' || event.key === 'Delete') && picked.length && state.canBin && !state.binMode) {
746
+ event.preventDefault()
747
+ state.labelling = false
748
+ state.binning = true
749
+ return
750
+ }
751
+ }
752
+ if (event.key === 'Escape' && state.peekId) {
753
+ event.preventDefault()
754
+ peek.value = null
755
+ return
756
+ }
757
+ if (event.key === 'Escape' && picked.length) {
758
+ event.preventDefault()
759
+ clearPicked()
760
+ }
761
+ }
762
+
763
+ // The quick look is over the wall, so its keys are heard on the document.
764
+ function onQuickKey(event) {
765
+ if (!state.quickId || event === openedBy) return
766
+ const move = MOVES[event.key]
767
+ if (move) {
768
+ event.preventDefault()
769
+ const next = neighbour(placed, state.quickId, move)
770
+ if (next) {
771
+ state.focusId = next
772
+ showQuick(next)
773
+ }
774
+ return
775
+ }
776
+ if (event.key === ' ' || event.key === 'Escape') {
777
+ event.preventDefault()
778
+ closeQuick()
779
+ } else if (event.key === 'Enter') {
780
+ event.preventDefault()
781
+ edit(state.quickId)
782
+ } else if (event.key === 'x' || event.key === 'X') {
783
+ event.preventDefault()
784
+ togglePick(state.quickId, false)
785
+ } else if (event.key === 'Tab') {
786
+ // One control in the dialog; focus stays inside it.
787
+ const button = refs.quick && refs.quick.querySelector('button')
788
+ if (button) {
789
+ event.preventDefault()
790
+ button.focus()
791
+ }
792
+ }
793
+ }
794
+
795
+ // --- describing one by one ------------------------------------------------------------
796
+
797
+ /** Only pictures this side may change go into a run: the rest would stop it
798
+ * at the first save. */
799
+ function startRun(list) {
800
+ const items = list.filter((one) => !one.whyViewOnly && !one.binned).map((one) => JSON.parse(JSON.stringify(one)))
801
+ if (!items.length) {
802
+ state.announce = 'None of those can be changed here'
803
+ return
804
+ }
805
+ peek.value = null
806
+ run.value = { items }
807
+ }
808
+
809
+ function describeShown() {
810
+ startRun(shown.filter((one) => one.noAlt))
811
+ }
812
+
813
+ function describePicked() {
814
+ startRun(shown.filter((one) => picked.includes(one.id)))
815
+ }
816
+
817
+ // --- doing something to everything picked -------------------------------------------
818
+
819
+ function toggleLabelling() {
820
+ state.binning = false
821
+ state.labelling = !state.labelling
822
+ if (state.labelling) requestAnimationFrame(() => refs.labelInput && refs.labelInput.focus())
823
+ }
824
+
825
+ /** The person's own labels on a picture, as the store wants them back: a
826
+ * model's proposals are left for the store to keep. */
827
+ function ownLabels(asset) {
828
+ return (asset.labels || [])
829
+ .filter((one) => !one.source || one.source.kind === 'person' || one.status === 'verified')
830
+ .map((one) => ({ term: one.term, ...(one.audience ? { audience: one.audience } : {}) }))
831
+ }
832
+
833
+ async function applyLabel(event) {
834
+ if (event) event.preventDefault()
835
+ const term = state.labelText.trim()
836
+ if (!term || state.working) return
837
+ state.working = true
838
+ const targets = assets.filter((one) => picked.includes(one.id) && !one.whyViewOnly)
839
+ const skipped = picked.length - targets.length
840
+ let done = 0
841
+ let lastError = ''
842
+ for (const asset of targets) {
843
+ const labels = ownLabels(asset)
844
+ if (labels.some((one) => one.term.toLowerCase() === term.toLowerCase())) {
845
+ done++
846
+ continue
847
+ }
848
+ try {
849
+ await getLibrary().describe(asset.id, { labels: labels.concat([{ term }]) })
850
+ asset.labels = (asset.labels || []).concat([{ term }])
851
+ done++
852
+ } catch (err) {
853
+ lastError = err && err.message ? err.message : 'no answer from the library'
854
+ }
855
+ }
856
+ state.working = false
857
+ state.labelText = ''
858
+ state.labelling = false
859
+ state.announce =
860
+ 'Added “' + term + '” to ' + plural(done, 'picture', 'pictures') +
861
+ (skipped ? '. ' + skipped + ' can only be viewed here' : '') +
862
+ (lastError ? '. Some did not save: ' + lastError : '')
863
+ }
864
+
865
+ async function binPicked() {
866
+ state.labelling = false
867
+ if (state.binMode) return restorePicked()
868
+ state.binning = !state.binning
869
+ }
870
+
871
+ async function confirmBin(event) {
872
+ if (event) event.preventDefault()
873
+ if (state.working) return
874
+ state.working = true
875
+ const targets = assets.filter((one) => picked.includes(one.id) && !one.whyViewOnly)
876
+ const skipped = picked.length - targets.length
877
+ let done = 0
878
+ for (const asset of targets) {
879
+ try {
880
+ await getLibrary().remove(asset.id, state.binReason)
881
+ done++
882
+ } catch {
883
+ // Counted by its absence below.
884
+ }
885
+ }
886
+ state.working = false
887
+ state.binning = false
888
+ picked = []
889
+ state.announce =
890
+ 'Moved ' + plural(done, 'picture', 'pictures') + ' to the bin' +
891
+ (skipped ? '. ' + skipped + ' can only be viewed here' : '') +
892
+ (done < targets.length ? '. ' + (targets.length - done) + " couldn't be moved" : '')
893
+ changed.value = (changed.value || 0) + 1
894
+ }
895
+
896
+ async function restorePicked() {
897
+ if (state.working) return
898
+ state.working = true
899
+ let done = 0
900
+ for (const id of picked.slice()) {
901
+ try {
902
+ await getLibrary().restore(id)
903
+ done++
904
+ } catch {
905
+ // As above.
906
+ }
907
+ }
908
+ state.working = false
909
+ picked = []
910
+ state.announce = 'Restored ' + plural(done, 'picture', 'pictures')
911
+ changed.value = (changed.value || 0) + 1
912
+ }
913
+
914
+ // --- pictures loading, and not -----------------------------------------------------
915
+
916
+ // `load` and `error` do not bubble, so they are heard on the way down.
917
+ function pictureLoaded(event) {
918
+ const target = event.target
919
+ if (target && target.classList && target.classList.contains('pic')) target.classList.add('is-in')
920
+ }
921
+
922
+ function pictureFailed(event) {
923
+ const target = event.target
924
+ if (!target || !target.classList || !target.classList.contains('pic')) return
925
+ const id = target.getAttribute('data-id')
926
+ if (!id || failed.has(id)) return
927
+ failed.add(id)
928
+ layout()
929
+ }
930
+
931
+ // --- following the rest of the library ---------------------------------------------
932
+
933
+ let lastSentence = ''
934
+ sentenceCell.subscribe((value) => {
935
+ const key = JSON.stringify(value || BLANK)
936
+ if (key === lastSentence) return
937
+ const before = lastSentence ? JSON.parse(lastSentence) : BLANK
938
+ lastSentence = key
939
+ kept.clear()
940
+ const next = value || BLANK
941
+ // Only the group and the text are asked of the store. The rest is judged
942
+ // on what is loaded, so it needs no new listing.
943
+ if (next.group !== before.group || (canSearch && next.about !== before.about)) reload()
944
+ else {
945
+ burst = 0
946
+ state.paused = false
947
+ refresh()
948
+ requestAnimationFrame(considerMore)
949
+ }
950
+ })
951
+
952
+ function readWall(value) {
953
+ const next = value || {}
954
+ const size = next.size === 'S' || next.size === 'L' ? next.size : 'M'
955
+ const resized = size !== state.size
956
+ state.size = size
957
+ state.names = Boolean(next.names)
958
+ if (resized) layout()
959
+ }
960
+ wall.subscribe(readWall)
961
+
962
+ // Back from the editor: the wall may have been redrawn while it was open,
963
+ // so focus goes to the picture by its id rather than to an element.
964
+ let lastEdited = ''
965
+ selected.subscribe((asset) => {
966
+ if (asset) {
967
+ lastEdited = asset.id
968
+ return
969
+ }
970
+ if (lastEdited && shown.some((one) => one.id === lastEdited)) focusTile(lastEdited)
971
+ lastEdited = ''
972
+ })
973
+
974
+ peek.subscribe((id) => {
975
+ const next = id || ''
976
+ if (next === state.peekId) return
977
+ state.peekId = next
978
+ if (next) state.focusId = next
979
+ layout()
980
+ })
981
+
982
+ // Words, a crop or a label changed somewhere else on the page.
983
+ patched.subscribe((change) => {
984
+ if (!change || !change.id) return
985
+ const at = assets.findIndex((one) => one.id === change.id)
986
+ if (at < 0) return
987
+ const before = sources.get(change.id) || assets[at]
988
+ // `replace` gives fields whole; `patch` merges a view's words into what
989
+ // is there. Either way, undefined takes a field away.
990
+ const patch = change.replace || change.patch || {}
991
+ const merged = { ...before, ...patch }
992
+ if (change.patch && patch.views) {
993
+ merged.views = { ...before.views }
994
+ for (const key of Object.keys(patch.views)) merged.views[key] = { ...(before.views && before.views[key]), ...patch.views[key] }
995
+ }
996
+ for (const key of Object.keys(merged)) {
997
+ if (merged[key] === undefined) delete merged[key]
998
+ }
999
+ assets[at] = present(merged)
1000
+ if (sentence().condition === 'needs') kept.add(change.id)
1001
+ refresh()
1002
+ })
1003
+
1004
+ pickedCell.subscribe((ids) => {
1005
+ const next = ids || []
1006
+ if (next.length === picked.length && next.every((id, index) => id === picked[index])) return
1007
+ picked = next.slice()
1008
+ layout()
1009
+ publishPicked()
1010
+ })
1011
+
1012
+ // Asked from outside the wall, such as the command bar.
1013
+ let lastCommand = 0
1014
+ command.subscribe((asked) => {
1015
+ if (!asked || asked.at === lastCommand) return
1016
+ lastCommand = asked.at
1017
+ if (asked.name === 'describe') describePicked()
1018
+ else if (asked.name === 'clear') clearPicked()
1019
+ else if (asked.name === 'label' && asked.arg) {
1020
+ state.labelText = asked.arg
1021
+ applyLabel()
1022
+ } else if (asked.name === 'bin' && asked.arg) {
1023
+ state.binReason = asked.arg
1024
+ confirmBin()
1025
+ }
1026
+ })
1027
+
1028
+ let lastChange = changed.value
1029
+ changed.subscribe((value) => {
1030
+ if (value === lastChange) return
1031
+ lastChange = value
1032
+ reload(true)
1033
+ })
1034
+
1035
+ let lastMode = ''
1036
+ function followMode() {
1037
+ const mode = props.mode === 'bin' ? 'bin' : 'library'
1038
+ if (mode === lastMode) return false
1039
+ lastMode = mode
1040
+ state.binMode = mode === 'bin'
1041
+ return true
1042
+ }
1043
+
1044
+ onUpdate(() => {
1045
+ state.picking = props.pick === true || props.pick === 'true'
1046
+ if (followMode()) {
1047
+ picked = []
1048
+ reload()
1049
+ }
1050
+ })
1051
+
1052
+ let resizer = null
1053
+ let watcher = null
1054
+
1055
+ onMounted(() => {
1056
+ document.addEventListener('load', pictureLoaded, true)
1057
+ document.addEventListener('error', pictureFailed, true)
1058
+ document.addEventListener('keydown', onQuickKey)
1059
+ state.picking = props.pick === true || props.pick === 'true'
1060
+ followMode()
1061
+ readWall(wall.value)
1062
+ lastSentence = JSON.stringify(sentenceCell.value || BLANK)
1063
+
1064
+ const root = refs.root
1065
+ width = root ? Math.floor(root.clientWidth) : 0
1066
+ if (root && typeof ResizeObserver !== 'undefined') {
1067
+ resizer = new ResizeObserver((entries) => {
1068
+ const next = Math.floor(entries[0].contentRect.width)
1069
+ if (!next || next === width) return
1070
+ width = next
1071
+ if (state.fresh) skeleton()
1072
+ else layout()
1073
+ })
1074
+ resizer.observe(root)
1075
+ }
1076
+ if (refs.sentinel && typeof IntersectionObserver !== 'undefined') {
1077
+ watcher = new IntersectionObserver(
1078
+ (entries) => {
1079
+ sentinelSeen = entries[0].isIntersecting
1080
+ if (sentinelSeen) considerMore()
1081
+ },
1082
+ { rootMargin: '600px 0px' },
1083
+ )
1084
+ watcher.observe(refs.sentinel)
1085
+ }
1086
+
1087
+ view.value = activeView() || null
1088
+ fetchPage(false)
1089
+ })
1090
+
1091
+ onUnmounted(() => {
1092
+ document.removeEventListener('load', pictureLoaded, true)
1093
+ document.removeEventListener('error', pictureFailed, true)
1094
+ document.removeEventListener('keydown', onQuickKey)
1095
+ if (resizer) resizer.disconnect()
1096
+ if (watcher) watcher.disconnect()
1097
+ if (inFlight) inFlight.abort()
1098
+ })
1099
+ </logic>
1100
+
1101
+ <style>
1102
+ .wall {
1103
+ display: flex;
1104
+ flex-direction: column;
1105
+ gap: 14px;
1106
+ min-width: 0;
1107
+ }
1108
+
1109
+ .tally {
1110
+ gap: 12px;
1111
+ align-items: baseline;
1112
+ }
1113
+
1114
+ .count {
1115
+ font-size: var(--px-fs-m);
1116
+ }
1117
+
1118
+ .sections {
1119
+ display: flex;
1120
+ flex-direction: column;
1121
+ gap: 6px;
1122
+ }
1123
+
1124
+ .date-h {
1125
+ padding: 14px 0 8px;
1126
+ font-size: var(--px-fs-m);
1127
+ font-weight: 600;
1128
+ display: flex;
1129
+ gap: 10px;
1130
+ align-items: baseline;
1131
+ }
1132
+
1133
+ .section:first-child .date-h {
1134
+ padding-top: 0;
1135
+ }
1136
+
1137
+ .date-n {
1138
+ font-weight: 400;
1139
+ }
1140
+
1141
+ .mx-rows {
1142
+ display: flex;
1143
+ flex-direction: column;
1144
+ gap: 6px;
1145
+ }
1146
+
1147
+ .mx-row {
1148
+ display: flex;
1149
+ gap: 6px;
1150
+ }
1151
+
1152
+ .skel {
1153
+ border-radius: var(--px-r-s);
1154
+ }
1155
+
1156
+ .ph {
1157
+ position: relative;
1158
+ min-width: 0;
1159
+ height: 100%;
1160
+ border: 0;
1161
+ padding: 0;
1162
+ border-radius: var(--px-r-s);
1163
+ overflow: hidden;
1164
+ cursor: pointer;
1165
+ background: var(--px-surface-2);
1166
+ color: inherit;
1167
+ font: inherit;
1168
+ transition: transform .2s ease, box-shadow .2s ease;
1169
+ }
1170
+
1171
+ .ph:hover {
1172
+ transform: translateY(-2px);
1173
+ box-shadow: 0 10px 30px rgba(0, 0, 0, .28);
1174
+ }
1175
+
1176
+ .ph:focus-visible {
1177
+ outline: 3px solid var(--px-focus);
1178
+ outline-offset: 2px;
1179
+ z-index: 1;
1180
+ }
1181
+
1182
+ .pic {
1183
+ position: absolute;
1184
+ inset: 0;
1185
+ width: 100%;
1186
+ height: 100%;
1187
+ object-fit: cover;
1188
+ opacity: 0;
1189
+ transition: opacity .25s ease, transform .15s ease;
1190
+ }
1191
+
1192
+ .pic.is-in {
1193
+ opacity: 1;
1194
+ }
1195
+
1196
+ .failed {
1197
+ position: absolute;
1198
+ inset: 0;
1199
+ display: grid;
1200
+ place-items: center;
1201
+ padding: 8px;
1202
+ font-size: var(--px-fs-xs);
1203
+ color: var(--px-text-2);
1204
+ text-align: center;
1205
+ }
1206
+
1207
+ .ov {
1208
+ position: absolute;
1209
+ inset: auto 0 0 0;
1210
+ padding: 28px 12px 10px;
1211
+ background: linear-gradient(transparent, rgba(0, 0, 0, .62));
1212
+ color: #fff;
1213
+ font-size: var(--px-fs-s);
1214
+ font-weight: 500;
1215
+ text-align: left;
1216
+ white-space: nowrap;
1217
+ overflow: hidden;
1218
+ text-overflow: ellipsis;
1219
+ opacity: 0;
1220
+ transition: opacity .15s;
1221
+ }
1222
+
1223
+ .ph:hover .ov,
1224
+ .ph:focus-visible .ov,
1225
+ .names .ov {
1226
+ opacity: 1;
1227
+ }
1228
+
1229
+ .dot {
1230
+ position: absolute;
1231
+ right: 10px;
1232
+ top: 10px;
1233
+ width: 10px;
1234
+ height: 10px;
1235
+ border-radius: 50%;
1236
+ background: #f2bd57;
1237
+ box-shadow: 0 0 0 2px rgba(0, 0, 0, .45);
1238
+ }
1239
+
1240
+ .flag {
1241
+ position: absolute;
1242
+ left: 8px;
1243
+ bottom: 8px;
1244
+ display: grid;
1245
+ place-items: center;
1246
+ width: 22px;
1247
+ height: 22px;
1248
+ border-radius: 50%;
1249
+ background: #f2bd57;
1250
+ color: #2b1d00;
1251
+ font-size: 13px;
1252
+ font-weight: 700;
1253
+ box-shadow: 0 0 0 2px rgba(0, 0, 0, .35);
1254
+ }
1255
+
1256
+ .flag.is-danger {
1257
+ background: #ff8f86;
1258
+ color: #3b0b07;
1259
+ }
1260
+
1261
+ .names .flag {
1262
+ bottom: 34px;
1263
+ }
1264
+
1265
+ .lock {
1266
+ position: absolute;
1267
+ right: 8px;
1268
+ bottom: 8px;
1269
+ display: grid;
1270
+ place-items: center;
1271
+ width: 22px;
1272
+ height: 22px;
1273
+ border-radius: 50%;
1274
+ background: rgba(0, 0, 0, .5);
1275
+ color: #fff;
1276
+ }
1277
+
1278
+ .ck {
1279
+ position: absolute;
1280
+ left: 8px;
1281
+ top: 8px;
1282
+ width: 28px;
1283
+ height: 28px;
1284
+ border-radius: 50%;
1285
+ border: 2px solid #fff;
1286
+ background: rgba(0, 0, 0, .3);
1287
+ display: grid;
1288
+ place-items: center;
1289
+ color: transparent;
1290
+ opacity: 0;
1291
+ transition: opacity .15s;
1292
+ }
1293
+
1294
+ .ph:hover .ck,
1295
+ .ph:focus-visible .ck,
1296
+ .ph.is-sel .ck {
1297
+ opacity: 1;
1298
+ }
1299
+
1300
+ .ck:hover {
1301
+ background: rgba(0, 0, 0, .55);
1302
+ color: #fff;
1303
+ }
1304
+
1305
+ .ph.is-sel {
1306
+ box-shadow: 0 0 0 3px var(--px-accent);
1307
+ }
1308
+
1309
+ .ph.is-sel .ck {
1310
+ background: var(--px-accent);
1311
+ border-color: var(--px-accent);
1312
+ color: var(--px-on-accent);
1313
+ }
1314
+
1315
+ .ph.is-sel .pic {
1316
+ transform: scale(.94);
1317
+ border-radius: 4px;
1318
+ }
1319
+
1320
+ .ph.is-open {
1321
+ box-shadow: 0 0 0 3px var(--px-text);
1322
+ }
1323
+
1324
+ .picking .ph.is-open {
1325
+ box-shadow: 0 0 0 4px var(--px-accent);
1326
+ }
1327
+
1328
+ .picking .ck {
1329
+ display: none;
1330
+ }
1331
+
1332
+ .ph.is-binned .pic {
1333
+ filter: grayscale(1);
1334
+ }
1335
+
1336
+ .ph.is-binned .pic.is-in {
1337
+ opacity: .5;
1338
+ }
1339
+
1340
+ .scrim {
1341
+ position: fixed;
1342
+ inset: 0;
1343
+ z-index: 30;
1344
+ background: rgba(10, 10, 12, .78);
1345
+ backdrop-filter: blur(6px);
1346
+ display: flex;
1347
+ flex-direction: column;
1348
+ align-items: center;
1349
+ justify-content: center;
1350
+ padding: 32px;
1351
+ }
1352
+
1353
+ .quick {
1354
+ display: flex;
1355
+ flex-direction: column;
1356
+ max-width: min(980px, 100%);
1357
+ max-height: calc(100vh - 120px);
1358
+ border-radius: 16px;
1359
+ overflow: hidden;
1360
+ background: var(--px-surface);
1361
+ box-shadow: 0 40px 120px rgba(0, 0, 0, .55);
1362
+ }
1363
+
1364
+ .quick:focus-visible {
1365
+ outline: none;
1366
+ }
1367
+
1368
+ .quick-pic {
1369
+ display: block;
1370
+ min-height: 0;
1371
+ max-width: 100%;
1372
+ max-height: calc(100vh - 260px);
1373
+ object-fit: contain;
1374
+ background: #111;
1375
+ }
1376
+
1377
+ .quick-meta {
1378
+ display: grid;
1379
+ grid-template-columns: 1fr auto;
1380
+ gap: 8px 24px;
1381
+ padding: 16px 20px;
1382
+ align-items: start;
1383
+ }
1384
+
1385
+ .quick-words {
1386
+ display: flex;
1387
+ flex-direction: column;
1388
+ gap: 6px;
1389
+ min-width: 0;
1390
+ }
1391
+
1392
+ .quick-alt {
1393
+ line-height: 1.5;
1394
+ }
1395
+
1396
+ .quick-hint {
1397
+ display: flex;
1398
+ flex-wrap: wrap;
1399
+ gap: 14px;
1400
+ justify-content: center;
1401
+ margin-top: 14px;
1402
+ color: rgba(255, 255, 255, .75);
1403
+ font-size: 12px;
1404
+ }
1405
+
1406
+ .quick-hint .px-kbd {
1407
+ background: rgba(255, 255, 255, .12);
1408
+ color: #fff;
1409
+ border-color: rgba(255, 255, 255, .25);
1410
+ }
1411
+
1412
+ .more {
1413
+ display: flex;
1414
+ align-items: center;
1415
+ justify-content: center;
1416
+ gap: 12px;
1417
+ padding: 16px 0;
1418
+ }
1419
+
1420
+ .sentinel {
1421
+ display: block;
1422
+ height: 1px;
1423
+ }
1424
+
1425
+ .empty {
1426
+ border: 1px dashed var(--px-border);
1427
+ border-radius: var(--px-r-l);
1428
+ }
1429
+
1430
+ .dock {
1431
+ position: fixed;
1432
+ left: 50%;
1433
+ bottom: 24px;
1434
+ transform: translateX(-50%);
1435
+ z-index: 7;
1436
+ display: flex;
1437
+ align-items: center;
1438
+ gap: 8px;
1439
+ padding: 8px 8px 8px 18px;
1440
+ border-radius: 999px;
1441
+ background: var(--px-text);
1442
+ color: var(--px-bg);
1443
+ box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
1444
+ font-size: 14px;
1445
+ }
1446
+
1447
+ .dock > button {
1448
+ min-height: var(--px-target);
1449
+ min-width: var(--px-target);
1450
+ padding: 0 14px;
1451
+ border-radius: 999px;
1452
+ border: 0;
1453
+ background: transparent;
1454
+ color: inherit;
1455
+ font: inherit;
1456
+ font-weight: 500;
1457
+ cursor: pointer;
1458
+ display: inline-grid;
1459
+ place-items: center;
1460
+ }
1461
+
1462
+ .dock > .pri {
1463
+ background: var(--px-accent);
1464
+ color: var(--px-on-accent);
1465
+ }
1466
+
1467
+ .describe {
1468
+ margin-left: auto;
1469
+ }
1470
+
1471
+ .dock > button:hover:not(.pri),
1472
+ .dock > button[aria-expanded="true"] {
1473
+ background: rgba(127, 127, 127, .3);
1474
+ }
1475
+
1476
+ .dock-pop {
1477
+ position: absolute;
1478
+ left: 50%;
1479
+ bottom: calc(100% + 10px);
1480
+ transform: translateX(-50%);
1481
+ display: flex;
1482
+ align-items: center;
1483
+ gap: 8px;
1484
+ flex-wrap: wrap;
1485
+ width: max-content;
1486
+ max-width: min(92vw, 560px);
1487
+ padding: 12px 14px;
1488
+ border: 1px solid var(--px-border);
1489
+ border-radius: var(--px-r-l);
1490
+ background: var(--px-surface);
1491
+ color: var(--px-text);
1492
+ box-shadow: var(--px-shadow);
1493
+ }
1494
+
1495
+ .dock-label {
1496
+ flex: 1 0 100%;
1497
+ font-size: var(--px-fs-s);
1498
+ font-weight: 600;
1499
+ }
1500
+
1501
+ .dock-pop .px-input,
1502
+ .dock-pop .px-select {
1503
+ flex: 1;
1504
+ min-width: 180px;
1505
+ }
1506
+
1507
+ .text-danger {
1508
+ color: var(--px-danger);
1509
+ }
1510
+
1511
+ .sr-only {
1512
+ position: absolute;
1513
+ width: 1px;
1514
+ height: 1px;
1515
+ overflow: hidden;
1516
+ clip-path: inset(50%);
1517
+ white-space: nowrap;
1518
+ }
1519
+
1520
+ @media (prefers-reduced-motion: reduce) {
1521
+ .ph,
1522
+ .pic,
1523
+ .ov,
1524
+ .ck {
1525
+ transition: none;
1526
+ }
1527
+
1528
+ .ph:hover {
1529
+ transform: none;
1530
+ }
1531
+ }
1532
+ </style>