@snowcone-app/sdk 0.1.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.
@@ -0,0 +1,96 @@
1
+ import { M as MockupResult, W as WebSocketConfig, u as PlacementSettings, F as FrameworkAdapter, b as ComponentProps, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, c as ComponentDescriptor, g as FrameworkUtilities } from './websocket-B8_XAwWx.cjs';
2
+
3
+ interface UseRealtimeMockupOptions {
4
+ wsUrl?: string;
5
+ onConnected?: (sessionId: string) => void;
6
+ onDisconnected?: () => void;
7
+ onConfigReceived?: () => void;
8
+ /** Called when server confirms it received a blob for a placement */
9
+ onBlobReceived?: (placement: string) => void;
10
+ /** Called when a blob is actually sent to server (after throttle completes) */
11
+ onBlobSent?: (placement: string) => void;
12
+ onMockupRendered?: (result: MockupResult) => void;
13
+ onAllMockupsRendered?: (results: MockupResult[]) => void;
14
+ onError?: (error: string) => void;
15
+ }
16
+ declare function useRealtimeMockup(options?: UseRealtimeMockupOptions): {
17
+ connect: () => void;
18
+ disconnect: () => void;
19
+ sendConfig: (config: WebSocketConfig) => boolean;
20
+ updateMockupIds: (mockupIds: string[]) => boolean;
21
+ updatePlacementSettings: (settings: Record<string, PlacementSettings>) => boolean;
22
+ sendCanvasBlob: (placement: string, blob: Blob, mockupCount?: number, baseThrottleMs?: number) => boolean;
23
+ sendColorBlob: (placement: string, hexColor: string) => boolean;
24
+ createEmptyCanvasBlob: (width?: number, height?: number) => Promise<Blob>;
25
+ sendInitialEmptyCanvases: (placements: Array<{
26
+ label: string;
27
+ width?: number;
28
+ height?: number;
29
+ }>) => Promise<void>;
30
+ setInitialData: (canvasBlobs: Map<string, Blob>, colors: Map<string, string>) => void;
31
+ clearLogs: () => void;
32
+ clearMockups: () => void;
33
+ flushPendingBlobs: () => void;
34
+ hasPendingBlobs: () => boolean;
35
+ isConnected: boolean;
36
+ sessionId: string | null;
37
+ isConfigured: boolean;
38
+ mockupResults: MockupResult[];
39
+ status: string;
40
+ logs: string[];
41
+ lastError: string | null;
42
+ };
43
+
44
+ /**
45
+ * React framework adapter implementation
46
+ */
47
+
48
+ /**
49
+ * React adapter implementation
50
+ */
51
+ declare class ReactAdapter implements FrameworkAdapter<ComponentProps> {
52
+ name: "react";
53
+ private React;
54
+ private hooks;
55
+ constructor(React: any, hooks?: any);
56
+ /**
57
+ * Create a stateful value using useState
58
+ */
59
+ createState<T>(initialValue: T): ComponentState<T>;
60
+ /**
61
+ * Create a context provider/consumer
62
+ */
63
+ createContext<T>(name: string): ComponentContext<T>;
64
+ /**
65
+ * Register lifecycle hooks
66
+ */
67
+ useLifecycle(lifecycle: ComponentLifecycleHooks): void;
68
+ /**
69
+ * Register event handlers
70
+ */
71
+ useEvents(handlers: EventHandler[]): void;
72
+ /**
73
+ * Create a ref to a DOM element
74
+ */
75
+ createRef<T extends HTMLElement>(): {
76
+ current: T | null;
77
+ };
78
+ /**
79
+ * Render a component
80
+ */
81
+ render(component: ComponentDescriptor, props: ComponentProps): any;
82
+ /**
83
+ * Get React-specific utilities
84
+ */
85
+ getUtilities(): FrameworkUtilities;
86
+ }
87
+ /**
88
+ * Create a React component from a descriptor
89
+ */
90
+ declare function createReactComponent(descriptor: ComponentDescriptor, React: any): any;
91
+ /**
92
+ * Hook to use framework adapter in React
93
+ */
94
+ declare function useFrameworkAdapter(React: any): ReactAdapter;
95
+
96
+ export { MockupResult, ReactAdapter, type UseRealtimeMockupOptions, WebSocketConfig, createReactComponent, useFrameworkAdapter as useReactAdapter, useRealtimeMockup };
@@ -0,0 +1,96 @@
1
+ import { M as MockupResult, W as WebSocketConfig, u as PlacementSettings, F as FrameworkAdapter, b as ComponentProps, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, c as ComponentDescriptor, g as FrameworkUtilities } from './websocket-B8_XAwWx.js';
2
+
3
+ interface UseRealtimeMockupOptions {
4
+ wsUrl?: string;
5
+ onConnected?: (sessionId: string) => void;
6
+ onDisconnected?: () => void;
7
+ onConfigReceived?: () => void;
8
+ /** Called when server confirms it received a blob for a placement */
9
+ onBlobReceived?: (placement: string) => void;
10
+ /** Called when a blob is actually sent to server (after throttle completes) */
11
+ onBlobSent?: (placement: string) => void;
12
+ onMockupRendered?: (result: MockupResult) => void;
13
+ onAllMockupsRendered?: (results: MockupResult[]) => void;
14
+ onError?: (error: string) => void;
15
+ }
16
+ declare function useRealtimeMockup(options?: UseRealtimeMockupOptions): {
17
+ connect: () => void;
18
+ disconnect: () => void;
19
+ sendConfig: (config: WebSocketConfig) => boolean;
20
+ updateMockupIds: (mockupIds: string[]) => boolean;
21
+ updatePlacementSettings: (settings: Record<string, PlacementSettings>) => boolean;
22
+ sendCanvasBlob: (placement: string, blob: Blob, mockupCount?: number, baseThrottleMs?: number) => boolean;
23
+ sendColorBlob: (placement: string, hexColor: string) => boolean;
24
+ createEmptyCanvasBlob: (width?: number, height?: number) => Promise<Blob>;
25
+ sendInitialEmptyCanvases: (placements: Array<{
26
+ label: string;
27
+ width?: number;
28
+ height?: number;
29
+ }>) => Promise<void>;
30
+ setInitialData: (canvasBlobs: Map<string, Blob>, colors: Map<string, string>) => void;
31
+ clearLogs: () => void;
32
+ clearMockups: () => void;
33
+ flushPendingBlobs: () => void;
34
+ hasPendingBlobs: () => boolean;
35
+ isConnected: boolean;
36
+ sessionId: string | null;
37
+ isConfigured: boolean;
38
+ mockupResults: MockupResult[];
39
+ status: string;
40
+ logs: string[];
41
+ lastError: string | null;
42
+ };
43
+
44
+ /**
45
+ * React framework adapter implementation
46
+ */
47
+
48
+ /**
49
+ * React adapter implementation
50
+ */
51
+ declare class ReactAdapter implements FrameworkAdapter<ComponentProps> {
52
+ name: "react";
53
+ private React;
54
+ private hooks;
55
+ constructor(React: any, hooks?: any);
56
+ /**
57
+ * Create a stateful value using useState
58
+ */
59
+ createState<T>(initialValue: T): ComponentState<T>;
60
+ /**
61
+ * Create a context provider/consumer
62
+ */
63
+ createContext<T>(name: string): ComponentContext<T>;
64
+ /**
65
+ * Register lifecycle hooks
66
+ */
67
+ useLifecycle(lifecycle: ComponentLifecycleHooks): void;
68
+ /**
69
+ * Register event handlers
70
+ */
71
+ useEvents(handlers: EventHandler[]): void;
72
+ /**
73
+ * Create a ref to a DOM element
74
+ */
75
+ createRef<T extends HTMLElement>(): {
76
+ current: T | null;
77
+ };
78
+ /**
79
+ * Render a component
80
+ */
81
+ render(component: ComponentDescriptor, props: ComponentProps): any;
82
+ /**
83
+ * Get React-specific utilities
84
+ */
85
+ getUtilities(): FrameworkUtilities;
86
+ }
87
+ /**
88
+ * Create a React component from a descriptor
89
+ */
90
+ declare function createReactComponent(descriptor: ComponentDescriptor, React: any): any;
91
+ /**
92
+ * Hook to use framework adapter in React
93
+ */
94
+ declare function useFrameworkAdapter(React: any): ReactAdapter;
95
+
96
+ export { MockupResult, ReactAdapter, type UseRealtimeMockupOptions, WebSocketConfig, createReactComponent, useFrameworkAdapter as useReactAdapter, useRealtimeMockup };
package/dist/react.js ADDED
@@ -0,0 +1,245 @@
1
+ import {
2
+ RealtimeMockupService
3
+ } from "./chunk-UJFJ7REN.js";
4
+
5
+ // src/realtime/react.ts
6
+ import { useCallback, useEffect, useRef, useState } from "react";
7
+ function useRealtimeMockup(options = {}) {
8
+ const serviceRef = useRef(null);
9
+ const [state, setState] = useState({
10
+ isConnected: false,
11
+ sessionId: null,
12
+ isConfigured: false,
13
+ mockupResults: [],
14
+ status: "Disconnected",
15
+ logs: [],
16
+ lastError: null
17
+ });
18
+ useEffect(() => {
19
+ const service = new RealtimeMockupService(options.wsUrl);
20
+ serviceRef.current = service;
21
+ service.setCallbacks({
22
+ onConnected: (sessionId) => {
23
+ setState(service.getState());
24
+ options.onConnected?.(sessionId);
25
+ },
26
+ onDisconnected: () => {
27
+ setState(service.getState());
28
+ options.onDisconnected?.();
29
+ },
30
+ onConfigReceived: () => {
31
+ setState(service.getState());
32
+ options.onConfigReceived?.();
33
+ },
34
+ onBlobReceived: (placement) => {
35
+ options.onBlobReceived?.(placement);
36
+ },
37
+ onBlobSent: (placement) => {
38
+ options.onBlobSent?.(placement);
39
+ },
40
+ onMockupRendered: (result) => {
41
+ setState(service.getState());
42
+ options.onMockupRendered?.(result);
43
+ },
44
+ onAllMockupsRendered: (results) => {
45
+ setState(service.getState());
46
+ options.onAllMockupsRendered?.(results);
47
+ },
48
+ onError: (error) => {
49
+ setState(service.getState());
50
+ options.onError?.(error);
51
+ }
52
+ // REMOVED: onLog callback was causing setState on every log message,
53
+ // which triggered re-renders during canvas drag operations
54
+ });
55
+ return () => {
56
+ service.disconnect();
57
+ };
58
+ }, [options.wsUrl]);
59
+ const connect = useCallback(() => {
60
+ serviceRef.current?.connect();
61
+ }, []);
62
+ const disconnect = useCallback(() => {
63
+ serviceRef.current?.disconnect();
64
+ }, []);
65
+ const sendConfig = useCallback((config) => {
66
+ return serviceRef.current?.sendConfig(config) || false;
67
+ }, []);
68
+ const updateMockupIds = useCallback((mockupIds) => {
69
+ return serviceRef.current?.updateMockupIds(mockupIds) || false;
70
+ }, []);
71
+ const updatePlacementSettings = useCallback((settings) => {
72
+ return serviceRef.current?.updatePlacementSettings(settings) || false;
73
+ }, []);
74
+ const sendCanvasBlob = useCallback((placement, blob, mockupCount, baseThrottleMs) => {
75
+ return serviceRef.current?.sendCanvasBlob(placement, blob, mockupCount, baseThrottleMs) || false;
76
+ }, []);
77
+ const sendColorBlob = useCallback((placement, hexColor) => {
78
+ return serviceRef.current?.sendColorBlob(placement, hexColor) || false;
79
+ }, []);
80
+ const createEmptyCanvasBlob = useCallback((width, height) => {
81
+ return serviceRef.current?.createEmptyCanvasBlob(width, height) || Promise.reject(new Error("Service not initialized"));
82
+ }, []);
83
+ const sendInitialEmptyCanvases = useCallback(async (placements) => {
84
+ await serviceRef.current?.sendInitialEmptyCanvases(placements);
85
+ }, []);
86
+ const setInitialData = useCallback((canvasBlobs, colors) => {
87
+ serviceRef.current?.setInitialData(canvasBlobs, colors);
88
+ }, []);
89
+ const clearLogs = useCallback(() => {
90
+ serviceRef.current?.clearLogs();
91
+ setState(serviceRef.current?.getState() || state);
92
+ }, [state]);
93
+ const clearMockups = useCallback(() => {
94
+ serviceRef.current?.clearMockups();
95
+ setState(serviceRef.current?.getState() || state);
96
+ }, [state]);
97
+ const flushPendingBlobs = useCallback(() => {
98
+ serviceRef.current?.flushPendingBlobs();
99
+ }, []);
100
+ const hasPendingBlobs = useCallback(() => {
101
+ return serviceRef.current?.hasPendingBlobs() || false;
102
+ }, []);
103
+ return {
104
+ ...state,
105
+ connect,
106
+ disconnect,
107
+ sendConfig,
108
+ updateMockupIds,
109
+ updatePlacementSettings,
110
+ sendCanvasBlob,
111
+ sendColorBlob,
112
+ createEmptyCanvasBlob,
113
+ sendInitialEmptyCanvases,
114
+ setInitialData,
115
+ clearLogs,
116
+ clearMockups,
117
+ flushPendingBlobs,
118
+ hasPendingBlobs
119
+ };
120
+ }
121
+
122
+ // src/framework/adapters/react.ts
123
+ var ReactAdapter = class {
124
+ name = "react";
125
+ React;
126
+ hooks;
127
+ constructor(React, hooks) {
128
+ this.React = React;
129
+ this.hooks = hooks || React;
130
+ }
131
+ /**
132
+ * Create a stateful value using useState
133
+ */
134
+ createState(initialValue) {
135
+ const [value, setValue] = this.hooks.useState(initialValue);
136
+ return {
137
+ get: () => value,
138
+ set: (newValue) => {
139
+ setValue(newValue);
140
+ },
141
+ subscribe: (callback) => {
142
+ this.hooks.useEffect(() => {
143
+ callback(value);
144
+ }, [value]);
145
+ return () => {
146
+ };
147
+ }
148
+ };
149
+ }
150
+ /**
151
+ * Create a context provider/consumer
152
+ */
153
+ createContext(name) {
154
+ const Context = this.React.createContext(void 0);
155
+ return {
156
+ provide: (value) => {
157
+ return this.React.createElement(Context.Provider, { value });
158
+ },
159
+ consume: () => {
160
+ return this.hooks.useContext(Context);
161
+ },
162
+ subscribe: (callback) => {
163
+ const value = this.hooks.useContext(Context);
164
+ this.hooks.useEffect(() => {
165
+ if (value !== void 0) {
166
+ callback(value);
167
+ }
168
+ }, [value]);
169
+ return () => {
170
+ };
171
+ }
172
+ };
173
+ }
174
+ /**
175
+ * Register lifecycle hooks
176
+ */
177
+ useLifecycle(lifecycle) {
178
+ this.hooks.useEffect(() => {
179
+ lifecycle.onMount?.();
180
+ return () => {
181
+ lifecycle.onUnmount?.();
182
+ };
183
+ }, []);
184
+ this.hooks.useEffect(() => {
185
+ lifecycle.onUpdate?.({});
186
+ });
187
+ }
188
+ /**
189
+ * Register event handlers
190
+ */
191
+ useEvents(handlers) {
192
+ handlers.forEach(({ name, handler }) => {
193
+ this.hooks.useCallback(handler, []);
194
+ });
195
+ }
196
+ /**
197
+ * Create a ref to a DOM element
198
+ */
199
+ createRef() {
200
+ return this.hooks.useRef(null);
201
+ }
202
+ /**
203
+ * Render a component
204
+ */
205
+ render(component, props) {
206
+ return component.render(this);
207
+ }
208
+ /**
209
+ * Get React-specific utilities
210
+ */
211
+ getUtilities() {
212
+ return {
213
+ batchUpdates: (callback) => {
214
+ callback();
215
+ },
216
+ nextTick: (callback) => {
217
+ Promise.resolve().then(callback);
218
+ },
219
+ computed: (deps, compute) => {
220
+ return this.hooks.useMemo(compute, deps);
221
+ },
222
+ memo: (value, deps) => {
223
+ return this.hooks.useMemo(() => value, deps);
224
+ }
225
+ };
226
+ }
227
+ };
228
+ function createReactComponent(descriptor, React) {
229
+ return function Component(props) {
230
+ const adapter = new ReactAdapter(React, React);
231
+ if (descriptor.lifecycle) {
232
+ adapter.useLifecycle(descriptor.lifecycle);
233
+ }
234
+ return adapter.render(descriptor, props);
235
+ };
236
+ }
237
+ function useFrameworkAdapter(React) {
238
+ return new ReactAdapter(React, React);
239
+ }
240
+ export {
241
+ ReactAdapter,
242
+ createReactComponent,
243
+ useFrameworkAdapter as useReactAdapter,
244
+ useRealtimeMockup
245
+ };