@niccolofanton/corkboard 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +116 -0
- package/LICENSE +21 -0
- package/README.md +96 -2
- 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 +1244 -0
- package/dist/corkboard.js.map +1 -0
- package/dist/decode.worker.d.ts +2 -0
- package/dist/decode.worker.js +117 -0
- package/dist/decode.worker.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/unstable.d.ts +336 -0
- package/dist/unstable.js +90 -0
- package/dist/unstable.js.map +1 -0
- package/package.json +96 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project follows [Semantic Versioning](https://semver.org/).
|
|
4
|
+
|
|
5
|
+
## [0.2.0]
|
|
6
|
+
|
|
7
|
+
### Breaking
|
|
8
|
+
|
|
9
|
+
- The root entry is a small designed API: `Corkboard`, `CorkboardError`, the themes, `DEFAULTS`, `MIN_SCALE`, `MAX_SCALE`, `parseEmbedUrl`, `normalizeEmbedUrl` and the types a host needs. `Stage`, `Store`, `Interaction`, the video and embed layers and the pure layout and snapping functions moved to `@niccolofanton/corkboard/unstable` (no semver guarantee).
|
|
10
|
+
- `board.store` and `board.stage` are private: use `getInternals(board)` from `/unstable`. `board.camera`, `board.layout`, `board.embeds` and `board.interaction` are typed as the interfaces `CameraApi`, `LayoutApi`, `EmbedsApi` (`live`, `interacting`, `info`, `interact`, `exitInteract`) and `InteractionApi` (`setPanMode`); `CameraApi` and `LayoutApi` are no longer classes.
|
|
11
|
+
- The `change` event is the net difference per card id: `added`, `removed` and `updated` never share an id (add then remove cancels, remove then add is one update, add then update is one add), `updated` is `{ el, prev, props }[]` (it was an array of cards; `props` compares each top-level field with `Object.is`), a batch with no net change emits nothing. It carries `source` (`'user' | 'api' | 'load' | 'system' | string`) and, when the draw order changed other than by an append, `order: { moved: { id, prevBelow, nextBelow }[] }`: anchors (the card directly below each moved card before and after), the minimal set of cards to take out and put back, not whole id lists. A removed card is in it, so an undo restores its depth.
|
|
12
|
+
- Removed from the root: `setVideo`, `setVideoPaused`, `playing`, `videoBudget` (now `board.video`), `setEmbeds` (`board.embeds.setOptions`), `clearSelection` (`select([])`), `arrangeTargets`, `CorkboardOptions.overlays` (`addOverlay` in `/unstable`), `DebugStats` (now `/unstable`, and `BoardStats.debug` is `@experimental`). `snapping` returns a copy.
|
|
13
|
+
- `screenRect(id)`, `bounds(ids?)` and `embeds.info(id)` return `undefined` when there is nothing to return (`bounds` no longer returns a unit rect on an empty board). A lookup miss is `undefined`; a "none right now" field is `null`.
|
|
14
|
+
- `camera.set` throws `'invalid'` for a non-finite `tx` / `ty` or a `scale` <= 0, and the `camera` option for anything but `0 < minScale <= maxScale` (no silent fallback).
|
|
15
|
+
- `stats()` returns a typed, grouped `BoardStats` (`textures`, `render`, `debug`, `embeds`, `video`) instead of a flat record; `embedsLive` / `embedsMaxLive` are `embeds.live` / `embeds.maxLive`, and the old timing series are `render.tickMs` / `cpuMs` / `gpuMs` percentiles.
|
|
16
|
+
- `all()` returns the cards in draw order, bottom first.
|
|
17
|
+
- `Card.media.thumbhash` (0.1: `Element`) is stored as a base64 string: `add`, `update` and `applyChange` convert a `Uint8Array`, so cards and `change` payloads are JSON-safe. `Card.media` is the new `CardMedia`; `CardMediaInput`, the input, still takes bytes or base64. `add` and `update` copy `media`.
|
|
18
|
+
- `interaction.commit: false` writes nothing to the board: no lift of the dragged card, no delete, no move. `transform` (with the new `toFront`) and `delete` are proposals for the host to apply (controlled mode, documented in the API reference). With `commit` on, `delete` fires after the removal.
|
|
19
|
+
- `update(id, { data: undefined })` with an own `data` key clears `data` (it used to keep it).
|
|
20
|
+
- `add` and `update` validate their input (0.1 stored whatever it got) and throw `CorkboardError('invalid')` (NaN, a size <= 0, a duplicate id, an embed with both or neither of `url` / `html`...); `loadSnapshot` and `applyChange` apply the same rules. Every method but `off` and the getters throws `CorkboardError('disposed')` after `dispose()`. `Corkboard.create` rejects with `CorkboardError('unsupported')` without WebGL2.
|
|
21
|
+
- A snippet frame that loads another document is given its `srcdoc` back; 3 such navigations within 10 s block the card (poster, `error` event, `embeds.info(id).blocked`) until its content changes. Best effort against accidents (a link clicked in interact mode), not a security boundary.
|
|
22
|
+
- The snippet preview cache is `corkboard-previews-v2`, keyed by SHA-256; opening the default cache deletes the v1 one. Persistent previews need `crypto.subtle` (otherwise memory only).
|
|
23
|
+
- The pure layout `ArrangeOpts` (`{ gap }`) is `ArrangeGapOptions`, so `ArrangeOptions` means one thing.
|
|
24
|
+
- Public types renamed, no aliases (the old `Element` and `MediaSource` shadowed the DOM globals in a consumer's module). The declarations (root and `/unstable`) show only the new names:
|
|
25
|
+
|
|
26
|
+
| 0.1 | 0.2 |
|
|
27
|
+
|---|---|
|
|
28
|
+
| `Element`, `ElementId`, `ElementInit`, `ElementPatch`, `ElementKind`, `ElementProp`, `ElementUpdate` | `Card`, `CardId`, `CardInit`, `CardPatch`, `CardKind`, `CardProp`, `CardUpdate` |
|
|
29
|
+
| `ElementMedia` (stored), `MediaSource` (input) | `CardMedia`, `CardMediaInput` |
|
|
30
|
+
| `SnapshotElement`, `SnapshotElementInput` | `SnapshotCard`, `SnapshotCardInput` |
|
|
31
|
+
| `CameraOptions` (`animate`, `padding` of `fit` / `zoomTo` / `center`) | `CameraMoveOptions`; the `camera` create option is typed `CameraRange` (new) |
|
|
32
|
+
| the inline `{ x, y, w, h }` of `screenRect` and `transform.rects` | `Box` (new, unit-neutral: screen px for `screenRect`, world px for `transform.rects`; `Rect` stays the world `{ x0, y0, x1, y1 }`) |
|
|
33
|
+
| `Box` of `/unstable` (`{ minX, minY, maxX, maxY }`, world px) | `Aabb` (frees `Box` for the root x/y/w/h type) |
|
|
34
|
+
|
|
35
|
+
- Every list of ids takes `CardId | readonly CardId[]`: `remove`, `bringToFront` and `sendToBack` already did; now `select`, `bounds`, `camera.fit` and every `board.layout` method do too. `setOrder` needs the full list as an array. A value of another type throws `CorkboardError('invalid')` (`board.select('id')` used to throw `ids.filter is not a function`).
|
|
36
|
+
- Options are validated, at `create` and in every setter, with `CorkboardError('invalid')` naming the option: `setTheme('blue')` (was a raw `TypeError`) and `create({ theme: 'blue' })` (was accepted), `video.setOptions({ maxPlaying: NaN })`, `embeds.setOptions({ maxLive: -1 })`, `textures.budgetBytes: -1`, enum values, booleans, a `Theme` with a missing field. Numbers must be finite and in range; `Infinity` only where "no cap" is documented (the `embeds` limits, `video.maxPlaying`). API reference: which options are create-only (`textures`, `cspSafe`, `nonce`, `gpuTimer`, `signal`, `interaction` on / off) and which can change later.
|
|
37
|
+
- `stats().embeds.maxLive` caps the new `stats().embeds.active` (active frames), not `live` (active + parked, as before); its documentation said otherwise. The demo HUD shows `active/maxLive`.
|
|
38
|
+
- `board.embeds.parked`, `culled`, `frozen`, `loading`, `animating`, `animatingBudget`, `maxLive`, `freezeThreshold` and `previewsPending` (members of the 0.1 layer object) are `board.stats().embeds.*` (counts; the id sets are in `getInternals(board).embeds`).
|
|
39
|
+
|
|
40
|
+
### Added
|
|
41
|
+
|
|
42
|
+
- `CorkboardError` (`code`: `'disposed' | 'unsupported' | 'invalid'`) and `Corkboard.isSupported()`.
|
|
43
|
+
- Save and load (the board had none in 0.1): `getSnapshot({ camera? })` returns a `BoardSnapshot`, `loadSnapshot(snapshot, { camera? })` replaces the board with it (all or nothing, at most one `change` event with `source: 'load'`); `SNAPSHOT_VERSION`. A snapshot from a newer corkboard than the build reads is refused; `loadSnapshot` follows the change rules (same ids become updates, unchanged cards are not reported) and checks cards with the same rules as `add`. Snapshots share no object with the board (`media` is copied; `data` stays by reference).
|
|
44
|
+
- `batch(fn, { source? })`: one `change` event for everything `fn` does, tagged with `source` (the outermost named one wins; `'load'` wins over any). Library-initiated writes are `'system'`: skip them in an undo stack, do not broadcast them. If `fn` throws, its error is the one rethrown.
|
|
45
|
+
- Z-order: `bringToFront(ids)`, `sendToBack(ids)`, `setOrder(ids)`, and `change.order` so an undo can restore depth.
|
|
46
|
+
- `board.applyChange(change, { invert?, source?, conflict? })` and the pure `invertChange(change)`: undo, redo and sync from the `change` payload (the `Change` type), in one batch. Removals, exact upserts of added cards, raw field writes (no size derived from the media; `data` cleared), then the draw order from the anchors. Inverted changes skip fields edited since; sources `'apply'` and `'undo'`; `ChangeSource`, `OrderChange`, `OrderMove`, `CardMedia` and `BoardSnapshotInput` are exported. A fuzz test undoes and redoes random operation sequences, and keeps two boards in sync through JSON.
|
|
47
|
+
- Namespaces: `board.video` (`playing`, `budget`, `paused`, `setPaused`, `setOptions`), `board.embeds.setOptions`, `board.interaction.setOptions` (never alters a running gesture), `camera.setRange(min, max)`.
|
|
48
|
+
- `addOverlay(board, factory)` in `/unstable`: DOM overlays at any time after `create`, with a disposer.
|
|
49
|
+
- Argument checks on the whole API: `board.layout` options (`gap`, `width`, `columns`, `duration`...) and `align` / `distribute` modes, `camera.center` / `zoomBy` / `zoomTo` / `fit` / coordinate conversions, `inRect`, `setGrid`, `setSnapping` throw `'invalid'` for a NaN, a negative or a wrong type before anything moves (`layout.tidy(ids, { gap: NaN })` wrote NaN positions that `loadSnapshot(getSnapshot())` then rejected; `masonry({ width: -50 })` stored a negative width). Whatever writes a card (layout, a drag, a resize, the embed layer) refuses a NaN or infinite position, a rotation that is not finite and a size <= 0; a layout is all or nothing. A fuzz test runs random layout calls, with bad options too.
|
|
50
|
+
- Root types `CameraRange`, `CameraMoveOptions`, `Box`, `AlignMode`, `SnippetNetwork`, `PreviewCacheMode`, `TextureOptions` and `VideoApi`.
|
|
51
|
+
- A listener that throws (`change` or any other event) is reported with `console.error` and no longer stops the other listeners or the board's own bookkeeping; the public `change` goes out after the internal subscribers.
|
|
52
|
+
- Events: `error` (`BoardErrorEvent`: a picture, worker, video or embed that failed), `contextLost`, `contextRestored`, `render` (`{ cpuMs, gpuMs }` per rendered frame).
|
|
53
|
+
- Options: `signal` (cancel a pending `create`, for React StrictMode), `nonce` (for a nonce-based `style-src`; the injected styles are shared by the boards on a document and removed with the last one).
|
|
54
|
+
- Embed security options: `snippetNetwork` (`'images'` | `'none'`), `isolatedHosts`, `previewCache: { persistent: true, name }`; `Corkboard.clearPreviewCache(name?)`; `resolve` and `resolveTimeoutMs` through `embeds.setOptions`.
|
|
55
|
+
- `@niccolofanton/corkboard/unstable` and `getInternals(board)`.
|
|
56
|
+
- JSDoc on every public type, so IDE hovers work on the published declarations.
|
|
57
|
+
- A Playwright smoke test on real WebGL (`pnpm test:e2e`), and a CI matrix over the pinned and the latest Pixi 8.x.
|
|
58
|
+
|
|
59
|
+
### Fixed
|
|
60
|
+
|
|
61
|
+
- A drag is ONE `change` event: the lift at drag start no longer writes to the store (the card is drawn on top while held, and the move and the bring-to-front are committed together on release; a cancelled drag writes nothing).
|
|
62
|
+
- `loadSnapshot` keeps the board's `data` object when the loaded one is structurally equal (as it already did for `media`): loading the same JSON twice emits nothing. A hand-written snapshot needs only `id`, `x`, `y`, `w`, `h` and `media`: `kind` and the rest default as in `add`. A `load` change carries `order` too, so undoing it restores the depth.
|
|
63
|
+
- The documented `embeds.info(id)?.poster` example did not compile (`ResolvedEmbed.posters` is an array); the docs now use the `embedResolved` event's `poster` or `posters[0]`.
|
|
64
|
+
- The decode worker's Blob is made when the first worker starts, not when the library is imported. Importing only `parseEmbedUrl` or the themes no longer pulls in the board or Pixi.
|
|
65
|
+
- The Pixi render group flag the texture retirement forces a batch rebuild with is only set when it exists; otherwise a child is added to and removed from the world.
|
|
66
|
+
- The texture upload uses Pixi's public API when the private members it leans on are missing (a Pixi minor renaming them).
|
|
67
|
+
- A dead decode worker no longer stalls its cards: its in-flight jobs move to the other workers, and with none left the failure is reported once.
|
|
68
|
+
- `Stage.create` honours the `signal` after each await and releases what it made; `Stage.dispose` runs every step even if one throws (the texture manager and the Pixi app are always released).
|
|
69
|
+
- A failed `Stage.create` or `Corkboard.create` gives everything back (canvas, GL context, ticker, workers, overlay root); a constructor step that fails no longer leaks the stage, and a dispose step that throws no longer skips the others.
|
|
70
|
+
- Pixi falling back to WebGPU, a 2D canvas or a WebGL1 context is a clear `'unsupported'` error.
|
|
71
|
+
- `Store.add` is all or nothing on a duplicate id; many updates to one card in a batch fold in linear time.
|
|
72
|
+
- The public texture-upload fallback (used when Pixi's private members are missing) wrote atlas cells and generated mipmaps on the active texture unit instead of the page's, so after a batch that used several units a card could show another card's picture. The page is now unbound and rebound on unit 0 before every upload; the e2e suite adds cards in rounds with different colours on both upload paths and checks every card's pixels.
|
|
73
|
+
- Moving the board in the DOM reloads a snippet's frame; that is detected by the iframe getting a new window and never counts as a navigation.
|
|
74
|
+
- `embeds.info(id)` returns `frameable: false, blocked: true` for a blocked snippet (new `ResolvedEmbed.blocked`), cleared when the card's content changes.
|
|
75
|
+
- `isolatedHosts` entries are normalised (host or URL, `*.` / leading dot, port, IDN, trailing dot, IPv6). IP literals match exactly and are never a suffix (`0.1` no longer isolates `127.0.0.1`). Entries that are not a host throw `CorkboardError('invalid')` from `create` / `setOptions`.
|
|
76
|
+
- The embed layer's automatic resize from a resolver's aspect is a `'system'` change.
|
|
77
|
+
- The generated placeholder of an HTML snippet is grey, without a glyph.
|
|
78
|
+
- A write made inside a `change` listener reaches the later listeners after the change that caused it, not before: `Store` and the board's emitter deliver one event at a time, in order, and queue what a listener emits (a listener forwarding changes to a peer used to see `[update, add]`).
|
|
79
|
+
- `applyChange` refuses a change that repeats an id in `added`, in `removed` or in `updated`, or has an id both added and removed, with `'invalid'` and nothing changed (it used to remove, emit, then throw). With `invert: true` the inverse is what is validated: the `removed` cards as whole cards and the `prev` values that would land; a malformed change is a `CorkboardError('invalid')`, never a `TypeError`.
|
|
80
|
+
- `deepEqual` (used to keep the board's own `media` / `data` objects) reads own keys only, so `{}` and `{ constructor: 'x' }` differ (`loadSnapshot` dropped such a `data` key), and compares shared or self-referencing values in time linear in their size.
|
|
81
|
+
- `media.thumbhash` validation rejects padded base64 that does not decode (`"AA="`, `"AAA=="`).
|
|
82
|
+
- A card added while a drag holds others draws below them (it used to share the held card's rank). Disposing the interaction layer, or `loadSnapshot`, during a drag cancels it: no stale lift or pin, and the release no longer writes the old position over the loaded board.
|
|
83
|
+
- Removing many cards one id at a time in one `batch` no longer costs a pass over the whole draw order each (50k cards, 3k removals: 2.6 s to 0.02 s).
|
|
84
|
+
|
|
85
|
+
### Docs and tooling
|
|
86
|
+
|
|
87
|
+
- The 0.1.0 entry and the README claimed a rotate gesture; there is none (`rot` is data only).
|
|
88
|
+
- API reference: a navigating snippet gets its `srcdoc` back and is blocked after 3 strikes in 10 s (it said "destroyed on the first reload"); the migration guide lists only what 0.1 had; the Overlays section describes `addOverlay` for DOM synced to the camera instead of pointing at `src/`; migration rows for the `board.embeds.*` counters and the type renames. The demo's version badge is read from `package.json`.
|
|
89
|
+
- HTML-EMBEDS: Security section rewritten (navigation guard, `csp` attribute, advisory `snippetNetwork`, separate-origin isolation as future work).
|
|
90
|
+
- Release hygiene: `test:e2e` always builds a separate e2e bundle (`dist-e2e`) first. The test hook `__corkboardForcePublicUpload` is compiled out of the published bundle (`__CORKBOARD_TEST__`) and no longer declared as a `global` in the published types (it was a local cast already); `check:package` fails if either the `.js` or the `.d.ts` files carry it. `prepublishOnly` also runs `check:package` and the e2e suite. The CI e2e job runs on Chromium and Firefox, with both Pixi versions.
|
|
91
|
+
|
|
92
|
+
### Security
|
|
93
|
+
|
|
94
|
+
- Snippets: `snippetNetwork: 'none'` is best effort. It blocks subresource requests (images, fonts, `fetch`...), but a snippet can still navigate its own frame (`location.href = 'https://x/?…'`) and that request always leaves; `'none'` is advisory. On engines other than Chromium a hostile snippet can run another page in its frame, outside the snippet CSP; only serving snippets from a separate origin would isolate them (future work). Snapshot replies over 2 MB are dropped.
|
|
95
|
+
- Snippets: in Chromium the iframe carries the snippet CSP in its `csp` attribute (Embedded Enforcement), so a page a snippet navigates to is not run unless it sends `Allow-CSP-From`.
|
|
96
|
+
- `isolatedHosts` removes `allow-same-origin` for chosen hosts. The same-origin guard (this one and the own-origin one) looks only at the URL a frame starts with: a redirect or a link followed in interact mode can leave it.
|
|
97
|
+
- The persistent preview cache key is a SHA-256 (it was a 64-bit hash).
|
|
98
|
+
- Documented: a `srcdoc` snippet inherits the host page's CSP; `worker-src blob:` / `textures.workerUrl`, `cspSafe` and `nonce` cover a strict CSP.
|
|
99
|
+
|
|
100
|
+
## [0.1.0]
|
|
101
|
+
|
|
102
|
+
First release, published as `@niccolofanton/corkboard`.
|
|
103
|
+
|
|
104
|
+
### Added
|
|
105
|
+
|
|
106
|
+
- Infinite WebGL canvas of image, video and embed cards on Pixi v8 (`pixi.js` ^8.22.0 as a peer dependency), with pan, zoom and an on-demand render loop (no `requestAnimationFrame` callbacks while nothing moves).
|
|
107
|
+
- Viewport culling through an rbush index, so cards outside the view cost nothing.
|
|
108
|
+
- Level-of-detail image pipeline: ThumbHash placeholder, shared atlas, per-card textures with baked rounded corners, decoded in a worker pool under an LRU memory budget.
|
|
109
|
+
- Video cards: a WebGL poster plus a `<video>` element synced to the camera, with a play pool (`always` / `hover` / `off`) that adapts to the frame rate.
|
|
110
|
+
- Embed cards for YouTube, Vimeo, Spotify, CodePen, Figma, any page or a snippet of HTML: a poster sprite that becomes a sandboxed iframe at a virtual 720p / 1080p screen, with live / parked / culled lifecycle, runtime posters and snapshots.
|
|
111
|
+
- Auto layout (masonry, tidy grid, align, distribute, equal width) with animated transitions.
|
|
112
|
+
- Interaction: selection and marquee, drag and resize, smart-guide and dot-grid snapping, keyboard shortcuts, hand tool.
|
|
113
|
+
- Typed events (`selection`, `hover`, `click`, `dblclick`, `transform`, `gesture`, `delete`, `change`, `camera`, `cameraSettled`, `embedInteract`, `embedLive`, `embedResolved`) and a `stats()` API.
|
|
114
|
+
- Extension points: custom element kinds (views and DOM overlays), light / dark theme, optional CSP-safe mode.
|
|
115
|
+
- Single bundled `dist/index.d.ts` that resolves under `node16`, `nodenext` and `bundler` module resolution.
|
|
116
|
+
- Decode worker inlined as a blob worker; also exported as `@niccolofanton/corkboard/decode.worker.js` for pages whose CSP forbids blob workers (`textures.workerUrl`).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Niccolò Fanton
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,97 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Corkboard
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@niccolofanton/corkboard)
|
|
4
|
+
[](https://github.com/niccolofanton/corkboard/actions/workflows/ci.yml)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
An infinite WebGL canvas of image, video and embed cards, built on Pixi v8. Framework-agnostic TypeScript, made for
|
|
10
|
+
boards of thousands of cards on an ordinary laptop.
|
|
11
|
+
|
|
12
|
+
- **Fast by not working:** on-demand render loop (idle at 0 rAF callbacks), viewport culling, level-of-detail textures
|
|
13
|
+
decoded in workers under a memory budget.
|
|
14
|
+
- **Video and embeds:** videos play over their WebGL poster; YouTube, Vimeo, Spotify, CodePen, Figma, any page or a
|
|
15
|
+
snippet of HTML become sandboxed live iframes, loaded in chunks, frozen to a snapshot when too small to read.
|
|
16
|
+
- **Layout and editing:** masonry, tidy grid, align and distribute with animated transitions; selection, drag, resize,
|
|
17
|
+
smart guides and grid snapping.
|
|
18
|
+
- **Production bits:** `getSnapshot()` / `loadSnapshot()`, net-diff `change` events with a draw order, `applyChange` / `invertChange` for undo, redo and sync, a typed `error` event, `Corkboard.isSupported()`.
|
|
19
|
+
|
|
20
|
+
**Live demo: [corkboard.niccolofanton.dev](https://corkboard.niccolofanton.dev)**
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
npm i @niccolofanton/corkboard pixi.js
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`pixi.js` ^8.22.0 is a peer dependency. ESM only, types included. Needs WebGL2.
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { Corkboard } from '@niccolofanton/corkboard';
|
|
34
|
+
|
|
35
|
+
async function main(): Promise<void> {
|
|
36
|
+
const board = await Corkboard.create(document.getElementById('board')!, { theme: 'dark' });
|
|
37
|
+
board.add([
|
|
38
|
+
{ media: { src: 'https://picsum.photos/seed/1/480/600', aspect: 1.25 } },
|
|
39
|
+
{ media: { src: 'https://picsum.photos/seed/2/480/270', video: 'https://example.com/clip.mp4' } },
|
|
40
|
+
{ media: { embed: { url: 'https://youtu.be/dQw4w9WgXcQ' } } },
|
|
41
|
+
{ media: { embed: { html: '<button onclick="this.textContent++">0</button>' } } },
|
|
42
|
+
]);
|
|
43
|
+
board.layout.tidy();
|
|
44
|
+
board.camera.fit();
|
|
45
|
+
board.on('selection', ({ ids }) => console.log(ids));
|
|
46
|
+
}
|
|
47
|
+
void main();
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- Pictures are fetched by a worker, so they need CORS headers.
|
|
51
|
+
- `Corkboard.create` is async; a top-level `await` also works if your build target allows it (Vite: `build.target: 'es2022'`).
|
|
52
|
+
- Embeds don't take pointer events: double-click (or Enter) to interact, Esc to leave. A known provider needs no setup;
|
|
53
|
+
for titles, thumbnails and framing checks of other pages, pass `embeds.resolve` (see the [API reference](docs/API.md#embeds)).
|
|
54
|
+
|
|
55
|
+
## React
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
const ctl = new AbortController(); // cancels a create() that StrictMode unmounts mid-flight
|
|
60
|
+
let board: Corkboard | undefined;
|
|
61
|
+
Corkboard.create(ref.current!, { signal: ctl.signal })
|
|
62
|
+
.then((b) => (board = b))
|
|
63
|
+
.catch((e) => { if (!ctl.signal.aborted) console.error(e); });
|
|
64
|
+
return () => { ctl.abort(); board?.dispose(); };
|
|
65
|
+
}, []);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Strict CSP
|
|
69
|
+
|
|
70
|
+
- `worker-src blob:`, or serve the bundled worker and pass `textures.workerUrl` (below).
|
|
71
|
+
- No `unsafe-eval`: `cspSafe: true`. Nonce-based `style-src`: `nonce`.
|
|
72
|
+
- `img-src data: blob:` for snapshots and previews. HTML snippets (`srcdoc`) inherit the page's CSP.
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import workerUrl from '@niccolofanton/corkboard/decode.worker.js?url'; // Vite; any bundler that gives you a file URL
|
|
76
|
+
await Corkboard.create(el, { textures: { workerUrl }, cspSafe: true, nonce });
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Docs
|
|
80
|
+
|
|
81
|
+
- [API reference](docs/API.md): methods, options, events, errors, embeds, migrating from 0.1.
|
|
82
|
+
- [HTML embeds](docs/HTML-EMBEDS.md): how embeds are loaded, culled, frozen and paused (§11), and the research behind it.
|
|
83
|
+
- [Renderer handoff](docs/HANDOFF.md): stage, culling, LOD textures, atlas, video, layout, snapping, performance.
|
|
84
|
+
- `@niccolofanton/corkboard/unstable`: the building blocks (stage, store, layout and snapping functions, `getInternals`), no semver guarantee.
|
|
85
|
+
|
|
86
|
+
## Development
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
pnpm install
|
|
90
|
+
pnpm dev # demo
|
|
91
|
+
pnpm test
|
|
92
|
+
pnpm build # dist/: library, bundled types, decode worker
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT
|