Socket
Socket
Sign inDemoInstall

@instructure/ui-utils

Package Overview
Dependencies
Maintainers
30
Versions
1980
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@instructure/ui-utils - npm Package Compare versions

Comparing version 5.2.0 to 5.3.0-dev.1

30

es/dom/getFontSize.js

@@ -24,3 +24,8 @@ /*

*/
import canUseDOM from './canUseDOM';
import ownerDocument from './ownerDocument';
import getComputedStyle from './getComputedStyle';
var COMPUTED_CACHE = {};
/**

@@ -36,21 +41,20 @@ * ---

*/
export default function getFontSize(el) {
var m = document.createElement('div');
export default function getFontSize(el, ignoreCache) {
if (!canUseDOM) {
return 16;
}
var container = el || document.body;
var fontSize = 16;
var container = el || ownerDocument(el).documentElement;
if (!container) {
container = document.createElement('body');
container.style.cssText = 'font-size:1em !important';
document.documentElement.insertBefore(container, document.body);
// return the cached font size if it's there
if (!ignoreCache && COMPUTED_CACHE[container]) {
return COMPUTED_CACHE[container];
}
m.style.cssText = ['display: inline-block !important;', 'padding: 0 !important;', 'line-height: 1 !important;', 'position: absolute !important;', 'visibility: hidden !important;', 'font-size: 1em !important;'].join('');
m.appendChild(document.createTextNode('M'));
container.appendChild(m);
fontSize = m.offsetHeight;
container.removeChild(m);
var fontSize = parseInt(getComputedStyle(container).getPropertyValue('font-size'));
// cache the computed font size so that we don't have to compute it again
COMPUTED_CACHE[container] = fontSize;
return fontSize;
}

@@ -7,2 +7,29 @@ 'use strict';

exports.default = getFontSize;
var _canUseDOM = require('./canUseDOM');
var _canUseDOM2 = _interopRequireDefault(_canUseDOM);
var _ownerDocument = require('./ownerDocument');
var _ownerDocument2 = _interopRequireDefault(_ownerDocument);
var _getComputedStyle = require('./getComputedStyle');
var _getComputedStyle2 = _interopRequireDefault(_getComputedStyle);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var COMPUTED_CACHE = {};
/**
* ---
* category: utilities/DOM
* ---
*
* Gets font size in px
*
* @param {ReactComponent|DomNode} el - component or DOM node
* @returns {Object} font size in px
*/
/*

@@ -31,32 +58,20 @@ * The MIT License (MIT)

*/
function getFontSize(el, ignoreCache) {
if (!_canUseDOM2.default) {
return 16;
}
/**
* ---
* category: utilities/DOM
* ---
*
* Gets font size in px
*
* @param {ReactComponent|DomNode} el - component or DOM node
* @returns {Object} font size in px
*/
function getFontSize(el) {
var m = document.createElement('div');
var container = el || (0, _ownerDocument2.default)(el).documentElement;
var container = el || document.body;
var fontSize = 16;
if (!container) {
container = document.createElement('body');
container.style.cssText = 'font-size:1em !important';
document.documentElement.insertBefore(container, document.body);
// return the cached font size if it's there
if (!ignoreCache && COMPUTED_CACHE[container]) {
return COMPUTED_CACHE[container];
}
m.style.cssText = ['display: inline-block !important;', 'padding: 0 !important;', 'line-height: 1 !important;', 'position: absolute !important;', 'visibility: hidden !important;', 'font-size: 1em !important;'].join('');
m.appendChild(document.createTextNode('M'));
container.appendChild(m);
fontSize = m.offsetHeight;
container.removeChild(m);
var fontSize = parseInt((0, _getComputedStyle2.default)(container).getPropertyValue('font-size'));
// cache the computed font size so that we don't have to compute it again
COMPUTED_CACHE[container] = fontSize;
return fontSize;
}
{
"name": "@instructure/ui-utils",
"version": "5.2.0",
"version": "5.3.0-dev.1",
"description": "A collection of utilities for UI components",

@@ -25,3 +25,3 @@ "author": "Instructure, Inc. Engineering and Product Design",

"devDependencies": {
"@instructure/ui-presets": "^5.2.0",
"@instructure/ui-presets": "^5.3.0-dev.1",
"react": "15.6.2",

@@ -28,0 +28,0 @@ "react-dom": "15.6.2"

@@ -24,3 +24,8 @@ /*

*/
import canUseDOM from './canUseDOM'
import ownerDocument from './ownerDocument'
import getComputedStyle from './getComputedStyle'
const COMPUTED_CACHE = {}
/**

@@ -36,28 +41,20 @@ * ---

*/
export default function getFontSize (el) {
const m = document.createElement('div')
export default function getFontSize (el, ignoreCache) {
if (!canUseDOM) {
return 16
}
let container = el || document.body
let fontSize = 16
const container = el || ownerDocument(el).documentElement
if (!container) {
container = document.createElement('body')
container.style.cssText = 'font-size:1em !important'
document.documentElement.insertBefore(container, document.body)
// return the cached font size if it's there
if (!ignoreCache && COMPUTED_CACHE[container]) {
return COMPUTED_CACHE[container]
}
m.style.cssText = [
'display: inline-block !important;',
'padding: 0 !important;',
'line-height: 1 !important;',
'position: absolute !important;',
'visibility: hidden !important;',
'font-size: 1em !important;'
].join('')
m.appendChild(document.createTextNode('M'))
container.appendChild(m)
fontSize = m.offsetHeight
container.removeChild(m)
const fontSize = parseInt(getComputedStyle(container).getPropertyValue('font-size'))
// cache the computed font size so that we don't have to compute it again
COMPUTED_CACHE[container] = fontSize
return fontSize
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc