'use strict'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018, 2019 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['textfit'], function (textfit) { /** * This class is to wrap original TextFit with error handling * * @class TextFitUtil */ var TextFitUtil = function () { function TextFitUtil() { _classCallCheck(this, TextFitUtil); } /** * This method adds addition error handling to TextFit * If TextFit throws errors, force the inner span font size to 0.1px * * @static * @param {*} el DOM single element * @param {*} [options={}] options to extend default TextFit options * @returns * @memberof TextFitUtil */ TextFitUtil.fillText = function fillText(el) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; try { textfit(el, options); } catch (e) { this._forceFitText(el); } }; /** * This method is to set font size of inner span to 0.1px * If there is no span, add one and set the font size to 0.1px * If a span with class textFitted, set the font size to 0.1px * @static * @param {*} el DOM single element * @memberof TextFitUtil */ TextFitUtil._forceFitText = function _forceFitText(el) { var originalHTML = el.innerHTML; var innerSpan = el.getElementsByClassName('textFitted'); var defaultFontSize = '0.1px'; // Can't be 0 because IE freaks out. if (innerSpan[0]) { return innerSpan[0].style.fontSize = defaultFontSize; } innerSpan = document.createElement('span'); innerSpan.className = 'textFitted'; // Inline block ensure it takes on the size of its contents, even if they are enclosed // in other tags like

innerSpan.style['display'] = 'inline-block'; innerSpan.innerHTML = originalHTML; innerSpan.style.fontSize = defaultFontSize; el.innerHTML = ''; el.appendChild(innerSpan); }; _createClass(TextFitUtil, null, [{ key: '_textFit', // setter for mocking unit tests :( set: function set(func) { textfit = func; } }]); return TextFitUtil; }(); return TextFitUtil; }); //# sourceMappingURL=TextFitUtil.js.map