UNPKG

@ts-common/azure-js-dev-tools

Version:

Developer dependencies for TypeScript related projects

875 lines 28.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BBuilder = exports.BlockQuoteBuilder = exports.BRBuilder = exports.LIBuilder = exports.ULBuilder = exports.SummaryBuilder = exports.DetailsBuilder = exports.ImgBuilder = exports.ABuilder = exports.TDBuilder = exports.TRBuilder = exports.TableBuilder = exports.HBuilder = exports.BodyBuilder = exports.HTMLBuilder = exports.HTMLElementBuilder = exports.b = exports.blockquote = exports.br = exports.li = exports.ul = exports.summary = exports.details = exports.img = exports.a = exports.td = exports.tr = exports.table = exports.h6 = exports.h5 = exports.h4 = exports.h3 = exports.h2 = exports.h1 = exports.h = exports.body = exports.html = void 0; var tslib_1 = require("tslib"); var textBuilder_1 = require("./textBuilder"); /** * Create an html element string. */ function html(htmlActions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return new HTMLBuilder(textBuilder).create(htmlActions); } exports.html = html; /** * Create a body element string. */ function body(bodyActions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return new BodyBuilder(textBuilder).create(bodyActions); } exports.body = body; /** * Create a h element string. */ function h(level, hActions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return new HBuilder(level, textBuilder).create(hActions); } exports.h = h; /** * Create a h1 element string. */ function h1(hActions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return h(1, hActions, textBuilder); } exports.h1 = h1; /** * Create a h2 element string. */ function h2(hActions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return h(2, hActions, textBuilder); } exports.h2 = h2; /** * Create a h3 element string. */ function h3(hActions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return h(3, hActions, textBuilder); } exports.h3 = h3; /** * Create a h4 element string. */ function h4(hActions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return h(4, hActions, textBuilder); } exports.h4 = h4; /** * Create a h5 element string. */ function h5(hActions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return h(5, hActions, textBuilder); } exports.h5 = h5; /** * Create a h6 element string. */ function h6(hActions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return h(6, hActions, textBuilder); } exports.h6 = h6; /** * Create a table element string. */ function table(tableActions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return new TableBuilder(textBuilder).create(tableActions); } exports.table = table; /** * Create a tr element string. */ function tr(trActions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return new TRBuilder(textBuilder).create(trActions); } exports.tr = tr; /** * Create a td element string. */ function td(tdActions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return new TDBuilder(textBuilder).create(tdActions); } exports.td = td; /** * Create a a element string. */ function a(aActions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return new ABuilder(textBuilder).create(aActions); } exports.a = a; /** * Create a img element string. */ function img(imgActions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return new ImgBuilder(textBuilder).create(imgActions); } exports.img = img; /** * Create a details element string. */ function details(actions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return new DetailsBuilder(textBuilder).create(actions); } exports.details = details; /** * Create a summary element string. */ function summary(actions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return new SummaryBuilder(textBuilder).create(actions); } exports.summary = summary; /** * Create a ul element string. */ function ul(actions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return new ULBuilder(textBuilder).create(actions); } exports.ul = ul; /** * Create an li element string. */ function li(actions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return new LIBuilder(textBuilder).create(actions); } exports.li = li; /** * Create an br element string. */ function br(actions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return new BRBuilder(textBuilder).create(actions); } exports.br = br; /** * Create a blockquote element string. */ function blockquote(actions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return new BlockQuoteBuilder(textBuilder).create(actions); } exports.blockquote = blockquote; /** * Create a b element string. */ function b(actions, textBuilder) { if (textBuilder === void 0) { textBuilder = new textBuilder_1.TextBuilder(); } return new BBuilder(textBuilder).create(actions); } exports.b = b; /** * A class that can be used to create a generic HTML element. */ var HTMLElementBuilder = /** @class */ (function () { /** * Create a new HTMLBuilder. */ function HTMLElementBuilder(elementName, text) { if (text === void 0) { text = new textBuilder_1.TextBuilder(); } this.elementName = elementName; this.text = text; this.hasContent = false; } /** * Start the html element. */ HTMLElementBuilder.prototype.start = function () { this.text.append("<" + this.elementName); }; /** * Add the provided attribute to the html element. * @param attributeName The name of the attribute. * @param attributeValue The value of the attribute. */ HTMLElementBuilder.prototype.attribute = function (attributeName, attributeValue) { this.text.append(" " + attributeName + "=\"" + attributeValue.toString() + "\""); return this; }; /** * Add the provided content to this element. This will close the start tag of the element if it * was open. * @param actions The content to add to the element. */ HTMLElementBuilder.prototype.content = function (actions) { var e_1, _a; if (typeof actions === "string" || typeof actions === "function") { actions = [actions]; } try { for (var actions_1 = tslib_1.__values(actions), actions_1_1 = actions_1.next(); !actions_1_1.done; actions_1_1 = actions_1.next()) { var contentAction = actions_1_1.value; if (contentAction) { if (!this.hasContent) { this.text.append(">"); this.hasContent = true; } if (typeof contentAction === "string") { this.text.append(contentAction); } else { contentAction(this); } } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (actions_1_1 && !actions_1_1.done && (_a = actions_1.return)) _a.call(actions_1); } finally { if (e_1) throw e_1.error; } } return this; }; /** * Append newline characters to the content of this HTML element. This will close the start tag if * it is still open. */ HTMLElementBuilder.prototype.contentNewLine = function (count) { if (count === void 0) { count = 1; } this.content(textBuilder_1.repeatText("\n", count)); return this; }; /** * End the html element. */ HTMLElementBuilder.prototype.end = function () { if (!this.hasContent) { this.text.append("/>"); } else { this.text.append("</" + this.elementName + ">"); } }; /** * Get the HTML text that this HTMLBuilder has been building. */ HTMLElementBuilder.prototype.toString = function () { return this.text.toString(); }; return HTMLElementBuilder; }()); exports.HTMLElementBuilder = HTMLElementBuilder; /** * A class that can be used to build an html element. */ var HTMLBuilder = /** @class */ (function (_super) { tslib_1.__extends(HTMLBuilder, _super); function HTMLBuilder(text) { return _super.call(this, "html", text) || this; } /** * Populate this element using the provided action. * @param htmlActions The actions that will populate this element. */ HTMLBuilder.prototype.create = function (htmlActions) { return textBuilder_1.create(this, htmlActions); }; /** * Add a body element to this html element's content. * @param bodyActions The action that will create the body element. */ HTMLBuilder.prototype.body = function (bodyActions) { this.content(body(bodyActions)); return this; }; return HTMLBuilder; }(HTMLElementBuilder)); exports.HTMLBuilder = HTMLBuilder; /** * A class that can be used to build a body element. */ var BodyBuilder = /** @class */ (function (_super) { tslib_1.__extends(BodyBuilder, _super); function BodyBuilder(text) { return _super.call(this, "body", text) || this; } /** * Populate this element using the provided action. * @param bodyActions The actions that will populate this element. */ BodyBuilder.prototype.create = function (bodyActions) { return textBuilder_1.create(this, bodyActions); }; /** * Create a bold element in this body element. * @param bActions The actions that will populate this element. */ BodyBuilder.prototype.b = function (bActions) { this.content(b(bActions)); return this; }; /** * Create a header element in this body element. * @param level The level of the header. * @param hActions The actions to use to populate the header element. */ BodyBuilder.prototype.h = function (level, hActions) { this.content(h(level, hActions)); return this; }; /** * Create a h1 element in this body element. * @param hActions The actions to use to populate the header element. */ BodyBuilder.prototype.h1 = function (hActions) { this.content(h1(hActions)); return this; }; /** * Create a h2 element in this body element. * @param hActions The actions to use to populate the header element. */ BodyBuilder.prototype.h2 = function (hActions) { this.content(h2(hActions)); return this; }; /** * Create a h3 element in this body element. * @param hActions The actions to use to populate the header element. */ BodyBuilder.prototype.h3 = function (hActions) { this.content(h3(hActions)); return this; }; /** * Create a h4 element in this body element. * @param hActions The actions to use to populate the header element. */ BodyBuilder.prototype.h4 = function (hActions) { this.content(h4(hActions)); return this; }; /** * Create a h5 element in this body element. * @param hActions The actions to use to populate the header element. */ BodyBuilder.prototype.h5 = function (hActions) { this.content(h5(hActions)); return this; }; /** * Create a h6 element in this body element. * @param hActions The actions to use to populate the header element. */ BodyBuilder.prototype.h6 = function (hActions) { this.content(h6(hActions)); return this; }; /** * Add a table element to this body element's content. * @param tableAction The action that will create the table element. */ BodyBuilder.prototype.table = function (tableActions) { this.content(table(tableActions)); return this; }; /** * Add a ul element to this body element's content. * @param ulActions The actions that will create the ul element. */ BodyBuilder.prototype.ul = function (ulActions) { this.content(ul(ulActions)); return this; }; /** * Add a details element to this body element's content. * @param detailsActions The actions that will create the details element. */ BodyBuilder.prototype.details = function (detailsActions) { this.content(details(detailsActions)); return this; }; /** * Add a br element to this body element's content. * @param brActions The actions that will create the br element. */ BodyBuilder.prototype.br = function (brActions) { this.content(br(brActions)); return this; }; return BodyBuilder; }(HTMLElementBuilder)); exports.BodyBuilder = BodyBuilder; /** * A class that can be used to build an h element. */ var HBuilder = /** @class */ (function (_super) { tslib_1.__extends(HBuilder, _super); function HBuilder(level, text) { return _super.call(this, "h" + level, text) || this; } /** * Populate this element using the provided action. * @param hActions The actions that will populate this element. */ HBuilder.prototype.create = function (hActions) { return textBuilder_1.create(this, hActions); }; /** * Add an a element to this h element's content. * @param aAction The action that will create the tr element. */ HBuilder.prototype.a = function (aActions) { this.content(a(aActions)); return this; }; return HBuilder; }(HTMLElementBuilder)); exports.HBuilder = HBuilder; /** * A class that can be used to build a table element. */ var TableBuilder = /** @class */ (function (_super) { tslib_1.__extends(TableBuilder, _super); function TableBuilder(text) { return _super.call(this, "table", text) || this; } /** * Populate this element using the provided action. * @param tableActions The actions that will populate this element. */ TableBuilder.prototype.create = function (tableActions) { return textBuilder_1.create(this, tableActions); }; /** * Add a border attribute to this table element. * @param value The value of the border attribute. */ TableBuilder.prototype.border = function (value) { this.attribute("border", value); return this; }; /** * Add a tr element to this table element's content. * @param trAction The action that will create the tr element. */ TableBuilder.prototype.tr = function (trActions) { this.content(tr(trActions)); return this; }; return TableBuilder; }(HTMLElementBuilder)); exports.TableBuilder = TableBuilder; /** * A class that can be used to build a tr element. */ var TRBuilder = /** @class */ (function (_super) { tslib_1.__extends(TRBuilder, _super); function TRBuilder(text) { return _super.call(this, "tr", text) || this; } /** * Populate this element using the provided action. * @param trActions The actions that will populate this element. */ TRBuilder.prototype.create = function (trActions) { return textBuilder_1.create(this, trActions); }; /** * Add a td element to this tr element's content. * @param tdActions The action that will create the td element. */ TRBuilder.prototype.td = function (tdActions) { this.content(td(tdActions)); return this; }; return TRBuilder; }(HTMLElementBuilder)); exports.TRBuilder = TRBuilder; /** * A class that can be used to build a td element. */ var TDBuilder = /** @class */ (function (_super) { tslib_1.__extends(TDBuilder, _super); function TDBuilder(text) { return _super.call(this, "td", text) || this; } /** * Populate this element using the provided action. * @param tdActions The actions that will populate this element. */ TDBuilder.prototype.create = function (tdActions) { return textBuilder_1.create(this, tdActions); }; /** * Add a colspan attribute to this td element. * @param value The value of the colspan attribute. */ TDBuilder.prototype.colspan = function (value) { this.attribute("colspan", value); return this; }; /** * Add a rowspan attribute to this td element. * @param value The value of the rowspan attribute. */ TDBuilder.prototype.rowspan = function (value) { this.attribute("rowspan", value); return this; }; /** * Create an a element in this td element. * @param aActions The actions to use to populate the a element. */ TDBuilder.prototype.a = function (aActions) { this.content(a(aActions)); return this; }; /** * Create a bold element in this td element. * @param bActions The actions that will populate this element. */ TDBuilder.prototype.b = function (bActions) { this.content(b(bActions)); return this; }; /** * Create a header element in this td element. * @param level The level of the header. * @param hActions The actions to use to populate the header element. */ TDBuilder.prototype.h = function (level, hActions) { this.content(h(level, hActions)); return this; }; /** * Create a h1 element in this td element. * @param hActions The actions to use to populate the header element. */ TDBuilder.prototype.h1 = function (hActions) { this.content(h1(hActions)); return this; }; /** * Create a h2 element in this td element. * @param hActions The actions to use to populate the header element. */ TDBuilder.prototype.h2 = function (hActions) { this.content(h2(hActions)); return this; }; /** * Create a h3 element in this td element. * @param hActions The actions to use to populate the header element. */ TDBuilder.prototype.h3 = function (hActions) { this.content(h3(hActions)); return this; }; /** * Create a h4 element in this td element. * @param hActions The actions to use to populate the header element. */ TDBuilder.prototype.h4 = function (hActions) { this.content(h4(hActions)); return this; }; /** * Create a h5 element in this td element. * @param hActions The actions to use to populate the header element. */ TDBuilder.prototype.h5 = function (hActions) { this.content(h5(hActions)); return this; }; /** * Create a h6 element in this td element. * @param hActions The actions to use to populate the header element. */ TDBuilder.prototype.h6 = function (hActions) { this.content(h6(hActions)); return this; }; /** * Create a img element in this td element. * @param imgActions The actions to use to populate the img element. */ TDBuilder.prototype.img = function (imgActions) { this.content(img(imgActions)); return this; }; return TDBuilder; }(HTMLElementBuilder)); exports.TDBuilder = TDBuilder; /** * A class that can be used to build an a element. */ var ABuilder = /** @class */ (function (_super) { tslib_1.__extends(ABuilder, _super); function ABuilder(text) { return _super.call(this, "a", text) || this; } /** * Populate this element using the provided action. * @param aActions The actions that will populate this element. */ ABuilder.prototype.create = function (aActions) { return textBuilder_1.create(this, aActions); }; /** * Add an href attribute to this a element. * @param hrefValue The value of the href attribute. */ ABuilder.prototype.href = function (hrefValue) { this.attribute("href", hrefValue); return this; }; return ABuilder; }(HTMLElementBuilder)); exports.ABuilder = ABuilder; /** * A class that can be used to build an img element. */ var ImgBuilder = /** @class */ (function (_super) { tslib_1.__extends(ImgBuilder, _super); function ImgBuilder(text) { return _super.call(this, "img", text) || this; } /** * Populate this element using the provided action. * @param imgActions The actions that will populate this element. */ ImgBuilder.prototype.create = function (imgActions) { return textBuilder_1.create(this, imgActions); }; /** * Add a src attribute to this img element. * @param srcValue The value of the src attribute. */ ImgBuilder.prototype.src = function (srcValue) { this.attribute("src", srcValue); return this; }; /** * Add an alt attribute to this img element. * @param altValue The value of the alt attribute. */ ImgBuilder.prototype.alt = function (altValue) { this.attribute("alt", altValue); return this; }; /** * Add an width attribute to this img element. * @param widthValue The value of the width attribute. */ ImgBuilder.prototype.width = function (widthValue) { this.attribute("width", widthValue); return this; }; /** * Add an height attribute to this img element. * @param heightValue The value of the height attribute. */ ImgBuilder.prototype.height = function (heightValue) { this.attribute("height", heightValue); return this; }; return ImgBuilder; }(HTMLElementBuilder)); exports.ImgBuilder = ImgBuilder; /** * A class that can be used to build a details element. */ var DetailsBuilder = /** @class */ (function (_super) { tslib_1.__extends(DetailsBuilder, _super); function DetailsBuilder(text) { return _super.call(this, "details", text) || this; } /** * Populate this element using the provided action. * @param actions The actions that will populate this element. */ DetailsBuilder.prototype.create = function (actions) { return textBuilder_1.create(this, actions); }; /** * Add a summary element to this details element. * @param actions The actions used to populate the summary element. */ DetailsBuilder.prototype.summary = function (actions) { this.content(summary(actions)); return this; }; /** * Add a blockquote element to this details element. * @param actions The actions used to populate the blockquote element. */ DetailsBuilder.prototype.blockquote = function (actions) { this.content(blockquote(actions)); return this; }; /** * Add a ul element to this details element. * @param actions The actions used to populate the ul element. */ DetailsBuilder.prototype.ul = function (actions) { this.content(ul(actions)); return this; }; return DetailsBuilder; }(HTMLElementBuilder)); exports.DetailsBuilder = DetailsBuilder; /** * A class that can be used to build a summary element. */ var SummaryBuilder = /** @class */ (function (_super) { tslib_1.__extends(SummaryBuilder, _super); function SummaryBuilder(text) { return _super.call(this, "summary", text) || this; } /** * Populate this element using the provided action. * @param actions The actions that will populate this element. */ SummaryBuilder.prototype.create = function (actions) { return textBuilder_1.create(this, actions); }; return SummaryBuilder; }(HTMLElementBuilder)); exports.SummaryBuilder = SummaryBuilder; /** * A class that can be used to build a ul element. */ var ULBuilder = /** @class */ (function (_super) { tslib_1.__extends(ULBuilder, _super); function ULBuilder(text) { return _super.call(this, "ul", text) || this; } /** * Populate this element using the provided action. * @param actions The actions that will populate this element. */ ULBuilder.prototype.create = function (actions) { return textBuilder_1.create(this, actions); }; /** * Add an li element to this ul element. * @param actions The actions used to populate the li element. */ ULBuilder.prototype.li = function (actions) { this.content(li(actions)); return this; }; return ULBuilder; }(HTMLElementBuilder)); exports.ULBuilder = ULBuilder; /** * A class that can be used to build a li element. */ var LIBuilder = /** @class */ (function (_super) { tslib_1.__extends(LIBuilder, _super); function LIBuilder(text) { return _super.call(this, "li", text) || this; } /** * Populate this element using the provided action. * @param actions The actions that will populate this element. */ LIBuilder.prototype.create = function (actions) { return textBuilder_1.create(this, actions); }; /** * Add a ul element to this li element's content. * @param ulActions The actions that will create the ul element. */ LIBuilder.prototype.ul = function (ulActions) { this.content(ul(ulActions)); return this; }; /** * Add a details element to this body element's content. * @param detailsActions The actions that will create the details element. */ LIBuilder.prototype.details = function (detailsActions) { this.content(details(detailsActions)); return this; }; return LIBuilder; }(HTMLElementBuilder)); exports.LIBuilder = LIBuilder; /** * A class that can be used to build a br element. */ var BRBuilder = /** @class */ (function (_super) { tslib_1.__extends(BRBuilder, _super); function BRBuilder(text) { return _super.call(this, "br", text) || this; } /** * Populate this element using the provided action. * @param actions The actions that will populate this element. */ BRBuilder.prototype.create = function (actions) { return textBuilder_1.create(this, actions); }; return BRBuilder; }(HTMLElementBuilder)); exports.BRBuilder = BRBuilder; /** * A class that can be used to build a blockquote element. */ var BlockQuoteBuilder = /** @class */ (function (_super) { tslib_1.__extends(BlockQuoteBuilder, _super); function BlockQuoteBuilder(text) { return _super.call(this, "blockquote", text) || this; } /** * Populate this element using the provided action. * @param actions The actions that will populate this element. */ BlockQuoteBuilder.prototype.create = function (actions) { return textBuilder_1.create(this, actions); }; /** * Add a ul element to this blockquote element's content. * @param ulActions The actions that will create the ul element. */ BlockQuoteBuilder.prototype.ul = function (ulActions) { this.content(ul(ulActions)); return this; }; /** * Add a details element to this blockquote element's content. * @param detailsActions The actions that will create the details element. */ BlockQuoteBuilder.prototype.details = function (detailsActions) { this.content(details(detailsActions)); return this; }; return BlockQuoteBuilder; }(HTMLElementBuilder)); exports.BlockQuoteBuilder = BlockQuoteBuilder; /** * A class that can be used to build a b element. */ var BBuilder = /** @class */ (function (_super) { tslib_1.__extends(BBuilder, _super); function BBuilder(text) { return _super.call(this, "b", text) || this; } /** * Populate this element using the provided action. * @param actions The actions that will populate this element. */ BBuilder.prototype.create = function (actions) { return textBuilder_1.create(this, actions); }; return BBuilder; }(HTMLElementBuilder)); exports.BBuilder = BBuilder; //# sourceMappingURL=htmlBuilder.js.map