@gxpl/sdk 0.0.28 → 0.0.29

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.
@@ -401,6 +401,7 @@ export declare const ProjectSchema: z.ZodObject<{
401
401
  google: string;
402
402
  adobe: string;
403
403
  }>;
404
+ scenesAssets: z.ZodArray<z.ZodString, "many">;
404
405
  relations: z.ZodArray<z.ZodObject<{
405
406
  from: z.ZodString;
406
407
  to: z.ZodString;
@@ -1038,6 +1039,7 @@ export declare const ProjectSchema: z.ZodObject<{
1038
1039
  google: string;
1039
1040
  adobe: string;
1040
1041
  };
1042
+ scenesAssets: string[];
1041
1043
  relations: {
1042
1044
  type: "slide" | "fade";
1043
1045
  direction: "north" | "east" | "south" | "west";
@@ -1185,6 +1187,7 @@ export declare const ProjectSchema: z.ZodObject<{
1185
1187
  google: string;
1186
1188
  adobe: string;
1187
1189
  };
1190
+ scenesAssets: string[];
1188
1191
  relations: {
1189
1192
  type: "slide" | "fade";
1190
1193
  direction: "north" | "east" | "south" | "west";
@@ -59,6 +59,7 @@ exports.ProjectSchema = zod_1.z.object({
59
59
  }))
60
60
  }))
61
61
  }),
62
+ scenesAssets: zod_1.z.array(zod_1.z.string()),
62
63
  relations: zod_1.z.array(zod_1.z.object({
63
64
  from: zod_1.z.string().min(1),
64
65
  to: zod_1.z.string().min(1),
@@ -16,6 +16,7 @@ export interface Project {
16
16
  pages: Page[];
17
17
  fonts: Fonts;
18
18
  relations: Relation[];
19
+ scenesAssets: string[];
19
20
  foreground: TFixedLayer;
20
21
  background: TFixedLayer;
21
22
  }
@@ -10,13 +10,15 @@ const Head_1 = require("./Head");
10
10
  const TransitionMachineContext_1 = require("../provider/TransitionMachineContext");
11
11
  const Scenes_1 = require("./Scenes/Scenes");
12
12
  const FixedLayer_1 = require("./fixedLayers/FixedLayer");
13
+ const usePrelaodAssets_1 = require("../utils/usePrelaodAssets");
13
14
  const Page = ({ project, articlesData }) => {
14
15
  var _a, _b;
15
16
  const afterBodyOpen = (0, html_react_parser_1.default)(project.html.afterBodyOpen);
16
17
  const beforeBodyClose = (0, html_react_parser_1.default)(project.html.beforeBodyClose);
17
18
  const startScene = (_b = (_a = project.pages.find(page => page.isStartScene)) === null || _a === void 0 ? void 0 : _a.articleId) !== null && _b !== void 0 ? _b : Object.keys(articlesData)[0];
18
19
  const scenes = Object.values(articlesData).map(({ article }) => ({ id: article.id }));
19
- const { relations } = project;
20
+ const { relations, scenesAssets } = project;
21
+ (0, usePrelaodAssets_1.usePreloadAssets)(scenesAssets);
20
22
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Head_1.CNTRLHead, { project: project }), afterBodyOpen, (0, jsx_runtime_1.jsxs)(TransitionMachineContext_1.TransitionMachineContext.Provider, { options: {
21
23
  input: {
22
24
  startScene,
@@ -0,0 +1 @@
1
+ export declare function usePreloadAssets(assets: string[]): void;
@@ -0,0 +1,38 @@
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(asset => {
18
+ if (isVideoAsset(asset)) {
19
+ const video = document.createElement('video');
20
+ video.src = asset;
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(asset)) {
33
+ const img = new Image();
34
+ img.src = asset;
35
+ }
36
+ });
37
+ }, [assets]);
38
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gxpl/sdk",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "description": "Generic SDK for use in public websites.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",