Reintent

@reintent/scene/svg

Things with names, drawn in SVG.

A thing a person could name is declared (its id, its words, its parts, its params) and drawn through semantic(), which wraps it in a <g data-sem> with its semantic path (man[bedside].hat); <Part> names a part inside it, and <Atmosphere> marks what is drawn but is not a thing. The registry holds what is on stage and the overrides laid over it.

Classes

Registry

Defined in: packages/scene/src/registry.ts

What is on stage, and the overrides laid over it. <Stage> makes one; useRegistry() reads it.

Example

import { Registry } from '@reintent/scene/svg';

const registry = new Registry();
registry.setOverride('man', 'size', 1.2);
registry.setOverride('man[bedside]', 'size', 1.5);
console.log(
  registry.overridesFor('man', 'man[bedside]'),
  registry.overridesFor('man', 'man[door]'),
);
// → { size: 1.5 } { size: 1.2 }

Constructors

Constructor
new Registry(): Registry;
Returns

Registry

Properties

PropertyModifierTypeDefault valueDescription
drawspublicDrawRecord[][]The Canvas drawings, in paint order.
flagsreadonlySet<string>undefinedThe switches that are on.
instancesreadonlyMap<string, InstanceRecord>undefinedEvery mounted semantic thing, by path.
overridesreadonlyMap<string, Record<string, unknown>>undefinedValues set from outside, by path or by entity.

Methods

addDraw()
addDraw(path, fn): object;

Defined in: packages/scene/src/registry.ts

Add a Canvas drawing for a path: set swaps its function, remove takes it off.

Parameters
ParameterType
pathstring
fnDrawFn
Returns

object

NameType
remove()() => void
set()(fn) => void
clearOverrides()
clearOverrides(): void;

Defined in: packages/scene/src/registry.ts

Let every override go.

Returns

void

declaration()
declaration(entity): 
  | Declaration<Params, Params>
  | undefined;

Defined in: packages/scene/src/registry.ts

The declaration of an entity.

Parameters
ParameterType
entitystring
Returns

| Declaration<Params, Params> | undefined

getVersion()
getVersion(): number;

Defined in: packages/scene/src/registry.ts

A number that changes with every override or flag.

Returns

number

mount()
mount(rec): () => void;

Defined in: packages/scene/src/registry.ts

Put a thing on stage; the function returned takes it off.

Parameters
ParameterType
recInstanceRecord
Returns

() => void

overridesFor()
overridesFor(entity, path): Record<string, unknown>;

Defined in: packages/scene/src/registry.ts

Entity-wide overrides, then this instance's: the more specific wins.

Parameters
ParameterType
entitystring
pathstring
Returns

Record<string, unknown>

setFlag()
setFlag(name, on): void;

Defined in: packages/scene/src/registry.ts

Turn a switch on or off.

Parameters
ParameterType
namestring
onboolean
Returns

void

setOverride()
setOverride(
   key, 
   prop, 
   value
): void;

Defined in: packages/scene/src/registry.ts

Set one prop of a path (or an entity) from outside; undefined lets it go.

Parameters
ParameterType
keystring
propstring
valueunknown
Returns

void

subscribe()
subscribe(fn): () => void;

Defined in: packages/scene/src/registry.ts

Called whenever an override or a flag changes.

Parameters
ParameterType
fn() => void
Returns

() => void

update()
update(path, props): void;

Defined in: packages/scene/src/registry.ts

A thing's props, as it was last drawn.

Parameters
ParameterType
pathstring
propsRecord<string, unknown>
Returns

void

Interfaces

ChoiceParam

Defined in: packages/scene/src/spec.ts

One of a few named options a thing is drawn with.

Properties

PropertyType
affects?readonly string[]
aka?readonly string[]
defaultstring
kind"choice"
optionsreadonly string[]

Declaration

Defined in: packages/scene/src/spec.ts

What a thing is called, what it is made of, and what can be turned.

Type Parameters

Type ParameterDefault type
P extends ParamsParams
S extends ParamsParams

Properties

