Skip to content

Agent-driven creation of editable, tastefully crafted visual artifacts.

Python
6.0 KB
Raw Blame

Rich Text

Shape text accepts strings, paragraph arrays, and structured runs.

Set Text

shape.text = textValue;
shape.text = paragraphs;
shape.text = structuredRuns;

Text Value Inline Types

type TextValue = string | string[] | StructuredTextInput | Text;

type StructuredTextInput =
  | ParagraphRunsInput
  | StructuredTextParagraphInput
  | Array<ParagraphRunsInput | StructuredTextParagraphInput>;

type ParagraphRunsInput = Array<string | number | TextRunInput>;

type StructuredTextParagraphInput = {
  runs?: ParagraphRunsInput;
  bulletCharacter?: string;
  marginLeft?: number;
  indent?: number;
  spaceBefore?: number;
  spaceAfter?: number;
  styleId?: string;
  paragraphStyle?: Record<string, unknown>;
};

type TextRunInput = {
  run: string;
  textStyle?: {
    bold?: boolean;
    italic?: boolean;
    underline?: string;
    fontSize?: string;
    typeface?: string;
    color?: FillConfig;
  };
  link?: { uri: string; isExternal: boolean; action?: string };
};

Structured run fontSize accepts unit strings such as "20pt" and "28px". Shape text style setters use numeric pixels with fontSize and numeric points with fontSizePt.

Structured Paragraphs

shape.text.set([
  [{ run: "Status", textStyle: { bold: true } }, { run: " review" }],
  {
    bulletCharacter: "•",
    marginLeft: 18 * 12700, // points to EMU
    indent: -10 * 12700,
    runs: [
      "Open the",
      {
        run: " rollout notes",
        textStyle: { underline: "sng", color: "#2563eb" },
        link: { uri: "https://example.com", isExternal: true },
      },
    ],
  },
]);

The paragraph-object form is the non-JSX peer of <paragraph>...</paragraph>. Use it when the text needs paragraph metadata plus authored runs. In the verified runtime, indentation is EMU and paragraph spacing is hundredths of a point, unlike shape-level pixel sizes. See native bullets for the point-based helper and serialization checks.

JSX Rich Text

/** @jsxRuntime automatic */

slide.compose(
  <column width="fill" height="hug" gap={8}>
    <paragraph width="fill" className="text-slate-950 text-2xl leading-tight">
      <run textStyle={{ bold: true }}>Status</run>
      <run> review</run>
    </paragraph>
    <paragraph
      width="fill"
      className="text-slate-950 text-2xl leading-tight"
      bulletCharacter="•"
      marginLeft={18 * 12700}
      indent={-10 * 12700}
    >
      Open the
      <run
        textStyle={{ underline: "sng", color: "#2563eb" }}
        link={{ uri: "https://example.com", isExternal: true }}
      >
        {" rollout notes"}
      </run>
    </paragraph>
  </column>,
  {
    frame: { left: 48, top: 40, width: 864, height: 160 },
    baseUnit: 8,
  },
);

Shape Text Style

shape.text.style = {
  styleName,
  fontSize: fontSizePx,
  color: colorConfig,
  fill: fillConfig,
  outline: lineConfig,
  alignment,
  verticalAlignment,
  autoFit: autoFitMode,
  wrap: wrapMode,
  insets,
};

Use grouped text.style = { ... } for whole-shape text formatting. Use single property setters for focused edits:

shape.text.fontSize = fontSizePx;
shape.text.color = colorConfig;
shape.text.fill = fillConfig;
shape.text.outline = lineConfig;
shape.text.alignment = alignment;
shape.text.verticalAlignment = verticalAlignment;
shape.text.autoFit = autoFitMode;
shape.text.wrap = wrapMode;
shape.text.insets = insets;

shape.text.color uses ColorConfig. shape.text.fill, run textStyle.fill, and text ranges accept the shared FillConfig, including linear and path gradients. shape.text.outline, run textStyle.outline, and text ranges accept LineConfig; the outline line fill can be a solid, pattern, or gradient fill.

shape.text.fill = {
  type: "gradient",
  gradientKind: "linear",
  angleDeg: 0,
  stops: [
    { offset: 0, color: "#ff5a5f" },
    { offset: 100000, color: "#4f46e5" },
  ],
};

Path gradients use the same fill config with gradientKind: "path", pathType, and optional fillRect in Office percentage units.

Text Style Inline Type

type TextStyleConfig = {
  styleName?: string;
  className?: string;
  bold?: boolean;
  italic?: boolean;
  fontSize?: number;
  lineSpacing?: number;
  alignment?: "left" | "center" | "right" | "justify";
  verticalAlignment?: "top" | "middle" | "bottom";
  underline?: string;
  fill?: FillConfig;
  color?: ColorConfig;
  outline?: LineConfig;
  wrap?: "square" | "none";
  autoFit?: "none" | "shrinkText" | "resizeShapeToFitText";
  insets?: { top?: number; right?: number; bottom?: number; left?: number };
  typeface?: string;
};

Ranges

const range = shape.text.get(searchText);
range.bold = isBold;
range.italic = isItalic;
range.fill = fillConfig;
range.outline = lineConfig;
range.link = linkConfig;

const fixedRange = shape.text.getRange(start, length);
fixedRange.style = styleName;

Lists

shape.text = listParagraphs;
shape.text.style = listStyleName;
shape.text.get(itemText).lineSpacing = lineSpacing;

Links

shape.text.get(linkText).link = {
  uri,
  isExternal,
};

Link Inline Type

type LinkConfig = {
  uri: string;
  isExternal: boolean;
  action?: string;
};

Cookbook

// Title with emphasized suffix.
shape.text.set([
  [
    { run: "Revenue", textStyle: { bold: true, color: "#0f172a" } },
    { run: " momentum", textStyle: { color: "#2563eb" } },
  ],
]);
shape.text.style = { fontSize: 44, lineSpacing: 0.92 };
// Bullets with bold lead-ins.
shape.text.set([
  { bulletCharacter: "•", marginLeft: 22 * 12700, indent: -12 * 12700, runs: [{ run: "Quality:", textStyle: { bold: true } }, " defect rate down 31%"] },
  { bulletCharacter: "•", marginLeft: 22 * 12700, indent: -12 * 12700, runs: [{ run: "Speed:", textStyle: { bold: true } }, " p95 latency under target"] },
]);
// Edit one phrase inside imported text.
const range = shape.text.get("legacy workflow");
range.text = "new workflow";
range.className = "text-emerald-700 font-bold";