# @askrjs/askr/foundations/structures

> Published API exports for @askrjs/askr/foundations/structures.

Source: [https://askrjs.com/docs/reference/api/askr/foundations--structures](https://askrjs.com/docs/reference/api/askr/foundations--structures)

Status: stable. Packages: @askrjs/askr/foundations/structures.

**Published packages are authoritative.** Examples may lag behind a published contract. When guidance differs, verify the exports and TypeScript declarations in your installed package, then file an issue.

## Exports

This entrypoint publishes 20 exports from the declarations shipped by @askrjs/askr.

### `cloneElement`

```ts
cloneElement: (element: JSXElement, props: Record<string, unknown>) => JSXElement
```

Clone a JSX element, shallow-merging `props` over its existing props.

### `Collection`

```ts
Collection: any
```

Ordered descendant registry returned by {@link createCollection}.

- `register`: Register a node with optional metadata.
Returns an unregister function.

- `items`: Get all registered items in insertion order.

- `clear`: Clear all registered items.

- `size`: Get the count of registered items.

### `CollectionItem`

```ts
CollectionItem: {
  node: TNode;
  metadata: TMetadata;
}
```

A registered node paired with its metadata inside a {@link Collection}.

### `createCollection`

```ts
createCollection: <TNode, TMetadata = unknown>() => Collection<TNode, TMetadata>
```

Create an empty, insertion-ordered {@link Collection} registry.

### `createLayer`

```ts
createLayer: () => LayerManager
```

Create a new, empty {@link LayerManager} for coordinating overlay stacking.

### `DefaultPortal`

```ts
DefaultPortal: Portal<RenderableChild>
```

The implicit portal channel that {@link Portal} writes to and that any
host rendered without an explicit portal falls back to.

### `definePortal`

```ts
definePortal: <T extends RenderableChild = RenderableChild>() => Portal<T>
```

Create a new named {@link Portal} channel with its own host and content.

### `isElement`

```ts
isElement: (value: unknown) => value is JSXElement
```

Check whether `value` is a JSX element vnode.

### `JSXElement`

```ts
JSXElement: any
```

The vnode shape produced by JSX/`jsx()` calls.

- `$$typeof`: Internal element marker

- `type`: Element type: string, component, Fragment, etc

- `props`: Props bag

- `key`: Optional key (normalized by runtime)

### `Layer`

```ts
Layer: any
```

A registered layer entry returned by {@link LayerManager.register}.

- `id`: Unique layer ID

- `isTop`: Check if this layer is the topmost

- `unregister`: Remove this layer from the stack

### `LayerManager`

```ts
LayerManager: any
```

Stacking coordinator returned by {@link createLayer}.

- `register`: Register a new layer

- `layers`: Get all active layers in order

- `handleEscape`: Manually trigger escape handling on the top layer

- `handleOutsidePointer`: Manually trigger outside pointer handling on the top layer

### `LayerOptions`

```ts
LayerOptions: any
```

Options for registering a layer with {@link LayerManager.register}.

- `onEscape`: Called when Escape is pressed and this is the top layer

- `onOutsidePointer`: Called when pointer event occurs outside and this is the top layer

- `node`: Optional node reference for outside pointer detection

### `layout`

```ts
layout: <P = object>(Layout: LayoutComponent<P>) => (children?: RenderableChild, props?: P) => unknown
```

Wrap a {@link LayoutComponent} so it can be invoked as `(children, props)`,
matching route layout conventions.

### `LayoutComponent`

```ts
LayoutComponent: (props: P & {
  children?: RenderableChild;
}) => unknown
```

A component that receives its route children via `props.children`.

### `Portal`

```ts
Portal: (props: PortalProps) => JSXElement | null
```

Write children to the {@link DefaultPortal} host wherever it is rendered.
A named portal channel created by {@link definePortal}: call it as a
component to render the host, and call `.render(props)` to write content.

### `PortalProps`

```ts
PortalProps: any
```

Props for the {@link Portal} component.

- `children`: children?: RenderableChild;

### `Presence`

```ts
Presence: ({ present, children }: PresenceProps) => JSXElement | null
```

Presence

Structural policy primitive for conditional mount/unmount.
- No timers
- No animation coupling
- No DOM side-effects

POLICY DECISIONS (LOCKED):

1. Present as Function
   Accepts boolean OR function to support lazy evaluation patterns.
   Function is called once per render. Use boolean form for static values.

2. Children Type
   Presence forwards normal renderable child content only.
   Imperative DOM nodes are not part of the public contract.

3. Immediate Mount/Unmount
   No exit animations or transitions. When `present` becomes false,
   children are removed immediately. Animation must be layered above
   this primitive.

### `PresenceProps`

```ts
PresenceProps: any
```

Props for {@link Presence}.

- `children`: children?: RenderableChild;

- `present`: Whether the children should be mounted, or a function returning it.

### `Slot`

```ts
Slot: (props: SlotProps) => JSXElement | null
```

Slot

Structural primitive for prop forwarding patterns.

POLICY DECISIONS (LOCKED):

1. asChild Pattern
   When asChild=true, merges props into the single child element.
   Child must be a valid JSXElement; non-element children return null.
   **Slot props override child props** (injection pattern).

2. Fallback Behavior
   When asChild=false, returns a Fragment (structural no-op).
   No DOM element is introduced.

3. Type Safety
   asChild=true requires exactly one JSXElement child (enforced by type).
   Runtime validates with isElement() check.

### `SlotProps`

```ts
SlotProps: {
  asChild: true;
  children: JSXElement;
  [key: string]: unknown;
} | {
  asChild?: false;
  children?: RenderableChild;
}
```

Props for {@link Slot}: `asChild` selects prop-merging vs. fragment mode.

- `asChild`: asChild?: boolean | undefined;

- `children`: children?: RenderableChild;

## Documentation navigation

[Previous](https://askrjs.com/docs/reference/api/askr/foundations--state/index.md) | [Next](https://askrjs.com/docs/reference/api/askr/foundations--icon/index.md)
