@gem-sdk/pages 17.0.0-dev.65 → 17.0.0-dev.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
- "use strict";var t=require("./helpers/check-option-font.js"),e=require("./helpers/gen-fonts.js"),r=require("./helpers/sentry.js"),n=require("./constants/theme-font-keys.js"),i=require("../constants/googleFontV1.js"),a=require("./data/fonts.js");const l="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36";async function o(t,e){try{return fetch(t,{headers:{"User-Agent":e}}).then(n=>200===n.status?n.text():(r.sentryCaptureException("getFontForUA",`Unexpected status ${n.status}`,{url:t,UA:e}),""))}catch(n){return r.sentryCaptureException("getFontForUA","Error fetching font",{url:t,UA:e,error:n}),""}}const s=t=>{let e=t.filter((t,e,r)=>e===r.findIndex(e=>e.family===t.family));return e.map(e=>{let r=t.filter(t=>t.family===e.family).reduce((t,e)=>[...t,...e.variants],[]).filter((t,e,r)=>e===r.findIndex(e=>e===t));return{...e,variants:r}})},f={"Roboto Flex":"https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,100..1000&display=swap"},c=t=>t?.trim().replace(/\s+/g,"+")??"",p=t=>t.includes("fonts.googleapis.com/css2")?"css2":t.includes("fonts.bunny.net")?"bunny":"css1",u=t=>{let e=c(t);return f[t]??f[e]},y={regular:"400",normal:"400",bold:"700",italic:"400italic"},g=new Set(i.googleFontFamilies),h=[...n.THEME_FONT_CSS_KEYS,...n.THEME_FONT_CSS_KEYS.map(t=>`--g-${t}`)],m=(e,r,n)=>{if(("google"===r||"google"===e.type)&&!g.has(e.family))return!1;let i="google"===e.type||"bunny"===e.type,a="theme"===e.type&&n,l=t.checkNotInOptionFont(e.family,r);return!(i&&l)&&(i||!e.type||a)},d=t=>{let e=String(t).toLowerCase().trim();return y[e]??t},S=t=>{let e=t=>{let e=String(t).toLowerCase().trim(),r=e.includes("italic"),n=e.replace("italic","").trim(),i=y[n]??n,a=parseInt(i,10)||400;return{weight:a,isItalic:r}};return[...t].sort((t,r)=>{let n=e(t),i=e(r);return n.weight!==i.weight?n.weight-i.weight:n.isItalic!==i.isItalic?n.isItalic?1:-1:0})},b=(t,e,r)=>{let n=s(t).map(t=>{let e=t.variants.map(t=>d(t)),r=S(e);return`${t.family.replace(/ /g,"+")}:${r.join(",")}`}).join("|");if("sans-serif"===n)return;let i=new URLSearchParams;return(i.append("family",n),i.append("display",r?.display||"swap"),"bunny"===e)?`https://fonts.bunny.net/css?${decodeURIComponent(i.toString())}`:(r?.subset&&i.append("subset",r.subset),r?.effect&&i.append("effect",r.effect),`https://fonts.googleapis.com/css?${decodeURIComponent(i.toString())}`)},v=(t,e,r,n)=>{let i=t.filter(t=>m(t,r||"google",n));if(!i.length)return;let a=i.filter((t,e,r)=>e===r.findIndex(e=>e.family===t.family)),l=[],o=[];for(let t of a){let e=u(t.family);e&&"bunny"!==r?l.push(e):o.push(t)}let s=o.length?b(o,r||"google",e):void 0;return l.length&&s?[...l,s]:s?[s,...l]:l};async function F(t,e,n=!0,i){let a=t.filter(t=>!h.includes(t.family)),s=v(a,e,i),f=Array.isArray(s)?s:s?[s]:[];if(!f.length)return"";if(n)return f.map(t=>`@import url('${t}');`).join("");let c="",u="";for(let t of f)try{let[e,r]=await Promise.all([o(t,"Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko"),o(t,l)]),n=`${e}${r}`;c+=n,u+=`@import url('${t}');`}catch(n){let e=p(t);r.sentryCaptureException("getFonts",`Error fetching font ${e}`,{url:t,fontType:i,fontApiVersion:e,error:String(n)}),u+="",c+=""}let y=new TextEncoder().encode(c).length;return y<51200?c:u}const w=(t,r)=>{let n=[];return t.forEach(t=>{n.push(...e.getFontsFromDataBuilder(t.data,r))}),s(n)},$=(t,e)=>{let r="400";if(null!=t){let e=String(t).toLowerCase().trim();r=d(e)}let n=r,i=e&&"italic"===e.toLowerCase();return i&&!r.includes("italic")&&(n=r.includes("i")?r:`${r}italic`),n},j="heading-",x="subheading-",E="paragraph-",O=t=>{let e=t?.typography??{},r=t?.font??{},n=new Map;Object.entries(e).forEach(([t,e])=>{if(!e||"object"!=typeof e)return;let i=t.startsWith(j)||t.startsWith(x)?r.heading?"heading":void 0:t.startsWith(E)&&r.body?"body":void 0,a=e.desktop,l=a?.fontFamily,o=l||i;["desktop","mobile","tablet"].forEach(t=>{let i=e[t];if(!i||"object"!=typeof i)return;let l=i.fontFamily||o;if(!l||"string"!=typeof l||!r[l])return;let s=i.fontWeight??a?.fontWeight,f=i.fontStyle??a?.fontStyle;if(null==s)return;let c=$(s,f);n.has(l)||n.set(l,new Set),n.get(l).add(c)})});let i={};return n.forEach((t,e)=>{let n=r[e];n&&(i[e]={variants:Array.from(t).sort(),family:n.family,type:n.type})}),i},W=t=>{let e=t?.typography??{},r=t?.font??{},n=t?.font??{},i={};return Object.entries(e).forEach(([t,e])=>{if(!e||"object"!=typeof e)return;let a=e.desktop,l=e.mobile,o=e.tablet,s=t.startsWith(j)||t.startsWith(x)?n.heading?"heading":void 0:t.startsWith(E)&&n.body?"body":void 0,f=a?.fontFamily||l?.fontFamily||o?.fontFamily||s;if(!f||"string"!=typeof f)return;let c=r[f],p=n[f],u=c?.family||p?.family||f,y=c?.type||p?.type||"google";u&&(i[t]={family:u,type:y})}),i},C=async(t,e)=>{if(!t)return"";try{let r=JSON.parse(t),n=r?.font??{},i=Object.values(n),a=O(r);Object.keys(a).length>0&&(i=Object.entries(n).filter(([t])=>a[t]).map(([t,e])=>({...e,variants:a[t].variants})));let l=s(i);return F(l,void 0,void 0,e)}catch{return""}};async function k(t,e,r){let n,i=null;if(r)try{i=JSON.parse(r),n=W(i)}catch{}let a=w(t,n);if(!i){if(0===a.length)return[];let t=await F(a,void 0,void 0,e);return t?[t]:[]}let l=O(i),o=new Map,s=new Map,f=(t,e)=>`${t}::${e}`;for(let t of Object.values(l)){if(t.type){let e=f(t.family,t.type),r=o.get(e);if(!r){o.set(e,new Set(t.variants));continue}t.variants.forEach(t=>r.add(t));continue}let e=s.get(t.family);if(!e){s.set(t.family,new Set(t.variants));continue}t.variants.forEach(t=>e.add(t))}if(0===(a=a.map(t=>{let e=o.get(f(t.family,t.type))||s.get(t.family);if(!e)return t;let r=t.variants.filter(t=>!e.has(t));return 0===r.length?null:{...t,variants:r}}).filter(t=>null!==t)).length)return[];let c=await F(a,void 0,void 0,e);return c?[c]:[]}let T=null;function I({fontFamily:t,fontStyle:e,fontWeight:r,src:n,fontDisplay:i}){let a=n.replace(/^"|"$/g,""),l=`@font-face {
1
+ "use strict";var t=require("./helpers/check-option-font.js"),e=require("./helpers/gen-fonts.js"),r=require("./helpers/sentry.js"),n=require("./constants/theme-font-keys.js"),i=require("../constants/googleFontV1.js"),a=require("./data/fonts.js");const l="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36";async function o(t,e){try{return fetch(t,{headers:{"User-Agent":e}}).then(n=>200===n.status?n.text():(r.sentryCaptureException("getFontForUA",`Unexpected status ${n.status}`,{url:t,UA:e}),""))}catch(n){return r.sentryCaptureException("getFontForUA","Error fetching font",{url:t,UA:e,error:n}),""}}const s=t=>{let e=t.filter((t,e,r)=>e===r.findIndex(e=>e.family===t.family));return e.map(e=>{let r=t.filter(t=>t.family===e.family).reduce((t,e)=>[...t,...e.variants],[]).filter((t,e,r)=>e===r.findIndex(e=>e===t));return{...e,variants:r}})},f={"Roboto Flex":"https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,100..1000&display=swap"},c=t=>t?.trim().replace(/\s+/g,"+")??"",u=t=>t.includes("fonts.googleapis.com/css2")?"css2":t.includes("fonts.bunny.net")?"bunny":"css1",p=t=>{let e=c(t);return f[t]??f[e]},y={regular:"400",normal:"400",bold:"700",italic:"400italic"},g=new Set(i.googleFontFamilies),h=[...n.THEME_FONT_CSS_KEYS,...n.THEME_FONT_CSS_KEYS.map(t=>`--g-${t}`)],m=(e,r,n)=>{if(("google"===r||"google"===e.type)&&!g.has(e.family))return!1;let i="google"===e.type||"bunny"===e.type,a="theme"===e.type&&n,l=t.checkNotInOptionFont(e.family,r);return!(i&&l)&&(i||!e.type||a)},d=t=>{let e=String(t).toLowerCase().trim();return y[e]??t},b=t=>{let e=t=>{let e=String(t).toLowerCase().trim(),r=e.includes("italic"),n=e.replace("italic","").trim(),i=y[n]??n,a=parseInt(i,10)||400;return{weight:a,isItalic:r}};return[...t].sort((t,r)=>{let n=e(t),i=e(r);return n.weight!==i.weight?n.weight-i.weight:n.isItalic!==i.isItalic?n.isItalic?1:-1:0})},S=(t,e,r)=>{let n=s(t).map(t=>{let e=t.variants.map(t=>d(t)),r=b(e);return`${t.family.replace(/ /g,"+")}:${r.join(",")}`}).join("|");if("sans-serif"===n)return;let i=new URLSearchParams;return(i.append("family",n),i.append("display",r?.display||"swap"),"bunny"===e)?`https://fonts.bunny.net/css?${decodeURIComponent(i.toString())}`:(r?.subset&&i.append("subset",r.subset),r?.effect&&i.append("effect",r.effect),`https://fonts.googleapis.com/css?${decodeURIComponent(i.toString())}`)},v=(t,e,r,n)=>{let i=t.filter(t=>m(t,r||"google",n));if(!i.length)return;let a=i.filter((t,e,r)=>e===r.findIndex(e=>e.family===t.family)),l=[],o=[];for(let t of a){let e=p(t.family);e&&"bunny"!==r?l.push(e):o.push(t)}let s=o.length?S(o,r||"google",e):void 0;return l.length&&s?[...l,s]:s?[s,...l]:l};async function F(t,e,n=!0,i){let a=t.filter(t=>!h.includes(t.family)),s=v(a,e,i),f=Array.isArray(s)?s:s?[s]:[];if(!f.length)return"";if(n)return f.map(t=>`@import url('${t}');`).join("");let c="",p="";for(let t of f)try{let[e,r]=await Promise.all([o(t,"Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko"),o(t,l)]),n=`${e}${r}`;c+=n,p+=`@import url('${t}');`}catch(n){let e=u(t);r.sentryCaptureException("getFonts",`Error fetching font ${e}`,{url:t,fontType:i,fontApiVersion:e,error:String(n)}),p+="",c+=""}let y=new TextEncoder().encode(c).length;return y<51200?c:p}const w=(t,r)=>{let n=[];return t.forEach(t=>{n.push(...e.getFontsFromDataBuilder(t.data,r))}),s(n)},$=(t,e)=>{let r="400";if(null!=t){let e=String(t).toLowerCase().trim();r=d(e)}let n=r,i=e&&"italic"===e.toLowerCase();return i&&!r.includes("italic")&&(n=r.includes("i")?r:`${r}italic`),n},j="heading-",x="subheading-",E="paragraph-",O=t=>{let e=t?.typography??{},r=t?.font??{},n=new Map;Object.entries(e).forEach(([t,e])=>{if(!e||"object"!=typeof e)return;let i=t.startsWith(j)||t.startsWith(x)?r.heading?"heading":void 0:t.startsWith(E)&&r.body?"body":void 0,a=e.desktop,l=a?.fontFamily,o=l||i;["desktop","mobile","tablet"].forEach(t=>{let i=e[t];if(!i||"object"!=typeof i)return;let l=i.fontFamily||o;if(!l||"string"!=typeof l||!r[l])return;let s=i.fontWeight??a?.fontWeight,f=i.fontStyle??a?.fontStyle;if(null==s)return;let c=$(s,f);n.has(l)||n.set(l,new Set),n.get(l).add(c)})});let i={};return n.forEach((t,e)=>{let n=r[e];n&&(i[e]={variants:Array.from(t).sort(),family:n.family,type:n.type})}),i},W=t=>{let e=t?.typography??{},r=t?.font??{},n=t?.font??{},i={};return Object.entries(e).forEach(([t,e])=>{if(!e||"object"!=typeof e)return;let a=e.desktop,l=e.mobile,o=e.tablet,s=t.startsWith(j)||t.startsWith(x)?n.heading?"heading":void 0:t.startsWith(E)&&n.body?"body":void 0,f=a?.fontFamily||l?.fontFamily||o?.fontFamily||s;if(!f||"string"!=typeof f)return;let c=r[f],u=n[f],p=c?.family||u?.family||f,y=c?.type||u?.type||"google";p&&(i[t]={family:p,type:y})}),i},C=async(t,e)=>{if(!t)return"";try{let r=JSON.parse(t),n=r?.font??{},i=Object.values(n),a=O(r);Object.keys(a).length>0&&(i=Object.entries(n).filter(([t])=>a[t]).map(([t,e])=>({...e,variants:a[t].variants})));let l=s(i);return F(l,void 0,void 0,e)}catch{return""}};async function k(t,e,r){let n,i=null;if(r)try{i=JSON.parse(r),n=W(i)}catch{}let a=w(t,n);if(!i){if(0===a.length)return[];let t=await F(a,void 0,void 0,e);return t?[t]:[]}let l=O(i),o=new Map,s=new Map,f=(t,e)=>`${t}::${e}`;for(let t of Object.values(l)){if(t.type){let e=f(t.family,t.type),r=o.get(e);if(!r){o.set(e,new Set(t.variants));continue}t.variants.forEach(t=>r.add(t));continue}let e=s.get(t.family);if(!e){s.set(t.family,new Set(t.variants));continue}t.variants.forEach(t=>e.add(t))}if(0===(a=a.map(t=>{let e=o.get(f(t.family,t.type))||s.get(t.family);if(!e)return t;let r=t.variants.filter(t=>!e.has(t));return 0===r.length?null:{...t,variants:r}}).filter(t=>null!==t)).length)return[];let c=await F(a,void 0,void 0,e);return c?[c]:[]}let T=null;function I({fontFamily:t,fontStyle:e,fontWeight:r,src:n,fontDisplay:i}){let a=n.replace(/^"|"$/g,""),l=`@font-face {
2
2
  `;return l+=` font-family: '${t}';
3
3
  font-style: ${e};
4
4
  font-weight: ${r};
5
5
  `,i&&(l+=` font-display: ${i};
6
6
  `),l+=` src: ${a};
7
- }`}function M({variant:t}){let e=t.trim().toLowerCase();if("regular"===e||"400"===e)return{fontStyle:"normal",fontWeight:"400"};if("italic"===e)return{fontStyle:"italic",fontWeight:"400"};if("bold"===e||"700"===e)return{fontStyle:"normal",fontWeight:"700"};let r=e.endsWith("i")||e.endsWith("italic"),n=e.replace(/i(talic)?$/,"").trim()||"400";return{fontStyle:r?"italic":"normal",fontWeight:n}}async function _({fonts:t,sourceFont:e}){let n=t.filter(t=>!h.includes(t.family));if(!n.length)return"";let i=function(){if(T)return T;for(let t of(T={},a.default.fonts)){let e=`${t.fontFamily}_${t.fontStyle}_${t.fontWeight}`.replace(/\s+/g,"");T[e]=t}return T}(),s=await Promise.all(n.map(async t=>{let n=[],a=[];for(let e of t.variants){let{fontStyle:r,fontWeight:l}=M({variant:e}),o=`${t.family}_${r}_${l}`.replace(/\s+/g,""),s=i[o];s?n.push(I(s)):a.push(e)}if(a.length){let i=v([{...t,variants:a}],void 0,e),s=Array.isArray(i)?i:i?[i]:[],f=await Promise.all(s.map(t=>o(t,l)));for(let e=0;e<f.length;e++)f[e]?n.push(f[e]||""):r.sentryCaptureException("resolveFontFaces","API fallback returned empty CSS",{family:t.family,variants:a,url:s[e]})}return n.length?n.join("\n"):""}));return s.filter(Boolean).join("\n")}async function A({data:t,sourceFont:e}){if(!t)return"";try{let r="string"==typeof t?JSON.parse(t):t,n=r?.font??{},i=Object.values(n),a=O(r);return Object.keys(a).length>0&&(i=Object.entries(n).filter(([t])=>a[t]).map(([t,e])=>Object.assign({},e,{variants:a[t].variants}))),_({fonts:s(i),sourceFont:e})}catch{return""}}async function N({pageTemplate:t,sourceFont:e,data:r}){let n,i=null;if(r)try{i="string"==typeof r?JSON.parse(r):r,n=W(i)}catch{}let a=w(t,n);if(!i){if(!a.length)return[];let t=await _({fonts:a,sourceFont:e});return t?[t]:[]}let l=O(i),o=new Map,s=new Map,f=(t,e)=>`${t}::${e}`;for(let t of Object.values(l))if(t.type){let e=f(t.family,t.type),r=o.get(e);r?t.variants.forEach(t=>r.add(t)):o.set(e,new Set(t.variants))}else{let e=s.get(t.family);e?t.variants.forEach(t=>e.add(t)):s.set(t.family,new Set(t.variants))}if(!(a=a.map(t=>{let e=o.get(f(t.family,t.type))||s.get(t.family);if(!e)return t;let r=t.variants.filter(t=>!e.has(t));return r.length?Object.assign({},t,{variants:r}):null}).filter(t=>null!==t)).length)return[];let c=await _({fonts:a,sourceFont:e});return c?[c]:[]}exports.composeFonts=s,exports.createFontUrls=v,exports.extractTypographyVariants=O,exports.getFontFromGlobalStyle=(t,e)=>{if(!t)return"";try{let r=JSON.parse(t),n=r?.font??{},i=Object.entries(n).map(([,t])=>t);return F(i,void 0,void 0,e)}catch{return""}},exports.getFontLinkFromGlobalStyle=C,exports.getFontStyleFromPageTemplate=k,exports.getFonts=F,exports.getStaticFontFacesFromGlobalStyle=A,exports.getStaticFontFacesFromPageTemplate=N,exports.mapTypographyToFontFamily=W,exports.parseVariant=M,exports.staticFontToCSS=I;
7
+ }`}function M({variant:t}){let e=t.trim().toLowerCase();if("regular"===e||"400"===e)return{fontStyle:"normal",fontWeight:"400"};if("italic"===e)return{fontStyle:"italic",fontWeight:"400"};if("bold"===e||"700"===e)return{fontStyle:"normal",fontWeight:"700"};let r=e.endsWith("i")||e.endsWith("italic"),n=e.replace(/i(talic)?$/,"").trim()||"400";return{fontStyle:r?"italic":"normal",fontWeight:n}}async function _({fonts:t,sourceFont:e}){let n=t.filter(t=>!h.includes(t.family));if(!n.length)return"";let i="bunny"===e,s=i?null:function(){if(T)return T;for(let t of(T={},a.default.fonts)){let e=`${t.fontFamily}_${t.fontStyle}_${t.fontWeight}`.replace(/\s+/g,"");T[e]=t}return T}(),f=await Promise.all(n.map(async t=>{let n=[],i=[];for(let e of t.variants){if(s){let{fontStyle:r,fontWeight:i}=M({variant:e}),a=`${t.family}_${r}_${i}`.replace(/\s+/g,""),l=s[a];if(l){n.push(I(l));continue}}i.push(e)}if(i.length){let a=v([{...t,variants:i}],void 0,e),s=Array.isArray(a)?a:a?[a]:[],f=await Promise.all(s.map(t=>o(t,l)));for(let e=0;e<f.length;e++){let a=f[e];a?n.push(a):r.sentryCaptureException("resolveFontFaces","API fallback returned empty CSS",{family:t.family,variants:i,url:s[e]})}}return n.length?n.join("\n"):""}));return f.filter(Boolean).join("\n")}async function A({data:t,sourceFont:e}){if(!t)return"";try{let r="string"==typeof t?JSON.parse(t):t,n=r?.font??{},i=Object.values(n),a=O(r);return Object.keys(a).length>0&&(i=Object.entries(n).filter(([t])=>a[t]).map(([t,e])=>Object.assign({},e,{variants:a[t].variants}))),_({fonts:s(i),sourceFont:e})}catch{return""}}async function N({pageTemplate:t,sourceFont:e,data:r}){let n,i=null;if(r)try{i="string"==typeof r?JSON.parse(r):r,n=W(i)}catch{}let a=w(t,n);if(!i){if(!a.length)return[];let t=await _({fonts:a,sourceFont:e});return t?[t]:[]}let l=O(i),o=new Map,s=new Map,f=(t,e)=>`${t}::${e}`;for(let t of Object.values(l))if(t.type){let e=f(t.family,t.type),r=o.get(e);r?t.variants.forEach(t=>r.add(t)):o.set(e,new Set(t.variants))}else{let e=s.get(t.family);e?t.variants.forEach(t=>e.add(t)):s.set(t.family,new Set(t.variants))}if(!(a=a.map(t=>{let e=o.get(f(t.family,t.type))||s.get(t.family);if(!e)return t;let r=t.variants.filter(t=>!e.has(t));return r.length?Object.assign({},t,{variants:r}):null}).filter(t=>null!==t)).length)return[];let c=await _({fonts:a,sourceFont:e});return c?[c]:[]}exports.composeFonts=s,exports.createFontUrls=v,exports.extractTypographyVariants=O,exports.getFontFromGlobalStyle=(t,e)=>{if(!t)return"";try{let r=JSON.parse(t),n=r?.font??{},i=Object.entries(n).map(([,t])=>t);return F(i,void 0,void 0,e)}catch{return""}},exports.getFontLinkFromGlobalStyle=C,exports.getFontStyleFromPageTemplate=k,exports.getFonts=F,exports.getStaticFontFacesFromGlobalStyle=A,exports.getStaticFontFacesFromPageTemplate=N,exports.mapTypographyToFontFamily=W,exports.parseVariant=M,exports.staticFontToCSS=I;
@@ -1,7 +1,7 @@
1
- import{checkNotInOptionFont as t}from"./helpers/check-option-font.js";import{getFontsFromDataBuilder as e}from"./helpers/gen-fonts.js";import{sentryCaptureException as r}from"./helpers/sentry.js";import{THEME_FONT_CSS_KEYS as n}from"./constants/theme-font-keys.js";import{googleFontFamilies as i}from"../constants/googleFontV1.js";import a from"./data/fonts.js";let l="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36";async function o(t,e){try{return fetch(t,{headers:{"User-Agent":e}}).then(n=>200===n.status?n.text():(r("getFontForUA",`Unexpected status ${n.status}`,{url:t,UA:e}),""))}catch(n){return r("getFontForUA","Error fetching font",{url:t,UA:e,error:n}),""}}let s=t=>{let e=t.filter((t,e,r)=>e===r.findIndex(e=>e.family===t.family));return e.map(e=>{let r=t.filter(t=>t.family===e.family).reduce((t,e)=>[...t,...e.variants],[]).filter((t,e,r)=>e===r.findIndex(e=>e===t));return{...e,variants:r}})},f={"Roboto Flex":"https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,100..1000&display=swap"},c=t=>t?.trim().replace(/\s+/g,"+")??"",y=t=>t.includes("fonts.googleapis.com/css2")?"css2":t.includes("fonts.bunny.net")?"bunny":"css1",u=t=>{let e=c(t);return f[t]??f[e]},p={regular:"400",normal:"400",bold:"700",italic:"400italic"},g=new Set(i),m=[...n,...n.map(t=>`--g-${t}`)],h=(e,r,n)=>{if(("google"===r||"google"===e.type)&&!g.has(e.family))return!1;let i="google"===e.type||"bunny"===e.type,a="theme"===e.type&&n,l=t(e.family,r);return!(i&&l)&&(i||!e.type||a)},d=t=>{let e=String(t).toLowerCase().trim();return p[e]??t},b=t=>{let e=t=>{let e=String(t).toLowerCase().trim(),r=e.includes("italic"),n=e.replace("italic","").trim(),i=p[n]??n,a=parseInt(i,10)||400;return{weight:a,isItalic:r}};return[...t].sort((t,r)=>{let n=e(t),i=e(r);return n.weight!==i.weight?n.weight-i.weight:n.isItalic!==i.isItalic?n.isItalic?1:-1:0})},v=(t,e,r)=>{let n=s(t).map(t=>{let e=t.variants.map(t=>d(t)),r=b(e);return`${t.family.replace(/ /g,"+")}:${r.join(",")}`}).join("|");if("sans-serif"===n)return;let i=new URLSearchParams;return(i.append("family",n),i.append("display",r?.display||"swap"),"bunny"===e)?`https://fonts.bunny.net/css?${decodeURIComponent(i.toString())}`:(r?.subset&&i.append("subset",r.subset),r?.effect&&i.append("effect",r.effect),`https://fonts.googleapis.com/css?${decodeURIComponent(i.toString())}`)},S=(t,e,r,n)=>{let i=t.filter(t=>h(t,r||"google",n));if(!i.length)return;let a=i.filter((t,e,r)=>e===r.findIndex(e=>e.family===t.family)),l=[],o=[];for(let t of a){let e=u(t.family);e&&"bunny"!==r?l.push(e):o.push(t)}let s=o.length?v(o,r||"google",e):void 0;return l.length&&s?[...l,s]:s?[s,...l]:l};async function w(t,e,n=!0,i){let a=t.filter(t=>!m.includes(t.family)),s=S(a,e,i),f=Array.isArray(s)?s:s?[s]:[];if(!f.length)return"";if(n)return f.map(t=>`@import url('${t}');`).join("");let c="",u="";for(let t of f)try{let[e,r]=await Promise.all([o(t,"Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko"),o(t,l)]),n=`${e}${r}`;c+=n,u+=`@import url('${t}');`}catch(n){let e=y(t);r("getFonts",`Error fetching font ${e}`,{url:t,fontType:i,fontApiVersion:e,error:String(n)}),u+="",c+=""}let p=new TextEncoder().encode(c).length;return p<51200?c:u}let F=(t,r)=>{let n=[];return t.forEach(t=>{n.push(...e(t.data,r))}),s(n)},$=(t,e)=>{let r="400";if(null!=t){let e=String(t).toLowerCase().trim();r=d(e)}let n=r,i=e&&"italic"===e.toLowerCase();return i&&!r.includes("italic")&&(n=r.includes("i")?r:`${r}italic`),n},j="heading-",O="subheading-",W="paragraph-",k=t=>{let e=t?.typography??{},r=t?.font??{},n=new Map;Object.entries(e).forEach(([t,e])=>{if(!e||"object"!=typeof e)return;let i=t.startsWith(j)||t.startsWith(O)?r.heading?"heading":void 0:t.startsWith(W)&&r.body?"body":void 0,a=e.desktop,l=a?.fontFamily,o=l||i;["desktop","mobile","tablet"].forEach(t=>{let i=e[t];if(!i||"object"!=typeof i)return;let l=i.fontFamily||o;if(!l||"string"!=typeof l||!r[l])return;let s=i.fontWeight??a?.fontWeight,f=i.fontStyle??a?.fontStyle;if(null==s)return;let c=$(s,f);n.has(l)||n.set(l,new Set),n.get(l).add(c)})});let i={};return n.forEach((t,e)=>{let n=r[e];n&&(i[e]={variants:Array.from(t).sort(),family:n.family,type:n.type})}),i},E=t=>{let e=t?.typography??{},r=t?.font??{},n=t?.font??{},i={};return Object.entries(e).forEach(([t,e])=>{if(!e||"object"!=typeof e)return;let a=e.desktop,l=e.mobile,o=e.tablet,s=t.startsWith(j)||t.startsWith(O)?n.heading?"heading":void 0:t.startsWith(W)&&n.body?"body":void 0,f=a?.fontFamily||l?.fontFamily||o?.fontFamily||s;if(!f||"string"!=typeof f)return;let c=r[f],y=n[f],u=c?.family||y?.family||f,p=c?.type||y?.type||"google";u&&(i[t]={family:u,type:p})}),i},I=async(t,e)=>{if(!t)return"";try{let r=JSON.parse(t),n=r?.font??{},i=Object.values(n),a=k(r);Object.keys(a).length>0&&(i=Object.entries(n).filter(([t])=>a[t]).map(([t,e])=>({...e,variants:a[t].variants})));let l=s(i);return w(l,void 0,void 0,e)}catch{return""}},x=(t,e)=>{if(!t)return"";try{let r=JSON.parse(t),n=r?.font??{},i=Object.entries(n).map(([,t])=>t);return w(i,void 0,void 0,e)}catch{return""}};async function A(t,e,r){let n,i=null;if(r)try{i=JSON.parse(r),n=E(i)}catch{}let a=F(t,n);if(!i){if(0===a.length)return[];let t=await w(a,void 0,void 0,e);return t?[t]:[]}let l=k(i),o=new Map,s=new Map,f=(t,e)=>`${t}::${e}`;for(let t of Object.values(l)){if(t.type){let e=f(t.family,t.type),r=o.get(e);if(!r){o.set(e,new Set(t.variants));continue}t.variants.forEach(t=>r.add(t));continue}let e=s.get(t.family);if(!e){s.set(t.family,new Set(t.variants));continue}t.variants.forEach(t=>e.add(t))}if(0===(a=a.map(t=>{let e=o.get(f(t.family,t.type))||s.get(t.family);if(!e)return t;let r=t.variants.filter(t=>!e.has(t));return 0===r.length?null:{...t,variants:r}}).filter(t=>null!==t)).length)return[];let c=await w(a,void 0,void 0,e);return c?[c]:[]}let C=null;function M({fontFamily:t,fontStyle:e,fontWeight:r,src:n,fontDisplay:i}){let a=n.replace(/^"|"$/g,""),l=`@font-face {
1
+ import{checkNotInOptionFont as t}from"./helpers/check-option-font.js";import{getFontsFromDataBuilder as e}from"./helpers/gen-fonts.js";import{sentryCaptureException as n}from"./helpers/sentry.js";import{THEME_FONT_CSS_KEYS as r}from"./constants/theme-font-keys.js";import{googleFontFamilies as i}from"../constants/googleFontV1.js";import a from"./data/fonts.js";let l="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36";async function o(t,e){try{return fetch(t,{headers:{"User-Agent":e}}).then(r=>200===r.status?r.text():(n("getFontForUA",`Unexpected status ${r.status}`,{url:t,UA:e}),""))}catch(r){return n("getFontForUA","Error fetching font",{url:t,UA:e,error:r}),""}}let s=t=>{let e=t.filter((t,e,n)=>e===n.findIndex(e=>e.family===t.family));return e.map(e=>{let n=t.filter(t=>t.family===e.family).reduce((t,e)=>[...t,...e.variants],[]).filter((t,e,n)=>e===n.findIndex(e=>e===t));return{...e,variants:n}})},f={"Roboto Flex":"https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,100..1000&display=swap"},c=t=>t?.trim().replace(/\s+/g,"+")??"",y=t=>t.includes("fonts.googleapis.com/css2")?"css2":t.includes("fonts.bunny.net")?"bunny":"css1",u=t=>{let e=c(t);return f[t]??f[e]},p={regular:"400",normal:"400",bold:"700",italic:"400italic"},g=new Set(i),m=[...r,...r.map(t=>`--g-${t}`)],h=(e,n,r)=>{if(("google"===n||"google"===e.type)&&!g.has(e.family))return!1;let i="google"===e.type||"bunny"===e.type,a="theme"===e.type&&r,l=t(e.family,n);return!(i&&l)&&(i||!e.type||a)},d=t=>{let e=String(t).toLowerCase().trim();return p[e]??t},b=t=>{let e=t=>{let e=String(t).toLowerCase().trim(),n=e.includes("italic"),r=e.replace("italic","").trim(),i=p[r]??r,a=parseInt(i,10)||400;return{weight:a,isItalic:n}};return[...t].sort((t,n)=>{let r=e(t),i=e(n);return r.weight!==i.weight?r.weight-i.weight:r.isItalic!==i.isItalic?r.isItalic?1:-1:0})},v=(t,e,n)=>{let r=s(t).map(t=>{let e=t.variants.map(t=>d(t)),n=b(e);return`${t.family.replace(/ /g,"+")}:${n.join(",")}`}).join("|");if("sans-serif"===r)return;let i=new URLSearchParams;return(i.append("family",r),i.append("display",n?.display||"swap"),"bunny"===e)?`https://fonts.bunny.net/css?${decodeURIComponent(i.toString())}`:(n?.subset&&i.append("subset",n.subset),n?.effect&&i.append("effect",n.effect),`https://fonts.googleapis.com/css?${decodeURIComponent(i.toString())}`)},S=(t,e,n,r)=>{let i=t.filter(t=>h(t,n||"google",r));if(!i.length)return;let a=i.filter((t,e,n)=>e===n.findIndex(e=>e.family===t.family)),l=[],o=[];for(let t of a){let e=u(t.family);e&&"bunny"!==n?l.push(e):o.push(t)}let s=o.length?v(o,n||"google",e):void 0;return l.length&&s?[...l,s]:s?[s,...l]:l};async function w(t,e,r=!0,i){let a=t.filter(t=>!m.includes(t.family)),s=S(a,e,i),f=Array.isArray(s)?s:s?[s]:[];if(!f.length)return"";if(r)return f.map(t=>`@import url('${t}');`).join("");let c="",u="";for(let t of f)try{let[e,n]=await Promise.all([o(t,"Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko"),o(t,l)]),r=`${e}${n}`;c+=r,u+=`@import url('${t}');`}catch(r){let e=y(t);n("getFonts",`Error fetching font ${e}`,{url:t,fontType:i,fontApiVersion:e,error:String(r)}),u+="",c+=""}let p=new TextEncoder().encode(c).length;return p<51200?c:u}let F=(t,n)=>{let r=[];return t.forEach(t=>{r.push(...e(t.data,n))}),s(r)},$=(t,e)=>{let n="400";if(null!=t){let e=String(t).toLowerCase().trim();n=d(e)}let r=n,i=e&&"italic"===e.toLowerCase();return i&&!n.includes("italic")&&(r=n.includes("i")?n:`${n}italic`),r},j="heading-",O="subheading-",W="paragraph-",k=t=>{let e=t?.typography??{},n=t?.font??{},r=new Map;Object.entries(e).forEach(([t,e])=>{if(!e||"object"!=typeof e)return;let i=t.startsWith(j)||t.startsWith(O)?n.heading?"heading":void 0:t.startsWith(W)&&n.body?"body":void 0,a=e.desktop,l=a?.fontFamily,o=l||i;["desktop","mobile","tablet"].forEach(t=>{let i=e[t];if(!i||"object"!=typeof i)return;let l=i.fontFamily||o;if(!l||"string"!=typeof l||!n[l])return;let s=i.fontWeight??a?.fontWeight,f=i.fontStyle??a?.fontStyle;if(null==s)return;let c=$(s,f);r.has(l)||r.set(l,new Set),r.get(l).add(c)})});let i={};return r.forEach((t,e)=>{let r=n[e];r&&(i[e]={variants:Array.from(t).sort(),family:r.family,type:r.type})}),i},E=t=>{let e=t?.typography??{},n=t?.font??{},r=t?.font??{},i={};return Object.entries(e).forEach(([t,e])=>{if(!e||"object"!=typeof e)return;let a=e.desktop,l=e.mobile,o=e.tablet,s=t.startsWith(j)||t.startsWith(O)?r.heading?"heading":void 0:t.startsWith(W)&&r.body?"body":void 0,f=a?.fontFamily||l?.fontFamily||o?.fontFamily||s;if(!f||"string"!=typeof f)return;let c=n[f],y=r[f],u=c?.family||y?.family||f,p=c?.type||y?.type||"google";u&&(i[t]={family:u,type:p})}),i},I=async(t,e)=>{if(!t)return"";try{let n=JSON.parse(t),r=n?.font??{},i=Object.values(r),a=k(n);Object.keys(a).length>0&&(i=Object.entries(r).filter(([t])=>a[t]).map(([t,e])=>({...e,variants:a[t].variants})));let l=s(i);return w(l,void 0,void 0,e)}catch{return""}},x=(t,e)=>{if(!t)return"";try{let n=JSON.parse(t),r=n?.font??{},i=Object.entries(r).map(([,t])=>t);return w(i,void 0,void 0,e)}catch{return""}};async function A(t,e,n){let r,i=null;if(n)try{i=JSON.parse(n),r=E(i)}catch{}let a=F(t,r);if(!i){if(0===a.length)return[];let t=await w(a,void 0,void 0,e);return t?[t]:[]}let l=k(i),o=new Map,s=new Map,f=(t,e)=>`${t}::${e}`;for(let t of Object.values(l)){if(t.type){let e=f(t.family,t.type),n=o.get(e);if(!n){o.set(e,new Set(t.variants));continue}t.variants.forEach(t=>n.add(t));continue}let e=s.get(t.family);if(!e){s.set(t.family,new Set(t.variants));continue}t.variants.forEach(t=>e.add(t))}if(0===(a=a.map(t=>{let e=o.get(f(t.family,t.type))||s.get(t.family);if(!e)return t;let n=t.variants.filter(t=>!e.has(t));return 0===n.length?null:{...t,variants:n}}).filter(t=>null!==t)).length)return[];let c=await w(a,void 0,void 0,e);return c?[c]:[]}let C=null;function M({fontFamily:t,fontStyle:e,fontWeight:n,src:r,fontDisplay:i}){let a=r.replace(/^"|"$/g,""),l=`@font-face {
2
2
  `;return l+=` font-family: '${t}';
3
3
  font-style: ${e};
4
- font-weight: ${r};
4
+ font-weight: ${n};
5
5
  `,i&&(l+=` font-display: ${i};
6
6
  `),l+=` src: ${a};
7
- }`}function T({variant:t}){let e=t.trim().toLowerCase();if("regular"===e||"400"===e)return{fontStyle:"normal",fontWeight:"400"};if("italic"===e)return{fontStyle:"italic",fontWeight:"400"};if("bold"===e||"700"===e)return{fontStyle:"normal",fontWeight:"700"};let r=e.endsWith("i")||e.endsWith("italic"),n=e.replace(/i(talic)?$/,"").trim()||"400";return{fontStyle:r?"italic":"normal",fontWeight:n}}async function L({fonts:t,sourceFont:e}){let n=t.filter(t=>!m.includes(t.family));if(!n.length)return"";let i=function(){if(C)return C;for(let t of(C={},a.fonts)){let e=`${t.fontFamily}_${t.fontStyle}_${t.fontWeight}`.replace(/\s+/g,"");C[e]=t}return C}(),s=await Promise.all(n.map(async t=>{let n=[],a=[];for(let e of t.variants){let{fontStyle:r,fontWeight:l}=T({variant:e}),o=`${t.family}_${r}_${l}`.replace(/\s+/g,""),s=i[o];s?n.push(M(s)):a.push(e)}if(a.length){let i=S([{...t,variants:a}],void 0,e),s=Array.isArray(i)?i:i?[i]:[],f=await Promise.all(s.map(t=>o(t,l)));for(let e=0;e<f.length;e++)f[e]?n.push(f[e]||""):r("resolveFontFaces","API fallback returned empty CSS",{family:t.family,variants:a,url:s[e]})}return n.length?n.join("\n"):""}));return s.filter(Boolean).join("\n")}async function U({data:t,sourceFont:e}){if(!t)return"";try{let r="string"==typeof t?JSON.parse(t):t,n=r?.font??{},i=Object.values(n),a=k(r);return Object.keys(a).length>0&&(i=Object.entries(n).filter(([t])=>a[t]).map(([t,e])=>Object.assign({},e,{variants:a[t].variants}))),L({fonts:s(i),sourceFont:e})}catch{return""}}async function P({pageTemplate:t,sourceFont:e,data:r}){let n,i=null;if(r)try{i="string"==typeof r?JSON.parse(r):r,n=E(i)}catch{}let a=F(t,n);if(!i){if(!a.length)return[];let t=await L({fonts:a,sourceFont:e});return t?[t]:[]}let l=k(i),o=new Map,s=new Map,f=(t,e)=>`${t}::${e}`;for(let t of Object.values(l))if(t.type){let e=f(t.family,t.type),r=o.get(e);r?t.variants.forEach(t=>r.add(t)):o.set(e,new Set(t.variants))}else{let e=s.get(t.family);e?t.variants.forEach(t=>e.add(t)):s.set(t.family,new Set(t.variants))}if(!(a=a.map(t=>{let e=o.get(f(t.family,t.type))||s.get(t.family);if(!e)return t;let r=t.variants.filter(t=>!e.has(t));return r.length?Object.assign({},t,{variants:r}):null}).filter(t=>null!==t)).length)return[];let c=await L({fonts:a,sourceFont:e});return c?[c]:[]}export{s as composeFonts,S as createFontUrls,k as extractTypographyVariants,x as getFontFromGlobalStyle,I as getFontLinkFromGlobalStyle,A as getFontStyleFromPageTemplate,w as getFonts,U as getStaticFontFacesFromGlobalStyle,P as getStaticFontFacesFromPageTemplate,E as mapTypographyToFontFamily,T as parseVariant,M as staticFontToCSS};
7
+ }`}function T({variant:t}){let e=t.trim().toLowerCase();if("regular"===e||"400"===e)return{fontStyle:"normal",fontWeight:"400"};if("italic"===e)return{fontStyle:"italic",fontWeight:"400"};if("bold"===e||"700"===e)return{fontStyle:"normal",fontWeight:"700"};let n=e.endsWith("i")||e.endsWith("italic"),r=e.replace(/i(talic)?$/,"").trim()||"400";return{fontStyle:n?"italic":"normal",fontWeight:r}}async function L({fonts:t,sourceFont:e}){let r=t.filter(t=>!m.includes(t.family));if(!r.length)return"";let i="bunny"===e,s=i?null:function(){if(C)return C;for(let t of(C={},a.fonts)){let e=`${t.fontFamily}_${t.fontStyle}_${t.fontWeight}`.replace(/\s+/g,"");C[e]=t}return C}(),f=await Promise.all(r.map(async t=>{let r=[],i=[];for(let e of t.variants){if(s){let{fontStyle:n,fontWeight:i}=T({variant:e}),a=`${t.family}_${n}_${i}`.replace(/\s+/g,""),l=s[a];if(l){r.push(M(l));continue}}i.push(e)}if(i.length){let a=S([{...t,variants:i}],void 0,e),s=Array.isArray(a)?a:a?[a]:[],f=await Promise.all(s.map(t=>o(t,l)));for(let e=0;e<f.length;e++){let a=f[e];a?r.push(a):n("resolveFontFaces","API fallback returned empty CSS",{family:t.family,variants:i,url:s[e]})}}return r.length?r.join("\n"):""}));return f.filter(Boolean).join("\n")}async function U({data:t,sourceFont:e}){if(!t)return"";try{let n="string"==typeof t?JSON.parse(t):t,r=n?.font??{},i=Object.values(r),a=k(n);return Object.keys(a).length>0&&(i=Object.entries(r).filter(([t])=>a[t]).map(([t,e])=>Object.assign({},e,{variants:a[t].variants}))),L({fonts:s(i),sourceFont:e})}catch{return""}}async function P({pageTemplate:t,sourceFont:e,data:n}){let r,i=null;if(n)try{i="string"==typeof n?JSON.parse(n):n,r=E(i)}catch{}let a=F(t,r);if(!i){if(!a.length)return[];let t=await L({fonts:a,sourceFont:e});return t?[t]:[]}let l=k(i),o=new Map,s=new Map,f=(t,e)=>`${t}::${e}`;for(let t of Object.values(l))if(t.type){let e=f(t.family,t.type),n=o.get(e);n?t.variants.forEach(t=>n.add(t)):o.set(e,new Set(t.variants))}else{let e=s.get(t.family);e?t.variants.forEach(t=>e.add(t)):s.set(t.family,new Set(t.variants))}if(!(a=a.map(t=>{let e=o.get(f(t.family,t.type))||s.get(t.family);if(!e)return t;let n=t.variants.filter(t=>!e.has(t));return n.length?Object.assign({},t,{variants:n}):null}).filter(t=>null!==t)).length)return[];let c=await L({fonts:a,sourceFont:e});return c?[c]:[]}export{s as composeFonts,S as createFontUrls,k as extractTypographyVariants,x as getFontFromGlobalStyle,I as getFontLinkFromGlobalStyle,A as getFontStyleFromPageTemplate,w as getFonts,U as getStaticFontFacesFromGlobalStyle,P as getStaticFontFacesFromPageTemplate,E as mapTypographyToFontFamily,T as parseVariant,M as staticFontToCSS};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/pages",
3
- "version": "17.0.0-dev.65",
3
+ "version": "17.0.0-dev.67",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",
@@ -27,7 +27,7 @@
27
27
  "next": "14.2.35"
28
28
  },
29
29
  "devDependencies": {
30
- "@gem-sdk/core": "17.0.0-dev.63",
30
+ "@gem-sdk/core": "17.0.0-dev.66",
31
31
  "@gem-sdk/plugin-cookie-bar": "17.0.0-dev.38",
32
32
  "@gem-sdk/plugin-quick-view": "17.0.0-dev.38",
33
33
  "@gem-sdk/plugin-sticky-add-to-cart": "17.0.0-dev.38"