mirror of
https://github.com/ful1e5/Bibata_Cursor.git
synced 2025-05-25 04:24:33 -04:00
🚨 render timeout & more
- Puppeteer timeout crash fixed - Docs updated in `bbpkg.configure` - Options type set as optional in `BitmapsGenerator.ts` - Changelogs added in `CHANGELOG.md`
This commit is contained in:
parent
7ca84b389c
commit
50c74ae51e
3 changed files with 110 additions and 113 deletions
|
@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Bibata Rainbow packages move to own repo
|
- Bibata Rainbow packages move to own repo
|
||||||
|
- puppeteer `svg` element timeout fixed
|
||||||
|
- optional options typing in `BitmapGenerator.ts`
|
||||||
- Format `svg` files
|
- Format `svg` files
|
||||||
|
|
||||||
## [Bibata v1.1.0] - 26 Feb 2021
|
## [Bibata v1.1.0] - 26 Feb 2021
|
||||||
|
|
|
@ -47,7 +47,7 @@ class BitmapsGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
const html = toHTML(content);
|
const html = toHTML(content);
|
||||||
await page.setContent(html);
|
await page.setContent(html, { timeout: 0 });
|
||||||
|
|
||||||
const svg = await page.$("#container svg");
|
const svg = await page.$("#container svg");
|
||||||
|
|
||||||
|
@ -57,11 +57,7 @@ class BitmapsGenerator {
|
||||||
return svg;
|
return svg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async generateStatic(
|
public async generateStatic(browser: Browser, content: string, key: string) {
|
||||||
browser: Browser,
|
|
||||||
content: string,
|
|
||||||
key: string
|
|
||||||
) {
|
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
const svg = await this.getSvgElement(page, content);
|
const svg = await this.getSvgElement(page, content);
|
||||||
|
|
||||||
|
@ -86,15 +82,15 @@ class BitmapsGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async stopAnimation(page: Page) {
|
private async stopAnimation(page: Page) {
|
||||||
//@ts-ignore
|
const client = await page.target().createCDPSession();
|
||||||
await page._client.send("Animation.setPlaybackRate", {
|
await client.send("Animation.setPlaybackRate", {
|
||||||
playbackRate: 0,
|
playbackRate: 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async resumeAnimation(page: Page, playbackRate: number) {
|
private async resumeAnimation(page: Page, playbackRate: number) {
|
||||||
//@ts-ignore
|
const client = await page.target().createCDPSession();
|
||||||
await page._client.send("Animation.setPlaybackRate", {
|
await client.send("Animation.setPlaybackRate", {
|
||||||
playbackRate,
|
playbackRate,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -108,18 +104,18 @@ class BitmapsGenerator {
|
||||||
browser: Browser,
|
browser: Browser,
|
||||||
content: string,
|
content: string,
|
||||||
key: string,
|
key: string,
|
||||||
options: {
|
options?: {
|
||||||
playbackRate: number;
|
playbackRate?: number;
|
||||||
diff: number;
|
diff?: number;
|
||||||
frameLimit: number;
|
frameLimit?: number;
|
||||||
framePadding: number;
|
framePadding?: number;
|
||||||
} = {
|
|
||||||
playbackRate: 0.3,
|
|
||||||
diff: 0,
|
|
||||||
frameLimit: 300,
|
|
||||||
framePadding: 4,
|
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
|
const opt = Object.assign(
|
||||||
|
{ playbackRate: 0.1, diff: 0, frameLimit: 300, framePadding: 4 },
|
||||||
|
options
|
||||||
|
);
|
||||||
|
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
const svg = await this.getSvgElement(page, content);
|
const svg = await this.getSvgElement(page, content);
|
||||||
await this.stopAnimation(page);
|
await this.stopAnimation(page);
|
||||||
|
@ -130,22 +126,22 @@ class BitmapsGenerator {
|
||||||
|
|
||||||
// Rendering frames till `imgN` matched to `imgN-1` (When Animation is done)
|
// Rendering frames till `imgN` matched to `imgN-1` (When Animation is done)
|
||||||
while (!breakRendering) {
|
while (!breakRendering) {
|
||||||
if (index > options.frameLimit) {
|
if (index > opt.frameLimit) {
|
||||||
throw new Error("Reached the frame limit.");
|
throw new Error("Reached the frame limit.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.resumeAnimation(page, options.playbackRate);
|
await this.resumeAnimation(page, opt.playbackRate);
|
||||||
const img: string | Buffer = await this.screenshot(svg);
|
const img: string | Buffer = await this.screenshot(svg);
|
||||||
this.stopAnimation(page);
|
await this.stopAnimation(page);
|
||||||
|
|
||||||
if (index > 1) {
|
if (index > 1) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const diff = matchImages(prevImg, img);
|
const diff = matchImages(prevImg, img);
|
||||||
if (diff <= options.diff) {
|
if (diff <= opt.diff) {
|
||||||
breakRendering = !breakRendering;
|
breakRendering = !breakRendering;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const number = frameNumber(index, options.framePadding);
|
const number = frameNumber(index, opt.framePadding);
|
||||||
const frame = `${key}-${number}.png`;
|
const frame = `${key}-${number}.png`;
|
||||||
|
|
||||||
this.saveFrameImage(frame, img);
|
this.saveFrameImage(frame, img);
|
||||||
|
@ -153,7 +149,6 @@ class BitmapsGenerator {
|
||||||
prevImg = img;
|
prevImg = img;
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
await page.close();
|
await page.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ def to_tuple(x: X) -> Tuple[X, X]:
|
||||||
|
|
||||||
|
|
||||||
def get_config(bitmaps_dir, **kwargs) -> Dict[str, Any]:
|
def get_config(bitmaps_dir, **kwargs) -> Dict[str, Any]:
|
||||||
"""Return configuration of `GoogleDot` pointers.
|
"""Return configuration of `Bibata` pointers.
|
||||||
|
|
||||||
```
|
```
|
||||||
Args:
|
Args:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue