Pipto Docs

pptx custom

中文文档

pptx-custom来源: README.zh-CN.md打开 package 目录

English

用于对 json2pptx JSON deck 进行两阶段定制:

  • 内容阶段:将后端内容映射到模板 deck。
  • 主题阶段:替换主题色/字体/背景,并按范围应用媒体资源。

安装

npm i pptx-custom

导出 API

  • applyCustomContent(template, input)
  • parseCustomContent(raw)
  • applyCustomContentToTemplate(template, slides)
  • applyCustomTheme(deck, themeInput)

同时导出类型,包括: CustomSlidePresentationPresentationDataPresentationThemePptxCustomContentInputPptxCustomThemeInputPptxCustomOptionsTemplateJsonTemplateJsonSlideTemplateJsonElementTemplateJsonTheme

快速开始

import {
  applyCustomContent,
  applyCustomTheme,
  parseCustomContent,
  applyCustomContentToTemplate
} from 'pptx-custom'

const withContent = applyCustomContent(templateJSON, backendText)

const withTheme = applyCustomTheme(withContent, {
  themeColors: ['#111111', '#333333', '#555555', '#777777', '#999999', '#BBBBBB'],
  fontColor: '#222222',
  backgroundColor: '#FFFFFF',
  backgroundImage: {
    src: 'https://example.com/background.png',
    scope: {
      cover: false,
      contents: true,
      transition: true,
      content: true,
      end: false
    }
  },
  logoImage: {
    src: 'https://example.com/logo.png',
    position: 'right',
    scope: {
      cover: true,
      contents: true,
      transition: true,
      content: true,
      end: true
    }
  }
})

const slides = parseCustomContent(customContent)
const withContentDirect = applyCustomContentToTemplate(templateJSON, slides)

自定义内容输入格式

parseCustomContentapplyCustomContent 支持:

  1. NDJSON(每行一个 slide)
  2. JSON slide 数组
  3. slides 字段的 JSON 对象
  4. 单个 slide JSON 对象(包含 type

支持的 slide 类型:

  • cover
  • contents
  • transition
  • content
  • end

兼容的历史别名:

  • agenda -> contents
  • section -> transition
  • ending -> end

自定义内容示例:

{"type":"cover","data":{"title":"Title","text":"Subtitle"}}
{"type":"contents","data":{"items":["Part A","Part B"]}}
{"type":"transition","data":{"title":"Part A","text":"Section intro"}}
{"type":"content","data":{"title":"Topic","items":[{"title":"Point","text":"Detail"}]}}
{"type":"end"}

主题输入

applyCustomTheme 接收 PptxCustomThemeInput

  • themeColors: string[](最多使用前 6 个)
  • fontColor: string
  • backgroundColor?: string
  • backgroundImage?: { src, scope, width?, height? }
  • logoImage?: { src, scope, position, width?, height? }
  • clearBackgroundImage?: boolean
  • clearLogoImage?: boolean

scope 可选键: cover | contents | transition | content | end

行为说明

  • applyCustomContentapplyCustomTheme 都会在返回前经过 json2pptx-schema 的解析与规范化。
  • applyCustomContenttype 选模板页;对 contents/content 会优先选择 与输入条目数容量最接近的布局。
  • applyCustomContent 会规范化 logo 元素(imageType: "logo"): 保持在顶部边距内,并移除 logo 裁剪配置。
  • applyCustomTheme 会将背景图以元素形式写入(imageType: "background"), 并将 logo 以 imageType: "logo" 写入。
  • 当同时提供 backgroundImagebackgroundColor 时,会在目标页应用 50% 透明度的背景色叠加效果。
  • 当前行为下,clearBackgroundImage 也会同时清除 logo 图片。