@gudhub/ssg-web-components-library 1.0.122 → 1.0.124

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/ssg-web-components-library",
3
- "version": "1.0.122",
3
+ "version": "1.0.124",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -183,7 +183,11 @@ class ImageComponent extends GHComponent {
183
183
  const fallbackSrc = this.getAttribute('src');
184
184
  const dataMaxWidth = parseInt(this.getAttribute('data-max-width'), 10);
185
185
 
186
- const src = this.normalizeUrlPath(dataSrc && dataUrl ? dataSrc : fallbackSrc);
186
+ const rawSrc = this.normalizedSrc
187
+ || imageFromPicture.getAttribute('data-src')
188
+ || this.getAttribute('src');
189
+
190
+ const src = this.normalizeUrlPath(rawSrc);
187
191
  if (!src) {
188
192
  console.warn('No valid image source found.');
189
193
  return;
@@ -76,12 +76,12 @@ class MasonryGallery extends GHComponent {
76
76
  'masonry-images'
77
77
  );
78
78
 
79
- const isInitImagesEqualNull =
80
- this.getAttribute('init-count') === 'null';
79
+ const initCountFromJson = Number(this.getAttribute('init-count'));
81
80
 
82
- const initCountImages = this.contactUsButton
83
- ? this.showCount
84
- : images.length;
81
+ const initCountImages =
82
+ initCountFromJson > 0
83
+ ? initCountFromJson
84
+ : (this.showCount || 10);
85
85
 
86
86
  const initImages = images.slice(0, initCountImages);
87
87
  const initMoreImages = images.slice(initCountImages);
@@ -208,68 +208,73 @@ class MasonryGallery extends GHComponent {
208
208
  const msnry = this.msnry;
209
209
 
210
210
  const promise = new Promise(async (res, rej) => {
211
- const img = document.createElement('img');
212
-
213
- const fileName = imageSrc.split('/').pop();
214
-
215
- const pathToJpg = `/assets/images/masonry/${fileName}`;
216
- const pathToWebp = `${pathToJpg}.webp`;
217
-
218
- const response = await fetch(pathToWebp, {
219
- method: 'HEAD'
220
- });
211
+ try {
212
+ const img = document.createElement('img');
213
+
214
+ const fileName = imageSrc.split('/').pop();
215
+
216
+ let finalSrc = `/assets/images/masonry/${fileName}`;
217
+
218
+ try {
219
+ const uploadResponse = await fetch('/upload-image-path', {
220
+ method: 'POST',
221
+ headers: {
222
+ 'Content-Type': 'application/json'
223
+ },
224
+ body: JSON.stringify({
225
+ imageSrc: finalSrc,
226
+ imageUrl: imageSrc,
227
+ isCrop: true
228
+ })
229
+ });
230
+
231
+ const uploadData = await uploadResponse.json();
232
+
233
+ if (uploadData?.normalizedSrc) {
234
+ finalSrc = uploadData.normalizedSrc;
235
+ }
236
+ } catch (error) {
237
+ console.error('upload-image-path error:', error);
238
+ }
221
239
 
222
- if (!response.ok) {
223
- await fetch('/upload-image-path', {
224
- method: 'POST',
225
- headers: {
226
- 'Content-Type': 'application/json'
227
- },
228
- body: JSON.stringify({
229
- imageSrc: pathToJpg,
230
- imageUrl: imageSrc,
231
- isCrop: true
232
- })
233
- });
234
- }
240
+ img.src = finalSrc;
235
241
 
236
- img.src = `/assets/images/masonry/${fileName}`;
242
+ img.setAttribute('src', finalSrc);
243
+ img.setAttribute('alt', imageAlt);
244
+ img.setAttribute('title', imageTitle);
237
245
 
238
- img.setAttribute(
239
- 'src',
240
- `/assets/images/masonry/${fileName}`
241
- );
242
- img.setAttribute('alt', imageAlt);
243
- img.setAttribute('title', imageTitle);
246
+ if (fullImageSrc) {
247
+ const tempoFullImageSrc = await this.temporaryImage(fullImageSrc);
244
248
 
245
- if (fullImageSrc) {
246
- const tempoFullImageSrc = await this.temporaryImage(fullImageSrc);
249
+ img.classList.add('open-modal');
250
+ img.setAttribute('data-modal-image', tempoFullImageSrc);
251
+ }
247
252
 
248
- img.classList.add('open-modal');
249
- img.setAttribute('data-modal-image', tempoFullImageSrc);
253
+ img.setAttribute('data-image-loading', 'true');
254
+
255
+ // Set image wrapper size while the image is loading
256
+ const interval = setInterval(() => {
257
+ if (img.width !== 0) {
258
+ img.style.width = `${img.naturalWidth}px`;
259
+ img.style.height = `${img.naturalHeight}px`;
260
+ clearInterval(interval);
261
+ res(imageWrapper);
262
+ }
263
+ }, 10);
264
+
265
+ // Create image wrapper and append the image to it
266
+ const imageWrapper = document.createElement('div');
267
+ imageWrapper.classList.add('masonry-grid-item')
268
+ // img.onload = () => {
269
+ img.removeAttribute('data-image-loading');
270
+ // }
271
+ imageWrapper.appendChild(img);
272
+ this.imagesContainer.appendChild(imageWrapper);
273
+ } catch (error) {
274
+ console.error(error);
275
+ rej(error);
250
276
  }
251
-
252
- img.setAttribute('data-image-loading', 'true');
253
-
254
- // Set image wrapper size while the image is loading
255
- const interval = setInterval(() => {
256
- if (img.width !== 0) {
257
- img.style.width = `${img.naturalWidth}px`;
258
- img.style.height = `${img.naturalHeight}px`;
259
- clearInterval(interval);
260
- res(imageWrapper);
261
- }
262
- }, 10);
263
-
264
- // Create image wrapper and append the image to it
265
- const imageWrapper = document.createElement('div');
266
- imageWrapper.classList.add('masonry-grid-item')
267
- // img.onload = () => {
268
- img.removeAttribute('data-image-loading');
269
- // }
270
- imageWrapper.appendChild(img);
271
- this.imagesContainer.appendChild(imageWrapper);
272
- });
277
+ });
273
278
 
274
279
  // After image is loaded, append it to Masonry layout and re-layout the grid
275
280
  promise.then((img) => {