Skip to content

Commit

Permalink
Ad xml correct creator image 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinatzo committed Oct 8, 2023
1 parent 78c7748 commit fb3068a
Showing 1 changed file with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,82 +44,84 @@ export function extractStyleNames(
return styleNameProps;
}

export type TextRowProps = TextCellProps & {};
export type TextRowProps = Omit<TextCellProps, "style"> & { readonly cellStyle?: TableCellStyle.TableCellStyle };

export function TextRow(props: TextRowProps, styleNameTypes: Record<string, string>): TableRow.TableRow {
return TableRow.create({}, [TextCell(props, styleNameTypes)]);
return TableRow.create({}, [TextCell({ ...props, style: props.cellStyle }, styleNameTypes)]);
}

export type TextCellProps = TextParagraphProps & {
export type TextCellProps = Omit<TextParagraphProps, "style"> & {
readonly columnSpan?: number;
readonly rowSpan?: number;
readonly cellStyle?: TableCellStyle.TableCellStyle;
readonly style?: TableCellStyle.TableCellStyle;
readonly paragraphStyle?: ParagraphStyle.ParagraphStyle;
readonly styleNames?: string;
};

export function TextCell(props: TextCellProps, styleNameTypes: Record<string, string>): TableCell.TableCell {
const { text, textStyle, paragraphStyle, cellStyle, columnSpan, rowSpan } = props;
const { text, textStyle, paragraphStyle, style, columnSpan, rowSpan } = props;
const styleNames = extractStyleNames(props.styleNames, styleNameTypes);
const textRun = TextRun.create({ text, style: textStyle, styleName: styleNames.TextStyle });
const paragraph = Paragraph.create({ style: paragraphStyle, styleName: styleNames.ParagraphStyle }, [textRun]);
return TableCell.create({ columnSpan, rowSpan, style: cellStyle, styleName: styleNames.TableCellStyle }, [paragraph]);
return TableCell.create({ columnSpan, rowSpan, style, styleName: styleNames.TableCellStyle }, [paragraph]);
}

export type TextParagraphProps = {
readonly text: string;
readonly style?: ParagraphStyle.ParagraphStyle;
readonly textStyle?: TextStyle.TextStyle;
readonly paragraphStyle?: ParagraphStyle.ParagraphStyle;
readonly styleNames?: string;
};

export function TextParagraph(props: TextParagraphProps, styleNameTypes: Record<string, string>): Paragraph.Paragraph {
const { text, textStyle, paragraphStyle } = props;
const { text, textStyle, style } = props;
const styleNames = extractStyleNames(props.styleNames, styleNameTypes);
const textRun = TextRun.create({ text, style: textStyle, styleName: styleNames.TextStyle });
return Paragraph.create({ style: paragraphStyle, styleName: styleNames.ParagraphStyle }, [textRun]);
return Paragraph.create({ style, styleName: styleNames.ParagraphStyle }, [textRun]);
}

export type ImageResource = ADImageResource.ImageResource & { readonly width?: number; readonly height?: number };

export type ImageRowProps = ImageCellProps & {};
export type ImageRowProps = Omit<ImageCellProps, "style"> & { readonly cellStyle?: TableCellStyle.TableCellStyle };

export function ImageRow(props: ImageCellProps, styleNameTypes: Record<string, string>): TableRow.TableRow {
return TableRow.create({}, [ImageCell(props, styleNameTypes)]);
export function ImageRow(props: ImageRowProps, styleNameTypes: Record<string, string>): TableRow.TableRow {
return TableRow.create({}, [ImageCell({ ...props, style: props.cellStyle }, styleNameTypes)]);
}

export type ImageCellProps = {
readonly cellStyle?: TableCellStyle.TableCellStyle;
export type ImageCellProps = Omit<ImageParagraphProps, "style"> & {
readonly style?: TableCellStyle.TableCellStyle;
readonly paragraphStyle?: ParagraphStyle.ParagraphStyle;
readonly columnSpan?: number;
readonly rowSpan?: number;
} & ImageParagraphProps;
};

export function ImageCell(props: ImageCellProps, styleNameTypes: Record<string, string>): TableCell.TableCell {
const { imageResource, width, height, paragraphStyle, cellStyle, columnSpan, rowSpan } = props;
const { imageResource, width, height, paragraphStyle, style, columnSpan, rowSpan } = props;
const styleNames = extractStyleNames(props.styleNames, styleNameTypes);
const imageElement = imageResource && Image.create({ imageResource, width, height });
const pararaphProps = { style: paragraphStyle, styleName: styleNames.ParagraphStyle };
const paragraph = imageElement
? Paragraph.create(pararaphProps, [imageElement])
: Paragraph.create(pararaphProps, [ImageMissing]);
return TableCell.create({ columnSpan, rowSpan, style: cellStyle, styleName: styleNames.TableCellStyle }, [paragraph]);
return TableCell.create({ columnSpan, rowSpan, style, styleName: styleNames.TableCellStyle }, [paragraph]);
}

export type ImageParagraphProps = {
readonly imageResource: ImageResource;
readonly width: number;
readonly height: number;
readonly paragraphStyle?: ParagraphStyle.ParagraphStyle;
readonly style?: ParagraphStyle.ParagraphStyle;
readonly styleNames?: string;
};

export function ImageParagraph(
props: ImageParagraphProps,
styleNameTypes: Record<string, string>
): Paragraph.Paragraph | undefined {
const { imageResource, width, height, paragraphStyle } = props;
const { imageResource, width, height, style } = props;
const styleNames = extractStyleNames(props.styleNames, styleNameTypes);
const imageElement = imageResource && Image.create({ imageResource, width, height });
const pararaphProps = { style: paragraphStyle, styleName: styleNames.ParagraphStyle };
const pararaphProps = { style, styleName: styleNames.ParagraphStyle };
return imageElement
? Paragraph.create(pararaphProps, [imageElement])
: Paragraph.create(pararaphProps, [ImageMissing]);
Expand Down

0 comments on commit fb3068a

Please sign in to comment.