PropertyTypeDescription
akareadonly string[]The words people use for it, in any language.
depicts?stringOne line: what it looks like, for whoever draws it again.
idstringStable, lower case, the name code and people share: 'man', 'wardrobe'.
instances?Readonly<Record<string, string>>Where it can appear, by instance name.
kindstring'character', 'prop', 'setting', 'camera', …
params?PWhat it is: turnable, and an edit when turned.
parts?readonly string[]Its nameable parts. Dotted names nest: 'door.left'.
state?SWhat the scene does to it, frame by frame: an override pins it.
visual?booleanFalse for a thing with state but no picture (the viewer).

DrawRecord

Defined in: packages/scene/src/registry.ts

A Canvas drawing on stage, and the path that owns it.

Properties

PropertyType
fnDrawFn
idnumber
pathstring

InstanceRecord

Defined in: packages/scene/src/registry.ts

A semantic thing on stage.

Properties

PropertyTypeDescription
entitystring-
host"canvas" | "svg"-
instancestring | null-
node() => Element | null-
pathstring-
propsRecord<string, unknown>Its props as last drawn: defaults, then what the code passed, then overrides.

NumberParam

Defined in: packages/scene/src/spec.ts

A number a thing is drawn with, and its range.

Properties

PropertyTypeDescription
affects?readonly string[]Parts this param is allowed to move. The verifier holds it to them. Default: the whole instance.
aka?readonly string[]Words for this param ("帽子大小", "hat size").
defaultnumber-
effect?"shape" | "appearance"What turning it changes: 'shape' (the default) must move something, or it is not wired; 'appearance' (an opacity, a colour, canvas dust) need not.
kind"number"-
maxnumber-
minnumber-
step?number-
unit?string-

Owner

Defined in: packages/scene/src/semantic.tsx

The semantic thing being drawn here: its path, and its entity.

Properties

PropertyType
entitystring
pathstring

ParsedPath

Defined in: packages/scene/src/path.ts

A semantic path, taken apart.

Properties

PropertyTypeDescription
entitystring-
instancestring | null-
partstring | nullThe dotted part, if any: 'hat.brim'.

Type Aliases

DrawFn

type DrawFn = (ctx, t) => void;

Defined in: packages/scene/src/registry.ts

A drawing in immediate mode: any Canvas calls, in scene units, at the scene's time t.

Parameters

ParameterType
ctxCanvasRenderingContext2D
tnumber

Returns

void


Param

type Param = NumberParam | ChoiceParam;

Defined in: packages/scene/src/spec.ts

A param: a number or a choice.


Params

type Params = Record<string, Param>;

Defined in: packages/scene/src/spec.ts

A thing's params, by name.


ParamValues

type ParamValues<P> = { [K in keyof P]: P[K] extends NumberParam ? number : string };

Defined in: packages/scene/src/spec.ts

The values of some params: a number for a number param, a string for a choice.

Type Parameters

Type Parameter
P extends Params

PartProps

type PartProps = object & SVGProps<SVGGElement>;

Defined in: packages/scene/src/semantic.tsx

The props of <Part> and <Atmosphere>: a name, and any attribute of an SVG <g>.

Type Declaration

NameType
children?ReactNode
namestring

SemanticComponent

type SemanticComponent<P, S> = (props) => ReactNode & object;

Defined in: packages/scene/src/semantic.tsx

A component made by semantic(), with its declaration.

Type Declaration

NameType
declarationDeclaration<P, S>

Type Parameters

Type ParameterDefault type
P extends Params-
S extends ParamsRecord<never, never>

SemanticProps

type SemanticProps<P, S> = Partial<ParamValues<P> & ParamValues<S>> & Placement & object;

Defined in: packages/scene/src/semantic.tsx

A semantic component's props: its params and state (any of them), where it is placed, and which one it is.

Type Declaration

NameTypeDescription
children?ReactNode-
instance?stringWhich one, when the thing appears more than once: 'wardrobe', 'bedside'.

Type Parameters

Type ParameterDefault type
P extends Params-
S extends ParamsRecord<never, never>

Variables

DECLARATIONS

const DECLARATIONS: Map<string, Declaration>;

Defined in: packages/scene/src/spec.ts

Every declaration made, by id. Declarations are module-level, like the components they describe, so the manifest exists before anything mounts.

Functions

Atmosphere()

function Atmosphere(props): ReactNode;

Defined in: packages/scene/src/semantic.tsx

What is drawn but is not a thing (a glow, a second image in a dream, grain). It is left out of measurement and coverage, by name: a <g data-sem-post>.

