@codellyson/framely 0.1.0
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/AbsoluteFill.d.ts +18 -0
- package/dist/AbsoluteFill.d.ts.map +1 -0
- package/dist/AbsoluteFill.js +25 -0
- package/dist/AbsoluteFill.js.map +1 -0
- package/dist/Audio.d.ts +80 -0
- package/dist/Audio.d.ts.map +1 -0
- package/dist/Audio.js +221 -0
- package/dist/Audio.js.map +1 -0
- package/dist/Composition.d.ts +208 -0
- package/dist/Composition.d.ts.map +1 -0
- package/dist/Composition.js +210 -0
- package/dist/Composition.js.map +1 -0
- package/dist/Easing.d.ts +88 -0
- package/dist/Easing.d.ts.map +1 -0
- package/dist/Easing.js +266 -0
- package/dist/Easing.js.map +1 -0
- package/dist/ErrorBoundary.d.ts +35 -0
- package/dist/ErrorBoundary.d.ts.map +1 -0
- package/dist/ErrorBoundary.js +74 -0
- package/dist/ErrorBoundary.js.map +1 -0
- package/dist/Folder.d.ts +46 -0
- package/dist/Folder.d.ts.map +1 -0
- package/dist/Folder.js +44 -0
- package/dist/Folder.js.map +1 -0
- package/dist/Freeze.d.ts +35 -0
- package/dist/Freeze.d.ts.map +1 -0
- package/dist/Freeze.js +40 -0
- package/dist/Freeze.js.map +1 -0
- package/dist/IFrame.d.ts +28 -0
- package/dist/IFrame.d.ts.map +1 -0
- package/dist/IFrame.js +57 -0
- package/dist/IFrame.js.map +1 -0
- package/dist/Img.d.ts +36 -0
- package/dist/Img.d.ts.map +1 -0
- package/dist/Img.js +91 -0
- package/dist/Img.js.map +1 -0
- package/dist/Loop.d.ts +66 -0
- package/dist/Loop.d.ts.map +1 -0
- package/dist/Loop.js +79 -0
- package/dist/Loop.js.map +1 -0
- package/dist/Player.d.ts +118 -0
- package/dist/Player.d.ts.map +1 -0
- package/dist/Player.js +311 -0
- package/dist/Player.js.map +1 -0
- package/dist/Sequence.d.ts +25 -0
- package/dist/Sequence.d.ts.map +1 -0
- package/dist/Sequence.js +37 -0
- package/dist/Sequence.js.map +1 -0
- package/dist/Series.d.ts +52 -0
- package/dist/Series.d.ts.map +1 -0
- package/dist/Series.js +86 -0
- package/dist/Series.js.map +1 -0
- package/dist/Text.d.ts +129 -0
- package/dist/Text.d.ts.map +1 -0
- package/dist/Text.js +211 -0
- package/dist/Text.js.map +1 -0
- package/dist/Video.d.ts +75 -0
- package/dist/Video.d.ts.map +1 -0
- package/dist/Video.js +136 -0
- package/dist/Video.js.map +1 -0
- package/dist/config.d.ts +128 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +243 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +84 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +131 -0
- package/dist/context.js.map +1 -0
- package/dist/delayRender.d.ts +130 -0
- package/dist/delayRender.d.ts.map +1 -0
- package/dist/delayRender.js +197 -0
- package/dist/delayRender.js.map +1 -0
- package/dist/getInputProps.d.ts +118 -0
- package/dist/getInputProps.d.ts.map +1 -0
- package/dist/getInputProps.js +181 -0
- package/dist/getInputProps.js.map +1 -0
- package/dist/hooks/useDelayRender.d.ts +52 -0
- package/dist/hooks/useDelayRender.d.ts.map +1 -0
- package/dist/hooks/useDelayRender.js +92 -0
- package/dist/hooks/useDelayRender.js.map +1 -0
- package/dist/hooks.d.ts +19 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +17 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/interpolate.d.ts +80 -0
- package/dist/interpolate.d.ts.map +1 -0
- package/dist/interpolate.js +108 -0
- package/dist/interpolate.js.map +1 -0
- package/dist/interpolateColors.d.ts +50 -0
- package/dist/interpolateColors.d.ts.map +1 -0
- package/dist/interpolateColors.js +300 -0
- package/dist/interpolateColors.js.map +1 -0
- package/dist/makeTransform.d.ts +98 -0
- package/dist/makeTransform.d.ts.map +1 -0
- package/dist/makeTransform.js +287 -0
- package/dist/makeTransform.js.map +1 -0
- package/dist/measureSpring.d.ts +75 -0
- package/dist/measureSpring.d.ts.map +1 -0
- package/dist/measureSpring.js +108 -0
- package/dist/measureSpring.js.map +1 -0
- package/dist/noise.d.ts +110 -0
- package/dist/noise.d.ts.map +1 -0
- package/dist/noise.js +228 -0
- package/dist/noise.js.map +1 -0
- package/dist/preload.d.ts +145 -0
- package/dist/preload.d.ts.map +1 -0
- package/dist/preload.js +225 -0
- package/dist/preload.js.map +1 -0
- package/dist/registerRoot.d.ts +140 -0
- package/dist/registerRoot.d.ts.map +1 -0
- package/dist/registerRoot.js +238 -0
- package/dist/registerRoot.js.map +1 -0
- package/dist/shapes/Circle.d.ts +15 -0
- package/dist/shapes/Circle.d.ts.map +1 -0
- package/dist/shapes/Circle.js +11 -0
- package/dist/shapes/Circle.js.map +1 -0
- package/dist/shapes/Ellipse.d.ts +16 -0
- package/dist/shapes/Ellipse.d.ts.map +1 -0
- package/dist/shapes/Ellipse.js +11 -0
- package/dist/shapes/Ellipse.js.map +1 -0
- package/dist/shapes/Line.d.ts +15 -0
- package/dist/shapes/Line.d.ts.map +1 -0
- package/dist/shapes/Line.js +11 -0
- package/dist/shapes/Line.js.map +1 -0
- package/dist/shapes/Path.d.ts +20 -0
- package/dist/shapes/Path.d.ts.map +1 -0
- package/dist/shapes/Path.js +14 -0
- package/dist/shapes/Path.js.map +1 -0
- package/dist/shapes/Polygon.d.ts +15 -0
- package/dist/shapes/Polygon.d.ts.map +1 -0
- package/dist/shapes/Polygon.js +16 -0
- package/dist/shapes/Polygon.js.map +1 -0
- package/dist/shapes/Rect.d.ts +18 -0
- package/dist/shapes/Rect.d.ts.map +1 -0
- package/dist/shapes/Rect.js +11 -0
- package/dist/shapes/Rect.js.map +1 -0
- package/dist/shapes/Svg.d.ts +16 -0
- package/dist/shapes/Svg.d.ts.map +1 -0
- package/dist/shapes/Svg.js +15 -0
- package/dist/shapes/Svg.js.map +1 -0
- package/dist/shapes/index.d.ts +16 -0
- package/dist/shapes/index.d.ts.map +1 -0
- package/dist/shapes/index.js +9 -0
- package/dist/shapes/index.js.map +1 -0
- package/dist/shapes/usePathLength.d.ts +24 -0
- package/dist/shapes/usePathLength.d.ts.map +1 -0
- package/dist/shapes/usePathLength.js +32 -0
- package/dist/shapes/usePathLength.js.map +1 -0
- package/dist/staticFile.d.ts +47 -0
- package/dist/staticFile.d.ts.map +1 -0
- package/dist/staticFile.js +105 -0
- package/dist/staticFile.js.map +1 -0
- package/dist/templates/api.d.ts +26 -0
- package/dist/templates/api.d.ts.map +1 -0
- package/dist/templates/api.js +142 -0
- package/dist/templates/api.js.map +1 -0
- package/dist/templates/index.d.ts +7 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +7 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/mockData.d.ts +7 -0
- package/dist/templates/mockData.d.ts.map +1 -0
- package/dist/templates/mockData.js +262 -0
- package/dist/templates/mockData.js.map +1 -0
- package/dist/templates/types.d.ts +104 -0
- package/dist/templates/types.d.ts.map +1 -0
- package/dist/templates/types.js +16 -0
- package/dist/templates/types.js.map +1 -0
- package/dist/transitions/TransitionSeries.d.ts +127 -0
- package/dist/transitions/TransitionSeries.d.ts.map +1 -0
- package/dist/transitions/TransitionSeries.js +190 -0
- package/dist/transitions/TransitionSeries.js.map +1 -0
- package/dist/transitions/index.d.ts +52 -0
- package/dist/transitions/index.d.ts.map +1 -0
- package/dist/transitions/index.js +31 -0
- package/dist/transitions/index.js.map +1 -0
- package/dist/transitions/presets/fade.d.ts +45 -0
- package/dist/transitions/presets/fade.d.ts.map +1 -0
- package/dist/transitions/presets/fade.js +56 -0
- package/dist/transitions/presets/fade.js.map +1 -0
- package/dist/transitions/presets/flip.d.ts +99 -0
- package/dist/transitions/presets/flip.d.ts.map +1 -0
- package/dist/transitions/presets/flip.js +153 -0
- package/dist/transitions/presets/flip.js.map +1 -0
- package/dist/transitions/presets/slide.d.ts +61 -0
- package/dist/transitions/presets/slide.d.ts.map +1 -0
- package/dist/transitions/presets/slide.js +116 -0
- package/dist/transitions/presets/slide.js.map +1 -0
- package/dist/transitions/presets/wipe.d.ts +69 -0
- package/dist/transitions/presets/wipe.d.ts.map +1 -0
- package/dist/transitions/presets/wipe.js +136 -0
- package/dist/transitions/presets/wipe.js.map +1 -0
- package/dist/transitions/presets/zoom.d.ts +76 -0
- package/dist/transitions/presets/zoom.d.ts.map +1 -0
- package/dist/transitions/presets/zoom.js +110 -0
- package/dist/transitions/presets/zoom.js.map +1 -0
- package/dist/useAudioData.d.ts +112 -0
- package/dist/useAudioData.d.ts.map +1 -0
- package/dist/useAudioData.js +183 -0
- package/dist/useAudioData.js.map +1 -0
- package/dist/useSpring.d.ts +79 -0
- package/dist/useSpring.d.ts.map +1 -0
- package/dist/useSpring.js +140 -0
- package/dist/useSpring.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delay Render System
|
|
3
|
+
*
|
|
4
|
+
* This module manages asynchronous operations that must complete before
|
|
5
|
+
* a frame can be captured during rendering. It's essential for:
|
|
6
|
+
* - Loading images, videos, fonts
|
|
7
|
+
* - Fetching data from APIs
|
|
8
|
+
* - Any async operation that affects the visual output
|
|
9
|
+
*
|
|
10
|
+
* The renderer (Playwright) checks window.__FRAMELY_DELAY_RENDER before
|
|
11
|
+
* capturing each frame. If any handles are pending, it waits.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Options for delayRender().
|
|
15
|
+
*/
|
|
16
|
+
export interface DelayRenderOptions {
|
|
17
|
+
/** Timeout in milliseconds before throwing a timeout error. Defaults to 30000. */
|
|
18
|
+
timeoutInMilliseconds?: number;
|
|
19
|
+
/** Number of retries on timeout. Defaults to 0. */
|
|
20
|
+
retries?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Internal data tracked for each delay render handle.
|
|
24
|
+
*/
|
|
25
|
+
export interface DelayRenderHandle {
|
|
26
|
+
handle: number;
|
|
27
|
+
label: string;
|
|
28
|
+
createdAt: number;
|
|
29
|
+
timeoutInMilliseconds: number;
|
|
30
|
+
retries: number;
|
|
31
|
+
retriesRemaining: number;
|
|
32
|
+
timeoutId: ReturnType<typeof setTimeout> | null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Information about a pending delay render, returned by getPendingDelayRenders().
|
|
36
|
+
*/
|
|
37
|
+
export interface PendingDelayRender {
|
|
38
|
+
handle: number;
|
|
39
|
+
label: string;
|
|
40
|
+
/** Age in milliseconds since the handle was created. */
|
|
41
|
+
age: number;
|
|
42
|
+
}
|
|
43
|
+
declare global {
|
|
44
|
+
interface Window {
|
|
45
|
+
__FRAMELY_DELAY_RENDER: {
|
|
46
|
+
pending: Map<number, DelayRenderHandle>;
|
|
47
|
+
isPending: () => boolean;
|
|
48
|
+
getPendingCount: () => number;
|
|
49
|
+
getLabels: () => string[];
|
|
50
|
+
};
|
|
51
|
+
__FRAMELY_RENDER_ERROR?: {
|
|
52
|
+
message: string;
|
|
53
|
+
stack?: string;
|
|
54
|
+
componentStack?: string | null;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Signals that the current frame should not be captured until
|
|
60
|
+
* continueRender() is called with the returned handle.
|
|
61
|
+
*
|
|
62
|
+
* Use this when loading assets or fetching data that must be
|
|
63
|
+
* displayed in the frame.
|
|
64
|
+
*
|
|
65
|
+
* @param {string | DelayRenderOptions} [label] - Optional label for debugging (shown in timeout errors), or an options object
|
|
66
|
+
* @param {DelayRenderOptions} [options]
|
|
67
|
+
* @param {number} [options.timeoutInMilliseconds=30000] - Timeout before throwing
|
|
68
|
+
* @param {number} [options.retries=0] - Number of retries on timeout
|
|
69
|
+
* @returns {number} Handle to pass to continueRender()
|
|
70
|
+
*
|
|
71
|
+
* Usage:
|
|
72
|
+
* const handle = delayRender('Loading profile image');
|
|
73
|
+
* fetch('/api/image')
|
|
74
|
+
* .then(data => {
|
|
75
|
+
* setImage(data);
|
|
76
|
+
* continueRender(handle);
|
|
77
|
+
* })
|
|
78
|
+
* .catch(err => cancelRender(err));
|
|
79
|
+
*/
|
|
80
|
+
export declare function delayRender(label?: string | DelayRenderOptions, options?: DelayRenderOptions): number;
|
|
81
|
+
/**
|
|
82
|
+
* Signals that the async operation for the given handle has completed.
|
|
83
|
+
* The frame can now be captured (if no other handles are pending).
|
|
84
|
+
*
|
|
85
|
+
* @param {number} handle - The handle returned by delayRender()
|
|
86
|
+
*
|
|
87
|
+
* Usage:
|
|
88
|
+
* const handle = delayRender('Loading data');
|
|
89
|
+
* fetchData().then(() => continueRender(handle));
|
|
90
|
+
*/
|
|
91
|
+
export declare function continueRender(handle: number): void;
|
|
92
|
+
/**
|
|
93
|
+
* Cancels the render with an error. Use this when an unrecoverable
|
|
94
|
+
* error occurs (e.g., asset failed to load, API error).
|
|
95
|
+
*
|
|
96
|
+
* @param {Error|string} error - The error that caused the cancellation
|
|
97
|
+
*
|
|
98
|
+
* Usage:
|
|
99
|
+
* fetch('/api/data')
|
|
100
|
+
* .catch(err => cancelRender(err));
|
|
101
|
+
*/
|
|
102
|
+
export declare function cancelRender(error: Error | string): never;
|
|
103
|
+
/**
|
|
104
|
+
* Check if there are any pending delay render handles.
|
|
105
|
+
*
|
|
106
|
+
* @returns {boolean}
|
|
107
|
+
*/
|
|
108
|
+
export declare function isDelayRenderPending(): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Get information about all pending delay render handles.
|
|
111
|
+
* Useful for debugging.
|
|
112
|
+
*
|
|
113
|
+
* @returns {Array<PendingDelayRender>}
|
|
114
|
+
*/
|
|
115
|
+
export declare function getPendingDelayRenders(): PendingDelayRender[];
|
|
116
|
+
/**
|
|
117
|
+
* Clear all pending delay render handles.
|
|
118
|
+
* Use with caution - mainly for testing/cleanup.
|
|
119
|
+
*/
|
|
120
|
+
export declare function clearAllDelayRenders(): void;
|
|
121
|
+
declare const _default: {
|
|
122
|
+
delayRender: typeof delayRender;
|
|
123
|
+
continueRender: typeof continueRender;
|
|
124
|
+
cancelRender: typeof cancelRender;
|
|
125
|
+
isDelayRenderPending: typeof isDelayRenderPending;
|
|
126
|
+
getPendingDelayRenders: typeof getPendingDelayRenders;
|
|
127
|
+
clearAllDelayRenders: typeof clearAllDelayRenders;
|
|
128
|
+
};
|
|
129
|
+
export default _default;
|
|
130
|
+
//# sourceMappingURL=delayRender.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delayRender.d.ts","sourceRoot":"","sources":["../src/delayRender.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,kFAAkF;IAClF,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,IAAI,CAAC;CACjD;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,GAAG,EAAE,MAAM,CAAC;CACb;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,sBAAsB,EAAE;YACtB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;YACxC,SAAS,EAAE,MAAM,OAAO,CAAC;YACzB,eAAe,EAAE,MAAM,MAAM,CAAC;YAC9B,SAAS,EAAE,MAAM,MAAM,EAAE,CAAC;SAC3B,CAAC;QACF,sBAAsB,CAAC,EAAE;YACvB,OAAO,EAAE,MAAM,CAAC;YAChB,KAAK,CAAC,EAAE,MAAM,CAAC;YACf,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;SAChC,CAAC;KACH;CACF;AAyBD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CACzB,KAAK,CAAC,EAAE,MAAM,GAAG,kBAAkB,EACnC,OAAO,GAAE,kBAAuB,GAC/B,MAAM,CAuDR;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAiBnD;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,CAyBzD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,IAAI,kBAAkB,EAAE,CAO7D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAO3C;;;;;;;;;AAED,wBAOE"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delay Render System
|
|
3
|
+
*
|
|
4
|
+
* This module manages asynchronous operations that must complete before
|
|
5
|
+
* a frame can be captured during rendering. It's essential for:
|
|
6
|
+
* - Loading images, videos, fonts
|
|
7
|
+
* - Fetching data from APIs
|
|
8
|
+
* - Any async operation that affects the visual output
|
|
9
|
+
*
|
|
10
|
+
* The renderer (Playwright) checks window.__FRAMELY_DELAY_RENDER before
|
|
11
|
+
* capturing each frame. If any handles are pending, it waits.
|
|
12
|
+
*/
|
|
13
|
+
// Global state for tracking delay render handles
|
|
14
|
+
let handleCounter = 0;
|
|
15
|
+
const pendingHandles = new Map();
|
|
16
|
+
const DEFAULT_TIMEOUT = 30000; // 30 seconds
|
|
17
|
+
/**
|
|
18
|
+
* Initialize the global delay render state.
|
|
19
|
+
* Called automatically when the module loads.
|
|
20
|
+
*/
|
|
21
|
+
function initDelayRenderState() {
|
|
22
|
+
if (typeof window !== 'undefined') {
|
|
23
|
+
window.__FRAMELY_DELAY_RENDER = {
|
|
24
|
+
pending: pendingHandles,
|
|
25
|
+
isPending: () => pendingHandles.size > 0,
|
|
26
|
+
getPendingCount: () => pendingHandles.size,
|
|
27
|
+
getLabels: () => Array.from(pendingHandles.values()).map(h => h.label),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Initialize on module load
|
|
32
|
+
initDelayRenderState();
|
|
33
|
+
/**
|
|
34
|
+
* Signals that the current frame should not be captured until
|
|
35
|
+
* continueRender() is called with the returned handle.
|
|
36
|
+
*
|
|
37
|
+
* Use this when loading assets or fetching data that must be
|
|
38
|
+
* displayed in the frame.
|
|
39
|
+
*
|
|
40
|
+
* @param {string | DelayRenderOptions} [label] - Optional label for debugging (shown in timeout errors), or an options object
|
|
41
|
+
* @param {DelayRenderOptions} [options]
|
|
42
|
+
* @param {number} [options.timeoutInMilliseconds=30000] - Timeout before throwing
|
|
43
|
+
* @param {number} [options.retries=0] - Number of retries on timeout
|
|
44
|
+
* @returns {number} Handle to pass to continueRender()
|
|
45
|
+
*
|
|
46
|
+
* Usage:
|
|
47
|
+
* const handle = delayRender('Loading profile image');
|
|
48
|
+
* fetch('/api/image')
|
|
49
|
+
* .then(data => {
|
|
50
|
+
* setImage(data);
|
|
51
|
+
* continueRender(handle);
|
|
52
|
+
* })
|
|
53
|
+
* .catch(err => cancelRender(err));
|
|
54
|
+
*/
|
|
55
|
+
export function delayRender(label, options = {}) {
|
|
56
|
+
const { timeoutInMilliseconds = DEFAULT_TIMEOUT, retries = 0, } = typeof label === 'object' ? label : options;
|
|
57
|
+
const actualLabel = typeof label === 'string' ? label : 'Unnamed delay';
|
|
58
|
+
const handle = ++handleCounter;
|
|
59
|
+
const handleData = {
|
|
60
|
+
handle,
|
|
61
|
+
label: actualLabel,
|
|
62
|
+
createdAt: Date.now(),
|
|
63
|
+
timeoutInMilliseconds,
|
|
64
|
+
retries,
|
|
65
|
+
retriesRemaining: retries,
|
|
66
|
+
timeoutId: null,
|
|
67
|
+
};
|
|
68
|
+
// Set up timeout
|
|
69
|
+
if (typeof window !== 'undefined' && timeoutInMilliseconds > 0) {
|
|
70
|
+
handleData.timeoutId = setTimeout(() => {
|
|
71
|
+
if (pendingHandles.has(handle)) {
|
|
72
|
+
const error = new Error(`delayRender() timed out after ${timeoutInMilliseconds}ms.\n` +
|
|
73
|
+
`Label: "${actualLabel}"\n` +
|
|
74
|
+
`Handle: ${handle}\n\n` +
|
|
75
|
+
`This usually means:\n` +
|
|
76
|
+
`- An asset failed to load (image, video, font)\n` +
|
|
77
|
+
`- A fetch request never completed\n` +
|
|
78
|
+
`- continueRender() was never called\n\n` +
|
|
79
|
+
`Make sure to call continueRender(handle) when your async operation completes.`);
|
|
80
|
+
error.name = 'DelayRenderTimeoutError';
|
|
81
|
+
// Check if we should retry
|
|
82
|
+
if (handleData.retriesRemaining > 0) {
|
|
83
|
+
handleData.retriesRemaining--;
|
|
84
|
+
console.warn(`delayRender retry (${retries - handleData.retriesRemaining}/${retries}): ${actualLabel}`);
|
|
85
|
+
// Reset timeout
|
|
86
|
+
handleData.timeoutId = setTimeout(() => {
|
|
87
|
+
if (pendingHandles.has(handle)) {
|
|
88
|
+
cancelRender(error);
|
|
89
|
+
}
|
|
90
|
+
}, timeoutInMilliseconds);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
cancelRender(error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}, timeoutInMilliseconds);
|
|
97
|
+
}
|
|
98
|
+
pendingHandles.set(handle, handleData);
|
|
99
|
+
return handle;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Signals that the async operation for the given handle has completed.
|
|
103
|
+
* The frame can now be captured (if no other handles are pending).
|
|
104
|
+
*
|
|
105
|
+
* @param {number} handle - The handle returned by delayRender()
|
|
106
|
+
*
|
|
107
|
+
* Usage:
|
|
108
|
+
* const handle = delayRender('Loading data');
|
|
109
|
+
* fetchData().then(() => continueRender(handle));
|
|
110
|
+
*/
|
|
111
|
+
export function continueRender(handle) {
|
|
112
|
+
const handleData = pendingHandles.get(handle);
|
|
113
|
+
if (!handleData) {
|
|
114
|
+
console.warn(`continueRender() called with unknown handle: ${handle}. ` +
|
|
115
|
+
`It may have already been continued or timed out.`);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
// Clear timeout
|
|
119
|
+
if (handleData.timeoutId) {
|
|
120
|
+
clearTimeout(handleData.timeoutId);
|
|
121
|
+
}
|
|
122
|
+
pendingHandles.delete(handle);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Cancels the render with an error. Use this when an unrecoverable
|
|
126
|
+
* error occurs (e.g., asset failed to load, API error).
|
|
127
|
+
*
|
|
128
|
+
* @param {Error|string} error - The error that caused the cancellation
|
|
129
|
+
*
|
|
130
|
+
* Usage:
|
|
131
|
+
* fetch('/api/data')
|
|
132
|
+
* .catch(err => cancelRender(err));
|
|
133
|
+
*/
|
|
134
|
+
export function cancelRender(error) {
|
|
135
|
+
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
136
|
+
// Clear all pending handles
|
|
137
|
+
for (const [handle, data] of pendingHandles) {
|
|
138
|
+
if (data.timeoutId) {
|
|
139
|
+
clearTimeout(data.timeoutId);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
pendingHandles.clear();
|
|
143
|
+
// Expose the error globally for the renderer to catch
|
|
144
|
+
if (typeof window !== 'undefined') {
|
|
145
|
+
window.__FRAMELY_RENDER_ERROR = errorObj;
|
|
146
|
+
// Also dispatch an event for any listeners
|
|
147
|
+
window.dispatchEvent(new CustomEvent('framely-render-error', {
|
|
148
|
+
detail: { error: errorObj }
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
// In development, also throw to show in console
|
|
152
|
+
console.error('Render cancelled:', errorObj);
|
|
153
|
+
throw errorObj;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Check if there are any pending delay render handles.
|
|
157
|
+
*
|
|
158
|
+
* @returns {boolean}
|
|
159
|
+
*/
|
|
160
|
+
export function isDelayRenderPending() {
|
|
161
|
+
return pendingHandles.size > 0;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Get information about all pending delay render handles.
|
|
165
|
+
* Useful for debugging.
|
|
166
|
+
*
|
|
167
|
+
* @returns {Array<PendingDelayRender>}
|
|
168
|
+
*/
|
|
169
|
+
export function getPendingDelayRenders() {
|
|
170
|
+
const now = Date.now();
|
|
171
|
+
return Array.from(pendingHandles.values()).map(data => ({
|
|
172
|
+
handle: data.handle,
|
|
173
|
+
label: data.label,
|
|
174
|
+
age: now - data.createdAt,
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Clear all pending delay render handles.
|
|
179
|
+
* Use with caution - mainly for testing/cleanup.
|
|
180
|
+
*/
|
|
181
|
+
export function clearAllDelayRenders() {
|
|
182
|
+
for (const [handle, data] of pendingHandles) {
|
|
183
|
+
if (data.timeoutId) {
|
|
184
|
+
clearTimeout(data.timeoutId);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
pendingHandles.clear();
|
|
188
|
+
}
|
|
189
|
+
export default {
|
|
190
|
+
delayRender,
|
|
191
|
+
continueRender,
|
|
192
|
+
cancelRender,
|
|
193
|
+
isDelayRenderPending,
|
|
194
|
+
getPendingDelayRenders,
|
|
195
|
+
clearAllDelayRenders,
|
|
196
|
+
};
|
|
197
|
+
//# sourceMappingURL=delayRender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delayRender.js","sourceRoot":"","sources":["../src/delayRender.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAmDH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AAI,GAAG,CAAC,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB;IACpC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,OAAO,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACtD,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,SAAS;KAC1B,CAAC,CAAC,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB;IAClC,KAAK,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,cAAc,EAAE,CAAC;QAC5C,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IACD,cAAc,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC;AAED,eAAe;IACb,WAAW;IACX,cAAc;IACd,YAAY;IACZ,oBAAoB;IACpB,sBAAsB;IACtB,oBAAoB;CACrB,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input Props System
|
|
3
|
+
*
|
|
4
|
+
* Manages props passed to compositions from external sources:
|
|
5
|
+
* - CLI flags (--props '{"key": "value"}')
|
|
6
|
+
* - API requests (render endpoint body)
|
|
7
|
+
* - URL query parameters (?props=...)
|
|
8
|
+
*
|
|
9
|
+
* This allows dynamic, data-driven video generation.
|
|
10
|
+
*/
|
|
11
|
+
/** A record of string keys to unknown values, representing input props. */
|
|
12
|
+
export type InputProps = Record<string, unknown>;
|
|
13
|
+
/** Possible sources from which input props can originate. */
|
|
14
|
+
export type InputPropsSource = 'url' | 'renderer' | 'manual' | null;
|
|
15
|
+
/** Augment the global Window interface with Framely-specific properties. */
|
|
16
|
+
declare global {
|
|
17
|
+
interface Window {
|
|
18
|
+
__FRAMELY_INPUT_PROPS?: InputProps;
|
|
19
|
+
__FRAMELY_SET_INPUT_PROPS?: typeof setInputProps;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the input props passed to the current render/preview.
|
|
24
|
+
*
|
|
25
|
+
* In the CLI, props are passed via --props flag:
|
|
26
|
+
* framely render my-video --props '{"name": "John"}'
|
|
27
|
+
*
|
|
28
|
+
* In the API, props are passed in the request body:
|
|
29
|
+
* POST /api/render { compositionId: "...", props: { name: "John" } }
|
|
30
|
+
*
|
|
31
|
+
* @returns {object} The input props object
|
|
32
|
+
*
|
|
33
|
+
* Usage:
|
|
34
|
+
* function MyVideo() {
|
|
35
|
+
* const { name, color } = getInputProps();
|
|
36
|
+
* return <div style={{ color }}>{name}</div>;
|
|
37
|
+
* }
|
|
38
|
+
*/
|
|
39
|
+
export declare function getInputProps<T extends InputProps = InputProps>(): T;
|
|
40
|
+
/**
|
|
41
|
+
* Set input props programmatically.
|
|
42
|
+
*
|
|
43
|
+
* This is primarily used by the renderer to inject props before
|
|
44
|
+
* the composition is rendered.
|
|
45
|
+
*
|
|
46
|
+
* @param {object} props - Props to set
|
|
47
|
+
* @param {string} [source] - Source identifier (for debugging)
|
|
48
|
+
*/
|
|
49
|
+
export declare function setInputProps(props: InputProps, source?: InputPropsSource): void;
|
|
50
|
+
/**
|
|
51
|
+
* Merge additional props into the existing input props.
|
|
52
|
+
*
|
|
53
|
+
* @param {object} props - Props to merge
|
|
54
|
+
*/
|
|
55
|
+
export declare function mergeInputProps(props: InputProps): void;
|
|
56
|
+
/**
|
|
57
|
+
* Get a specific input prop by key.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} key - Prop key
|
|
60
|
+
* @param {*} [defaultValue] - Default value if prop doesn't exist
|
|
61
|
+
* @returns {*} The prop value or default
|
|
62
|
+
*
|
|
63
|
+
* Usage:
|
|
64
|
+
* const name = getInputProp('name', 'Anonymous');
|
|
65
|
+
*/
|
|
66
|
+
export declare function getInputProp<T = unknown>(key: string, defaultValue?: T): T;
|
|
67
|
+
/**
|
|
68
|
+
* Check if input props were provided.
|
|
69
|
+
*
|
|
70
|
+
* @returns {boolean}
|
|
71
|
+
*/
|
|
72
|
+
export declare function hasInputProps(): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Get the source of the current input props.
|
|
75
|
+
*
|
|
76
|
+
* @returns {string|null} 'url', 'renderer', 'manual', or null
|
|
77
|
+
*/
|
|
78
|
+
export declare function getInputPropsSource(): InputPropsSource;
|
|
79
|
+
/**
|
|
80
|
+
* Clear all input props (mainly for testing).
|
|
81
|
+
*/
|
|
82
|
+
export declare function clearInputProps(): void;
|
|
83
|
+
/**
|
|
84
|
+
* Parse props from a JSON string or file path.
|
|
85
|
+
*
|
|
86
|
+
* @param {string} input - JSON string or path to JSON file
|
|
87
|
+
* @returns {object} Parsed props
|
|
88
|
+
*/
|
|
89
|
+
export declare function parsePropsInput(input: string): InputProps;
|
|
90
|
+
/**
|
|
91
|
+
* Serialize props to a URL-safe string.
|
|
92
|
+
*
|
|
93
|
+
* @param {object} props - Props to serialize
|
|
94
|
+
* @returns {string} URL-encoded JSON string
|
|
95
|
+
*/
|
|
96
|
+
export declare function serializeProps(props: InputProps): string;
|
|
97
|
+
/**
|
|
98
|
+
* Create a URL with props embedded as query parameter.
|
|
99
|
+
*
|
|
100
|
+
* @param {string} baseUrl - Base URL
|
|
101
|
+
* @param {object} props - Props to embed
|
|
102
|
+
* @returns {string} URL with props
|
|
103
|
+
*/
|
|
104
|
+
export declare function createUrlWithProps(baseUrl: string, props: InputProps): string;
|
|
105
|
+
declare const _default: {
|
|
106
|
+
getInputProps: typeof getInputProps;
|
|
107
|
+
setInputProps: typeof setInputProps;
|
|
108
|
+
mergeInputProps: typeof mergeInputProps;
|
|
109
|
+
getInputProp: typeof getInputProp;
|
|
110
|
+
hasInputProps: typeof hasInputProps;
|
|
111
|
+
getInputPropsSource: typeof getInputPropsSource;
|
|
112
|
+
clearInputProps: typeof clearInputProps;
|
|
113
|
+
parsePropsInput: typeof parsePropsInput;
|
|
114
|
+
serializeProps: typeof serializeProps;
|
|
115
|
+
createUrlWithProps: typeof createUrlWithProps;
|
|
116
|
+
};
|
|
117
|
+
export default _default;
|
|
118
|
+
//# sourceMappingURL=getInputProps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getInputProps.d.ts","sourceRoot":"","sources":["../src/getInputProps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,2EAA2E;AAC3E,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjD,6DAA6D;AAC7D,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,UAAU,GAAG,QAAQ,GAAG,IAAI,CAAC;AAEpE,4EAA4E;AAC5E,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,qBAAqB,CAAC,EAAE,UAAU,CAAC;QACnC,yBAAyB,CAAC,EAAE,OAAO,aAAa,CAAC;KAClD;CACF;AAuCD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,KAAK,CAAC,CAEpE;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,UAAU,EACjB,MAAM,GAAE,gBAA2B,GAClC,IAAI,CAQN;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAMvD;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,CAE1E;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,CAEtD;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAOtC;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAYzD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAExD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CAI7E;;;;;;;;;;;;;AAED,wBAWE"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input Props System
|
|
3
|
+
*
|
|
4
|
+
* Manages props passed to compositions from external sources:
|
|
5
|
+
* - CLI flags (--props '{"key": "value"}')
|
|
6
|
+
* - API requests (render endpoint body)
|
|
7
|
+
* - URL query parameters (?props=...)
|
|
8
|
+
*
|
|
9
|
+
* This allows dynamic, data-driven video generation.
|
|
10
|
+
*/
|
|
11
|
+
// Global storage for input props
|
|
12
|
+
let inputProps = {};
|
|
13
|
+
let inputPropsSource = null;
|
|
14
|
+
/**
|
|
15
|
+
* Initialize input props from various sources.
|
|
16
|
+
* Called automatically on module load.
|
|
17
|
+
*/
|
|
18
|
+
function initInputProps() {
|
|
19
|
+
if (typeof window === 'undefined')
|
|
20
|
+
return;
|
|
21
|
+
// Check URL query params first
|
|
22
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
23
|
+
const propsParam = urlParams.get('props');
|
|
24
|
+
if (propsParam) {
|
|
25
|
+
try {
|
|
26
|
+
inputProps = JSON.parse(decodeURIComponent(propsParam));
|
|
27
|
+
inputPropsSource = 'url';
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
console.warn('Failed to parse props from URL:', err);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Check for props injected by renderer
|
|
34
|
+
if (window.__FRAMELY_INPUT_PROPS) {
|
|
35
|
+
inputProps = { ...inputProps, ...window.__FRAMELY_INPUT_PROPS };
|
|
36
|
+
inputPropsSource = 'renderer';
|
|
37
|
+
}
|
|
38
|
+
// Expose setter for external use
|
|
39
|
+
window.__FRAMELY_SET_INPUT_PROPS = setInputProps;
|
|
40
|
+
}
|
|
41
|
+
// Initialize on module load
|
|
42
|
+
initInputProps();
|
|
43
|
+
/**
|
|
44
|
+
* Get the input props passed to the current render/preview.
|
|
45
|
+
*
|
|
46
|
+
* In the CLI, props are passed via --props flag:
|
|
47
|
+
* framely render my-video --props '{"name": "John"}'
|
|
48
|
+
*
|
|
49
|
+
* In the API, props are passed in the request body:
|
|
50
|
+
* POST /api/render { compositionId: "...", props: { name: "John" } }
|
|
51
|
+
*
|
|
52
|
+
* @returns {object} The input props object
|
|
53
|
+
*
|
|
54
|
+
* Usage:
|
|
55
|
+
* function MyVideo() {
|
|
56
|
+
* const { name, color } = getInputProps();
|
|
57
|
+
* return <div style={{ color }}>{name}</div>;
|
|
58
|
+
* }
|
|
59
|
+
*/
|
|
60
|
+
export function getInputProps() {
|
|
61
|
+
return { ...inputProps };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Set input props programmatically.
|
|
65
|
+
*
|
|
66
|
+
* This is primarily used by the renderer to inject props before
|
|
67
|
+
* the composition is rendered.
|
|
68
|
+
*
|
|
69
|
+
* @param {object} props - Props to set
|
|
70
|
+
* @param {string} [source] - Source identifier (for debugging)
|
|
71
|
+
*/
|
|
72
|
+
export function setInputProps(props, source = 'manual') {
|
|
73
|
+
inputProps = { ...props };
|
|
74
|
+
inputPropsSource = source;
|
|
75
|
+
// Update global reference
|
|
76
|
+
if (typeof window !== 'undefined') {
|
|
77
|
+
window.__FRAMELY_INPUT_PROPS = inputProps;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Merge additional props into the existing input props.
|
|
82
|
+
*
|
|
83
|
+
* @param {object} props - Props to merge
|
|
84
|
+
*/
|
|
85
|
+
export function mergeInputProps(props) {
|
|
86
|
+
inputProps = { ...inputProps, ...props };
|
|
87
|
+
if (typeof window !== 'undefined') {
|
|
88
|
+
window.__FRAMELY_INPUT_PROPS = inputProps;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get a specific input prop by key.
|
|
93
|
+
*
|
|
94
|
+
* @param {string} key - Prop key
|
|
95
|
+
* @param {*} [defaultValue] - Default value if prop doesn't exist
|
|
96
|
+
* @returns {*} The prop value or default
|
|
97
|
+
*
|
|
98
|
+
* Usage:
|
|
99
|
+
* const name = getInputProp('name', 'Anonymous');
|
|
100
|
+
*/
|
|
101
|
+
export function getInputProp(key, defaultValue) {
|
|
102
|
+
return (key in inputProps ? inputProps[key] : defaultValue);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Check if input props were provided.
|
|
106
|
+
*
|
|
107
|
+
* @returns {boolean}
|
|
108
|
+
*/
|
|
109
|
+
export function hasInputProps() {
|
|
110
|
+
return Object.keys(inputProps).length > 0;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get the source of the current input props.
|
|
114
|
+
*
|
|
115
|
+
* @returns {string|null} 'url', 'renderer', 'manual', or null
|
|
116
|
+
*/
|
|
117
|
+
export function getInputPropsSource() {
|
|
118
|
+
return inputPropsSource;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Clear all input props (mainly for testing).
|
|
122
|
+
*/
|
|
123
|
+
export function clearInputProps() {
|
|
124
|
+
inputProps = {};
|
|
125
|
+
inputPropsSource = null;
|
|
126
|
+
if (typeof window !== 'undefined') {
|
|
127
|
+
delete window.__FRAMELY_INPUT_PROPS;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Parse props from a JSON string or file path.
|
|
132
|
+
*
|
|
133
|
+
* @param {string} input - JSON string or path to JSON file
|
|
134
|
+
* @returns {object} Parsed props
|
|
135
|
+
*/
|
|
136
|
+
export function parsePropsInput(input) {
|
|
137
|
+
if (!input)
|
|
138
|
+
return {};
|
|
139
|
+
// Try parsing as JSON directly
|
|
140
|
+
try {
|
|
141
|
+
return JSON.parse(input);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// Not valid JSON, might be a file path (handled by CLI)
|
|
145
|
+
throw new Error(`Invalid props input. Expected JSON string, got: ${input.slice(0, 50)}...`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Serialize props to a URL-safe string.
|
|
150
|
+
*
|
|
151
|
+
* @param {object} props - Props to serialize
|
|
152
|
+
* @returns {string} URL-encoded JSON string
|
|
153
|
+
*/
|
|
154
|
+
export function serializeProps(props) {
|
|
155
|
+
return encodeURIComponent(JSON.stringify(props));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Create a URL with props embedded as query parameter.
|
|
159
|
+
*
|
|
160
|
+
* @param {string} baseUrl - Base URL
|
|
161
|
+
* @param {object} props - Props to embed
|
|
162
|
+
* @returns {string} URL with props
|
|
163
|
+
*/
|
|
164
|
+
export function createUrlWithProps(baseUrl, props) {
|
|
165
|
+
const url = new URL(baseUrl);
|
|
166
|
+
url.searchParams.set('props', serializeProps(props));
|
|
167
|
+
return url.toString();
|
|
168
|
+
}
|
|
169
|
+
export default {
|
|
170
|
+
getInputProps,
|
|
171
|
+
setInputProps,
|
|
172
|
+
mergeInputProps,
|
|
173
|
+
getInputProp,
|
|
174
|
+
hasInputProps,
|
|
175
|
+
getInputPropsSource,
|
|
176
|
+
clearInputProps,
|
|
177
|
+
parsePropsInput,
|
|
178
|
+
serializeProps,
|
|
179
|
+
createUrlWithProps,
|
|
180
|
+
};
|
|
181
|
+
//# sourceMappingURL=getInputProps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getInputProps.js","sourceRoot":"","sources":["../src/getInputProps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAgBH,i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