Skip to Content
Bear documentation

relations

Import from bear/engine/relations.

Interfaces

ConnectRole

Defined in: bear/engine/relations.ts:392

One connection role on a PartDef.connects: the prop lowers through the registered relation prop named by rel, and props, when given, computes the role's edge props from the element's own props (how a catalog connector's chosen schedule reaches its edges; see blueprints/connectors). Role-computed keys own themselves: a target descriptor cannot override them. A returned error is a diagnostic on the element.

Properties

PropertyType
props?(elementProps) => | Record<string, unknown> | { error: string; }
relstring

Edge

Defined in: bear/engine/relations.ts:66

A typed, directed edge between two rendered elements.

Properties

PropertyTypeDescription
fromTreeNode-
fromRef?stringRef key the edge attaches through on the from element, if given.
kindRelationKind-
propsReadonly<Record<string, unknown>>Edge data: fastener schedules, tributary shares, flow demands.
sourcereadonly SourceLocation[]Call sites of the element that declared the edge.
system?stringSystem tag inherited from an enclosing System assembly, if any.
toTreeNode-
toRef?stringRef key the edge attaches through on the to element, if given.

ExtractedRelations

Defined in: bear/engine/relations.ts:426

What collection extracts from an element's props.

Properties

PropertyTypeDescription
decls?RelationDecl[]Declarations to land on the element's node, if any.
propsErasedPropsThe props the node (and any assembly body) should see.

GraphStep

Defined in: bear/engine/relations.ts:768

One traversal step: the neighbor, plus the declared edge when one made the step (absent for the implicit containment step to/from a parent).

Properties

PropertyType
edge?Edge
nodeTreeNode

MateTarget

Defined in: bear/engine/relations.ts:226

A resolved attachment target: the node, and the port if one was named.

Properties

PropertyType
key?string
nodeTreeNode

RelationDecl

Defined in: bear/engine/relations.ts:416

One declared edge, waiting for target resolution: both ends stated outright, with SELF standing for the declaring element, so resolution is one symmetric rule with no direction flag. Lives on the node the declaring element produced (node.relationDecls), so its lifecycle is the node's: no cross-pass state, and late-collected children carry their declarations into the tree with them.

Properties

PropertyTypeDescription
fromDeclEnd-
kindRelationKind-
propsReadonly<Record<string, unknown>>-
role?stringThe connector role this was declared through, if any.
toDeclEnd-

RelationKinds

Defined in: bear/engine/relations.ts:56

The registered relation kinds, as a mergeable interface so kind positions autocomplete and typo-check. A model registering its own kind extends it:

declare module "bear/engine/relations" {
  interface RelationKinds { controls: true }
}

Properties

PropertyType
bearstrue
cutstrue
fastenstrue
feedstrue
joinstrue

RelationOptions

Defined in: bear/engine/relations.ts:142

Properties

PropertyTypeDescription
check?EdgeCheckWhether a resolved edge of this kind makes sense against the tree it was resolved in: each returned problem is a warning on the declaring element. The relation's counterpart to a connector part's check.
containment?booleanContainment is a transfer statement for this kind: an element that declares no edge of the kind implicitly transfers to its enclosing assembly ("carried by"). True for bears; wrong for flow kinds, where an undeclared terminal is just a terminal.
inverse?stringInverse spelling, target → owner: carries={x} means x bears on the owner.
mate?MateRuleHow a solvable anchor attached through this kind mates with its target's geometry (Lowerer.attach). A kind without one is edge-only.
propstringThe prop name that declares this kind, owner → target.

RelationProps

Defined in: bear/engine/relations.ts:132

The registered relation props, recognized on ANY element. Merged into the same module declaration that extends RelationKinds.

Extended by

Properties


Relations

Defined in: bear/engine/relations.ts:579

What relation resolution produces for one pass.

Properties

PropertyType
diagnosticsreadonly Diagnostic[]
edgesreadonly Edge[]

RelationTargetDescriptor

Defined in: bear/engine/relations.ts:97

A target wrapped with edge props: bearsOn={bears(beam, { tributary: 0.5 })}. The kind parameter makes a descriptor on the wrong prop a compile error at typed sites; the runtime check in declOf guards the untyped JSX boundary.

Type Parameters

Type ParameterDefault type
K extends RelationKindRelationKind

Properties

PropertyModifierType
[BEAR_REL_TARGET]readonlytrue
kindreadonlyK
propsreadonlyReadonly<Record<string, unknown>>
targetreadonlyRelationTarget

Type Aliases

EdgeCheck

type EdgeCheck = (edge) => readonly string[];

Defined in: bear/engine/relations.ts:168

Problems with one resolved edge, in words; empty when it is sound.

Parameters

ParameterType
edgeEdge

Returns

readonly string[]


MateRule

type MateRule = (target) => 
  | WorldPlane[]
  | {
  error: string;
};

Defined in: bear/engine/relations.ts:237

The world planes an attached anchor must lie on, from the target's geometry. Rotation is never solved: a mate constrains the anchor's position only, and the solver turns each plane into one linear equation over the anchor's coordinates.

Parameters

ParameterType
targetMateTarget

Returns

| WorldPlane[] | { error: string; }


RelationKind

type RelationKind = keyof RelationKinds & string;

Defined in: bear/engine/relations.ts:63


RelationPropValue

type RelationPropValue = 
  | RelationTarget
  | RelationTargetDescriptor
  | readonly (
  | RelationTarget
  | RelationTargetDescriptor)[];

Defined in: bear/engine/relations.ts:123

What a registered relation prop accepts in JSX: targets, single or many.


RelationTarget

type RelationTarget = BearElement | Ref | string;

Defined in: bear/engine/relations.ts:87

What a relation prop can point at: an element handle, a Ref (when the attachment port matters), or a lexical element name resolved with dim endpoint scoping rules.


RelationTargetFactory

type RelationTargetFactory<K> = (target, props?) => RelationTargetDescriptor<K>;

Defined in: bear/engine/relations.ts:117

Type Parameters

Type ParameterDefault type
K extends RelationKindRelationKind

Parameters

ParameterType
targetRelationTarget
props?Record<string, unknown>

Returns

RelationTargetDescriptor<K>

Variables

atPort

const atPort: MateRule;

Defined in: bear/engine/relations.ts:256

feeds: the anchor sits at the target's named port.


bears

const bears: RelationTargetFactory<"bears">;

Defined in: bear/engine/relations.ts:353

"Transfers load to." Bearing vs. fastened is edge data, not a kind.


cuts

const cuts: RelationTargetFactory<"cuts">;

Defined in: bear/engine/relations.ts:377

"My solid is subtracted from yours." A rough opening's Void cuts the wall's layers and plate; an electrical box cuts the drywall. Applied to geometry once the tree has converged (see engine/geometry.ts), so the layout never depends on it: a layer panelizes its whole face and the hole arrives afterward, which is also how it is built.


fastens

const fastens: RelationTargetFactory<"fastens">;

Defined in: bear/engine/relations.ts:360

A fastened connection whose edge carries the fastener schedule.


feeds

const feeds: RelationTargetFactory<"feeds">;

Defined in: bear/engine/relations.ts:365

Flow topology: supply, DWV, duct runs. Directed with the flow.


onBearingPlane

const onBearingPlane: MateRule;

Defined in: bear/engine/relations.ts:244

bears: the member's end lands on the support. A named port (a face, a hanger's seat, a pier's center) is the plane; a bare element is a point support, and the anchor lands on its plan center.


onFace

const onFace: MateRule;

Defined in: bear/engine/relations.ts:248

fastens: the anchor sits on the target's named face.


SELF

const SELF: typeof SELF;

Defined in: bear/engine/relations.ts:404

The declaring element's own side of an edge.


SystemContext

const SystemContext: BearContext<string>;

Defined in: bear/engine/relations.ts:350

The system tag a subtree's edges inherit (edge.system). Published by the System assembly; a "system" is that assembly + layer duo, nothing more.

Functions

extractRelationProps()

function extractRelationProps(element): ExtractedRelations;

Defined in: bear/engine/relations.ts:448

Extract edge declarations off an element's props. Globally registered relation props are stripped (the node and any assembly body never see them); a part's connects role props stay on the node, descriptors unwrapped, so collection can resolve Ref targets for placement.

Parameters

ParameterType
elementBearElement

Returns

ExtractedRelations


isDescriptor()

function isDescriptor(value): value is RelationTargetDescriptor<RelationKind>;

Defined in: bear/engine/relations.ts:106

Parameters

ParameterType
valueunknown

Returns

value is RelationTargetDescriptor<RelationKind>


mateRuleOf()

function mateRuleOf(kind): MateRule | undefined;

Defined in: bear/engine/relations.ts:217

The mate rule a kind registered, if it has one.

Parameters

ParameterType
kindRelationKind

Returns

MateRule | undefined


relation()

function relation<K>(kind, options): RelationTargetFactory<K>;

Defined in: bear/engine/relations.ts:321

Register a relation kind. Its props become recognized on any element and lower to edge declarations at collect. Returns the target-descriptor factory for attaching edge props to a target.

Type Parameters

Type Parameter
K extends RelationKind

Parameters

ParameterType
kindK
optionsRelationOptions

Returns

RelationTargetFactory<K>


resolveRelations()

function resolveRelations(root, map): Relations;

Defined in: bear/engine/relations.ts:592

Walk the finished tree and resolve every node's declarations into the edge set. Both ends resolve by one rule (SELF is the declaring node); endpoint failures are diagnostics on the declaring node, like dims. An edge is one fact about a pair, however many times it is declared: a hanger's joist role and the joist resting on the hanger's seat coalesce into one edge carrying both declarations' props.

Parameters

ParameterType
rootTreeNode
mapReadonlyMap<BearElement<object>, TreeNode>

Returns

Relations


resolveRelationTarget()

function resolveRelationTarget<N>(
   target, 
   scope, 
   map
): 
  | {
  key?: string;
  node: N;
}
  | {
  error: string;
};

Defined in: bear/engine/relations.ts:729

Resolve a relation target from a node's scope, in whatever phase the caller is in (placement runs on drafts). Shared with placement.

Type Parameters

Type Parameter
N extends Scoped<N>

Parameters

ParameterType
targetRelationTarget
scopeN | null
mapReadonlyMap<BearElement<object>, N>

Returns

| { key?: string; node: N; } | { error: string; }


stepsIn()

function stepsIn(
   node, 
   kind, 
   edges
): GraphStep[];

Defined in: bear/engine/relations.ts:800

Incoming steps of kind into a node: its declared edges, plus, for a containment kind, the implicit step from each child that declares no edge of the kind (the node carries its undeclared contents).

Parameters

ParameterType
nodeTreeNode
kindstring
edgesreadonly Edge[]

Returns

GraphStep[]


stepsOut()

function stepsOut(
   node, 
   kind, 
   edges
): GraphStep[];

Defined in: bear/engine/relations.ts:782

Outgoing steps of kind from a node: its declared edges. For a containment kind (bears), an element that declares none implicitly transfers to its enclosing assembly instead: a part with no stated support is carried by whatever contains it, and a declared edge opts out of that default. Construction nodes transfer nothing.

Shared by trace and load folds so the rule has exactly one home.

Parameters

ParameterType
nodeTreeNode
kindstring
edgesreadonly Edge[]

Returns

GraphStep[]


withAttachments()

function withAttachments(element, descriptors): BearElement;

Defined in: bear/engine/relations.ts:557

The element with attachments declared on it: each descriptor joins the kind's owner → target prop, exactly as an author would write it, so attach() and bearsOn={...} are one declaration path. Refs stay pointed at the original element, which the element map also records.

Parameters

ParameterType
elementBearElement
descriptorsreadonly RelationTargetDescriptor<RelationKind>[]

Returns

BearElement

On this page