unify Shading; breaking change: Paragraph/Run shading option key type changed to val, and shadow alias removed

This commit is contained in:
Tom Hunkapiller
2021-05-23 04:25:07 +03:00
parent fcc393aca2
commit 496fcb55fa
22 changed files with 70 additions and 162 deletions

View File

@ -1,5 +1,4 @@
export * from "./table";
export * from "./table-cell";
export * from "./table-properties";
export * from "./shading";
export * from "./table-row";

View File

@ -1 +0,0 @@
export * from "./shading";

View File

@ -1,33 +0,0 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { ShadingType, TableShading } from "./shading";
describe("TableShading", () => {
describe("#constructor", () => {
it("should create", () => {
const shading = new TableShading({});
const tree = new Formatter().format(shading);
expect(tree).to.deep.equal({
"w:shd": {
_attr: {},
},
});
});
it("should create with params", () => {
const shading = new TableShading({ val: ShadingType.PERCENT_40, color: "FF0000", fill: "555555" });
const tree = new Formatter().format(shading);
expect(tree).to.deep.equal({
"w:shd": {
_attr: {
"w:color": "FF0000",
"w:fill": "555555",
"w:val": "pct40",
},
},
});
});
});
});

View File

@ -1,64 +0,0 @@
// http://officeopenxml.com/WPtableShading.php
// http://officeopenxml.com/WPtableCellProperties-Shading.php
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
export interface ITableShadingAttributesProperties {
readonly fill?: string;
readonly color?: string;
readonly val?: ShadingType;
}
class TableShadingAttributes extends XmlAttributeComponent<ITableShadingAttributesProperties> {
protected readonly xmlKeys = {
fill: "w:fill",
color: "w:color",
val: "w:val",
};
}
export class TableShading extends XmlComponent {
constructor(attrs: ITableShadingAttributesProperties) {
super("w:shd");
this.root.push(new TableShadingAttributes(attrs));
}
}
export enum ShadingType {
CLEAR = "clear",
DIAGONAL_CROSS = "diagCross",
DIAGONAL_STRIPE = "diagStripe",
HORIZONTAL_CROSS = "horzCross",
HORIZONTAL_STRIPE = "horzStripe",
NIL = "nil",
PERCENT_5 = "pct5",
PERCENT_10 = "pct10",
PERCENT_12 = "pct12",
PERCENT_15 = "pct15",
PERCENT_20 = "pct20",
PERCENT_25 = "pct25",
PERCENT_30 = "pct30",
PERCENT_35 = "pct35",
PERCENT_37 = "pct37",
PERCENT_40 = "pct40",
PERCENT_45 = "pct45",
PERCENT_50 = "pct50",
PERCENT_55 = "pct55",
PERCENT_60 = "pct60",
PERCENT_62 = "pct62",
PERCENT_65 = "pct65",
PERCENT_70 = "pct70",
PERCENT_75 = "pct75",
PERCENT_80 = "pct80",
PERCENT_85 = "pct85",
PERCENT_87 = "pct87",
PERCENT_90 = "pct90",
PERCENT_95 = "pct95",
REVERSE_DIAGONAL_STRIPE = "reverseDiagStripe",
SOLID = "solid",
THIN_DIAGONAL_CROSS = "thinDiagCross",
THIN_DIAGONAL_STRIPE = "thinDiagStripe",
THIN_HORIZONTAL_CROSS = "thinHorzCross",
THIN_REVERSE_DIAGONAL_STRIPE = "thinReverseDiagStripe",
THIN_VERTICAL_STRIPE = "thinVertStripe",
VERTICAL_STRIPE = "vertStripe",
}

View File

@ -1,6 +1,6 @@
import { IgnoreIfEmptyXmlComponent } from "file/xml-components";
import { ITableShadingAttributesProperties, TableShading } from "../shading";
import { IShadingAttributesProperties, Shading } from "../../shading";
import { ITableCellMarginOptions, TableCellMargin } from "./cell-margin/table-cell-margins";
import {
GridSpan,
@ -17,7 +17,7 @@ import {
} from "./table-cell-components";
export interface ITableCellPropertiesOptions {
readonly shading?: ITableShadingAttributesProperties;
readonly shading?: IShadingAttributesProperties;
readonly margins?: ITableCellMarginOptions;
readonly verticalAlign?: VerticalAlign;
readonly textDirection?: TextDirection;
@ -55,7 +55,7 @@ export class TableCellProperties extends IgnoreIfEmptyXmlComponent {
}
if (options.shading) {
this.root.push(new TableShading(options.shading));
this.root.push(new Shading(options.shading));
}
if (options.margins) {

View File

@ -3,7 +3,7 @@ import { expect } from "chai";
import { Formatter } from "export/formatter";
import { BorderStyle } from "file/styles";
import { ShadingType } from "../shading";
import { ShadingType } from "file/shading";
import { TableCell } from "./table-cell";
import { TableCellBorders, TableCellWidth, TextDirection, VerticalAlign, VerticalMergeType, WidthType } from "./table-cell-components";

View File

@ -2,8 +2,9 @@ import { expect } from "chai";
import { Formatter } from "export/formatter";
import { AlignmentType } from "../../paragraph";
import { ShadingType } from "../shading";
import { AlignmentType } from "file/paragraph";
import { ShadingType } from "file/shading";
import { WidthType } from "../table-cell";
import { TableLayoutType } from "./table-layout";
import { TableProperties } from "./table-properties";

View File

@ -2,7 +2,7 @@
import { IgnoreIfEmptyXmlComponent } from "file/xml-components";
import { Alignment, AlignmentType } from "../../paragraph";
import { ITableShadingAttributesProperties, TableShading } from "../shading";
import { IShadingAttributesProperties, Shading } from "../../shading";
import { WidthType } from "../table-cell";
import { ITableBordersOptions, TableBorders } from "./table-borders";
import { ITableCellMarginOptions, TableCellMargin } from "./table-cell-margin";
@ -20,7 +20,7 @@ export interface ITablePropertiesOptions {
readonly layout?: TableLayoutType;
readonly borders?: ITableBordersOptions;
readonly float?: ITableFloatOptions;
readonly shading?: ITableShadingAttributesProperties;
readonly shading?: IShadingAttributesProperties;
readonly style?: string;
readonly alignment?: AlignmentType;
readonly cellMargin?: ITableCellMarginOptions;
@ -56,7 +56,7 @@ export class TableProperties extends IgnoreIfEmptyXmlComponent {
}
if (options.shading) {
this.root.push(new TableShading(options.shading));
this.root.push(new Shading(options.shading));
}
if (options.layout) {