Socket
Socket
Sign inDemoInstall

fontfaceobserver

Package Overview
Dependencies
2
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.9 to 1.4.11

src/css.js

19

fontfaceobserver.js

@@ -1,9 +0,10 @@

(function(){'use strict';function e(a){function b(){document.body?a():setTimeout(b,0)}b()};function f(a){this.a=document.createElement("div");this.a.setAttribute("aria-hidden","true");this.a.appendChild(document.createTextNode(a));this.b=document.createElement("span");this.c=document.createElement("span");this.f=document.createElement("span");this.e=document.createElement("span");this.d=-1;this.b.style.cssText="display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;";this.c.style.cssText="display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;";
this.e.style.cssText="display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;";this.f.style.cssText="display:inline-block;width:200%;height:200%;";this.b.appendChild(this.f);this.c.appendChild(this.e);this.a.appendChild(this.b);this.a.appendChild(this.c)}function n(a,b,c){a.a.style.cssText="min-width:20px;min-height:20px;display:inline-block;position:absolute;width:auto;margin:0;padding:0;top:-999px;left:-999px;white-space:nowrap;font-size:100px;font-family:"+b+";"+c}
function u(a){var b=a.a.offsetWidth,c=b+100;a.e.style.width=c+"px";a.c.scrollLeft=c;a.b.scrollLeft=a.b.scrollWidth+100;return a.d!==b?(a.d=b,!0):!1}function z(a,b){a.b.addEventListener("scroll",function(){u(a)&&null!==a.a.parentNode&&b(a.d)},!1);a.c.addEventListener("scroll",function(){u(a)&&null!==a.a.parentNode&&b(a.d)},!1);u(a)};function A(a){this.a=B;this.b=void 0;this.c=[];var b=this;try{a(function(a){b.resolve(a)},function(a){b.reject(a)})}catch(c){b.reject(c)}}var B=2;A.prototype.resolve=function(a){var b=this;if(b.a===B){if(a===b)throw new TypeError("Promise settled with itself.");var c=!1;try{var g=a&&a.then;if(null!==a&&"object"===typeof a&&"function"===typeof g){g.call(a,function(a){c||b.resolve(a);c=!0},function(a){c||b.reject(a);c=!0});return}}catch(d){c||b.reject(d);return}b.a=0;b.b=a;C(b)}};
A.prototype.reject=function(a){if(this.a===B){if(a===this)throw new TypeError("Promise settled with itself.");this.a=1;this.b=a;C(this)}};function C(a){setTimeout(function(){if(a.a!==B)for(;a.c.length;){var b=a.c.shift(),c=b[0],g=b[1],d=b[2],b=b[3];try{0===a.a?"function"===typeof c?d(c.call(void 0,a.b)):d(a.b):1===a.a&&("function"===typeof g?d(g.call(void 0,a.b)):b(a.b))}catch(h){b(h)}}},0)}A.prototype.catch=function(a){return this.then(void 0,a)};
A.prototype.then=function(a,b){var c=this;return new A(function(g,d){c.c.push([a,b,g,d]);C(c)})};
if(window.Promise){var D=window.Promise;D.prototype.then=window.Promise.prototype.then;D.prototype.catch=window.Promise.prototype["catch"];D.all=window.Promise.all;D.race=window.Promise.race;D.resolve=window.Promise.resolve;D.reject=window.Promise.reject}else D=A,D.prototype.then=A.prototype.then,D.prototype.catch=A.prototype.catch,D.all=A.prototype.all,D.race=A.prototype.race,D.resolve=A.prototype.resolve,D.reject=A.prototype.reject;function E(a,b){var c=b||{};this.family=a;this.style=c.style||"normal";this.variant=c.variant||"normal";this.weight=c.weight||"normal";this.stretch=c.stretch||"stretch";this.featureSettings=c.featureSettings||"normal"}var F=null;
E.prototype.a=function(a,b){var c=a||"BESbswy",g=b||3E3,d="font-style:"+this.style+";font-variant:"+this.variant+";font-weight:"+this.weight+";font-stretch:"+this.stretch+";font-feature-settings:"+this.featureSettings+";-moz-font-feature-settings:"+this.featureSettings+";-webkit-font-feature-settings:"+this.featureSettings+";",h=document.createElement("div"),p=new f(c),q=new f(c),r=new f(c),k=-1,l=-1,m=-1,v=-1,w=-1,x=-1,t=this;return new D(function(a,b){function c(){null!==h.parentNode&&h.parentNode.removeChild(h)}
function y(){if(-1!==k&&-1!==l||-1!==k&&-1!==m||-1!==l&&-1!==m)if(k===l||k===m||l===m){if(null===F){var b=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(window.navigator.userAgent);F=!!b&&(536>parseInt(b[1],10)||536===parseInt(b[1],10)&&11>=parseInt(b[2],10))}F?k===v&&l===v&&m===v||k===w&&l===w&&m===w||k===x&&l===x&&m===x||(c(),a(t)):(c(),a(t))}}e(function(){function a(){if(Date.now()-G>=g)c(),b(t);else{var d=document.hidden;if(!0===d||void 0===d)k=p.a.offsetWidth,l=q.a.offsetWidth,m=r.a.offsetWidth,
y();setTimeout(a,50)}}var G=Date.now();n(p,"sans-serif",d);n(q,"serif",d);n(r,"monospace",d);h.appendChild(p.a);h.appendChild(q.a);h.appendChild(r.a);document.body.appendChild(h);v=p.a.offsetWidth;w=q.a.offsetWidth;x=r.a.offsetWidth;a();z(p,function(a){k=a;y()});n(p,t.family+",sans-serif",d);z(q,function(a){l=a;y()});n(q,t.family+",serif",d);z(r,function(a){m=a;y()});n(r,t.family+",monospace",d)})})};window.FontFaceObserver=E;window.FontFaceObserver.prototype.check=E.prototype.a;}());
(function(){'use strict';function f(a){function b(){document.body?a():setTimeout(b,0)}b()};function h(a){this.a=document.createElement("div");this.a.setAttribute("aria-hidden","true");this.a.appendChild(document.createTextNode(a));this.b=document.createElement("span");this.c=document.createElement("span");this.f=document.createElement("span");this.e=document.createElement("span");this.d=-1;this.b.style.cssText="display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;";this.c.style.cssText="display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;";
this.e.style.cssText="display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;";this.f.style.cssText="display:inline-block;width:200%;height:200%;";this.b.appendChild(this.f);this.c.appendChild(this.e);this.a.appendChild(this.b);this.a.appendChild(this.c)}function p(a,b,c){a.a.style.cssText="min-width:20px;min-height:20px;display:inline-block;position:absolute;width:auto;margin:0;padding:0;top:-999px;left:-999px;white-space:nowrap;font-size:100px;font-family:"+b+";"+c}
function u(a){var b=a.a.offsetWidth,c=b+100;a.e.style.width=c+"px";a.c.scrollLeft=c;a.b.scrollLeft=a.b.scrollWidth+100;return a.d!==b?(a.d=b,!0):!1}function v(a,b){a.b.addEventListener("scroll",function(){u(a)&&null!==a.a.parentNode&&b(a.d)},!1);a.c.addEventListener("scroll",function(){u(a)&&null!==a.a.parentNode&&b(a.d)},!1);u(a)};var A=[];function B(a){A.push(a);1===A.length&&C()}function D(){for(;A.length;)A[0](),A.shift()}if(window.MutationObserver){var E=document.createElement("div");(new MutationObserver(D)).observe(E,{attributes:!0});var C=function(){E.setAttribute("x",0)}}else C=function(){setTimeout(D)};function F(a){this.a=G;this.b=void 0;this.c=[];var b=this;try{a(function(a){b.resolve(a)},function(a){b.reject(a)})}catch(c){b.reject(c)}}var G=2;function H(a){return new F(function(b,c){c(a)})}function I(a){return new F(function(b){b(a)})}
F.prototype.resolve=function(a){var b=this;if(b.a===G){if(a===b)throw new TypeError("Promise settled with itself.");var c=!1;try{var e=a&&a.then;if(null!==a&&"object"===typeof a&&"function"===typeof e){e.call(a,function(a){c||b.resolve(a);c=!0},function(a){c||b.reject(a);c=!0});return}}catch(d){c||b.reject(d);return}b.a=0;b.b=a;J(b)}};F.prototype.reject=function(a){if(this.a===G){if(a===this)throw new TypeError("Promise settled with itself.");this.a=1;this.b=a;J(this)}};
function J(a){B(function(){if(a.a!==G)for(;a.c.length;){var b=a.c.shift(),c=b[0],e=b[1],d=b[2],b=b[3];try{0===a.a?"function"===typeof c?d(c.call(void 0,a.b)):d(a.b):1===a.a&&("function"===typeof e?d(e.call(void 0,a.b)):b(a.b))}catch(g){b(g)}}})}F.prototype.catch=function(a){return this.then(void 0,a)};F.prototype.then=function(a,b){var c=this;return new F(function(e,d){c.c.push([a,b,e,d]);J(c)})};
function K(a){return new F(function(b,c){function e(c){return function(e){g[c]=e;d+=1;d===a.length&&b(g)}}var d=0,g=[];0===a.length&&b(g);for(var k=0;k<a.length;k+=1)a[k].then(e(k),c)})}function L(a){return new F(function(b,c){for(var e=0;e<a.length;e+=1)a[e].then(b,c)})}
if(window.Promise){var M=window.Promise;M.prototype.then=window.Promise.prototype.then;M.prototype.catch=window.Promise.prototype["catch"];M.all=window.Promise.all;M.race=window.Promise.race;M.resolve=window.Promise.resolve;M.reject=window.Promise.reject}else M=F,M.prototype.then=F.prototype.then,M.prototype.catch=F.prototype.catch,M.all=K,M.race=L,M.resolve=I,M.reject=H;function N(a,b){var c=b||{};this.family=a;this.style=c.style||"normal";this.variant=c.variant||"normal";this.weight=c.weight||"normal";this.stretch=c.stretch||"stretch";this.featureSettings=c.featureSettings||"normal"}var O=null;
N.prototype.a=function(a,b){var c=a||"BESbswy",e=b||3E3,d="font-style:"+this.style+";font-variant:"+this.variant+";font-weight:"+this.weight+";font-stretch:"+this.stretch+";font-feature-settings:"+this.featureSettings+";-moz-font-feature-settings:"+this.featureSettings+";-webkit-font-feature-settings:"+this.featureSettings+";",g=document.createElement("div"),k=new h(c),q=new h(c),r=new h(c),l=-1,m=-1,n=-1,w=-1,x=-1,y=-1,t=this;return new M(function(a,b){function c(){null!==g.parentNode&&g.parentNode.removeChild(g)}
function z(){if(-1!==l&&-1!==m||-1!==l&&-1!==n||-1!==m&&-1!==n)if(l===m||l===n||m===n){if(null===O){var b=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(window.navigator.userAgent);O=!!b&&(536>parseInt(b[1],10)||536===parseInt(b[1],10)&&11>=parseInt(b[2],10))}O?l===w&&m===w&&n===w||l===x&&m===x&&n===x||l===y&&m===y&&n===y||(c(),a(t)):(c(),a(t))}}f(function(){function a(){if(Date.now()-P>=e)c(),b(t);else{var d=document.hidden;if(!0===d||void 0===d)l=k.a.offsetWidth,m=q.a.offsetWidth,n=r.a.offsetWidth,
z();setTimeout(a,50)}}var P=Date.now();p(k,"sans-serif",d);p(q,"serif",d);p(r,"monospace",d);g.appendChild(k.a);g.appendChild(q.a);g.appendChild(r.a);document.body.appendChild(g);w=k.a.offsetWidth;x=q.a.offsetWidth;y=r.a.offsetWidth;a();v(k,function(a){l=a;z()});p(k,t.family+",sans-serif",d);v(q,function(a){m=a;z()});p(q,t.family+",serif",d);v(r,function(a){n=a;z()});p(r,t.family+",monospace",d)})})};window.FontFaceObserver=N;window.FontFaceObserver.prototype.check=N.prototype.a;}());
{
"name": "fontfaceobserver",
"version": "1.4.9",
"version": "1.4.11",
"description": "Detect if web fonts are available",

@@ -22,3 +22,3 @@ "directories": {

"dependencies": {
"promis": "=1.0.4",
"promis": "=1.0.6",
"closure-dom": "=0.0.1"

@@ -25,0 +25,0 @@ },

# Font Face Observer
Font Face Observer is a small `@font-face` loader and monitor (4.6KB minified and 1.7KB gzipped) compatible with any web font service. It will monitor when a web font is applied to the page and notify you. It does not limit you in any way in where, when, or how you load your web fonts. Unlike the [Web Font Loader](https://github.com/typekit/webfontloader) Font Face Observer uses scroll events to detect font loads efficiently and with minimum overhead.
Font Face Observer is a small `@font-face` loader and monitor (5.2KB minified and 1.9KB gzipped) compatible with any web font service. It will monitor when a web font is applied to the page and notify you. It does not limit you in any way in where, when, or how you load your web fonts. Unlike the [Web Font Loader](https://github.com/typekit/webfontloader) Font Face Observer uses scroll events to detect font loads efficiently and with minimum overhead.

@@ -9,11 +9,13 @@ ## How to use

var observer = new FontFaceObserver('My Family', {
weight: 400
});
```js
var observer = new FontFaceObserver('My Family', {
weight: 400
});
observer.check().then(function () {
console.log('Font is available');
}, function () {
console.log('Font is not available');
});
observer.check().then(function () {
console.log('Font is available');
}, function () {
console.log('Font is not available');
});
```

@@ -24,19 +26,23 @@ The `FontFaceObserver` constructor takes two arguments: the font family name (required) and an object describing the variation (optional). The object can contain `weight`, `style`, `stretch`, `variant`, and `featureSettings` properties. If a property is not present it will default to `normal`. To start observing font loads, call the `check` method. It'll immediately return a new Promise that resolves when the font is available and rejected when the font is not available.

var observer = new FontFaceObserver('My Family', {});
```js
var observer = new FontFaceObserver('My Family', {});
observer.check('中国').then(function () {
console.log('Font is available');
}, function () {
console.log('Font is not available');
});
observer.check('中国').then(function () {
console.log('Font is available');
}, function () {
console.log('Font is not available');
});
```
The default timeout for giving up on font loading is 3 seconds. You can increase or decrease this by passing a number of milliseconds as the second parameter to the `check` method.
var observer = new FontFaceObserver('My Family', {});
```js
var observer = new FontFaceObserver('My Family', {});
observer.check(null, 5000).then(function () {
console.log('Font is available');
}, function () {
console.log('Font is not available after waiting 5 seconds');
});
observer.check(null, 5000).then(function () {
console.log('Font is available');
}, function () {
console.log('Font is not available after waiting 5 seconds');
});
```

@@ -47,5 +53,7 @@ ## Installation

> npm install fontfaceobserver
```shell
$ npm install fontfaceobserver
```
You can then include `node_modules/fontfaceobserver/fontfaceobserver.js`. If you're not using npm, grab `fontfaceobserver.js` and include it in your project.
You can then include `node_modules/fontfaceobserver/fontfaceobserver.js`. If you're not using npm, grab `fontfaceobserver.js` and include it in your project.

@@ -52,0 +60,0 @@ ## Browser support

// This file was autogenerated by calcdeps.js
goog.addDependency("../../node_modules/closure-dom/src/dom.js", ["dom"], []);
goog.addDependency("../../src/css.js", ["fontface.Css"], []);
goog.addDependency("../../src/descriptors.js", ["fontface.Descriptors"], []);
goog.addDependency("../../src/main.js", [], ["fontface.Observer"]);
goog.addDependency("../../src/observer.js", ["fontface.Observer"], ["fontface.Ruler","dom"]);
goog.addDependency("../../src/ruler.js", ["fontface.Ruler"], []);
goog.addDependency("../../src/observer.js", ["fontface.Observer"], ["fontface.Ruler","dom","lang.Promise"]);
goog.addDependency("../../src/ruler.js", ["fontface.Ruler"], ["dom"]);
goog.addDependency("../../node_modules/promis/src/async.js", ["lang.async"], []);
goog.addDependency("../../node_modules/promis/src/promise.js", ["lang.Promise"], ["lang.async"]);
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