import type PptxGenJs from "pptxgenjs" ; import React from "react" ; import { InternalImageSrc , InternalPresentation , InternalText , InternalTextPart , InternalTextPartBaseStyle , } from "./normalizer" ; import { ChildElement } from "./util" ; export enum NodeTypes { SHAPE = "shape" , LINE = "line" , TEXT_LINK = "text-link" , TEXT_BULLET = "text-bullet" , SLIDE = "slide" , MASTER_SLIDE = "master-slide" , IMAGE = "image" , PRESENTATION = "presentation" } type VisualBaseProps = { style ? : { x : number | string ; y : number | string ; w : number | string ; h : number | string ; } ; } ; interface TextNodeBaseStyle extends Omit < InternalTextPartBaseStyle , "color" > { color ? : string ; } type TextNodeBaseProps = Pick < InternalTextPart , "rtlMode" | "lang" > ; export type TextLinkProps = TextNodeBaseProps & { children : string ; tooltip ? : string ; style ? : TextNodeBaseStyle ; } & ( { url : string ; } | { slide : number ; } ) ; const TextLink = NodeTypes . TEXT_LINK as unknown as React . FC ; export const isTextLink = ( el ) : el is React . ReactElement < TextLinkProps > => { return el . type === NodeTypes . TEXT_LINK ; } ; export type TextBulletProps = TextNodeBaseProps & { children : TextChild ; style ? : TextNodeBaseStyle ; } & Omit < Exclude < PptxGenJs . TextBaseProps [ "bullet" ] , boolean | undefined > , "style" > ; const TextBullet = NodeTypes . TEXT_BULLET as unknown as React . FC ; export const isTextBullet = ( el ) : el is React . ReactElement < TextBulletProps > => { return el . type === NodeTypes . TEXT_BULLET ; } ; export type TextChild = string | number | ChildElement < TextLinkProps > | ChildElement < TextBulletProps > | TextChild [ ] ; export type TextProps = TextNodeBaseProps & { children ? : TextChild ; style ? : Partial < Exclude < VisualBaseProps [ "style" ] , undefined > > & TextNodeBaseStyle & { align ? : InternalText [ "style" ] [ "align" ] ; verticalAlign ? : InternalText [ "style" ] [ "verticalAlign" ] ; } ; } ; const TextFn = ( ) => null ; TextFn . prototype . isPptxTextElement = true ; TextFn . prototype . Link = TextLink ; TextFn . prototype . Bullet = TextBullet ; export const Text = Object . assign ( TextFn , { Link : TextLink , Bullet : TextBullet , } ) ; ( Text . prototype as any ) . isPptxTextElement = true ; export const isText = ( el ) : el is React . FunctionComponentElement < TextProps > => { return el . type instanceof Function && el . type . prototype ?. isPptxTextElement ; } ; export type ImageProps = VisualBaseProps & { src : InternalImageSrc ; style ? : { deprecated backgroundSize ? : "contain" | "cover" ; sizing ? : { fit : "contain" | "cover" | "crop" ; imageWidth ? : number ; imageHeight ? : number ; } ; } ; } ; export const Image = NodeTypes . IMAGE as unknown as React . FC ; export const isImage = ( el ) : el is React . ReactElement < ImageProps > => { return el . type === NodeTypes . IMAGE ; } ; export type ShapeProps = VisualBaseProps & { type : keyof typeof PptxGenJs . ShapeType ; children ? : TextChild ; style ? : { backgroundColor ? : string ; borderWidth ? : number ; borderColor ? : string ; } ; } ; export const Shape = NodeTypes . SHAPE as unknown as React . FC ; export const isShape = ( el ) : el is React . ReactElement < ShapeProps > => { return el . type === NodeTypes . SHAPE ; } ; export type LineProps = { x1 : number ; x2 : number ; y1 : number ; y2 : number ; style ? : { color ? : string ; width ? : number ; } ; } ; export const Line = NodeTypes . LINE as unknown as React . FC ; export const isLine = ( el ) : el is React . ReactElement < LineProps > => { return el . type === NodeTypes . LINE ; } ; export type VisualProps = TextProps | ImageProps | ShapeProps ; export type Visual = typeof Text | typeof Image | typeof Shape ; export type SlideProps = { children ? : ChildElement < VisualProps > ; masterName ? : string ; hidden ? : boolean ; style ? : { backgroundColor ? : string ; backgroundImage ? : InternalImageSrc ; } ; } ; export const Slide = NodeTypes . SLIDE as unknown as React . FC ; export type MasterSlideProps = { name : string ; children ? : ChildElement < VisualProps > ; style ? : { backgroundColor ? : string ; backgroundImage ? : InternalImageSrc ; } ; } ; export const MasterSlide = NodeTypes . MASTER_SLIDE as unknown as React . FC ; export type PresentationProps = Omit < InternalPresentation , "slides" | "masterSlides" | "layout" > & { children ? : ChildElement < SlideProps | MasterSlideProps > ; layout ? : InternalPresentation [ "layout" ] ; } ; export const Presentation = NodeTypes . PRESENTATION as unknown as React . FC ; export const isReactPPTXComponent = ( node ) : boolean => Object . values ( NodeTypes ) . includes ( node . type as NodeTypes ) || isText ( node ) ;