diff --git a/src/LGraph.ts b/src/LGraph.ts index 94fe12ac1c..5dcc289296 100644 --- a/src/LGraph.ts +++ b/src/LGraph.ts @@ -1,3 +1,4 @@ +import type { DragAndScaleState } from "./DragAndScale" import type { Dictionary, IContextMenuValue, @@ -51,6 +52,7 @@ export interface LGraphConfig { export interface LGraphExtra extends Dictionary { reroutes?: SerialisableReroute[] linkExtensions?: { id: number, parentId: number | undefined }[] + ds?: DragAndScaleState } export interface BaseLGraph { @@ -1374,6 +1376,12 @@ export class LGraph implements LinkNetwork, BaseLGraph, Serialisable> { - const { id, revision, config, state, extra } = this + const { id, revision, config, state } = this const nodeList = !LiteGraph.use_uuids && options?.sortNodes // @ts-expect-error If LiteGraph.use_uuids is false, ids are numbers. @@ -1397,6 +1405,11 @@ export class LGraph implements LinkNetwork, BaseLGraph, Serialisable x.asSerialisable()) : undefined const reroutes = this.reroutes.size ? [...this.reroutes.values()].map(x => x.asSerialisable()) : undefined + // Save scale and offset + const extra = { ...this.extra } + if (LiteGraph.saveViewportWithGraph) extra.ds = this.#getDragAndScale() + if (!extra.ds) delete extra.ds + const data: ReturnType = { id, revision, diff --git a/src/LiteGraphGlobal.ts b/src/LiteGraphGlobal.ts index cff4ff487e..ab13f17288 100644 --- a/src/LiteGraphGlobal.ts +++ b/src/LiteGraphGlobal.ts @@ -308,6 +308,12 @@ export class LiteGraphGlobal { */ truncateWidgetValuesFirst: boolean = false + /** + * If `true`, the current viewport scale & offset of the first attached canvas will be included with the graph when exporting. + * @default true + */ + saveViewportWithGraph: boolean = true + // TODO: Remove legacy accessors LGraph = LGraph LLink = LLink diff --git a/test/__snapshots__/litegraph.test.ts.snap b/test/__snapshots__/litegraph.test.ts.snap index 9e31d2e33f..f168f791dd 100644 --- a/test/__snapshots__/litegraph.test.ts.snap +++ b/test/__snapshots__/litegraph.test.ts.snap @@ -175,6 +175,7 @@ LiteGraphGlobal { "registered_slot_in_types": {}, "registered_slot_out_types": {}, "release_link_on_empty_shows_menu": false, + "saveViewportWithGraph": true, "search_filter_enabled": false, "search_hide_on_mouse_leave": true, "search_show_all_on_open": true,