@immediate-diagram/shared

v1.2.3

Published

Shared types, constants, and utilities used across all `@immediate-diagram` packages. Zero runtime dependencies.

Readme

@immediate-diagram/shared

Shared types, constants, and utilities used across all @immediate-diagram packages. Zero runtime dependencies.

Install

bun add @immediate-diagram/shared

Note: This package publishes raw .ts source. Requires Bun as runtime.

What's Included

AST Types

Full TypeScript type definitions for the Immediate Diagram AST — Document, NodeDeclaration, EdgeStatement, StateBlock, StyleBlock, TimelineBlock, and all diagram-specific constructs.

import type { Document, NodeDeclaration, EdgeStatement } from "@immediate-diagram/shared";

Diagram Types (Discriminated Unions)

Narrowed diagram types for type-safe handling of each diagram kind:

import type {
  FlowchartDiagram,
  SequenceDiagram,
  ArchitectureDiagram,
  PieDiagram,
  BlockDiagram,
  VennDiagram,
} from "@immediate-diagram/shared";

import { narrowDiagram } from "@immediate-diagram/shared";

// Narrows a parsed Document into a specific diagram type
const diagram = narrowDiagram(doc);
if (diagram.type === "flowchart") {
  diagram.nodes;  // FlowchartDiagram-specific
  diagram.edges;
}

Positioned Types

Layout output types used by the renderer — PositionedDiagram, PositionedNode, PositionedEdge, and diagram-specific positioned types.

import type { PositionedDiagram, PositionedNode, PositionedEdge } from "@immediate-diagram/shared";

Theme System

Theme definitions, defaults, and resolution:

import { DEFAULT_LIGHT_THEME, DEFAULT_DARK_THEME } from "@immediate-diagram/shared";
import type { DiagramTheme } from "@immediate-diagram/shared";

Complexity Validation

Per-diagram-type complexity limits for resource protection:

import { validateDiagramComplexity, DIAGRAM_TYPE_LIMITS } from "@immediate-diagram/shared";

const violations = validateDiagramComplexity(doc);
if (violations.length > 0) {
  console.error("Diagram too complex:", violations);
}

Utilities

  • generateId() — short random IDs
  • CircuitBreaker — circuit breaker pattern for external service calls
  • inferTimelineDefinition() — infer timeline from state/transition blocks
  • State property classification (LAYOUT_AFFECTING_PROPERTIES, STYLE_ONLY_PROPERTIES)

Development

bun test        # Run tests
bun run typecheck   # Type checking

License

MIT