@5cover/lectern 0.1.0 → 0.2.1
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/README.md +1 -1
- package/dist/cli/index.js +7 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/client/entry.js +119 -0
- package/dist/client/entry.js.map +1 -0
- package/dist/client/graph-CUYNIBIQ.js +407 -0
- package/dist/client/graph-CUYNIBIQ.js.map +1 -0
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/package.json +4 -5
- package/src/cli/build.ts +0 -79
- package/src/cli/dev.ts +0 -58
- package/src/cli/index.ts +0 -126
- package/src/cli/paths.ts +0 -81
- package/src/cli/pdf.ts +0 -70
- package/src/cli/render.ts +0 -40
- package/src/cli/rules.ts +0 -31
- package/src/cli/serve.ts +0 -112
- package/src/client/entry.ts +0 -170
- package/src/client/graph.tsx +0 -207
- package/src/components/Deck.tsx +0 -19
- package/src/components/InfographDiscovery.tsx +0 -51
- package/src/components/layout.tsx +0 -145
- package/src/components/mechanics.tsx +0 -74
- package/src/components/util.ts +0 -12
- package/src/index.ts +0 -37
- package/src/infographDiscovery.ts +0 -188
- package/src/infographDiscoveryView.tsx +0 -202
- package/src/jsx-runtime.ts +0 -4
- package/src/profiles/engie/assets/engie-logo-dark.svg +0 -1
- package/src/profiles/engie/assets/engie-logo-white.svg +0 -6
- package/src/profiles/engie/assets.d.ts +0 -4
- package/src/profiles/engie/atoms.tsx +0 -203
- package/src/profiles/engie/index.ts +0 -44
- package/src/profiles/engie/profile.ts +0 -132
- package/src/profiles/engie/slides.tsx +0 -230
- package/src/profiles/index.ts +0 -30
- package/src/profiles/types.ts +0 -49
- package/src/render/renderDeck.tsx +0 -74
- package/src/render/template.ts +0 -68
- package/src/types.ts +0 -53
- /package/{src → dist}/profiles/engie/engie.css +0 -0
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { BaseKeys, Infograph, InfographNodeKey } from 'infograph'
|
|
2
|
-
import { toDiscoveryPayload, validateDiscoverySeed } from '../infographDiscovery'
|
|
3
|
-
import { InfographDiscoveryDetails } from '../infographDiscoveryView'
|
|
4
|
-
import type { StyleEscapeHatch } from '../types'
|
|
5
|
-
import { cx } from './util'
|
|
6
|
-
|
|
7
|
-
export interface InfographDiscoveryProps<Keys extends BaseKeys = BaseKeys> extends StyleEscapeHatch {
|
|
8
|
-
/** Parsed infograph to browse. The component never modifies it. */
|
|
9
|
-
infograph: Infograph<Keys>
|
|
10
|
-
/** Initial node key. Must identify a node in `infograph`. */
|
|
11
|
-
seed: InfographNodeKey<Keys>
|
|
12
|
-
/** Number of relation rows initially visible in the BFS neighborhood. */
|
|
13
|
-
relationBudget?: number
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Interactive, bounded exploration of an infograph for a presentation annex.
|
|
18
|
-
*
|
|
19
|
-
* The static HTML renders the seed state for PDF export. The browser client
|
|
20
|
-
* enhances it with search and click navigation between nodes and edges.
|
|
21
|
-
*/
|
|
22
|
-
export function InfographDiscovery<Keys extends BaseKeys>({
|
|
23
|
-
infograph,
|
|
24
|
-
seed,
|
|
25
|
-
relationBudget = 16,
|
|
26
|
-
class: cls,
|
|
27
|
-
style,
|
|
28
|
-
}: InfographDiscoveryProps<Keys>) {
|
|
29
|
-
if (!Number.isInteger(relationBudget) || relationBudget < 1)
|
|
30
|
-
throw new Error(`InfographDiscovery relationBudget must be a positive integer, got ${relationBudget}`)
|
|
31
|
-
const payload = toDiscoveryPayload(infograph)
|
|
32
|
-
validateDiscoverySeed(payload, seed)
|
|
33
|
-
const json = JSON.stringify(payload).replace(/</g, '\\u003c')
|
|
34
|
-
const searchId = `lectern-infograph-discovery-${encodeURIComponent(seed)}`
|
|
35
|
-
return (
|
|
36
|
-
<div
|
|
37
|
-
class={cx('lectern-infograph-discovery', cls)}
|
|
38
|
-
style={style}
|
|
39
|
-
data-lectern-infograph-discovery
|
|
40
|
-
data-relation-budget={relationBudget}
|
|
41
|
-
data-discovery-seed={seed}>
|
|
42
|
-
<div class="lectern-infograph-panel lectern-infograph-details-panel">
|
|
43
|
-
<InfographDiscoveryDetails payload={payload} selection={{ type: 'node', key: seed }} searchId={searchId} />
|
|
44
|
-
</div>
|
|
45
|
-
<div class="lectern-infograph-panel lectern-infograph-neighborhood-panel">
|
|
46
|
-
<div class="lectern-infograph-graph" aria-label="Sous-graphe exploré autour de la sélection" />
|
|
47
|
-
</div>
|
|
48
|
-
<script type="application/json" class="lectern-infograph-data" dangerouslySetInnerHTML={{ __html: json }} />
|
|
49
|
-
</div>
|
|
50
|
-
)
|
|
51
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import type { ComponentChildren } from 'preact'
|
|
2
|
-
import type { StyleEscapeHatch } from '../types'
|
|
3
|
-
import { cx, children as toArray } from './util'
|
|
4
|
-
|
|
5
|
-
type Align = 'start' | 'center' | 'end' | 'stretch'
|
|
6
|
-
type Justify = 'start' | 'center' | 'end' | 'between' | 'around'
|
|
7
|
-
|
|
8
|
-
const alignMap: Record<Align, string> = {
|
|
9
|
-
start: 'flex-start',
|
|
10
|
-
center: 'center',
|
|
11
|
-
end: 'flex-end',
|
|
12
|
-
stretch: 'stretch',
|
|
13
|
-
}
|
|
14
|
-
const justifyMap: Record<Justify, string> = {
|
|
15
|
-
start: 'flex-start',
|
|
16
|
-
center: 'center',
|
|
17
|
-
end: 'flex-end',
|
|
18
|
-
between: 'space-between',
|
|
19
|
-
around: 'space-around',
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function mergeStyle(
|
|
23
|
-
base: Record<string, string | number>,
|
|
24
|
-
extra?: StyleEscapeHatch['style']
|
|
25
|
-
): Record<string, string | number> | string {
|
|
26
|
-
if (extra == null) return base
|
|
27
|
-
if (typeof extra === 'string') {
|
|
28
|
-
const b = Object.entries(base)
|
|
29
|
-
.map(([k, v]) => `${k}:${v}`)
|
|
30
|
-
.join(';')
|
|
31
|
-
return `${b};${extra}`
|
|
32
|
-
}
|
|
33
|
-
return { ...base, ...extra }
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Horizontal layout. Each child becomes an equal column unless `ratio` is
|
|
38
|
-
* given (e.g. `[2, 1]` → first column twice as wide). Uses Fluid spacing.
|
|
39
|
-
*/
|
|
40
|
-
export interface ColumnsProps extends StyleEscapeHatch {
|
|
41
|
-
children?: ComponentChildren
|
|
42
|
-
/** Gap between columns (any CSS length). Defaults to a Fluid spacing token. */
|
|
43
|
-
gap?: string
|
|
44
|
-
/** Cross-axis alignment. Defaults to "stretch". */
|
|
45
|
-
align?: Align
|
|
46
|
-
/** Relative widths of the columns. */
|
|
47
|
-
ratio?: number[]
|
|
48
|
-
/** Explicit CSS Grid tracks, for content-sized rather than proportional columns. */
|
|
49
|
-
tracks?: string[]
|
|
50
|
-
/** Occupy the remaining height of a flex slide body. */
|
|
51
|
-
fill?: boolean
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function Columns({
|
|
55
|
-
children,
|
|
56
|
-
gap,
|
|
57
|
-
align = 'stretch',
|
|
58
|
-
ratio,
|
|
59
|
-
tracks,
|
|
60
|
-
fill = false,
|
|
61
|
-
class: cls,
|
|
62
|
-
style,
|
|
63
|
-
}: ColumnsProps) {
|
|
64
|
-
const cols = toArray(children)
|
|
65
|
-
const usesGrid = tracks != null
|
|
66
|
-
const base = {
|
|
67
|
-
display: usesGrid ? 'grid' : 'flex',
|
|
68
|
-
...(usesGrid ? { 'grid-template-columns': tracks.join(' ') } : { 'flex-direction': 'row' }),
|
|
69
|
-
gap: gap ?? 'var(--lectern-gap, 1.5rem)',
|
|
70
|
-
'align-items': alignMap[align],
|
|
71
|
-
...(fill ? { flex: '1 1 0', 'min-height': 0 } : {}),
|
|
72
|
-
}
|
|
73
|
-
return (
|
|
74
|
-
<div class={cx('lectern-columns', fill && 'is-fill', cls)} style={mergeStyle(base, style)}>
|
|
75
|
-
{usesGrid
|
|
76
|
-
? cols
|
|
77
|
-
: cols.map((child, i) => (
|
|
78
|
-
<div
|
|
79
|
-
class="lectern-col"
|
|
80
|
-
style={{
|
|
81
|
-
...(!usesGrid ? { flex: ratio?.[i] ?? 1 } : {}),
|
|
82
|
-
'min-width': 0,
|
|
83
|
-
...(fill ? { display: 'flex', 'min-height': 0 } : {}),
|
|
84
|
-
}}>
|
|
85
|
-
{child}
|
|
86
|
-
</div>
|
|
87
|
-
))}
|
|
88
|
-
</div>
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** Vertical stack with consistent spacing between children. */
|
|
93
|
-
export interface StackProps extends StyleEscapeHatch {
|
|
94
|
-
children?: ComponentChildren
|
|
95
|
-
gap?: string
|
|
96
|
-
align?: Align
|
|
97
|
-
justify?: Justify
|
|
98
|
-
/** Occupy the remaining height of a flex container. */
|
|
99
|
-
fill?: boolean
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function Stack({ children, gap, align, justify, fill = false, class: cls, style }: StackProps) {
|
|
103
|
-
const base: Record<string, string> = {
|
|
104
|
-
display: 'flex',
|
|
105
|
-
'flex-direction': 'column',
|
|
106
|
-
gap: gap ?? 'var(--lectern-gap, 1rem)',
|
|
107
|
-
}
|
|
108
|
-
if (fill) {
|
|
109
|
-
base.flex = '1 1 0'
|
|
110
|
-
base['min-height'] = '0'
|
|
111
|
-
}
|
|
112
|
-
if (align) base['align-items'] = alignMap[align]
|
|
113
|
-
if (justify) base['justify-content'] = justifyMap[justify]
|
|
114
|
-
return (
|
|
115
|
-
<div class={cx('lectern-stack', fill && 'is-fill', cls)} style={mergeStyle(base, style)}>
|
|
116
|
-
{children}
|
|
117
|
-
</div>
|
|
118
|
-
)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/** Simple responsive grid with a fixed number of columns. */
|
|
122
|
-
export interface GridProps extends StyleEscapeHatch {
|
|
123
|
-
children?: ComponentChildren
|
|
124
|
-
/** Number of columns. Defaults to 2. */
|
|
125
|
-
cols?: number
|
|
126
|
-
gap?: string
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function Grid({ children, cols = 2, gap, class: cls, style }: GridProps) {
|
|
130
|
-
const base = {
|
|
131
|
-
display: 'grid',
|
|
132
|
-
'grid-template-columns': `repeat(${cols}, minmax(0, 1fr))`,
|
|
133
|
-
gap: gap ?? 'var(--lectern-gap, 1.5rem)',
|
|
134
|
-
}
|
|
135
|
-
return (
|
|
136
|
-
<div class={cx('lectern-grid', cls)} style={mergeStyle(base, style)}>
|
|
137
|
-
{children}
|
|
138
|
-
</div>
|
|
139
|
-
)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/** Vertical whitespace. */
|
|
143
|
-
export function Spacer({ size = '1rem' }: { size?: string }) {
|
|
144
|
-
return <div class="lectern-spacer" style={{ height: size }} aria-hidden="true" />
|
|
145
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { ComponentChildren } from 'preact'
|
|
2
|
-
import type { StyleEscapeHatch } from '../types'
|
|
3
|
-
import { cx } from './util'
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* Neutral, reveal-mechanics components: structure only. Their look (if any) is
|
|
7
|
-
* supplied by the active profile's CSS via the `lectern-*` classes they emit.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A code block, syntax-highlighted client-side by reveal's highlight plugin.
|
|
12
|
-
* The code is passed as a string child; it is HTML-escaped safely by the
|
|
13
|
-
* renderer, so `<`, `>` and `&` display correctly.
|
|
14
|
-
*/
|
|
15
|
-
export interface CodeProps extends StyleEscapeHatch {
|
|
16
|
-
children: string
|
|
17
|
-
/** Language for highlighting, e.g. "js", "json", "bash". */
|
|
18
|
-
lang?: string
|
|
19
|
-
/** Show line numbers, optionally with a highlight spec like "2-4|6". */
|
|
20
|
-
lineNumbers?: boolean | string
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function Code({ children, lang, lineNumbers, class: cls, style }: CodeProps) {
|
|
24
|
-
const dataLineNumbers = typeof lineNumbers === 'string' ? lineNumbers : lineNumbers ? '' : undefined
|
|
25
|
-
return (
|
|
26
|
-
<pre class={cx('lectern-code', cls)} style={style}>
|
|
27
|
-
<code class={lang ? `language-${lang}` : undefined} data-trim data-line-numbers={dataLineNumbers}>
|
|
28
|
-
{children}
|
|
29
|
-
</code>
|
|
30
|
-
</pre>
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* A Mermaid diagram. The diagram source is passed as a string child and
|
|
36
|
-
* rendered in the browser by the bundled Mermaid runtime (themed by the profile).
|
|
37
|
-
*/
|
|
38
|
-
export function Mermaid({ children, class: cls, style }: { children: string } & StyleEscapeHatch) {
|
|
39
|
-
return (
|
|
40
|
-
<pre class={cx('mermaid', cls)} style={style}>
|
|
41
|
-
{children}
|
|
42
|
-
</pre>
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Speaker notes: hidden on slides, shown in reveal's speaker view (press S). */
|
|
47
|
-
export function Notes({ children }: { children: ComponentChildren }) {
|
|
48
|
-
return <aside class="notes">{children}</aside>
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Wrap content so it appears as a reveal.js fragment (on the next advance). */
|
|
52
|
-
export interface FragmentProps {
|
|
53
|
-
children: ComponentChildren
|
|
54
|
-
/** Fragment animation type, e.g. "fade-in", "highlight-red". */
|
|
55
|
-
type?: string
|
|
56
|
-
/** Explicit ordering index. */
|
|
57
|
-
index?: number
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function Fragment({ children, type, index }: FragmentProps) {
|
|
61
|
-
return (
|
|
62
|
-
<span class={cx('fragment', type)} data-fragment-index={index}>
|
|
63
|
-
{children}
|
|
64
|
-
</span>
|
|
65
|
-
)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Escape hatch: inject raw HTML for one specific slide. You own its
|
|
70
|
-
* correctness and safety. Content is emitted verbatim (not escaped).
|
|
71
|
-
*/
|
|
72
|
-
export function Raw({ html }: { html: string }) {
|
|
73
|
-
return <div class="lectern-raw" dangerouslySetInnerHTML={{ __html: html }} />
|
|
74
|
-
}
|
package/src/components/util.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ComponentChildren } from 'preact'
|
|
2
|
-
import { toChildArray } from 'preact'
|
|
3
|
-
|
|
4
|
-
/** Join truthy class names. */
|
|
5
|
-
export function cx(...parts: Array<string | false | null | undefined>): string {
|
|
6
|
-
return parts.filter(Boolean).join(' ')
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** Normalize children into a flat array (drops null/boolean, keeps text). */
|
|
10
|
-
export function children(nodes: ComponentChildren) {
|
|
11
|
-
return toChildArray(nodes)
|
|
12
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// Core `@5cover/lectern` API — the render engine + neutral, profile-agnostic components.
|
|
2
|
-
// Philosophy-bearing components (slides, styled atoms) live in a profile,
|
|
3
|
-
// e.g. `@5cover/lectern/engie`.
|
|
4
|
-
|
|
5
|
-
export { Deck, isDeck } from './components/Deck'
|
|
6
|
-
|
|
7
|
-
// Neutral layout primitives.
|
|
8
|
-
export { Columns, Stack, Grid, Spacer } from './components/layout'
|
|
9
|
-
export type { ColumnsProps, StackProps, GridProps } from './components/layout'
|
|
10
|
-
export { InfographDiscovery } from './components/InfographDiscovery'
|
|
11
|
-
export type { InfographDiscoveryProps } from './components/InfographDiscovery'
|
|
12
|
-
|
|
13
|
-
// Neutral reveal-mechanics components.
|
|
14
|
-
export { Code, Mermaid, Notes, Fragment, Raw } from './components/mechanics'
|
|
15
|
-
export type { CodeProps, FragmentProps } from './components/mechanics'
|
|
16
|
-
|
|
17
|
-
// Shared class helper (useful when building profile components).
|
|
18
|
-
export { cx } from './components/util'
|
|
19
|
-
|
|
20
|
-
// Renderer (used by the CLI, and available programmatically).
|
|
21
|
-
export { renderDeck, renderToHtml } from './render/renderDeck'
|
|
22
|
-
export type { RenderOptions } from './render/renderDeck'
|
|
23
|
-
|
|
24
|
-
// Types.
|
|
25
|
-
export type {
|
|
26
|
-
Transition,
|
|
27
|
-
ProfileName,
|
|
28
|
-
DeckMeta,
|
|
29
|
-
ResolvedDeckMeta,
|
|
30
|
-
DeckProps,
|
|
31
|
-
Slide as SlideNode,
|
|
32
|
-
StyleEscapeHatch,
|
|
33
|
-
} from './types'
|
|
34
|
-
|
|
35
|
-
// Profiles (house styles: look + reveal config + rules).
|
|
36
|
-
export { DEFAULT_PROFILE, getProfile, profileNames, profiles, resolveProfile } from './profiles'
|
|
37
|
-
export type { Profile, Rule, RuleGroup, RuleSeverity } from './profiles/types'
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import type { BaseKeys, Infograph } from 'infograph'
|
|
2
|
-
|
|
3
|
-
export type DiscoveryClaim = {
|
|
4
|
-
type: string
|
|
5
|
-
content: string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export type DiscoveryReason = {
|
|
9
|
-
is: string
|
|
10
|
-
why: string[]
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type DiscoveryNode = {
|
|
14
|
-
key: string
|
|
15
|
-
kind: string
|
|
16
|
-
id: string
|
|
17
|
-
title: string
|
|
18
|
-
summary?: string
|
|
19
|
-
claim?: DiscoveryClaim[]
|
|
20
|
-
date?: { from: string; to: string }
|
|
21
|
-
importance?: DiscoveryReason
|
|
22
|
-
complexity: DiscoveryReason
|
|
23
|
-
technicality?: DiscoveryReason
|
|
24
|
-
source?: DiscoveryReason[]
|
|
25
|
-
tag?: string[]
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type DiscoveryEdge = {
|
|
29
|
-
key: string
|
|
30
|
-
from: string
|
|
31
|
-
to: string
|
|
32
|
-
verb: string
|
|
33
|
-
complexity: DiscoveryReason
|
|
34
|
-
technicality?: DiscoveryReason
|
|
35
|
-
claim?: DiscoveryClaim[]
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type DiscoveryPayload = {
|
|
39
|
-
nodes: DiscoveryNode[]
|
|
40
|
-
edges: DiscoveryEdge[]
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type DiscoverySelection = { type: 'node'; key: string } | { type: 'edge'; key: string }
|
|
44
|
-
|
|
45
|
-
export type DiscoveryRelation = {
|
|
46
|
-
edge: DiscoveryEdge
|
|
47
|
-
distance: number
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function toDiscoveryPayload<Keys extends BaseKeys>(infograph: Infograph<Keys>): DiscoveryPayload {
|
|
51
|
-
return {
|
|
52
|
-
nodes: [...infograph.nodes].map(([key, node]) => {
|
|
53
|
-
const [kind, id] = key.split(' ', 2)
|
|
54
|
-
return {
|
|
55
|
-
key,
|
|
56
|
-
kind,
|
|
57
|
-
id,
|
|
58
|
-
title: node.title,
|
|
59
|
-
...(node.summary ? { summary: node.summary } : {}),
|
|
60
|
-
...(node.claim ? { claim: node.claim } : {}),
|
|
61
|
-
...(node.date ? { date: { from: dateText(node.date.from), to: dateText(node.date.to) } } : {}),
|
|
62
|
-
...(node.importance ? { importance: node.importance } : {}),
|
|
63
|
-
complexity: node.complexity,
|
|
64
|
-
...(node.technicality ? { technicality: node.technicality } : {}),
|
|
65
|
-
...(node.source ? { source: node.source } : {}),
|
|
66
|
-
...(node.tag ? { tag: node.tag } : {}),
|
|
67
|
-
}
|
|
68
|
-
}),
|
|
69
|
-
edges: infograph.edges.map(edge => ({
|
|
70
|
-
key: `${edge.from} ${edge.verb} ${edge.to}`,
|
|
71
|
-
from: edge.from,
|
|
72
|
-
to: edge.to,
|
|
73
|
-
verb: edge.verb,
|
|
74
|
-
complexity: edge.info.complexity,
|
|
75
|
-
...(edge.info.technicality ? { technicality: edge.info.technicality } : {}),
|
|
76
|
-
...(edge.info.claim ? { claim: edge.info.claim } : {}),
|
|
77
|
-
})),
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function validateDiscoverySeed(payload: DiscoveryPayload, seed: string): void {
|
|
82
|
-
if (!payload.nodes.some(node => node.key === seed)) throw new Error(`InfographDiscovery seed does not exist: ${seed}`)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function selectDiscoveryRelations(
|
|
86
|
-
payload: DiscoveryPayload,
|
|
87
|
-
selection: DiscoverySelection
|
|
88
|
-
): DiscoveryRelation[] {
|
|
89
|
-
const nodeByKey = new Map(payload.nodes.map(node => [node.key, node]))
|
|
90
|
-
const edgeByKey = new Map(payload.edges.map(edge => [edge.key, edge]))
|
|
91
|
-
const selectedEdge = selection.type === 'edge' ? edgeByKey.get(selection.key) : undefined
|
|
92
|
-
const roots = selection.type === 'node' ? [selection.key] : selectedEdge ? [selectedEdge.from, selectedEdge.to] : []
|
|
93
|
-
const incidence = countIncidence(payload)
|
|
94
|
-
const adjacency = new Map<string, DiscoveryEdge[]>()
|
|
95
|
-
for (const edge of payload.edges) {
|
|
96
|
-
add(adjacency, edge.from, edge)
|
|
97
|
-
add(adjacency, edge.to, edge)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const queue = roots.map(key => ({ key, distance: 0 }))
|
|
101
|
-
const nodeDistance = new Map(roots.map(key => [key, 0]))
|
|
102
|
-
const seenEdges = new Set<string>()
|
|
103
|
-
const result: DiscoveryRelation[] = []
|
|
104
|
-
|
|
105
|
-
if (selectedEdge) {
|
|
106
|
-
seenEdges.add(selectedEdge.key)
|
|
107
|
-
result.push({ edge: selectedEdge, distance: 0 })
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
for (let cursor = 0; cursor < queue.length; cursor++) {
|
|
111
|
-
const current = queue[cursor]!
|
|
112
|
-
const edges = [...(adjacency.get(current.key) ?? [])].sort((left, right) =>
|
|
113
|
-
compareEdges(left, right, current.key, nodeByKey, incidence)
|
|
114
|
-
)
|
|
115
|
-
for (const edge of edges) {
|
|
116
|
-
if (seenEdges.has(edge.key)) continue
|
|
117
|
-
seenEdges.add(edge.key)
|
|
118
|
-
const neighbor = edge.from === current.key ? edge.to : edge.from
|
|
119
|
-
const distance = current.distance + 1
|
|
120
|
-
result.push({ edge, distance })
|
|
121
|
-
if (!nodeDistance.has(neighbor)) {
|
|
122
|
-
nodeDistance.set(neighbor, distance)
|
|
123
|
-
queue.push({ key: neighbor, distance })
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return result
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function add<K, V>(map: Map<K, V[]>, key: K, value: V) {
|
|
131
|
-
const values = map.get(key)
|
|
132
|
-
if (values) values.push(value)
|
|
133
|
-
else map.set(key, [value])
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function countIncidence(payload: DiscoveryPayload): Map<string, number> {
|
|
137
|
-
const incidence = new Map(payload.nodes.map(node => [node.key, 0]))
|
|
138
|
-
for (const edge of payload.edges) {
|
|
139
|
-
incidence.set(edge.from, (incidence.get(edge.from) ?? 0) + 1)
|
|
140
|
-
incidence.set(edge.to, (incidence.get(edge.to) ?? 0) + 1)
|
|
141
|
-
}
|
|
142
|
-
return incidence
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function compareEdges(
|
|
146
|
-
left: DiscoveryEdge,
|
|
147
|
-
right: DiscoveryEdge,
|
|
148
|
-
current: string,
|
|
149
|
-
nodes: Map<string, DiscoveryNode>,
|
|
150
|
-
incidence: Map<string, number>
|
|
151
|
-
): number {
|
|
152
|
-
const leftNeighbor = left.from === current ? left.to : left.from
|
|
153
|
-
const rightNeighbor = right.from === current ? right.to : right.from
|
|
154
|
-
const importance =
|
|
155
|
-
importanceRank(nodes.get(rightNeighbor)?.importance?.is) - importanceRank(nodes.get(leftNeighbor)?.importance?.is)
|
|
156
|
-
if (importance !== 0) return importance
|
|
157
|
-
const degree = (incidence.get(rightNeighbor) ?? 0) - (incidence.get(leftNeighbor) ?? 0)
|
|
158
|
-
if (degree !== 0) return degree
|
|
159
|
-
const title = (nodes.get(leftNeighbor)?.title ?? leftNeighbor).localeCompare(
|
|
160
|
-
nodes.get(rightNeighbor)?.title ?? rightNeighbor
|
|
161
|
-
)
|
|
162
|
-
if (title !== 0) return title
|
|
163
|
-
const verb = left.verb.localeCompare(right.verb)
|
|
164
|
-
return verb !== 0 ? verb : left.key.localeCompare(right.key)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function importanceRank(value: string | undefined): number {
|
|
168
|
-
switch (value) {
|
|
169
|
-
case 'central':
|
|
170
|
-
return 4
|
|
171
|
-
case 'major':
|
|
172
|
-
return 3
|
|
173
|
-
case 'useful':
|
|
174
|
-
return 2
|
|
175
|
-
case 'minor':
|
|
176
|
-
return 1
|
|
177
|
-
default:
|
|
178
|
-
return 0
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function dateText(date: Date): string {
|
|
183
|
-
return date.toISOString().slice(0, 10)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export function searchLabel(node: DiscoveryNode): string {
|
|
187
|
-
return `${node.title} · ${node.key}`
|
|
188
|
-
}
|