@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
Properties
| Property | Modifier | Type | Default value | Description |
|---|---|---|---|---|
draws | public | DrawRecord[] | [] | The Canvas drawings, in paint order. |
flags | readonly | Set<string> | undefined | The switches that are on. |
instances | readonly | Map<string, InstanceRecord> | undefined | Every mounted semantic thing, by path. |
overrides | readonly | Map<string, Record<string, unknown>> | undefined | Values 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
| Parameter | Type |
|---|---|
path | string |
fn | DrawFn |
Returns
object
| Name | Type |
|---|---|
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
| Parameter | Type |
|---|---|
entity | string |
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
| Parameter | Type |
|---|---|
rec | InstanceRecord |
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
| Parameter | Type |
|---|---|
entity | string |
path | string |
Returns
Record<string, unknown>
setFlag()
setFlag(name, on): void;Defined in: packages/scene/src/registry.ts
Turn a switch on or off.
Parameters
| Parameter | Type |
|---|---|
name | string |
on | boolean |
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
| Parameter | Type |
|---|---|
key | string |
prop | string |
value | unknown |
Returns
void
subscribe()
subscribe(fn): () => void;Defined in: packages/scene/src/registry.ts
Called whenever an override or a flag changes.
Parameters
| Parameter | Type |
|---|---|
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
| Parameter | Type |
|---|---|
path | string |
props | Record<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
| Property | Type |
|---|---|
affects? | readonly string[] |
aka? | readonly string[] |
default | string |
kind | "choice" |
options | readonly 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
Properties
DrawRecord
Defined in: packages/scene/src/registry.ts
A Canvas drawing on stage, and the path that owns it.
Properties
| Property | Type |
|---|---|
fn | DrawFn |
id | number |
path | string |
InstanceRecord
Defined in: packages/scene/src/registry.ts
A semantic thing on stage.
Properties
NumberParam
Defined in: packages/scene/src/spec.ts
A number a thing is drawn with, and its range.
Properties
Owner
Defined in: packages/scene/src/semantic.tsx
The semantic thing being drawn here: its path, and its entity.
Properties
ParsedPath
Defined in: packages/scene/src/path.ts
A semantic path, taken apart.
Properties
| Property | Type | Description |
|---|---|---|
entity | string | - |
instance | string | null | - |
part | string | null | The 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
| Parameter | Type |
|---|---|
ctx | CanvasRenderingContext2D |
t | number |
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
| Name | Type |
|---|---|
children? | ReactNode |
name | string |
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
| Name | Type |
|---|---|
declaration | Declaration<P, S> |
Type Parameters
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
| Name | Type | Description |
|---|---|---|
children? | ReactNode | - |
instance? | string | Which one, when the thing appears more than once: 'wardrobe', 'bedside'. |
Type Parameters
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
| Parameter | Type |
|---|---|
props | PartProps |
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
| Parameter | Type |
|---|---|
def | string |
options | readonly string[] |
o | Omit<ChoiceParam, "kind" | "default" | "options"> |
Returns
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
| Parameter | Type |
|---|---|
entity | string |
instance | string | 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
| Parameter | Type |
|---|---|
path | string |
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
| Parameter | Type |
|---|---|
path | string |
Returns
boolean
num()
function num(def, o): NumberParam;Defined in: packages/scene/src/spec.ts
A number param: its default and its range.
Parameters
| Parameter | Type |
|---|---|
def | number |
o | Omit<NumberParam, "kind" | "default"> |
Returns
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
| Parameter | Type |
|---|---|
path | string |
Returns
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
| Parameter | Type |
|---|---|
props | PartProps |
Returns
ReactNode
prefixes()
function prefixes(path): string[];Defined in: packages/scene/src/path.ts
The path itself and every shorter one above it.
Parameters
| Parameter | Type |
|---|---|
path | string |
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
| Parameter | Type |
|---|---|
selection | string |
path | string |
Returns
boolean
Example
import { reaches } from '@reintent/scene/svg';
console.log(reaches('man', 'man[bedside].hat'), reaches('man.hat', 'man'));
// → true falsesemantic()
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
Parameters
| Parameter | Type |
|---|---|
decl | Declaration<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