easydiffusion/ui/media/js/parameters.js

155 lines
3.8 KiB
JavaScript
Raw Normal View History

2022-10-29 01:48:32 +02:00
/**
* Enum of parameter types
* @readonly
* @enum {string}
*/
var ParameterType = {
checkbox: "checkbox",
select: "select",
select_multiple: "select_multiple",
2022-10-29 03:25:54 +02:00
custom: "custom",
2022-10-29 01:48:32 +02:00
};
/**
* JSDoc style
* @typedef {object} Parameter
* @property {string} id
* @property {ParameterType} type
* @property {string} label
* @property {?string} note
* @property {number|boolean|string} default
*/
/** @type {Array.<Parameter>} */
var PARAMETERS = [
{
id: "theme",
type: ParameterType.select,
label: "Theme",
default: "theme-default",
options: [ // Note: options expanded dynamically
{
value: "theme-default",
label: "Default"
}
]
},
{
id: "save_to_disk",
type: ParameterType.checkbox,
2022-10-29 03:31:46 +02:00
label: "Auto-Save Images",
note: "automatically saves images to the specified location",
2022-10-29 01:48:32 +02:00
default: false,
},
{
2022-10-29 03:25:54 +02:00
id: "diskPath",
type: ParameterType.custom,
2022-10-29 01:48:32 +02:00
label: "Save Location",
2022-10-29 03:25:54 +02:00
render: (parameter) => {
return `<input id="${parameter.id}" name="${parameter.id}" size="30" disabled>`
2022-10-29 03:25:54 +02:00
}
2022-10-29 01:48:32 +02:00
},
{
id: "sound_toggle",
type: ParameterType.checkbox,
2022-10-29 03:31:46 +02:00
label: "Enable Sound",
note: "plays a sound on task completion",
2022-10-29 01:48:32 +02:00
default: true,
},
{
id: "turbo",
type: ParameterType.checkbox,
label: "Turbo Mode",
default: true,
note: "generates images faster, but uses an additional 1 GB of GPU memory",
},
{
id: "use_cpu",
type: ParameterType.checkbox,
label: "Use CPU (not GPU)",
2022-10-29 01:48:32 +02:00
note: "warning: this will be *very* slow",
default: false,
},
{
id: "auto_pick_gpus",
type: ParameterType.checkbox,
label: "Automatically pick the GPUs",
default: false,
},
{
id: "use_gpus",
type: ParameterType.select_multiple,
label: "GPUs to use",
note: "to process in parallel",
default: false,
},
2022-10-29 01:48:32 +02:00
{
id: "use_full_precision",
type: ParameterType.checkbox,
2022-10-29 03:31:46 +02:00
label: "Use Full Precision",
2022-10-29 01:48:32 +02:00
note: "for GPU-only. warning: this will consume more VRAM",
default: false,
},
{
id: "auto_save_settings",
type: ParameterType.checkbox,
2022-10-29 03:31:46 +02:00
label: "Auto-Save Settings",
note: "restores settings on browser load",
2022-10-29 01:48:32 +02:00
default: true,
},
{
id: "use_beta_channel",
type: ParameterType.checkbox,
label: "🔥Beta channel",
note: "Get the latest features immediately (but could be less stable). Please restart the program after changing this.",
default: false,
},
2022-10-29 03:25:54 +02:00
];
function getParameterSettingsEntry(id) {
let parameter = PARAMETERS.filter(p => p.id === id)
if (parameter.length === 0) {
return
}
return parameter[0].settingsEntry
}
2022-10-29 03:25:54 +02:00
function getParameterElement(parameter) {
switch (parameter.type) {
case ParameterType.checkbox:
var is_checked = parameter.default ? " checked" : "";
return `<input id="${parameter.id}" name="${parameter.id}"${is_checked} type="checkbox">`
case ParameterType.select:
case ParameterType.select_multiple:
2022-10-29 03:25:54 +02:00
var options = (parameter.options || []).map(option => `<option value="${option.value}">${option.label}</option>`).join("")
var multiple = (parameter.type == ParameterType.select_multiple ? 'multiple' : '')
return `<select id="${parameter.id}" name="${parameter.id}" ${multiple}>${options}</select>`
2022-10-29 03:25:54 +02:00
case ParameterType.custom:
return parameter.render(parameter)
default:
console.error(`Invalid type for parameter ${parameter.id}`);
return "ERROR: Invalid Type"
}
}
var parametersTable = document.querySelector("#system-settings table")
/* fill in the system settings popup table */
function initParameters() {
PARAMETERS.forEach(parameter => {
var element = getParameterElement(parameter)
var note = parameter.note ? `<small>${parameter.note}</small>` : "";
var newrow = document.createElement('tr')
newrow.innerHTML = `
2022-10-29 03:25:54 +02:00
<td><label for="${parameter.id}">${parameter.label}</label></td>
<td><div>${element}${note}<div></td>`
parametersTable.appendChild(newrow)
parameter.settingsEntry = newrow
2022-10-29 03:25:54 +02:00
})
}
initParameters();