UNPKG

@cloudinary/url-gen

Version:

Cloudinary URL-Gen SDK ========================= [![Build Status](https://api.travis-ci.com/cloudinary/js-url-gen.svg?branch=master)](https://app.travis-ci.com/github/cloudinary/js-url-gen) ## About The Cloudinary URL-Gen SDK allows you to quickly and eas

108 lines (104 loc) 3.62 kB
'use strict'; var Action = require('./Action-34aa7481.cjs'); var QualifierValue = require('./QualifierValue-e770d619.cjs'); var Qualifier = require('./Qualifier-6633a22f.cjs'); /** * @description A class that defines how to remove objects from an asset using Generative AI * @extends SDK.Action * @memberOf Actions.Effect * @see Visit {@link Actions.Effect|Effect} for an example */ class GenerativeRemove extends Action.Action { constructor() { super(); this._prompts = []; this._regions = []; this._detectMultiple = false; this._actionModel.actionType = "generativeRemove"; } prompt(value) { return this.prompts([value]); } prompts(value) { this._prompts = value; if (this._prompts) { this._actionModel.prompts = this._prompts; } return this; } region(value) { return this.regions([value]); } regions(value) { this._regions = value; if (this._regions) { this._actionModel.regions = this._regions; } return this; } detectMultiple(value = true) { this._detectMultiple = value; if (this._detectMultiple) { this._actionModel.detectMultiple = this._detectMultiple; } return this; } prepareQualifiers() { switch (true) { case this._prompts.length === 1: { return this.preparePromptQualifier(); } case this._prompts.length > 1: { return this.preparePromptsQualifier(); } case this._regions.length === 1: { return this.prepareRegionQualifier(); } case this._regions.length > 1: { return this.prepareRegionsQualifier(); } } } preparePromptQualifier() { const prompt = this._prompts[0]; let str = `gen_remove:${new QualifierValue.QualifierValue(`prompt_${prompt}`).toString()}`; if (this._detectMultiple) { str += `;${new QualifierValue.QualifierValue(`multiple_true`).toString()}`; } this.addQualifier(new Qualifier.Qualifier("e", str)); } preparePromptsQualifier() { const prompts = this._prompts; const str = `gen_remove:${new QualifierValue.QualifierValue(`prompt_(${prompts.join(";")})`).toString()}`; this.addQualifier(new Qualifier.Qualifier("e", str)); } prepareRegionQualifier() { const region = this.stringifyRegion(this._regions[0]); const str = `gen_remove:${new QualifierValue.QualifierValue(`region_${region}`).toString()}`; this.addQualifier(new Qualifier.Qualifier("e", str)); } prepareRegionsQualifier() { const regions = this._regions.map((region) => this.stringifyRegion(region)); const str = `gen_remove:${new QualifierValue.QualifierValue(`region_(${regions.join(";")})`).toString()}`; this.addQualifier(new Qualifier.Qualifier("e", str)); } stringifyRegion(region) { const { x, y, width, height } = region; return `(x_${x};y_${y};w_${width};h_${height})`; } static fromJson(actionModel) { const { prompts, regions, detectMultiple } = actionModel; const result = new this(); if (regions) { result.regions(regions); } if (prompts) { result.prompts(prompts); } if (detectMultiple) { result.detectMultiple(detectMultiple); } return result; } } exports.GenerativeRemove = GenerativeRemove;