-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
386 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
--- | ||
outline: deep | ||
publish: false | ||
--- | ||
|
||
See [Lesson 10 - Importing and Exporting Images] for more information. | ||
|
||
```ts | ||
import { ImageExporter } from '@infinite-canvas-tutorial/core'; | ||
const exporter = new ImageExporter({ canvas }); | ||
``` | ||
|
||
## constructor | ||
|
||
- Required parameter `canvas`, the [Canvas] instance. | ||
- Optional parameter `defaultFilename`, default value is `g`. | ||
|
||
```ts | ||
export interface ImageExporterOptions { | ||
canvas: Canvas; | ||
defaultFilename?: string; | ||
} | ||
``` | ||
|
||
## toCanvas | ||
|
||
Returns an `HTMLCanvasElement`, which can be called [toDataURL] later. | ||
|
||
```ts | ||
const canvas = await exporter.toCanvas(); | ||
canvas.toDataURL(); // data:image/png;base64,... | ||
``` | ||
|
||
The meaning of each configuration item is as follows: | ||
|
||
- `grid` Whether to include a grid | ||
- `beforeDrawImage` Called before drawing the content of the canvas, suitable for drawing the background color. | ||
- `afterDrawImage` Called after drawing the content of the canvas, suitable for drawing watermarks. | ||
|
||
```ts | ||
export interface CanvasOptions { | ||
grid: boolean; | ||
beforeDrawImage: (context: CanvasRenderingContext2D) => void; | ||
afterDrawImage: (context: CanvasRenderingContext2D) => void; | ||
} | ||
``` | ||
|
||
## toSVG | ||
|
||
Generate an SVGElement. The `grid` parameter indicates whether to display the grid. | ||
|
||
```ts | ||
export interface SVGOptions { | ||
grid: boolean; | ||
} | ||
``` | ||
|
||
## toSVGDataURL | ||
|
||
Generate an SVG's `dataURL`. The `grid` parameter indicates whether to display the grid. | ||
|
||
```ts | ||
export interface SVGOptions { | ||
grid: boolean; | ||
} | ||
``` | ||
|
||
## downloadImage | ||
|
||
Triggers the browser's download behavior. | ||
|
||
```ts | ||
export interface DownloadImageOptions { | ||
dataURL: string; | ||
name?: string; | ||
} | ||
``` | ||
|
||
[Lesson 10 - Importing and Exporting Images]: /guide/lesson-010 | ||
[Canvas]: /reference/canvas | ||
[toDataURL]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
outline: deep | ||
publish: false | ||
--- | ||
|
||
Our canvas includes UI components implemented using Web Components. | ||
|
||
```ts | ||
import '@infinite-canvas-tutorial/ui'; | ||
``` | ||
|
||
Use this component in HTML: | ||
|
||
```html | ||
<ic-canvas renderer="webgpu"></ic-canvas> | ||
``` | ||
|
||
`<ic-canvas>` component supports the following properties, all of which are strings. | ||
|
||
## renderer | ||
|
||
Support `webgpu` and `webgl` renderers, default to `webgl`. | ||
|
||
```html | ||
<ic-canvas renderer="webgpu"></ic-canvas> | ||
``` | ||
|
||
## shaderCompilerPath | ||
|
||
Specify the path of the WebGPU shader compiler, which compiles GLSL to WGSL. The default value is `https://unpkg.com/@antv/g-device-api@1.6.8/dist/pkg/glsl_wgsl_compiler_bg.wasm` | ||
|
||
## shoelaceBasePath | ||
|
||
Our UI components use the Shoelace component library, which specifies the CDN path of Shoelace. The default value is `https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.19.1/cdn` | ||
|
||
## zoom | ||
|
||
The zoom level of the canvas, default to `100`. | ||
|
||
## mode | ||
|
||
The interaction mode of the canvas, default to `CanvasMode.HAND`. | ||
|
||
## modes | ||
|
||
The interaction mode of the canvas, default to `[CanvasMode.HAND, CanvasMode.SELECT, CanvasMode.DRAW_RECT]`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.