From f883492ea5d2aab9f0c45d56003f2338adfa125f Mon Sep 17 00:00:00 2001 From: bokuweb Date: Sat, 17 Aug 2024 19:40:42 +0900 Subject: [PATCH] feat: support diff image ext --- src/states/entity.ts | 10 ++++++---- src/types/reg.ts | 1 + src/utils/transformer.ts | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/states/entity.ts b/src/states/entity.ts index 3945fa6..09c0577 100644 --- a/src/states/entity.ts +++ b/src/states/entity.ts @@ -46,11 +46,13 @@ export const initializeEntityState = ( actual: data.actualDir, }; + const diffExtension = data.diffImageExtension ?? 'png'; + store.set(defaultEntityAtom, { - new: toEntities('new', dirs, data.newItems), - passed: toEntities('passed', dirs, data.passedItems), - failed: toEntities('changed', dirs, data.failedItems), - deleted: toEntities('deleted', dirs, data.deletedItems), + new: toEntities('new', dirs, data.newItems, diffExtension), + passed: toEntities('passed', dirs, data.passedItems, diffExtension), + failed: toEntities('changed', dirs, data.failedItems, diffExtension), + deleted: toEntities('deleted', dirs, data.deletedItems, diffExtension), }); const defaultEntity = store.get(defaultEntityAtom); diff --git a/src/types/reg.ts b/src/types/reg.ts index 8335ba6..a06bde4 100644 --- a/src/types/reg.ts +++ b/src/types/reg.ts @@ -30,6 +30,7 @@ export type RegData = { deletedItems: RegItem[]; ximgdiffConfig?: XIMGDiffConfig; links?: RegLink[]; + diffImageExtension?: 'webp' | 'png'; }; export type RegEntity = { diff --git a/src/utils/transformer.ts b/src/utils/transformer.ts index 3691f55..58f532d 100644 --- a/src/utils/transformer.ts +++ b/src/utils/transformer.ts @@ -15,6 +15,7 @@ export const toEntities = ( variant: RegVariant, dirs: Dirs, items: RegItem[], + diffExtension: 'png' | 'webp' = 'png', ): RegEntity[] => { const join = (key: keyof Dirs, to: string) => dirs[key].replace(/\/$/, '') + '/' + to.replace(/^\//, ''); @@ -26,7 +27,7 @@ export const toEntities = ( id, variant, name: item.raw, - diff: join('diff', item.encoded).replace(/\.[^.]+$/, '.png'), + diff: join('diff', item.encoded).replace(/\.[^.]+$/, `.${diffExtension}`), before: join('expected', item.encoded), after: join('actual', item.encoded), };