Socket
Socket
Sign inDemoInstall

fontfaceobserver-es

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.2.0 to 3.3.0

2

dist/fontfaceobserver.cjs.js

@@ -1,1 +0,1 @@

"use strict";var classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}}(),_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},styles={maxWidth:"none",display:"inline-block",position:"absolute",height:"100%",width:"100%",overflow:"scroll",fontSize:"16px"},collapsibleInnerStyles={display:"inline-block",height:"200%",width:"200%",fontSize:"16px",maxWidth:"none"},fontStyle={maxWidth:"none",minWidth:"20px",minHeight:"20px",display:"inline-block",overflow:"hidden",position:"absolute",width:"auto",margin:"0",padding:"0",top:"-999px",whiteSpace:"nowrap",fontSynthesis:"none"},Ruler=function(){function t(e){classCallCheck(this,t),this.element=document.createElement("div"),this.element.setAttribute("aria-hidden","true"),this.element.appendChild(document.createTextNode(e)),this.collapsible=document.createElement("span"),this.expandable=document.createElement("span"),this.collapsibleInner=document.createElement("span"),this.expandableInner=document.createElement("span"),this.lastOffsetWidth=-1,Object.assign(this.collapsible.style,styles),Object.assign(this.expandable.style,styles),Object.assign(this.expandableInner.style,styles),Object.assign(this.collapsibleInner.style,collapsibleInnerStyles),this.collapsible.appendChild(this.collapsibleInner),this.expandable.appendChild(this.expandableInner),this.element.appendChild(this.collapsible),this.element.appendChild(this.expandable)}return createClass(t,[{key:"getElement",value:function(){return this.element}},{key:"setFont",value:function(e){Object.assign(this.element.style,_extends({},fontStyle,{font:e}))}},{key:"getWidth",value:function(){return this.element.offsetWidth}},{key:"setWidth",value:function(e){this.element.style.width=e+"px"}},{key:"reset",value:function(){var e=this.getWidth(),t=e+100;return this.expandableInner.style.width=t+"px",this.expandable.scrollLeft=t,this.collapsible.scrollLeft=this.collapsible.scrollWidth+100,this.lastOffsetWidth!==e&&(this.lastOffsetWidth=e,!0)}},{key:"onScroll",value:function(e){this.reset()&&null!==this.element.parentNode&&e(this.lastOffsetWidth)}},{key:"onResize",value:function(e){var t=this;function n(){t.onScroll(e)}this.collapsible.addEventListener("scroll",n),this.expandable.addEventListener("scroll",n),this.reset()}}]),t}();function onReady(t){document.body?t():document.addEventListener?document.addEventListener("DOMContentLoaded",function e(){document.removeEventListener("DOMContentLoaded",e),t()}):document.attachEvent("onreadystatechange",function e(){"interactive"!=document.readyState&&"complete"!=document.readyState||(document.detachEvent("onreadystatechange",e),t())})}var FontFaceObserver=function(){function S(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return classCallCheck(this,S),this.family=e,this.style=t.style||"normal",this.weight=t.weight||"normal",this.stretch=t.stretch||"normal",this}return createClass(S,null,[{key:"getUserAgent",value:function(){return window.navigator.userAgent}},{key:"getNavigatorVendor",value:function(){return window.navigator.vendor}},{key:"hasWebKitFallbackBug",value:function(){if(null===S.HAS_WEBKIT_FALLBACK_BUG){var e=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(S.getUserAgent());S.HAS_WEBKIT_FALLBACK_BUG=!!e&&(parseInt(e[1],10)<536||536===parseInt(e[1],10)&&parseInt(e[2],10)<=11)}return S.HAS_WEBKIT_FALLBACK_BUG}},{key:"hasSafari10Bug",value:function(){if(null===S.HAS_SAFARI_10_BUG)if(S.supportsNativeFontLoading()&&/Apple/.test(S.getNavigatorVendor())){var e=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))(?:\.([0-9]+))/.exec(S.getUserAgent());S.HAS_SAFARI_10_BUG=!!e&&parseInt(e[1],10)<603}else S.HAS_SAFARI_10_BUG=!1;return S.HAS_SAFARI_10_BUG}},{key:"supportsNativeFontLoading",value:function(){return null===S.SUPPORTS_NATIVE_FONT_LOADING&&(S.SUPPORTS_NATIVE_FONT_LOADING=!!document.fonts),S.SUPPORTS_NATIVE_FONT_LOADING}},{key:"supportStretch",value:function(){if(null===S.SUPPORTS_STRETCH){var e=document.createElement("div");try{e.style.font="condensed 100px sans-serif"}catch(e){}S.SUPPORTS_STRETCH=""!==e.style.font}return S.SUPPORTS_STRETCH}}]),createClass(S,[{key:"load",value:function(e,t){var p=this,m=e||"BESbswy",v=0,y=t||S.DEFAULT_TIMEOUT,g=p.getTime();return new Promise(function(h,f){if(S.supportsNativeFontLoading()&&!S.hasSafari10Bug()){var e=new Promise(function(n,i){!function t(){var e=p.getTime();y<=e-g?i():document.fonts.load(p.getStyle('"'+p.family+'"'),m).then(function(e){1<=e.length?n():setTimeout(t,25)},function(){i()})}()}),t=new Promise(function(e,t){v=setTimeout(t,y)});Promise.race([t,e]).then(function(){clearTimeout(v),h(p)},function(){f(p)})}else onReady(function(){var i=new Ruler(m),l=new Ruler(m),s=new Ruler(m),a=-1,o=-1,r=-1,e=-1,t=-1,n=-1,c=document.createElement("div");function u(){null!==c.parentNode&&c.parentNode.removeChild(c)}function d(){if((-1!=a&&-1!=o||-1!=a&&-1!=r||-1!=o&&-1!=r)&&(a==o||a==r||o==r)){if(S.hasWebKitFallbackBug()&&(a==e&&o==e&&r==e||a==t&&o==t&&r==t||a==n&&o==n&&r==n))return;u(),clearTimeout(v),h(p)}}c.dir="ltr",i.setFont(p.getStyle("sans-serif")),l.setFont(p.getStyle("serif")),s.setFont(p.getStyle("monospace")),c.appendChild(i.getElement()),c.appendChild(l.getElement()),c.appendChild(s.getElement()),document.body.appendChild(c),e=i.getWidth(),t=l.getWidth(),n=s.getWidth(),function e(){var t=p.getTime();if(y<=t-g)u(),f(p);else{var n=document.hidden;!0!==n&&void 0!==n||(a=i.getWidth(),o=l.getWidth(),r=s.getWidth(),d()),v=setTimeout(e,50)}}(),i.onResize(function(e){a=e,d()}),i.setFont(p.getStyle('"'+p.family+'",sans-serif')),l.onResize(function(e){o=e,d()}),l.setFont(p.getStyle('"'+p.family+'",serif')),s.onResize(function(e){r=e,d()}),s.setFont(p.getStyle('"'+p.family+'",monospace'))})})}},{key:"getStyle",value:function(e){return[this.style,this.weight,S.supportStretch()?this.stretch:"","100px",e].join(" ")}},{key:"getTime",value:function(){return(new Date).getTime()}}]),S}();FontFaceObserver.Ruler=Ruler,FontFaceObserver.HAS_WEBKIT_FALLBACK_BUG=null,FontFaceObserver.HAS_SAFARI_10_BUG=null,FontFaceObserver.SUPPORTS_STRETCH=null,FontFaceObserver.SUPPORTS_NATIVE_FONT_LOADING=null,FontFaceObserver.DEFAULT_TIMEOUT=3e3,module.exports=FontFaceObserver;
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),i.forEach(function(e){_defineProperty(t,e,n[e])})}return t}var styles={maxWidth:"none",display:"inline-block",position:"absolute",height:"100%",width:"100%",overflow:"scroll",fontSize:"16px"},collapsibleInnerStyles={display:"inline-block",height:"200%",width:"200%",fontSize:"16px",maxWidth:"none"},fontStyle={maxWidth:"none",minWidth:"20px",minHeight:"20px",display:"inline-block",overflow:"hidden",position:"absolute",width:"auto",margin:"0",padding:"0",top:"-999px",whiteSpace:"nowrap",fontSynthesis:"none"},Ruler=function(){function t(e){_classCallCheck(this,t),this.element=document.createElement("div"),this.element.setAttribute("aria-hidden","true"),this.element.appendChild(document.createTextNode(e)),this.collapsible=document.createElement("span"),this.expandable=document.createElement("span"),this.collapsibleInner=document.createElement("span"),this.expandableInner=document.createElement("span"),this.lastOffsetWidth=-1,Object.assign(this.collapsible.style,styles),Object.assign(this.expandable.style,styles),Object.assign(this.expandableInner.style,styles),Object.assign(this.collapsibleInner.style,collapsibleInnerStyles),this.collapsible.appendChild(this.collapsibleInner),this.expandable.appendChild(this.expandableInner),this.element.appendChild(this.collapsible),this.element.appendChild(this.expandable)}return _createClass(t,[{key:"getElement",value:function(){return this.element}},{key:"setFont",value:function(e){Object.assign(this.element.style,_objectSpread({},fontStyle,{font:e}))}},{key:"getWidth",value:function(){return this.element.offsetWidth}},{key:"setWidth",value:function(e){this.element.style.width=e+"px"}},{key:"reset",value:function(){var e=this.getWidth(),t=e+100;return this.expandableInner.style.width=t+"px",this.expandable.scrollLeft=t,this.collapsible.scrollLeft=this.collapsible.scrollWidth+100,this.lastOffsetWidth!==e&&(this.lastOffsetWidth=e,!0)}},{key:"onScroll",value:function(e){this.reset()&&null!==this.element.parentNode&&e(this.lastOffsetWidth)}},{key:"onResize",value:function(e){var t=this;function n(){t.onScroll(e)}this.collapsible.addEventListener("scroll",n),this.expandable.addEventListener("scroll",n),this.reset()}}]),t}();function onReady(t){document.body?t():document.addEventListener?document.addEventListener("DOMContentLoaded",function e(){document.removeEventListener("DOMContentLoaded",e),t()}):document.attachEvent("onreadystatechange",function e(){"interactive"!=document.readyState&&"complete"!=document.readyState||(document.detachEvent("onreadystatechange",e),t())})}var FontFaceObserver=function(){function b(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return _classCallCheck(this,b),this.family=e,this.style=t.style||"normal",this.weight=t.weight||"normal",this.stretch=t.stretch||"normal",this}return _createClass(b,null,[{key:"getUserAgent",value:function(){return window.navigator.userAgent}},{key:"getNavigatorVendor",value:function(){return window.navigator.vendor}},{key:"hasWebKitFallbackBug",value:function(){if(null===b.HAS_WEBKIT_FALLBACK_BUG){var e=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(b.getUserAgent());b.HAS_WEBKIT_FALLBACK_BUG=!!e&&(parseInt(e[1],10)<536||536===parseInt(e[1],10)&&parseInt(e[2],10)<=11)}return b.HAS_WEBKIT_FALLBACK_BUG}},{key:"hasSafari10Bug",value:function(){if(null===b.HAS_SAFARI_10_BUG)if(b.supportsNativeFontLoading()&&/Apple/.test(b.getNavigatorVendor())){var e=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))(?:\.([0-9]+))/.exec(b.getUserAgent());b.HAS_SAFARI_10_BUG=!!e&&parseInt(e[1],10)<603}else b.HAS_SAFARI_10_BUG=!1;return b.HAS_SAFARI_10_BUG}},{key:"supportsNativeFontLoading",value:function(){return null===b.SUPPORTS_NATIVE_FONT_LOADING&&(b.SUPPORTS_NATIVE_FONT_LOADING=!!document.fonts),b.SUPPORTS_NATIVE_FONT_LOADING}},{key:"supportStretch",value:function(){if(null===b.SUPPORTS_STRETCH){var e=document.createElement("div");try{e.style.font="condensed 100px sans-serif"}catch(e){}b.SUPPORTS_STRETCH=""!==e.style.font}return b.SUPPORTS_STRETCH}}]),_createClass(b,[{key:"load",value:function(e,t){var p=this,m=e||"BESbswy",y=0,g=t||b.DEFAULT_TIMEOUT,v=p.getTime();return new Promise(function(h,f){if(b.supportsNativeFontLoading()&&!b.hasSafari10Bug()){var e=new Promise(function(n,i){!function t(){var e=p.getTime();g<=e-v?i(new Error(g+"ms timeout exceeded")):document.fonts.load(p.getStyle('"'+p.family+'"'),m).then(function(e){1<=e.length?n():setTimeout(t,25)},i)}()}),t=new Promise(function(e,t){y=setTimeout(function(){t(new Error(g+"ms timeout exceeded"))},g)});Promise.race([t,e]).then(function(){clearTimeout(y),h(p)},f)}else onReady(function(){var i=new Ruler(m),r=new Ruler(m),l=new Ruler(m),o=-1,s=-1,a=-1,e=-1,t=-1,n=-1,c=document.createElement("div");function u(){null!==c.parentNode&&c.parentNode.removeChild(c)}function d(){if((-1!=o&&-1!=s||-1!=o&&-1!=a||-1!=s&&-1!=a)&&(o==s||o==a||s==a)){if(b.hasWebKitFallbackBug()&&(o==e&&s==e&&a==e||o==t&&s==t&&a==t||o==n&&s==n&&a==n))return;u(),clearTimeout(y),h(p)}}c.dir="ltr",i.setFont(p.getStyle("sans-serif")),r.setFont(p.getStyle("serif")),l.setFont(p.getStyle("monospace")),c.appendChild(i.getElement()),c.appendChild(r.getElement()),c.appendChild(l.getElement()),document.body.appendChild(c),e=i.getWidth(),t=r.getWidth(),n=l.getWidth(),function e(){var t=p.getTime();if(g<=t-v)u(),f(new Error(g+"ms timeout exceeded"));else{var n=document.hidden;!0!==n&&void 0!==n||(o=i.getWidth(),s=r.getWidth(),a=l.getWidth(),d()),y=setTimeout(e,50)}}(),i.onResize(function(e){o=e,d()}),i.setFont(p.getStyle('"'+p.family+'",sans-serif')),r.onResize(function(e){s=e,d()}),r.setFont(p.getStyle('"'+p.family+'",serif')),l.onResize(function(e){a=e,d()}),l.setFont(p.getStyle('"'+p.family+'",monospace'))})})}},{key:"getStyle",value:function(e){return[this.style,this.weight,b.supportStretch()?this.stretch:"","100px",e].join(" ")}},{key:"getTime",value:function(){return(new Date).getTime()}}]),b}();_defineProperty(FontFaceObserver,"Ruler",Ruler),_defineProperty(FontFaceObserver,"HAS_WEBKIT_FALLBACK_BUG",null),_defineProperty(FontFaceObserver,"HAS_SAFARI_10_BUG",null),_defineProperty(FontFaceObserver,"SUPPORTS_STRETCH",null),_defineProperty(FontFaceObserver,"SUPPORTS_NATIVE_FONT_LOADING",null),_defineProperty(FontFaceObserver,"DEFAULT_TIMEOUT",3e3),module.exports=FontFaceObserver;

