@niccolofanton/corkboard 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/CHANGELOG.md +96 -1
- package/README.md +47 -136
- package/dist/chunk-CNSKM2Mi.d.ts +2992 -0
- package/dist/chunk-layer-CRDYkQT5.js +7394 -0
- package/dist/chunk-layer-CRDYkQT5.js.map +1 -0
- package/dist/chunk-values-D2mwqJ9D.js +253 -0
- package/dist/chunk-values-D2mwqJ9D.js.map +1 -0
- package/dist/corkboard.js +1156 -7393
- package/dist/corkboard.js.map +1 -1
- package/dist/index.d.ts +2 -1543
- package/dist/unstable.d.ts +336 -0
- package/dist/unstable.js +90 -0
- package/dist/unstable.js.map +1 -0
- package/package.json +10 -3
|
@@ -0,0 +1,2992 @@
|
|
|
1
|
+
import * as pixi_js from 'pixi.js';
|
|
2
|
+
import { Container, WebGLRenderer, Texture, Application } from 'pixi.js';
|
|
3
|
+
|
|
4
|
+
/** What a card shows: a picture, a video (a DOM `<video>` over its poster) or a live web page / HTML snippet. */
|
|
5
|
+
type CardKind = 'image' | 'video' | 'embed';
|
|
6
|
+
/** The id of a card: a string, unique on the board. */
|
|
7
|
+
type CardId = string;
|
|
8
|
+
/**
|
|
9
|
+
* The virtual screen a live iframe is laid out at, then scaled onto the card.
|
|
10
|
+
* - `'720p'`: the page is laid out with its short side at 720 CSS px (a 16:9 card is a 1280 x 720 page).
|
|
11
|
+
* - `'1080p'`: the same at 1080 (1920 x 1080).
|
|
12
|
+
* - a number: that short side, in CSS px.
|
|
13
|
+
* - `'native'`: the card's world size (a 400 px card is a 400 px wide page: mobile layouts, big text).
|
|
14
|
+
*/
|
|
15
|
+
type EmbedResolution = '720p' | '1080p' | 'native' | number;
|
|
16
|
+
/**
|
|
17
|
+
* What an `embed` card shows live: a page (`url`) or a snippet of HTML (`html`), in a sandboxed iframe. Exactly
|
|
18
|
+
* one of the two. The sandbox profile is derived from this and the provider at render time and is never stored.
|
|
19
|
+
*/
|
|
20
|
+
type EmbedSource = ({
|
|
21
|
+
url: string;
|
|
22
|
+
html?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
html: string;
|
|
25
|
+
url?: undefined;
|
|
26
|
+
}) & {
|
|
27
|
+
/** Shown on the generated tile and in the iframe's `title`. */
|
|
28
|
+
title?: string;
|
|
29
|
+
/** Overrides the board's `embeds.resolution` for this card. */
|
|
30
|
+
resolution?: EmbedResolution;
|
|
31
|
+
};
|
|
32
|
+
/** Where a card's pixels come from. */
|
|
33
|
+
interface CardMediaInput {
|
|
34
|
+
/**
|
|
35
|
+
* The picture: an image URL, or the poster of a video or an embed. Must be fetchable with CORS (the
|
|
36
|
+
* decode worker reads it with `fetch`, then uploads it to WebGL). Required for `image` and `video`
|
|
37
|
+
* cards. An `embed` card may leave it out: the embed layer fills it with a poster it resolves (a
|
|
38
|
+
* provider thumbnail, the `resolve` option's, or a generated tile).
|
|
39
|
+
*/
|
|
40
|
+
src?: string;
|
|
41
|
+
/** The video file, for a `video` card. Played in a DOM `<video>` laid over the card. */
|
|
42
|
+
video?: string;
|
|
43
|
+
/** The content of an `embed` card. Makes the card an `embed` unless `kind` says otherwise. */
|
|
44
|
+
embed?: EmbedSource;
|
|
45
|
+
/**
|
|
46
|
+
* Optional smaller / larger renditions of `src`. The texture pipeline picks the level that matches
|
|
47
|
+
* the card's size on screen: `small` fills an atlas cell (~160 px long side), `medium` is the sharp
|
|
48
|
+
* texture of a card at normal zoom (~480 px), `large` is for close zoom (~1600 px). A missing
|
|
49
|
+
* rendition falls back to `src`, which the decode worker then downsamples itself.
|
|
50
|
+
*/
|
|
51
|
+
sizes?: {
|
|
52
|
+
small?: string;
|
|
53
|
+
medium?: string;
|
|
54
|
+
large?: string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* `aspect`: height / width of the picture (the inverse of CSS `aspect-ratio`). Optional: with no `h` on the
|
|
58
|
+
* element it sizes the card; a card whose size is known never needs it.
|
|
59
|
+
*/
|
|
60
|
+
aspect?: number;
|
|
61
|
+
/**
|
|
62
|
+
* ThumbHash (https://evanw.github.io/thumbhash/) of the picture, <= 25 bytes, as bytes or base64.
|
|
63
|
+
* The blurred first paint of a card; without it the card shows a flat `color` until its picture lands.
|
|
64
|
+
* The board stores it as base64 (see {@link CardMedia}), so a card and its `change` payloads are JSON-safe.
|
|
65
|
+
*/
|
|
66
|
+
thumbhash?: Uint8Array | string;
|
|
67
|
+
/** Flat placeholder colour, "#rrggbb". */
|
|
68
|
+
color?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The `media` of a stored card: a {@link CardMediaInput} as the board keeps it. A copy of what was passed to
|
|
72
|
+
* `add` / `update` (later changes to the caller's object do not reach the card), with the thumbhash always a
|
|
73
|
+
* base64 string, so a card, a `change` payload and a snapshot are plain JSON.
|
|
74
|
+
*/
|
|
75
|
+
interface CardMedia extends Omit<CardMediaInput, 'thumbhash'> {
|
|
76
|
+
/** ThumbHash as base64 (a `Uint8Array` given to `add` / `update` is converted). */
|
|
77
|
+
thumbhash?: string;
|
|
78
|
+
}
|
|
79
|
+
/** A card as the board holds it. Coordinates are world px at zoom 1. */
|
|
80
|
+
interface Card {
|
|
81
|
+
/** Unique on the board. */
|
|
82
|
+
id: CardId;
|
|
83
|
+
/** What the card shows. */
|
|
84
|
+
kind: CardKind;
|
|
85
|
+
/** Left edge, world px (before rotation). */
|
|
86
|
+
x: number;
|
|
87
|
+
/** Top edge, world px (before rotation). */
|
|
88
|
+
y: number;
|
|
89
|
+
/** Width, world px. */
|
|
90
|
+
w: number;
|
|
91
|
+
/** Height, world px. */
|
|
92
|
+
h: number;
|
|
93
|
+
/** Rotation, degrees clockwise about the card's centre. Data only: there is no rotate gesture. */
|
|
94
|
+
rot: number;
|
|
95
|
+
/** A locked card cannot be moved, resized or deleted from the canvas and stays put in auto layout. */
|
|
96
|
+
locked: boolean;
|
|
97
|
+
/** Where the pixels come from. */
|
|
98
|
+
media: CardMedia;
|
|
99
|
+
/** Corner radius, world px. */
|
|
100
|
+
radius: number;
|
|
101
|
+
/** Keep w:h when resized (default true for image and video). */
|
|
102
|
+
aspectLocked: boolean;
|
|
103
|
+
/** Free for the host: carried through unchanged (and into `getSnapshot()`, by reference). */
|
|
104
|
+
data?: unknown;
|
|
105
|
+
}
|
|
106
|
+
/** A field of a card that can change (everything but the `id`). */
|
|
107
|
+
type CardProp = Exclude<keyof Card, 'id'>;
|
|
108
|
+
/**
|
|
109
|
+
* One card in a `change` event's `updated`: the card as it is after the change, as it was before it, and which
|
|
110
|
+
* fields differ. Inside a `batch` the changes to a card fold into one entry from the first `prev` to the last
|
|
111
|
+
* `el`, so a card that ends up as it started is not reported at all.
|
|
112
|
+
*/
|
|
113
|
+
interface CardUpdate {
|
|
114
|
+
/** The card now. */
|
|
115
|
+
el: Card;
|
|
116
|
+
/** The card as it was before the change (or the batch). */
|
|
117
|
+
prev: Card;
|
|
118
|
+
/**
|
|
119
|
+
* The fields that differ between `prev` and `el`, compared per top-level field with `Object.is`: a `media`
|
|
120
|
+
* that was replaced counts as changed even if its contents are equal (and `data` is compared by reference).
|
|
121
|
+
* Never empty. A field that was cleared (`data` set to `undefined`) is listed too: read `el[prop]`.
|
|
122
|
+
*/
|
|
123
|
+
props: readonly CardProp[];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* What `add` takes. Everything but `media` is optional: a card with no position is placed next to what is on
|
|
127
|
+
* screen (an `x` or `y` it has is kept); a missing size is derived from `w` and the media's aspect (an embed's
|
|
128
|
+
* default width is `DEFAULTS.embedWidth`).
|
|
129
|
+
*/
|
|
130
|
+
interface CardInit {
|
|
131
|
+
/** Default: a generated unique id. Must not be on the board already. */
|
|
132
|
+
id?: CardId;
|
|
133
|
+
/** Default: `'embed'` when `media.embed` is set, else `'video'` when `media.video` is, else `'image'`. */
|
|
134
|
+
kind?: CardKind;
|
|
135
|
+
/** Left edge, world px. Default: placed. */
|
|
136
|
+
x?: number;
|
|
137
|
+
/** Top edge, world px. Default: placed. */
|
|
138
|
+
y?: number;
|
|
139
|
+
/** Width, world px. Default: `DEFAULTS.cardWidth` (`DEFAULTS.embedWidth` for an embed). */
|
|
140
|
+
w?: number;
|
|
141
|
+
/** Height, world px. Default: `w` times the media's aspect. */
|
|
142
|
+
h?: number;
|
|
143
|
+
/**
|
|
144
|
+
* Rotation, degrees clockwise.
|
|
145
|
+
* @default 0
|
|
146
|
+
*/
|
|
147
|
+
rot?: number;
|
|
148
|
+
/**
|
|
149
|
+
* @default false
|
|
150
|
+
*/
|
|
151
|
+
locked?: boolean;
|
|
152
|
+
/** Where the pixels come from. */
|
|
153
|
+
media: CardMediaInput;
|
|
154
|
+
/**
|
|
155
|
+
* Corner radius, world px.
|
|
156
|
+
* @default DEFAULTS.cardRadius
|
|
157
|
+
*/
|
|
158
|
+
radius?: number;
|
|
159
|
+
/**
|
|
160
|
+
* Keep w:h when resized.
|
|
161
|
+
* @default true
|
|
162
|
+
*/
|
|
163
|
+
aspectLocked?: boolean;
|
|
164
|
+
/** Free for the host: carried through unchanged. */
|
|
165
|
+
data?: unknown;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* What `update` takes: any field of a card but `id`. `kind` changes with `media` unless given. A field left out
|
|
169
|
+
* or set to `undefined` is left as it is - except `data`: an own `data` key set to `undefined` clears it.
|
|
170
|
+
*/
|
|
171
|
+
type CardPatch = Partial<Omit<Card, 'id' | 'kind' | 'media'>> & {
|
|
172
|
+
kind?: CardKind;
|
|
173
|
+
media?: CardMediaInput;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Who made a change: a pointer or keyboard gesture (`'user'`), a call on the board or on `board.layout`
|
|
177
|
+
* (`'api'`), `loadSnapshot()` (`'load'`), `applyChange()` (`'apply'`, or `'undo'` when inverted), or the library
|
|
178
|
+
* itself (`'system'`: an embed card resized to its content, say). A host may pass its own tag to
|
|
179
|
+
* `batch(fn, { source })`, e.g. `'remote'` for edits it replays from a peer.
|
|
180
|
+
*
|
|
181
|
+
* `'system'`, `'undo'` and `'apply'` writes are not new user edits: skip them when recording history and do not
|
|
182
|
+
* broadcast them.
|
|
183
|
+
*/
|
|
184
|
+
type ChangeSource = 'user' | 'api' | 'load' | 'system' | 'apply' | 'undo' | (string & {});
|
|
185
|
+
/**
|
|
186
|
+
* One card whose place in the draw order is part of a {@link Change}. `prevBelow` / `nextBelow` are the card
|
|
187
|
+
* directly BELOW it (drawn just before it) before and after the change; `null` means the bottom of the order
|
|
188
|
+
* (or, in `prevBelow`, that the card did not exist before).
|
|
189
|
+
*/
|
|
190
|
+
interface OrderMove {
|
|
191
|
+
/** The card. */
|
|
192
|
+
id: CardId;
|
|
193
|
+
/** The card directly below it before the change (`null`: it was at the bottom, or did not exist). */
|
|
194
|
+
prevBelow: CardId | null;
|
|
195
|
+
/** The card directly below it after the change (`null`: it is at the bottom, or it was removed). */
|
|
196
|
+
nextBelow: CardId | null;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The draw-order part of a {@link Change}, as anchors instead of whole id lists (so it is O(moved) to store and
|
|
200
|
+
* to replay, and it survives a peer whose order differs elsewhere).
|
|
201
|
+
*
|
|
202
|
+
* `moved` is a minimal set of cards that, taken out and put back, turns the old order into the new one: each is
|
|
203
|
+
* placed directly above its `nextBelow`, bottom first (an undo does the same with `prevBelow`). It holds the
|
|
204
|
+
* cards outside the longest run of cards that kept their relative order; for `bringToFront` / `sendToBack` it is
|
|
205
|
+
* just the ids given. A removed card is in it with its `prevBelow` (and `nextBelow: null`), so undoing a delete
|
|
206
|
+
* restores its depth. A card that was only appended on top (the usual `add`) is not in it: replaying the change
|
|
207
|
+
* on a board where the card is not there yet puts it on top.
|
|
208
|
+
*/
|
|
209
|
+
interface OrderChange {
|
|
210
|
+
/** The cards to place, bottom of the new order first. */
|
|
211
|
+
moved: readonly OrderMove[];
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* What one `change` event carries: the net difference between the board before and after a call, a gesture
|
|
215
|
+
* commit, a `batch` or a `loadSnapshot`. Plain data: `JSON.stringify` of it (with `media.thumbhash` stored as
|
|
216
|
+
* base64 and a JSON-safe `data`) is what a sync or an undo stack can keep and replay with
|
|
217
|
+
* `board.applyChange` / {@link invertChange}. The elements are the board's own objects: do not mutate them.
|
|
218
|
+
*/
|
|
219
|
+
interface Change {
|
|
220
|
+
/** Who made it. */
|
|
221
|
+
source: ChangeSource;
|
|
222
|
+
/** Cards that are new. */
|
|
223
|
+
added: readonly Card[];
|
|
224
|
+
/** Cards that are gone, as they were. */
|
|
225
|
+
removed: readonly Card[];
|
|
226
|
+
/** Cards that changed. */
|
|
227
|
+
updated: readonly CardUpdate[];
|
|
228
|
+
/** Present when the draw order changed other than by cards appended on top. */
|
|
229
|
+
order?: OrderChange;
|
|
230
|
+
}
|
|
231
|
+
/** The sizes cards take when `add` is given none, and the limits of a resize. World px; aspects are height / width. */
|
|
232
|
+
declare const DEFAULTS: {
|
|
233
|
+
/** Width of an image or video card. */
|
|
234
|
+
readonly cardWidth: 248;
|
|
235
|
+
/** Height / width of an image card whose picture has no known aspect. */
|
|
236
|
+
readonly cardAspect: 1.25;
|
|
237
|
+
/** Height / width of a video card with no known aspect. */
|
|
238
|
+
readonly videoAspect: number;
|
|
239
|
+
/** Height / width of an embed card whose provider has no shape of its own. */
|
|
240
|
+
readonly embedAspect: number;
|
|
241
|
+
/** Width of an embed card. */
|
|
242
|
+
readonly embedWidth: 400;
|
|
243
|
+
/** Corner radius. */
|
|
244
|
+
readonly cardRadius: 8;
|
|
245
|
+
/** Narrowest a resize gesture makes a card. */
|
|
246
|
+
readonly minCardW: 40;
|
|
247
|
+
/** Widest a resize gesture makes a card. */
|
|
248
|
+
readonly maxCardW: 1600;
|
|
249
|
+
};
|
|
250
|
+
/** Lowest default zoom of the camera (`camera.minScale` overrides it). */
|
|
251
|
+
declare const MIN_SCALE = 0.05;
|
|
252
|
+
/** Highest default zoom of the camera (`camera.maxScale` overrides it). */
|
|
253
|
+
declare const MAX_SCALE = 4;
|
|
254
|
+
|
|
255
|
+
/** Why a {@link CorkboardError} was thrown. */
|
|
256
|
+
type CorkboardErrorCode =
|
|
257
|
+
/** A method was called after `dispose()`. */
|
|
258
|
+
'disposed'
|
|
259
|
+
/** The browser cannot run the board (no WebGL2, or Pixi picked another renderer). */
|
|
260
|
+
| 'unsupported'
|
|
261
|
+
/**
|
|
262
|
+
* A call or an option got a value it cannot use: `add` / `update` / `loadSnapshot` / `applyChange` a card value
|
|
263
|
+
* (NaN, a size <= 0, a duplicate id...), or any method an id list of the wrong type, a NaN or out-of-range
|
|
264
|
+
* number, an unknown enum value or a bad option. Nothing was changed.
|
|
265
|
+
*/
|
|
266
|
+
| 'invalid';
|
|
267
|
+
/** The one error class the board throws: `instanceof CorkboardError`, then branch on `code`. */
|
|
268
|
+
declare class CorkboardError extends Error {
|
|
269
|
+
/** Why it was thrown; branch on this. */
|
|
270
|
+
readonly code: CorkboardErrorCode;
|
|
271
|
+
constructor(code: CorkboardErrorCode, message: string, options?: {
|
|
272
|
+
cause?: unknown;
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* A failure at runtime that did not throw: a picture that did not decode, a worker that died, a video or an
|
|
277
|
+
* embed that failed. Reported through the board's `error` event; the card falls back to its placeholder.
|
|
278
|
+
*/
|
|
279
|
+
interface BoardErrorEvent {
|
|
280
|
+
/** What failed. */
|
|
281
|
+
kind: 'texture' | 'worker' | 'video' | 'embed' | 'context';
|
|
282
|
+
/** The card it concerns, if any. */
|
|
283
|
+
id?: CardId;
|
|
284
|
+
/** The URL that failed, if any. */
|
|
285
|
+
url?: string;
|
|
286
|
+
/** The underlying error (an Error, a DOM event, or a message). */
|
|
287
|
+
cause: unknown;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** The view: a world point (wx, wy) shows at (`tx` + wx * `scale`, `ty` + wy * `scale`) in host-local CSS px. */
|
|
291
|
+
interface Camera {
|
|
292
|
+
/** Screen x of the world origin, CSS px. */
|
|
293
|
+
tx: number;
|
|
294
|
+
/** Screen y of the world origin, CSS px. */
|
|
295
|
+
ty: number;
|
|
296
|
+
/** Zoom: CSS px per world px. */
|
|
297
|
+
scale: number;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* A world rectangle by its corners: (`x0`, `y0`) top-left, (`x1`, `y1`) bottom-right. What `camera.visible()`,
|
|
301
|
+
* `bounds()`, `inRect()` and `camera.zoomTo()` use. See {@link Box} for the `{ x, y, w, h }` shape.
|
|
302
|
+
*/
|
|
303
|
+
interface Rect {
|
|
304
|
+
/** Left edge. */
|
|
305
|
+
x0: number;
|
|
306
|
+
/** Top edge. */
|
|
307
|
+
y0: number;
|
|
308
|
+
/** Right edge. */
|
|
309
|
+
x1: number;
|
|
310
|
+
/** Bottom edge. */
|
|
311
|
+
y1: number;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* An x/y/w/h rectangle: top-left corner and size. Each use says whether it is world px or screen px:
|
|
315
|
+
* `board.screenRect(id)` returns one in host-local CSS px (where the card is drawn), the `rects` of the `transform`
|
|
316
|
+
* event are in world px. Not to be confused with {@link Rect}, the world rectangle by corners.
|
|
317
|
+
*/
|
|
318
|
+
interface Box {
|
|
319
|
+
/** Left edge. */
|
|
320
|
+
x: number;
|
|
321
|
+
/** Top edge. */
|
|
322
|
+
y: number;
|
|
323
|
+
/** Width. */
|
|
324
|
+
w: number;
|
|
325
|
+
/** Height. */
|
|
326
|
+
h: number;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Axis-aligned bounding box in world px, rbush-compatible. */
|
|
330
|
+
interface Aabb {
|
|
331
|
+
minX: number;
|
|
332
|
+
minY: number;
|
|
333
|
+
maxX: number;
|
|
334
|
+
maxY: number;
|
|
335
|
+
}
|
|
336
|
+
/** A rectangle in world px: position and size. */
|
|
337
|
+
interface WorldRect {
|
|
338
|
+
x: number;
|
|
339
|
+
y: number;
|
|
340
|
+
w: number;
|
|
341
|
+
h: number;
|
|
342
|
+
rot: number;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** The spread of a series of timings, in ms. */
|
|
346
|
+
interface Percentiles {
|
|
347
|
+
/** How many samples (the stage keeps the latest 4096 per series). */
|
|
348
|
+
n: number;
|
|
349
|
+
/** Median. */
|
|
350
|
+
p50: number;
|
|
351
|
+
/** 95th percentile. */
|
|
352
|
+
p95: number;
|
|
353
|
+
/** The slowest sample. */
|
|
354
|
+
max: number;
|
|
355
|
+
}
|
|
356
|
+
/** A tick that took over 25 ms, with where the time went. */
|
|
357
|
+
interface SlowTick {
|
|
358
|
+
/** The whole tick. */
|
|
359
|
+
ms: number;
|
|
360
|
+
/** The camera zoom when it happened. */
|
|
361
|
+
scale: number;
|
|
362
|
+
/** Views mounted at the time. */
|
|
363
|
+
mounted: number;
|
|
364
|
+
/** Views mounted so far (cumulative). */
|
|
365
|
+
mounts: number;
|
|
366
|
+
/** The phases of the tick, ms: syncing the store... */
|
|
367
|
+
store: number;
|
|
368
|
+
/** ...the camera step... */
|
|
369
|
+
camera: number;
|
|
370
|
+
/** ...texture uploads... */
|
|
371
|
+
upload: number;
|
|
372
|
+
/** ...the DOM layers... */
|
|
373
|
+
overlay: number;
|
|
374
|
+
/** ...and the render call. */
|
|
375
|
+
render: number;
|
|
376
|
+
}
|
|
377
|
+
/** Texture memory and the decode / upload pipeline. */
|
|
378
|
+
interface TextureStats {
|
|
379
|
+
/** GPU bytes held by the pipeline now. */
|
|
380
|
+
bytes: number;
|
|
381
|
+
/** The budget it keeps under (`textures.budgetBytes`). */
|
|
382
|
+
budget: number;
|
|
383
|
+
/** The most it has held since the start (or the last reset). */
|
|
384
|
+
peakBytes: number;
|
|
385
|
+
/** The longest it stayed over budget, ms. */
|
|
386
|
+
overBudgetMsMax: number;
|
|
387
|
+
/** Mounted cards by the level their texture is at: `[L0, L1, L2, L3]` (placeholder, atlas cell, own texture, close zoom). */
|
|
388
|
+
levelsMounted: [number, number, number, number];
|
|
389
|
+
/** Atlas pages: placeholders (L0) and pictures (L1). */
|
|
390
|
+
pages: {
|
|
391
|
+
l0: number;
|
|
392
|
+
l1: number;
|
|
393
|
+
};
|
|
394
|
+
/** Cards that own a texture at the medium / large level. */
|
|
395
|
+
l2: number;
|
|
396
|
+
/** Same, at the close-zoom level. */
|
|
397
|
+
l3: number;
|
|
398
|
+
/** Textures evicted and waiting for the next render to be destroyed. */
|
|
399
|
+
retiredPending: number;
|
|
400
|
+
/** Where the bytes are. `pinned*` is the share of the own textures that is on screen (cannot be evicted). */
|
|
401
|
+
breakdown: {
|
|
402
|
+
pageBytes: number;
|
|
403
|
+
l2Bytes: number;
|
|
404
|
+
l3Bytes: number;
|
|
405
|
+
pinnedBytes: number;
|
|
406
|
+
pinned: number;
|
|
407
|
+
};
|
|
408
|
+
/** Decodes waiting for a worker / running. */
|
|
409
|
+
queued: number;
|
|
410
|
+
/** Decodes running in the workers. */
|
|
411
|
+
inflight: number;
|
|
412
|
+
/** Finished decodes, and their mean time, ms. */
|
|
413
|
+
decodes: number;
|
|
414
|
+
/** Mean decode time, ms. */
|
|
415
|
+
decodeMsAvg: number;
|
|
416
|
+
/** Bytes the workers fetched. */
|
|
417
|
+
fetchedBytes: number;
|
|
418
|
+
/** Decodes cancelled before they finished. */
|
|
419
|
+
cancelled: number;
|
|
420
|
+
/** Decodes that failed. */
|
|
421
|
+
failed: number;
|
|
422
|
+
/** Textures dropped to stay in budget, by level. */
|
|
423
|
+
evicted: {
|
|
424
|
+
l1: number;
|
|
425
|
+
l2: number;
|
|
426
|
+
l3: number;
|
|
427
|
+
};
|
|
428
|
+
/** Textures uploaded to the GPU. */
|
|
429
|
+
uploads: number;
|
|
430
|
+
/** Upload time per frame: the worst and the mean, ms. */
|
|
431
|
+
uploadMsMax: number;
|
|
432
|
+
uploadMsAvg: number;
|
|
433
|
+
/** Uploads done in the last rendered frame. */
|
|
434
|
+
uploadsLastFrame: number;
|
|
435
|
+
}
|
|
436
|
+
/** The render loop. Timings are in ms; a series with no sample yet is `null`. */
|
|
437
|
+
interface RenderStats {
|
|
438
|
+
/** Frames rendered (idle ticks do not count). */
|
|
439
|
+
frames: number;
|
|
440
|
+
/** `requestAnimationFrame` callbacks asked for: it stops growing when the board is idle. */
|
|
441
|
+
rafCalls: number;
|
|
442
|
+
/** Ticks run, idle ones included. */
|
|
443
|
+
ticks: number;
|
|
444
|
+
/** Time of the whole tick (store sync, culling, uploads, render). */
|
|
445
|
+
tickMs: Percentiles | null;
|
|
446
|
+
/** Main-thread time of the render call. */
|
|
447
|
+
cpuMs: Percentiles | null;
|
|
448
|
+
/** GPU time per render (`gpuTimer: true` and a browser with `EXT_disjoint_timer_query_webgl2`). */
|
|
449
|
+
gpuMs: Percentiles | null;
|
|
450
|
+
/** Why `gpuMs` is `null`: the option is off, the browser has no timer, or no result came back yet. */
|
|
451
|
+
gpuTimer: 'off' | 'unsupported' | 'on';
|
|
452
|
+
/** Frames that threw and were healed by rebuilding the textures: since the last reset, and since the start. */
|
|
453
|
+
renderErrors: number;
|
|
454
|
+
/** Same, since the start. */
|
|
455
|
+
renderErrorsTotal: number;
|
|
456
|
+
/** Callbacks (yours or a layer's) that threw in a frame. */
|
|
457
|
+
hookErrors: number;
|
|
458
|
+
/** From the stage's start to the first painted frame / until every visible card had its picture, ms. */
|
|
459
|
+
firstPaintMs: number | null;
|
|
460
|
+
/** See `firstPaintMs`: until every visible card had its picture. */
|
|
461
|
+
l1CompleteMs: number | null;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* @experimental Internals for profiling the stage (`board.stats().debug`). Not a stable surface: fields may
|
|
465
|
+
* change in any release. Exported from `@niccolofanton/corkboard/unstable` only.
|
|
466
|
+
*/
|
|
467
|
+
interface DebugStats {
|
|
468
|
+
/** Culling passes run. */
|
|
469
|
+
cullPasses: number;
|
|
470
|
+
/** Spatial queries run. */
|
|
471
|
+
requeries: number;
|
|
472
|
+
/** Level-of-detail passes run. */
|
|
473
|
+
lodPasses: number;
|
|
474
|
+
/** Views mounted / unmounted since the start. */
|
|
475
|
+
mounts: number;
|
|
476
|
+
unmounts: number;
|
|
477
|
+
/** The latest ticks over 25 ms. */
|
|
478
|
+
slowTicks: SlowTick[];
|
|
479
|
+
/** Cumulative time of the spatial query, mounting, unmounting and the LOD pass, ms. */
|
|
480
|
+
requeryMs: {
|
|
481
|
+
search: number;
|
|
482
|
+
mount: number;
|
|
483
|
+
unmount: number;
|
|
484
|
+
lod: number;
|
|
485
|
+
};
|
|
486
|
+
/** Time of the LOD pass, ms. */
|
|
487
|
+
lodPassMs: Percentiles | null;
|
|
488
|
+
/** Children of the Pixi world container. */
|
|
489
|
+
worldChildren: number;
|
|
490
|
+
/** The view pool: views created, taken back from it, and waiting in it. */
|
|
491
|
+
viewPool: {
|
|
492
|
+
created: number;
|
|
493
|
+
reused: number;
|
|
494
|
+
pooled: number;
|
|
495
|
+
};
|
|
496
|
+
/** The GPU as the browser names it. */
|
|
497
|
+
glRenderer: string;
|
|
498
|
+
}
|
|
499
|
+
/** What the stage reports (`Stage.stats()`). */
|
|
500
|
+
interface StageStats {
|
|
501
|
+
/** Cards the stage knows. */
|
|
502
|
+
cards: number;
|
|
503
|
+
/** Cards that have a view now (the rest are culled). */
|
|
504
|
+
mounted: number;
|
|
505
|
+
/** Views waiting for their mount slot. */
|
|
506
|
+
mountQueue: number;
|
|
507
|
+
/** The WebGL context is lost: nothing is drawn until it is restored. */
|
|
508
|
+
lost: boolean;
|
|
509
|
+
/** The camera zoom, the device pixel ratio and the host's size in CSS px. */
|
|
510
|
+
scale: number;
|
|
511
|
+
dpr: number;
|
|
512
|
+
viewport: [number, number];
|
|
513
|
+
/** Texture memory and the decode pipeline. */
|
|
514
|
+
textures: TextureStats;
|
|
515
|
+
/** The render loop. */
|
|
516
|
+
render: RenderStats;
|
|
517
|
+
/**
|
|
518
|
+
* @experimental Profiling internals: fields may change in any release. The type is `DebugStats` from
|
|
519
|
+
* `@niccolofanton/corkboard/unstable`.
|
|
520
|
+
*/
|
|
521
|
+
debug: DebugStats;
|
|
522
|
+
}
|
|
523
|
+
/** The live iframes of the `embed` cards. Counts, except where noted. */
|
|
524
|
+
interface EmbedStats {
|
|
525
|
+
/** Mounted iframes now, active and parked. */
|
|
526
|
+
live: number;
|
|
527
|
+
/** Of those: active, rendering and interactive. This is the count `maxLive` caps. */
|
|
528
|
+
active: number;
|
|
529
|
+
/** The cap on `active` now (`embeds.maxLive`, or `maxLiveTouch` on a touch device; can be `Infinity`). */
|
|
530
|
+
maxLive: number;
|
|
531
|
+
/** Of the mounted ones: parked, mounted but inert, showing their last frame (`live - active`). */
|
|
532
|
+
parked: number;
|
|
533
|
+
/** ... off screen: hidden and not rendering. */
|
|
534
|
+
culled: number;
|
|
535
|
+
/** ... replaced by a snapshot. */
|
|
536
|
+
frozen: number;
|
|
537
|
+
/** ... allowed to animate, and how many may now (lowered while the page runs slow; can be `Infinity`). */
|
|
538
|
+
animating: number;
|
|
539
|
+
animatingBudget: number;
|
|
540
|
+
/** ... whose page is still loading. */
|
|
541
|
+
loading: number;
|
|
542
|
+
/** Snippet previews not done yet (waiting, in the cache lookup, being rendered). */
|
|
543
|
+
previewsPending: number;
|
|
544
|
+
/** The short side (CSS px) under which a snippet freezes now (raised while the page stays slow). */
|
|
545
|
+
freezeThreshold: number;
|
|
546
|
+
/** The card in interact mode (null: none). */
|
|
547
|
+
interacting: CardId | null;
|
|
548
|
+
}
|
|
549
|
+
/** Playing videos. */
|
|
550
|
+
interface VideoStats {
|
|
551
|
+
/** Clips playing now. */
|
|
552
|
+
playing: number;
|
|
553
|
+
/** How many the always-playing pool may run now (`video.maxPlaying`, lowered while the page runs slow; can be `Infinity`). */
|
|
554
|
+
budget: number;
|
|
555
|
+
}
|
|
556
|
+
/** What `board.stats()` returns: a snapshot, safe to keep. */
|
|
557
|
+
interface BoardStats extends StageStats {
|
|
558
|
+
/** The live iframes of the embed cards. */
|
|
559
|
+
embeds: EmbedStats;
|
|
560
|
+
/** Playing videos. */
|
|
561
|
+
video: VideoStats;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* What changed in one store batch, as a net diff per card id: `added`, `removed` and `updated` never share an id.
|
|
566
|
+
* Cards are the store's own objects: do not mutate them. This is the public {@link Change} plus `reload`.
|
|
567
|
+
*/
|
|
568
|
+
interface ChangeSet extends Change {
|
|
569
|
+
source: ChangeSource;
|
|
570
|
+
added: Card[];
|
|
571
|
+
removed: Card[];
|
|
572
|
+
updated: CardUpdate[];
|
|
573
|
+
reload?: boolean;
|
|
574
|
+
}
|
|
575
|
+
/** An event of the store: `change` (a {@link ChangeSet}) or one of its others. */
|
|
576
|
+
type StoreEvent = {
|
|
577
|
+
type: 'change';
|
|
578
|
+
change: ChangeSet;
|
|
579
|
+
};
|
|
580
|
+
/** The cards of a board: id lookup, draw order, a spatial index, change events and batches. The board owns one; reach it with `getInternals`. */
|
|
581
|
+
declare class Store {
|
|
582
|
+
private readonly map;
|
|
583
|
+
private readonly tree;
|
|
584
|
+
private readonly entries;
|
|
585
|
+
private _order;
|
|
586
|
+
private readonly dead;
|
|
587
|
+
private ranks;
|
|
588
|
+
private ranksDirty;
|
|
589
|
+
orderVersion: number;
|
|
590
|
+
private readonly listeners;
|
|
591
|
+
private depth;
|
|
592
|
+
private touched;
|
|
593
|
+
private batchSource;
|
|
594
|
+
private source;
|
|
595
|
+
private sawLoad;
|
|
596
|
+
private reloaded;
|
|
597
|
+
private orderLen0;
|
|
598
|
+
private orderPrev;
|
|
599
|
+
private orderHint;
|
|
600
|
+
private orderHintBad;
|
|
601
|
+
private liftRank;
|
|
602
|
+
private dispatching;
|
|
603
|
+
private readonly queue;
|
|
604
|
+
private get order();
|
|
605
|
+
private set order(value);
|
|
606
|
+
private compact;
|
|
607
|
+
get size(): number;
|
|
608
|
+
subscribe(listener: (e: StoreEvent) => void): () => void;
|
|
609
|
+
get(id: CardId): Card | undefined;
|
|
610
|
+
has(id: CardId): boolean;
|
|
611
|
+
elements(): IterableIterator<Card>;
|
|
612
|
+
ids(): readonly CardId[];
|
|
613
|
+
rank(id: CardId): number;
|
|
614
|
+
lift(ids: readonly CardId[]): void;
|
|
615
|
+
private relift;
|
|
616
|
+
private baseRank;
|
|
617
|
+
searchInto(box: Aabb, out: Card[]): Card[];
|
|
618
|
+
add(els: readonly Card[], source?: ChangeSource): void;
|
|
619
|
+
update(id: CardId, patch: CardPatch, source?: ChangeSource): CardProp[];
|
|
620
|
+
remove(ids: readonly CardId[], source?: ChangeSource): Card[];
|
|
621
|
+
bringToFront(ids: readonly CardId[], source?: ChangeSource): void;
|
|
622
|
+
sendToBack(ids: readonly CardId[], source?: ChangeSource): void;
|
|
623
|
+
setOrder(ids: readonly CardId[], source?: ChangeSource): void;
|
|
624
|
+
applyOrderMoves(moves: readonly OrderMove[], source?: ChangeSource): void;
|
|
625
|
+
clear(source?: ChangeSource): void;
|
|
626
|
+
replaceAll(els: readonly Card[]): void;
|
|
627
|
+
batch(fn: () => void, source?: ChangeSource): void;
|
|
628
|
+
private entryOf;
|
|
629
|
+
private note;
|
|
630
|
+
private touch;
|
|
631
|
+
private markOrder;
|
|
632
|
+
private reorder;
|
|
633
|
+
private rebuildRanks;
|
|
634
|
+
private flush;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/** A wheel event reduced to what the camera needs. */
|
|
638
|
+
interface WheelInput {
|
|
639
|
+
x: number;
|
|
640
|
+
y: number;
|
|
641
|
+
deltaX: number;
|
|
642
|
+
deltaY: number;
|
|
643
|
+
deltaMode: number;
|
|
644
|
+
zoom: boolean;
|
|
645
|
+
}
|
|
646
|
+
/** The camera of the stage: the current view, animated moves and the zoom limits. */
|
|
647
|
+
declare class CameraController {
|
|
648
|
+
private readonly wake;
|
|
649
|
+
private readonly bounds;
|
|
650
|
+
readonly cam: Camera;
|
|
651
|
+
version: number;
|
|
652
|
+
width: number;
|
|
653
|
+
height: number;
|
|
654
|
+
private targetScale;
|
|
655
|
+
private anchor;
|
|
656
|
+
private vel;
|
|
657
|
+
private dragging;
|
|
658
|
+
private samples;
|
|
659
|
+
private fly;
|
|
660
|
+
private lastDrag;
|
|
661
|
+
private empty;
|
|
662
|
+
private pendingFit;
|
|
663
|
+
constructor(wake: () => void, bounds?: {
|
|
664
|
+
min: number;
|
|
665
|
+
max: number;
|
|
666
|
+
});
|
|
667
|
+
setViewport(w: number, h: number, empty?: boolean): void;
|
|
668
|
+
get isEmpty(): boolean;
|
|
669
|
+
get scale(): number;
|
|
670
|
+
get minScale(): number;
|
|
671
|
+
get maxScale(): number;
|
|
672
|
+
setRange(min: number, max: number): void;
|
|
673
|
+
get busy(): boolean;
|
|
674
|
+
visibleRect(): Rect;
|
|
675
|
+
wheel(e: WheelInput): void;
|
|
676
|
+
dragStart(x: number, y: number, t: number): void;
|
|
677
|
+
dragMove(x: number, y: number, t: number): void;
|
|
678
|
+
dragEnd(t: number): void;
|
|
679
|
+
panBy(dx: number, dy: number): void;
|
|
680
|
+
zoomStep(k: number, ax: number, ay: number): void;
|
|
681
|
+
pinch(ax: number, ay: number, ratio: number, dx: number, dy: number): void;
|
|
682
|
+
fitCamera(world: Rect, pad?: number): Camera;
|
|
683
|
+
requestFit(target: () => Rect | null, pad?: number, animate?: boolean, duration?: number): void;
|
|
684
|
+
private clampCamera;
|
|
685
|
+
jumpTo(c: Camera): void;
|
|
686
|
+
flyTo(c: Camera, duration?: number): void;
|
|
687
|
+
zoomToActual(duration?: number): void;
|
|
688
|
+
step(dt: number): boolean;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/** A resize handle of the selection: a corner or an edge. */
|
|
692
|
+
type HandleId = 'nw' | 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w';
|
|
693
|
+
/** A resize handle: its id, world position (centre) and mouse cursor. */
|
|
694
|
+
interface Handle {
|
|
695
|
+
id: HandleId;
|
|
696
|
+
x: number;
|
|
697
|
+
y: number;
|
|
698
|
+
cursor: string;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/** The rectangle of a selection or hover outline. */
|
|
702
|
+
interface OutlineRect extends WorldRect {
|
|
703
|
+
radius?: number;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/** A card the snapping session compares a moving card against. */
|
|
707
|
+
interface SnapCandidate {
|
|
708
|
+
id: string;
|
|
709
|
+
box: Aabb;
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Screen px: the snap threshold and how far a guide runs past its outermost marker. Callers divide by
|
|
713
|
+
* the zoom.
|
|
714
|
+
*/
|
|
715
|
+
declare const SNAP_THRESHOLD_PX = 6;
|
|
716
|
+
/** How far a guide line extends past the cards it joins, screen px. */
|
|
717
|
+
declare const GUIDE_OVERSHOOT_PX = 3;
|
|
718
|
+
/**
|
|
719
|
+
* An alignment guide. A vertical guide (axis 'x') is the line x = `at` running from y = `from` to
|
|
720
|
+
* y = `to`; a horizontal guide (axis 'y') is the line y = `at` running from x = `from` to x = `to`.
|
|
721
|
+
* World units. `kind` follows the moving line that produced it ('center' for the centre / middle line,
|
|
722
|
+
* 'edge' for the outer ones).
|
|
723
|
+
* `marks`: where the line meets each aligned box, sorted (positions along the line, world units): the
|
|
724
|
+
* two corners of a box aligned by an edge, the midpoint of one aligned by its centre, for the moving
|
|
725
|
+
* box and the candidates on the line nearest to it (at most six). The span runs from the first mark to
|
|
726
|
+
* the last plus the overshoot.
|
|
727
|
+
*/
|
|
728
|
+
interface LineGuide {
|
|
729
|
+
axis: 'x' | 'y';
|
|
730
|
+
at: number;
|
|
731
|
+
from: number;
|
|
732
|
+
to: number;
|
|
733
|
+
kind: 'edge' | 'center';
|
|
734
|
+
marks?: number[];
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* A measurement marker. NOTE the axis convention differs from `LineGuide`: here `axis` is the direction
|
|
738
|
+
* the measured segment RUNS along. A segment along 'x' is horizontal: it sits at y = `at` and runs from
|
|
739
|
+
* x = `from` to x = `to`; along 'y' it is vertical at x = `at`, from y = `from` to y = `to`. World units.
|
|
740
|
+
* - 'gap': the empty space between two boxes, `label` = its size in world px, rounded to an integer.
|
|
741
|
+
* Emitted for the moving box's own gap(s) and for each existing gap it was matched to; `at` is the
|
|
742
|
+
* middle of the range the two boxes face each other over.
|
|
743
|
+
* - 'width' (axis 'x') / 'height' (axis 'y'): the extent of one box, spanning from edge to edge, drawn
|
|
744
|
+
* at the middle of the box (`at`). Emitted for the resized box and for each box whose extent it was
|
|
745
|
+
* matched to; `label` = the extent in world px, rounded (the overlay draws "=" instead).
|
|
746
|
+
*/
|
|
747
|
+
interface MeasureGuide {
|
|
748
|
+
axis: 'x' | 'y';
|
|
749
|
+
at: number;
|
|
750
|
+
from: number;
|
|
751
|
+
to: number;
|
|
752
|
+
kind: 'gap' | 'width';
|
|
753
|
+
label: number;
|
|
754
|
+
}
|
|
755
|
+
/** Every guide carries `axis`, `at`, `from`, `to` and `kind`; tell the families apart by `kind`. */
|
|
756
|
+
type Guide = LineGuide | MeasureGuide;
|
|
757
|
+
/**
|
|
758
|
+
* `dx` / `dy`: the correction to ADD to the moving box (0 when that axis does not snap). A box that
|
|
759
|
+
* already lies on a line reports 0 and still carries the guide.
|
|
760
|
+
*/
|
|
761
|
+
interface SnapResult {
|
|
762
|
+
dx: number;
|
|
763
|
+
dy: number;
|
|
764
|
+
guides: Guide[];
|
|
765
|
+
edgeX?: 'min' | 'max';
|
|
766
|
+
edgeY?: 'min' | 'max';
|
|
767
|
+
}
|
|
768
|
+
/** Which edges of a card a resize moves. */
|
|
769
|
+
interface ResizeEdges {
|
|
770
|
+
left?: boolean;
|
|
771
|
+
right?: boolean;
|
|
772
|
+
top?: boolean;
|
|
773
|
+
bottom?: boolean;
|
|
774
|
+
}
|
|
775
|
+
/** The alignment lines found along one axis. */
|
|
776
|
+
interface AxisLines {
|
|
777
|
+
readonly v: Float64Array;
|
|
778
|
+
readonly owner: Int32Array;
|
|
779
|
+
readonly kind: Uint8Array;
|
|
780
|
+
}
|
|
781
|
+
/** The equal-gap measures found along one axis. */
|
|
782
|
+
interface GapList {
|
|
783
|
+
readonly v: Float64Array;
|
|
784
|
+
readonly before: Int32Array;
|
|
785
|
+
readonly after: Int32Array;
|
|
786
|
+
}
|
|
787
|
+
/** The size-match measures found along one axis. */
|
|
788
|
+
interface SizeList {
|
|
789
|
+
readonly v: Float64Array;
|
|
790
|
+
readonly owner: Int32Array;
|
|
791
|
+
}
|
|
792
|
+
/** Opaque to callers: build it with `buildSnapIndex`, hand it back to `snapMove` / `snapResize`. */
|
|
793
|
+
interface SnapIndex {
|
|
794
|
+
readonly count: number;
|
|
795
|
+
readonly candCount: number;
|
|
796
|
+
readonly ids: readonly string[];
|
|
797
|
+
readonly boxes: Float64Array;
|
|
798
|
+
readonly x: AxisLines;
|
|
799
|
+
readonly y: AxisLines;
|
|
800
|
+
readonly gapsX: GapList;
|
|
801
|
+
readonly gapsY: GapList;
|
|
802
|
+
readonly widths: SizeList;
|
|
803
|
+
readonly heights: SizeList;
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* O(n log n) for the lines and sizes, done once at drag start; the gaps cost a bounded quadratic pass
|
|
807
|
+
* over at most GAP_BOX_CAP boxes. Candidates give left / centre / right and top / middle / bottom
|
|
808
|
+
* lines, gaps and sizes. Boxes that are not finite are ignored.
|
|
809
|
+
*/
|
|
810
|
+
declare function buildSnapIndex(candidates: readonly SnapCandidate[]): SnapIndex;
|
|
811
|
+
/**
|
|
812
|
+
* Moving a whole box (a card, or a multi-selection's union). The smallest |delta| within
|
|
813
|
+
* `thresholdWorld` wins over the three lines of each axis and the gap snaps; ties prefer
|
|
814
|
+
* centre-to-centre, then edge-to-edge, and an alignment over a gap. Pass `out`
|
|
815
|
+
* to reuse one result object across a drag.
|
|
816
|
+
*/
|
|
817
|
+
declare function snapMove(index: SnapIndex, moving: Aabb, thresholdWorld: number, extendWorld: number, out?: SnapResult): SnapResult;
|
|
818
|
+
/**
|
|
819
|
+
* Resizing: only the dragged edges snap (a centre moves with the box, so it never does), to lines, to
|
|
820
|
+
* the box's width / height matching a nearby box's, and to equal gaps next to the dragged edge. The
|
|
821
|
+
* correction applies to the dragged edge's coordinate: `dx` to the left or right edge, `dy` to the
|
|
822
|
+
* top or bottom one. If both opposite edges of an axis are flagged (a symmetric resize), only the
|
|
823
|
+
* nearer one snaps to a line and sizes and gaps are skipped; `edgeX` / `edgeY` then say which edge the
|
|
824
|
+
* correction belongs to.
|
|
825
|
+
*/
|
|
826
|
+
declare function snapResize(index: SnapIndex, moving: Aabb, edges: ResizeEdges, thresholdWorld: number, extendWorld: number, out?: SnapResult): SnapResult;
|
|
827
|
+
|
|
828
|
+
/** Canvas colours, as 0xRRGGBB numbers. Pass one to `Corkboard.create` / `board.setTheme`; `DARK_THEME` and `LIGHT_THEME` are ready-made. */
|
|
829
|
+
interface Theme {
|
|
830
|
+
/** A dark canvas: picks the default guide colour and the contrast of the UI drawn on the canvas. */
|
|
831
|
+
dark: boolean;
|
|
832
|
+
/** Canvas background (also the WebGL clear colour). */
|
|
833
|
+
canvas: number;
|
|
834
|
+
/** Background dots and their opacity (kept low: the grid is a quiet guide, not a pattern). */
|
|
835
|
+
dot: number;
|
|
836
|
+
/** Opacity of the background dots. */
|
|
837
|
+
dotAlpha?: number;
|
|
838
|
+
/** Hairline around a card: baked into the textures, so a theme change rebuilds them. */
|
|
839
|
+
border: number;
|
|
840
|
+
/** Opacity of the hairline. */
|
|
841
|
+
borderAlpha: number;
|
|
842
|
+
/** Selection outline, handles and marquee. */
|
|
843
|
+
accent: number;
|
|
844
|
+
/** Placeholder of a card whose picture has not landed yet and that has no ThumbHash or `color`. */
|
|
845
|
+
well: number;
|
|
846
|
+
/**
|
|
847
|
+
* Smart guides (alignment lines, spacing and size measures) and the label on their pills. Their own
|
|
848
|
+
* warm hue, apart from the accent of the selection, tuned for contrast on each canvas; the mode's
|
|
849
|
+
* default when absent.
|
|
850
|
+
*/
|
|
851
|
+
guide?: number;
|
|
852
|
+
/** Colour of the text on the guide pills. */
|
|
853
|
+
onGuide?: number;
|
|
854
|
+
}
|
|
855
|
+
/** The ready-made dark theme. */
|
|
856
|
+
declare const DARK_THEME: Theme;
|
|
857
|
+
/** The ready-made light theme. */
|
|
858
|
+
declare const LIGHT_THEME: Theme;
|
|
859
|
+
|
|
860
|
+
/** What the overlay draws for the selection. */
|
|
861
|
+
interface SelectionVisual {
|
|
862
|
+
frame: OutlineRect;
|
|
863
|
+
members: OutlineRect[];
|
|
864
|
+
handles: readonly Handle[];
|
|
865
|
+
showHandles: boolean;
|
|
866
|
+
}
|
|
867
|
+
/** The canvas layer that draws the selection, handles, marquee and guides. */
|
|
868
|
+
declare class OverlayLayer {
|
|
869
|
+
private readonly wake;
|
|
870
|
+
readonly container: Container<pixi_js.ContainerChild>;
|
|
871
|
+
private readonly g;
|
|
872
|
+
private theme;
|
|
873
|
+
private selection;
|
|
874
|
+
private hover;
|
|
875
|
+
private marquee;
|
|
876
|
+
private dirty;
|
|
877
|
+
private lastCam;
|
|
878
|
+
private readonly guides;
|
|
879
|
+
private readonly pts;
|
|
880
|
+
constructor(theme: Theme, wake?: () => void, dpr?: number);
|
|
881
|
+
setTheme(theme: Theme): void;
|
|
882
|
+
setDpr(dpr: number): void;
|
|
883
|
+
setSelection(s: SelectionVisual | null): void;
|
|
884
|
+
setHover(r: OutlineRect | null): void;
|
|
885
|
+
setMarquee(b: Aabb | null): void;
|
|
886
|
+
setGuides(g: readonly Guide[]): void;
|
|
887
|
+
get guideCount(): number;
|
|
888
|
+
get currentGuides(): Guide[];
|
|
889
|
+
get active(): boolean;
|
|
890
|
+
invalidate(): void;
|
|
891
|
+
draw(cam: Camera): boolean;
|
|
892
|
+
private rectPath;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/** Texture level of a card: 0 placeholder, 1 atlas cell, 2 own texture, 3 close zoom. */
|
|
896
|
+
type Level = 0 | 1 | 2 | 3;
|
|
897
|
+
|
|
898
|
+
/** A card as the stage tracks it. */
|
|
899
|
+
interface BoardCard {
|
|
900
|
+
id: number;
|
|
901
|
+
w: number;
|
|
902
|
+
h: number;
|
|
903
|
+
thumbhash: Uint8Array | undefined;
|
|
904
|
+
l1Url: string | undefined;
|
|
905
|
+
l2Url: string | undefined;
|
|
906
|
+
l3Url: string | undefined;
|
|
907
|
+
radius: number;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
/** Options of the texture manager. */
|
|
911
|
+
interface TextureManagerOptions {
|
|
912
|
+
budgetBytes: number;
|
|
913
|
+
workers: number;
|
|
914
|
+
workerUrl?: string | URL;
|
|
915
|
+
softCanvas?: boolean;
|
|
916
|
+
border?: string;
|
|
917
|
+
retireDelay?: number;
|
|
918
|
+
onRetire?: () => void;
|
|
919
|
+
onWake: () => void;
|
|
920
|
+
onError?: (e: TextureError) => void;
|
|
921
|
+
}
|
|
922
|
+
/** A texture failure, as the texture manager reports it. */
|
|
923
|
+
interface TextureError {
|
|
924
|
+
kind: 'texture' | 'worker';
|
|
925
|
+
slot?: number;
|
|
926
|
+
url?: string;
|
|
927
|
+
cause: unknown;
|
|
928
|
+
}
|
|
929
|
+
/** A texture the stage asks the manager for. */
|
|
930
|
+
interface WantedItem {
|
|
931
|
+
card: BoardCard;
|
|
932
|
+
level: Level;
|
|
933
|
+
dist: number;
|
|
934
|
+
bucket?: number;
|
|
935
|
+
}
|
|
936
|
+
/** Decodes pictures in workers and keeps them in atlases and own textures within a memory budget. */
|
|
937
|
+
declare class TextureManager {
|
|
938
|
+
private readonly opts;
|
|
939
|
+
private readonly texSys;
|
|
940
|
+
private readonly privateUpload;
|
|
941
|
+
private readonly gl;
|
|
942
|
+
private readonly workers;
|
|
943
|
+
private readonly workerLoad;
|
|
944
|
+
private readonly workerDead;
|
|
945
|
+
private liveWorkers;
|
|
946
|
+
private disposed;
|
|
947
|
+
private readonly reported;
|
|
948
|
+
private atlas0;
|
|
949
|
+
private atlas1;
|
|
950
|
+
private readonly cards;
|
|
951
|
+
private readonly reqs;
|
|
952
|
+
private readonly reqByKey;
|
|
953
|
+
private readonly failedAt;
|
|
954
|
+
private queue;
|
|
955
|
+
private decoded;
|
|
956
|
+
private readonly decodedKeys;
|
|
957
|
+
private readonly retire;
|
|
958
|
+
private evicted;
|
|
959
|
+
private rid;
|
|
960
|
+
private inflight;
|
|
961
|
+
private pageBytes;
|
|
962
|
+
private ownBytes;
|
|
963
|
+
private overSince;
|
|
964
|
+
private border;
|
|
965
|
+
readonly stats: {
|
|
966
|
+
uploads: number;
|
|
967
|
+
uploadFrames: number;
|
|
968
|
+
uploadMsTotal: number;
|
|
969
|
+
uploadMsMax: number;
|
|
970
|
+
uploadsLastFrame: number;
|
|
971
|
+
uploadMsLastFrame: number;
|
|
972
|
+
decodes: number;
|
|
973
|
+
decodeMsTotal: number;
|
|
974
|
+
fetchedBytes: number;
|
|
975
|
+
cancelled: number;
|
|
976
|
+
failed: number;
|
|
977
|
+
evictedL2: number;
|
|
978
|
+
evictedL3: number;
|
|
979
|
+
evictedL1: number;
|
|
980
|
+
overBudgetMsMax: number;
|
|
981
|
+
peakBytes: number;
|
|
982
|
+
};
|
|
983
|
+
constructor(renderer: WebGLRenderer, opts: TextureManagerOptions);
|
|
984
|
+
private makeAtlas0;
|
|
985
|
+
private makeAtlas1;
|
|
986
|
+
private spawnWorkers;
|
|
987
|
+
private onWorkerError;
|
|
988
|
+
get totalBytes(): number;
|
|
989
|
+
get workerCount(): number;
|
|
990
|
+
get pendingWork(): boolean;
|
|
991
|
+
get queued(): number;
|
|
992
|
+
get inflightCount(): number;
|
|
993
|
+
get retiredPending(): number;
|
|
994
|
+
pageCount(): {
|
|
995
|
+
l0: number;
|
|
996
|
+
l1: number;
|
|
997
|
+
};
|
|
998
|
+
ownCount(level: 2 | 3): number;
|
|
999
|
+
l2Count(): number;
|
|
1000
|
+
l3Count(): number;
|
|
1001
|
+
breakdown(): {
|
|
1002
|
+
pageBytes: number;
|
|
1003
|
+
l2Bytes: number;
|
|
1004
|
+
l3Bytes: number;
|
|
1005
|
+
pinnedBytes: number;
|
|
1006
|
+
pinned: number;
|
|
1007
|
+
};
|
|
1008
|
+
hasHeadroom(): boolean;
|
|
1009
|
+
has(card: BoardCard, level: Level): boolean;
|
|
1010
|
+
best(card: BoardCard, desired: Level): {
|
|
1011
|
+
tex: Texture;
|
|
1012
|
+
level: Level;
|
|
1013
|
+
} | null;
|
|
1014
|
+
hasOutgoing(card: BoardCard): boolean;
|
|
1015
|
+
touch(card: BoardCard, now: number, needsOwn: boolean): void;
|
|
1016
|
+
private urlOf;
|
|
1017
|
+
setWanted(items: WantedItem[], now?: number): void;
|
|
1018
|
+
private cancelReq;
|
|
1019
|
+
private pump;
|
|
1020
|
+
private onWorker;
|
|
1021
|
+
private reportTexture;
|
|
1022
|
+
frame(budgetMs: number, now: number): number[];
|
|
1023
|
+
takeEvicted(): number[];
|
|
1024
|
+
afterRender(): void;
|
|
1025
|
+
flushRetired(): void;
|
|
1026
|
+
private retireTexture;
|
|
1027
|
+
private releaseCell;
|
|
1028
|
+
private upload;
|
|
1029
|
+
private cardTex;
|
|
1030
|
+
forget(id: number): void;
|
|
1031
|
+
swapPictures(id: number, keep: boolean): void;
|
|
1032
|
+
dropOutgoing(card: BoardCard): void;
|
|
1033
|
+
private releaseOutgoing;
|
|
1034
|
+
setBorder(border: string): void;
|
|
1035
|
+
private createPage;
|
|
1036
|
+
private destroyPage;
|
|
1037
|
+
private bindPage;
|
|
1038
|
+
private uploadCell;
|
|
1039
|
+
private flushMips;
|
|
1040
|
+
keep: (id: number, level: 1 | 2 | 3) => boolean;
|
|
1041
|
+
enforceBudget(now: number): void;
|
|
1042
|
+
reset(): void;
|
|
1043
|
+
dispose(): void;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
/** What a card view is drawn with. */
|
|
1047
|
+
interface ViewCtx {
|
|
1048
|
+
theme: Theme;
|
|
1049
|
+
dpr: number;
|
|
1050
|
+
scale: number;
|
|
1051
|
+
wake(): void;
|
|
1052
|
+
invalidate(): void;
|
|
1053
|
+
}
|
|
1054
|
+
/** The Pixi view of one card. */
|
|
1055
|
+
interface CardView {
|
|
1056
|
+
readonly kind: CardKind;
|
|
1057
|
+
readonly variant: string;
|
|
1058
|
+
readonly display: Container;
|
|
1059
|
+
el: Card | null;
|
|
1060
|
+
mark: number;
|
|
1061
|
+
mount(el: Card, rect: WorldRect, ctx: ViewCtx): void;
|
|
1062
|
+
update(el: Card, props: readonly string[], rect: WorldRect, ctx: ViewCtx): void;
|
|
1063
|
+
setRect(rect: WorldRect): void;
|
|
1064
|
+
refresh(ctx: ViewCtx): void;
|
|
1065
|
+
setAlphaOverride(alpha: number): void;
|
|
1066
|
+
unmount(): void;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
/** Pools of card views, reused as cards enter and leave the viewport. */
|
|
1070
|
+
declare class ViewPools {
|
|
1071
|
+
private readonly pools;
|
|
1072
|
+
private created;
|
|
1073
|
+
private reused;
|
|
1074
|
+
acquire(kind: CardKind): CardView;
|
|
1075
|
+
release(view: CardView): void;
|
|
1076
|
+
stats(): {
|
|
1077
|
+
created: number;
|
|
1078
|
+
reused: number;
|
|
1079
|
+
pooled: number;
|
|
1080
|
+
};
|
|
1081
|
+
dispose(): void;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
/** What the stage reads from the store (`Store` satisfies it structurally). */
|
|
1085
|
+
interface StageStore {
|
|
1086
|
+
subscribe(listener: (e: StoreEvent) => void): () => void;
|
|
1087
|
+
get(id: CardId): Card | undefined;
|
|
1088
|
+
elements(): IterableIterator<Card>;
|
|
1089
|
+
searchInto(box: Aabb, out: Card[]): Card[];
|
|
1090
|
+
rank(id: CardId): number;
|
|
1091
|
+
readonly orderVersion: number;
|
|
1092
|
+
}
|
|
1093
|
+
/** Options of the stage. `CorkboardOptions.textures` takes the texture ones. */
|
|
1094
|
+
interface StageOptions {
|
|
1095
|
+
/**
|
|
1096
|
+
* GPU texture memory budget in bytes. Use ~128 MB on small devices.
|
|
1097
|
+
* @default 268435456 (256 MB)
|
|
1098
|
+
*/
|
|
1099
|
+
budgetBytes?: number;
|
|
1100
|
+
/**
|
|
1101
|
+
* Decode workers.
|
|
1102
|
+
* @default a quarter of the cores, 1..4
|
|
1103
|
+
*/
|
|
1104
|
+
workers?: number;
|
|
1105
|
+
/**
|
|
1106
|
+
* URL of the decode worker script, for pages whose CSP forbids `worker-src blob:` (the built-in worker is
|
|
1107
|
+
* inlined and started from a blob URL). Serve `@niccolofanton/corkboard/decode.worker.js` yourself and pass its URL here.
|
|
1108
|
+
*/
|
|
1109
|
+
workerUrl?: string | URL;
|
|
1110
|
+
/**
|
|
1111
|
+
* Bake the rounded corners in a software canvas in the workers. Measured about 2x slower to load.
|
|
1112
|
+
* @default false
|
|
1113
|
+
*/
|
|
1114
|
+
softCanvas?: boolean;
|
|
1115
|
+
/**
|
|
1116
|
+
* Per-frame texture upload budget, ms.
|
|
1117
|
+
* @default 4
|
|
1118
|
+
*/
|
|
1119
|
+
uploadBudgetMs?: number;
|
|
1120
|
+
/**
|
|
1121
|
+
* Overscan, as a fraction of the viewport added on every side.
|
|
1122
|
+
* @default 0.5
|
|
1123
|
+
*/
|
|
1124
|
+
overscan?: number;
|
|
1125
|
+
/** Wrap each render in an EXT_disjoint_timer_query_webgl2 query where the browser has one. */
|
|
1126
|
+
gpuTimer?: boolean;
|
|
1127
|
+
theme?: Theme;
|
|
1128
|
+
/** Show the background dot grid (default true). */
|
|
1129
|
+
grid?: boolean;
|
|
1130
|
+
/** Completed renders before a retired texture is destroyed (see retire.ts). */
|
|
1131
|
+
retireDelay?: number;
|
|
1132
|
+
/** Load Pixi's CSP-safe build (no `new Function`), for pages whose content security policy forbids eval. */
|
|
1133
|
+
cspSafe?: boolean;
|
|
1134
|
+
/**
|
|
1135
|
+
* The zoom range of the camera (default 0.05..4). A board of thousands of world px wide that is fitted
|
|
1136
|
+
* whole needs a lower minimum.
|
|
1137
|
+
*/
|
|
1138
|
+
minScale?: number;
|
|
1139
|
+
maxScale?: number;
|
|
1140
|
+
/**
|
|
1141
|
+
* A texture that would not load, a decode worker that died, the WebGL context lost: the board forwards
|
|
1142
|
+
* these to the host as its `error` event.
|
|
1143
|
+
*/
|
|
1144
|
+
onError?: (e: BoardErrorEvent) => void;
|
|
1145
|
+
/** The WebGL context was lost / came back (the textures are rebuilt by themselves). */
|
|
1146
|
+
onContextLost?: () => void;
|
|
1147
|
+
onContextRestored?: () => void;
|
|
1148
|
+
/**
|
|
1149
|
+
* Called once per rendered frame (not per idle tick) with the main-thread time of the render and the GPU
|
|
1150
|
+
* timer results that arrived meanwhile (those belong to earlier frames; empty without `gpuTimer`).
|
|
1151
|
+
*/
|
|
1152
|
+
onRender?: (e: {
|
|
1153
|
+
cpuMs: number;
|
|
1154
|
+
gpuMs: readonly number[];
|
|
1155
|
+
}) => void;
|
|
1156
|
+
/**
|
|
1157
|
+
* Cancels `Stage.create`: checked after each await, and when it aborts everything made so far is released
|
|
1158
|
+
* and the promise rejects with `signal.reason`.
|
|
1159
|
+
*/
|
|
1160
|
+
signal?: AbortSignal;
|
|
1161
|
+
}
|
|
1162
|
+
/** World px between background dots, also the grid cards snap to when grid snapping is on. */
|
|
1163
|
+
declare const GRID = 24;
|
|
1164
|
+
/** A preview / committed geometry in world space, owned by the stage while a gesture runs. */
|
|
1165
|
+
type PreviewRect = WorldRect;
|
|
1166
|
+
/** The WebGL stage of a board: Pixi renderer, camera, culling, texture pipeline and card views. The board owns one; reach it with `getInternals`. */
|
|
1167
|
+
declare class Stage {
|
|
1168
|
+
private readonly unparkTicker;
|
|
1169
|
+
readonly app: Application;
|
|
1170
|
+
readonly world: Container;
|
|
1171
|
+
readonly overlay: OverlayLayer;
|
|
1172
|
+
readonly cam: CameraController;
|
|
1173
|
+
readonly tm: TextureManager;
|
|
1174
|
+
readonly pools: ViewPools;
|
|
1175
|
+
private readonly renderer;
|
|
1176
|
+
private readonly bg;
|
|
1177
|
+
private readonly canvas;
|
|
1178
|
+
private readonly opts;
|
|
1179
|
+
private readonly ro;
|
|
1180
|
+
private readonly cleanups;
|
|
1181
|
+
private dpr;
|
|
1182
|
+
private readonly hostEl;
|
|
1183
|
+
private readonly onError;
|
|
1184
|
+
private readonly onContextLost;
|
|
1185
|
+
private readonly onContextRestored;
|
|
1186
|
+
private readonly onRender;
|
|
1187
|
+
private theme;
|
|
1188
|
+
private showGrid;
|
|
1189
|
+
private readonly ctx;
|
|
1190
|
+
private store;
|
|
1191
|
+
private unsub;
|
|
1192
|
+
private readonly views;
|
|
1193
|
+
private readonly mediaViews;
|
|
1194
|
+
private readonly hits;
|
|
1195
|
+
private mountQueue;
|
|
1196
|
+
private readonly queued;
|
|
1197
|
+
private queueSorted;
|
|
1198
|
+
private stamp;
|
|
1199
|
+
private mountedWin;
|
|
1200
|
+
private mountedScale;
|
|
1201
|
+
private orderSeen;
|
|
1202
|
+
private pendingAdded;
|
|
1203
|
+
private pendingRemoved;
|
|
1204
|
+
private pendingUpdated;
|
|
1205
|
+
private pendingReload;
|
|
1206
|
+
private slotOf;
|
|
1207
|
+
private freeSlots;
|
|
1208
|
+
private slotCount;
|
|
1209
|
+
private slotCard;
|
|
1210
|
+
private slotView;
|
|
1211
|
+
private slotLevel;
|
|
1212
|
+
private slotOnScreen;
|
|
1213
|
+
private slotOwn;
|
|
1214
|
+
private slotBaked;
|
|
1215
|
+
private slotBakedAspect;
|
|
1216
|
+
private l0Missing;
|
|
1217
|
+
private readonly hashCache;
|
|
1218
|
+
private readonly previews;
|
|
1219
|
+
private readonly hidden;
|
|
1220
|
+
private readonly posters;
|
|
1221
|
+
private readonly alphas;
|
|
1222
|
+
private readonly pinned;
|
|
1223
|
+
private raf;
|
|
1224
|
+
private lastTs;
|
|
1225
|
+
private renderedVersion;
|
|
1226
|
+
private dirty;
|
|
1227
|
+
private lodDirty;
|
|
1228
|
+
private lastLod;
|
|
1229
|
+
private settleTimer;
|
|
1230
|
+
private lost;
|
|
1231
|
+
private disposed;
|
|
1232
|
+
private beforeHooks;
|
|
1233
|
+
private frameHooks;
|
|
1234
|
+
private settleHooks;
|
|
1235
|
+
private readonly reportedHooks;
|
|
1236
|
+
private dprQuery;
|
|
1237
|
+
private renderErrorsTotal;
|
|
1238
|
+
private where;
|
|
1239
|
+
private rendersSinceRetire;
|
|
1240
|
+
private t0;
|
|
1241
|
+
private firstPaintMs;
|
|
1242
|
+
private l1CompleteMs;
|
|
1243
|
+
private counters;
|
|
1244
|
+
private readonly phase;
|
|
1245
|
+
private slowTicks;
|
|
1246
|
+
private reqMs;
|
|
1247
|
+
private lodPassMs;
|
|
1248
|
+
private nLodPass;
|
|
1249
|
+
private tickMs;
|
|
1250
|
+
private renderMs;
|
|
1251
|
+
private nTick;
|
|
1252
|
+
private nRender;
|
|
1253
|
+
private gpu;
|
|
1254
|
+
private gpuMs;
|
|
1255
|
+
private nGpu;
|
|
1256
|
+
static create(host: HTMLElement, options?: StageOptions): Promise<Stage>;
|
|
1257
|
+
private static createParked;
|
|
1258
|
+
private constructor();
|
|
1259
|
+
private setDpr;
|
|
1260
|
+
private watchDpr;
|
|
1261
|
+
private unwatchDpr;
|
|
1262
|
+
private onDprChange;
|
|
1263
|
+
get activeTheme(): Theme;
|
|
1264
|
+
get canvasEl(): HTMLCanvasElement;
|
|
1265
|
+
attach(store: StageStore): void;
|
|
1266
|
+
detach(): void;
|
|
1267
|
+
private onStoreEvent;
|
|
1268
|
+
private flushStore;
|
|
1269
|
+
private reloadAll;
|
|
1270
|
+
private clearViews;
|
|
1271
|
+
private allocSlot;
|
|
1272
|
+
private growSlots;
|
|
1273
|
+
private freeSlot;
|
|
1274
|
+
private hashOf;
|
|
1275
|
+
private fillCard;
|
|
1276
|
+
private urlsOf;
|
|
1277
|
+
private newCard;
|
|
1278
|
+
private mountMedia;
|
|
1279
|
+
private refreshCard;
|
|
1280
|
+
private syncCard;
|
|
1281
|
+
setPosterOverride(id: CardId, url: string | null): void;
|
|
1282
|
+
posterShown(id: CardId): boolean;
|
|
1283
|
+
private syncSlot;
|
|
1284
|
+
private rectOf;
|
|
1285
|
+
private forceMount;
|
|
1286
|
+
private inWindow;
|
|
1287
|
+
private enqueueMount;
|
|
1288
|
+
private drainMounts;
|
|
1289
|
+
private mount;
|
|
1290
|
+
private unmountId;
|
|
1291
|
+
private applyOverrides;
|
|
1292
|
+
setPreview(id: CardId, x: number, y: number, w: number, h: number, rot: number): void;
|
|
1293
|
+
clearPreview(id: CardId): void;
|
|
1294
|
+
clearPreviews(): void;
|
|
1295
|
+
previewRectOf(id: CardId): PreviewRect | undefined;
|
|
1296
|
+
get previewCount(): number;
|
|
1297
|
+
setHidden(id: CardId, hidden: boolean): void;
|
|
1298
|
+
setAlpha(id: CardId, alpha: number | null): void;
|
|
1299
|
+
pin(id: CardId, pinned: boolean): void;
|
|
1300
|
+
viewOf(id: CardId): CardView | null;
|
|
1301
|
+
isMounted(id: CardId): boolean;
|
|
1302
|
+
screenToWorld(sx: number, sy: number): {
|
|
1303
|
+
x: number;
|
|
1304
|
+
y: number;
|
|
1305
|
+
};
|
|
1306
|
+
worldToScreen(wx: number, wy: number): {
|
|
1307
|
+
x: number;
|
|
1308
|
+
y: number;
|
|
1309
|
+
};
|
|
1310
|
+
clientToLocal(cx: number, cy: number): {
|
|
1311
|
+
x: number;
|
|
1312
|
+
y: number;
|
|
1313
|
+
};
|
|
1314
|
+
get dprValue(): number;
|
|
1315
|
+
boundsOf(ids?: Iterable<CardId>): Rect | undefined;
|
|
1316
|
+
fit(animate?: boolean, pad?: number): void;
|
|
1317
|
+
fitRect(r: Rect | undefined | (() => Rect | undefined), animate?: boolean, pad?: number): void;
|
|
1318
|
+
private fitTarget;
|
|
1319
|
+
zoomToActual(): void;
|
|
1320
|
+
setCamera(c: Camera): void;
|
|
1321
|
+
setScaleRange(min: number, max: number): void;
|
|
1322
|
+
zoomBy(k: number): void;
|
|
1323
|
+
setTheme(theme: Theme): void;
|
|
1324
|
+
setGrid(on: boolean): void;
|
|
1325
|
+
private borderCss;
|
|
1326
|
+
private applyThemeToScene;
|
|
1327
|
+
requestFrame(): void;
|
|
1328
|
+
onBeforeFrame(hook: () => void): () => void;
|
|
1329
|
+
private rebuildBatches;
|
|
1330
|
+
onFrame(hook: (camChanged: boolean) => void): () => void;
|
|
1331
|
+
onSettle(hook: () => void): () => void;
|
|
1332
|
+
markDirty(): void;
|
|
1333
|
+
private tick;
|
|
1334
|
+
private settle;
|
|
1335
|
+
private uploadsPending;
|
|
1336
|
+
private runHook;
|
|
1337
|
+
private render;
|
|
1338
|
+
private emitRender;
|
|
1339
|
+
private applyCamera;
|
|
1340
|
+
private cullAndLod;
|
|
1341
|
+
private requery;
|
|
1342
|
+
private paintMedia;
|
|
1343
|
+
private applySlot;
|
|
1344
|
+
private lodPass;
|
|
1345
|
+
private repointEvicted;
|
|
1346
|
+
private trackProgress;
|
|
1347
|
+
private loseExt;
|
|
1348
|
+
private bindContextLoss;
|
|
1349
|
+
private reportTextureError;
|
|
1350
|
+
private dropAllTextures;
|
|
1351
|
+
private recoverTextures;
|
|
1352
|
+
loseContext(): void;
|
|
1353
|
+
restoreContext(): void;
|
|
1354
|
+
resetStats(): void;
|
|
1355
|
+
stats(): StageStats;
|
|
1356
|
+
dispose(): void;
|
|
1357
|
+
private makeBackground;
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
/** One window of frame-time samples from the frame-rate monitor. */
|
|
1361
|
+
interface FrameWindow {
|
|
1362
|
+
fps: number;
|
|
1363
|
+
slow: boolean;
|
|
1364
|
+
smooth: boolean;
|
|
1365
|
+
}
|
|
1366
|
+
/** What the frame-rate monitor needs from its environment (a seam for tests). */
|
|
1367
|
+
interface FrameRateDeps {
|
|
1368
|
+
raf?: (cb: (time: number) => void) => number;
|
|
1369
|
+
caf?: (id: number) => void;
|
|
1370
|
+
doc?: Document;
|
|
1371
|
+
burstWindows?: number;
|
|
1372
|
+
agreeWindows?: number;
|
|
1373
|
+
heartbeatMs?: number;
|
|
1374
|
+
}
|
|
1375
|
+
/** Measures the page's frame rate in short bursts, for the layers that shed load when it is slow. */
|
|
1376
|
+
declare class FrameRateMonitor {
|
|
1377
|
+
private readonly rafFn;
|
|
1378
|
+
private readonly cafFn;
|
|
1379
|
+
private readonly doc;
|
|
1380
|
+
private readonly burstWindows;
|
|
1381
|
+
private readonly agreeWindows;
|
|
1382
|
+
private readonly heartbeatMs;
|
|
1383
|
+
private run;
|
|
1384
|
+
private readonly loads;
|
|
1385
|
+
private readonly windowFns;
|
|
1386
|
+
private readonly startFns;
|
|
1387
|
+
private counted;
|
|
1388
|
+
private streak;
|
|
1389
|
+
private verdict;
|
|
1390
|
+
private beat;
|
|
1391
|
+
private peakFps;
|
|
1392
|
+
private disposed;
|
|
1393
|
+
private readonly cleanups;
|
|
1394
|
+
constructor(deps?: FrameRateDeps);
|
|
1395
|
+
get running(): boolean;
|
|
1396
|
+
get peak(): number;
|
|
1397
|
+
load(fn: () => boolean): () => void;
|
|
1398
|
+
onWindow(fn: (w: FrameWindow) => void): () => void;
|
|
1399
|
+
onStart(fn: () => void): () => void;
|
|
1400
|
+
poke(): void;
|
|
1401
|
+
dispose(): void;
|
|
1402
|
+
private canRun;
|
|
1403
|
+
private armBeat;
|
|
1404
|
+
private clearBeat;
|
|
1405
|
+
private start;
|
|
1406
|
+
private stop;
|
|
1407
|
+
private window;
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
/** Providers recognised from a URL. They get a nocookie / embed URL, a natural card shape and a poster that needs no server; any other URL is `'generic'`. */
|
|
1411
|
+
type EmbedProvider = 'youtube' | 'vimeo' | 'spotify' | 'codepen' | 'figma' | 'generic';
|
|
1412
|
+
/** What a URL says about an embed card, without a network request. */
|
|
1413
|
+
interface ParsedEmbed {
|
|
1414
|
+
/** The URL as the card keeps it: https, no credentials. */
|
|
1415
|
+
url: string;
|
|
1416
|
+
/** Host without `www.`, for the generated tile. */
|
|
1417
|
+
host: string;
|
|
1418
|
+
/** Which provider the URL belongs to. */
|
|
1419
|
+
provider: EmbedProvider;
|
|
1420
|
+
/** What the iframe loads when the card goes live. */
|
|
1421
|
+
iframeSrc: string;
|
|
1422
|
+
/** `aspect`: height / width of the card for this provider, when it has a natural one. */
|
|
1423
|
+
aspect?: number;
|
|
1424
|
+
/** Poster URLs that need no server, best first (each must be CORS-readable; the layer probes them). */
|
|
1425
|
+
posters: string[];
|
|
1426
|
+
/** A human label for the tile ("YouTube"). */
|
|
1427
|
+
label: string;
|
|
1428
|
+
}
|
|
1429
|
+
/** The human label of each provider, as shown on a tile. */
|
|
1430
|
+
declare const PROVIDER_LABEL: Record<EmbedProvider, string>;
|
|
1431
|
+
/**
|
|
1432
|
+
* Cleans a URL for an embed card: only http(s) URLs without credentials. `http:` is upgraded to `https:` except on
|
|
1433
|
+
* localhost (dev) and on an explicit port (a LAN or dev server there has no TLS). `javascript:`, `data:`, `file:`,
|
|
1434
|
+
* `blob:` and the rest are refused.
|
|
1435
|
+
*
|
|
1436
|
+
* @returns The normalised URL, or `null` when it cannot be an embed.
|
|
1437
|
+
*/
|
|
1438
|
+
declare function normalizeEmbedUrl(raw: string): string | null;
|
|
1439
|
+
/** `90`, `90s`, `1m30s`, `1h2m3s` -> seconds. */
|
|
1440
|
+
declare function parseTimestamp(t: string | null): number | null;
|
|
1441
|
+
/**
|
|
1442
|
+
* Parses a pasted URL into what an embed card needs: provider, iframe URL (`youtube.com/watch?v=x` becomes
|
|
1443
|
+
* `youtube-nocookie.com/embed/x`), poster candidates and the card's shape. Use it to validate input before it
|
|
1444
|
+
* becomes a card. Any other http(s) URL parses as `generic` (loaded as is, with the stricter sandbox).
|
|
1445
|
+
*
|
|
1446
|
+
* @returns `null` when the URL is not http(s).
|
|
1447
|
+
*/
|
|
1448
|
+
declare function parseEmbedUrl(raw: string): ParsedEmbed | null;
|
|
1449
|
+
/** The provider an iframe URL belongs to. */
|
|
1450
|
+
declare function providerOfIframeSrc(src: string): EmbedProvider;
|
|
1451
|
+
/** Whether a provider is one the library knows (its pages get the sandbox of a provider). */
|
|
1452
|
+
declare const isAllowlisted: (p: EmbedProvider) => boolean;
|
|
1453
|
+
|
|
1454
|
+
/** What a resolver may tell about a URL. Every field is optional; what it leaves out stays as the library derived it. */
|
|
1455
|
+
interface EmbedInfo {
|
|
1456
|
+
/** A CORS-readable image URL for the poster. */
|
|
1457
|
+
poster?: string;
|
|
1458
|
+
/** The URL to load in the iframe, when it is not the card's `url` (an oEmbed `iframe` src, say). */
|
|
1459
|
+
iframeSrc?: string;
|
|
1460
|
+
/** `aspect`: height / width of the card. */
|
|
1461
|
+
aspect?: number;
|
|
1462
|
+
/** Shown on the generated tile and as the iframe's `title`. */
|
|
1463
|
+
title?: string;
|
|
1464
|
+
/**
|
|
1465
|
+
* `false`: the page refuses framing. The card is a bookmark: it never goes live, and a double-click opens
|
|
1466
|
+
* the URL in a new tab.
|
|
1467
|
+
*/
|
|
1468
|
+
frameable?: boolean;
|
|
1469
|
+
}
|
|
1470
|
+
/**
|
|
1471
|
+
* A lookup on a server of yours for what the browser cannot know about a URL: oEmbed thumbnails and titles,
|
|
1472
|
+
* `og:image`, a screenshot, whether the page may be framed at all (`X-Frame-Options`, CSP `frame-ancestors`).
|
|
1473
|
+
* Cache it and re-host the poster CORS-enabled (a WebGL texture needs CORS).
|
|
1474
|
+
*
|
|
1475
|
+
* @example
|
|
1476
|
+
* ```ts
|
|
1477
|
+
* resolve: async (url) => {
|
|
1478
|
+
* const r = await fetch(`/api/embed-info?url=${encodeURIComponent(url)}`);
|
|
1479
|
+
* return r.ok ? ((await r.json()) as EmbedInfo) : null;
|
|
1480
|
+
* }
|
|
1481
|
+
* ```
|
|
1482
|
+
*/
|
|
1483
|
+
type EmbedResolver = (url: string) => Promise<EmbedInfo | null | undefined> | EmbedInfo | null | undefined;
|
|
1484
|
+
/** Everything the layer knows about a card's embed, settled (`board.embeds.info(id)`). */
|
|
1485
|
+
interface ResolvedEmbed {
|
|
1486
|
+
/** A page (`'url'`) or a snippet (`'html'`). */
|
|
1487
|
+
kind: 'url' | 'html';
|
|
1488
|
+
/** The provider, `'generic'` for a snippet or an unknown host. */
|
|
1489
|
+
provider: EmbedProvider;
|
|
1490
|
+
/** The card's URL (normalised), or '' for a snippet. */
|
|
1491
|
+
url: string;
|
|
1492
|
+
/** Host of the URL (`'html'` for a snippet). */
|
|
1493
|
+
host: string;
|
|
1494
|
+
/** What the tile says: the provider, else the host; the title if there is one. */
|
|
1495
|
+
label: string;
|
|
1496
|
+
/** The title, from the card or the resolver. */
|
|
1497
|
+
title?: string;
|
|
1498
|
+
/** The URL to load live. null: the card cannot go live (not an http(s) URL) or is a snippet. */
|
|
1499
|
+
iframeSrc: string | null;
|
|
1500
|
+
/** `false`: the page refuses framing; the card is a bookmark and never goes live. */
|
|
1501
|
+
frameable: boolean;
|
|
1502
|
+
/**
|
|
1503
|
+
* `true`: a snippet that kept navigating its frame away from its document (3 times within 10 s) and was
|
|
1504
|
+
* blocked; it stays on its poster, and `frameable` is `false` while this is set. Cleared when the card's content
|
|
1505
|
+
* changes. Absent otherwise.
|
|
1506
|
+
*/
|
|
1507
|
+
blocked?: boolean;
|
|
1508
|
+
/** `aspect`: height / width of the card, when the provider or the resolver gave one. */
|
|
1509
|
+
aspect?: number;
|
|
1510
|
+
/** Poster candidates, best first. */
|
|
1511
|
+
posters: string[];
|
|
1512
|
+
}
|
|
1513
|
+
/** The synchronous part: what the URL alone says. */
|
|
1514
|
+
declare function baseResolved(embed: EmbedSource): ResolvedEmbed;
|
|
1515
|
+
/**
|
|
1516
|
+
* A resolver's answer over the base. Untrusted: an `iframeSrc` that is not an http(s) URL is ignored, a
|
|
1517
|
+
* resolver cannot make a snippet frameable or a card load something the URL parser refused.
|
|
1518
|
+
*/
|
|
1519
|
+
declare function mergeResolved(base: ResolvedEmbed, info: EmbedInfo | null | undefined): ResolvedEmbed;
|
|
1520
|
+
/** Can the card go live? */
|
|
1521
|
+
declare const canGoLive: (r: ResolvedEmbed) => boolean;
|
|
1522
|
+
/**
|
|
1523
|
+
* Do two embeds describe the same content? (A card whose embed did not change keeps its poster and its live
|
|
1524
|
+
* frame.) The title and the resolution are labels, not content.
|
|
1525
|
+
*/
|
|
1526
|
+
declare const sameEmbed: (a: EmbedSource, b: EmbedSource) => boolean;
|
|
1527
|
+
|
|
1528
|
+
/** `-v2`: the entries of `-v1` were named by a different hash and can never be read again. */
|
|
1529
|
+
declare const PREVIEW_CACHE_NAME = "corkboard-previews-v2";
|
|
1530
|
+
/**
|
|
1531
|
+
* Where the rendered previews of HTML snippets are kept. `'memory'`: this page only. `'persistent'`: also in Cache Storage,
|
|
1532
|
+
* under the default name. `{ persistent: true, name }`: the same, in the Cache Storage entry `name` (to keep several boards apart, or to clear one without touching the others).
|
|
1533
|
+
*/
|
|
1534
|
+
type PreviewCacheMode = 'memory' | 'persistent' | {
|
|
1535
|
+
persistent: true;
|
|
1536
|
+
name?: string;
|
|
1537
|
+
};
|
|
1538
|
+
/**
|
|
1539
|
+
* Deletes the Cache Storage entry of the previews (default: the default name, and the one an older version
|
|
1540
|
+
* used). Resolves when done; never throws, and does nothing where Cache Storage does not exist.
|
|
1541
|
+
*/
|
|
1542
|
+
declare function clearPreviewCache(name?: string): Promise<void>;
|
|
1543
|
+
|
|
1544
|
+
/** How much a frame is trusted: a known `provider`, an `arbitrary` URL or an HTML `snippet`. */
|
|
1545
|
+
type SandboxProfile = 'provider' | 'arbitrary' | 'snippet';
|
|
1546
|
+
/**
|
|
1547
|
+
* Allowlisted providers: they run their player (scripts, their own origin's storage), post forms, open
|
|
1548
|
+
* popups and go presentation mode.
|
|
1549
|
+
*/
|
|
1550
|
+
declare const SANDBOX_PROVIDER = "allow-scripts allow-same-origin allow-forms allow-popups allow-presentation";
|
|
1551
|
+
/**
|
|
1552
|
+
* Any other URL: the same minus presentation.
|
|
1553
|
+
*
|
|
1554
|
+
* `allow-same-origin` is kept here on purpose: many sites break without their own cookies and storage.
|
|
1555
|
+
* The risk: the sandbox flags survive navigation inside the frame, so a link the user follows in interact
|
|
1556
|
+
* mode loads the next site with scripts AND its real origin (cookies, storage, credentialed requests to
|
|
1557
|
+
* its own server). It never reaches the board's page unless that page is itself served from the same origin
|
|
1558
|
+
* (see `appOrigin`, which is best-effort: it only looks at the URL the frame starts with). Never serve
|
|
1559
|
+
* user-controlled HTML on the board's origin. `arbitrarySameOrigin: false` drops the flag for every
|
|
1560
|
+
* arbitrary URL (opaque origin: no cookies, no storage), `isolatedHosts` for the hosts it names, at the cost
|
|
1561
|
+
* of the sites that need them.
|
|
1562
|
+
*/
|
|
1563
|
+
declare const SANDBOX_ARBITRARY = "allow-scripts allow-same-origin allow-forms allow-popups";
|
|
1564
|
+
/**
|
|
1565
|
+
* User HTML: scripts only. No `allow-same-origin` (the frame gets an opaque origin: no cookies, no storage,
|
|
1566
|
+
* no parent DOM), no forms, no popups.
|
|
1567
|
+
*/
|
|
1568
|
+
declare const SANDBOX_SNIPPET = "allow-scripts";
|
|
1569
|
+
/**
|
|
1570
|
+
* What an HTML snippet may load. `'images'`: pictures and fonts over https (still requests to any server, so a snippet can tell one it was shown).
|
|
1571
|
+
* `'none'`: only what it carries itself (`data:` and `blob:`): no subresource request (image, font, `fetch`...) is
|
|
1572
|
+
* allowed. Advisory, not isolation. The CSP is the policy of the snippet's own document, and a snippet can
|
|
1573
|
+
* navigate its own frame (`location.href = 'https://x/?...'`): that request always leaves (its URL can carry data
|
|
1574
|
+
* out), and the page that answers is not under the snippet CSP. Chromium additionally enforces the CSP on whatever
|
|
1575
|
+
* the frame navigates to (the iframe `csp` attribute, see `IframeSpec.csp`), so there the page does not run; other
|
|
1576
|
+
* engines run it, for as long as it likes. The layer's navigation guard is best effort against accidents (a link
|
|
1577
|
+
* clicked in interact mode), not a security boundary. Only serving snippets from a separate origin would be one.
|
|
1578
|
+
*/
|
|
1579
|
+
type SnippetNetwork = 'images' | 'none';
|
|
1580
|
+
/** The CSP of a snippet with `snippetNetwork: 'images'`. */
|
|
1581
|
+
declare const SNIPPET_CSP = "default-src 'none'; img-src data: https:; style-src 'unsafe-inline'; script-src 'unsafe-inline'; font-src https: data:";
|
|
1582
|
+
/** The CSP of a snippet with `snippetNetwork: 'none'`. */
|
|
1583
|
+
declare const SNIPPET_CSP_NONE = "default-src 'none'; img-src data: blob:; style-src 'unsafe-inline'; script-src 'unsafe-inline'; font-src data:";
|
|
1584
|
+
/** The CSP a snippet document carries for a `snippetNetwork` mode. */
|
|
1585
|
+
declare const snippetCsp: (network?: SnippetNetwork) => string;
|
|
1586
|
+
/** The referrer policy of every embed frame. */
|
|
1587
|
+
declare const REFERRER_POLICY = "strict-origin-when-cross-origin";
|
|
1588
|
+
/** The attributes an embed frame is created with: `sandbox`, `allow`, `referrerpolicy`, `src` or `srcdoc`. */
|
|
1589
|
+
interface IframeSpec {
|
|
1590
|
+
profile: SandboxProfile;
|
|
1591
|
+
provider: EmbedProvider;
|
|
1592
|
+
src?: string;
|
|
1593
|
+
srcdoc?: string;
|
|
1594
|
+
sandbox: string;
|
|
1595
|
+
csp?: string;
|
|
1596
|
+
allow: string;
|
|
1597
|
+
referrerPolicy: typeof REFERRER_POLICY;
|
|
1598
|
+
loading: 'lazy';
|
|
1599
|
+
title: string;
|
|
1600
|
+
}
|
|
1601
|
+
/**
|
|
1602
|
+
* `<!doctype html>` and the CSP `<meta>` come first so nothing in the snippet is parsed before the policy.
|
|
1603
|
+
* A snippet cannot loosen it (several policies only intersect), nor can it unset the sandbox.
|
|
1604
|
+
* Then the bootstrap (bootstrap.ts: pause / resume / snapshot for the layer), which runs before the snippet's
|
|
1605
|
+
* own scripts so it can gate requestAnimationFrame. The CSP already allows inline scripts, so it is unchanged.
|
|
1606
|
+
*
|
|
1607
|
+
* This policy is the document's own. The host page's CSP applies on top of it (a `srcdoc` frame inherits it):
|
|
1608
|
+
* a nonce-based `script-src` there blocks the bootstrap and the snippet's inline scripts.
|
|
1609
|
+
*/
|
|
1610
|
+
declare function snippetDocument(html: string, network?: SnippetNetwork): string;
|
|
1611
|
+
/**
|
|
1612
|
+
* Whether `url`'s host is one of `hosts` or a subdomain of one. Entries are normalised first (see
|
|
1613
|
+
* {@link normalizeIsolatedHost}; it throws for one that is no host). A domain entry covers itself and its
|
|
1614
|
+
* subdomains (`example.com` and `.example.com` and `*.example.com` alike); an IP literal covers exactly that
|
|
1615
|
+
* address and is never a suffix (`0.1` does not cover `127.0.0.1`).
|
|
1616
|
+
*/
|
|
1617
|
+
declare function hostIsolated(url: string, hosts: readonly string[] | undefined): boolean;
|
|
1618
|
+
/** What decides an embed frame's attributes. */
|
|
1619
|
+
interface IframeInput {
|
|
1620
|
+
source: EmbedSource;
|
|
1621
|
+
iframeSrc?: string;
|
|
1622
|
+
appOrigin?: string;
|
|
1623
|
+
arbitrarySameOrigin?: boolean;
|
|
1624
|
+
isolatedHosts?: readonly string[];
|
|
1625
|
+
snippetNetwork?: SnippetNetwork;
|
|
1626
|
+
}
|
|
1627
|
+
/** null: nothing safe to load (not an http(s) URL). */
|
|
1628
|
+
declare function iframeSpecFor(input: IframeInput): IframeSpec | null;
|
|
1629
|
+
|
|
1630
|
+
/**
|
|
1631
|
+
* Options of the embed layer (`CorkboardOptions.embeds`, `board.embeds.setOptions()`). Numeric limits accept `Infinity` for
|
|
1632
|
+
* "no cap". A page is a live iframe only while its card is in view and within these limits; the rest show their poster.
|
|
1633
|
+
*/
|
|
1634
|
+
interface EmbedOptions {
|
|
1635
|
+
/**
|
|
1636
|
+
* Live iframes at once on a mouse / pen device.
|
|
1637
|
+
* @default 12
|
|
1638
|
+
*/
|
|
1639
|
+
maxLive?: number;
|
|
1640
|
+
/**
|
|
1641
|
+
* Live iframes at once on a touch device.
|
|
1642
|
+
* @default 3
|
|
1643
|
+
*/
|
|
1644
|
+
maxLiveTouch?: number;
|
|
1645
|
+
/**
|
|
1646
|
+
* Mounted iframes at once (live + parked) on a mouse / pen device.
|
|
1647
|
+
* @default 24
|
|
1648
|
+
*/
|
|
1649
|
+
maxMounted?: number;
|
|
1650
|
+
/**
|
|
1651
|
+
* Mounted iframes at once (live + parked) on a touch device.
|
|
1652
|
+
* @default 6
|
|
1653
|
+
*/
|
|
1654
|
+
maxMountedTouch?: number;
|
|
1655
|
+
/**
|
|
1656
|
+
* Mounted iframes kept while their card is off screen (culled: hidden, not rendering, but alive), a subset of
|
|
1657
|
+
* `maxMounted`, on a mouse / pen device. The most recently seen stay; the rest are destroyed when the camera
|
|
1658
|
+
* settles. `Infinity`: only `maxMounted` limits them.
|
|
1659
|
+
* @default 64
|
|
1660
|
+
*/
|
|
1661
|
+
maxOffscreen?: number;
|
|
1662
|
+
/**
|
|
1663
|
+
* The same as `maxOffscreen`, on a touch device.
|
|
1664
|
+
* @default 12
|
|
1665
|
+
*/
|
|
1666
|
+
maxOffscreenTouch?: number;
|
|
1667
|
+
/**
|
|
1668
|
+
* How far past the viewport a card still counts as on screen, as a fraction of the viewport on each side. Frames in
|
|
1669
|
+
* that ring keep rendering, and cards entering it mount ahead of the pan.
|
|
1670
|
+
* @default 0.5
|
|
1671
|
+
*/
|
|
1672
|
+
cullMargin?: number;
|
|
1673
|
+
/**
|
|
1674
|
+
* A card goes live when it is at least this big on screen, in CSS px, or selected. Default 0: any card in view, up
|
|
1675
|
+
* to `maxLive`, the biggest on screen first. A number is the width; the height keeps a 320:200 ratio.
|
|
1676
|
+
*/
|
|
1677
|
+
minLivePx?: number | {
|
|
1678
|
+
w: number;
|
|
1679
|
+
h: number;
|
|
1680
|
+
};
|
|
1681
|
+
/**
|
|
1682
|
+
* Below this zoom no new iframe mounts. Interacting still flies in to a zoom of 0.25.
|
|
1683
|
+
* @default 0 (any zoom)
|
|
1684
|
+
*/
|
|
1685
|
+
minLiveScale?: number;
|
|
1686
|
+
/**
|
|
1687
|
+
* Async lookup for what the browser cannot know: oEmbed thumbnails and titles, og:image, screenshots,
|
|
1688
|
+
* and whether the page may be framed at all. Runs on a server of yours. See EmbedResolver. A failed or
|
|
1689
|
+
* timed-out lookup is reported through the `error` event (kind 'embed') and the card falls back to what the
|
|
1690
|
+
* URL says. `setOptions` takes it too (it cannot be unset): it applies to lookups started afterwards; cards
|
|
1691
|
+
* already resolved keep their result.
|
|
1692
|
+
*/
|
|
1693
|
+
resolve?: EmbedResolver;
|
|
1694
|
+
/**
|
|
1695
|
+
* Give up on `resolve` after this long, ms, and use what the URL says. `board.embeds.setOptions` changes it for lookups started afterwards.
|
|
1696
|
+
* @default 4000
|
|
1697
|
+
*/
|
|
1698
|
+
resolveTimeoutMs?: number;
|
|
1699
|
+
/**
|
|
1700
|
+
* The virtual screen a live page is laid out at; a card's `embed.resolution` wins.
|
|
1701
|
+
* @default '720p'
|
|
1702
|
+
*/
|
|
1703
|
+
resolution?: EmbedResolution;
|
|
1704
|
+
/**
|
|
1705
|
+
* Keep `allow-same-origin` in the sandbox of arbitrary (non-provider) URLs. Many sites break without their own
|
|
1706
|
+
* cookies and storage, but the frame then keeps its real origin across the navigations it makes. `false`: those
|
|
1707
|
+
* frames get an opaque origin. Providers and snippets are not affected.
|
|
1708
|
+
* @default true
|
|
1709
|
+
*/
|
|
1710
|
+
arbitrarySameOrigin?: boolean;
|
|
1711
|
+
/**
|
|
1712
|
+
* Hosts whose frames never get `allow-same-origin` (opaque origin: no cookies, no storage), whatever the
|
|
1713
|
+
* profile. Each entry is normalised once: a bare host (`example.com`, `bücher.de`, `.example.com`,
|
|
1714
|
+
* `*.example.com`, `example.com:443`, `::1`) or a full URL (its host is taken); case, port, a trailing dot and
|
|
1715
|
+
* punycode do not matter. A URL matches a domain entry when its host equals it or is a subdomain of it
|
|
1716
|
+
* (`example.com`, `.example.com` and `*.example.com` all cover `app.example.com`). An IP literal (v4 or v6)
|
|
1717
|
+
* matches exactly that address and is never a suffix. A blank entry matches nothing; an entry with a path,
|
|
1718
|
+
* credentials or a query, or that cannot be parsed, throws `CorkboardError` (`'invalid'`) from the constructor
|
|
1719
|
+
* or `setOptions`. Judged by the URL the frame starts with only: a redirect, or a link followed in interact
|
|
1720
|
+
* mode, can land on a host that is not listed. Changing it remounts the frames it affects.
|
|
1721
|
+
*/
|
|
1722
|
+
isolatedHosts?: readonly string[];
|
|
1723
|
+
/**
|
|
1724
|
+
* What a snippet (`embed.html`) may load: `'images'` is pictures and fonts over https, which are still requests
|
|
1725
|
+
* to any server; `'none'` is only `data:` and `blob:`: no subresource request (image, font, `fetch`...) is
|
|
1726
|
+
* allowed. It is advisory, not isolation: a snippet can still navigate its own frame
|
|
1727
|
+
* (`location.href = 'https://x/leak?...'`), and that request always leaves (its URL can carry data out); the CSP and
|
|
1728
|
+
* the sandbox cannot stop a self-navigation. The page that answers is not under the snippet CSP either, except
|
|
1729
|
+
* in Chromium, which enforces the CSP on the pages the frame navigates to (the iframe `csp` attribute) and does not
|
|
1730
|
+
* run them; on other engines it runs for as long as it likes. The layer's navigation guard (see `error`) only
|
|
1731
|
+
* catches accidents, such as a link clicked in interact mode. Only serving snippets from a separate origin would
|
|
1732
|
+
* isolate. Applies to frames mounted after the change; a frame that is already live keeps the policy it was mounted with.
|
|
1733
|
+
* @default 'images'
|
|
1734
|
+
*/
|
|
1735
|
+
snippetNetwork?: SnippetNetwork;
|
|
1736
|
+
/**
|
|
1737
|
+
* Start YouTube and Vimeo videos playing on their own, muted and looping, as soon as their card goes live. Changing it remounts the live frames. Snippets run their own scripts either way.
|
|
1738
|
+
* @default false
|
|
1739
|
+
*/
|
|
1740
|
+
autoplay?: boolean;
|
|
1741
|
+
/**
|
|
1742
|
+
* Iframes loading at once. New frames mount in chunks, nearest the centre of the view first, as earlier ones
|
|
1743
|
+
* finish, so a board full of embeds does not start hundreds of pages in the same frame. A frame that has not
|
|
1744
|
+
* loaded after 8 s gives its slot up. `Infinity`: no limit.
|
|
1745
|
+
* @default 6
|
|
1746
|
+
*/
|
|
1747
|
+
maxLoading?: number;
|
|
1748
|
+
/**
|
|
1749
|
+
* A mounted card whose short side on screen drops under this many CSS px is not worth rendering. A snippet frame is
|
|
1750
|
+
* frozen: it is snapshotted into the card's poster and hidden. A YouTube / Vimeo frame is paused. Both come back above
|
|
1751
|
+
* 1.4x this size, when selected or in interact mode. `0`: neither freezing nor size-based pausing (parked and culled frames are still paused).
|
|
1752
|
+
* @default 140
|
|
1753
|
+
*/
|
|
1754
|
+
freezePx?: number;
|
|
1755
|
+
/**
|
|
1756
|
+
* At most this many mounted, visible frames that can be paused (snippets, YouTube / Vimeo) animate at once; the
|
|
1757
|
+
* rest are paused, showing their last frame, biggest on screen and nearest the centre first. Pages that cannot be
|
|
1758
|
+
* paused (plain URLs, Spotify, CodePen, Figma) are not counted.
|
|
1759
|
+
* @default Infinity
|
|
1760
|
+
*/
|
|
1761
|
+
maxAnimating?: number;
|
|
1762
|
+
/**
|
|
1763
|
+
* Lower the number of animating frames while the page runs under 40 fps, and raise it back (up to `maxAnimating`) when it is smooth again. `false`: always `maxAnimating`.
|
|
1764
|
+
* @default true
|
|
1765
|
+
*/
|
|
1766
|
+
adaptive?: boolean;
|
|
1767
|
+
/**
|
|
1768
|
+
* Hidden frames that render snippets which have not been live, to give their cards a real picture instead of a generated tile. `0`: none, the tile stays until the card goes live.
|
|
1769
|
+
* @default 3
|
|
1770
|
+
*/
|
|
1771
|
+
previewWorkers?: number;
|
|
1772
|
+
/**
|
|
1773
|
+
* Where those pictures are kept: `'memory'` is this page only. `'persistent'` also keeps them in Cache Storage (at
|
|
1774
|
+
* most 1000, oldest dropped first), so a reload shows them at once; it leaves pictures of the snippets on the
|
|
1775
|
+
* visitor's disk, hence opt-in. Falls back to memory where Cache Storage cannot be used, or in an insecure context
|
|
1776
|
+
* (entries are named by a SHA-256, which needs `crypto.subtle`). `{ persistent: true, name }` uses the Cache Storage
|
|
1777
|
+
* entry `name` instead of the default `corkboard-previews-v2`. `Corkboard.clearPreviewCache(name?)` empties it.
|
|
1778
|
+
* @default 'memory'
|
|
1779
|
+
*/
|
|
1780
|
+
previewCache?: PreviewCacheMode;
|
|
1781
|
+
}
|
|
1782
|
+
/** The embed layer's events, on the board's `on()` (see `CorkboardEvents`). */
|
|
1783
|
+
interface EmbedEvents {
|
|
1784
|
+
/** Interact mode began (`active: true`) or ended on an embed card. */
|
|
1785
|
+
embedInteract: {
|
|
1786
|
+
id: CardId;
|
|
1787
|
+
active: boolean;
|
|
1788
|
+
};
|
|
1789
|
+
/** A card's iframe was mounted (`live: true`) or destroyed. */
|
|
1790
|
+
embedLive: {
|
|
1791
|
+
id: CardId;
|
|
1792
|
+
live: boolean;
|
|
1793
|
+
};
|
|
1794
|
+
/**
|
|
1795
|
+
* A card's embed was resolved. `poster` is a URL worth persisting (the host's own or a provider thumbnail), absent for a
|
|
1796
|
+
* generated tile or any blob URL this layer made (they die with the page).
|
|
1797
|
+
*/
|
|
1798
|
+
embedResolved: {
|
|
1799
|
+
id: CardId;
|
|
1800
|
+
provider: EmbedProvider;
|
|
1801
|
+
frameable: boolean;
|
|
1802
|
+
aspect?: number;
|
|
1803
|
+
title?: string;
|
|
1804
|
+
poster?: string;
|
|
1805
|
+
};
|
|
1806
|
+
/**
|
|
1807
|
+
* Something failed at runtime (`kind: 'embed'`): the resolver threw or timed out, or a snippet kept navigating its
|
|
1808
|
+
* frame away from its document (3 times within 10 s; each time the layer put its document back, and now the card
|
|
1809
|
+
* stays on its poster and `info()` says `blocked`). The navigation guard is best effort against accidents, such as a
|
|
1810
|
+
* link clicked in interact mode: it is not a security boundary (see `snippetNetwork`). The card keeps working on its
|
|
1811
|
+
* fallback (URL-derived info, or its poster).
|
|
1812
|
+
*/
|
|
1813
|
+
error: BoardErrorEvent;
|
|
1814
|
+
}
|
|
1815
|
+
/** What the embed layer is given by the board. */
|
|
1816
|
+
interface EmbedLayerDeps {
|
|
1817
|
+
root: HTMLElement;
|
|
1818
|
+
host: HTMLElement;
|
|
1819
|
+
store: Store;
|
|
1820
|
+
stage: Stage;
|
|
1821
|
+
emit<K extends keyof EmbedEvents>(type: K, payload: EmbedEvents[K]): void;
|
|
1822
|
+
nonce?: string;
|
|
1823
|
+
frameRate?: FrameRateMonitor;
|
|
1824
|
+
raf?: (cb: (time: number) => void) => number;
|
|
1825
|
+
caf?: (id: number) => void;
|
|
1826
|
+
rasterize?: (svg: string, w: number, h: number) => Promise<Blob | null>;
|
|
1827
|
+
}
|
|
1828
|
+
/** The live iframes of the embed cards: mounting, limits, parking, freezing, previews and interact mode. The board owns one; reach it with `getInternals`. */
|
|
1829
|
+
declare class EmbedLayer {
|
|
1830
|
+
private readonly root;
|
|
1831
|
+
private readonly host;
|
|
1832
|
+
private readonly store;
|
|
1833
|
+
private readonly stage;
|
|
1834
|
+
private readonly emit;
|
|
1835
|
+
private readonly doc;
|
|
1836
|
+
private readonly entries;
|
|
1837
|
+
private readonly frames;
|
|
1838
|
+
private readonly done;
|
|
1839
|
+
private readonly cleanups;
|
|
1840
|
+
private readonly timers;
|
|
1841
|
+
private readonly appOrigin;
|
|
1842
|
+
private opts;
|
|
1843
|
+
private selected;
|
|
1844
|
+
private touch;
|
|
1845
|
+
private moving;
|
|
1846
|
+
private planDirty;
|
|
1847
|
+
private interactId;
|
|
1848
|
+
private pendingInteract;
|
|
1849
|
+
private clock;
|
|
1850
|
+
private snapSeq;
|
|
1851
|
+
private snapping;
|
|
1852
|
+
private disposed;
|
|
1853
|
+
private readonly monitor;
|
|
1854
|
+
private readonly rasterize;
|
|
1855
|
+
private adaptiveN;
|
|
1856
|
+
private animatingIds;
|
|
1857
|
+
private candidates;
|
|
1858
|
+
private renderCount;
|
|
1859
|
+
private rankDirty;
|
|
1860
|
+
private smooth;
|
|
1861
|
+
private freezeMul;
|
|
1862
|
+
private freezeSmooth;
|
|
1863
|
+
private camSpeed;
|
|
1864
|
+
private lastCam;
|
|
1865
|
+
private readonly studios;
|
|
1866
|
+
private readonly previews;
|
|
1867
|
+
private previewScan;
|
|
1868
|
+
private readonly drawing;
|
|
1869
|
+
constructor(deps: EmbedLayerDeps, options?: EmbedOptions);
|
|
1870
|
+
get live(): ReadonlySet<CardId>;
|
|
1871
|
+
get parked(): ReadonlySet<CardId>;
|
|
1872
|
+
get culled(): ReadonlySet<CardId>;
|
|
1873
|
+
get frozen(): ReadonlySet<CardId>;
|
|
1874
|
+
get animating(): ReadonlySet<CardId>;
|
|
1875
|
+
get animatingBudget(): number;
|
|
1876
|
+
get freezeThreshold(): number;
|
|
1877
|
+
get loading(): ReadonlySet<CardId>;
|
|
1878
|
+
get interacting(): CardId | null;
|
|
1879
|
+
get maxLive(): number;
|
|
1880
|
+
get maxMounted(): number;
|
|
1881
|
+
get maxOffscreen(): number;
|
|
1882
|
+
info(id: CardId): Readonly<ResolvedEmbed> | null;
|
|
1883
|
+
get resolution(): EmbedResolution;
|
|
1884
|
+
get previewsPending(): number;
|
|
1885
|
+
setOptions(o: EmbedOptions): void;
|
|
1886
|
+
interact(id: CardId): boolean;
|
|
1887
|
+
exitInteract(): void;
|
|
1888
|
+
setSelection(ids: readonly CardId[]): void;
|
|
1889
|
+
setTouch(touch: boolean): void;
|
|
1890
|
+
onDblClick(id: CardId | null): void;
|
|
1891
|
+
setTheme(): void;
|
|
1892
|
+
onFrame(camChanged: boolean): void;
|
|
1893
|
+
private trackSpeed;
|
|
1894
|
+
onSettle(): void;
|
|
1895
|
+
dispose(): void;
|
|
1896
|
+
private onStore;
|
|
1897
|
+
private untrack;
|
|
1898
|
+
private trackCurrent;
|
|
1899
|
+
private track;
|
|
1900
|
+
private retitle;
|
|
1901
|
+
private settle;
|
|
1902
|
+
private specFor;
|
|
1903
|
+
private resolve;
|
|
1904
|
+
private needsPoster;
|
|
1905
|
+
private loadPoster;
|
|
1906
|
+
private makeTile;
|
|
1907
|
+
private applyPoster;
|
|
1908
|
+
private syncOverride;
|
|
1909
|
+
private retire;
|
|
1910
|
+
private requestPlan;
|
|
1911
|
+
private cullRect;
|
|
1912
|
+
private cards;
|
|
1913
|
+
private runPlan;
|
|
1914
|
+
private byPriority;
|
|
1915
|
+
private releaseSlot;
|
|
1916
|
+
private mountFrame;
|
|
1917
|
+
private guardLoad;
|
|
1918
|
+
private blockSnippet;
|
|
1919
|
+
private destroyFrame;
|
|
1920
|
+
private place;
|
|
1921
|
+
private cull;
|
|
1922
|
+
private canSnapCull;
|
|
1923
|
+
private finishCull;
|
|
1924
|
+
private uncull;
|
|
1925
|
+
private tune;
|
|
1926
|
+
private setFrozen;
|
|
1927
|
+
private syncPause;
|
|
1928
|
+
private post;
|
|
1929
|
+
private command;
|
|
1930
|
+
private pausable;
|
|
1931
|
+
private rerank;
|
|
1932
|
+
private setOverBudget;
|
|
1933
|
+
private onWindow;
|
|
1934
|
+
private adaptFreeze;
|
|
1935
|
+
private requestSnapshot;
|
|
1936
|
+
private dropRequest;
|
|
1937
|
+
private cancelSnapshot;
|
|
1938
|
+
private snapshotFailed;
|
|
1939
|
+
private markSnapFailed;
|
|
1940
|
+
private onMessage;
|
|
1941
|
+
private whenIdle;
|
|
1942
|
+
private showSnapshot;
|
|
1943
|
+
private awaitPoster;
|
|
1944
|
+
private posterShown;
|
|
1945
|
+
private wantsPreview;
|
|
1946
|
+
private previewPlan;
|
|
1947
|
+
private scanPreviews;
|
|
1948
|
+
private lookupPreview;
|
|
1949
|
+
private applyPreview;
|
|
1950
|
+
private nextPreview;
|
|
1951
|
+
private pumpPreviews;
|
|
1952
|
+
private makeStudio;
|
|
1953
|
+
private removeStudio;
|
|
1954
|
+
private startPreview;
|
|
1955
|
+
private askPreview;
|
|
1956
|
+
private endJob;
|
|
1957
|
+
private jobAlive;
|
|
1958
|
+
private previewFailed;
|
|
1959
|
+
private previewReply;
|
|
1960
|
+
private abortPreview;
|
|
1961
|
+
private stopPreviews;
|
|
1962
|
+
private flyIn;
|
|
1963
|
+
private activate;
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
/**
|
|
1967
|
+
* Which edge or centre cards line up on: the left / right edge, the vertical centre line (`'centerX'`), the top /
|
|
1968
|
+
* bottom edge, or the horizontal centre line (`'middleY'`). Measured on the cards' world bounding boxes (rotation included).
|
|
1969
|
+
*/
|
|
1970
|
+
type AlignMode = 'left' | 'centerX' | 'right' | 'top' | 'middleY' | 'bottom';
|
|
1971
|
+
/** A move: `dx`, `dy` in world px. */
|
|
1972
|
+
interface Delta {
|
|
1973
|
+
dx: number;
|
|
1974
|
+
dy: number;
|
|
1975
|
+
}
|
|
1976
|
+
/** Options of the align and distribute functions. */
|
|
1977
|
+
interface ArrangeGapOptions {
|
|
1978
|
+
gap?: number;
|
|
1979
|
+
}
|
|
1980
|
+
/**
|
|
1981
|
+
* The gap an arrange keeps between the selected items: the placement gap of their median width (the same
|
|
1982
|
+
* `placementGap` the grid and the placement of new cards use).
|
|
1983
|
+
*/
|
|
1984
|
+
declare function arrangeGap(widths: readonly number[]): number;
|
|
1985
|
+
/**
|
|
1986
|
+
* Slides boxes apart until none is on top of another or closer than `gap`: the minimal moves, the first
|
|
1987
|
+
* of every pile staying where it is. Items are settled one after the other; one that collides with the
|
|
1988
|
+
* ones already settled goes past them, to the right or down by whichever is shorter (`axis` forces
|
|
1989
|
+
* one). Only ever right or down, so a box that has cleared another stays clear of it and the loop ends.
|
|
1990
|
+
*
|
|
1991
|
+
* Order: the bands of `axis` (a row stays in its left-to-right order, a column in its top-to-bottom
|
|
1992
|
+
* one), else reading order (rows, then left to right); `inOrder` takes the items as given (the caller
|
|
1993
|
+
* ordered them on their boxes from before a move). Pure; returns the deltas of the boxes that moved.
|
|
1994
|
+
*/
|
|
1995
|
+
declare function separate(items: readonly {
|
|
1996
|
+
id: string;
|
|
1997
|
+
box: Aabb;
|
|
1998
|
+
}[], gap: number, axis?: 'x' | 'y', inOrder?: boolean): Map<string, Delta>;
|
|
1999
|
+
/**
|
|
2000
|
+
* Move every item so the chosen edge or centre matches the union box of the items. Items that
|
|
2001
|
+
* already are aligned are omitted. With `opts.gap` the items that would pile up on the aligned edge
|
|
2002
|
+
* slide along the other axis (a row aligned left becomes a column, in the row's order).
|
|
2003
|
+
*/
|
|
2004
|
+
declare function align(items: readonly {
|
|
2005
|
+
id: string;
|
|
2006
|
+
box: Aabb;
|
|
2007
|
+
}[], mode: AlignMode, opts?: ArrangeGapOptions): Map<string, Delta>;
|
|
2008
|
+
/**
|
|
2009
|
+
* Equal GAPS between consecutive boxes (not equal centres): sorted by position along the axis,
|
|
2010
|
+
* the two extremes stay and the ones between slide. Needs three or more items. With `opts.gap` the
|
|
2011
|
+
* gap is never smaller than that (a span too short for the boxes would overlap them): then the last
|
|
2012
|
+
* ones move on past the far extreme.
|
|
2013
|
+
*/
|
|
2014
|
+
declare function distribute(items: readonly {
|
|
2015
|
+
id: string;
|
|
2016
|
+
box: Aabb;
|
|
2017
|
+
}[], axis: 'x' | 'y', opts?: ArrangeGapOptions): Map<string, Delta>;
|
|
2018
|
+
/**
|
|
2019
|
+
* Equal width: every item takes the median width; aspect-locked items (cards) scale their
|
|
2020
|
+
* height along. Items that already have the median width are omitted.
|
|
2021
|
+
*/
|
|
2022
|
+
declare function equalWidth(items: readonly {
|
|
2023
|
+
id: string;
|
|
2024
|
+
w: number;
|
|
2025
|
+
h: number;
|
|
2026
|
+
aspectLocked: boolean;
|
|
2027
|
+
}[]): Map<string, {
|
|
2028
|
+
w: number;
|
|
2029
|
+
h: number;
|
|
2030
|
+
}>;
|
|
2031
|
+
|
|
2032
|
+
/** An event listener. */
|
|
2033
|
+
type Listener<T> = (payload: T) => void;
|
|
2034
|
+
/**
|
|
2035
|
+
* A tiny typed event emitter. A listener that throws is reported with `console.error` and does not stop the others.
|
|
2036
|
+
* An event emitted by a listener while another is being delivered waits until that one has reached every listener:
|
|
2037
|
+
* events are delivered one at a time, in the order they were emitted.
|
|
2038
|
+
*/
|
|
2039
|
+
declare class Emitter<M extends object> {
|
|
2040
|
+
private readonly map;
|
|
2041
|
+
private delivering;
|
|
2042
|
+
private readonly queue;
|
|
2043
|
+
on<K extends keyof M>(type: K, fn: Listener<M[K]>): () => void;
|
|
2044
|
+
off<K extends keyof M>(type: K, fn: Listener<M[K]>): void;
|
|
2045
|
+
emit<K extends keyof M>(type: K, payload: M[K]): void;
|
|
2046
|
+
private deliver;
|
|
2047
|
+
clear(): void;
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
/** Snapping while moving and resizing (`CorkboardOptions.snapping`, `board.setSnapping()`). */
|
|
2051
|
+
interface SnapSettings {
|
|
2052
|
+
/** Alignment lines, equal gaps and size matches against other cards, drawn as guides. */
|
|
2053
|
+
guides: boolean;
|
|
2054
|
+
/** Snap to the background dot grid where no guide snapped. */
|
|
2055
|
+
grid: boolean;
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
/**
|
|
2059
|
+
* Options of the pointer, touch and keyboard layer (`CorkboardOptions.interaction`). Wheel and pinch always pan
|
|
2060
|
+
* and zoom.
|
|
2061
|
+
*/
|
|
2062
|
+
interface InteractionOptions {
|
|
2063
|
+
/** Selecting, moving and resizing cards (default true). With false the layer only pans and zooms. */
|
|
2064
|
+
select?: boolean;
|
|
2065
|
+
/** What dragging the empty canvas does (default 'pan'); Shift does the other one. */
|
|
2066
|
+
emptyDrag?: 'pan' | 'marquee';
|
|
2067
|
+
/**
|
|
2068
|
+
* Keyboard shortcuts on the focused board.
|
|
2069
|
+
* @default true
|
|
2070
|
+
*/
|
|
2071
|
+
keyboard?: boolean;
|
|
2072
|
+
/**
|
|
2073
|
+
* Dragging, resizing, nudging and Delete write to the store (on release, on each key press) - one `change`
|
|
2074
|
+
* event per gesture, `source: 'user'` (default true). With false the layer NEVER writes: it emits `transform`
|
|
2075
|
+
* (the proposed rects and, for a drag, the cards to bring to the front) and `delete` (the ids) as proposals and
|
|
2076
|
+
* leaves the cards where they are, for a host that owns the state and applies them itself (controlled mode).
|
|
2077
|
+
* A card being dragged is still drawn on top until the release.
|
|
2078
|
+
*/
|
|
2079
|
+
commit?: boolean;
|
|
2080
|
+
/** Rubber-band selection (default true). With false a drag on the empty canvas always pans, Shift or not. */
|
|
2081
|
+
marquee?: boolean;
|
|
2082
|
+
/**
|
|
2083
|
+
* A drag on the empty canvas pans without clearing the selection first; a click that does not move still
|
|
2084
|
+
* clears it (default false: the selection is cleared as soon as the pointer goes down on empty canvas).
|
|
2085
|
+
*/
|
|
2086
|
+
keepSelectionOnPan?: boolean;
|
|
2087
|
+
/**
|
|
2088
|
+
* Draw the selection outline and the resize handles on the canvas (default true). With false the layer
|
|
2089
|
+
* still selects, moves and resizes (the handles keep their hit areas) but draws no selection: the host
|
|
2090
|
+
* draws its own. The hover outline is not part of it.
|
|
2091
|
+
*/
|
|
2092
|
+
selectionOutline?: boolean;
|
|
2093
|
+
}
|
|
2094
|
+
/** The events of the interaction layer; the board re-emits them (see `CorkboardEvents`). Points are in world coordinates. */
|
|
2095
|
+
interface InteractionEvents {
|
|
2096
|
+
/** The selection changed: the selected ids now. */
|
|
2097
|
+
selection: {
|
|
2098
|
+
ids: readonly CardId[];
|
|
2099
|
+
};
|
|
2100
|
+
/** The card under the pointer changed (`null`: none). Touch has no hover. */
|
|
2101
|
+
hover: {
|
|
2102
|
+
id: CardId | null;
|
|
2103
|
+
};
|
|
2104
|
+
/** A click (or tap): the card hit (`null`: the empty canvas), whether Shift was held, and the point in world coordinates. */
|
|
2105
|
+
click: {
|
|
2106
|
+
id: CardId | null;
|
|
2107
|
+
shift: boolean;
|
|
2108
|
+
x: number;
|
|
2109
|
+
y: number;
|
|
2110
|
+
};
|
|
2111
|
+
/** A double click (or double tap): the card hit (`null`: the empty canvas) and the point in world coordinates. */
|
|
2112
|
+
dblclick: {
|
|
2113
|
+
id: CardId | null;
|
|
2114
|
+
x: number;
|
|
2115
|
+
y: number;
|
|
2116
|
+
};
|
|
2117
|
+
/**
|
|
2118
|
+
* A drag, resize or arrow-key nudge ended: the new {@link Box} of every card it touched, in world px (already
|
|
2119
|
+
* written to the store, in one `change` event, unless `commit` is false: then it is a proposal).
|
|
2120
|
+
*/
|
|
2121
|
+
transform: {
|
|
2122
|
+
kind: 'move' | 'resize';
|
|
2123
|
+
rects: ReadonlyMap<CardId, Box>;
|
|
2124
|
+
/**
|
|
2125
|
+
* Set by a pointer drag: the cards it holds, bottom of the draw order first, which a drag brings to the front.
|
|
2126
|
+
* Already done when `commit` is on (it is part of the same `change`); with `commit: false` it is the proposal:
|
|
2127
|
+
* `board.bringToFront(toFront)`.
|
|
2128
|
+
*/
|
|
2129
|
+
toFront?: readonly CardId[];
|
|
2130
|
+
};
|
|
2131
|
+
/** A gesture started or ended: its kind, or `null` when it ended. */
|
|
2132
|
+
gesture: {
|
|
2133
|
+
kind: 'pan' | 'marquee' | 'drag' | 'resize' | 'pinch' | null;
|
|
2134
|
+
};
|
|
2135
|
+
/** The pointer device changed between touch and mouse / pen (`touch: true`: touch). */
|
|
2136
|
+
touch: {
|
|
2137
|
+
touch: boolean;
|
|
2138
|
+
};
|
|
2139
|
+
/**
|
|
2140
|
+
* Delete was pressed with a selection: the ids (locked cards excluded). With `commit` on they were removed
|
|
2141
|
+
* just before this fires; with `commit: false` nothing was, it is a proposal.
|
|
2142
|
+
*/
|
|
2143
|
+
delete: {
|
|
2144
|
+
ids: readonly CardId[];
|
|
2145
|
+
};
|
|
2146
|
+
}
|
|
2147
|
+
/** The pointer, touch and keyboard layer of a board. The board owns one; reach it with `getInternals`. */
|
|
2148
|
+
declare class Interaction {
|
|
2149
|
+
private readonly host;
|
|
2150
|
+
private readonly stage;
|
|
2151
|
+
private readonly store;
|
|
2152
|
+
readonly events: Emitter<InteractionEvents>;
|
|
2153
|
+
selection: readonly CardId[];
|
|
2154
|
+
readonly snapping: SnapSettings;
|
|
2155
|
+
private readonly opts;
|
|
2156
|
+
private pendingOpts;
|
|
2157
|
+
private gesture;
|
|
2158
|
+
private readonly pointers;
|
|
2159
|
+
private pointerType;
|
|
2160
|
+
private hoverId;
|
|
2161
|
+
private selDirty;
|
|
2162
|
+
private spaceDown;
|
|
2163
|
+
private panMode;
|
|
2164
|
+
private handles;
|
|
2165
|
+
private handlesScale;
|
|
2166
|
+
private hadPreviews;
|
|
2167
|
+
private lastMods;
|
|
2168
|
+
private readonly cleanups;
|
|
2169
|
+
private disposed;
|
|
2170
|
+
constructor(host: HTMLElement, stage: Stage, store: Store, snapping: SnapSettings, options?: InteractionOptions);
|
|
2171
|
+
setSelection(ids: readonly CardId[]): void;
|
|
2172
|
+
setOptions(o: Partial<InteractionOptions>): void;
|
|
2173
|
+
private applyOptions;
|
|
2174
|
+
setPanMode(on: boolean): void;
|
|
2175
|
+
private dropRemoved;
|
|
2176
|
+
private onFrame;
|
|
2177
|
+
private selectionVisual;
|
|
2178
|
+
private bind;
|
|
2179
|
+
private local;
|
|
2180
|
+
private mods;
|
|
2181
|
+
private onWheel;
|
|
2182
|
+
private startGesture;
|
|
2183
|
+
private endGesture;
|
|
2184
|
+
private onDown;
|
|
2185
|
+
private beginPan;
|
|
2186
|
+
private onMove;
|
|
2187
|
+
private beginDrag;
|
|
2188
|
+
private updateDrag;
|
|
2189
|
+
private updateResize;
|
|
2190
|
+
private onUp;
|
|
2191
|
+
private emitClick;
|
|
2192
|
+
private onDblClick;
|
|
2193
|
+
private cancelGesture;
|
|
2194
|
+
private cancelDrag;
|
|
2195
|
+
private cancelResize;
|
|
2196
|
+
private commit;
|
|
2197
|
+
private commitDrag;
|
|
2198
|
+
private commitResize;
|
|
2199
|
+
private updateHover;
|
|
2200
|
+
private setHover;
|
|
2201
|
+
private onKey;
|
|
2202
|
+
dispose(): void;
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
/**
|
|
2206
|
+
* How videos play. `'always'`: every video card in view plays on its own, muted and looping (a pool, limited by
|
|
2207
|
+
* `maxPlaying`); hover and selection still play a card with sound when `muted` is false. `'hover'`: a hovered card plays
|
|
2208
|
+
* after a short delay, a single selected card plays at once. `'off'`: nothing plays, video cards are their poster.
|
|
2209
|
+
*/
|
|
2210
|
+
type VideoMode = 'always' | 'hover' | 'off';
|
|
2211
|
+
/** Options of the video layer (`CorkboardOptions.video`, `board.video.setOptions()`). A card plays only while it is on screen and the camera is still. */
|
|
2212
|
+
interface VideoOptions {
|
|
2213
|
+
/**
|
|
2214
|
+
* How videos play.
|
|
2215
|
+
* @default 'always'
|
|
2216
|
+
*/
|
|
2217
|
+
mode?: VideoMode;
|
|
2218
|
+
/**
|
|
2219
|
+
* Loop the videos.
|
|
2220
|
+
* @default true
|
|
2221
|
+
*/
|
|
2222
|
+
loop?: boolean;
|
|
2223
|
+
/**
|
|
2224
|
+
* Mute the videos. Only a hovered / selected card can play with sound, and only in a page that has had a user gesture (autoplay policy).
|
|
2225
|
+
* @default true
|
|
2226
|
+
*/
|
|
2227
|
+
muted?: boolean;
|
|
2228
|
+
/**
|
|
2229
|
+
* `mode: 'always'`: a card plays on its own only if its long side is at least this many CSS px on screen. Smaller ones stay a thumbnail.
|
|
2230
|
+
* @default 160
|
|
2231
|
+
*/
|
|
2232
|
+
minPlayPx?: number;
|
|
2233
|
+
/**
|
|
2234
|
+
* `mode: 'always'`: at most this many cards play at once on a mouse / pen device. The biggest and most central cards win.
|
|
2235
|
+
* @default 8
|
|
2236
|
+
*/
|
|
2237
|
+
maxPlaying?: number;
|
|
2238
|
+
/**
|
|
2239
|
+
* `mode: 'always'`: at most this many cards play at once on a touch device.
|
|
2240
|
+
* @default 2
|
|
2241
|
+
*/
|
|
2242
|
+
maxPlayingTouch?: number;
|
|
2243
|
+
}
|
|
2244
|
+
/** What the video layer is given by the board. */
|
|
2245
|
+
interface VideoLayerDeps {
|
|
2246
|
+
root: HTMLElement;
|
|
2247
|
+
store: Store;
|
|
2248
|
+
stage: Stage;
|
|
2249
|
+
frameRate?: FrameRateMonitor;
|
|
2250
|
+
nonce?: string;
|
|
2251
|
+
onError?: (e: BoardErrorEvent) => void;
|
|
2252
|
+
}
|
|
2253
|
+
/** Plays the videos of the video cards: the hover / selection overlay and the always-playing pool. The board owns one; reach it with `getInternals`. */
|
|
2254
|
+
declare class VideoLayer {
|
|
2255
|
+
private readonly overlay;
|
|
2256
|
+
private readonly controller;
|
|
2257
|
+
private readonly ambient;
|
|
2258
|
+
private readonly store;
|
|
2259
|
+
private readonly stage;
|
|
2260
|
+
private mode;
|
|
2261
|
+
private loop;
|
|
2262
|
+
private muted;
|
|
2263
|
+
private paused;
|
|
2264
|
+
private hidden;
|
|
2265
|
+
private readonly cleanups;
|
|
2266
|
+
constructor(deps: VideoLayerDeps, options?: VideoOptions);
|
|
2267
|
+
setOptions(o: VideoOptions): void;
|
|
2268
|
+
get playing(): ReadonlySet<CardId>;
|
|
2269
|
+
get isPaused(): boolean;
|
|
2270
|
+
get playingBudget(): number;
|
|
2271
|
+
setHover(id: CardId | null): void;
|
|
2272
|
+
setSelection(ids: readonly CardId[]): void;
|
|
2273
|
+
setTouch(touch: boolean): void;
|
|
2274
|
+
setPaused(paused: boolean): void;
|
|
2275
|
+
onFrame(camChanged: boolean): void;
|
|
2276
|
+
onSettle(): void;
|
|
2277
|
+
dispose(): void;
|
|
2278
|
+
private follow;
|
|
2279
|
+
private setHidden;
|
|
2280
|
+
private showOverlay;
|
|
2281
|
+
private targetOf;
|
|
2282
|
+
private candidates;
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
/** Options of the camera moves that can animate. */
|
|
2286
|
+
interface CameraMoveOptions {
|
|
2287
|
+
/**
|
|
2288
|
+
* Animate the move.
|
|
2289
|
+
* @default true
|
|
2290
|
+
*/
|
|
2291
|
+
animate?: boolean;
|
|
2292
|
+
/**
|
|
2293
|
+
* Screen px kept free around the target.
|
|
2294
|
+
* @default 48
|
|
2295
|
+
*/
|
|
2296
|
+
padding?: number;
|
|
2297
|
+
}
|
|
2298
|
+
/**
|
|
2299
|
+
* Camera control, `board.camera`. A camera is `{ tx, ty, scale }`: a world point (wx, wy) shows at
|
|
2300
|
+
* (tx + wx * scale, ty + wy * scale) in host-local CSS px. The scale stays within the `camera` option's range.
|
|
2301
|
+
* Every method throws a `CorkboardError` (`'disposed'`) after `dispose()`.
|
|
2302
|
+
*/
|
|
2303
|
+
interface CameraApi {
|
|
2304
|
+
/** The camera now (a copy). */
|
|
2305
|
+
get(): Camera;
|
|
2306
|
+
/**
|
|
2307
|
+
* Jumps to a camera, without animation. The scale is held to the zoom range.
|
|
2308
|
+
*
|
|
2309
|
+
* @throws {CorkboardError} `'invalid'` when `tx` or `ty` is not a finite number or `scale` is not a finite
|
|
2310
|
+
* number > 0.
|
|
2311
|
+
*/
|
|
2312
|
+
set(c: Camera): void;
|
|
2313
|
+
/**
|
|
2314
|
+
* Fits the given cards (default: all) in the view. With nothing to fit (an empty board, or none of the ids is
|
|
2315
|
+
* a card) the camera stays where it is.
|
|
2316
|
+
*
|
|
2317
|
+
* @param ids One id or a list of ids.
|
|
2318
|
+
* @throws {CorkboardError} `'invalid'` for ids of the wrong type or a bad `padding` (not a finite number >= 0).
|
|
2319
|
+
*/
|
|
2320
|
+
fit(ids?: CardId | readonly CardId[], o?: CameraMoveOptions): void;
|
|
2321
|
+
/**
|
|
2322
|
+
* Fits a world rectangle in the view.
|
|
2323
|
+
*
|
|
2324
|
+
* @throws {CorkboardError} `'invalid'` unless the four corners are finite numbers (and `padding` is >= 0).
|
|
2325
|
+
*/
|
|
2326
|
+
zoomTo(r: Rect, o?: CameraMoveOptions): void;
|
|
2327
|
+
/**
|
|
2328
|
+
* Multiplies the zoom by `k` about the middle of the view (animated; clamped to the zoom range).
|
|
2329
|
+
*
|
|
2330
|
+
* @throws {CorkboardError} `'invalid'` unless `k` is a finite number > 0.
|
|
2331
|
+
*/
|
|
2332
|
+
zoomBy(k: number): void;
|
|
2333
|
+
/** Zooms to 100 % about the middle of the view. */
|
|
2334
|
+
actual(): void;
|
|
2335
|
+
/**
|
|
2336
|
+
* Centres the view on a world point, optionally at a given zoom (default: the current one).
|
|
2337
|
+
*
|
|
2338
|
+
* @throws {CorkboardError} `'invalid'` unless `x` and `y` are finite and `scale`, when given, is finite and > 0.
|
|
2339
|
+
*/
|
|
2340
|
+
center(x: number, y: number, scale?: number, o?: CameraMoveOptions): void;
|
|
2341
|
+
/**
|
|
2342
|
+
* Changes the zoom range (the `camera` option's `minScale` / `maxScale`). A camera outside the new range is
|
|
2343
|
+
* brought into it about the middle of the view.
|
|
2344
|
+
*
|
|
2345
|
+
* @throws {CorkboardError} `'invalid'` unless `0 < min <= max` and both are finite.
|
|
2346
|
+
*/
|
|
2347
|
+
setRange(min: number, max: number): void;
|
|
2348
|
+
/** The world rectangle in view. */
|
|
2349
|
+
visible(): Rect;
|
|
2350
|
+
/** Converts host-local CSS px to world coordinates. Throws `'invalid'` for a non-finite number. */
|
|
2351
|
+
screenToWorld(x: number, y: number): {
|
|
2352
|
+
x: number;
|
|
2353
|
+
y: number;
|
|
2354
|
+
};
|
|
2355
|
+
/** Converts world coordinates to host-local CSS px. Throws `'invalid'` for a non-finite number. */
|
|
2356
|
+
worldToScreen(x: number, y: number): {
|
|
2357
|
+
x: number;
|
|
2358
|
+
y: number;
|
|
2359
|
+
};
|
|
2360
|
+
}
|
|
2361
|
+
/** Options of the arrange methods of {@link LayoutApi}. */
|
|
2362
|
+
interface ArrangeOptions {
|
|
2363
|
+
/**
|
|
2364
|
+
* Animate the move.
|
|
2365
|
+
* @default true; elements far from the viewport jump
|
|
2366
|
+
*/
|
|
2367
|
+
animate?: boolean;
|
|
2368
|
+
/**
|
|
2369
|
+
* Duration of the animation, ms.
|
|
2370
|
+
* @default 320
|
|
2371
|
+
*/
|
|
2372
|
+
duration?: number;
|
|
2373
|
+
}
|
|
2374
|
+
/** Options of `layout.tidy` and `layout.masonry`. */
|
|
2375
|
+
interface GridOptions extends ArrangeOptions {
|
|
2376
|
+
/** Space between cards, world px (default: a tenth of the card width, 12..48). */
|
|
2377
|
+
gap?: number;
|
|
2378
|
+
/** Number of columns (default: a roughly square block, at most 10). */
|
|
2379
|
+
columns?: number;
|
|
2380
|
+
}
|
|
2381
|
+
/** Options of `layout.masonry`. */
|
|
2382
|
+
interface MasonryOptions extends GridOptions {
|
|
2383
|
+
/** Width of every card, world px (default: the median width). */
|
|
2384
|
+
width?: number;
|
|
2385
|
+
}
|
|
2386
|
+
/**
|
|
2387
|
+
* Auto layout, `board.layout`. Every method takes the ids to arrange (one id or a list; default: all) and writes
|
|
2388
|
+
* the result to the store in one batch, right away (one `change` event with `source: 'api'`): the animation only
|
|
2389
|
+
* changes how the cards are drawn. Locked cards stay where they are.
|
|
2390
|
+
*
|
|
2391
|
+
* Every method throws a `CorkboardError` (`'invalid'`) before writing anything for ids of the wrong type, an
|
|
2392
|
+
* unknown `mode` / `axis`, or an option out of range: `gap` and `duration` must be finite numbers >= 0, `columns`
|
|
2393
|
+
* an integer >= 1, `width` a finite number > 0, `animate` a boolean.
|
|
2394
|
+
*/
|
|
2395
|
+
interface LayoutApi {
|
|
2396
|
+
/**
|
|
2397
|
+
* Reorders the cards into a masonry grid in reading order (rows top to bottom, left to right). Cards take the
|
|
2398
|
+
* median width and keep their aspect; the block stays anchored at its current top-left.
|
|
2399
|
+
*/
|
|
2400
|
+
tidy(ids?: CardId | readonly CardId[], opts?: GridOptions): void;
|
|
2401
|
+
/**
|
|
2402
|
+
* Packs the cards into columns in the order given (the store's draw order by default): each goes into the
|
|
2403
|
+
* shortest column. Unlike `tidy` nothing is reordered by position.
|
|
2404
|
+
*/
|
|
2405
|
+
masonry(ids?: CardId | readonly CardId[], opts?: MasonryOptions): void;
|
|
2406
|
+
/** Aligns the cards' edges or centres to one line (see {@link AlignMode}); cards that would overlap slide along the other axis. */
|
|
2407
|
+
align(mode: AlignMode, ids?: CardId | readonly CardId[], opts?: ArrangeOptions): void;
|
|
2408
|
+
/** Equal gaps between the cards along an axis (three or more). */
|
|
2409
|
+
distribute(axis: 'x' | 'y', ids?: CardId | readonly CardId[], opts?: ArrangeOptions): void;
|
|
2410
|
+
/**
|
|
2411
|
+
* Every card takes the median width; aspect-locked cards scale their height along. A card that grew pushes its
|
|
2412
|
+
* neighbours away (the arrange gap), as with align and distribute.
|
|
2413
|
+
*/
|
|
2414
|
+
equalWidth(ids?: CardId | readonly CardId[], opts?: ArrangeOptions): void;
|
|
2415
|
+
}
|
|
2416
|
+
/**
|
|
2417
|
+
* The live iframes of the embed cards, `board.embeds`. The counters (live, parked, culled, frozen...) are in
|
|
2418
|
+
* `board.stats().embeds`.
|
|
2419
|
+
*/
|
|
2420
|
+
interface EmbedsApi {
|
|
2421
|
+
/** Ids of the cards that hold a mounted iframe now (active and parked). */
|
|
2422
|
+
readonly live: ReadonlySet<CardId>;
|
|
2423
|
+
/** The card in interact mode (`null`: none). */
|
|
2424
|
+
readonly interacting: CardId | null;
|
|
2425
|
+
/** What is known about a card's embed (`undefined`: not an embed card, or no such card). */
|
|
2426
|
+
info(id: CardId): Readonly<ResolvedEmbed> | undefined;
|
|
2427
|
+
/**
|
|
2428
|
+
* Changes the embed options at any time (live limits, `resolution`, the security options...); fields left
|
|
2429
|
+
* out keep their value. See {@link EmbedOptions} for which apply to frames already mounted.
|
|
2430
|
+
*/
|
|
2431
|
+
setOptions(o: Partial<EmbedOptions>): void;
|
|
2432
|
+
/**
|
|
2433
|
+
* Interact mode on a card: makes it live (whatever its size) and gives it pointer events. A card the page refuses
|
|
2434
|
+
* to frame opens its URL in a new tab instead.
|
|
2435
|
+
*
|
|
2436
|
+
* @returns `false` when there is nothing to do.
|
|
2437
|
+
*/
|
|
2438
|
+
interact(id: CardId): boolean;
|
|
2439
|
+
/** Leaves interact mode (does nothing when no card is in it). */
|
|
2440
|
+
exitInteract(): void;
|
|
2441
|
+
}
|
|
2442
|
+
/** Video playback, `board.video`. The counters are also in `board.stats().video`. */
|
|
2443
|
+
interface VideoApi {
|
|
2444
|
+
/** Ids of the cards whose video plays now. */
|
|
2445
|
+
readonly playing: ReadonlySet<CardId>;
|
|
2446
|
+
/**
|
|
2447
|
+
* How many clips the always-playing pool may run now: `video.maxPlaying`, lowered while the page runs slow
|
|
2448
|
+
* and raised back when it is smooth (compare with `playing.size`). Can be `Infinity`.
|
|
2449
|
+
*/
|
|
2450
|
+
readonly budget: number;
|
|
2451
|
+
/** Whether {@link VideoApi.setPaused} paused the videos. */
|
|
2452
|
+
readonly paused: boolean;
|
|
2453
|
+
/** Pauses every video (a lightbox open over the canvas, say), or lets them play again. */
|
|
2454
|
+
setPaused(paused: boolean): void;
|
|
2455
|
+
/** Changes the video options at any time; fields left out keep their value. */
|
|
2456
|
+
setOptions(o: Partial<VideoOptions>): void;
|
|
2457
|
+
}
|
|
2458
|
+
/**
|
|
2459
|
+
* What a host may drive on the pointer, touch and keyboard layer, `board.interaction` (`null` when
|
|
2460
|
+
* `interaction: false`). Selection is `board.select()`, events are `board.on()`.
|
|
2461
|
+
*/
|
|
2462
|
+
interface InteractionApi {
|
|
2463
|
+
/**
|
|
2464
|
+
* A hand tool the host can switch (a toolbar button, a key of its own): while on, a left-button drag pans the
|
|
2465
|
+
* canvas wherever it starts, over a card included, exactly as with Space held.
|
|
2466
|
+
*/
|
|
2467
|
+
setPanMode(on: boolean): void;
|
|
2468
|
+
/**
|
|
2469
|
+
* Changes the interaction options; fields left out keep their value. A gesture that is running is never
|
|
2470
|
+
* altered: the change applies at once when none is, else from the next pointer down after it ends.
|
|
2471
|
+
*/
|
|
2472
|
+
setOptions(o: Partial<InteractionOptions>): void;
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
/**
|
|
2476
|
+
* The change that undoes `c`: `added` and `removed` swap, each `updated` entry swaps `el` and `prev` (its
|
|
2477
|
+
* `props` stay), and each `order.moved` entry swaps `prevBelow` and `nextBelow`. `source` is kept. Pure, and an
|
|
2478
|
+
* involution: `invertChange(invertChange(c))` deep-equals `c`.
|
|
2479
|
+
*
|
|
2480
|
+
* Applying the result to a board in the state `c` left it in (`board.applyChange(c, { invert: true })` does
|
|
2481
|
+
* both) brings the board back to the state before `c`, draw order included.
|
|
2482
|
+
*/
|
|
2483
|
+
declare function invertChange(c: Change): Change;
|
|
2484
|
+
/** Options of `board.applyChange`. */
|
|
2485
|
+
interface ApplyChangeOptions {
|
|
2486
|
+
/**
|
|
2487
|
+
* Apply the inverse of the change (an undo).
|
|
2488
|
+
* @default false
|
|
2489
|
+
*/
|
|
2490
|
+
invert?: boolean;
|
|
2491
|
+
/**
|
|
2492
|
+
* The `source` of the `change` event this produces.
|
|
2493
|
+
* @default 'undo' when `invert` is set, else 'apply'
|
|
2494
|
+
*/
|
|
2495
|
+
source?: ChangeSource;
|
|
2496
|
+
/**
|
|
2497
|
+
* What to do with an `updated` field that is no longer what the change started from (it was edited since):
|
|
2498
|
+
* `'skip'` leaves that field alone, `'overwrite'` writes it anyway. Cards that were `removed` and cards that
|
|
2499
|
+
* were `added` are not subject to it.
|
|
2500
|
+
* @default 'skip' when `invert` is set, else 'overwrite'
|
|
2501
|
+
*/
|
|
2502
|
+
conflict?: 'skip' | 'overwrite';
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
/**
|
|
2506
|
+
* The version of the snapshot format this build writes, and the newest it reads. It goes up whenever a field
|
|
2507
|
+
* is added to, or changes meaning in, what a snapshot persists (the card fields, `media`, the camera): an older
|
|
2508
|
+
* build then refuses the file instead of dropping the field. `data` is the extension slot - put what you need
|
|
2509
|
+
* to persist there and the version does not change.
|
|
2510
|
+
*/
|
|
2511
|
+
declare const SNAPSHOT_VERSION = 1;
|
|
2512
|
+
/** A card as a snapshot holds it: a `Card` (its `media.thumbhash` is a base64 string). */
|
|
2513
|
+
type SnapshotCard = Card;
|
|
2514
|
+
/**
|
|
2515
|
+
* A card as `loadSnapshot` reads it: the `id`, the position and size and the `media` are required, every other
|
|
2516
|
+
* field takes the default `add` gives it (`kind` comes from `media`). A `getSnapshot()` card fits.
|
|
2517
|
+
*/
|
|
2518
|
+
type SnapshotCardInput = Pick<Card, 'id' | 'x' | 'y' | 'w' | 'h'> & Partial<Omit<Card, 'id' | 'x' | 'y' | 'w' | 'h' | 'media'>> & {
|
|
2519
|
+
media: CardMediaInput;
|
|
2520
|
+
};
|
|
2521
|
+
/** What `loadSnapshot` takes: a {@link BoardSnapshot}, or one written by hand with only the required card fields. */
|
|
2522
|
+
interface BoardSnapshotInput {
|
|
2523
|
+
/** Must be `'corkboard'`. */
|
|
2524
|
+
format: 'corkboard';
|
|
2525
|
+
/** Format version; a newer one than this build reads is refused. */
|
|
2526
|
+
version: number;
|
|
2527
|
+
/** The cards, bottom of the draw order first. */
|
|
2528
|
+
elements: readonly SnapshotCardInput[];
|
|
2529
|
+
/** The view to jump to. */
|
|
2530
|
+
camera?: Camera;
|
|
2531
|
+
}
|
|
2532
|
+
/**
|
|
2533
|
+
* The persistent part of a board: its cards, bottom of the draw order first, and the camera. Selection,
|
|
2534
|
+
* theme, settings and runtime state (posters, snapshots, resolved embed posters) are not in it.
|
|
2535
|
+
*/
|
|
2536
|
+
interface BoardSnapshot {
|
|
2537
|
+
/** Marks the object as a corkboard snapshot. */
|
|
2538
|
+
format: 'corkboard';
|
|
2539
|
+
/** Format version, {@link SNAPSHOT_VERSION}. `loadSnapshot()` refuses a newer one. */
|
|
2540
|
+
version: typeof SNAPSHOT_VERSION;
|
|
2541
|
+
/** Draw order, bottom first. */
|
|
2542
|
+
elements: SnapshotCard[];
|
|
2543
|
+
/** The view when it was taken. Absent with `getSnapshot({ camera: false })`. */
|
|
2544
|
+
camera?: Camera;
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
/** The texture pipeline's options (`CorkboardOptions.textures`). Every one is optional. Create-only: the pipeline is built once, per board. */
|
|
2548
|
+
interface TextureOptions {
|
|
2549
|
+
/**
|
|
2550
|
+
* GPU texture memory budget in bytes (a finite number > 0). Use ~128 MB on small devices.
|
|
2551
|
+
* @default 268435456 (256 MB)
|
|
2552
|
+
*/
|
|
2553
|
+
budgetBytes?: number;
|
|
2554
|
+
/**
|
|
2555
|
+
* Decode workers.
|
|
2556
|
+
* @default a quarter of the cores, 1..4
|
|
2557
|
+
*/
|
|
2558
|
+
workers?: number;
|
|
2559
|
+
/**
|
|
2560
|
+
* URL of the decode worker script, for pages whose CSP forbids `worker-src blob:` (the built-in worker is
|
|
2561
|
+
* inlined and started from a blob URL). Serve `@niccolofanton/corkboard/decode.worker.js` yourself and pass
|
|
2562
|
+
* its URL here.
|
|
2563
|
+
*/
|
|
2564
|
+
workerUrl?: string | URL;
|
|
2565
|
+
/**
|
|
2566
|
+
* Per-frame texture upload budget, ms.
|
|
2567
|
+
* @default 4
|
|
2568
|
+
*/
|
|
2569
|
+
uploadBudgetMs?: number;
|
|
2570
|
+
/**
|
|
2571
|
+
* How far past the viewport textures are prepared, as a fraction of the viewport added on every side.
|
|
2572
|
+
* @default 0.5
|
|
2573
|
+
*/
|
|
2574
|
+
overscan?: number;
|
|
2575
|
+
/**
|
|
2576
|
+
* Bake the rounded corners in a software canvas in the workers. Measured about 2x slower to load.
|
|
2577
|
+
* @default false
|
|
2578
|
+
*/
|
|
2579
|
+
softCanvas?: boolean;
|
|
2580
|
+
}
|
|
2581
|
+
/** The zoom range of the camera (`CorkboardOptions.camera`). Both limits are optional. */
|
|
2582
|
+
interface CameraRange {
|
|
2583
|
+
/**
|
|
2584
|
+
* Lowest zoom. Lower it for a board that is much wider than the screen and must still fit whole.
|
|
2585
|
+
* @default 0.05
|
|
2586
|
+
*/
|
|
2587
|
+
minScale?: number;
|
|
2588
|
+
/**
|
|
2589
|
+
* Highest zoom.
|
|
2590
|
+
* @default 4
|
|
2591
|
+
*/
|
|
2592
|
+
maxScale?: number;
|
|
2593
|
+
}
|
|
2594
|
+
/**
|
|
2595
|
+
* Options of {@link Corkboard.create}. Every one is optional, and each is checked up front: a bad value (a NaN or
|
|
2596
|
+
* negative limit, an unknown theme name or enum value...) rejects `create` with `CorkboardError('invalid')`.
|
|
2597
|
+
*
|
|
2598
|
+
* Changeable later: `theme` (`setTheme`), `grid` (`setGrid`), `snapping` (`setSnapping`), `video`
|
|
2599
|
+
* (`video.setOptions`), `embeds` (`embeds.setOptions`), `camera` (`camera.setRange`) and the options of an
|
|
2600
|
+
* `interaction` object (`interaction.setOptions`). Create-only: `interaction` on / off, `textures`, `cspSafe`,
|
|
2601
|
+
* `nonce`, `gpuTimer` and `signal`.
|
|
2602
|
+
*/
|
|
2603
|
+
interface CorkboardOptions {
|
|
2604
|
+
/**
|
|
2605
|
+
* `'dark'`, `'light'`, or a full {@link Theme}.
|
|
2606
|
+
* @default 'dark'
|
|
2607
|
+
*/
|
|
2608
|
+
theme?: Theme | 'dark' | 'light';
|
|
2609
|
+
/**
|
|
2610
|
+
* Background dot grid.
|
|
2611
|
+
* @default true
|
|
2612
|
+
*/
|
|
2613
|
+
grid?: boolean;
|
|
2614
|
+
/**
|
|
2615
|
+
* Snapping while moving and resizing. `false` turns guides and grid off, `true` turns both on.
|
|
2616
|
+
* @default { guides: true, grid: false }
|
|
2617
|
+
*/
|
|
2618
|
+
snapping?: Partial<SnapSettings> | boolean;
|
|
2619
|
+
/**
|
|
2620
|
+
* Pointer, touch and keyboard handling. `false` leaves the canvas to the host: drive the camera with
|
|
2621
|
+
* `board.camera` and the cards with the API (and `board.interaction` is `null`).
|
|
2622
|
+
* @default true
|
|
2623
|
+
*/
|
|
2624
|
+
interaction?: boolean | InteractionOptions;
|
|
2625
|
+
/** Video playback: mode, loop, mute and how many clips play at once. */
|
|
2626
|
+
video?: VideoOptions;
|
|
2627
|
+
/** Embed cards (`media.embed`): live iframe limits, the `resolve` hook and the security options. */
|
|
2628
|
+
embeds?: EmbedOptions;
|
|
2629
|
+
/** Texture pipeline: memory budget, decode workers, upload budget. */
|
|
2630
|
+
textures?: TextureOptions;
|
|
2631
|
+
/** The zoom range of the camera (`0 < minScale <= maxScale`, else `create` rejects with `'invalid'`; `camera.setRange` changes it later). */
|
|
2632
|
+
camera?: CameraRange;
|
|
2633
|
+
/**
|
|
2634
|
+
* Load Pixi's CSP-safe build, which does not use `new Function`. Needed under a CSP without `'unsafe-eval'`.
|
|
2635
|
+
* @default false
|
|
2636
|
+
*/
|
|
2637
|
+
cspSafe?: boolean;
|
|
2638
|
+
/**
|
|
2639
|
+
* Nonce for the `<style>` elements the board injects (the embed layer's and the video layer's), for a CSP
|
|
2640
|
+
* with a nonce-based `style-src`. The styles are shared by the boards on a document and removed when the
|
|
2641
|
+
* last one is disposed.
|
|
2642
|
+
*/
|
|
2643
|
+
nonce?: string;
|
|
2644
|
+
/**
|
|
2645
|
+
* Time each GPU render (`EXT_disjoint_timer_query_webgl2`): `stats().render.gpuMs` and the `render` event's
|
|
2646
|
+
* `gpuMs`. Off by default: the timer queries are not free.
|
|
2647
|
+
* @default false
|
|
2648
|
+
*/
|
|
2649
|
+
gpuTimer?: boolean;
|
|
2650
|
+
/**
|
|
2651
|
+
* Cancels a pending `create` (React StrictMode mounts, unmounts and mounts again before the first board is
|
|
2652
|
+
* up): if it aborts before `create` resolves, the half-made board is disposed and `create` rejects with
|
|
2653
|
+
* `signal.reason`. Once the board exists the signal does nothing: call `dispose()`.
|
|
2654
|
+
*/
|
|
2655
|
+
signal?: AbortSignal;
|
|
2656
|
+
}
|
|
2657
|
+
/**
|
|
2658
|
+
* The events of a board, for {@link Corkboard.on}. The interaction events (`selection`, `hover`, `click`,
|
|
2659
|
+
* `dblclick`, `transform`, `gesture`, `touch`, `delete`) are emitted only when `interaction` is not `false`.
|
|
2660
|
+
*/
|
|
2661
|
+
interface CorkboardEvents extends InteractionEvents, EmbedEvents {
|
|
2662
|
+
/**
|
|
2663
|
+
* Cards were added, changed or removed: one event per API call, per gesture commit, per `batch` and per
|
|
2664
|
+
* `loadSnapshot`. It is the NET difference between the board before and after: a card id appears in at most
|
|
2665
|
+
* one of `added`, `removed` and `updated`.
|
|
2666
|
+
* - add then remove of a card in one batch: nothing; remove then add of the same id: one update (`prev` is the
|
|
2667
|
+
* card that was there); add then update: one add with the final card.
|
|
2668
|
+
* - `updated` entries run from the first `prev` to the last `el`; a card that ends up as it started is not
|
|
2669
|
+
* there, and a batch with no net change emits no event.
|
|
2670
|
+
* - `loadSnapshot` follows the same rules: a card with the same id becomes an update, an unchanged card is
|
|
2671
|
+
* not reported.
|
|
2672
|
+
*
|
|
2673
|
+
* `source` says who: a gesture (`'user'`), a call on the board or on `board.layout` (`'api'`), `loadSnapshot`
|
|
2674
|
+
* (`'load'`), `applyChange` (`'apply'`, or `'undo'` when inverted), the library itself (`'system'`, e.g. an
|
|
2675
|
+
* embed resized to its content), or the tag a host gave `batch(fn, { source })`. When recording history or
|
|
2676
|
+
* broadcasting, skip `'system'`, `'undo'` and `'apply'`.
|
|
2677
|
+
*
|
|
2678
|
+
* `order` is present when the draw order changed other than by cards appended on top: a card brought to the
|
|
2679
|
+
* front, a reorder, a removal. It lists the cards that moved with the card below each one before and after
|
|
2680
|
+
* (see {@link OrderChange}), not whole id lists. A drag is ONE event: the move and the bring-to-front.
|
|
2681
|
+
*
|
|
2682
|
+
* The payload is a {@link Change}: keep it, `invertChange` it, replay it with {@link Corkboard.applyChange}.
|
|
2683
|
+
*/
|
|
2684
|
+
change: Change;
|
|
2685
|
+
/**
|
|
2686
|
+
* A frame was rendered (not emitted while the board is idle): the main-thread time of the render call and
|
|
2687
|
+
* the GPU timer results that arrived meanwhile, in ms. GPU results come back a few frames late, so `gpuMs`
|
|
2688
|
+
* holds the timings of earlier frames (0, 1 or several), and is always empty unless `gpuTimer: true`.
|
|
2689
|
+
*/
|
|
2690
|
+
render: {
|
|
2691
|
+
cpuMs: number;
|
|
2692
|
+
gpuMs: readonly number[];
|
|
2693
|
+
};
|
|
2694
|
+
/** The camera moved (emitted every frame of a move). */
|
|
2695
|
+
camera: {
|
|
2696
|
+
camera: Camera;
|
|
2697
|
+
};
|
|
2698
|
+
/** The camera has been still for a moment. */
|
|
2699
|
+
cameraSettled: {
|
|
2700
|
+
camera: Camera;
|
|
2701
|
+
};
|
|
2702
|
+
/**
|
|
2703
|
+
* Something failed at runtime without throwing: a picture or video that would not load, a dead decode
|
|
2704
|
+
* worker, an embed lookup that failed, the WebGL context lost (`kind: 'context'`, together with
|
|
2705
|
+
* `contextLost`). The card stays on its placeholder.
|
|
2706
|
+
*/
|
|
2707
|
+
error: BoardErrorEvent;
|
|
2708
|
+
/** The WebGL context was lost: nothing is drawn until `contextRestored` (the textures then reload). */
|
|
2709
|
+
contextLost: Record<string, never>;
|
|
2710
|
+
/** The WebGL context is back and the textures reload by themselves. */
|
|
2711
|
+
contextRestored: Record<string, never>;
|
|
2712
|
+
}
|
|
2713
|
+
/**
|
|
2714
|
+
* An infinite canvas of image, video and embed cards, drawn with WebGL.
|
|
2715
|
+
*
|
|
2716
|
+
* Make one with {@link Corkboard.create}; it mounts a canvas and a DOM overlay layer in the host and runs until
|
|
2717
|
+
* `dispose()`. After `dispose()` every method throws a {@link CorkboardError} (`'disposed'`) except `off`
|
|
2718
|
+
* (a no-op) and the getters, which keep the last state.
|
|
2719
|
+
*
|
|
2720
|
+
* @example
|
|
2721
|
+
* ```ts
|
|
2722
|
+
* const board = await Corkboard.create(div, { theme: 'dark' });
|
|
2723
|
+
* board.add([{ media: { src: 'https://example.com/a.jpg' } }]);
|
|
2724
|
+
* board.layout.tidy();
|
|
2725
|
+
* board.camera.fit();
|
|
2726
|
+
* board.on('selection', ({ ids }) => console.log(ids));
|
|
2727
|
+
* // later
|
|
2728
|
+
* board.dispose();
|
|
2729
|
+
* ```
|
|
2730
|
+
*/
|
|
2731
|
+
declare class Corkboard {
|
|
2732
|
+
/** Camera control: pan, zoom, fit and the world / screen conversions. */
|
|
2733
|
+
readonly camera: CameraApi;
|
|
2734
|
+
/** Auto layout: tidy, masonry, align, distribute, equal width. */
|
|
2735
|
+
readonly layout: LayoutApi;
|
|
2736
|
+
/** The live iframes of the `embed` cards: what is mounted, what is known about a card, interact mode, their options. */
|
|
2737
|
+
readonly embeds: EmbedsApi;
|
|
2738
|
+
/** Video playback: what plays, the budget, pause, the options. */
|
|
2739
|
+
readonly video: VideoApi;
|
|
2740
|
+
/** The pointer, touch and keyboard layer (`null` with `interaction: false`). */
|
|
2741
|
+
readonly interaction: InteractionApi | null;
|
|
2742
|
+
private readonly store;
|
|
2743
|
+
private readonly stage;
|
|
2744
|
+
private readonly layoutCtl;
|
|
2745
|
+
private readonly input;
|
|
2746
|
+
private readonly emitter;
|
|
2747
|
+
private readonly snapSettings;
|
|
2748
|
+
private readonly overlayRoot;
|
|
2749
|
+
private readonly videoLayer;
|
|
2750
|
+
private readonly frameRate;
|
|
2751
|
+
private readonly embedLayer;
|
|
2752
|
+
private readonly cleanups;
|
|
2753
|
+
private disposed;
|
|
2754
|
+
/** Whether this browser can run a board: a WebGL2 context can be made. Never throws. */
|
|
2755
|
+
static isSupported(): boolean;
|
|
2756
|
+
/**
|
|
2757
|
+
* Deletes the Cache Storage entry that keeps the rendered previews of HTML snippets.
|
|
2758
|
+
*
|
|
2759
|
+
* @param name The `embeds.previewCache` name, if you set one. Default: the default cache and the one
|
|
2760
|
+
* version 0.1 used.
|
|
2761
|
+
* @returns Resolves when done. Never throws, and does nothing where Cache Storage does not exist. Boards
|
|
2762
|
+
* already open keep the previews they hold in memory.
|
|
2763
|
+
*/
|
|
2764
|
+
static clearPreviewCache(name?: string): Promise<void>;
|
|
2765
|
+
/**
|
|
2766
|
+
* Creates a board in `host`: mounts a WebGL canvas and a DOM overlay layer in it, and sets `position:
|
|
2767
|
+
* relative` on the host if it was static. The host needs a size (it is observed).
|
|
2768
|
+
*
|
|
2769
|
+
* @param host The element to draw in.
|
|
2770
|
+
* @param options See {@link CorkboardOptions}.
|
|
2771
|
+
* @throws {CorkboardError} `'invalid'` when `host` is not an element or an option holds a value it cannot use
|
|
2772
|
+
* (an unknown theme name, a NaN or negative limit, a zoom range with `minScale > maxScale`...); nothing is made.
|
|
2773
|
+
* @throws {CorkboardError} `'unsupported'` when the browser cannot run WebGL2.
|
|
2774
|
+
* @throws The `signal`'s reason, if it aborts before the board is up.
|
|
2775
|
+
* @example
|
|
2776
|
+
* ```ts
|
|
2777
|
+
* const ctl = new AbortController();
|
|
2778
|
+
* const board = await Corkboard.create(host, { theme: 'light', signal: ctl.signal });
|
|
2779
|
+
* ```
|
|
2780
|
+
*/
|
|
2781
|
+
static create(host: HTMLElement, opts?: CorkboardOptions): Promise<Corkboard>;
|
|
2782
|
+
private constructor();
|
|
2783
|
+
/**
|
|
2784
|
+
* Adds cards and returns their ids. A card with no `x` / `y` is placed on a free spot near the middle of what
|
|
2785
|
+
* is on screen, together with the others that have none, as one masonry block. Its size is the one it was
|
|
2786
|
+
* given, or its kind's default if that has a width of its own (embeds); an `x` or `y` it came with is kept,
|
|
2787
|
+
* the other coordinate is placed.
|
|
2788
|
+
*
|
|
2789
|
+
* @param input One card or an array of them. Pass thousands as ONE array: each call places its unplaced cards
|
|
2790
|
+
* against the whole board. `media` is copied (and a `Uint8Array` thumbhash stored as base64): changing the
|
|
2791
|
+
* object you passed afterwards does not touch the card or the history.
|
|
2792
|
+
* @returns The ids, in order.
|
|
2793
|
+
* @throws {CorkboardError} `'invalid'` on a value a card cannot hold (a NaN, a size <= 0, a duplicate id, an
|
|
2794
|
+
* embed with both or neither of `url` / `html`...). Nothing was added, whatever the batch.
|
|
2795
|
+
*/
|
|
2796
|
+
add(input: CardInit | readonly CardInit[]): CardId[];
|
|
2797
|
+
/**
|
|
2798
|
+
* Changes a card. A field left out, or set to `undefined`, is left as it is - except `data`: a patch with an
|
|
2799
|
+
* own `data` key set to `undefined` clears it (`{ data: undefined }`; `{ data: null }` stores `null`).
|
|
2800
|
+
* `media` is copied, with a `Uint8Array` thumbhash stored as base64. A new `media` with an `aspect` or a
|
|
2801
|
+
* `thumbhash` and no `w` / `h` in the patch keeps the card's width and takes the new height.
|
|
2802
|
+
*
|
|
2803
|
+
* @returns `false` when there is no such card.
|
|
2804
|
+
* @throws {CorkboardError} `'invalid'` on a value a card cannot hold; nothing changed.
|
|
2805
|
+
*/
|
|
2806
|
+
update(id: CardId, patch: CardPatch): boolean;
|
|
2807
|
+
/**
|
|
2808
|
+
* Removes cards.
|
|
2809
|
+
*
|
|
2810
|
+
* @param ids One id or a list of ids.
|
|
2811
|
+
* @returns How many of the ids existed.
|
|
2812
|
+
* @throws {CorkboardError} `'invalid'` when `ids` is not a string or an array of strings.
|
|
2813
|
+
*/
|
|
2814
|
+
remove(ids: CardId | readonly CardId[]): number;
|
|
2815
|
+
/** Removes every card and clears the selection. */
|
|
2816
|
+
clear(): void;
|
|
2817
|
+
/**
|
|
2818
|
+
* Runs `fn` and emits ONE `change` event for everything it did (`add`, `update`, `remove`, `loadSnapshot`,
|
|
2819
|
+
* `applyChange`, `board.layout.*`, the z-order methods): the net difference, see {@link CorkboardEvents}. Batches nest: an
|
|
2820
|
+
* inner one folds into the outer. Reads inside `fn` see every change made so far. `fn` must be synchronous.
|
|
2821
|
+
*
|
|
2822
|
+
* If `fn` throws there is no rollback: what it already did stays, the event for it is still emitted (after
|
|
2823
|
+
* `fn` stopped), and `fn`'s error is the one rethrown - a listener that throws does not replace it.
|
|
2824
|
+
*
|
|
2825
|
+
* @param opts `source` tags the event (see `ChangeSource`); default `'api'`. With nested batches the
|
|
2826
|
+
* outermost one that names a source wins; `'load'` (from `loadSnapshot`) wins over any.
|
|
2827
|
+
*/
|
|
2828
|
+
batch(fn: () => void, opts?: {
|
|
2829
|
+
source?: ChangeSource;
|
|
2830
|
+
}): void;
|
|
2831
|
+
/**
|
|
2832
|
+
* Replays a {@link Change} (or its inverse) on the board: the one primitive behind undo, redo and sync.
|
|
2833
|
+
*
|
|
2834
|
+
* ```ts
|
|
2835
|
+
* board.on('change', (c) => { if (!['system', 'undo', 'apply'].includes(c.source)) undoStack.push(c); });
|
|
2836
|
+
* board.applyChange(undoStack.pop()!, { invert: true }); // undo
|
|
2837
|
+
* board.applyChange(redoChange); // redo / apply a peer's change (JSON round trip is fine)
|
|
2838
|
+
* ```
|
|
2839
|
+
*
|
|
2840
|
+
* First every value is validated (`'invalid'` on a bad one, nothing changed; with `invert`, the inverse is what is checked; an id may not repeat in `added`, `removed` or `updated`, nor be both added and removed), then ONE batch (one `change`
|
|
2841
|
+
* event) does, in this order:
|
|
2842
|
+
* 1. `removed` cards are removed (ids that are not on the board are skipped).
|
|
2843
|
+
* 2. `added` cards are upserted exactly as given: no placement, no default size; an id already on the board is
|
|
2844
|
+
* overwritten in place.
|
|
2845
|
+
* 3. `updated` entries write each field of `props` from `el` as it is (no height is derived from the media's
|
|
2846
|
+
* aspect; a field that is `undefined` - `data` cleared - clears it). A card that is gone is skipped. With
|
|
2847
|
+
* `conflict: 'skip'` (the default for an inverted change) a field is written only if the card still holds
|
|
2848
|
+
* the value the change started from (`prev`), compared structurally.
|
|
2849
|
+
* 4. `order.moved` is replayed bottom first: each card goes directly above its `nextBelow` (`null`: the
|
|
2850
|
+
* bottom). An entry whose card or anchor is not on the board is skipped. A card that was only appended on
|
|
2851
|
+
* top is not in `order`, so redoing such an `add` puts it on top.
|
|
2852
|
+
*
|
|
2853
|
+
* It does not touch the camera or the selection: those are the host's. The result is a pure function of the
|
|
2854
|
+
* change and the board, so peers that start equal and replay the same changes stay equal.
|
|
2855
|
+
*
|
|
2856
|
+
* @param c A change from the `change` event, or its JSON round trip.
|
|
2857
|
+
* @param opts See {@link ApplyChangeOptions}.
|
|
2858
|
+
* @throws {CorkboardError} `'invalid'` when the change holds a value a card cannot hold, or repeats an id; nothing changed.
|
|
2859
|
+
*/
|
|
2860
|
+
applyChange(c: Change, opts?: ApplyChangeOptions): void;
|
|
2861
|
+
/**
|
|
2862
|
+
* The cards and the camera as plain data, to persist or to restore with {@link Corkboard.loadSnapshot}: the
|
|
2863
|
+
* cards in draw order (bottom first), each as `add` took it plus the size and position the board gave it.
|
|
2864
|
+
*
|
|
2865
|
+
* The snapshot shares no object with the board: `media` is copied (so is a `Uint8Array` thumbhash, which
|
|
2866
|
+
* becomes base64). `data` is the exception, passed by reference: keep it JSON-safe, since `JSON.stringify`
|
|
2867
|
+
* of the snapshot walks it. `data` is also the place for what you need to persist beyond the card fields:
|
|
2868
|
+
* any new persisted field of the library bumps `SNAPSHOT_VERSION`, `data` never does. A `blob:` URL
|
|
2869
|
+
* (`media.src`, `video`, `sizes`) is left out, since it is dead after a reload. Not included: selection,
|
|
2870
|
+
* theme, grid, snapping, video and embed settings, runtime posters and snapshots, and the poster an embed
|
|
2871
|
+
* resolved (the `embedResolved` event's `poster`, or `embeds.info(id)?.posters[0]`): to keep that one, read it
|
|
2872
|
+
* and store it yourself, then `update(id, { media: { ...board.get(id)!.media, src: poster } })`.
|
|
2873
|
+
*
|
|
2874
|
+
* @param o `camera: false` leaves the camera out.
|
|
2875
|
+
*/
|
|
2876
|
+
getSnapshot(o?: {
|
|
2877
|
+
camera?: boolean;
|
|
2878
|
+
}): BoardSnapshot;
|
|
2879
|
+
/**
|
|
2880
|
+
* Replaces the board with a snapshot (from {@link Corkboard.getSnapshot}, or `JSON.parse` of a saved one).
|
|
2881
|
+
*
|
|
2882
|
+
* All or nothing: the format, the version and every card are checked first with the same rules as `add`
|
|
2883
|
+
* (plus finite x / y and w / h > 0, required here) - a card `add` accepts, a snapshot accepts. Only `id`, `x`,
|
|
2884
|
+
* `y`, `w`, `h` and `media` are required: the other fields take the defaults of `add` (`kind` comes from
|
|
2885
|
+
* `media`). Keys a card does not have are dropped. Then the selection is cleared, a running layout animation and any drag or resize in progress end, and the cards are
|
|
2886
|
+
* swapped in one step with their ids, positions and order kept (nothing is auto-placed); `media` is copied,
|
|
2887
|
+
* `data` is taken by reference - except that a `data` structurally equal to the card's current one keeps the
|
|
2888
|
+
* current object, like `media`, so loading the same JSON twice emits nothing. The camera jumps to the snapshot's one, if it has one and `camera` is not
|
|
2889
|
+
* `false`. Emits at most one `change` event with `source: 'load'`, as a net diff (see {@link CorkboardEvents}):
|
|
2890
|
+
* cards with a new id are `added`, cards gone are `removed`, a card whose id is in both is an `updated` entry,
|
|
2891
|
+
* and one that did not change is not reported.
|
|
2892
|
+
*
|
|
2893
|
+
* @throws {CorkboardError} `'invalid'` when the snapshot is malformed or written by a newer corkboard than
|
|
2894
|
+
* this build reads (`SNAPSHOT_VERSION`); nothing changed.
|
|
2895
|
+
*/
|
|
2896
|
+
loadSnapshot(snapshot: BoardSnapshot | BoardSnapshotInput, o?: {
|
|
2897
|
+
camera?: boolean;
|
|
2898
|
+
}): void;
|
|
2899
|
+
/** A card by id (`undefined`: none). The object is the store's: do not mutate it, use `update`. */
|
|
2900
|
+
get(id: CardId): Card | undefined;
|
|
2901
|
+
/** Every card in draw order, bottom first: the order of `getSnapshot()`, and the one a gesture changes when it brings a card to the front. */
|
|
2902
|
+
all(): Card[];
|
|
2903
|
+
/**
|
|
2904
|
+
* Moves cards to the top of the draw order, keeping their relative order. Ids that are not on the board are
|
|
2905
|
+
* ignored. Throws `'invalid'` when `ids` is not a string or an array of strings.
|
|
2906
|
+
*/
|
|
2907
|
+
bringToFront(ids: CardId | readonly CardId[]): void;
|
|
2908
|
+
/**
|
|
2909
|
+
* Moves cards to the bottom of the draw order, keeping their relative order. Ids that are not on the board are
|
|
2910
|
+
* ignored. Throws `'invalid'` when `ids` is not a string or an array of strings.
|
|
2911
|
+
*/
|
|
2912
|
+
sendToBack(ids: CardId | readonly CardId[]): void;
|
|
2913
|
+
/**
|
|
2914
|
+
* Sets the whole draw order, bottom first.
|
|
2915
|
+
*
|
|
2916
|
+
* @param ids Every id on the board exactly once (as `all().map((e) => e.id)` returns them, reordered). An array
|
|
2917
|
+
* only: unlike the other id lists it takes no single id.
|
|
2918
|
+
* @throws {CorkboardError} `'invalid'` when `ids` is not an array that is a permutation of the ids on the board; nothing changed.
|
|
2919
|
+
*/
|
|
2920
|
+
setOrder(ids: readonly CardId[]): void;
|
|
2921
|
+
/** How many cards are on the board. */
|
|
2922
|
+
get size(): number;
|
|
2923
|
+
/** The ids of the cards whose box meets a world rectangle. */
|
|
2924
|
+
inRect(r: Rect): CardId[];
|
|
2925
|
+
/**
|
|
2926
|
+
* The world rectangle covering the given cards (default: all).
|
|
2927
|
+
*
|
|
2928
|
+
* @param ids One id or a list of ids.
|
|
2929
|
+
* @returns `undefined` when there is nothing to cover: an empty board, or none of the ids is a card.
|
|
2930
|
+
* @throws {CorkboardError} `'invalid'` when `ids` is not a string or an array of strings.
|
|
2931
|
+
*/
|
|
2932
|
+
bounds(ids?: CardId | readonly CardId[]): Rect | undefined;
|
|
2933
|
+
/** The selected card ids. Always empty with `interaction: false`. */
|
|
2934
|
+
get selection(): readonly CardId[];
|
|
2935
|
+
/**
|
|
2936
|
+
* Selects exactly these cards (one id or a list; an empty array clears the selection) and emits `selection`.
|
|
2937
|
+
* Does nothing with `interaction: false`. Throws `'invalid'` when `ids` is not a string or an array of strings.
|
|
2938
|
+
*
|
|
2939
|
+
* For an "arrange" button: `board.layout.tidy(board.selection.length >= 2 ? board.selection : undefined)`.
|
|
2940
|
+
*/
|
|
2941
|
+
select(ids: CardId | readonly CardId[]): void;
|
|
2942
|
+
/** Selects every card. Does nothing with `interaction: false`. */
|
|
2943
|
+
selectAll(): void;
|
|
2944
|
+
/**
|
|
2945
|
+
* Switches the theme.
|
|
2946
|
+
*
|
|
2947
|
+
* @throws {CorkboardError} `'invalid'` for a name other than `'dark'` / `'light'` or a `Theme` that is missing
|
|
2948
|
+
* a field or holds a bad colour.
|
|
2949
|
+
*/
|
|
2950
|
+
setTheme(theme: Theme | 'dark' | 'light'): void;
|
|
2951
|
+
/** Shows or hides the background dot grid. Throws `'invalid'` unless `on` is a boolean. */
|
|
2952
|
+
setGrid(on: boolean): void;
|
|
2953
|
+
/**
|
|
2954
|
+
* Alignment guides / snap to the background grid while moving and resizing. `true` / `false` set both. Throws
|
|
2955
|
+
* `'invalid'` for anything but a boolean or `{ guides?, grid? }` of booleans.
|
|
2956
|
+
*/
|
|
2957
|
+
setSnapping(s: Partial<SnapSettings> | boolean): void;
|
|
2958
|
+
/** The snapping settings now (a copy: change them with `setSnapping`). */
|
|
2959
|
+
get snapping(): Readonly<SnapSettings>;
|
|
2960
|
+
/**
|
|
2961
|
+
* Subscribes to an event (see {@link CorkboardEvents}).
|
|
2962
|
+
*
|
|
2963
|
+
* @returns The function that unsubscribes.
|
|
2964
|
+
*/
|
|
2965
|
+
on<K extends keyof CorkboardEvents>(type: K, fn: (payload: CorkboardEvents[K]) => void): () => void;
|
|
2966
|
+
/** Removes a listener added with `on`. Does nothing after `dispose()`. */
|
|
2967
|
+
off<K extends keyof CorkboardEvents>(type: K, fn: (payload: CorkboardEvents[K]) => void): void;
|
|
2968
|
+
/**
|
|
2969
|
+
* A snapshot of the counters and timings of the board: the render loop and its percentiles, texture memory
|
|
2970
|
+
* and the decode pipeline, the embeds and the videos (see {@link BoardStats}). Cheap enough to call twice a
|
|
2971
|
+
* second; it sorts the timing history, so not every frame (listen to the `render` event for that).
|
|
2972
|
+
*/
|
|
2973
|
+
stats(): BoardStats;
|
|
2974
|
+
/**
|
|
2975
|
+
* The bounding box of a card on screen, as a {@link Box} in host-local CSS px (for HTML UI pinned to a card).
|
|
2976
|
+
*
|
|
2977
|
+
* @returns `undefined` when there is no such card.
|
|
2978
|
+
*/
|
|
2979
|
+
screenRect(id: CardId): Box | undefined;
|
|
2980
|
+
/**
|
|
2981
|
+
* Tears the board down: events, DOM, workers, textures, the WebGL context. Idempotent. Every other method
|
|
2982
|
+
* throws a {@link CorkboardError} (`'disposed'`) afterwards, except `off` (a no-op) and the getters (`size`,
|
|
2983
|
+
* `selection`, `video.playing`...), which keep the last state.
|
|
2984
|
+
*/
|
|
2985
|
+
dispose(): void;
|
|
2986
|
+
private alive;
|
|
2987
|
+
private teardown;
|
|
2988
|
+
private attempt;
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2991
|
+
export { canGoLive as $, EmbedLayer as E, GRID as G, SNAP_THRESHOLD_PX as H, Interaction as I, SNIPPET_CSP as J, SNIPPET_CSP_NONE as K, PREVIEW_CACHE_NAME as P, Stage as S, VideoLayer as V, align as X, arrangeGap as Y, baseResolved as Z, buildSnapIndex as _, Store as a, clearPreviewCache as a0, distribute as a1, equalWidth as a2, hostIsolated as a3, iframeSpecFor as a4, isAllowlisted as a5, mergeResolved as a6, normalizeEmbedUrl as a7, parseEmbedUrl as a8, parseTimestamp as a9, CorkboardError as aA, DARK_THEME as aE, DEFAULTS as aF, LIGHT_THEME as aN, MAX_SCALE as aP, MIN_SCALE as aQ, SNAPSHOT_VERSION as aX, providerOfIframeSrc as aa, sameEmbed as ab, separate as ac, snapMove as ad, snapResize as ae, snippetCsp as af, snippetDocument as ag, Corkboard as b, invertChange as b8, FrameRateMonitor as o, GUIDE_OVERSHOOT_PX as q, PROVIDER_LABEL as u, SANDBOX_ARBITRARY as x, SANDBOX_PROVIDER as y, SANDBOX_SNIPPET as z };
|
|
2992
|
+
export type { Aabb as A, Box as B, Card as C, DebugStats as D, FrameRateDeps as F, LineGuide as L, MeasureGuide as M, SandboxProfile as N, SnapIndex as O, SnapResult as Q, ResolvedEmbed as R, SnippetNetwork as T, StageOptions as U, StoreEvent as W, SnapshotCardInput as a$, CorkboardErrorCode as aB, CorkboardEvents as aC, CorkboardOptions as aD, EmbedSource as aG, EmbedStats as aH, EmbedsApi as aI, GridOptions as aJ, InteractionApi as aK, InteractionEvents as aL, InteractionOptions as aM, LayoutApi as aO, MasonryOptions as aR, OrderChange as aS, OrderMove as aT, Percentiles as aU, Rect as aV, RenderStats as aW, SlowTick as aY, SnapSettings as aZ, SnapshotCard as a_, ApplyChangeOptions as ah, ArrangeOptions as ai, BoardErrorEvent as aj, BoardSnapshot as ak, BoardSnapshotInput as al, BoardStats as am, CameraApi as an, CameraMoveOptions as ao, CameraRange as ap, CardId as aq, CardInit as ar, CardKind as as, CardMedia as at, CardMediaInput as au, CardPatch as av, CardProp as aw, CardUpdate as ax, Change as ay, ChangeSource as az, StageStats as b0, TextureOptions as b1, TextureStats as b2, Theme as b3, VideoApi as b4, VideoMode as b5, VideoOptions as b6, VideoStats as b7, EmbedResolution as c, Camera as d, AlignMode as e, ArrangeGapOptions as f, ChangeSet as g, Delta as h, EmbedEvents as i, EmbedInfo as j, EmbedLayerDeps as k, EmbedOptions as l, EmbedProvider as m, EmbedResolver as n, FrameWindow as p, Guide as r, IframeInput as s, IframeSpec as t, ParsedEmbed as v, PreviewCacheMode as w };
|