UNPKG

@ez-aem/policies

Version:

Easily Manage AEM Policies and Style System with EZ-AEM Policies.

108 lines (107 loc) 4.07 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CQStyle = exports.CQStyleGroup = exports.CQStyleGroups = void 0; var CQStyleGroups = (function () { function CQStyleGroups(items) { this.items = items || []; } CQStyleGroups.prototype.addStyleGroup = function (styleGroup) { this.items.push(styleGroup); }; CQStyleGroups.prototype.format = function (output, theme) { var _a; if (output === void 0) { output = "xml"; } if (theme === void 0) { theme = {}; } if (output === "xml") { return __assign({ attributes: { "jcr:primaryType": "nt:unstructured", } }, this.formatItems(output, theme)); } else if (output === "json") { return __assign((_a = {}, _a["jcr:primaryType"] = "nt:unstructured", _a), this.formatItems(output, theme)); } }; CQStyleGroups.prototype.formatItems = function (output, theme) { var formattedItems = {}; this.items.forEach(function (item, i) { if (typeof item === "function") { formattedItems["item".concat(i)] = item(theme).format(output); } else if (typeof item.format === "function") formattedItems["item".concat(i)] = item.format(output); }); return formattedItems; }; return CQStyleGroups; }()); exports.CQStyleGroups = CQStyleGroups; var CQStyleGroup = (function () { function CQStyleGroup(settings) { if (!settings) throw new Error("No Settings were passed: ".concat(settings)); this.label = settings.label; this.allowMultiple = settings.allowMultiple || false; this.styles = settings.styles || []; } CQStyleGroup.prototype.format = function (output) { var _a, _b; if (output === void 0) { output = "xml"; } return _a = { attributes: (_b = {}, _b["jcr:primaryType"] = "nt:unstructured", _b["cq:styleGroupLabel"] = this.label, _b["cq:styleGroupMultiple"] = this.allowMultiple, _b) }, _a["cq:styles"] = __assign({ attributes: { "jcr:primaryType": "nt:unstructured", } }, this.formatStyles(output)), _a; }; CQStyleGroup.prototype.formatStyles = function (output) { var formattedStyles = {}; this.styles.forEach(function (style, i) { return formattedStyles["item".concat(i)] = style.format(output); }); return formattedStyles; }; CQStyleGroup.prototype.addStyle = function (style) { this.styles.push(style); }; return CQStyleGroup; }()); exports.CQStyleGroup = CQStyleGroup; var CQStyle = (function () { function CQStyle(settings) { if (!settings) throw new Error("No Settings were passed: ".concat(settings)); this.id = settings.id; this.label = settings.label; this.classes = settings.classes || settings.id; if (settings.element) this.element = settings.element; } CQStyle.prototype.format = function (output) { if (output === void 0) { output = "xml"; } var attributes = { "jcr:primaryType": "nt:unstructured", "cq:styleId": this.id, "cq:styleLabel": this.label, "cq:styleClasses": this.classes, }; if (this.element) attributes.element = this.element; if (output === "xml") attributes = { attributes: attributes }; return attributes; }; return CQStyle; }()); exports.CQStyle = CQStyle;