@figma-vars/hooks 1.3.3 → 1.4.3

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.
Files changed (46) hide show
  1. package/README.md +85 -19
  2. package/dist/figma-vars-hooks.js +312 -296
  3. package/dist/figma-vars-hooks.umd.cjs +3 -3
  4. package/dist/src/api/fetcher.d.ts +28 -0
  5. package/dist/src/api/index.d.ts +25 -0
  6. package/dist/src/api/mutator.d.ts +33 -0
  7. package/dist/src/api/mutator.test.d.ts +1 -0
  8. package/dist/src/constants/index.d.ts +89 -0
  9. package/dist/src/contexts/FigmaVarsProvider.d.ts +56 -0
  10. package/dist/src/contexts/index.d.ts +21 -0
  11. package/dist/src/hooks/index.d.ts +143 -0
  12. package/dist/src/hooks/useBulkUpdateVariables.d.ts +46 -0
  13. package/dist/src/hooks/useCreateVariable.d.ts +45 -0
  14. package/dist/src/hooks/useDeleteVariable.d.ts +33 -0
  15. package/dist/src/hooks/useFigmaToken.d.ts +21 -0
  16. package/dist/src/hooks/useMutation.d.ts +53 -0
  17. package/dist/src/hooks/useUpdateVariable.d.ts +40 -0
  18. package/dist/src/hooks/useVariableCollections.d.ts +35 -0
  19. package/dist/src/hooks/useVariableModes.d.ts +32 -0
  20. package/dist/src/hooks/useVariables.d.ts +32 -0
  21. package/dist/src/index.d.ts +80 -0
  22. package/dist/src/types/contexts.d.ts +77 -0
  23. package/dist/src/types/figma.d.ts +244 -0
  24. package/dist/src/types/hooks.d.ts +67 -0
  25. package/dist/src/types/index.d.ts +30 -0
  26. package/dist/src/types/mutations.d.ts +314 -0
  27. package/dist/src/utils/filterVariables.d.ts +31 -0
  28. package/dist/src/utils/index.d.ts +21 -0
  29. package/dist/tests/FigmaVarsProvider.test.d.ts +1 -0
  30. package/dist/tests/api/fetcher.test.d.ts +1 -0
  31. package/dist/tests/api/mutator.test.d.ts +1 -0
  32. package/dist/tests/constants/index.test.d.ts +1 -0
  33. package/dist/tests/hooks/useBulkUpdateVariables.test.d.ts +1 -0
  34. package/dist/tests/hooks/useCreateVariable.test.d.ts +1 -0
  35. package/dist/tests/hooks/useDeleteVariable.test.d.ts +1 -0
  36. package/dist/tests/hooks/useMutation.test.d.ts +1 -0
  37. package/dist/tests/hooks/useUpdateVariable.test.d.ts +1 -0
  38. package/dist/tests/hooks/useVariableCollections.test.d.ts +1 -0
  39. package/dist/tests/hooks/useVariableModes.test.d.ts +1 -0
  40. package/dist/tests/hooks/useVariables.test.d.ts +1 -0
  41. package/dist/tests/mocks/variables.d.ts +2 -0
  42. package/dist/tests/setup.d.ts +0 -0
  43. package/dist/tests/test-utils.d.ts +10 -0
  44. package/dist/tests/test-utils.test.d.ts +1 -0
  45. package/package.json +4 -2
  46. package/dist/index.d.ts +0 -1221
@@ -1,20 +1,20 @@
1
- import { jsx as we } from "react/jsx-runtime";
2
- import et, { createContext as Qt, useContext as Zt, useEffect as Re, useLayoutEffect as ge, useRef as B, useMemo as ft, useCallback as lt, useDebugValue as ye, useReducer as Te } from "react";
3
- const te = Qt(
1
+ import { jsx as Oe } from "react/jsx-runtime";
2
+ import et, { createContext as Zt, useContext as te, useEffect as ve, useLayoutEffect as we, useRef as $, useMemo as ft, useCallback as lt, useDebugValue as Re, useReducer as Te } from "react";
3
+ const ee = Zt(
4
4
  void 0
5
5
  ), En = ({
6
6
  children: t,
7
7
  token: e,
8
8
  fileKey: n
9
- }) => /* @__PURE__ */ we(te.Provider, { value: { token: e, fileKey: n }, children: t }), X = () => {
10
- const t = Zt(te);
9
+ }) => /* @__PURE__ */ Oe(ee.Provider, { value: { token: e, fileKey: n }, children: t }), nt = () => {
10
+ const t = te(ee);
11
11
  if (t === void 0)
12
12
  throw new Error(
13
13
  "useFigmaTokenContext must be used within a FigmaVarsProvider"
14
14
  );
15
15
  return t;
16
16
  };
17
- var at = { exports: {} }, St = {};
17
+ var at = { exports: {} }, _t = {};
18
18
  /**
19
19
  * @license React
20
20
  * use-sync-external-store-shim.production.js
@@ -24,32 +24,32 @@ var at = { exports: {} }, St = {};
24
24
  * This source code is licensed under the MIT license found in the
25
25
  * LICENSE file in the root directory of this source tree.
26
26
  */
