@gxpl/sdk 0.0.37 → 0.0.38

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": "@gxpl/sdk",
3
- "version": "0.0.37",
3
+ "version": "0.0.38",
4
4
  "description": "Generic SDK for use in public websites.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -1,4 +0,0 @@
1
- export declare function usePreloadAssets(assets: {
2
- url: string;
3
- id: string;
4
- }[]): void;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usePreloadAssets = usePreloadAssets;
4
- const react_1 = require("react");
5
- function isVideoAsset(url) {
6
- const videoExtensions = ['.mp4', '.mov', '.webm'];
7
- const lowerUrl = url.toLowerCase();
8
- return videoExtensions.some(ext => lowerUrl.endsWith(ext));
9
- }
10
- function isImageAsset(url) {
11
- const imageExtensions = ['.gif', '.png', '.jpg', '.jpeg', '.webp', '.avif', '.svg'];
12
- const lowerUrl = url.toLowerCase();
13
- return imageExtensions.some(ext => lowerUrl.endsWith(ext));
14
- }
15
- function usePreloadAssets(assets) {
16
- (0, react_1.useEffect)(() => {
17
- assets.forEach(({ url, id }) => {
18
- if (isVideoAsset(url)) {
19
- const video = document.createElement('video');
20
- video.src = url;
21
- video.preload = 'auto';
22
- video.style.display = 'none';
23
- document.body.appendChild(video);
24
- video.addEventListener('loadeddata', () => {
25
- setTimeout(() => {
26
- if (video.parentNode) {
27
- video.parentNode.removeChild(video);
28
- }
29
- }, 1000);
30
- });
31
- }
32
- if (isImageAsset(url)) {
33
- const img = new Image();
34
- img.src = url;
35
- }
36
- });
37
- }, [assets]);
38
- }