[TS] Enable strict mode (#3136)

This commit is contained in:
Chenlei Hu
2025-03-18 22:57:17 -04:00
committed by GitHub
parent 44edec7ad2
commit a049e9ae2d
64 changed files with 924 additions and 781 deletions

View File

@@ -1,4 +1,3 @@
// @ts-strict-ignore
import {
LGraph,
LGraphCanvas,
@@ -62,6 +61,7 @@ import { type ComfyWidgetConstructor, ComfyWidgets } from './widgets'
export const ANIM_PREVIEW_WIDGET = '$$comfy_animation_preview'
// @ts-expect-error fixme ts strict error
function sanitizeNodeName(string) {
let entityMap = {
'&': '',
@@ -73,6 +73,7 @@ function sanitizeNodeName(string) {
'=': ''
}
return String(string).replace(/[&<>"'`=]/g, function fromEntityMap(s) {
// @ts-expect-error fixme ts strict error
return entityMap[s]
})
}
@@ -110,17 +111,27 @@ export class ComfyApp {
vueAppReady: boolean
api: ComfyApi
ui: ComfyUI
// @ts-expect-error fixme ts strict error
extensionManager: ExtensionManager
// @ts-expect-error fixme ts strict error
_nodeOutputs: Record<string, any>
nodePreviewImages: Record<string, string[]>
// @ts-expect-error fixme ts strict error
graph: LGraph
// @ts-expect-error fixme ts strict error
canvas: LGraphCanvas
// @ts-expect-error fixme ts strict error
dragOverNode: LGraphNode | null
// @ts-expect-error fixme ts strict error
canvasEl: HTMLCanvasElement
// @ts-expect-error fixme ts strict error
lastNodeErrors: any[] | null
/** @type {ExecutionErrorWsMessage} */
// @ts-expect-error fixme ts strict error
lastExecutionError: { node_id?: NodeId } | null
// @ts-expect-error fixme ts strict error
configuringGraph: boolean
// @ts-expect-error fixme ts strict error
ctx: CanvasRenderingContext2D
bodyTop: HTMLElement
bodyLeft: HTMLElement
@@ -258,9 +269,11 @@ export class ComfyApp {
ComfyApp.clipspace_return_node = null
}
// @ts-expect-error fixme ts strict error
static copyToClipspace(node) {
var widgets = null
if (node.widgets) {
// @ts-expect-error fixme ts strict error
widgets = node.widgets.map(({ type, name, value }) => ({
type,
name,
@@ -361,6 +374,7 @@ export class ComfyApp {
}
if (ComfyApp.clipspace.widgets) {
ComfyApp.clipspace.widgets.forEach(({ type, name, value }) => {
// @ts-expect-error fixme ts strict error
const prop = Object.values(node.widgets).find(
(obj) => obj.type === type && obj.name === name
)
@@ -378,6 +392,7 @@ export class ComfyApp {
resultItem.filename +
(resultItem.type ? ` [${resultItem.type}]` : '')
} else {
// @ts-expect-error fixme ts strict error
prop.value = value
prop.callback?.(value)
}
@@ -394,6 +409,7 @@ export class ComfyApp {
const serialize = LGraph.prototype.serialize
const self = this
LGraph.prototype.serialize = function () {
// @ts-expect-error fixme ts strict error
const workflow = serialize.apply(this, arguments)
// Store the drag & scale info in the serialized workflow if the setting is enabled
@@ -432,17 +448,22 @@ export class ComfyApp {
}
// Dragging from Chrome->Firefox there is a file but its a bmp, so ignore that
if (
// @ts-expect-error fixme ts strict error
event.dataTransfer.files.length &&
// @ts-expect-error fixme ts strict error
event.dataTransfer.files[0].type !== 'image/bmp'
) {
// @ts-expect-error fixme ts strict error
await this.handleFile(event.dataTransfer.files[0])
} else {
// Try loading the first URI in the transfer list
const validTypes = ['text/uri-list', 'text/x-moz-url']
// @ts-expect-error fixme ts strict error
const match = [...event.dataTransfer.types].find((t) =>
validTypes.find((v) => t === v)
)
if (match) {
// @ts-expect-error fixme ts strict error
const uri = event.dataTransfer.getData(match)?.split('\n')?.[0]
if (uri) {
await this.handleFile(await (await fetch(uri)).blob())
@@ -533,6 +554,7 @@ export class ComfyApp {
}
// Fall through to Litegraph defaults
// @ts-expect-error fixme ts strict error
return origProcessKey.apply(this, arguments)
}
}
@@ -550,12 +572,15 @@ export class ComfyApp {
_fgcolor,
bgcolor
) {
// @ts-expect-error fixme ts strict error
const res = origDrawNodeShape.apply(this, arguments)
// @ts-expect-error fixme ts strict error
const nodeErrors = self.lastNodeErrors?.[node.id]
let color = null
let lineWidth = 1
// @ts-expect-error fixme ts strict error
if (node.id === +self.runningNodeId) {
color = '#0f0'
} else if (self.dragOverNode && node.id === self.dragOverNode.id) {
@@ -565,6 +590,7 @@ export class ComfyApp {
lineWidth = 2
} else if (
self.lastExecutionError &&
// @ts-expect-error fixme ts strict error
+self.lastExecutionError.node_id === node.id
) {
color = '#f0f'
@@ -587,6 +613,7 @@ export class ComfyApp {
})
}
// @ts-expect-error fixme ts strict error
if (self.progress && node.id === +self.runningNodeId) {
ctx.fillStyle = 'green'
ctx.fillRect(
@@ -659,6 +686,7 @@ export class ComfyApp {
node.bgcolor = adjustColor(bgColor, adjustments)
// @ts-expect-error fixme ts strict error
const res = origDrawNode.apply(this, arguments)
this.editor_alpha = editor_alpha
@@ -683,7 +711,9 @@ export class ComfyApp {
api.addEventListener('executing', () => {
this.graph.setDirtyCanvas(true, false)
// @ts-expect-error fixme ts strict error
this.revokePreviews(this.runningNodeId)
// @ts-expect-error fixme ts strict error
delete this.nodePreviewImages[this.runningNodeId]
})
@@ -741,6 +771,7 @@ export class ComfyApp {
LGraph.prototype.configure = function () {
app.configuringGraph = true
try {
// @ts-expect-error fixme ts strict error
return configure.apply(this, arguments)
} finally {
app.configuringGraph = false
@@ -757,6 +788,7 @@ export class ComfyApp {
node.onGraphConfigured?.()
}
// @ts-expect-error fixme ts strict error
const r = onConfigure?.apply(this, arguments)
// Fire after onConfigure, used by primitives to generate widget using input nodes config
@@ -772,10 +804,15 @@ export class ComfyApp {
* Set up the app on the page
*/
async setup(canvasEl: HTMLCanvasElement) {
// @ts-expect-error fixme ts strict error
this.bodyTop = document.getElementById('comfyui-body-top')
// @ts-expect-error fixme ts strict error
this.bodyLeft = document.getElementById('comfyui-body-left')
// @ts-expect-error fixme ts strict error
this.bodyRight = document.getElementById('comfyui-body-right')
// @ts-expect-error fixme ts strict error
this.bodyBottom = document.getElementById('comfyui-body-bottom')
// @ts-expect-error fixme ts strict error
this.canvasContainer = document.getElementById('graph-canvas-container')
this.canvasEl = canvasEl
@@ -798,6 +835,7 @@ export class ComfyApp {
this.canvas.state = reactive(this.canvas.state)
this.canvas.ds.state = reactive(this.canvas.ds.state)
// @ts-expect-error fixme ts strict error
this.ctx = canvasEl.getContext('2d')
LiteGraph.alt_drag_do_clone_nodes = true
@@ -831,6 +869,7 @@ export class ComfyApp {
const { width, height } = this.canvasEl.getBoundingClientRect()
this.canvasEl.width = Math.round(width * scale)
this.canvasEl.height = Math.round(height * scale)
// @ts-expect-error fixme ts strict error
this.canvasEl.getContext('2d').scale(scale, scale)
this.canvas?.draw(true, true)
}
@@ -840,6 +879,7 @@ export class ComfyApp {
) {
// Frontend only nodes registered by custom nodes.
// Example: https://github.com/rgthree/rgthree-comfy/blob/dd534e5384be8cf0c0fa35865afe2126ba75ac55/src_web/comfyui/fast_groups_bypasser.ts#L10
// @ts-expect-error fixme ts strict error
const rawDefs: Record<string, ComfyNodeDefV1> = Object.fromEntries(
Object.entries(LiteGraph.registered_node_types).map(([name, node]) => [
name,
@@ -880,6 +920,7 @@ export class ComfyApp {
`nodeDefs.${def.name}.display_name`,
def.display_name ?? def.name
),
// @ts-expect-error fixme ts strict error
description: def.description
? st(`nodeDefs.${def.name}.description`, def.description)
: undefined,
@@ -906,6 +947,7 @@ export class ComfyApp {
await this.registerNodesFromDefs(defs)
await useExtensionService().invokeExtensionsAsync('registerCustomNodes')
if (this.vueAppReady) {
// @ts-expect-error fixme ts strict error
this.updateVueAppNodeDefs(defs)
}
}
@@ -923,6 +965,7 @@ export class ComfyApp {
}
}
// @ts-expect-error fixme ts strict error
loadTemplateData(templateData) {
if (!templateData?.templates) {
return
@@ -955,14 +998,17 @@ export class ComfyApp {
nodeBottom = node.pos[1] + node.size[1]
// @ts-expect-error fixme ts strict error
if (maxY === false || nodeBottom > maxY) {
maxY = nodeBottom
}
}
// @ts-expect-error fixme ts strict error
app.canvas.graph_mouse[1] = maxY + 50
}
// @ts-expect-error fixme ts strict error
localStorage.setItem('litegrapheditor_clipboard', old)
}
@@ -972,6 +1018,7 @@ export class ComfyApp {
}
}
// @ts-expect-error fixme ts strict error
#showMissingModelsError(missingModels, paths) {
if (useSettingStore().get('Comfy.Workflow.ShowMissingModelsWarning')) {
useDialogService().showMissingModelsWarning({
@@ -1092,7 +1139,9 @@ export class ComfyApp {
let errorHint = []
// Try extracting filename to see if it was caused by an extension script
const filename =
// @ts-expect-error fixme ts strict error
error.fileName ||
// @ts-expect-error fixme ts strict error
(error.stack || '').match(/(\/extensions\/.*\.js)/)?.[1]
const pos = (filename || '').indexOf('/extensions/')
if (pos > -1) {
@@ -1118,6 +1167,7 @@ export class ComfyApp {
}),
$el('pre', {
style: { padding: '5px', backgroundColor: 'rgba(255,0,0,0.2)' },
// @ts-expect-error fixme ts strict error
textContent: error.toString()
}),
$el('pre', {
@@ -1129,6 +1179,7 @@ export class ComfyApp {
overflow: 'auto',
backgroundColor: 'rgba(0,0,0,0.2)'
},
// @ts-expect-error fixme ts strict error
textContent: error.stack || 'No stacktrace available'
}),
...errorHint
@@ -1174,9 +1225,12 @@ export class ComfyApp {
if (reset_invalid_values) {
if (widget.type == 'combo') {
if (
// @ts-expect-error fixme ts strict error
!widget.options.values.includes(widget.value as string) &&
// @ts-expect-error fixme ts strict error
widget.options.values.length > 0
) {
// @ts-expect-error fixme ts strict error
widget.value = widget.options.values[0]
}
}
@@ -1225,6 +1279,7 @@ export class ComfyApp {
})
}
// @ts-expect-error fixme ts strict error
#formatPromptError(error) {
if (error == null) {
return '(unknown error)'
@@ -1251,10 +1306,12 @@ export class ComfyApp {
}
async queuePrompt(number: number, batchCount: number = 1): Promise<boolean> {
// @ts-expect-error fixme ts strict error
this.#queueItems.push({ number, batchCount })
// Only have one action process the items so each one gets a unique seed correctly
if (this.#processingQueue) {
// @ts-expect-error fixme ts strict error
return
}
@@ -1263,6 +1320,7 @@ export class ComfyApp {
try {
while (this.#queueItems.length) {
// @ts-expect-error fixme ts strict error
;({ number, batchCount } = this.#queueItems.pop())
for (let i = 0; i < batchCount; i++) {
@@ -1273,12 +1331,15 @@ export class ComfyApp {
const p = await this.graphToPrompt()
try {
const res = await api.queuePrompt(number, p)
// @ts-expect-error fixme ts strict error
this.lastNodeErrors = res.node_errors
// @ts-expect-error fixme ts strict error
if (this.lastNodeErrors.length > 0) {
this.canvas.draw(true, true)
} else {
try {
useExecutionStore().storePrompt({
// @ts-expect-error fixme ts strict error
id: res.prompt_id,
nodes: Object.keys(p.output),
workflow: useWorkspaceStore().workflow
@@ -1289,7 +1350,9 @@ export class ComfyApp {
} catch (error) {
const formattedError = this.#formatPromptError(error)
this.ui.dialog.show(formattedError)
// @ts-expect-error fixme ts strict error
if (error.response) {
// @ts-expect-error fixme ts strict error
this.lastNodeErrors = error.response.node_errors
this.canvas.draw(true, true)
}
@@ -1299,6 +1362,7 @@ export class ComfyApp {
// Allow widgets to run callbacks after a prompt has been queued
// e.g. random seed after every gen
executeWidgetsCallback(
// @ts-expect-error fixme ts strict error
p.workflow.nodes.map((n) => this.graph.getNodeById(n.id)),
'afterQueued'
)
@@ -1313,6 +1377,7 @@ export class ComfyApp {
return !this.lastNodeErrors
}
// @ts-expect-error fixme ts strict error
showErrorOnFileLoad(file) {
this.ui.dialog.show(
$el('div', [
@@ -1325,7 +1390,9 @@ export class ComfyApp {
* Loads workflow data from the specified file
* @param {File} file
*/
// @ts-expect-error fixme ts strict error
async handleFile(file) {
// @ts-expect-error fixme ts strict error
const removeExt = (f) => {
if (!f) return f
const p = f.lastIndexOf('.')
@@ -1437,11 +1504,13 @@ export class ComfyApp {
}
}
// @ts-expect-error fixme ts strict error
isApiJson(data) {
// @ts-expect-error
return Object.values(data).every((v) => v.class_type)
}
// @ts-expect-error fixme ts strict error
loadApiJson(apiData, fileName: string) {
useWorkflowService().beforeLoadNewGraph()
@@ -1462,8 +1531,11 @@ export class ComfyApp {
for (const id of ids) {
const data = apiData[id]
const node = LiteGraph.createNode(data.class_type)
// @ts-expect-error fixme ts strict error
node.id = isNaN(+id) ? id : +id
// @ts-expect-error fixme ts strict error
node.title = data._meta?.title ?? node.title
// @ts-expect-error fixme ts strict error
app.graph.add(node)
}
@@ -1475,21 +1547,26 @@ export class ComfyApp {
if (value instanceof Array) {
const [fromId, fromSlot] = value
const fromNode = app.graph.getNodeById(fromId)
// @ts-expect-error fixme ts strict error
let toSlot = node.inputs?.findIndex((inp) => inp.name === input)
if (toSlot == null || toSlot === -1) {
try {
// Target has no matching input, most likely a converted widget
// @ts-expect-error fixme ts strict error
const widget = node.widgets?.find((w) => w.name === input)
// @ts-expect-error
if (widget && node.convertWidgetToInput?.(widget)) {
// @ts-expect-error fixme ts strict error
toSlot = node.inputs?.length - 1
}
} catch (error) {}
}
if (toSlot != null || toSlot !== -1) {
// @ts-expect-error fixme ts strict error
fromNode.connect(fromSlot, node, toSlot)
}
} else {
// @ts-expect-error fixme ts strict error
const widget = node.widgets?.find((w) => w.name === input)
if (widget) {
widget.value = value
@@ -1508,21 +1585,26 @@ export class ComfyApp {
if (value instanceof Array) {
const [fromId, fromSlot] = value
const fromNode = app.graph.getNodeById(fromId)
// @ts-expect-error fixme ts strict error
let toSlot = node.inputs?.findIndex((inp) => inp.name === input)
if (toSlot == null || toSlot === -1) {
try {
// Target has no matching input, most likely a converted widget
// @ts-expect-error fixme ts strict error
const widget = node.widgets?.find((w) => w.name === input)
// @ts-expect-error
if (widget && node.convertWidgetToInput?.(widget)) {
// @ts-expect-error fixme ts strict error
toSlot = node.inputs?.length - 1
}
} catch (error) {}
}
if (toSlot != null || toSlot !== -1) {
// @ts-expect-error fixme ts strict error
fromNode.connect(fromSlot, node, toSlot)
}
} else {
// @ts-expect-error fixme ts strict error
const widget = node.widgets?.find((w) => w.name === input)
if (widget) {
widget.value = value
@@ -1565,19 +1647,19 @@ export class ComfyApp {
this.registerNodeDef(nodeId, defs[nodeId])
}
for (const node of this.graph.nodes) {
// @ts-expect-error fixme ts strict error
const def = defs[node.type]
// Allow primitive nodes to handle refresh
node.refreshComboInNode?.(defs)
if (!def?.input) continue
// @ts-expect-error fixme ts strict error
for (const widget of node.widgets) {
if (widget.type === 'combo') {
if (def['input'].required?.[widget.name] !== undefined) {
// @ts-expect-error InputSpec is not typed correctly
widget.options.values = def['input'].required[widget.name][0]
} else if (def['input'].optional?.[widget.name] !== undefined) {
// @ts-expect-error InputSpec is not typed correctly
widget.options.values = def['input'].optional[widget.name][0]
}
}
@@ -1590,6 +1672,7 @@ export class ComfyApp {
)
if (this.vueAppReady) {
// @ts-expect-error fixme ts strict error
this.updateVueAppNodeDefs(defs)
useToastStore().remove(requestToastMessage)
useToastStore().add({
@@ -1628,6 +1711,7 @@ export class ComfyApp {
const rect = this.canvasContainer.getBoundingClientRect()
const containerOffsets = [rect.left, rect.top]
return _.zip(pos, this.canvas.ds.offset, containerOffsets).map(
// @ts-expect-error fixme ts strict error
([p, o1, o2]) => (p - o2) / this.canvas.ds.scale - o1
) as Vector2
}
@@ -1636,6 +1720,7 @@ export class ComfyApp {
const rect = this.canvasContainer.getBoundingClientRect()
const containerOffsets = [rect.left, rect.top]
return _.zip(pos, this.canvas.ds.offset, containerOffsets).map(
// @ts-expect-error fixme ts strict error
([p, o1, o2]) => (p + o1) * this.canvas.ds.scale + o2
) as Vector2
}

View File

@@ -1,4 +1,3 @@
// @ts-strict-ignore
export function getFromFlacBuffer(buffer: ArrayBuffer): Record<string, string> {
const dataView = new DataView(buffer)
@@ -6,6 +5,7 @@ export function getFromFlacBuffer(buffer: ArrayBuffer): Record<string, string> {
const signature = String.fromCharCode(...new Uint8Array(buffer, 0, 4))
if (signature !== 'fLaC') {
console.error('Not a valid FLAC file')
// @ts-expect-error fixme ts strict error
return
}
@@ -29,6 +29,7 @@ export function getFromFlacBuffer(buffer: ArrayBuffer): Record<string, string> {
if (isLastBlock) break
}
// @ts-expect-error fixme ts strict error
return vorbisComment
}
@@ -36,6 +37,7 @@ export function getFromFlacFile(file: File): Promise<Record<string, string>> {
return new Promise((r) => {
const reader = new FileReader()
reader.onload = function (event) {
// @ts-expect-error fixme ts strict error
const arrayBuffer = event.target.result as ArrayBuffer
r(getFromFlacBuffer(arrayBuffer))
}
@@ -64,6 +66,7 @@ function parseVorbisComment(dataView: DataView): Record<string, string> {
const ind = comment.indexOf('=')
const key = comment.substring(0, ind)
// @ts-expect-error fixme ts strict error
comments[key] = comment.substring(ind + 1)
}

View File

@@ -1,4 +1,3 @@
// @ts-strict-ignore
export function getFromPngBuffer(buffer: ArrayBuffer) {
// Get the PNG data as a Uint8Array
const pngData = new Uint8Array(buffer)
@@ -46,6 +45,7 @@ export function getFromPngFile(file: File) {
return new Promise<Record<string, string>>((r) => {
const reader = new FileReader()
reader.onload = (event) => {
// @ts-expect-error fixme ts strict error
r(getFromPngBuffer(event.target.result as ArrayBuffer))
}

View File

@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { LiteGraph } from '@comfyorg/litegraph'
import { api } from './api'
@@ -14,11 +13,13 @@ export function getFlacMetadata(file: File): Promise<Record<string, string>> {
return getFromFlacFile(file)
}
// @ts-expect-error fixme ts strict error
function parseExifData(exifData) {
// Check for the correct TIFF header (0x4949 for little-endian or 0x4D4D for big-endian)
const isLittleEndian = String.fromCharCode(...exifData.slice(0, 2)) === 'II'
// Function to read 16-bit and 32-bit integers from binary data
// @ts-expect-error fixme ts strict error
function readInt(offset, isLittleEndian, length) {
let arr = exifData.slice(offset, offset + length)
if (length === 2) {
@@ -37,10 +38,12 @@ function parseExifData(exifData) {
// Read the offset to the first IFD (Image File Directory)
const ifdOffset = readInt(4, isLittleEndian, 4)
// @ts-expect-error fixme ts strict error
function parseIFD(offset) {
const numEntries = readInt(offset, isLittleEndian, 2)
const result = {}
// @ts-expect-error fixme ts strict error
for (let i = 0; i < numEntries; i++) {
const entryOffset = offset + 2 + i * 12
const tag = readInt(entryOffset, isLittleEndian, 2)
@@ -53,10 +56,12 @@ function parseExifData(exifData) {
if (type === 2) {
// ASCII string
value = new TextDecoder('utf-8').decode(
// @ts-expect-error fixme ts strict error
exifData.subarray(valueOffset, valueOffset + numValues - 1)
)
}
// @ts-expect-error fixme ts strict error
result[tag] = value
}
@@ -68,10 +73,12 @@ function parseExifData(exifData) {
return ifdData
}
// @ts-expect-error fixme ts strict error
export function getWebpMetadata(file) {
return new Promise<Record<string, string>>((r) => {
const reader = new FileReader()
reader.onload = (event) => {
// @ts-expect-error fixme ts strict error
const webp = new Uint8Array(event.target.result as ArrayBuffer)
const dataView = new DataView(webp.buffer)
@@ -105,9 +112,11 @@ export function getWebpMetadata(file) {
webp.slice(offset + 8, offset + 8 + chunk_length)
)
for (var key in data) {
// @ts-expect-error fixme ts strict error
const value = data[key] as string
if (typeof value === 'string') {
const index = value.indexOf(':')
// @ts-expect-error fixme ts strict error
txt_chunks[value.slice(0, index)] = value.slice(index + 1)
}
}
@@ -124,10 +133,12 @@ export function getWebpMetadata(file) {
})
}
// @ts-expect-error fixme ts strict error
export function getLatentMetadata(file) {
return new Promise((r) => {
const reader = new FileReader()
reader.onload = (event) => {
// @ts-expect-error fixme ts strict error
const safetensorsData = new Uint8Array(event.target.result as ArrayBuffer)
const dataView = new DataView(safetensorsData.buffer)
let header_size = dataView.getUint32(0, true)
@@ -145,6 +156,7 @@ export function getLatentMetadata(file) {
})
}
// @ts-expect-error fixme ts strict error
export async function importA1111(graph, parameters) {
const p = parameters.lastIndexOf('\nSteps:')
if (p > -1) {
@@ -155,6 +167,7 @@ export async function importA1111(graph, parameters) {
.match(
new RegExp('\\s*([^:]+:\\s*([^"\\{].*?|".*?"|\\{.*?\\}))\\s*(,|$)', 'g')
)
// @ts-expect-error fixme ts strict error
.reduce((p, n) => {
const s = n.split(':')
if (s[1].endsWith(',')) {
@@ -176,18 +189,24 @@ export async function importA1111(graph, parameters) {
const imageNode = LiteGraph.createNode('EmptyLatentImage')
const vaeNode = LiteGraph.createNode('VAEDecode')
const saveNode = LiteGraph.createNode('SaveImage')
// @ts-expect-error fixme ts strict error
let hrSamplerNode = null
let hrSteps = null
// @ts-expect-error fixme ts strict error
const ceil64 = (v) => Math.ceil(v / 64) * 64
// @ts-expect-error fixme ts strict error
const getWidget = (node, name) => {
// @ts-expect-error fixme ts strict error
return node.widgets.find((w) => w.name === name)
}
// @ts-expect-error fixme ts strict error
const setWidgetValue = (node, name, value, isOptionPrefix?) => {
const w = getWidget(node, name)
if (isOptionPrefix) {
// @ts-expect-error fixme ts strict error
const o = w.options.values.find((w) => w.startsWith(value))
if (o) {
w.value = o
@@ -200,8 +219,11 @@ export async function importA1111(graph, parameters) {
}
}
// @ts-expect-error fixme ts strict error
const createLoraNodes = (clipNode, text, prevClip, prevModel) => {
// @ts-expect-error fixme ts strict error
const loras = []
// @ts-expect-error fixme ts strict error
text = text.replace(/<lora:([^:]+:[^>]+)>/g, function (m, c) {
const s = c.split(':')
const weight = parseFloat(s[1])
@@ -213,6 +235,7 @@ export async function importA1111(graph, parameters) {
return ''
})
// @ts-expect-error fixme ts strict error
for (const l of loras) {
const loraNode = LiteGraph.createNode('LoraLoader')
graph.add(loraNode)
@@ -227,6 +250,7 @@ export async function importA1111(graph, parameters) {
prevClip.node.connect(1, clipNode, 0)
prevModel.node.connect(0, samplerNode, 0)
// @ts-expect-error fixme ts strict error
if (hrSamplerNode) {
prevModel.node.connect(0, hrSamplerNode, 0)
}
@@ -234,6 +258,7 @@ export async function importA1111(graph, parameters) {
return { text, prevModel, prevClip }
}
// @ts-expect-error fixme ts strict error
const replaceEmbeddings = (text) => {
if (!embeddings.length) return text
return text.replaceAll(
@@ -249,6 +274,7 @@ export async function importA1111(graph, parameters) {
)
}
// @ts-expect-error fixme ts strict error
const popOpt = (name) => {
const v = opts[name]
delete opts[name]
@@ -265,28 +291,42 @@ export async function importA1111(graph, parameters) {
graph.add(vaeNode)
graph.add(saveNode)
// @ts-expect-error fixme ts strict error
ckptNode.connect(1, clipSkipNode, 0)
// @ts-expect-error fixme ts strict error
clipSkipNode.connect(0, positiveNode, 0)
// @ts-expect-error fixme ts strict error
clipSkipNode.connect(0, negativeNode, 0)
// @ts-expect-error fixme ts strict error
ckptNode.connect(0, samplerNode, 0)
// @ts-expect-error fixme ts strict error
positiveNode.connect(0, samplerNode, 1)
// @ts-expect-error fixme ts strict error
negativeNode.connect(0, samplerNode, 2)
// @ts-expect-error fixme ts strict error
imageNode.connect(0, samplerNode, 3)
// @ts-expect-error fixme ts strict error
vaeNode.connect(0, saveNode, 0)
// @ts-expect-error fixme ts strict error
samplerNode.connect(0, vaeNode, 0)
// @ts-expect-error fixme ts strict error
ckptNode.connect(2, vaeNode, 1)
const handlers = {
// @ts-expect-error fixme ts strict error
model(v) {
setWidgetValue(ckptNode, 'ckpt_name', v, true)
},
vae() {},
// @ts-expect-error fixme ts strict error
'cfg scale'(v) {
setWidgetValue(samplerNode, 'cfg', +v)
},
// @ts-expect-error fixme ts strict error
'clip skip'(v) {
setWidgetValue(clipSkipNode, 'stop_at_clip_layer', -v)
},
// @ts-expect-error fixme ts strict error
sampler(v) {
let name = v.toLowerCase().replace('++', 'pp').replaceAll(' ', '_')
if (name.includes('karras')) {
@@ -297,12 +337,14 @@ export async function importA1111(graph, parameters) {
}
const w = getWidget(samplerNode, 'sampler_name')
const o = w.options.values.find(
// @ts-expect-error fixme ts strict error
(w) => w === name || w === 'sample_' + name
)
if (o) {
setWidgetValue(samplerNode, 'sampler_name', o)
}
},
// @ts-expect-error fixme ts strict error
size(v) {
const wxh = v.split('x')
const w = ceil64(+wxh[0])
@@ -332,6 +374,7 @@ export async function importA1111(graph, parameters) {
if (hrMethod.startsWith('Latent')) {
latentNode = upscaleNode = LiteGraph.createNode('LatentUpscale')
graph.add(upscaleNode)
// @ts-expect-error fixme ts strict error
samplerNode.connect(0, upscaleNode, 0)
switch (hrMethod) {
@@ -343,7 +386,9 @@ export async function importA1111(graph, parameters) {
} else {
const decode = LiteGraph.createNode('VAEDecodeTiled')
graph.add(decode)
// @ts-expect-error fixme ts strict error
samplerNode.connect(0, decode, 0)
// @ts-expect-error fixme ts strict error
ckptNode.connect(2, decode, 1)
const upscaleLoaderNode =
@@ -355,17 +400,22 @@ export async function importA1111(graph, parameters) {
'ImageUpscaleWithModel'
)
graph.add(modelUpscaleNode)
// @ts-expect-error fixme ts strict error
decode.connect(0, modelUpscaleNode, 1)
// @ts-expect-error fixme ts strict error
upscaleLoaderNode.connect(0, modelUpscaleNode, 0)
upscaleNode = LiteGraph.createNode('ImageScale')
graph.add(upscaleNode)
// @ts-expect-error fixme ts strict error
modelUpscaleNode.connect(0, upscaleNode, 0)
const vaeEncodeNode = (latentNode =
LiteGraph.createNode('VAEEncodeTiled'))
graph.add(vaeEncodeNode)
// @ts-expect-error fixme ts strict error
upscaleNode.connect(0, vaeEncodeNode, 0)
// @ts-expect-error fixme ts strict error
ckptNode.connect(2, vaeEncodeNode, 1)
}
@@ -374,16 +424,23 @@ export async function importA1111(graph, parameters) {
hrSamplerNode = LiteGraph.createNode('KSampler')
graph.add(hrSamplerNode)
// @ts-expect-error fixme ts strict error
ckptNode.connect(0, hrSamplerNode, 0)
// @ts-expect-error fixme ts strict error
positiveNode.connect(0, hrSamplerNode, 1)
// @ts-expect-error fixme ts strict error
negativeNode.connect(0, hrSamplerNode, 2)
// @ts-expect-error fixme ts strict error
latentNode.connect(0, hrSamplerNode, 3)
// @ts-expect-error fixme ts strict error
hrSamplerNode.connect(0, vaeNode, 0)
}
},
// @ts-expect-error fixme ts strict error
steps(v) {
setWidgetValue(samplerNode, 'steps', +v)
},
// @ts-expect-error fixme ts strict error
seed(v) {
setWidgetValue(samplerNode, 'seed', +v)
}
@@ -391,6 +448,7 @@ export async function importA1111(graph, parameters) {
for (const opt in opts) {
if (opt in handlers) {
// @ts-expect-error fixme ts strict error
handlers[opt](popOpt(opt))
}
}

View File

@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { type StatusWsMessageStatus, TaskItem } from '@/schemas/apiSchema'
import { useDialogService } from '@/services/dialogService'
import { useLitegraphService } from '@/services/litegraphService'
@@ -92,6 +91,7 @@ export function $el<TTag extends string>(
return element as ElementType<TTag>
}
// @ts-expect-error fixme ts strict error
function dragElement(dragEl): () => void {
var posDiffX = 0,
posDiffY = 0,
@@ -148,6 +148,7 @@ function dragElement(dragEl): () => void {
dragEl.style.top = newPosY + 'px'
dragEl.style.bottom = 'unset'
// @ts-expect-error fixme ts strict error
if (savePos) {
localStorage.setItem(
'Comfy.MenuPosition',
@@ -170,10 +171,12 @@ function dragElement(dragEl): () => void {
}
}
// @ts-expect-error fixme ts strict error
let savePos = undefined
restorePos()
savePos = true
// @ts-expect-error fixme ts strict error
function dragMouseDown(e) {
e = e || window.event
e.preventDefault()
@@ -185,6 +188,7 @@ function dragElement(dragEl): () => void {
document.onmousemove = elementDrag
}
// @ts-expect-error fixme ts strict error
function elementDrag(e) {
e = e || window.event
e.preventDefault()
@@ -229,6 +233,7 @@ class ComfyList {
element: HTMLDivElement
button?: HTMLButtonElement
// @ts-expect-error fixme ts strict error
constructor(text, type?, reverse?) {
this.#text = text
this.#type = type || text.toLowerCase()
@@ -249,6 +254,7 @@ class ComfyList {
textContent: section
}),
$el('div.comfy-list-items', [
// @ts-expect-error fixme ts strict error
...(this.#reverse ? items[section].reverse() : items[section]).map(
(item: TaskItem) => {
// Allow items to specify a custom remove action (e.g. for interrupt current prompt)
@@ -264,6 +270,7 @@ class ComfyList {
textContent: 'Load',
onclick: async () => {
await app.loadGraphData(
// @ts-expect-error fixme ts strict error
item.prompt[3].extra_pnginfo.workflow,
true,
false
@@ -310,6 +317,7 @@ class ComfyList {
async show() {
this.element.style.display = 'block'
// @ts-expect-error fixme ts strict error
this.button.textContent = 'Close'
await this.load()
@@ -317,6 +325,7 @@ class ComfyList {
hide() {
this.element.style.display = 'none'
// @ts-expect-error fixme ts strict error
this.button.textContent = 'View ' + this.#text
}
@@ -339,14 +348,22 @@ export class ComfyUI {
lastQueueSize: number
queue: ComfyList
history: ComfyList
// @ts-expect-error fixme ts strict error
autoQueueMode: string
// @ts-expect-error fixme ts strict error
graphHasChanged: boolean
// @ts-expect-error fixme ts strict error
autoQueueEnabled: boolean
// @ts-expect-error fixme ts strict error
menuContainer: HTMLDivElement
// @ts-expect-error fixme ts strict error
queueSize: Element
// @ts-expect-error fixme ts strict error
restoreMenuPosition: () => void
// @ts-expect-error fixme ts strict error
loadFile: () => void
// @ts-expect-error fixme ts strict error
constructor(app) {
this.app = app
this.dialog = new ComfyDialog()
@@ -373,6 +390,7 @@ export class ComfyUI {
style: { display: 'none' },
parent: document.body,
onchange: async () => {
// @ts-expect-error fixme ts strict error
await app.handleFile(fileInput.files[0])
fileInput.value = ''
}
@@ -394,6 +412,7 @@ export class ComfyUI {
}
],
{
// @ts-expect-error fixme ts strict error
onChange: (value) => {
this.autoQueueMode = value.item.value
}
@@ -456,7 +475,9 @@ export class ComfyUI {
$el('label', { innerHTML: 'Extra options' }, [
$el('input', {
type: 'checkbox',
// @ts-expect-error fixme ts strict error
onchange: (i) => {
// @ts-expect-error fixme ts strict error
document.getElementById('extraOptions').style.display = i
.srcElement.checked
? 'block'
@@ -492,6 +513,7 @@ export class ComfyUI {
value: this.batchCount,
min: '1',
style: { width: '35%', marginLeft: '0.4em' },
// @ts-expect-error fixme ts strict error
oninput: (i) => {
this.batchCount = i.target.value
/* Even though an <input> element with a type of range logically represents a number (since
@@ -511,6 +533,7 @@ export class ComfyUI {
min: '1',
max: '100',
value: this.batchCount,
// @ts-expect-error fixme ts strict error
oninput: (i) => {
this.batchCount = i.srcElement.value
// Note
@@ -532,6 +555,7 @@ export class ComfyUI {
type: 'checkbox',
checked: false,
title: 'Automatically queue prompt when the queue size hits 0',
// @ts-expect-error fixme ts strict error
onchange: (e) => {
this.autoQueueEnabled = e.target.checked
autoQueueModeEl.style.display = this.autoQueueEnabled

View File

@@ -1,13 +1,14 @@
// @ts-strict-ignore
import { $el } from '../../ui'
import { ComfyDialog } from '../dialog'
export class ComfyAsyncDialog extends ComfyDialog<HTMLDialogElement> {
// @ts-expect-error fixme ts strict error
#resolve: (value: any) => void
constructor(actions?: Array<string | { value?: any; text: string }>) {
super(
'dialog.comfy-dialog.comfyui-dialog',
// @ts-expect-error fixme ts strict error
actions?.map((opt) => {
if (typeof opt === 'string') {
opt = { text: opt }

View File

@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { Settings } from '@/schemas/apiSchema'
import type { ComfyApp } from '@/scripts/app'
@@ -27,6 +26,7 @@ export class ComfyButton implements ComfyComponent<HTMLElement> {
isOver = false
iconElement = $el('i.mdi')
contentElement = $el('span')
// @ts-expect-error fixme ts strict error
popup: ComfyPopup
element: HTMLElement
overIcon: string
@@ -70,18 +70,22 @@ export class ComfyButton implements ComfyComponent<HTMLElement> {
[this.iconElement, this.contentElement]
)
// @ts-expect-error fixme ts strict error
this.icon = prop(
this,
'icon',
icon,
toggleElement(this.iconElement, { onShow: this.updateIcon })
)
// @ts-expect-error fixme ts strict error
this.overIcon = prop(this, 'overIcon', overIcon, () => {
if (this.isOver) {
this.updateIcon()
}
})
// @ts-expect-error fixme ts strict error
this.iconSize = prop(this, 'iconSize', iconSize, this.updateIcon)
// @ts-expect-error fixme ts strict error
this.content = prop(
this,
'content',
@@ -97,6 +101,7 @@ export class ComfyButton implements ComfyComponent<HTMLElement> {
})
)
// @ts-expect-error fixme ts strict error
this.tooltip = prop(this, 'tooltip', tooltip, (v) => {
if (v) {
this.element.title = v
@@ -113,6 +118,7 @@ export class ComfyButton implements ComfyComponent<HTMLElement> {
this.updateClasses()
;(this.element as HTMLButtonElement).disabled = !this.enabled
})
// @ts-expect-error fixme ts strict error
this.action = prop(this, 'action', action)
this.element.addEventListener('click', (e) => {
if (this.popup) {
@@ -127,9 +133,11 @@ export class ComfyButton implements ComfyComponent<HTMLElement> {
if (visibilitySetting?.id) {
const settingUpdated = () => {
this.hidden =
// @ts-expect-error fixme ts strict error
app.ui.settings.getSettingValue(visibilitySetting.id) !==
visibilitySetting.showValue
}
// @ts-expect-error fixme ts strict error
app.ui.settings.addEventListener(
visibilitySetting.id + '.change',
settingUpdated

View File

@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { $el } from '../../ui'
import { prop } from '../../utils'
import { ComfyButton } from './button'
@@ -33,6 +32,7 @@ export class ComfyButtonGroup {
}
update() {
// @ts-expect-error fixme ts strict error
this.element.replaceChildren(...this.buttons.map((b) => b['element'] ?? b))
}
}

View File

@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { $el } from '../../ui'
import { prop } from '../../utils'
import { ClassList, applyClasses } from '../utils'
@@ -90,6 +89,7 @@ export class ComfyPopup extends EventTarget {
this.dispatchEvent(new CustomEvent('change'))
}
// @ts-expect-error fixme ts strict error
#escHandler = (e) => {
if (e.key === 'Escape') {
this.open = false
@@ -98,6 +98,7 @@ export class ComfyPopup extends EventTarget {
}
}
// @ts-expect-error fixme ts strict error
#clickHandler = (e) => {
/** @type {any} */
const target = e.target

View File

@@ -1,10 +1,10 @@
// @ts-strict-ignore
import { $el } from '../ui'
export class ComfyDialog<
T extends HTMLElement = HTMLElement
> extends EventTarget {
element: T
// @ts-expect-error fixme ts strict error
textElement: HTMLElement
#buttons: HTMLButtonElement[] | null
@@ -35,6 +35,7 @@ export class ComfyDialog<
this.element.style.display = 'none'
}
// @ts-expect-error fixme ts strict error
show(html) {
if (typeof html === 'string') {
this.textElement.innerHTML = html

View File

@@ -1,4 +1,3 @@
// @ts-strict-ignore
/*
Original implementation:
https://github.com/TahaSh/drag-to-reorder
@@ -45,9 +44,13 @@ $el('style', {
export class DraggableList extends EventTarget {
listContainer
// @ts-expect-error fixme ts strict error
draggableItem
// @ts-expect-error fixme ts strict error
pointerStartX
// @ts-expect-error fixme ts strict error
pointerStartY
// @ts-expect-error fixme ts strict error
scrollYMax
itemsGap = 0
items = []
@@ -56,6 +59,7 @@ export class DraggableList extends EventTarget {
off = []
offDrag = []
// @ts-expect-error fixme ts strict error
constructor(element, itemSelector) {
super()
this.listContainer = element
@@ -63,9 +67,13 @@ export class DraggableList extends EventTarget {
if (!this.listContainer) return
// @ts-expect-error fixme ts strict error
this.off.push(this.on(this.listContainer, 'mousedown', this.dragStart))
// @ts-expect-error fixme ts strict error
this.off.push(this.on(this.listContainer, 'touchstart', this.dragStart))
// @ts-expect-error fixme ts strict error
this.off.push(this.on(document, 'mouseup', this.dragEnd))
// @ts-expect-error fixme ts strict error
this.off.push(this.on(document, 'touchend', this.dragEnd))
}
@@ -75,6 +83,7 @@ export class DraggableList extends EventTarget {
this.listContainer.querySelectorAll(this.itemSelector)
)
this.items.forEach((element) => {
// @ts-expect-error fixme ts strict error
element.classList.add('is-idle')
})
}
@@ -83,24 +92,29 @@ export class DraggableList extends EventTarget {
getIdleItems() {
return this.getAllItems().filter((item) =>
// @ts-expect-error fixme ts strict error
item.classList.contains('is-idle')
)
}
// @ts-expect-error fixme ts strict error
isItemAbove(item) {
return item.hasAttribute('data-is-above')
}
// @ts-expect-error fixme ts strict error
isItemToggled(item) {
return item.hasAttribute('data-is-toggled')
}
// @ts-expect-error fixme ts strict error
on(source, event, listener, options?) {
listener = listener.bind(this)
source.addEventListener(event, listener, options)
return () => source.removeEventListener(event, listener)
}
// @ts-expect-error fixme ts strict error
dragStart(e) {
if (e.target.classList.contains(this.handleClass)) {
this.draggableItem = e.target.closest(this.itemSelector)
@@ -117,8 +131,10 @@ export class DraggableList extends EventTarget {
this.initDraggableItem()
this.initItemsState()
// @ts-expect-error fixme ts strict error
this.offDrag.push(this.on(document, 'mousemove', this.drag))
this.offDrag.push(
// @ts-expect-error fixme ts strict error
this.on(document, 'touchmove', this.drag, { passive: false })
)
@@ -126,6 +142,7 @@ export class DraggableList extends EventTarget {
new CustomEvent('dragstart', {
detail: {
element: this.draggableItem,
// @ts-expect-error fixme ts strict error
position: this.getAllItems().indexOf(this.draggableItem)
}
})
@@ -141,7 +158,9 @@ export class DraggableList extends EventTarget {
const item1 = this.getIdleItems()[0]
const item2 = this.getIdleItems()[1]
// @ts-expect-error fixme ts strict error
const item1Rect = item1.getBoundingClientRect()
// @ts-expect-error fixme ts strict error
const item2Rect = item2.getBoundingClientRect()
this.itemsGap = Math.abs(item1Rect.bottom - item2Rect.top)
@@ -149,7 +168,9 @@ export class DraggableList extends EventTarget {
initItemsState() {
this.getIdleItems().forEach((item, i) => {
// @ts-expect-error fixme ts strict error
if (this.getAllItems().indexOf(this.draggableItem) > i) {
// @ts-expect-error fixme ts strict error
item.dataset.isAbove = ''
}
})
@@ -160,6 +181,7 @@ export class DraggableList extends EventTarget {
this.draggableItem.classList.add('is-draggable')
}
// @ts-expect-error fixme ts strict error
drag(e) {
if (!this.draggableItem) return
@@ -193,18 +215,23 @@ export class DraggableList extends EventTarget {
// Update state
this.getIdleItems().forEach((item) => {
// @ts-expect-error fixme ts strict error
const itemRect = item.getBoundingClientRect()
const itemY = itemRect.top + itemRect.height / 2
if (this.isItemAbove(item)) {
if (draggableItemY <= itemY) {
// @ts-expect-error fixme ts strict error
item.dataset.isToggled = ''
} else {
// @ts-expect-error fixme ts strict error
delete item.dataset.isToggled
}
} else {
if (draggableItemY >= itemY) {
// @ts-expect-error fixme ts strict error
item.dataset.isToggled = ''
} else {
// @ts-expect-error fixme ts strict error
delete item.dataset.isToggled
}
}
@@ -214,8 +241,10 @@ export class DraggableList extends EventTarget {
this.getIdleItems().forEach((item) => {
if (this.isItemToggled(item)) {
const direction = this.isItemAbove(item) ? 1 : -1
// @ts-expect-error fixme ts strict error
item.style.transform = `translateY(${direction * (draggableItemRect.height + this.itemsGap)}px)`
} else {
// @ts-expect-error fixme ts strict error
item.style.transform = ''
}
})
@@ -256,6 +285,7 @@ export class DraggableList extends EventTarget {
this.listContainer.appendChild(item)
})
// @ts-expect-error fixme ts strict error
this.items = reorderedItems
this.dispatchEvent(
@@ -275,6 +305,7 @@ export class DraggableList extends EventTarget {
this.unsetDraggableItem()
this.unsetItemState()
// @ts-expect-error fixme ts strict error
this.offDrag.forEach((f) => f())
this.offDrag = []
}
@@ -288,13 +319,17 @@ export class DraggableList extends EventTarget {
unsetItemState() {
this.getIdleItems().forEach((item) => {
// @ts-expect-error fixme ts strict error
delete item.dataset.isAbove
// @ts-expect-error fixme ts strict error
delete item.dataset.isToggled
// @ts-expect-error fixme ts strict error
item.style.transform = ''
})
}
dispose() {
// @ts-expect-error fixme ts strict error
this.off.forEach((f) => f())
}
}

View File

@@ -1,10 +1,12 @@
// @ts-strict-ignore
import { app } from '../app'
import { $el } from '../ui'
export function calculateImageGrid(
// @ts-expect-error fixme ts strict error
imgs,
// @ts-expect-error fixme ts strict error
dw,
// @ts-expect-error fixme ts strict error
dh
): {
cellWidth: number
@@ -42,11 +44,14 @@ export function calculateImageGrid(
}
}
// @ts-expect-error fixme ts strict error
return { cellWidth, cellHeight, cols, rows, shiftX }
}
// @ts-expect-error fixme ts strict error
export function createImageHost(node) {
const el = $el('div.comfy-img-preview')
// @ts-expect-error fixme ts strict error
let currentImgs
let first = true
@@ -54,6 +59,7 @@ export function createImageHost(node) {
let w = null
let h = null
// @ts-expect-error fixme ts strict error
if (currentImgs) {
let elH = el.clientHeight
if (first) {
@@ -73,17 +79,24 @@ export function createImageHost(node) {
nw - 20,
elH
))
// @ts-expect-error fixme ts strict error
w += 'px'
// @ts-expect-error fixme ts strict error
h += 'px'
// @ts-expect-error fixme ts strict error
el.style.setProperty('--comfy-img-preview-width', w)
// @ts-expect-error fixme ts strict error
el.style.setProperty('--comfy-img-preview-height', h)
}
}
return {
el,
// @ts-expect-error fixme ts strict error
updateImages(imgs) {
// @ts-expect-error fixme ts strict error
if (imgs !== currentImgs) {
// @ts-expect-error fixme ts strict error
if (currentImgs == null) {
requestAnimationFrame(() => {
updateSize()
@@ -109,6 +122,7 @@ export function createImageHost(node) {
if (!over) return
// Set the overIndex so Open Image etc work
// @ts-expect-error fixme ts strict error
const idx = currentImgs.indexOf(over)
node.overIndex = idx
}

View File

@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { $el } from '../ui'
/**
@@ -11,24 +10,33 @@ import { $el } from '../ui'
* @param { Object } [opts]
* @param { (e: { item: ToggleSwitchItem, prev?: ToggleSwitchItem }) => void } [opts.onChange]
*/
// @ts-expect-error fixme ts strict error
export function toggleSwitch(name, items, e?) {
const onChange = e?.onChange
// @ts-expect-error fixme ts strict error
let selectedIndex
// @ts-expect-error fixme ts strict error
let elements
// @ts-expect-error fixme ts strict error
function updateSelected(index) {
// @ts-expect-error fixme ts strict error
if (selectedIndex != null) {
// @ts-expect-error fixme ts strict error
elements[selectedIndex].classList.remove('comfy-toggle-selected')
}
onChange?.({
item: items[index],
// @ts-expect-error fixme ts strict error
prev: selectedIndex == null ? undefined : items[selectedIndex]
})
selectedIndex = index
// @ts-expect-error fixme ts strict error
elements[selectedIndex].classList.add('comfy-toggle-selected')
}
// @ts-expect-error fixme ts strict error
elements = items.map((item, i) => {
if (typeof item === 'string') item = { text: item }
if (!item.value) item.value = item.text

View File

@@ -1,4 +1,3 @@
// @ts-strict-ignore
export type ClassList = string | string[] | Record<string, boolean>
export function applyClasses(
@@ -34,11 +33,13 @@ export function toggleElement(
onShow
}: {
onHide?: (el: HTMLElement) => void
// @ts-expect-error fixme ts strict error
onShow?: (el: HTMLElement, value) => void
} = {}
) {
let placeholder: HTMLElement | Comment
let hidden: boolean
// @ts-expect-error fixme ts strict error
return (value) => {
if (value) {
if (hidden) {

View File

@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { applyTextReplacements as _applyTextReplacements } from '@/utils/searchAndReplace'
import { api } from './api'
@@ -90,12 +89,15 @@ export function prop<T>(
name: string
) => void
): T {
// @ts-expect-error fixme ts strict error
let currentValue
Object.defineProperty(target, name, {
get() {
// @ts-expect-error fixme ts strict error
return currentValue
},
set(newValue) {
// @ts-expect-error fixme ts strict error
const prevValue = currentValue
currentValue = newValue
onChanged?.(currentValue, prevValue, target, name)