@gem-sdk/components 3.0.0-pre-production.2 → 3.0.0-pre-production.6

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.
@@ -171,9 +171,17 @@ const HeroBanner = ({ builderAttrs, builderProps, setting, styles, style, childr
171
171
  top: isScale ? '0px' : 'unset'
172
172
  };
173
173
  };
174
- const getBgImageByDeviceOnly = (device)=>{
174
+ const getBgImageByScreen = (device)=>{
175
175
  if (!background) return '';
176
- return core.getBgImageByDevice(background, device, {
176
+ const backgroundByDevice = core.getResponsiveValueByScreen(background, device);
177
+ const gradientColor = backgroundByDevice?.color ? `, ${backgroundByDevice.color}` : '';
178
+ if (backgroundByDevice?.color?.includes(core.GRADIENT_BGR_KEY) && bgiEnableByDevice[device]) {
179
+ return `${index.getBgImageByDevice(background, device) || ''}${gradientColor}`;
180
+ }
181
+ if (backgroundByDevice?.color?.includes(core.GRADIENT_BGR_KEY) && !bgiEnableByDevice[device]) {
182
+ return `${backgroundByDevice.color}`;
183
+ }
184
+ return index.getBgImageByDevice(background, device, {
177
185
  ignoreBgAttachment: true
178
186
  });
179
187
  };
@@ -264,7 +272,6 @@ const HeroBanner = ({ builderAttrs, builderProps, setting, styles, style, childr
264
272
  ...background ? {
265
273
  ...core.getStyleBgColor(background)
266
274
  } : {},
267
- ...core.getGradientBgrStyleByDevice(background, bgiEnableByDevice),
268
275
  ...core.getStyleShadow({
269
276
  value: shadowBg,
270
277
  styleAppliedFor: 'box-shadow',
@@ -288,16 +295,16 @@ const HeroBanner = ({ builderAttrs, builderProps, setting, styles, style, childr
288
295
  }),
289
296
  style: {
290
297
  ...styleHeroBanner(),
298
+ ...core.makeStyleResponsive('bgi', {
299
+ desktop: getBgImageByScreen('desktop'),
300
+ tablet: getBgImageByScreen('tablet'),
301
+ mobile: getBgImageByScreen('mobile')
302
+ }),
291
303
  ...core.getStyleBackgroundByDevice(background, {
292
304
  ignoreBgAttachment: true,
293
305
  ignoreBackgroundImage: true,
294
306
  ignoreBackgroundColor: backgroundResponsive[currentDevice]?.type === 'video'
295
307
  }),
296
- ...core.makeStyleResponsive('bgi', {
297
- desktop: bgiEnableByDevice['desktop'] ? getBgImageByDeviceOnly('desktop') : 'url()',
298
- tablet: bgiEnableByDevice['tablet'] ? getBgImageByDeviceOnly('tablet') : 'url()',
299
- mobile: bgiEnableByDevice['mobile'] ? getBgImageByDeviceOnly('mobile') : 'url()'
300
- }),
301
308
  position: attachment === 'fixed' ? 'fixed' : 'absolute',
302
309
  '--duration': `${hoverEffectDuration ?? 0}s`,
303
310
  '--scale': hoverEffectScale ?? 1,
@@ -138,6 +138,20 @@ const HeroBanner = ({ builderAttrs, builderProps, setting, styles, style, childr
138
138
  mobile: helpers$1.createBlurDataURL(srcSet?.mobile?.width ?? srcSet?.tablet?.width ?? srcSet?.desktop?.width ?? 0, srcSet?.mobile?.height ?? srcSet?.tablet?.height ?? srcSet?.desktop?.width ?? 0)
139
139
  };
140
140
  const enableLazyLoad = !setting?.preload && pageContext?.enableLazyLoadImage;
141
+ const getBgImageByScreen = (device)=>{
142
+ if (!background) return '';
143
+ const backgroundByDevice = core.getResponsiveValueByScreen(background, device);
144
+ const imageUrl = enableLazyLoad ? `url(${imagePlaceholder[device]})` : `url(${getSrcSet.getImageSrc(core.getResponsiveValueByScreen(srcSet, device), device)})`;
145
+ const gradientColor = backgroundByDevice?.color ? `, ${backgroundByDevice?.color}` : '';
146
+ if (backgroundByDevice?.color?.includes(core.GRADIENT_BGR_KEY) && bgiEnableByDevice[device]) {
147
+ return `${imageUrl}${gradientColor}`;
148
+ }
149
+ if (backgroundByDevice?.color?.includes(core.GRADIENT_BGR_KEY) && !bgiEnableByDevice[device]) {
150
+ return `${backgroundByDevice?.color}`;
151
+ }
152
+ if (bgiEnableByDevice[device]) return imageUrl;
153
+ return 'url()';
154
+ };
141
155
  const renderInnerHeroBanner = ()=>{
142
156
  return core.template /* liquid */ `
143
157
  <div
@@ -162,7 +176,6 @@ const HeroBanner = ({ builderAttrs, builderProps, setting, styles, style, childr
162
176
  ...background ? {
163
177
  ...core.getStyleBgColor(background)
164
178
  } : {},
165
- ...core.getGradientBgrStyleByDevice(background, bgiEnableByDevice),
166
179
  ...core.getStyleShadow({
167
180
  value: shadowBg,
168
181
  styleAppliedFor: 'box-shadow',
@@ -208,16 +221,16 @@ const HeroBanner = ({ builderAttrs, builderProps, setting, styles, style, childr
208
221
  gp_lazybg: enableLazyLoad
209
222
  })}"
210
223
  style="${{
224
+ ...core.makeStyleResponsive('bgi', {
225
+ desktop: getBgImageByScreen('desktop'),
226
+ tablet: getBgImageByScreen('tablet'),
227
+ mobile: getBgImageByScreen('mobile')
228
+ }),
211
229
  ...core.getStyleBackgroundByDevice(background, {
212
230
  ignoreBgAttachment: true,
213
231
  ignoreBackgroundImage: true,
214
232
  liquid: true
215
233
  }),
216
- ...core.makeStyleResponsive('bgi', {
217
- desktop: `url('${bgiEnableByDevice['desktop'] ? !enableLazyLoad ? getSrcSet.getImageSrc(core.getResponsiveValueByScreen(srcSet, 'desktop'), 'desktop') : imagePlaceholder['desktop'] : ''}')`,
218
- tablet: `url('${bgiEnableByDevice['tablet'] ? !enableLazyLoad ? getSrcSet.getImageSrc(core.getResponsiveValueByScreen(srcSet, 'tablet'), 'tablet') : imagePlaceholder['tablet'] : ''}')`,
219
- mobile: `url('${bgiEnableByDevice['mobile'] ? !enableLazyLoad ? getSrcSet.getImageSrc(core.getResponsiveValueByScreen(srcSet, 'mobile'), 'mobile') : imagePlaceholder['mobile'] : ''}')`
220
- }),
221
234
  '--duration': `${hoverEffectDuration ?? 0}s`,
222
235
  '--scale': hoverEffectScale ?? 1,
223
236
  ...core.makeStyleResponsive('pos', getAttachmentDevice()),
@@ -106,7 +106,36 @@ const getClipPath = (borderWidth, borderRadius)=>{
106
106
  const bl = calcRounderClipPath(parseInt(bblr ?? '0'), bbw, blw);
107
107
  return `inset(0 0 0 round ${tl}px ${tr}px ${br}px ${bl}px)`;
108
108
  };
109
+ const getBgImageByDevice = (background, device, options)=>{
110
+ const backgroundByDevice = core.getResponsiveValueByScreen(background, device);
111
+ const isBgVideo = backgroundByDevice?.type === 'video';
112
+ if (isBgVideo) return;
113
+ if (backgroundByDevice?.type === 'color') return 'url()'; // To prevent overriding background image from upper device
114
+ const backupFileKey = backgroundByDevice?.image?.backupFileKey;
115
+ const storage = backgroundByDevice?.image?.storage;
116
+ let imageByDevice = backgroundByDevice?.image?.src;
117
+ let newBackupFilekey = backupFileKey;
118
+ const shopifyHandleName = imageByDevice?.match(// eslint-disable-next-line
119
+ /\/files\/([^\/]+\.(jpg|jpeg|gif|png|webp|svg))/)?.[1];
120
+ if (backupFileKey && shopifyHandleName && shopifyHandleName != backupFileKey) {
121
+ newBackupFilekey = shopifyHandleName;
122
+ }
123
+ if (storage === 'FILE_CONTENT') {
124
+ if (options?.liquid && newBackupFilekey) {
125
+ imageByDevice = `{{ "${newBackupFilekey.replace('.jpeg', '.jpg')}" | file_url }}`;
126
+ }
127
+ }
128
+ if (storage === 'THEME' || !storage) {
129
+ if (options?.liquid && newBackupFilekey) {
130
+ imageByDevice = `{{ "${newBackupFilekey}" | asset_url }}`;
131
+ }
132
+ }
133
+ if (typeof imageByDevice === 'string') {
134
+ return `url(${imageByDevice})`;
135
+ }
136
+ };
109
137
 
138
+ exports.getBgImageByDevice = getBgImageByDevice;
110
139
  exports.getClipPath = getClipPath;
111
140
  exports.getPercentageVisible = getPercentageVisible;
112
141
  exports.getStyleHeroBannerBg = getStyleHeroBannerBg;
@@ -1,5 +1,5 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { useEditorMode, useCurrentDevice, makeStyleResponsive, getHeightByShapeGlobalSize, makeStyleWithDefault, getWidthByShapeGlobalSize, getPaddingGlobalSize, getResponsiveValueByScreen, cls, makeStyle, getSingleColorVariable, getRadiusStyleActiveState, getStyleBgColor, getGradientBgrStyleByDevice, getStyleShadow, getStyleBackgroundByDevice, getGlobalColorStateClass, getGlobalColorStateStyle, makeStyleState, filterToolbarPreview, getAspectRatioGlobalSize, getBgImageByDevice } from '@gem-sdk/core';
2
+ import { useEditorMode, useCurrentDevice, makeStyleResponsive, getHeightByShapeGlobalSize, makeStyleWithDefault, getWidthByShapeGlobalSize, getPaddingGlobalSize, getResponsiveValueByScreen, cls, makeStyle, getSingleColorVariable, getRadiusStyleActiveState, getStyleBgColor, getStyleShadow, getStyleBackgroundByDevice, getGlobalColorStateClass, getGlobalColorStateStyle, makeStyleState, filterToolbarPreview, getAspectRatioGlobalSize, GRADIENT_BGR_KEY } from '@gem-sdk/core';
3
3
  import { useMemo, useRef, useState, useEffect, useCallback } from 'react';
4
4
  import Row from '../../../grid/components/Row.js';
5
5
  import Link from '../../../link/components/Link.js';
@@ -12,7 +12,7 @@ import HTML5Embed from '../../../video/components/HTML5Embed.js';
12
12
  import useIntersectionObserver from './hooks/useIntersectionObserver.js';
13
13
  import AnimationManager from './parallax/AnimationManager.js';
14
14
  import { useTranslateValue } from './hooks/useTranslateValue.js';
15
- import { getClipPath, isScaleImage } from './utils/index.js';
15
+ import { getClipPath, getBgImageByDevice, isScaleImage } from './utils/index.js';
16
16
  import useAspectRatioSettings from './hooks/useAspectRatioSettings.js';
17
17
  import { createBlurDataURL } from '../../../image/components/helpers.js';
18
18
 
@@ -167,8 +167,16 @@ const HeroBanner = ({ builderAttrs, builderProps, setting, styles, style, childr
167
167
  top: isScale ? '0px' : 'unset'
168
168
  };
169
169
  };
170
- const getBgImageByDeviceOnly = (device)=>{
170
+ const getBgImageByScreen = (device)=>{
171
171
  if (!background) return '';
172
+ const backgroundByDevice = getResponsiveValueByScreen(background, device);
173
+ const gradientColor = backgroundByDevice?.color ? `, ${backgroundByDevice.color}` : '';
174
+ if (backgroundByDevice?.color?.includes(GRADIENT_BGR_KEY) && bgiEnableByDevice[device]) {
175
+ return `${getBgImageByDevice(background, device) || ''}${gradientColor}`;
176
+ }
177
+ if (backgroundByDevice?.color?.includes(GRADIENT_BGR_KEY) && !bgiEnableByDevice[device]) {
178
+ return `${backgroundByDevice.color}`;
179
+ }
172
180
  return getBgImageByDevice(background, device, {
173
181
  ignoreBgAttachment: true
174
182
  });
@@ -260,7 +268,6 @@ const HeroBanner = ({ builderAttrs, builderProps, setting, styles, style, childr
260
268
  ...background ? {
261
269
  ...getStyleBgColor(background)
262
270
  } : {},
263
- ...getGradientBgrStyleByDevice(background, bgiEnableByDevice),
264
271
  ...getStyleShadow({
265
272
  value: shadowBg,
266
273
  styleAppliedFor: 'box-shadow',
@@ -284,16 +291,16 @@ const HeroBanner = ({ builderAttrs, builderProps, setting, styles, style, childr
284
291
  }),
285
292
  style: {
286
293
  ...styleHeroBanner(),
294
+ ...makeStyleResponsive('bgi', {
295
+ desktop: getBgImageByScreen('desktop'),
296
+ tablet: getBgImageByScreen('tablet'),
297
+ mobile: getBgImageByScreen('mobile')
298
+ }),
287
299
  ...getStyleBackgroundByDevice(background, {
288
300
  ignoreBgAttachment: true,
289
301
  ignoreBackgroundImage: true,
290
302
  ignoreBackgroundColor: backgroundResponsive[currentDevice]?.type === 'video'
291
303
  }),
292
- ...makeStyleResponsive('bgi', {
293
- desktop: bgiEnableByDevice['desktop'] ? getBgImageByDeviceOnly('desktop') : 'url()',
294
- tablet: bgiEnableByDevice['tablet'] ? getBgImageByDeviceOnly('tablet') : 'url()',
295
- mobile: bgiEnableByDevice['mobile'] ? getBgImageByDeviceOnly('mobile') : 'url()'
296
- }),
297
304
  position: attachment === 'fixed' ? 'fixed' : 'absolute',
298
305
  '--duration': `${hoverEffectDuration ?? 0}s`,
299
306
  '--scale': hoverEffectScale ?? 1,
@@ -1,4 +1,4 @@
1
- import { makeStyleResponsive, getHeightByShapeGlobalSize, makeStyleWithDefault, getWidthByShapeGlobalSize, getPaddingGlobalSize, removeUndefinedValuesFromObject, template, cls, dataStringify, RenderIf, isLocalEnv, baseAssetURL, getResponsiveValueByScreen, makeStyle, getSingleColorVariable, getRadiusStyleActiveState, getStyleBgColor, getGradientBgrStyleByDevice, getStyleShadow, getAspectRatioGlobalSize, getStyleBackgroundByDevice, getGlobalColorStateClass, getGlobalColorStateStyle, makeStyleState } from '@gem-sdk/core';
1
+ import { makeStyleResponsive, getHeightByShapeGlobalSize, makeStyleWithDefault, getWidthByShapeGlobalSize, getPaddingGlobalSize, removeUndefinedValuesFromObject, template, cls, dataStringify, RenderIf, isLocalEnv, baseAssetURL, getResponsiveValueByScreen, makeStyle, getSingleColorVariable, getRadiusStyleActiveState, getStyleBgColor, getStyleShadow, getAspectRatioGlobalSize, getStyleBackgroundByDevice, getGlobalColorStateClass, getGlobalColorStateStyle, makeStyleState, GRADIENT_BGR_KEY } from '@gem-sdk/core';
2
2
  import Row from '../../../grid/components/Row.liquid.js';
3
3
  import AdaptiveImage from '../../../image/components/AdaptiveImage.liquid.js';
4
4
  import { getVisibilityStyle, getMarginStyle, getStyleAspectRatioHeroBannerCustom, removeMarginStyle, getContentPosition, mapContentPositionToHorizontal, getClassJustify, getResponsiveSetting, getClassContentPosition, getDisplayStyleByFitContent, fallBackImg, getClassForContentByFitContent, getClassForStretchContent, getClassSpaceBetween, getWidth, getBgImage } from '../../helpers/common.js';
@@ -7,7 +7,7 @@ import HTML5Embed from '../../../video/components/HTML5Embed.liquid.js';
7
7
  import { getClipPath, getStyleHeroBannerBg } from './utils/index.js';
8
8
  import useAspectRatioSettings from './hooks/useAspectRatioSettings.js';
9
9
  import NextImage from '../../../image/components/NextImage.liquid.js';
10
- import { getImageSrc, DEVICES } from '../../../image/helpers/getSrcSet.js';
10
+ import { DEVICES, getImageSrc } from '../../../image/helpers/getSrcSet.js';
11
11
  import { createBlurDataURL } from '../../../image/components/helpers.js';
12
12
 
13
13
  const HeroBanner = ({ builderAttrs, builderProps, setting, styles, style, children, rawChildren, advanced, pageContext })=>{
@@ -134,6 +134,20 @@ const HeroBanner = ({ builderAttrs, builderProps, setting, styles, style, childr
134
134
  mobile: createBlurDataURL(srcSet?.mobile?.width ?? srcSet?.tablet?.width ?? srcSet?.desktop?.width ?? 0, srcSet?.mobile?.height ?? srcSet?.tablet?.height ?? srcSet?.desktop?.width ?? 0)
135
135
  };
136
136
  const enableLazyLoad = !setting?.preload && pageContext?.enableLazyLoadImage;
137
+ const getBgImageByScreen = (device)=>{
138
+ if (!background) return '';
139
+ const backgroundByDevice = getResponsiveValueByScreen(background, device);
140
+ const imageUrl = enableLazyLoad ? `url(${imagePlaceholder[device]})` : `url(${getImageSrc(getResponsiveValueByScreen(srcSet, device), device)})`;
141
+ const gradientColor = backgroundByDevice?.color ? `, ${backgroundByDevice?.color}` : '';
142
+ if (backgroundByDevice?.color?.includes(GRADIENT_BGR_KEY) && bgiEnableByDevice[device]) {
143
+ return `${imageUrl}${gradientColor}`;
144
+ }
145
+ if (backgroundByDevice?.color?.includes(GRADIENT_BGR_KEY) && !bgiEnableByDevice[device]) {
146
+ return `${backgroundByDevice?.color}`;
147
+ }
148
+ if (bgiEnableByDevice[device]) return imageUrl;
149
+ return 'url()';
150
+ };
137
151
  const renderInnerHeroBanner = ()=>{
138
152
  return template /* liquid */ `
139
153
  <div
@@ -158,7 +172,6 @@ const HeroBanner = ({ builderAttrs, builderProps, setting, styles, style, childr
158
172
  ...background ? {
159
173
  ...getStyleBgColor(background)
160
174
  } : {},
161
- ...getGradientBgrStyleByDevice(background, bgiEnableByDevice),
162
175
  ...getStyleShadow({
163
176
  value: shadowBg,
164
177
  styleAppliedFor: 'box-shadow',
@@ -204,16 +217,16 @@ const HeroBanner = ({ builderAttrs, builderProps, setting, styles, style, childr
204
217
  gp_lazybg: enableLazyLoad
205
218
  })}"
206
219
  style="${{
220
+ ...makeStyleResponsive('bgi', {
221
+ desktop: getBgImageByScreen('desktop'),
222
+ tablet: getBgImageByScreen('tablet'),
223
+ mobile: getBgImageByScreen('mobile')
224
+ }),
207
225
  ...getStyleBackgroundByDevice(background, {
208
226
  ignoreBgAttachment: true,
209
227
  ignoreBackgroundImage: true,
210
228
  liquid: true
211
229
  }),
212
- ...makeStyleResponsive('bgi', {
213
- desktop: `url('${bgiEnableByDevice['desktop'] ? !enableLazyLoad ? getImageSrc(getResponsiveValueByScreen(srcSet, 'desktop'), 'desktop') : imagePlaceholder['desktop'] : ''}')`,
214
- tablet: `url('${bgiEnableByDevice['tablet'] ? !enableLazyLoad ? getImageSrc(getResponsiveValueByScreen(srcSet, 'tablet'), 'tablet') : imagePlaceholder['tablet'] : ''}')`,
215
- mobile: `url('${bgiEnableByDevice['mobile'] ? !enableLazyLoad ? getImageSrc(getResponsiveValueByScreen(srcSet, 'mobile'), 'mobile') : imagePlaceholder['mobile'] : ''}')`
216
- }),
217
230
  '--duration': `${hoverEffectDuration ?? 0}s`,
218
231
  '--scale': hoverEffectScale ?? 1,
219
232
  ...makeStyleResponsive('pos', getAttachmentDevice()),
@@ -1,4 +1,4 @@
1
- import { makeStyleResponsive } from '@gem-sdk/core';
1
+ import { getResponsiveValueByScreen, makeStyleResponsive } from '@gem-sdk/core';
2
2
 
3
3
  const getPercentageVisible = (boundingClientRect, windowHeight)=>{
4
4
  const { top, height } = boundingClientRect;
@@ -104,5 +104,33 @@ const getClipPath = (borderWidth, borderRadius)=>{
104
104
  const bl = calcRounderClipPath(parseInt(bblr ?? '0'), bbw, blw);
105
105
  return `inset(0 0 0 round ${tl}px ${tr}px ${br}px ${bl}px)`;
106
106
  };
107
+ const getBgImageByDevice = (background, device, options)=>{
108
+ const backgroundByDevice = getResponsiveValueByScreen(background, device);
109
+ const isBgVideo = backgroundByDevice?.type === 'video';
110
+ if (isBgVideo) return;
111
+ if (backgroundByDevice?.type === 'color') return 'url()'; // To prevent overriding background image from upper device
112
+ const backupFileKey = backgroundByDevice?.image?.backupFileKey;
113
+ const storage = backgroundByDevice?.image?.storage;
114
+ let imageByDevice = backgroundByDevice?.image?.src;
115
+ let newBackupFilekey = backupFileKey;
116
+ const shopifyHandleName = imageByDevice?.match(// eslint-disable-next-line
117
+ /\/files\/([^\/]+\.(jpg|jpeg|gif|png|webp|svg))/)?.[1];
118
+ if (backupFileKey && shopifyHandleName && shopifyHandleName != backupFileKey) {
119
+ newBackupFilekey = shopifyHandleName;
120
+ }
121
+ if (storage === 'FILE_CONTENT') {
122
+ if (options?.liquid && newBackupFilekey) {
123
+ imageByDevice = `{{ "${newBackupFilekey.replace('.jpeg', '.jpg')}" | file_url }}`;
124
+ }
125
+ }
126
+ if (storage === 'THEME' || !storage) {
127
+ if (options?.liquid && newBackupFilekey) {
128
+ imageByDevice = `{{ "${newBackupFilekey}" | asset_url }}`;
129
+ }
130
+ }
131
+ if (typeof imageByDevice === 'string') {
132
+ return `url(${imageByDevice})`;
133
+ }
134
+ };
107
135
 
108
- export { getClipPath, getPercentageVisible, getStyleHeroBannerBg, isScaleImage };
136
+ export { getBgImageByDevice, getClipPath, getPercentageVisible, getStyleHeroBannerBg, isScaleImage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/components",
3
- "version": "3.0.0-pre-production.2",
3
+ "version": "3.0.0-pre-production.6",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",
@@ -21,7 +21,7 @@
21
21
  "format": "prettier --write \"./src/**/*.{ts,tsx}\""
22
22
  },
23
23
  "devDependencies": {
24
- "@gem-sdk/core": "3.0.0-pre-production.1",
24
+ "@gem-sdk/core": "3.0.0-pre-production.6",
25
25
  "@gem-sdk/styles": "3.0.0-pre-production.1",
26
26
  "@types/react-transition-group": "^4.4.5"
27
27
  },