UNPKG

@codegouvfr/react-dsfr

Version:

French State Design System React integration library

4 lines (3 loc) 2.53 kB
/*! DSFR v1.8.5 | SPDX-License-Identifier: MIT | License-Filename: LICENSE.md | restricted use (see terms and conditions) */ !function(){"use strict";var t=window.dsfr,e={DOWNLOAD_ASSESS_FILE:""+t.internals.ns.attr.selector("assess-file"),DOWNLOAD_DETAIL:""+t.internals.ns.selector("download__detail")},n=function(n){function s(){n.apply(this,arguments)}n&&(s.__proto__=n),s.prototype=Object.create(n&&n.prototype),s.prototype.constructor=s;var i={instanceClassName:{configurable:!0}};return i.instanceClassName.get=function(){return"AssessFile"},s.prototype.init=function(){this.lang=this.getLang(this.node),this.href=this.getAttribute("href"),this.hreflang=this.getAttribute("hreflang"),this.file={},this.detail=this.querySelector(e.DOWNLOAD_DETAIL),this.update()},s.prototype.getFileLength=function(){var t=this;void 0!==this.href?fetch(this.href,{method:"HEAD",mode:"cors"}).then((function(e){t.length=e.headers.get("content-length")||-1,-1===t.length&&console.warn("Impossible de détecter le poids du fichier "+t.href+'\nErreur de récupération de l\'en-tête HTTP : "content-length"'),t.update()})):this.length=-1},s.prototype.update=function(){if(this.isLegacy&&(this.length=-1),this.length){var t=[];if(this.detail){if(this.href){var e=this.parseExtension(this.href);e&&t.push(e.toUpperCase())}-1!==this.length&&t.push(this.bytesToSize(this.length)),this.hreflang&&t.push(this.getLangDisplayName(this.hreflang)),this.detail.innerHTML=t.join(" - ")}}else this.getFileLength()},s.prototype.getLang=function(t){return t.lang?t.lang:document.documentElement===t?window.navigator.language:this.getLang(t.parentElement)},s.prototype.parseExtension=function(t){return t.match(/\.(\w{1,9})(?:$|[?#])/)[0].replace(".","")},s.prototype.getLangDisplayName=function(t){if(this.isLegacy)return t;var e=new Intl.DisplayNames([this.lang],{type:"language"}).of(t);return e.charAt(0).toUpperCase()+e.slice(1)},s.prototype.bytesToSize=function(e){if(-1===e)return null;var n=["octets","ko","Mo","Go","To"];"bytes"===this.getAttribute(t.internals.ns.attr("assess-file"))&&(n=["bytes","KB","MB","GB","TB"]);var s=parseInt(Math.floor(Math.log(e)/Math.log(1e3)),10);if(0===s)return e+" "+n[s];var i=e/Math.pow(1e3,s),r=Math.round(100*(i+Number.EPSILON))/100;return String(r).replace(".",",")+" "+n[s]},Object.defineProperties(s,i),s}(t.core.Instance);t.download={DownloadSelector:e,AssessFile:n},t.internals.register(t.download.DownloadSelector.DOWNLOAD_ASSESS_FILE,t.download.AssessFile)}(); //# sourceMappingURL=download.nomodule.min.js.map