Skip to content

definePrimitive

Read as Markdown

import { definePrimitive } from "@pibbl/core";

definePrimitive(render, capabilities?) creates a Pibbl primitive component from a PrimitiveRender callback and optional PrimitiveCapabilities, with private style normalization, resolution, and optional measurement capabilities. Use it for component-library primitives, not ordinary application components: invoking its returned component outside the Pibbl renderer throws.

const Dot = definePrimitive(function renderDot(props) {
// paint with the active Pibbl Canvas context
});

The exact generic contracts are in the Elements and components type reference; primitive painting receives Pibbl’s active Canvas context. See Custom components and primitives.

The experimental measureIntrinsic capability returns both intrinsic content sizes through IntrinsicSizesResult. Its first consumer is a direct custom primitive in a finite nowrap Flex row. Ordinary measure remains unchanged. Providers are pure and use the existing receiver dependency and teardown transaction. Mutable nested inputs and changes to the provider’s own style conservatively remeasure; unrelated sibling paint can reuse a successful snapshot.

For a direct custom leaf with both capabilities in a finite nowrap Flex row, measure also runs at the settled content width when cross height is automatic. Its constraints.minWidth and .maxWidth both equal that width. It can return a width-dependent height while measureIntrinsic remains the basis/minimum input. Declared cross dimensions and intrinsic-only providers keep their existing paths. Unsupported finite results diagnose instead of publishing stale height. The intrinsic-leaf example exposes Adaptive owner and Adaptive paint controls for this bounded behavior.

The experimental measureBaselines capability returns a fixed BaselinesResult from a BaselineMeasureInput at the final content allocation. A finite LTR nowrap Flex row can use alignItems: "first-baseline" with direct fixed primitive leaves. The provider is pure, measurement-owned and cached only through successful existing receiver transactions. Missing providers use the content bottom edge; declared unsupported, nonfinite or unordered results diagnose before painting. Offsets may be negative or outside the content box. Existing measure and measureIntrinsic remain separate operations. See the baseline composition.

Defines a platform component with private style and measurement behavior.

definePrimitive: <P = Record<string, never>, S extends SystemStyle = SystemStyle, N extends SystemStyle = S, R extends SystemStyle = N>(render: PrimitiveRender<P, R> & PrimitiveStyleGuard<S, N, R> & (PrimitiveInput<P, S> extends never ? never : unknown), ...capabilityArguments: CapabilityArguments<P, S, N, R>) => PibblPrimitiveComponent<PrimitiveProgramProps<P>, PrimitiveInput<P, S>>

Related API: definePrimitive, SystemStyle, PrimitiveRender, PrimitiveInput, PibblPrimitiveComponent, PrimitiveProgramProps.

  • render — Synchronous primitive renderer receiving props, resolved style, and Canvas context. See PrimitiveRender , PrimitiveStyleGuard , PrimitiveInput .

  • capabilityArguments — Style normalization, resolution, and measurement capabilities required by the primitive. See CapabilityArguments .

A primitive component usable with JSX or createElement. See PibblPrimitiveComponent , PrimitiveProgramProps , PrimitiveInput .

PrimitiveRender

PrimitiveInput

PibblPrimitiveComponent

PrimitiveProgramProps

SystemStyle

View source — packages/core/src/lib/define-primitive.ts:87

Read the Authoring, signals, and lifecycle companion for ownership, adaptation, failure modes, and verification. Agent start provides the version-selection workflow.

Documentation built with @pibbl/core 0.0.2, revision a1dcf8e. ALPHA — NOT FOR PRODUCTION USE.