@arraypress/effects-astro 0.1.0 → 0.1.1

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
@@ -173,7 +173,7 @@ The package's main entry is the runtime the components are built on, for use wit
173
173
 
174
174
  ## Demo
175
175
 
176
- `demo/` is an Astro site: one gallery of every effect as a working hero, each ShaderBackground and Paper shader on its own, shown one at a time with its own URL (`/#liquid-metal`), filters by type (backgrounds, logos, wordmarks, text, surfaces; `/?type=logos`), arrows and ← → keys to step through them, and a Customise panel to set each one up and copy the line:
176
+ `demo/` is live at [effects.lumithemes.com](https://effects.lumithemes.com). It is an Astro site: one gallery of every effect as a working hero, each ShaderBackground and Paper shader on its own, shown one at a time with its own URL (`/#liquid-metal`), filters by type (backgrounds, logos, wordmarks, text, surfaces; `/?type=logos`), arrows and ← → keys to step through them, and a Customise panel to set each one up and copy the line:
177
177
 
178
178
  ```bash
179
179
  cd demo && npm install && npm run dev # http://127.0.0.1:4400
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arraypress/effects-astro",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "GPU effects for Astro sites, as components: liquid light with a real fluid under it, ink in water, and outline text a spotlight fills. Plain WebGL, no dependencies, with the fallbacks a theme needs (reduced motion, no WebGL, touch screens, off-screen pausing).",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -134,6 +134,22 @@ async function silhouette(src) {
134
134
  return canvas.toDataURL();
135
135
  }
136
136
 
137
+ /**
138
+ * Reads a Blob as a data: URL.
139
+ *
140
+ * @param {Blob} blob The blob (a prepared picture).
141
+ * @returns {Promise<string>} Its contents as a data: URL.
142
+ * @throws {DOMException} When the blob cannot be read.
143
+ */
144
+ function dataUrl(blob) {
145
+ return new Promise((resolve, reject) => {
146
+ const reader = new FileReader();
147
+ reader.onload = () => resolve(String(reader.result));
148
+ reader.onerror = () => reject(reader.error);
149
+ reader.readAsDataURL(blob);
150
+ });
151
+ }
152
+
137
153
  /**
138
154
  * A picture made from colours: a linear gradient, square.
139
155
  *
@@ -203,7 +219,9 @@ async function start(el, config) {
203
219
  if (SILHOUETTE.has(config.shader)) src = await silhouette(src);
204
220
  const result = await module[prepare](src);
205
221
  // The helpers name their result differently: `pngBlob` (liquid metal, gem smoke) or `blob` (heatmap).
206
- src = URL.createObjectURL(result.pngBlob ?? result.blob);
222
+ // Read as a data: URL, not a blob: one, so it loads under a CSP that allows data: images
223
+ // but not blob: (a common default), and there is no object URL left to revoke.
224
+ src = await dataUrl(result.pngBlob ?? result.blob);
207
225
  }
208
226
  if (src) pictures.u_image = await loadImage(src);
209
227
  else if (config.gradient?.length) pictures.u_image = await gradientImage(config.gradient, config.gradientAngle ?? 135);