import { AttributeData, AttributePayload, Attributes, NextAttributeComponent, XmlComponent } from "@file/xml-components"; import { hpsMeasureValue } from "@util/values"; // This represents element type CT_OnOff, which indicate a boolean value. // // 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. // // // // export class OnOffElement extends XmlComponent { public constructor(name: string, val: boolean | undefined = true) { super(name); if (val !== true) { this.root.push(new Attributes({ val })); } } } // This represents element type CT_HpsMeasure, which indicate an unsigned int or a measurement with unit. // // // // export class HpsMeasureElement extends XmlComponent { public constructor(name: string, val: number | string) { super(name); this.root.push(new Attributes({ val: hpsMeasureValue(val) })); } } // This represents element type CT_String, which indicate a string value. // // export class EmptyElement extends XmlComponent {} // This represents element type CT_Empty, which indicate aan empty element. // // // // export class StringValueElement extends XmlComponent { public constructor(name: string, val: string) { super(name); this.root.push(new Attributes({ val })); } } // This represents various number element types. export class NumberValueElement extends XmlComponent { public constructor(name: string, val: number) { super(name); this.root.push(new Attributes({ val })); } } export class StringEnumValueElement extends XmlComponent { public constructor(name: string, val: T) { super(name); this.root.push(new Attributes({ val })); } } // Simple nodes containing text. // // new StringContainer("hello", "world") // world export class StringContainer extends XmlComponent { public constructor(name: string, val: string) { super(name); this.root.push(val); } } export class BuilderElement extends XmlComponent { public constructor(options: { readonly name: string; readonly attributes?: AttributePayload; readonly children?: readonly XmlComponent[]; }) { super(options.name); if (options.attributes) { this.root.push(new NextAttributeComponent(options.attributes)); } } }