From 68945cb54df8f0374cfead29051a749cb7a27be8 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Sun, 9 Mar 2025 00:27:49 +1100 Subject: [PATCH] Remove getTime workaround and Node.js type bleeding (#723) - Removes legacy timer workaround (redundant on Chrome v6 / Node.js v16) - Removes old type workarounds - Improves type inference speed --- src/LGraph.ts | 1 - src/LGraphCanvas.ts | 10 +++++----- src/LiteGraphGlobal.ts | 22 +++------------------- test/__snapshots__/litegraph.test.ts.snap | 1 - tsconfig.json | 3 +-- 5 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/LGraph.ts b/src/LGraph.ts index 70452178e..a5ce449bc 100644 --- a/src/LGraph.ts +++ b/src/LGraph.ts @@ -375,7 +375,6 @@ export class LGraph implements LinkNetwork, Serialisable { on_frame() } else { // execute every 'interval' ms - // @ts-expect-error this.execution_timer_id = setInterval(() => { // execute this.onBeforeStep?.() diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index bdaa689d3..33e5f9d30 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -1166,7 +1166,7 @@ export class LGraphCanvas implements ConnectionColorContext { input.focus() - let dialogCloseTimer: ReturnType + let dialogCloseTimer: number dialog.addEventListener("mouseleave", function () { if (LiteGraph.dialog_close_on_mouse_leave) { if (!dialog.is_modified && LiteGraph.dialog_close_on_mouse_leave) { @@ -5872,7 +5872,7 @@ export class LGraphCanvas implements ConnectionColorContext { if (this.ds.scale > 1) dialog.style.transform = `scale(${this.ds.scale})` - let dialogCloseTimer: ReturnType + let dialogCloseTimer: number let prevent_timeout = 0 LiteGraph.pointerListenerAdd(dialog, "leave", function () { if (prevent_timeout) return @@ -6058,7 +6058,7 @@ export class LGraphCanvas implements ConnectionColorContext { if (options.hide_on_mouse_leave) { // FIXME: Remove "any" kludge let prevent_timeout: any = false - let timeout_close: ReturnType | null = null + let timeout_close: number | null = null LiteGraph.pointerListenerAdd(dialog, "enter", function () { if (timeout_close) { clearTimeout(timeout_close) @@ -6103,7 +6103,7 @@ export class LGraphCanvas implements ConnectionColorContext { that.search_box = dialog let first: string | null = null - let timeout: ReturnType | null = null + let timeout: number | null = null let selected: ChildNode | null = null const maybeInput = dialog.querySelector("input") @@ -6713,7 +6713,7 @@ export class LGraphCanvas implements ConnectionColorContext { } } - let dialogCloseTimer: ReturnType + let dialogCloseTimer: number let prevent_timeout = 0 dialog.addEventListener("mouseleave", function () { if (prevent_timeout) return diff --git a/src/LiteGraphGlobal.ts b/src/LiteGraphGlobal.ts index 505130c51..12f8bfcd1 100644 --- a/src/LiteGraphGlobal.ts +++ b/src/LiteGraphGlobal.ts @@ -284,24 +284,6 @@ export class LiteGraphGlobal { } } - constructor() { - // timer that works everywhere - if (typeof performance != "undefined") { - this.getTime = performance.now.bind(performance) - } else if (typeof Date != "undefined" && Date.now) { - this.getTime = Date.now.bind(Date) - } else if (typeof process != "undefined") { - this.getTime = function () { - const t = process.hrtime() - return t[0] * 0.001 + t[1] * 1e-6 - } - } else { - this.getTime = function () { - return Date.now() - } - } - } - /** * Register a node class so it can be listed when the user wants to create a new one * @param type name of the node and path @@ -734,7 +716,9 @@ export class LiteGraphGlobal { } } - getTime: () => number + getTime(): number { + return performance.now() + } distance = distance diff --git a/test/__snapshots__/litegraph.test.ts.snap b/test/__snapshots__/litegraph.test.ts.snap index f8cc67079..5e3fe4727 100644 --- a/test/__snapshots__/litegraph.test.ts.snap +++ b/test/__snapshots__/litegraph.test.ts.snap @@ -150,7 +150,6 @@ LiteGraphGlobal { "dialog_close_on_mouse_leave_delay": 500, "distance": [Function], "do_add_triggers_slots": false, - "getTime": [Function], "highlight_selected_group": true, "isInsideRectangle": [Function], "middle_click_slot_add_default_node": false, diff --git a/tsconfig.json b/tsconfig.json index 1f2ca4ea3..f9d5d9f9e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,8 +26,7 @@ "paths": { "@/*": ["src/*"] }, - // TODO: Remove workaround from initial vite impl: public/src - "typeRoots": ["src/types", "node_modules/@types", "public/src"], + "typeRoots": [], "outDir": "./dist", "rootDir": "./" },