2022-12-18 00:52:29 +00:00
|
|
|
import { AttributeData, AttributePayload, Attributes, NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
2021-05-24 08:20:08 +03:00
|
|
|
|
2022-06-26 23:26:42 +01:00
|
|
|
import { hpsMeasureValue } from "@util/values";
|
2021-05-24 08:20:08 +03:00
|
|
|
|
|
|
|
// This represents element type CT_OnOff, which indicate a boolean value.
|
|
|
|
//
|
2021-05-24 11:28:10 +03:00
|
|
|
// A value of 1 or true specifies that the property shall be explicitly applied.
|
|
|
|
// This is the default value for this attribute, and is implied when the parent
|
|
|
|
// element is present, but this attribute is omitted.
|
|
|
|
// A value of 0 or false specifies that the property shall be explicitly turned off.
|
|
|
|
//
|
2021-05-24 08:20:08 +03:00
|
|
|
// <xsd:complexType name="CT_OnOff">
|
|
|
|
// <xsd:attribute name="val" type="s:ST_OnOff"/>
|
|
|
|
// </xsd:complexType>
|
|
|
|
export class OnOffElement extends XmlComponent {
|
2022-08-31 07:52:27 +01:00
|
|
|
public constructor(name: string, val: boolean | undefined = true) {
|
2021-05-24 08:20:08 +03:00
|
|
|
super(name);
|
2021-05-24 11:28:10 +03:00
|
|
|
if (val !== true) {
|
|
|
|
this.root.push(new Attributes({ val }));
|
|
|
|
}
|
2021-05-24 08:20:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This represents element type CT_HpsMeasure, which indicate an unsigned int or a measurement with unit.
|
|
|
|
//
|
|
|
|
// <xsd:complexType name="CT_HpsMeasure">
|
|
|
|
// <xsd:attribute name="val" type="ST_HpsMeasure" use="required"/>
|
|
|
|
// </xsd:complexType>
|
|
|
|
export class HpsMeasureElement extends XmlComponent {
|
2022-08-31 07:52:27 +01:00
|
|
|
public constructor(name: string, val: number | string) {
|
2021-05-24 08:20:08 +03:00
|
|
|
super(name);
|
|
|
|
this.root.push(new Attributes({ val: hpsMeasureValue(val) }));
|
|
|
|
}
|
|
|
|
}
|
2021-05-24 11:28:10 +03:00
|
|
|
|
|
|
|
// This represents element type CT_String, which indicate a string value.
|
|
|
|
//
|
2022-12-24 19:32:44 +00:00
|
|
|
// <xsd:complexType name="CT_Empty"/>
|
|
|
|
export class EmptyElement extends XmlComponent {}
|
|
|
|
|
|
|
|
// This represents element type CT_Empty, which indicate aan empty element.
|
|
|
|
//
|
2021-05-24 11:28:10 +03:00
|
|
|
// <xsd:complexType name="CT_String">
|
|
|
|
// <xsd:attribute name="val" type="s:ST_String" use="required"/>
|
|
|
|
// </xsd:complexType>
|
|
|
|
export class StringValueElement extends XmlComponent {
|
2022-08-31 07:52:27 +01:00
|
|
|
public constructor(name: string, val: string) {
|
2021-05-24 11:28:10 +03:00
|
|
|
super(name);
|
|
|
|
this.root.push(new Attributes({ val }));
|
|
|
|
}
|
|
|
|
}
|
2021-05-24 21:05:29 +03:00
|
|
|
|
|
|
|
// This represents various number element types.
|
|
|
|
export class NumberValueElement extends XmlComponent {
|
2022-08-31 07:52:27 +01:00
|
|
|
public constructor(name: string, val: number) {
|
2021-05-24 21:05:29 +03:00
|
|
|
super(name);
|
|
|
|
this.root.push(new Attributes({ val }));
|
|
|
|
}
|
|
|
|
}
|
2021-05-26 09:27:05 +03:00
|
|
|
|
2022-11-03 00:30:16 +00:00
|
|
|
export class StringEnumValueElement<T extends string> extends XmlComponent {
|
|
|
|
public constructor(name: string, val: T) {
|
|
|
|
super(name);
|
|
|
|
this.root.push(new Attributes({ val }));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-26 09:27:05 +03:00
|
|
|
// Simple nodes containing text.
|
|
|
|
//
|
|
|
|
// new StringContainer("hello", "world")
|
|
|
|
// <hello>world</hello>
|
|
|
|
export class StringContainer extends XmlComponent {
|
2022-08-31 07:52:27 +01:00
|
|
|
public constructor(name: string, val: string) {
|
2021-05-26 09:27:05 +03:00
|
|
|
super(name);
|
|
|
|
this.root.push(val);
|
|
|
|
}
|
|
|
|
}
|
2022-12-18 00:52:29 +00:00
|
|
|
|
|
|
|
export class BuilderElement<T extends AttributeData> extends XmlComponent {
|
2022-12-20 21:42:26 +00:00
|
|
|
public constructor(options: {
|
|
|
|
readonly name: string;
|
|
|
|
readonly attributes?: AttributePayload<T>;
|
|
|
|
readonly children?: readonly XmlComponent[];
|
|
|
|
}) {
|
2022-12-18 00:52:29 +00:00
|
|
|
super(options.name);
|
|
|
|
|
|
|
|
if (options.attributes) {
|
|
|
|
this.root.push(new NextAttributeComponent(options.attributes));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|