UNPKG

@adobe/uxp-optimized

Version:

Library of react components optimized for Adobe's Unified Extensibility Platform

63 lines (61 loc) 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseCssSize = void 0; /* Copyright 2019 Adobe All Rights Reserved. NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms of the Adobe license agreement accompanying it. If you have received this file from a source other than Adobe, then your use, modification, or distribution of it requires the prior written permission of Adobe. */ function parseCssSize(size) { if (size && size !== "none") { if (size.endsWith("px")) { return parseFloat(size.slice(0, -2)); } else { console.warn("Unsupported units: " + size); } } return 0; } exports.parseCssSize = parseCssSize; class Margin { constructor(left, top = left, right = left, bottom = top) { this.left = left; this.top = top; this.right = right; this.bottom = bottom; } get horizontal() { return this.left + this.right; } get vertical() { return this.top + this.bottom; } static fromCssMargin(css) { let cacheKey = css.margin || ""; let cached = Margin.cache.get(cacheKey); if (cached == null) { Margin.cache.set(cacheKey, cached = new Margin(parseCssSize(css.marginLeft), parseCssSize(css.marginTop), parseCssSize(css.marginRight), parseCssSize(css.marginBottom))); } return cached; } static fromCssPadding(css) { let cacheKey = css.padding || ""; let cached = Margin.cache.get(cacheKey); if (cached == null) { Margin.cache.set(cacheKey, cached = new Margin(parseCssSize(css.paddingLeft), parseCssSize(css.paddingTop), parseCssSize(css.paddingRight), parseCssSize(css.paddingBottom))); } return cached; } toString() { return `Margin(${this.left},${this.top},${this.right},${this.bottom})`; } } exports.default = Margin; // we are going to memoize these values for performance... // and because they are almost always the same few values. Margin.cache = new Map();