Skip to content

Commit

Permalink
feat: upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
qq15725 committed May 11, 2023
1 parent 10641a5 commit 8101932
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@
"vitest": "^0.31.0"
},
"dependencies": {
"modern-palette": "^0.1.8"
"modern-palette": "^0.2.0"
}
}
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 19 additions & 5 deletions src/create-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ export function createEncoder(options: EncoderOptions) {
log.timeEnd(`palette:sample-${ index }`)
},
async flush(): Promise<Uint8Array> {
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)
Expand All @@ -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,
Expand Down Expand Up @@ -156,14 +170,14 @@ export function createEncoder(options: EncoderOptions) {
encoder.palette.addSample(options)
}

async function generateInWorker(): Promise<Context> {
async function generateInWorker(maxColors: number): Promise<Context> {
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
}

Expand Down
3 changes: 2 additions & 1 deletion src/create-logger.ts
Original file line number Diff line number Diff line change
@@ -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),
}
}
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }`)
Expand Down

1 comment on commit 8101932

@vercel
Copy link

@vercel vercel bot commented on 8101932 May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

modern-gif – ./

modern-gif.vercel.app
modern-gif-git-main-qq15725.vercel.app
modern-gif-qq15725.vercel.app

Please sign in to comment.