@pseudolux-ui/media-library 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/checks.ts +132 -0
- package/src/components/CommandBar.lsp +526 -0
- package/src/components/DescribeRun.lsp +527 -0
- package/src/components/GroupCover.lsp +227 -0
- package/src/components/LibraryDesk.lsp +415 -0
- package/src/components/LibraryFrame.lsp +362 -0
- package/src/components/LibraryGroups.lsp +197 -0
- package/src/components/LinkDialog.lsp +436 -0
- package/src/components/PictureEditor.lsp +1813 -0
- package/src/components/PicturePeek.lsp +428 -0
- package/src/components/PictureWall.lsp +1532 -0
- package/src/components/SentenceBar.lsp +361 -0
- package/src/components/UploadBatch.lsp +1083 -0
- package/src/config.ts +74 -5
- package/src/cuts.ts +29 -0
- package/src/index.ts +11 -0
- package/src/rows.ts +142 -0
- package/src/sentence.ts +164 -0
- package/src/styles/px.css +1 -26
- package/src/survey.ts +75 -0
- package/src/components/AssetGrid.lsp +0 -1777
- package/src/components/AssetInspector.lsp +0 -1622
package/src/config.ts
CHANGED
|
@@ -116,13 +116,13 @@ export const SELECTED = "media:selected"
|
|
|
116
116
|
* learning what each action means. */
|
|
117
117
|
export const CHANGED = "media:changed"
|
|
118
118
|
|
|
119
|
-
/** Which group the library is being looked at as, if any: the
|
|
120
|
-
*
|
|
121
|
-
* picture for this view beside the
|
|
119
|
+
/** Which group the library is being looked at as, if any: the group in the
|
|
120
|
+
* sentence, or the tag a host mounted it with. The editor describes the
|
|
121
|
+
* picture for this view beside the shared words. */
|
|
122
122
|
export const VIEW = "media:view"
|
|
123
123
|
|
|
124
|
-
/** The shapes pictures are cut to, as the last page said. The
|
|
125
|
-
* from the page's capabilities; the
|
|
124
|
+
/** The shapes pictures are cut to, as the last page said. The wall fills it
|
|
125
|
+
* from the page's capabilities; the editor and the peek draw crops from it. */
|
|
126
126
|
export const PRESETS = "media:presets"
|
|
127
127
|
|
|
128
128
|
export const CROP_EDITOR = "media:crop-editor"
|
|
@@ -135,3 +135,72 @@ export const BIN_DIALOG = "media:bin-dialog"
|
|
|
135
135
|
export const UPLOAD_TYPES = ["image/jpeg", "image/png", "image/webp", "image/tiff", "image/gif", "image/avif"]
|
|
136
136
|
|
|
137
137
|
export const UPLOAD_LIMIT = 250 * 1024 * 1024
|
|
138
|
+
|
|
139
|
+
/** Which view of the library is showing: "desk", "all", "groups" or "bin". */
|
|
140
|
+
export const TAB = "media:tab"
|
|
141
|
+
|
|
142
|
+
/** The sentence the pictures are read through. See `sentence.ts`. */
|
|
143
|
+
export const SENTENCE = "media:sentence"
|
|
144
|
+
|
|
145
|
+
/** How the wall of pictures is drawn: `{ size: "S" | "M" | "L", names: boolean }`. */
|
|
146
|
+
export const WALL = "media:wall"
|
|
147
|
+
|
|
148
|
+
/** The ids picked on the wall, in the order they were picked. */
|
|
149
|
+
export const PICKED = "media:picked"
|
|
150
|
+
|
|
151
|
+
/** What the last page said this side can do, for the parts around the wall
|
|
152
|
+
* that have no listing of their own. */
|
|
153
|
+
export const CAPABILITIES = "media:capabilities"
|
|
154
|
+
|
|
155
|
+
/** Bumped to ask whoever holds the file input to open it. */
|
|
156
|
+
export const UPLOAD = "media:upload"
|
|
157
|
+
|
|
158
|
+
/** The id of the picture the wall is peeking at, or null. */
|
|
159
|
+
export const PEEK = "media:peek"
|
|
160
|
+
|
|
161
|
+
/** `{ id, patch }`: something changed one picture's record. Whoever holds a
|
|
162
|
+
* listing merges the patch into its copy rather than fetching again. */
|
|
163
|
+
export const PATCHED = "media:patched"
|
|
164
|
+
|
|
165
|
+
/** The pictures the wall is showing, in order, for anything that steps
|
|
166
|
+
* through them: `{ items: [{ id, label, noAlt }] }`. */
|
|
167
|
+
export const SET = "media:set"
|
|
168
|
+
|
|
169
|
+
/** `{ items }`: pictures to describe one after another, or null when no run
|
|
170
|
+
* is on. Each item is a picture as the wall presents it. */
|
|
171
|
+
export const RUN = "media:run"
|
|
172
|
+
|
|
173
|
+
/** The picture a link or file is being made for, as a record, or null. */
|
|
174
|
+
export const LINK = "media:link"
|
|
175
|
+
|
|
176
|
+
/** `{ name, arg?, at }`: something asked of the wall from outside it, such
|
|
177
|
+
* as the command bar: "describe", "label", "bin", "clear" for the picked. */
|
|
178
|
+
export const COMMAND = "media:command"
|
|
179
|
+
|
|
180
|
+
const LETTER_KEYS = "pseudolux:letter-keys"
|
|
181
|
+
|
|
182
|
+
/** Whether single-letter shortcuts are on. They can be turned off, since a
|
|
183
|
+
* stray key press, or speech input, should not move pictures to the bin. */
|
|
184
|
+
export const letterKeys = (): boolean => {
|
|
185
|
+
try {
|
|
186
|
+
return localStorage.getItem(LETTER_KEYS) !== "off"
|
|
187
|
+
} catch {
|
|
188
|
+
return true
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export const setLetterKeys = (on: boolean): void => {
|
|
193
|
+
try {
|
|
194
|
+
localStorage.setItem(LETTER_KEYS, on ? "on" : "off")
|
|
195
|
+
} catch {
|
|
196
|
+
// On for this visit, then.
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Whether the frame shows the bin itself, rather than its host having a
|
|
201
|
+
* Bin page of its own. */
|
|
202
|
+
export const OWN_BIN = "media:own-bin"
|
|
203
|
+
|
|
204
|
+
/** The picture chosen in a picker, as a record, or null. Set by the wall
|
|
205
|
+
* when the frame is mounted with `mode="pick"`; the host reads it. */
|
|
206
|
+
export const CHOSEN = "media:chosen"
|
package/src/cuts.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A crop drawn from a picture that is already on the page: the whole picture
|
|
3
|
+
* as a background, sized and slid so only the rectangle shows. One file
|
|
4
|
+
* serves every crop preview of a picture, where a URL per crop would be a
|
|
5
|
+
* transform each.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { CropRect } from "./port.js"
|
|
9
|
+
|
|
10
|
+
const pct = (value: number): string => String(Math.round(value * 100) / 100)
|
|
11
|
+
|
|
12
|
+
export const cutStyle = (
|
|
13
|
+
rect: CropRect,
|
|
14
|
+
source: { width: number; height: number },
|
|
15
|
+
url: string,
|
|
16
|
+
box: { height: number; maxWidth?: number },
|
|
17
|
+
): string => {
|
|
18
|
+
const ratio = rect.width / rect.height
|
|
19
|
+
const width = Math.min(box.maxWidth ?? Infinity, box.height * ratio)
|
|
20
|
+
const x = source.width > rect.width ? (rect.x / (source.width - rect.width)) * 100 : 0
|
|
21
|
+
const y = source.height > rect.height ? (rect.y / (source.height - rect.height)) * 100 : 0
|
|
22
|
+
return [
|
|
23
|
+
"width: " + pct(width) + "px",
|
|
24
|
+
"height: " + pct(width / ratio) + "px",
|
|
25
|
+
'background-image: url("' + url + '")',
|
|
26
|
+
"background-size: " + pct((source.width / rect.width) * 100) + "% auto",
|
|
27
|
+
"background-position: " + pct(x) + "% " + pct(y) + "%",
|
|
28
|
+
].join(";")
|
|
29
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -31,3 +31,14 @@ export type {
|
|
|
31
31
|
} from "./port.js"
|
|
32
32
|
export { CROP_EDITOR, BIN_DIALOG } from "./config.js"
|
|
33
33
|
export { UPLOAD_TYPES, UPLOAD_LIMIT } from "./config.js"
|
|
34
|
+
export { TAB, SENTENCE, WALL, PICKED, CAPABILITIES, UPLOAD, PEEK, PATCHED, SET, RUN, LINK, COMMAND, CHOSEN } from "./config.js"
|
|
35
|
+
export { cutStyle } from "./cuts.js"
|
|
36
|
+
export { BLANK, parse, fits, isSet, said, words, shapeOf } from "./sentence.js"
|
|
37
|
+
export type { Sentence, Shape, Condition, When } from "./sentence.js"
|
|
38
|
+
export { justify, byDate, aspectOf, place, neighbour, TARGET_HEIGHT } from "./rows.js"
|
|
39
|
+
export type { Row, Section, Size, Move } from "./rows.js"
|
|
40
|
+
export { altChecks, completeness, textOver, flagsOf } from "./checks.js"
|
|
41
|
+
export type { Check, Completeness, Flag } from "./checks.js"
|
|
42
|
+
export { survey, tally, atLeast, forgetSurveys } from "./survey.js"
|
|
43
|
+
export type { Survey, Tally } from "./survey.js"
|
|
44
|
+
export { letterKeys, setLetterKeys } from "./config.js"
|
package/src/rows.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pictures laid out in rows at their own shape: nothing is cropped to fit a
|
|
3
|
+
* tile, so what is in the library is what is on the screen.
|
|
4
|
+
*
|
|
5
|
+
* Worked out from width and height alone, which arrive with the listing, so
|
|
6
|
+
* every row has its place before a single image has loaded.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { startOf } from "./sentence.js"
|
|
10
|
+
|
|
11
|
+
export type Size = "S" | "M" | "L"
|
|
12
|
+
|
|
13
|
+
export const TARGET_HEIGHT: Record<Size, number> = { S: 160, M: 230, L: 320 }
|
|
14
|
+
|
|
15
|
+
export const GAP = 6
|
|
16
|
+
|
|
17
|
+
/** A banner ten times wider than tall would take a row to itself at a sliver
|
|
18
|
+
* of the height, and a tall strip would be a line. Held to shapes a row can
|
|
19
|
+
* carry; the picture is still drawn whole inside its tile. */
|
|
20
|
+
const WIDEST = 3.2
|
|
21
|
+
const NARROWEST = 0.45
|
|
22
|
+
|
|
23
|
+
export const aspectOf = (item: { width?: number; height?: number }): number => {
|
|
24
|
+
if (!item.width || !item.height) return 1.5
|
|
25
|
+
return Math.min(WIDEST, Math.max(NARROWEST, item.width / item.height))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface Row<T> {
|
|
29
|
+
items: T[]
|
|
30
|
+
height: number
|
|
31
|
+
/** The last row keeps the target height rather than stretching to fill. */
|
|
32
|
+
last: boolean
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Pictures are added to a row until it would be at least as wide as the
|
|
37
|
+
* space at the target height, then the row is scaled to fit exactly.
|
|
38
|
+
*/
|
|
39
|
+
export const justify = <T extends { aspect: number }>(items: T[], width: number, target: number, gap = GAP): Row<T>[] => {
|
|
40
|
+
const rows: Row<T>[] = []
|
|
41
|
+
if (width <= 0) return rows
|
|
42
|
+
let current: T[] = []
|
|
43
|
+
let sum = 0
|
|
44
|
+
for (const item of items) {
|
|
45
|
+
current.push(item)
|
|
46
|
+
sum += item.aspect
|
|
47
|
+
const gaps = gap * (current.length - 1)
|
|
48
|
+
if (sum * target + gaps >= width) {
|
|
49
|
+
rows.push({ items: current, height: Math.round((width - gaps) / sum), last: false })
|
|
50
|
+
current = []
|
|
51
|
+
sum = 0
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (current.length) {
|
|
55
|
+
const gaps = gap * (current.length - 1)
|
|
56
|
+
// A last row wider than the space (one very wide picture on a narrow
|
|
57
|
+
// screen) is scaled down like any other.
|
|
58
|
+
const height = Math.min(target, Math.round((width - gaps) / sum))
|
|
59
|
+
rows.push({ items: current, height, last: true })
|
|
60
|
+
}
|
|
61
|
+
return rows
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface Section<T> {
|
|
65
|
+
key: string
|
|
66
|
+
label: string
|
|
67
|
+
items: T[]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Pictures under the time they were added: this week, earlier this month,
|
|
72
|
+
* earlier this year, then a heading per year. The order given is kept, so a
|
|
73
|
+
* listing that is newest first reads top to bottom.
|
|
74
|
+
*/
|
|
75
|
+
export const byDate = <T extends { createdAt?: string }>(items: T[], now: Date): Section<T>[] => {
|
|
76
|
+
const week = startOf("week", now)
|
|
77
|
+
const month = startOf("month", now)
|
|
78
|
+
const year = startOf("year", now)
|
|
79
|
+
const sections = new Map<string, Section<T>>()
|
|
80
|
+
for (const item of items) {
|
|
81
|
+
const added = item.createdAt ? Date.parse(item.createdAt) : NaN
|
|
82
|
+
const [key, label] = Number.isNaN(added)
|
|
83
|
+
? ["undated", "No date"]
|
|
84
|
+
: added >= week
|
|
85
|
+
? ["week", "This week"]
|
|
86
|
+
: added >= month
|
|
87
|
+
? ["month", "Earlier this month"]
|
|
88
|
+
: added >= year
|
|
89
|
+
? ["year", "Earlier this year"]
|
|
90
|
+
: [String(new Date(added).getFullYear()), String(new Date(added).getFullYear())]
|
|
91
|
+
const section = sections.get(key) ?? { key, label, items: [] }
|
|
92
|
+
section.items.push(item)
|
|
93
|
+
sections.set(key, section)
|
|
94
|
+
}
|
|
95
|
+
return [...sections.values()]
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface Placed {
|
|
99
|
+
id: string
|
|
100
|
+
row: number
|
|
101
|
+
/** The horizontal middle of the tile, in pixels from the left. */
|
|
102
|
+
middle: number
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Where each tile sits, over every row on the page in order. */
|
|
106
|
+
export const place = <T extends { id: string; aspect: number }>(rows: Row<T>[], gap = GAP): Placed[] => {
|
|
107
|
+
const placed: Placed[] = []
|
|
108
|
+
rows.forEach((row, index) => {
|
|
109
|
+
let x = 0
|
|
110
|
+
for (const item of row.items) {
|
|
111
|
+
const width = item.aspect * row.height
|
|
112
|
+
placed.push({ id: item.id, row: index, middle: x + width / 2 })
|
|
113
|
+
x += width + gap
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
return placed
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export type Move = "left" | "right" | "up" | "down" | "home" | "end"
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The tile an arrow key lands on. Left and right follow reading order across
|
|
123
|
+
* rows; up and down go to whichever tile in the next row sits most nearly
|
|
124
|
+
* above or below, since rows do not share columns.
|
|
125
|
+
*/
|
|
126
|
+
export const neighbour = (placed: Placed[], id: string, move: Move): string => {
|
|
127
|
+
const at = placed.findIndex((one) => one.id === id)
|
|
128
|
+
const first = placed[0]
|
|
129
|
+
const from = placed[at]
|
|
130
|
+
if (!first) return ""
|
|
131
|
+
if (!from) return first.id
|
|
132
|
+
const idAt = (index: number): string => placed[Math.max(0, Math.min(placed.length - 1, index))]?.id ?? id
|
|
133
|
+
if (move === "home") return first.id
|
|
134
|
+
if (move === "end") return idAt(placed.length - 1)
|
|
135
|
+
if (move === "left") return idAt(at - 1)
|
|
136
|
+
if (move === "right") return idAt(at + 1)
|
|
137
|
+
|
|
138
|
+
const target = from.row + (move === "down" ? 1 : -1)
|
|
139
|
+
const candidates = placed.filter((one) => one.row === target)
|
|
140
|
+
if (!candidates.length) return id
|
|
141
|
+
return candidates.reduce((best, one) => (Math.abs(one.middle - from.middle) < Math.abs(best.middle - from.middle) ? one : best)).id
|
|
142
|
+
}
|
package/src/sentence.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sentence the library is read through: "Portrait pictures of the dome in
|
|
3
|
+
* Events that need words, added this month." Each part is one narrowing, and
|
|
4
|
+
* a part left alone reads as "any".
|
|
5
|
+
*
|
|
6
|
+
* Kept apart from the component that draws it so typed text, the option rows
|
|
7
|
+
* and the rows of pictures all agree on what a sentence means.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type Shape = "" | "landscape" | "portrait" | "square"
|
|
11
|
+
export type Condition = "" | "needs" | "unused" | "used" | "flagged"
|
|
12
|
+
export type When = "" | "week" | "month" | "year"
|
|
13
|
+
|
|
14
|
+
export interface Sentence {
|
|
15
|
+
shape: Shape
|
|
16
|
+
/** Free text: names, alt text, labels. */
|
|
17
|
+
about: string
|
|
18
|
+
/** One group, or "" for any the person can see. */
|
|
19
|
+
group: string
|
|
20
|
+
condition: Condition
|
|
21
|
+
when: When
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const BLANK: Sentence = { shape: "", about: "", group: "", condition: "", when: "" }
|
|
25
|
+
|
|
26
|
+
export const SHAPES: Array<[Shape, string]> = [
|
|
27
|
+
["", "Any shape"],
|
|
28
|
+
["landscape", "Landscape"],
|
|
29
|
+
["portrait", "Portrait"],
|
|
30
|
+
["square", "Square"],
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
export const CONDITIONS: Array<[Condition, string]> = [
|
|
34
|
+
["", "are in any state"],
|
|
35
|
+
["needs", "need words"],
|
|
36
|
+
["unused", "aren't used anywhere"],
|
|
37
|
+
["used", "are used on pages"],
|
|
38
|
+
["flagged", "have quality flags"],
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
export const WHENS: Array<[When, string]> = [
|
|
42
|
+
["", "any time"],
|
|
43
|
+
["week", "this week"],
|
|
44
|
+
["month", "this month"],
|
|
45
|
+
["year", "this year"],
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
export const isSet = (sentence: Sentence): boolean =>
|
|
49
|
+
Boolean(sentence.shape || sentence.about || sentence.group || sentence.condition || sentence.when)
|
|
50
|
+
|
|
51
|
+
export const sameSentence = (a: Sentence, b: Sentence): boolean =>
|
|
52
|
+
a.shape === b.shape && a.about === b.about && a.group === b.group && a.condition === b.condition && a.when === b.when
|
|
53
|
+
|
|
54
|
+
/** A picture within 5% of square is square: nobody calls 1000 × 1010 a portrait. */
|
|
55
|
+
export const shapeOf = (width: number | undefined, height: number | undefined): Shape => {
|
|
56
|
+
if (!width || !height) return ""
|
|
57
|
+
const aspect = width / height
|
|
58
|
+
return aspect > 1.05 ? "landscape" : aspect < 0.95 ? "portrait" : "square"
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** When "this week", "this month" or "this year" began, local time. Weeks start on Monday. */
|
|
62
|
+
export const startOf = (when: When, now: Date): number => {
|
|
63
|
+
if (when === "year") return new Date(now.getFullYear(), 0, 1).getTime()
|
|
64
|
+
if (when === "month") return new Date(now.getFullYear(), now.getMonth(), 1).getTime()
|
|
65
|
+
if (when === "week") {
|
|
66
|
+
const sinceMonday = (now.getDay() + 6) % 7
|
|
67
|
+
return new Date(now.getFullYear(), now.getMonth(), now.getDate() - sinceMonday).getTime()
|
|
68
|
+
}
|
|
69
|
+
return 0
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const FILLER = /\b(pictures?|photos?|images?|of|in|from|that|the|added|with|and|show|me|all|are|is)\b/g
|
|
73
|
+
|
|
74
|
+
const escaped = (text: string): string => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* What somebody typed, as a sentence: "portraits in events without alt text"
|
|
78
|
+
* sets three parts, and whatever is left over is what the pictures are of.
|
|
79
|
+
* `usage` says whether "unused" means anything here; where it does not, the
|
|
80
|
+
* word stays in the search.
|
|
81
|
+
*/
|
|
82
|
+
export const parse = (text: string, options: { groups?: string[]; usage?: boolean } = {}): Sentence => {
|
|
83
|
+
let rest = " " + text.toLowerCase() + " "
|
|
84
|
+
const out: Sentence = { ...BLANK }
|
|
85
|
+
const take = (pattern: RegExp, found: (match: RegExpMatchArray) => void) => {
|
|
86
|
+
const match = rest.match(pattern)
|
|
87
|
+
if (!match) return
|
|
88
|
+
found(match)
|
|
89
|
+
rest = rest.replace(pattern, " ")
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Longest first, so "events archive" is not read as "events".
|
|
93
|
+
const groups = (options.groups ?? []).slice().sort((a, b) => b.length - a.length)
|
|
94
|
+
for (const group of groups) {
|
|
95
|
+
if (out.group) break
|
|
96
|
+
take(new RegExp("(?<![\\w-])" + escaped(group.toLowerCase()) + "(?![\\w-])"), () => (out.group = group))
|
|
97
|
+
}
|
|
98
|
+
take(/\bportraits?\b/, () => (out.shape = "portrait"))
|
|
99
|
+
take(/\blandscapes?\b/, () => (out.shape = "landscape"))
|
|
100
|
+
take(/\bsquares?\b/, () => (out.shape = "square"))
|
|
101
|
+
take(/\b(without|no|missing) alt( text)?\b|\bneeds? words\b|\bneeds? alt( text)?\b|\bundescribed\b/, () => (out.condition = "needs"))
|
|
102
|
+
if (options.usage) {
|
|
103
|
+
take(/\b(unused|not used( anywhere)?)\b/, () => (out.condition = "unused"))
|
|
104
|
+
}
|
|
105
|
+
take(/\b(too small|low quality|quality flags?|flagged)\b/, () => (out.condition = "flagged"))
|
|
106
|
+
take(/\bthis (week|month|year)\b/, (match) => (out.when = (match[1] ?? "") as When))
|
|
107
|
+
out.about = rest.replace(FILLER, " ").replace(/\s+/g, " ").trim()
|
|
108
|
+
return out
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface Judged {
|
|
112
|
+
width?: number
|
|
113
|
+
height?: number
|
|
114
|
+
createdAt?: string
|
|
115
|
+
/** The alt text as the current view reads it. */
|
|
116
|
+
altText?: string
|
|
117
|
+
filename?: string
|
|
118
|
+
id?: string
|
|
119
|
+
/** Whether its file has a quality flag. */
|
|
120
|
+
flagged?: boolean
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Whether a picture fits the parts a listing cannot answer for itself: its
|
|
125
|
+
* shape, whether it has words, and when it was added. The group and the free
|
|
126
|
+
* text are asked of the store; `aboutHere` judges the text on the name
|
|
127
|
+
* instead, for a store that cannot search.
|
|
128
|
+
*/
|
|
129
|
+
export const fits = (item: Judged, sentence: Sentence, now: Date, aboutHere = false): boolean => {
|
|
130
|
+
if (sentence.shape && shapeOf(item.width, item.height) !== sentence.shape) return false
|
|
131
|
+
if (sentence.condition === "needs" && item.altText) return false
|
|
132
|
+
if (sentence.condition === "flagged" && !item.flagged) return false
|
|
133
|
+
if (sentence.when) {
|
|
134
|
+
const added = item.createdAt ? Date.parse(item.createdAt) : NaN
|
|
135
|
+
if (!(added >= startOf(sentence.when, now))) return false
|
|
136
|
+
}
|
|
137
|
+
if (aboutHere && sentence.about) {
|
|
138
|
+
const name = (item.filename || item.id || "").toLowerCase()
|
|
139
|
+
if (!sentence.about.split(" ").every((word) => name.includes(word))) return false
|
|
140
|
+
}
|
|
141
|
+
return true
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Whether any part is judged on the pictures already loaded. */
|
|
145
|
+
export const judgedHere = (sentence: Sentence, aboutHere = false): boolean =>
|
|
146
|
+
Boolean(sentence.shape || sentence.condition === "needs" || sentence.condition === "flagged" || sentence.when || (aboutHere && sentence.about))
|
|
147
|
+
|
|
148
|
+
const labelOf = <T extends string>(options: Array<[T, string]>, value: T): string =>
|
|
149
|
+
options.find(([key]) => key === value)?.[1] ?? options[0]?.[1] ?? ""
|
|
150
|
+
|
|
151
|
+
/** Each part as the words on its button. */
|
|
152
|
+
export const words = (sentence: Sentence): Record<"shape" | "about" | "group" | "condition" | "when", string> => ({
|
|
153
|
+
shape: labelOf(SHAPES, sentence.shape),
|
|
154
|
+
about: sentence.about ? "“" + sentence.about + "”" : "anything",
|
|
155
|
+
group: sentence.group || "any group",
|
|
156
|
+
condition: labelOf(CONDITIONS, sentence.condition),
|
|
157
|
+
when: labelOf(WHENS, sentence.when),
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
/** The whole sentence as text, for a screen reader and a saved name. */
|
|
161
|
+
export const said = (sentence: Sentence): string => {
|
|
162
|
+
const part = words(sentence)
|
|
163
|
+
return `${part.shape} pictures of ${part.about} in ${part.group} that ${part.condition}, added ${part.when}.`
|
|
164
|
+
}
|
package/src/styles/px.css
CHANGED
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
|
|
10
10
|
.px {
|
|
11
11
|
--px-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
12
|
+
--px-font-sentence: "Source Serif 4", Georgia, "Times New Roman", serif;
|
|
12
13
|
--px-fs-xs: 12px; --px-fs-s: 13px; --px-fs-m: 15px; --px-fs-l: 17px; --px-fs-h: 22px;
|
|
13
14
|
--px-sp: 4px;
|
|
14
15
|
--px-r-s: 6px; --px-r-m: 8px; --px-r-l: 12px;
|
|
15
16
|
--px-target: 44px;
|
|
16
|
-
--px-tile: 184px;
|
|
17
17
|
|
|
18
18
|
--px-bg: #f4f4f4;
|
|
19
19
|
--px-surface: #ffffff;
|
|
@@ -113,47 +113,23 @@
|
|
|
113
113
|
.px-pic { background: linear-gradient(135deg, #b8bcc4, #8f96a3); position: relative; overflow: hidden; }
|
|
114
114
|
|
|
115
115
|
/* Grid and tiles */
|
|
116
|
-
.px-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--px-tile), 1fr)); gap: 12px; }
|
|
117
|
-
.px-tile { position: relative; display: flex; flex-direction: column; padding: 0; border: 1px solid var(--px-border); border-radius: var(--px-r-l); background: var(--px-surface); overflow: hidden; text-align: left; font: inherit; color: inherit; cursor: pointer; }
|
|
118
|
-
.px-tile .px-pic { aspect-ratio: 4 / 3; }
|
|
119
|
-
.px-tile-name { display: block; padding: 7px 10px 8px; font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
120
|
-
.px-tile-flags { position: absolute; left: 8px; bottom: 38px; display: flex; gap: 4px; flex-wrap: wrap; }
|
|
121
|
-
.px-tile-check { position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border-radius: 50%; background: var(--px-accent); color: var(--px-on-accent); display: grid; place-items: center; box-shadow: 0 0 0 2px var(--px-surface); }
|
|
122
|
-
.px-tile.is-selected { border: 3px solid var(--px-accent); }
|
|
123
|
-
.px-tile.is-binned .px-pic { opacity: .45; filter: grayscale(1); }
|
|
124
|
-
.px-tile.is-processing .px-pic { background: var(--px-surface-2); display: grid; place-items: center; color: var(--px-text-3); font-size: 12px; }
|
|
125
116
|
|
|
126
117
|
/* Dense list view */
|
|
127
|
-
.px-list-row { display: grid; grid-template-columns: 64px minmax(0, 1.3fr) minmax(0, 2fr) 140px 120px; gap: 14px; align-items: center; padding: 8px 12px; min-height: 60px; border-bottom: 1px solid var(--px-border); }
|
|
128
|
-
.px-list-head { min-height: 40px; font-size: var(--px-fs-xs); font-weight: 600; color: var(--px-text-3); text-transform: uppercase; letter-spacing: .05em; background: var(--px-surface-2); }
|
|
129
118
|
|
|
130
119
|
/* Layout parts */
|
|
131
|
-
.px-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
|
|
132
120
|
.px-seg { display: inline-flex; padding: 3px; border: 1px solid var(--px-border); border-radius: var(--px-r-m); background: var(--px-surface-2); }
|
|
133
121
|
.px-seg button { min-height: 36px; padding: 0 12px; border: 0; border-radius: calc(var(--px-r-m) - 2px); background: transparent; font: inherit; font-size: var(--px-fs-s); color: var(--px-text-2); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
|
|
134
122
|
.px-seg button[aria-pressed="true"], .px-seg button[aria-checked="true"] { background: var(--px-surface); color: var(--px-text); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 600; }
|
|
135
123
|
|
|
136
|
-
.px-inspector { background: var(--px-surface); border-left: 1px solid var(--px-border); display: flex; flex-direction: column; min-width: 0; }
|
|
137
|
-
.px-insp-head { padding: 14px 16px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--px-border); }
|
|
138
|
-
.px-sec { padding: 16px; border-bottom: 1px solid var(--px-border); display: flex; flex-direction: column; gap: 10px; }
|
|
139
|
-
.px-sec:last-child { border-bottom: 0; }
|
|
140
|
-
.px-sec-title { display: flex; align-items: center; gap: 8px; }
|
|
141
|
-
.px-sec-title h4 { flex: 1; }
|
|
142
124
|
|
|
143
|
-
.px-shared { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: var(--px-r-m); background: var(--px-surface-2); font-size: var(--px-fs-xs); color: var(--px-text-2); }
|
|
144
|
-
.px-shared.is-local { background: var(--px-warn-soft); color: var(--px-warn); }
|
|
145
125
|
|
|
146
126
|
.px-focal { position: absolute; width: 28px; height: 28px; margin: -14px 0 0 -14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 2px rgba(0,0,0,.55); display: grid; place-items: center; }
|
|
147
127
|
.px-focal::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.55); }
|
|
148
128
|
|
|
149
|
-
.px-crops { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
|
|
150
129
|
.px-crop { flex: none; display: flex; flex-direction: column; gap: 4px; padding: 0; border: 0; background: transparent; font: inherit; color: inherit; text-align: left; cursor: pointer; }
|
|
151
130
|
.px-crop .px-pic { border-radius: var(--px-r-s); border: 1px solid var(--px-border); }
|
|
152
131
|
.px-crop.is-current .px-pic { outline: 3px solid var(--px-accent); outline-offset: 1px; }
|
|
153
|
-
.px-crop-name { font-size: 11px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
|
|
154
132
|
|
|
155
|
-
.px-swatches { display: flex; gap: 6px; }
|
|
156
|
-
.px-swatches span { width: 32px; height: 32px; border-radius: var(--px-r-s); border: 1px solid var(--px-border); }
|
|
157
133
|
|
|
158
134
|
.px-skel { background: linear-gradient(90deg, var(--px-surface-2), var(--px-hover), var(--px-surface-2)); border-radius: var(--px-r-s); }
|
|
159
135
|
.px-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; padding: 32px; }
|
|
@@ -166,7 +142,6 @@
|
|
|
166
142
|
.px-callout-danger { background: var(--px-danger-soft); border-color: var(--px-danger); }
|
|
167
143
|
.px-callout-accent { background: var(--px-accent-soft); border-color: var(--px-accent); }
|
|
168
144
|
|
|
169
|
-
.px-queue-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--px-border); min-height: 56px; font-size: 14px; }
|
|
170
145
|
.px-bar { height: 6px; border-radius: 3px; background: var(--px-surface-2); overflow: hidden; }
|
|
171
146
|
.px-bar > span { display: block; height: 100%; background: var(--px-accent); }
|
|
172
147
|
|
package/src/survey.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A look over the newest pictures in a group, for the parts of the library
|
|
3
|
+
* that count things: the desk and the group cards.
|
|
4
|
+
*
|
|
5
|
+
* A listing gives no totals, so a count is only ever of what was read. Each
|
|
6
|
+
* survey says whether it reached the end, and whoever shows a number says
|
|
7
|
+
* "at least" when it did not.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { LibraryItem, LibraryPort } from "./port.js"
|
|
11
|
+
import { describedFor } from "./config.js"
|
|
12
|
+
import { startOf } from "./sentence.js"
|
|
13
|
+
|
|
14
|
+
export interface Survey {
|
|
15
|
+
group: string
|
|
16
|
+
items: LibraryItem[]
|
|
17
|
+
/** Whether every picture in the group was read. */
|
|
18
|
+
complete: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface Tally {
|
|
22
|
+
count: number
|
|
23
|
+
complete: boolean
|
|
24
|
+
/** Pictures with no alt text as the group reads them. */
|
|
25
|
+
needs: LibraryItem[]
|
|
26
|
+
week: LibraryItem[]
|
|
27
|
+
month: LibraryItem[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const PAGE = 100
|
|
31
|
+
const PAGES = 3
|
|
32
|
+
const FRESH_FOR = 60_000
|
|
33
|
+
|
|
34
|
+
const cache = new Map<string, { at: number; survey: Promise<Survey> }>()
|
|
35
|
+
|
|
36
|
+
/** The newest pictures in a group, up to a few hundred. Kept for a minute so
|
|
37
|
+
* the desk and the group cards ask once between them. */
|
|
38
|
+
export const survey = (port: LibraryPort, group: string, pages = PAGES): Promise<Survey> => {
|
|
39
|
+
const key = group + ":" + pages
|
|
40
|
+
const kept = cache.get(key)
|
|
41
|
+
if (kept && Date.now() - kept.at < FRESH_FOR) return kept.survey
|
|
42
|
+
const asked = (async (): Promise<Survey> => {
|
|
43
|
+
const items: LibraryItem[] = []
|
|
44
|
+
let cursor: string | undefined
|
|
45
|
+
for (let page = 0; page < pages; page++) {
|
|
46
|
+
const answer = await port.list({ limit: PAGE, ...(group ? { group } : {}), ...(cursor ? { cursor } : {}) })
|
|
47
|
+
items.push(...answer.items)
|
|
48
|
+
cursor = answer.nextCursor
|
|
49
|
+
if (!cursor) break
|
|
50
|
+
}
|
|
51
|
+
return { group, items, complete: !cursor }
|
|
52
|
+
})()
|
|
53
|
+
cache.set(key, { at: Date.now(), survey: asked })
|
|
54
|
+
asked.catch(() => cache.delete(key))
|
|
55
|
+
return asked
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Something changed the library: the next survey reads it again. */
|
|
59
|
+
export const forgetSurveys = (): void => cache.clear()
|
|
60
|
+
|
|
61
|
+
export const tally = (found: Survey, now: Date): Tally => {
|
|
62
|
+
const week = startOf("week", now)
|
|
63
|
+
const month = startOf("month", now)
|
|
64
|
+
const added = (item: LibraryItem): number => (item.createdAt ? Date.parse(item.createdAt) : NaN)
|
|
65
|
+
return {
|
|
66
|
+
count: found.items.length,
|
|
67
|
+
complete: found.complete,
|
|
68
|
+
needs: found.items.filter((item) => !describedFor(item, found.group || undefined).altText),
|
|
69
|
+
week: found.items.filter((item) => added(item) >= week),
|
|
70
|
+
month: found.items.filter((item) => added(item) >= month),
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** "12", or "at least 12" when there may be more than were read. */
|
|
75
|
+
export const atLeast = (n: number, complete: boolean): string => (complete ? String(n) : "at least " + n)
|