UNPKG

web-atoms-core

Version:
114 lines 3.96 kB
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); }; (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function cssNumberToString(n, unit) { if (unit === void 0) { unit = "px"; } if (typeof n === "number") { if (n === 0) { return n + ""; } return n + unit; } return n; } exports.cssNumberToString = cssNumberToString; var StyleBuilder = /** @class */ (function () { function StyleBuilder(style) { this.style = style; this.style = this.style || {}; } Object.defineProperty(StyleBuilder, "newStyle", { get: function () { return new StyleBuilder(); }, enumerable: true, configurable: true }); StyleBuilder.prototype.toStyle = function () { return this.style; }; StyleBuilder.prototype.size = function (width, height) { width = cssNumberToString(width); height = cssNumberToString(height); return this.merge({ width: width, height: height }); }; StyleBuilder.prototype.roundBorder = function (radius) { radius = cssNumberToString(radius); return this.merge({ borderRadius: radius, padding: radius }); }; StyleBuilder.prototype.border = function (borderWidth, borderColor, borderStyle) { if (borderStyle === void 0) { borderStyle = "solid"; } borderWidth = cssNumberToString(borderWidth); return this.merge({ borderWidth: borderWidth, borderStyle: borderStyle, borderColor: borderColor }); }; StyleBuilder.prototype.center = function (width, height) { width = cssNumberToString(width); height = cssNumberToString(height); return this.merge({ position: "absolute", left: 0, right: 0, top: 0, bottom: 0, width: width, height: height, margin: "auto" }); }; StyleBuilder.prototype.absolute = function (left, top, right, bottom) { left = cssNumberToString(left); top = cssNumberToString(top); if (right !== undefined) { right = cssNumberToString(right); bottom = cssNumberToString(bottom); return this.merge({ position: "absolute", left: left, top: top, right: right, bottom: bottom }); } return this.merge({ position: "absolute", left: left, top: top }); }; StyleBuilder.prototype.merge = function (style) { return new StyleBuilder(__assign(__assign({}, this.style), style)); }; return StyleBuilder; }()); exports.default = StyleBuilder; }); //# sourceMappingURL=StyleBuilder.js.map