diff --git a/.gitignore b/.gitignore index cade06665..e6ffaa20a 100755 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,32 @@ -node_modules/ -node_modules/* -npm-debug.log temp/ temp/* coverage/ # Editors -/.vscode/* -!/.vscode/extensions.json *.bak -.project \ No newline at end of file +.project + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/package.json b/package.json index 72fd260fb..30ed3cf0d 100755 --- a/package.json +++ b/package.json @@ -1,52 +1,42 @@ { - "name": "@comfyorg/litegraph", - "version": "0.7.35", - "description": "A graph node editor similar to PD or UDK Blueprints. It works in an HTML5 Canvas and allows to export graphs to be included in applications.", - "main": "src/litegraph.js", - "types": "src/litegraph.d.ts", - "directories": { - "doc": "doc" - }, - "private": false, - "scripts": { - "prebuild": "rimraf build", - "build": "grunt build", - "start": "nodemon utils/server.js", - "test": "jest", - "test:allVersions": "./utils/test.sh", - "prettier": "npx prettier --write src/**/*.* css/**/*.*", - "lint": "npx eslint src", - "lint:fix": "npx eslint --fix src" - }, - "repository": { - "type": "git", - "url": "git@github.com:Comfy-Org/litegraph.js.git" - }, - "author": "comfyorg", - "license": "MIT", - "files": [ - "src/litegraph.js", - "css/litegraph.css", - "src/litegraph.d.ts" - ], - "bugs": { - "url": "https://github.com/Comfy-Org/litegraph.js/issues" - }, - "homepage": "https://github.com/Comfy-Org/litegraph.js", - "devDependencies": { - "@types/jest": "^28.1.3", - "eslint": "^8.37.0 ", - "eslint-plugin-jest": "^27.2.1", - "express": "^4.17.1", - "google-closure-compiler": "^20230411.0.0", - "grunt": "^1.1.0", - "grunt-cli": "^1.2.0", - "grunt-closure-tools": "^1.0.0", - "grunt-contrib-concat": "^2.1.0", - "jest": "^28.1.3", - "jest-cli": "^28.1.3", - "nodemon": "^2.0.22", - "rimraf": "^5.0.0", - "yuidocjs": "^0.10.2" - } -} + "name": "@comfyorg/litegraph", + "version": "0.7.35", + "type": "module", + "description": "A graph node editor similar to PD or UDK Blueprints. It works in an HTML5 Canvas and allows to export graphs to be included in applications.", + "main": "src/litegraph.js", + "types": "src/litegraph.d.ts", + "directories": { + "doc": "doc" + }, + "private": false, + "scripts": { + "build": "tsc && vite build", + "dev": "vite", + "preview": "vite preview", + "deprecated-prebuild": "rimraf build", + "deprecated-start": "nodemon utils/server.js", + "deprecated-test": "jest", + "deprecated-test:allVersions": "./utils/test.sh", + "deprecated-prettier": "npx prettier --write src/**/*.* css/**/*.*", + "deprecated-lint": "npx eslint src", + "deprecated-lint:fix": "npx eslint --fix src" + }, + "repository": { + "type": "git", + "url": "git@github.com:Comfy-Org/litegraph.js.git" + }, + "author": "comfyorg", + "license": "MIT", + "files": [ + "dist" + ], + "bugs": { + "url": "https://github.com/Comfy-Org/litegraph.js/issues" + }, + "homepage": "https://github.com/Comfy-Org/litegraph.js", + "devDependencies": { + "@types/node": "^22.1.0", + "typescript": "^5.2.2", + "vite": "^5.3.4" + } +} \ No newline at end of file diff --git a/css/litegraph.css b/public/css/litegraph.css old mode 100755 new mode 100644 similarity index 100% rename from css/litegraph.css rename to public/css/litegraph.css diff --git a/src/litegraph.d.ts b/public/src/litegraph.d.ts old mode 100755 new mode 100644 similarity index 100% rename from src/litegraph.d.ts rename to public/src/litegraph.d.ts diff --git a/src/litegraph.js b/src/litegraph.js index 015928177..dd617d52e 100755 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -1,5 +1,4 @@ -(function(global) { // ************************************************************* // LiteGraph CLASS ******* // ************************************************************* @@ -11,7 +10,7 @@ * @constructor */ - var LiteGraph = (global.LiteGraph = { + var LiteGraph = (globalThis.LiteGraph = { VERSION: 0.4, CANVAS_GRID_SIZE: 10, @@ -783,7 +782,7 @@ } } - global.LGraph = LiteGraph.LGraph = LGraph; + globalThis.LGraph = LiteGraph.LGraph = LGraph; //default supported types LGraph.supported_types = ["number", "string", "boolean"]; @@ -2411,7 +2410,7 @@ this._ctor(title); } - global.LGraphNode = LiteGraph.LGraphNode = LGraphNode; + globalThis.LGraphNode = LiteGraph.LGraphNode = LGraphNode; LGraphNode.prototype._ctor = function(title) { this.title = title || "Unnamed"; @@ -4904,7 +4903,7 @@ LGraphNode.prototype.executeAction = function(action) this._ctor(title); } - global.LGraphGroup = LiteGraph.LGraphGroup = LGraphGroup; + globalThis.LGraphGroup = LiteGraph.LGraphGroup = LGraphGroup; LGraphGroup.prototype._ctor = function(title) { this.title = title || "Group"; @@ -5360,7 +5359,7 @@ LGraphNode.prototype.executeAction = function(action) this.autoresize = options.autoresize; } - global.LGraphCanvas = LiteGraph.LGraphCanvas = LGraphCanvas; + globalThis.LGraphCanvas = LiteGraph.LGraphCanvas = LGraphCanvas; LGraphCanvas.DEFAULT_BACKGROUND_IMAGE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; @@ -14504,7 +14503,7 @@ LGraphNode.prototype.executeAction = function(action) function clamp(v, a, b) { return a > v ? a : b < v ? b : v; }; - global.clamp = clamp; + globalThis.clamp = clamp; if (typeof window != "undefined" && !window["requestAnimationFrame"]) { window.requestAnimationFrame = @@ -14514,15 +14513,14 @@ LGraphNode.prototype.executeAction = function(action) window.setTimeout(callback, 1000 / 60); }; } -})(this); if (typeof exports != "undefined") { - exports.LiteGraph = this.LiteGraph; - exports.LGraph = this.LGraph; - exports.LLink = this.LLink; - exports.LGraphNode = this.LGraphNode; - exports.LGraphGroup = this.LGraphGroup; - exports.DragAndScale = this.DragAndScale; - exports.LGraphCanvas = this.LGraphCanvas; - exports.ContextMenu = this.ContextMenu; + exports.LiteGraph = globalThis.LiteGraph; + exports.LGraph = globalThis.LGraph; + exports.LLink = globalThis.LLink; + exports.LGraphNode = globalThis.LGraphNode; + exports.LGraphGroup = globalThis.LGraphGroup; + exports.DragAndScale = globalThis.DragAndScale; + exports.LGraphCanvas = globalThis.LGraphCanvas; + exports.ContextMenu = globalThis.ContextMenu; } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..4bd301b12 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,33 @@ +{ + "compilerOptions": { + "target": "ES2022", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2022", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + "sourceMap": true, + "esModuleInterop": true, + "moduleResolution": "Node", + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + + /* Linting */ + "strict": false, + "noUnusedLocals": false, + "noUnusedParameters": false, + "noFallthroughCasesInSwitch": true, + "downlevelIteration": true, + + /* AllowJs during migration phase */ + "allowJs": true, + "baseUrl": ".", + "paths": { + "@/*": ["src/*"], + }, + // TODO: Remove workaround from initial vite impl: public/src + "typeRoots": ["src/types", "node_modules/@types", "public/src"], + "outDir": "./dist", + "rootDir": "./", + }, + "include": ["src/**/*"] +} diff --git a/vite.config.mts b/vite.config.mts new file mode 100644 index 000000000..6ff64e248 --- /dev/null +++ b/vite.config.mts @@ -0,0 +1,21 @@ +import { defineConfig } from 'vite' +import path from 'path' + +export default defineConfig({ + build: { + lib: { + entry: path.resolve(__dirname, 'src/litegraph.js'), + name: 'litegraph.js', + // TODO: Below workaround ensures output matches pre-vite format. Should be removed. + fileName: (moduleFormat, entryAlias) => 'src/litegraph.js', + formats: ['iife'] + }, + minify: false, + sourcemap: true, + rollupOptions: { + // Disabling tree-shaking + // Prevent vite remove unused exports + treeshake: false + } + }, +}) \ No newline at end of file