[TS] Enable noUnusedLocals (#3108)

This commit is contained in:
Chenlei Hu
2025-03-17 16:20:56 -04:00
committed by GitHub
parent 9e9459815d
commit 7e66e99c3a
28 changed files with 27 additions and 248 deletions

View File

@@ -178,7 +178,6 @@ export class ClipspaceDialog extends ComfyDialog {
}
show() {
const img_preview = document.getElementById('clipspace_preview')
ClipspaceDialog.invalidate()
this.element.style.display = 'block'

View File

@@ -1,5 +1,5 @@
// @ts-strict-ignore
import { type LGraph, LGraphCanvas, LiteGraph } from '@comfyorg/litegraph'
import { LGraphCanvas, LiteGraph } from '@comfyorg/litegraph'
import { LGraphNode, type NodeId } from '@comfyorg/litegraph/dist/LGraphNode'
import { t } from '@/i18n'
@@ -1044,7 +1044,7 @@ export class GroupNodeHandler {
const onDrawForeground = node.onDrawForeground
const groupData = this.groupData.nodeData
node.onDrawForeground = function (ctx) {
const r = onDrawForeground?.apply?.(this, arguments)
onDrawForeground?.apply?.(this, arguments)
if (
+app.runningNodeId === this.id &&
this.runningInternalNodeId !== null

View File

@@ -14,6 +14,7 @@ export class CameraManager implements CameraManagerInterface {
orthographicCamera: THREE.OrthographicCamera
activeCamera: THREE.Camera
// @ts-expect-error unused variable
private renderer: THREE.WebGLRenderer
private eventManager: EventManagerInterface
private nodeStorage: NodeStorageInterface

View File

@@ -9,7 +9,7 @@ import {
export class ControlsManager implements ControlsManagerInterface {
controls: OrbitControls
// @ts-expect-error unused variable
private eventManager: EventManagerInterface
private nodeStorage: NodeStorageInterface
private camera: THREE.Camera

View File

@@ -2,7 +2,6 @@ import type { IWidget } from '@comfyorg/litegraph'
import Load3d from '@/extensions/core/load3d/Load3d'
import Load3dUtils from '@/extensions/core/load3d/Load3dUtils'
import { MaterialMode } from '@/extensions/core/load3d/interfaces'
import { api } from '@/scripts/api'
class Load3DConfiguration {

View File

@@ -1,6 +1,6 @@
import * as THREE from 'three'
import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader'
import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader'
import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader'
import { STLLoader } from 'three/examples/jsm/loaders/STLLoader'

View File

@@ -17,6 +17,7 @@ export class PreviewManager implements PreviewManagerInterface {
private getControls: () => OrbitControls
private eventManager: EventManagerInterface
// @ts-expect-error unused variable
private getRenderer: () => THREE.WebGLRenderer
private previewBackgroundScene: THREE.Scene

View File

@@ -17,6 +17,7 @@ export class SceneManager implements SceneManagerInterface {
private renderer: THREE.WebGLRenderer
private getActiveCamera: () => THREE.Camera
// @ts-expect-error unused variable
private getControls: () => OrbitControls
constructor(

View File

@@ -11,6 +11,7 @@ export class ViewHelperManager implements ViewHelperManagerInterface {
private getActiveCamera: () => THREE.Camera
private getControls: () => OrbitControls
private nodeStorage: NodeStorageInterface
// @ts-expect-error unused variable
private renderer: THREE.WebGLRenderer
constructor(

View File

@@ -18,22 +18,6 @@ function dataURLToBlob(dataURL) {
return new Blob([arrayBuffer], { type: contentType })
}
function loadedImageToBlob(image) {
const canvas = document.createElement('canvas')
canvas.width = image.width
canvas.height = image.height
const ctx = canvas.getContext('2d')
ctx.drawImage(image, 0, 0)
const dataURL = canvas.toDataURL('image/png', 1)
const blob = dataURLToBlob(dataURL)
return blob
}
function loadImage(imagePath) {
return new Promise((resolve, reject) => {
const image = new Image()
@@ -526,8 +510,6 @@ export class MaskEditorDialogOld extends ComfyDialog {
maskCtx.clearRect(0, 0, this.maskCanvas.width, this.maskCanvas.height)
// image load
const filepath = ComfyApp.clipspace.images
const alpha_url = new URL(
ComfyApp.clipspace.imgs[ComfyApp.clipspace['selectedIndex']].src
)

View File

@@ -821,8 +821,11 @@ class MaskEditorDialog extends ComfyDialog {
//new
private uiManager!: UIManager
// @ts-expect-error unused variable
private toolManager!: ToolManager
// @ts-expect-error unused variable
private panAndZoomManager!: PanAndZoomManager
// @ts-expect-error unused variable
private brushTool!: BrushTool
private paintBucketTool!: PaintBucketTool
private colorSelectTool!: ColorSelectTool
@@ -1190,6 +1193,7 @@ class MaskEditorDialog extends ComfyDialog {
}
class CanvasHistory {
// @ts-expect-error unused variable
private maskEditor!: MaskEditorDialog
private messageBroker!: MessageBroker
@@ -1542,6 +1546,7 @@ class PaintBucketTool {
}
class ColorSelectTool {
// @ts-expect-error unused variable
private maskEditor!: MaskEditorDialog
private messageBroker!: MessageBroker
private width: number | null = null
@@ -2329,9 +2334,6 @@ class BrushTool {
const cappedDeltaY = Math.max(-100, Math.min(100, finalDeltaY))
// Rest of the function remains the same
const sizeDelta = cappedDeltaX / 40
const hardnessDelta = cappedDeltaY / 800
const newSize = Math.max(
1,
Math.min(
@@ -2450,90 +2452,6 @@ class BrushTool {
}
}
private calculateCubicSplinePoints(
points: Point[],
numSegments: number = 10
): Point[] {
const result: Point[] = []
const xCoords = points.map((p) => p.x)
const yCoords = points.map((p) => p.y)
const xDerivatives = this.calculateSplineCoefficients(xCoords)
const yDerivatives = this.calculateSplineCoefficients(yCoords)
// Generate points along the spline
for (let i = 0; i < points.length - 1; i++) {
const p0 = points[i]
const p1 = points[i + 1]
const d0x = xDerivatives[i]
const d1x = xDerivatives[i + 1]
const d0y = yDerivatives[i]
const d1y = yDerivatives[i + 1]
for (let t = 0; t <= numSegments; t++) {
const t_normalized = t / numSegments
// Hermite basis functions
const h00 = 2 * t_normalized ** 3 - 3 * t_normalized ** 2 + 1
const h10 = t_normalized ** 3 - 2 * t_normalized ** 2 + t_normalized
const h01 = -2 * t_normalized ** 3 + 3 * t_normalized ** 2
const h11 = t_normalized ** 3 - t_normalized ** 2
const x = h00 * p0.x + h10 * d0x + h01 * p1.x + h11 * d1x
const y = h00 * p0.y + h10 * d0y + h01 * p1.y + h11 * d1y
result.push({ x, y })
}
}
return result
}
private generateEvenlyDistributedPoints(
splinePoints: Point[],
numPoints: number
): Point[] {
const distances: number[] = [0]
for (let i = 1; i < splinePoints.length; i++) {
const dx = splinePoints[i].x - splinePoints[i - 1].x
const dy = splinePoints[i].y - splinePoints[i - 1].y
const dist = Math.hypot(dx, dy)
distances.push(distances[i - 1] + dist)
}
const totalLength = distances[distances.length - 1]
const interval = totalLength / (numPoints - 1)
const result: Point[] = []
let currentIndex = 0
for (let i = 0; i < numPoints; i++) {
const targetDistance = i * interval
while (
currentIndex < distances.length - 1 &&
distances[currentIndex + 1] < targetDistance
) {
currentIndex++
}
const t =
(targetDistance - distances[currentIndex]) /
(distances[currentIndex + 1] - distances[currentIndex])
const x =
splinePoints[currentIndex].x +
t * (splinePoints[currentIndex + 1].x - splinePoints[currentIndex].x)
const y =
splinePoints[currentIndex].y +
t * (splinePoints[currentIndex + 1].y - splinePoints[currentIndex].y)
result.push({ x, y })
}
return result
}
private generateEquidistantPoints(
points: Point[],
distance: number
@@ -2582,45 +2500,6 @@ class BrushTool {
return result
}
private calculateSplineCoefficients(values: number[]): number[] {
const n = values.length - 1
const matrix: number[][] = new Array(n + 1)
.fill(0)
.map(() => new Array(n + 1).fill(0))
const rhs: number[] = new Array(n + 1).fill(0)
// Set up tridiagonal matrix
for (let i = 1; i < n; i++) {
matrix[i][i - 1] = 1
matrix[i][i] = 4
matrix[i][i + 1] = 1
rhs[i] = 3 * (values[i + 1] - values[i - 1])
}
// Set boundary conditions (natural spline)
matrix[0][0] = 2
matrix[0][1] = 1
matrix[n][n - 1] = 1
matrix[n][n] = 2
rhs[0] = 3 * (values[1] - values[0])
rhs[n] = 3 * (values[n] - values[n - 1])
// Solve tridiagonal system using Thomas algorithm
for (let i = 1; i <= n; i++) {
const m = matrix[i][i - 1] / matrix[i - 1][i - 1]
matrix[i][i] -= m * matrix[i - 1][i]
rhs[i] -= m * rhs[i - 1]
}
const solution: number[] = new Array(n + 1)
solution[n] = rhs[n] / matrix[n][n]
for (let i = n - 1; i >= 0; i--) {
solution[i] = (rhs[i] - matrix[i][i + 1] * solution[i + 1]) / matrix[i][i]
}
return solution
}
private setBrushSize(size: number) {
this.brushSettings.size = size
saveBrushToCache('maskeditor_brush_settings', this.brushSettings)
@@ -2658,13 +2537,16 @@ class UIManager {
private brushSettingsHTML!: HTMLDivElement
private paintBucketSettingsHTML!: HTMLDivElement
private colorSelectSettingsHTML!: HTMLDivElement
// @ts-expect-error unused variable
private maskOpacitySlider!: HTMLInputElement
private brushHardnessSlider!: HTMLInputElement
private brushSizeSlider!: HTMLInputElement
// @ts-expect-error unused variable
private brushOpacitySlider!: HTMLInputElement
private sidebarImage!: HTMLImageElement
private saveButton!: HTMLButtonElement
private toolPanel!: HTMLDivElement
// @ts-expect-error unused variable
private sidePanel!: HTMLDivElement
private pointerZone!: HTMLDivElement
private canvasBackground!: HTMLDivElement
@@ -3817,7 +3699,7 @@ class UIManager {
private async createBrush() {
var brush = document.createElement('div')
const brushSettings = await this.messageBroker.pull('brushSettings')
await this.messageBroker.pull('brushSettings')
brush.id = 'maskEditor_brush'
var brush_preview_gradient = document.createElement('div')
@@ -4741,7 +4623,7 @@ class PanAndZoomManager {
}
private handlePanStart(event: PointerEvent) {
let coords_canvas = this.messageBroker.pull('screenToCanvas', {
this.messageBroker.pull('screenToCanvas', {
x: event.offsetX,
y: event.offsetY
})
@@ -4947,6 +4829,7 @@ class MessageBroker {
class KeyboardManager {
private keysDown: string[] = []
// @ts-expect-error unused variable
private maskEditor: MaskEditorDialog
private messageBroker: MessageBroker
@@ -4995,24 +4878,6 @@ class KeyboardManager {
private isKeyDown(key: string) {
return this.keysDown.includes(key)
}
// combinations
private undoCombinationPressed() {
const combination = ['ctrl', 'z']
const keysDownLower = this.keysDown.map((key) => key.toLowerCase())
const result = combination.every((key) => keysDownLower.includes(key))
if (result) this.messageBroker.publish('undo')
return result
}
private redoCombinationPressed() {
const combination = ['ctrl', 'shift', 'z']
const keysDownLower = this.keysDown.map((key) => key.toLowerCase())
const result = combination.every((key) => keysDownLower.includes(key))
if (result) this.messageBroker.publish('redo')
return result
}
}
app.registerExtension({

View File

@@ -7,7 +7,6 @@ import type {
ISlotType,
IWidget,
LLink,
LiteGraphCanvasEvent,
Vector2
} from '@comfyorg/litegraph'
import type { CanvasMouseEvent } from '@comfyorg/litegraph/dist/types/events'