Parameters

ParameterType
propsPartProps

Returns

ReactNode


choice()

function choice(
   def, 
   options, 
   o?
): ChoiceParam;

Defined in: packages/scene/src/spec.ts

A choice param: its default and its options.

Parameters

ParameterType
defstring
optionsreadonly string[]
oOmit<ChoiceParam, "kind" | "default" | "options">

Returns

ChoiceParam

Example

import { choice } from '@reintent/scene/svg';

console.log(choice('felt', ['felt', 'straw']));
// → { kind: 'choice', default: 'felt', options: [ 'felt', 'straw' ] }

instancePath()

function instancePath(entity, instance): string;

Defined in: packages/scene/src/path.ts

The path of one instance of an entity: man[bedside], or man when there is no instance.

Parameters

ParameterType
entitystring
instancestring | null | undefined

Returns

string


isDeclared()

function isDeclared(path): boolean;

Defined in: packages/scene/src/path.ts

Is this path declared? Its entity, its instance (when the entity lists them), and its part (one of the parts, or a prefix of one). Timeline paths (beat.door, phase.awake, input.hold) answer from the timeline.

Parameters

ParameterType
pathstring

Returns

boolean


isNode()

function isNode(path): boolean;

Defined in: packages/scene/src/path.ts

A path worth a box and a row: an instance, or exactly one of its declared parts.

Parameters

ParameterType
pathstring

Returns

boolean


num()

function num(def, o): NumberParam;

Defined in: packages/scene/src/spec.ts

A number param: its default and its range.

Parameters

ParameterType
defnumber
oOmit<NumberParam, "kind" | "default">

Returns

NumberParam

Example

import { num } from '@reintent/scene/svg';

console.log(num(1, { min: 0.5, max: 2, aka: ['hat size'] }));
// → { kind: 'number', default: 1, min: 0.5, max: 2, aka: [ 'hat size' ] }

parsePath()

function parsePath(path): ParsedPath;

Defined in: packages/scene/src/path.ts

A semantic path, taken apart.

Parameters

ParameterType
pathstring

Returns

ParsedPath

Example

import { parsePath } from '@reintent/scene/svg';

console.log(parsePath('man[bedside].hat.brim'));
// → { entity: 'man', instance: 'bedside', part: 'hat.brim' }

Part()

function Part(props): ReactNode;

Defined in: packages/scene/src/semantic.tsx

A named part of the semantic thing it is drawn inside: <Part name="hat">, a <g data-sem="man.hat">.

Parameters

ParameterType
propsPartProps

Returns

ReactNode


prefixes()

function prefixes(path): string[];

Defined in: packages/scene/src/path.ts

The path itself and every shorter one above it.

Parameters

ParameterType
pathstring

Returns

string[]

Example

import { prefixes } from '@reintent/scene/svg';

console.log(prefixes('man[bedside].hat.brim'));
// → [ 'man[bedside]', 'man[bedside].hat', 'man[bedside].hat.brim' ]

reaches()

function reaches(selection, path): boolean;

Defined in: packages/scene/src/path.ts

Does a selection reach this path? Same entity; instances agree where both name one; one part is a prefix of the other. A selected part does not reach the whole entity.

Parameters

ParameterType
selectionstring
pathstring

Returns

boolean

Example

import { reaches } from '@reintent/scene/svg';

console.log(reaches('man', 'man[bedside].hat'), reaches('man.hat', 'man'));
// → true false

semantic()

function semantic<P, S>(decl, Render): SemanticComponent<P, S>;

Defined in: packages/scene/src/semantic.tsx

A component for a thing a person could name: Render draws it from its params and state, with overrides laid over them, inside a <g data-sem="entity[instance]">. Declares the thing when it is called, so the manifest exists before anything mounts. Draw it inside a <Stage>.

Type Parameters

Type ParameterDefault type
P extends ParamsRecord<never, never>
S extends ParamsRecord<never, never>

Parameters

ParameterType
declDeclaration<P, S>
Render(props) => ReactNode

Returns

SemanticComponent<P, S>


useOwner()

function useOwner(): Owner | null;

Defined in: packages/scene/src/semantic.tsx

The path of the semantic thing being drawn here (for a <Draw> or a hook), if any.

Returns

Owner | null

Last updated on

Edit on GitHub