Remove comments that only restate the code, keeping the section banners and the notes that carry a reason, a measured fact or an external contract. ButtonOptions.width claimed to be a fixed width but only set minWidth, so the Graph and Texture pickers grew with the name they showed. It is now what it promises, with a separate minWidth for the buttons that have two forms. Narrow buttons shrink their padding, otherwise a 24px icon button had 8px left for its glyph and truncate dropped it entirely. __gm.labelsDropped() guards that class: the overflow guard only saw text that was too wide, never a label truncated to nothing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import type { NodeDef } from '../../NodeRegistry';
|
|
import { asNumber } from '../../values';
|
|
import { bool, num } from '../shared';
|
|
|
|
const OPERATORS: Record<string, (a: number, b: number) => boolean> = {
|
|
'==': (a, b) => a === b,
|
|
'!=': (a, b) => a !== b,
|
|
'<': (a, b) => a < b,
|
|
'<=': (a, b) => a <= b,
|
|
'>': (a, b) => a > b,
|
|
'>=': (a, b) => a >= b,
|
|
};
|
|
|
|
export const Compare: NodeDef = {
|
|
type: 'Compare',
|
|
label: 'Compare',
|
|
category: 'data',
|
|
description: 'Compares two numbers.',
|
|
inputs: [num('a'), num('b')],
|
|
outputs: [bool('result')],
|
|
params: [
|
|
{
|
|
key: 'op',
|
|
label: 'Operator',
|
|
kind: 'enum',
|
|
default: '<',
|
|
options: Object.keys(OPERATORS).map((op) => ({ value: op, label: op })),
|
|
},
|
|
],
|
|
run: (_ctx, inputs, params) => {
|
|
// The fallback matches the param's declared default, so a node with no setting behaves
|
|
// like a freshly created one.
|
|
const compare = OPERATORS[String(params.op)] ?? OPERATORS['<']!;
|
|
return { outputs: { result: compare(asNumber(inputs.a), asNumber(inputs.b)) } };
|
|
},
|
|
};
|