@lensmap/starlight 0.2.1 → 0.4.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.
@@ -10,6 +10,7 @@ interface Props {
10
10
  authoredFrontmatter: Record<string, unknown>;
11
11
  executable: boolean;
12
12
  inspectorId?: string;
13
+ mapId?: string;
13
14
  }
14
15
  const { graph: semantic, executable, inspectorId = "default" } = Astro.props;
15
16
  const entry = Astro.props.entry ?? Astro.locals.starlightRoute?.entry;
@@ -29,7 +30,7 @@ const publicGraph = {
29
30
  };
30
31
  ---
31
32
  <div data-lensmap-document data-executable={String(executable)}>
32
- <div class="not-content"><ViewerHost client:load graph={publicGraph} rendered={rendered} inspectorId={inspectorId} /></div>
33
+ <div class="not-content"><ViewerHost client:load mapId={Astro.props.mapId} graph={publicGraph} rendered={rendered} inspectorId={inspectorId} /></div>
33
34
  <section data-static-thoughts>
34
35
  {graph.nodes.map((node) => <section data-thought={node.key}><h2>{node.title}</h2><div set:html={rendered[node.key]} /></section>)}
35
36
  </section>
package/dist/index.js CHANGED
@@ -2,12 +2,27 @@
2
2
  import { fileURLToPath } from "node:url";
3
3
  import lensmap from "@lensmap/astro-loader";
