index.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /**
  2. * `@colbymchenry/codegraph-ui` — the CodeGraph reader as Svelte components.
  3. *
  4. * The same Symbol view, Flow strip and Map that `codegraph ui` serves, behind
  5. * one seam: a {@link GraphAdapter}. The CLI's viewer runs them on
  6. * {@link createHttpAdapter} (the read-only JSON API over loopback); a host that
  7. * already holds the index — CodeGraph Pro, which opens it in-process — installs
  8. * its own adapter and renders the identical components over its own reads.
  9. * Nothing is forked, so the two can never draw different answers from the same
  10. * graph.
  11. *
  12. * ```svelte
  13. * <script>
  14. * import { CodegraphUi, SymbolView, FlowStrip, ArchitectureMap }
  15. * from '@colbymchenry/codegraph-ui';
  16. * import '@colbymchenry/codegraph-ui/theme.css';
  17. * </script>
  18. *
  19. * <CodegraphUi adapter={myAdapter} nav={myNavigation}>
  20. * <SymbolView id={symbolId} line={null} />
  21. * </CodegraphUi>
  22. * ```
  23. *
  24. * Three things a host has to know, all of them in the docs and repeated here
  25. * because they are the ones that bite:
  26. *
  27. * 1. **Import `theme.css` once.** Every component paints from the design
  28. * tokens; without them the screens render as unstyled ink on white. Override
  29. * any variable on a narrower selector.
  30. * 2. **The adapter is module-level, not context.** The pure model modules are
  31. * plain TypeScript and cannot read a component's context, so one page reads
  32. * one project. `<CodegraphUi>` installs it during initialisation.
  33. * 3. **Geometry is not themable.** 34px rail rows, 300/320px rails, the 20px
  34. * code line: the Symbol view measures these against each other to put a
  35. * callee row beside the line that calls it. Colour and type are yours.
  36. */
  37. /* ------------------------------------------------------------ the seams -- */
  38. export { default as CodegraphUi } from './components/CodegraphUi.svelte';
  39. export {
  40. ApiFailure,
  41. createHttpAdapter,
  42. getGraphAdapter,
  43. setGraphAdapter,
  44. } from './lib/adapter';
  45. export type {
  46. DeadCodeRequest,
  47. EntryPointsRequest,
  48. FlowRequest,
  49. GraphAdapter,
  50. HttpAdapterOptions,
  51. LiveHandlers,
  52. MapRequest,
  53. RoutesRequest,
  54. SearchRequest,
  55. SourceRequest,
  56. } from './lib/adapter';
  57. export {
  58. back,
  59. deadHref,
  60. entryHref,
  61. fileHref,
  62. flowHref,
  63. getNavigationDriver,
  64. hashNavigation,
  65. mapHref,
  66. navigate,
  67. setNavigationDriver,
  68. symbolHref,
  69. } from './lib/navigation';
  70. export type {
  71. DeadCodeHrefOptions,
  72. FileHrefOptions,
  73. FlowHrefOptions,
  74. MapHrefOptions,
  75. NavigationDriver,
  76. SymbolHrefOptions,
  77. } from './lib/navigation';
  78. /** The wire vocabulary an adapter answers in. Types only — no runtime. */
  79. export * from './lib/wire';
  80. /* ----------------------------------------------------------- the screens -- */
  81. /** Callers | verbatim source with gutter ports | line-anchored callee rail. */
  82. export { default as SymbolView } from './views/SymbolView.svelte';
  83. /** How one symbol reaches another, one card per hop, opened at the call line. */
  84. export { default as FlowStrip } from './views/FlowView.svelte';
  85. /** The repository at module granularity, layered so dependencies point down. */
  86. export { default as ArchitectureMap } from './views/MapView.svelte';
  87. /** One file: the outline in source order between two dependency rails. */
  88. export { default as FileView } from './views/FileView.svelte';
  89. /** One file's whole source, with gutter ports and intra-file call arcs. */
  90. export { default as FileSourceView } from './views/FileCodeView.svelte';
  91. /** Where a reader starts: routes, files that run something, tests, hubs. */
  92. export { default as EntryPointsView } from './views/EntryView.svelte';
  93. /** Symbols nothing reaches, grouped by file, with every exclusion printed. */
  94. export { default as DeadCodeView } from './views/DeadCodeView.svelte';
  95. /* -------------------------------------------------------- the furniture -- */
  96. /** The path walked, with its arrows and its "read as flow". */
  97. export { default as TrailBar } from './components/TrailBar.svelte';
  98. /** The search box, its keyboard and its results panel — one component. */
  99. export { default as SearchPalette } from './components/SearchPalette.svelte';
  100. /** The results panel alone, for a host that owns the input. */
  101. export { default as PalettePanel } from './components/PalettePanel.svelte';
  102. /** The rows inside the panel, for a host that owns the whole shell. */
  103. export { default as PaletteRows } from './components/PaletteRows.svelte';
  104. /** "This file changed on disk since it was indexed." */
  105. export { default as DriftBanner } from './components/DriftBanner.svelte';
  106. /** The one-letter square that stands for a symbol's kind. */
  107. export { default as KindGlyph } from './components/KindGlyph.svelte';
  108. /** Copy image / download SVG for a Flow strip or a Map layout. */
  109. export { default as ExportButtons } from './components/ExportButtons.svelte';
  110. /** Ancestors up, subtypes down, and the fan an interface call dispatches into. */
  111. export { default as TypeHierarchy } from './components/symbol/TypeHierarchy.svelte';
  112. /* ------------------------------------------------------------- the state -- */
  113. export { trail, resolveTrailNames } from './lib/trail.svelte';
  114. export { encodeTrail, decodeTrail, hopLabel } from './lib/trail-codec';
  115. export type { HopDirection, TrailHop } from './lib/trail-codec';
  116. export { live, liveRefresh, touchesFile } from './lib/live.svelte';
  117. export type { LiveChanged, LiveHello, LiveIndexEvent, LiveIndexRevision } from './lib/live.svelte';
  118. export { project } from './lib/project.svelte';
  119. export { hot, railFocus } from './lib/focus.svelte';
  120. export type { RailSide } from './lib/focus.svelte';
  121. export { palette } from './lib/palette.svelte';
  122. export { toast } from './lib/toast.svelte';
  123. export { walkTo, arrivedFrom, openEntryTarget } from './lib/walk';
  124. export type { WalkTarget } from './lib/walk';
  125. /* ------------------------------------------------------------ the models --
  126. Pure functions: no DOM, no fetch, no state. A host that wants a different
  127. screen over the same answers builds it out of these rather than out of the
  128. payloads, so its arithmetic is the arithmetic the shipped screens use. */
  129. export { decodeLine, plainLine, tokenClass, tokensByLine } from './lib/highlight';
  130. export type { Token, TokenClass, WireHighlight, WireToken } from './lib/highlight';
  131. export {
  132. assignRefs,
  133. basename,
  134. buildCalleeRail,
  135. buildCallerRail,
  136. buildCodeBlock,
  137. buildOutline,
  138. edgeWord,
  139. graphCallLines,
  140. kindPhrase,
  141. lastSegment,
  142. refsByLine,
  143. relationWords,
  144. showsBody,
  145. synthesizedBy,
  146. } from './lib/symbol-model';
  147. export type {
  148. CalleeRailModel,
  149. CalleeRow,
  150. CallerFileGroup,
  151. CallerRailModel,
  152. CallerRow,
  153. CodeBlock,
  154. Connector,
  155. LineRef,
  156. OutlineRow,
  157. SourceWindow,
  158. } from './lib/symbol-model';
  159. export { buildFlowLayout, cardHeight, endCapHeight, endCapText } from './lib/flow-model';
  160. export type {
  161. EndCapSite,
  162. EndCapText,
  163. FlowCardLayout,
  164. FlowEndCapLayout,
  165. FlowLayout,
  166. FlowLinkLayout,
  167. } from './lib/flow-model';
  168. export {
  169. buildHierarchyModel,
  170. connectorPath,
  171. visibleHierarchy,
  172. HIER_FOLD_AT,
  173. HIER_INDENT,
  174. HIER_PORT_X,
  175. HIER_ROW_H,
  176. } from './lib/hierarchy-model';
  177. export type {
  178. HierarchyConnector,
  179. HierarchyModel,
  180. HierarchyRow,
  181. } from './lib/hierarchy-model';
  182. export { buildMapLayout, isEdgeVisible, moduleMetaLabel } from './lib/map-model';
  183. export type {
  184. MapEdgeLayout,
  185. MapLayerLayout,
  186. MapLayout,
  187. MapLayoutOptions,
  188. MapNodeLayout,
  189. } from './lib/map-model';
  190. export { buildFileOutline, buildFileRail, fileMetaLine, fileTitle } from './lib/file-model';
  191. export type { FileRailModel, FileRailRow, OutlineEntryRow } from './lib/file-model';
  192. export {
  193. buildFileArcs,
  194. buildFileCallRows,
  195. buildFileRefs,
  196. documentHeight,
  197. lineCentre,
  198. lineTop,
  199. pageFor,
  200. visibleLines,
  201. } from './lib/filecode-model';
  202. export type { FileArc, FileCallRow, SourcePage } from './lib/filecode-model';
  203. export {
  204. deadCodeHeadline,
  205. deadCodeRowMeta,
  206. deadCodeScale,
  207. emptyMessage as deadCodeEmptyMessage,
  208. exclusionPhrases,
  209. groupMeta as deadCodeGroupMeta,
  210. DEAD_CODE_CAVEAT,
  211. } from './lib/deadcode-model';
  212. export { buildEntryPanel, flowPair, matchEntries } from './lib/entry-model';
  213. export type {
  214. EntryGroup,
  215. EntryPanel,
  216. EntryRow,
  217. EntrySection,
  218. EntryTarget,
  219. } from './lib/entry-model';
  220. export {
  221. buildEntryPalette,
  222. buildSearchPalette,
  223. moveSelection,
  224. parseFlowQuery,
  225. } from './lib/search-model';
  226. export type { FlowQuery, Palette, PaletteItem, PaletteSection } from './lib/search-model';
  227. export { exportFilename, flowSvg, mapSvg } from './lib/export-svg';
  228. export type { ExportOptions, FlowExportOptions, MapExportOptions } from './lib/export-svg';
  229. export { copyPngToClipboard, downloadSvg, svgToPng } from './lib/export-image';
  230. export { kindLetter, kindWord } from './lib/kinds';