2022-10-02 21:50:51 +00:00
|
|
|
export abstract class BaseOperation<P extends {}> {
|
2022-03-07 21:08:28 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-03-07 21:32:24 +00:00
|
|
|
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)) {
|
2022-03-07 21:32:24 +00:00
|
|
|
if (
|
2022-03-07 21:45:50 +00:00
|
|
|
!includeDefaults &&
|
2022-03-07 21:32:24 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|