4
4
  function starlightLensmap(options = {}) {
5
- return lensmap({
5
+ const integration = lensmap({
6
6
  ...options,
7
7
  contentComponent: fileURLToPath(
8
8
  new URL("./components/MapContent.astro", import.meta.url)
9
9
  )
10
10
  });
11
+ const setup = integration.hooks["astro:config:setup"];
12
+ integration.hooks["astro:config:setup"] = async (context) => {
13
+ await setup?.(context);
14
+ context.updateConfig({
15
+ vite: {
16
+ optimizeDeps: {
17
+ include: [
18
+ "@lensmap/starlight > @lensmap/document",
19
+ "@lensmap/starlight > react-markdown"
20
+ ]
21
+ }
22
+ }
23
+ });
24
+ };
25
+ return integration;
11
26
  }
12
27
  export {
13
28
  starlightLensmap as default
package/dist/layout.js CHANGED
@@ -6,6 +6,15 @@ import {
6
6
  forceY
7
7
  } from "d3-force";
8
8
 
9
+ // ../../apps/web/src/node-style.ts
10
+ function positionAxis(node, axis) {
11
+ const value = node.style?.[axis];
12
+ return value === "auto" ? void 0 : value ?? node.position?.[axis];
13
+ }
14
+ function baseRadius(style) {
15
+ return 43 * (typeof style?.scale === "number" ? style.scale : 1);
16
+ }
17
+
9
18
  // ../../apps/web/src/document/subtree.ts
10
19
  import { polygonHull } from "d3-polygon";
11
20
  function silhouette(contour, distance, padding) {
@@ -74,8 +83,9 @@ function layoutGraph(nodes, edges) {
74
83
  }
75
84
  const roots = nodes.filter((node) => !childKeys.has(node.key));
76
85
  const placed = /* @__PURE__ */ new Map();
77
- const step = 180;
78
- const padding = 56;
86
+ const maximum = Math.max(43, ...nodes.map((n) => n.baseRadius ?? 43));
87
+ const step = Math.max(180, maximum * 2 + 24);
88
+ const padding = Math.max(56, maximum + 13);
79
89
  function plan(node, isRoot) {
80
90
  const descendants = (children.get(node.key) ?? []).map(
81
91
  (child) => plan(child, false)
@@ -84,16 +94,17 @@ function layoutGraph(nodes, edges) {
84
94
  }
85
95
  const plans = roots.map((root) => plan(root, true));
86
96
  function seed(node, subtree, point, heading, isRoot) {
87
- const actual = node.position ?? point;
88
- const fixed = Boolean(node.position) || isRoot;
97
+ const pinX = positionAxis(node, "x");
98
+ const pinY = positionAxis(node, "y");
99
+ const actual = { x: pinX ?? point.x, y: pinY ?? point.y };
89
100
  placed.set(node.key, {
90
101
  key: node.key,
91
102
  x: actual.x,
92
103
  y: actual.y,
93
104
  targetX: actual.x,
94
105
  targetY: actual.y,
95
- fx: fixed ? actual.x : void 0,
96
- fy: fixed ? actual.y : void 0
106
+ fx: pinX !== void 0 || isRoot ? actual.x : void 0,
107
+ fy: pinY !== void 0 || isRoot ? actual.y : void 0
97
108
  });
98
109
  subtree.children.forEach((placement) => {
99
110
  const child = byKey.get(placement.subtree.key);
@@ -106,12 +117,18 @@ function layoutGraph(nodes, edges) {
106
117
  x: actual.x + Math.cos(angle) * placement.distance,
107
118
  y: actual.y + Math.sin(angle) * placement.distance
108
119
  };
109
- const childPoint = child.position ?? target;
120
+ const childPoint = {
121
+ x: positionAxis(child, "x") ?? target.x,
122
+ y: positionAxis(child, "y") ?? target.y
123
+ };
110
124
  const direction = childPoint.x === actual.x && childPoint.y === actual.y ? angle : Math.atan2(childPoint.y - actual.y, childPoint.x - actual.x);
111
125
  seed(child, placement.subtree, target, direction, false);
112
126
  });
113
127
  }
114
- const anchor = nodes[0].position ?? { x: 0, y: 0 };
128
+ const anchor = {
129
+ x: positionAxis(nodes[0], "x") ?? 0,
130
+ y: positionAxis(nodes[0], "y") ?? 0
131
+ };
115
132
  const rootRadius = roots.length > 1 ? step * 2 / Math.sin(Math.PI / roots.length) : 0;
116
133
  roots.forEach((root, index) => {
117
134
  const angle = -Math.PI / 2 + Math.PI * 2 * index / roots.length;
@@ -132,12 +149,13 @@ function layoutGraph(nodes, edges) {
132
149
  );
133
150
  simulation.tick(ticks);
134
151
  return {
135
- nodes: nodes.map(({ position: _position, ...node }) => {
152
+ nodes: nodes.map(({ position, ...node }) => {
136
153
  const point = placed.get(node.key);
137
154
  if (!point)
138
155
  throw new Error(`Automatic layout could not place node "${node.key}".`);
139
156
  return {
140
157
  ...node,
158
+ ...position ? { position } : {},
141
159
  x: point.x,
142
160
  y: point.y
143
161
  };
@@ -149,7 +167,12 @@ function layoutGraph(nodes, edges) {
149
167
  // ../../apps/web/src/semantic-layout.ts
150
168
  var branches = ["blue", "amber", "mint", "rose"];
151
169
  var layoutKey = (graph) => JSON.stringify({
152
- nodes: graph.nodes.map((node) => [node.key, node.position]),
170
+ nodes: graph.nodes.map((node) => [
171
+ node.key,
172
+ positionAxis(node, "x"),
173
+ positionAxis(node, "y"),
174
+ baseRadius(node.style)
175
+ ]),
153
176
  edges: graph.edges.map((edge) => [edge.key, edge.from, edge.to, edge.kind])
154
177
  });
155
178
  function layoutSemanticGraph(graph, previous) {
@@ -177,30 +200,44 @@ function layoutSemanticGraph(graph, previous) {
177
200
  colour(node.key, branches[i % branches.length], 0);
178
201
  });
179
202
  const drafts = graph.nodes.map(
180
- ({ key, id, title, markdown, unresolved, position, destination }) => ({
203
+ ({
181
204
  key,
182
205
  id,
183
206
  title,
184
207
  markdown,
185
208
  unresolved,
186
209
  position,
210
+ destination,
211
+ style
212
+ }) => ({
213
+ key,
214
+ id,
215
+ title,
216
+ markdown,
217
+ unresolved,
218
+ position,
219
+ style,
220
+ baseRadius: baseRadius(style),
187
221
  ...destination ? { destination } : {},
188
222
  branch: colours.get(key) ?? "blue"
189
223
  })
190
224
  );
191
- const edges = graph.edges.map(({ key, from, to, kind, type }) => ({
192
- key,
193
- from,
194
- to,
195
- kind,
196
- ...type !== void 0 ? { type } : {}
197
- }));
225
+ const edges = graph.edges.map(
226
+ ({ key, from, to, kind, type, presentation }) => ({
227
+ key,
228
+ from,
229
+ to,
230
+ kind,
231
+ ...type !== void 0 ? { type } : {},
232
+ ...presentation ? { presentation } : {}
233
+ })
234
+ );
198
235
  if (previous && layoutKey(previous.semantic) === layoutKey(graph)) {
199
236
  const points = new Map(
200
237
  previous.layout.nodes.map((node) => [node.key, node])
201
238
  );
202
239
  return {
203
- nodes: drafts.map(({ position: _position, ...node }) => ({
240
+ nodes: drafts.map((node) => ({
204
241
  ...node,
205
242
  x: points.get(node.key)?.x ?? 0,
206
243
  y: points.get(node.key)?.y ?? 0
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.2.1",
2
+ "version": "0.4.0",
3
3
  "type": "module",
4
4
  "license": "MIT",
5
5
  "files": [
@@ -33,31 +33,31 @@
33
33
  "./viewer.css": "./dist/ViewerHost.css"
34
34
  },
35
35
  "dependencies": {
36
- "@lensmap/astro-loader": "0.2.1",
37
- "@lensmap/document": "0.2.1",
38
- "react-markdown": "10.1.0",
36
+ "@lensmap/astro-loader": "0.4.0",
37
+ "@lensmap/document": "0.4.0",
39
38
  "d3-force": "3.0.1",
40
- "d3-polygon": "3.0.2"
39
+ "d3-polygon": "3.0.2",
40
+ "react-markdown": "10.1.0"
41
41
  },
42
42
  "peerDependencies": {
43
- "astro": "7.4.0",
44
- "@astrojs/starlight": "0.42.6",
45
43
  "@astrojs/react": "6.0.6",
44
+ "@astrojs/starlight": "0.42.6",
45
+ "astro": "7.4.0",
46
46
  "react": "19.3.1",
47
47
  "react-dom": "19.3.1"
48
48
  },
49
49
  "devDependencies": {
50
- "@lensmap/web": "0.0.0",
51
- "astro": "7.4.0",
52
- "@astrojs/starlight": "0.42.6",
53
50
  "@astrojs/react": "6.0.6",
54
- "react": "19.3.1",
55
- "react-dom": "19.3.1",
51
+ "@astrojs/starlight": "0.42.6",
52
+ "@lensmap/web": "0.0.0",
53
+ "@types/node": "24.19.2",
56
54
  "@types/react": "19.3.0",
57
55
  "@types/react-dom": "19.3.0",
56
+ "astro": "7.4.0",
58
57
  "esbuild": "0.28.2",
59
- "typescript": "7.0.2",
60
- "@types/node": "24.19.2"
58
+ "react": "19.3.1",
59
+ "react-dom": "19.3.1",
60
+ "typescript": "7.0.2"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "node build.mjs",