27
- var kt;
28
- function Ae() {
29
- if (kt) return St;
30
- kt = 1;
27
+ var Ht;
28
+ function ye() {
29
+ if (Ht) return _t;
30
+ Ht = 1;
31
31
  var t = et;
32
32
  function e(u, d) {
33
33
  return u === d && (u !== 0 || 1 / u === 1 / d) || u !== u && d !== d;
34
34
  }
35
- var n = typeof Object.is == "function" ? Object.is : e, r = t.useState, o = t.useEffect, s = t.useLayoutEffect, a = t.useDebugValue;
36
- function m(u, d) {
37
- var c = d(), E = r({ inst: { value: c, getSnapshot: d } }), l = E[0].inst, D = E[1];
35
+ var n = typeof Object.is == "function" ? Object.is : e, r = t.useState, o = t.useEffect, s = t.useLayoutEffect, i = t.useDebugValue;
36
+ function E(u, d) {
37
+ var c = d(), p = r({ inst: { value: c, getSnapshot: d } }), l = p[0].inst, D = p[1];
38
38
  return s(
39
39
  function() {
40
- l.value = c, l.getSnapshot = d, _(l) && D({ inst: l });
40
+ l.value = c, l.getSnapshot = d, h(l) && D({ inst: l });
41
41
  },
42
42
  [u, c, d]
43
43
  ), o(
44
44
  function() {
45
- return _(l) && D({ inst: l }), u(function() {
46
- _(l) && D({ inst: l });
45
+ return h(l) && D({ inst: l }), u(function() {
46
+ h(l) && D({ inst: l });
47
47
  });
48
48
  },
49
49
  [u]
50
- ), a(c), c;
50
+ ), i(c), c;
51
51
  }
52
- function _(u) {
52
+ function h(u) {
53
53
  var d = u.getSnapshot;
54
54
  u = u.value;
55
55
  try {
@@ -62,10 +62,10 @@ function Ae() {
62
62
  function y(u, d) {
63
63
  return d();
64
64
  }
65
- var O = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? y : m;
66
- return St.useSyncExternalStore = t.useSyncExternalStore !== void 0 ? t.useSyncExternalStore : O, St;
65
+ var O = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? y : E;
66
+ return _t.useSyncExternalStore = t.useSyncExternalStore !== void 0 ? t.useSyncExternalStore : O, _t;
67
67
  }
68
- var ht = {};
68
+ var St = {};
69
69
  /**
70
70
  * @license React
71
71
  * use-sync-external-store-shim.development.js
@@ -75,67 +75,67 @@ var ht = {};
75
75
  * This source code is licensed under the MIT license found in the
76
76
  * LICENSE file in the root directory of this source tree.
77
77
  */
78
- var $t;
79
- function De() {
80
- return $t || ($t = 1, process.env.NODE_ENV !== "production" && function() {
81
- function t(c, E) {
82
- return c === E && (c !== 0 || 1 / c === 1 / E) || c !== c && E !== E;
78
+ var kt;
79
+ function ge() {
80
+ return kt || (kt = 1, process.env.NODE_ENV !== "production" && function() {
81
+ function t(c, p) {
82
+ return c === p && (c !== 0 || 1 / c === 1 / p) || c !== c && p !== p;
83
83
  }
84
- function e(c, E) {
84
+ function e(c, p) {
85
85
  O || o.startTransition === void 0 || (O = !0, console.error(
86
86
  "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
87
87
  ));
88
- var l = E();
88
+ var l = p();
89
89
  if (!u) {
90
- var D = E();
90
+ var D = p();
91
91
  s(l, D) || (console.error(
92
92
  "The result of getSnapshot should be cached to avoid an infinite loop"
93
93
  ), u = !0);
94
94
  }
95
- D = a({
96
- inst: { value: l, getSnapshot: E }
95
+ D = i({
96
+ inst: { value: l, getSnapshot: p }
97
97
  });
98
- var i = D[0].inst, M = D[1];
99
- return _(
98
+ var a = D[0].inst, P = D[1];
99
+ return h(
100
100
  function() {
101
- i.value = l, i.getSnapshot = E, n(i) && M({ inst: i });
101
+ a.value = l, a.getSnapshot = p, n(a) && P({ inst: a });
102
102
  },
103
- [c, l, E]
104
- ), m(
103
+ [c, l, p]
104
+ ), E(
105
105
  function() {
106
- return n(i) && M({ inst: i }), c(function() {
107
- n(i) && M({ inst: i });
106
+ return n(a) && P({ inst: a }), c(function() {
107
+ n(a) && P({ inst: a });
108
108
  });
109
109
  },
110
110
  [c]
111
111
  ), y(l), l;
112
112
  }
113
113
  function n(c) {
114
- var E = c.getSnapshot;
114
+ var p = c.getSnapshot;
115
115
  c = c.value;
116
116
  try {
117
- var l = E();
117
+ var l = p();
118
118
  return !s(c, l);
119
119
  } catch {
120
120
  return !0;
121
121
  }
122
122
  }
123
- function r(c, E) {
124
- return E();
123
+ function r(c, p) {
124
+ return p();
125
125
  }
126
126
  typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
127
- var o = et, s = typeof Object.is == "function" ? Object.is : t, a = o.useState, m = o.useEffect, _ = o.useLayoutEffect, y = o.useDebugValue, O = !1, u = !1, d = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? r : e;
128
- ht.useSyncExternalStore = o.useSyncExternalStore !== void 0 ? o.useSyncExternalStore : d, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
129
- }()), ht;
127
+ var o = et, s = typeof Object.is == "function" ? Object.is : t, i = o.useState, E = o.useEffect, h = o.useLayoutEffect, y = o.useDebugValue, O = !1, u = !1, d = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? r : e;
128
+ St.useSyncExternalStore = o.useSyncExternalStore !== void 0 ? o.useSyncExternalStore : d, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
129
+ }()), St;
130
130
  }
131
- var Ht;
132
- function Ie() {
133
- return Ht || (Ht = 1, process.env.NODE_ENV === "production" ? at.exports = Ae() : at.exports = De()), at.exports;
131
+ var Kt;
132
+ function Ae() {
133
+ return Kt || (Kt = 1, process.env.NODE_ENV === "production" ? at.exports = ye() : at.exports = ge()), at.exports;
134
134
  }
135
- var Le = Ie();
136
- const ee = 0, ne = 1, re = 2, Kt = 3;
137
- var Jt = Object.prototype.hasOwnProperty;
138
- function Tt(t, e) {
135
+ var De = Ae();
136
+ const ne = 0, re = 1, oe = 2, Jt = 3;
137
+ var Yt = Object.prototype.hasOwnProperty;
138
+ function gt(t, e) {
139
139
  var n, r;
140
140
  if (t === e) return !0;
141
141
  if (t && e && (n = t.constructor) === e.constructor) {
@@ -143,27 +143,27 @@ function Tt(t, e) {
143
143
  if (n === RegExp) return t.toString() === e.toString();
144
144
  if (n === Array) {
145
145
  if ((r = t.length) === e.length)
146
- for (; r-- && Tt(t[r], e[r]); ) ;
146
+ for (; r-- && gt(t[r], e[r]); ) ;
147
147
  return r === -1;
148
148
  }
149
149
  if (!n || typeof t == "object") {
150
150
  r = 0;
151
151
  for (n in t)
152
- if (Jt.call(t, n) && ++r && !Jt.call(e, n) || !(n in e) || !Tt(t[n], e[n])) return !1;
152
+ if (Yt.call(t, n) && ++r && !Yt.call(e, n) || !(n in e) || !gt(t[n], e[n])) return !1;
153
153
  return Object.keys(e).length === r;
154
154
  }
155
155
  }
156
156
  return t !== t && e !== e;
157
157
  }
158
- const P = /* @__PURE__ */ new WeakMap(), U = () => {
158
+ const M = /* @__PURE__ */ new WeakMap(), U = () => {
159
159
  }, A = (
160
160
  /*#__NOINLINE__*/
161
161
  U()
162
162
  ), At = Object, f = (t) => t === A, N = (t) => typeof t == "function", G = (t, e) => ({
163
163
  ...t,
164
164
  ...e
165
- }), oe = (t) => N(t.then), Ot = {}, ct = {}, Nt = "undefined", nt = typeof window != Nt, Dt = typeof document != Nt, Ce = nt && "Deno" in window, be = () => nt && typeof window.requestAnimationFrame != Nt, se = (t, e) => {
166
- const n = P.get(t);
165
+ }), se = (t) => N(t.then), Ot = {}, ct = {}, Nt = "undefined", rt = typeof window != Nt, Dt = typeof document != Nt, Ie = rt && "Deno" in window, Le = () => rt && typeof window.requestAnimationFrame != Nt, ie = (t, e) => {
166
+ const n = M.get(t);
167
167
  return [
168
168
  // Getter
169
169
  () => !f(e) && t.get(e) || Ot,
@@ -181,18 +181,18 @@ const P = /* @__PURE__ */ new WeakMap(), U = () => {
181
181
  ];
182
182
  };
183
183
  let It = !0;
184
- const Ve = () => It, [Lt, Ct] = nt && window.addEventListener ? [
184
+ const Ce = () => It, [Lt, Ct] = rt && window.addEventListener ? [
185
185
  window.addEventListener.bind(window),
186
186
  window.removeEventListener.bind(window)
187
187
  ] : [
188
188
  U,
189
189
  U
190
- ], Ne = () => {
190
+ ], be = () => {
191
191
  const t = Dt && document.visibilityState;
192
192
  return f(t) || t !== "hidden";
193
- }, Fe = (t) => (Dt && document.addEventListener("visibilitychange", t), Lt("focus", t), () => {
193
+ }, Ve = (t) => (Dt && document.addEventListener("visibilitychange", t), Lt("focus", t), () => {
194
194
  Dt && document.removeEventListener("visibilitychange", t), Ct("focus", t);
195
- }), xe = (t) => {
195
+ }), Ne = (t) => {
196
196
  const e = () => {
197
197
  It = !0, t();
198
198
  }, n = () => {
@@ -201,32 +201,32 @@ const Ve = () => It, [Lt, Ct] = nt && window.addEventListener ? [
201
201
  return Lt("online", e), Lt("offline", n), () => {
202
202
  Ct("online", e), Ct("offline", n);
203
203
  };
204
- }, Pe = {
205
- isOnline: Ve,
206
- isVisible: Ne
207
- }, Me = {
208
- initFocus: Fe,
209
- initReconnect: xe
210
- }, Yt = !et.useId, tt = !nt || Ce, je = (t) => be() ? window.requestAnimationFrame(t) : setTimeout(t, 1), vt = tt ? Re : ge, wt = typeof navigator < "u" && navigator.connection, zt = !tt && wt && ([
204
+ }, Fe = {
205
+ isOnline: Ce,
206
+ isVisible: be
207
+ }, xe = {
208
+ initFocus: Ve,
209
+ initReconnect: Ne
210
+ }, zt = !et.useId, tt = !rt || Ie, Me = (t) => Le() ? window.requestAnimationFrame(t) : setTimeout(t, 1), vt = tt ? ve : we, wt = typeof navigator < "u" && navigator.connection, Xt = !tt && wt && ([
211
211
  "slow-2g",
212
212
  "2g"
213
213
  ].includes(wt.effectiveType) || wt.saveData), ut = /* @__PURE__ */ new WeakMap(), Rt = (t, e) => At.prototype.toString.call(t) === `[object ${e}]`;
214
- let Ue = 0;
214
+ let Pe = 0;
215
215
  const bt = (t) => {
216
216
  const e = typeof t, n = Rt(t, "Date"), r = Rt(t, "RegExp"), o = Rt(t, "Object");
217
- let s, a;
217
+ let s, i;
218
218
  if (At(t) === t && !n && !r) {
219
219
  if (s = ut.get(t), s) return s;
220
- if (s = ++Ue + "~", ut.set(t, s), Array.isArray(t)) {
221
- for (s = "@", a = 0; a < t.length; a++)
222
- s += bt(t[a]) + ",";
220
+ if (s = ++Pe + "~", ut.set(t, s), Array.isArray(t)) {
221
+ for (s = "@", i = 0; i < t.length; i++)
222
+ s += bt(t[i]) + ",";
223
223
  ut.set(t, s);
224
224
  }
225
225
  if (o) {
226
226
  s = "#";
227
- const m = At.keys(t).sort();
228
- for (; !f(a = m.pop()); )
229
- f(t[a]) || (s += a + ":" + bt(t[a]) + ",");
227
+ const E = At.keys(t).sort();
228
+ for (; !f(i = E.pop()); )
229
+ f(t[i]) || (s += i + ":" + bt(t[i]) + ",");
230
230
  ut.set(t, s);
231
231
  }
232
232
  } else
@@ -245,22 +245,22 @@ const bt = (t) => {
245
245
  e
246
246
  ];
247
247
  };
248
- let Ge = 0;
249
- const Vt = () => ++Ge;
250
- async function ie(...t) {
248
+ let je = 0;
249
+ const Vt = () => ++je;
250
+ async function ae(...t) {
251
251
  const [e, n, r, o] = t, s = G({
252
252
  populateCache: !0,
253
253
  throwOnError: !0
254
254
  }, typeof o == "boolean" ? {
255
255
  revalidate: o
256
256
  } : o || {});
257
- let a = s.populateCache;
258
- const m = s.rollbackOnError;
259
- let _ = s.optimisticData;
260
- const y = (d) => typeof m == "function" ? m(d) : m !== !1, O = s.throwOnError;
257
+ let i = s.populateCache;
258
+ const E = s.rollbackOnError;
259
+ let h = s.optimisticData;
260
+ const y = (d) => typeof E == "function" ? E(d) : E !== !1, O = s.throwOnError;
261
261
  if (N(n)) {
262
- const d = n, c = [], E = e.keys();
263
- for (const l of E)
262
+ const d = n, c = [], p = e.keys();
263
+ for (const l of p)
264
264
  // Skip the special useSWRInfinite and useSWRSubscription keys.
265
265
  !/^\$(inf|sub)\$/.test(l) && d(e.get(l)._k) && c.push(l);
266
266
  return Promise.all(c.map(u));
@@ -269,21 +269,21 @@ async function ie(...t) {
269
269
  async function u(d) {
270
270
  const [c] = Ft(d);
271
271
  if (!c) return;
272
- const [E, l] = se(e, c), [D, i, M, Q] = P.get(e), j = () => {
272
+ const [p, l] = ie(e, c), [D, a, P, Q] = M.get(e), j = () => {
273
273
  const C = D[c];
274
- return (N(s.revalidate) ? s.revalidate(E().data, d) : s.revalidate !== !1) && (delete M[c], delete Q[c], C && C[0]) ? C[0](re).then(() => E().data) : E().data;
274
+ return (N(s.revalidate) ? s.revalidate(p().data, d) : s.revalidate !== !1) && (delete P[c], delete Q[c], C && C[0]) ? C[0](oe).then(() => p().data) : p().data;
275
275
  };
276
276
  if (t.length < 3)
277
277
  return j();
278
278
  let R = r, I;
279
- const k = Vt();
280
- i[c] = [
281
- k,
279
+ const q = Vt();
280
+ a[c] = [
281
+ q,
282
282
  0
283
283
  ];
284
- const h = !f(_), $ = E(), V = $.data, H = $._c, W = f(H) ? V : H;
285
- if (h && (_ = N(_) ? _(W, V) : _, l({
286
- data: _,
284
+ const S = !f(h), H = p(), V = H.data, k = H._c, W = f(k) ? V : k;
285
+ if (S && (h = N(h) ? h(W, V) : h, l({
286
+ data: h,
287
287
  _c: W
288
288
  })), N(R))
289
289
  try {
@@ -291,19 +291,19 @@ async function ie(...t) {
291
291
  } catch (C) {
292
292
  I = C;
293
293
  }
294
- if (R && oe(R))
294
+ if (R && se(R))
295
295
  if (R = await R.catch((C) => {
296
296
  I = C;
297
- }), k !== i[c][0]) {
297
+ }), q !== a[c][0]) {
298
298
  if (I) throw I;
299
299
  return R;
300
- } else I && h && y(I) && (a = !0, l({
300
+ } else I && S && y(I) && (i = !0, l({
301
301
  data: W,
302
302
  _c: A
303
303
  }));
304
- if (a && !I)
305
- if (N(a)) {
306
- const C = a(R, W);
304
+ if (i && !I)
305
+ if (N(i)) {
306
+ const C = i(R, W);
307
307
  l({
308
308
  data: C,
309
309
  error: A,
@@ -315,7 +315,7 @@ async function ie(...t) {
315
315
  error: A,
316
316
  _c: A
317
317
  });
318
- if (i[c][1] = Vt(), Promise.resolve(j()).then(() => {
318
+ if (a[c][1] = Vt(), Promise.resolve(j()).then(() => {
319
319
  l({
320
320
  _c: A
321
321
  });
@@ -326,35 +326,35 @@ async function ie(...t) {
326
326
  return R;
327
327
  }
328
328
  }
329
- const Xt = (t, e) => {
329
+ const Qt = (t, e) => {
330
330
  for (const n in t)
331
331
  t[n][0] && t[n][0](e);
332
- }, We = (t, e) => {
333
- if (!P.has(t)) {
334
- const n = G(Me, e), r = /* @__PURE__ */ Object.create(null), o = ie.bind(A, t);
332
+ }, Ue = (t, e) => {
333
+ if (!M.has(t)) {
334
+ const n = G(xe, e), r = /* @__PURE__ */ Object.create(null), o = ae.bind(A, t);
335
335
  let s = U;
336
- const a = /* @__PURE__ */ Object.create(null), m = (O, u) => {
337
- const d = a[O] || [];
338
- return a[O] = d, d.push(u), () => d.splice(d.indexOf(u), 1);
339
- }, _ = (O, u, d) => {
336
+ const i = /* @__PURE__ */ Object.create(null), E = (O, u) => {
337
+ const d = i[O] || [];
338
+ return i[O] = d, d.push(u), () => d.splice(d.indexOf(u), 1);
339
+ }, h = (O, u, d) => {
340
340
  t.set(O, u);
341
- const c = a[O];
341
+ const c = i[O];
342
342
  if (c)
343
- for (const E of c)
344
- E(u, d);
343
+ for (const p of c)
344
+ p(u, d);
345
345
  }, y = () => {
346
- if (!P.has(t) && (P.set(t, [
346
+ if (!M.has(t) && (M.set(t, [
347
347
  r,
348
348
  /* @__PURE__ */ Object.create(null),
349
349
  /* @__PURE__ */ Object.create(null),
350
350
  /* @__PURE__ */ Object.create(null),
351
351
  o,
352
- _,
353
- m
352
+ h,
353
+ E
354
354
  ]), !tt)) {
355
- const O = n.initFocus(setTimeout.bind(A, Xt.bind(A, r, ee))), u = n.initReconnect(setTimeout.bind(A, Xt.bind(A, r, ne)));
355
+ const O = n.initFocus(setTimeout.bind(A, Qt.bind(A, r, ne))), u = n.initReconnect(setTimeout.bind(A, Qt.bind(A, r, re)));
356
356
  s = () => {
357
- O && O(), u && u(), P.delete(t);
357
+ O && O(), u && u(), M.delete(t);
358
358
  };
359
359
  }
360
360
  };
@@ -367,18 +367,18 @@ const Xt = (t, e) => {
367
367
  }
368
368
  return [
369
369
  t,
370
- P.get(t)[4]
370
+ M.get(t)[4]
371
371
  ];
372
- }, qe = (t, e, n, r, o) => {
373
- const s = n.errorRetryCount, a = o.retryCount, m = ~~((Math.random() + 0.5) * (1 << (a < 8 ? a : 8))) * n.errorRetryInterval;
374
- !f(s) && a > s || setTimeout(r, m, o);
375
- }, Be = Tt, [ae, ke] = We(/* @__PURE__ */ new Map()), $e = G(
372
+ }, Ge = (t, e, n, r, o) => {
373
+ const s = n.errorRetryCount, i = o.retryCount, E = ~~((Math.random() + 0.5) * (1 << (i < 8 ? i : 8))) * n.errorRetryInterval;
374
+ !f(s) && i > s || setTimeout(r, E, o);
375
+ }, We = gt, [ce, Be] = Ue(/* @__PURE__ */ new Map()), $e = G(
376
376
  {
377
377
  // events
378
378
  onLoadingSlow: U,
379
379
  onSuccess: U,
380
380
  onError: U,
381
- onErrorRetry: qe,
381
+ onErrorRetry: Ge,
382
382
  onDiscarded: U,
383
383
  // switches
384
384
  revalidateOnFocus: !0,
@@ -386,29 +386,29 @@ const Xt = (t, e) => {
386
386
  revalidateIfStale: !0,
387
387
  shouldRetryOnError: !0,
388
388
  // timeouts
389
- errorRetryInterval: zt ? 1e4 : 5e3,
389
+ errorRetryInterval: Xt ? 1e4 : 5e3,
390
390
  focusThrottleInterval: 5 * 1e3,
391
391
  dedupingInterval: 2 * 1e3,
392
- loadingTimeout: zt ? 5e3 : 3e3,
392
+ loadingTimeout: Xt ? 5e3 : 3e3,
393
393
  // providers
394
- compare: Be,
394
+ compare: We,
395
395
  isPaused: () => !1,
396
- cache: ae,
397
- mutate: ke,
396
+ cache: ce,
397
+ mutate: Be,
398
398
  fallback: {}
399
399
  },
400
400
  // use web preset by default
401
- Pe
402
- ), He = (t, e) => {
401
+ Fe
402
+ ), qe = (t, e) => {
403
403
  const n = G(t, e);
404
404
  if (e) {
405
- const { use: r, fallback: o } = t, { use: s, fallback: a } = e;
406
- r && s && (n.use = r.concat(s)), o && a && (n.fallback = G(o, a));
405
+ const { use: r, fallback: o } = t, { use: s, fallback: i } = e;
406
+ r && s && (n.use = r.concat(s)), o && i && (n.fallback = G(o, i));
407
407
  }
408
408
  return n;
409
- }, Ke = Qt({}), Je = "$inf$", ce = nt && window.__SWR_DEVTOOLS_USE__, Ye = ce ? window.__SWR_DEVTOOLS_USE__ : [], ze = () => {
410
- ce && (window.__SWR_DEVTOOLS_REACT__ = et);
411
- }, Xe = (t) => N(t[1]) ? [
409
+ }, He = Zt({}), ke = "$inf$", ue = rt && window.__SWR_DEVTOOLS_USE__, Ke = ue ? window.__SWR_DEVTOOLS_USE__ : [], Je = () => {
410
+ ue && (window.__SWR_DEVTOOLS_REACT__ = et);
411
+ }, Ye = (t) => N(t[1]) ? [
412
412
  t[0],
413
413
  t[1],
414
414
  t[2] || {}
@@ -416,28 +416,28 @@ const Xt = (t, e) => {
416
416
  t[0],
417
417
  null,
418
418
  (t[1] === null ? t[2] : t[1]) || {}
419
- ], Qe = () => G($e, Zt(Ke)), Ze = (t) => (e, n, r) => t(e, n && ((...s) => {
420
- const [a] = Ft(e), [, , , m] = P.get(ae);
421
- if (a.startsWith(Je))
419
+ ], ze = () => G($e, te(He)), Xe = (t) => (e, n, r) => t(e, n && ((...s) => {
420
+ const [i] = Ft(e), [, , , E] = M.get(ce);
421
+ if (i.startsWith(ke))
422
422
  return n(...s);
423
- const _ = m[a];
424
- return f(_) ? n(...s) : (delete m[a], _);
425
- }), r), tn = Ye.concat(Ze), en = (t) => function(...n) {
426
- const r = Qe(), [o, s, a] = Xe(n), m = He(r, a);
427
- let _ = t;
428
- const { use: y } = m, O = (y || []).concat(tn);
423
+ const h = E[i];
424
+ return f(h) ? n(...s) : (delete E[i], h);
425
+ }), r), Qe = Ke.concat(Xe), Ze = (t) => function(...n) {
426
+ const r = ze(), [o, s, i] = Ye(n), E = qe(r, i);
427
+ let h = t;
428
+ const { use: y } = E, O = (y || []).concat(Qe);
429
429
  for (let u = O.length; u--; )
430
- _ = O[u](_);
431
- return _(o, s || m.fetcher || null, m);
432
- }, nn = (t, e, n) => {
430
+ h = O[u](h);
431
+ return h(o, s || E.fetcher || null, E);
432
+ }, tn = (t, e, n) => {
433
433
  const r = e[t] || (e[t] = []);
434
434
  return r.push(n), () => {
435
435
  const o = r.indexOf(n);
436
436
  o >= 0 && (r[o] = r[r.length - 1], r.pop());
437
437
  };
438
438
  };
439
- ze();
440
- const gt = et.use || // This extra generic is to avoid TypeScript mixing up the generic and JSX sytax
439
+ Je();
440
+ const Tt = et.use || // This extra generic is to avoid TypeScript mixing up the generic and JSX sytax
441
441
  // and emitting an error.
442
442
  // We assume that this is only for the `use(thenable)` case, not `use(context)`.
443
443
  // https://github.com/facebook/react/blob/aed00dacfb79d17c53218404c52b1c7aa59c4a89/packages/react-server/src/ReactFizzThenable.js#L45
@@ -458,93 +458,93 @@ const gt = et.use || // This extra generic is to avoid TypeScript mixing up the
458
458
  }
459
459
  }), yt = {
460
460
  dedupe: !0
461
- }, rn = (t, e, n) => {
462
- const { cache: r, compare: o, suspense: s, fallbackData: a, revalidateOnMount: m, revalidateIfStale: _, refreshInterval: y, refreshWhenHidden: O, refreshWhenOffline: u, keepPreviousData: d } = n, [c, E, l, D] = P.get(r), [i, M] = Ft(t), Q = B(!1), j = B(!1), R = B(i), I = B(e), k = B(n), h = () => k.current, $ = () => h().isVisible() && h().isOnline(), [V, H, W, C] = se(r, i), K = B({}).current, ot = f(a) ? f(n.fallback) ? A : n.fallback[i] : a, xt = (S, p) => {
463
- for (const g in K) {
464
- const v = g;
461
+ }, en = (t, e, n) => {
462
+ const { cache: r, compare: o, suspense: s, fallbackData: i, revalidateOnMount: E, revalidateIfStale: h, refreshInterval: y, refreshWhenHidden: O, refreshWhenOffline: u, keepPreviousData: d } = n, [c, p, l, D] = M.get(r), [a, P] = Ft(t), Q = $(!1), j = $(!1), R = $(a), I = $(e), q = $(n), S = () => q.current, H = () => S().isVisible() && S().isOnline(), [V, k, W, C] = ie(r, a), K = $({}).current, ot = f(i) ? f(n.fallback) ? A : n.fallback[a] : i, Mt = (_, m) => {
463
+ for (const T in K) {
464
+ const v = T;
465
465
  if (v === "data") {
466
- if (!o(S[v], p[v]) && (!f(S[v]) || !o(it, p[v])))
466
+ if (!o(_[v], m[v]) && (!f(_[v]) || !o(it, m[v])))
467
467
  return !1;
468
- } else if (p[v] !== S[v])
468
+ } else if (m[v] !== _[v])
469
469
  return !1;
470
470
  }
471
471
  return !0;
472
472
  }, Pt = ft(() => {
473
- const S = !i || !e ? !1 : f(m) ? h().isPaused() || s ? !1 : _ !== !1 : m, p = (T) => {
474
- const F = G(T);
475
- return delete F._k, S ? {
473
+ const _ = !a || !e ? !1 : f(E) ? S().isPaused() || s ? !1 : h !== !1 : E, m = (g) => {
474
+ const F = G(g);
475
+ return delete F._k, _ ? {
476
476
  isValidating: !0,
477
477
  isLoading: !0,
478
478
  ...F
479
479
  } : F;
480
- }, g = V(), v = C(), b = p(g), z = g === v ? b : p(v);
480
+ }, T = V(), v = C(), b = m(T), z = T === v ? b : m(v);
481
481
  let w = b;
482
482
  return [
483
483
  () => {
484
- const T = p(V());
485
- return xt(T, w) ? (w.data = T.data, w.isLoading = T.isLoading, w.isValidating = T.isValidating, w.error = T.error, w) : (w = T, T);
484
+ const g = m(V());
485
+ return Mt(g, w) ? (w.data = g.data, w.isLoading = g.isLoading, w.isValidating = g.isValidating, w.error = g.error, w) : (w = g, g);
486
486
  },
487
487
  () => z
488
488
  ];
489
489
  }, [
490
490
  r,
491
- i
492
- ]), J = Le.useSyncExternalStore(lt(
493
- (S) => W(i, (p, g) => {
494
- xt(g, p) || S();
491
+ a
492
+ ]), J = De.useSyncExternalStore(lt(
493
+ (_) => W(a, (m, T) => {
494
+ Mt(T, m) || _();
495
495
  }),
496
496
  // eslint-disable-next-line react-hooks/exhaustive-deps
497
497
  [
498
498
  r,
499
- i
499
+ a
500
500
  ]
501
- ), Pt[0], Pt[1]), Mt = !Q.current, Se = c[i] && c[i].length > 0, Y = J.data, q = f(Y) ? ot && oe(ot) ? gt(ot) : ot : Y, st = J.error, pt = B(q), it = d ? f(Y) ? f(pt.current) ? q : pt.current : Y : q, jt = Se && !f(st) ? !1 : Mt && !f(m) ? m : h().isPaused() ? !1 : s ? f(q) ? !1 : _ : f(q) || _, Ut = !!(i && e && Mt && jt), he = f(J.isValidating) ? Ut : J.isValidating, Oe = f(J.isLoading) ? Ut : J.isLoading, Z = lt(
502
- async (S) => {
503
- const p = I.current;
504
- if (!i || !p || j.current || h().isPaused())
501
+ ), Pt[0], Pt[1]), jt = !Q.current, me = c[a] && c[a].length > 0, Y = J.data, B = f(Y) ? ot && se(ot) ? Tt(ot) : ot : Y, st = J.error, pt = $(B), it = d ? f(Y) ? f(pt.current) ? B : pt.current : Y : B, Ut = me && !f(st) ? !1 : jt && !f(E) ? E : S().isPaused() ? !1 : s ? f(B) ? !1 : h : f(B) || h, Gt = !!(a && e && jt && Ut), he = f(J.isValidating) ? Gt : J.isValidating, _e = f(J.isLoading) ? Gt : J.isLoading, Z = lt(
502
+ async (_) => {
503
+ const m = I.current;
504
+ if (!a || !m || j.current || S().isPaused())
505
505
  return !1;
506
- let g, v, b = !0;
507
- const z = S || {}, w = !l[i] || !z.dedupe, T = () => Yt ? !j.current && i === R.current && Q.current : i === R.current, F = {
506
+ let T, v, b = !0;
507
+ const z = _ || {}, w = !l[a] || !z.dedupe, g = () => zt ? !j.current && a === R.current && Q.current : a === R.current, F = {
508
508
  isValidating: !1,
509
509
  isLoading: !1
510
- }, Wt = () => {
511
- H(F);
512
- }, qt = () => {
513
- const L = l[i];
514
- L && L[1] === v && delete l[i];
515
- }, Bt = {
510
+ }, Bt = () => {
511
+ k(F);
512
+ }, $t = () => {
513
+ const L = l[a];
514
+ L && L[1] === v && delete l[a];
515
+ }, qt = {
516
516
  isValidating: !0
517
517
  };
518
- f(V().data) && (Bt.isLoading = !0);
518
+ f(V().data) && (qt.isLoading = !0);
519
519
  try {
520
- if (w && (H(Bt), n.loadingTimeout && f(V().data) && setTimeout(() => {
521
- b && T() && h().onLoadingSlow(i, n);
522
- }, n.loadingTimeout), l[i] = [
523
- p(M),
520
+ if (w && (k(qt), n.loadingTimeout && f(V().data) && setTimeout(() => {
521
+ b && g() && S().onLoadingSlow(a, n);
522
+ }, n.loadingTimeout), l[a] = [
523
+ m(P),
524
524
  Vt()
525
- ]), [g, v] = l[i], g = await g, w && setTimeout(qt, n.dedupingInterval), !l[i] || l[i][1] !== v)
526
- return w && T() && h().onDiscarded(i), !1;
525
+ ]), [T, v] = l[a], T = await T, w && setTimeout($t, n.dedupingInterval), !l[a] || l[a][1] !== v)
526
+ return w && g() && S().onDiscarded(a), !1;
527
527
  F.error = A;
528
- const L = E[i];
528
+ const L = p[a];
529
529
  if (!f(L) && // case 1
530
530
  (v <= L[0] || // case 2
531
531
  v <= L[1] || // case 3
532
532
  L[1] === 0))
533
- return Wt(), w && T() && h().onDiscarded(i), !1;
533
+ return Bt(), w && g() && S().onDiscarded(a), !1;
534
534
  const x = V().data;
535
- F.data = o(x, g) ? x : g, w && T() && h().onSuccess(g, i, n);
535
+ F.data = o(x, T) ? x : T, w && g() && S().onSuccess(T, a, n);
536
536
  } catch (L) {
537
- qt();
538
- const x = h(), { shouldRetryOnError: mt } = x;
539
- x.isPaused() || (F.error = L, w && T() && (x.onError(L, i, x), (mt === !0 || N(mt) && mt(L)) && (!h().revalidateOnFocus || !h().revalidateOnReconnect || $()) && x.onErrorRetry(L, i, x, (ve) => {
540
- const _t = c[i];
541
- _t && _t[0] && _t[0](Kt, ve);
537
+ $t();
538
+ const x = S(), { shouldRetryOnError: mt } = x;
539
+ x.isPaused() || (F.error = L, w && g() && (x.onError(L, a, x), (mt === !0 || N(mt) && mt(L)) && (!S().revalidateOnFocus || !S().revalidateOnReconnect || H()) && x.onErrorRetry(L, a, x, (Se) => {
540
+ const ht = c[a];
541
+ ht && ht[0] && ht[0](Jt, Se);
542
542
  }, {
543
543
  retryCount: (z.retryCount || 0) + 1,
544
544
  dedupe: !0
545
545
  })));
546
546
  }
547
- return b = !1, Wt(), !0;
547
+ return b = !1, Bt(), !0;
548
548
  },
549
549
  // `setState` is immutable, and `eventsCallback`, `fnArg`, and
550
550
  // `keyValidating` are depending on `key`, so we can exclude them from
@@ -558,76 +558,76 @@ const gt = et.use || // This extra generic is to avoid TypeScript mixing up the
558
558
  // even though it might cause unexpected behaviors.
559
559
  // eslint-disable-next-line react-hooks/exhaustive-deps
560
560
  [
561
- i,
561
+ a,
562
562
  r
563
563
  ]
564
- ), Gt = lt(
564
+ ), Wt = lt(
565
565
  // Use callback to make sure `keyRef.current` returns latest result every time
566
- (...S) => ie(r, R.current, ...S),
566
+ (..._) => ae(r, R.current, ..._),
567
567
  // eslint-disable-next-line react-hooks/exhaustive-deps
568
568
  []
569
569
  );
570
570
  if (vt(() => {
571
- I.current = e, k.current = n, f(Y) || (pt.current = Y);
571
+ I.current = e, q.current = n, f(Y) || (pt.current = Y);
572
572
  }), vt(() => {
573
- if (!i) return;
574
- const S = Z.bind(A, yt);
575
- let p = 0;
576
- h().revalidateOnFocus && (p = Date.now() + h().focusThrottleInterval);
577
- const v = nn(i, c, (b, z = {}) => {
578
- if (b == ee) {
573
+ if (!a) return;
574
+ const _ = Z.bind(A, yt);
575
+ let m = 0;
576
+ S().revalidateOnFocus && (m = Date.now() + S().focusThrottleInterval);
577
+ const v = tn(a, c, (b, z = {}) => {
578
+ if (b == ne) {
579
579
  const w = Date.now();
580
- h().revalidateOnFocus && w > p && $() && (p = w + h().focusThrottleInterval, S());
581
- } else if (b == ne)
582
- h().revalidateOnReconnect && $() && S();
580
+ S().revalidateOnFocus && w > m && H() && (m = w + S().focusThrottleInterval, _());
581
+ } else if (b == re)
582
+ S().revalidateOnReconnect && H() && _();
583
583
  else {
584
- if (b == re)
584
+ if (b == oe)
585
585
  return Z();
586
- if (b == Kt)
586
+ if (b == Jt)
587
587
  return Z(z);
588
588
  }
589
589
  });
590
- return j.current = !1, R.current = i, Q.current = !0, H({
591
- _k: M
592
- }), jt && (f(q) || tt ? S() : je(S)), () => {
590
+ return j.current = !1, R.current = a, Q.current = !0, k({
591
+ _k: P
592
+ }), Ut && (f(B) || tt ? _() : Me(_)), () => {
593
593
  j.current = !0, v();
594
594
  };
595
595
  }, [
596
- i
596
+ a
597
597
  ]), vt(() => {
598
- let S;
599
- function p() {
598
+ let _;
599
+ function m() {
600
600
  const v = N(y) ? y(V().data) : y;
601
- v && S !== -1 && (S = setTimeout(g, v));
601
+ v && _ !== -1 && (_ = setTimeout(T, v));
602
602
  }
603
- function g() {
604
- !V().error && (O || h().isVisible()) && (u || h().isOnline()) ? Z(yt).then(p) : p();
603
+ function T() {
604
+ !V().error && (O || S().isVisible()) && (u || S().isOnline()) ? Z(yt).then(m) : m();
605
605
  }
606
- return p(), () => {
607
- S && (clearTimeout(S), S = -1);
606
+ return m(), () => {
607
+ _ && (clearTimeout(_), _ = -1);
608
608
  };
609
609
  }, [
610
610
  y,
611
611
  O,
612
612
  u,
613
- i
614
- ]), ye(it), s && f(q) && i) {
615
- if (!Yt && tt)
613
+ a
614
+ ]), Re(it), s && f(B) && a) {
615
+ if (!zt && tt)
616
616
  throw new Error("Fallback data is required when using Suspense in SSR.");
617
- I.current = e, k.current = n, j.current = !1;
618
- const S = D[i];
619
- if (!f(S)) {
620
- const p = Gt(S);
621
- gt(p);
617
+ I.current = e, q.current = n, j.current = !1;
618
+ const _ = D[a];
619
+ if (!f(_)) {
620
+ const m = Wt(_);
621
+ Tt(m);
622
622
  }
623
623
  if (f(st)) {
624
- const p = Z(yt);
625
- f(it) || (p.status = "fulfilled", p.value = !0), gt(p);
624
+ const m = Z(yt);
625
+ f(it) || (m.status = "fulfilled", m.value = !0), Tt(m);
626
626
  } else
627
627
  throw st;
628
628
  }
629
629
  return {
630
- mutate: Gt,
630
+ mutate: Wt,
631
631
  get data() {
632
632
  return K.data = !0, it;
633
633
  },
@@ -638,36 +638,45 @@ const gt = et.use || // This extra generic is to avoid TypeScript mixing up the
638
638
  return K.isValidating = !0, he;
639
639
  },
640
640
  get isLoading() {
641
- return K.isLoading = !0, Oe;
641
+ return K.isLoading = !0, _e;
642
642
  }
643
643
  };
644
- }, on = en(rn), ue = "https://api.figma.com", sn = `${ue}/v1/files`, le = `${ue}/v1/variables`, fe = le, de = (t) => `${le}/${t}`, an = (t) => `${sn}/${t}/variables/local`, Ee = "application/json", pe = "X-FIGMA-TOKEN", rt = "A Figma API token is required.", me = "An error occurred while fetching data from the Figma API.", cn = async (t, e) => {
644
+ }, nn = Ze(en), xt = "https://api.figma.com", rn = `${xt}/v1/files`, le = `${xt}/v1/variables`, fe = le, de = (t) => `${le}/${t}`, on = (t) => `${rn}/${t}/variables/local`, sn = "application/json", Ee = "X-FIGMA-TOKEN", X = "A Figma API token is required.", an = "An error occurred while fetching data from the Figma API.";
645
+ async function cn(t, e) {
645
646
  if (!e)
646
- throw new Error(rt);
647
+ throw new Error(X);
647
648
  const n = await fetch(t, {
649
+ method: "GET",
648
650
  headers: {
649
- [pe]: e,
650
- "Content-Type": Ee
651
+ [Ee]: e,
652
+ "Content-Type": sn
651
653
  }
652
654
  });
653
655
  if (!n.ok) {
654
- const r = await n.json();
655
- throw new Error(r.message || me);
656
+ let r = an;
657
+ try {
658
+ const o = await n.json();
659
+ o != null && o.message && (r = o.message);
660
+ } catch {
661
+ }
662
+ throw new Error(r);
656
663
  }
657
664
  return n.json();
658
- }, _e = () => {
659
- const { token: t, fileKey: e } = X(), n = e ? an(e) : null, { data: r, error: o, isLoading: s, isValidating: a } = on(
665
+ }
666
+ const pe = () => {
667
+ const { token: t, fileKey: e } = nt(), n = e ? on(e) : null, { data: r, error: o, isLoading: s, isValidating: i, mutate: E } = nn(
660
668
  t && n ? [n, t] : null,
661
669
  cn
662
670
  );
663
671
  return {
664
672
  data: r,
665
673
  isLoading: s,
666
- isValidating: a,
667
- error: o
674
+ isValidating: i,
675
+ error: o,
676
+ mutate: E
668
677
  };
669
678
  }, pn = () => {
670
- const { data: t } = _e(), e = ft(
679
+ const { data: t } = pe(), e = ft(
671
680
  () => t != null && t.meta ? Object.values(t.meta.variableCollections) : [],
672
681
  [t]
673
682
  ), n = ft(
@@ -679,7 +688,7 @@ const gt = et.use || // This extra generic is to avoid TypeScript mixing up the
679
688
  collectionsById: n
680
689
  };
681
690
  }, mn = () => {
682
- const { data: t } = _e();
691
+ const { data: t } = pe();
683
692
  return ft(() => {
684
693
  const e = [], n = {}, r = {};
685
694
  if (t != null && t.meta)
@@ -696,9 +705,6 @@ const gt = et.use || // This extra generic is to avoid TypeScript mixing up the
696
705
  modesById: r
697
706
  };
698
707
  }, [t]);
699
- }, _n = () => {
700
- const { token: t } = X();
701
- return t;
702
708
  };
703
709
  function un(t, e) {
704
710
  switch (e.type) {
@@ -723,10 +729,10 @@ const dt = (t) => {
723
729
  async (s) => {
724
730
  r({ type: "loading" });
725
731
  try {
726
- const a = await t(s);
727
- return r({ type: "success", payload: a }), a;
728
- } catch (a) {
729
- r({ type: "error", payload: a });
732
+ const i = await t(s);
733
+ return r({ type: "success", payload: i }), i;
734
+ } catch (i) {
735
+ r({ type: "error", payload: i });
730
736
  return;
731
737
  }
732
738
  },
@@ -737,70 +743,81 @@ const dt = (t) => {
737
743
  isSuccess: n.status === "success",
738
744
  isError: n.status === "error"
739
745
  };
740
- }, Et = async (t, e, n, r) => {
746
+ };
747
+ async function Et(t, e, n, r) {
741
748
  if (!e)
742
- throw new Error(rt);
743
- const o = await fetch(t, {
744
- method: n,
749
+ throw new Error(X);
750
+ const s = {
751
+ CREATE: "POST",
752
+ UPDATE: "PUT",
753
+ DELETE: "DELETE"
754
+ }[n], i = await fetch(`${xt}${t}`, {
755
+ method: s,
745
756
  headers: {
746
- [pe]: e,
747
- "Content-Type": Ee
757
+ "Content-Type": "application/json",
758
+ [Ee]: e
748
759
  },
749
- ...r && { body: JSON.stringify(r) }
760
+ body: r ? JSON.stringify(r) : void 0
750
761
  });
751
- if (!o.ok) {
752
- const s = await o.json();
753
- throw new Error(s.message || me);
762
+ if (!i.ok) {
763
+ const E = await i.json().catch(() => ({}));
764
+ throw new Error(
765
+ E.err || E.message || "An API error occurred"
766
+ );
754
767
  }
755
- return o.status === 204 ? Promise.resolve(void 0) : o.json();
756
- }, Sn = () => {
757
- const { token: t } = X();
758
- if (!t)
759
- throw new Error(rt);
760
- return dt(async (n) => await Et(
761
- fe,
762
- t,
763
- "POST",
764
- n
765
- ));
766
- }, hn = () => {
767
- const { token: t } = X();
768
+ return i.status === 204 || !i.body ? {} : i.json();
769
+ }
770
+ const hn = () => {
771
+ const { token: t } = nt();
772
+ return dt(async (n) => {
773
+ if (!t)
774
+ throw new Error(X);
775
+ return await Et(
776
+ fe,
777
+ t,
778
+ "CREATE",
779
+ n
780
+ );
781
+ });
782
+ }, _n = () => {
783
+ const { token: t } = nt();
768
784
  if (!t)
769
- throw new Error(rt);
770
- return dt(async (n) => await Et(
771
- de(n),
772
- t,
773
- "DELETE"
774
- ));
775
- }, On = () => {
776
- const { token: t } = X();
785
+ throw new Error(X);
777
786
  return dt(
778
787
  async ({ variableId: n, payload: r }) => {
779
- if (!t)
780
- throw new Error("A Figma API token is required.");
781
788
  const o = de(n);
782
789
  return await Et(
783
790
  o,
784
791
  t,
785
- "PUT",
792
+ "UPDATE",
786
793
  r
787
794
  );
788
795
  }
789
796
  );
790
- }, vn = () => {
791
- const { token: t } = X();
797
+ }, Sn = () => {
798
+ const { token: t } = nt();
799
+ if (!t)
800
+ throw new Error(X);
801
+ return dt(async (n) => await Et(
802
+ de(n),
803
+ t,
804
+ "DELETE",
805
+ void 0
806
+ ));
807
+ }, On = () => {
808
+ const { token: t } = nt();
792
809
  return dt(async (n) => {
793
810
  if (!t)
794
- throw new Error(rt);
811
+ throw new Error(X);
795
812
  return await Et(
796
813
  fe,
797
814
  t,
798
- "PUT",
815
+ "CREATE",
799
816
  n
800
817
  );
801
818
  });
802
819
  };
803
- function wn(t, e) {
820
+ function vn(t, e) {
804
821
  return t.filter((n) => {
805
822
  let r = !0;
806
823
  return e.resolvedType && (r = r && n.resolvedType === e.resolvedType), e.name && (r = r && n.name.includes(e.name)), r;
@@ -808,13 +825,12 @@ function wn(t, e) {
808
825
  }
809
826
  export {
810
827
  En as FigmaVarsProvider,
811
- wn as filterVariables,
812
- vn as useBulkUpdateVariables,
813
- Sn as useCreateVariable,
814
- hn as useDeleteVariable,
815
- _n as useFigmaToken,
816
- On as useUpdateVariable,
828
+ vn as filterVariables,
829
+ On as useBulkUpdateVariables,
830
+ hn as useCreateVariable,
831
+ Sn as useDeleteVariable,
832
+ _n as useUpdateVariable,
817
833
  pn as useVariableCollections,
818
834
  mn as useVariableModes,
819
- _e as useVariables
835
+ pe as useVariables
820
836
  };