@datocms/astro 0.3.4 → 0.3.5

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/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  👉 [Visit the DatoCMS homepage](https://www.datocms.com) or see [What is DatoCMS?](#what-is-datocms)
6
6
 
7
+ ---
8
+
7
9
  <!--datocms-autoinclude-header end-->
8
10
 
9
11
  # @datocms/astro
@@ -38,6 +40,8 @@ npm install @datocms/astro
38
40
 
39
41
  <!--datocms-autoinclude-footer start-->
40
42
 
43
+ ---
44
+
41
45
  # What is DatoCMS?
42
46
 
43
47
  <a href="https://www.datocms.com/"><img src="https://www.datocms.com/images/full_logo.svg" height="60"></a>
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@datocms/astro",
3
3
  "description": "A set of components and utilities to work faster with DatoCMS in Astro projects.",
4
4
  "type": "module",
5
- "version": "0.3.4",
5
+ "version": "0.3.5",
6
6
  "sideEffects": false,
7
7
  "repository": {
8
8
  "type": "git",
@@ -41,7 +41,7 @@ const sizingStyle = {
41
41
  };
42
42
  ---
43
43
 
44
- <picture class={pictureClass} style={pictureStyle}>
44
+ <picture class={pictureClass} style={pictureStyle} data-datocms-image="true">
45
45
  {
46
46
  data.webpSrcSet && (
47
47
  <source srcset={data.webpSrcSet} sizes={sizes ?? data.sizes ?? null} type="image/webp" />
@@ -70,3 +70,33 @@ const sizingStyle = {
70
70
  )
71
71
  }
72
72
  </picture>
73
+
74
+ <script>
75
+ function removeBackgroundStyles(element: HTMLElement) {
76
+ element.style.backgroundColor = '';
77
+ element.style.backgroundImage = '';
78
+ }
79
+
80
+ function setup() {
81
+ for (const pictureEl of [...document.querySelectorAll('picture[data-datocms-image=true]')]) {
82
+ const imgEl = pictureEl.querySelector('img');
83
+
84
+ if (!imgEl) {
85
+ return;
86
+ }
87
+
88
+ if (imgEl.complete) {
89
+ removeBackgroundStyles(imgEl);
90
+ } else {
91
+ imgEl.addEventListener('load', () => removeBackgroundStyles(imgEl));
92
+ }
93
+ }
94
+ }
95
+
96
+ document.addEventListener('DOMContentLoaded', setup);
97
+ document.addEventListener('astro:page-load', setup);
98
+
99
+ if (document.readyState === 'complete') {
100
+ setup();
101
+ }
102
+ </script>