2021-05-23 07:14:00 +03:00
|
|
|
import { BorderElement, IBorderOptions } from "file/border";
|
2021-05-24 12:00:04 +03:00
|
|
|
import { decimalNumber } from "file/values";
|
2019-04-09 05:27:18 -04:00
|
|
|
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
2018-05-04 15:56:28 +02:00
|
|
|
|
2021-05-24 12:00:04 +03:00
|
|
|
// <xsd:complexType name="CT_TcBorders">
|
|
|
|
// <xsd:sequence>
|
|
|
|
// <xsd:element name="top" type="CT_Border" minOccurs="0"/>
|
|
|
|
// <xsd:element name="start" type="CT_Border" minOccurs="0"/>
|
|
|
|
// <xsd:element name="left" type="CT_Border" minOccurs="0"/>
|
|
|
|
// <xsd:element name="bottom" type="CT_Border" minOccurs="0"/>
|
|
|
|
// <xsd:element name="end" type="CT_Border" minOccurs="0"/>
|
|
|
|
// <xsd:element name="right" type="CT_Border" minOccurs="0"/>
|
|
|
|
// <xsd:element name="insideH" type="CT_Border" minOccurs="0"/>
|
|
|
|
// <xsd:element name="insideV" type="CT_Border" minOccurs="0"/>
|
|
|
|
// <xsd:element name="tl2br" type="CT_Border" minOccurs="0"/>
|
|
|
|
// <xsd:element name="tr2bl" type="CT_Border" minOccurs="0"/>
|
|
|
|
// </xsd:sequence>
|
|
|
|
// </xsd:complexType>
|
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
export interface ITableCellBorders {
|
2021-05-23 07:14:00 +03:00
|
|
|
readonly top?: IBorderOptions;
|
|
|
|
readonly start?: IBorderOptions;
|
|
|
|
readonly left?: IBorderOptions;
|
|
|
|
readonly bottom?: IBorderOptions;
|
|
|
|
readonly end?: IBorderOptions;
|
|
|
|
readonly right?: IBorderOptions;
|
2021-05-22 04:03:40 +03:00
|
|
|
}
|
|
|
|
|
2019-04-09 05:27:18 -04:00
|
|
|
export class TableCellBorders extends IgnoreIfEmptyXmlComponent {
|
2021-05-22 04:03:40 +03:00
|
|
|
constructor(options: ITableCellBorders) {
|
2018-05-04 15:56:28 +02:00
|
|
|
super("w:tcBorders");
|
2019-03-05 10:39:18 +01:00
|
|
|
|
2021-05-22 04:03:40 +03:00
|
|
|
if (options.top) {
|
2021-05-23 07:14:00 +03:00
|
|
|
this.root.push(new BorderElement("w:top", options.top));
|
2021-05-22 04:03:40 +03:00
|
|
|
}
|
|
|
|
if (options.start) {
|
2021-05-23 07:14:00 +03:00
|
|
|
this.root.push(new BorderElement("w:start", options.start));
|
2021-05-22 04:03:40 +03:00
|
|
|
}
|
|
|
|
if (options.left) {
|
2021-05-23 07:14:00 +03:00
|
|
|
this.root.push(new BorderElement("w:left", options.left));
|
2021-05-22 04:03:40 +03:00
|
|
|
}
|
|
|
|
if (options.bottom) {
|
2021-05-23 07:14:00 +03:00
|
|
|
this.root.push(new BorderElement("w:bottom", options.bottom));
|
2021-05-22 04:03:40 +03:00
|
|
|
}
|
|
|
|
if (options.end) {
|
2021-05-23 07:14:00 +03:00
|
|
|
this.root.push(new BorderElement("w:end", options.end));
|
2021-05-22 04:03:40 +03:00
|
|
|
}
|
|
|
|
if (options.right) {
|
2021-05-23 07:14:00 +03:00
|
|
|
this.root.push(new BorderElement("w:right", options.right));
|
2021-05-22 04:03:40 +03:00
|
|
|
}
|
2019-03-05 10:39:18 +01:00
|
|
|
}
|
2018-05-04 15:56:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attributes fot the GridSpan element.
|
|
|
|
*/
|
2018-11-02 02:51:57 +00:00
|
|
|
class GridSpanAttributes extends XmlAttributeComponent<{ readonly val: number }> {
|
|
|
|
protected readonly xmlKeys = { val: "w:val" };
|
2018-05-04 15:56:28 +02:00
|
|
|
}
|
|
|
|
|
2021-05-24 12:00:04 +03:00
|
|
|
// <xsd:complexType name="CT_TcPrBase">
|
|
|
|
// ...
|
|
|
|
// <xsd:element name="gridSpan" type="CT_DecimalNumber" minOccurs="0"/>
|
|
|
|
// </xsd>
|
2018-05-04 15:56:28 +02:00
|
|
|
/**
|
|
|
|
* GridSpan element. Should be used in a table cell. Pass the number of columns that this cell need to span.
|
|
|
|
*/
|
|
|
|
export class GridSpan extends XmlComponent {
|
|
|
|
constructor(value: number) {
|
|
|
|
super("w:gridSpan");
|
|
|
|
|
|
|
|
this.root.push(
|
|
|
|
new GridSpanAttributes({
|
2021-05-24 12:00:04 +03:00
|
|
|
val: decimalNumber(value),
|
2018-05-04 15:56:28 +02:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Vertical merge types.
|
|
|
|
*/
|
2019-09-26 02:03:17 +01:00
|
|
|
export enum VerticalMergeType {
|
2018-05-04 15:56:28 +02:00
|
|
|
/**
|
|
|
|
* Cell that is merged with upper one.
|
|
|
|
*/
|
|
|
|
CONTINUE = "continue",
|
|
|
|
/**
|
|
|
|
* Cell that is starting the vertical merge.
|
|
|
|
*/
|
|
|
|
RESTART = "restart",
|
|
|
|
}
|
|
|
|
|
2019-09-26 02:03:17 +01:00
|
|
|
class VerticalMergeAttributes extends XmlAttributeComponent<{ readonly val: VerticalMergeType }> {
|
2018-11-02 02:51:57 +00:00
|
|
|
protected readonly xmlKeys = { val: "w:val" };
|
2018-05-04 15:56:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Vertical merge element. Should be used in a table cell.
|
|
|
|
*/
|
2019-09-26 02:03:17 +01:00
|
|
|
export class VerticalMerge extends XmlComponent {
|
|
|
|
constructor(value: VerticalMergeType) {
|
2018-05-04 15:56:28 +02:00
|
|
|
super("w:vMerge");
|
|
|
|
|
|
|
|
this.root.push(
|
2019-09-26 02:03:17 +01:00
|
|
|
new VerticalMergeAttributes({
|
2018-05-04 15:56:28 +02:00
|
|
|
val: value,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-10 10:36:25 -07:00
|
|
|
export enum TextDirection {
|
2020-05-13 02:51:47 +01:00
|
|
|
BOTTOM_TO_TOP_LEFT_TO_RIGHT = "btLr",
|
|
|
|
LEFT_TO_RIGHT_TOP_TO_BOTTOM = "lrTb",
|
|
|
|
TOP_TO_BOTTOM_RIGHT_TO_LEFT = "tbRl",
|
2020-05-10 10:36:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
class TDirectionAttributes extends XmlAttributeComponent<{ readonly val: TextDirection }> {
|
|
|
|
protected readonly xmlKeys = { val: "w:val" };
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Text Direction within a table cell
|
|
|
|
*/
|
|
|
|
export class TDirection extends XmlComponent {
|
|
|
|
constructor(value: TextDirection) {
|
|
|
|
super("w:textDirection");
|
|
|
|
|
|
|
|
this.root.push(
|
|
|
|
new TDirectionAttributes({
|
|
|
|
val: value,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|