@niccolofanton/corkboard 0.1.0 → 0.2.1
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 +102 -1
- package/README.md +47 -136
- package/dist/chunk-CNSKM2Mi.d.ts +2992 -0
- package/dist/chunk-layer-9my2O3ye.js +7405 -0
- package/dist/chunk-layer-9my2O3ye.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,336 @@
|
|
|
1
|
+
import { A as Aabb, S as Stage, a as Store, I as Interaction, E as EmbedLayer, V as VideoLayer, R as ResolvedEmbed } from './chunk-CNSKM2Mi.js';
|
|
2
|
+
import { Card, Corkboard, Box, EmbedResolution, Camera } from './index.js';
|
|
3
|
+
export { e as AlignMode, f as ArrangeGapOptions, g as ChangeSet, D as DebugStats, h as Delta, i as EmbedEvents, j as EmbedInfo, k as EmbedLayerDeps, l as EmbedOptions, m as EmbedProvider, n as EmbedResolver, F as FrameRateDeps, o as FrameRateMonitor, p as FrameWindow, G as GRID, q as GUIDE_OVERSHOOT_PX, r as Guide, s as IframeInput, t as IframeSpec, L as LineGuide, M as MeasureGuide, P as PREVIEW_CACHE_NAME, u as PROVIDER_LABEL, v as ParsedEmbed, w as PreviewCacheMode, x as SANDBOX_ARBITRARY, y as SANDBOX_PROVIDER, z as SANDBOX_SNIPPET, H as SNAP_THRESHOLD_PX, J as SNIPPET_CSP, K as SNIPPET_CSP_NONE, N as SandboxProfile, O as SnapIndex, Q as SnapResult, T as SnippetNetwork, U as StageOptions, W as StoreEvent, X as align, Y as arrangeGap, Z as baseResolved, _ as buildSnapIndex, $ as canGoLive, a0 as clearPreviewCache, a1 as distribute, a2 as equalWidth, a3 as hostIsolated, a4 as iframeSpecFor, a5 as isAllowlisted, a6 as mergeResolved, a7 as normalizeEmbedUrl, a8 as parseEmbedUrl, a9 as parseTimestamp, aa as providerOfIframeSrc, ab as sameEmbed, ac as separate, ad as snapMove, ae as snapResize, af as snippetCsp, ag as snippetDocument } from './chunk-CNSKM2Mi.js';
|
|
4
|
+
import 'pixi.js';
|
|
5
|
+
|
|
6
|
+
/** A read-only view of the cards, for the hit test. */
|
|
7
|
+
interface CardReader {
|
|
8
|
+
get(id: string): Card | undefined;
|
|
9
|
+
searchInto(box: Aabb, out: Card[]): Card[];
|
|
10
|
+
rank(id: string): number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The parts a board is made of, as returned by {@link getInternals}. */
|
|
14
|
+
interface BoardInternals {
|
|
15
|
+
stage: Stage;
|
|
16
|
+
store: Store;
|
|
17
|
+
interaction: Interaction | null;
|
|
18
|
+
embeds: EmbedLayer;
|
|
19
|
+
video: VideoLayer;
|
|
20
|
+
overlayRoot: HTMLElement;
|
|
21
|
+
isDisposed(): boolean;
|
|
22
|
+
onDispose(fn: () => void): () => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The stage, store, interaction layer, embed layer and video layer of a board. No stability promise: see
|
|
26
|
+
* `@niccolofanton/corkboard/unstable`. Works on a disposed board too (the parts are then torn down).
|
|
27
|
+
*/
|
|
28
|
+
declare function getInternals(board: Corkboard): BoardInternals;
|
|
29
|
+
|
|
30
|
+
/** What an overlay factory is given. */
|
|
31
|
+
interface OverlayContext {
|
|
32
|
+
/**
|
|
33
|
+
* A div that covers the canvas (`position: absolute; inset: 0; overflow: hidden; pointer-events:
|
|
34
|
+
* none`). Put elements in it; position them with the camera's transform (`stage.cam.cam`).
|
|
35
|
+
*/
|
|
36
|
+
root: HTMLElement;
|
|
37
|
+
store: Store;
|
|
38
|
+
stage: Stage;
|
|
39
|
+
}
|
|
40
|
+
/** A DOM layer synced to the camera in the same animation frame as the render (see {@link OverlayFactory}). */
|
|
41
|
+
interface Overlay {
|
|
42
|
+
/**
|
|
43
|
+
* Every animation frame the stage ticks, after the camera step. `camChanged` is true when the camera
|
|
44
|
+
* moved since the previous frame.
|
|
45
|
+
*/
|
|
46
|
+
onFrame?(camChanged: boolean): void;
|
|
47
|
+
/** The camera has been still for a moment. */
|
|
48
|
+
onSettle?(): void;
|
|
49
|
+
/** Removes the overlay's DOM and listeners. Called by the disposer {@link addOverlay} returns, or by `board.dispose()`. */
|
|
50
|
+
dispose(): void;
|
|
51
|
+
}
|
|
52
|
+
/** Makes an extra DOM overlay for a board (see {@link addOverlay}): a new element kind that needs live DOM. */
|
|
53
|
+
type OverlayFactory = (ctx: OverlayContext) => Overlay;
|
|
54
|
+
/**
|
|
55
|
+
* Adds a DOM overlay to a board, at any time after `create`: `factory` is called now with the overlay root,
|
|
56
|
+
* the store and the stage, and the overlay it returns gets the frame and settle ticks until it is removed.
|
|
57
|
+
*
|
|
58
|
+
* @returns The function that removes the overlay (calls its `dispose`); idempotent. `board.dispose()` removes
|
|
59
|
+
* every overlay that is still there.
|
|
60
|
+
* @throws {CorkboardError} `'disposed'` on a disposed board; whatever `factory` throws (nothing is added then).
|
|
61
|
+
*/
|
|
62
|
+
declare function addOverlay(board: Corkboard, factory: OverlayFactory): () => void;
|
|
63
|
+
|
|
64
|
+
/** Options of {@link hitTest}. */
|
|
65
|
+
interface HitOptions {
|
|
66
|
+
zoom: number;
|
|
67
|
+
tolerancePx?: number;
|
|
68
|
+
skipLocked?: boolean;
|
|
69
|
+
filter?: (el: Card) => boolean;
|
|
70
|
+
}
|
|
71
|
+
/** The topmost element under the point (by draw order), or null. */
|
|
72
|
+
declare function hitTest(reader: CardReader, wx: number, wy: number, opts: HitOptions): Card | null;
|
|
73
|
+
|
|
74
|
+
/** Options of {@link elementsInBox}. */
|
|
75
|
+
interface MarqueeOptions {
|
|
76
|
+
skipLocked?: boolean;
|
|
77
|
+
filter?: (el: Card) => boolean;
|
|
78
|
+
}
|
|
79
|
+
/** Ids of the elements selected by dragging `box`, ordered by draw order (bottom first). */
|
|
80
|
+
declare function elementsInBox(reader: CardReader, box: Aabb, mode: 'touch' | 'contain', opts?: MarqueeOptions): string[];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The world area `autoSpot` can put the block in: only boxes meeting it can block a candidate. Query the
|
|
84
|
+
* store for this, not for the viewport: the search reaches 2 viewport diagonals out, and the block's own
|
|
85
|
+
* size past that.
|
|
86
|
+
*/
|
|
87
|
+
declare function autoSpotArea(block: {
|
|
88
|
+
w: number;
|
|
89
|
+
h: number;
|
|
90
|
+
}, viewport: Aabb, opts?: {
|
|
91
|
+
step?: number;
|
|
92
|
+
maxRadiusFactor?: number;
|
|
93
|
+
}): Aabb;
|
|
94
|
+
/**
|
|
95
|
+
* How the search works: the block's top-left at lattice point p overlaps the box B exactly when
|
|
96
|
+
* p lies strictly inside B grown by the block's size on its min sides, i.e. in the open range
|
|
97
|
+
* (B.min - blockSize, B.max). So instead of testing every candidate against every box, each
|
|
98
|
+
* box paints a rectangle of lattice cells into a 2D difference array; one prefix-sum pass then
|
|
99
|
+
* tells whether any candidate is blocked. Cost: O(boxes + cells), independent of block size.
|
|
100
|
+
*/
|
|
101
|
+
declare function autoSpot(block: {
|
|
102
|
+
w: number;
|
|
103
|
+
h: number;
|
|
104
|
+
}, viewport: Aabb, occupied: readonly Aabb[], opts?: {
|
|
105
|
+
step?: number;
|
|
106
|
+
maxRadiusFactor?: number;
|
|
107
|
+
}): {
|
|
108
|
+
x: number;
|
|
109
|
+
y: number;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* True when more than half of the block lies outside the viewport: the camera then flies there.
|
|
113
|
+
* Exactly half visible does not count.
|
|
114
|
+
*/
|
|
115
|
+
declare function shouldPanTo(block: Aabb, viewport: Aabb): boolean;
|
|
116
|
+
|
|
117
|
+
/** Width, world px, assumed for a card with no usable size when placing. */
|
|
118
|
+
declare const PLACEMENT_FALLBACK_WIDTH: number;
|
|
119
|
+
/** Height / width assumed for a card with no usable aspect when placing. */
|
|
120
|
+
declare const PLACEMENT_FALLBACK_ASPECT: number;
|
|
121
|
+
/** A card as the pure layout functions see it: id, size and aspect. */
|
|
122
|
+
interface LayoutItem {
|
|
123
|
+
aspect: number;
|
|
124
|
+
w?: number;
|
|
125
|
+
h?: number;
|
|
126
|
+
}
|
|
127
|
+
/** A rectangle a layout function placed a card at, world px. */
|
|
128
|
+
interface LayoutRect {
|
|
129
|
+
x: number;
|
|
130
|
+
y: number;
|
|
131
|
+
w: number;
|
|
132
|
+
h: number;
|
|
133
|
+
}
|
|
134
|
+
/** What {@link masonry} returns: a rect per card and the block's size. */
|
|
135
|
+
interface MasonryResult {
|
|
136
|
+
rects: LayoutRect[];
|
|
137
|
+
width: number;
|
|
138
|
+
height: number;
|
|
139
|
+
}
|
|
140
|
+
/** The height / width a layout uses for a card: its aspect if it is usable, else a default. */
|
|
141
|
+
declare function effectiveAspect(aspect: number | undefined): number;
|
|
142
|
+
/**
|
|
143
|
+
* Column slot width that never lets an item with its own (larger) width spill into the next
|
|
144
|
+
* column: callers that mix fixed-width items with resized cards pass it as `opts.slot`.
|
|
145
|
+
*/
|
|
146
|
+
declare function slotWidth(items: readonly LayoutItem[], width: number): number;
|
|
147
|
+
/**
|
|
148
|
+
* Items go in order into the shortest column, the leftmost when tied. Heights are integers
|
|
149
|
+
* (width * aspect rounded) so equal-height columns tie exactly and the layout is reproducible.
|
|
150
|
+
*/
|
|
151
|
+
declare function masonry(items: readonly LayoutItem[], opts: {
|
|
152
|
+
width: number;
|
|
153
|
+
gap: number;
|
|
154
|
+
columns: number;
|
|
155
|
+
slot?: number;
|
|
156
|
+
}): MasonryResult;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Bands along `axis` ('y': rows, top to bottom; 'x': columns, left to right), each band sorted along the
|
|
160
|
+
* other axis. Items are clustered by centre (a band's tolerance is half the median extent along `axis`,
|
|
161
|
+
* measured from the band's running mean centre), so cards of a row that differ in height stay one row
|
|
162
|
+
* instead of being shuffled by their centres.
|
|
163
|
+
*/
|
|
164
|
+
declare function bandOrder<T extends {
|
|
165
|
+
id: string;
|
|
166
|
+
box: Aabb;
|
|
167
|
+
}>(items: readonly T[], axis?: 'x' | 'y'): T[];
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* W: the median width of the cards already on the canvas, so new cards blend in (>= 3 cards),
|
|
171
|
+
* else the default card width.
|
|
172
|
+
*/
|
|
173
|
+
declare function placementWidth(existingCardWidths: readonly number[]): number;
|
|
174
|
+
/**
|
|
175
|
+
* G: a tenth of the width, kept between 12 and 48 so tiny cards still breathe and huge ones
|
|
176
|
+
* don't float apart.
|
|
177
|
+
*/
|
|
178
|
+
declare function placementGap(width: number): number;
|
|
179
|
+
/** c: roughly square block. One item is one column; Shift (singleRow) lays everything out in a row. */
|
|
180
|
+
declare function placementColumns(n: number, meanAspect: number, singleRow?: boolean): number;
|
|
181
|
+
/** Input of {@link planPlacement}: the new cards and the room around them. */
|
|
182
|
+
interface PlacementInput {
|
|
183
|
+
items: readonly LayoutItem[];
|
|
184
|
+
existingCardWidths: readonly number[];
|
|
185
|
+
singleRow?: boolean;
|
|
186
|
+
anchor: {
|
|
187
|
+
kind: 'grab';
|
|
188
|
+
x: number;
|
|
189
|
+
y: number;
|
|
190
|
+
} | {
|
|
191
|
+
kind: 'center';
|
|
192
|
+
x: number;
|
|
193
|
+
y: number;
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/** What {@link planPlacement} returns: where the new cards go. */
|
|
197
|
+
interface PlacementResult {
|
|
198
|
+
rects: LayoutRect[];
|
|
199
|
+
bounds: Aabb;
|
|
200
|
+
width: number;
|
|
201
|
+
gap: number;
|
|
202
|
+
columns: number;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Pure and cheap (100 items: well under a millisecond): the caller caches the result per carry
|
|
206
|
+
* and only moves it with translatePlacement[InPlace].
|
|
207
|
+
*/
|
|
208
|
+
declare function planPlacement(input: PlacementInput): PlacementResult;
|
|
209
|
+
/** Shifted copy; the input is untouched. */
|
|
210
|
+
declare function translatePlacement(result: PlacementResult, dx: number, dy: number): PlacementResult;
|
|
211
|
+
/** Per-pointer-move path: no allocation, mutates the cached result and returns it. */
|
|
212
|
+
declare function translatePlacementInPlace(result: PlacementResult, dx: number, dy: number): PlacementResult;
|
|
213
|
+
|
|
214
|
+
/** A card as {@link tidy} sees it: id, box and aspect. */
|
|
215
|
+
interface TidyItem {
|
|
216
|
+
id: string;
|
|
217
|
+
fixed?: boolean;
|
|
218
|
+
free?: boolean;
|
|
219
|
+
box: Aabb;
|
|
220
|
+
w: number;
|
|
221
|
+
h: number;
|
|
222
|
+
}
|
|
223
|
+
/** What {@link tidy} returns: the new rect of every card. */
|
|
224
|
+
interface TidyResult {
|
|
225
|
+
moves: Map<string, Box>;
|
|
226
|
+
count: number;
|
|
227
|
+
bounds: Aabb;
|
|
228
|
+
}
|
|
229
|
+
/** Reorders cards into a masonry grid in reading order, anchored at their current top-left. Pure. */
|
|
230
|
+
declare function tidy(items: readonly TidyItem[], opts?: {
|
|
231
|
+
anchor?: {
|
|
232
|
+
x: number;
|
|
233
|
+
y: number;
|
|
234
|
+
};
|
|
235
|
+
gap?: number;
|
|
236
|
+
columns?: number;
|
|
237
|
+
}): TidyResult;
|
|
238
|
+
|
|
239
|
+
/** Default `embeds.maxLive` on a mouse / pen device. */
|
|
240
|
+
declare const MAX_LIVE_DESKTOP = 12;
|
|
241
|
+
/** Default `embeds.maxLiveTouch` on a touch device. */
|
|
242
|
+
declare const MAX_LIVE_TOUCH = 3;
|
|
243
|
+
/** Width of the 320 x 200 reference box, CSS px: the aspect a numeric `embeds.minLivePx` keeps. */
|
|
244
|
+
declare const MIN_LIVE_W = 320;
|
|
245
|
+
/** Height of the 320 x 200 reference box, CSS px. */
|
|
246
|
+
declare const MIN_LIVE_H = 200;
|
|
247
|
+
/** Below this zoom nothing mounts, selected or not. */
|
|
248
|
+
declare const MIN_LIVE_SCALE = 0.25;
|
|
249
|
+
/**
|
|
250
|
+
* A live card is kept until it shrinks under this fraction of the size that earned it the iframe, so a
|
|
251
|
+
* card hovering around the threshold does not flicker between poster and iframe.
|
|
252
|
+
*/
|
|
253
|
+
declare const KEEP_FACTOR = 0.6;
|
|
254
|
+
/** A card as the live-iframe policy sees it. */
|
|
255
|
+
interface PolicyCard {
|
|
256
|
+
id: string;
|
|
257
|
+
screenW: number;
|
|
258
|
+
screenH: number;
|
|
259
|
+
onScreen: boolean;
|
|
260
|
+
selected: boolean;
|
|
261
|
+
interacting: boolean;
|
|
262
|
+
frameable: boolean;
|
|
263
|
+
live: boolean;
|
|
264
|
+
lastUsed: number;
|
|
265
|
+
lastSeen?: number;
|
|
266
|
+
}
|
|
267
|
+
/** Input of {@link planLive}: the cards, the caps and the zoom. */
|
|
268
|
+
interface PolicyInput {
|
|
269
|
+
cards: readonly PolicyCard[];
|
|
270
|
+
cameraMoving: boolean;
|
|
271
|
+
scale: number;
|
|
272
|
+
max: number;
|
|
273
|
+
maxMounted?: number;
|
|
274
|
+
maxOffscreen?: number;
|
|
275
|
+
minW?: number;
|
|
276
|
+
minH?: number;
|
|
277
|
+
minScale?: number;
|
|
278
|
+
}
|
|
279
|
+
/** What {@link planLive} decides: which cards go live and which are parked. */
|
|
280
|
+
interface PolicyPlan {
|
|
281
|
+
mount: string[];
|
|
282
|
+
destroy: string[];
|
|
283
|
+
parked: string[];
|
|
284
|
+
culled: string[];
|
|
285
|
+
}
|
|
286
|
+
/** Whether a card may be live at this zoom: big enough on screen, or selected. Pure. */
|
|
287
|
+
declare function isEligible(c: PolicyCard, scale: number, o: Pick<PolicyInput, 'minW' | 'minH' | 'minScale'>): boolean;
|
|
288
|
+
/** Chooses which embed cards hold a live iframe, within the caps. Pure. */
|
|
289
|
+
declare function planLive(input: PolicyInput): PolicyPlan;
|
|
290
|
+
|
|
291
|
+
/** A card's box in world px: the top-left of the unrotated box, its size and its rotation in degrees. */
|
|
292
|
+
interface VideoRect {
|
|
293
|
+
x: number;
|
|
294
|
+
y: number;
|
|
295
|
+
w: number;
|
|
296
|
+
h: number;
|
|
297
|
+
rot?: number;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** The most a page's layout viewport is made wide or tall, CSS px. */
|
|
301
|
+
declare const MAX_LAYOUT_PX = 4096;
|
|
302
|
+
/** The default virtual screen for embeds: `'720p'`. */
|
|
303
|
+
declare const DEFAULT_RESOLUTION: EmbedResolution;
|
|
304
|
+
/** The short side of the layout box in CSS px, or null for 'native' (the card's world size). */
|
|
305
|
+
declare function resolutionShortSide(res: EmbedResolution): number | null;
|
|
306
|
+
/** Where and how big a live iframe is laid out, and the scale that maps it onto its card. */
|
|
307
|
+
interface EmbedPlacement {
|
|
308
|
+
width: number;
|
|
309
|
+
height: number;
|
|
310
|
+
x: number;
|
|
311
|
+
y: number;
|
|
312
|
+
cx: number;
|
|
313
|
+
cy: number;
|
|
314
|
+
topRightX: number;
|
|
315
|
+
topRightY: number;
|
|
316
|
+
transform: string;
|
|
317
|
+
}
|
|
318
|
+
/** Computes the iframe's layout size and the transform that fits it on a card's box. Pure. */
|
|
319
|
+
declare function embedPlacement(r: VideoRect, camera: Camera, resolution?: EmbedResolution): EmbedPlacement;
|
|
320
|
+
|
|
321
|
+
/** The icon on a generated tile. */
|
|
322
|
+
type TileGlyph = 'play' | 'music' | 'code' | 'design' | 'globe' | 'link-off';
|
|
323
|
+
/** What a generated tile (the poster of an embed card with no picture) looks like. */
|
|
324
|
+
interface TileSpec {
|
|
325
|
+
glyph: TileGlyph | null;
|
|
326
|
+
label: string;
|
|
327
|
+
title: string;
|
|
328
|
+
hue: number | null;
|
|
329
|
+
}
|
|
330
|
+
/** A stable hue, in degrees, for a host name. */
|
|
331
|
+
declare function hostHue(host: string): number;
|
|
332
|
+
/** The look of the generated tile for a resolved embed. Pure. */
|
|
333
|
+
declare function tileSpec(r: ResolvedEmbed): TileSpec;
|
|
334
|
+
|
|
335
|
+
export { Aabb, DEFAULT_RESOLUTION, EmbedLayer, Interaction, KEEP_FACTOR, MAX_LAYOUT_PX, MAX_LIVE_DESKTOP, MAX_LIVE_TOUCH, MIN_LIVE_H, MIN_LIVE_SCALE, MIN_LIVE_W, PLACEMENT_FALLBACK_ASPECT, PLACEMENT_FALLBACK_WIDTH, ResolvedEmbed, Stage, Store, VideoLayer, addOverlay, autoSpot, autoSpotArea, bandOrder, effectiveAspect, elementsInBox, embedPlacement, getInternals, hitTest, hostHue, isEligible, masonry, placementColumns, placementGap, placementWidth, planLive, planPlacement, resolutionShortSide, shouldPanTo, slotWidth, tidy, tileSpec, translatePlacement, translatePlacementInPlace };
|
|
336
|
+
export type { BoardInternals, EmbedPlacement, LayoutItem, LayoutRect, MasonryResult, Overlay, OverlayContext, OverlayFactory, PlacementInput, PlacementResult, PolicyCard, PolicyInput, PolicyPlan, TidyItem, TidyResult, TileGlyph, TileSpec };
|
package/dist/unstable.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { O as d } from "./chunk-layer-9my2O3ye.js";
|
|
2
|
+
import { P as A, L as I, G as L, Q as O, R as T, M as f, T as C, U as R, W as u, X as N, Y as b, Z as v, _ as h, $ as D, a0 as g, a1 as M, a2 as V, a3 as X, a4 as B, a5 as F, a6 as H, a7 as y, I as U, S as W, V as x, w as G, v as w, C as k, B as K, a8 as q, a9 as z, aa as Y, ab as j, H as Q, x as Z, j as $, ac as J, ad as aa, y as sa, ae as ea, af as ta, ag as oa, ah as ra, ai as na, q as ia, aj as la, k as pa, h as da, ak as ma, al as Ea, A as _a, am as Pa, an as Sa, z as ca, ao as Aa, u as Ia, ap as La, aq as Oa, ar as Ta, as as fa, t as Ca, at as Ra, au as ua, av as Na } from "./chunk-layer-9my2O3ye.js";
|
|
3
|
+
import { C as m } from "./chunk-values-D2mwqJ9D.js";
|
|
4
|
+
import { P as va, i as ha, n as Da, p as ga, c as Ma, d as Va } from "./chunk-values-D2mwqJ9D.js";
|
|
5
|
+
function P(o, r) {
|
|
6
|
+
const a = d(o);
|
|
7
|
+
if (a.isDisposed()) throw new m("disposed", "Corkboard: the board has been disposed");
|
|
8
|
+
const s = r({ root: a.overlayRoot, store: a.store, stage: a.stage }), n = a.stage.onFrame((p) => s.onFrame?.(p)), i = a.stage.onSettle(() => s.onSettle?.());
|
|
9
|
+
let e = !1;
|
|
10
|
+
const l = a.onDispose(() => t());
|
|
11
|
+
function t() {
|
|
12
|
+
e || (e = !0, l(), n(), i(), s.dispose());
|
|
13
|
+
}
|
|
14
|
+
return t;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
A as DEFAULT_RESOLUTION,
|
|
18
|
+
I as EmbedLayer,
|
|
19
|
+
L as FrameRateMonitor,
|
|
20
|
+
O as GRID,
|
|
21
|
+
T as GUIDE_OVERSHOOT_PX,
|
|
22
|
+
f as Interaction,
|
|
23
|
+
C as KEEP_FACTOR,
|
|
24
|
+
R as MAX_LAYOUT_PX,
|
|
25
|
+
u as MAX_LIVE_DESKTOP,
|
|
26
|
+
N as MAX_LIVE_TOUCH,
|
|
27
|
+
b as MIN_LIVE_H,
|
|
28
|
+
v as MIN_LIVE_SCALE,
|
|
29
|
+
h as MIN_LIVE_W,
|
|
30
|
+
D as PLACEMENT_FALLBACK_ASPECT,
|
|
31
|
+
g as PLACEMENT_FALLBACK_WIDTH,
|
|
32
|
+
M as PREVIEW_CACHE_NAME,
|
|
33
|
+
va as PROVIDER_LABEL,
|
|
34
|
+
V as SANDBOX_ARBITRARY,
|
|
35
|
+
X as SANDBOX_PROVIDER,
|
|
36
|
+
B as SANDBOX_SNIPPET,
|
|
37
|
+
F as SNAP_THRESHOLD_PX,
|
|
38
|
+
H as SNIPPET_CSP,
|
|
39
|
+
y as SNIPPET_CSP_NONE,
|
|
40
|
+
U as Stage,
|
|
41
|
+
W as Store,
|
|
42
|
+
x as VideoLayer,
|
|
43
|
+
P as addOverlay,
|
|
44
|
+
G as align,
|
|
45
|
+
w as arrangeGap,
|
|
46
|
+
k as autoSpot,
|
|
47
|
+
K as autoSpotArea,
|
|
48
|
+
q as bandOrder,
|
|
49
|
+
z as baseResolved,
|
|
50
|
+
Y as buildSnapIndex,
|
|
51
|
+
j as canGoLive,
|
|
52
|
+
Q as clearPreviewCache,
|
|
53
|
+
Z as distribute,
|
|
54
|
+
$ as effectiveAspect,
|
|
55
|
+
J as elementsInBox,
|
|
56
|
+
aa as embedPlacement,
|
|
57
|
+
sa as equalWidth,
|
|
58
|
+
d as getInternals,
|
|
59
|
+
ea as hitTest,
|
|
60
|
+
ta as hostHue,
|
|
61
|
+
oa as hostIsolated,
|
|
62
|
+
ra as iframeSpecFor,
|
|
63
|
+
ha as isAllowlisted,
|
|
64
|
+
na as isEligible,
|
|
65
|
+
ia as masonry,
|
|
66
|
+
la as mergeResolved,
|
|
67
|
+
Da as normalizeEmbedUrl,
|
|
68
|
+
ga as parseEmbedUrl,
|
|
69
|
+
Ma as parseTimestamp,
|
|
70
|
+
pa as placementColumns,
|
|
71
|
+
da as placementGap,
|
|
72
|
+
ma as placementWidth,
|
|
73
|
+
Ea as planLive,
|
|
74
|
+
_a as planPlacement,
|
|
75
|
+
Va as providerOfIframeSrc,
|
|
76
|
+
Pa as resolutionShortSide,
|
|
77
|
+
Sa as sameEmbed,
|
|
78
|
+
ca as separate,
|
|
79
|
+
Aa as shouldPanTo,
|
|
80
|
+
Ia as slotWidth,
|
|
81
|
+
La as snapMove,
|
|
82
|
+
Oa as snapResize,
|
|
83
|
+
Ta as snippetCsp,
|
|
84
|
+
fa as snippetDocument,
|
|
85
|
+
Ca as tidy,
|
|
86
|
+
Ra as tileSpec,
|
|
87
|
+
ua as translatePlacement,
|
|
88
|
+
Na as translatePlacementInPlace
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=unstable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unstable.js","sources":["../src/overlay.ts"],"sourcesContent":["// DOM overlays: layers of real DOM laid over the canvas and synced to the camera in the same animation\n// frame as the render. The video layer is one (src/video/layer.ts). A new element kind that needs live\n// DOM (an iframe, an HTML card) is one `Overlay`, added with `addOverlay` from\n// `@niccolofanton/corkboard/unstable`, next to its view in src/render/views/registry.ts.\nimport { CorkboardError } from './errors';\nimport type { Corkboard } from './Corkboard';\nimport { getInternals } from './internals';\nimport type { Stage } from './render/stage';\nimport type { Store } from './store';\n\n/** What an overlay factory is given. */\nexport interface OverlayContext {\n /**\n * A div that covers the canvas (`position: absolute; inset: 0; overflow: hidden; pointer-events:\n * none`). Put elements in it; position them with the camera's transform (`stage.cam.cam`).\n */\n root: HTMLElement;\n store: Store;\n stage: Stage;\n}\n\n/** A DOM layer synced to the camera in the same animation frame as the render (see {@link OverlayFactory}). */\nexport interface Overlay {\n /**\n * Every animation frame the stage ticks, after the camera step. `camChanged` is true when the camera\n * moved since the previous frame.\n */\n onFrame?(camChanged: boolean): void;\n /** The camera has been still for a moment. */\n onSettle?(): void;\n /** Removes the overlay's DOM and listeners. Called by the disposer {@link addOverlay} returns, or by `board.dispose()`. */\n dispose(): void;\n}\n\n/** Makes an extra DOM overlay for a board (see {@link addOverlay}): a new element kind that needs live DOM. */\nexport type OverlayFactory = (ctx: OverlayContext) => Overlay;\n\n/**\n * Adds a DOM overlay to a board, at any time after `create`: `factory` is called now with the overlay root,\n * the store and the stage, and the overlay it returns gets the frame and settle ticks until it is removed.\n *\n * @returns The function that removes the overlay (calls its `dispose`); idempotent. `board.dispose()` removes\n * every overlay that is still there.\n * @throws {CorkboardError} `'disposed'` on a disposed board; whatever `factory` throws (nothing is added then).\n */\nexport function addOverlay(board: Corkboard, factory: OverlayFactory): () => void {\n const parts = getInternals(board);\n if (parts.isDisposed()) throw new CorkboardError('disposed', 'Corkboard: the board has been disposed');\n const overlay = factory({ root: parts.overlayRoot, store: parts.store, stage: parts.stage });\n const offFrame = parts.stage.onFrame((camChanged) => overlay.onFrame?.(camChanged));\n const offSettle = parts.stage.onSettle(() => overlay.onSettle?.());\n let removed = false;\n const unregister = parts.onDispose(() => remove());\n function remove(): void {\n if (removed) return;\n removed = true;\n unregister();\n offFrame();\n offSettle();\n overlay.dispose();\n }\n return remove;\n}\n"],"names":["addOverlay","board","factory","parts","getInternals","CorkboardError","overlay","offFrame","camChanged","offSettle","removed","unregister","remove"],"mappings":";;;;AA6CO,SAASA,EAAWC,GAAkBC,GAAqC;AAChF,QAAMC,IAAQC,EAAaH,CAAK;AAChC,MAAIE,EAAM,WAAA,SAAoB,IAAIE,EAAe,YAAY,wCAAwC;AACrG,QAAMC,IAAUJ,EAAQ,EAAE,MAAMC,EAAM,aAAa,OAAOA,EAAM,OAAO,OAAOA,EAAM,MAAA,CAAO,GACrFI,IAAWJ,EAAM,MAAM,QAAQ,CAACK,MAAeF,EAAQ,UAAUE,CAAU,CAAC,GAC5EC,IAAYN,EAAM,MAAM,SAAS,MAAMG,EAAQ,YAAY;AACjE,MAAII,IAAU;AACd,QAAMC,IAAaR,EAAM,UAAU,MAAMS,GAAQ;AACjD,WAASA,IAAe;AACtB,IAAIF,MACJA,IAAU,IACVC,EAAA,GACAJ,EAAA,GACAE,EAAA,GACAH,EAAQ,QAAA;AAAA,EACV;AACA,SAAOM;AACT;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@niccolofanton/corkboard",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "An infinite canvas of media cards on WebGL: culling, LOD textures, video overlays, auto layout and snapping.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Niccolò Fanton",
|
|
@@ -39,6 +39,10 @@
|
|
|
39
39
|
"types": "./dist/index.d.ts",
|
|
40
40
|
"default": "./dist/corkboard.js"
|
|
41
41
|
},
|
|
42
|
+
"./unstable": {
|
|
43
|
+
"types": "./dist/unstable.d.ts",
|
|
44
|
+
"import": "./dist/unstable.js"
|
|
45
|
+
},
|
|
42
46
|
"./decode.worker.js": {
|
|
43
47
|
"types": "./dist/decode.worker.d.ts",
|
|
44
48
|
"default": "./dist/decode.worker.js"
|
|
@@ -59,8 +63,10 @@
|
|
|
59
63
|
"typecheck": "tsc --noEmit",
|
|
60
64
|
"test": "vitest run",
|
|
61
65
|
"test:watch": "vitest",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
66
|
+
"build:e2e": "vite build --mode e2e --outDir dist-e2e",
|
|
67
|
+
"check:package": "publint && attw --pack . --profile esm-only && node scripts/check-dist.mjs",
|
|
68
|
+
"prepublishOnly": "pnpm typecheck && pnpm test && pnpm build && pnpm check:package && pnpm test:e2e",
|
|
69
|
+
"test:e2e": "pnpm build:e2e && playwright test"
|
|
64
70
|
},
|
|
65
71
|
"dependencies": {
|
|
66
72
|
"rbush": "^4.0.1",
|
|
@@ -71,6 +77,7 @@
|
|
|
71
77
|
},
|
|
72
78
|
"devDependencies": {
|
|
73
79
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
80
|
+
"@playwright/test": "^1.64.1",
|
|
74
81
|
"@types/node": "^22.0.0",
|
|
75
82
|
"@types/rbush": "^4.0.0",
|
|
76
83
|
"jsdom": "^24.1.3",
|