Skip to content

Latest commit

 

History

History
51 lines (37 loc) · 15.5 KB

components.md

File metadata and controls

51 lines (37 loc) · 15.5 KB
assumes blueprint/core, blueprint/layout
dsl
comp
inst
axes
variant
at
override
slot
lib
projds
no-projds

Blueprint Components

Two kinds. A plain component (same shape, only content differs): mark the first comp, inst() the rest, override() the content. A SET (discrete states): comp "Name" axes[state[...]], a variant() per state, then inst() at(state(...)). Editing a master propagates to every instance, and editing a variant to every instance in that state. A variant can inst() another set. A typeless comp "Name" row with indented children hugs them (no clip), and every inst() of it is born at that hugged size. An element that already exists becomes a master with #ref comp on a modify row (a shape that cannot be promoted, an arc circle, a vector or text, is wrapped in a master frame), on every door.

-- DEFINE: axes[axis[labels]] names the axis and its values, each variant() child carries its coordinate
al(v,g($spacing.lg),pad($spacing.lg)) s(hug,hug) f[($color.surface.container)] rd($radius.lg) "Components" #lib
  comp "Settings Row" axes[accessory[chevron,toggle]] #row
    al(h,y(c),g($spacing.md),pad($spacing.sm,$spacing.md)) variant(accessory(chevron)) s(320,hug) f[($color.surface)] rd($radius.md)
      al(h,x(c),y(c),pad($spacing.none)) s(29,29) slot #row_leading
      t("Label",$font.family,$font.size.md) s(fill,hug) f[($color.text.primary)] #row_title
      svg(icon:caret-right) s(14,14) f[($color.text.disabled)]
    al(h,y(c),g($spacing.md),pad($spacing.sm,$spacing.md)) variant(accessory(toggle)) s(320,hug) f[($color.surface)] rd($radius.md)
      al(h,x(c),y(c),pad($spacing.none)) s(29,29) slot
      t("Label",$font.family,$font.size.md) s(fill,hug) f[($color.text.primary)]
