Files
MajoorWaldi f7967be180 feat: add image processing scopes and media handling
- Implemented `computeScopes`, `drawHistogram`, `drawWaveform`, `drawRgbWaveform`, and `drawVectorscope` functions for image analysis.
- Created `parseAnnotated`, `makeViewUrl`, `ensureBitmap`, and `ensureVideoFrameCanvas` functions for media source handling.
- Added TypeScript definitions for ComfyUI integration, including node state, media state, and scopes options.
- Established project structure with `package.json`, `tsconfig.json`, and `package-lock.json` for dependency management and TypeScript configuration.
2026-03-18 06:40:43 +01:00

55 lines
1.5 KiB
JavaScript

function attachProgressBus(api) {
const state = {
running: false,
byNodeId: /* @__PURE__ */ new Map(),
widgets: /* @__PURE__ */ new Map()
};
function update(nodeId, value, max) {
const w = state.widgets.get(nodeId);
if (!w) return;
if (!state.running) {
w.wrap.style.display = "none";
w.bar.style.width = "0%";
return;
}
const pct = max > 0 ? value / max : 0;
w.wrap.style.display = "block";
w.bar.style.width = `${Math.round(Math.max(0, Math.min(1, pct)) * 100)}%`;
}
function resetAll() {
for (const [nodeId] of state.widgets) update(nodeId, 0, 0);
}
api.addEventListener("execution_start", () => {
state.running = true;
state.byNodeId.clear();
resetAll();
});
api.addEventListener("execution_error", () => {
state.running = false;
state.byNodeId.clear();
resetAll();
});
api.addEventListener("execution_end", () => {
state.running = false;
state.byNodeId.clear();
resetAll();
});
api.addEventListener("progress", (e) => {
const d = e?.detail ?? {};
const nodeId = d.node ?? d.node_id ?? d.nodeId ?? null;
if (nodeId == null) return;
state.byNodeId.set(nodeId, { value: d.value ?? 0, max: d.max ?? 0 });
update(nodeId, d.value ?? 0, d.max ?? 0);
});
return {
registerNodeWidget(node, wrap, bar) {
if (!node?.id) return;
state.widgets.set(node.id, { wrap, bar });
update(node.id, 0, 0);
}
};
}
export {
attachProgressBus
};