Repository navigation
Expand file tree
/
Copy pathModuleNode.svelte
More file actions
177 lines (170 loc) · 5.24 KB
/
Copy pathModuleNode.svelte
File metadata and controls
177 lines (170 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<script lang="ts">
/**
* One module box on the Map (design spec §3.6): a 40px rectangle carrying
* the module's path and what is inside it.
*
* The handles are the point of the component. Svelte Flow routes an edge
* between two handles, so giving each box one hidden handle per link — laid
* out along its top and bottom edges at `(i+1)/(n+1)` — is what makes a
* bundle of eight dependencies fan across the box instead of converging on a
* single corner. They are invisible and non-connectable: this canvas is a
* drawing, never an editor.
*/
import { Handle, Position, type NodeProps } from '@xyflow/svelte';
import { moduleMetaLabel, type MapNodeLayout } from '../../lib/map-model';
let { data }: NodeProps = $props();
const node = $derived(
data as unknown as {
layout: MapNodeLayout;
selected: boolean;
dimmed: boolean;
onSelect: (id: string) => void;
}
);
const layout = $derived(node.layout);
const module = $derived(layout.module);
function portStyle(index: number, total: number): string {
return `left:${((index + 1) / (total + 1)) * 100}%`;
}
</script>
{#each layout.targetHandles as handle, i (handle)}
<Handle
type="target"
id={`t:${handle}`}
position={Position.Top}
style={portStyle(i, layout.targetHandles.length)}
isConnectable={false}
/>
{/each}
<button
class="mnode"
class:sel={node.selected}
class:dimmed={node.dimmed}
class:test={module.test}
class:gen={layout.generated}
style={`width:${layout.width}px;height:${layout.height}px`}
onclick={() => node.onSelect(layout.id)}
aria-pressed={node.selected}
title={`${module.id} — ${module.symbols} symbols in ${module.files} file${
module.files === 1 ? '' : 's'
}${
(module.dependents?.files ?? 0) > 0
? `. ${module.dependents.files} file${module.dependents.files === 1 ? '' : 's'} outside it, across ${module.dependents.modules} module${module.dependents.modules === 1 ? '' : 's'}, reference into it.`
: ''
}${layout.island ? '. Nothing in the index depends on it.' : ''}${
layout.generated ? '. Every file in it is tool-generated.' : ''
}`}
>
<!-- The label elides a folder chain nothing forks in; the title keeps the full path. -->
<span class="name">{module.label || module.id}</span>
<!-- The same string nodeWidth() sized the box for; they must not drift. -->
<span class="count" class:island={layout.island}
>{moduleMetaLabel(module, layout.island)}</span
>
<!-- How much leans on this box, as a share of the heaviest one drawn. Inside
the border rather than on it, so it reads as a level in the box and not
as a second, thicker edge. -->
{#if layout.weight > 0}
<span class="weight" style={`width:${(layout.weight * 100).toFixed(1)}%`}></span>
{/if}
</button>
{#each layout.sourceHandles as handle, i (handle)}
<Handle
type="source"
id={`s:${handle}`}
position={Position.Bottom}
style={portStyle(i, layout.sourceHandles.length)}
isConnectable={false}
/>
{/each}
<style>
.mnode {
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
gap: 1px;
box-sizing: border-box;
padding: 0 9px;
border: 1px solid var(--ink);
border-radius: 0;
background: var(--paper);
text-align: left;
cursor: pointer;
font: inherit;
color: var(--ink);
transition: background 90ms linear;
}
.mnode:hover,
.mnode.sel {
border-width: 2px;
padding: 0 8px;
background: var(--press);
}
.mnode.dimmed {
border-color: var(--ink-4);
color: var(--ink-4);
}
.mnode.dimmed .count {
color: var(--ink-4);
}
/* Nothing depends on it — the stroke stays normal (it is not a lesser module,
it is an unreached one); only the count line changes what it says. */
.count.island {
color: var(--ink-2);
}
/* Generated code: nobody wrote it by hand and nobody deletes it by hand. */
.mnode.gen {
color: var(--ink-4);
border-color: var(--rule-soft);
}
.mnode.gen .count {
color: var(--ink-4);
}
/* Test modules read as scaffolding, not as part of the program. */
.mnode.test {
border-style: dashed;
border-color: var(--ink-3);
}
.mnode:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 1px;
}
/* A wash, not a rule: it is a quantity the eye should compare across boxes at
a glance, never a line competing with the box's own border. */
.weight {
position: absolute;
left: 0;
bottom: 0;
height: 4px;
background: var(--ink);
/* Dark enough to survive the fit: the map opens as far out as 0.45, where a
3px band at 0.18 was a rumour. Length is what carries the comparison, and
length cannot be read off a stroke the eye has to hunt for. */
opacity: 0.3;
pointer-events: none;
}
.mnode:hover .weight,
.mnode.sel .weight {
opacity: 0.55;
}
.mnode.dimmed .weight,
.mnode.gen .weight {
opacity: 0.1;
}
.name {
font: 500 13px var(--mono);
line-height: 15px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.count {
font: 400 11px var(--sans);
line-height: 13px;
color: var(--ink-3);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>