@typeonce/effect-machine-devtools 0.36.0 → 0.38.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.
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <meta name="description" content="Interactive statechart visualization for Effect Machine" />
7
7
  <title>Effect Machine · Statechart</title>
8
- <script type="module" crossorigin src="./assets/index-s8iI2tep.js"></script>
8
+ <script type="module" crossorigin src="./assets/index-De9zZEnz.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="./assets/index-DkC3PbTy.css">
10
10
  </head>
11
11
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typeonce/effect-machine-devtools",
3
- "version": "0.36.0",
3
+ "version": "0.38.0",
4
4
  "description": "Local development tools for Effect Machine",
5
5
  "author": "Sandro Maglione",
6
6
  "repository": {
@@ -27,20 +27,21 @@
27
27
  "./internal/*": null
28
28
  },
29
29
  "dependencies": {
30
- "@effect/platform-browser": "4.0.0-rc.112",
31
- "@effect/platform-node": "4.0.0-rc.112",
30
+ "@effect/platform-browser": "4.0.0-rc.116",
31
+ "@effect/platform-node": "4.0.0-rc.116",
32
+ "@effect/platform-node-shared": "4.0.0-rc.116",
32
33
  "chokidar": "4.0.3",
33
34
  "elkjs": "0.12.0",
34
35
  "typescript": "6.0.3",
35
36
  "vite": "8.1.5",
36
- "@typeonce/effect-machine": "^0.36.0"
37
+ "@typeonce/effect-machine": "^0.38.0"
37
38
  },
38
39
  "peerDependencies": {
39
- "effect": "4.0.0-rc.112"
40
+ "effect": "4.0.0-rc.116"
40
41
  },
41
42
  "devDependencies": {
42
43
  "@types/node": "25.7.0",
43
- "effect": "4.0.0-rc.112",
44
+ "effect": "4.0.0-rc.116",
44
45
  "tsx": "4.21.0"
45
46
  },
