From 552378887a2ebe0b594293d8db181b9433162f46 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: Fri, 12 May 2023 11:21:09 +0800 Subject: [PATCH] fix: clear the previous sample after generation --- src/add-sample.ts | 2 +- src/create-palette.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/add-sample.ts b/src/add-sample.ts index 3bc2044..23ef41e 100644 --- a/src/add-sample.ts +++ b/src/add-sample.ts @@ -53,7 +53,7 @@ export function addSample( context2d.drawImage(img, 0, 0, canvas.width, canvas.height) return addSample( context, - context2d.getImageData(0, 0, img.width, img.height).data, + context2d.getImageData(0, 0, canvas.width, canvas.height).data, options, ) }) diff --git a/src/create-palette.ts b/src/create-palette.ts index c55a851..60481a4 100644 --- a/src/create-palette.ts +++ b/src/create-palette.ts @@ -58,7 +58,9 @@ export function createPalette(options?: Options | Context): Palette { return result }, - generate(options) { + generate(options = {}) { + const { clearSamples = true } = options + if (clearSamples) previousSample = null generate(context, options) return this },