Skip to content

Commit 943102d

Browse files
committed
init on better image generation
1 parent a07b8fa commit 943102d

File tree

3 files changed

+101
-17
lines changed

3 files changed

+101
-17
lines changed

frontend/webEditor/package-lock.json

Lines changed: 85 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/webEditor/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"sprotty-protocol": "^1.4.0",
2626
"typescript": "^5.8.3",
2727
"typescript-eslint": "^8.54.0",
28-
"vite": "^7.3.1"
28+
"vite": "^7.3.1",
29+
"snabbdom-to-html": "^7.1.0"
2930
},
3031
"scripts": {
3132
"dev": "vite",

frontend/webEditor/src/serialize/image.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Command, CommandExecutionContext, CommandReturn, TYPES } from "sprotty";
1+
import { Command, CommandExecutionContext, CommandReturn, IVNodePostprocessor, ModelRenderer, TYPES, ViewRegistration, ViewRegistry } from "sprotty";
22
import themeCss from "../assets/theme.css?raw";
33
import elementCss from "../diagram/style.css?raw";
4+
import toHTML from "snabbdom-to-html"
45
import { Action } from "sprotty-protocol";
5-
import { inject } from "inversify";
6+
import { inject, multiInject } from "inversify";
67
import { FileName } from "../fileName/fileName";
78

89
export namespace SaveImageAction {
@@ -21,21 +22,24 @@ export class SaveImageCommand extends Command {
2122
constructor(
2223
@inject(TYPES.Action) _: Action,
2324
@inject(FileName) private readonly fileName: FileName,
25+
@inject(TYPES.ViewRegistry) private readonly viewRegistry: ViewRegistry,
26+
@multiInject(TYPES.IVNodePostprocessor) private readonly postProcessors: IVNodePostprocessor[]
2427
) {
2528
super();
2629
}
2730

2831
execute(context: CommandExecutionContext): CommandReturn {
29-
const root = document.getElementById("sprotty_root");
30-
if (!root) return context.root;
31-
const firstChild = root.children[0];
32-
if (!firstChild) return context.root;
33-
const innerSvg = firstChild.innerHTML;
32+
const renderer = new ModelRenderer(this.viewRegistry, 'main', this.postProcessors )
33+
const svg = renderer.renderElement(context.root)
34+
if (!svg) return context.root
35+
console.debug(toHTML(svg))
36+
37+
3438
/* The result svg will render (0,0) as the top left corner of the svg.
3539
* We calculate the minimum translation of all children.
3640
* We then offset the whole svg by this opposite of this amount.
3741
*/
38-
const minTranslate = { x: Infinity, y: Infinity };
42+
/*const minTranslate = { x: Infinity, y: Infinity };
3943
for (const child of firstChild.children) {
4044
const childTranslate = this.getMinTranslate(child as HTMLElement);
4145
minTranslate.x = Math.min(minTranslate.x, childTranslate.x);
@@ -47,8 +51,8 @@ export class SaveImageCommand extends Command {
4751
const url = URL.createObjectURL(blob);
4852
const link = document.createElement("a");
4953
link.href = url;
50-
link.download = this.fileName.getName() + ".svg";
51-
link.click();
54+
link.download = this.fileName.getName() + ".svg";*/
55+
//link.click();
5256

5357
return context.root;
5458
}

0 commit comments

Comments
 (0)