@varianta/sdk 0.1.8 → 0.1.9

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/react.esm.js CHANGED
@@ -1,322 +1,321 @@
1
- import { jsx as O } from "react/jsx-runtime";
2
- import { forwardRef as j, useRef as D, useEffect as p, useImperativeHandle as H, useState as l, useCallback as c } from "react";
3
- import { initCustomizer as J } from "./index.esm.js";
4
- const K = j(
5
- (b, T) => {
1
+ import { jsx as M } from "react/jsx-runtime";
2
+ import { forwardRef as B, useRef as A, useEffect as v, useImperativeHandle as j, useState as d, useCallback as a } from "react";
3
+ import { initCustomizer as H, CustomizerError as u } from "./index.esm.js";
4
+ const J = B(
5
+ (U, S) => {
6
6
  const {
7
- templateId: g,
8
- productId: w,
9
- apiUrl: r,
10
- theme: s = "light",
11
- mode: z = "edit",
12
- debug: F = !1,
13
- className: U,
14
- style: k,
15
- initialDesign: h,
16
- showCloseButton: V,
17
- showSaveButton: A,
18
- onReady: d,
7
+ templateId: w,
8
+ productId: L,
9
+ apiUrl: t,
10
+ theme: l = "light",
11
+ mode: g = "edit",
12
+ debug: O = !1,
13
+ className: _,
14
+ style: V,
15
+ initialDesign: z,
16
+ showCloseButton: Z,
17
+ showSaveButton: p,
18
+ onReady: f,
19
19
  onChange: y,
20
- onLayerSelect: f,
20
+ onLayerSelect: I,
21
21
  onLayerAdd: m,
22
- onLayerRemove: E,
23
- onLayerUpdate: L,
24
- onError: R,
25
- onFinalize: C,
26
- onViewChange: a,
27
- onClose: v,
28
- onSave: S
29
- } = b, I = D(null), e = D(null), i = D({
30
- onReady: d,
22
+ onLayerRemove: h,
23
+ onLayerUpdate: T,
24
+ onError: E,
25
+ onFinalize: R,
26
+ onViewChange: s,
27
+ onClose: N,
28
+ onSave: C
29
+ } = U, D = A(null), e = A(null), c = A({
30
+ onReady: f,
31
31
  onChange: y,
32
- onLayerSelect: f,
32
+ onLayerSelect: I,
33
33
  onLayerAdd: m,
34
- onLayerRemove: E,
35
- onLayerUpdate: L,
36
- onError: R,
37
- onFinalize: C,
38
- onViewChange: a,
39
- onClose: v,
40
- onSave: S
34
+ onLayerRemove: h,
35
+ onLayerUpdate: T,
36
+ onError: E,
37
+ onFinalize: R,
38
+ onViewChange: s,
39
+ onClose: N,
40
+ onSave: C
41
41
  });
42
- return p(() => {
43
- i.current = {
44
- onReady: d,
42
+ return v(() => {
43
+ c.current = {
44
+ onReady: f,
45
45
  onChange: y,
46
- onLayerSelect: f,
46
+ onLayerSelect: I,
47
47
  onLayerAdd: m,
48
- onLayerRemove: E,
49
- onLayerUpdate: L,
50
- onError: R,
51
- onFinalize: C,
52
- onViewChange: a,
53
- onClose: v,
54
- onSave: S
48
+ onLayerRemove: h,
49
+ onLayerUpdate: T,
50
+ onError: E,
51
+ onFinalize: R,
52
+ onViewChange: s,
53
+ onClose: N,
54
+ onSave: C
55
55
  };
56
- }, [d, y, f, m, E, L, R, C, a, v, S]), p(() => {
57
- if (!I.current) return;
58
- const o = {
59
- templateId: g,
60
- productId: w,
61
- apiUrl: r,
62
- theme: s,
63
- mode: z,
64
- debug: F,
65
- initialDesign: h,
66
- showCloseButton: V,
67
- showSaveButton: A,
56
+ }, [f, y, I, m, h, T, E, R, s, N, C]), v(() => {
57
+ if (!D.current) return;
58
+ const n = {
59
+ templateId: w,
60
+ productId: L,
61
+ apiUrl: t,
62
+ theme: l,
63
+ mode: g,
64
+ debug: O,
65
+ initialDesign: z,
66
+ showCloseButton: Z,
67
+ showSaveButton: p,
68
68
  // Use callback refs to always get latest callbacks
69
- onReady: () => i.current.onReady?.(),
70
- onChange: (t) => i.current.onChange?.(t),
71
- onLayerSelect: (t) => i.current.onLayerSelect?.(t),
72
- onLayerAdd: (t) => i.current.onLayerAdd?.(t),
73
- onLayerRemove: (t) => i.current.onLayerRemove?.(t),
74
- onLayerUpdate: (t) => i.current.onLayerUpdate?.(t),
75
- onError: (t) => i.current.onError?.(t),
76
- onFinalize: (t) => i.current.onFinalize?.(t),
77
- onViewChange: (t) => i.current.onViewChange?.(t),
78
- onClose: () => i.current.onClose?.(),
79
- onSave: (t) => i.current.onSave?.(t)
69
+ onReady: () => c.current.onReady?.(),
70
+ onChange: (r) => c.current.onChange?.(r),
71
+ onLayerSelect: (r) => c.current.onLayerSelect?.(r),
72
+ onLayerAdd: (r) => c.current.onLayerAdd?.(r),
73
+ onLayerRemove: (r) => c.current.onLayerRemove?.(r),
74
+ onLayerUpdate: (r) => c.current.onLayerUpdate?.(r),
75
+ onError: (r) => c.current.onError?.(r),
76
+ onFinalize: (r) => c.current.onFinalize?.(r),
77
+ onViewChange: (r) => c.current.onViewChange?.(r),
78
+ onClose: () => c.current.onClose?.(),
79
+ onSave: (r) => c.current.onSave?.(r)
80
80
  };
81
81
  try {
82
- const t = J(I.current, o);
83
- e.current = t;
84
- } catch (t) {
85
- console.error("[Customizer React] Failed to initialize:", t), i.current.onError?.({
86
- code: "INIT_ERROR",
87
- message: t instanceof Error ? t.message : "Unknown error",
88
- details: t
89
- });
82
+ const r = H(D.current, n);
83
+ e.current = r;
84
+ } catch (r) {
85
+ console.error("[Customizer React] Failed to initialize:", r);
86
+ const x = r instanceof u ? r : new u("INIT_ERROR", r instanceof Error ? r.message : "Unknown error", r);
87
+ c.current.onError?.(x);
90
88
  }
91
89
  return () => {
92
90
  e.current && (e.current.destroy(), e.current = null);
93
91
  };
94
- }, [g, w, r, F, h, V, A]), p(() => {
95
- e.current && e.current.setTheme(s);
96
- }, [s]), p(() => {
97
- e.current && e.current.setMode(z);
98
- }, [z]), H(
99
- T,
92
+ }, [w, L, t, O, z, Z, p]), v(() => {
93
+ e.current && e.current.setTheme(l);
94
+ }, [l]), v(() => {
95
+ e.current && e.current.setMode(g);
96
+ }, [g]), j(
97
+ S,
100
98
  () => ({
101
99
  getDesign: () => {
102
100
  if (!e.current)
103
- throw new Error("Editor not initialized");
101
+ throw new u("NOT_INITIALIZED", "Editor not initialized");
104
102
  return e.current.getDesign();
105
103
  },
106
- setDesign: (o) => {
104
+ setDesign: (n) => {
107
105
  if (!e.current)
108
- throw new Error("Editor not initialized");
109
- e.current.setDesign(o);
106
+ throw new u("NOT_INITIALIZED", "Editor not initialized");
107
+ e.current.setDesign(n);
110
108
  },
111
109
  undo: () => {
112
110
  if (!e.current)
113
- throw new Error("Editor not initialized");
111
+ throw new u("NOT_INITIALIZED", "Editor not initialized");
114
112
  e.current.undo();
115
113
  },
116
114
  redo: () => {
117
115
  if (!e.current)
118
- throw new Error("Editor not initialized");
116
+ throw new u("NOT_INITIALIZED", "Editor not initialized");
119
117
  e.current.redo();
120
118
  },
121
119
  canUndo: () => e.current ? e.current.canUndo() : !1,
122
120
  canRedo: () => e.current ? e.current.canRedo() : !1,
123
- finalize: async () => {
121
+ finalize: async (n) => {
124
122
  if (!e.current)
125
- throw new Error("Editor not initialized");
126
- return e.current.finalize();
123
+ throw new u("NOT_INITIALIZED", "Editor not initialized");
124
+ return e.current.finalize(n);
127
125
  },
128
- waitForResult: async (o, t) => {
126
+ waitForResult: async (n, r) => {
129
127
  if (!e.current)
130
- throw new Error("Editor not initialized");
131
- return e.current.waitForResult(o, t);
128
+ throw new u("NOT_INITIALIZED", "Editor not initialized");
129
+ return e.current.waitForResult(n, r);
132
130
  },
133
- addTextLayer: (o) => {
131
+ addTextLayer: (n) => {
134
132
  if (!e.current)
135
- throw new Error("Editor not initialized");
136
- e.current.addTextLayer(o);
133
+ throw new u("NOT_INITIALIZED", "Editor not initialized");
134
+ e.current.addTextLayer(n);
137
135
  },
138
- addImageLayer: async (o) => {
136
+ addImageLayer: async (n) => {
139
137
  if (!e.current)
140
- throw new Error("Editor not initialized");
141
- return e.current.addImageLayer(o);
138
+ throw new u("NOT_INITIALIZED", "Editor not initialized");
139
+ return e.current.addImageLayer(n);
142
140
  },
143
- removeLayer: (o) => {
141
+ removeLayer: (n) => {
144
142
  if (!e.current)
145
- throw new Error("Editor not initialized");
146
- e.current.removeLayer(o);
143
+ throw new u("NOT_INITIALIZED", "Editor not initialized");
144
+ e.current.removeLayer(n);
147
145
  },
148
- selectLayer: (o) => {
146
+ selectLayer: (n) => {
149
147
  if (!e.current)
150
- throw new Error("Editor not initialized");
151
- e.current.selectLayer(o);
148
+ throw new u("NOT_INITIALIZED", "Editor not initialized");
149
+ e.current.selectLayer(n);
152
150
  },
153
151
  getSelectedLayerId: () => e.current ? e.current.getSelectedLayerId() : null,
154
152
  getActiveView: () => e.current ? e.current.getActiveView() : null,
155
153
  getViews: () => e.current ? e.current.getViews() : [],
156
- setActiveView: (o) => {
154
+ setActiveView: (n) => {
157
155
  if (!e.current)
158
- throw new Error("Editor not initialized");
159
- e.current.setActiveView(o);
156
+ throw new u("NOT_INITIALIZED", "Editor not initialized");
157
+ e.current.setActiveView(n);
160
158
  },
161
- setTheme: (o) => {
159
+ setTheme: (n) => {
162
160
  if (!e.current)
163
- throw new Error("Editor not initialized");
164
- e.current.setTheme(o);
161
+ throw new u("NOT_INITIALIZED", "Editor not initialized");
162
+ e.current.setTheme(n);
165
163
  },
166
- setMode: (o) => {
164
+ setMode: (n) => {
167
165
  if (!e.current)
168
- throw new Error("Editor not initialized");
169
- e.current.setMode(o);
166
+ throw new u("NOT_INITIALIZED", "Editor not initialized");
167
+ e.current.setMode(n);
170
168
  },
171
169
  destroy: () => {
172
170
  e.current && (e.current.destroy(), e.current = null);
173
171
  },
174
172
  getElement: () => {
175
173
  if (!e.current)
176
- throw new Error("Editor not initialized");
174
+ throw new u("NOT_INITIALIZED", "Editor not initialized");
177
175
  return e.current.getElement();
178
176
  }
179
177
  }),
180
178
  []
181
179
  // Empty deps is OK - we always read from instanceRef.current
182
- ), /* @__PURE__ */ O(
180
+ ), /* @__PURE__ */ M(
183
181
  "div",
184
182
  {
185
- ref: I,
186
- className: U,
183
+ ref: D,
184
+ className: _,
187
185
  style: {
188
186
  width: "100%",
189
187
  height: "100%",
190
- ...k
188
+ ...V
191
189
  }
192
190
  }
193
191
  );
194
192
  }
195
193
  );
196
- K.displayName = "Customizer";
197
- function P(b = {}) {
194
+ J.displayName = "Customizer";
195
+ function P(U = {}) {
198
196
  const {
199
- autoSave: T = !1,
200
- autoSaveKey: g = "customizer-design",
201
- autoSaveDebounce: w = 1e3
202
- } = b, r = D(null), [s, z] = l(null), [F, U] = l(!1), [k, h] = l(!1), [V, A] = l(null), [d, y] = l(!1), [f, m] = l(!1), [E, L] = l(
197
+ autoSave: S = !1,
198
+ autoSaveKey: w = "customizer-design",
199
+ autoSaveDebounce: L = 1e3
200
+ } = U, t = A(null), [l, g] = d(null), [O, _] = d(!1), [V, z] = d(!1), [Z, p] = d(null), [f, y] = d(!1), [I, m] = d(!1), [h, T] = d(
203
201
  null
204
- ), [R, C] = l(null), a = D(void 0);
205
- p(() => {
206
- if (!(!T || !s))
207
- return a.current && clearTimeout(a.current), a.current = setTimeout(() => {
202
+ ), [E, R] = d(null), s = A(void 0);
203
+ v(() => {
204
+ if (!(!S || !l))
205
+ return s.current && clearTimeout(s.current), s.current = setTimeout(() => {
208
206
  try {
209
- localStorage.setItem(g, JSON.stringify(s));
210
- } catch (n) {
211
- console.error("[useCustomizer] Auto-save failed:", n);
207
+ localStorage.setItem(w, JSON.stringify(l));
208
+ } catch (o) {
209
+ console.error("[useCustomizer] Auto-save failed:", o);
212
210
  }
213
- }, w), () => {
214
- a.current && clearTimeout(a.current);
211
+ }, L), () => {
212
+ s.current && clearTimeout(s.current);
215
213
  };
216
- }, [s, T, g, w]);
217
- const v = c(() => {
218
- if (!r.current) return null;
214
+ }, [l, S, w, L]);
215
+ const N = a(() => {
216
+ if (!t.current) return null;
219
217
  try {
220
- return r.current.getDesign();
221
- } catch (n) {
222
- return console.error("[useCustomizer] getDesign failed:", n), null;
218
+ return t.current.getDesign();
219
+ } catch (o) {
220
+ return console.error("[useCustomizer] getDesign failed:", o), null;
223
221
  }
224
- }, []), S = c((n) => {
225
- if (r.current)
222
+ }, []), C = a((o) => {
223
+ if (t.current)
226
224
  try {
227
- r.current.setDesign(n), z(n);
228
- } catch (u) {
229
- console.error("[useCustomizer] setDesign failed:", u);
225
+ t.current.setDesign(o), g(o);
226
+ } catch (i) {
227
+ console.error("[useCustomizer] setDesign failed:", i);
230
228
  }
231
- }, []), I = c(() => {
232
- if (r.current)
229
+ }, []), D = a(() => {
230
+ if (t.current)
233
231
  try {
234
- r.current.undo(), U(r.current.canUndo()), h(r.current.canRedo());
235
- } catch (n) {
236
- console.error("[useCustomizer] undo failed:", n);
232
+ t.current.undo(), _(t.current.canUndo()), z(t.current.canRedo());
233
+ } catch (o) {
234
+ console.error("[useCustomizer] undo failed:", o);
237
235
  }
238
- }, []), e = c(() => {
239
- if (r.current)
236
+ }, []), e = a(() => {
237
+ if (t.current)
240
238
  try {
241
- r.current.redo(), U(r.current.canUndo()), h(r.current.canRedo());
242
- } catch (n) {
243
- console.error("[useCustomizer] redo failed:", n);
239
+ t.current.redo(), _(t.current.canUndo()), z(t.current.canRedo());
240
+ } catch (o) {
241
+ console.error("[useCustomizer] redo failed:", o);
244
242
  }
245
- }, []), i = c(async () => {
246
- if (!r.current || d) return null;
243
+ }, []), c = a(async (o) => {
244
+ if (!t.current || f) return null;
247
245
  y(!0);
248
246
  try {
249
- const n = await r.current.finalize();
250
- return L(n), n;
251
- } catch (n) {
252
- return console.error("[useCustomizer] finalize failed:", n), null;
247
+ const i = await t.current.finalize(o);
248
+ return T(i), i;
249
+ } catch (i) {
250
+ return console.error("[useCustomizer] finalize failed:", i), null;
253
251
  } finally {
254
252
  y(!1);
255
253
  }
256
- }, [d]), o = c(async (n, u) => {
257
- if (!r.current || f) return null;
254
+ }, [f]), n = a(async (o, i) => {
255
+ if (!t.current || I) return null;
258
256
  m(!0);
259
257
  try {
260
- const x = await r.current.waitForResult(n, u);
261
- return C(x), x;
262
- } catch (x) {
263
- return console.error("[useCustomizer] waitForResult failed:", x), null;
258
+ const F = await t.current.waitForResult(o, i);
259
+ return R(F), F;
260
+ } catch (F) {
261
+ return console.error("[useCustomizer] waitForResult failed:", F), null;
264
262
  } finally {
265
263
  m(!1);
266
264
  }
267
- }, [f]), t = c((n) => {
268
- if (r.current)
265
+ }, [I]), r = a((o) => {
266
+ if (t.current)
269
267
  try {
270
- r.current.addTextLayer(n);
271
- } catch (u) {
272
- console.error("[useCustomizer] addTextLayer failed:", u);
268
+ t.current.addTextLayer(o);
269
+ } catch (i) {
270
+ console.error("[useCustomizer] addTextLayer failed:", i);
273
271
  }
274
- }, []), N = c(async (n) => {
275
- if (r.current)
272
+ }, []), x = a(async (o) => {
273
+ if (t.current)
276
274
  try {
277
- await r.current.addImageLayer(n);
278
- } catch (u) {
279
- console.error("[useCustomizer] addImageLayer failed:", u);
275
+ await t.current.addImageLayer(o);
276
+ } catch (i) {
277
+ console.error("[useCustomizer] addImageLayer failed:", i);
280
278
  }
281
- }, []), M = c((n) => {
282
- if (r.current)
279
+ }, []), b = a((o) => {
280
+ if (t.current)
283
281
  try {
284
- r.current.removeLayer(n);
285
- } catch (u) {
286
- console.error("[useCustomizer] removeLayer failed:", u);
282
+ t.current.removeLayer(o);
283
+ } catch (i) {
284
+ console.error("[useCustomizer] removeLayer failed:", i);
287
285
  }
288
- }, []), B = c((n) => {
289
- if (r.current)
286
+ }, []), k = a((o) => {
287
+ if (t.current)
290
288
  try {
291
- r.current.selectLayer(n), A(n);
292
- } catch (u) {
293
- console.error("[useCustomizer] selectLayer failed:", u);
289
+ t.current.selectLayer(o), p(o);
290
+ } catch (i) {
291
+ console.error("[useCustomizer] selectLayer failed:", i);
294
292
  }
295
293
  }, []);
296
294
  return {
297
- customizerRef: r,
298
- design: s,
299
- canUndo: F,
300
- canRedo: k,
301
- selectedLayerId: V,
302
- isFinalizing: d,
303
- isRendering: f,
304
- finalizeResult: E,
305
- renderResult: R,
306
- getDesign: v,
307
- setDesign: S,
308
- undo: I,
295
+ customizerRef: t,
296
+ design: l,
297
+ canUndo: O,
298
+ canRedo: V,
299
+ selectedLayerId: Z,
300
+ isFinalizing: f,
301
+ isRendering: I,
302
+ finalizeResult: h,
303
+ renderResult: E,
304
+ getDesign: N,
305
+ setDesign: C,
306
+ undo: D,
309
307
  redo: e,
310
- finalize: i,
311
- waitForResult: o,
312
- addTextLayer: t,
313
- addImageLayer: N,
314
- removeLayer: M,
315
- selectLayer: B
308
+ finalize: c,
309
+ waitForResult: n,
310
+ addTextLayer: r,
311
+ addImageLayer: x,
312
+ removeLayer: b,
313
+ selectLayer: k
316
314
  };
317
315
  }
318
316
  export {
319
- K as Customizer,
317
+ J as Customizer,
318
+ u as CustomizerError,
320
319
  P as useCustomizer
321
320
  };
322
321
  //# sourceMappingURL=react.esm.js.map