- Add Ctrl+mousewheel zooming to draw node preview - Implement grab+drag panning for draw node preview - Double-click to reset zoom/pan - Adjust brush cursor size for zoom level - Refactor preview rendering and interaction handling
54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
const DEFAULTS = {
|
|
version: 1,
|
|
epsilon: 1e-6,
|
|
luma_weights: [0.2126, 0.7152, 0.0722],
|
|
gamma_safe_min: 0.2,
|
|
gamma_max: 5,
|
|
preview_gamma_epsilon: 1e-3
|
|
};
|
|
let cached = { ...DEFAULTS };
|
|
let initPromise = null;
|
|
function toNum(v, fallback) {
|
|
const n = typeof v === "number" ? v : parseFloat(v);
|
|
return Number.isFinite(n) ? n : fallback;
|
|
}
|
|
function normalize(raw) {
|
|
const obj = raw && typeof raw === "object" ? raw : {};
|
|
const lw = Array.isArray(obj.luma_weights) ? obj.luma_weights : DEFAULTS.luma_weights;
|
|
return {
|
|
version: 1,
|
|
epsilon: toNum(obj.epsilon, DEFAULTS.epsilon),
|
|
luma_weights: [
|
|
toNum(lw[0], DEFAULTS.luma_weights[0]),
|
|
toNum(lw[1], DEFAULTS.luma_weights[1]),
|
|
toNum(lw[2], DEFAULTS.luma_weights[2])
|
|
],
|
|
gamma_safe_min: toNum(obj.gamma_safe_min, DEFAULTS.gamma_safe_min),
|
|
gamma_max: toNum(obj.gamma_max, DEFAULTS.gamma_max),
|
|
preview_gamma_epsilon: toNum(obj.preview_gamma_epsilon, DEFAULTS.preview_gamma_epsilon)
|
|
};
|
|
}
|
|
function getOpsConstants() {
|
|
return cached;
|
|
}
|
|
function initOpsConstants() {
|
|
initPromise ?? (initPromise = (async () => {
|
|
try {
|
|
const url = new URL("../shared/ops_constants.json", import.meta.url);
|
|
const res = await fetch(url, { cache: "no-store" });
|
|
if (!res.ok) {
|
|
console.warn("[ImageOps] ops_constants.json fetch failed:", res.status, res.statusText, "\u2014 using defaults");
|
|
return;
|
|
}
|
|
cached = normalize(await res.json());
|
|
} catch (err) {
|
|
console.warn("[ImageOps] ops_constants.json fetch error \u2014 using defaults:", err);
|
|
}
|
|
})());
|
|
return initPromise;
|
|
}
|
|
export {
|
|
getOpsConstants,
|
|
initOpsConstants
|
|
};
|