@formulavize/renderer-cytoscape-formulavize 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +135 -2
  3. package/dist/CytoscapeRenderer.vue.d.ts +52 -0
  4. package/dist/CytoscapeRenderer.vue.d.ts.map +1 -0
  5. package/dist/completions.d.ts +6 -0
  6. package/dist/completions.d.ts.map +1 -0
  7. package/dist/completions.js +226 -0
  8. package/dist/constants.d.ts +4 -0
  9. package/dist/constants.d.ts.map +1 -0
  10. package/dist/constants.js +5 -0
  11. package/dist/cyDiffer.d.ts +27 -0
  12. package/dist/cyDiffer.d.ts.map +1 -0
  13. package/dist/cyDiffer.js +112 -0
  14. package/dist/cyExport.d.ts +12 -0
  15. package/dist/cyExport.d.ts.map +1 -0
  16. package/dist/cyExport.js +41 -0
  17. package/dist/cyGraphFactory.d.ts +6 -0
  18. package/dist/cyGraphFactory.d.ts.map +1 -0
  19. package/dist/cyGraphFactory.js +65 -0
  20. package/dist/cyLayout.d.ts +45 -0
  21. package/dist/cyLayout.d.ts.map +1 -0
  22. package/dist/cyLayout.js +48 -0
  23. package/dist/cyLayoutExtensions.d.ts +18 -0
  24. package/dist/cyLayoutExtensions.d.ts.map +1 -0
  25. package/dist/cyLayoutExtensions.js +29 -0
  26. package/dist/cyLayoutSchema.d.ts +12 -0
  27. package/dist/cyLayoutSchema.d.ts.map +1 -0
  28. package/dist/cyLayoutSchema.js +38 -0
  29. package/dist/cyNodePositions.d.ts +28 -0
  30. package/dist/cyNodePositions.d.ts.map +1 -0
  31. package/dist/cyNodePositions.js +103 -0
  32. package/dist/cyPopperExtender.d.ts +37 -0
  33. package/dist/cyPopperExtender.d.ts.map +1 -0
  34. package/dist/cyPopperExtender.js +271 -0
  35. package/dist/cyRendererDirectives.d.ts +11 -0
  36. package/dist/cyRendererDirectives.d.ts.map +1 -0
  37. package/dist/cyRendererDirectives.js +17 -0
  38. package/dist/cyStyleSheetsFactory.d.ts +18 -0
  39. package/dist/cyStyleSheetsFactory.d.ts.map +1 -0
  40. package/dist/cyStyleSheetsFactory.js +124 -0
  41. package/dist/headless.d.ts +18 -0
  42. package/dist/headless.d.ts.map +1 -0
  43. package/dist/headless.js +234 -0
  44. package/dist/index.d.ts +9 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +207 -0
  47. package/dist/layouts/breadthfirst.d.ts +3 -0
  48. package/dist/layouts/breadthfirst.d.ts.map +1 -0
  49. package/dist/layouts/breadthfirst.js +47 -0
  50. package/dist/layouts/dagre.d.ts +3 -0
  51. package/dist/layouts/dagre.d.ts.map +1 -0
  52. package/dist/layouts/dagre.js +58 -0
  53. package/dist/layouts/elk.d.ts +4 -0
  54. package/dist/layouts/elk.d.ts.map +1 -0
  55. package/dist/layouts/elk.js +127 -0
  56. package/dist/layouts/index.d.ts +24 -0
  57. package/dist/layouts/index.d.ts.map +1 -0
  58. package/dist/layouts/index.js +40 -0
  59. package/dist/layouts/manual.d.ts +3 -0
  60. package/dist/layouts/manual.d.ts.map +1 -0
  61. package/dist/layouts/manual.js +10 -0
  62. package/dist/layouts/optionParsers.d.ts +25 -0
  63. package/dist/layouts/optionParsers.d.ts.map +1 -0
  64. package/dist/layouts/optionParsers.js +66 -0
  65. package/dist/layouts/types.d.ts +34 -0
  66. package/dist/layouts/types.d.ts.map +1 -0
  67. package/dist/layouts/types.js +10 -0
  68. package/dist/meta.d.ts +10 -0
  69. package/dist/meta.d.ts.map +1 -0
  70. package/dist/meta.js +22 -0
  71. package/package.json +98 -4
  72. package/src/CytoscapeRenderer.vue +321 -0
  73. package/src/completions.ts +294 -0
  74. package/src/constants.ts +11 -0
  75. package/src/cyDiffer.ts +191 -0
  76. package/src/cyExport.ts +59 -0
  77. package/src/cyGraphFactory.ts +89 -0
  78. package/src/cyLayout.ts +94 -0
  79. package/src/cyLayoutExtensions.ts +40 -0
  80. package/src/cyLayoutSchema.ts +74 -0
  81. package/src/cyNodePositions.ts +143 -0
  82. package/src/cyPopperExtender.ts +479 -0
  83. package/src/cyRendererDirectives.ts +21 -0
  84. package/src/cyStyleSheetsFactory.ts +232 -0
  85. package/src/headless.ts +317 -0
  86. package/src/index.ts +14 -0
  87. package/src/layouts/breadthfirst.ts +47 -0
  88. package/src/layouts/dagre.ts +57 -0
  89. package/src/layouts/elk.ts +150 -0
  90. package/src/layouts/index.ts +73 -0
  91. package/src/layouts/manual.ts +26 -0
  92. package/src/layouts/optionParsers.ts +112 -0
  93. package/src/layouts/types.ts +90 -0
  94. package/src/meta.ts +24 -0
  95. package/src/shims-cytoscape-ext.d.ts +8 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 formulavize
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,136 @@
1
- # Temporary Holding Version
1
+ # @formulavize/renderer-cytoscape-formulavize
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The [Cytoscape.js](https://js.cytoscape.org/) renderer for
4
+ [formulavize](https://github.com/formulavize/editor-formulavize).
5
+ It draws a compiled fiz `Dag` as an interactive graph, and is the default
6
+ renderer the app ships with.
7
+
8
+ It implements
9
+ [`@formulavize/renderer-api-formulavize`](https://github.com/formulavize/renderer-api-formulavize),
10
+ so it plugs into the editor without the editor knowing anything about
11
+ Cytoscape.
12
+
13
+ A recipe selects and configures it with a renderer directive:
14
+
15
+ ```
16
+ ^cytoscape{
17
+ layout: "elk"
18
+ background-color: #1e1e1e
19
+ }
20
+
21
+ t = fetch()
22
+ c = chop(t)
23
+ p = purée(c)
24
+ ```
25
+
26
+ ## Install
27
+
28
+ ```sh
29
+ pnpm add @formulavize/renderer-cytoscape-formulavize
30
+ ```
31
+
32
+ `vue`, `@formulavize/renderer-api-formulavize`, and
33
+ `@formulavize/compiler-frontend-fiz` are peer dependencies. This ensures the
34
+ host and renderer share the same Vue runtime, `Dag` implementation, and
35
+ renderer contract types.
36
+
37
+ `jsdom` and `@napi-rs/canvas` are **optional** peers, needed only for headless
38
+ rendering. A browser-only consumer can leave them out.
39
+
40
+ ## Register it
41
+
42
+ ```ts
43
+ import { cytoscapePlugin } from "@formulavize/renderer-cytoscape-formulavize";
44
+
45
+ export const defaultRendererPlugins = [cytoscapePlugin /*, … */];
46
+ ```
47
+
48
+ ## Three entry points
49
+
50
+ | Subpath | Gives you | Pulls in |
51
+ | ------------ | -------------------------------------------------------------- | ------------------------------------------- |
52
+ | `.` | `cytoscapePlugin` — the full plugin | The Vue component, `cytoscape-svg`, the DOM |
53
+ | `./meta` | `cytoscapeRendererMeta` — the descriptor, plus the completions | Nothing browser-only |
54
+ | `./headless` | `cytoscapeHeadlessPlugin`, `renderDagToBytes` | `jsdom` + a canvas backend |
55
+
56
+ The split is intentional and essential. `./index` pulls in a component that
57
+ reaches for `window` the moment it loads, so anything running outside a browser
58
+ must import `./meta` or `./headless` instead — which is exactly what the CLI
59
+ does.
60
+
61
+ Every other module is also reachable on its own subpath
62
+ (`…/constants`, `…/layouts/elk`, `…/completions`, …), but the three above are
63
+ the supported surface.
64
+
65
+ ## Rendering outside a browser
66
+
67
+ ```ts
68
+ import { renderDagToBytes } from "@formulavize/renderer-cytoscape-formulavize/headless";
69
+
70
+ const bytes = await renderDagToBytes(dag, {
71
+ fileType: "svg",
72
+ scalingFactor: 1,
73
+ isDark: false,
74
+ includeDescriptions: true,
75
+ });
76
+ ```
77
+
78
+ This installs jsdom globals and a canvas backend, then loads Cytoscape, so it
79
+ lives behind its own entry point rather than in `./index`. `jsdom` and
80
+ `@napi-rs/canvas` are optional peers you supply only if you need this path.
81
+
82
+ ## Layouts
83
+
84
+ `layout` in the directive block selects node placement. Each layout takes its
85
+ own options, specified as that layout's own documentation names them.
86
+
87
+ | Layout | Behaviour |
88
+ | -------------- | ------------------------------------------------------------------ |
89
+ | `dagre` | Automatic (default); hierarchical; loosely follows statement order |
90
+ | `breadthfirst` | Automatic; Cytoscape built-in; **ignores namespaces** |
91
+ | `elk` | Automatic; Eclipse Layout Kernel; best model-order preservation |
92
+ | `manual` | Layout manager off; manually position nodes by dragging |
93
+
94
+ `cytoscape-dagre` and `cytoscape-elk` are loaded with a dynamic `import()` on
95
+ first use, so a recipe that never asks for ELK never pays for elkjs — the
96
+ published build keeps those as separate chunks.
97
+
98
+ ELK option ids are dotted, but a fiz property names cannot contain `.`, so they
99
+ are written with dashes and rewritten on the way out:
100
+
101
+ ```
102
+ ^cytoscape{
103
+ layout: "elk"
104
+ elk-algorithm: "layered"
105
+ elk-spacing-nodeNode: 40
106
+ }
107
+ ```
108
+
109
+ Any `elk-*` key not in the documented list is passed straight through with the
110
+ same rewriting, which keeps the whole ELK option namespace reachable.
111
+
112
+ ## Directives are never validated
113
+
114
+ Directive keys and values are read by the renderer, not by the compiler. A key
115
+ it does not know is ignored, a value that fails to parse is dropped so the
116
+ default applies, and an unrecognized `layout` name falls back to `dagre`. A typo
117
+ changes nothing rather than breaking the recipe.
118
+
119
+ ## Editor completions
120
+
121
+ This renderer states its own vocabulary — the Cytoscape style property names and
122
+ the directive keys each layout accepts — through the contract's `completions`
123
+ field, in `src/completions.ts`. The editor offers whatever this returns without
124
+ holding any Cytoscape vocabulary of its own.
125
+
126
+ ## Development
127
+
128
+ ```sh
129
+ pnpm install
130
+ pnpm build # vite (lib mode) -> dist/, then vue-tsc for .d.ts
131
+ pnpm test # vitest
132
+ pnpm test:format # prettier --check
133
+ pnpm all # build then test
134
+ ```
135
+
136
+ Requires Node >= 26 and pnpm >= 12.
@@ -0,0 +1,52 @@
1
+ import { PropType } from "vue";
2
+ import { Core, ElementsDefinition, Layouts, StylesheetCSS } from "cytoscape";
3
+ import { PopperCleanup } from "./cyPopperExtender.js";
4
+ import { Dag } from "@formulavize/compiler-frontend-fiz/dag";
5
+ import { FileExportOptions } from "@formulavize/renderer-api-formulavize";
6
+ declare module "cytoscape-popper" {
7
+ interface PopperInstance {
8
+ update(): void;
9
+ }
10
+ }
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
13
+ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
14
+ dag: {
15
+ type: PropType<Dag>;
16
+ required: true;
17
+ };
18
+ isDark: {
19
+ type: BooleanConstructor;
20
+ default: boolean;
21
+ };
22
+ }>, {}, {
23
+ cy: Core | null;
24
+ previousElements: ElementsDefinition | null;
25
+ previousStylesheetsJson: string | null;
26
+ previousLayoutSignature: string | null;
27
+ runningLayout: Layouts | null;
28
+ popperCleanup: PopperCleanup | null;
29
+ }, {}, {
30
+ initializeCytoscape(): void;
31
+ applyGrabbability(): void;
32
+ runLayout(): Promise<void>;
33
+ applyStyles(newStylesheets: StylesheetCSS[]): void;
34
+ applyCanvasBackground(): void;
35
+ applyThemeStyles(): void;
36
+ updateDag(dag: Dag): void;
37
+ addGhostNodes(): string[];
38
+ removeGhostNodes(ghostIds: string[]): void;
39
+ export(exportOptions: FileExportOptions): void;
40
+ }, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
41
+ dag: {
42
+ type: PropType<Dag>;
43
+ required: true;
44
+ };
45
+ isDark: {
46
+ type: BooleanConstructor;
47
+ default: boolean;
48
+ };
49
+ }>> & Readonly<{}>, {
50
+ isDark: boolean;
51
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
52
+ //# sourceMappingURL=CytoscapeRenderer.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CytoscapeRenderer.vue.d.ts","sourceRoot":"","sources":["../src/CytoscapeRenderer.vue"],"names":[],"mappings":"AAoUA,OAAO,EAAmB,QAAQ,EAAE,MAAM,KAAK,CAAC;AAChD,OAAkB,EAChB,IAAI,EACJ,kBAAkB,EAClB,OAAO,EACP,aAAa,EACd,MAAM,WAAW,CAAC;AAwBnB,OAAO,EAGL,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,GAAG,EAAE,MAAM,wCAAwC,CAAC;AAM7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAE1E,OAAO,QAAQ,kBAAkB,CAAC;IAEhC,UAAU,cAAc;QACtB,MAAM,IAAI,IAAI,CAAC;KAChB;CACF;wBA+OoB,OAAO,YAAY;AAAxC,wBAAyC;AAiCzC,QAAA,MAAM,YAAY;;cA5OI,QAAQ,CAAC,GAAG,CAAC;;;;;;;;QAUjB,IAAI,GAAG,IAAI;sBACG,kBAAkB,GAAG,IAAI;6BAClB,MAAM,GAAG,IAAI;6BACb,MAAM,GAAG,IAAI;mBACvB,OAAO,GAAG,IAAI;mBACd,aAAa,GAAG,IAAI;;2BAsBtB,IAAI;yBAUN,IAAI;iBAON,OAAO,CAAC,IAAI,CAAC;gCAmBJ,aAAa,EAAE,GAAG,IAAI;6BAazB,IAAI;wBAOT,IAAI;mBAOT,GAAG,GAAG,IAAI;qBAmER,MAAM,EAAE;+BAKE,MAAM,EAAE,GAAG,IAAI;0BAOpB,iBAAiB,GAAG,IAAI;;;cAnL5B,QAAQ,CAAC,GAAG,CAAC;;;;;;;;;4EA4OG,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { RendererCompletions } from "@formulavize/renderer-api-formulavize";
2
+ /**
3
+ * The cytoscape renderer's editor vocabulary.
4
+ */
5
+ export declare const cytoscapeCompletions: RendererCompletions;
6
+ //# sourceMappingURL=completions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completions.d.ts","sourceRoot":"","sources":["../src/completions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EACpB,MAAM,uCAAuC,CAAC;AA6Q/C;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,mBAkBlC,CAAC"}
@@ -0,0 +1,226 @@
1
+ import { BACKGROUND_COLOR_PROPERTY, LAYOUT_PROPERTY } from "./constants.js";
2
+ import { CYTOSCAPE_LAYOUT_NAMES } from "./layouts/types.js";
3
+ import { getLayoutOptionKeys } from "./cyLayoutSchema.js";
4
+ import { resolveLayoutName } from "./layouts/index.js";
5
+ import { DESCRIPTION_PREFIX, DESCRIPTION_PROPERTY } from "@formulavize/compiler-frontend-fiz/constants";
6
+ // src/completions.ts
7
+ var CYTOSCAPE_NODE_BODY_PROPERTIES = [
8
+ "height",
9
+ "width",
10
+ "shape",
11
+ "shape-polygon-points",
12
+ "corner-radius",
13
+ "background-color",
14
+ "background-fill",
15
+ "background-opacity",
16
+ "background-blacken",
17
+ "background-gradient-stop-colors",
18
+ "background-gradient-stop-positions",
19
+ "background-gradient-direction",
20
+ "padding",
21
+ "padding-relative-to",
22
+ "bounds-expansion"
23
+ ];
24
+ var CYTOSCAPE_NODE_BORDER_PROPERTIES = [
25
+ "border-color",
26
+ "border-opacity",
27
+ "border-width",
28
+ "border-style",
29
+ "border-cap",
30
+ "border-join",
31
+ "border-dash-pattern",
32
+ "border-dash-offset",
33
+ "border-position"
34
+ ];
35
+ var CYTOSCAPE_NODE_OUTLINE_PROPERTIES = [
36
+ "outline-color",
37
+ "outline-opacity",
38
+ "outline-width",
39
+ "outline-style",
40
+ "outline-offset"
41
+ ];
42
+ var CYTOSCAPE_BACKGROUND_IMAGE_PROPERTIES = [
43
+ "background-image",
44
+ "background-image-crossorigin",
45
+ "background-image-opacity",
46
+ "background-image-containment",
47
+ "background-image-smoothing",
48
+ "background-position-x",
49
+ "background-position-y",
50
+ "background-width-relative-to",
51
+ "background-height-relative-to",
52
+ "background-repeat",
53
+ "background-fit",
54
+ "background-clip",
55
+ "background-width",
56
+ "background-height",
57
+ "background-offset-x",
58
+ "background-offset-y"
59
+ ];
60
+ var CYTOSCAPE_LABEL_PROPERTIES = [
61
+ "label",
62
+ "text-rotation",
63
+ "text-margin-x",
64
+ "text-margin-y",
65
+ "source-label",
66
+ "source-text-rotation",
67
+ "source-text-margin-x",
68
+ "source-text-margin-y",
69
+ "source-text-offset",
70
+ "target-label",
71
+ "target-text-rotation",
72
+ "target-text-margin-x",
73
+ "target-text-margin-y",
74
+ "target-text-offset"
75
+ ];
76
+ var CYTOSCAPE_LABEL_STYLE_PROPERTIES = [
77
+ "font-family",
78
+ "font-style",
79
+ "font-weight",
80
+ "font-size",
81
+ "text-transform",
82
+ "text-wrap",
83
+ "text-overflow-wrap",
84
+ "text-max-width",
85
+ "text-outline-width",
86
+ "line-height",
87
+ "text-valign",
88
+ "text-halign",
89
+ "color",
90
+ "text-outline-color",
91
+ "text-outline-opacity",
92
+ "text-background-color",
93
+ "text-background-opacity",
94
+ "text-background-padding",
95
+ "text-border-opacity",
96
+ "text-border-color",
97
+ "text-border-width",
98
+ "text-border-style",
99
+ "text-background-shape",
100
+ "text-justification"
101
+ ];
102
+ var CYTOSCAPE_VISIBILITY_PROPERTIES = [
103
+ "display",
104
+ "visibility",
105
+ "opacity",
106
+ "text-opacity",
107
+ "min-zoomed-font-size",
108
+ "z-index"
109
+ ];
110
+ var CYTOSCAPE_EDGE_LINE_PROPERTIES = [
111
+ "line-style",
112
+ "line-color",
113
+ "line-fill",
114
+ "line-cap",
115
+ "line-opacity",
116
+ "line-dash-pattern",
117
+ "line-dash-offset",
118
+ "line-outline-width",
119
+ "line-outline-color",
120
+ "line-gradient-stop-colors",
121
+ "line-gradient-stop-positions",
122
+ "curve-style",
123
+ "haystack-radius",
124
+ "source-endpoint",
125
+ "target-endpoint",
126
+ "control-point-step-size",
127
+ "control-point-distances",
128
+ "control-point-weights",
129
+ "segment-distances",
130
+ "segment-weights",
131
+ "segment-radii",
132
+ "radius-type",
133
+ "taxi-turn",
134
+ "taxi-turn-min-distance",
135
+ "taxi-direction",
136
+ "taxi-radius",
137
+ "edge-distances",
138
+ "arrow-scale",
139
+ "loop-direction",
140
+ "loop-sweep",
141
+ "source-distance-from-node",
142
+ "target-distance-from-node"
143
+ ];
144
+ var CYTOSCAPE_EDGE_ARROW_PROPERTIES = [
145
+ "source-arrow-shape",
146
+ "source-arrow-color",
147
+ "source-arrow-fill",
148
+ "source-arrow-width",
149
+ "mid-source-arrow-shape",
150
+ "mid-source-arrow-color",
151
+ "mid-source-arrow-fill",
152
+ "mid-source-arrow-width",
153
+ "target-arrow-shape",
154
+ "target-arrow-color",
155
+ "target-arrow-fill",
156
+ "target-arrow-width",
157
+ "mid-target-arrow-shape",
158
+ "mid-target-arrow-color",
159
+ "mid-target-arrow-fill",
160
+ "mid-target-arrow-width"
161
+ ];
162
+ var DESCRIPTION_VISIBILITY_PROPERTIES = ["text-opacity", "min-zoomed-font-size"];
163
+ var DESCRIPTION_EXCLUDED_PROPERTIES = /* @__PURE__ */ new Set(["text-halign", "text-valign"]);
164
+ var DESCRIPTION_PROPERTIES = [
165
+ DESCRIPTION_PROPERTY,
166
+ ...CYTOSCAPE_LABEL_STYLE_PROPERTIES.filter((p) => !DESCRIPTION_EXCLUDED_PROPERTIES.has(p)).map((p) => DESCRIPTION_PREFIX + p),
167
+ ...DESCRIPTION_VISIBILITY_PROPERTIES.map((p) => DESCRIPTION_PREFIX + p)
168
+ ];
169
+ function toPropertyCompletions(propertyNames) {
170
+ return [...new Set(propertyNames)].sort().map((name) => ({ name }));
171
+ }
172
+ var CYTOSCAPE_SHARED_PROPERTIES = [
173
+ ...CYTOSCAPE_LABEL_PROPERTIES,
174
+ ...CYTOSCAPE_LABEL_STYLE_PROPERTIES,
175
+ ...CYTOSCAPE_VISIBILITY_PROPERTIES,
176
+ ...DESCRIPTION_PROPERTIES
177
+ ];
178
+ var allProperties = toPropertyCompletions([
179
+ ...CYTOSCAPE_NODE_BODY_PROPERTIES,
180
+ ...CYTOSCAPE_NODE_BORDER_PROPERTIES,
181
+ ...CYTOSCAPE_NODE_OUTLINE_PROPERTIES,
182
+ ...CYTOSCAPE_BACKGROUND_IMAGE_PROPERTIES,
183
+ ...CYTOSCAPE_LABEL_PROPERTIES,
184
+ ...CYTOSCAPE_LABEL_STYLE_PROPERTIES,
185
+ ...CYTOSCAPE_VISIBILITY_PROPERTIES,
186
+ ...CYTOSCAPE_EDGE_LINE_PROPERTIES,
187
+ ...CYTOSCAPE_EDGE_ARROW_PROPERTIES,
188
+ ...DESCRIPTION_PROPERTIES
189
+ ]);
190
+ var nodeProperties = toPropertyCompletions([
191
+ ...CYTOSCAPE_NODE_BODY_PROPERTIES,
192
+ ...CYTOSCAPE_NODE_BORDER_PROPERTIES,
193
+ ...CYTOSCAPE_NODE_OUTLINE_PROPERTIES,
194
+ ...CYTOSCAPE_BACKGROUND_IMAGE_PROPERTIES,
195
+ ...CYTOSCAPE_SHARED_PROPERTIES
196
+ ]);
197
+ var propertiesByElementType = {
198
+ node: nodeProperties,
199
+ edge: toPropertyCompletions([
200
+ ...CYTOSCAPE_EDGE_LINE_PROPERTIES,
201
+ ...CYTOSCAPE_EDGE_ARROW_PROPERTIES,
202
+ ...CYTOSCAPE_SHARED_PROPERTIES
203
+ ]),
204
+ subgraph: nodeProperties
205
+ };
206
+ var DIRECTIVE_BASE_PROPERTIES = [BACKGROUND_COLOR_PROPERTY, LAYOUT_PROPERTY];
207
+ var directivePropertiesByLayout = Object.fromEntries(CYTOSCAPE_LAYOUT_NAMES.map((layoutName) => [layoutName, toPropertyCompletions([...DIRECTIVE_BASE_PROPERTIES, ...getLayoutOptionKeys(layoutName)])]));
208
+ /**
209
+ * The cytoscape renderer's editor vocabulary.
210
+ */
211
+ var cytoscapeCompletions = {
212
+ styleProperties(elementType) {
213
+ if (elementType === void 0) return allProperties;
214
+ return propertiesByElementType[elementType] ?? allProperties;
215
+ },
216
+ /**
217
+ * A directive block only accepts the options of the layout it selects.
218
+ * resolveLayoutName folds an absent or unrecognized layout onto the default,
219
+ * exactly as the renderer does when it reads the same directive, so the
220
+ * offered keys are always the ones the block will really accept.
221
+ */
222
+ directiveProperties(declared) {
223
+ return directivePropertiesByLayout[resolveLayoutName(declared.get(LAYOUT_PROPERTY))];
224
+ }
225
+ };
226
+ export { cytoscapeCompletions };
@@ -0,0 +1,4 @@
1
+ export declare const CYTOSCAPE_RENDERER_NAME: string;
2
+ export declare const LAYOUT_PROPERTY: string;
3
+ export declare const BACKGROUND_COLOR_PROPERTY: string;
4
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,uBAAuB,EAAE,MAAoB,CAAC;AAK3D,eAAO,MAAM,eAAe,EAAE,MAAiB,CAAC;AAIhD,eAAO,MAAM,yBAAyB,EAAE,MAA2B,CAAC"}
@@ -0,0 +1,5 @@
1
+ // src/constants.ts
2
+ var CYTOSCAPE_RENDERER_NAME = "cytoscape";
3
+ var LAYOUT_PROPERTY = "layout";
4
+ var BACKGROUND_COLOR_PROPERTY = "background-color";
5
+ export { BACKGROUND_COLOR_PROPERTY, CYTOSCAPE_RENDERER_NAME, LAYOUT_PROPERTY };
@@ -0,0 +1,27 @@
1
+ import { Core, NodeDefinition, EdgeDefinition, ElementsDefinition, NodeDataDefinition, EdgeDataDefinition } from "cytoscape";
2
+ type ElementId = string;
3
+ type ElementDataDef = NodeDataDefinition | EdgeDataDefinition;
4
+ export interface NodeUpdate {
5
+ id: ElementId;
6
+ data: ElementDataDef;
7
+ classes?: string;
8
+ }
9
+ export interface EdgeUpdate {
10
+ id: ElementId;
11
+ data: ElementDataDef;
12
+ classes?: string;
13
+ }
14
+ export interface CyDiffResult {
15
+ nodesToAdd: NodeDefinition[];
16
+ nodesToRemove: ElementId[];
17
+ nodesToUpdate: NodeUpdate[];
18
+ edgesToAdd: EdgeDefinition[];
19
+ edgesToRemove: ElementId[];
20
+ edgesToUpdate: EdgeUpdate[];
21
+ topologyChanged: boolean;
22
+ }
23
+ export declare function diffCyElements(oldElements: ElementsDefinition, newElements: ElementsDefinition): CyDiffResult;
24
+ export declare function applyDataUpdates(cy: Core, diff: CyDiffResult): void;
25
+ export declare function applyDiff(cy: Core, diff: CyDiffResult): void;
26
+ export {};
27
+ //# sourceMappingURL=cyDiffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cyDiffer.d.ts","sourceRoot":"","sources":["../src/cyDiffer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,WAAW,CAAC;AAEnB,KAAK,SAAS,GAAG,MAAM,CAAC;AAExB,KAAK,cAAc,GAAG,kBAAkB,GAAG,kBAAkB,CAAC;AAE9D,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,SAAS,CAAC;IACd,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,SAAS,CAAC;IACd,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,aAAa,EAAE,SAAS,EAAE,CAAC;IAC3B,aAAa,EAAE,UAAU,EAAE,CAAC;IAC5B,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,aAAa,EAAE,SAAS,EAAE,CAAC;IAC3B,aAAa,EAAE,UAAU,EAAE,CAAC;IAC5B,eAAe,EAAE,OAAO,CAAC;CAC1B;AAoDD,wBAAgB,cAAc,CAC5B,WAAW,EAAE,kBAAkB,EAC/B,WAAW,EAAE,kBAAkB,GAC9B,YAAY,CAiFd;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAQnE;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAS5D"}
@@ -0,0 +1,112 @@
1
+ // src/cyDiffer.ts
2
+ function valueEqual(a, b) {
3
+ if (a === b) return true;
4
+ if (Array.isArray(a) && Array.isArray(b)) {
5
+ if (a.length !== b.length) return false;
6
+ return a.every((val, i) => valueEqual(val, b[i]));
7
+ }
8
+ return false;
9
+ }
10
+ function dataEqual(a, b) {
11
+ const keysA = Object.keys(a);
12
+ const keysB = Object.keys(b);
13
+ if (keysA.length !== keysB.length) return false;
14
+ for (const key of keysA) if (!valueEqual(a[key], b[key])) return false;
15
+ return true;
16
+ }
17
+ function normalizeClasses(classes) {
18
+ if (classes === void 0) return void 0;
19
+ if (Array.isArray(classes)) return classes.join(" ");
20
+ return classes;
21
+ }
22
+ function elementChanged(oldEl, newEl) {
23
+ const oldClasses = normalizeClasses(oldEl.classes);
24
+ const newClasses = normalizeClasses(newEl.classes);
25
+ return {
26
+ changed: !dataEqual(oldEl.data, newEl.data) || oldClasses !== newClasses,
27
+ newClasses
28
+ };
29
+ }
30
+ function indexById(elements) {
31
+ return new Map(elements.filter((element) => element.data.id).map((element) => [element.data.id, element]));
32
+ }
33
+ function diffCyElements(oldElements, newElements) {
34
+ const oldNodes = indexById(oldElements.nodes);
35
+ const newNodes = indexById(newElements.nodes);
36
+ const oldEdges = indexById(oldElements.edges);
37
+ const newEdges = indexById(newElements.edges);
38
+ const nodesToAdd = [];
39
+ const nodesToRemove = [];
40
+ const nodesToUpdate = [];
41
+ const edgesToAdd = [];
42
+ const edgesToRemove = [];
43
+ const edgesToUpdate = [];
44
+ let topologyChanged = false;
45
+ for (const [id, newNode] of newNodes) {
46
+ const oldNode = oldNodes.get(id);
47
+ if (!oldNode) {
48
+ nodesToAdd.push(newNode);
49
+ topologyChanged = true;
50
+ } else {
51
+ const { changed, newClasses } = elementChanged(oldNode, newNode);
52
+ if (changed) nodesToUpdate.push({
53
+ id,
54
+ data: newNode.data,
55
+ classes: newClasses
56
+ });
57
+ }
58
+ }
59
+ for (const id of oldNodes.keys()) if (!newNodes.has(id)) {
60
+ nodesToRemove.push(id);
61
+ topologyChanged = true;
62
+ }
63
+ for (const [id, newEdge] of newEdges) {
64
+ const oldEdge = oldEdges.get(id);
65
+ if (!oldEdge) {
66
+ edgesToAdd.push(newEdge);
67
+ topologyChanged = true;
68
+ } else if (oldEdge.data.source !== newEdge.data.source || oldEdge.data.target !== newEdge.data.target) {
69
+ edgesToRemove.push(id);
70
+ edgesToAdd.push(newEdge);
71
+ topologyChanged = true;
72
+ } else {
73
+ const { changed, newClasses } = elementChanged(oldEdge, newEdge);
74
+ if (changed) edgesToUpdate.push({
75
+ id,
76
+ data: newEdge.data,
77
+ classes: newClasses
78
+ });
79
+ }
80
+ }
81
+ for (const id of oldEdges.keys()) if (!newEdges.has(id)) {
82
+ edgesToRemove.push(id);
83
+ topologyChanged = true;
84
+ }
85
+ return {
86
+ nodesToAdd,
87
+ nodesToRemove,
88
+ nodesToUpdate,
89
+ edgesToAdd,
90
+ edgesToRemove,
91
+ edgesToUpdate,
92
+ topologyChanged
93
+ };
94
+ }
95
+ function applyDataUpdates(cy, diff) {
96
+ cy.batch(() => {
97
+ for (const upd of [...diff.nodesToUpdate, ...diff.edgesToUpdate]) {
98
+ const ele = cy.getElementById(upd.id);
99
+ ele.data(upd.data);
100
+ if (upd.classes !== void 0) ele.classes(upd.classes);
101
+ }
102
+ });
103
+ }
104
+ function applyDiff(cy, diff) {
105
+ cy.batch(() => {
106
+ for (const id of [...diff.nodesToRemove, ...diff.edgesToRemove]) cy.getElementById(id).remove();
107
+ cy.add(diff.nodesToAdd);
108
+ cy.add(diff.edgesToAdd);
109
+ applyDataUpdates(cy, diff);
110
+ });
111
+ }
112
+ export { applyDataUpdates, applyDiff, diffCyElements };
@@ -0,0 +1,12 @@
1
+ import { Core } from "cytoscape";
2
+ import { FileExportOptions } from "@formulavize/renderer-api-formulavize";
3
+ /**
4
+ * Export a Cytoscape instance to an image Blob using the format and scaling
5
+ * factor from the given options. Returns null for unsupported formats.
6
+ *
7
+ * Shared by the Vue renderer component and the headless CLI so both produce
8
+ * identical output. Callers are responsible for adding/removing description
9
+ * ghost nodes around this call and for persisting the resulting Blob.
10
+ */
11
+ export declare function exportCyToBlob(cy: Core, exportOptions: FileExportOptions): Blob | null;
12
+ //# sourceMappingURL=cyExport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cyExport.d.ts","sourceRoot":"","sources":["../src/cyExport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAEL,iBAAiB,EAClB,MAAM,uCAAuC,CAAC;AAE/C;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,EAAE,EAAE,IAAI,EACR,aAAa,EAAE,iBAAiB,GAC/B,IAAI,GAAG,IAAI,CAwCb"}
@@ -0,0 +1,41 @@
1
+ import { match } from "ts-pattern";
2
+ import { ExportFormat } from "@formulavize/renderer-api-formulavize";
3
+ // src/cyExport.ts
4
+ /**
5
+ * Export a Cytoscape instance to an image Blob using the format and scaling
6
+ * factor from the given options. Returns null for unsupported formats.
7
+ *
8
+ * Shared by the Vue renderer component and the headless CLI so both produce
9
+ * identical output. Callers are responsible for adding/removing description
10
+ * ghost nodes around this call and for persisting the resulting Blob.
11
+ */
12
+ function exportCyToBlob(cy, exportOptions) {
13
+ const scaleFactor = exportOptions.scalingFactor;
14
+ const bgColor = exportOptions.backgroundColor;
15
+ return match(exportOptions.fileType).with(ExportFormat.PNG, () => {
16
+ return cy.png({
17
+ full: true,
18
+ scale: scaleFactor,
19
+ output: "blob",
20
+ bg: bgColor
21
+ });
22
+ }).with(ExportFormat.JPG, () => {
23
+ return cy.jpg({
24
+ full: true,
25
+ scale: scaleFactor,
26
+ output: "blob",
27
+ bg: bgColor
28
+ });
29
+ }).with(ExportFormat.SVG, () => {
30
+ const svgData = cy.svg({
31
+ full: true,
32
+ scale: scaleFactor,
33
+ bg: bgColor
34
+ });
35
+ return new Blob([svgData], { type: "image/svg+xml;charset=utf-8" });
36
+ }).otherwise((format) => {
37
+ console.error(`Unsupported export format: ${format}`);
38
+ return null;
39
+ });
40
+ }
41
+ export { exportCyToBlob };
@@ -0,0 +1,6 @@
1
+ import { EdgeDefinition, ElementsDefinition, NodeDefinition } from "cytoscape";
2
+ import { Dag } from "@formulavize/compiler-frontend-fiz/dag";
3
+ export declare function makeCyNodes(dag: Dag): NodeDefinition[];
4
+ export declare function makeCyEdges(dag: Dag): EdgeDefinition[];
5
+ export declare function makeCyElements(dag: Dag, parentOrderPath?: number[]): ElementsDefinition;
6
+ //# sourceMappingURL=cyGraphFactory.d.ts.map