amp-font-0.1.js 6.6 KB
;
(self.AMP=self.AMP||[]).push({m:0,v:"2402231941000",n:"amp-font",ev:"0.1",l:!0,f:function(n,t){!function(){function t(n,i){return(t=Object.setPrototypeOf||function(n,t){return n.__proto__=t,n})(n,i)}function i(n){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)})(n)}function r(n){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(n)}function e(n,t){if(t&&("object"===r(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(n){if(void 0===n)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return n}(n)}Array.isArray;var o=Object.prototype;o.hasOwnProperty,o.toString,self.__AMP_LOG=self.__AMP_LOG||{user:null,dev:null,userForEmbed:null};var u=self.__AMP_LOG;function f(n){return u.user||(u.user=s()),function(n,t){return t&&t.ownerDocument.defaultView!=n}(u.user.win,n)?u.userForEmbed||(u.userForEmbed=s()):u.user}function s(n){return function(n,t){throw new Error("failed to call initLogConstructor")}()}function c(n,t,i,r,e,o,u,f,s,c,a){return n}function a(n,t){c(function(n,t){var i=n.__AMP_SERVICES&&n.__AMP_SERVICES[t];return!(!i||!i.ctor)}(n,t));var i=function(n){var t=n.__AMP_SERVICES;return t||(t=n.__AMP_SERVICES={}),t}(n)[t];return i.obj||(c(i.ctor),c(i.context),i.obj=new i.ctor(i.context),c(i.obj),i.context=null,i.resolve&&i.resolve(i.obj)),i.obj}var h,l=function(n){return a(n,"timer")},d=["Webkit","webkit","Moz","moz","ms","O","o"];function v(n,t,i,r,e){var o=function(n,t,i){if(t.startsWith("--"))return t;h||(h=Object.create(null));var r=h[t];if(!r||i){if(r=t,void 0===n[t]){var e=function(n){return n.charAt(0).toUpperCase()+n.slice(1)}(t),o=function(n,t){for(var i=0;i<d.length;i++){var r=d[i]+t;if(void 0!==n[r])return r}return""}(n,e);void 0!==n[o]&&(r=o)}i||(h[t]=r)}return r}(n.style,t,e);if(o){var u,f=r?i+r:i;n.style.setProperty((u=o.replace(/[A-Z]/g,(function(n){return"-"+n.toLowerCase()})),d.some((function(n){return u.startsWith(n+"-")}))?"-".concat(u):u),f)}}function m(n,t){for(var i in t)v(n,i,t[i])}var y=["sans-serif","serif"],b=function(){function n(n){this.Ki=n,this.Qf=n.win.document,this.mb=null,this.iF=null,this.oF=!1,this.uF=!1}var t=n.prototype;return t.load=function(n,t){var i=this;return this.iF=n,l(this.Ki.win).timeoutPromise(t,this.fF()).then((function(){i.oF=!0,i.sF()}),(function(n){throw i.uF=!0,i.sF(),n}))},t.fF=function(){var n=this;return new Promise((function(t,i){var r=n.iF.fontStyle+" "+n.iF.variant+" "+n.iF.weight+" "+n.iF.size+" '"+n.iF.family+"'";n.cF()?n.Qf.fonts.check(r)?t():n.Qf.fonts.load(r).then((function(){return n.Qf.fonts.load(r)})).then((function(){n.Qf.fonts.check(r)?t():i(new Error("Font could not be loaded, probably due to incorrect @font-face."))})).catch(i):n.aF().then(t,i)}))},t.cF=function(){return"fonts"in this.Qf},t.aF=function(){var n=this;return new Promise((function(t,i){var r,e,o=(r=n.Ki.win,a((e=r).__AMP_TOP||(e.__AMP_TOP=e),"vsync")),u=n.hF(),f=o.createTask({measure:function(){n.oF?t():n.uF?i(new Error("Font loading timed out.")):u.some((function(n){return n.compare()}))?t():f()}});f()}))},t.hF=function(){var n=this,t=this.mb=this.Qf.createElement("div");m(t,{fontSize:"40px",fontVariant:this.iF.variant,fontWeight:this.iF.weight,fontStyle:this.iF.fontStyle,left:"-999px",lineHeight:"normal",margin:0,padding:0,position:"absolute",top:"-999px",visibility:"hidden"});var i=y.map((function(i){return new p(t,n.iF.family,i)}));return this.Ki.getBody().appendChild(t),i},t.sF=function(){var n,t;this.mb&&(null===(t=(n=this.mb).parentElement)||void 0===t||t.removeChild(n)),this.mb=null},n}(),p=function(){function n(n,t,i){var r=n.ownerDocument,e="".concat(t,",").concat(i);this.lF=this.dF(r,i),this.vF=this.dF(r,e),n.appendChild(this.lF),n.appendChild(this.vF)}var t=n.prototype;return t.dF=function(n,t){var i=n.createElement("div");return i.textContent="MAxmTYklsjo190QW",m(i,{float:"left",fontFamily:t,margin:0,padding:0,whiteSpace:"nowrap"}),i},t.compare=function(){var n=Math.abs(this.lF.offsetWidth-this.vF.offsetWidth)>2,t=Math.abs(this.lF.offsetHeight-this.vF.offsetHeight)>2;return n||t},n}(),w="amp-font",g=function(n){!function(n,i){if("function"!=typeof i&&null!==i)throw new TypeError("Super expression must either be null or a function");n.prototype=Object.create(i&&i.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),i&&t(n,i)}(s,n);var r,o,u=(r=s,o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(n){return!1}}(),function(){var n,t=i(r);if(o){var u=i(this).constructor;n=Reflect.construct(t,arguments,u)}else n=t.apply(this,arguments);return e(this,n)});function s(n){var t;return(t=u.call(this,n)).mF="",t.yF="",t.bF="",t.pF="",t.wF=null,t}s.prerenderAllowed=function(){return!0};var c=s.prototype;return c.buildCallback=function(){var n,t;this.mF=(n=this.element.getAttribute("font-family"),"The font-family attribute is required for <amp-font> %s",t=this.element,f().assert(n,"The font-family attribute is required for <amp-font> %s",t,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined)),this.yF=this.element.getAttribute("font-weight")||"400",this.bF=this.element.getAttribute("font-style")||"normal",this.pF=this.element.getAttribute("font-variant")||"normal",this.wF=new b(this.getAmpDoc()),this.gF()},c.gF=function(){var n=this,t={fontStyle:this.bF,variant:this.pF,weight:this.yF,size:"medium",family:this.mF};this.wF.load(t,this.jF()).then((function(){n.SF()})).catch((function(t){n.OF(),f().warn(w,"Font download timed out for "+n.mF)}))},c.SF=function(){var n=this.element.getAttribute("on-load-add-class"),t=this.element.getAttribute("on-load-remove-class");this.EF(n,t)},c.OF=function(){var n=this.element.getAttribute("on-error-add-class"),t=this.element.getAttribute("on-error-remove-class");this.EF(n,t)},c.EF=function(n,t){var i=this.getAmpDoc(),r=i.getRootNode().documentElement||i.getBody();n&&r.classList.add(n),t&&r.classList.remove(t),this.sF()},c.sF=function(){this.wF=null},c.jF=function(){var n,t=parseInt(this.element.getAttribute("timeout"),10);return t="number"!=typeof(n=t)||!isFinite(n)||t<0?3e3:t,Math.max(t-l(this.win).timeSinceStart(),100)},s}(n.BaseElement);n.registerElement(w,g)}();
/*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */}});
//# sourceMappingURL=amp-font-0.1.js.map