@gem-sdk/pages 17.0.0-dev.61 → 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.
- package/dist/cjs/libs/api/get-static-page-props-v2.js +1 -1
- package/dist/cjs/libs/data/fonts.js +1 -0
- package/dist/cjs/libs/google-fonts.js +7 -1
- package/dist/cjs/libs/helpers/gen-fonts.js +1 -1
- package/dist/cjs/pages/static-v2.js +3 -3
- package/dist/esm/libs/api/get-static-page-props-v2.js +1 -1
- package/dist/esm/libs/data/fonts.js +1 -0
- package/dist/esm/libs/google-fonts.js +7 -1
- package/dist/esm/libs/helpers/gen-fonts.js +1 -1
- package/dist/esm/pages/static-v2.js +3 -3
- package/package.json +2 -2
- package/dist/cjs/components/FontLink.js +0 -1
- package/dist/esm/components/FontLink.js +0 -1
|
@@ -1 +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
|
|
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
|
+
`;return l+=` font-family: '${t}';
|
|
3
|
+
font-style: ${e};
|
|
4
|
+
font-weight: ${n};
|
|
5
|
+
`,i&&(l+=` font-display: ${i};
|
|
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 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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
let t=["sans-serif"],e=(t,e)=>{if(e&&t?.type&&!t?.custom?.fontFamily){let l=e[t.type];if(l){let e=JSON.parse(JSON.stringify(t));return e.custom||(e.custom={}),e.custom.fontFamily={value:l.family,type:l.type},e}}return t},l=(t,e)=>{let l=[];for(let o in t)if(Object.prototype.hasOwnProperty.call(t,o)){let
|
|
1
|
+
let t=["sans-serif"],e=(t,e)=>{if(e&&t?.type&&!t?.custom?.fontFamily){let l=e[t.type];if(l){let e=JSON.parse(JSON.stringify(t));return e.custom||(e.custom={}),e.custom.fontFamily={value:l.family,type:l.type},e}}return t},l=(t,e)=>{let l=[];for(let o in t)if(Object.prototype.hasOwnProperty.call(t,o)){let s=t[o],n=s.styles,r=s.settings;i(l,n,e),i(l,r,e)}return l},i=(t,l,i)=>{let o=["normal","hover","focus","active","disabled","price","compareAtPrice"];for(let n in l)if(Object.prototype.hasOwnProperty.call(l,n)){let r=l[n];if(!r)continue;let a=i?e(r,i):r;for(let l of(s(t,a),o)){if(!r[l])continue;let o=i?e(r[l],i):r[l];s(t,o)}}},o=t=>Array.from(new Set(t)),s=(e,l)=>{let i=l.custom?.fontFamily;"string"==typeof i&&(i={value:l.custom?.fontFamily||"",type:"google"});let s=i?.value;if(t.includes(s))return;let n=l.custom?.fontVariants;if(n?.length||(n=[l.custom?.fontWeight]),i&&n?.length){let t=n.map(t=>"regular"===t?"400":t),r=l.custom?.fontWeight&&t.includes(l.custom?.fontWeight)?l.custom?.fontWeight:t[0];if(r){let n=o([r,...l?.attrs?.isAlwaysLoadBold?["700"]:[],...l?.attrs?.loadFontStyles?.includes("bold")?["700"]:[]]);if(l?.attrs?.loadFontStyles?.includes("italic")){let t=n.map(t=>"string"==typeof t&&/^\d+$/.test(t)?`${t}i`:null).filter(t=>null!==t);n.push(...t)}let a=e.find(t=>t.family==s&&n.every(e=>t.variants.includes(e)));if(!a){let l=e.find(t=>t.family==s);l?n.forEach(t=>{l.variants.includes(t)||l.variants.push(t)}):("700"!==r&&t.includes("700")&&n.push("700"),e.push({family:s||"",variants:o(n),subsets:[],type:i.type}))}}}};export{i as getFontFromGroupSetting,l as getFontsFromDataBuilder};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t,Fragment as s}from"react/jsx-runtime";import{useI18n as
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as s}from"react/jsx-runtime";import{useI18n as a,PageProvider as r,BuilderComponentProvider as n,I18nProvider as l,SectionProvider as o,BuilderProvider as i,Render as p}from"@gem-sdk/core";import{NextSeo as c}from"next-seo";import m from"next/head";import{useRouter as d}from"next/router";import{useTrackingView as g}from"../libs/hooks/use-tracking-view.js";import{parseHtml as u}from"../libs/parse-html.js";import h from"../components/builder/Header.js";import f from"../components/FooterForPostPurchase.js";import y from"next/script";import{useEffect as _}from"react";import{usePageViewedTracking as b}from"../libs/hooks/usePageViewedTracking.js";let v=({components:v,builderData:k,sectionData:S,seo:x,themeStyle:P,fontStyle:N,elementFontStyle:T,customCodeHeader:j,shopToken:H,pageHandle:I,customFonts:L,isPostPurchase:M,shopName:$,productOffers:w,publicStoreFrontData:E,dynamicDiscountOffer:F,isPreview:q,interaction:A,pageBackground:O,sellingPlanSetting:z,buyerConsentPreCheck:C,id:D,shopID:U,domainTrackingIlp:B})=>{let R=d(),{t:V}=a(),G=process.env.NEXT_GP_BASE_ASSET_URL||"https://assets.gemcommerce.xyz";g(H,I,R.isFallback),b({id:D,shopID:U,domain:B});let J="custom-code-header";if(_(()=>{let e=document.querySelectorAll(`[class*="${J}-"]`),t=[];e.length>1&&e.forEach(e=>{let s=e.className;if(t.includes(s)){e.remove();return}t.push(s)})},[]),R.isFallback)return e("div",{className:"gp-flex gp-h-[100vh] gp-items-center gp-justify-center",children:t("div",{className:"gp-flex gp-gap-2",children:[e("span",{className:"gp-aspect-square gp-h-2 gp-animate-[flashing_500ms_infinite_alternate] gp-rounded-full gp-bg-slate-800"}),e("span",{className:"gp-aspect-square gp-h-2 gp-animate-[flashing_500ms_infinite_200ms_linear_alternate] gp-rounded-full gp-bg-slate-800"}),e("span",{className:"gp-aspect-square gp-h-2 gp-animate-[flashing_500ms_infinite_500ms_alternate] gp-rounded-full gp-bg-slate-800"})]})});let X=(A?.value||[]).length>0;return t(s,{children:[e(c,{...x}),t(m,{children:[u(J,j,!0),P&&e("style",{"data-id":"global-style",type:"text/css",dangerouslySetInnerHTML:{__html:P}},"global-style"),N&&e("style",{"data-id":"google-fonts",type:"text/css",dangerouslySetInnerHTML:{__html:N}},"google-fonts"),T&&T.map(t=>e("style",{"data-id":"google-element-fonts",type:"text/css",dangerouslySetInnerHTML:{__html:t}},t)),L&&e("style",{"data-id":"custom-element-fonts",type:"text/css",dangerouslySetInnerHTML:{__html:L}},N),O?.isUsePageBackground&&O?.background&&e("style",{children:`
|
|
2
2
|
body {
|
|
3
|
-
background: ${
|
|
3
|
+
background: ${O.background};
|
|
4
4
|
}
|
|
5
|
-
`},`page_background_${
|
|
5
|
+
`},`page_background_${O?.background}`)]}),e(r,{productOffers:w,publicStoreFrontData:E,dynamicDiscountOffer:F,sellingPlanMeta:z,buyerConsentChecked:C,children:e(n,{components:v,children:e(l,{t:V,children:t("div",{className:`${M?"gp-bg-white post-purchase-page":""} `,role:"main",children:[M&&e(h,{pageType:"POST_PURCHASE"}),X&&e("div",{dangerouslySetInnerHTML:{__html:`<div id="gp-interaction" style="display: none;">${JSON.stringify(A?.value||[])}</div>`}}),e(o,{data:S,children:k?.map(s=>t(i,{state:s.data,lazy:s.lazy,priority:s.priority,isPostPurchase:M,isPreview:q,children:[e(p,{uid:s.uid}),X&&e(y,{defer:!0,src:`${G}/assets-v2/gp-flow-action-lip-v7-5.js`})]},s.uid))}),M&&e(f,{shopName:$||""})]})})})})]})};export{v as StaticPageV2};
|
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.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.
|
|
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"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),r=require("next/head"),t=require("../libs/helpers/gen-fonts.js");exports.FontLink=({fontStyle:s,dataId:l})=>{let i=t.extractImportUrls(s),n=s.replace(/@import url\(['"]?[^'")\s]+['"]?\);?/g,"").trim();return e.jsxs(r,{children:[i.map(r=>e.jsx("link",{rel:"stylesheet",href:r},r)),n&&e.jsx("style",{"data-id":l,type:"text/css",dangerouslySetInnerHTML:{__html:n}})]})};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{jsxs as e,jsx as t}from"react/jsx-runtime";import r from"next/head";import{extractImportUrls as l}from"../libs/helpers/gen-fonts.js";let n=({fontStyle:n,dataId:s})=>{let i=l(n),m=n.replace(/@import url\(['"]?[^'")\s]+['"]?\);?/g,"").trim();return e(r,{children:[i.map(e=>t("link",{rel:"stylesheet",href:e},e)),m&&t("style",{"data-id":s,type:"text/css",dangerouslySetInnerHTML:{__html:m}})]})};export{n as FontLink};
|