@funnelsgrove/runtime 0.7.9 → 0.7.10

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/dist/index.d.ts CHANGED
@@ -28,6 +28,7 @@ export * from './runtime/published-runtime-resolution.js';
28
28
  export * from './runtime/route-resolver.js';
29
29
  export * from './runtime/submit-email-capture.js';
30
30
  export * from './runtime/subscription-handoff.js';
31
+ export * from './runtime/step-asset-preloader.js';
31
32
  export * from './runtime/url-user-attributes.js';
32
33
  export * from './runtime/use-url-user-attributes-sync.js';
33
34
  export * from './services/api.service.js';
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ export * from './runtime/published-runtime-resolution.js';
29
29
  export * from './runtime/route-resolver.js';
30
30
  export * from './runtime/submit-email-capture.js';
31
31
  export * from './runtime/subscription-handoff.js';
32
+ export * from './runtime/step-asset-preloader.js';
32
33
  export * from './runtime/url-user-attributes.js';
33
34
  export * from './runtime/use-url-user-attributes-sync.js';
34
35
  // Browser-safe services.
@@ -0,0 +1,8 @@
1
+ import type { FunnelManifest } from '../config/funnel.manifest.types.js';
2
+ export type StepImagePreload = {
3
+ src: string;
4
+ width?: number;
5
+ height?: number;
6
+ };
7
+ export declare const resolveNextStepImagePreloads: (manifest: FunnelManifest, currentStepId: string) => StepImagePreload[];
8
+ export declare const scheduleNextStepImagePreload: (manifest: FunnelManifest, currentStepId: string) => (() => void);
@@ -0,0 +1,44 @@
1
+ const normalizeIdleImageAsset = (asset) => {
2
+ if (!asset || typeof asset === 'string' || asset.preload !== 'idle') {
3
+ return null;
4
+ }
5
+ return {
6
+ src: asset.src,
7
+ width: asset.width,
8
+ height: asset.height,
9
+ };
10
+ };
11
+ export const resolveNextStepImagePreloads = (manifest, currentStepId) => {
12
+ var _a, _b;
13
+ const nextStepIds = ((_a = manifest.edgesByStepId[currentStepId]) !== null && _a !== void 0 ? _a : [])
14
+ .map((edge) => edge.toStepId);
15
+ const preloadBySrc = new Map();
16
+ for (const nextStepId of nextStepIds) {
17
+ const nextStep = manifest.steps.find((step) => step.id === nextStepId);
18
+ for (const assetId of (_b = nextStep === null || nextStep === void 0 ? void 0 : nextStep.assetIds) !== null && _b !== void 0 ? _b : []) {
19
+ const preload = normalizeIdleImageAsset(manifest.assets[assetId]);
20
+ if (preload && !preloadBySrc.has(preload.src)) {
21
+ preloadBySrc.set(preload.src, preload);
22
+ }
23
+ }
24
+ }
25
+ return [...preloadBySrc.values()];
26
+ };
27
+ export const scheduleNextStepImagePreload = (manifest, currentStepId) => {
28
+ const preloads = resolveNextStepImagePreloads(manifest, currentStepId);
29
+ if (typeof window === 'undefined' || preloads.length === 0) {
30
+ return () => undefined;
31
+ }
32
+ const preload = () => {
33
+ for (const asset of preloads) {
34
+ const image = new window.Image();
35
+ image.src = asset.src;
36
+ }
37
+ };
38
+ if (typeof window.requestIdleCallback === 'function') {
39
+ const idleCallbackId = window.requestIdleCallback(preload);
40
+ return () => window.cancelIdleCallback(idleCallbackId);
41
+ }
42
+ const timeoutId = window.setTimeout(preload, 200);
43
+ return () => window.clearTimeout(timeoutId);
44
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/runtime",
3
- "version": "0.7.9",
3
+ "version": "0.7.10",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",