@gratiaos/presence-kernel 1.1.0
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/LICENSE +243 -0
- package/README.md +166 -0
- package/dist/ConstellationHUD.d.ts +18 -0
- package/dist/ConstellationHUD.d.ts.map +1 -0
- package/dist/ConstellationHUD.js +103 -0
- package/dist/ConstellationHUD.js.map +1 -0
- package/dist/Heartbeat.d.ts +4 -0
- package/dist/Heartbeat.d.ts.map +1 -0
- package/dist/Heartbeat.js +161 -0
- package/dist/Heartbeat.js.map +1 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +140 -0
- package/dist/index.js.map +1 -0
- package/dist/phase-sound-profile.d.ts +9 -0
- package/dist/phase-sound-profile.d.ts.map +1 -0
- package/dist/phase-sound-profile.js +8 -0
- package/dist/phase-sound-profile.js.map +1 -0
- package/dist/useConstellationAudio.d.ts +9 -0
- package/dist/useConstellationAudio.d.ts.map +1 -0
- package/dist/useConstellationAudio.js +16 -0
- package/dist/useConstellationAudio.js.map +1 -0
- package/dist/usePhaseSound.d.ts +2 -0
- package/dist/usePhaseSound.d.ts.map +1 -0
- package/dist/usePhaseSound.js +137 -0
- package/dist/usePhaseSound.js.map +1 -0
- package/dist/usePhaseSpatialSound.d.ts +2 -0
- package/dist/usePhaseSpatialSound.d.ts.map +1 -0
- package/dist/usePhaseSpatialSound.js +206 -0
- package/dist/usePhaseSpatialSound.js.map +1 -0
- package/package.json +56 -0
- package/src/ConstellationHUD.tsx +136 -0
- package/src/Heartbeat.tsx +178 -0
- package/src/constellation-hud.css +101 -0
- package/src/heartbeat.css +75 -0
- package/src/index.ts +177 -0
- package/src/phase-sound-profile.ts +15 -0
- package/src/useConstellationAudio.ts +16 -0
- package/src/usePhaseSound.ts +163 -0
- package/src/usePhaseSpatialSound.ts +237 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { phase$, mood$, peers$, pulse$ } from './index';
|
|
4
|
+
import './heartbeat.css';
|
|
5
|
+
const DEFAULT_COLOR = '#ffffff';
|
|
6
|
+
function resolveColor(color) {
|
|
7
|
+
var _a, _b, _c, _d;
|
|
8
|
+
if (typeof document === 'undefined')
|
|
9
|
+
return [255, 255, 255];
|
|
10
|
+
const element = document.createElement('span');
|
|
11
|
+
element.style.color = color;
|
|
12
|
+
document.body.appendChild(element);
|
|
13
|
+
const computed = getComputedStyle(element).color;
|
|
14
|
+
document.body.removeChild(element);
|
|
15
|
+
const match = (_a = computed.match(/\d+/g)) === null || _a === void 0 ? void 0 : _a.map(Number);
|
|
16
|
+
if (!match || match.length < 3)
|
|
17
|
+
return [255, 255, 255];
|
|
18
|
+
return [(_b = match[0]) !== null && _b !== void 0 ? _b : 255, (_c = match[1]) !== null && _c !== void 0 ? _c : 255, (_d = match[2]) !== null && _d !== void 0 ? _d : 255];
|
|
19
|
+
}
|
|
20
|
+
function rgbToHsl(r, g, b) {
|
|
21
|
+
r /= 255;
|
|
22
|
+
g /= 255;
|
|
23
|
+
b /= 255;
|
|
24
|
+
const max = Math.max(r, g, b);
|
|
25
|
+
const min = Math.min(r, g, b);
|
|
26
|
+
let h = 0;
|
|
27
|
+
let s = 0;
|
|
28
|
+
const l = (max + min) / 2;
|
|
29
|
+
if (max !== min) {
|
|
30
|
+
const d = max - min;
|
|
31
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
32
|
+
switch (max) {
|
|
33
|
+
case r:
|
|
34
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
35
|
+
break;
|
|
36
|
+
case g:
|
|
37
|
+
h = (b - r) / d + 2;
|
|
38
|
+
break;
|
|
39
|
+
default:
|
|
40
|
+
h = (r - g) / d + 4;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
h *= 60;
|
|
44
|
+
}
|
|
45
|
+
return { h, s: s * 100, l: l * 100 };
|
|
46
|
+
}
|
|
47
|
+
function amplitudeForMood(mood) {
|
|
48
|
+
if (mood === 'celebratory')
|
|
49
|
+
return 4;
|
|
50
|
+
if (mood === 'presence')
|
|
51
|
+
return 3;
|
|
52
|
+
if (mood === 'focused')
|
|
53
|
+
return 2.5;
|
|
54
|
+
if (mood === 'soft')
|
|
55
|
+
return 1.8;
|
|
56
|
+
return 1.5;
|
|
57
|
+
}
|
|
58
|
+
export const Heartbeat = () => {
|
|
59
|
+
const [phase, setPhase] = useState(phase$.value);
|
|
60
|
+
const [mood, setMood] = useState(mood$.value);
|
|
61
|
+
const [peerWaves, setPeerWaves] = useState(peers$.value);
|
|
62
|
+
const [pulseActive, setPulseActive] = useState(false);
|
|
63
|
+
const canvasRef = useRef(null);
|
|
64
|
+
const pulseTimeoutRef = useRef(null);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
const stopPhase = phase$.subscribe(setPhase);
|
|
67
|
+
const stopMood = mood$.subscribe(setMood);
|
|
68
|
+
const stopPeers = peers$.subscribe(setPeerWaves);
|
|
69
|
+
return () => {
|
|
70
|
+
stopPhase();
|
|
71
|
+
stopMood();
|
|
72
|
+
stopPeers();
|
|
73
|
+
};
|
|
74
|
+
}, []);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (typeof window === 'undefined')
|
|
77
|
+
return;
|
|
78
|
+
let first = true;
|
|
79
|
+
const stop = pulse$.subscribe(() => {
|
|
80
|
+
if (first) {
|
|
81
|
+
first = false;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
setPulseActive(true);
|
|
85
|
+
if (pulseTimeoutRef.current) {
|
|
86
|
+
window.clearTimeout(pulseTimeoutRef.current);
|
|
87
|
+
}
|
|
88
|
+
pulseTimeoutRef.current = window.setTimeout(() => {
|
|
89
|
+
setPulseActive(false);
|
|
90
|
+
pulseTimeoutRef.current = null;
|
|
91
|
+
}, 520);
|
|
92
|
+
});
|
|
93
|
+
return () => {
|
|
94
|
+
stop();
|
|
95
|
+
if (pulseTimeoutRef.current) {
|
|
96
|
+
window.clearTimeout(pulseTimeoutRef.current);
|
|
97
|
+
pulseTimeoutRef.current = null;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}, []);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
if (typeof window === 'undefined' || typeof document === 'undefined')
|
|
103
|
+
return;
|
|
104
|
+
const canvas = canvasRef.current;
|
|
105
|
+
if (!canvas)
|
|
106
|
+
return;
|
|
107
|
+
const ctx = canvas.getContext('2d');
|
|
108
|
+
if (!ctx)
|
|
109
|
+
return;
|
|
110
|
+
let t = 0;
|
|
111
|
+
let frame;
|
|
112
|
+
const draw = () => {
|
|
113
|
+
const { width, height } = canvas;
|
|
114
|
+
ctx.clearRect(0, 0, width, height);
|
|
115
|
+
const computed = getComputedStyle(document.documentElement);
|
|
116
|
+
const strokeValue = computed.getPropertyValue(`--color-${phase}`).trim() || DEFAULT_COLOR;
|
|
117
|
+
const [r, g, b] = resolveColor(strokeValue);
|
|
118
|
+
const { h: baseHue, s: baseSat, l: baseLight } = rgbToHsl(r, g, b);
|
|
119
|
+
const mainColor = `hsl(${baseHue}, ${baseSat}%, ${baseLight}%)`;
|
|
120
|
+
const drawWave = (color, amplitude, phaseOffset = 0, opacity = 1) => {
|
|
121
|
+
ctx.save();
|
|
122
|
+
ctx.globalAlpha = opacity;
|
|
123
|
+
ctx.strokeStyle = color;
|
|
124
|
+
ctx.lineWidth = 1.5;
|
|
125
|
+
ctx.beginPath();
|
|
126
|
+
for (let x = 0; x < width; x++) {
|
|
127
|
+
const y = height / 2 + Math.sin((x + t + phaseOffset) * 0.06) * amplitude;
|
|
128
|
+
if (x === 0)
|
|
129
|
+
ctx.moveTo(x, y);
|
|
130
|
+
else
|
|
131
|
+
ctx.lineTo(x, y);
|
|
132
|
+
}
|
|
133
|
+
ctx.stroke();
|
|
134
|
+
ctx.restore();
|
|
135
|
+
};
|
|
136
|
+
drawWave(mainColor, 5 + amplitudeForMood(mood));
|
|
137
|
+
const hueDrift = (offset) => (Date.now() / 1000 / 8 + offset) % 360;
|
|
138
|
+
peerWaves.forEach((peerId, index) => {
|
|
139
|
+
const baseOffset = Array.from(peerId).reduce((sum, char) => sum + char.charCodeAt(0), 0) + index * 45;
|
|
140
|
+
const peerHue = (baseOffset + hueDrift(index)) % 360;
|
|
141
|
+
const peerColor = `hsl(${peerHue}, ${Math.min(baseSat + 10, 90)}%, ${Math.min(baseLight + 5, 70)}%)`;
|
|
142
|
+
drawWave(peerColor, 3 + amplitudeForMood(mood) * 0.6, index * 20, 0.4);
|
|
143
|
+
});
|
|
144
|
+
t += 2;
|
|
145
|
+
frame = requestAnimationFrame(draw);
|
|
146
|
+
};
|
|
147
|
+
draw();
|
|
148
|
+
return () => cancelAnimationFrame(frame);
|
|
149
|
+
}, [phase, mood, peerWaves]);
|
|
150
|
+
const color = `var(--color-${phase}, var(--color-${mood}, var(--color-accent)))`;
|
|
151
|
+
const scale = pulseActive ? 1.2 : 1;
|
|
152
|
+
return (_jsxs("div", { className: `heartbeat-wrapper ${pulseActive ? 'pulse-on' : ''}`, style: { color }, title: `phase: ${phase}, mood: ${mood}`, children: [_jsx("div", { className: "heartbeat", style: {
|
|
153
|
+
width: '16px',
|
|
154
|
+
height: '16px',
|
|
155
|
+
backgroundColor: color,
|
|
156
|
+
transform: `scale(${scale})`,
|
|
157
|
+
transition: 'transform 0.3s ease, background 0.6s ease',
|
|
158
|
+
boxShadow: `0 0 12px ${color}`,
|
|
159
|
+
} }), _jsx("span", { className: "heartbeat-ring", style: { borderColor: color } }), _jsx("span", { className: "heartbeat-ring echo", style: { borderColor: color } }), _jsx("canvas", { ref: canvasRef, width: 80, height: 16, className: "heartbeat-wave" })] }));
|
|
160
|
+
};
|
|
161
|
+
//# sourceMappingURL=Heartbeat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Heartbeat.js","sourceRoot":"","sources":["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EF,IAAI,EAAE,CAAC;QACP,OAAO,GAAG,EAAE,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IAE7B,MAAM,KAAK,GAAG,eAAe,KAAK,iBAAiB,IAAI,yBAAyB,CAAC;IACjF,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpC,OAAO,CACL,eAAK,SAAS,EAAE,qBAAqB,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,UAAU,KAAK,WAAW,IAAI,EAAE,aAC7H,cACE,SAAS,EAAC,WAAW,EACrB,KAAK,EAAE;oBACL,KAAK,EAAE,MAAM;oBACb,MAAM,EAAE,MAAM;oBACd,eAAe,EAAE,KAAK;oBACtB,SAAS,EAAE,SAAS,KAAK,GAAG;oBAC5B,UAAU,EAAE,2CAA2C;oBACvD,SAAS,EAAE,YAAY,KAAK,EAAE;iBAC/B,GACD,EACF,eAAM,SAAS,EAAC,gBAAgB,EAAC,KAAK,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,GAAI,EAClE,eAAM,SAAS,EAAC,qBAAqB,EAAC,KAAK,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,GAAI,EACvE,iBAAQ,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAC,gBAAgB,GAAG,IACxE,CACP,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export type Phase = 'companion' | 'presence' | 'archive' | (string & {});
|
|
2
|
+
export type Mood = 'soft' | 'presence' | 'focused' | 'celebratory' | (string & {});
|
|
3
|
+
export type PresenceSnapshot = Readonly<{
|
|
4
|
+
t: number;
|
|
5
|
+
phase: Phase;
|
|
6
|
+
mood: Mood;
|
|
7
|
+
peers: number;
|
|
8
|
+
whisper?: string;
|
|
9
|
+
meta?: Record<string, unknown>;
|
|
10
|
+
}>;
|
|
11
|
+
export type KernelEvent = {
|
|
12
|
+
type: 'tick';
|
|
13
|
+
snap: PresenceSnapshot;
|
|
14
|
+
} | {
|
|
15
|
+
type: 'phase:set';
|
|
16
|
+
phase: Phase;
|
|
17
|
+
snap: PresenceSnapshot;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'mood:set';
|
|
20
|
+
mood: Mood;
|
|
21
|
+
snap: PresenceSnapshot;
|
|
22
|
+
} | {
|
|
23
|
+
type: 'whisper';
|
|
24
|
+
message: string;
|
|
25
|
+
snap: PresenceSnapshot;
|
|
26
|
+
} | {
|
|
27
|
+
type: 'peer:up';
|
|
28
|
+
id: string;
|
|
29
|
+
snap: PresenceSnapshot;
|
|
30
|
+
} | {
|
|
31
|
+
type: 'peer:down';
|
|
32
|
+
id: string;
|
|
33
|
+
snap: PresenceSnapshot;
|
|
34
|
+
};
|
|
35
|
+
export type Unsubscribe = () => void;
|
|
36
|
+
export interface PresenceAdapter {
|
|
37
|
+
init?(kernel: PresenceKernel): void;
|
|
38
|
+
onTick?(snap: PresenceSnapshot): void;
|
|
39
|
+
emit?(evt: KernelEvent): void;
|
|
40
|
+
dispose?(): void;
|
|
41
|
+
}
|
|
42
|
+
export type KernelPlugin = (kernel: PresenceKernel) => void;
|
|
43
|
+
import { type Signal } from '@gratiaos/signal';
|
|
44
|
+
export declare const phase$: Signal<Phase>;
|
|
45
|
+
export declare const mood$: Signal<Mood>;
|
|
46
|
+
export declare const peers$: Signal<string[]>;
|
|
47
|
+
export declare const pulse$: Signal<number>;
|
|
48
|
+
export declare const setPhase: (phase: Phase) => void;
|
|
49
|
+
export declare const setMood: (mood: Mood) => void;
|
|
50
|
+
export declare class PresenceKernel {
|
|
51
|
+
private phase;
|
|
52
|
+
private mood;
|
|
53
|
+
private peers;
|
|
54
|
+
private whisperMsg;
|
|
55
|
+
private listeners;
|
|
56
|
+
private adapters;
|
|
57
|
+
private timer;
|
|
58
|
+
private readonly intervalMs;
|
|
59
|
+
private readonly now;
|
|
60
|
+
private syncPeers;
|
|
61
|
+
constructor(intervalMs?: number, now?: () => number);
|
|
62
|
+
start(): void;
|
|
63
|
+
stop(): void;
|
|
64
|
+
setPhase(next: Phase): void;
|
|
65
|
+
setMood(next: Mood): void;
|
|
66
|
+
whisper(message: string): void;
|
|
67
|
+
upsertPeer(id: string): void;
|
|
68
|
+
dropPeer(id: string): void;
|
|
69
|
+
activePeerCount(staleMs?: number): number;
|
|
70
|
+
use(adapter: PresenceAdapter): this;
|
|
71
|
+
plugin(plugin: KernelPlugin): this;
|
|
72
|
+
on(listener: (event: KernelEvent) => void): Unsubscribe;
|
|
73
|
+
get snapshot(): PresenceSnapshot;
|
|
74
|
+
private tick;
|
|
75
|
+
private publish;
|
|
76
|
+
}
|
|
77
|
+
export { Heartbeat } from './Heartbeat';
|
|
78
|
+
export { ConstellationHUD } from './ConstellationHUD';
|
|
79
|
+
export { usePhaseSound } from './usePhaseSound';
|
|
80
|
+
export { usePhaseSpatialSound } from './usePhaseSpatialSound';
|
|
81
|
+
export { createSignal } from '@gratiaos/signal';
|
|
82
|
+
export type { Signal, SignalListener } from '@gratiaos/signal';
|
|
83
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AACzE,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,aAAa,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAEnF,MAAM,MAAM,g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CAQ/B;IAED,OAAO,CAAC,IAAI;IAOZ,OAAO,CAAC,OAAO;CAUhB;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAI9D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { createSignal } from '@gratiaos/signal';
|
|
2
|
+
// Signals are now sourced from @gratiaos/signal (shared micro observable).
|
|
3
|
+
export const phase$ = createSignal('presence');
|
|
4
|
+
export const mood$ = createSignal('soft'); // phase can be vivid while mood stays gentle by default
|
|
5
|
+
export const peers$ = createSignal([]);
|
|
6
|
+
export const pulse$ = createSignal(0);
|
|
7
|
+
export const setPhase = (phase) => phase$.set(phase);
|
|
8
|
+
export const setMood = (mood) => mood$.set(mood);
|
|
9
|
+
export class PresenceKernel {
|
|
10
|
+
syncPeers() {
|
|
11
|
+
peers$.set(Array.from(this.peers.keys()));
|
|
12
|
+
}
|
|
13
|
+
constructor(intervalMs = 1000, now = () => Date.now()) {
|
|
14
|
+
this.phase = 'presence';
|
|
15
|
+
this.mood = 'soft';
|
|
16
|
+
this.peers = new Map();
|
|
17
|
+
this.whisperMsg = '';
|
|
18
|
+
this.listeners = new Set();
|
|
19
|
+
this.adapters = new Set();
|
|
20
|
+
this.timer = null;
|
|
21
|
+
this.intervalMs = intervalMs;
|
|
22
|
+
this.now = now;
|
|
23
|
+
}
|
|
24
|
+
start() {
|
|
25
|
+
var _a;
|
|
26
|
+
if (this.timer)
|
|
27
|
+
return;
|
|
28
|
+
this.timer = setInterval(() => this.tick(), this.intervalMs);
|
|
29
|
+
for (const adapter of this.adapters)
|
|
30
|
+
(_a = adapter.init) === null || _a === void 0 ? void 0 : _a.call(adapter, this);
|
|
31
|
+
this.tick();
|
|
32
|
+
}
|
|
33
|
+
stop() {
|
|
34
|
+
var _a;
|
|
35
|
+
if (this.timer)
|
|
36
|
+
clearInterval(this.timer);
|
|
37
|
+
this.timer = null;
|
|
38
|
+
for (const adapter of this.adapters)
|
|
39
|
+
(_a = adapter.dispose) === null || _a === void 0 ? void 0 : _a.call(adapter);
|
|
40
|
+
}
|
|
41
|
+
setPhase(next) {
|
|
42
|
+
if (this.phase === next)
|
|
43
|
+
return;
|
|
44
|
+
this.phase = next;
|
|
45
|
+
setPhase(next);
|
|
46
|
+
this.publish({ type: 'phase:set', phase: next, snap: this.snapshot });
|
|
47
|
+
}
|
|
48
|
+
setMood(next) {
|
|
49
|
+
if (this.mood === next)
|
|
50
|
+
return;
|
|
51
|
+
this.mood = next;
|
|
52
|
+
setMood(next);
|
|
53
|
+
this.publish({ type: 'mood:set', mood: next, snap: this.snapshot });
|
|
54
|
+
}
|
|
55
|
+
whisper(message) {
|
|
56
|
+
this.whisperMsg = message;
|
|
57
|
+
this.publish({ type: 'whisper', message, snap: this.snapshot });
|
|
58
|
+
}
|
|
59
|
+
upsertPeer(id) {
|
|
60
|
+
const isNew = !this.peers.has(id);
|
|
61
|
+
this.peers.set(id, this.now());
|
|
62
|
+
if (isNew)
|
|
63
|
+
this.syncPeers();
|
|
64
|
+
this.publish({ type: 'peer:up', id, snap: this.snapshot });
|
|
65
|
+
}
|
|
66
|
+
dropPeer(id) {
|
|
67
|
+
const existed = this.peers.delete(id);
|
|
68
|
+
if (!existed)
|
|
69
|
+
return;
|
|
70
|
+
this.syncPeers();
|
|
71
|
+
this.publish({ type: 'peer:down', id, snap: this.snapshot });
|
|
72
|
+
}
|
|
73
|
+
activePeerCount(staleMs = 15000) {
|
|
74
|
+
const now = this.now();
|
|
75
|
+
let changed = false;
|
|
76
|
+
for (const [id, seen] of Array.from(this.peers)) {
|
|
77
|
+
if (now - seen > staleMs) {
|
|
78
|
+
this.peers.delete(id);
|
|
79
|
+
changed = true;
|
|
80
|
+
this.publish({ type: 'peer:down', id, snap: this.snapshot });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (changed)
|
|
84
|
+
this.syncPeers();
|
|
85
|
+
return this.peers.size;
|
|
86
|
+
}
|
|
87
|
+
use(adapter) {
|
|
88
|
+
var _a;
|
|
89
|
+
this.adapters.add(adapter);
|
|
90
|
+
if (this.timer)
|
|
91
|
+
(_a = adapter.init) === null || _a === void 0 ? void 0 : _a.call(adapter, this);
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
plugin(plugin) {
|
|
95
|
+
plugin(this);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
on(listener) {
|
|
99
|
+
this.listeners.add(listener);
|
|
100
|
+
return () => this.listeners.delete(listener);
|
|
101
|
+
}
|
|
102
|
+
get snapshot() {
|
|
103
|
+
return Object.freeze({
|
|
104
|
+
t: this.now(),
|
|
105
|
+
phase: this.phase,
|
|
106
|
+
mood: this.mood,
|
|
107
|
+
peers: this.activePeerCount(),
|
|
108
|
+
whisper: this.whisperMsg || undefined,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
tick() {
|
|
112
|
+
var _a;
|
|
113
|
+
pulse$.set(pulse$.value + 1);
|
|
114
|
+
const snap = this.snapshot;
|
|
115
|
+
this.publish({ type: 'tick', snap });
|
|
116
|
+
for (const adapter of this.adapters)
|
|
117
|
+
(_a = adapter.onTick) === null || _a === void 0 ? void 0 : _a.call(adapter, snap);
|
|
118
|
+
}
|
|
119
|
+
publish(event) {
|
|
120
|
+
var _a;
|
|
121
|
+
this.listeners.forEach((listener) => {
|
|
122
|
+
try {
|
|
123
|
+
listener(event);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// keep kernel resilient when listeners misbehave
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
for (const adapter of this.adapters)
|
|
130
|
+
(_a = adapter.emit) === null || _a === void 0 ? void 0 : _a.call(adapter, event);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export { Heartbeat } from './Heartbeat';
|
|
134
|
+
export { ConstellationHUD } from './ConstellationHUD';
|
|
135
|
+
export { usePhaseSound } from './usePhaseSound';
|
|
136
|
+
export { usePhaseSpatialSound } from './usePhaseSpatialSound';
|
|
137
|
+
// Re-export micro signal primitives to preserve historical import patterns
|
|
138
|
+
// for downstream packages that previously consumed signals via presence-kernel.
|
|
139
|
+
export { createSignal } from '@gratiaos/signal';
|
|
140
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,YAAY,EAAoC,MAAM,kBAAkB,CAAC;AAClF,2EAA2E;AAE3E,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,CAAQ,UAAU,CAAC,CAAC;AACtD,MAAM,CAAC,MAAM,KAAK,GAAG,YAAY,CAAO,MAAM,CAAC,CAAC,CAAC,wDAAwD;AACzG,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,CAAW,EAAE,CAAC,CAAC;AACjD,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,CAAS,CAAC,CAAC,CAAC;AAE9C,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAY,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAU,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAEvD,MAAM,OAAO,cAAc;IAWjB,SAAS;QACf,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IA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@@
|
|
|
1
|
+
export type PhaseSoundProfile = {
|
|
2
|
+
root: number;
|
|
3
|
+
intervals: number[];
|
|
4
|
+
interval: number;
|
|
5
|
+
filter: BiquadFilterType;
|
|
6
|
+
};
|
|
7
|
+
export declare const PHASE_SOUND_PROFILE: Record<string, PhaseSoundProfile>;
|
|
8
|
+
export declare const DEFAULT_SOUND_PROFILE: PhaseSoundProfile;
|
|
9
|
+
//# sourceMappingURL=phase-sound-profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phase-sound-profile.d.ts","sourceRoot":"","sources":["../src/phase-sound-profile.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,gBAAgB,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAKjE,CAAC;AAEF,eAAO,MAAM,qBAAqB,mBAA+B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const PHASE_SOUND_PROFILE = {
|
|
2
|
+
presence: { root: 220, intervals: [0, 3, 7], interval: 4500, filter: 'lowpass' },
|
|
3
|
+
soft: { root: 294, intervals: [0, 4, 7], interval: 3500, filter: 'bandpass' },
|
|
4
|
+
focused: { root: 392, intervals: [0, 3, 6], interval: 2000, filter: 'highpass' },
|
|
5
|
+
celebratory: { root: 523.25, intervals: [0, 4, 8], interval: 1500, filter: 'notch' },
|
|
6
|
+
};
|
|
7
|
+
export const DEFAULT_SOUND_PROFILE = PHASE_SOUND_PROFILE.presence;
|
|
8
|
+
//# sourceMappingURL=phase-sound-profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phase-sound-profile.js","sourceRoot":"","sources":["../src/phase-sound-profile.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,mBAAmB,GAAsC;IACpE,QAAQ,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE;IAChF,IAAI,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE;IAC7E,OAAO,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE;IAChF,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE;CACrF,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,mBAAmB,CAAC,QAAQ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useConstellationAudio — unified audio gating for Constellation HUD.
|
|
3
|
+
* Always calls underlying hooks (Rules of Hooks) but passes enabled flags
|
|
4
|
+
* derived from soundMode so audio engines mount/unmount cleanly.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useConstellationAudio(soundMode: 'spatial' | 'phase' | 'both' | 'none', selfId?: string, opts?: {
|
|
7
|
+
haptics?: boolean;
|
|
8
|
+
}): void;
|
|
9
|
+
//# sourceMappingURL=useConstellationAudio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConstellationAudio.d.ts","sourceRoot":"","sources":["../src/useConstellationAudio.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,QAOpI"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { usePhaseSpatialSound } from './usePhaseSpatialSound';
|
|
2
|
+
import { usePhaseSound } from './usePhaseSound';
|
|
3
|
+
/**
|
|
4
|
+
* useConstellationAudio — unified audio gating for Constellation HUD.
|
|
5
|
+
* Always calls underlying hooks (Rules of Hooks) but passes enabled flags
|
|
6
|
+
* derived from soundMode so audio engines mount/unmount cleanly.
|
|
7
|
+
*/
|
|
8
|
+
export function useConstellationAudio(soundMode, selfId, opts) {
|
|
9
|
+
var _a;
|
|
10
|
+
const spatialEnabled = soundMode === 'spatial' || soundMode === 'both';
|
|
11
|
+
const phaseEnabled = soundMode === 'phase' || soundMode === 'both';
|
|
12
|
+
// Pass enabled flags; underlying hooks early-exit when disabled.
|
|
13
|
+
usePhaseSpatialSound(selfId, spatialEnabled);
|
|
14
|
+
usePhaseSound((_a = opts === null || opts === void 0 ? void 0 : opts.haptics) !== null && _a !== void 0 ? _a : false, phaseEnabled);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=useConstellationAudio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConstellationAudio.js","sourceRoot":"","sources":["../src/useConstellationAudio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,SAAgD,EAAE,MAAe,EAAE,IAA4B;;IACnI,MAAM,cAAc,GAAG,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,MAAM,CAAC;IACvE,MAAM,YAAY,GAAG,SAAS,KAAK,OAAO,IAAI,SAAS,KAAK,MAAM,CAAC;IAEnE,iEAAiE;IACjE,oBAAoB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC7C,aAAa,CAAC,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,mCAAI,KAAK,EAAE,YAAY,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePhaseSound.d.ts","sourceRoot":"","sources":["../src/usePhaseSound.ts"],"names":[],"mappings":"AAgBA,wBAAgB,aAAa,CAAC,aAAa,UAAQ,EAAE,OAAO,GAAE,OAAc,QAkJ3E"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { phase$ } from './index';
|
|
3
|
+
import { DEFAULT_SOUND_PROFILE, PHASE_SOUND_PROFILE } from './phase-sound-profile';
|
|
4
|
+
export function usePhaseSound(enableHaptics = false, enabled = true) {
|
|
5
|
+
const timerRef = useRef(null);
|
|
6
|
+
const ctxRef = useRef(null);
|
|
7
|
+
const readyRef = useRef(false);
|
|
8
|
+
const pendingRef = useRef([]);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (!enabled)
|
|
11
|
+
return; // gated effect; previous teardown runs before disabled state
|
|
12
|
+
if (typeof window === 'undefined')
|
|
13
|
+
return;
|
|
14
|
+
const win = window;
|
|
15
|
+
const events = ['pointerdown', 'keydown', 'touchstart'];
|
|
16
|
+
const playToneInternal = (frequency, duration = 0.25, delay = 0, filterType = 'lowpass') => {
|
|
17
|
+
const ctx = ctxRef.current;
|
|
18
|
+
if (!ctx)
|
|
19
|
+
return;
|
|
20
|
+
const start = ctx.currentTime + Math.max(0, delay);
|
|
21
|
+
const osc = ctx.createOscillator();
|
|
22
|
+
const gain = ctx.createGain();
|
|
23
|
+
const filter = ctx.createBiquadFilter();
|
|
24
|
+
osc.type = 'sine';
|
|
25
|
+
osc.frequency.setValueAtTime(frequency, start);
|
|
26
|
+
filter.type = filterType;
|
|
27
|
+
const defaultFreq = 1200;
|
|
28
|
+
const filterFreq = filterType === 'lowpass' ? 650 : filterType === 'bandpass' ? 1500 : filterType === 'highpass' ? 2600 : defaultFreq;
|
|
29
|
+
filter.frequency.setValueAtTime(filterFreq, start);
|
|
30
|
+
gain.gain.setValueAtTime(0.05, start);
|
|
31
|
+
gain.gain.exponentialRampToValueAtTime(0.001, start + duration);
|
|
32
|
+
osc.connect(filter);
|
|
33
|
+
filter.connect(gain);
|
|
34
|
+
gain.connect(ctx.destination);
|
|
35
|
+
osc.start(start);
|
|
36
|
+
osc.stop(start + duration);
|
|
37
|
+
};
|
|
38
|
+
const flushPending = () => {
|
|
39
|
+
if (!ctxRef.current || pendingRef.current.length === 0)
|
|
40
|
+
return;
|
|
41
|
+
const pending = pendingRef.current.splice(0, pendingRef.current.length);
|
|
42
|
+
pending.forEach(({ freq, duration, delay, filter }) => playToneInternal(freq, duration, delay, filter));
|
|
43
|
+
};
|
|
44
|
+
const removeUnlockListeners = () => {
|
|
45
|
+
events.forEach((event) => win.removeEventListener(event, unlock));
|
|
46
|
+
};
|
|
47
|
+
const ensureContext = (allowResume) => {
|
|
48
|
+
var _a;
|
|
49
|
+
const AudioCtx = (_a = win.AudioContext) !== null && _a !== void 0 ? _a : win.webkitAudioContext;
|
|
50
|
+
if (!AudioCtx)
|
|
51
|
+
return false;
|
|
52
|
+
try {
|
|
53
|
+
if (!ctxRef.current) {
|
|
54
|
+
ctxRef.current = new AudioCtx();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if (!ctxRef.current)
|
|
61
|
+
return false;
|
|
62
|
+
if (ctxRef.current.state === 'suspended') {
|
|
63
|
+
if (!allowResume)
|
|
64
|
+
return false;
|
|
65
|
+
void ctxRef.current
|
|
66
|
+
.resume()
|
|
67
|
+
.then(() => {
|
|
68
|
+
readyRef.current = true;
|
|
69
|
+
removeUnlockListeners();
|
|
70
|
+
flushPending();
|
|
71
|
+
})
|
|
72
|
+
.catch(() => {
|
|
73
|
+
// still awaiting gesture
|
|
74
|
+
});
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
readyRef.current = true;
|
|
78
|
+
removeUnlockListeners();
|
|
79
|
+
flushPending();
|
|
80
|
+
return true;
|
|
81
|
+
};
|
|
82
|
+
const playTone = (frequency, duration, delay, filter) => {
|
|
83
|
+
if (!readyRef.current && !ensureContext(false)) {
|
|
84
|
+
pendingRef.current.push({ freq: frequency, duration, delay, filter });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
readyRef.current = true;
|
|
88
|
+
playToneInternal(frequency, duration, delay, filter);
|
|
89
|
+
};
|
|
90
|
+
const scheduleBaseline = (profile) => {
|
|
91
|
+
if (timerRef.current) {
|
|
92
|
+
window.clearInterval(timerRef.current);
|
|
93
|
+
timerRef.current = null;
|
|
94
|
+
}
|
|
95
|
+
timerRef.current = window.setInterval(() => {
|
|
96
|
+
playTone(profile.root, 0.18, 0, profile.filter);
|
|
97
|
+
}, profile.interval);
|
|
98
|
+
};
|
|
99
|
+
const unlock = () => {
|
|
100
|
+
if (ensureContext(true)) {
|
|
101
|
+
readyRef.current = true;
|
|
102
|
+
flushPending();
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
events.forEach((event) => win.addEventListener(event, unlock, { passive: true }));
|
|
106
|
+
// Try to initialize immediately in case interaction already happened
|
|
107
|
+
ensureContext(false);
|
|
108
|
+
const stopPhase = phase$.subscribe((phase) => {
|
|
109
|
+
var _a, _b;
|
|
110
|
+
const profile = (_a = PHASE_SOUND_PROFILE[phase]) !== null && _a !== void 0 ? _a : DEFAULT_SOUND_PROFILE;
|
|
111
|
+
profile.intervals.forEach((semi, index) => {
|
|
112
|
+
const freq = profile.root * Math.pow(2, semi / 12);
|
|
113
|
+
playTone(freq, 0.25, index * 0.08, profile.filter);
|
|
114
|
+
});
|
|
115
|
+
if (enableHaptics && typeof navigator !== 'undefined' && 'vibrate' in navigator) {
|
|
116
|
+
(_b = navigator.vibrate) === null || _b === void 0 ? void 0 : _b.call(navigator, [30, 60, 30]);
|
|
117
|
+
}
|
|
118
|
+
scheduleBaseline(profile);
|
|
119
|
+
});
|
|
120
|
+
return () => {
|
|
121
|
+
var _a;
|
|
122
|
+
stopPhase();
|
|
123
|
+
removeUnlockListeners();
|
|
124
|
+
if (timerRef.current) {
|
|
125
|
+
window.clearInterval(timerRef.current);
|
|
126
|
+
timerRef.current = null;
|
|
127
|
+
}
|
|
128
|
+
pendingRef.current = [];
|
|
129
|
+
readyRef.current = false;
|
|
130
|
+
void ((_a = ctxRef.current) === null || _a === void 0 ? void 0 : _a.close().catch(() => {
|
|
131
|
+
// ignore close errors
|
|
132
|
+
}));
|
|
133
|
+
ctxRef.current = null;
|
|
134
|
+
};
|
|
135
|
+
}, [enableHaptics, enabled]);
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=usePhaseSound.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePhaseSound.js","sourceRoot":"","sources":["../src/usePhaseSound.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAA0B,MAAM,uBAAuB,CAAC;AAc3G,MAAM,UAAU,aAAa,CAAC,aAAa,GAAG,KAAK,EAAE,UAAmB,IAAI;IAC1E,MAAM,QAAQ,GAAG,MAAM,CAAwC,IAAI,CAAC,CAAC;IACrE,MAAM,MAAM,GAAG,MAAM,CAAsB,IAAI,CAAC,CAAC;IACjD,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,MAAM,UAAU,GAAG,MAAM,CAAgB,EAAE,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