@git-stunts/git-cas 5.3.2 → 6.0.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/ADVANCED_GUIDE.md +1027 -0
- package/ARCHITECTURE.md +514 -0
- package/CHANGELOG.md +449 -5
- package/CODE_OF_CONDUCT.md +33 -0
- package/GUIDE.md +926 -0
- package/README.md +106 -366
- package/SECURITY.md +993 -0
- package/SUPPORT.md +54 -0
- package/UPGRADING.md +299 -0
- package/bin/actions.js +70 -21
- package/bin/agent/cli.js +51 -0
- package/bin/agent/commands/doctor.js +99 -0
- package/bin/agent/commands/index.js +1489 -0
- package/bin/agent/input.js +619 -0
- package/bin/agent/passphrase-source.js +123 -0
- package/bin/agent/protocol.js +193 -0
- package/bin/build-version.js +64 -0
- package/bin/credentials.js +425 -0
- package/bin/git-cas.js +595 -449
- package/bin/passphrase-source.js +266 -0
- package/bin/restore-output-target.js +28 -0
- package/bin/ui/blocks/asset-card.js +109 -0
- package/bin/ui/blocks/health-dashboard.js +149 -0
- package/bin/ui/blocks/heatmap-block.js +67 -0
- package/bin/ui/blocks/merkle-explorer.js +163 -0
- package/bin/ui/blocks/operation-feed.js +176 -0
- package/bin/ui/blocks/wizard-block.js +168 -0
- package/bin/ui/components/short-sha.js +36 -0
- package/bin/ui/context.js +56 -1
- package/bin/ui/dashboard-cmds.js +1578 -13
- package/bin/ui/dashboard-view.js +612 -145
- package/bin/ui/dashboard.js +1255 -212
- package/bin/ui/encryption-card.js +69 -26
- package/bin/ui/heatmap.js +26 -54
- package/bin/ui/history-timeline.js +51 -19
- package/bin/ui/manifest-view.js +115 -60
- package/bin/ui/merkle-dag.js +83 -0
- package/bin/ui/progress.js +15 -9
- package/bin/ui/repo-treemap.js +328 -0
- package/bin/ui/shaders/bak-sneppen.js +180 -0
- package/bin/ui/shaders/fractal-zoom.js +99 -0
- package/bin/ui/shaders/merkle-tree.js +142 -0
- package/bin/ui/shaders/organic-flow.js +96 -0
- package/bin/ui/shaders/phase-portrait.js +93 -0
- package/bin/ui/store-wizard.js +367 -0
- package/bin/ui/theme.js +155 -0
- package/bin/ui/vault-report.js +495 -0
- package/build-info.json +4 -0
- package/docs/API.md +2254 -0
- package/docs/ENCRYPTION_MODES.md +33 -0
- package/docs/EXTENDING.md +174 -0
- package/docs/STORE_RESTORE_PIPELINE.md +199 -0
- package/docs/THREAT_MODEL.md +269 -0
- package/docs/VAULT_INTERNALS.md +251 -0
- package/docs/WALKTHROUGH.md +1868 -0
- package/docs/demo.gif +0 -0
- package/docs/releases/v6.0.0.md +104 -0
- package/examples/README.md +260 -0
- package/index.d.ts +273 -80
- package/index.js +220 -59
- package/package.json +35 -6
- package/scripts/migrate-encryption.js +680 -0
- package/src/domain/bytes/ByteLayout.js +96 -0
- package/src/domain/encoding/base64.js +91 -0
- package/src/domain/encoding/hex.js +14 -0
- package/src/domain/encoding/utf8.js +123 -0
- package/src/domain/encryption/schemes.js +132 -0
- package/src/domain/errors/CannotRemoveLastRecipientError.js +10 -0
- package/src/domain/errors/CasError.d.ts +28 -0
- package/src/domain/errors/CasError.js +43 -6
- package/src/domain/errors/Codes.js +54 -0
- package/src/domain/errors/DekUnwrapFailedError.js +10 -0
- package/src/domain/errors/GitError.js +10 -0
- package/src/domain/errors/GitPlumbingInitializationError.js +10 -0
- package/src/domain/errors/IntegrityError.js +10 -0
- package/src/domain/errors/InvalidChunkingStrategyError.js +10 -0
- package/src/domain/errors/InvalidOidError.js +10 -0
- package/src/domain/errors/InvalidOptionsError.js +10 -0
- package/src/domain/errors/ManifestIntegrityError.js +10 -0
- package/src/domain/errors/ManifestNotFoundError.js +10 -0
- package/src/domain/errors/NoMatchingRecipientError.js +10 -0
- package/src/domain/errors/PersistenceCapabilityRequiredError.js +10 -0
- package/src/domain/errors/PortNotImplementedError.js +10 -0
- package/src/domain/errors/RecipientAlreadyExistsError.js +10 -0
- package/src/domain/errors/RecipientNotFoundError.js +10 -0
- package/src/domain/errors/RestoreTooLargeError.js +10 -0
- package/src/domain/errors/RotationNotSupportedError.js +10 -0
- package/src/domain/errors/createCasError.js +68 -0
- package/src/domain/errors/index.js +20 -0
- package/src/domain/helpers/buildKdfMetadata.js +4 -2
- package/src/domain/helpers/codecBytes.js +34 -0
- package/src/domain/helpers/gitRefErrors.js +84 -0
- package/src/domain/helpers/scryptMaxmem.js +22 -0
- package/src/domain/outcomes/RestoreFailure.js +15 -0
- package/src/domain/outcomes/RestoreOutcome.js +11 -0
- package/src/domain/outcomes/RestoreSuccess.js +34 -0
- package/src/domain/outcomes/StoreFailure.js +15 -0
- package/src/domain/outcomes/StoreOutcome.js +11 -0
- package/src/domain/outcomes/StoreSuccess.js +17 -0
- package/src/domain/schemas/ManifestSchema.d.ts +40 -9
- package/src/domain/schemas/ManifestSchema.js +67 -13
- package/src/domain/services/CasService.d.ts +153 -53
- package/src/domain/services/CasService.js +322 -837
- package/src/domain/services/ChunkRepository.js +268 -0
- package/src/domain/services/CompressionStreams.js +72 -0
- package/src/domain/services/ConvergentEncryption.js +128 -0
- package/src/domain/services/GitTreeBuilder.js +86 -0
- package/src/domain/services/IntegrityVerifier.js +199 -0
- package/src/domain/services/KeyResolver.js +49 -42
- package/src/domain/services/ManifestDiff.js +56 -0
- package/src/domain/services/ManifestRepository.js +286 -0
- package/src/domain/services/PrefetchWindow.js +48 -0
- package/src/domain/services/RecipientService.js +157 -0
- package/src/domain/services/RedactingObservability.js +169 -0
- package/src/domain/services/RestorePipeline.js +68 -0
- package/src/domain/services/StorePipeline.js +201 -0
- package/src/domain/services/VaultKeyVerifier.js +101 -0
- package/src/domain/services/VaultMetadataCodec.js +206 -0
- package/src/domain/services/VaultMutationRetryPolicy.js +105 -0
- package/src/domain/services/VaultPersistence.js +410 -0
- package/src/domain/services/VaultPrivacyIndex.js +191 -0
- package/src/domain/services/VaultService.js +749 -251
- package/src/domain/services/VaultStateCache.js +225 -0
- package/src/domain/services/VaultTreeCodec.js +121 -0
- package/src/domain/services/rotateVaultPassphrase.js +37 -20
- package/src/domain/strategies/Aad.js +39 -0
- package/src/domain/strategies/FramedRecordCodec.js +204 -0
- package/src/domain/strategies/RestoreCompressed.js +40 -0
- package/src/domain/strategies/RestoreConvergent.js +44 -0
- package/src/domain/strategies/RestoreFramed.js +55 -0
- package/src/domain/strategies/RestorePlain.js +37 -0
- package/src/domain/strategies/RestoreStrategy.js +35 -0
- package/src/domain/strategies/RestoreWhole.js +135 -0
- package/src/domain/strategies/StoreConvergent.js +28 -0
- package/src/domain/strategies/StoreFramed.js +39 -0
- package/src/domain/strategies/StorePlain.js +20 -0
- package/src/domain/strategies/StoreStrategy.js +61 -0
- package/src/domain/strategies/StoreWhole.js +34 -0
- package/src/domain/value-objects/Chunk.js +1 -2
- package/src/domain/value-objects/EncryptionMetadata.js +87 -0
- package/src/domain/value-objects/Manifest.d.ts +40 -4
- package/src/domain/value-objects/Manifest.js +61 -20
- package/src/domain/value-objects/Oid.js +45 -0
- package/src/domain/value-objects/Slug.js +124 -0
- package/src/domain/value-objects/StoreEncryptionConfig.js +114 -0
- package/src/helpers/aesGcmMeta.js +55 -0
- package/src/helpers/canonicalBase64.js +1 -0
- package/src/helpers/kdfPolicy.js +194 -0
- package/src/infrastructure/adapters/BunCryptoAdapter.js +124 -8
- package/src/infrastructure/adapters/FileIOHelper.js +180 -13
- package/src/infrastructure/adapters/GitPersistenceAdapter.js +235 -42
- package/src/infrastructure/adapters/GitPlumbingFactoryAdapter.js +62 -0
- package/src/infrastructure/adapters/GitRefAdapter.js +19 -6
- package/src/infrastructure/adapters/NodeCompressionAdapter.js +64 -0
- package/src/infrastructure/adapters/NodeCryptoAdapter.js +130 -10
- package/src/infrastructure/adapters/WebCryptoAdapter.js +187 -77
- package/src/infrastructure/chunkers/CdcChunker.js +53 -19
- package/src/infrastructure/chunkers/FixedChunker.js +15 -7
- package/src/infrastructure/chunkers/resolveChunker.js +10 -6
- package/src/infrastructure/codecs/CborCodec.js +3 -3
- package/src/infrastructure/codecs/JsonCodec.js +5 -5
- package/src/infrastructure/createGitPlumbing.js +22 -0
- package/src/package-version.js +1 -0
- package/src/ports/ChunkingPort.js +3 -3
- package/src/ports/CodecPort.js +4 -4
- package/src/ports/CompressionPort.js +57 -0
- package/src/ports/CryptoPort.js +138 -50
- package/src/ports/GitPersistencePort.js +32 -2
- package/src/ports/GitPlumbingFactoryPort.js +16 -0
- package/src/ports/GitRefPort.js +1 -1
- package/src/types/ambient.d.ts +10 -5
- package/test/CONVENTIONS.md +94 -0
- package/test/cycles/README.md +13 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mandelbrot fractal zoom shader for the title screen.
|
|
3
|
+
* Optimized via monolithic rasterization for 60fps performance.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const TWILIGHT_STOPS = [
|
|
7
|
+
[228, 207, 212], [120, 130, 180], [50, 40, 80],
|
|
8
|
+
[30, 20, 40], [150, 60, 80], [210, 130, 110], [228, 207, 212]
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
function rgbToHex(r, g, b) {
|
|
12
|
+
return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const PALETTE = new Array(256).fill(0).map((_, i) => twilightHex(i / 255));
|
|
16
|
+
|
|
17
|
+
function twilightHex(t) {
|
|
18
|
+
const nt = Math.max(0, Math.min(1, t));
|
|
19
|
+
const max = TWILIGHT_STOPS.length - 1;
|
|
20
|
+
const scaled = nt * max;
|
|
21
|
+
const idx = Math.floor(scaled);
|
|
22
|
+
if (idx >= max) {return rgbToHex(...TWILIGHT_STOPS[max]);}
|
|
23
|
+
const frac = scaled - idx;
|
|
24
|
+
const c1 = TWILIGHT_STOPS[idx];
|
|
25
|
+
const c2 = TWILIGHT_STOPS[idx + 1];
|
|
26
|
+
return rgbToHex(
|
|
27
|
+
Math.round(c1[0] + (c2[0] - c1[0]) * frac),
|
|
28
|
+
Math.round(c1[1] + (c2[1] - c1[1]) * frac),
|
|
29
|
+
Math.round(c1[2] + (c2[2] - c1[2]) * frac)
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let frameBuffer = new Int16Array(0);
|
|
34
|
+
let bufferW = 0;
|
|
35
|
+
let bufferH = 0;
|
|
36
|
+
let lastSimTime = -1;
|
|
37
|
+
|
|
38
|
+
function rasterizeFractal(time) {
|
|
39
|
+
const period = 20;
|
|
40
|
+
const t = time % period;
|
|
41
|
+
const zoom = Math.pow(10, (t / period) * 7);
|
|
42
|
+
const cx = -0.743643135;
|
|
43
|
+
const cy = 0.131825963;
|
|
44
|
+
const maxIteration = 100 + Math.floor((t / period) * 300);
|
|
45
|
+
const invZoom = 2.5 / zoom;
|
|
46
|
+
const log2 = Math.log(2);
|
|
47
|
+
|
|
48
|
+
for (let py = 0; py < bufferH; py++) {
|
|
49
|
+
const y0 = cy + ((py / (bufferH - 1)) * 2.4 - 1.2) * invZoom;
|
|
50
|
+
for (let px = 0; px < bufferW; px++) {
|
|
51
|
+
const x0 = cx + ((px / (bufferW - 1)) * 2.0 - 1.0) * invZoom;
|
|
52
|
+
|
|
53
|
+
let x = 0; let y = 0; let x2 = 0; let y2 = 0; let iteration = 0;
|
|
54
|
+
while (x2 + y2 <= 4 && iteration < maxIteration) {
|
|
55
|
+
y = 2 * x * y + y0;
|
|
56
|
+
x = x2 - y2 + x0;
|
|
57
|
+
x2 = x * x;
|
|
58
|
+
y2 = y * y;
|
|
59
|
+
iteration++;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (iteration === maxIteration) {
|
|
63
|
+
frameBuffer[py * bufferW + px] = -1;
|
|
64
|
+
} else {
|
|
65
|
+
// Coarse smooth coloring for speed
|
|
66
|
+
const mu = iteration + 1 - Math.log(Math.log(x2 + y2) / 2) / log2;
|
|
67
|
+
frameBuffer[py * bufferW + px] = Math.floor((mu / 50) * 255) % 255;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param {import('@flyingrobots/bijou-tui').ShaderParams} params
|
|
75
|
+
* @returns {import('@flyingrobots/bijou').Cell}
|
|
76
|
+
*/
|
|
77
|
+
export function fractalZoomShader({ u, v, time, uniforms }) {
|
|
78
|
+
const tw = (uniforms?.width ?? 80) * 2;
|
|
79
|
+
const th = (uniforms?.height ?? 24) * 2;
|
|
80
|
+
|
|
81
|
+
if (tw !== bufferW || th !== bufferH) {
|
|
82
|
+
bufferW = tw;
|
|
83
|
+
bufferH = th;
|
|
84
|
+
frameBuffer = new Int16Array(bufferW * bufferH);
|
|
85
|
+
lastSimTime = -1;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (time !== lastSimTime) {
|
|
89
|
+
rasterizeFractal(time);
|
|
90
|
+
lastSimTime = time;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const px = Math.floor(u * (bufferW - 1));
|
|
94
|
+
const py = Math.floor(v * (bufferH - 1));
|
|
95
|
+
const val = frameBuffer[py * bufferW + px];
|
|
96
|
+
|
|
97
|
+
if (val === -1) {return { char: ' ', bg: '#1d252b' };}
|
|
98
|
+
return { char: '█', fg: PALETTE[val], bg: '#1d252b' };
|
|
99
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merkle Tree visualization shader for the title screen.
|
|
3
|
+
* Animates data flowing from leaves to root with glowing hash propagation.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
let frameBuffer = new Int32Array(0);
|
|
7
|
+
let bufferW = 0;
|
|
8
|
+
let bufferH = 0;
|
|
9
|
+
let lastSimTime = -1;
|
|
10
|
+
|
|
11
|
+
const COLORS = {
|
|
12
|
+
BG: 0x1d252b,
|
|
13
|
+
LEAF: 0x07BEB8, // Cyan/Teal
|
|
14
|
+
NODE: 0x120e2e, // Darker
|
|
15
|
+
ROOT: 0xFF8552, // Orange/Brand
|
|
16
|
+
EDGE: 0x3d4b59, // Subdued grey-blue
|
|
17
|
+
GLOW: 0xffffff // White for pulse
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const INT_TO_HEX = {
|
|
21
|
+
[COLORS.BG]: '#1d252b',
|
|
22
|
+
[COLORS.LEAF]: '#07BEB8',
|
|
23
|
+
[COLORS.NODE]: '#120e2e',
|
|
24
|
+
[COLORS.ROOT]: '#FF8552',
|
|
25
|
+
[COLORS.EDGE]: '#3d4b59',
|
|
26
|
+
[COLORS.GLOW]: '#ffffff'
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function setBufferPixel(x, y, color) {
|
|
30
|
+
if (x >= 0 && x < bufferW && y >= 0 && y < bufferH) {
|
|
31
|
+
frameBuffer[y * bufferW + x] = color;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function drawLine({ x0, y0, x1, y1, color }) {
|
|
36
|
+
const dx = Math.abs(x1 - x0);
|
|
37
|
+
const dy = -Math.abs(y1 - y0);
|
|
38
|
+
const sx = x0 < x1 ? 1 : -1;
|
|
39
|
+
const sy = y0 < y1 ? 1 : -1;
|
|
40
|
+
let err = dx + dy;
|
|
41
|
+
let cx = x0;
|
|
42
|
+
let cy = y0;
|
|
43
|
+
while (true) {
|
|
44
|
+
setBufferPixel(cx, cy, color);
|
|
45
|
+
if (cx === x1 && cy === y1) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
const e2 = 2 * err;
|
|
49
|
+
if (e2 >= dy) { err += dy; cx += sx; }
|
|
50
|
+
if (e2 <= dx) { err += dx; cy += sy; }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function drawCircle({ x, y, radius, color }) {
|
|
55
|
+
for (let dy = -radius; dy <= radius; dy++) {
|
|
56
|
+
for (let dx = -radius; dx <= radius; dx++) {
|
|
57
|
+
if (dx * dx + dy * dy <= radius * radius) {
|
|
58
|
+
setBufferPixel(x + dx, y + dy, color);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function calculateNodes({ depth, treeW, treeH, margin }) {
|
|
65
|
+
const nodes = [];
|
|
66
|
+
for (let d = 0; d <= depth; d++) {
|
|
67
|
+
const levelNodes = Math.pow(2, d);
|
|
68
|
+
const y = margin + (d / depth) * treeH;
|
|
69
|
+
const row = [];
|
|
70
|
+
for (let i = 0; i < levelNodes; i++) {
|
|
71
|
+
const x = margin + ((i + 0.5) / levelNodes) * treeW;
|
|
72
|
+
row.push({ x: Math.floor(x), y: Math.floor(y), level: d });
|
|
73
|
+
}
|
|
74
|
+
nodes.push(row);
|
|
75
|
+
}
|
|
76
|
+
return nodes;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function drawTreeEdges(nodes, depth, pulseLevel) {
|
|
80
|
+
for (let d = depth; d > 0; d--) {
|
|
81
|
+
for (let i = 0; i < nodes[d].length; i++) {
|
|
82
|
+
const child = nodes[d][i];
|
|
83
|
+
const parent = nodes[d - 1][Math.floor(i / 2)];
|
|
84
|
+
const isPulse = Math.abs(d - 1 - (depth - pulseLevel)) < 0.5;
|
|
85
|
+
drawLine({ x0: child.x, y0: child.y, x1: parent.x, y1: parent.y, color: isPulse ? COLORS.LEAF : COLORS.EDGE });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function drawTreeNodes(nodes, depth, pulseLevel) {
|
|
91
|
+
for (let d = 0; d <= depth; d++) {
|
|
92
|
+
const isPulse = Math.abs(d - (depth - pulseLevel)) < 0.5;
|
|
93
|
+
for (const node of nodes[d]) {
|
|
94
|
+
let color = COLORS.NODE;
|
|
95
|
+
if (d === 0) { color = COLORS.ROOT; }
|
|
96
|
+
else if (d === depth) { color = COLORS.LEAF; }
|
|
97
|
+
if (isPulse) { color = COLORS.GLOW; }
|
|
98
|
+
drawCircle({ x: node.x, y: node.y, radius: d === 0 ? 3 : 2, color });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function rasterizeTree(time, entryCount) {
|
|
104
|
+
frameBuffer.fill(COLORS.BG);
|
|
105
|
+
const count = Math.max(8, Math.min(32, entryCount));
|
|
106
|
+
const depth = Math.ceil(Math.log2(count));
|
|
107
|
+
const margin = 10;
|
|
108
|
+
const treeW = bufferW - (margin * 2);
|
|
109
|
+
const treeH = bufferH - (margin * 2);
|
|
110
|
+
const pulseLevel = (time * 2) % (depth + 1);
|
|
111
|
+
|
|
112
|
+
const nodes = calculateNodes({ depth, treeW, treeH, margin });
|
|
113
|
+
drawTreeEdges(nodes, depth, pulseLevel);
|
|
114
|
+
drawTreeNodes(nodes, depth, pulseLevel);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function updateFrameBuffer({ time, entryCount, tw, th }) {
|
|
118
|
+
if (tw !== bufferW || th !== bufferH) {
|
|
119
|
+
bufferW = tw;
|
|
120
|
+
bufferH = th;
|
|
121
|
+
frameBuffer = new Int32Array(bufferW * bufferH);
|
|
122
|
+
lastSimTime = -1;
|
|
123
|
+
}
|
|
124
|
+
if (time !== lastSimTime) {
|
|
125
|
+
rasterizeTree(time, entryCount);
|
|
126
|
+
lastSimTime = time;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function merkleTreeShader({ u, v, time, uniforms }) {
|
|
131
|
+
const tw = (uniforms?.width ?? 80) * 2;
|
|
132
|
+
const th = (uniforms?.height ?? 24) * 2;
|
|
133
|
+
updateFrameBuffer({ time, entryCount: uniforms?.entryCount ?? 120, tw, th });
|
|
134
|
+
const px = Math.floor(u * (bufferW - 1));
|
|
135
|
+
const py = Math.floor(v * (bufferH - 1));
|
|
136
|
+
const colorInt = frameBuffer[py * bufferW + px];
|
|
137
|
+
return {
|
|
138
|
+
char: colorInt === COLORS.BG ? ' ' : '█',
|
|
139
|
+
fg: INT_TO_HEX[colorInt] || '#1d252b',
|
|
140
|
+
bg: '#1d252b'
|
|
141
|
+
};
|
|
142
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Organic Flow shader for the title screen.
|
|
3
|
+
* Recreates the dense Braille aesthetic of background.txt with liquid animation.
|
|
4
|
+
* Uses Braille resolution (2x4 sub-pixels per cell).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { GIT_CAS_PALETTE } from '../theme.js';
|
|
8
|
+
|
|
9
|
+
let frameBuffer = new Int16Array(0);
|
|
10
|
+
let bufferW = 0;
|
|
11
|
+
let bufferH = 0;
|
|
12
|
+
let lastSimTime = -1;
|
|
13
|
+
|
|
14
|
+
const COLOR_STOPS = [
|
|
15
|
+
GIT_CAS_PALETTE.cyan,
|
|
16
|
+
GIT_CAS_PALETTE.sky,
|
|
17
|
+
GIT_CAS_PALETTE.violet,
|
|
18
|
+
GIT_CAS_PALETTE.orange,
|
|
19
|
+
GIT_CAS_PALETTE.ruby,
|
|
20
|
+
GIT_CAS_PALETTE.ghost,
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const FLOW_PALETTE = Array.from({ length: 192 }, (_, index) =>
|
|
24
|
+
interpolateColor(index / 191));
|
|
25
|
+
|
|
26
|
+
function rgbToHex(rgb) {
|
|
27
|
+
return `#${rgb.map((ch) => ch.toString(16).padStart(2, '0')).join('')}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function interpolateColor(t) {
|
|
31
|
+
const scaled = Math.max(0, Math.min(1, t)) * (COLOR_STOPS.length - 1);
|
|
32
|
+
const index = Math.floor(scaled);
|
|
33
|
+
const next = Math.min(COLOR_STOPS.length - 1, index + 1);
|
|
34
|
+
const mix = scaled - index;
|
|
35
|
+
return rgbToHex(COLOR_STOPS[index].map((ch, offset) =>
|
|
36
|
+
Math.round(ch + (COLOR_STOPS[next][offset] - ch) * mix)));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function setBufferPixel(x, y, state) {
|
|
40
|
+
if (x >= 0 && x < bufferW && y >= 0 && y < bufferH) {
|
|
41
|
+
frameBuffer[y * bufferW + x] = state;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function rasterizeFlow(time) {
|
|
46
|
+
for (let py = 0; py < bufferH; py++) {
|
|
47
|
+
const y = (py / bufferH) * 2.0 - 1.0;
|
|
48
|
+
for (let px = 0; px < bufferW; px++) {
|
|
49
|
+
const x = (px / bufferW) * 3.0 - 1.5;
|
|
50
|
+
|
|
51
|
+
let v = Math.sin(x * 3.0 + time * 0.5);
|
|
52
|
+
v += Math.sin((y * 4.0 + time * 0.7) * 1.5);
|
|
53
|
+
v += Math.sin((x * 2.0 + y * 2.0 + time * 0.3) * 0.8);
|
|
54
|
+
|
|
55
|
+
const cx = x + 0.5 * Math.sin(time * 0.2);
|
|
56
|
+
const cy = y + 0.5 * Math.cos(time * 0.4);
|
|
57
|
+
v += Math.sin(Math.sqrt(100.0 * (cx * cx + cy * cy) + 1.0) + time);
|
|
58
|
+
|
|
59
|
+
const val = (v + 4.0) / 8.0;
|
|
60
|
+
const dither = (Math.sin(px * 12.9898 + py * 78.233) * 43758.5453) % 1.0;
|
|
61
|
+
const colorWave = Math.sin(x * 2.6 - y * 1.9 + time * 0.9)
|
|
62
|
+
+ Math.sin((x + y) * 3.1 + time * 0.35);
|
|
63
|
+
const colorIndex = Math.floor((((colorWave + 2) / 4) ** 0.85) * (FLOW_PALETTE.length - 1));
|
|
64
|
+
|
|
65
|
+
setBufferPixel(px, py, val > (0.41 + dither * 0.12) ? colorIndex : -1);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {import('@flyingrobots/bijou-tui').ShaderParams} params
|
|
72
|
+
* @returns {import('@flyingrobots/bijou').Cell | string}
|
|
73
|
+
*/
|
|
74
|
+
export function organicFlowShader({ u, v, time, uniforms }) {
|
|
75
|
+
// Braille resolution is 2x4 per cell
|
|
76
|
+
const tw = (uniforms?.width ?? 80) * 2;
|
|
77
|
+
const th = (uniforms?.height ?? 24) * 4;
|
|
78
|
+
|
|
79
|
+
if (tw !== bufferW || th !== bufferH) {
|
|
80
|
+
bufferW = tw;
|
|
81
|
+
bufferH = th;
|
|
82
|
+
frameBuffer = new Int16Array(bufferW * bufferH);
|
|
83
|
+
lastSimTime = -1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (time !== lastSimTime) {
|
|
87
|
+
rasterizeFlow(time);
|
|
88
|
+
lastSimTime = time;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const px = Math.floor(u * (bufferW - 1));
|
|
92
|
+
const py = Math.floor(v * (bufferH - 1));
|
|
93
|
+
const colorIndex = frameBuffer[py * bufferW + px];
|
|
94
|
+
|
|
95
|
+
return colorIndex >= 0 ? FLOW_PALETTE[colorIndex] : ' ';
|
|
96
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase portrait shader for the title screen.
|
|
3
|
+
* Adapts the polynomial roots phase visualization to the terminal grid.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const TWILIGHT_STOPS = [
|
|
7
|
+
[228, 207, 212], // Light pinkish-white
|
|
8
|
+
[120, 130, 180], // Slate blue/periwinkle
|
|
9
|
+
[50, 40, 80], // Dark purple
|
|
10
|
+
[30, 20, 40], // Deep midnight/black
|
|
11
|
+
[150, 60, 80], // Deep red/burgundy
|
|
12
|
+
[210, 130, 110], // Warm orange
|
|
13
|
+
[228, 207, 212] // Light pinkish-white
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {number} r
|
|
18
|
+
* @param {number} g
|
|
19
|
+
* @param {number} b
|
|
20
|
+
* @returns {string}
|
|
21
|
+
*/
|
|
22
|
+
function rgbToHex(r, g, b) {
|
|
23
|
+
return `#${ [r, g, b].map(x => {
|
|
24
|
+
const hex = x.toString(16);
|
|
25
|
+
return hex.length === 1 ? `0${ hex}` : hex;
|
|
26
|
+
}).join('')}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Maps a normalized value [0..1] to the twilight colormap.
|
|
31
|
+
* @param {number} t
|
|
32
|
+
* @returns {string} hex color
|
|
33
|
+
*/
|
|
34
|
+
function twilightHex(t) {
|
|
35
|
+
t = Math.max(0, Math.min(1, t));
|
|
36
|
+
const max = TWILIGHT_STOPS.length - 1;
|
|
37
|
+
const scaled = t * max;
|
|
38
|
+
const idx = Math.floor(scaled);
|
|
39
|
+
if (idx >= max) {return rgbToHex(TWILIGHT_STOPS[max][0], TWILIGHT_STOPS[max][1], TWILIGHT_STOPS[max][2]);}
|
|
40
|
+
|
|
41
|
+
const frac = scaled - idx;
|
|
42
|
+
const c1 = TWILIGHT_STOPS[idx];
|
|
43
|
+
const c2 = TWILIGHT_STOPS[idx + 1];
|
|
44
|
+
|
|
45
|
+
const r = Math.round(c1[0] + (c2[0] - c1[0]) * frac);
|
|
46
|
+
const g = Math.round(c1[1] + (c2[1] - c1[1]) * frac);
|
|
47
|
+
const b = Math.round(c1[2] + (c2[2] - c1[2]) * frac);
|
|
48
|
+
return rgbToHex(r, g, b);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {import('@flyingrobots/bijou-tui').ShaderParams} params
|
|
53
|
+
* @returns {import('@flyingrobots/bijou').Cell | string}
|
|
54
|
+
*/
|
|
55
|
+
export function phasePortraitShader({ u, v, time }) {
|
|
56
|
+
// Grid bounds mapping u,v (0..1) to x,y (-1.5..1.5)
|
|
57
|
+
// Adjust aspect ratio since we will be using sub-cell 'quad' resolution (2:2 or roughly 1:1 visually)
|
|
58
|
+
// The 'quad' resolution mode samples at 2x2 per cell, bringing the aspect ratio much closer to 1:1
|
|
59
|
+
// We'll leave the UV multiplier alone, or apply a slight correction if necessary.
|
|
60
|
+
const dx = 1.5;
|
|
61
|
+
const dy = 1.5;
|
|
62
|
+
const zx = (u * 2 - 1) * dx;
|
|
63
|
+
const zy = (v * 2 - 1) * dy;
|
|
64
|
+
|
|
65
|
+
const nRoots = 8;
|
|
66
|
+
let totalAngle = 0;
|
|
67
|
+
|
|
68
|
+
for (let i = 0; i < nRoots; i++) {
|
|
69
|
+
// Generate pseudo-random orbit
|
|
70
|
+
const r = Math.sqrt(((i + 1) * 0.6180339887) % 1.0);
|
|
71
|
+
const th = ((i + 1) * 2.39996) + time * (0.2 + i * 0.05);
|
|
72
|
+
|
|
73
|
+
const rx = r * Math.cos(th);
|
|
74
|
+
const ry = r * Math.sin(th);
|
|
75
|
+
|
|
76
|
+
totalAngle += Math.atan2(zy - ry, zx - rx);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Wrap total angle to 0..2PI
|
|
80
|
+
let ang = (totalAngle + Math.PI) % (2 * Math.PI);
|
|
81
|
+
if (ang < 0) {
|
|
82
|
+
ang += 2 * Math.PI;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Normalize to 0..1 for colormap
|
|
86
|
+
const t = ang / (2 * Math.PI);
|
|
87
|
+
|
|
88
|
+
const hex = twilightHex(t);
|
|
89
|
+
|
|
90
|
+
// Return hex string. When using `canvas` with resolution 'quad', Bijou expects the shader
|
|
91
|
+
// to return a color string which it will downsample into block characters.
|
|
92
|
+
return hex;
|
|
93
|
+
}
|