pptx custom
中文文档
Source: README.mdOpen package directory
pptx-custom
Utilities for customizing json2pptx JSON decks in two stages:
- Content stage: map backend slide content into a template deck.
- Theme stage: replace theme colors/font/background and apply scoped media.
Install
npm i pptx-custom
Exports
applyCustomContent(template, input)parseCustomContent(raw)applyCustomContentToTemplate(template, slides)applyCustomTheme(deck, themeInput)
Types are also exported, including:
CustomSlide, Presentation, PresentationData, PresentationTheme, PptxCustomContentInput, PptxCustomThemeInput,
PptxCustomOptions, TemplateJson, TemplateJsonSlide, TemplateJsonElement,
TemplateJsonTheme.
Quick Start
import {
applyCustomContent,
applyCustomTheme,
parseCustomContent,
applyCustomContentToTemplate
} from 'pptx-custom'
const withContent = applyCustomContent(templateJSON, customContent)
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)
Custom Content Input
parseCustomContent and applyCustomContent support:
- NDJSON (one slide per line)
- JSON array of slides
- JSON object with a
slidesarray - JSON object containing a single slide (with
type)
Supported slide types:
covercontentstransitioncontentend
Legacy aliases accepted in input:
agenda->contentssection->transitionending->end
Example custom content:
{"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"}
Theme Input
applyCustomTheme accepts PptxCustomThemeInput:
themeColors: string[](uses first 6)fontColor: stringbackgroundColor?: stringbackgroundImage?: { src, scope, width?, height? }logoImage?: { src, scope, position, width?, height? }clearBackgroundImage?: booleanclearLogoImage?: boolean
scope keys:
cover | contents | transition | content | end
Behavior Notes
- Both
applyCustomContentandapplyCustomThemerun throughjson2pptx-schemaparsing/normalization before returning. applyCustomContentselects template slides bytype, and forcontents/contentprefers layouts with the closest capacity to the requested item count.applyCustomContentnormalizes logo elements (imageType: "logo") to stay within top margins and removes logo clipping.applyCustomThemeinserts scoped background images as slide elements withimageType: "background"and logo images withimageType: "logo".- When both
backgroundImageandbackgroundColorare provided, background color is applied as a 50% alpha overlay color on targeted slides. clearBackgroundImagealso clears logo images in current behavior.