@@ -1,39 +0,57 @@

/* Font Face Observer v3.2.0 - © Bram Stein - Damien Seguin. License: BSD-3-Clause */
var classCallCheck = function (instance, Constructor) {
/* Font Face Observer v3.3.0 - © Bram Stein - Damien Seguin. License: BSD-3-Clause */
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
}
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);
}
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 _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
var _extends = Object.assign || function (target) {
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}
return target;
};
}

@@ -49,3 +67,2 @@ var styles = {

};
var collapsibleInnerStyles = {

@@ -58,3 +75,2 @@ display: "inline-block",

};
var fontStyle = {

@@ -75,3 +91,5 @@ maxWidth: "none",

var Ruler = function () {
var Ruler =
/*#__PURE__*/
function () {
/**

@@ -82,9 +100,7 @@ *

function Ruler(text) {
classCallCheck(this, Ruler);
_classCallCheck(this, Ruler);
this.element = document.createElement("div");
this.element.setAttribute("aria-hidden", "true");
this.element.appendChild(document.createTextNode(text));
this.collapsible = document.createElement("span");

@@ -94,5 +110,3 @@ this.expandable = document.createElement("span");

this.expandableInner = document.createElement("span");
this.lastOffsetWidth = -1;
Object.assign(this.collapsible.style, styles);

@@ -102,10 +116,7 @@ Object.assign(this.expandable.style, styles);

Object.assign(this.collapsibleInner.style, collapsibleInnerStyles);
this.collapsible.appendChild(this.collapsibleInner);
this.expandable.appendChild(this.expandableInner);
this.element.appendChild(this.collapsible);
this.element.appendChild(this.expandable);
}
/**

@@ -116,3 +127,3 @@ * @return {Element}

createClass(Ruler, [{
_createClass(Ruler, [{
key: "getElement",

@@ -122,3 +133,2 @@ value: function getElement() {

}
/**

@@ -131,5 +141,6 @@ * @param {string} font

value: function setFont(font) {
Object.assign(this.element.style, _extends({}, fontStyle, { font: font }));
Object.assign(this.element.style, _objectSpread({}, fontStyle, {
font: font
}));
}
/**

@@ -144,3 +155,2 @@ * @return {number}

}
/**

@@ -155,3 +165,2 @@ * @param {string} width

}
/**

@@ -168,3 +177,2 @@ * @private

var width = offsetWidth + 100;
this.expandableInner.style.width = width + "px";

@@ -181,3 +189,2 @@ this.expandable.scrollLeft = width;

}
/**

@@ -195,3 +202,2 @@ * @private

}
/**

@@ -215,2 +221,3 @@ * @param {function(number)} callback

}]);
return Ruler;

@@ -230,12 +237,12 @@ }();

var FontFaceObserver = function () {
createClass(FontFaceObserver, null, [{
var FontFaceObserver =
/*#__PURE__*/
function () {
_createClass(FontFaceObserver, null, [{
key: "getUserAgent",
/**
* @return {string}
* @type {null|boolean}
*/
/**

@@ -245,15 +252,10 @@ * @type {null|boolean}

/**
* @type {null|boolean}
*/
value: function getUserAgent() {
return window.navigator.userAgent;
}
/**
* @return {string}
* @type {null|boolean}
*/
/**

@@ -263,10 +265,10 @@ * @type {number}

/**
* @type {null|boolean}
* @return {string}
*/
value: function getUserAgent() {
return window.navigator.userAgent;
}
/**
* @type {null|boolean}
* @return {string}
*/

@@ -279,3 +281,2 @@

}
/**

@@ -293,8 +294,7 @@ * Returns true if this browser is WebKit and it has the fallback bug which is

var match = /AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(FontFaceObserver.getUserAgent());
FontFaceObserver.HAS_WEBKIT_FALLBACK_BUG = !!match && (parseInt(match[1], 10) < 536 || parseInt(match[1], 10) === 536 && parseInt(match[2], 10) <= 11);
}
return FontFaceObserver.HAS_WEBKIT_FALLBACK_BUG;
}
/**

@@ -323,3 +323,2 @@ * Returns true if the browser has the Safari 10 bugs. The native font load

var match = /AppleWebKit\/([0-9]+)(?:\.([0-9]+))(?:\.([0-9]+))/.exec(FontFaceObserver.getUserAgent());
FontFaceObserver.HAS_SAFARI_10_BUG = !!match && parseInt(match[1], 10) < 603;

@@ -330,5 +329,5 @@ } else {

}
return FontFaceObserver.HAS_SAFARI_10_BUG;
}
/**

@@ -346,5 +345,5 @@ * Returns true if the browser supports the native font loading API.

}
return FontFaceObserver.SUPPORTS_NATIVE_FONT_LOADING;
}
/**

@@ -366,2 +365,3 @@ * Returns true if the browser supports font-style in the font short-hand

} catch (e) {}
FontFaceObserver.SUPPORTS_STRETCH = div.style.font !== "";

@@ -372,3 +372,2 @@ }

}
/**

@@ -380,2 +379,3 @@ * @typedef {Object} Descriptors

*/
/**

@@ -393,13 +393,11 @@ *

var descriptors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
classCallCheck(this, FontFaceObserver);
_classCallCheck(this, FontFaceObserver);
this.family = family;
this.style = descriptors.style || "normal";
this.weight = descriptors.weight || "normal";
this.stretch = descriptors.stretch || "normal";
return this;
}
/**

@@ -414,3 +412,3 @@ * @param {string=} text Optional test string to use for detecting if a font

createClass(FontFaceObserver, [{
_createClass(FontFaceObserver, [{
key: "load",

@@ -423,3 +421,2 @@ value: function load(text, timeout) {

var start = that.getTime();
return new Promise(function (resolve, reject) {

@@ -432,3 +429,3 @@ if (FontFaceObserver.supportsNativeFontLoading() && !FontFaceObserver.hasSafari10Bug()) {

if (now - start >= timeoutValue) {
reject();
reject(new Error("" + timeoutValue + "ms timeout exceeded"));
} else {

@@ -441,20 +438,17 @@ document.fonts.load(that.getStyle('"' + that["family"] + '"'), testString).then(function (fonts) {

}
}, function () {
reject();
});
}, reject);
}
};
check();
});
var timer = new Promise(function (resolve, reject) {
timeoutId = setTimeout(reject, timeoutValue);
timeoutId = setTimeout(function () {
reject(new Error("" + timeoutValue + "ms timeout exceeded"));
}, timeoutValue);
});
Promise.race([timer, loader]).then(function () {
clearTimeout(timeoutId);
resolve(that);
}, function () {
reject(that);
});
}, reject);
} else {

@@ -465,16 +459,13 @@ onReady(function () {

var rulerC = new Ruler(testString);
var widthA = -1;
var widthB = -1;
var widthC = -1;
var fallbackWidthA = -1;
var fallbackWidthB = -1;
var fallbackWidthC = -1;
var container = document.createElement("div");
/**
* @private
*/
function removeContainer() {

@@ -485,3 +476,2 @@ if (container.parentNode !== null) {

}
/**

@@ -505,2 +495,4 @@ * @private

*/
function check() {

@@ -511,3 +503,2 @@ if (widthA != -1 && widthB != -1 || widthA != -1 && widthC != -1 || widthB != -1 && widthC != -1) {

// loaded the web font
if (FontFaceObserver.hasWebKitFallbackBug()) {

@@ -517,3 +508,2 @@ // Except if the browser has the WebKit fallback bug, in which

// last resort fonts.
if (widthA == fallbackWidthA && widthB == fallbackWidthA && widthC == fallbackWidthA || widthA == fallbackWidthB && widthB == fallbackWidthB && widthC == fallbackWidthB || widthA == fallbackWidthC && widthB == fallbackWidthC && widthC == fallbackWidthC) {

@@ -526,2 +516,3 @@ // The width we got matches some of the known last resort

}
removeContainer();

@@ -532,17 +523,13 @@ clearTimeout(timeoutId);

}
}
} // This ensures the scroll direction is correct.
// This ensures the scroll direction is correct.
container.dir = "ltr";
rulerA.setFont(that.getStyle("sans-serif"));
rulerB.setFont(that.getStyle("serif"));
rulerC.setFont(that.getStyle("monospace"));
container.appendChild(rulerA.getElement());
container.appendChild(rulerB.getElement());
container.appendChild(rulerC.getElement());
document.body.appendChild(container);
fallbackWidthA = rulerA.getWidth();

@@ -557,5 +544,6 @@ fallbackWidthB = rulerB.getWidth();

removeContainer();
reject(that);
reject(new Error("" + timeoutValue + "ms timeout exceeded"));
} else {
var hidden = document["hidden"];
if (hidden === true || hidden === undefined) {

@@ -567,2 +555,3 @@ widthA = rulerA.getWidth();

}
timeoutId = setTimeout(checkForTimeout, 50);

@@ -573,3 +562,2 @@ }

checkForTimeout();
rulerA.onResize(function (width) {

@@ -579,5 +567,3 @@ widthA = width;

});
rulerA.setFont(that.getStyle('"' + that["family"] + '",sans-serif'));
rulerB.onResize(function (width) {

@@ -587,5 +573,3 @@ widthB = width;

});
rulerB.setFont(that.getStyle('"' + that["family"] + '",serif'));
rulerC.onResize(function (width) {

@@ -595,3 +579,2 @@ widthC = width;

});
rulerC.setFont(that.getStyle('"' + that["family"] + '",monospace'));

@@ -602,3 +585,2 @@ });

}
/**

@@ -628,12 +610,18 @@ * @private

}]);
return FontFaceObserver;
}();
FontFaceObserver.Ruler = Ruler;
FontFaceObserver.HAS_WEBKIT_FALLBACK_BUG = null;
FontFaceObserver.HAS_SAFARI_10_BUG = null;
FontFaceObserver.SUPPORTS_STRETCH = null;
FontFaceObserver.SUPPORTS_NATIVE_FONT_LOADING = null;
FontFaceObserver.DEFAULT_TIMEOUT = 3000;
_defineProperty(FontFaceObserver, "Ruler", Ruler);
_defineProperty(FontFaceObserver, "HAS_WEBKIT_FALLBACK_BUG", null);
_defineProperty(FontFaceObserver, "HAS_SAFARI_10_BUG", null);
_defineProperty(FontFaceObserver, "SUPPORTS_STRETCH", null);
_defineProperty(FontFaceObserver, "SUPPORTS_NATIVE_FONT_LOADING", null);
_defineProperty(FontFaceObserver, "DEFAULT_TIMEOUT", 3000);
export default FontFaceObserver;

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.FontFaceObserver=t()}(this,function(){"use strict";var n=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e=function(){function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}}(),i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},o={maxWidth:"none",display:"inline-block",position:"absolute",height:"100%",width:"100%",overflow:"scroll",fontSize:"16px"},l={display:"inline-block",height:"200%",width:"200%",fontSize:"16px",maxWidth:"none"},a={maxWidth:"none",minWidth:"20px",minHeight:"20px",display:"inline-block",overflow:"hidden",position:"absolute",width:"auto",margin:"0",padding:"0",top:"-999px",whiteSpace:"nowrap",fontSynthesis:"none"},b=function(){function t(e){n(this,t),this.element=document.createElement("div"),this.element.setAttribute("aria-hidden","true"),this.element.appendChild(document.createTextNode(e)),this.collapsible=document.createElement("span"),this.expandable=document.createElement("span"),this.collapsibleInner=document.createElement("span"),this.expandableInner=document.createElement("span"),this.lastOffsetWidth=-1,Object.assign(this.collapsible.style,o),Object.assign(this.expandable.style,o),Object.assign(this.expandableInner.style,o),Object.assign(this.collapsibleInner.style,l),this.collapsible.appendChild(this.collapsibleInner),this.expandable.appendChild(this.expandableInner),this.element.appendChild(this.collapsible),this.element.appendChild(this.expandable)}return e(t,[{key:"getElement",value:function(){return this.element}},{key:"setFont",value:function(e){Object.assign(this.element.style,i({},a,{font:e}))}},{key:"getWidth",value:function(){return this.element.offsetWidth}},{key:"setWidth",value:function(e){this.element.style.width=e+"px"}},{key:"reset",value:function(){var e=this.getWidth(),t=e+100;return this.expandableInner.style.width=t+"px",this.expandable.scrollLeft=t,this.collapsible.scrollLeft=this.collapsible.scrollWidth+100,this.lastOffsetWidth!==e&&(this.lastOffsetWidth=e,!0)}},{key:"onScroll",value:function(e){this.reset()&&null!==this.element.parentNode&&e(this.lastOffsetWidth)}},{key:"onResize",value:function(e){var t=this;function n(){t.onScroll(e)}this.collapsible.addEventListener("scroll",n),this.expandable.addEventListener("scroll",n),this.reset()}}]),t}();var t=function(){function S(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return n(this,S),this.family=e,this.style=t.style||"normal",this.weight=t.weight||"normal",this.stretch=t.stretch||"normal",this}return e(S,null,[{key:"getUserAgent",value:function(){return window.navigator.userAgent}},{key:"getNavigatorVendor",value:function(){return window.navigator.vendor}},{key:"hasWebKitFallbackBug",value:function(){if(null===S.HAS_WEBKIT_FALLBACK_BUG){var e=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(S.getUserAgent());S.HAS_WEBKIT_FALLBACK_BUG=!!e&&(parseInt(e[1],10)<536||536===parseInt(e[1],10)&&parseInt(e[2],10)<=11)}return S.HAS_WEBKIT_FALLBACK_BUG}},{key:"hasSafari10Bug",value:function(){if(null===S.HAS_SAFARI_10_BUG)if(S.supportsNativeFontLoading()&&/Apple/.test(S.getNavigatorVendor())){var e=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))(?:\.([0-9]+))/.exec(S.getUserAgent());S.HAS_SAFARI_10_BUG=!!e&&parseInt(e[1],10)<603}else S.HAS_SAFARI_10_BUG=!1;return S.HAS_SAFARI_10_BUG}},{key:"supportsNativeFontLoading",value:function(){return null===S.SUPPORTS_NATIVE_FONT_LOADING&&(S.SUPPORTS_NATIVE_FONT_LOADING=!!document.fonts),S.SUPPORTS_NATIVE_FONT_LOADING}},{key:"supportStretch",value:function(){if(null===S.SUPPORTS_STRETCH){var e=document.createElement("div");try{e.style.font="condensed 100px sans-serif"}catch(e){}S.SUPPORTS_STRETCH=""!==e.style.font}return S.SUPPORTS_STRETCH}}]),e(S,[{key:"load",value:function(e,t){var p=this,m=e||"BESbswy",g=0,v=t||S.DEFAULT_TIMEOUT,y=p.getTime();return new Promise(function(h,f){if(S.supportsNativeFontLoading()&&!S.hasSafari10Bug()){var e=new Promise(function(n,i){!function t(){var e=p.getTime();v<=e-y?i():document.fonts.load(p.getStyle('"'+p.family+'"'),m).then(function(e){1<=e.length?n():setTimeout(t,25)},function(){i()})}()}),t=new Promise(function(e,t){g=setTimeout(t,v)});Promise.race([t,e]).then(function(){clearTimeout(g),h(p)},function(){f(p)})}else n=function(){var i=new b(m),o=new b(m),l=new b(m),a=-1,s=-1,r=-1,e=-1,t=-1,n=-1,u=document.createElement("div");function c(){null!==u.parentNode&&u.parentNode.removeChild(u)}function d(){if((-1!=a&&-1!=s||-1!=a&&-1!=r||-1!=s&&-1!=r)&&(a==s||a==r||s==r)){if(S.hasWebKitFallbackBug()&&(a==e&&s==e&&r==e||a==t&&s==t&&r==t||a==n&&s==n&&r==n))return;c(),clearTimeout(g),h(p)}}u.dir="ltr",i.setFont(p.getStyle("sans-serif")),o.setFont(p.getStyle("serif")),l.setFont(p.getStyle("monospace")),u.appendChild(i.getElement()),u.appendChild(o.getElement()),u.appendChild(l.getElement()),document.body.appendChild(u),e=i.getWidth(),t=o.getWidth(),n=l.getWidth(),function e(){var t=p.getTime();if(v<=t-y)c(),f(p);else{var n=document.hidden;!0!==n&&void 0!==n||(a=i.getWidth(),s=o.getWidth(),r=l.getWidth(),d()),g=setTimeout(e,50)}}(),i.onResize(function(e){a=e,d()}),i.setFont(p.getStyle('"'+p.family+'",sans-serif')),o.onResize(function(e){s=e,d()}),o.setFont(p.getStyle('"'+p.family+'",serif')),l.onResize(function(e){r=e,d()}),l.setFont(p.getStyle('"'+p.family+'",monospace'))},document.body?n():document.addEventListener?document.addEventListener("DOMContentLoaded",function e(){document.removeEventListener("DOMContentLoaded",e),n()}):document.attachEvent("onreadystatechange",function e(){"interactive"!=document.readyState&&"complete"!=document.readyState||(document.detachEvent("onreadystatechange",e),n())});var n})}},{key:"getStyle",value:function(e){return[this.style,this.weight,S.supportStretch()?this.stretch:"","100px",e].join(" ")}},{key:"getTime",value:function(){return(new Date).getTime()}}]),S}();return t.Ruler=b,t.HAS_WEBKIT_FALLBACK_BUG=null,t.HAS_SAFARI_10_BUG=null,t.SUPPORTS_STRETCH=null,t.SUPPORTS_NATIVE_FONT_LOADING=null,t.DEFAULT_TIMEOUT=3e3,t});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).FontFaceObserver=t()}(this,function(){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function e(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var l={maxWidth:"none",display:"inline-block",position:"absolute",height:"100%",width:"100%",overflow:"scroll",fontSize:"16px"},a={display:"inline-block",height:"200%",width:"200%",fontSize:"16px",maxWidth:"none"},s={maxWidth:"none",minWidth:"20px",minHeight:"20px",display:"inline-block",overflow:"hidden",position:"absolute",width:"auto",margin:"0",padding:"0",top:"-999px",whiteSpace:"nowrap",fontSynthesis:"none"},S=function(){function t(e){n(this,t),this.element=document.createElement("div"),this.element.setAttribute("aria-hidden","true"),this.element.appendChild(document.createTextNode(e)),this.collapsible=document.createElement("span"),this.expandable=document.createElement("span"),this.collapsibleInner=document.createElement("span"),this.expandableInner=document.createElement("span"),this.lastOffsetWidth=-1,Object.assign(this.collapsible.style,l),Object.assign(this.expandable.style,l),Object.assign(this.expandableInner.style,l),Object.assign(this.collapsibleInner.style,a),this.collapsible.appendChild(this.collapsibleInner),this.expandable.appendChild(this.expandableInner),this.element.appendChild(this.collapsible),this.element.appendChild(this.expandable)}return e(t,[{key:"getElement",value:function(){return this.element}},{key:"setFont",value:function(e){Object.assign(this.element.style,function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),i.forEach(function(e){o(t,e,n[e])})}return t}({},s,{font:e}))}},{key:"getWidth",value:function(){return this.element.offsetWidth}},{key:"setWidth",value:function(e){this.element.style.width=e+"px"}},{key:"reset",value:function(){var e=this.getWidth(),t=e+100;return this.expandableInner.style.width=t+"px",this.expandable.scrollLeft=t,this.collapsible.scrollLeft=this.collapsible.scrollWidth+100,this.lastOffsetWidth!==e&&(this.lastOffsetWidth=e,!0)}},{key:"onScroll",value:function(e){this.reset()&&null!==this.element.parentNode&&e(this.lastOffsetWidth)}},{key:"onResize",value:function(e){var t=this;function n(){t.onScroll(e)}this.collapsible.addEventListener("scroll",n),this.expandable.addEventListener("scroll",n),this.reset()}}]),t}();var t=function(){function b(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return n(this,b),this.family=e,this.style=t.style||"normal",this.weight=t.weight||"normal",this.stretch=t.stretch||"normal",this}return e(b,null,[{key:"getUserAgent",value:function(){return window.navigator.userAgent}},{key:"getNavigatorVendor",value:function(){return window.navigator.vendor}},{key:"hasWebKitFallbackBug",value:function(){if(null===b.HAS_WEBKIT_FALLBACK_BUG){var e=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(b.getUserAgent());b.HAS_WEBKIT_FALLBACK_BUG=!!e&&(parseInt(e[1],10)<536||536===parseInt(e[1],10)&&parseInt(e[2],10)<=11)}return b.HAS_WEBKIT_FALLBACK_BUG}},{key:"hasSafari10Bug",value:function(){if(null===b.HAS_SAFARI_10_BUG)if(b.supportsNativeFontLoading()&&/Apple/.test(b.getNavigatorVendor())){var e=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))(?:\.([0-9]+))/.exec(b.getUserAgent());b.HAS_SAFARI_10_BUG=!!e&&parseInt(e[1],10)<603}else b.HAS_SAFARI_10_BUG=!1;return b.HAS_SAFARI_10_BUG}},{key:"supportsNativeFontLoading",value:function(){return null===b.SUPPORTS_NATIVE_FONT_LOADING&&(b.SUPPORTS_NATIVE_FONT_LOADING=!!document.fonts),b.SUPPORTS_NATIVE_FONT_LOADING}},{key:"supportStretch",value:function(){if(null===b.SUPPORTS_STRETCH){var e=document.createElement("div");try{e.style.font="condensed 100px sans-serif"}catch(e){}b.SUPPORTS_STRETCH=""!==e.style.font}return b.SUPPORTS_STRETCH}}]),e(b,[{key:"load",value:function(e,t){var p=this,m=e||"BESbswy",g=0,y=t||b.DEFAULT_TIMEOUT,v=p.getTime();return new Promise(function(h,f){if(b.supportsNativeFontLoading()&&!b.hasSafari10Bug()){var e=new Promise(function(n,i){!function t(){var e=p.getTime();y<=e-v?i(new Error(y+"ms timeout exceeded")):document.fonts.load(p.getStyle('"'+p.family+'"'),m).then(function(e){1<=e.length?n():setTimeout(t,25)},i)}()}),t=new Promise(function(e,t){g=setTimeout(function(){t(new Error(y+"ms timeout exceeded"))},y)});Promise.race([t,e]).then(function(){clearTimeout(g),h(p)},f)}else n=function(){var i=new S(m),o=new S(m),l=new S(m),a=-1,s=-1,r=-1,e=-1,t=-1,n=-1,u=document.createElement("div");function c(){null!==u.parentNode&&u.parentNode.removeChild(u)}function d(){if((-1!=a&&-1!=s||-1!=a&&-1!=r||-1!=s&&-1!=r)&&(a==s||a==r||s==r)){if(b.hasWebKitFallbackBug()&&(a==e&&s==e&&r==e||a==t&&s==t&&r==t||a==n&&s==n&&r==n))return;c(),clearTimeout(g),h(p)}}u.dir="ltr",i.setFont(p.getStyle("sans-serif")),o.setFont(p.getStyle("serif")),l.setFont(p.getStyle("monospace")),u.appendChild(i.getElement()),u.appendChild(o.getElement()),u.appendChild(l.getElement()),document.body.appendChild(u),e=i.getWidth(),t=o.getWidth(),n=l.getWidth(),function e(){var t=p.getTime();if(y<=t-v)c(),f(new Error(y+"ms timeout exceeded"));else{var n=document.hidden;!0!==n&&void 0!==n||(a=i.getWidth(),s=o.getWidth(),r=l.getWidth(),d()),g=setTimeout(e,50)}}(),i.onResize(function(e){a=e,d()}),i.setFont(p.getStyle('"'+p.family+'",sans-serif')),o.onResize(function(e){s=e,d()}),o.setFont(p.getStyle('"'+p.family+'",serif')),l.onResize(function(e){r=e,d()}),l.setFont(p.getStyle('"'+p.family+'",monospace'))},document.body?n():document.addEventListener?document.addEventListener("DOMContentLoaded",function e(){document.removeEventListener("DOMContentLoaded",e),n()}):document.attachEvent("onreadystatechange",function e(){"interactive"!=document.readyState&&"complete"!=document.readyState||(document.detachEvent("onreadystatechange",e),n())});var n})}},{key:"getStyle",value:function(e){return[this.style,this.weight,b.supportStretch()?this.stretch:"","100px",e].join(" ")}},{key:"getTime",value:function(){return(new Date).getTime()}}]),b}();return o(t,"Ruler",S),o(t,"HAS_WEBKIT_FALLBACK_BUG",null),o(t,"HAS_SAFARI_10_BUG",null),o(t,"SUPPORTS_STRETCH",null),o(t,"SUPPORTS_NATIVE_FONT_LOADING",null),o(t,"DEFAULT_TIMEOUT",3e3),t});
{
"name": "fontfaceobserver-es",
"version": "3.2.0",
"version": "3.3.0",
"description": "Detect if web fonts are available",

@@ -36,28 +36,27 @@ "directories": {

"contributors": [
"Damien Seguin <https://twitter.com/dmnsgn> (https://dmnsgn.me/)"
"Damien Seguin <https://github.com/dmnsgn> (https://dmnsgn.me/)"
],
"license": "BSD-3-Clause",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.3",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"@babel/core": "^7.3.4",
"@babel/plugin-proposal-class-properties": "^7.3.4",
"@babel/plugin-proposal-object-rest-spread": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"babel-eslint": "^10.0.1",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"eslint": "^4.19.1",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-prettier": "^2.6.0",
"eslint": "^5.15.2",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-prettier": "^3.0.1",
"jsdoc": "^3.5.5",
"mocha": "^2.5.3",
"mocha-phantomjs-core": "^2.0.0",
"phantomjs-prebuilt": "^2.1.7",
"prettier": "^1.12.1",
"rollup": "^0.59.3",
"rollup-plugin-babel": "^3.0.4",
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-uglify": "^4.0.0",
"sinon": "^1.17.4",
"unexpected": "^10.38.0"
"mocha": "^6.0.2",
"mocha-phantomjs-core": "^2.1.2",
"phantomjs-prebuilt": "^2.1.16",
"prettier": "^1.16.4",
"rollup": "^1.6.0",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^9.2.1",
"rollup-plugin-node-resolve": "^4.0.1",
"rollup-plugin-uglify": "^6.0.2",
"sinon": "^7.2.7",
"unexpected": "^11.2.0"
},

@@ -73,3 +72,3 @@ "scripts": {

"postversion": "git push && git push --tags && npm publish",
"test": "phantomjs node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/index.html spec"
"test": "npx phantomjs ./node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/index.html spec"
},

@@ -88,7 +87,4 @@ "eslintConfig": {

"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"experimentalObjectRestSpread": false
}
"ecmaVersion": 2019,
"sourceType": "module"
}

@@ -95,0 +91,0 @@ },

@@ -141,2 +141,39 @@ # Font Face Observer

If you are working with a large number of fonts, you may decide to create `FontFaceObserver` instances dynamically:
```js
// An example collection of font data with additional metadata,
// in this case “color.”
var exampleFontData = {
'Family A': { weight: 400, color: 'red' },
'Family B': { weight: 400, color: 'orange' },
'Family C': { weight: 900, color: 'yellow' },
// Etc.
};
var observers = [];
// Make one observer for each font,
// by iterating over the data we already have
Object.keys(exampleFontData).forEach(function(family) {
var data = exampleFontData[family];
var obs = new FontFaceObserver(family, data);
observers.push(obs.load());
});
Promise.all(observers)
.then(function(fonts) {
fonts.forEach(function(font) {
console.log(font.family + ' ' + font.weight + ' ' + 'loaded');
// Map the result of the Promise back to our existing data,
// to get the other properties we need.
console.log(exampleFontData[font.family].color);
});
})
.catch(function(err) {
console.warn('Some critical font are not available:', err);
});
```
The following example emulates FOUT with Font Face Observer for `My Family`.

@@ -143,0 +180,0 @@

@@ -5,13 +5,13 @@ export function onReady(callback) {

: document.addEventListener
? document.addEventListener("DOMContentLoaded", function c() {
document.removeEventListener("DOMContentLoaded", c);
callback();
})
: document.attachEvent("onreadystatechange", function k() {
if (
"interactive" == document.readyState ||
"complete" == document.readyState
)
document.detachEvent("onreadystatechange", k), callback();
});
? document.addEventListener("DOMContentLoaded", function c() {
document.removeEventListener("DOMContentLoaded", c);
callback();
})
: document.attachEvent("onreadystatechange", function k() {
if (
"interactive" == document.readyState ||
"complete" == document.readyState
)
document.detachEvent("onreadystatechange", k), callback();
});
}

@@ -180,18 +180,13 @@ import Ruler from "./Ruler.js";

if (now - start >= timeoutValue) {
reject();
reject(new Error("" + timeoutValue + "ms timeout exceeded"));
} else {
document.fonts
.load(that.getStyle('"' + that["family"] + '"'), testString)
.then(
function(fonts) {
if (fonts.length >= 1) {
resolve();
} else {
setTimeout(check, 25);
}
},
function() {
reject();
.then(function(fonts) {
if (fonts.length >= 1) {
resolve();
} else {
setTimeout(check, 25);
}
);
}, reject);
}

@@ -203,14 +198,11 @@ };

const timer = new Promise(function(resolve, reject) {
timeoutId = setTimeout(reject, timeoutValue);
timeoutId = setTimeout(function() {
reject(new Error("" + timeoutValue + "ms timeout exceeded"));
}, timeoutValue);
});
Promise.race([timer, loader]).then(
function() {
clearTimeout(timeoutId);
resolve(that);
},
function() {
reject(that);
}
);
Promise.race([timer, loader]).then(function() {
clearTimeout(timeoutId);
resolve(that);
}, reject);
} else {

@@ -320,3 +312,3 @@ onReady(function() {

removeContainer();
reject(that);
reject(new Error("" + timeoutValue + "ms timeout exceeded"));
} else {

@@ -323,0 +315,0 @@ const hidden = document["hidden"];

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc