mirror of
https://github.com/ful1e5/Bibata_Cursor.git
synced 2025-06-01 23:58:30 -04:00
🔗 Object as input
This commit is contained in:
parent
5c1d89c282
commit
d646cf0312
1 changed files with 20 additions and 10 deletions
|
@ -3,6 +3,8 @@ import path from "path";
|
||||||
import SvgDirectoryParser from "./SvgDirectoryParser";
|
import SvgDirectoryParser from "./SvgDirectoryParser";
|
||||||
import { Colors } from "../types";
|
import { Colors } from "../types";
|
||||||
|
|
||||||
|
export type Inputs = { svgDir: string; colors: Colors };
|
||||||
|
|
||||||
interface Cursors {
|
interface Cursors {
|
||||||
[cursorName: string]: {
|
[cursorName: string]: {
|
||||||
content: string;
|
content: string;
|
||||||
|
@ -17,11 +19,13 @@ export const keyColors: Colors = {
|
||||||
outline: "#0000FF"
|
outline: "#0000FF"
|
||||||
};
|
};
|
||||||
|
|
||||||
export class ColoredSvgGenerator {
|
export default class ColoredSvgGenerator {
|
||||||
private staticCursors: string[];
|
private staticCursors: string[];
|
||||||
private animatedCursors: string[];
|
private animatedCursors: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
|
* Generate custom color cursor's `.svg`.
|
||||||
*
|
*
|
||||||
* @param svgDir directory where animated & static cursors located.
|
* @param svgDir directory where animated & static cursors located.
|
||||||
*
|
*
|
||||||
|
@ -31,8 +35,8 @@ export class ColoredSvgGenerator {
|
||||||
*
|
*
|
||||||
* @param colors `Colors` for static cursors.
|
* @param colors `Colors` for static cursors.
|
||||||
*/
|
*/
|
||||||
constructor(private svgDir: string, private colors: Colors) {
|
constructor(private inputs: Inputs) {
|
||||||
const svgParser = new SvgDirectoryParser(this.svgDir);
|
const svgParser = new SvgDirectoryParser(this.inputs.svgDir);
|
||||||
this.animatedCursors = svgParser.getAnimatedCursors();
|
this.animatedCursors = svgParser.getAnimatedCursors();
|
||||||
this.staticCursors = svgParser.getStaticCursors();
|
this.staticCursors = svgParser.getStaticCursors();
|
||||||
}
|
}
|
||||||
|
@ -49,8 +53,11 @@ export class ColoredSvgGenerator {
|
||||||
let content = fs.readFileSync(cursor, "utf-8").toString();
|
let content = fs.readFileSync(cursor, "utf-8").toString();
|
||||||
|
|
||||||
content = content
|
content = content
|
||||||
.replace(new RegExp(keyColors.base, "g"), this.colors.base)
|
.replace(new RegExp(keyColors.base, "g"), this.inputs.colors.base)
|
||||||
.replace(new RegExp(keyColors.outline, "g"), this.colors.outline);
|
.replace(
|
||||||
|
new RegExp(keyColors.outline, "g"),
|
||||||
|
this.inputs.colors.outline
|
||||||
|
);
|
||||||
|
|
||||||
cursors[`${path.basename(cursor)}`] = { content };
|
cursors[`${path.basename(cursor)}`] = { content };
|
||||||
});
|
});
|
||||||
|
@ -70,16 +77,19 @@ export class ColoredSvgGenerator {
|
||||||
let content = fs.readFileSync(cursor, "utf-8").toString();
|
let content = fs.readFileSync(cursor, "utf-8").toString();
|
||||||
|
|
||||||
content = content
|
content = content
|
||||||
.replace(new RegExp(keyColors.base, "g"), this.colors.base)
|
.replace(new RegExp(keyColors.base, "g"), this.inputs.colors.base)
|
||||||
.replace(new RegExp(keyColors.outline, "g"), this.colors.outline);
|
.replace(
|
||||||
|
new RegExp(keyColors.outline, "g"),
|
||||||
|
this.inputs.colors.outline
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// === trying to replace `watch` color ===
|
// === trying to replace `watch` color ===
|
||||||
|
|
||||||
if (!this.colors.watch?.background) {
|
if (!this.inputs.colors.watch?.background) {
|
||||||
throw new Error("");
|
throw new Error("");
|
||||||
}
|
}
|
||||||
const { background: b } = this.colors.watch;
|
const { background: b } = this.inputs.colors.watch;
|
||||||
content = content.replace(
|
content = content.replace(
|
||||||
new RegExp(keyColors.watch!.background, "g"),
|
new RegExp(keyColors.watch!.background, "g"),
|
||||||
b
|
b
|
||||||
|
@ -89,7 +99,7 @@ export class ColoredSvgGenerator {
|
||||||
|
|
||||||
content = content.replace(
|
content = content.replace(
|
||||||
new RegExp(keyColors.watch!.background, "g"),
|
new RegExp(keyColors.watch!.background, "g"),
|
||||||
this.colors.base
|
this.inputs.colors.base
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue