mirror of
https://github.com/ful1e5/Bibata_Cursor.git
synced 2025-05-19 17:55:11 -04:00
🧹 Remove old render.ts
This commit is contained in:
parent
0712fcd257
commit
e6694cd487
1 changed files with 0 additions and 104 deletions
|
@ -1,104 +0,0 @@
|
|||
import fs from "fs";
|
||||
import path from "path";
|
||||
import puppeteer from "puppeteer";
|
||||
|
||||
import { generateRenderTemplate } from "./htmlTemplate";
|
||||
import { Config } from "../types";
|
||||
|
||||
// --------------------------- Helpers
|
||||
|
||||
const frameNumber = (number: number, length: number) => {
|
||||
var str = "" + number;
|
||||
while (str.length < length) {
|
||||
str = "0" + str;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
// --------------------------- Render Func
|
||||
export const renderCursors = async ({
|
||||
staticCursors,
|
||||
bitmapsDir,
|
||||
svgsDir,
|
||||
animatedCursors
|
||||
}: Config) => {
|
||||
const browser = await puppeteer.launch({
|
||||
ignoreDefaultArgs: [" --single-process ", "--no-sandbox"],
|
||||
headless: true
|
||||
});
|
||||
try {
|
||||
// Rendering satic .svg files
|
||||
for (let svg of staticCursors) {
|
||||
const buffer = fs.readFileSync(path.resolve(svgsDir, svg), "utf-8");
|
||||
if (!buffer) throw new Error(`${svg} File Read error`);
|
||||
|
||||
const data = buffer.toString();
|
||||
// Generating HTML Template
|
||||
const template = generateRenderTemplate(data);
|
||||
|
||||
// config
|
||||
const bitmap = `${path.basename(svg, ".svg")}.png`;
|
||||
const out = path.resolve(bitmapsDir, bitmap);
|
||||
|
||||
// Render
|
||||
const page = await browser.newPage();
|
||||
|
||||
await page.setContent(template, {
|
||||
timeout: 0,
|
||||
waitUntil: "networkidle0"
|
||||
});
|
||||
|
||||
await page.waitForSelector("#container");
|
||||
const svgElement = await page.$("#container svg");
|
||||
|
||||
if (!svgElement) throw new Error("svg element not found");
|
||||
|
||||
await svgElement.screenshot({ omitBackground: true, path: out });
|
||||
// console.log(`Static Cursor rendered at ${out}`);
|
||||
|
||||
await page.close();
|
||||
}
|
||||
|
||||
// Rendering animated .svg files
|
||||
for (let [svg, { frames }] of Object.entries(animatedCursors)) {
|
||||
const buffer = fs.readFileSync(path.resolve(svgsDir, svg), "utf-8");
|
||||
if (!buffer) throw new Error(`${svg} File Read error`);
|
||||
|
||||
const data = buffer.toString();
|
||||
// Generating HTML Template
|
||||
const template = generateRenderTemplate(data);
|
||||
|
||||
const page = await browser.newPage();
|
||||
page.setDefaultNavigationTimeout(0);
|
||||
await page.setContent(template);
|
||||
|
||||
await page.waitForSelector("#container");
|
||||
const svgElement = await page.$("#container svg");
|
||||
|
||||
if (!svgElement) throw new Error("svg element not found");
|
||||
|
||||
// Render Frames
|
||||
for (let index = 1; index <= frames; index++) {
|
||||
// config
|
||||
const frame = frameNumber(index, frames.toString().length);
|
||||
const bitmap =
|
||||
frames == 1
|
||||
? `${path.basename(svg, ".svg")}.png`
|
||||
: `${path.basename(svg, ".svg")}-${frame}.png`;
|
||||
|
||||
const out = path.resolve(bitmapsDir, bitmap);
|
||||
|
||||
// Render
|
||||
await svgElement.screenshot({
|
||||
omitBackground: true,
|
||||
path: out
|
||||
});
|
||||
// console.log(`${svg} frame ${frame}/${frames} rendered at ${out}`);
|
||||
}
|
||||
|
||||
await page.close();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue