@gem-sdk/pages 17.0.0-dev.38 → 17.0.0-dev.51
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 +1 @@
|
|
|
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");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 a=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}})},l={"Roboto Flex":"https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,100..1000&display=swap"},s=t=>t?.trim().replace(/\s+/g,"+")??"",f=t=>t.includes("fonts.googleapis.com/css2")?"css2":t.includes("fonts.bunny.net")?"bunny":"css1",p=t=>{let e=s(t);return l[t]??l[e]},c={regular:"400",normal:"400",bold:"700",italic:"400italic"},
|
|
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");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 a=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}})},l={"Roboto Flex":"https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,100..1000&display=swap"},s=t=>t?.trim().replace(/\s+/g,"+")??"",f=t=>t.includes("fonts.googleapis.com/css2")?"css2":t.includes("fonts.bunny.net")?"bunny":"css1",p=t=>{let e=s(t);return l[t]??l[e]},c={regular:"400",normal:"400",bold:"700",italic:"400italic"},y=new Set(i.googleFontFamilies),u=[...n.THEME_FONT_CSS_KEYS,...n.THEME_FONT_CSS_KEYS.map(t=>`--g-${t}`)],g=(e,r,n)=>{if(("google"===r||"google"===e.type)&&!y.has(e.family))return!1;let i="google"===e.type||"bunny"===e.type,o="theme"===e.type&&n,a=t.checkNotInOptionFont(e.family,r);return!(i&&a)&&(i||!e.type||o)},h=t=>{let e=String(t).toLowerCase().trim();return c[e]??t},m=t=>{let e=t=>{let e=String(t).toLowerCase().trim(),r=e.includes("italic"),n=e.replace("italic","").trim(),i=c[n]??n,o=parseInt(i,10)||400;return{weight:o,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})},d=(t,e,r)=>{let n=a(t).map(t=>{let e=t.variants.map(t=>h(t)),r=m(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())}`)},b=(t,e,r,n)=>{let i=t.filter(t=>g(t,r||"google",n));if(!i.length)return;let o=i.filter((t,e,r)=>e===r.findIndex(e=>e.family===t.family)),a=[],l=[];for(let t of o){let e=p(t.family);e&&"bunny"!==r?a.push(e):l.push(t)}let s=l.length?d(l,r||"google",e):void 0;return a.length&&s?[...a,s]:s?[s,...a]:a};async function F(t,e,n=!0,i){let a=t.filter(t=>!u.includes(t.family)),l=b(a,e,i),s=Array.isArray(l)?l:l?[l]:[];if(!s.length)return"";if(n)return s.map(t=>`@import url('${t}');`).join("");let p="",c="";for(let t of s)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,"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")]),n=`${e}${r}`;p+=n,c+=`@import url('${t}');`}catch(n){let e=f(t);r.sentryCaptureException("getFonts",`Error fetching font ${e}`,{url:t,fontType:i,fontApiVersion:e,error:String(n)}),c+="",p+=""}let y=new TextEncoder().encode(p).length;return y<51200?p:c}const v=(t,r)=>{let n=[];return t.forEach(t=>{n.push(...e.getFontsFromDataBuilder(t.data,r))}),a(n)},S=(t,e)=>{let r="400";if(null!=t){let e=String(t).toLowerCase().trim();r=h(e)}let n=r,i=e&&"italic"===e.toLowerCase();return i&&!r.includes("italic")&&(n=r.includes("i")?r:`${r}italic`),n},w="heading-",x="subheading-",E="paragraph-",j=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(w)||t.startsWith(x)?r.heading?"heading":void 0:t.startsWith(E)&&r.body?"body":void 0,o=e.desktop,a=o?.fontFamily,l=a||i;["desktop","mobile","tablet"].forEach(t=>{let i=e[t];if(!i||"object"!=typeof i)return;let a=i.fontFamily||l;if(!a||"string"!=typeof a||!r[a])return;let s=i.fontWeight??o?.fontWeight,f=i.fontStyle??o?.fontStyle;if(null==s)return;let p=S(s,f);n.has(a)||n.set(a,new Set),n.get(a).add(p)})});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},O=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 o=e.desktop,a=e.mobile,l=e.tablet,s=t.startsWith(w)||t.startsWith(x)?n.heading?"heading":void 0:t.startsWith(E)&&n.body?"body":void 0,f=o?.fontFamily||a?.fontFamily||l?.fontFamily||s;if(!f||"string"!=typeof f)return;let p=r[f],c=n[f],y=p?.family||c?.family||f,u=p?.type||c?.type||"google";y&&(i[t]={family:y,type:u})}),i},$=async(t,e)=>{if(!t)return"";try{let r=JSON.parse(t),n=r?.font??{},i=Object.values(n),o=j(r);Object.keys(o).length>0&&(i=Object.entries(n).filter(([t])=>o[t]).map(([t,e])=>({...e,variants:o[t].variants})));let l=a(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=O(i)}catch{}let o=v(t,n);if(!i){if(0===o.length)return[];let t=await F(o,void 0,void 0,e);return t?[t]:[]}let a=j(i),l=new Map,s=new Map,f=(t,e)=>`${t}::${e}`;for(let t of Object.values(a)){if(t.type){let e=f(t.family,t.type),r=l.get(e);if(!r){l.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===(o=o.map(t=>{let e=l.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 p=await F(o,void 0,void 0,e);return p?[p]:[]}exports.composeFonts=a,exports.createFontUrls=b,exports.extractTypographyVariants=j,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=$,exports.getFontStyleFromPageTemplate=k,exports.getFonts=F,exports.mapTypographyToFontFamily=O;
|
|
@@ -1 +1 @@
|
|
|
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";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
|
|
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";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 a=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}})},l={"Roboto Flex":"https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,100..1000&display=swap"},s=t=>t?.trim().replace(/\s+/g,"+")??"",f=t=>t.includes("fonts.googleapis.com/css2")?"css2":t.includes("fonts.bunny.net")?"bunny":"css1",p=t=>{let e=s(t);return l[t]??l[e]},c={regular:"400",normal:"400",bold:"700",italic:"400italic"},y=new Set(i),u=[...n,...n.map(t=>`--g-${t}`)],g=(e,r,n)=>{if(("google"===r||"google"===e.type)&&!y.has(e.family))return!1;let i="google"===e.type||"bunny"===e.type,o="theme"===e.type&&n,a=t(e.family,r);return!(i&&a)&&(i||!e.type||o)},m=t=>{let e=String(t).toLowerCase().trim();return c[e]??t},h=t=>{let e=t=>{let e=String(t).toLowerCase().trim(),r=e.includes("italic"),n=e.replace("italic","").trim(),i=c[n]??n,o=parseInt(i,10)||400;return{weight:o,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})},d=(t,e,r)=>{let n=a(t).map(t=>{let e=t.variants.map(t=>m(t)),r=h(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())}`)},b=(t,e,r,n)=>{let i=t.filter(t=>g(t,r||"google",n));if(!i.length)return;let o=i.filter((t,e,r)=>e===r.findIndex(e=>e.family===t.family)),a=[],l=[];for(let t of o){let e=p(t.family);e&&"bunny"!==r?a.push(e):l.push(t)}let s=l.length?d(l,r||"google",e):void 0;return a.length&&s?[...a,s]:s?[s,...a]:a};async function v(t,e,n=!0,i){let a=t.filter(t=>!u.includes(t.family)),l=b(a,e,i),s=Array.isArray(l)?l:l?[l]:[];if(!s.length)return"";if(n)return s.map(t=>`@import url('${t}');`).join("");let p="",c="";for(let t of s)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,"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")]),n=`${e}${r}`;p+=n,c+=`@import url('${t}');`}catch(n){let e=f(t);r("getFonts",`Error fetching font ${e}`,{url:t,fontType:i,fontApiVersion:e,error:String(n)}),c+="",p+=""}let y=new TextEncoder().encode(p).length;return y<51200?p:c}let w=(t,r)=>{let n=[];return t.forEach(t=>{n.push(...e(t.data,r))}),a(n)},F=(t,e)=>{let r="400";if(null!=t){let e=String(t).toLowerCase().trim();r=m(e)}let n=r,i=e&&"italic"===e.toLowerCase();return i&&!r.includes("italic")&&(n=r.includes("i")?r:`${r}italic`),n},S="heading-",j="subheading-",$="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(S)||t.startsWith(j)?r.heading?"heading":void 0:t.startsWith($)&&r.body?"body":void 0,o=e.desktop,a=o?.fontFamily,l=a||i;["desktop","mobile","tablet"].forEach(t=>{let i=e[t];if(!i||"object"!=typeof i)return;let a=i.fontFamily||l;if(!a||"string"!=typeof a||!r[a])return;let s=i.fontWeight??o?.fontWeight,f=i.fontStyle??o?.fontStyle;if(null==s)return;let p=F(s,f);n.has(a)||n.set(a,new Set),n.get(a).add(p)})});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},O=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 o=e.desktop,a=e.mobile,l=e.tablet,s=t.startsWith(S)||t.startsWith(j)?n.heading?"heading":void 0:t.startsWith($)&&n.body?"body":void 0,f=o?.fontFamily||a?.fontFamily||l?.fontFamily||s;if(!f||"string"!=typeof f)return;let p=r[f],c=n[f],y=p?.family||c?.family||f,u=p?.type||c?.type||"google";y&&(i[t]={family:y,type:u})}),i},x=async(t,e)=>{if(!t)return"";try{let r=JSON.parse(t),n=r?.font??{},i=Object.values(n),o=k(r);Object.keys(o).length>0&&(i=Object.entries(n).filter(([t])=>o[t]).map(([t,e])=>({...e,variants:o[t].variants})));let l=a(i);return v(l,void 0,void 0,e)}catch{return""}},E=(t,e)=>{if(!t)return"";try{let r=JSON.parse(t),n=r?.font??{},i=Object.entries(n).map(([,t])=>t);return v(i,void 0,void 0,e)}catch{return""}};async function I(t,e,r){let n,i=null;if(r)try{i=JSON.parse(r),n=O(i)}catch{}let o=w(t,n);if(!i){if(0===o.length)return[];let t=await v(o,void 0,void 0,e);return t?[t]:[]}let a=k(i),l=new Map,s=new Map,f=(t,e)=>`${t}::${e}`;for(let t of Object.values(a)){if(t.type){let e=f(t.family,t.type),r=l.get(e);if(!r){l.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===(o=o.map(t=>{let e=l.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 p=await v(o,void 0,void 0,e);return p?[p]:[]}export{a as composeFonts,b as createFontUrls,k as extractTypographyVariants,E as getFontFromGlobalStyle,x as getFontLinkFromGlobalStyle,I as getFontStyleFromPageTemplate,v as getFonts,O as mapTypographyToFontFamily};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gem-sdk/pages",
|
|
3
|
-
"version": "17.0.0-dev.
|
|
3
|
+
"version": "17.0.0-dev.51",
|
|
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.
|
|
30
|
+
"@gem-sdk/core": "17.0.0-dev.50",
|
|
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"
|