Skip to content

Commit

Permalink
Merge pull request #5 from bruno-sartori/BUG-3_as_waifus_nao_estao_se…
Browse files Browse the repository at this point in the history
…ndo_exibidas

BUG-3: As waifus não estao sendo exibidas
  • Loading branch information
bruno-sartori authored Aug 28, 2024
2 parents 885cfbc + c4652fd commit 3ae26da
Show file tree
Hide file tree
Showing 29 changed files with 43 additions and 20 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ logger.configure({
enabled: true,
visual: true,
containerStyle: {
position: 'bottom-left'
position: 'bottom-left',
width: 800,
height: 800,
opacity: 1,
lineHeight: 20,
},
waifu: {
name: 'alya',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bsartori/weeb-logger",
"version": "1.0.14",
"version": "1.0.16",
"author": "Bruno Sartori <[email protected]>",
"license": "MIT",
"repository": {
Expand All @@ -14,8 +14,8 @@
"dist"
],
"scripts": {
"prepare-assets": "node ./scripts/generateBase64Assets.js",
"build": "tsc",
"postbuild": "shx mkdir -p dist/assets && shx cp -r ./src/assets/* ./dist/assets",
"prepublishOnly": "yarn build",
"test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest",
"prepare": "husky"
Expand Down
30 changes: 30 additions & 0 deletions scripts/generateBase64Assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const fs = require('fs').promises;
const path = require('path');

const convertImageToBase64 = async (name, src) => {
console.log(name, src);
const data = await fs.readFile(src);
const base64Image = Buffer.from(data, 'binary').toString('base64');
return { [name]: base64Image };
}

const generateBase64Assets = async () => {
const waifuPath = './docs/waifus'
try {
const filenames = await fs.readdir(waifuPath);

const promises = filenames.map(async (fileName) => {
const asset = await convertImageToBase64(fileName.split('_')[0], path.join(waifuPath, fileName));
return asset;
});

let base64Assets = await Promise.all(promises);
base64Assets = base64Assets.reduce(((r, c) => Object.assign(r, c)), {});

fs.writeFile('src/waifus.json', JSON.stringify(base64Assets));
} catch (error) {
console.error(error);
}
}

generateBase64Assets();
Binary file removed src/assets/images/akeno_300.png
Binary file not shown.
Binary file removed src/assets/images/alya_300.png
Binary file not shown.
Binary file removed src/assets/images/aqua_300.png
Binary file not shown.
Binary file removed src/assets/images/ayano_300.png
Binary file not shown.
Binary file removed src/assets/images/darkness_300.png
Binary file not shown.
Binary file removed src/assets/images/koneko_300.png
Binary file not shown.
Binary file removed src/assets/images/masha_300.png
Binary file not shown.
Binary file removed src/assets/images/megumin_300.png
Binary file not shown.
Binary file removed src/assets/images/tohka_300.png
Binary file not shown.
Binary file removed src/assets/images/yuki_300.png
Binary file not shown.
Binary file removed src/assets/images/zerotwo_300.png
Binary file not shown.
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import chalk from 'chalk';
import { formatDate, getTimeDiff, isUndefined, isValidString, pxToRem, waifuUrls } from './utils';
import { formatDate, getTimeDiff, isUndefined, isValidString, pxToRem } from './utils';
import { BORDER_RADIUS, SCROLLBAR_WIDTH, WAIFU_SIZE, WAIFU_THEME } from './constants';
import WeebLoggerCanvasHandler from './CanvasHandler'
import { IWeebLog, IWeebLoggerConfig } from './interfaces';
import { IWeebRequiredLoggerConfig, LogType } from './types';
import waifus from './waifus.json';

const isNode = typeof process === 'object' && `${process}` === '[object process]';

Expand Down Expand Up @@ -200,7 +201,8 @@ class WeebLogger {

if (this.config.waifu.showWaifu) {
const img = document.createElement('img');
img.src = waifuUrls[`${this.config.waifu.name}@${WAIFU_SIZE[this.config.waifu.size]}`];
// @ts-ignore
img.src = `data:image/webp;base64, ${waifus[this.config.waifu.name]}`;
img.width = parseInt(WAIFU_SIZE[this.config.waifu.size], 10);
img.height = parseInt(WAIFU_SIZE[this.config.waifu.size], 10);
img.id = 'weeb-logger-waifu';
Expand Down
14 changes: 0 additions & 14 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,3 @@ export const getTimeDiff = (date1: Date, date2: Date): string => {

return result;
};

export const waifuUrls: any = { // new URL(src, import.meta.url) f#$%&?! fails with dynamic string :/ https://github.com/vitejs/vite/issues/11157
'akeno@300': new URL('assets/images/akeno_300.webp', import.meta.url).toString(),
'alya@300': new URL('assets/images/alya_300.webp', import.meta.url).toString(),
'aqua@300': new URL('assets/images/aqua_300.webp', import.meta.url).toString(),
'ayano@300': new URL('assets/images/ayano_300.webp', import.meta.url).toString(),
'darkness@300': new URL('assets/images/darkness_300.webp', import.meta.url).toString(),
'koneko@300': new URL('assets/images/koneko_300.webp', import.meta.url).toString(),
'masha@300': new URL('assets/images/masha_300.webp', import.meta.url).toString(),
'megumin@300': new URL('assets/images/megumin_300.webp', import.meta.url).toString(),
'tohka@300': new URL('assets/images/tohka_300.webp', import.meta.url).toString(),
'yuki@300': new URL('assets/images/yuki_300.webp', import.meta.url).toString(),
'zerotwo@300': new URL('assets/images/zerotwo_300.webp', import.meta.url).toString(),
}
1 change: 1 addition & 0 deletions src/waifus.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
"resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

Expand Down

0 comments on commit 3ae26da

Please sign in to comment.