Typescript LGraphCanvas (#202)

* Format only

* Revert accidental change

* Fix redundant falsy check - uninit. var

* nit - Refactor const/let

* nit - Refactor const/let (manual)

* nit - Redeclared params

* Add TS types & minor refactor only

* Refactor - Clean up / reformat

- Add strings.ts helper functions
- Remove unused vars & local function params
- Simplifies code
- Rename vars for clarity
- Add TODOs and other comments
- Add ts-expect-error

* Redirect draw.ts enums to global file (temp.)

Should be revisited after TS merge complete
Corrects import of types from draw.ts into interfaces

* Add measure.ts - move util funcs from Global

* Add all imports required for TS conversion

* Refactor - TS narrowing

* nit - TS types & minor refactor

* Add missing types from recent PRs

Removes duplicate declarations
Fixes some type mismatches

* nit - Refactor recent PRs

* Revert incorrect decls backported

* Remove unused params

* Add TS types only

* Fix minor TS type coercion issues

Also removes redundant code

* nit - Refactor

* Remove @ts-nocheck

* Fix refactor regression - drag link to output

Issue was the result of fixing var declared outside of closure

* Restore original logic

---------

Co-authored-by: huchenlei <huchenlei@proton.me>
This commit is contained in:
filtered
2024-10-12 03:21:10 +11:00
committed by GitHub
parent edfa5e70f2
commit d69a2ae9b0
10 changed files with 3982 additions and 4170 deletions

View File

@@ -9,6 +9,7 @@ import { LiteGraph } from "./litegraph"
import { LGraphNode } from "./LGraphNode"
import { drawSlot, SlotShape, SlotDirection, SlotType, LabelPosition } from "./draw"
import type { Dictionary, ISlotType, Rect } from "./interfaces"
import { distance, isInsideRectangle, overlapBounding } from "./measure"
/**
* The Global Scope. It contains all the registered node classes.
@@ -1060,34 +1061,3 @@ export class LiteGraphGlobal {
}
}
}
export function distance(a, b) {
return Math.sqrt(
(b[0] - a[0]) * (b[0] - a[0]) + (b[1] - a[1]) * (b[1] - a[1])
)
}
export function isInsideRectangle(x, y, left, top, width, height) {
if (left < x && left + width > x && top < y && top + height > y) {
return true
}
return false
}
//bounding overlap, format: [ startx, starty, width, height ]
export function overlapBounding(a, b) {
var A_end_x = a[0] + a[2]
var A_end_y = a[1] + a[3]
var B_end_x = b[0] + b[2]
var B_end_y = b[1] + b[3]
if (
a[0] > B_end_x ||
a[1] > B_end_y ||
A_end_x < b[0] ||
A_end_y < b[1]
) {
return false
}
return true
}