From 5e43887098f7e243495c615e200374c94d700ba3 Mon Sep 17 00:00:00 2001 From: Claudio Biselli Date: Mon, 2 Dec 2024 09:31:23 +0100 Subject: [PATCH 1/6] updated co2js --- .../conditional_metrics/carbon-footprint.js | 53 ++++++++++++------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/www/assets/js/conditional_metrics/carbon-footprint.js b/www/assets/js/conditional_metrics/carbon-footprint.js index 5f77c75b24..f748b4cc3c 100644 --- a/www/assets/js/conditional_metrics/carbon-footprint.js +++ b/www/assets/js/conditional_metrics/carbon-footprint.js @@ -1,23 +1,31 @@ +// co2js version 0.16 // prettier-ignore -var co2=(()=>{var Ee=Object.create;var _=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var me=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var L=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),he=(r,e)=>{for(var t in e)_(r,t,{get:e[t],enumerable:!0})},ee=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ye(e))!pe.call(r,n)&&n!==t&&_(r,n,{get:()=>e[n],enumerable:!(o=Re(e,n))||o.enumerable});return r};var D=(r,e,t)=>(t=r!=null?Ee(me(r)):{},ee(e||!r||!r.__esModule?_(t,"default",{value:r,enumerable:!0}):t,r)),Ne=r=>ee(_({},"__esModule",{value:!0}),r);var ne=L((ze,re)=>{var h=1e3,N=h*60,I=N*60,p=I*24,Ie=p*7,Ae=p*365.25;re.exports=function(r,e){e=e||{};var t=typeof r;if(t==="string"&&r.length>0)return Te(r);if(t==="number"&&isFinite(r))return e.long?Oe(r):be(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function Te(r){if(r=String(r),!(r.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(!!e){var t=parseFloat(e[1]),o=(e[2]||"ms").toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return t*Ae;case"weeks":case"week":case"w":return t*Ie;case"days":case"day":case"d":return t*p;case"hours":case"hour":case"hrs":case"hr":case"h":return t*I;case"minutes":case"minute":case"mins":case"min":case"m":return t*N;case"seconds":case"second":case"secs":case"sec":case"s":return t*h;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function be(r){var e=Math.abs(r);return e>=p?Math.round(r/p)+"d":e>=I?Math.round(r/I)+"h":e>=N?Math.round(r/N)+"m":e>=h?Math.round(r/h)+"s":r+"ms"}function Oe(r){var e=Math.abs(r);return e>=p?G(r,e,p,"day"):e>=I?G(r,e,I,"hour"):e>=N?G(r,e,N,"minute"):e>=h?G(r,e,h,"second"):r+" ms"}function G(r,e,t,o){var n=e>=t*1.5;return Math.round(r/t)+" "+o+(n?"s":"")}});var se=L((Je,oe)=>{function Se(r){t.debug=t,t.default=t,t.coerce=C,t.disable=i,t.enable=n,t.enabled=a,t.humanize=ne(),t.destroy=l,Object.keys(r).forEach(s=>{t[s]=r[s]}),t.names=[],t.skips=[],t.formatters={};function e(s){let c=0;for(let d=0;d{if(M==="%%")return"%";B++;let X=t.formatters[Ce];if(typeof X=="function"){let ge=E[B];M=X.call(m,ge),E.splice(B,1),B--}return M}),t.formatArgs.call(m,E),(m.log||t.log).apply(m,E)}return R.namespace=s,R.useColors=t.useColors(),R.color=t.selectColor(s),R.extend=o,R.destroy=t.destroy,Object.defineProperty(R,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(F!==t.namespaces&&(F=t.namespaces,q=t.enabled(s)),q),set:E=>{d=E}}),typeof t.init=="function"&&t.init(R),R}function o(s,c){let d=t(this.namespace+(typeof c>"u"?":":c)+s);return d.log=this.log,d}function n(s){t.save(s),t.namespaces=s,t.names=[],t.skips=[];let c,d=(typeof s=="string"?s:"").split(/[\s,]+/),F=d.length;for(c=0;c"-"+c)].join(",");return t.enable(""),s}function a(s){if(s[s.length-1]==="*")return!0;let c,d;for(c=0,d=t.skips.length;c{g.formatArgs=Pe;g.save=Be;g.load=_e;g.useColors=Fe;g.storage=Ge();g.destroy=(()=>{let r=!1;return()=>{r||(r=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();g.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Fe(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Pe(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+v.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;r.splice(1,0,e,"color: inherit");let t=0,o=0;r[0].replace(/%[a-zA-Z%]/g,n=>{n!=="%%"&&(t++,n==="%c"&&(o=t))}),r.splice(o,0,e)}g.log=console.debug||console.log||(()=>{});function Be(r){try{r?g.storage.setItem("debug",r):g.storage.removeItem("debug")}catch{}}function _e(){let r;try{r=g.storage.getItem("debug")}catch{}return!r&&typeof process<"u"&&"env"in process&&(r=process.env.DEBUG),r}function Ge(){try{return localStorage}catch{}}v.exports=se()(g);var{formatters:ve}=v.exports;ve.j=function(r){try{return JSON.stringify(r)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var xe={};he(xe,{averageIntensity:()=>y,co2:()=>z,default:()=>He,hosting:()=>J,marginalIntensity:()=>Q});var V=4883333333333333e-25;var U=class{constructor(e){this.options=e,this.KWH_PER_BYTE_FOR_NETWORK=V}perByte(e,t){if(e<1)return 0;if(t){let n=e*72e-12*0,i=e*V*475;return n+i}let o=72e-12+V;return e*o*519}};var te=U;var ce=D(w());var K={GIGABYTE:1e9};var ie=.81,W=.52,Y=.14,k=.15,H=.19,u=442,T=50,b=.75,O=.25,S=.02;var A=r=>parseFloat(r.toFixed(2));function x(r){if(typeof r!="object")throw new Error("Options must be an object");let e={};if(r?.gridIntensity){e.gridIntensity={};let{device:t,dataCenter:o,network:n}=r.gridIntensity;t&&(typeof t=="object"?(y.data[t.country?.toUpperCase()]||(console.warn(`"${t.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. -See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. -Falling back to global average grid intensity.`),e.gridIntensity.device={value:u}),e.gridIntensity.device={country:t.country,value:parseFloat(y.data[t.country?.toUpperCase()])}):typeof t=="number"?e.gridIntensity.device={value:t}:(e.gridIntensity.device={value:u},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof t}. -Falling back to global average grid intensity.`))),o&&(typeof o=="object"?(y.data[o.country?.toUpperCase()]||(console.warn(`"${o.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. -See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. -Falling back to global average grid intensity.`),e.gridIntensity.dataCenter={value:u}),e.gridIntensity.dataCenter={country:o.country,value:parseFloat(y.data[o.country?.toUpperCase()])}):typeof o=="number"?e.gridIntensity.dataCenter={value:o}:(e.gridIntensity.dataCenter={value:u},console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof o}. -Falling back to global average grid intensity.`))),n&&(typeof n=="object"?(y.data[n.country?.toUpperCase()]||(console.warn(`"${n.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. -See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. -Falling back to global average grid intensity.`),e.gridIntensity.network={value:u}),e.gridIntensity.network={country:n.country,value:parseFloat(y.data[n.country?.toUpperCase()])}):typeof n=="number"?e.gridIntensity.network={value:n}:(e.gridIntensity.network={value:u},console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof n}. -Falling back to global average grid intensity.`)))}return r?.dataReloadRatio&&(typeof r.dataReloadRatio=="number"?r.dataReloadRatio>=0&&r.dataReloadRatio<=1?e.dataReloadRatio=r.dataReloadRatio:(e.dataReloadRatio=S,console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${r.dataReloadRatio}. -Falling back to default value.`)):(e.dataReloadRatio=S,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof r.dataReloadRatio}. -Falling back to default value.`))),r?.firstVisitPercentage&&(typeof r.firstVisitPercentage=="number"?r.firstVisitPercentage>=0&&r.firstVisitPercentage<=1?e.firstVisitPercentage=r.firstVisitPercentage:(e.firstVisitPercentage=b,console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${r.firstVisitPercentage}. -Falling back to default value.`)):(e.firstVisitPercentage=b,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof r.firstVisitPercentage}. -Falling back to default value.`))),r?.returnVisitPercentage&&(typeof r.returnVisitPercentage=="number"?r.returnVisitPercentage>=0&&r.returnVisitPercentage<=1?e.returnVisitPercentage=r.returnVisitPercentage:(e.returnVisitPercentage=O,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${r.returnVisitPercentage}. -Falling back to default value.`)):(e.returnVisitPercentage=O,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof r.returnVisitPercentage}. -Falling back to default value.`))),e}var ae=(0,ce.default)("tgwf:sustainable-web-design"),j=class{constructor(e){this.options=e}energyPerByteByComponent(e){let o=e/K.GIGABYTE*ie;return{consumerDeviceEnergy:o*W,networkEnergy:o*Y,productionEnergy:o*H,dataCenterEnergy:o*k}}co2byComponent(e,t=u,o={}){let n=u,i=u,a=u,f=u;if(o?.gridIntensity){let{device:l,network:s,dataCenter:c}=o.gridIntensity;l?.value&&(n=l.value),s?.value&&(i=s.value),c?.value&&(a=c.value)}t===!0&&(a=T);let C={};for(let[l,s]of Object.entries(e))l.startsWith("dataCenterEnergy")?C[l.replace("Energy","CO2")]=s*a:l.startsWith("consumerDeviceEnergy")?C[l.replace("Energy","CO2")]=s*n:l.startsWith("networkEnergy")?C[l.replace("Energy","CO2")]=s*i:C[l.replace("Energy","CO2")]=s*f;return C}perByte(e,t=!1,o=!1,n={}){let i=this.energyPerByteByComponent(e,n);if(typeof t!="boolean")throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${t}`);let a=this.co2byComponent(i,t,n),C=Object.values(a).reduce((l,s)=>l+s);return o?{...a,total:C}:C}perVisit(e,t=!1,o=!1,n={}){let i=this.energyPerVisitByComponent(e,n);if(typeof t!="boolean")throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${t}`);let a=this.co2byComponent(i,t,n),C=Object.values(a).reduce((l,s)=>l+s);return o?{...a,total:C}:C}energyPerByte(e){let t=this.energyPerByteByComponent(e);return Object.values(t).reduce((n,i)=>n+i)}energyPerVisitByComponent(e,t={},o=b,n=O,i=S){t.dataReloadRatio&&(i=t.dataReloadRatio),t.firstVisitPercentage&&(o=t.firstVisitPercentage),t.returnVisitPercentage&&(n=t.returnVisitPercentage);let a=this.energyPerByteByComponent(e),f={};ae({energyBycomponent:a});let C=Object.values(a);for(let[l,s]of Object.entries(a))f[`${l} - first`]=s*o,f[`${l} - subsequent`]=s*n*i;return ae({cacheAdjustedSegmentEnergy:f}),f}energyPerVisit(e){let t=0,o=0,n=Object.entries(this.energyPerVisitByComponent(e));for(let[i,a]of n)i.indexOf("first")>0&&(t+=a);for(let[i,a]of n)i.indexOf("subsequent")>0&&(o+=a);return t+o}emissionsPerVisitInGrams(e,t=u){return A(e*t)}annualEnergyInKwh(e,t=1e3){return e*t*12}annualEmissionsInGrams(e,t=1e3){return e*t*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:A(e*W),networkEnergy:A(e*Y),dataCenterEnergy:A(e*k),productionEnergy:A(e*H)}}};var Z=j;var $=class{constructor(e){if(this.model=new Z,e?.model==="1byte")this.model=new te;else if(e?.model==="swd")this.model=new Z;else if(e?.model)throw new Error(`"${e.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model. -See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);e?.results==="segment"?this.model.results={segment:!0}:this.model.results={segment:!1}}perByte(e,t=!1){return this.model.perByte(e,t,this.model.results.segment)}perVisit(e,t=!1){if(this.model?.perVisit)return this.model.perVisit(e,t,this.model.results.segment);throw new Error(`The perVisit() method is not supported in the model you are using. Try using perByte() instead. -See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`)}perByteTrace(e,t=!1,o={}){let n={};return o&&(n=x(o)),{co2:this.model.perByte(e,t,this.model.results.segment,n),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:n?.gridIntensity?.network?.value||u,dataCenter:t?T:n?.gridIntensity?.dataCenter?.value||u,production:u,device:n?.gridIntensity?.device?.value||u}}}}perVisitTrace(e,t=!1,o={}){if(this.model?.perVisit){let n={};return o&&(n=x(o)),{co2:this.model.perVisit(e,t,this.model.results.segment,n),green:t,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",network:n?.gridIntensity?.network?.value||u,dataCenter:t?T:n?.gridIntensity?.dataCenter?.value||u,production:u,device:n?.gridIntensity?.device?.value||u},dataReloadRatio:n?.dataReloadRatio||.02,firstVisitPercentage:n?.firstVisitPercentage||.75,returnVisitPercentage:n?.returnVisitPercentage||.25}}}else throw new Error(`The perVisitDetailed() method is not supported in the model you are using. Try using perByte() instead. -See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`)}perDomain(e,t){let o=[];for(let n of Object.keys(e.domains)){let i;t&&t.indexOf(n)>-1?i=this.perByte(e.domains[n].transferSize,!0):i=this.perByte(e.domains[n].transferSize),o.push({domain:n,co2:i,transferSize:e.domains[n].transferSize})}return o.sort((n,i)=>i.co2-n.co2),o}perPage(e,t){let o=this.perDomain(e,t),n=0;for(let i of o)n+=i.co2;return n}perContentType(e,t){let o={};for(let i of e.assets){let a=new URL(i.url).domain,f=i.transferSize,C=this.perByte(f,t&&t.indexOf(a)>-1),l=i.type;o[l]||(o[l]={co2:0,transferSize:0}),o[l].co2+=C,o[l].transferSize+=f}let n=[];for(let i of Object.keys(o))n.push({type:i,co2:o[i].co2,transferSize:o[i].transferSize});return n.sort((i,a)=>a.co2-i.co2),n}dirtiestResources(e,t){let o=[];for(let n of e.assets){let i=new URL(n.url).domain,a=n.transferSize,f=this.perByte(a,t&&t.indexOf(i)>-1);o.push({url:n.url,co2:f,transferSize:a})}return o.sort((n,i)=>i.co2-n.co2),o.slice(0,o.length>10?10:o.length)}perParty(e,t){let o=0,n=0,i=e.firstPartyRegEx;for(let a of Object.keys(e.domains))a.match(i)?o+=this.perByte(e.domains[a].transferSize,t&&t.indexOf(a)>-1):n+=this.perByte(e.domains[a].transferSize,t&&t.indexOf(a)>-1);return{firstParty:o,thirdParty:n}}};var z=$;var de=D(w());var le=D(w()),dt=(0,le.default)("tgwf:hostingAPI");function we(r){return typeof r=="string"?Me(r):Le(r)}async function Me(r){return(await(await fetch(`https://api.thegreenwebfoundation.org/greencheck/${r}`)).json()).green}async function Le(r){try{let e="https://api.thegreenwebfoundation.org/v2/greencheckmulti",t=JSON.stringify(r),n=await(await fetch(`${e}/${t}`)).json();return De(n)}catch{return[]}}function De(r){return Object.entries(r).filter(([o,n])=>n.green).map(([o,n])=>n.url)}var ue={check:we};var Ct=(0,de.default)("tgwf:hosting");function Ve(r,e){return ue.check(r)}var J={check:Ve};var Ue={AFG:120.482,AFRICA:483.78,ALB:23.438,DZA:488.393,ASM:687.5,AGO:168.594,ATG:657.143,ARG:337.533,ARM:222.678,ABW:591.398,ASIA:531.78,AUS:503.179,AUT:157.52,AZE:532.902,BHS:698.113,BHR:489.924,BGD:581.485,BRB:644.86,BLR:415.774,BEL:165.363,BLZ:484.375,BEN:666.667,BTN:24.444,BOL:319.432,BIH:516.626,BWA:794.521,BRA:102.411,BRN:658.849,BGR:399.565,BFA:611.429,BDI:250,CPV:600,KHM:399.31,CMR:278.261,CAN:125.55,CYM:684.932,CAF:0,TCD:677.419,CHL:333.173,CHN:530.214,COL:169.309,COM:714.286,COG:398.01,COD:25.362,COK:400,CRI:37.213,CIV:390.71,HRV:246.459,CUB:574.684,CYP:589.354,CZE:415.345,DNK:180.709,DJI:666.667,DMA:529.412,DOM:540.387,ECU:169.384,EGY:485.367,SLV:194.226,GNQ:492.958,ERI:688.889,EST:464.029,SWZ:189.189,ETH:25.187,EU:277.35,EUROPE:298.01,FLK:500,FRO:428.571,FJI:292.035,FIN:130.977,FRA:84.817,GUF:254.717,PYF:471.429,G20:440.39,G7:341.23,GAB:397.38,GMB:700,GEO:134.831,DEU:385.467,GHA:362.942,GRC:343.822,GRL:133.333,GRD:714.286,GLP:611.765,GUM:670.33,GTM:313.019,GIN:208.633,GNB:750,GUY:634.146,HTI:606.061,HND:374.269,HKG:684.823,HUN:222.973,ISL:28.557,IND:632.406,IDN:623.281,IRN:493.595,IRQ:500.206,IRL:345.347,ISR:550.493,ITA:371.692,JAM:524.138,JPN:483.039,JOR:399.909,KAZ:635.574,KEN:99.919,KIR:666.667,XKX:766.605,KWT:489.61,KGZ:104.354,LAO:242.182,"LATIN AMERICA AND CARIBBEAN":238.27,LVA:181.818,LBN:545.941,LSO:20,LBR:304.348,LBY:496.565,LTU:194.245,LUX:168.142,MAC:491.525,MDG:483.254,MWI:133.803,MYS:543.737,MDV:651.515,MLI:466.077,MLT:442.478,MTQ:698.63,MRT:526.596,MUS:611.111,MEX:421.402,"MIDDLE EAST":514.89,MDA:685.874,MNG:749.656,MNE:399.381,MSR:1e3,MAR:610.412,MOZ:125.063,MMR:348.837,NAM:63.694,NRU:750,NPL:24.51,NLD:354.988,NCL:610.119,NZL:98.639,NIC:354.212,NER:622.222,NGA:368.421,"NORTH AMERICA":336.4,PRK:157.785,MKD:529.328,NOR:28.818,OCEANIA:446.65,OECD:338.75,OMN:488.272,PAK:343.366,PSE:465.116,PAN:193.923,PNG:526.749,PRY:25.487,PER:254.521,POL:634.579,PRT:234.029,PRI:681.469,QAT:489.867,REU:519.031,ROU:264.121,RUS:367.189,RWA:294.118,KNA:681.818,LCA:685.714,SPM:800,VCT:500,WSM:470.588,STP:600,SAU:571.336,SEN:502.674,SRB:569.375,SYC:615.385,SLE:47.619,SGP:489.234,SVK:140.666,SVN:237.378,SLB:727.273,SOM:634.146,ZAF:709.002,KOR:435.689,SSD:684.211,ESP:217.373,LKA:479.829,SDN:242.917,SUR:356.436,SWE:45.084,CHE:45.622,SYR:540.573,TWN:561.431,TJK:84.136,TZA:361.077,THA:503.07,PHL:582.365,TGO:507.937,TON:625,TTO:520.046,TUN:469.428,TUR:413.628,TKM:544.393,TCA:703.704,UGA:52.273,UKR:206.539,ARE:461.845,GBR:257.379,USA:367.768,URY:116.168,UZB:506.164,VUT:571.429,VEN:189.446,VNM:376.828,VGB:714.286,VIR:685.714,WORLD:435.99,YEM:528.409,ZMB:84.698,ZWE:393.035},Ke="average";var y={data:Ue,type:Ke};var We={AFG:"414",ALB:"0",DZA:"528",ASM:"753",AND:"188",AGO:"1476",AIA:"753",ATG:"753",ARG:"478",ARM:"390",ABW:"753",AUS:"808",AUT:"242",AZE:"534","AZORES (PORTUGAL)":"753",BHS:"753",BHR:"726",BGD:"528",BRB:"749",BLR:"400",BEL:"252",BLZ:"403",BEN:"745",BMU:"753",BTN:"0",BOL:"604",BES:"753",BIH:"1197",BWA:"1486",BRA:"284",VGB:"753",BRN:"681",BGR:"911",BFA:"753",BDI:"414",KHM:"1046",CMR:"659",CAN:"372",CYM:"753",CPV:"753",CAF:"188",TCD:"753","CHANNEL ISLANDS (U.K)":"753",CHL:"657",CHN:"899",COL:"410",COM:"753",COD:"0",COG:"659",COK:"753",CRI:"108",CIV:"466",HRV:"294",CUB:"559",CUW:"876",CYP:"751",CZE:"902",DNK:"362",DJI:"753",DMA:"753",DOM:"601",ECU:"560",EGY:"554",SLV:"547",GNQ:"632",ERI:"915",EST:"1057",SWZ:"0",ETH:"0",FLK:"753",FRO:"753",FJI:"640",FIN:"267",FRA:"158",GUF:"423",PYF:"753",GAB:"946",GMB:"753",GEO:"289",DEU:"650",GHA:"495",GIB:"779",GRC:"507",GRL:"264",GRD:"753",GLP:"753",GUM:"753",GTM:"798",GIN:"753",GNB:"753",GUY:"847",HTI:"1048",HND:"662",HUN:"296",ISL:"0",IND:"951",IDN:"783",IRN:"592",IRQ:"1080",IRL:"380",IMN:"436",ISR:"394",ITA:"414",JAM:"711",JPN:"471",JOR:"529",KAZ:"797",KEN:"574",KIR:"753",PRK:"754",KOR:"555",XKX:"1145",KWT:"675",KGZ:"217",LAO:"1069",LVA:"240",LBN:"794",LSO:"0",LBR:"677",LBY:"668",LIE:"151",LTU:"211",LUX:"220",MDG:"876","MADEIRA (PORTUGAL)":"663",MWI:"489",MYS:"551",MDV:"753",MLI:"1076",MLT:"520",MHL:"753",MTQ:"753",MRT:"753",MUS:"700",MYT:"753",MEX:"531",FSM:"753",MDA:"541",MCO:"158",MNG:"1366",MNE:"899",MSR:"753",MAR:"729",MOZ:"234",MMR:"719",NAM:"355",NRU:"753",NPL:"0",NLD:"326",NCL:"779",NZL:"246",NIC:"675",NER:"772",NGA:"526",NIU:"753",MKD:"851",MNP:"753",NOR:"47",OMN:"479",PAK:"592",PLW:"753",PSE:"719",PAN:"477",PNG:"597",PRY:"0",PER:"473",PHL:"672",POL:"828",PRT:"389",PRI:"596",QAT:"503",REU:"772",ROU:"489",RUS:"476",RWA:"712",SHN:"753",KNA:"753",LCA:"753",MAF:"753",SPM:"753",VCT:"753",WSM:"753",SMR:"414",STP:"753",SAU:"592",SEN:"870",SRB:"1086",SYC:"753",SLE:"489",SGP:"379",SXM:"753",SVK:"332",SVN:"620",SLB:"753",SOM:"753",ZAF:"1070",SSD:"890",ESP:"402",LKA:"731",SDN:"736",SUR:"1029",SWE:"68",CHE:"48",SYR:"713",TWN:"484",TJK:"255",TZA:"531",THA:"450",TLS:"753",TGO:"859",TON:"753",TTO:"559",TUN:"468",TUR:"376",TKM:"927",TCA:"753",TUV:"753",UGA:"279",UKR:"768",ARE:"556",GBR:"380",USA:"416",URY:"174",UZB:"612",VUT:"753",VEN:"711",VNM:"560",VIR:"650",YEM:"807",ZMB:"416",ZWE:"1575","MEMO: EU 27":"409"},Ye="marginal",ke="2021";var Q={data:We,type:Ye,year:ke};var He={co2:z,hosting:J,averageIntensity:y,marginalIntensity:Q};return Ne(xe);})(); +var co2=(()=>{var ae=Object.create;var P=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var le=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Ee=(t,e)=>{for(var r in e)P(t,r,{get:e[r],enumerable:!0})},j=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of oe(e))!ce.call(t,n)&&n!==r&&P(t,n,{get:()=>e[n],enumerable:!(a=ie(e,n))||a.enumerable});return t};var ue=(t,e,r)=>(r=t!=null?ae(se(t)):{},j(e||!t||!t.__esModule?P(r,"default",{value:t,enumerable:!0}):r,t)),de=t=>j(P({},"__esModule",{value:!0}),t);var te=le((ct,ee)=>{"use strict";async function me(t,e){return typeof t=="string"?Oe(t,e):Pe(t,e)}function Oe(t,e){return e.indexOf(t)>-1}function ye(t){return Object.entries(t).filter(([a,n])=>n.green).map(([a,n])=>n.url)}function Pe(t,e){let r=[];for(let a of t)e.indexOf(a)>-1&&r.push(a);return r}function Ge(t,e){return typeof t=="string"?z(t,e):Se(t,e)}function z(t,e){return e.indexOf(t)>-1?t:{url:t,green:!1}}function Se(t,e){let r={};for(let a of t)r[a]=z(a,e);return r}ee.exports={check:me,greenDomainsFromResults:ye,find:Ge}});var we={};Ee(we,{averageIntensity:()=>R,co2:()=>U,default:()=>Me,hosting:()=>K,marginalIntensity:()=>k});var B=4883333333333333e-25;var D=class{constructor(e){this.allowRatings=!1,this.options=e,this.KWH_PER_BYTE_FOR_NETWORK=B}perByte(e,r){if(e<1)return 0;if(r){let n=e*72e-12*0,i=e*B*475;return n+i}let a=72e-12+B;return e*a*519}};var x=D;var N={GIGABYTE:1e9};var Re={AFG:132.53,AFRICA:545.15,ALB:24.29,DZA:634.61,ASM:611.11,AGO:174.73,ATG:611.11,ARG:354.1,ARM:264.54,ABW:561.22,ASEAN:569.86,ASIA:589.78,AUS:548.69,AUT:110.81,AZE:671.39,BHS:660.1,BHR:904.62,BGD:691.41,BRB:605.51,BLR:441.74,BEL:138.11,BLZ:225.81,BEN:584.07,BTN:23.33,BOL:531.69,BIH:601.29,BWA:847.91,BRA:98.32,BRN:893.91,BGR:335.33,BFA:467.53,BDI:250,CPV:558.14,KHM:417.71,CMR:305.42,CAN:171.12,CYM:642.86,CAF:0,TCD:628.57,CHL:291.11,CHN:582.29,COL:259.51,COM:642.86,COG:700,COD:24.46,COK:250,CRI:53.38,CIV:393.89,HRV:204.96,CUB:637.61,CYP:534.32,CZE:449.72,DNK:151.65,DJI:692.31,DMA:529.41,DOM:580.78,ECU:166.91,EGY:570.31,SLV:224.76,GNQ:591.84,ERI:631.58,EST:416.67,SWZ:172.41,ETH:24.64,EU:243.83,EUROPE:300.24,FLK:500,FRO:404.76,FJI:288.46,FIN:79.16,FRA:56.02,GUF:217.82,PYF:442.86,G20:477.08,G7:341.01,GAB:491.6,GMB:666.67,GEO:167.59,DEU:380.95,GHA:484,GRC:336.57,GRL:178.57,GRD:640,GLP:500,GUM:622.86,GTM:328.27,GIN:236.84,GNB:625,GUY:640.35,HTI:567.31,HND:282.27,HKG:699.5,HUN:204.19,ISL:27.68,IND:713.44,IDN:675.93,IRN:655.13,IRQ:688.81,IRL:290.81,ISR:582.93,ITA:330.72,JAM:555.56,JPN:485.39,JOR:540.92,KAZ:821.39,KEN:70.49,KIR:666.67,XKX:894.65,KWT:649.16,KGZ:147.29,LAO:265.51,"LATIN AMERICA AND CARIBBEAN":258.18,LVA:123.2,LBN:599.01,LSO:20,LBR:227.85,LBY:818.69,LTU:160.07,LUX:105.26,MAC:448.98,MDG:436.44,MWI:66.67,MYS:605.32,MDV:611.77,MLI:408,MLT:459.14,MTQ:523.18,MRT:464.71,MUS:632.48,MEX:507.25,"MIDDLE EAST":657.56,MDA:643.46,MNG:775.31,MNE:418.09,MSR:1e3,MAR:630.01,MOZ:135.65,MMR:398.9,NAM:59.26,NRU:750,NPL:24.44,NLD:267.62,NCL:660.58,NZL:112.76,NIC:265.12,NER:670.89,NGA:523.25,"NORTH AMERICA":343.66,PRK:389.59,MKD:556.19,NOR:30.08,OCEANIA:489.62,OECD:341.16,OMN:564.64,PAK:440.61,PSE:516.13,PAN:161.68,PNG:507.25,PRY:23.76,PER:266.48,POL:661.93,PRT:165.55,PRI:676.19,QAT:602.5,REU:572.82,ROU:240.58,RUS:441.04,RWA:316.33,KNA:636.36,LCA:666.67,SPM:600,VCT:529.41,WSM:473.68,STP:642.86,SAU:706.79,SEN:511.6,SRB:647.52,SYC:564.52,SLE:50,SGP:470.78,SVK:116.77,SVN:231.28,SLB:700,SOM:578.95,ZAF:707.69,KOR:430.57,SSD:629.03,ESP:174.05,LKA:509.78,SDN:263.16,SUR:349.28,SWE:40.7,CHE:34.68,SYR:701.66,TWN:642.38,TJK:116.86,TZA:339.25,THA:549.61,PHL:610.74,TGO:443.18,TON:625,TTO:681.53,TUN:563.96,TUR:464.59,TKM:1306.03,TCA:653.85,UGA:44.53,UKR:259.69,ARE:561.14,GBR:237.59,USA:369.47,URY:128.79,UZB:1167.6,VUT:571.43,VEN:185.8,VNM:475.45,VGB:647.06,VIR:632.35,WORLD:480.79,YEM:566.1,ZMB:111.97,ZWE:297.87},ge="average";var R={data:Re,type:ge};var Z=.81,p=.52,b=.14,L=.15,V=.19,g=R.data.WORLD,$=50,_=.75,C=.25,A=.02,G={OPERATIONAL_KWH_PER_GB_DATACENTER:.055,OPERATIONAL_KWH_PER_GB_NETWORK:.059,OPERATIONAL_KWH_PER_GB_DEVICE:.08,EMBODIED_KWH_PER_GB_DATACENTER:.012,EMBODIED_KWH_PER_GB_NETWORK:.013,EMBODIED_KWH_PER_GB_DEVICE:.081,GLOBAL_GRID_INTENSITY:494},J={FIFTH_PERCENTILE:.095,TENTH_PERCENTILE:.186,TWENTIETH_PERCENTILE:.341,THIRTIETH_PERCENTILE:.493,FORTIETH_PERCENTILE:.656,FIFTIETH_PERCENTILE:.846},T={FIFTH_PERCENTILE:.04,TENTH_PERCENTILE:.079,TWENTIETH_PERCENTILE:.145,THIRTIETH_PERCENTILE:.209,FORTIETH_PERCENTILE:.278,FIFTIETH_PERCENTILE:.359};var fe=G.GLOBAL_GRID_INTENSITY,O=t=>parseFloat(t.toFixed(2)),m=(t,e)=>t<=e;function v(t={},e=3,r=!1){let a=e===4?fe:g;if(typeof t!="object")throw new Error("Options must be an object");let n={};if(t?.gridIntensity){n.gridIntensity={};let{device:i,dataCenter:o,network:s}=t.gridIntensity;(i||i===0)&&(typeof i=="object"?(R.data[i.country?.toUpperCase()]||(console.warn(`"${i.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. + See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. + Falling back to global average grid intensity.`),n.gridIntensity.device={value:a}),n.gridIntensity.device={country:i.country,value:parseFloat(R.data[i.country?.toUpperCase()])}):typeof i=="number"?n.gridIntensity.device={value:i}:(n.gridIntensity.device={value:a},console.warn(`The device grid intensity must be a number or an object. You passed in a ${typeof i}. + Falling back to global average grid intensity.`))),(o||o===0)&&(typeof o=="object"?(R.data[o.country?.toUpperCase()]||(console.warn(`"${o.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. + See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. + Falling back to global average grid intensity.`),n.gridIntensity.dataCenter={value:g}),n.gridIntensity.dataCenter={country:o.country,value:parseFloat(R.data[o.country?.toUpperCase()])}):typeof o=="number"?n.gridIntensity.dataCenter={value:o}:(n.gridIntensity.dataCenter={value:a},console.warn(`The data center grid intensity must be a number or an object. You passed in a ${typeof o}. + Falling back to global average grid intensity.`))),(s||s===0)&&(typeof s=="object"?(R.data[s.country?.toUpperCase()]||(console.warn(`"${s.country}" is not a valid country. Please use a valid 3 digit ISO 3166 country code. + See https://developers.thegreenwebfoundation.org/co2js/data/ for more information. Falling back to global average grid intensity. + Falling back to global average grid intensity.`),n.gridIntensity.network={value:a}),n.gridIntensity.network={country:s.country,value:parseFloat(R.data[s.country?.toUpperCase()])}):typeof s=="number"?n.gridIntensity.network={value:s}:(n.gridIntensity.network={value:a},console.warn(`The network grid intensity must be a number or an object. You passed in a ${typeof s}. + Falling back to global average grid intensity.`)))}else n.gridIntensity={device:{value:a},dataCenter:{value:a},network:{value:a}};return t?.dataReloadRatio||t.dataReloadRatio===0?typeof t.dataReloadRatio=="number"?t.dataReloadRatio>=0&&t.dataReloadRatio<=1?n.dataReloadRatio=t.dataReloadRatio:(n.dataReloadRatio=e===3?A:0,console.warn(`The dataReloadRatio option must be a number between 0 and 1. You passed in ${t.dataReloadRatio}. + Falling back to default value.`)):(n.dataReloadRatio=e===3?A:0,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof t.dataReloadRatio}. + Falling back to default value.`)):(n.dataReloadRatio=e===3?A:0,console.warn(`The dataReloadRatio option must be a number. You passed in a ${typeof t.dataReloadRatio}. + Falling back to default value.`)),t?.firstVisitPercentage||t.firstVisitPercentage===0?typeof t.firstVisitPercentage=="number"?t.firstVisitPercentage>=0&&t.firstVisitPercentage<=1?n.firstVisitPercentage=t.firstVisitPercentage:(n.firstVisitPercentage=e===3?_:1,console.warn(`The firstVisitPercentage option must be a number between 0 and 1. You passed in ${t.firstVisitPercentage}. + Falling back to default value.`)):(n.firstVisitPercentage=e===3?_:1,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof t.firstVisitPercentage}. + Falling back to default value.`)):(n.firstVisitPercentage=e===3?_:1,console.warn(`The firstVisitPercentage option must be a number. You passed in a ${typeof t.firstVisitPercentage}. + Falling back to default value.`)),t?.returnVisitPercentage||t.returnVisitPercentage===0?typeof t.returnVisitPercentage=="number"?t.returnVisitPercentage>=0&&t.returnVisitPercentage<=1?n.returnVisitPercentage=t.returnVisitPercentage:(n.returnVisitPercentage=e===3?C:0,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${t.returnVisitPercentage}. + Falling back to default value.`)):(n.returnVisitPercentage=e===3?C:0,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof t.returnVisitPercentage}. + Falling back to default value.`)):(n.returnVisitPercentage=e===3?C:0,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof t.returnVisitPercentage}. + Falling back to default value.`)),t?.greenHostingFactor||t.greenHostingFactor===0&&e===4?typeof t.greenHostingFactor=="number"?t.greenHostingFactor>=0&&t.greenHostingFactor<=1?n.greenHostingFactor=t.greenHostingFactor:(n.greenHostingFactor=0,console.warn(`The returnVisitPercentage option must be a number between 0 and 1. You passed in ${t.returnVisitPercentage}. + Falling back to default value.`)):(n.greenHostingFactor=0,console.warn(`The returnVisitPercentage option must be a number. You passed in a ${typeof t.returnVisitPercentage}. + Falling back to default value.`)):e===4&&(n.greenHostingFactor=0),r&&(n.greenHostingFactor=1),n}function M(t=""){return{"User-Agent":`co2js/0.15.0 ${t}`}}function S(t,e){let{FIFTH_PERCENTILE:r,TENTH_PERCENTILE:a,TWENTIETH_PERCENTILE:n,THIRTIETH_PERCENTILE:i,FORTIETH_PERCENTILE:o,FIFTIETH_PERCENTILE:s}=J;return e===4&&(r=T.FIFTH_PERCENTILE,a=T.TENTH_PERCENTILE,n=T.TWENTIETH_PERCENTILE,i=T.THIRTIETH_PERCENTILE,o=T.FORTIETH_PERCENTILE,s=T.FIFTIETH_PERCENTILE),m(t,r)?"A+":m(t,a)?"A":m(t,n)?"B":m(t,i)?"C":m(t,o)?"D":m(t,s)?"E":"F"}var w=class{constructor(e){this.allowRatings=!0,this.options=e,this.version=3}energyPerByteByComponent(e){let a=e/N.GIGABYTE*Z;return{consumerDeviceEnergy:a*p,networkEnergy:a*b,productionEnergy:a*V,dataCenterEnergy:a*L}}co2byComponent(e,r=g,a={}){let n=g,i=g,o=g,s=g;if(a?.gridIntensity){let{device:l,network:c,dataCenter:E}=a.gridIntensity;(l?.value||l?.value===0)&&(n=l.value),(c?.value||c?.value===0)&&(i=c.value),(E?.value||E?.value===0)&&(o=E.value)}r===!0&&(o=$);let u={};for(let[l,c]of Object.entries(e))l.startsWith("dataCenterEnergy")?u[l.replace("Energy","CO2")]=c*o:l.startsWith("consumerDeviceEnergy")?u[l.replace("Energy","CO2")]=c*n:l.startsWith("networkEnergy")?u[l.replace("Energy","CO2")]=c*i:u[l.replace("Energy","CO2")]=c*s;return u}perByte(e,r=!1,a=!1,n=!1,i={}){e<1&&(e=0);let o=this.energyPerByteByComponent(e,i);if(typeof r!="boolean")throw new Error(`perByte expects a boolean for the carbon intensity value. Received: ${r}`);let s=this.co2byComponent(o,r,i),l=Object.values(s).reduce((E,d)=>E+d),c=null;return n&&(c=this.ratingScale(l)),a?n?{...s,total:l,rating:c}:{...s,total:l}:n?{total:l,rating:c}:l}perVisit(e,r=!1,a=!1,n=!1,i={}){let o=this.energyPerVisitByComponent(e,i);if(typeof r!="boolean")throw new Error(`perVisit expects a boolean for the carbon intensity value. Received: ${r}`);let s=this.co2byComponent(o,r,i),l=Object.values(s).reduce((E,d)=>E+d),c=null;return n&&(c=this.ratingScale(l)),a?n?{...s,total:l,rating:c}:{...s,total:l}:n?{total:l,rating:c}:l}energyPerByte(e){let r=this.energyPerByteByComponent(e);return Object.values(r).reduce((n,i)=>n+i)}energyPerVisitByComponent(e,r={},a=_,n=C,i=A){(r.dataReloadRatio||r.dataReloadRatio===0)&&(i=r.dataReloadRatio),(r.firstVisitPercentage||r.firstVisitPercentage===0)&&(a=r.firstVisitPercentage),(r.returnVisitPercentage||r.returnVisitPercentage===0)&&(n=r.returnVisitPercentage);let o=this.energyPerByteByComponent(e),s={},u=Object.values(o);for(let[l,c]of Object.entries(o))s[`${l} - first`]=c*a,s[`${l} - subsequent`]=c*n*i;return s}energyPerVisit(e){let r=0,a=0,n=Object.entries(this.energyPerVisitByComponent(e));for(let[i,o]of n)i.indexOf("first")>0&&(r+=o);for(let[i,o]of n)i.indexOf("subsequent")>0&&(a+=o);return r+a}emissionsPerVisitInGrams(e,r=g){return O(e*r)}annualEnergyInKwh(e,r=1e3){return e*r*12}annualEmissionsInGrams(e,r=1e3){return e*r*12}annualSegmentEnergy(e){return{consumerDeviceEnergy:O(e*p),networkEnergy:O(e*b),dataCenterEnergy:O(e*L),productionEnergy:O(e*V)}}ratingScale(e){return S(e,this.version)}};var H=w;var{OPERATIONAL_KWH_PER_GB_DATACENTER:Te,OPERATIONAL_KWH_PER_GB_NETWORK:Ie,OPERATIONAL_KWH_PER_GB_DEVICE:Ne,EMBODIED_KWH_PER_GB_DATACENTER:_e,EMBODIED_KWH_PER_GB_NETWORK:Ce,EMBODIED_KWH_PER_GB_DEVICE:Ae,GLOBAL_GRID_INTENSITY:y}=G;function X(t,e){let r=t.dataCenter+t.network+t.device,a=e.dataCenter+e.network+e.device,n=t.dataCenter+e.dataCenter,i=t.network+e.network,o=t.device+e.device;return{dataCenterOperationalCO2e:t.dataCenter,networkOperationalCO2e:t.network,consumerDeviceOperationalCO2e:t.device,dataCenterEmbodiedCO2e:e.dataCenter,networkEmbodiedCO2e:e.network,consumerDeviceEmbodiedCO2e:e.device,totalEmbodiedCO2e:a,totalOperationalCO2e:r,dataCenterCO2e:n,networkCO2e:i,consumerDeviceCO2e:o}}function Q(t,e){return t?1:e?.greenHostingFactor||e?.greenHostingFactor===0?e.greenHostingFactor:0}var F=class{constructor(e){this.allowRatings=!0,this.options=e,this.version=4}operationalEnergyPerSegment(e){let r=e/N.GIGABYTE,a=r*Te,n=r*Ie,i=r*Ne;return{dataCenter:a,network:n,device:i}}operationalEmissions(e,r={}){let{dataCenter:a,network:n,device:i}=this.operationalEnergyPerSegment(e),o=y,s=y,u=y;if(r?.gridIntensity){let{device:d,network:I,dataCenter:f}=r.gridIntensity;(d?.value||d?.value===0)&&(u=d.value),(I?.value||I?.value===0)&&(s=I.value),(f?.value||f?.value===0)&&(o=f.value)}let l=a*o,c=n*s,E=i*u;return{dataCenter:l,network:c,device:E}}embodiedEnergyPerSegment(e){let r=e/N.GIGABYTE,a=r*_e,n=r*Ce,i=r*Ae;return{dataCenter:a,network:n,device:i}}embodiedEmissions(e){let{dataCenter:r,network:a,device:n}=this.embodiedEnergyPerSegment(e),i=y,o=y,s=y,u=r*i,l=a*o,c=n*s;return{dataCenter:u,network:l,device:c}}perByte(e,r=!1,a=!1,n=!1,i={}){if(e<1)return 0;let o=this.operationalEmissions(e,i),s=this.embodiedEmissions(e),u=Q(r,i),l={dataCenter:o.dataCenter*(1-u)+s.dataCenter,network:o.network+s.network,device:o.device+s.device},c=l.dataCenter+l.network+l.device,E=null;if(n&&(E=this.ratingScale(c)),a){let d={...X(o,s)};return n?{...d,total:c,rating:E}:{...d,total:c}}return n?{total:c,rating:E}:c}perVisit(e,r=!1,a=!1,n=!1,i={}){let o=1,s=0,u=0,l=Q(r,i),c=this.operationalEmissions(e,i),E=this.embodiedEmissions(e);if(e<1)return 0;(i.firstVisitPercentage||i.firstVisitPercentage===0)&&(o=i.firstVisitPercentage),(i.returnVisitPercentage||i.returnVisitPercentage===0)&&(s=i.returnVisitPercentage),(i.dataReloadRatio||i.dataReloadRatio===0)&&(u=i.dataReloadRatio);let d=c.dataCenter*(1-l)+E.dataCenter+c.network+E.network+c.device+E.device,I=(c.dataCenter*(1-l)+E.dataCenter+c.network+E.network+c.device+E.device)*(1-u),f=d*o+I*s,h=null;if(n&&(h=this.ratingScale(f)),a){let Y={...X(c,E),firstVisitCO2e:d,returnVisitCO2e:I};return n?{...Y,total:f,rating:h}:{...Y,total:f}}return n?{total:f,rating:h}:f}ratingScale(e){return S(e,this.version)}};var q=F;var W=class{constructor(e){if(this.model=new H,e?.model==="1byte")this.model=new x;else if(e?.model==="swd")this.model=new H,e?.version===4&&(this.model=new q);else if(e?.model)throw new Error(`"${e.model}" is not a valid model. Please use "1byte" for the OneByte model, and "swd" for the Sustainable Web Design model. + See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`);if(e?.rating&&typeof e.rating!="boolean")throw new Error(`The rating option must be a boolean. Please use true or false. + See https://developers.thegreenwebfoundation.org/co2js/options/ to learn more about the options available in CO2.js.`);let r=!!this.model.allowRatings;if(this._segment=e?.results==="segment",this._rating=e?.rating===!0,!r&&this._rating)throw new Error(`The rating system is not supported in the model you are using. Try using the Sustainable Web Design model instead. + See https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`)}perByte(e,r=!1){return this.model.perByte(e,r,this._segment,this._rating)}perVisit(e,r=!1){if(this.model?.perVisit)return this.model.perVisit(e,r,this._segment,this._rating);throw new Error(`The perVisit() method is not supported in the model you are using. Try using perByte() instead. + See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`)}perByteTrace(e,r=!1,a={}){let n=v(a,this.model.version,r),{gridIntensity:i,...o}=n,{dataReloadRatio:s,firstVisitPercentage:u,returnVisitPercentage:l,...c}=o;return{co2:this.model.perByte(e,r,this._segment,this._rating,n),green:r,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",...n.gridIntensity},...c}}}perVisitTrace(e,r=!1,a={}){if(this.model?.perVisit){let n=v(a,this.model.version,r),{gridIntensity:i,...o}=n;return{co2:this.model.perVisit(e,r,this._segment,this._rating,n),green:r,variables:{description:"Below are the variables used to calculate this CO2 estimate.",bytes:e,gridIntensity:{description:"The grid intensity (grams per kilowatt-hour) used to calculate this CO2 estimate.",...n.gridIntensity},...o}}}else throw new Error(`The perVisitTrace() method is not supported in the model you are using. Try using perByte() instead. + See https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`)}};var U=W;var re=ue(te());function he(t,e){let r=typeof e=="string"?{userAgentIdentifier:e}:e;if(r?.db&&r.verbose)throw new Error("verbose mode cannot be used with a local lookup database");return typeof t=="string"?Be(t,r):De(t,r)}async function Be(t,e={}){let r=await fetch(`https://api.thegreenwebfoundation.org/greencheck/${t}`,{headers:M(e.userAgentIdentifier)});if(e?.db)return re.default.check(t,e.db);let a=await r.json();return e.verbose?a:a.green}async function De(t,e={}){try{let r="https://api.thegreenwebfoundation.org/v2/greencheckmulti",a=JSON.stringify(t),i=await(await fetch(`${r}/${a}`,{headers:M(e.userAgentIdentifier)})).json();return e.verbose?i:pe(i)}catch{return e.verbose?{}:[]}}function pe(t){return Object.entries(t).filter(([a,n])=>n.green).map(([a,n])=>n.url)}var ne={check:he};function be(t,e){return ne.check(t,e)}var K={check:be};var Le={AFG:"414",ALB:"0",DZA:"528",ASM:"753",AND:"188",AGO:"1476",AIA:"753",ATG:"753",ARG:"478",ARM:"390",ABW:"753",AUS:"808",AUT:"242",AZE:"534","AZORES (PORTUGAL)":"753",BHS:"753",BHR:"726",BGD:"528",BRB:"749",BLR:"400",BEL:"252",BLZ:"403",BEN:"745",BMU:"753",BTN:"0",BOL:"604",BES:"753",BIH:"1197",BWA:"1486",BRA:"284",VGB:"753",BRN:"681",BGR:"911",BFA:"753",BDI:"414",KHM:"1046",CMR:"659",CAN:"372",CYM:"753",CPV:"753",CAF:"188",TCD:"753","CHANNEL ISLANDS (U.K)":"753",CHL:"657",CHN:"899",COL:"410",COM:"753",COD:"0",COG:"659",COK:"753",CRI:"108",CIV:"466",HRV:"294",CUB:"559",CUW:"876",CYP:"751",CZE:"902",DNK:"362",DJI:"753",DMA:"753",DOM:"601",ECU:"560",EGY:"554",SLV:"547",GNQ:"632",ERI:"915",EST:"1057",SWZ:"0",ETH:"0",FLK:"753",FRO:"753",FJI:"640",FIN:"267",FRA:"158",GUF:"423",PYF:"753",GAB:"946",GMB:"753",GEO:"289",DEU:"650",GHA:"495",GIB:"779",GRC:"507",GRL:"264",GRD:"753",GLP:"753",GUM:"753",GTM:"798",GIN:"753",GNB:"753",GUY:"847",HTI:"1048",HND:"662",HUN:"296",ISL:"0",IND:"951",IDN:"783",IRN:"592",IRQ:"1080",IRL:"380",IMN:"436",ISR:"394",ITA:"414",JAM:"711",JPN:"471",JOR:"529",KAZ:"797",KEN:"574",KIR:"753",PRK:"754",KOR:"555",XKX:"1145",KWT:"675",KGZ:"217",LAO:"1069",LVA:"240",LBN:"794",LSO:"0",LBR:"677",LBY:"668",LIE:"151",LTU:"211",LUX:"220",MDG:"876","MADEIRA (PORTUGAL)":"663",MWI:"489",MYS:"551",MDV:"753",MLI:"1076",MLT:"520",MHL:"753",MTQ:"753",MRT:"753",MUS:"700",MYT:"753",MEX:"531",FSM:"753",MDA:"541",MCO:"158",MNG:"1366",MNE:"899",MSR:"753",MAR:"729",MOZ:"234",MMR:"719",NAM:"355",NRU:"753",NPL:"0",NLD:"326",NCL:"779",NZL:"246",NIC:"675",NER:"772",NGA:"526",NIU:"753",MKD:"851",MNP:"753",NOR:"47",OMN:"479",PAK:"592",PLW:"753",PSE:"719",PAN:"477",PNG:"597",PRY:"0",PER:"473",PHL:"672",POL:"828",PRT:"389",PRI:"596",QAT:"503",REU:"772",ROU:"489",RUS:"476",RWA:"712",SHN:"753",KNA:"753",LCA:"753",MAF:"753",SPM:"753",VCT:"753",WSM:"753",SMR:"414",STP:"753",SAU:"592",SEN:"870",SRB:"1086",SYC:"753",SLE:"489",SGP:"379",SXM:"753",SVK:"332",SVN:"620",SLB:"753",SOM:"753",ZAF:"1070",SSD:"890",ESP:"402",LKA:"731",SDN:"736",SUR:"1029",SWE:"68",CHE:"48",SYR:"713",TWN:"484",TJK:"255",TZA:"531",THA:"450",TLS:"753",TGO:"859",TON:"753",TTO:"559",TUN:"468",TUR:"376",TKM:"927",TCA:"753",TUV:"753",UGA:"279",UKR:"768",ARE:"556",GBR:"380",USA:"416",URY:"174",UZB:"612",VUT:"753",VEN:"711",VNM:"560",VIR:"650",YEM:"807",ZMB:"416",ZWE:"1575","MEMO: EU 27":"409"},Ve="marginal",ve="2021";var k={data:Le,type:Ve,year:ve};var Me={co2:U,hosting:K,averageIntensity:R,marginalIntensity:k};return de(we);})(); //# sourceMappingURL=index.js.map let hasCSPblock = false; @@ -43,8 +51,13 @@ let collectHostStatuses = async function () { } }); + const options = { + verbose: false, + userAgentIdentifier: "WebPageTest", + }; + // This uses hosting.check to go out to the Green Web Foundation API with one bulk lookup for hosts - let dependenciesCheck = co2.hosting.check(hosts).then((result) => { + let dependenciesCheck = co2.hosting.check(hosts, options).then((result) => { let greenResults = result.map((host) => { return { url: host, green: true }; }); From 3a43468b3fa9005cda749eab5bdd5fd01ae87d04 Mon Sep 17 00:00:00 2001 From: Claudio Biselli Date: Thu, 5 Dec 2024 12:09:23 +0100 Subject: [PATCH 2/6] updated webalmanac version --- www/assets/js/conditional_metrics/carbon-footprint.js | 2 +- www/resources/views/pages/carboncontrol.blade.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/www/assets/js/conditional_metrics/carbon-footprint.js b/www/assets/js/conditional_metrics/carbon-footprint.js index f748b4cc3c..183162527f 100644 --- a/www/assets/js/conditional_metrics/carbon-footprint.js +++ b/www/assets/js/conditional_metrics/carbon-footprint.js @@ -86,7 +86,7 @@ let collectHostStatuses = async function () { let calculate_carbon = async function () { let totalCarbon = 0; - const emissionsSWD = new co2.co2(); + const emissionsSWD = new co2.co2({ model: "swd", version: 4 }); let greenstatuses = await collectHostStatuses(); $WPT_REQUESTS.forEach((req) => { diff --git a/www/resources/views/pages/carboncontrol.blade.php b/www/resources/views/pages/carboncontrol.blade.php index d346cd7f6f..eb768045f7 100644 --- a/www/resources/views/pages/carboncontrol.blade.php +++ b/www/resources/views/pages/carboncontrol.blade.php @@ -115,7 +115,7 @@

