rspace-online/lib/layer-types.ts

101 lines
2.8 KiB
TypeScript

/**
* Layer & Flow types for the rSpace tab/layer system.
*
* Each "tab" is a Layer — a named canvas page backed by a module.
* Layers stack vertically. Flows are typed connections (economic, trust,
* data, attention, governance) that move between shapes on different layers.
*
* The "stack view" renders all layers from the side, showing flows as
* arcs/lines between strata.
*/
// ── Flow types ──
export type FlowKind =
| "economic" // token/currency/value flows
| "trust" // reputation, attestation, endorsement
| "data" // information, content, feeds
| "attention" // views, engagement, focus
| "governance" // votes, proposals, decisions
| "resource" // files, assets, media
| "custom"; // user-defined
export const FLOW_COLORS: Record<FlowKind, string> = {
economic: "#bef264", // lime
trust: "#c4b5fd", // violet
data: "#67e8f9", // cyan
attention: "#fcd34d", // amber
governance: "#f0abfc", // fuchsia
resource: "#6ee7b7", // emerald
custom: "#94a3b8", // slate
};
export const FLOW_LABELS: Record<FlowKind, string> = {
economic: "Economic",
trust: "Trust",
data: "Data",
attention: "Attention",
governance: "Governance",
resource: "Resource",
custom: "Custom",
};
// ── Layer definition ──
export interface Layer {
/** Unique layer ID (e.g. "layer-abc123") */
id: string;
/** Module ID this layer is bound to (e.g. "canvas", "notes", "funds") */
moduleId: string;
/** Display label (defaults to module name, user-customizable) */
label: string;
/** Position in the tab bar (0-indexed, left to right) */
order: number;
/** Layer color for the stack view strata */
color: string;
/** Whether this layer is visible in stack view */
visible: boolean;
/** Created timestamp */
createdAt: number;
}
// ── Inter-layer flow ──
export interface LayerFlow {
/** Unique flow ID */
id: string;
/** Flow type */
kind: FlowKind;
/** Source layer ID */
sourceLayerId: string;
/** Source shape ID (optional — can be layer-wide) */
sourceShapeId?: string;
/** Target layer ID */
targetLayerId: string;
/** Target shape ID (optional — can be layer-wide) */
targetShapeId?: string;
/** Human-readable label */
label?: string;
/** Flow strength/weight (0-1, affects visual thickness) */
strength: number;
/** Whether this flow is currently active */
active: boolean;
/** Custom color override */
color?: string;
/** Metadata for the flow */
meta?: Record<string, unknown>;
}
// ── Layer config stored in Automerge doc ──
export interface LayerConfig {
/** Ordered list of layers */
layers: { [id: string]: Layer };
/** Inter-layer flows */
flows: { [id: string]: LayerFlow };
/** Currently active layer ID */
activeLayerId: string;
/** View mode: 'flat' (normal tabs) or 'stack' (side/3D view) */
viewMode: "flat" | "stack";
}