-- USE: at() picks the variant, override(#ref) retargets a child, override(#slot) + indented lines fill a slot (its direct children)
al(v,g($spacing.sm),pad($spacing.lg)) s(hug,hug) f[($color.surface.container)] rd($radius.lg) "Settings" #list
  inst(#row) at(accessory(chevron))
    override(#row_title) t("Wi-Fi")
    override(#row_leading) slot
      al(h,x(c),y(c),pad($spacing.none)) s(29,29) f[($color.info)] rd($radius.md)
        svg(icon:wifi-high) s(18,18) f[($color.surface)]

Edit a set later by re-declaring axes against the #ref: #row axes[+state[idle,active]] adds an axis (existing rows take the first value), #row axes[accessory[+swipe]] adds a value, #row axes[accessory->trailing] renames (keys kept, so at(trailing(toggle)) still lands), #row axes[-state] removes (flags collisions, never deletes content). To reorder values, re-declare every axis with no +, - or ->: #row axes[accessory[toggle,chevron],state] takes the listed order (keys kept, so every at() still lands); list every value, an axis named without a bracket keeps its values, and a value or axis left out is removed (the answer names what it removed, and one undo restores it). A new label in a listed value's place (or a new axis name in a listed axis's place) takes over that value or axis, so every variant on it now reads the new name, and the answer names which became which. A number works the same way: #row axes[count[+6]] adds 6, #row axes[count[-5]] removes 5, #row axes[size[+6]] adds a size axis when the set has none, and removing a value or axis that is not there, or adding a value that is, changes nothing and is named. Value order never picks the set's default: the default (what a bare inst() takes, and what fills the axes an at() skips) is the top-left-most variant, so move the look you want as default to the set's top-left corner. A new variant(...) frame nested under the #ref adds a variant: unseen value labels register, it joins the set's grid (its columns are the first axis's values): below the variants that share its first-axis value, or, for a first-axis value no variant has yet, in a new column to the right at the top row. A p() on the row puts it there instead. Existing variants never move, and undo reverts the whole edit. An inst() later in the same block can already pick a value the block added. Adding axes to a plain component turns it into a set whose first variant is the original, so its instances keep their overrides.

Reconfigure on canvas: #row_2 at(accessory(toggle)) (an instance of a one-axis on/off set whose off variant is empty is a show/hide slot: off takes it out of the auto layout flow, and the answer says so; a set with no off variant at all switched off is hidden and leaves the flow the same way, and at(on) restores it); an at() row changes the axes it names and keeps the others, and drops any stored entry the set no longer defines, so restating every axis leaves exactly those pairs; a switch takes the new variant's fill, stroke, effects and opacity (a variant with no fill leaves the instance with none) unless you set that paint on the instance yourself; an at() naming a combination no variant holds shows the nearest variant and the answer says the variant does not exist and lists the ones that do; an instance you resized keeps its size when the new variant is the same size as the old one, and takes the new variant's size (named in the answer) when it is not. Override a child of a placed instance by indenting the override() line under the instance's ref: #row_2 then override(#row_title) t("Bluetooth"). override() on a non-slot child changes its existing props (locking that category against master edits); a text is per field: a copy whose characters you retyped (or whose size you set) still takes every other text style edit of the master, its weight, line height, font, spacing and type-role binding, and keeps only what you set. A copy whose text style is already apart from the master's when the master edit lands keeps it (the edit cannot tell a style you set from one an earlier edit left behind): the edit's answer names those copies by name and id, and execute_commands with reset_text_style_overrides on a copy's text (or the instance) gives it the master's text style and keeps its characters, so the next master edit reaches it. To put back ONE overridden property and keep the rest (Figma's "Reset "), remove its category from the copy's ov[...] list with -: override(#row_title) ov[-fills] under the instance (or <childId> ov[-fills] on a real child id, or <copyId> ov[-size] on the copy itself, several at once as ov[-fills,-strokes]). That property takes what the master declares at the copy's current variant again (for a copy nested inside another component, what that component declares for it, else its own master at its variant); the copy keeps its variant and every other override, and one undo puts it back. The categories are the ones read prints in ov[...] and mref(ref,...): fills, strokes, effects, opacity, isVisible, rotation, isFlippedH, isFlippedV, vectorPath, layoutBehavior, name, textData, rectangleData, circleData, parentData, constrainProportions, designSystem, and on a copy itself size. The answer names a category the copy does not hold, or one it never holds, and changes nothing for it. A row inside an instance that lost its link to the master (read shows it without mref(...), while its linked siblings print mref(<masterChildId>)) re-links by naming that master child on a modify row: <rowId> mref(<masterChildId>). Everything the row does not state on that same row comes from the master child again, and the answer names each value that changed; state what to keep on the row. The usual repair keeps the row hidden: <rowId> mref(<masterChildId>) hidden. A row that keeps its own name states it: <rowId> mref(<masterChildId>) "My name". The answer refuses, and changes nothing, when the row is not inside an instance, already has a link, states a different type, or when another row of the instance already holds that master child. New content needs a slot. A slot fill replaces the slot's content (the answer counts what it replaced as slotReplaced, apart from deleted), and the bare override(#slot) slot (no props, nothing indented) empties the slot. A slot row that carries props and nothing indented (override(#slot) slot s(300,90)) sets those props and keeps the content; the answer says it kept it. Fill an existing empty slot by creating into it: svg(icon:wifi-high) s(18,18) parent(<slotId>). Only the override(#slot) slot row replaces: a row indented under the slot restated by its id (<slotId> al(h) then t("Step") before(<childId>)), or a create with parent(<slotId>), adds to the slot's content where its before()/after() puts it, and keeps every child already there. The result of the block that creates an instance lists its slot rows under slots ({"#c1": ["override(#card_body) slot"]}); read prints the same rows plus each slot's content, and expandInstances: true shows the instance's real children. A slot fill stays through a variant switch when the new variant has that slot (the same slot, or the one slot of that name); a fill the new variant has no slot for is named in the answer. A master change to a slot frame's sizing reaches every instance (the content stays), unless the instance sized that slot itself. spans[...] under an override(#text) row styles the instance's text, with or without a t() on the row. A real child id from expandInstances: true takes a modify row (<id> t("..."), <id> f[...], <id> at(...) on a nested copy, <id> with an indented override(#slot) slot fill), and it stays as that instance's override. A nested copy you switched with <id> at(...) reads back with an override(...) at(...) row before its children's rows. A new set lays its variants out in its axis grid and sizes itself; the answer says so when that moved a p() you sent.

An instance of an icon-like component (content only vectors, plain frames or groups around them, and booleans or masks whose operands may be rectangles or circles; no text, auto layout, nested instance, slot or image) scales that content with its box, like Figma's Scale constraint: every child at the default pin (l,t, written or not) scales, a non-uniform resize stretches the glyph, and stroke weight is kept. Resize an icon instance by its box, s() on the inst row (#ic s(16,16)), never by overriding its glyph's path or size. To opt a child out, give it any non-default pin (pin(c,c) keeps a glyph's size, centred); boolean and mask operands always scale. Outside an icon-like component, a child keeps its pin when you resize an instance: a fixed child at the default pin (l,t) keeps its size, and when it spanned the instance the answer names it with the row that sizes it with this copy (override(<child>) s(640,hug) under the instance); a pin(lr,) (or pin(,tb)) on that child in the master makes every copy follow.

Swapping an instance child's icon (#<childRef> svg(icon:...) or override(#ref) svg(icon:...), inline svg(<svg ...>) markup included) is an override of that child: master edits never revert it, and reset overrides restores the master's icon. The child keeps its id; an svg of several shapes makes it a frame of those shapes, and when the instance sits inside another main, every instance of that main shows the swapped shapes. override() targets a master child by the #ref assigned when the master was built, by a master-child id, or by exact child name, and lands on that instance's own copy. Any variant's child id works: a child the variants share lands on the instance's copy of it, and a child of another variant that is its own layer lands on the one child of the instance with the same name and type (two such children, or none, and the row is dropped and named). A live child id from expandInstances: true targets exactly that child. When the master holds several copies of one nested instance (two PropertyFields, four segments), each copy's child is one id away: override(<child id inside the 2nd copy in the master>) lands under the instance's 2nd copy. The id the nested copies share (the inner atom's own child id, which read prints once per copy) matches by order: the first row naming it takes the first copy, the next row the next copy. A block with fewer such rows than copies gets a note naming the copy each row reached; to reach one copy, name its child id from the master or the live child id instead.

Recoloring an instance child vector, by f[...] or by its regions (vr(rN) f[...]), is a fill override only: the vector keeps following the master's shape, so a master glyph move, resize or swap still reaches the recolored copy, and the copy keeps its color when the master is recolored.

A nested instance (an atom inside a molecule variant) materializes its own copy, with its own id, inside each outer instance; <copyId> at(axis(value)) reconfigures that one copy. Switching the OUTER instance's variant moves every nested copy to the coordinates the target variant declares for it, except a copy you reconfigured yourself to a different coordinate: that choice is an override and stays until reset overrides. Editing a nested instance's at() inside the master's variant moves the existing instances' copies the same way (a copy you reconfigured keeps its choice). A switch, outer or on one copy, takes the target variant's style and the overrides that variant declares for the copy, drops what only the leaving variant declared, and keeps the characters you overrode (a text you only retyped takes the new variant's weight and size; a text whose style you changed keeps the whole style). override(<master child id>) on a placed instance reaches that child under any variant, cross-canvas too. Reset overrides on a nested copy returns it to what the outer master declares for that copy (its tint, its size), never to the inner component's own defaults.

Across canvases

Masters are referenced BY NAME, unique per canvas: inst(Name) on the same canvas, inst(Name, canvas(path)) on another (path = the canvas identifier you pass in tool calls). Within one pass a master's #ref also resolves across canvases (inst(#toggle, canvas(Atoms)) "Wi-Fi"). Quote a name that contains a comma, parens, or quotes, inst("Card, small"). The instance follows its cross-canvas master's edits, and that canvas loads on demand.

Restating an existing instance as <id> inst(Name, canvas(path)) re-points it to that canvas's master of the name, keeping its overrides (re-pointed ... in the answer, which counts any override naming a child the new master does not have); no master of the name there, or two, refuses naming them.

parent(#master, canvas(path)) relocates a master to another canvas: every instance that referenced it is re-pointed (same-canvas instances become cross-canvas) in one undoable step, and if any consumer canvas cannot be updated nothing changes.

From a library

A project can instance components from a library: another published project it depends on at a pinned version (declared in libraries.yaml at the project root). lib() names the library's handle/project (no @), and canvas() the canvas path inside it: inst(Button, lib(acme/design-kit), canvas(Atoms/Buttons)). A local folder library wraps its manifest key in local(): inst(Button, lib(local(my-kit)), canvas(Atoms/Buttons)), the key written bare even with spaces or parentheses (lib(local(Material 3 Kit))), quoted only with a comma, quote, or newline. at(), override() and slots work as usual, and overrides survive library updates. Library content is read-only from the consuming project. A library instance renders with the library's own design system; the projds flag re-themes it with the project's tokens, when placing it or later (<id> projds), and <id> no-projds reverts. Adding libraries, updates, and the rest: reference/libraries.