From 81019324d3273aa42127d55f69645fc4a7c3fa64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=A0=E6=89=8B=E6=8D=A7=E9=B2=9C=E8=8A=B1?= <157215725@qq.com> Date: Thu, 11 May 2023 22:47:32 +0800 Subject: [PATCH] feat: upgrade dependencies --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- src/create-encoder.ts | 24 +++++++++++++++++++----- src/create-logger.ts | 3 ++- src/utils.ts | 2 ++ 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 0f8bd99..41d8dd5 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,6 @@ "vitest": "^0.31.0" }, "dependencies": { - "modern-palette": "^0.1.8" + "modern-palette": "^0.2.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 26f8b17..896dead 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2,8 +2,8 @@ lockfileVersion: '6.0' dependencies: modern-palette: - specifier: ^0.1.8 - version: 0.1.8 + specifier: ^0.2.0 + version: 0.2.0 devDependencies: '@qq15725/eslint-config': @@ -2642,8 +2642,8 @@ packages: ufo: 1.1.2 dev: true - /modern-palette@0.1.8: - resolution: {integrity: sha512-kCPy5P2nABa+suI34uWyh87PQzhaFmZ5igEEoPowXoCxOpgF6UW8Bj4pdvf+NRFnhMC3Tok6a36bgd/4oT8SRA==} + /modern-palette@0.2.0: + resolution: {integrity: sha512-rQ+elZGi7jr8RO+eUz2ISH41T3aOOJWNL2ehWobEQE+kMo6AJBT6h7vXBZwX8zUjFLyGQ6GhGvVic8pb5dbMdg==} dev: false /modify-values@1.0.1: diff --git a/src/create-encoder.ts b/src/create-encoder.ts index 0f27b56..6505855 100644 --- a/src/create-encoder.ts +++ b/src/create-encoder.ts @@ -73,10 +73,10 @@ export function createEncoder(options: EncoderOptions) { log.timeEnd(`palette:sample-${ index }`) }, async flush(): Promise { - const { log, frames, width, height, palette } = encoder + const { log, frames, width, height, maxColors, palette } = encoder log.time('palette:generate') - const context = await generateInWorker() + const context = await generateInWorker(maxColors) const colorTable = createPalette(context) .getColors('rgb') .map(val => val.color) @@ -85,6 +85,20 @@ export function createEncoder(options: EncoderOptions) { } log.timeEnd('palette:generate') + // debug + log.debug('palette:maxColors', maxColors) + const hexColorTable = colorTable.map(rgb => { + const r = rgb[0].toString(16).padStart(2, '0') + const g = rgb[1].toString(16).padStart(2, '0') + const b = rgb[2].toString(16).padStart(2, '0') + return `#${ r }${ g }${ b }` + }) + // eslint-disable-next-line no-console + debug && console.debug( + hexColorTable.map(() => '%c ').join(''), + ...hexColorTable.map(hex => `margin: 1px; background: ${ hex }`), + ) + log.time('frames:index') const indexedFrames = await indexFramesInWorker({ frames, @@ -156,14 +170,14 @@ export function createEncoder(options: EncoderOptions) { encoder.palette.addSample(options) } - async function generateInWorker(): Promise { + async function generateInWorker(maxColors: number): Promise { const result = await encoder.worker.call( - { type: 'palette:generate', options: { maxColors: encoder.maxColors } }, + { type: 'palette:generate', options: { maxColors } }, undefined, 0, ) if (result) return result as any - encoder.palette.generate({ maxColors: encoder.maxColors }) + encoder.palette.generate({ maxColors }) return encoder.palette.context } diff --git a/src/create-logger.ts b/src/create-logger.ts index aec9686..90f1b93 100644 --- a/src/create-logger.ts +++ b/src/create-logger.ts @@ -1,9 +1,10 @@ -import { consoleTime, consoleTimeEnd, consoleWarn } from './utils' +import { consoleDebug, consoleTime, consoleTimeEnd, consoleWarn } from './utils' export function createLogger(debug: boolean) { return { time: (label: string) => debug && consoleTime(label), timeEnd: (label: string) => debug && consoleTimeEnd(label), + debug: (...args: any[]) => debug && consoleDebug(...args), warn: (...args: any[]) => debug && consoleWarn(...args), } } diff --git a/src/utils.ts b/src/utils.ts index 334c5ce..8c3504b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -18,6 +18,8 @@ export const TRAILER = 0x3B // Console export const consoleWarn = (...args: any[]) => console.warn(PREFIX, ...args) // eslint-disable-next-line no-console +export const consoleDebug = (...args: any[]) => console.debug(PREFIX, ...args) +// eslint-disable-next-line no-console export const consoleTime = (label: string) => console.time(`${ PREFIX } ${ label }`) // eslint-disable-next-line no-console export const consoleTimeEnd = (label: string) => console.timeEnd(`${ PREFIX } ${ label }`)