Purrx

Components: one tag, a whole layout

Build React-style components for slides: a template with props, required-prop checks, and expansion of nested components into plain layout before it's laid out.

13 min+35 XPHands-on

A card is a box with a fill, padding, a bold heading in the primary color and some smaller text. Writing that out for every card on every slide is long, and each copy is a chance for the model to change something. So we write it once, give it a name, and let the model use the name.

<Card title="Labor">
  Hard to hire.
</Card>
<box fill="$surface" padding="20" gap="10">
  <text fontSize="$body" bold="true"
        color="$primary">Labor</text>
  <text grow="1" fontSize="$small">
    Hard to hire.
  </text>
</box>
The model writes one line. Before layout, expandAll() swaps it for the template with {title} filled in, so the model never has to repeat padding, colors or sizes.

A component

A has a name, a list of , and a template: ordinary SlideML with {placeholders}.

defining one
const Tag = defineComponent({
  name: "Tag",
  props: { label: { required: true, description: "One or two words" } },
  template: `<box fill="$surface" padding="8"><text bold="true">{label}</text></box>`,
});

Expanding

  • interpolate(text, props) replaces every {name} with the prop's value, or an empty string.
  • expandComponent(node, component) checks required props, then copies the template with props filled into every text and every attribute.
  • expandAll(tree, registry) (written for you) walks the whole tree and expands every component it finds. A template can use other components, so it keeps going until only built-in elements are left.
Going deeper — components are a token budget, not just tidiness

A card written in raw SlideML is roughly 60 tokens. <Card title="Labor">Hard to hire.</Card> is about 12. Over a ten-slide deck that's thousands of output tokens, and output tokens are both the expensive ones and the slow ones, because the model writes them one at a time.

Consistency improves for the same reason. The model can't vary padding or colors it never writes. The production PPTX Lab has over 25 components for exactly this reason.

Key takeaways

  • A component is a named template: <Card title="Labor"> expands into the full layout for a card.
  • Props fill {placeholders} in the template, and missing required props are clear errors.
  • Components make model output shorter, cheaper and far more consistent.

Sign in to run the exercise

Reading is free. Writing code here needs an account so we have somewhere to keep your Gemini key and the +35 XP you are about to earn.