/** * PptxGenJS: Slide Class */ import { CHART_NAME, SHAPE_NAME } from './core-enums' import { AddSlideProps, BackgroundProps, HexColor, IChartMulti, IChartOpts, IChartOptsLib, IOptsChartData, ISlideObject, ISlideRel, ISlideRelChart, ISlideRelMedia, ImageProps, MediaProps, PresLayout, PresSlide, ShapeProps, SlideLayout, SlideNumberProps, TableProps, TableRow, TextProps, TextPropsOptions, } from './core-interfaces' import * as genObj from './gen-objects' export default class Slide { private readonly _setSlideNum: (value: SlideNumberProps) => void public addSlide: (options?: AddSlideProps) => PresSlide public getSlide: (slideNum: number) => PresSlide public _name: string public _presLayout: PresLayout public _rels: ISlideRel[] public _relsChart: ISlideRelChart[] public _relsMedia: ISlideRelMedia[] public _rId: number public _slideId: number public _slideLayout: SlideLayout public _slideNum: number public _slideNumberProps: SlideNumberProps public _slideObjects: ISlideObject[] public _newAutoPagedSlides: PresSlide[] constructor(params: { addSlide: (options?: AddSlideProps) => PresSlide getSlide: (slideNum: number) => PresSlide presLayout: PresLayout setSlideNum: (value: SlideNumberProps) => void slideId: number slideRId: number slideNumber: number slideLayout?: SlideLayout }) { this.addSlide = params.addSlide this.getSlide = params.getSlide this._name = `Slide ${params.slideNumber}` this._presLayout = params.presLayout this._rId = params.slideRId this._rels = [] this._relsChart = [] this._relsMedia = [] this._setSlideNum = params.setSlideNum this._slideId = params.slideId this._slideLayout = params.slideLayout || null this._slideNum = params.slideNumber this._slideObjects = [] /** NOTE: Slide Numbers: In order for Slide Numbers to function they need to be in all 3 files: master/layout/slide * `defineSlideMaster` and `addNewSlide.slideNumber` will add {slideNumber} to `this.masterSlide` and `this.slideLayouts` * so, lastly, add to the Slide now. */ this._slideNumberProps = this._slideLayout?._slideNumberProps ? this._slideLayout._slideNumberProps : null } /** * Background color * @type {string|BackgroundProps} * @deprecated in v3.3.0 - use `background` instead */ private _bkgd: string | BackgroundProps public set bkgd(value: string | BackgroundProps) { this._bkgd = value if (!this._background || !this._background.color) { if (!this._background) this._background = {} if (typeof value === 'string') this._background.color = value } } public get bkgd(): string | BackgroundProps { return this._bkgd } /** * Background color or image * @type {BackgroundProps} * @example solid color `background: { color:'FF0000' }` * @example color+trans `background: { color:'FF0000', transparency:0.5 }` * @example base64 `background: { data:'image/png;base64,ABC[...]123' }` * @example url `background: { path:'https://some.url/image.jpg'}` * @since v3.3.0 */ private _background: BackgroundProps public set background(props: BackgroundProps) { this._background = props // Add background (image data/path must be captured before `exportPresentation()` is called) if (props) genObj.addBackgroundDefinition(props, this) } public get background(): BackgroundProps { return this._background } /** * Default font color * @type {HexColor} */ private _color: HexColor public set color(value: HexColor) { this._color = value } public get color(): HexColor { return this._color } /** * @type {boolean} */ private _hidden: boolean public set hidden(value: boolean) { this._hidden = value } public get hidden(): boolean { return this._hidden } /** * @type {SlideNumberProps} */ public set slideNumber(value: SlideNumberProps) { // NOTE: Slide Numbers: In order for Slide Numbers to function they need to be in all 3 files: master/layout/slide this._slideNumberProps = value this._setSlideNum(value) } public get slideNumber(): SlideNumberProps { return this._slideNumberProps } public get newAutoPagedSlides(): PresSlide[] { return this._newAutoPagedSlides } /** * Add chart to Slide * @param {CHART_NAME|IChartMulti[]} type - chart type * @param {object[]} data - data object * @param {IChartOpts} options - chart options * @return {Slide} this Slide */ addChart(type: CHART_NAME | IChartMulti[], data: IOptsChartData[], options?: IChartOpts): Slide { // FUTURE: TODO-VERSION-4: Remove first arg - only take data and opts, with "type" required on opts // Set `_type` on IChartOptsLib as its what is used as object is passed around const optionsWithType: IChartOptsLib = options || {} optionsWithType._type = type genObj.addChartDefinition(this, type, data, options) return this } /** * Add image to Slide * @param {ImageProps} options - image options * @return {Slide} this Slide */ addImage(options: ImageProps): Slide { genObj.addImageDefinition(this, options) return this } /** * Add media (audio/video) to Slide * @param {MediaProps} options - media options * @return {Slide} this Slide */ addMedia(options: MediaProps): Slide { genObj.addMediaDefinition(this, options) return this } /** * Add speaker notes to Slide * @docs https://gitbrent.github.io/PptxGenJS/docs/speaker-notes.html * @param {string} notes - notes to add to slide * @return {Slide} this Slide */ addNotes(notes: string): Slide { genObj.addNotesDefinition(this, notes) return this } /** * Add shape to Slide * @param {SHAPE_NAME} shapeName - shape name * @param {ShapeProps} options - shape options * @return {Slide} this Slide */ addShape(shapeName: SHAPE_NAME, options?: ShapeProps): Slide { // NOTE: As of v3.1.0,