@robosystems/core 0.21.7 → 0.22.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 +20 -19
- package/graph-stage/Dust.d.ts +10 -0
- package/graph-stage/Dust.js +28 -0
- package/graph-stage/GraphGalaxies.d.ts +11 -0
- package/graph-stage/GraphGalaxies.js +47 -0
- package/graph-stage/GraphOrb.d.ts +6 -0
- package/graph-stage/GraphOrb.js +94 -0
- package/graph-stage/GraphStage.d.ts +10 -0
- package/graph-stage/GraphStage.js +24 -0
- package/graph-stage/GridFloor.d.ts +10 -0
- package/graph-stage/GridFloor.js +11 -0
- package/graph-stage/NodeGlow.d.ts +6 -0
- package/graph-stage/NodeGlow.js +22 -0
- package/graph-stage/graphGalaxy.d.ts +24 -0
- package/graph-stage/graphGalaxy.js +87 -0
- package/graph-stage/graphStageGl.d.ts +47 -0
- package/graph-stage/graphStageGl.js +389 -0
- package/graph-stage/index.d.ts +7 -0
- package/graph-stage/index.js +7 -0
- package/graph-stage/palette.d.ts +15 -0
- package/graph-stage/palette.js +40 -0
- package/package.json +1 -1
- package/styles/graph-stage.css +360 -0
package/README.md
CHANGED
|
@@ -3,28 +3,29 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@robosystems/core)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
**The shared frontend core of [RoboSystems](https://github.com/RoboFinSystems/robosystems), the open-source knowledge graph for finance.** `@robosystems/core` holds what [robosystems-app](https://github.com/RoboFinSystems/robosystems-app), [roboledger-app](https://github.com/RoboFinSystems/roboledger-app) and [roboinvestor-app](https://github.com/RoboFinSystems/roboinvestor-app) share: sign-in, the platform contexts, task monitoring and the UI component set. It is built for the Next.js App Router (client and server components, Server Actions) and ships as a versioned npm package.
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## What it does
|
|
9
9
|
|
|
10
|
-
- **Authentication
|
|
11
|
-
- **Contexts
|
|
12
|
-
- **Task monitoring
|
|
13
|
-
- **UI components
|
|
14
|
-
- **Docs rendering
|
|
15
|
-
- **
|
|
10
|
+
- **Authentication**: sign-in and sign-up forms, `AuthProvider` and `AuthGuard`, JWT and SSO token handling
|
|
11
|
+
- **Contexts**: graph, entity, organization, service-offering and sidebar state
|
|
12
|
+
- **Task monitoring**: SSE-based monitoring of long-running operations, with a polling fallback
|
|
13
|
+
- **UI components**: layout, chat, forms, settings, API keys, the shared Tailwind theme and the owned UI primitives (`@robosystems/core/ui`)
|
|
14
|
+
- **Docs rendering**: the docs catalog loader (`@robosystems/core/docs/catalog`) and the markdown renderer (`@robosystems/core/docs/DocsMarkdown`), server-side, for each app's `/docs`
|
|
15
|
+
- **Graph stage**: the landing pages' backdrop (`@robosystems/core/graph-stage`), a live clustered graph with dust, sphere orbs, galaxies, a grid floor and the `node-card` / `node-icon` styles, in each app's own colours
|
|
16
|
+
- **Hooks and utilities**: user, limits, toast and media-query hooks, and cookie persistence helpers
|
|
16
17
|
|
|
17
|
-
##
|
|
18
|
+
## Install
|
|
18
19
|
|
|
19
20
|
```bash
|
|
20
21
|
npm install @robosystems/core
|
|
21
22
|
```
|
|
22
23
|
|
|
23
|
-
`react`, `react-dom`, `next`, `react-icons
|
|
24
|
+
Needs Node.js 24 or later. `react`, `react-dom`, `next`, `react-icons` and `@robosystems/client` are peer dependencies the consuming app provides. [CLAUDE.md](CLAUDE.md) covers the app wiring (the Tailwind content scan, vitest inlining), packaging and the release flow.
|
|
24
25
|
|
|
25
26
|
## Usage
|
|
26
27
|
|
|
27
|
-
Import from the root barrel or from subpaths
|
|
28
|
+
Import from the root barrel, or from subpaths that mirror the folder structure:
|
|
28
29
|
|
|
29
30
|
```tsx
|
|
30
31
|
import { AuthProvider, useGraphContext } from '@robosystems/core'
|
|
@@ -34,18 +35,18 @@ import { useToast } from '@robosystems/core/hooks/use-toast'
|
|
|
34
35
|
import { getDocsCatalog } from '@robosystems/core/docs/catalog'
|
|
35
36
|
```
|
|
36
37
|
|
|
37
|
-
##
|
|
38
|
+
## Versioning
|
|
38
39
|
|
|
39
|
-
- [
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
Pre-1.0: the API can change in a minor release, named in the [release notes](https://github.com/RoboFinSystems/robosystems-core/releases). The three apps move to a new version together, with [`@robosystems/report-components`](https://github.com/RoboFinSystems/robosystems-report-components) bumped in the same change.
|
|
41
|
+
|
|
42
|
+
## Documentation
|
|
43
|
+
|
|
44
|
+
- **Technical docs**: [robosystems.ai/docs/technical](https://robosystems.ai/docs/technical). For this package: [Local Development](https://robosystems.ai/docs/technical/local-development) · [Authentication & API Keys](https://robosystems.ai/docs/technical/authentication-and-api-keys)
|
|
45
|
+
- **Related**: [RoboSystems](https://github.com/RoboFinSystems/robosystems) · [robosystems-app](https://github.com/RoboFinSystems/robosystems-app) · [roboledger-app](https://github.com/RoboFinSystems/roboledger-app) · [roboinvestor-app](https://github.com/RoboFinSystems/roboinvestor-app) · [TypeScript client](https://github.com/RoboFinSystems/robosystems-typescript-client)
|
|
42
46
|
|
|
43
47
|
## Support
|
|
44
48
|
|
|
45
|
-
- [Issues](https://github.com/RoboFinSystems/robosystems-core/issues)
|
|
46
|
-
- [Documentation](https://robosystems.ai/docs/technical)
|
|
47
|
-
- [Projects](https://github.com/orgs/RoboFinSystems/projects)
|
|
48
|
-
- [Discussions](https://github.com/orgs/RoboFinSystems/discussions)
|
|
49
|
+
- [Issues](https://github.com/RoboFinSystems/robosystems-core/issues) · [Discussions](https://github.com/orgs/RoboFinSystems/discussions) · [Projects](https://github.com/orgs/RoboFinSystems/projects)
|
|
49
50
|
|
|
50
51
|
## License
|
|
51
52
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dust of the brand film's stage as a section backdrop: faint points drifting
|
|
3
|
+
* slowly upward, in two layers at different speeds. It is two repeating tiles moved by CSS,
|
|
4
|
+
* so it costs no script and carries on below the hero's live graph without a second WebGL
|
|
5
|
+
* canvas. Each tile is a mask over the first brand colour (`--graph-1`), so the dust takes
|
|
6
|
+
* the app's colour. Decorative, and still for a visitor who asks for reduced motion.
|
|
7
|
+
*/
|
|
8
|
+
export declare function Dust({ className }: {
|
|
9
|
+
className?: string;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The dust of the brand film's stage as a section backdrop: faint points drifting
|
|
4
|
+
* slowly upward, in two layers at different speeds. It is two repeating tiles moved by CSS,
|
|
5
|
+
* so it costs no script and carries on below the hero's live graph without a second WebGL
|
|
6
|
+
* canvas. Each tile is a mask over the first brand colour (`--graph-1`), so the dust takes
|
|
7
|
+
* the app's colour. Decorative, and still for a visitor who asks for reduced motion.
|
|
8
|
+
*/
|
|
9
|
+
/** One square tile of seeded points, as a CSS mask image. */
|
|
10
|
+
function tile(seed, size, count) {
|
|
11
|
+
let s = seed;
|
|
12
|
+
const rnd = () => ((s = (s * 16807) % 2147483647), s / 2147483647);
|
|
13
|
+
const dots = Array.from({ length: count }, (_, i) => {
|
|
14
|
+
// every eighth point is large and soft, out of the lens's focus
|
|
15
|
+
const soft = i % 8 === 0;
|
|
16
|
+
const r = soft ? 3 + rnd() * 3 : 0.6 + rnd() * 1.3;
|
|
17
|
+
const o = soft ? 0.05 + rnd() * 0.06 : 0.14 + rnd() * 0.34;
|
|
18
|
+
const [x, y] = [rnd() * size, rnd() * size];
|
|
19
|
+
return `<circle cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="${r.toFixed(1)}" opacity="${o.toFixed(2)}"/>`;
|
|
20
|
+
});
|
|
21
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" fill="#000">${dots.join('')}</svg>`;
|
|
22
|
+
return `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;
|
|
23
|
+
}
|
|
24
|
+
const NEAR = tile(11, 900, 46);
|
|
25
|
+
const FAR = tile(29, 620, 40);
|
|
26
|
+
export function Dust({ className = '' }) {
|
|
27
|
+
return (_jsxs("div", { "aria-hidden": "true", className: `pointer-events-none absolute inset-0 overflow-hidden ${className}`, children: [_jsx("div", { className: "graph-dust graph-dust-far absolute inset-x-0 top-0 h-[calc(100%+620px)] opacity-60", style: { maskImage: FAR, WebkitMaskImage: FAR } }), _jsx("div", { className: "graph-dust graph-dust-near absolute inset-x-0 top-0 h-[calc(100%+900px)]", style: { maskImage: NEAR, WebkitMaskImage: NEAR } })] }));
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge graphs in the distance behind a section: a few galaxies of clustered nodes,
|
|
3
|
+
* different on every visit, each floating and turning slowly. Decorative, drawn only in the
|
|
4
|
+
* browser (the server sends nothing, so nothing random has to match), and still for a
|
|
5
|
+
* visitor who asks for reduced motion.
|
|
6
|
+
*/
|
|
7
|
+
export declare function GraphGalaxies({ count, keepClear, }: {
|
|
8
|
+
count?: number;
|
|
9
|
+
/** A side to leave empty, for a section that has something else there. */
|
|
10
|
+
keepClear?: 'left' | 'right';
|
|
11
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useSyncExternalStore } from 'react';
|
|
4
|
+
import { buildGalaxy, HUB } from './graphGalaxy';
|
|
5
|
+
import { ink } from './palette';
|
|
6
|
+
const subscribeNever = () => () => { };
|
|
7
|
+
const colour = (hue) => (hue === HUB ? '#fff' : ink(hue));
|
|
8
|
+
/** Galaxies scattered toward the edges of a section, smaller ones dimmer, as if further off. */
|
|
9
|
+
function scatter(count, keepClear) {
|
|
10
|
+
const rnd = Math.random;
|
|
11
|
+
const firstLeft = rnd() < 0.5;
|
|
12
|
+
return Array.from({ length: count }, (_, i) => {
|
|
13
|
+
const left = keepClear ? keepClear === 'right' : firstLeft === (i % 2 === 0);
|
|
14
|
+
const size = 260 + rnd() * 400;
|
|
15
|
+
const edge = `${-(size * (0.1 + rnd() * 0.28)).toFixed(0)}px`;
|
|
16
|
+
return {
|
|
17
|
+
galaxy: buildGalaxy(rnd),
|
|
18
|
+
style: {
|
|
19
|
+
width: size,
|
|
20
|
+
height: size,
|
|
21
|
+
top: `${(4 + ((i + rnd()) / count) * 78).toFixed(1)}%`,
|
|
22
|
+
[left ? 'left' : 'right']: edge,
|
|
23
|
+
opacity: 0.42 + ((size - 260) / 400) * 0.45,
|
|
24
|
+
},
|
|
25
|
+
spin: {
|
|
26
|
+
animationDuration: `${(220 + rnd() * 260).toFixed(0)}s`,
|
|
27
|
+
animationDirection: rnd() < 0.5 ? 'normal' : 'reverse',
|
|
28
|
+
},
|
|
29
|
+
float: i % 2 ? 'graph-float-b' : 'graph-float-a',
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Knowledge graphs in the distance behind a section: a few galaxies of clustered nodes,
|
|
35
|
+
* different on every visit, each floating and turning slowly. Decorative, drawn only in the
|
|
36
|
+
* browser (the server sends nothing, so nothing random has to match), and still for a
|
|
37
|
+
* visitor who asks for reduced motion.
|
|
38
|
+
*/
|
|
39
|
+
export function GraphGalaxies({ count = 2, keepClear, }) {
|
|
40
|
+
const inBrowser = useSyncExternalStore(subscribeNever, () => true, () => false);
|
|
41
|
+
const [placed] = useState(() => scatter(count, keepClear));
|
|
42
|
+
if (!inBrowser)
|
|
43
|
+
return null;
|
|
44
|
+
return (_jsx("div", { "aria-hidden": "true", className: "pointer-events-none absolute inset-0 overflow-hidden", children: placed.map(({ galaxy, style, spin, float }, i) => (_jsx("div", { className: `absolute ${float}`, style: style, children: _jsxs("svg", { viewBox: "-1.05 -1.05 2.1 2.1", className: "graph-turn h-full w-full", style: spin, children: [galaxy.links.map(({ a, b, lit, hue }) => (_jsx("line", { x1: galaxy.nodes[a].x, y1: galaxy.nodes[a].y, x2: galaxy.nodes[b].x, y2: galaxy.nodes[b].y, style: { stroke: colour(hue) }, strokeWidth: 0.004, opacity: lit * 0.5 }, `${a}-${b}`))), galaxy.nodes.map(({ x, y, r, lit, hue }, n) => (_jsx("circle", { cx: x, cy: y, r: r, style: { fill: colour(hue) }, opacity: lit }, n))), galaxy.nodes
|
|
45
|
+
.filter(({ hue }) => hue === HUB)
|
|
46
|
+
.map(({ x, y, r, lit }, n) => (_jsx("circle", { cx: x, cy: y, r: r * 2.1, fill: "none", stroke: "#ffffff", strokeWidth: 0.004, opacity: lit * 0.45 }, `ring-${n}`)))] }) }, i))) }));
|
|
47
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function GraphOrb({ side, count, }: {
|
|
2
|
+
/** The edge of the section the balls hang off. */
|
|
3
|
+
side: 'left' | 'right';
|
|
4
|
+
/** How many balls: one large and close, or two or three smaller at different distances. */
|
|
5
|
+
count?: 1 | 2 | 3;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useSyncExternalStore } from 'react';
|
|
4
|
+
import { ink as tint } from './palette';
|
|
5
|
+
/**
|
|
6
|
+
* The brand film's sphere as a section backdrop: balls of linked points, each with a soft
|
|
7
|
+
* glow for its body, hanging off one edge of the section, floating and turning slowly. One
|
|
8
|
+
* alone is large and close; two or three are smaller, and the smaller a ball the dimmer it
|
|
9
|
+
* is, as if further off. Each is a node of the galaxies seen near: a graph inside a node.
|
|
10
|
+
* Sizes, places and angles are drawn at random in the browser, so they differ on every
|
|
11
|
+
* visit. Inline SVG moved by CSS: no canvas. Decorative.
|
|
12
|
+
*/
|
|
13
|
+
const COUNT = 150;
|
|
14
|
+
// The film's sphere: points spread evenly over a ball, each joined to its three nearest.
|
|
15
|
+
const BALL = Array.from({ length: COUNT }, (_, i) => {
|
|
16
|
+
const y = 1 - (i / (COUNT - 1)) * 2;
|
|
17
|
+
const r = Math.sqrt(1 - y * y);
|
|
18
|
+
const a = i * 2.39996;
|
|
19
|
+
return [Math.cos(a) * r, y, Math.sin(a) * r];
|
|
20
|
+
});
|
|
21
|
+
const LINKS = BALL.flatMap((p, i) => BALL.map((q, j) => ({
|
|
22
|
+
j,
|
|
23
|
+
d: Math.hypot(p[0] - q[0], p[1] - q[1], p[2] - q[2]),
|
|
24
|
+
}))
|
|
25
|
+
.sort((m, n) => m.d - n.d)
|
|
26
|
+
.slice(1, 4)
|
|
27
|
+
.filter(({ j }) => i < j)
|
|
28
|
+
.map(({ j }) => [i, j]));
|
|
29
|
+
const lit = (z) => 0.14 + 0.86 * Math.max(0, Math.min(1, z + 0.4));
|
|
30
|
+
/** The ball turned to an angle and flattened onto the page; depth decides brightness. */
|
|
31
|
+
function turned(ay, ax) {
|
|
32
|
+
const [cy, sy, cx, sx] = [
|
|
33
|
+
Math.cos(ay),
|
|
34
|
+
Math.sin(ay),
|
|
35
|
+
Math.cos(ax),
|
|
36
|
+
Math.sin(ax),
|
|
37
|
+
];
|
|
38
|
+
return BALL.map(([x, y, z]) => {
|
|
39
|
+
const [x1, z1] = [x * cy + z * sy, z * cy - x * sy];
|
|
40
|
+
return { x: x1, y: y * cx - z1 * sx, z: y * sx + z1 * cx };
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// each ball's lines in one brand colour's lighter shade, its glow in that colour and the next
|
|
44
|
+
const TINTS = [
|
|
45
|
+
[tint(1), `${tint(0, 0.16)}, ${tint(2, 0.08)}`],
|
|
46
|
+
[tint(3), `${tint(2, 0.18)}, ${tint(4, 0.08)}`],
|
|
47
|
+
[tint(5), `${tint(4, 0.18)}, ${tint(0, 0.07)}`],
|
|
48
|
+
];
|
|
49
|
+
// how large a ball may be, by how many share the section: [smallest, largest] in px
|
|
50
|
+
const SIZES = {
|
|
51
|
+
1: [560, 720],
|
|
52
|
+
2: [300, 580],
|
|
53
|
+
3: [220, 480],
|
|
54
|
+
};
|
|
55
|
+
function scatter(count, side) {
|
|
56
|
+
const rnd = Math.random;
|
|
57
|
+
const [lo, hi] = SIZES[count];
|
|
58
|
+
return Array.from({ length: count }, (_, i) => {
|
|
59
|
+
// 0 = the furthest a ball gets here, 1 = the nearest
|
|
60
|
+
const near = count === 1 ? rnd() : (i + rnd()) / count;
|
|
61
|
+
const size = lo + (hi - lo) * near;
|
|
62
|
+
const [ink, glow] = TINTS[Math.floor(rnd() * TINTS.length)];
|
|
63
|
+
return {
|
|
64
|
+
points: turned(rnd() * Math.PI * 2, (rnd() - 0.5) * 1.2),
|
|
65
|
+
ink,
|
|
66
|
+
glow,
|
|
67
|
+
near,
|
|
68
|
+
// a near ball hangs well off the edge; a far one sits just inside it
|
|
69
|
+
box: {
|
|
70
|
+
width: size,
|
|
71
|
+
height: size,
|
|
72
|
+
[side]: -size * (0.05 + 0.38 * near),
|
|
73
|
+
},
|
|
74
|
+
spin: {
|
|
75
|
+
animationDuration: `${(200 + rnd() * 200).toFixed(0)}s`,
|
|
76
|
+
animationDirection: rnd() < 0.5 ? 'normal' : 'reverse',
|
|
77
|
+
},
|
|
78
|
+
float: i % 2 ? 'graph-float-b' : 'graph-float-a',
|
|
79
|
+
};
|
|
80
|
+
})
|
|
81
|
+
.sort(() => rnd() - 0.5)
|
|
82
|
+
.map((orb, slot) => (Object.assign(Object.assign({}, orb), { box: Object.assign(Object.assign({}, orb.box), { top: `${(6 + ((slot + rnd() * 0.5) / count) * 72).toFixed(1)}%` }) })));
|
|
83
|
+
}
|
|
84
|
+
const subscribeNever = () => () => { };
|
|
85
|
+
const n = (v) => v.toFixed(3);
|
|
86
|
+
export function GraphOrb({ side, count = 1, }) {
|
|
87
|
+
const inBrowser = useSyncExternalStore(subscribeNever, () => true, () => false);
|
|
88
|
+
const [orbs] = useState(() => scatter(count, side));
|
|
89
|
+
if (!inBrowser)
|
|
90
|
+
return null;
|
|
91
|
+
return (_jsx("div", { "aria-hidden": "true", className: "pointer-events-none absolute inset-0 overflow-hidden", children: orbs.map(({ points, ink, glow, box, near, spin, float }, i) => (_jsxs("div", { className: `absolute ${float}`, style: Object.assign(Object.assign({}, box), { opacity: 0.45 + 0.55 * near }), children: [_jsx("div", { className: "absolute inset-0 rounded-full blur-2xl", style: {
|
|
92
|
+
backgroundImage: `radial-gradient(circle at 38% 32%, ${glow} 48%, transparent 70%)`,
|
|
93
|
+
} }), _jsxs("svg", { viewBox: "-1.06 -1.06 2.12 2.12", className: "graph-turn absolute inset-0 h-full w-full opacity-60", style: spin, children: [_jsx("g", { style: { stroke: ink }, strokeWidth: "0.004", children: LINKS.map(([a, b]) => (_jsx("line", { x1: n(points[a].x), y1: n(points[a].y), x2: n(points[b].x), y2: n(points[b].y), opacity: n(lit((points[a].z + points[b].z) / 2) * 0.6) }, `${a}-${b}`))) }), _jsx("g", { fill: "#fff", children: points.map((p, k) => (_jsx("circle", { cx: n(p.x), cy: n(p.y), r: k % 6 === 0 ? 0.02 : 0.012, opacity: n(lit(p.z)) }, k))) })] })] }, i))) }));
|
|
94
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A knowledge graph in the brand film's look, as a live backdrop, in the colours the app
|
|
3
|
+
* sets (see palette.ts). Decorative: it fills its positioned parent, takes no pointer events
|
|
4
|
+
* and is hidden from screen readers.
|
|
5
|
+
*/
|
|
6
|
+
export declare function GraphStage({ besideFrom, className, }: {
|
|
7
|
+
/** The width from which the page sets its words beside the graph (Tailwind's xl). */
|
|
8
|
+
besideFrom?: number;
|
|
9
|
+
className?: string;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { mountGraphStage } from './graphStageGl';
|
|
5
|
+
/**
|
|
6
|
+
* A knowledge graph in the brand film's look, as a live backdrop, in the colours the app
|
|
7
|
+
* sets (see palette.ts). Decorative: it fills its positioned parent, takes no pointer events
|
|
8
|
+
* and is hidden from screen readers.
|
|
9
|
+
*/
|
|
10
|
+
export function GraphStage({ besideFrom = 1280, className = '', }) {
|
|
11
|
+
const canvas = useRef(null);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!canvas.current)
|
|
14
|
+
return;
|
|
15
|
+
try {
|
|
16
|
+
return mountGraphStage(canvas.current, besideFrom);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
// The page stands without the backdrop, but a broken shader should still show up.
|
|
20
|
+
console.error('GraphStage failed to start', err);
|
|
21
|
+
}
|
|
22
|
+
}, [besideFrom]);
|
|
23
|
+
return (_jsx("canvas", { ref: canvas, "aria-hidden": "true", className: `pointer-events-none absolute inset-0 h-full w-full ${className}` }));
|
|
24
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A grid floor running away to a horizon, for the foot of a section. It is one plane tilted
|
|
3
|
+
* in perspective: the horizon sits perspective / tan(tilt) above the section's foot, about
|
|
4
|
+
* 480px here. The lines that run across are drawn thicker, because the tilt thins them and
|
|
5
|
+
* they would vanish. Drawn in the first brand colour (`--graph-1`). Decorative; it fills
|
|
6
|
+
* the width of its positioned parent, which should hide its overflow.
|
|
7
|
+
*/
|
|
8
|
+
export declare function GridFloor({ className }: {
|
|
9
|
+
className?: string;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A grid floor running away to a horizon, for the foot of a section. It is one plane tilted
|
|
4
|
+
* in perspective: the horizon sits perspective / tan(tilt) above the section's foot, about
|
|
5
|
+
* 480px here. The lines that run across are drawn thicker, because the tilt thins them and
|
|
6
|
+
* they would vanish. Drawn in the first brand colour (`--graph-1`). Decorative; it fills
|
|
7
|
+
* the width of its positioned parent, which should hide its overflow.
|
|
8
|
+
*/
|
|
9
|
+
export function GridFloor({ className = '' }) {
|
|
10
|
+
return (_jsx("div", { "aria-hidden": "true", className: `graph-floor pointer-events-none absolute -inset-x-[150%] bottom-0 h-[600%] origin-bottom ${className}` }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lights the cards marked `node-card` under the pointer. Mounted once on a page, it tells
|
|
3
|
+
* whichever card the pointer is over where the pointer is (`--mx`, `--my`), and the
|
|
4
|
+
* `node-card` styles in styles/graph-stage.css draw the glow and the lit edge from that. Renders nothing.
|
|
5
|
+
*/
|
|
6
|
+
export declare function NodeGlow(): any;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Lights the cards marked `node-card` under the pointer. Mounted once on a page, it tells
|
|
5
|
+
* whichever card the pointer is over where the pointer is (`--mx`, `--my`), and the
|
|
6
|
+
* `node-card` styles in styles/graph-stage.css draw the glow and the lit edge from that. Renders nothing.
|
|
7
|
+
*/
|
|
8
|
+
export function NodeGlow() {
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const move = (e) => {
|
|
11
|
+
const card = e.target instanceof Element ? e.target.closest('.node-card') : null;
|
|
12
|
+
if (!(card instanceof HTMLElement))
|
|
13
|
+
return;
|
|
14
|
+
const box = card.getBoundingClientRect();
|
|
15
|
+
card.style.setProperty('--mx', `${e.clientX - box.left}px`);
|
|
16
|
+
card.style.setProperty('--my', `${e.clientY - box.top}px`);
|
|
17
|
+
};
|
|
18
|
+
document.addEventListener('pointermove', move, { passive: true });
|
|
19
|
+
return () => document.removeEventListener('pointermove', move);
|
|
20
|
+
}, []);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One galaxy: a small knowledge graph in clusters, like the hero's, but drawn from whatever
|
|
3
|
+
* random source it is given, so no two are alike. Built in three dimensions, turned to a
|
|
4
|
+
* random angle and flattened onto the page; a node's depth decides how bright it is.
|
|
5
|
+
*/
|
|
6
|
+
export interface Galaxy {
|
|
7
|
+
/** x, y in -1..1, radius, brightness 0..1, and a palette colour (`HUB` for a hub). */
|
|
8
|
+
nodes: Array<{
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
r: number;
|
|
12
|
+
lit: number;
|
|
13
|
+
hue: number;
|
|
14
|
+
}>;
|
|
15
|
+
links: Array<{
|
|
16
|
+
a: number;
|
|
17
|
+
b: number;
|
|
18
|
+
lit: number;
|
|
19
|
+
hue: number;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
/** A hub's colour: not one of the palette's, it is drawn white. */
|
|
23
|
+
export declare const HUB = -1;
|
|
24
|
+
export declare function buildGalaxy(rnd: () => number): Galaxy;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One galaxy: a small knowledge graph in clusters, like the hero's, but drawn from whatever
|
|
3
|
+
* random source it is given, so no two are alike. Built in three dimensions, turned to a
|
|
4
|
+
* random angle and flattened onto the page; a node's depth decides how bright it is.
|
|
5
|
+
*/
|
|
6
|
+
/** A hub's colour: not one of the palette's, it is drawn white. */
|
|
7
|
+
export const HUB = -1;
|
|
8
|
+
// the three brand colours, in two shades each
|
|
9
|
+
const HUES = 6;
|
|
10
|
+
export function buildGalaxy(rnd) {
|
|
11
|
+
const between = (lo, hi) => lo + rnd() * (hi - lo);
|
|
12
|
+
const clusters = Math.round(between(3, 8));
|
|
13
|
+
// the shape it is spread over: anything from a ball to a flat, stretched disc
|
|
14
|
+
const shape = [between(0.6, 1), between(0.35, 1), between(0.25, 0.9)];
|
|
15
|
+
const turn = between(0, Math.PI * 2);
|
|
16
|
+
const pts = [];
|
|
17
|
+
const hue = [];
|
|
18
|
+
const hubs = [];
|
|
19
|
+
const links = [];
|
|
20
|
+
const d2 = (i, j) => pts[i].reduce((sum, v, k) => sum + (v - pts[j][k]) ** 2, 0);
|
|
21
|
+
const nearest = (i, among, n) => among
|
|
22
|
+
.filter((j) => j !== i)
|
|
23
|
+
.sort((p, q) => d2(i, p) - d2(i, q))
|
|
24
|
+
.slice(0, n);
|
|
25
|
+
for (let c = 0; c < clusters; c++) {
|
|
26
|
+
const y = 1 - ((c + 0.5) / clusters) * 2;
|
|
27
|
+
const r = Math.sqrt(1 - y * y);
|
|
28
|
+
const a = c * 2.39996 + turn;
|
|
29
|
+
const centre = [
|
|
30
|
+
Math.cos(a) * r * shape[0],
|
|
31
|
+
y * shape[1],
|
|
32
|
+
Math.sin(a) * r * shape[2],
|
|
33
|
+
];
|
|
34
|
+
const count = Math.round(between(8, 30));
|
|
35
|
+
const spread = between(0.1, 0.24);
|
|
36
|
+
const tint = Math.floor(rnd() * HUES);
|
|
37
|
+
const members = [];
|
|
38
|
+
for (let m = 0; m < count; m++) {
|
|
39
|
+
const off = () => (m === 0 ? 0 : (rnd() + rnd() + rnd() - 1.5) * spread);
|
|
40
|
+
pts.push([centre[0] + off(), centre[1] + off(), centre[2] + off()]);
|
|
41
|
+
hue.push(m === 0 ? HUB : tint);
|
|
42
|
+
members.push(pts.length - 1);
|
|
43
|
+
}
|
|
44
|
+
hubs.push(members[0]);
|
|
45
|
+
members.slice(1).forEach((n) => {
|
|
46
|
+
if (rnd() < 0.62 || members.length < 3)
|
|
47
|
+
links.push([members[0], n]);
|
|
48
|
+
else
|
|
49
|
+
links.push([n, nearest(n, members.slice(1), 1)[0]]);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
hubs.forEach((h) => nearest(h, hubs, 2).forEach((o) => {
|
|
53
|
+
if (!links.some(([p, q]) => p === o && q === h))
|
|
54
|
+
links.push([h, o]);
|
|
55
|
+
}));
|
|
56
|
+
// a random turn about two axes, then fitted inside the unit circle
|
|
57
|
+
const [ay, ax] = [between(0, Math.PI * 2), between(-0.9, 0.9)];
|
|
58
|
+
const turned = pts.map(([x, y, z]) => {
|
|
59
|
+
const [x1, z1] = [
|
|
60
|
+
x * Math.cos(ay) + z * Math.sin(ay),
|
|
61
|
+
z * Math.cos(ay) - x * Math.sin(ay),
|
|
62
|
+
];
|
|
63
|
+
return [
|
|
64
|
+
x1,
|
|
65
|
+
y * Math.cos(ax) - z1 * Math.sin(ax),
|
|
66
|
+
y * Math.sin(ax) + z1 * Math.cos(ax),
|
|
67
|
+
];
|
|
68
|
+
});
|
|
69
|
+
const reach = Math.max(...turned.map(([x, y]) => Math.hypot(x, y)));
|
|
70
|
+
const lit = (z) => 0.3 + 0.7 * Math.max(0, Math.min(1, z / 1.6 + 0.5));
|
|
71
|
+
const nodes = turned.map(([x, y, z], i) => ({
|
|
72
|
+
x: (x / reach) * 0.97,
|
|
73
|
+
y: (y / reach) * 0.97,
|
|
74
|
+
r: hubs.includes(i) ? 0.026 : between(0.007, 0.014),
|
|
75
|
+
lit: lit(z),
|
|
76
|
+
hue: hue[i],
|
|
77
|
+
}));
|
|
78
|
+
return {
|
|
79
|
+
nodes,
|
|
80
|
+
links: links.map(([a, b]) => ({
|
|
81
|
+
a,
|
|
82
|
+
b,
|
|
83
|
+
lit: (nodes[a].lit + nodes[b].lit) / 2,
|
|
84
|
+
hue: hue[a] === HUB ? hue[b] : hue[a],
|
|
85
|
+
})),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A knowledge graph drawn live, in the look of the brand film: nodes scattered in space come
|
|
3
|
+
* home to clusters around their hubs, drift a little, and turn slowly over a field of dust,
|
|
4
|
+
* while a pulse of light travels each link between hubs. Decoration: the clusters stand for
|
|
5
|
+
* nothing in particular. Plain WebGL with no library, so the landing page pays for a few
|
|
6
|
+
* hundred lines rather than a 3D engine. The lens and the dust are the film stage's own.
|
|
7
|
+
*/
|
|
8
|
+
import { type Rgb } from './palette';
|
|
9
|
+
export declare const RADIUS = 3.4;
|
|
10
|
+
export interface Graph {
|
|
11
|
+
dust: Float32Array;
|
|
12
|
+
dustSize: Float32Array;
|
|
13
|
+
scatter: Float32Array;
|
|
14
|
+
home: Float32Array;
|
|
15
|
+
size: Float32Array;
|
|
16
|
+
/** One colour per node. */
|
|
17
|
+
color: Float32Array;
|
|
18
|
+
/** How far each node drifts about its place. */
|
|
19
|
+
drift: Float32Array;
|
|
20
|
+
/** Index pairs: the relationships drawn between nodes. */
|
|
21
|
+
pairs: number[];
|
|
22
|
+
/** Index pairs, hub to hub, that a pulse of light travels along. */
|
|
23
|
+
routes: number[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Seeded, so every visitor and every screenshot gets the same picture. The palette colours
|
|
27
|
+
* the nodes and takes no part in where they sit.
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildGraph(seed?: number, palette?: Rgb[]): Graph;
|
|
30
|
+
/**
|
|
31
|
+
* Where the graph sits: right of the words when they are set beside it, above them
|
|
32
|
+
* otherwise. Beside them its centre is a fixed distance from the top, level with the words,
|
|
33
|
+
* so a tall window does not drop it toward the section below.
|
|
34
|
+
*/
|
|
35
|
+
export declare function placeGraph(aspect: number, beside: boolean, height: number): {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
scale: number;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Draws the stage on `canvas` until the returned function is called. It runs only while the
|
|
42
|
+
* canvas is on screen, and holds one settled frame for a visitor who asks for reduced
|
|
43
|
+
* motion. Where WebGL is unavailable it draws nothing: the page stands without it.
|
|
44
|
+
*/
|
|
45
|
+
export declare function mountGraphStage(canvas: HTMLCanvasElement,
|
|
46
|
+
/** The CSS width from which the page sets its words beside the graph. */
|
|
47
|
+
besideFrom: number): () => void;
|