@figma-vars/hooks 1.1.1 → 1.3.1

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.
@@ -1,301 +1,20 @@
1
- import fe, { createContext as it, useContext as ct, useEffect as ht, useLayoutEffect as St, useRef as se, useMemo as bt, useCallback as ae, useDebugValue as Ot, useState as M } from "react";
2
- var Se = { exports: {} }, pe = {};
3
- /**
4
- * @license React
5
- * react-jsx-runtime.production.js
6
- *
7
- * Copyright (c) Meta Platforms, Inc. and affiliates.
8
- *
9
- * This source code is licensed under the MIT license found in the
10
- * LICENSE file in the root directory of this source tree.
11
- */
12
- var ze;
13
- function Rt() {
14
- if (ze) return pe;
15
- ze = 1;
16
- var e = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment");
17
- function t(n, o, a) {
18
- var i = null;
19
- if (a !== void 0 && (i = "" + a), o.key !== void 0 && (i = "" + o.key), "key" in o) {
20
- a = {};
21
- for (var f in o)
22
- f !== "key" && (a[f] = o[f]);
23
- } else a = o;
24
- return o = a.ref, {
25
- $$typeof: e,
26
- type: n,
27
- key: i,
28
- ref: o !== void 0 ? o : null,
29
- props: a
30
- };
31
- }
32
- return pe.Fragment = r, pe.jsx = t, pe.jsxs = t, pe;
33
- }
34
- var ve = {};
35
- /**
36
- * @license React
37
- * react-jsx-runtime.development.js
38
- *
39
- * Copyright (c) Meta Platforms, Inc. and affiliates.
40
- *
41
- * This source code is licensed under the MIT license found in the
42
- * LICENSE file in the root directory of this source tree.
43
- */
44
- var Xe;
45
- function Tt() {
46
- return Xe || (Xe = 1, process.env.NODE_ENV !== "production" && function() {
47
- function e(s) {
48
- if (s == null) return null;
49
- if (typeof s == "function")
50
- return s.$$typeof === V ? null : s.displayName || s.name || null;
51
- if (typeof s == "string") return s;
52
- switch (s) {
53
- case m:
54
- return "Fragment";
55
- case c:
56
- return "Profiler";
57
- case k:
58
- return "StrictMode";
59
- case y:
60
- return "Suspense";
61
- case I:
62
- return "SuspenseList";
63
- case Q:
64
- return "Activity";
65
- }
66
- if (typeof s == "object")
67
- switch (typeof s.tag == "number" && console.error(
68
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
69
- ), s.$$typeof) {
70
- case h:
71
- return "Portal";
72
- case ne:
73
- return (s.displayName || "Context") + ".Provider";
74
- case W:
75
- return (s._context.displayName || "Context") + ".Consumer";
76
- case $:
77
- var l = s.render;
78
- return s = s.displayName, s || (s = l.displayName || l.name || "", s = s !== "" ? "ForwardRef(" + s + ")" : "ForwardRef"), s;
79
- case Z:
80
- return l = s.displayName || null, l !== null ? l : e(s.type) || "Memo";
81
- case O:
82
- l = s._payload, s = s._init;
83
- try {
84
- return e(s(l));
85
- } catch {
86
- }
87
- }
88
- return null;
89
- }
90
- function r(s) {
91
- return "" + s;
92
- }
93
- function t(s) {
94
- try {
95
- r(s);
96
- var l = !1;
97
- } catch {
98
- l = !0;
99
- }
100
- if (l) {
101
- l = console;
102
- var S = l.error, T = typeof Symbol == "function" && Symbol.toStringTag && s[Symbol.toStringTag] || s.constructor.name || "Object";
103
- return S.call(
104
- l,
105
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
106
- T
107
- ), r(s);
108
- }
109
- }
110
- function n(s) {
111
- if (s === m) return "<>";
112
- if (typeof s == "object" && s !== null && s.$$typeof === O)
113
- return "<...>";
114
- try {
115
- var l = e(s);
116
- return l ? "<" + l + ">" : "<...>";
117
- } catch {
118
- return "<...>";
119
- }
120
- }
121
- function o() {
122
- var s = q.A;
123
- return s === null ? null : s.getOwner();
124
- }
125
- function a() {
126
- return Error("react-stack-top-frame");
127
- }
128
- function i(s) {
129
- if (G.call(s, "key")) {
130
- var l = Object.getOwnPropertyDescriptor(s, "key").get;
131
- if (l && l.isReactWarning) return !1;
132
- }
133
- return s.key !== void 0;
134
- }
135
- function f(s, l) {
136
- function S() {
137
- oe || (oe = !0, console.error(
138
- "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
139
- l
140
- ));
141
- }
142
- S.isReactWarning = !0, Object.defineProperty(s, "key", {
143
- get: S,
144
- configurable: !0
145
- });
146
- }
147
- function E() {
148
- var s = e(this.type);
149
- return de[s] || (de[s] = !0, console.error(
150
- "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
151
- )), s = this.props.ref, s !== void 0 ? s : null;
152
- }
153
- function g(s, l, S, T, F, L, ce, ue) {
154
- return S = L.ref, s = {
155
- $$typeof: u,
156
- type: s,
157
- key: l,
158
- props: L,
159
- _owner: F
160
- }, (S !== void 0 ? S : null) !== null ? Object.defineProperty(s, "ref", {
161
- enumerable: !1,
162
- get: E
163
- }) : Object.defineProperty(s, "ref", { enumerable: !1, value: null }), s._store = {}, Object.defineProperty(s._store, "validated", {
164
- configurable: !1,
165
- enumerable: !1,
166
- writable: !0,
167
- value: 0
168
- }), Object.defineProperty(s, "_debugInfo", {
169
- configurable: !1,
170
- enumerable: !1,
171
- writable: !0,
172
- value: null
173
- }), Object.defineProperty(s, "_debugStack", {
174
- configurable: !1,
175
- enumerable: !1,
176
- writable: !0,
177
- value: ce
178
- }), Object.defineProperty(s, "_debugTask", {
179
- configurable: !1,
180
- enumerable: !1,
181
- writable: !0,
182
- value: ue
183
- }), Object.freeze && (Object.freeze(s.props), Object.freeze(s)), s;
184
- }
185
- function v(s, l, S, T, F, L, ce, ue) {
186
- var A = l.children;
187
- if (A !== void 0)
188
- if (T)
189
- if (P(A)) {
190
- for (T = 0; T < A.length; T++)
191
- d(A[T]);
192
- Object.freeze && Object.freeze(A);
193
- } else
194
- console.error(
195
- "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
196
- );
197
- else d(A);
198
- if (G.call(l, "key")) {
199
- A = e(s);
200
- var ee = Object.keys(l).filter(function(he) {
201
- return he !== "key";
202
- });
203
- T = 0 < ee.length ? "{key: someKey, " + ee.join(": ..., ") + ": ...}" : "{key: someKey}", Ee[A + T] || (ee = 0 < ee.length ? "{" + ee.join(": ..., ") + ": ...}" : "{}", console.error(
204
- `A props object containing a "key" prop is being spread into JSX:
205
- let props = %s;
206
- <%s {...props} />
207
- React keys must be passed directly to JSX without using spread:
208
- let props = %s;
209
- <%s key={someKey} {...props} />`,
210
- T,
211
- A,
212
- ee,
213
- A
214
- ), Ee[A + T] = !0);
215
- }
216
- if (A = null, S !== void 0 && (t(S), A = "" + S), i(l) && (t(l.key), A = "" + l.key), "key" in l) {
217
- S = {};
218
- for (var J in l)
219
- J !== "key" && (S[J] = l[J]);
220
- } else S = l;
221
- return A && f(
222
- S,
223
- typeof s == "function" ? s.displayName || s.name || "Unknown" : s
224
- ), g(
225
- s,
226
- A,
227
- L,
228
- F,
229
- o(),
230
- S,
231
- ce,
232
- ue
233
- );
234
- }
235
- function d(s) {
236
- typeof s == "object" && s !== null && s.$$typeof === u && s._store && (s._store.validated = 1);
237
- }
238
- var p = fe, u = Symbol.for("react.transitional.element"), h = Symbol.for("react.portal"), m = Symbol.for("react.fragment"), k = Symbol.for("react.strict_mode"), c = Symbol.for("react.profiler"), W = Symbol.for("react.consumer"), ne = Symbol.for("react.context"), $ = Symbol.for("react.forward_ref"), y = Symbol.for("react.suspense"), I = Symbol.for("react.suspense_list"), Z = Symbol.for("react.memo"), O = Symbol.for("react.lazy"), Q = Symbol.for("react.activity"), V = Symbol.for("react.client.reference"), q = p.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, G = Object.prototype.hasOwnProperty, P = Array.isArray, Y = console.createTask ? console.createTask : function() {
239
- return null;
240
- };
241
- p = {
242
- "react-stack-bottom-frame": function(s) {
243
- return s();
244
- }
245
- };
246
- var oe, de = {}, me = p["react-stack-bottom-frame"].bind(
247
- p,
248
- a
249
- )(), H = Y(n(a)), Ee = {};
250
- ve.Fragment = m, ve.jsx = function(s, l, S, T, F) {
251
- var L = 1e4 > q.recentlyCreatedOwnerStacks++;
252
- return v(
253
- s,
254
- l,
255
- S,
256
- !1,
257
- T,
258
- F,
259
- L ? Error("react-stack-top-frame") : me,
260
- L ? Y(n(s)) : H
261
- );
262
- }, ve.jsxs = function(s, l, S, T, F) {
263
- var L = 1e4 > q.recentlyCreatedOwnerStacks++;
264
- return v(
265
- s,
266
- l,
267
- S,
268
- !0,
269
- T,
270
- F,
271
- L ? Error("react-stack-top-frame") : me,
272
- L ? Y(n(s)) : H
273
- );
274
- };
275
- }()), ve;
276
- }
277
- var Ze;
278
- function wt() {
279
- return Ze || (Ze = 1, process.env.NODE_ENV === "production" ? Se.exports = Rt() : Se.exports = Tt()), Se.exports;
280
- }
281
- var yt = wt();
282
- const ut = it(
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(
283
4
  void 0
284
- ), Er = ({
285
- children: e,
286
- token: r
287
- }) => /* @__PURE__ */ yt.jsx(ut.Provider, { value: { token: r }, children: e }), At = () => {
288
- const e = ct(ut);
289
- if (e === void 0)
5
+ ), En = ({
6
+ children: t,
7
+ token: e,
8
+ fileKey: n
9
+ }) => /* @__PURE__ */ we(te.Provider, { value: { token: e, fileKey: n }, children: t }), X = () => {
10
+ const t = Zt(te);
11
+ if (t === void 0)
290
12
  throw new Error(
291
13
  "useFigmaTokenContext must be used within a FigmaVarsProvider"
292
14
  );
293
- return e;
294
- }, ie = () => {
295
- const { token: e } = At();
296
- return e;
15
+ return t;
297
16
  };
298
- var be = { exports: {} }, ye = {};
17
+ var at = { exports: {} }, St = {};
299
18
  /**
300
19
  * @license React
301
20
  * use-sync-external-store-shim.production.js
@@ -305,48 +24,48 @@ var be = { exports: {} }, ye = {};
305
24
  * This source code is licensed under the MIT license found in the
306
25
  * LICENSE file in the root directory of this source tree.
307
26
  */
308
- var Qe;
309
- function Dt() {
310
- if (Qe) return ye;
311
- Qe = 1;
312
- var e = fe;
313
- function r(d, p) {
314
- return d === p && (d !== 0 || 1 / d === 1 / p) || d !== d && p !== p;
27
+ var kt;
28
+ function Ae() {
29
+ if (kt) return St;
30
+ kt = 1;
31
+ var t = et;
32
+ function e(u, d) {
33
+ return u === d && (u !== 0 || 1 / u === 1 / d) || u !== u && d !== d;
315
34
  }
316
- var t = typeof Object.is == "function" ? Object.is : r, n = e.useState, o = e.useEffect, a = e.useLayoutEffect, i = e.useDebugValue;
317
- function f(d, p) {
318
- var u = p(), h = n({ inst: { value: u, getSnapshot: p } }), m = h[0].inst, k = h[1];
319
- return a(
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];
38
+ return s(
320
39
  function() {
321
- m.value = u, m.getSnapshot = p, E(m) && k({ inst: m });
40
+ l.value = c, l.getSnapshot = d, _(l) && D({ inst: l });
322
41
  },
323
- [d, u, p]
42
+ [u, c, d]
324
43
  ), o(
325
44
  function() {
326
- return E(m) && k({ inst: m }), d(function() {
327
- E(m) && k({ inst: m });
45
+ return _(l) && D({ inst: l }), u(function() {
46
+ _(l) && D({ inst: l });
328
47
  });
329
48
  },
330
- [d]
331
- ), i(u), u;
49
+ [u]
50
+ ), a(c), c;
332
51
  }
333
- function E(d) {
334
- var p = d.getSnapshot;
335
- d = d.value;
52
+ function _(u) {
53
+ var d = u.getSnapshot;
54
+ u = u.value;
336
55
  try {
337
- var u = p();
338
- return !t(d, u);
56
+ var c = d();
57
+ return !n(u, c);
339
58
  } catch {
340
59
  return !0;
341
60
  }
342
61
  }
343
- function g(d, p) {
344
- return p();
62
+ function y(u, d) {
63
+ return d();
345
64
  }
346
- var v = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? g : f;
347
- return ye.useSyncExternalStore = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : v, ye;
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;
348
67
  }
349
- var Ae = {};
68
+ var ht = {};
350
69
  /**
351
70
  * @license React
352
71
  * use-sync-external-store-shim.development.js
@@ -356,476 +75,476 @@ var Ae = {};
356
75
  * This source code is licensed under the MIT license found in the
357
76
  * LICENSE file in the root directory of this source tree.
358
77
  */
359
- var et;
360
- function Ct() {
361
- return et || (et = 1, process.env.NODE_ENV !== "production" && function() {
362
- function e(u, h) {
363
- return u === h && (u !== 0 || 1 / u === 1 / h) || u !== u && h !== h;
364
- }
365
- function r(u, h) {
366
- v || o.startTransition === void 0 || (v = !0, console.error(
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;
83
+ }
84
+ function e(c, E) {
85
+ O || o.startTransition === void 0 || (O = !0, console.error(
367
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."
368
87
  ));
369
- var m = h();
370
- if (!d) {
371
- var k = h();
372
- a(m, k) || (console.error(
88
+ var l = E();
89
+ if (!u) {
90
+ var D = E();
91
+ s(l, D) || (console.error(
373
92
  "The result of getSnapshot should be cached to avoid an infinite loop"
374
- ), d = !0);
93
+ ), u = !0);
375
94
  }
376
- k = i({
377
- inst: { value: m, getSnapshot: h }
95
+ D = a({
96
+ inst: { value: l, getSnapshot: E }
378
97
  });
379
- var c = k[0].inst, W = k[1];
380
- return E(
98
+ var i = D[0].inst, M = D[1];
99
+ return _(
381
100
  function() {
382
- c.value = m, c.getSnapshot = h, t(c) && W({ inst: c });
101
+ i.value = l, i.getSnapshot = E, n(i) && M({ inst: i });
383
102
  },
384
- [u, m, h]
385
- ), f(
103
+ [c, l, E]
104
+ ), m(
386
105
  function() {
387
- return t(c) && W({ inst: c }), u(function() {
388
- t(c) && W({ inst: c });
106
+ return n(i) && M({ inst: i }), c(function() {
107
+ n(i) && M({ inst: i });
389
108
  });
390
109
  },
391
- [u]
392
- ), g(m), m;
110
+ [c]
111
+ ), y(l), l;
393
112
  }
394
- function t(u) {
395
- var h = u.getSnapshot;
396
- u = u.value;
113
+ function n(c) {
114
+ var E = c.getSnapshot;
115
+ c = c.value;
397
116
  try {
398
- var m = h();
399
- return !a(u, m);
117
+ var l = E();
118
+ return !s(c, l);
400
119
  } catch {
401
120
  return !0;
402
121
  }
403
122
  }
404
- function n(u, h) {
405
- return h();
123
+ function r(c, E) {
124
+ return E();
406
125
  }
407
126
  typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
408
- var o = fe, a = typeof Object.is == "function" ? Object.is : e, i = o.useState, f = o.useEffect, E = o.useLayoutEffect, g = o.useDebugValue, v = !1, d = !1, p = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? n : r;
409
- Ae.useSyncExternalStore = o.useSyncExternalStore !== void 0 ? o.useSyncExternalStore : p, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
410
- }()), Ae;
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;
411
130
  }
412
- var tt;
413
- function kt() {
414
- return tt || (tt = 1, process.env.NODE_ENV === "production" ? be.exports = Dt() : be.exports = Ct()), be.exports;
131
+ var Ht;
132
+ function Ie() {
133
+ return Ht || (Ht = 1, process.env.NODE_ENV === "production" ? at.exports = Ae() : at.exports = De()), at.exports;
415
134
  }
416
- var It = kt();
417
- const lt = 0, ft = 1, dt = 2, rt = 3;
418
- var nt = Object.prototype.hasOwnProperty;
419
- function je(e, r) {
420
- var t, n;
421
- if (e === r) return !0;
422
- if (e && r && (t = e.constructor) === r.constructor) {
423
- if (t === Date) return e.getTime() === r.getTime();
424
- if (t === RegExp) return e.toString() === r.toString();
425
- if (t === Array) {
426
- if ((n = e.length) === r.length)
427
- for (; n-- && je(e[n], r[n]); ) ;
428
- return n === -1;
429
- }
430
- if (!t || typeof e == "object") {
431
- n = 0;
432
- for (t in e)
433
- if (nt.call(e, t) && ++n && !nt.call(r, t) || !(t in r) || !je(e[t], r[t])) return !1;
434
- return Object.keys(r).length === n;
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) {
139
+ var n, r;
140
+ if (t === e) return !0;
141
+ if (t && e && (n = t.constructor) === e.constructor) {
142
+ if (n === Date) return t.getTime() === e.getTime();
143
+ if (n === RegExp) return t.toString() === e.toString();
144
+ if (n === Array) {
145
+ if ((r = t.length) === e.length)
146
+ for (; r-- && Tt(t[r], e[r]); ) ;
147
+ return r === -1;
148
+ }
149
+ if (!n || typeof t == "object") {
150
+ r = 0;
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;
153
+ return Object.keys(e).length === r;
435
154
  }
436
155
  }
437
- return e !== e && r !== r;
156
+ return t !== t && e !== e;
438
157
  }
439
- const X = /* @__PURE__ */ new WeakMap(), te = () => {
440
- }, j = (
158
+ const P = /* @__PURE__ */ new WeakMap(), U = () => {
159
+ }, A = (
441
160
  /*#__NOINLINE__*/
442
- te()
443
- ), Pe = Object, _ = (e) => e === j, B = (e) => typeof e == "function", re = (e, r) => ({
444
- ...e,
445
- ...r
446
- }), mt = (e) => B(e.then), De = {}, Oe = {}, $e = "undefined", _e = typeof window != $e, Ve = typeof document != $e, Lt = _e && "Deno" in window, xt = () => _e && typeof window.requestAnimationFrame != $e, Et = (e, r) => {
447
- const t = X.get(e);
161
+ U()
162
+ ), At = Object, f = (t) => t === A, N = (t) => typeof t == "function", G = (t, e) => ({
163
+ ...t,
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);
448
167
  return [
449
168
  // Getter
450
- () => !_(r) && e.get(r) || De,
169
+ () => !f(e) && t.get(e) || Ot,
451
170
  // Setter
452
- (n) => {
453
- if (!_(r)) {
454
- const o = e.get(r);
455
- r in Oe || (Oe[r] = o), t[5](r, re(o, n), o || De);
171
+ (r) => {
172
+ if (!f(e)) {
173
+ const o = t.get(e);
174
+ e in ct || (ct[e] = o), n[5](e, G(o, r), o || Ot);
456
175
  }
457
176
  },
458
177
  // Subscriber
459
- t[6],
178
+ n[6],
460
179
  // Get server cache snapshot
461
- () => !_(r) && r in Oe ? Oe[r] : !_(r) && e.get(r) || De
180
+ () => !f(e) && e in ct ? ct[e] : !f(e) && t.get(e) || Ot
462
181
  ];
463
182
  };
464
- let Fe = !0;
465
- const jt = () => Fe, [Ne, Me] = _e && window.addEventListener ? [
183
+ let It = !0;
184
+ const Ve = () => It, [Lt, Ct] = nt && window.addEventListener ? [
466
185
  window.addEventListener.bind(window),
467
186
  window.removeEventListener.bind(window)
468
187
  ] : [
469
- te,
470
- te
471
- ], Pt = () => {
472
- const e = Ve && document.visibilityState;
473
- return _(e) || e !== "hidden";
474
- }, Vt = (e) => (Ve && document.addEventListener("visibilitychange", e), Ne("focus", e), () => {
475
- Ve && document.removeEventListener("visibilitychange", e), Me("focus", e);
476
- }), Ft = (e) => {
477
- const r = () => {
478
- Fe = !0, e();
479
- }, t = () => {
480
- Fe = !1;
188
+ U,
189
+ U
190
+ ], Ne = () => {
191
+ const t = Dt && document.visibilityState;
192
+ return f(t) || t !== "hidden";
193
+ }, Fe = (t) => (Dt && document.addEventListener("visibilitychange", t), Lt("focus", t), () => {
194
+ Dt && document.removeEventListener("visibilitychange", t), Ct("focus", t);
195
+ }), xe = (t) => {
196
+ const e = () => {
197
+ It = !0, t();
198
+ }, n = () => {
199
+ It = !1;
481
200
  };
482
- return Ne("online", r), Ne("offline", t), () => {
483
- Me("online", r), Me("offline", t);
201
+ return Lt("online", e), Lt("offline", n), () => {
202
+ Ct("online", e), Ct("offline", n);
484
203
  };
485
- }, Nt = {
486
- isOnline: jt,
487
- isVisible: Pt
488
- }, Mt = {
489
- initFocus: Vt,
490
- initReconnect: Ft
491
- }, ot = !fe.useId, ge = !_e || Lt, Ut = (e) => xt() ? window.requestAnimationFrame(e) : setTimeout(e, 1), Ce = ge ? ht : St, ke = typeof navigator < "u" && navigator.connection, st = !ge && ke && ([
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 && ([
492
211
  "slow-2g",
493
212
  "2g"
494
- ].includes(ke.effectiveType) || ke.saveData), Re = /* @__PURE__ */ new WeakMap(), Ie = (e, r) => Pe.prototype.toString.call(e) === `[object ${r}]`;
495
- let Wt = 0;
496
- const Ue = (e) => {
497
- const r = typeof e, t = Ie(e, "Date"), n = Ie(e, "RegExp"), o = Ie(e, "Object");
498
- let a, i;
499
- if (Pe(e) === e && !t && !n) {
500
- if (a = Re.get(e), a) return a;
501
- if (a = ++Wt + "~", Re.set(e, a), Array.isArray(e)) {
502
- for (a = "@", i = 0; i < e.length; i++)
503
- a += Ue(e[i]) + ",";
504
- Re.set(e, a);
213
+ ].includes(wt.effectiveType) || wt.saveData), ut = /* @__PURE__ */ new WeakMap(), Rt = (t, e) => At.prototype.toString.call(t) === `[object ${e}]`;
214
+ let Ue = 0;
215
+ const bt = (t) => {
216
+ const e = typeof t, n = Rt(t, "Date"), r = Rt(t, "RegExp"), o = Rt(t, "Object");
217
+ let s, a;
218
+ if (At(t) === t && !n && !r) {
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]) + ",";
223
+ ut.set(t, s);
505
224
  }
506
225
  if (o) {
507
- a = "#";
508
- const f = Pe.keys(e).sort();
509
- for (; !_(i = f.pop()); )
510
- _(e[i]) || (a += i + ":" + Ue(e[i]) + ",");
511
- Re.set(e, a);
226
+ s = "#";
227
+ const m = At.keys(t).sort();
228
+ for (; !f(a = m.pop()); )
229
+ f(t[a]) || (s += a + ":" + bt(t[a]) + ",");
230
+ ut.set(t, s);
512
231
  }
513
232
  } else
514
- a = t ? e.toJSON() : r == "symbol" ? e.toString() : r == "string" ? JSON.stringify(e) : "" + e;
515
- return a;
516
- }, qe = (e) => {
517
- if (B(e))
233
+ s = n ? t.toJSON() : e == "symbol" ? t.toString() : e == "string" ? JSON.stringify(t) : "" + t;
234
+ return s;
235
+ }, Ft = (t) => {
236
+ if (N(t))
518
237
  try {
519
- e = e();
238
+ t = t();
520
239
  } catch {
521
- e = "";
240
+ t = "";
522
241
  }
523
- const r = e;
524
- return e = typeof e == "string" ? e : (Array.isArray(e) ? e.length : e) ? Ue(e) : "", [
525
- e,
526
- r
242
+ const e = t;
243
+ return t = typeof t == "string" ? t : (Array.isArray(t) ? t.length : t) ? bt(t) : "", [
244
+ t,
245
+ e
527
246
  ];
528
247
  };
529
- let $t = 0;
530
- const We = () => ++$t;
531
- async function pt(...e) {
532
- const [r, t, n, o] = e, a = re({
248
+ let Ge = 0;
249
+ const Vt = () => ++Ge;
250
+ async function ie(...t) {
251
+ const [e, n, r, o] = t, s = G({
533
252
  populateCache: !0,
534
253
  throwOnError: !0
535
254
  }, typeof o == "boolean" ? {
536
255
  revalidate: o
537
256
  } : o || {});
538
- let i = a.populateCache;
539
- const f = a.rollbackOnError;
540
- let E = a.optimisticData;
541
- const g = (p) => typeof f == "function" ? f(p) : f !== !1, v = a.throwOnError;
542
- if (B(t)) {
543
- const p = t, u = [], h = r.keys();
544
- for (const m of h)
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;
261
+ if (N(n)) {
262
+ const d = n, c = [], E = e.keys();
263
+ for (const l of E)
545
264
  // Skip the special useSWRInfinite and useSWRSubscription keys.
546
- !/^\$(inf|sub)\$/.test(m) && p(r.get(m)._k) && u.push(m);
547
- return Promise.all(u.map(d));
265
+ !/^\$(inf|sub)\$/.test(l) && d(e.get(l)._k) && c.push(l);
266
+ return Promise.all(c.map(u));
548
267
  }
549
- return d(t);
550
- async function d(p) {
551
- const [u] = qe(p);
552
- if (!u) return;
553
- const [h, m] = Et(r, u), [k, c, W, ne] = X.get(r), $ = () => {
554
- const P = k[u];
555
- return (B(a.revalidate) ? a.revalidate(h().data, p) : a.revalidate !== !1) && (delete W[u], delete ne[u], P && P[0]) ? P[0](dt).then(() => h().data) : h().data;
268
+ return u(n);
269
+ async function u(d) {
270
+ const [c] = Ft(d);
271
+ if (!c) return;
272
+ const [E, l] = se(e, c), [D, i, M, Q] = P.get(e), j = () => {
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;
556
275
  };
557
- if (e.length < 3)
558
- return $();
559
- let y = n, I;
560
- const Z = We();
561
- c[u] = [
562
- Z,
276
+ if (t.length < 3)
277
+ return j();
278
+ let R = r, I;
279
+ const k = Vt();
280
+ i[c] = [
281
+ k,
563
282
  0
564
283
  ];
565
- const O = !_(E), Q = h(), V = Q.data, q = Q._c, G = _(q) ? V : q;
566
- if (O && (E = B(E) ? E(G, V) : E, m({
567
- data: E,
568
- _c: G
569
- })), B(y))
284
+ const h = !f(_), $ = E(), V = $.data, H = $._c, W = f(H) ? V : H;
285
+ if (h && (_ = N(_) ? _(W, V) : _, l({
286
+ data: _,
287
+ _c: W
288
+ })), N(R))
570
289
  try {
571
- y = y(G);
572
- } catch (P) {
573
- I = P;
290
+ R = R(W);
291
+ } catch (C) {
292
+ I = C;
574
293
  }
575
- if (y && mt(y))
576
- if (y = await y.catch((P) => {
577
- I = P;
578
- }), Z !== c[u][0]) {
294
+ if (R && oe(R))
295
+ if (R = await R.catch((C) => {
296
+ I = C;
297
+ }), k !== i[c][0]) {
579
298
  if (I) throw I;
580
- return y;
581
- } else I && O && g(I) && (i = !0, m({
582
- data: G,
583
- _c: j
299
+ return R;
300
+ } else I && h && y(I) && (a = !0, l({
301
+ data: W,
302
+ _c: A
584
303
  }));
585
- if (i && !I)
586
- if (B(i)) {
587
- const P = i(y, G);
588
- m({
589
- data: P,
590
- error: j,
591
- _c: j
304
+ if (a && !I)
305
+ if (N(a)) {
306
+ const C = a(R, W);
307
+ l({
308
+ data: C,
309
+ error: A,
310
+ _c: A
592
311
  });
593
312
  } else
594
- m({
595
- data: y,
596
- error: j,
597
- _c: j
313
+ l({
314
+ data: R,
315
+ error: A,
316
+ _c: A
598
317
  });
599
- if (c[u][1] = We(), Promise.resolve($()).then(() => {
600
- m({
601
- _c: j
318
+ if (i[c][1] = Vt(), Promise.resolve(j()).then(() => {
319
+ l({
320
+ _c: A
602
321
  });
603
322
  }), I) {
604
- if (v) throw I;
323
+ if (O) throw I;
605
324
  return;
606
325
  }
607
- return y;
326
+ return R;
608
327
  }
609
328
  }
610
- const at = (e, r) => {
611
- for (const t in e)
612
- e[t][0] && e[t][0](r);
613
- }, qt = (e, r) => {
614
- if (!X.has(e)) {
615
- const t = re(Mt, r), n = /* @__PURE__ */ Object.create(null), o = pt.bind(j, e);
616
- let a = te;
617
- const i = /* @__PURE__ */ Object.create(null), f = (v, d) => {
618
- const p = i[v] || [];
619
- return i[v] = p, p.push(d), () => p.splice(p.indexOf(d), 1);
620
- }, E = (v, d, p) => {
621
- e.set(v, d);
622
- const u = i[v];
623
- if (u)
624
- for (const h of u)
625
- h(d, p);
626
- }, g = () => {
627
- if (!X.has(e) && (X.set(e, [
628
- n,
329
+ const Xt = (t, e) => {
330
+ for (const n in t)
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);
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) => {
340
+ t.set(O, u);
341
+ const c = a[O];
342
+ if (c)
343
+ for (const E of c)
344
+ E(u, d);
345
+ }, y = () => {
346
+ if (!P.has(t) && (P.set(t, [
347
+ r,
629
348
  /* @__PURE__ */ Object.create(null),
630
349
  /* @__PURE__ */ Object.create(null),
631
350
  /* @__PURE__ */ Object.create(null),
632
351
  o,
633
- E,
634
- f
635
- ]), !ge)) {
636
- const v = t.initFocus(setTimeout.bind(j, at.bind(j, n, lt))), d = t.initReconnect(setTimeout.bind(j, at.bind(j, n, ft)));
637
- a = () => {
638
- v && v(), d && d(), X.delete(e);
352
+ _,
353
+ m
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)));
356
+ s = () => {
357
+ O && O(), u && u(), P.delete(t);
639
358
  };
640
359
  }
641
360
  };
642
- return g(), [
643
- e,
361
+ return y(), [
362
+ t,
644
363
  o,
645
- g,
646
- a
364
+ y,
365
+ s
647
366
  ];
648
367
  }
649
368
  return [
650
- e,
651
- X.get(e)[4]
369
+ t,
370
+ P.get(t)[4]
652
371
  ];
653
- }, Gt = (e, r, t, n, o) => {
654
- const a = t.errorRetryCount, i = o.retryCount, f = ~~((Math.random() + 0.5) * (1 << (i < 8 ? i : 8))) * t.errorRetryInterval;
655
- !_(a) && i > a || setTimeout(n, f, o);
656
- }, Yt = je, [vt, Bt] = qt(/* @__PURE__ */ new Map()), Ht = re(
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(
657
376
  {
658
377
  // events
659
- onLoadingSlow: te,
660
- onSuccess: te,
661
- onError: te,
662
- onErrorRetry: Gt,
663
- onDiscarded: te,
378
+ onLoadingSlow: U,
379
+ onSuccess: U,
380
+ onError: U,
381
+ onErrorRetry: qe,
382
+ onDiscarded: U,
664
383
  // switches
665
384
  revalidateOnFocus: !0,
666
385
  revalidateOnReconnect: !0,
667
386
  revalidateIfStale: !0,
668
387
  shouldRetryOnError: !0,
669
388
  // timeouts
670
- errorRetryInterval: st ? 1e4 : 5e3,
389
+ errorRetryInterval: zt ? 1e4 : 5e3,
671
390
  focusThrottleInterval: 5 * 1e3,
672
391
  dedupingInterval: 2 * 1e3,
673
- loadingTimeout: st ? 5e3 : 3e3,
392
+ loadingTimeout: zt ? 5e3 : 3e3,
674
393
  // providers
675
- compare: Yt,
394
+ compare: Be,
676
395
  isPaused: () => !1,
677
- cache: vt,
678
- mutate: Bt,
396
+ cache: ae,
397
+ mutate: ke,
679
398
  fallback: {}
680
399
  },
681
400
  // use web preset by default
682
- Nt
683
- ), Jt = (e, r) => {
684
- const t = re(e, r);
685
- if (r) {
686
- const { use: n, fallback: o } = e, { use: a, fallback: i } = r;
687
- n && a && (t.use = n.concat(a)), o && i && (t.fallback = re(o, i));
401
+ Pe
402
+ ), He = (t, e) => {
403
+ const n = G(t, e);
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));
688
407
  }
689
- return t;
690
- }, Kt = it({}), zt = "$inf$", gt = _e && window.__SWR_DEVTOOLS_USE__, Xt = gt ? window.__SWR_DEVTOOLS_USE__ : [], Zt = () => {
691
- gt && (window.__SWR_DEVTOOLS_REACT__ = fe);
692
- }, Qt = (e) => B(e[1]) ? [
693
- e[0],
694
- e[1],
695
- e[2] || {}
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]) ? [
412
+ t[0],
413
+ t[1],
414
+ t[2] || {}
696
415
  ] : [
697
- e[0],
416
+ t[0],
698
417
  null,
699
- (e[1] === null ? e[2] : e[1]) || {}
700
- ], er = () => re(Ht, ct(Kt)), tr = (e) => (r, t, n) => e(r, t && ((...a) => {
701
- const [i] = qe(r), [, , , f] = X.get(vt);
702
- if (i.startsWith(zt))
703
- return t(...a);
704
- const E = f[i];
705
- return _(E) ? t(...a) : (delete f[i], E);
706
- }), n), rr = Xt.concat(tr), nr = (e) => function(...t) {
707
- const n = er(), [o, a, i] = Qt(t), f = Jt(n, i);
708
- let E = e;
709
- const { use: g } = f, v = (g || []).concat(rr);
710
- for (let d = v.length; d--; )
711
- E = v[d](E);
712
- return E(o, a || f.fetcher || null, f);
713
- }, or = (e, r, t) => {
714
- const n = r[e] || (r[e] = []);
715
- return n.push(t), () => {
716
- const o = n.indexOf(t);
717
- o >= 0 && (n[o] = n[n.length - 1], n.pop());
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))
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);
429
+ for (let u = O.length; u--; )
430
+ _ = O[u](_);
431
+ return _(o, s || m.fetcher || null, m);
432
+ }, nn = (t, e, n) => {
433
+ const r = e[t] || (e[t] = []);
434
+ return r.push(n), () => {
435
+ const o = r.indexOf(n);
436
+ o >= 0 && (r[o] = r[r.length - 1], r.pop());
718
437
  };
719
438
  };
720
- Zt();
721
- const Le = fe.use || // This extra generic is to avoid TypeScript mixing up the generic and JSX sytax
439
+ ze();
440
+ const gt = et.use || // This extra generic is to avoid TypeScript mixing up the generic and JSX sytax
722
441
  // and emitting an error.
723
442
  // We assume that this is only for the `use(thenable)` case, not `use(context)`.
724
443
  // https://github.com/facebook/react/blob/aed00dacfb79d17c53218404c52b1c7aa59c4a89/packages/react-server/src/ReactFizzThenable.js#L45
725
- ((e) => {
726
- switch (e.status) {
444
+ ((t) => {
445
+ switch (t.status) {
727
446
  case "pending":
728
- throw e;
447
+ throw t;
729
448
  case "fulfilled":
730
- return e.value;
449
+ return t.value;
731
450
  case "rejected":
732
- throw e.reason;
451
+ throw t.reason;
733
452
  default:
734
- throw e.status = "pending", e.then((r) => {
735
- e.status = "fulfilled", e.value = r;
736
- }, (r) => {
737
- e.status = "rejected", e.reason = r;
738
- }), e;
453
+ throw t.status = "pending", t.then((e) => {
454
+ t.status = "fulfilled", t.value = e;
455
+ }, (e) => {
456
+ t.status = "rejected", t.reason = e;
457
+ }), t;
739
458
  }
740
- }), xe = {
459
+ }), yt = {
741
460
  dedupe: !0
742
- }, sr = (e, r, t) => {
743
- const { cache: n, compare: o, suspense: a, fallbackData: i, revalidateOnMount: f, revalidateIfStale: E, refreshInterval: g, refreshWhenHidden: v, refreshWhenOffline: d, keepPreviousData: p } = t, [u, h, m, k] = X.get(n), [c, W] = qe(e), ne = se(!1), $ = se(!1), y = se(c), I = se(r), Z = se(t), O = () => Z.current, Q = () => O().isVisible() && O().isOnline(), [V, q, G, P] = Et(n, c), Y = se({}).current, oe = _(i) ? _(t.fallback) ? j : t.fallback[c] : i, de = (R, b) => {
744
- for (const C in Y) {
745
- const w = C;
746
- if (w === "data") {
747
- if (!o(R[w], b[w]) && (!_(R[w]) || !o(L, b[w])))
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;
465
+ if (v === "data") {
466
+ if (!o(S[v], p[v]) && (!f(S[v]) || !o(it, p[v])))
748
467
  return !1;
749
- } else if (b[w] !== R[w])
468
+ } else if (p[v] !== S[v])
750
469
  return !1;
751
470
  }
752
471
  return !0;
753
- }, me = bt(() => {
754
- const R = !c || !r ? !1 : _(f) ? O().isPaused() || a ? !1 : E !== !1 : f, b = (x) => {
755
- const K = re(x);
756
- return delete K._k, R ? {
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 ? {
757
476
  isValidating: !0,
758
477
  isLoading: !0,
759
- ...K
760
- } : K;
761
- }, C = V(), w = P(), U = b(C), le = C === w ? U : b(w);
762
- let D = U;
478
+ ...F
479
+ } : F;
480
+ }, g = V(), v = C(), b = p(g), z = g === v ? b : p(v);
481
+ let w = b;
763
482
  return [
764
483
  () => {
765
- const x = b(V());
766
- return de(x, D) ? (D.data = x.data, D.isLoading = x.isLoading, D.isValidating = x.isValidating, D.error = x.error, D) : (D = x, x);
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);
767
486
  },
768
- () => le
487
+ () => z
769
488
  ];
770
489
  }, [
771
- n,
772
- c
773
- ]), H = It.useSyncExternalStore(ae(
774
- (R) => G(c, (b, C) => {
775
- de(C, b) || R();
490
+ r,
491
+ i
492
+ ]), J = Le.useSyncExternalStore(lt(
493
+ (S) => W(i, (p, g) => {
494
+ xt(g, p) || S();
776
495
  }),
777
496
  // eslint-disable-next-line react-hooks/exhaustive-deps
778
497
  [
779
- n,
780
- c
498
+ r,
499
+ i
781
500
  ]
782
- ), me[0], me[1]), Ee = !ne.current, s = u[c] && u[c].length > 0, l = H.data, S = _(l) ? oe && mt(oe) ? Le(oe) : oe : l, T = H.error, F = se(S), L = p ? _(l) ? _(F.current) ? S : F.current : l : S, ce = s && !_(T) ? !1 : Ee && !_(f) ? f : O().isPaused() ? !1 : a ? _(S) ? !1 : E : _(S) || E, ue = !!(c && r && Ee && ce), A = _(H.isValidating) ? ue : H.isValidating, ee = _(H.isLoading) ? ue : H.isLoading, J = ae(
783
- async (R) => {
784
- const b = I.current;
785
- if (!c || !b || $.current || O().isPaused())
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())
786
505
  return !1;
787
- let C, w, U = !0;
788
- const le = R || {}, D = !m[c] || !le.dedupe, x = () => ot ? !$.current && c === y.current && ne.current : c === y.current, K = {
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 = {
789
508
  isValidating: !1,
790
509
  isLoading: !1
791
- }, He = () => {
792
- q(K);
793
- }, Je = () => {
794
- const N = m[c];
795
- N && N[1] === w && delete m[c];
796
- }, Ke = {
510
+ }, Wt = () => {
511
+ H(F);
512
+ }, qt = () => {
513
+ const L = l[i];
514
+ L && L[1] === v && delete l[i];
515
+ }, Bt = {
797
516
  isValidating: !0
798
517
  };
799
- _(V().data) && (Ke.isLoading = !0);
518
+ f(V().data) && (Bt.isLoading = !0);
800
519
  try {
801
- if (D && (q(Ke), t.loadingTimeout && _(V().data) && setTimeout(() => {
802
- U && x() && O().onLoadingSlow(c, t);
803
- }, t.loadingTimeout), m[c] = [
804
- b(W),
805
- We()
806
- ]), [C, w] = m[c], C = await C, D && setTimeout(Je, t.dedupingInterval), !m[c] || m[c][1] !== w)
807
- return D && x() && O().onDiscarded(c), !1;
808
- K.error = j;
809
- const N = h[c];
810
- if (!_(N) && // case 1
811
- (w <= N[0] || // case 2
812
- w <= N[1] || // case 3
813
- N[1] === 0))
814
- return He(), D && x() && O().onDiscarded(c), !1;
815
- const z = V().data;
816
- K.data = o(z, C) ? z : C, D && x() && O().onSuccess(C, c, t);
817
- } catch (N) {
818
- Je();
819
- const z = O(), { shouldRetryOnError: Te } = z;
820
- z.isPaused() || (K.error = N, D && x() && (z.onError(N, c, z), (Te === !0 || B(Te) && Te(N)) && (!O().revalidateOnFocus || !O().revalidateOnReconnect || Q()) && z.onErrorRetry(N, c, z, (_t) => {
821
- const we = u[c];
822
- we && we[0] && we[0](rt, _t);
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),
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;
527
+ F.error = A;
528
+ const L = E[i];
529
+ if (!f(L) && // case 1
530
+ (v <= L[0] || // case 2
531
+ v <= L[1] || // case 3
532
+ L[1] === 0))
533
+ return Wt(), w && T() && h().onDiscarded(i), !1;
534
+ const x = V().data;
535
+ F.data = o(x, g) ? x : g, w && T() && h().onSuccess(g, i, n);
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);
823
542
  }, {
824
- retryCount: (le.retryCount || 0) + 1,
543
+ retryCount: (z.retryCount || 0) + 1,
825
544
  dedupe: !0
826
545
  })));
827
546
  }
828
- return U = !1, He(), !0;
547
+ return b = !1, Wt(), !0;
829
548
  },
830
549
  // `setState` is immutable, and `eventsCallback`, `fnArg`, and
831
550
  // `keyValidating` are depending on `key`, so we can exclude them from
@@ -839,336 +558,263 @@ const Le = fe.use || // This extra generic is to avoid TypeScript mixing up the
839
558
  // even though it might cause unexpected behaviors.
840
559
  // eslint-disable-next-line react-hooks/exhaustive-deps
841
560
  [
842
- c,
843
- n
561
+ i,
562
+ r
844
563
  ]
845
- ), he = ae(
564
+ ), Gt = lt(
846
565
  // Use callback to make sure `keyRef.current` returns latest result every time
847
- (...R) => pt(n, y.current, ...R),
566
+ (...S) => ie(r, R.current, ...S),
848
567
  // eslint-disable-next-line react-hooks/exhaustive-deps
849
568
  []
850
569
  );
851
- if (Ce(() => {
852
- I.current = r, Z.current = t, _(l) || (F.current = l);
853
- }), Ce(() => {
854
- if (!c) return;
855
- const R = J.bind(j, xe);
856
- let b = 0;
857
- O().revalidateOnFocus && (b = Date.now() + O().focusThrottleInterval);
858
- const w = or(c, u, (U, le = {}) => {
859
- if (U == lt) {
860
- const D = Date.now();
861
- O().revalidateOnFocus && D > b && Q() && (b = D + O().focusThrottleInterval, R());
862
- } else if (U == ft)
863
- O().revalidateOnReconnect && Q() && R();
570
+ if (vt(() => {
571
+ I.current = e, k.current = n, f(Y) || (pt.current = Y);
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) {
579
+ const w = Date.now();
580
+ h().revalidateOnFocus && w > p && $() && (p = w + h().focusThrottleInterval, S());
581
+ } else if (b == ne)
582
+ h().revalidateOnReconnect && $() && S();
864
583
  else {
865
- if (U == dt)
866
- return J();
867
- if (U == rt)
868
- return J(le);
584
+ if (b == re)
585
+ return Z();
586
+ if (b == Kt)
587
+ return Z(z);
869
588
  }
870
589
  });
871
- return $.current = !1, y.current = c, ne.current = !0, q({
872
- _k: W
873
- }), ce && (_(S) || ge ? R() : Ut(R)), () => {
874
- $.current = !0, w();
590
+ return j.current = !1, R.current = i, Q.current = !0, H({
591
+ _k: M
592
+ }), jt && (f(q) || tt ? S() : je(S)), () => {
593
+ j.current = !0, v();
875
594
  };
876
595
  }, [
877
- c
878
- ]), Ce(() => {
879
- let R;
880
- function b() {
881
- const w = B(g) ? g(V().data) : g;
882
- w && R !== -1 && (R = setTimeout(C, w));
883
- }
884
- function C() {
885
- !V().error && (v || O().isVisible()) && (d || O().isOnline()) ? J(xe).then(b) : b();
886
- }
887
- return b(), () => {
888
- R && (clearTimeout(R), R = -1);
596
+ i
597
+ ]), vt(() => {
598
+ let S;
599
+ function p() {
600
+ const v = N(y) ? y(V().data) : y;
601
+ v && S !== -1 && (S = setTimeout(g, v));
602
+ }
603
+ function g() {
604
+ !V().error && (O || h().isVisible()) && (u || h().isOnline()) ? Z(yt).then(p) : p();
605
+ }
606
+ return p(), () => {
607
+ S && (clearTimeout(S), S = -1);
889
608
  };
890
609
  }, [
891
- g,
892
- v,
893
- d,
894
- c
895
- ]), Ot(L), a && _(S) && c) {
896
- if (!ot && ge)
610
+ y,
611
+ O,
612
+ u,
613
+ i
614
+ ]), ye(it), s && f(q) && i) {
615
+ if (!Yt && tt)
897
616
  throw new Error("Fallback data is required when using Suspense in SSR.");
898
- I.current = r, Z.current = t, $.current = !1;
899
- const R = k[c];
900
- if (!_(R)) {
901
- const b = he(R);
902
- Le(b);
903
- }
904
- if (_(T)) {
905
- const b = J(xe);
906
- _(L) || (b.status = "fulfilled", b.value = !0), Le(b);
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);
622
+ }
623
+ if (f(st)) {
624
+ const p = Z(yt);
625
+ f(it) || (p.status = "fulfilled", p.value = !0), gt(p);
907
626
  } else
908
- throw T;
627
+ throw st;
909
628
  }
910
629
  return {
911
- mutate: he,
630
+ mutate: Gt,
912
631
  get data() {
913
- return Y.data = !0, L;
632
+ return K.data = !0, it;
914
633
  },
915
634
  get error() {
916
- return Y.error = !0, T;
635
+ return K.error = !0, st;
917
636
  },
918
637
  get isValidating() {
919
- return Y.isValidating = !0, A;
638
+ return K.isValidating = !0, he;
920
639
  },
921
640
  get isLoading() {
922
- return Y.isLoading = !0, ee;
641
+ return K.isLoading = !0, Oe;
923
642
  }
924
643
  };
925
- }, Ge = nr(sr), pr = () => null, Ye = async (e, r = { method: "GET" }) => {
926
- throw new Error("Figma API token is not available.");
927
- }, ar = "https://api.figma.com", ir = `${ar}/v1/files`, Be = (e) => `${ir}/${e}/variables`, vr = (e) => {
928
- const r = ie(), { data: t, error: n, isLoading: o, isValidating: a } = Ge(
929
- r ? Be(e) : null,
930
- Ye
931
- ), i = t != null && t.meta ? Object.values(t.meta.variables) : [], f = t != null && t.meta ? t.meta.variables : {};
932
- return {
933
- variables: i,
934
- variablesById: f,
935
- isLoading: o,
936
- isValidating: a,
937
- error: n ?? (t && "message" in t ? new Error(t.message) : null)
938
- };
939
- }, gr = (e) => {
940
- const r = ie(), { data: t, error: n, isLoading: o, isValidating: a } = Ge(
941
- r ? Be(e) : null,
942
- Ye
943
- ), i = t != null && t.meta ? Object.values(t.meta.variableCollections) : [], f = t != null && t.meta ? t.meta.variableCollections : {};
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) => {
645
+ if (!e)
646
+ throw new Error(rt);
647
+ const n = await fetch(t, {
648
+ headers: {
649
+ [pe]: e,
650
+ "Content-Type": Ee
651
+ }
652
+ });
653
+ if (!n.ok) {
654
+ const r = await n.json();
655
+ throw new Error(r.message || me);
656
+ }
657
+ 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(
660
+ t && n ? [n, t] : null,
661
+ cn
662
+ );
944
663
  return {
945
- collections: i,
946
- collectionsById: f,
947
- isLoading: o,
664
+ data: r,
665
+ isLoading: s,
948
666
  isValidating: a,
949
- error: n ?? (t && "message" in t ? new Error(t.message) : null)
667
+ error: o
950
668
  };
951
- }, _r = (e) => {
952
- const r = ie(), { data: t, error: n, isLoading: o, isValidating: a } = Ge(
953
- r ? Be(e) : null,
954
- Ye
955
- ), i = [], f = {}, E = {};
956
- if (t != null && t.meta)
957
- for (const g of Object.values(
958
- t.meta.variableCollections
959
- )) {
960
- i.push(...g.modes), f[g.id] = g.modes;
961
- for (const v of g.modes)
962
- E[v.modeId] = v;
963
- }
669
+ }, pn = () => {
670
+ const { data: t } = _e(), e = ft(
671
+ () => t != null && t.meta ? Object.values(t.meta.variableCollections) : [],
672
+ [t]
673
+ ), n = ft(
674
+ () => t != null && t.meta ? t.meta.variableCollections : {},
675
+ [t]
676
+ );
964
677
  return {
965
- modes: i,
966
- modesByCollectionId: f,
967
- modesById: E,
968
- isLoading: o,
969
- isValidating: a,
970
- error: n ?? (t && "message" in t ? new Error(t.message) : null)
678
+ collections: e,
679
+ collectionsById: n
971
680
  };
972
- };
973
- async function cr(e, r, t) {
974
- const n = `https://api.figma.com/v1/files/${r}/variables`;
975
- try {
976
- const o = await fetch(n, {
977
- method: "POST",
978
- headers: {
979
- "Content-Type": "application/json",
980
- "X-FIGMA-TOKEN": e
981
- },
982
- body: JSON.stringify(t)
983
- }), a = await o.json();
984
- return o.ok ? {
985
- error: !1,
986
- status: o.status,
987
- meta: a.meta
988
- } : {
989
- error: !0,
990
- status: o.status,
991
- message: a.message || "Failed to perform bulk update."
992
- };
993
- } catch (o) {
994
- return {
995
- error: !0,
996
- status: 500,
997
- message: o instanceof Error ? o.message : "An unknown error occurred."
998
- };
999
- }
1000
- }
1001
- const hr = () => {
1002
- const e = ie(), [r, t] = M(!1), [n, o] = M(null), [a, i] = M(null);
1003
- return { bulkUpdate: ae(
1004
- async (E, g) => {
1005
- if (!e) {
1006
- o("Figma API token is not provided.");
1007
- return;
681
+ }, mn = () => {
682
+ const { data: t } = _e();
683
+ return ft(() => {
684
+ const e = [], n = {}, r = {};
685
+ if (t != null && t.meta)
686
+ for (const o of Object.values(
687
+ t.meta.variableCollections
688
+ )) {
689
+ e.push(...o.modes), n[o.id] = o.modes;
690
+ for (const s of o.modes)
691
+ r[s.modeId] = s;
1008
692
  }
1009
- t(!0), o(null);
1010
- const v = await cr(e, E, g);
1011
- i(v), v.error && o(v.message || "An error occurred during the bulk update."), t(!1);
1012
- },
1013
- [e]
1014
- ), loading: r, error: n, data: a };
1015
- };
1016
- async function ur(e, r) {
1017
- const t = "https://api.figma.com/v1/variables";
1018
- try {
1019
- const n = await fetch(t, {
1020
- method: "POST",
1021
- headers: {
1022
- "Content-Type": "application/json",
1023
- "X-FIGMA-TOKEN": e
1024
- },
1025
- body: JSON.stringify(r)
1026
- });
1027
- if (!n.ok) {
1028
- const a = await n.json();
1029
- return {
1030
- error: !0,
1031
- status: n.status,
1032
- message: a.message || "Failed to create Figma variable"
1033
- };
1034
- }
1035
- const o = await n.json();
1036
- return {
1037
- error: !1,
1038
- status: n.status,
1039
- variable: o
1040
- };
1041
- } catch (n) {
1042
693
  return {
1043
- error: !0,
1044
- status: 500,
1045
- message: n instanceof Error ? n.message : "An unknown error occurred"
694
+ modes: e,
695
+ modesByCollectionId: n,
696
+ modesById: r
1046
697
  };
1047
- }
1048
- }
1049
- const Sr = () => {
1050
- const e = ie(), [r, t] = M(!1), [n, o] = M(null), [a, i] = M(null);
1051
- return { createVariable: ae(
1052
- async (E) => {
1053
- if (!e) {
1054
- o("Figma API token is not provided.");
1055
- return;
1056
- }
1057
- t(!0), o(null);
1058
- const g = await ur(e, E);
1059
- i(g), g.error && o(g.message || "An error occurred."), t(!1);
1060
- },
1061
- [e]
1062
- ), loading: r, error: n, data: a };
698
+ }, [t]);
699
+ }, _n = () => {
700
+ const { token: t } = X();
701
+ return t;
1063
702
  };
1064
- async function lr(e, r) {
1065
- const t = `https://api.figma.com/v1/variables/${r}`;
1066
- try {
1067
- const n = await fetch(t, {
1068
- method: "DELETE",
1069
- headers: {
1070
- "Content-Type": "application/json",
1071
- "X-FIGMA-TOKEN": e
1072
- }
1073
- });
1074
- if (!n.ok) {
1075
- const o = await n.json();
1076
- return {
1077
- error: !0,
1078
- status: n.status,
1079
- message: o.message || "Failed to delete Figma variable"
1080
- };
1081
- }
1082
- return {
1083
- error: !1,
1084
- status: n.status
1085
- };
1086
- } catch (n) {
1087
- return {
1088
- error: !0,
1089
- status: 500,
1090
- message: n instanceof Error ? n.message : "An unknown error occurred"
1091
- };
703
+ function un(t, e) {
704
+ switch (e.type) {
705
+ case "loading":
706
+ return { ...t, status: "loading", error: null };
707
+ case "success":
708
+ return { ...t, status: "success", data: e.payload };
709
+ case "error":
710
+ return { ...t, status: "error", error: e.payload };
711
+ default:
712
+ return t;
1092
713
  }
1093
714
  }
1094
- const br = () => {
1095
- const e = ie(), [r, t] = M(!1), [n, o] = M(null), [a, i] = M(null);
1096
- return { deleteVariable: ae(
1097
- async (E) => {
1098
- if (!e) {
1099
- o("Figma API token is not provided.");
1100
- return;
1101
- }
1102
- t(!0), o(null);
1103
- const g = await lr(e, E);
1104
- i(g), g.error && o(g.message || "An error occurred."), t(!1);
1105
- },
1106
- [e]
1107
- ), loading: r, error: n, data: a };
1108
- };
1109
- async function fr(e, r, t) {
1110
- const n = `https://api.figma.com/v1/variables/${r}`;
1111
- try {
1112
- const o = await fetch(n, {
1113
- method: "PUT",
1114
- headers: {
1115
- "Content-Type": "application/json",
1116
- "X-FIGMA-TOKEN": e
715
+ const dt = (t) => {
716
+ const e = {
717
+ status: "idle",
718
+ data: null,
719
+ error: null
720
+ }, [n, r] = Te(un, e);
721
+ return {
722
+ mutate: lt(
723
+ async (s) => {
724
+ r({ type: "loading" });
725
+ try {
726
+ const a = await t(s);
727
+ return r({ type: "success", payload: a }), a;
728
+ } catch (a) {
729
+ r({ type: "error", payload: a });
730
+ return;
731
+ }
1117
732
  },
1118
- body: JSON.stringify(t)
1119
- });
1120
- if (!o.ok) {
1121
- const a = await o.json();
1122
- return {
1123
- error: !0,
1124
- status: o.status,
1125
- message: a.message || "Failed to update Figma variable"
1126
- };
1127
- }
1128
- return {
1129
- error: !1,
1130
- status: o.status
1131
- };
1132
- } catch (o) {
1133
- return {
1134
- error: !0,
1135
- status: 500,
1136
- message: o instanceof Error ? o.message : "An unknown error occurred"
1137
- };
1138
- }
1139
- }
1140
- const Or = () => {
1141
- const e = ie(), [r, t] = M(!1), [n, o] = M(null), [a, i] = M(null);
1142
- return { updateVariable: ae(
1143
- async (E, g) => {
1144
- if (!e) {
1145
- o("Figma API token is not provided.");
1146
- return;
1147
- }
1148
- t(!0), o(null);
1149
- const v = await fr(e, E, g);
1150
- i(v), v.error && o(v.message || "An error occurred."), t(!1);
733
+ [t]
734
+ ),
735
+ ...n,
736
+ isLoading: n.status === "loading",
737
+ isSuccess: n.status === "success",
738
+ isError: n.status === "error"
739
+ };
740
+ }, Et = async (t, e, n, r) => {
741
+ if (!e)
742
+ throw new Error(rt);
743
+ const o = await fetch(t, {
744
+ method: n,
745
+ headers: {
746
+ [pe]: e,
747
+ "Content-Type": Ee
1151
748
  },
1152
- [e]
1153
- ), loading: r, error: n, data: a };
749
+ ...r && { body: JSON.stringify(r) }
750
+ });
751
+ if (!o.ok) {
752
+ const s = await o.json();
753
+ throw new Error(s.message || me);
754
+ }
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
+ 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();
777
+ return dt(
778
+ async ({ variableId: n, payload: r }) => {
779
+ if (!t)
780
+ throw new Error("A Figma API token is required.");
781
+ const o = de(n);
782
+ return await Et(
783
+ o,
784
+ t,
785
+ "PUT",
786
+ r
787
+ );
788
+ }
789
+ );
790
+ }, vn = () => {
791
+ const { token: t } = X();
792
+ return dt(async (n) => {
793
+ if (!t)
794
+ throw new Error(rt);
795
+ return await Et(
796
+ fe,
797
+ t,
798
+ "PUT",
799
+ n
800
+ );
801
+ });
1154
802
  };
1155
- function Rr(e, r) {
1156
- return e.filter((t) => {
1157
- let n = !0;
1158
- return r.resolvedType && (n = n && t.resolvedType === r.resolvedType), r.name && (n = n && t.name.includes(r.name)), n;
803
+ function wn(t, e) {
804
+ return t.filter((n) => {
805
+ let r = !0;
806
+ return e.resolvedType && (r = r && n.resolvedType === e.resolvedType), e.name && (r = r && n.name.includes(e.name)), r;
1159
807
  });
1160
808
  }
1161
809
  export {
1162
- Er as FigmaVarsProvider,
1163
- Ye as fetchWithAuth,
1164
- Rr as filterVariables,
1165
- pr as getFigmaToken,
1166
- hr as useBulkUpdateVariables,
1167
- Sr as useCreateVariable,
1168
- br as useDeleteVariable,
1169
- ie as useFigmaToken,
1170
- Or as useUpdateVariable,
1171
- gr as useVariableCollections,
1172
- _r as useVariableModes,
1173
- vr as useVariables
810
+ 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,
817
+ pn as useVariableCollections,
818
+ mn as useVariableModes,
819
+ _e as useVariables
1174
820
  };