@artifact-kit/pptxgenjs-jsx

中文文档
0.1.6发布于 2026/04/29MITTypeScriptESM + CJS近 30 天下载 2.9万

LLM-friendly JSX declaration layer for PptxGenJS.

原始使用文档
文档目录8 节
  1. What It Can Produce
  2. Install
  3. Basic Usage
  4. HTML to Editable PPTX
  5. When To Use It
  6. Documentation Layout
  7. Build Outputs
  8. Development

@artifact-kit/pptxgenjs-jsx

Write editable PowerPoint decks as JSX. Recreate rendered HTML and SVG as native .pptx objects when a screenshot is not good enough.

This package wraps PptxGenJS with an LLM-friendly component model:

  • Describe a deck as a readable tree: <Deck><Slide><Text /></Slide></Deck>.
  • Use dedicated components for text, shapes, images, tables, charts, lines, and raw PptxGenJS escape hatches.
  • Validate the structure before writing a file.
  • In browser workflows, measure real DOM nodes and map them into PowerPoint coordinates.
  • Export editable PowerPoint objects instead of flattening a page into one bitmap.

What It Can Produce

The attention example is the clearest proof in this repo. It starts with a 1600x900 HTML/Tailwind/SVG lecture slide, measures the rendered DOM in the browser, then rebuilds the slide as editable PowerPoint text, shapes, lines, arrows, chart objects, and diagram parts.

Source HTML:

Source HTML slide

Generated PPTX preview:

Generated PPTX preview

Editable native PowerPoint objects:

Editable native PowerPoint objects

Open the exporter at examples/attention/exporter.html. It exercises DOM measurement, SVG primitive mapping, LineBetween, CustomGeometry, native chart output, validation, and browser download behavior.

Install

pnpm add @artifact-kit/pptxgenjs-jsx

Basic Usage

Use JSX when you already know the slide structure and coordinates:

/** @jsxImportSource @artifact-kit/pptxgenjs-jsx */
import { BarChart, Deck, RoundRect, Slide, Text, renderPptx, validateDeck } from "@artifact-kit/pptxgenjs-jsx";

const deck = (
  <Deck title="Q1 Review" layout={{ name: "WIDE", width: 13.333, height: 7.5 }}>
    <Slide background={{ color: "FFFFFF" }}>
      <RoundRect x={0.7} y={0.6} w={3.8} h={0.6} fill={{ color: "EEF2FF" }} />
      <Text x={0.9} y={0.78} w={3.4} h={0.3} fontSize={18} bold>Q1 Review</Text>
      <BarChart data={[{ name: "Revenue", labels: ["Jan", "Feb", "Mar"], values: [12, 18, 24] }]} x={6.5} y={1} w={5.5} h={3} />
    </Slide>
  </Deck>
);

const issues = validateDeck(deck);
if (issues.some((issue) => issue.level === "error")) throw new Error(JSON.stringify(issues, null, 2));
await renderPptx(deck, { fileName: "q1-review.pptx" });

If you do not want a JSX transform, use pptxElement(Component, props, ...children).

HTML to Editable PPTX

For local tools and agent-generated exporters, you can write JSX directly in the browser with the IIFE build plus Babel Standalone. This is useful when the source of truth is a rendered HTML page, dashboard, report, or slide-like document.

The workflow is:

  1. Keep the source HTML clean.
  2. Copy it into an exporter page.
  3. Make every slide/page visible in one vertical document.
  4. Add data-ak-slide, data-ak-width, data-ak-height, data-ak-px-per-in, and data-ak-measure markers.
  5. On export, call measureArtifacts({ document }).
  6. Use readSlideLayout(), readPptBox(), and readFontPt() to place native PowerPoint objects.
  7. Run validateDeck(), then renderPptx().

Minimal browser pattern:

<script src="https://unpkg.com/@artifact-kit/pptxgenjs-jsx/dist/pptxgenjs-jsx.browser.iife.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script type="text/babel" data-presets="typescript,react">
  /** @jsx pptxElement */
  const {
    Deck,
    Slide,
    Text,
    measureArtifacts,
    pptxElement,
    readFontPt,
    readPptBox,
    readSlideLayout,
    renderPptx,
    validateDeck,
  } = window.ArtifactKitPptxGenJsx;

  document.querySelector("#export-pptx").addEventListener("click", async () => {
    await measureArtifacts({ document });

    const deck = (
      <Deck title="Measured deck" layout={readSlideLayout("slide-1")}>
        <Slide background={{ color: "FFFFFF" }}>
          <Text {...readPptBox("title-1")} fontSize={readFontPt("title-1")} bold margin={0}>
            {document.querySelector('[data-ak-measure="title-1"]').textContent.trim()}
          </Text>
        </Slide>
      </Deck>
    );

    const issues = validateDeck(deck);
    if (issues.some((issue) => issue.level === "error")) throw new Error(JSON.stringify(issues, null, 2));
    await renderPptx(deck, { fileName: "measured-export.pptx" });
  });
</script>

See examples/browser-jsx.html for a small browser example and examples/attention/exporter.html for the full measure-first HTML-to-PPTX example.

When To Use It

Use this package when you need:

  • Editable PowerPoint files generated from TypeScript, browser tools, or agent-authored code.
  • A declarative surface that is easier for LLMs to write and review than ordered imperative calls.
  • Native charts, tables, shapes, images, text runs, lines, and custom geometry.
  • HTML-to-PPTX reconstruction where layout comes from real browser measurement.
  • Machine-readable docs and a component manifest for coding agents.

Do not use it when a single screenshot image is the intended final artifact. This package is most valuable when the generated deck must remain editable.

Documentation Layout

This repo is organized for both humans and agents:

Build Outputs

OutputFile
Node ESMdist/pptxgenjs-jsx.es.js
Node CJSdist/pptxgenjs-jsx.cjs
Browser ESMdist/pptxgenjs-jsx.browser.es.js
Browser IIFEdist/pptxgenjs-jsx.browser.iife.js global ArtifactKitPptxGenJsx

Development

pnpm install
pnpm docs:generate
pnpm test
pnpm test:attention

版本与发布记录

@artifact-kit/pptxgenjs-jsx 共发布 4 个版本,首次发布于 2026/04/29;过去 12 个月发布了 4 个版本。

版本发布日期距今
0.1.6latest2026/04/296 个月前
0.1.52026/04/296 个月前
0.1.12026/04/296 个月前
0.1.02026/04/296 个月前

关于 @artifact-kit/pptxgenjs-jsx 的常见问题

@artifact-kit/pptxgenjs-jsx 是什么?

LLM-friendly JSX declaration layer for PptxGenJS.

如何安装 @artifact-kit/pptxgenjs-jsx?

在项目目录运行 npm install @artifact-kit/pptxgenjs-jsx,或使用 pnpm add / yarn add / bun add。

@artifact-kit/pptxgenjs-jsx 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@artifact-kit/pptxgenjs-jsx 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@artifact-kit/pptxgenjs-jsx 可以商用吗?

@artifact-kit/pptxgenjs-jsx 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@artifact-kit/pptxgenjs-jsx 的下载量有多少?

根据 npm 官方下载统计,@artifact-kit/pptxgenjs-jsx 在 2026/10/07 – 2026/11/05 这 30 天内被下载 29,120 次,日均约 971 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@artifact-kit/pptxgenjs-jsx 还在维护吗?

最新版本 0.1.6 发布于 2026/04/29(6 个月前);至今共发布 4 个版本,其中过去 12 个月发布了 4 个;首次发布于 2026/04/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。