@molecule/app-feature-graph-view-vue 0.0.0-stage → 0.0.1-stage

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.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
- # Temporary Holding Version
1
+ # @molecule/app-feature-graph-view-vue
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
+ Force-directed graph view (Obsidian-style) for visualizing note / page linkages
4
+
5
+ ```
6
+ npm install @molecule/app-feature-graph-view-vue
7
+ ```
8
+
9
+ Part of the [Molecule](https://www.molecule.dev) package fleet. This page carries the manifest summary; the full generated documentation ships with the package's first committed version.
10
+
11
+ License: Apache-2.0
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Vue force-directed graph view: the Vue counterpart of
3
+ * `@molecule/app-feature-graph-view-react`'s `<GraphView>` — the same props
4
+ * (React names), the same classes, and the same DOM for the same input.
5
+ *
6
+ * @module
7
+ */
8
+ import { type PropType, type VNode } from 'vue';
9
+ import { type ForceLayoutOptions } from './layout.js';
10
+ import type { GraphEdge, GraphEdgeRenderer, GraphLayout, GraphNode, GraphNodeRenderer } from './types.js';
11
+ /**
12
+ * Force-directed graph view (Obsidian-style).
13
+ *
14
+ * Renders nodes + edges into an SVG, computing positions via a built-in
15
+ * minimal velocity-Verlet simulation. Three layouts are supported —
16
+ * `force` (default), `circular` and `grid` — and either nodes or edges
17
+ * can be overridden via custom renderers.
18
+ *
19
+ * Style is driven by `getClassMap()`. Inline styles are reserved for
20
+ * SVG geometry — `transform`, viewBox computation, stroke widths — which
21
+ * classes can't express.
22
+ *
23
+ * @returns The graph-view component.
24
+ */
25
+ export declare const GraphView: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
26
+ nodes: {
27
+ type: PropType<GraphNode[]>;
28
+ required: true;
29
+ };
30
+ edges: {
31
+ type: PropType<GraphEdge[]>;
32
+ required: true;
33
+ };
34
+ onNodeClick: PropType<(node: GraphNode) => void>;
35
+ selectedNodeId: StringConstructor;
36
+ layout: {
37
+ type: PropType<GraphLayout>;
38
+ default: string;
39
+ };
40
+ nodeRenderer: PropType<GraphNodeRenderer>;
41
+ edgeRenderer: PropType<GraphEdgeRenderer>;
42
+ forceOptions: PropType<ForceLayoutOptions>;
43
+ className: StringConstructor;
44
+ }>, () => VNode, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
45
+ nodes: {
46
+ type: PropType<GraphNode[]>;
47
+ required: true;
48
+ };
49
+ edges: {
50
+ type: PropType<GraphEdge[]>;
51
+ required: true;
52
+ };
53
+ onNodeClick: PropType<(node: GraphNode) => void>;
54
+ selectedNodeId: StringConstructor;
55
+ layout: {
56
+ type: PropType<GraphLayout>;
57
+ default: string;
58
+ };
59
+ nodeRenderer: PropType<GraphNodeRenderer>;
60
+ edgeRenderer: PropType<GraphEdgeRenderer>;
61
+ forceOptions: PropType<ForceLayoutOptions>;
62
+ className: StringConstructor;
63
+ }>> & Readonly<{}>, {
64
+ layout: GraphLayout;
65
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
66
+ //# sourceMappingURL=GraphView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphView.d.ts","sourceRoot":"","sources":["../src/GraphView.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAgC,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAE,MAAM,KAAK,CAAA;AAK7E,OAAO,EAAe,KAAK,kBAAkB,EAAe,MAAM,aAAa,CAAA;AAC/E,OAAO,KAAK,EACV,SAAS,EACT,iBAAiB,EACjB,WAAW,EACX,SAAS,EACT,iBAAiB,EAElB,MAAM,YAAY,CAAA;AA8CnB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,SAAS;;cAGM,QAAQ,CAAC,SAAS,EAAE,CAAC;;;;cACrB,QAAQ,CAAC,SAAS,EAAE,CAAC;;;iBACpB,QAAQ,CAAC,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;;;cAElC,QAAQ,CAAC,WAAW,CAAC;;;kBACrB,QAAQ,CAAC,iBAAiB,CAAC;kBAC3B,QAAQ,CAAC,iBAAiB,CAAC;kBAC7B,QAAQ,CAAC,kBAAkB,CAAC;;UAiGzC,KAAK;;cAxGQ,QAAQ,CAAC,SAAS,EAAE,CAAC;;;;cACrB,QAAQ,CAAC,SAAS,EAAE,CAAC;;;iBACpB,QAAQ,CAAC,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;;;cAElC,QAAQ,CAAC,WAAW,CAAC;;;kBACrB,QAAQ,CAAC,iBAAiB,CAAC;kBAC3B,QAAQ,CAAC,iBAAiB,CAAC;kBAC7B,QAAQ,CAAC,kBAAkB,CAAC;;;;4EA2ItD,CAAA"}
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Vue force-directed graph view: the Vue counterpart of
3
+ * `@molecule/app-feature-graph-view-react`'s `<GraphView>` — the same props
4
+ * (React names), the same classes, and the same DOM for the same input.
5
+ *
6
+ * @module
7
+ */
8
+ import { computed, defineComponent, h } from 'vue';
9
+ import { getClassMap } from '@molecule/app-ui';
10
+ import { useTranslation } from '@molecule/app-vue';
11
+ import { boundingBox, layoutNodes } from './layout.js';
12
+ /** Default base radius (world units) of an unweighted node. */
13
+ const NODE_RADIUS = 8;
14
+ /**
15
+ * Render the default circle + label for one node. Pulled out so the
16
+ * component stays small.
17
+ *
18
+ * @param node - The positioned node.
19
+ * @param isSelected - Whether the node is currently selected.
20
+ * @returns The default node SVG markup.
21
+ */
22
+ function defaultNode(node, isSelected) {
23
+ const r = NODE_RADIUS * Math.sqrt(Math.max(0.25, node.weight ?? 1));
24
+ return h('g', {
25
+ 'data-mol-id': `graph-view-node-${node.id}`,
26
+ 'data-selected': isSelected ? 'true' : 'false',
27
+ transform: `translate(${node.x}, ${node.y})`,
28
+ }, [
29
+ h('circle', {
30
+ r,
31
+ fill: 'currentColor',
32
+ opacity: isSelected ? 1 : 0.85,
33
+ stroke: 'currentColor',
34
+ 'stroke-width': isSelected ? 2 : 0,
35
+ }),
36
+ h('text', {
37
+ x: r + 4,
38
+ y: 4,
39
+ 'font-size': 11,
40
+ fill: 'currentColor',
41
+ opacity: isSelected ? 1 : 0.75,
42
+ style: { pointerEvents: 'none', userSelect: 'none' },
43
+ }, [node.label]),
44
+ ]);
45
+ }
46
+ /**
47
+ * Force-directed graph view (Obsidian-style).
48
+ *
49
+ * Renders nodes + edges into an SVG, computing positions via a built-in
50
+ * minimal velocity-Verlet simulation. Three layouts are supported —
51
+ * `force` (default), `circular` and `grid` — and either nodes or edges
52
+ * can be overridden via custom renderers.
53
+ *
54
+ * Style is driven by `getClassMap()`. Inline styles are reserved for
55
+ * SVG geometry — `transform`, viewBox computation, stroke widths — which
56
+ * classes can't express.
57
+ *
58
+ * @returns The graph-view component.
59
+ */
60
+ export const GraphView = defineComponent({
61
+ name: 'GraphView',
62
+ props: {
63
+ nodes: { type: Array, required: true },
64
+ edges: { type: Array, required: true },
65
+ onNodeClick: Function,
66
+ selectedNodeId: String,
67
+ layout: { type: String, default: 'force' },
68
+ nodeRenderer: Function,
69
+ edgeRenderer: Function,
70
+ forceOptions: Object,
71
+ className: String,
72
+ },
73
+ setup(props) {
74
+ const cm = getClassMap();
75
+ const { t } = useTranslation();
76
+ // Positions depend only on (nodes, edges, layout, forceOptions), and the
77
+ // simulation is deterministic given a fixed seed — the same computation
78
+ // React memoizes, recomputed here only when one of its inputs changes.
79
+ const positioned = computed(() => layoutNodes(props.nodes, props.edges, props.layout ?? 'force', props.forceOptions));
80
+ const nodeById = computed(() => {
81
+ const m = new Map();
82
+ for (const n of positioned.value)
83
+ m.set(n.id, n);
84
+ return m;
85
+ });
86
+ // Compute viewBox so the graph always fits the SVG bounds, regardless of
87
+ // the world-space size produced by the layout.
88
+ const viewBox = computed(() => {
89
+ const box = boundingBox(positioned.value, 40);
90
+ return box
91
+ ? `${box.minX} ${box.minY} ${Math.max(1, box.maxX - box.minX)} ${Math.max(1, box.maxY - box.minY)}`
92
+ : '-100 -100 200 200';
93
+ });
94
+ const ariaLabel = computed(() => t('graphView.aria.canvas', {}, { defaultValue: 'Graph view' }));
95
+ const emptyLabel = computed(() => t('graphView.empty', {}, { defaultValue: 'No nodes to display' }));
96
+ /**
97
+ * One edge: a custom renderer's nodes inside a per-edge group, or the
98
+ * default `<line>`. An edge whose endpoints are missing renders nothing.
99
+ *
100
+ * @param edge - The edge.
101
+ * @returns The edge's vnode, or null when an endpoint is missing.
102
+ */
103
+ const renderEdge = (edge) => {
104
+ const src = nodeById.value.get(edge.source);
105
+ const tgt = nodeById.value.get(edge.target);
106
+ if (!src || !tgt)
107
+ return null;
108
+ if (props.edgeRenderer)
109
+ return h('g', { key: edge.id, 'data-mol-id': `graph-view-edge-${edge.id}` }, [
110
+ props.edgeRenderer(edge, src, tgt),
111
+ ]);
112
+ return h('line', {
113
+ key: edge.id,
114
+ 'data-mol-id': `graph-view-edge-${edge.id}`,
115
+ x1: src.x,
116
+ y1: src.y,
117
+ x2: tgt.x,
118
+ y2: tgt.y,
119
+ stroke: 'currentColor',
120
+ 'stroke-width': 1,
121
+ opacity: 0.4,
122
+ });
123
+ };
124
+ /**
125
+ * One node's keyboard-activatable hit group, containing the custom
126
+ * renderer's node or the default circle + label.
127
+ *
128
+ * @param node - The positioned node.
129
+ * @returns The node's hit-group vnode.
130
+ */
131
+ const renderNode = (node) => {
132
+ const isSelected = node.id === props.selectedNodeId;
133
+ const aria = t('graphView.aria.node', { label: node.label }, { defaultValue: 'Node {{label}}' });
134
+ return h('g', {
135
+ key: node.id,
136
+ 'data-mol-id': `graph-view-node-hit-${node.id}`,
137
+ role: 'button',
138
+ 'aria-label': aria,
139
+ tabindex: 0,
140
+ onClick: () => props.onNodeClick?.(node),
141
+ onKeydown: (event) => {
142
+ if (event.key === 'Enter' || event.key === ' ') {
143
+ event.preventDefault();
144
+ props.onNodeClick?.(node);
145
+ }
146
+ },
147
+ style: { cursor: props.onNodeClick ? 'pointer' : 'default', outline: 'none' },
148
+ }, [props.nodeRenderer ? props.nodeRenderer(node) : defaultNode(node, isSelected)]);
149
+ };
150
+ return () => h('div', {
151
+ role: 'application',
152
+ 'aria-label': ariaLabel.value,
153
+ 'data-mol-id': 'graph-view',
154
+ class: cm.cn(cm.position('relative'), cm.surfaceSecondary, props.className),
155
+ style: { width: '100%', height: '100%', overflow: 'hidden' },
156
+ }, positioned.value.length === 0
157
+ ? [
158
+ h('div', {
159
+ 'data-mol-id': 'graph-view-empty',
160
+ role: 'status',
161
+ class: cm.cn(cm.position('absolute'), cm.sp('p', 6)),
162
+ style: { inset: 0, display: 'grid', placeItems: 'center' },
163
+ }, [emptyLabel.value]),
164
+ ]
165
+ : [
166
+ h('svg', {
167
+ 'data-mol-id': 'graph-view-svg',
168
+ width: '100%',
169
+ height: '100%',
170
+ viewBox: viewBox.value,
171
+ preserveAspectRatio: 'xMidYMid meet',
172
+ style: { display: 'block' },
173
+ }, [
174
+ h('g', { 'data-mol-id': 'graph-view-edges' }, props.edges.map(renderEdge)),
175
+ h('g', { 'data-mol-id': 'graph-view-nodes' }, positioned.value.map(renderNode)),
176
+ ]),
177
+ ]);
178
+ },
179
+ });
180
+ //# sourceMappingURL=GraphView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphView.js","sourceRoot":"","sources":["../src/GraphView.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,EAA6B,MAAM,KAAK,CAAA;AAE7E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,OAAO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AO,EAAE;iBAC5B,EACD;oBACE,CAAC,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,kBAAkB,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;oBAC1E,CAAC,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,kBAAkB,EAAE,EAAE,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;iBAChF,CACF;aACF,CACN,CAAA;IACL,CAAC;CACF,CAAC,CAAA"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Vue force-directed graph view (Obsidian-style) — the Vue counterpart of
3
+ * `@molecule/app-feature-graph-view-react`: the same exports, the same props
4
+ * (React names), and the same DOM for the same input.
5
+ *
6
+ * Exports:
7
+ * - `<GraphView>` — top-level node-and-edge visualization with built-in
8
+ * `force`, `circular`, and `grid` layouts, click + selection support,
9
+ * and pluggable node / edge renderers.
10
+ * - `GraphNode`, `GraphEdge`, `GraphLayout`, `GraphPoint`, `PositionedNode`,
11
+ * `GraphNodeRenderer`, `GraphEdgeRenderer`, `GraphViewProps` types.
12
+ * - Pure layout helpers (`forceLayout`, `circularLayout`, `gridLayout`,
13
+ * `layoutNodes`, `boundingBox`, `createRng`).
14
+ *
15
+ * Used by note-taking and other apps to visualize page / note linkages
16
+ * the same way Obsidian does — a force-directed map of which notes link
17
+ * to which.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { createApp, defineComponent, h } from 'vue'
22
+ * import { GraphView, type GraphEdge, type GraphNode } from '@molecule/app-feature-graph-view-vue'
23
+ *
24
+ * const nodes: GraphNode[] = [
25
+ * { id: 'a', label: 'Alpha' },
26
+ * { id: 'b', label: 'Beta', group: 'project', weight: 2 },
27
+ * ]
28
+ * const edges: GraphEdge[] = [{ id: 'e1', source: 'a', target: 'b' }]
29
+ *
30
+ * const NoteGraph = defineComponent({
31
+ * setup() {
32
+ * return () =>
33
+ * h(GraphView, {
34
+ * nodes,
35
+ * edges,
36
+ * onNodeClick: (node: GraphNode) => console.log(`open ${node.id}`),
37
+ * })
38
+ * },
39
+ * })
40
+ *
41
+ * createApp(NoteGraph).mount('#app')
42
+ * ```
43
+ *
44
+ * @remarks
45
+ * The root element fills 100% of its parent — the PARENT must have an
46
+ * explicit height (e.g. a fixed-height panel or a flex/grid track) or
47
+ * the graph renders zero-tall and appears blank.
48
+ *
49
+ * Interaction surface is click / keyboard-activate + `selectedNodeId`
50
+ * highlighting only. Nodes are NOT draggable and there is no built-in
51
+ * pan / zoom — the SVG `viewBox` auto-fits the layout bounds. For a
52
+ * pannable / zoomable surface, compose with
53
+ * `@molecule/app-feature-canvas-vue` instead.
54
+ *
55
+ * Layout is deterministic (seeded RNG), computed once per
56
+ * `(nodes, edges, layout, forceOptions)` change. `forceOptions` is
57
+ * ignored by the `circular` and `grid` layouts.
58
+ *
59
+ * @module
60
+ */
61
+ export * from './GraphView.js';
62
+ export * from './layout.js';
63
+ export * from './types.js';
64
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Vue force-directed graph view (Obsidian-style) — the Vue counterpart of
3
+ * `@molecule/app-feature-graph-view-react`: the same exports, the same props
4
+ * (React names), and the same DOM for the same input.
5
+ *
6
+ * Exports:
7
+ * - `<GraphView>` — top-level node-and-edge visualization with built-in
8
+ * `force`, `circular`, and `grid` layouts, click + selection support,
9
+ * and pluggable node / edge renderers.
10
+ * - `GraphNode`, `GraphEdge`, `GraphLayout`, `GraphPoint`, `PositionedNode`,
11
+ * `GraphNodeRenderer`, `GraphEdgeRenderer`, `GraphViewProps` types.
12
+ * - Pure layout helpers (`forceLayout`, `circularLayout`, `gridLayout`,
13
+ * `layoutNodes`, `boundingBox`, `createRng`).
14
+ *
15
+ * Used by note-taking and other apps to visualize page / note linkages
16
+ * the same way Obsidian does — a force-directed map of which notes link
17
+ * to which.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { createApp, defineComponent, h } from 'vue'
22
+ * import { GraphView, type GraphEdge, type GraphNode } from '@molecule/app-feature-graph-view-vue'
23
+ *
24
+ * const nodes: GraphNode[] = [
25
+ * { id: 'a', label: 'Alpha' },
26
+ * { id: 'b', label: 'Beta', group: 'project', weight: 2 },
27
+ * ]
28
+ * const edges: GraphEdge[] = [{ id: 'e1', source: 'a', target: 'b' }]
29
+ *
30
+ * const NoteGraph = defineComponent({
31
+ * setup() {
32
+ * return () =>
33
+ * h(GraphView, {
34
+ * nodes,
35
+ * edges,
36
+ * onNodeClick: (node: GraphNode) => console.log(`open ${node.id}`),
37
+ * })
38
+ * },
39
+ * })
40
+ *
41
+ * createApp(NoteGraph).mount('#app')
42
+ * ```
43
+ *
44
+ * @remarks
45
+ * The root element fills 100% of its parent — the PARENT must have an
46
+ * explicit height (e.g. a fixed-height panel or a flex/grid track) or
47
+ * the graph renders zero-tall and appears blank.
48
+ *
49
+ * Interaction surface is click / keyboard-activate + `selectedNodeId`
50
+ * highlighting only. Nodes are NOT draggable and there is no built-in
51
+ * pan / zoom — the SVG `viewBox` auto-fits the layout bounds. For a
52
+ * pannable / zoomable surface, compose with
53
+ * `@molecule/app-feature-canvas-vue` instead.
54
+ *
55
+ * Layout is deterministic (seeded RNG), computed once per
56
+ * `(nodes, edges, layout, forceOptions)` change. `forceOptions` is
57
+ * ignored by the `circular` and `grid` layouts.
58
+ *
59
+ * @module
60
+ */
61
+ export * from './GraphView.js';
62
+ export * from './layout.js';
63
+ export * from './types.js';
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
@@ -0,0 +1,101 @@
1
+ import type { GraphEdge, GraphLayout, GraphNode, PositionedNode } from './types.js';
2
+ /**
3
+ * Pure (framework-free) layout helpers for `<GraphView>`. Extracted so the
4
+ * math is unit-testable without a component library or jsdom.
5
+ *
6
+ * @module
7
+ */
8
+ /** Default cap on force-layout iterations. */
9
+ export declare const DEFAULT_FORCE_ITERATIONS = 200;
10
+ /** Default repulsion strength used by `forceLayout`. */
11
+ export declare const DEFAULT_REPULSION = 800;
12
+ /** Default spring stiffness used by `forceLayout`. */
13
+ export declare const DEFAULT_SPRING = 0.05;
14
+ /** Default ideal edge length used by `forceLayout`. */
15
+ export declare const DEFAULT_REST_LENGTH = 80;
16
+ /** Default velocity damping used by `forceLayout`. */
17
+ export declare const DEFAULT_DAMPING = 0.85;
18
+ /** Convergence threshold (max per-node displacement squared). */
19
+ export declare const CONVERGENCE_EPSILON = 0.01;
20
+ /** Force-layout tunables. */
21
+ export interface ForceLayoutOptions {
22
+ /** Hard cap on iterations. Defaults to {@link DEFAULT_FORCE_ITERATIONS}. */
23
+ iterations?: number;
24
+ /** Repulsive constant between every pair of nodes. */
25
+ repulsion?: number;
26
+ /** Spring (Hooke) constant for edges. */
27
+ spring?: number;
28
+ /** Ideal edge length (rest distance). */
29
+ restLength?: number;
30
+ /** Velocity damping per step (0–1). */
31
+ damping?: number;
32
+ /** Optional deterministic seed (for tests). Defaults to a fixed value. */
33
+ seed?: number;
34
+ }
35
+ /**
36
+ * Tiny deterministic PRNG (mulberry32). Allows reproducible initial
37
+ * positions in tests without depending on `Math.random()`.
38
+ *
39
+ * @param seed - 32-bit unsigned seed.
40
+ * @returns A function returning floats in `[0, 1)`.
41
+ */
42
+ export declare function createRng(seed: number): () => number;
43
+ /**
44
+ * Place nodes evenly around the unit circle (scaled by `radius`).
45
+ *
46
+ * @param nodes - Nodes to position.
47
+ * @param radius - Circle radius in world units.
48
+ * @returns Positioned nodes, in input order.
49
+ */
50
+ export declare function circularLayout(nodes: GraphNode[], radius: number): PositionedNode[];
51
+ /**
52
+ * Place nodes on a square-ish grid, centred on the origin.
53
+ *
54
+ * @param nodes - Nodes to position.
55
+ * @param spacing - Pixel spacing between adjacent grid cells.
56
+ * @returns Positioned nodes, in input order.
57
+ */
58
+ export declare function gridLayout(nodes: GraphNode[], spacing: number): PositionedNode[];
59
+ /**
60
+ * Run a minimal velocity-Verlet force-directed simulation.
61
+ *
62
+ * Implements:
63
+ * - Pairwise repulsion (Coulomb-like, O(n²)) between every node pair.
64
+ * - Spring (Hooke) attraction along each edge toward `restLength`.
65
+ * - Per-step velocity damping for stability.
66
+ *
67
+ * Stops early once the maximum per-node displacement-squared drops below
68
+ * {@link CONVERGENCE_EPSILON}, or after `iterations` steps — whichever
69
+ * comes first.
70
+ *
71
+ * @param nodes - Nodes to lay out.
72
+ * @param edges - Edges (used only for attractive springs).
73
+ * @param options - Force-layout tunables.
74
+ * @returns Positioned nodes, in input order.
75
+ */
76
+ export declare function forceLayout(nodes: GraphNode[], edges: GraphEdge[], options?: ForceLayoutOptions): PositionedNode[];
77
+ /**
78
+ * Compute world-space positions for every node using the chosen layout.
79
+ *
80
+ * @param nodes - Nodes to position.
81
+ * @param edges - Edges (consumed only by `force`).
82
+ * @param layout - Layout strategy.
83
+ * @param options - Optional force-layout tunables (ignored for non-force).
84
+ * @returns Positioned nodes.
85
+ */
86
+ export declare function layoutNodes(nodes: GraphNode[], edges: GraphEdge[], layout: GraphLayout, options?: ForceLayoutOptions): PositionedNode[];
87
+ /**
88
+ * Compute the world-space bounding box of a set of positioned nodes,
89
+ * with a small padding for visual breathing room.
90
+ *
91
+ * @param nodes - Positioned nodes.
92
+ * @param padding - Padding (world units) added to every side. Default 40.
93
+ * @returns Bounding box `{ minX, minY, maxX, maxY }` — or `null` if empty.
94
+ */
95
+ export declare function boundingBox(nodes: PositionedNode[], padding?: number): {
96
+ minX: number;
97
+ minY: number;
98
+ maxX: number;
99
+ maxY: number;
100
+ } | null;
101
+ //# sourceMappingURL=layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEnF;;;;;GAKG;AAEH,8CAA8C;AAC9C,eAAO,MAAM,wBAAwB,MAAM,CAAA;AAE3C,wDAAwD;AACxD,eAAO,MAAM,iBAAiB,MAAM,CAAA;AAEpC,sDAAsD;AACtD,eAAO,MAAM,cAAc,OAAO,CAAA;AAElC,uDAAuD;AACvD,eAAO,MAAM,mBAAmB,KAAK,CAAA;AAErC,sDAAsD;AACtD,eAAO,MAAM,eAAe,OAAO,CAAA;AAEnC,iEAAiE;AACjE,eAAO,MAAM,mBAAmB,OAAO,CAAA;AAEvC,6BAA6B;AAC7B,MAAM,WAAW,kBAAkB;IACjC,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,MAAM,CASpD;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,EAAE,CAOnF;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc,EAAE,CAWhF;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,EAAE,EAClB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,GAAE,kBAAuB,GAC/B,cAAc,EAAE,CA0GlB;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,EAAE,EAClB,KAAK,EAAE,SAAS,EAAE,EAClB,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,cAAc,EAAE,CAUlB;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,SAAK,GACX;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAanE"}
package/dist/layout.js ADDED
@@ -0,0 +1,239 @@
1
+ /**
2
+ * Pure (framework-free) layout helpers for `<GraphView>`. Extracted so the
3
+ * math is unit-testable without a component library or jsdom.
4
+ *
5
+ * @module
6
+ */
7
+ /** Default cap on force-layout iterations. */
8
+ export const DEFAULT_FORCE_ITERATIONS = 200;
9
+ /** Default repulsion strength used by `forceLayout`. */
10
+ export const DEFAULT_REPULSION = 800;
11
+ /** Default spring stiffness used by `forceLayout`. */
12
+ export const DEFAULT_SPRING = 0.05;
13
+ /** Default ideal edge length used by `forceLayout`. */
14
+ export const DEFAULT_REST_LENGTH = 80;
15
+ /** Default velocity damping used by `forceLayout`. */
16
+ export const DEFAULT_DAMPING = 0.85;
17
+ /** Convergence threshold (max per-node displacement squared). */
18
+ export const CONVERGENCE_EPSILON = 0.01;
19
+ /**
20
+ * Tiny deterministic PRNG (mulberry32). Allows reproducible initial
21
+ * positions in tests without depending on `Math.random()`.
22
+ *
23
+ * @param seed - 32-bit unsigned seed.
24
+ * @returns A function returning floats in `[0, 1)`.
25
+ */
26
+ export function createRng(seed) {
27
+ let s = seed >>> 0;
28
+ return function rand() {
29
+ s = (s + 0x6d2b79f5) >>> 0;
30
+ let t = s;
31
+ t = Math.imul(t ^ (t >>> 15), t | 1);
32
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
33
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
34
+ };
35
+ }
36
+ /**
37
+ * Place nodes evenly around the unit circle (scaled by `radius`).
38
+ *
39
+ * @param nodes - Nodes to position.
40
+ * @param radius - Circle radius in world units.
41
+ * @returns Positioned nodes, in input order.
42
+ */
43
+ export function circularLayout(nodes, radius) {
44
+ if (nodes.length === 0)
45
+ return [];
46
+ if (nodes.length === 1)
47
+ return [{ ...nodes[0], x: 0, y: 0 }];
48
+ return nodes.map((n, i) => {
49
+ const angle = (i / nodes.length) * Math.PI * 2;
50
+ return { ...n, x: Math.cos(angle) * radius, y: Math.sin(angle) * radius };
51
+ });
52
+ }
53
+ /**
54
+ * Place nodes on a square-ish grid, centred on the origin.
55
+ *
56
+ * @param nodes - Nodes to position.
57
+ * @param spacing - Pixel spacing between adjacent grid cells.
58
+ * @returns Positioned nodes, in input order.
59
+ */
60
+ export function gridLayout(nodes, spacing) {
61
+ if (nodes.length === 0)
62
+ return [];
63
+ const cols = Math.max(1, Math.ceil(Math.sqrt(nodes.length)));
64
+ const rows = Math.ceil(nodes.length / cols);
65
+ const offsetX = ((cols - 1) * spacing) / 2;
66
+ const offsetY = ((rows - 1) * spacing) / 2;
67
+ return nodes.map((n, i) => {
68
+ const col = i % cols;
69
+ const row = Math.floor(i / cols);
70
+ return { ...n, x: col * spacing - offsetX, y: row * spacing - offsetY };
71
+ });
72
+ }
73
+ /**
74
+ * Run a minimal velocity-Verlet force-directed simulation.
75
+ *
76
+ * Implements:
77
+ * - Pairwise repulsion (Coulomb-like, O(n²)) between every node pair.
78
+ * - Spring (Hooke) attraction along each edge toward `restLength`.
79
+ * - Per-step velocity damping for stability.
80
+ *
81
+ * Stops early once the maximum per-node displacement-squared drops below
82
+ * {@link CONVERGENCE_EPSILON}, or after `iterations` steps — whichever
83
+ * comes first.
84
+ *
85
+ * @param nodes - Nodes to lay out.
86
+ * @param edges - Edges (used only for attractive springs).
87
+ * @param options - Force-layout tunables.
88
+ * @returns Positioned nodes, in input order.
89
+ */
90
+ export function forceLayout(nodes, edges, options = {}) {
91
+ const iterations = options.iterations ?? DEFAULT_FORCE_ITERATIONS;
92
+ const repulsion = options.repulsion ?? DEFAULT_REPULSION;
93
+ const spring = options.spring ?? DEFAULT_SPRING;
94
+ const restLength = options.restLength ?? DEFAULT_REST_LENGTH;
95
+ const damping = options.damping ?? DEFAULT_DAMPING;
96
+ const rand = createRng(options.seed ?? 0x9e3779b9);
97
+ const n = nodes.length;
98
+ if (n === 0)
99
+ return [];
100
+ // Seed positions on a small circle so all-pairs repulsion has somewhere
101
+ // to push from on iteration 0 (true zero-vectors give NaN directions).
102
+ const seedRadius = Math.max(20, Math.sqrt(n) * 10);
103
+ const x = new Float64Array(n);
104
+ const y = new Float64Array(n);
105
+ const vx = new Float64Array(n);
106
+ const vy = new Float64Array(n);
107
+ for (let i = 0; i < n; i++) {
108
+ const angle = (i / Math.max(1, n)) * Math.PI * 2 + rand() * 0.5;
109
+ const jitter = 1 + rand() * 0.5;
110
+ x[i] = Math.cos(angle) * seedRadius * jitter;
111
+ y[i] = Math.sin(angle) * seedRadius * jitter;
112
+ }
113
+ // Map id → index once (edges reference ids).
114
+ const idx = new Map();
115
+ for (let i = 0; i < n; i++)
116
+ idx.set(nodes[i].id, i);
117
+ // Precompute valid edges (both endpoints present, not self-loops).
118
+ const ea = [];
119
+ const eb = [];
120
+ const ew = [];
121
+ for (const e of edges) {
122
+ const a = idx.get(e.source);
123
+ const b = idx.get(e.target);
124
+ if (a === undefined || b === undefined || a === b)
125
+ continue;
126
+ ea.push(a);
127
+ eb.push(b);
128
+ ew.push(e.weight ?? 1);
129
+ }
130
+ for (let step = 0; step < iterations; step++) {
131
+ // Reset force accumulator (we reuse vx/vy as fx/fy then integrate).
132
+ const fx = new Float64Array(n);
133
+ const fy = new Float64Array(n);
134
+ // Pairwise repulsion — O(n²). Acceptable for the small graphs the
135
+ // note-taking app will throw at this (hundreds, not millions, of nodes).
136
+ for (let i = 0; i < n; i++) {
137
+ for (let j = i + 1; j < n; j++) {
138
+ let dx = x[i] - x[j];
139
+ let dy = y[i] - y[j];
140
+ let distSq = dx * dx + dy * dy;
141
+ if (distSq < 1e-4) {
142
+ // Two nodes on top of each other — nudge them apart.
143
+ dx = (rand() - 0.5) * 0.1;
144
+ dy = (rand() - 0.5) * 0.1;
145
+ distSq = dx * dx + dy * dy + 1e-4;
146
+ }
147
+ const dist = Math.sqrt(distSq);
148
+ const f = repulsion / distSq;
149
+ const fxi = (dx / dist) * f;
150
+ const fyi = (dy / dist) * f;
151
+ fx[i] += fxi;
152
+ fy[i] += fyi;
153
+ fx[j] -= fxi;
154
+ fy[j] -= fyi;
155
+ }
156
+ }
157
+ // Edge springs.
158
+ for (let k = 0; k < ea.length; k++) {
159
+ const a = ea[k];
160
+ const b = eb[k];
161
+ const w = ew[k];
162
+ const dx = x[b] - x[a];
163
+ const dy = y[b] - y[a];
164
+ const dist = Math.sqrt(dx * dx + dy * dy) || 1e-4;
165
+ const displacement = dist - restLength;
166
+ const f = spring * displacement * w;
167
+ const fxk = (dx / dist) * f;
168
+ const fyk = (dy / dist) * f;
169
+ fx[a] += fxk;
170
+ fy[a] += fyk;
171
+ fx[b] -= fxk;
172
+ fy[b] -= fyk;
173
+ }
174
+ // Integrate (semi-implicit Euler with damping).
175
+ let maxDispSq = 0;
176
+ for (let i = 0; i < n; i++) {
177
+ vx[i] = (vx[i] + fx[i]) * damping;
178
+ vy[i] = (vy[i] + fy[i]) * damping;
179
+ const dx = vx[i];
180
+ const dy = vy[i];
181
+ x[i] += dx;
182
+ y[i] += dy;
183
+ const dispSq = dx * dx + dy * dy;
184
+ if (dispSq > maxDispSq)
185
+ maxDispSq = dispSq;
186
+ }
187
+ if (maxDispSq < CONVERGENCE_EPSILON)
188
+ break;
189
+ }
190
+ return nodes.map((node, i) => ({ ...node, x: x[i], y: y[i] }));
191
+ }
192
+ /**
193
+ * Compute world-space positions for every node using the chosen layout.
194
+ *
195
+ * @param nodes - Nodes to position.
196
+ * @param edges - Edges (consumed only by `force`).
197
+ * @param layout - Layout strategy.
198
+ * @param options - Optional force-layout tunables (ignored for non-force).
199
+ * @returns Positioned nodes.
200
+ */
201
+ export function layoutNodes(nodes, edges, layout, options) {
202
+ switch (layout) {
203
+ case 'circular':
204
+ return circularLayout(nodes, Math.max(40, Math.sqrt(nodes.length) * 30));
205
+ case 'grid':
206
+ return gridLayout(nodes, 60);
207
+ case 'force':
208
+ default:
209
+ return forceLayout(nodes, edges, options);
210
+ }
211
+ }
212
+ /**
213
+ * Compute the world-space bounding box of a set of positioned nodes,
214
+ * with a small padding for visual breathing room.
215
+ *
216
+ * @param nodes - Positioned nodes.
217
+ * @param padding - Padding (world units) added to every side. Default 40.
218
+ * @returns Bounding box `{ minX, minY, maxX, maxY }` — or `null` if empty.
219
+ */
220
+ export function boundingBox(nodes, padding = 40) {
221
+ if (nodes.length === 0)
222
+ return null;
223
+ let minX = Infinity;
224
+ let minY = Infinity;
225
+ let maxX = -Infinity;
226
+ let maxY = -Infinity;
227
+ for (const n of nodes) {
228
+ if (n.x < minX)
229
+ minX = n.x;
230
+ if (n.y < minY)
231
+ minY = n.y;
232
+ if (n.x > maxX)
233
+ maxX = n.x;
234
+ if (n.y > maxY)
235
+ maxY = n.y;
236
+ }
237
+ return { minX: minX - padding, minY: minY - padding, maxX: maxX + padding, maxY: maxY + padding };
238
+ }
239
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1 @@
1
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I,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,EAAE,CAAA;AACnG,CAAC"}
@@ -0,0 +1,80 @@
1
+ import type { VNodeChild } from 'vue';
2
+ import type { ForceLayoutOptions } from './layout.js';
3
+ /**
4
+ * Graph-view types: nodes, edges, layout choice and renderer hooks for
5
+ * `<GraphView>`.
6
+ *
7
+ * @module
8
+ */
9
+ /** A 2-D point in graph (world) coordinates. */
10
+ export interface GraphPoint {
11
+ /** X coordinate. */
12
+ x: number;
13
+ /** Y coordinate. */
14
+ y: number;
15
+ }
16
+ /**
17
+ * Single node in the graph.
18
+ *
19
+ * `group` is an opaque grouping discriminator (e.g. tag, folder) the
20
+ * caller can use for colouring; `weight` scales the rendered radius.
21
+ */
22
+ export interface GraphNode {
23
+ /** Unique node id. */
24
+ id: string;
25
+ /** Human-readable label rendered next to the node. */
26
+ label: string;
27
+ /** Optional grouping discriminator (e.g. tag id). */
28
+ group?: string;
29
+ /** Optional weight; default 1. Scales the rendered radius. */
30
+ weight?: number;
31
+ }
32
+ /** Edge connecting two nodes by id. */
33
+ export interface GraphEdge {
34
+ /** Unique edge id. */
35
+ id: string;
36
+ /** Source node id. */
37
+ source: string;
38
+ /** Target node id. */
39
+ target: string;
40
+ /** Optional weight; default 1. Stronger edges pull harder under force layout. */
41
+ weight?: number;
42
+ }
43
+ /** Available layout strategies. */
44
+ export type GraphLayout = 'force' | 'circular' | 'grid';
45
+ /**
46
+ * Internal positioned node used by the renderer; the `x`/`y` coordinates
47
+ * are in world (graph) space, with `(0, 0)` at the canvas centre.
48
+ */
49
+ export interface PositionedNode extends GraphNode {
50
+ /** World-space X coordinate. */
51
+ x: number;
52
+ /** World-space Y coordinate. */
53
+ y: number;
54
+ }
55
+ /** Renderer for an individual node. Receives the positioned node. */
56
+ export type GraphNodeRenderer = (node: PositionedNode) => VNodeChild;
57
+ /** Renderer for an individual edge. Receives the edge plus both endpoints. */
58
+ export type GraphEdgeRenderer = (edge: GraphEdge, source: PositionedNode, target: PositionedNode) => VNodeChild;
59
+ /** `<GraphView>` props. */
60
+ export interface GraphViewProps {
61
+ /** Nodes to render. */
62
+ nodes: GraphNode[];
63
+ /** Edges to render. */
64
+ edges: GraphEdge[];
65
+ /** Fired when the user clicks (or activates) a node. */
66
+ onNodeClick?: (node: GraphNode) => void;
67
+ /** Currently-selected node id (highlighted in the view). */
68
+ selectedNodeId?: string;
69
+ /** Layout strategy. Defaults to `'force'`. */
70
+ layout?: GraphLayout;
71
+ /** Custom node renderer (overrides the default circle + label). */
72
+ nodeRenderer?: GraphNodeRenderer;
73
+ /** Custom edge renderer (overrides the default `<line>`). */
74
+ edgeRenderer?: GraphEdgeRenderer;
75
+ /** Force-layout tunables; ignored for non-force layouts. */
76
+ forceOptions?: ForceLayoutOptions;
77
+ /** Extra classes merged onto the outer wrapper. */
78
+ className?: string;
79
+ }
80
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAErC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErD;;;;;GAKG;AAEH,gDAAgD;AAChD,MAAM,WAAW,UAAU;IACzB,oBAAoB;IACpB,CAAC,EAAE,MAAM,CAAA;IACT,oBAAoB;IACpB,CAAC,EAAE,MAAM,CAAA;CACV;AAED;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,sBAAsB;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAA;IACb,qDAAqD;IACrD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,uCAAuC;AACvC,MAAM,WAAW,SAAS;IACxB,sBAAsB;IAC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.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,69 @@
1
1
  {
2
2
  "name": "@molecule/app-feature-graph-view-vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1-stage",
4
+ "description": "Force-directed graph view (Obsidian-style) for visualizing note / page linkages",
5
+ "homepage": "https://www.molecule.dev/packages/app-feature-graph-view-vue",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "dev": "vue-tsc --watch",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest"
24
+ },
25
+ "keywords": [
26
+ "molecule",
27
+ "graph",
28
+ "force-directed",
29
+ "visualization",
30
+ "obsidian",
31
+ "notes",
32
+ "vue"
33
+ ],
34
+ "author": "Molecule Dev, Inc. (https://molecule.dev)",
35
+ "license": "Apache-2.0",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/molecule-dev/molecule.git",
39
+ "directory": "packages/app/features/feature-graph-view-vue"
40
+ },
41
+ "engines": {
42
+ "node": ">=20"
43
+ },
44
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "peerDependencies": {
49
+ "@molecule/app-ui": "^1.0.1",
50
+ "@molecule/app-ui-vue": "^1.1.0",
51
+ "@molecule/app-vue": "^3.5.0",
52
+ "vue": "^3.4.0"
53
+ },
54
+ "devDependencies": {
55
+ "@molecule/app-framework-conformance": "0.0.0",
56
+ "@molecule/app-i18n": "1.2.2",
57
+ "@molecule/app-icons": "1.0.4",
58
+ "@molecule/app-ui": "1.4.0",
59
+ "@molecule/app-ui-vue": "1.1.5",
60
+ "@molecule/app-vue": "3.7.2",
61
+ "@types/node": "26.6.5",
62
+ "jsdom": "30.1.3",
63
+ "typescript": "6.0.3",
64
+ "vite": "8.3.5",
65
+ "vitest": "4.1.12",
66
+ "vue": "3.5.44",
67
+ "vue-tsc": "3.3.13"
68
+ }
69
+ }