interlinked/source/gegl/base.ts

40 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-10-02 21:50:51 +00:00
export abstract class BaseOperation<P extends {}> {
public abstract get default(): P;
2022-03-07 15:33:44 +00:00
public parameters: P;
/**
* Some GEGL operations will run infinitely unless you limit the buffer in
* some way, so all operations must indicate whether or not they should be
* followed by a crop operation.
*/
public abstract appendCrop: boolean;
/** The GEGL operation name, starting with `gegl:`. */
public abstract name: string;
constructor(parameters: P) {
this.parameters = parameters;
}
public graph(includeDefaults = false): string[] {
const defaults = this.default;
2022-03-07 15:33:44 +00:00
const graph: string[] = [this.name];
for (const [key, value] of Object.entries(this.parameters)) {
if (
2022-03-07 21:45:50 +00:00
!includeDefaults &&
key in defaults &&
(defaults as Record<string, any>)[key] === value
) {
continue;
}
2022-03-07 15:33:44 +00:00
const kebabCasedKey = key.replace(/([A-Z])/g, '-$1').toLowerCase();
graph.push(`${kebabCasedKey}=${value as string}`);
}
return graph;
}
}