Package Exports
- @netless/white-snapshot
- @netless/white-snapshot/index.js
- @netless/white-snapshot/index.mjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@netless/white-snapshot) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@netless/white-snapshot
Take a snapshot of a white-web-sdk scene.
Requires white-web-sdk ≥ 2.16.20.
Usage
import { snapshot } from "@netless/white-snapshot";
// room = await sdk.joinRoom(...)
snapshot(room).then(canvas => {
document.body.append(canvas);
});Options
snapshot(room, {
scenePath: "/init",
padding: 5,
background: 'transparent',
crop: null,
crossorigin: false,
}): Promise<HTMLCanvasElement | null>;Returns null if failed.
| Option | Type | Default | Description |
|---|---|---|---|
| scenePath | string | current scene | Default is displayer.state.sceneState.scenePath. |
| padding | number | 5 | Pixels to the border of canvas. |
| background | string | Background color. | |
| crop | Rectangle | null | Apply crop on the snapshot. Note that the snapshot includes padding. |
| crossorigin | boolean | false | Apply hack to document.createElement('img') to enable crossorigin images. |
Develop
pnpm devChangelog
0.4.0
- Added back
html2canvas.
0.3.1
Fixed
paddingnot work.
It still has a little visual bug.Added Options:
interface SnapshotOptions { /** * Background color. * * @default transparent */ background?: string; }
0.3.0
- Removed html2canvas dependency.
Now it must requires white-web-sdk ≥ 2.16.20.
0.2.2
Fixed
html2canvasusage may get empty output.
Now it works the same as 0.2.0.Added Options:
interface SnapshotOptions { /** * Print which scene. * * @default displayer.state.sceneState.scenePath */ scenePath?: string; }
0.2.1
Support white-web-sdk 2.16.20's native canvas output.
Added options:
interface SnapshotOptions { /** * Use `html2canvas` to print SVG directly. * * @default false */ html2canvas?: boolean; /** * Apply hack to all `document.createElement('img')` to include crossorigin attribute. * This option requires image server settings and therefore is not enabled by default. * * @default false */ crossorigin?: boolean; }
0.2.0
Support
html2canvasbased snapshot. Options:interface SnapshotOptions { /** * @default 5 (px) */ padding?: number; /** * Apply crop on the snapshot. Note that the snapshot includes padding. * * @default null */ crop?: Record<"x" | "y" | "width" | "height", number> | null; } function snapshot( displayer: Displayer, { padding, crop: crop_ }?: SnapshotOptions ): Promise<HTMLCanvasElement | null>;
License
MIT @ netless