@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.
package/src/config.ts ADDED
@@ -0,0 +1,206 @@
1
+ /** What the library's components talk to.
2
+ *
3
+ * Injected by the host rather than built here. The same components run in the
4
+ * standalone browser app and embedded in a CMS, and those two disagree about
5
+ * everything that would go into constructing a client: which distribution,
6
+ * whether requests carry a session, and who is allowed to see what. A package
7
+ * that read an environment variable would be right in exactly one of them.
8
+ */
9
+
10
+ import type { LibraryPort } from "./port.js"
11
+
12
+ /** The alt text and credit as one group sees them. The same merge Pseudolux
13
+ * and its client make; written here so a component needs only this package. */
14
+ export const describedFor = (
15
+ item: { altText?: string; credit?: string; views?: Record<string, { altText?: string; credit?: string }> },
16
+ view: string | undefined
17
+ ): { altText?: string; credit?: string } => {
18
+ const override = view ? item.views?.[view.trim().toLowerCase()] : undefined
19
+ return {
20
+ ...(item.altText !== undefined ? { altText: item.altText } : {}),
21
+ ...(item.credit !== undefined ? { credit: item.credit } : {}),
22
+ ...override,
23
+ }
24
+ }
25
+
26
+ let port: LibraryPort | null = null
27
+ let writable = false
28
+ let writeGroup: string | undefined
29
+ let writeGroups: string[] | undefined
30
+ let hostView: string | undefined
31
+
32
+ export const configure = (
33
+ instance: LibraryPort,
34
+ options: { canWrite?: boolean; writeGroup?: string; writeGroups?: string[]; view?: string } = {}
35
+ ): void => {
36
+ port = instance
37
+ /** Declared by the host, because only the host knows. A browser client with
38
+ * no write endpoint cannot describe anything; a CMS knows whether *this
39
+ * account* may. Either way the form should say so rather than finding out
40
+ * on the save button. */
41
+ writable = options.canWrite ?? false
42
+ /** The one group this side may describe a view for. Unset with `canWrite`
43
+ * means any, which is what a direct build signing as itself gets. */
44
+ writeGroup = options.writeGroup
45
+ /** Every group this side may change pictures on, where it may write to
46
+ * more than one. */
47
+ writeGroups = options.writeGroups
48
+ /** The group the library is looked at as when none is chosen: a CMS
49
+ * mounts it as its own, so pictures are worded for where they will be
50
+ * used. Choosing a group in the grid looks at that one instead. */
51
+ hostView = options.view
52
+ }
53
+
54
+ /**
55
+ * Why this side may not change a picture, or `""` when it may. With a write
56
+ * group declared, only pictures in that group can be changed here; the rest
57
+ * are there to be used.
58
+ */
59
+ export const cannotChange = (tags: string[] | undefined): string => {
60
+ if (!writable) return "Read-only — no write endpoint configured"
61
+ const groups = writeGroups ?? (writeGroup !== undefined ? [writeGroup] : undefined)
62
+ if (groups !== undefined && !(tags ?? []).some((tag) => groups.includes(tag))) {
63
+ return `Read-only here — it can be used, but it is not in ${groups.join(" or ")}`
64
+ }
65
+ return ""
66
+ }
67
+
68
+ /** The host's own view, if it declared one. */
69
+ export const defaultView = (): string | undefined => hostView
70
+
71
+ /** Whether this side may say what a picture means in `view`. */
72
+ export const canDescribeView = (view: string | undefined): boolean =>
73
+ Boolean(view) && writable && (writeGroup === undefined || writeGroup === view)
74
+
75
+ export const getLibrary = (): LibraryPort => {
76
+ if (!port) {
77
+ /** A clear failure at the first request beats a component that silently
78
+ * renders nothing, which is indistinguishable from an empty library. */
79
+ throw new Error(
80
+ "@pseudolux-ui/media-library is not configured. Call configure(port) " +
81
+ "before mounting its components."
82
+ )
83
+ }
84
+ return port
85
+ }
86
+
87
+ export const canWrite = (): boolean => writable
88
+
89
+ /** How large a thumbnail to request.
90
+ *
91
+ * A fixed size rather than the grid's rendered size: every distinct width is
92
+ * its own CDN entry and its own transform, so a handful of sizes shared by
93
+ * everybody beats a size per viewport. */
94
+ export const THUMBNAIL_WIDTH = 400
95
+
96
+ export const thumbnailUrl = (id: string): string =>
97
+ getLibrary().imageUrl(id, { width: THUMBNAIL_WIDTH, format: "webp" })
98
+
99
+ /** Large enough to judge a picture by, small enough not to send a 5000px
100
+ * original to a side panel. */
101
+ export const PREVIEW_WIDTH = 1000
102
+
103
+ export const previewUrl = (id: string): string =>
104
+ getLibrary().imageUrl(id, { width: PREVIEW_WIDTH, format: "webp" })
105
+
106
+ /** Which asset the library is looking at, if any.
107
+ *
108
+ * A cell rather than a prop: the grid opens the panel and the panel closes
109
+ * itself, and neither owns the other. It is also the seam a picker needs -
110
+ * choosing an asset is reading this, wherever the components are mounted.
111
+ */
112
+ export const SELECTED = "media:selected"
113
+
114
+ /** Bumped when something changed the library behind the grid's back: an asset
115
+ * binned or restored from the panel. The grid reloads on it rather than
116
+ * learning what each action means. */
117
+ export const CHANGED = "media:changed"
118
+
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
+ export const VIEW = "media:view"
123
+
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
+ export const PRESETS = "media:presets"
127
+
128
+ export const CROP_EDITOR = "media:crop-editor"
129
+
130
+ export const BIN_DIALOG = "media:bin-dialog"
131
+
132
+ /** What an upload may be when the host does not say: the types and size both
133
+ * hosts' servers accept today. A page's `uploadTypes` and `uploadLimit`
134
+ * capabilities replace them. */
135
+ export const UPLOAD_TYPES = ["image/jpeg", "image/png", "image/webp", "image/tiff", "image/gif", "image/avif"]
136
+
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 ADDED
@@ -0,0 +1,44 @@
1
+ export {
2
+ configure,
3
+ cannotChange,
4
+ defaultView,
5
+ describedFor,
6
+ getLibrary,
7
+ canWrite,
8
+ canDescribeView,
9
+ thumbnailUrl,
10
+ previewUrl,
11
+ THUMBNAIL_WIDTH,
12
+ PREVIEW_WIDTH,
13
+ SELECTED,
14
+ CHANGED,
15
+ VIEW,
16
+ PRESETS,
17
+ } from "./config.js"
18
+ export { snapWidth, pixelsFor, MAX_DPR, WIDTH_LADDER } from "./ladder.js"
19
+ export type {
20
+ LibraryPort,
21
+ LibraryPage,
22
+ LibraryItem,
23
+ LibraryQuery,
24
+ LibraryCapabilities,
25
+ EnrichResult,
26
+ CropRect,
27
+ Preset,
28
+ LibraryUsage,
29
+ UploadOutcome,
30
+ Swatch,
31
+ } from "./port.js"
32
+ export { CROP_EDITOR, BIN_DIALOG } from "./config.js"
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/ladder.ts ADDED
@@ -0,0 +1,82 @@
1
+ /** The widths a component is willing to ask for.
2
+ *
3
+ * Here rather than in the client package, because the components deliberately
4
+ * depend on nothing: the same grid runs against a CMS that has its own way of
5
+ * addressing images, and the rung is what *this component* decides to ask
6
+ * for - not something the Pseudolux URL grammar knows about. */
7
+
8
+ /**
9
+ * Every distinct width is its own CDN entry and its own transform.
10
+ *
11
+ * A component that measures its container and asks for exactly that many
12
+ * pixels generates unbounded addresses - 387, 412, 1043 - and none of them is
13
+ * ever a cache hit for the next visitor.
14
+ *
15
+ * Steps of about 15%. The obvious worry is that more rungs mean a more
16
+ * fragmented cache, and it is mostly unfounded: **the ladder bounds the worst
17
+ * case, but what an asset actually accumulates is set by how many distinct box
18
+ * widths the site's layout produces.** Three layouts at two pixel ratios is
19
+ * six addresses whether this list has thirteen rungs or twenty-four. Fine
20
+ * rungs only cost anything on a genuinely fluid layout, which is the case
21
+ * where they are also saving the most.
22
+ *
23
+ * 500, 1000 and 2000 are checkpoint sizes, so those transforms read a small
24
+ * stored copy instead of decoding the original.
25
+ */
26
+ export const WIDTH_LADDER = [
27
+ 320, 370, 430, 500, 575, 660, 760, 875, 1000, 1150, 1320, 1520, 1750, 2000,
28
+ 2300, 2650, 3050, 3500, 4000,
29
+ ] as const
30
+
31
+ /**
32
+ * How much a picture may be stretched to save a whole rung.
33
+ *
34
+ * Rounding *up* is the safe direction and it is what costs the bytes: a box
35
+ * one pixel above a rung takes the next one and throws away a quarter of the
36
+ * file. Three per cent of upscaling on a photograph is not visible - the
37
+ * screen is usually downsampling anyway - and it saves the entire step.
38
+ *
39
+ * This one number takes the average waste from 18% to 8%. Raising it further
40
+ * keeps paying, but 5% starts to show on hard edges and text in an image.
41
+ */
42
+ const TOLERANCE = 0.03
43
+
44
+ /**
45
+ * The most device pixels we will ask for per CSS pixel.
46
+ *
47
+ * A 3× screen wants 2.25 times the pixels of a 2× one for a difference almost
48
+ * nobody can resolve on a photograph, and it is the single largest saving
49
+ * available here - larger than anything the ladder does. Capped rather than
50
+ * honoured, deliberately: this is a judgement about what a reader can see, not
51
+ * about arithmetic.
52
+ */
53
+ export const MAX_DPR = 2
54
+
55
+ /**
56
+ * The rung to ask for, given a measured CSS width and a device pixel ratio.
57
+ *
58
+ * The one entry point, so the cap and the tolerance cannot be applied in one
59
+ * component and forgotten in another.
60
+ */
61
+ export const pixelsFor = (cssWidth: number, dpr: number): number =>
62
+ snapWidth(Math.round(cssWidth * Math.min(dpr || 1, MAX_DPR)))
63
+
64
+ /**
65
+ * The rung that best covers `wanted`.
66
+ *
67
+ * Rounds up, except when the rung below is within {@link TOLERANCE} - see
68
+ * there for why that exception is the whole point. Past the top rung it
69
+ * returns the top rung: beyond 4,000 pixels the source is usually the limit
70
+ * anyway, and the server falls back to it.
71
+ */
72
+ export const snapWidth = (wanted: number): number => {
73
+ if (!Number.isFinite(wanted) || wanted <= 0) return WIDTH_LADDER[0]
74
+
75
+ const below = [...WIDTH_LADDER].reverse().find((rung) => rung <= wanted)
76
+ if (below !== undefined && wanted <= below * (1 + TOLERANCE)) return below
77
+
78
+ return (
79
+ WIDTH_LADDER.find((rung) => rung >= wanted) ??
80
+ WIDTH_LADDER[WIDTH_LADDER.length - 1]!
81
+ )
82
+ }
package/src/port.ts ADDED
@@ -0,0 +1,217 @@
1
+ /**
2
+ * What the library's components need from whatever is behind them.
3
+ *
4
+ * Not `PseudoluxClient`, though that satisfies it as written. The same grid
5
+ * runs in the standalone browser, which talks to Pseudolux directly, and
6
+ * inside a CMS, which talks to *its own server* - because that is the side
7
+ * holding a credential, enforcing permissions, and deciding which slice of the
8
+ * library this deployment may see.
9
+ *
10
+ * Those two speak different vocabularies on purpose: a CMS says `key` where a
11
+ * delivery platform says `pid`, and teaching the CMS the platform's words to
12
+ * share a grid would be the wrong trade. A port is the seam that lets both
13
+ * mount the same components without either learning the other's language.
14
+ */
15
+
16
+ export interface CropRect {
17
+ x: number
18
+ y: number
19
+ width: number
20
+ height: number
21
+ }
22
+
23
+ /** A shape the library cuts pictures to. */
24
+ export interface Preset {
25
+ name: string
26
+ label: string
27
+ ratio: number
28
+ ratioLabel: string
29
+ minWidth?: number
30
+ }
31
+
32
+ /** Where a picture is used, three ways, kept apart. */
33
+ export interface LibraryUsage {
34
+ /** Pages that reported using it. */
35
+ placements: Array<{
36
+ site: string
37
+ page: string
38
+ title: string
39
+ url?: string
40
+ status: "draft" | "published"
41
+ uses: Array<{ field?: string; block?: string; crop?: string; view?: string }>
42
+ reportedAt: string
43
+ }>
44
+ /** Origins it has been requested from, from the access logs. */
45
+ seen: Array<{ origin: string; days: Record<string, number>; firstSeenAt: string; lastSeenAt: string }>
46
+ /** URLs taken by hand. */
47
+ copies: Array<{ at: string; actor?: string; crop?: string }>
48
+ }
49
+
50
+ export interface LibraryQuery {
51
+ text?: string
52
+ format?: string
53
+ limit?: number
54
+ cursor?: string
55
+ /** The bin instead of the library. */
56
+ deleted?: boolean
57
+ /** One group: only what is on this shelf. */
58
+ group?: string
59
+ /** One label: only what is about this. */
60
+ label?: string
61
+ }
62
+
63
+ /** One colour a picture is mostly made of. */
64
+ export interface Swatch {
65
+ /** `#rrggbb`, lowercase. */
66
+ hex: string
67
+ /** Share of the picture, 0-1. */
68
+ weight: number
69
+ /** A basic colour term - "teal", "brown" - where the store works one out. */
70
+ name?: string
71
+ }
72
+
73
+ /** One asset, as a grid needs it. */
74
+ export interface LibraryItem {
75
+ id: string
76
+ filename?: string
77
+ width?: number
78
+ height?: number
79
+ format?: string
80
+ altText?: string
81
+ credit?: string
82
+ /**
83
+ * The colours the picture is made of, heaviest first.
84
+ *
85
+ * A flat list rather than the roles the platform also publishes. The port is
86
+ * what a *grid and a panel* need, and both of those show colours rather than
87
+ * choosing between them - a template picking a background is the one that
88
+ * wants roles, and it is not on this side of the seam.
89
+ */
90
+ palette?: Swatch[]
91
+ createdAt?: string
92
+ /** What it is about, and how each word got there. Not groups. */
93
+ labels?: Array<{
94
+ term: string
95
+ status?: "generated" | "pending" | "verified" | "rejected"
96
+ source?: { kind: "person" | "model" | "import"; [key: string]: unknown }
97
+ score?: number
98
+ audience?: "public" | "internal"
99
+ }>
100
+ /** Where the subject is, as whole percentages from the top left. */
101
+ focal?: { x: number; y: number }
102
+ /** Rectangles somebody chose, by preset name or a custom name. */
103
+ crops?: Record<string, CropRect & { savedAt?: string }>
104
+ /** The groups it is on. */
105
+ tags?: string[]
106
+ /** What it means in each of its groups, where that differs from the
107
+ * defaults above. */
108
+ views?: Record<string, { altText?: string; credit?: string }>
109
+ /** Set while the asset is in the bin. */
110
+ deletedAt?: string
111
+ deletedReason?: string
112
+ /** Who put it in the bin, where the host knows. */
113
+ deletedBy?: string
114
+ }
115
+
116
+ /**
117
+ * What the thing behind the port can do.
118
+ *
119
+ * Travels with every page, because the moment a UI has a list is the moment it
120
+ * needs to know which controls are worth drawing. A search box over something
121
+ * that cannot search matches nothing, and an empty grid reads as an empty
122
+ * library rather than as an unsupported query.
123
+ */
124
+ export interface LibraryCapabilities {
125
+ text: boolean
126
+ describe: boolean
127
+ /** Whether this side may put assets in the bin, look in it, and restore. */
128
+ remove: boolean
129
+ formats: string[]
130
+ /** The groups this view may browse by. Empty means no group browsing: the
131
+ * host has no list to offer, not that the library has no groups. */
132
+ groups: string[]
133
+ /** The one group this side may describe a view for. Absent with `describe`
134
+ * true means any (a direct build signing as itself). */
135
+ writeGroup?: string
136
+ /** The groups this side may upload to, its own first. Asked which when
137
+ * there is more than one. Absent means `writeGroup` alone. */
138
+ writeGroups?: string[]
139
+ /** The shapes pictures are cut to, so an editor can offer them. */
140
+ presets: Preset[]
141
+ /** Whether this side may add pictures. */
142
+ upload?: boolean
143
+ /** The MIME types an upload may be, where the host says. Absent means any
144
+ * `image/*`, and the server has the last word either way. */
145
+ uploadTypes?: string[]
146
+ /** The largest upload in bytes, where the host says. */
147
+ uploadLimit?: number
148
+ }
149
+
150
+ /** What came of an upload: a new asset; a picture the library already has,
151
+ * exactly or near enough, with a token to go ahead anyway; or a store that
152
+ * is still working on it. */
153
+ export type UploadOutcome =
154
+ | { id: string }
155
+ | { pending: true }
156
+ | { duplicateOf: string[]; similar: Array<{ id: string; distance: number }>; token: string }
157
+
158
+ export interface LibraryPage {
159
+ items: LibraryItem[]
160
+ nextCursor?: string
161
+ capabilities: LibraryCapabilities
162
+ }
163
+
164
+ export interface LibraryPort {
165
+ list(query?: LibraryQuery): Promise<LibraryPage>
166
+ /** Everything known about one asset. May be the same data the list carries. */
167
+ detail(id: string): Promise<LibraryItem>
168
+ /** An address for the picture at a size. */
169
+ imageUrl(
170
+ id: string,
171
+ options?: {
172
+ width?: number
173
+ height?: number
174
+ format?: string
175
+ focal?: { x: number; y: number }
176
+ crop?: CropRect
177
+ }
178
+ ): string
179
+ /** Set the defaults, or with `view`, what the picture means in that group. */
180
+ describe(
181
+ id: string,
182
+ patch: {
183
+ altText?: string | null
184
+ credit?: string | null
185
+ focal?: { x: number; y: number } | null
186
+ /** The person's words, replaced as a whole; a model's are left alone. */
187
+ labels?: Array<string | { term: string; audience?: "public" | "internal" }> | null
188
+ },
189
+ options?: { view?: string }
190
+ ): Promise<unknown>
191
+ /** Drop a group's override, so it reads the defaults again. */
192
+ removeView(id: string, view: string): Promise<unknown>
193
+ /** Keep a rectangle under a name. A preset's name is held to its shape. */
194
+ setCrop(id: string, name: string, rect: CropRect): Promise<unknown>
195
+ removeCrop(id: string, name: string): Promise<unknown>
196
+ /** Where it is used. Absent where the host cannot say. */
197
+ usage?(id: string): Promise<LibraryUsage>
198
+ /** Add a picture. Absent where this side cannot. `onProgress` is 0-1 of the
199
+ * bytes sent; the ingest that follows has no progress to report. */
200
+ upload?(file: File, options?: { onProgress?: (fraction: number) => void; group?: string }): Promise<UploadOutcome>
201
+ /** Go ahead with an upload the library thought it already had. */
202
+ confirmUpload?(token: string): Promise<{ id: string } | { pending: true }>
203
+ /** A URL was taken from the library by hand, for `crop` if named. */
204
+ copied?(id: string, crop?: string): Promise<unknown>
205
+ /** Into the bin, with a reason. Reversible by `restore`. */
206
+ remove(id: string, reason: string): Promise<unknown>
207
+ restore(id: string): Promise<unknown>
208
+ /** Ask the store to work out what it derives from the picture - the
209
+ * colours, for one. `wanted` says what it derives at all. */
210
+ enrich(id: string): Promise<EnrichResult>
211
+ }
212
+
213
+ export interface EnrichResult {
214
+ status: "scheduled" | "complete"
215
+ wanted: string[]
216
+ outstanding?: string[]
217
+ }