46
47
  "files": [
package/src/bin.ts CHANGED
@@ -12,37 +12,37 @@ import * as StaticSite from "./internal/staticSite.js"
12
12
  import * as MachineRegistry from "./MachineRegistry.js"
13
13
  import * as ProjectInspector from "./ProjectInspector.js"
14
14
 
15
- const root = Flag.directory("root", { mustExist: true }).pipe(
15
+ const root = Flag.Directory("root", { mustExist: true }).pipe(
16
16
  Flag.withDescription("Project root to inspect"),
17
17
  Flag.withDefault(process.cwd())
18
18
  )
19
19
 
20
- const include = Flag.string("include").pipe(
20
+ const include = Flag.String("include").pipe(
21
21
  Flag.withDescription("Machine source glob relative to the project root"),
22
22
  Flag.withDefault("**/src/**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}")
23
23
  )
24
24
 
25
- const host = Flag.string("host").pipe(
25
+ const host = Flag.String("host").pipe(
26
26
  Flag.withDescription("Host for the local visualizer"),
27
27
  Flag.withDefault("127.0.0.1")
28
28
  )
29
29
 
30
- const port = Flag.integer("port").pipe(
30
+ const port = Flag.Int("port").pipe(
31
31
  Flag.withDescription("Port for the local visualizer"),
32
32
  Flag.withDefault(5173)
33
33
  )
34
34
 
35
- const open = Flag.boolean("open").pipe(
35
+ const open = Flag.Boolean("open").pipe(
36
36
  Flag.withDescription("Open the visualizer in the default browser"),
37
37
  Flag.withDefault(false)
38
38
  )
39
39
 
40
- const watchPolling = Flag.boolean("watch-polling").pipe(
40
+ const watchPolling = Flag.Boolean("watch-polling").pipe(
41
41
  Flag.withDescription("Use polling instead of native file-system events"),
42
42
  Flag.withDefault(false)
43
43
  )
44
44
 
45
- const outputDirectory = Flag.directory("out-dir").pipe(
45
+ const outputDirectory = Flag.Directory("out-dir").pipe(
46
46
  Flag.withAlias("o"),
47
47
  Flag.withDescription("Directory to write the static website"),
48
48
  Flag.withDefault(".effect-machine/site")
@@ -896,35 +896,52 @@ const shortenTransitionRoute = (
896
896
  return candidate
897
897
  }
898
898
 
899
- const normalizeTerminalDirection = (
900
- edge: ChartEdge,
899
+ // Both repairs use a route oriented away from the endpoint being repaired.
900
+ // An attached opposite endpoint is a constraint, including on two-point routes
901
+ // where replacing the connection would otherwise replace both endpoint steps.
902
+ const normalizeEndpointDirection = (
901
903
  points: ReadonlyArray<ChartPoint>,
902
- nodes: ReadonlyMap<string, LaidOutChartNode>,
903
- allNodes: ReadonlyArray<LaidOutChartNode>
904
+ node: LaidOutChartNode,
905
+ opposite: LaidOutChartNode | undefined,
906
+ obstacles: ReadonlyArray<ChartRect>
904
907
  ): ReadonlyArray<ChartPoint> => {
905
- if (edge.target === null || isSelfTransition(edge) || points.length < 2) return points
906
- const target = nodes.get(edge.target)
907
- if (target === undefined) return points
908
- const rawEnd = points.at(-1)!
909
- const side = endpointSide(rawEnd, target)
910
- const end = pointOnNodeBoundary(rawEnd, target, side)
911
- const prefix = points.slice(0, -1)
912
- const previous = prefix.at(-1)!
913
- const attached = compactPoints([...prefix, end])
914
- if (isOutwardStep(end, previous, side)) return attached
915
-
916
- const targetStub = outwardPoint(end, side, 18)
917
- const obstacles = [...routeObstacles(edge, allNodes), routeNodeRect(target)]
918
- return endpointConnections(previous, targetStub, routeNodeRect(target), side)
919
- .filter((connection) =>
920
- !connection.slice(0, -1).some((point) => point.x === end.x && point.y === end.y) &&
921
- routeIsClear([...connection, end], obstacles)
908
+ const rawStart = points[0]!
909
+ const side = endpointStepSide(rawStart, points[1]!, node)
910
+ const start = pointOnNodeBoundary(rawStart, node, side)
911
+ const end = points.at(-1)!
912
+ const previous = points.at(-2)!
913
+ const oppositeSide = opposite === undefined ? undefined : endpointStepSide(end, previous, opposite)
914
+ const preserveOpposite = opposite !== undefined && oppositeSide !== undefined &&
915
+ nodeBoundaryDistance(end, opposite) <= 0.5 && isOutwardStep(end, previous, oppositeSide)
916
+ const validEndpoints = (route: ReadonlyArray<ChartPoint>): boolean =>
917
+ isOutwardStep(route[0]!, route[1]!, side) && chartRouteLength(route.slice(0, 2)) >= 9 &&
918
+ (!preserveOpposite ||
919
+ isOutwardStep(route.at(-1)!, route.at(-2)!, oppositeSide!) && chartRouteLength(route.slice(-2)) >= 9)
920
+
921
+ const tail = points.slice(1)
922
+ const attached = compactPoints([start, ...tail])
923
+ if (attached.length >= 2 && validEndpoints(attached)) return attached
924
+
925
+ if (tail.length === 1 && preserveOpposite) {
926
+ tail.unshift(outwardPoint(end, oppositeSide!, 18))
927
+ }
928
+ const stub = outwardPoint(start, side, 18)
929
+ const endpointObstacles = [
930
+ ...obstacles,
931
+ routeNodeRect(node),
932
+ ...(preserveOpposite ? [routeNodeRect(opposite!)] : [])
933
+ ]
934
+ return endpointConnections(stub, tail[0]!, routeNodeRect(node), side)
935
+ .map((connection) => compactPoints([start, ...connection, ...tail.slice(1)]))
936
+ .filter((route) =>
937
+ route.length >= 2 && validEndpoints(route) &&
938
+ !route.slice(1).some((point) => point.x === start.x && point.y === start.y) &&
939
+ routeIsClear(route, endpointObstacles)
922
940
  )
923
- .map((connection) => compactPoints([...prefix, ...connection.slice(1), end]))
924
941
  .sort((left, right) => chartRouteLength(left) - chartRouteLength(right))[0] ?? attached
925
942
  }
926
943
 
927
- const normalizeSourceDirection = (
944
+ const normalizeTransitionEndpoints = (
928
945
  edge: ChartEdge,
929
946
  points: ReadonlyArray<ChartPoint>,
930
947
  nodes: ReadonlyMap<string, LaidOutChartNode>,
@@ -932,21 +949,14 @@ const normalizeSourceDirection = (
932
949
  ): ReadonlyArray<ChartPoint> => {
933
950
  if (isSelfTransition(edge) || points.length < 2) return points
934
951
  const source = nodes.get(edge.source)
935
- if (source === undefined || source.node.children.length > 0) return points
936
- const rawStart = points[0]!
937
- const side = endpointSide(rawStart, source)
938
- const start = pointOnNodeBoundary(rawStart, source, side)
939
- const tail = points.slice(1)
940
- const next = tail[0]!
941
- const attached = compactPoints([start, ...tail])
942
- if (isOutwardStep(start, next, side)) return attached
943
-
944
- const sourceStub = outwardPoint(start, side, 18)
945
- const obstacles = [...routeObstacles(edge, allNodes), routeNodeRect(source)]
946
- return endpointConnections(sourceStub, next, routeNodeRect(source), side)
947
- .filter((connection) => routeIsClear([start, ...connection, ...tail.slice(1)], obstacles))
948
- .map((connection) => compactPoints([start, ...connection, ...tail.slice(1)]))
949
- .sort((left, right) => chartRouteLength(left) - chartRouteLength(right))[0] ?? attached
952
+ const target = edge.target === null ? undefined : nodes.get(edge.target)
953
+ const obstacles = routeObstacles(edge, allNodes)
954
+ const fromSource = source === undefined || source.node.children.length > 0
955
+ ? points
956
+ : normalizeEndpointDirection(points, source, target, obstacles)
957
+ return target === undefined
958
+ ? fromSource
959
+ : [...normalizeEndpointDirection([...fromSource].reverse(), target, source, obstacles)].reverse()
950
960
  }
951
961
 
952
962
  const headerDetour = (
@@ -1207,24 +1217,19 @@ const collectLayout = (
1207
1217
  if (elkPoints === undefined) return []
1208
1218
  const chartEdge = chartEdges.get(edge.id)
1209
1219
  if (chartEdge === undefined) return []
1210
- const points = normalizeTerminalDirection(
1220
+ const points = normalizeTransitionEndpoints(
1211
1221
  chartEdge,
1212
- normalizeSourceDirection(
1222
+ avoidCompoundHeaders(
1213
1223
  chartEdge,
1214
- avoidCompoundHeaders(
1224
+ (shortenRoutes ? shortenTransitionRoute : (_edge: ChartEdge, route: ReadonlyArray<ChartPoint>) => route)(
1215
1225
  chartEdge,
1216
- (shortenRoutes ? shortenTransitionRoute : (_edge: ChartEdge, route: ReadonlyArray<ChartPoint>) => route)(
1217
- chartEdge,
1218
- normalizeHierarchyRoute(chartEdge, elkPoints, nodesByPath, nodes, hierarchyLanes),
1219
- nodesByPath,
1220
- nodes,
1221
- directLanes
1222
- ),
1226
+ normalizeHierarchyRoute(chartEdge, elkPoints, nodesByPath, nodes, hierarchyLanes),
1227
+ nodesByPath,
1223
1228
  nodes,
1224
- hierarchyLanes
1229
+ directLanes
1225
1230
  ),
1226
- nodesByPath,
1227
- nodes
1231
+ nodes,
1232
+ hierarchyLanes
1228
1233
  ),
1229
1234
  nodesByPath,
1230
1235
  nodes
@@ -1700,7 +1705,7 @@ export const layoutChartWith = (
1700
1705
  new ChartLayoutError({
1701
1706
  cause: { failures, invalid },
1702
1707
  message:
1703
- `ELK did not produce a safe layout for ${model.machineId} after ${layoutProfiles.length} deterministic attempts: ${detail}`
1708
+ `Chart routing did not produce a safe layout for ${model.machineId} after ${layoutProfiles.length} deterministic attempts: ${detail}`
1704
1709
  })
1705
1710
  )
1706
1711
  }