google-fonts-css2
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -110,3 +110,3 @@ // google-fonts-css2 v2.0.0 Copyright (c) 2022 Adriano Tirloni | ||
axisString += axis[0] + separator; | ||
valuesString += (Array.isArray(axis[1]) ? axis[1].join('..') : axis[1]) + separator; | ||
valuesString += (Array.isArray(axis[1]) ? axis[1].sort((a,b) => a-b).join('..') : axis[1]) + separator; | ||
}); | ||
@@ -113,0 +113,0 @@ |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e={italic:"ital",opticalSize:"opsz",slant:"slnt",weight:"wght",width:"wdth",ascenderHeight:"YTAS",casual:"CASL",counter_width:"XTRA",cursive:"CRSV",descenderDepth:"YTDE",figureHeight:"YTFI",fill:"FILL",grade:"GRAD",lowercaseHeight:"YTLC",monospace:"MONO",softness:"SOFT",thickStroke:"XOPQ",thinStroke:"YOPQ",uppercaseHeight:"YTUC",wonky:"WONK",ital:"ital",opsz:"opsz",slnt:"slnt",wght:"wght",wdth:"wdth",YTAS:"YTAS",CASL:"CASL",XTRA:"XTRA",CRSV:"CRSV",YTDE:"YTDE",YTFI:"YTFI",FILL:"FILL",GRAD:"GRAD",YTLC:"YTLC",MONO:"MONO",SOFT:"SOFT",XOPQ:"XOPQ",YOPQ:"YOPQ",YTUC:"YTUC",WONK:"WONK"},t=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],i={thin:100,extralight:200,light:300,regular:400,medium:500,semibold:600,bold:700,extrabold:800,black:900},r={supercondensed:25,ultracondensed:50,extracondensed:62.5,condensed:75,semicondensed:87.5,normal:100,semiexpanded:112.5,expanded:125,extraexpanded:150};let s=(e,i)=>{if(e===i)throw new Error(`Styles Object key are not unique: ${e}`);let r=t.indexOf(e[0])-t.indexOf(i[0]);return 0===r?s(e.substr(1),i.substr(1)):r};const l=(t,i="auto",r)=>"https://fonts.googleapis.com/css2?"+function(t){return t.reduce(((t,i,r)=>t+(r?"&":"")+(({family:t,styles:i})=>{const r=t.replaceAll(" ","+");let l=i.map((t=>{for(let i in t){let r=e[i];if(!r)throw new Error(`The directive axis (${i}) is not on Google Fonts axis list (weight, wgth, ital...)`);r!==i&&delete Object.assign(t,{[r]:t[i]})[i]}return Object.entries(t).sort(((e,t)=>s(e[0],t[0])))})),o="";return l.forEach(((e,t)=>{o+=(0===t?"":"&")+"family="+r+":";let i="",s="";e.forEach(((t,r)=>{let l=e.length===r+1?"":",";i+=t[0]+l,s+=(Array.isArray(t[1])?t[1].join(".."):t[1])+l})),o+=i+"@"+s})),o})(i)),"")}(t)+function(e="auto"){return"&display="+e}(i)+function(e=null){return e?"&text="+encodeURIComponent(e):""}(r);function o(e,t){if(e.includes(".."))return e.split("..").map((e=>Number(e)));if(isNaN(Number(e))){if(!t[e])throw new Error(`Invalid name for weight or width: ${e}. You may have misplaced the argument order or separator.`);return t[e]}if("number"==typeof Number(e))return Number(e);throw new Error("Could not convert font weight or width.")}exports.getGoogleFontsUrl=l,exports.getGoogleFontsUrlSimple=(...e)=>{let t={families:[],display:void 0,onlyThisCharacters:void 0};return e.forEach((e=>{if(e.display||e.onlyThisCharacters)t.display=e.display,t.onlyThisCharacters=e.onlyThisCharacters;else if("string"==typeof e){let s=e.slice(0,e.indexOf(",")),l=e.slice(e.indexOf(",")+1).toLowerCase().replaceAll(" ",""),[n,...a]=l.split(","),h=a?a.indexOf("italic"):-1,d=h>=0,c=a.length?a[0===h?1:0]:null,u={family:s,styles:[]};n.split("&").forEach((e=>{if(e=o(e,i),c)c.split("&").forEach((t=>{t=o(t,r);let i={weight:e,width:t};d&&(i.italic=1),u.styles.push(i)}));else{let t={weight:e};d&&(t.italic=1),u.styles.push(t)}})),t.families.push(u)}else"object"==typeof e&&t.families.push(e)})),l(t.families,t.display,t.onlyThisCharacters)}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e={italic:"ital",opticalSize:"opsz",slant:"slnt",weight:"wght",width:"wdth",ascenderHeight:"YTAS",casual:"CASL",counter_width:"XTRA",cursive:"CRSV",descenderDepth:"YTDE",figureHeight:"YTFI",fill:"FILL",grade:"GRAD",lowercaseHeight:"YTLC",monospace:"MONO",softness:"SOFT",thickStroke:"XOPQ",thinStroke:"YOPQ",uppercaseHeight:"YTUC",wonky:"WONK",ital:"ital",opsz:"opsz",slnt:"slnt",wght:"wght",wdth:"wdth",YTAS:"YTAS",CASL:"CASL",XTRA:"XTRA",CRSV:"CRSV",YTDE:"YTDE",YTFI:"YTFI",FILL:"FILL",GRAD:"GRAD",YTLC:"YTLC",MONO:"MONO",SOFT:"SOFT",XOPQ:"XOPQ",YOPQ:"YOPQ",YTUC:"YTUC",WONK:"WONK"},t=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],i={thin:100,extralight:200,light:300,regular:400,medium:500,semibold:600,bold:700,extrabold:800,black:900},r={supercondensed:25,ultracondensed:50,extracondensed:62.5,condensed:75,semicondensed:87.5,normal:100,semiexpanded:112.5,expanded:125,extraexpanded:150};let s=(e,i)=>{if(e===i)throw new Error(`Styles Object key are not unique: ${e}`);let r=t.indexOf(e[0])-t.indexOf(i[0]);return 0===r?s(e.substr(1),i.substr(1)):r};const l=(t,i="auto",r)=>"https://fonts.googleapis.com/css2?"+function(t){return t.reduce(((t,i,r)=>t+(r?"&":"")+(({family:t,styles:i})=>{const r=t.replaceAll(" ","+");let l=i.map((t=>{for(let i in t){let r=e[i];if(!r)throw new Error(`The directive axis (${i}) is not on Google Fonts axis list (weight, wgth, ital...)`);r!==i&&delete Object.assign(t,{[r]:t[i]})[i]}return Object.entries(t).sort(((e,t)=>s(e[0],t[0])))})),o="";return l.forEach(((e,t)=>{o+=(0===t?"":"&")+"family="+r+":";let i="",s="";e.forEach(((t,r)=>{let l=e.length===r+1?"":",";i+=t[0]+l,s+=(Array.isArray(t[1])?t[1].sort(((e,t)=>e-t)).join(".."):t[1])+l})),o+=i+"@"+s})),o})(i)),"")}(t)+function(e="auto"){return"&display="+e}(i)+function(e=null){return e?"&text="+encodeURIComponent(e):""}(r);function o(e,t){if(e.includes(".."))return e.split("..").map((e=>Number(e)));if(isNaN(Number(e))){if(!t[e])throw new Error(`Invalid name for weight or width: ${e}. You may have misplaced the argument order or separator.`);return t[e]}if("number"==typeof Number(e))return Number(e);throw new Error("Could not convert font weight or width.")}exports.getGoogleFontsUrl=l,exports.getGoogleFontsUrlSimple=(...e)=>{let t={families:[],display:void 0,onlyThisCharacters:void 0};return e.forEach((e=>{if(e.display||e.onlyThisCharacters)t.display=e.display,t.onlyThisCharacters=e.onlyThisCharacters;else if("string"==typeof e){let s=e.slice(0,e.indexOf(",")),l=e.slice(e.indexOf(",")+1).toLowerCase().replaceAll(" ",""),[n,...a]=l.split(","),h=a?a.indexOf("italic"):-1,d=h>=0,c=a.length?a[0===h?1:0]:null,u={family:s,styles:[]};n.split("&").forEach((e=>{if(e=o(e,i),c)c.split("&").forEach((t=>{t=o(t,r);let i={weight:e,width:t};d&&(i.italic=1),u.styles.push(i)}));else{let t={weight:e};d&&(t.italic=1),u.styles.push(t)}})),t.families.push(u)}else"object"==typeof e&&t.families.push(e)})),l(t.families,t.display,t.onlyThisCharacters)}; |
@@ -106,3 +106,3 @@ // google-fonts-css2 v2.0.0 Copyright (c) 2022 Adriano Tirloni | ||
axisString += axis[0] + separator; | ||
valuesString += (Array.isArray(axis[1]) ? axis[1].join('..') : axis[1]) + separator; | ||
valuesString += (Array.isArray(axis[1]) ? axis[1].sort((a,b) => a-b).join('..') : axis[1]) + separator; | ||
}); | ||
@@ -109,0 +109,0 @@ |
@@ -1,1 +0,1 @@ | ||
const e={italic:"ital",opticalSize:"opsz",slant:"slnt",weight:"wght",width:"wdth",ascenderHeight:"YTAS",casual:"CASL",counter_width:"XTRA",cursive:"CRSV",descenderDepth:"YTDE",figureHeight:"YTFI",fill:"FILL",grade:"GRAD",lowercaseHeight:"YTLC",monospace:"MONO",softness:"SOFT",thickStroke:"XOPQ",thinStroke:"YOPQ",uppercaseHeight:"YTUC",wonky:"WONK",ital:"ital",opsz:"opsz",slnt:"slnt",wght:"wght",wdth:"wdth",YTAS:"YTAS",CASL:"CASL",XTRA:"XTRA",CRSV:"CRSV",YTDE:"YTDE",YTFI:"YTFI",FILL:"FILL",GRAD:"GRAD",YTLC:"YTLC",MONO:"MONO",SOFT:"SOFT",XOPQ:"XOPQ",YOPQ:"YOPQ",YTUC:"YTUC",WONK:"WONK"},t=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],i={thin:100,extralight:200,light:300,regular:400,medium:500,semibold:600,bold:700,extrabold:800,black:900},r={supercondensed:25,ultracondensed:50,extracondensed:62.5,condensed:75,semicondensed:87.5,normal:100,semiexpanded:112.5,expanded:125,extraexpanded:150};let s=(e,i)=>{if(e===i)throw new Error(`Styles Object key are not unique: ${e}`);let r=t.indexOf(e[0])-t.indexOf(i[0]);return 0===r?s(e.substr(1),i.substr(1)):r};const l=(t,i="auto",r)=>"https://fonts.googleapis.com/css2?"+function(t){return t.reduce(((t,i,r)=>t+(r?"&":"")+(({family:t,styles:i})=>{const r=t.replaceAll(" ","+");let l=i.map((t=>{for(let i in t){let r=e[i];if(!r)throw new Error(`The directive axis (${i}) is not on Google Fonts axis list (weight, wgth, ital...)`);r!==i&&delete Object.assign(t,{[r]:t[i]})[i]}return Object.entries(t).sort(((e,t)=>s(e[0],t[0])))})),n="";return l.forEach(((e,t)=>{n+=(0===t?"":"&")+"family="+r+":";let i="",s="";e.forEach(((t,r)=>{let l=e.length===r+1?"":",";i+=t[0]+l,s+=(Array.isArray(t[1])?t[1].join(".."):t[1])+l})),n+=i+"@"+s})),n})(i)),"")}(t)+function(e="auto"){return"&display="+e}(i)+function(e=null){return e?"&text="+encodeURIComponent(e):""}(r);const n=(...e)=>{let t={families:[],display:void 0,onlyThisCharacters:void 0};return e.forEach((e=>{if(e.display||e.onlyThisCharacters)t.display=e.display,t.onlyThisCharacters=e.onlyThisCharacters;else if("string"==typeof e){let s=e.slice(0,e.indexOf(",")),l=e.slice(e.indexOf(",")+1).toLowerCase().replaceAll(" ",""),[n,...a]=l.split(","),h=a?a.indexOf("italic"):-1,c=h>=0,d=a.length?a[0===h?1:0]:null,u={family:s,styles:[]};n.split("&").forEach((e=>{if(e=o(e,i),d)d.split("&").forEach((t=>{t=o(t,r);let i={weight:e,width:t};c&&(i.italic=1),u.styles.push(i)}));else{let t={weight:e};c&&(t.italic=1),u.styles.push(t)}})),t.families.push(u)}else"object"==typeof e&&t.families.push(e)})),l(t.families,t.display,t.onlyThisCharacters)};function o(e,t){if(e.includes(".."))return e.split("..").map((e=>Number(e)));if(isNaN(Number(e))){if(!t[e])throw new Error(`Invalid name for weight or width: ${e}. You may have misplaced the argument order or separator.`);return t[e]}if("number"==typeof Number(e))return Number(e);throw new Error("Could not convert font weight or width.")}export{l as getGoogleFontsUrl,n as getGoogleFontsUrlSimple}; | ||
const e={italic:"ital",opticalSize:"opsz",slant:"slnt",weight:"wght",width:"wdth",ascenderHeight:"YTAS",casual:"CASL",counter_width:"XTRA",cursive:"CRSV",descenderDepth:"YTDE",figureHeight:"YTFI",fill:"FILL",grade:"GRAD",lowercaseHeight:"YTLC",monospace:"MONO",softness:"SOFT",thickStroke:"XOPQ",thinStroke:"YOPQ",uppercaseHeight:"YTUC",wonky:"WONK",ital:"ital",opsz:"opsz",slnt:"slnt",wght:"wght",wdth:"wdth",YTAS:"YTAS",CASL:"CASL",XTRA:"XTRA",CRSV:"CRSV",YTDE:"YTDE",YTFI:"YTFI",FILL:"FILL",GRAD:"GRAD",YTLC:"YTLC",MONO:"MONO",SOFT:"SOFT",XOPQ:"XOPQ",YOPQ:"YOPQ",YTUC:"YTUC",WONK:"WONK"},t=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],i={thin:100,extralight:200,light:300,regular:400,medium:500,semibold:600,bold:700,extrabold:800,black:900},r={supercondensed:25,ultracondensed:50,extracondensed:62.5,condensed:75,semicondensed:87.5,normal:100,semiexpanded:112.5,expanded:125,extraexpanded:150};let s=(e,i)=>{if(e===i)throw new Error(`Styles Object key are not unique: ${e}`);let r=t.indexOf(e[0])-t.indexOf(i[0]);return 0===r?s(e.substr(1),i.substr(1)):r};const l=(t,i="auto",r)=>"https://fonts.googleapis.com/css2?"+function(t){return t.reduce(((t,i,r)=>t+(r?"&":"")+(({family:t,styles:i})=>{const r=t.replaceAll(" ","+");let l=i.map((t=>{for(let i in t){let r=e[i];if(!r)throw new Error(`The directive axis (${i}) is not on Google Fonts axis list (weight, wgth, ital...)`);r!==i&&delete Object.assign(t,{[r]:t[i]})[i]}return Object.entries(t).sort(((e,t)=>s(e[0],t[0])))})),n="";return l.forEach(((e,t)=>{n+=(0===t?"":"&")+"family="+r+":";let i="",s="";e.forEach(((t,r)=>{let l=e.length===r+1?"":",";i+=t[0]+l,s+=(Array.isArray(t[1])?t[1].sort(((e,t)=>e-t)).join(".."):t[1])+l})),n+=i+"@"+s})),n})(i)),"")}(t)+function(e="auto"){return"&display="+e}(i)+function(e=null){return e?"&text="+encodeURIComponent(e):""}(r);const n=(...e)=>{let t={families:[],display:void 0,onlyThisCharacters:void 0};return e.forEach((e=>{if(e.display||e.onlyThisCharacters)t.display=e.display,t.onlyThisCharacters=e.onlyThisCharacters;else if("string"==typeof e){let s=e.slice(0,e.indexOf(",")),l=e.slice(e.indexOf(",")+1).toLowerCase().replaceAll(" ",""),[n,...a]=l.split(","),h=a?a.indexOf("italic"):-1,c=h>=0,d=a.length?a[0===h?1:0]:null,u={family:s,styles:[]};n.split("&").forEach((e=>{if(e=o(e,i),d)d.split("&").forEach((t=>{t=o(t,r);let i={weight:e,width:t};c&&(i.italic=1),u.styles.push(i)}));else{let t={weight:e};c&&(t.italic=1),u.styles.push(t)}})),t.families.push(u)}else"object"==typeof e&&t.families.push(e)})),l(t.families,t.display,t.onlyThisCharacters)};function o(e,t){if(e.includes(".."))return e.split("..").map((e=>Number(e)));if(isNaN(Number(e))){if(!t[e])throw new Error(`Invalid name for weight or width: ${e}. You may have misplaced the argument order or separator.`);return t[e]}if("number"==typeof Number(e))return Number(e);throw new Error("Could not convert font weight or width.")}export{l as getGoogleFontsUrl,n as getGoogleFontsUrlSimple}; |
@@ -112,3 +112,3 @@ // google-fonts-css2 v2.0.0 Copyright (c) 2022 Adriano Tirloni | ||
axisString += axis[0] + separator; | ||
valuesString += (Array.isArray(axis[1]) ? axis[1].join('..') : axis[1]) + separator; | ||
valuesString += (Array.isArray(axis[1]) ? axis[1].sort((a,b) => a-b).join('..') : axis[1]) + separator; | ||
}); | ||
@@ -115,0 +115,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GoogleFontsCSS2={})}(this,(function(e){"use strict";const t={italic:"ital",opticalSize:"opsz",slant:"slnt",weight:"wght",width:"wdth",ascenderHeight:"YTAS",casual:"CASL",counter_width:"XTRA",cursive:"CRSV",descenderDepth:"YTDE",figureHeight:"YTFI",fill:"FILL",grade:"GRAD",lowercaseHeight:"YTLC",monospace:"MONO",softness:"SOFT",thickStroke:"XOPQ",thinStroke:"YOPQ",uppercaseHeight:"YTUC",wonky:"WONK",ital:"ital",opsz:"opsz",slnt:"slnt",wght:"wght",wdth:"wdth",YTAS:"YTAS",CASL:"CASL",XTRA:"XTRA",CRSV:"CRSV",YTDE:"YTDE",YTFI:"YTFI",FILL:"FILL",GRAD:"GRAD",YTLC:"YTLC",MONO:"MONO",SOFT:"SOFT",XOPQ:"XOPQ",YOPQ:"YOPQ",YTUC:"YTUC",WONK:"WONK"},i=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],r={thin:100,extralight:200,light:300,regular:400,medium:500,semibold:600,bold:700,extrabold:800,black:900},s={supercondensed:25,ultracondensed:50,extracondensed:62.5,condensed:75,semicondensed:87.5,normal:100,semiexpanded:112.5,expanded:125,extraexpanded:150};let o=(e,t)=>{if(e===t)throw new Error(`Styles Object key are not unique: ${e}`);let r=i.indexOf(e[0])-i.indexOf(t[0]);return 0===r?o(e.substr(1),t.substr(1)):r};const n=(e,i="auto",r)=>"https://fonts.googleapis.com/css2?"+function(e){return e.reduce(((e,i,r)=>e+(r?"&":"")+(({family:e,styles:i})=>{const r=e.replaceAll(" ","+");let s=i.map((e=>{for(let i in e){let r=t[i];if(!r)throw new Error(`The directive axis (${i}) is not on Google Fonts axis list (weight, wgth, ital...)`);r!==i&&delete Object.assign(e,{[r]:e[i]})[i]}return Object.entries(e).sort(((e,t)=>o(e[0],t[0])))})),n="";return s.forEach(((e,t)=>{n+=(0===t?"":"&")+"family="+r+":";let i="",s="";e.forEach(((t,r)=>{let o=e.length===r+1?"":",";i+=t[0]+o,s+=(Array.isArray(t[1])?t[1].join(".."):t[1])+o})),n+=i+"@"+s})),n})(i)),"")}(e)+function(e="auto"){return"&display="+e}(i)+function(e=null){return e?"&text="+encodeURIComponent(e):""}(r);function l(e,t){if(e.includes(".."))return e.split("..").map((e=>Number(e)));if(isNaN(Number(e))){if(!t[e])throw new Error(`Invalid name for weight or width: ${e}. You may have misplaced the argument order or separator.`);return t[e]}if("number"==typeof Number(e))return Number(e);throw new Error("Could not convert font weight or width.")}e.getGoogleFontsUrl=n,e.getGoogleFontsUrlSimple=(...e)=>{let t={families:[],display:void 0,onlyThisCharacters:void 0};return e.forEach((e=>{if(e.display||e.onlyThisCharacters)t.display=e.display,t.onlyThisCharacters=e.onlyThisCharacters;else if("string"==typeof e){let i=e.slice(0,e.indexOf(",")),o=e.slice(e.indexOf(",")+1).toLowerCase().replaceAll(" ",""),[n,...a]=o.split(","),d=a?a.indexOf("italic"):-1,h=d>=0,c=a.length?a[0===d?1:0]:null,f={family:i,styles:[]};n.split("&").forEach((e=>{if(e=l(e,r),c)c.split("&").forEach((t=>{t=l(t,s);let i={weight:e,width:t};h&&(i.italic=1),f.styles.push(i)}));else{let t={weight:e};h&&(t.italic=1),f.styles.push(t)}})),t.families.push(f)}else"object"==typeof e&&t.families.push(e)})),n(t.families,t.display,t.onlyThisCharacters)},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GoogleFontsCSS2={})}(this,(function(e){"use strict";const t={italic:"ital",opticalSize:"opsz",slant:"slnt",weight:"wght",width:"wdth",ascenderHeight:"YTAS",casual:"CASL",counter_width:"XTRA",cursive:"CRSV",descenderDepth:"YTDE",figureHeight:"YTFI",fill:"FILL",grade:"GRAD",lowercaseHeight:"YTLC",monospace:"MONO",softness:"SOFT",thickStroke:"XOPQ",thinStroke:"YOPQ",uppercaseHeight:"YTUC",wonky:"WONK",ital:"ital",opsz:"opsz",slnt:"slnt",wght:"wght",wdth:"wdth",YTAS:"YTAS",CASL:"CASL",XTRA:"XTRA",CRSV:"CRSV",YTDE:"YTDE",YTFI:"YTFI",FILL:"FILL",GRAD:"GRAD",YTLC:"YTLC",MONO:"MONO",SOFT:"SOFT",XOPQ:"XOPQ",YOPQ:"YOPQ",YTUC:"YTUC",WONK:"WONK"},i=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],r={thin:100,extralight:200,light:300,regular:400,medium:500,semibold:600,bold:700,extrabold:800,black:900},s={supercondensed:25,ultracondensed:50,extracondensed:62.5,condensed:75,semicondensed:87.5,normal:100,semiexpanded:112.5,expanded:125,extraexpanded:150};let o=(e,t)=>{if(e===t)throw new Error(`Styles Object key are not unique: ${e}`);let r=i.indexOf(e[0])-i.indexOf(t[0]);return 0===r?o(e.substr(1),t.substr(1)):r};const n=(e,i="auto",r)=>"https://fonts.googleapis.com/css2?"+function(e){return e.reduce(((e,i,r)=>e+(r?"&":"")+(({family:e,styles:i})=>{const r=e.replaceAll(" ","+");let s=i.map((e=>{for(let i in e){let r=t[i];if(!r)throw new Error(`The directive axis (${i}) is not on Google Fonts axis list (weight, wgth, ital...)`);r!==i&&delete Object.assign(e,{[r]:e[i]})[i]}return Object.entries(e).sort(((e,t)=>o(e[0],t[0])))})),n="";return s.forEach(((e,t)=>{n+=(0===t?"":"&")+"family="+r+":";let i="",s="";e.forEach(((t,r)=>{let o=e.length===r+1?"":",";i+=t[0]+o,s+=(Array.isArray(t[1])?t[1].sort(((e,t)=>e-t)).join(".."):t[1])+o})),n+=i+"@"+s})),n})(i)),"")}(e)+function(e="auto"){return"&display="+e}(i)+function(e=null){return e?"&text="+encodeURIComponent(e):""}(r);function l(e,t){if(e.includes(".."))return e.split("..").map((e=>Number(e)));if(isNaN(Number(e))){if(!t[e])throw new Error(`Invalid name for weight or width: ${e}. You may have misplaced the argument order or separator.`);return t[e]}if("number"==typeof Number(e))return Number(e);throw new Error("Could not convert font weight or width.")}e.getGoogleFontsUrl=n,e.getGoogleFontsUrlSimple=(...e)=>{let t={families:[],display:void 0,onlyThisCharacters:void 0};return e.forEach((e=>{if(e.display||e.onlyThisCharacters)t.display=e.display,t.onlyThisCharacters=e.onlyThisCharacters;else if("string"==typeof e){let i=e.slice(0,e.indexOf(",")),o=e.slice(e.indexOf(",")+1).toLowerCase().replaceAll(" ",""),[n,...a]=o.split(","),d=a?a.indexOf("italic"):-1,h=d>=0,c=a.length?a[0===d?1:0]:null,f={family:i,styles:[]};n.split("&").forEach((e=>{if(e=l(e,r),c)c.split("&").forEach((t=>{t=l(t,s);let i={weight:e,width:t};h&&(i.italic=1),f.styles.push(i)}));else{let t={weight:e};h&&(t.italic=1),f.styles.push(t)}})),t.families.push(f)}else"object"==typeof e&&t.families.push(e)})),n(t.families,t.display,t.onlyThisCharacters)},Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "google-fonts-css2", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "A Javascript package to integrate with Google Fonts API.", | ||
@@ -20,4 +20,4 @@ "author": "Adriano Tirloni", | ||
"exports": { | ||
"require": "./dist/cjs/index.js", | ||
"import": "./dist/esm/index.js" | ||
"require": "./dist/cjs/index.js", | ||
"import": "./dist/esm/index.js" | ||
}, | ||
@@ -24,0 +24,0 @@ "scripts": { |
247
README.md
@@ -1,11 +0,11 @@ | ||
# 📃GOOGLE FONT CSS 2 | ||
# 📜GOOGLE FONTS CSS 2 | ||
## A Javascript package to integrate with Google Fonts API. | ||
⚠️ *If you were using the v1 of this package check the new API below, it is slightly different. * | ||
`⚠️If you were using the v1 of this package check the new API below, it is slightly different.⚠️` | ||
This is a package with a **single purpose**: To provide an easy interface to create the latest version of a Google Fonts CSS2 URL. | ||
- **Single purpose**: To provide an easy interface to create the latest version of a Google Fonts CSS2 URL. | ||
- No dependencies. | ||
- It adheres to the rules described on [the current Google Fonts Documentation (CSS2)](https://developers.google.com/fonts/docs/css2 "Google Fonts Documentation (CSS2)"). | ||
- Works on browser and server side (**SSR**). | ||
- Can create** Material Symbols** and **Material Icons** URLs | ||
- Can create **Material Symbols** and **Material Icons** URLs | ||
@@ -25,23 +25,232 @@ Read on for more information. | ||
------------ | ||
- **Get Started** | ||
- **NodeJS, Browser, Common-JS, ES-Modules** | ||
- **Functions** | ||
- **Android, IOS & Flutter** | ||
- **[Getting Started](#getting-started)** | ||
- **[NodeJS, Browser, Common-JS, ES-Modules](#nodejs-browser-common-js-es-modules)** | ||
- **[Functions](#functions)** | ||
- **[Android, IOS & Flutter](#android-ios--flutter)** | ||
- **Google Fonts** | ||
- **Regular Fonts** | ||
- **Variable Fonts** | ||
- **Variable Fonts Options** | ||
- **[Regular Fonts](#regular-fonts)** | ||
- **[Variable Fonts](#variable-fonts)** | ||
- **[Variable Fonts Options](#variable-fonts-options)** | ||
- **Google Material Symbols** | ||
- **Variable Symbols Options** | ||
- **Google Material Icons** | ||
- **Validations** | ||
- **Examples** | ||
- **[Validations](#input-validation)** | ||
- **[Examples](#examples)** | ||
--- | ||
## Get Started | ||
asd | ||
## Getting Started | ||
### NodeJS, Browser, Common-JS, ES-Modules | ||
This package is bundled to be used in multiple environments (ESM, CJS, UMD). | ||
Check the `/dist` folder for enviroment options. | ||
### Install | ||
```console | ||
npm i google-fonts-css2 | ||
``` | ||
```console | ||
yarn add google-fonts-css2 | ||
``` | ||
```html | ||
<!-- directly in browser, note the /dist/umd path --> | ||
<script src="https://cdn.jsdelivr.net/npm/google-fonts-css2@2.0.0/dist/umd/index.min.js"></script> | ||
``` | ||
### Import | ||
You can seamlessly `import` or `require`: | ||
```javascript | ||
import { getGoogleFontsUrl, getGoogleFontsUrlSimple } from "google-fonts-css2" | ||
``` | ||
or | ||
```javascript | ||
const { getGoogleFontsUrl, getGoogleFontsUrlSimple } = require("google-fonts-css2") | ||
``` | ||
or | ||
`For HTML check the codepen:` [https://codepen.io/adrianotirloni/pen/ExEWbdd](https://codepen.io/adrianotirloni/pen/ExEWbdd) | ||
### Functions | ||
#### 📜 getGoogleFontsUrlSimple | ||
This function calls getGoogleFontsUrl but with simpler argurments and reduced options. | ||
- **Arguments**: Any number of strings or objects. | ||
- **Strings**: Directive family style strings - All spaces and cases are removed from the string, except for the Font Family name. | ||
- **Objects**: Directive family style objects or a options object. | ||
**Strings format**: "`<case-sensitive-spaced font name>`,`<weights>`,`<?italic> or <?widths>`" | ||
**Objects** | ||
1) Options object: {display: <string>, onlyThisCharacters: <string>} | ||
2) Font Style object: Same as [getGoogleFontsUrl function](#-getgooglefontsurl) (this allow full directive request). | ||
##### Examples (open urls in browser to check it): | ||
```javascript | ||
//Open Sans - Named regular weight | ||
getGoogleFontsUrlSimple('Open Sans, regular') | ||
//=> https://fonts.googleapis.com/css2?family=Open+Sans:wght@400&display=auto | ||
//Open Sans - Named regular weight, with options object | ||
getGoogleFontsUrlSimple( | ||
{display: "swap", onlyThisCharacters: "abcd"}, | ||
"Open Sans, regular" | ||
) | ||
//=> https://fonts.googleapis.com/css2?family=Open+Sans:wght@400&display=swap&text=abcd | ||
//Multiple arguments, multiple fonts, unordered | ||
getGoogleFontsUrlSimple("Open Sans, 300, italic", {display: "swap"}, "Lato, regular") | ||
//=> https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@1,300&family=Lato:wght@400&display=swap | ||
//Open Sans - Numbered regular weight | ||
getGoogleFontsUrlSimple("Open Sans, 400") | ||
//=> https://fonts.googleapis.com/css2?family=Open+Sans:wght@400&display=auto | ||
//Open Sans - Multiple Named and Numbered weight | ||
getGoogleFontsUrlSimple("Open Sans, regular & 600") | ||
//=> https://fonts.googleapis.com/css2?family=Open+Sans:wght@400&family=Open+Sans:wght@600&display=auto | ||
//Open Sans - Multiple Named weight | ||
getGoogleFontsUrlSimple("Open Sans, regular & semibold & bold") | ||
//=> https://fonts.googleapis.com/css2?family=Open+Sans:wght@400&family=Open+Sans:wght@600&family=Open+Sans:wght@700&display=auto | ||
//Open Sans - Ranged weight | ||
getGoogleFontsUrlSimple("Open Sans, 300..800") | ||
//=> https://fonts.googleapis.com/css2?family=Open+Sans:wght@300..800&display=auto | ||
//Open Sans - Regular Italic | ||
getGoogleFontsUrlSimple("Open Sans, 400, italic") | ||
//=> https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@1,400&display=auto | ||
//Open Sans - Full weight range, italic and named width | ||
getGoogleFontsUrlSimple("Open Sans, 300..800, italic, condensed & normal") | ||
//=> https://fonts.googleapis.com/css2?family=Open+Sans:ital,wdth,wght@1,75,300..800&family=Open+Sans:ital,wdth,wght@1,100,300..800&display=auto | ||
//Open Sans - Full weight range, WITHOUT italic and named width | ||
getGoogleFontsUrlSimple("Open Sans, 300..800, condensed & semiCondensed & normal") | ||
//=> https://fonts.googleapis.com/css2?family=Open+Sans:wdth,wght@75,300..800&family=Open+Sans:wdth,wght@87.5,300..800&family=Open+Sans:wdth,wght@100,300..800&display=auto | ||
//Open Sans - Full weight range, with italic and full ranged width | ||
getGoogleFontsUrlSimple("Open Sans, 300..800, 75..100, italic") | ||
//=> https://fonts.googleapis.com/css2?family=Open+Sans:ital,wdth,wght@1,75..100,300..800&display=auto | ||
``` | ||
#### 📜 getGoogleFontsUrl | ||
The full base function to construct the urls. | ||
Check a live example here: [https://codepen.io/adrianotirloni/pen/wvmJxpG](https://codepen.io/adrianotirloni/pen/wvmJxpG) | ||
- Arguments: An array of objects (Font Families), Display, OnlyThisCharacters | ||
- Display: `'auto' | 'block' | 'swap' | 'fallback' | 'optional'` | ||
- OnlyThisCharacters: Optional, string. | ||
- Font Family Object: | ||
- family: Case sensitive font family name, as per Google Fonts website. | ||
- styles: Array of Font Styles Objects available to the chosen family. | ||
- Font Style Object: | ||
- Any number of directive pairs: `<axisDirective>: <axisOption>` | ||
- Axis Directive: `wght` (axis symbol) or `weight` (humanized name) | ||
- Examples: `ital` or `italic`, `XOPQ` or `thickStroke` | ||
- Axis Option: Number, String or Range | ||
- Range: `[Number, Number]` or `[String, Number]` or `[String, String]` or `"StrNumber..StrNumber"` | ||
- Number: Negative or positive with decimal places accordingly to selected Font | ||
- String: Number or Range representation as String. | ||
![getGoogleFontsUrl picture](https://user-images.githubusercontent.com/6390605/179752075-46b4ba36-acb8-4904-bbc6-3c1f3fd8cd24.jpg) | ||
```javascript | ||
getGoogleFontsUrl([ | ||
{ | ||
family: 'Roboto Flex', | ||
styles: [ | ||
{weight: '800..1000', width: [25, 150], slant: -5, figureHeight: 500}, | ||
{weight: 300}, | ||
{weight: 400}, | ||
] | ||
}, | ||
{ | ||
family: 'Open Sans', | ||
styles: [ | ||
{weight: '400', italic: 1}, | ||
] | ||
} | ||
], 'swap', 'abcdefgh') | ||
getGoogleFontsUrl( | ||
[ | ||
{ | ||
family: 'Material Icons', | ||
styles: [ | ||
{ wght: '500', wght: '501' } | ||
] | ||
} | ||
], | ||
'swap' | ||
) | ||
getGoogleFontsUrl([ | ||
{ | ||
family: 'Roboto Flex', | ||
styles: [ | ||
{ weight: '100..500', width: [-10, 0] } | ||
] | ||
} | ||
], 'swap') | ||
``` | ||
### Android, IOS & Flutter | ||
Android, IOS and Flutter implementation are not the same as web implementation [https://developers.google.com/fonts/docs/android](https://developers.google.com/fonts/docs/android), so is out of the scope of this package. | ||
(If you know a library for tose tools open a PR to this document listing it here) | ||
## Google Fonts | ||
### Regular Fonts | ||
Google Fonts has as of today **1429** font families, of those, **1176** are regular fonts. | ||
Regular Fonts are those that don't have a variable directive axis, like `weight`. | ||
As an example, a regular font will have `400`,`500`,`600` `weight`. | ||
A Font with a `variable weight axis` will have every integer from 400 to 600. (`401`, `476` ... `599`, `600`) | ||
### Variable Fonts | ||
A Variable Font can have one or multiple directive axis as a varaible axis. A variable font can have standard `weights` (`400`,`500`,`600`) but a variable `width` axis (from 1 to 150). This font will be considered variable. | ||
You can check all variable fonts and their **directive axes** on this link: **[https://fonts.google.com/variablefonts](https://fonts.google.com/variablefonts)** | ||
### Variable Fonts Options | ||
Variable or Regular fonts may have any number of directive axes. | ||
Google API will only accept the axis symbol on a specific order, to make readability better this package will allow the use of the **`case-sensitive symbol`** AND/OR **`human readable name`** | ||
#### The avaliable directives symbol and human names are below: | ||
```yaml | ||
italic: ital | ||
opticalSize: opsz | ||
slant: slnt | ||
weight: wght | ||
width: wdth | ||
ascenderHeight: YTAS | ||
casual: CASL | ||
counterWidth: XTRA | ||
cursive: CRSV | ||
descenderDepth: YTDE | ||
figureHeight: YTFI | ||
fill: FILL | ||
grade: GRAD | ||
lowercaseHeight: YTLC | ||
monospace: MONO | ||
softness: SOFT | ||
thickStroke: XOPQ | ||
thinStroke: YOPQ | ||
uppercaseHeight: YTUC | ||
``` | ||
You can read about each on: [https://fonts.google.com/variablefonts#axis-definitions](https://fonts.google.com/variablefonts#axis-definitions) | ||
## Input Validation | ||
✅ Validates the existence of the directive axis used. (`weight or wght`, `opticalSize or opsz`) | ||
✅ Ignores duplicate directives (`wght`) and uses the latest one. | ||
❌ Does **not** validate if the font requested has the directive in its options. Eg: If you request **Open Sans**, asking for `slant -10` the URL will properly be created **BUT** Google will return a `400` answer as the **slant** directive is not avaliable for **Open Sans** | ||
- ✅ Validates the existence of the directive axis used. (`weight or wght`, `opticalSize or opsz`) | ||
- ✅ Ignores duplicate directives (`wght`) and uses the latest one. | ||
- ❌ Does **not** validate if the font requested has the directive in its options. Eg: If you request **Open Sans**, asking for `slant -10` the URL will properly be created **BUT** Google will return a `400` answer as the **slant** directive is not avaliable for **Open Sans** | ||
## Examples | ||
- HTML Import: [https://codepen.io/adrianotirloni/pen/ExEWbdd](https://codepen.io/adrianotirloni/pen/ExEWbdd) | ||
- Function use: [https://codepen.io/adrianotirloni/pen/wvmJxpG](https://codepen.io/adrianotirloni/pen/wvmJxpG) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
51247
11
256
0