Your Footprint, in Context... (Using Sustainable Web Design Model)

    - @php ($avgSiteCarbon = 0.6) + @php ($avgSiteCarbon = 0.3) @php ($avgMileCarbon = 404) @php ( $mileCompare = round($avgMileCarbon / $carbon_footprint['sustainable-web-design'])) @@ -134,7 +134,7 @@ car with exhaust sketch
  • - The median CO2 footprint of the top 1000 websites is {{ $avgSiteCarbon }} grams per visit*. This website emits {!! $footCompare !!} per visit. * Source: 2022 Web Almanac + The median CO2 footprint of the top 1000 websites is {{ $avgSiteCarbon }} grams per visit*. This website emits {!! $footCompare !!} per visit. * Source: 2024 Web Almanac scales with servers in them sketch
  • @@ -250,7 +250,7 @@

    Additionally, check out these excellent resources:

From bb99dea04dcb1efc741c19e21f6ae617a7b26707 Mon Sep 17 00:00:00 2001 From: Claudio Biselli Date: Thu, 19 Dec 2024 17:37:53 +0100 Subject: [PATCH 3/6] fallback on country if state is missing --- www/src/CPGraphQlTypes/Customer.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/www/src/CPGraphQlTypes/Customer.php b/www/src/CPGraphQlTypes/Customer.php index c9709a3431..b258eaa933 100644 --- a/www/src/CPGraphQlTypes/Customer.php +++ b/www/src/CPGraphQlTypes/Customer.php @@ -72,6 +72,11 @@ public function __construct(array $options) new DateTime($options['planRenewalDate']) : null; $this->next_wpt_plan_id = $options['nextWptPlanId'] ?? null; $this->address = null; + + if (!isset($options['creditCardBillingState']) && strlen(trim($options['creditCardBillingState'])) == 0) { + $options['creditCardBillingState'] = $options['creditCardBillingCountry']; + } + if ( isset($options['creditCardBillingCountry']) && isset($options['creditCardBillingZip']) && From d7838a47fa2e8a7ff516024eb02e02c3a78790c4 Mon Sep 17 00:00:00 2001 From: Claudio Biselli Date: Fri, 20 Dec 2024 14:00:50 +0100 Subject: [PATCH 4/6] fix --- www/src/CPGraphQlTypes/Customer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/src/CPGraphQlTypes/Customer.php b/www/src/CPGraphQlTypes/Customer.php index b258eaa933..5b0c4fec1b 100644 --- a/www/src/CPGraphQlTypes/Customer.php +++ b/www/src/CPGraphQlTypes/Customer.php @@ -73,7 +73,7 @@ public function __construct(array $options) $this->next_wpt_plan_id = $options['nextWptPlanId'] ?? null; $this->address = null; - if (!isset($options['creditCardBillingState']) && strlen(trim($options['creditCardBillingState'])) == 0) { + if (!isset($options['creditCardBillingState']) || strlen(trim($options['creditCardBillingState'])) == 0) { $options['creditCardBillingState'] = $options['creditCardBillingCountry']; } From 717c914a970a58f81f795c0637f7c952501dac8c Mon Sep 17 00:00:00 2001 From: Leonardo Bartoli <142893024+lbartoli79@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:55:46 +0100 Subject: [PATCH 5/6] Test fix --- tests/Handlers/AccountTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Handlers/AccountTest.php b/tests/Handlers/AccountTest.php index 724b3a3a9a..a69639795b 100644 --- a/tests/Handlers/AccountTest.php +++ b/tests/Handlers/AccountTest.php @@ -798,7 +798,9 @@ public function testGetUpdatePaymentMethodAddressPage(): void 'subscriptionPrice' => 10.00, 'status' => 'ACTIVE', 'wptPlanName' => '', - 'monthlyRuns' => 8 + 'monthlyRuns' => 8, + 'creditCardBillingCountry' => 'US', + 'creditCardBillingState' => 'US' ]); $wpt_api_key_list = new ApiKeyList(); $paid_page_info = new PaidPageInfo($customer, $wpt_api_key_list); From 58939649672a293d9a2107951256a2d9e9705bd3 Mon Sep 17 00:00:00 2001 From: Leonardo Bartoli <142893024+lbartoli79@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:01:31 +0100 Subject: [PATCH 6/6] Remove whitestace --- www/src/CPGraphQlTypes/Customer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/src/CPGraphQlTypes/Customer.php b/www/src/CPGraphQlTypes/Customer.php index 5b0c4fec1b..e105773b33 100644 --- a/www/src/CPGraphQlTypes/Customer.php +++ b/www/src/CPGraphQlTypes/Customer.php @@ -74,9 +74,9 @@ public function __construct(array $options) $this->address = null; if (!isset($options['creditCardBillingState']) || strlen(trim($options['creditCardBillingState'])) == 0) { - $options['creditCardBillingState'] = $options['creditCardBillingCountry']; + $options['creditCardBillingState'] = $options['creditCardBillingCountry']; } - + if ( isset($options['creditCardBillingCountry']) && isset($options['creditCardBillingZip']) &&