Skip to content

Commit

Permalink
docs: update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernankez committed Apr 18, 2024
1 parent ce642f8 commit 1809ae6
Show file tree
Hide file tree
Showing 8 changed files with 2,079 additions and 5 deletions.
495 changes: 495 additions & 0 deletions README.md

Large diffs are not rendered by default.

495 changes: 495 additions & 0 deletions packages/core/README.md

Large diffs are not rendered by default.

495 changes: 495 additions & 0 deletions packages/react/README.md

Large diffs are not rendered by default.

495 changes: 495 additions & 0 deletions packages/vue/README.md

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions playground/public/favicon-paw.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion playground/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { title = "Backmoji" } = Astro.props;
<meta charset="UTF-8" />
<meta name="description" content="Astro description" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="icon" type="image/svg+xml" href="/favicon-paw.svg" />
<meta name="generator" content={Astro.generator} />
<title>{title}</title>
</head>
Expand Down
Binary file added playground/src/pages/explainations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 89 additions & 4 deletions playground/src/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
layout: ./_Index.astro
---

> **This library is still under development, and the APIs are not stable yet.**
## Install

```sh
Expand Down Expand Up @@ -267,7 +269,7 @@ render();

### With animation

`backmoji` itself does not provide any animation-related functionality, but through `customRender`, you can implement your own animatino functionality, just like the animated background on this website. Here is a demonstration related to animation functionality.
`backmoji` itself does not provide any animation-related functionality, but through `customRender`, you can implement your own animation functionality, just like the animated background on this website. Here is a demonstration related to animation functionality.

import AnimationPattern from "@/demos/AnimationPattern.astro";

Expand Down Expand Up @@ -438,7 +440,90 @@ parent.appendChild(statDom);
play();
```

### Options
## Customize

You can create your own `renderer` if the provided renderers do not meet your needs. See [renderer.ts](https://github.com/Bernankez/Backmoji/blob/master/packages/core/src/renderer.ts) for more details.

## Options

### `backmoji`

```ts
declare function backmoji(canvas: Awaitable<HTMLCanvasElement>, renderer: Awaitable<Renderer>, options?: BackmojiOptions): {
render: () => Promise<void>;
setOptions: (options: BackmojiOptions, combine?: boolean) => void;
/*
* Set the size of the canvas. It handles device pixel ratio automatically.
*/
setSize: (width: number | undefined, height: number | undefined) => Promise<void>;
};

interface BackmojiOptions {
degree?: number;
rowGap?: number;
columnGap?: number;
}

type Renderer = (context: RendererContext) => void;

interface RendererContext {
ctx: CanvasRenderingContext2D;
width: number;
height: number;
rowGap: number;
columnGap: number;
degree: number;
angle: number;
/*
* Measure size of texts, using CanvasRenderingContext2D.measureText underhood
*/
measureText: (text: string) => {
width: number;
fontHeight: number;
height: number;
};
/*
* Calculate how many items should be rendered each row
*/
calculateRenderCount: (renderItemWidth: number, renderItemHeight: number) => number[] & {
row: number;
column: number;
};
/*
* Calculate the translate after rotation
*/
calculateTranslate: () => number[] & {
x: number;
y: number;
};
}
```

### renderer

```ts
interface CreateTextRendererOptions {
font?: string;
customRender?: (context: RenderContext<string>) => void;
}
/*
* The default render function if no customRender provided
*/
declare function textRender(context: RenderContext<string>): void;
declare function createTextRenderer(text: string, options?: CreateTextRendererOptions): Renderer;
interface CreateImageRendererOptions {
customRender?: (context: RenderContext<HTMLImageElement>) => void;
}
```

```ts
/*
* The default render function if no customRender provided
*/
declare function imageRender(context: RenderContext<HTMLImageElement>): void;
declare function createImageRenderer(img: HTMLImageElement, options?: CreateImageRendererOptions): Renderer;
```

The following image explains the meanings of various attribute values:

// TODO
// explaination for options
![options](./explainations.png)

0 comments on commit 1809ae6

Please sign in to comment.