修复滤镜两处问题:type 匹配不再靠 id 拼写、统一边缘格行为

- filters/index.ts 从 build() 实例读出真实 fabric type,导出 FILTER_TYPES 供面板使用
- FilterPanel.vue 改用 FILTER_TYPES[def.id],与注册表 id 命名解耦
- crystallize.ts applyTo2d 不再跳过越界格,越界种子参与取最近并 clamp 采样,与 WebGL 路径一致
This commit is contained in:
2026-09-04 16:39:05 +08:00
parent 9f2b14572d
commit 2f87a77992
3 changed files with 26 additions and 27 deletions
+4 -9
View File
@@ -2,7 +2,7 @@
import { onBeforeUnmount, reactive, watch } from "vue";
import { FabricImage, filters } from "fabric";
import type { FilterDef, FilterParam } from "@/types";
import { FILTERS } from "@/editor/filters";
import { FILTERS, FILTER_TYPES } from "@/editor/filters";
import { useEditor } from "@/editor/useEditor";
/**
@@ -27,11 +27,6 @@ for (const def of FILTERS) {
state[def.id] = { enabled: false, values };
}
/** 注册表 id → fabric 滤镜的 type 名(首字母大写即可覆盖当前六种)。 */
function fabricTypeOf(def: FilterDef): string {
return def.id.charAt(0).toUpperCase() + def.id.slice(1);
}
function currentImage(): FabricImage | null {
const obj = activeObject.value;
return obj instanceof FabricImage ? obj : null;
@@ -44,7 +39,7 @@ function readFromImage() {
? (image.filters as filters.BaseFilter<string>[])
: [];
for (const def of FILTERS) {
const type = fabricTypeOf(def);
const type = FILTER_TYPES[def.id];
const found = list.find((f) => f.type === type);
const st = state[def.id];
if (found) {
@@ -77,7 +72,7 @@ function scheduleApply() {
function toggle(def: FilterDef) {
const image = currentImage();
if (!image) return;
const type = fabricTypeOf(def);
const type = FILTER_TYPES[def.id];
const st = state[def.id];
st.enabled = !st.enabled;
if (st.enabled) {
@@ -95,7 +90,7 @@ function onParam(def: FilterDef, p: FilterParam, event: Event) {
const value = Number((event.target as HTMLInputElement).value);
state[def.id].values[p.key] = value;
const type = fabricTypeOf(def);
const type = FILTER_TYPES[def.id];
const instance = (
image.filters as filters.BaseFilter<string>[]
).find((f) => f.type === type);