@figma-vars/hooks 1.2.0 → 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.
- package/README.md +73 -15
- package/dist/figma-vars-hooks.js +559 -799
- package/dist/figma-vars-hooks.umd.cjs +3 -24
- package/dist/index.d.ts +936 -11
- package/package.json +17 -8
- package/dist/constants/index.d.ts +0 -3
- package/dist/contexts/FigmaTokenContext.d.ts +0 -49
- package/dist/hooks/useFigmaToken.d.ts +0 -17
- package/dist/hooks/useVariableCollections.d.ts +0 -26
- package/dist/hooks/useVariableModes.d.ts +0 -16
- package/dist/hooks/useVariables.d.ts +0 -25
- package/dist/mutations/bulkUpdateVariables.d.ts +0 -25
- package/dist/mutations/createVariable.d.ts +0 -26
- package/dist/mutations/deleteVariable.d.ts +0 -19
- package/dist/mutations/updateVariable.d.ts +0 -26
- package/dist/types/figma.d.ts +0 -111
- package/dist/types/hooks.d.ts +0 -12
- package/dist/types/index.d.ts +0 -3
- package/dist/types/mutations.d.ts +0 -114
- package/dist/utils/fetcher.d.ts +0 -13
- package/dist/utils/filterVariables.d.ts +0 -31
|
@@ -1,25 +1,4 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
* @license React
|
|
3
|
-
* react-jsx-runtime.production.js
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the MIT license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Ye;function dt(){if(Ye)return ue;Ye=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function n(o,s,a){var u=null;if(a!==void 0&&(u=""+a),s.key!==void 0&&(u=""+s.key),"key"in s){a={};for(var h in s)h!=="key"&&(a[h]=s[h])}else a=s;return s=a.ref,{$$typeof:e,type:o,key:u,ref:s!==void 0?s:null,props:a}}return ue.Fragment=t,ue.jsx=n,ue.jsxs=n,ue}var le={};/**
|
|
10
|
-
* @license React
|
|
11
|
-
* react-jsx-runtime.development.js
|
|
12
|
-
*
|
|
13
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the MIT license found in the
|
|
16
|
-
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var Ge;function mt(){return Ge||(Ge=1,process.env.NODE_ENV!=="production"&&function(){function e(r){if(r==null)return null;if(typeof r=="function")return r.$$typeof===F?null:r.displayName||r.name||null;if(typeof r=="string")return r;switch(r){case d:return"Fragment";case i:return"Profiler";case L:return"StrictMode";case y:return"Suspense";case P:return"SuspenseList";case ne:return"Activity"}if(typeof r=="object")switch(typeof r.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),r.$$typeof){case v:return"Portal";case oe:return(r.displayName||"Context")+".Provider";case G:return(r._context.displayName||"Context")+".Consumer";case H:var l=r.render;return r=r.displayName,r||(r=l.displayName||l.name||"",r=r!==""?"ForwardRef("+r+")":"ForwardRef"),r;case te:return l=r.displayName||null,l!==null?l:e(r.type)||"Memo";case O:l=r._payload,r=r._init;try{return e(r(l))}catch{}}return null}function t(r){return""+r}function n(r){try{t(r);var l=!1}catch{l=!0}if(l){l=console;var S=l.error,b=typeof Symbol=="function"&&Symbol.toStringTag&&r[Symbol.toStringTag]||r.constructor.name||"Object";return S.call(l,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",b),t(r)}}function o(r){if(r===d)return"<>";if(typeof r=="object"&&r!==null&&r.$$typeof===O)return"<...>";try{var l=e(r);return l?"<"+l+">":"<...>"}catch{return"<...>"}}function s(){var r=B.A;return r===null?null:r.getOwner()}function a(){return Error("react-stack-top-frame")}function u(r){if(J.call(r,"key")){var l=Object.getOwnPropertyDescriptor(r,"key").get;if(l&&l.isReactWarning)return!1}return r.key!==void 0}function h(r,l){function S(){se||(se=!0,console.error("%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)",l))}S.isReactWarning=!0,Object.defineProperty(r,"key",{get:S,configurable:!0})}function _(){var r=e(this.type);return me[r]||(me[r]=!0,console.error("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.")),r=this.props.ref,r!==void 0?r:null}function C(r,l,S,b,M,V,ae,ie){return S=V.ref,r={$$typeof:c,type:r,key:l,props:V,_owner:M},(S!==void 0?S:null)!==null?Object.defineProperty(r,"ref",{enumerable:!1,get:_}):Object.defineProperty(r,"ref",{enumerable:!1,value:null}),r._store={},Object.defineProperty(r._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(r,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(r,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:ae}),Object.defineProperty(r,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:ie}),Object.freeze&&(Object.freeze(r.props),Object.freeze(r)),r}function w(r,l,S,b,M,V,ae,ie){var A=l.children;if(A!==void 0)if(b)if(N(A)){for(b=0;b<A.length;b++)f(A[b]);Object.freeze&&Object.freeze(A)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else f(A);if(J.call(l,"key")){A=e(r);var re=Object.keys(l).filter(function(Re){return Re!=="key"});b=0<re.length?"{key: someKey, "+re.join(": ..., ")+": ...}":"{key: someKey}",pe[A+b]||(re=0<re.length?"{"+re.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
|
-
let props = %s;
|
|
19
|
-
<%s {...props} />
|
|
20
|
-
React keys must be passed directly to JSX without using spread:
|
|
21
|
-
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,b,A,re,A),pe[A+b]=!0)}if(A=null,S!==void 0&&(n(S),A=""+S),u(l)&&(n(l.key),A=""+l.key),"key"in l){S={};for(var q in l)q!=="key"&&(S[q]=l[q])}else S=l;return A&&h(S,typeof r=="function"?r.displayName||r.name||"Unknown":r),C(r,A,V,M,s(),S,ae,ie)}function f(r){typeof r=="object"&&r!==null&&r.$$typeof===c&&r._store&&(r._store.validated=1)}var m=p,c=Symbol.for("react.transitional.element"),v=Symbol.for("react.portal"),d=Symbol.for("react.fragment"),L=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),G=Symbol.for("react.consumer"),oe=Symbol.for("react.context"),H=Symbol.for("react.forward_ref"),y=Symbol.for("react.suspense"),P=Symbol.for("react.suspense_list"),te=Symbol.for("react.memo"),O=Symbol.for("react.lazy"),ne=Symbol.for("react.activity"),F=Symbol.for("react.client.reference"),B=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,J=Object.prototype.hasOwnProperty,N=Array.isArray,K=console.createTask?console.createTask:function(){return null};m={"react-stack-bottom-frame":function(r){return r()}};var se,me={},Ee=m["react-stack-bottom-frame"].bind(m,a)(),z=K(o(a)),pe={};le.Fragment=d,le.jsx=function(r,l,S,b,M){var V=1e4>B.recentlyCreatedOwnerStacks++;return w(r,l,S,!1,b,M,V?Error("react-stack-top-frame"):Ee,V?K(o(r)):z)},le.jsxs=function(r,l,S,b,M){var V=1e4>B.recentlyCreatedOwnerStacks++;return w(r,l,S,!0,b,M,V?Error("react-stack-top-frame"):Ee,V?K(o(r)):z)}}()),le}var He;function Et(){return He||(He=1,process.env.NODE_ENV==="production"?he.exports=dt():he.exports=mt()),he.exports}var pt=Et();const Be=p.createContext(void 0),ht=({children:e,token:t,fileKey:n})=>pt.jsx(Be.Provider,{value:{token:t,fileKey:n},children:e}),Je=()=>{const e=p.useContext(Be);if(e===void 0)throw new Error("useFigmaTokenContext must be used within a FigmaVarsProvider");return e},vt=()=>{const{token:e}=Je();return e};var ve={exports:{}},Oe={};/**
|
|
1
|
+
(function(g,Z){typeof exports=="object"&&typeof module<"u"?Z(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],Z):(g=typeof globalThis<"u"?globalThis:g||self,Z(g["@figma-vars/hooks"]={},g["react/jsx-runtime"],g.React))})(this,function(g,Z,m){"use strict";const Me=m.createContext(void 0),mt=({children:e,token:t,fileKey:n})=>Z.jsx(Me.Provider,{value:{token:t,fileKey:n},children:e}),H=()=>{const e=m.useContext(Me);if(e===void 0)throw new Error("useFigmaTokenContext must be used within a FigmaVarsProvider");return e};var se={exports:{}},Ee={};/**
|
|
23
2
|
* @license React
|
|
24
3
|
* use-sync-external-store-shim.production.js
|
|
25
4
|
*
|
|
@@ -27,7 +6,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
27
6
|
*
|
|
28
7
|
* This source code is licensed under the MIT license found in the
|
|
29
8
|
* LICENSE file in the root directory of this source tree.
|
|
30
|
-
*/var
|
|
9
|
+
*/var Pe;function pt(){if(Pe)return Ee;Pe=1;var e=m;function t(c,d){return c===d&&(c!==0||1/c===1/d)||c!==c&&d!==d}var n=typeof Object.is=="function"?Object.is:t,r=e.useState,o=e.useEffect,s=e.useLayoutEffect,a=e.useDebugValue;function h(c,d){var u=d(),E=r({inst:{value:u,getSnapshot:d}}),l=E[0].inst,C=E[1];return s(function(){l.value=u,l.getSnapshot=d,S(l)&&C({inst:l})},[c,u,d]),o(function(){return S(l)&&C({inst:l}),c(function(){S(l)&&C({inst:l})})},[c]),a(u),u}function S(c){var d=c.getSnapshot;c=c.value;try{var u=d();return!n(c,u)}catch{return!0}}function D(c,d){return d()}var O=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?D:h;return Ee.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:O,Ee}var me={};/**
|
|
31
10
|
* @license React
|
|
32
11
|
* use-sync-external-store-shim.development.js
|
|
33
12
|
*
|
|
@@ -35,4 +14,4 @@ React keys must be passed directly to JSX without using spread:
|
|
|
35
14
|
*
|
|
36
15
|
* This source code is licensed under the MIT license found in the
|
|
37
16
|
* LICENSE file in the root directory of this source tree.
|
|
38
|
-
*/var Xe;function _t(){return Xe||(Xe=1,process.env.NODE_ENV!=="production"&&function(){function e(c,v){return c===v&&(c!==0||1/c===1/v)||c!==c&&v!==v}function t(c,v){w||s.startTransition===void 0||(w=!0,console.error("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."));var d=v();if(!f){var L=v();a(d,L)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}L=u({inst:{value:d,getSnapshot:v}});var i=L[0].inst,G=L[1];return _(function(){i.value=d,i.getSnapshot=v,n(i)&&G({inst:i})},[c,d,v]),h(function(){return n(i)&&G({inst:i}),c(function(){n(i)&&G({inst:i})})},[c]),C(d),d}function n(c){var v=c.getSnapshot;c=c.value;try{var d=v();return!a(c,d)}catch{return!0}}function o(c,v){return v()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var s=p,a=typeof Object.is=="function"?Object.is:e,u=s.useState,h=s.useEffect,_=s.useLayoutEffect,C=s.useDebugValue,w=!1,f=!1,m=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?o:t;Te.useSyncExternalStore=s.useSyncExternalStore!==void 0?s.useSyncExternalStore:m,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Te}var ze;function Rt(){return ze||(ze=1,process.env.NODE_ENV==="production"?ve.exports=St():ve.exports=_t()),ve.exports}var Ot=Rt();const qe=0,Ze=1,Qe=2,$e=3;var et=Object.prototype.hasOwnProperty;function we(e,t){var n,o;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((o=e.length)===t.length)for(;o--&&we(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(et.call(e,n)&&++o&&!et.call(t,n)||!(n in t)||!we(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const X=new WeakMap,$=()=>{},k=$(),be=Object,E=e=>e===k,Y=e=>typeof e=="function",ee=(e,t)=>({...e,...t}),tt=e=>Y(e.then),ge={},Se={},ye="undefined",fe=typeof window!=ye,Ae=typeof document!=ye,Tt=fe&&"Deno"in window,wt=()=>fe&&typeof window.requestAnimationFrame!=ye,nt=(e,t)=>{const n=X.get(e);return[()=>!E(t)&&e.get(t)||ge,o=>{if(!E(t)){const s=e.get(t);t in Se||(Se[t]=s),n[5](t,ee(s,o),s||ge)}},n[6],()=>!E(t)&&t in Se?Se[t]:!E(t)&&e.get(t)||ge]};let Ce=!0;const bt=()=>Ce,[De,Ie]=fe&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[$,$],gt=()=>{const e=Ae&&document.visibilityState;return E(e)||e!=="hidden"},yt=e=>(Ae&&document.addEventListener("visibilitychange",e),De("focus",e),()=>{Ae&&document.removeEventListener("visibilitychange",e),Ie("focus",e)}),At=e=>{const t=()=>{Ce=!0,e()},n=()=>{Ce=!1};return De("online",t),De("offline",n),()=>{Ie("online",t),Ie("offline",n)}},Ct={isOnline:bt,isVisible:gt},Dt={initFocus:yt,initReconnect:At},rt=!p.useId,de=!fe||Tt,It=e=>wt()?window.requestAnimationFrame(e):setTimeout(e,1),je=de?p.useEffect:p.useLayoutEffect,ke=typeof navigator<"u"&&navigator.connection,ot=!de&&ke&&(["slow-2g","2g"].includes(ke.effectiveType)||ke.saveData),_e=new WeakMap,Le=(e,t)=>be.prototype.toString.call(e)===`[object ${t}]`;let jt=0;const Pe=e=>{const t=typeof e,n=Le(e,"Date"),o=Le(e,"RegExp"),s=Le(e,"Object");let a,u;if(be(e)===e&&!n&&!o){if(a=_e.get(e),a)return a;if(a=++jt+"~",_e.set(e,a),Array.isArray(e)){for(a="@",u=0;u<e.length;u++)a+=Pe(e[u])+",";_e.set(e,a)}if(s){a="#";const h=be.keys(e).sort();for(;!E(u=h.pop());)E(e[u])||(a+=u+":"+Pe(e[u])+",");_e.set(e,a)}}else a=n?e.toJSON():t=="symbol"?e.toString():t=="string"?JSON.stringify(e):""+e;return a},Ve=e=>{if(Y(e))try{e=e()}catch{e=""}const t=e;return e=typeof e=="string"?e:(Array.isArray(e)?e.length:e)?Pe(e):"",[e,t]};let kt=0;const xe=()=>++kt;async function st(...e){const[t,n,o,s]=e,a=ee({populateCache:!0,throwOnError:!0},typeof s=="boolean"?{revalidate:s}:s||{});let u=a.populateCache;const h=a.rollbackOnError;let _=a.optimisticData;const C=m=>typeof h=="function"?h(m):h!==!1,w=a.throwOnError;if(Y(n)){const m=n,c=[],v=t.keys();for(const d of v)!/^\$(inf|sub)\$/.test(d)&&m(t.get(d)._k)&&c.push(d);return Promise.all(c.map(f))}return f(n);async function f(m){const[c]=Ve(m);if(!c)return;const[v,d]=nt(t,c),[L,i,G,oe]=X.get(t),H=()=>{const N=L[c];return(Y(a.revalidate)?a.revalidate(v().data,m):a.revalidate!==!1)&&(delete G[c],delete oe[c],N&&N[0])?N[0](Qe).then(()=>v().data):v().data};if(e.length<3)return H();let y=o,P;const te=xe();i[c]=[te,0];const O=!E(_),ne=v(),F=ne.data,B=ne._c,J=E(B)?F:B;if(O&&(_=Y(_)?_(J,F):_,d({data:_,_c:J})),Y(y))try{y=y(J)}catch(N){P=N}if(y&&tt(y))if(y=await y.catch(N=>{P=N}),te!==i[c][0]){if(P)throw P;return y}else P&&O&&C(P)&&(u=!0,d({data:J,_c:k}));if(u&&!P)if(Y(u)){const N=u(y,J);d({data:N,error:k,_c:k})}else d({data:y,error:k,_c:k});if(i[c][1]=xe(),Promise.resolve(H()).then(()=>{d({_c:k})}),P){if(w)throw P;return}return y}}const at=(e,t)=>{for(const n in e)e[n][0]&&e[n][0](t)},Lt=(e,t)=>{if(!X.has(e)){const n=ee(Dt,t),o=Object.create(null),s=st.bind(k,e);let a=$;const u=Object.create(null),h=(w,f)=>{const m=u[w]||[];return u[w]=m,m.push(f),()=>m.splice(m.indexOf(f),1)},_=(w,f,m)=>{e.set(w,f);const c=u[w];if(c)for(const v of c)v(f,m)},C=()=>{if(!X.has(e)&&(X.set(e,[o,Object.create(null),Object.create(null),Object.create(null),s,_,h]),!de)){const w=n.initFocus(setTimeout.bind(k,at.bind(k,o,qe))),f=n.initReconnect(setTimeout.bind(k,at.bind(k,o,Ze)));a=()=>{w&&w(),f&&f(),X.delete(e)}}};return C(),[e,s,C,a]}return[e,X.get(e)[4]]},Pt=(e,t,n,o,s)=>{const a=n.errorRetryCount,u=s.retryCount,h=~~((Math.random()+.5)*(1<<(u<8?u:8)))*n.errorRetryInterval;!E(a)&&u>a||setTimeout(o,h,s)},Vt=we,[it,xt]=Lt(new Map),Nt=ee({onLoadingSlow:$,onSuccess:$,onError:$,onErrorRetry:Pt,onDiscarded:$,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:ot?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:ot?5e3:3e3,compare:Vt,isPaused:()=>!1,cache:it,mutate:xt,fallback:{}},Ct),Ft=(e,t)=>{const n=ee(e,t);if(t){const{use:o,fallback:s}=e,{use:a,fallback:u}=t;o&&a&&(n.use=o.concat(a)),s&&u&&(n.fallback=ee(s,u))}return n},Mt=p.createContext({}),Ut="$inf$",ct=fe&&window.__SWR_DEVTOOLS_USE__,Wt=ct?window.__SWR_DEVTOOLS_USE__:[],Yt=()=>{ct&&(window.__SWR_DEVTOOLS_REACT__=p)},Gt=e=>Y(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],Ht=()=>ee(Nt,p.useContext(Mt)),Bt=e=>(t,n,o)=>e(t,n&&((...a)=>{const[u]=Ve(t),[,,,h]=X.get(it);if(u.startsWith(Ut))return n(...a);const _=h[u];return E(_)?n(...a):(delete h[u],_)}),o),Jt=Wt.concat(Bt),Kt=e=>function(...n){const o=Ht(),[s,a,u]=Gt(n),h=Ft(o,u);let _=e;const{use:C}=h,w=(C||[]).concat(Jt);for(let f=w.length;f--;)_=w[f](_);return _(s,a||h.fetcher||null,h)},Xt=(e,t,n)=>{const o=t[e]||(t[e]=[]);return o.push(n),()=>{const s=o.indexOf(n);s>=0&&(o[s]=o[o.length-1],o.pop())}};Yt();const Ne=p.use||(e=>{switch(e.status){case"pending":throw e;case"fulfilled":return e.value;case"rejected":throw e.reason;default:throw e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e}}),Fe={dedupe:!0},zt=Kt((e,t,n)=>{const{cache:o,compare:s,suspense:a,fallbackData:u,revalidateOnMount:h,revalidateIfStale:_,refreshInterval:C,refreshWhenHidden:w,refreshWhenOffline:f,keepPreviousData:m}=n,[c,v,d,L]=X.get(o),[i,G]=Ve(e),oe=p.useRef(!1),H=p.useRef(!1),y=p.useRef(i),P=p.useRef(t),te=p.useRef(n),O=()=>te.current,ne=()=>O().isVisible()&&O().isOnline(),[F,B,J,N]=nt(o,i),K=p.useRef({}).current,se=E(u)?E(n.fallback)?k:n.fallback[i]:u,me=(T,R)=>{for(const j in K){const g=j;if(g==="data"){if(!s(T[g],R[g])&&(!E(T[g])||!s(V,R[g])))return!1}else if(R[g]!==T[g])return!1}return!0},Ee=p.useMemo(()=>{const T=!i||!t?!1:E(h)?O().isPaused()||a?!1:_!==!1:h,R=x=>{const Z=ee(x);return delete Z._k,T?{isValidating:!0,isLoading:!0,...Z}:Z},j=F(),g=N(),W=R(j),ce=j===g?W:R(g);let D=W;return[()=>{const x=R(F());return me(x,D)?(D.data=x.data,D.isLoading=x.isLoading,D.isValidating=x.isValidating,D.error=x.error,D):(D=x,x)},()=>ce]},[o,i]),z=Ot.useSyncExternalStore(p.useCallback(T=>J(i,(R,j)=>{me(j,R)||T()}),[o,i]),Ee[0],Ee[1]),pe=!oe.current,r=c[i]&&c[i].length>0,l=z.data,S=E(l)?se&&tt(se)?Ne(se):se:l,b=z.error,M=p.useRef(S),V=m?E(l)?E(M.current)?S:M.current:l:S,ae=r&&!E(b)?!1:pe&&!E(h)?h:O().isPaused()?!1:a?E(S)?!1:_:E(S)||_,ie=!!(i&&t&&pe&&ae),A=E(z.isValidating)?ie:z.isValidating,re=E(z.isLoading)?ie:z.isLoading,q=p.useCallback(async T=>{const R=P.current;if(!i||!R||H.current||O().isPaused())return!1;let j,g,W=!0;const ce=T||{},D=!d[i]||!ce.dedupe,x=()=>rt?!H.current&&i===y.current&&oe.current:i===y.current,Z={isValidating:!1,isLoading:!1},ut=()=>{B(Z)},lt=()=>{const U=d[i];U&&U[1]===g&&delete d[i]},ft={isValidating:!0};E(F().data)&&(ft.isLoading=!0);try{if(D&&(B(ft),n.loadingTimeout&&E(F().data)&&setTimeout(()=>{W&&x()&&O().onLoadingSlow(i,n)},n.loadingTimeout),d[i]=[R(G),xe()]),[j,g]=d[i],j=await j,D&&setTimeout(lt,n.dedupingInterval),!d[i]||d[i][1]!==g)return D&&x()&&O().onDiscarded(i),!1;Z.error=k;const U=v[i];if(!E(U)&&(g<=U[0]||g<=U[1]||U[1]===0))return ut(),D&&x()&&O().onDiscarded(i),!1;const Q=F().data;Z.data=s(Q,j)?Q:j,D&&x()&&O().onSuccess(j,i,n)}catch(U){lt();const Q=O(),{shouldRetryOnError:Ue}=Q;Q.isPaused()||(Z.error=U,D&&x()&&(Q.onError(U,i,Q),(Ue===!0||Y(Ue)&&Ue(U))&&(!O().revalidateOnFocus||!O().revalidateOnReconnect||ne())&&Q.onErrorRetry(U,i,Q,on=>{const We=c[i];We&&We[0]&&We[0]($e,on)},{retryCount:(ce.retryCount||0)+1,dedupe:!0})))}return W=!1,ut(),!0},[i,o]),Re=p.useCallback((...T)=>st(o,y.current,...T),[]);if(je(()=>{P.current=t,te.current=n,E(l)||(M.current=l)}),je(()=>{if(!i)return;const T=q.bind(k,Fe);let R=0;O().revalidateOnFocus&&(R=Date.now()+O().focusThrottleInterval);const g=Xt(i,c,(W,ce={})=>{if(W==qe){const D=Date.now();O().revalidateOnFocus&&D>R&&ne()&&(R=D+O().focusThrottleInterval,T())}else if(W==Ze)O().revalidateOnReconnect&&ne()&&T();else{if(W==Qe)return q();if(W==$e)return q(ce)}});return H.current=!1,y.current=i,oe.current=!0,B({_k:G}),ae&&(E(S)||de?T():It(T)),()=>{H.current=!0,g()}},[i]),je(()=>{let T;function R(){const g=Y(C)?C(F().data):C;g&&T!==-1&&(T=setTimeout(j,g))}function j(){!F().error&&(w||O().isVisible())&&(f||O().isOnline())?q(Fe).then(R):R()}return R(),()=>{T&&(clearTimeout(T),T=-1)}},[C,w,f,i]),p.useDebugValue(V),a&&E(S)&&i){if(!rt&&de)throw new Error("Fallback data is required when using Suspense in SSR.");P.current=t,te.current=n,H.current=!1;const T=L[i];if(!E(T)){const R=Re(T);Ne(R)}if(E(b)){const R=q(Fe);E(V)||(R.status="fulfilled",R.value=!0),Ne(R)}else throw b}return{mutate:Re,get data(){return K.data=!0,V},get error(){return K.error=!0,b},get isValidating(){return K.isValidating=!0,A},get isLoading(){return K.isLoading=!0,re}}}),qt=async(e,t)=>{if(!t)throw new Error("A Figma API token is required to make this request.");const n=await fetch(e,{headers:{"X-FIGMA-TOKEN":t,"Content-Type":"application/json"}});if(!n.ok){const o=await n.json();throw new Error(o.message||"An error occurred while fetching data from the Figma API.")}return n.json()},Me=()=>{const{token:e,fileKey:t}=Je(),n=t?`https://api.figma.com/v1/files/${t}/variables/local`:null,{data:o,error:s,isLoading:a,isValidating:u}=zt(e&&n?[n,e]:null,qt);return{data:o,isLoading:a,isValidating:u,error:s}},Zt=()=>{const{data:e}=Me(),t=p.useMemo(()=>e!=null&&e.meta?Object.values(e.meta.variableCollections):[],[e]),n=p.useMemo(()=>e!=null&&e.meta?e.meta.variableCollections:{},[e]);return{collections:t,collectionsById:n}},Qt=()=>{const{data:e}=Me();return p.useMemo(()=>{const t=[],n={},o={};if(e!=null&&e.meta)for(const s of Object.values(e.meta.variableCollections)){t.push(...s.modes),n[s.id]=s.modes;for(const a of s.modes)o[a.modeId]=a}return{modes:t,modesByCollectionId:n,modesById:o}},[e])},$t=async(e,t,n)=>{if(!e||!t)throw new Error("A Figma API token and file key are required.");const o=`https://api.figma.com/v1/files/${t}/variables`,s=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json","X-FIGMA-TOKEN":e},body:JSON.stringify(n)}),a=await s.json();if(!s.ok)throw new Error(a.message||"Failed to perform bulk update.");return a},en=async(e,t)=>{if(!e)throw new Error("A Figma API token is required.");const n=await fetch("https://api.figma.com/v1/variables",{method:"POST",headers:{"Content-Type":"application/json","X-FIGMA-TOKEN":e},body:JSON.stringify(t)});if(!n.ok){const o=await n.json();throw new Error(o.message||"Failed to create Figma variable.")}return n.json()},tn=async(e,t)=>{if(!e)throw new Error("A Figma API token is required.");const n=`https://api.figma.com/v1/variables/${t}`,o=await fetch(n,{method:"DELETE",headers:{"Content-Type":"application/json","X-FIGMA-TOKEN":e}});if(!o.ok){const s=await o.json();throw new Error(s.message||"Failed to delete Figma variable.")}},nn=async(e,t,n)=>{if(!e)throw new Error("A Figma API token is required.");const o=`https://api.figma.com/v1/variables/${t}`,s=await fetch(o,{method:"PUT",headers:{"Content-Type":"application/json","X-FIGMA-TOKEN":e},body:JSON.stringify(n)});if(!s.ok){const a=await s.json();throw new Error(a.message||"Failed to update Figma variable.")}};function rn(e,t){return e.filter(n=>{let o=!0;return t.resolvedType&&(o=o&&n.resolvedType===t.resolvedType),t.name&&(o=o&&n.name.includes(t.name)),o})}I.FigmaVarsProvider=ht,I.bulkUpdateVariables=$t,I.createVariable=en,I.deleteVariable=tn,I.filterVariables=rn,I.updateVariable=nn,I.useFigmaToken=vt,I.useVariableCollections=Zt,I.useVariableModes=Qt,I.useVariables=Me,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
|
|
17
|
+
*/var je;function ht(){return je||(je=1,process.env.NODE_ENV!=="production"&&function(){function e(u,E){return u===E&&(u!==0||1/u===1/E)||u!==u&&E!==E}function t(u,E){O||o.startTransition===void 0||(O=!0,console.error("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."));var l=E();if(!c){var C=E();s(l,C)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),c=!0)}C=a({inst:{value:l,getSnapshot:E}});var i=C[0].inst,q=C[1];return S(function(){i.value=l,i.getSnapshot=E,n(i)&&q({inst:i})},[u,l,E]),h(function(){return n(i)&&q({inst:i}),u(function(){n(i)&&q({inst:i})})},[u]),D(l),l}function n(u){var E=u.getSnapshot;u=u.value;try{var l=E();return!s(u,l)}catch{return!0}}function r(u,E){return E()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var o=m,s=typeof Object.is=="function"?Object.is:e,a=o.useState,h=o.useEffect,S=o.useLayoutEffect,D=o.useDebugValue,O=!1,c=!1,d=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:t;me.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())}()),me}var xe;function St(){return xe||(xe=1,process.env.NODE_ENV==="production"?se.exports=pt():se.exports=ht()),se.exports}var _t=St();const Ue=0,ke=1,qe=2,Ge=3;var We=Object.prototype.hasOwnProperty;function pe(e,t){var n,r;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((r=e.length)===t.length)for(;r--&&pe(e[r],t[r]););return r===-1}if(!n||typeof e=="object"){r=0;for(n in e)if(We.call(e,n)&&++r&&!We.call(t,n)||!(n in t)||!pe(e[n],t[n]))return!1;return Object.keys(t).length===r}}return e!==e&&t!==t}const P=new WeakMap,U=()=>{},R=U(),he=Object,f=e=>e===R,N=e=>typeof e=="function",k=(e,t)=>({...e,...t}),Be=e=>N(e.then),Se={},ie={},_e="undefined",ee=typeof window!=_e,ve=typeof document!=_e,vt=ee&&"Deno"in window,Ot=()=>ee&&typeof window.requestAnimationFrame!=_e,He=(e,t)=>{const n=P.get(e);return[()=>!f(t)&&e.get(t)||Se,r=>{if(!f(t)){const o=e.get(t);t in ie||(ie[t]=o),n[5](t,k(o,r),o||Se)}},n[6],()=>!f(t)&&t in ie?ie[t]:!f(t)&&e.get(t)||Se]};let Oe=!0;const wt=()=>Oe,[we,ge]=ee&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[U,U],gt=()=>{const e=ve&&document.visibilityState;return f(e)||e!=="hidden"},yt=e=>(ve&&document.addEventListener("visibilitychange",e),we("focus",e),()=>{ve&&document.removeEventListener("visibilitychange",e),ge("focus",e)}),Tt=e=>{const t=()=>{Oe=!0,e()},n=()=>{Oe=!1};return we("online",t),we("offline",n),()=>{ge("online",t),ge("offline",n)}},At={isOnline:wt,isVisible:gt},Rt={initFocus:yt,initReconnect:Tt},$e=!m.useId,te=!ee||vt,Dt=e=>Ot()?window.requestAnimationFrame(e):setTimeout(e,1),ye=te?m.useEffect:m.useLayoutEffect,Te=typeof navigator<"u"&&navigator.connection,Ke=!te&&Te&&(["slow-2g","2g"].includes(Te.effectiveType)||Te.saveData),ae=new WeakMap,Ae=(e,t)=>he.prototype.toString.call(e)===`[object ${t}]`;let It=0;const Re=e=>{const t=typeof e,n=Ae(e,"Date"),r=Ae(e,"RegExp"),o=Ae(e,"Object");let s,a;if(he(e)===e&&!n&&!r){if(s=ae.get(e),s)return s;if(s=++It+"~",ae.set(e,s),Array.isArray(e)){for(s="@",a=0;a<e.length;a++)s+=Re(e[a])+",";ae.set(e,s)}if(o){s="#";const h=he.keys(e).sort();for(;!f(a=h.pop());)f(e[a])||(s+=a+":"+Re(e[a])+",");ae.set(e,s)}}else s=n?e.toJSON():t=="symbol"?e.toString():t=="string"?JSON.stringify(e):""+e;return s},De=e=>{if(N(e))try{e=e()}catch{e=""}const t=e;return e=typeof e=="string"?e:(Array.isArray(e)?e.length:e)?Re(e):"",[e,t]};let Ct=0;const Ie=()=>++Ct;async function Je(...e){const[t,n,r,o]=e,s=k({populateCache:!0,throwOnError:!0},typeof o=="boolean"?{revalidate:o}:o||{});let a=s.populateCache;const h=s.rollbackOnError;let S=s.optimisticData;const D=d=>typeof h=="function"?h(d):h!==!1,O=s.throwOnError;if(N(n)){const d=n,u=[],E=t.keys();for(const l of E)!/^\$(inf|sub)\$/.test(l)&&d(t.get(l)._k)&&u.push(l);return Promise.all(u.map(c))}return c(n);async function c(d){const[u]=De(d);if(!u)return;const[E,l]=He(t,u),[C,i,q,re]=P.get(t),G=()=>{const V=C[u];return(N(s.revalidate)?s.revalidate(E().data,d):s.revalidate!==!1)&&(delete q[u],delete re[u],V&&V[0])?V[0](qe).then(()=>E().data):E().data};if(e.length<3)return G();let T=r,b;const $=Ie();i[u]=[$,0];const v=!f(S),K=E(),M=K.data,J=K._c,W=f(J)?M:J;if(v&&(S=N(S)?S(W,M):S,l({data:S,_c:W})),N(T))try{T=T(W)}catch(V){b=V}if(T&&Be(T))if(T=await T.catch(V=>{b=V}),$!==i[u][0]){if(b)throw b;return T}else b&&v&&D(b)&&(a=!0,l({data:W,_c:R}));if(a&&!b)if(N(a)){const V=a(T,W);l({data:V,error:R,_c:R})}else l({data:T,error:R,_c:R});if(i[u][1]=Ie(),Promise.resolve(G()).then(()=>{l({_c:R})}),b){if(O)throw b;return}return T}}const Ye=(e,t)=>{for(const n in e)e[n][0]&&e[n][0](t)},bt=(e,t)=>{if(!P.has(e)){const n=k(Rt,t),r=Object.create(null),o=Je.bind(R,e);let s=U;const a=Object.create(null),h=(O,c)=>{const d=a[O]||[];return a[O]=d,d.push(c),()=>d.splice(d.indexOf(c),1)},S=(O,c,d)=>{e.set(O,c);const u=a[O];if(u)for(const E of u)E(c,d)},D=()=>{if(!P.has(e)&&(P.set(e,[r,Object.create(null),Object.create(null),Object.create(null),o,S,h]),!te)){const O=n.initFocus(setTimeout.bind(R,Ye.bind(R,r,Ue))),c=n.initReconnect(setTimeout.bind(R,Ye.bind(R,r,ke)));s=()=>{O&&O(),c&&c(),P.delete(e)}}};return D(),[e,o,D,s]}return[e,P.get(e)[4]]},Lt=(e,t,n,r,o)=>{const s=n.errorRetryCount,a=o.retryCount,h=~~((Math.random()+.5)*(1<<(a<8?a:8)))*n.errorRetryInterval;!f(s)&&a>s||setTimeout(r,h,o)},Vt=pe,[ze,Ft]=bt(new Map),Nt=k({onLoadingSlow:U,onSuccess:U,onError:U,onErrorRetry:Lt,onDiscarded:U,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:Ke?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:Ke?5e3:3e3,compare:Vt,isPaused:()=>!1,cache:ze,mutate:Ft,fallback:{}},At),Mt=(e,t)=>{const n=k(e,t);if(t){const{use:r,fallback:o}=e,{use:s,fallback:a}=t;r&&s&&(n.use=r.concat(s)),o&&a&&(n.fallback=k(o,a))}return n},Pt=m.createContext({}),jt="$inf$",Xe=ee&&window.__SWR_DEVTOOLS_USE__,xt=Xe?window.__SWR_DEVTOOLS_USE__:[],Ut=()=>{Xe&&(window.__SWR_DEVTOOLS_REACT__=m)},kt=e=>N(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],qt=()=>k(Nt,m.useContext(Pt)),Gt=e=>(t,n,r)=>e(t,n&&((...s)=>{const[a]=De(t),[,,,h]=P.get(ze);if(a.startsWith(jt))return n(...s);const S=h[a];return f(S)?n(...s):(delete h[a],S)}),r),Wt=xt.concat(Gt),Bt=e=>function(...n){const r=qt(),[o,s,a]=kt(n),h=Mt(r,a);let S=e;const{use:D}=h,O=(D||[]).concat(Wt);for(let c=O.length;c--;)S=O[c](S);return S(o,s||h.fetcher||null,h)},Ht=(e,t,n)=>{const r=t[e]||(t[e]=[]);return r.push(n),()=>{const o=r.indexOf(n);o>=0&&(r[o]=r[r.length-1],r.pop())}};Ut();const Ce=m.use||(e=>{switch(e.status){case"pending":throw e;case"fulfilled":return e.value;case"rejected":throw e.reason;default:throw e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e}}),be={dedupe:!0},$t=Bt((e,t,n)=>{const{cache:r,compare:o,suspense:s,fallbackData:a,revalidateOnMount:h,revalidateIfStale:S,refreshInterval:D,refreshWhenHidden:O,refreshWhenOffline:c,keepPreviousData:d}=n,[u,E,l,C]=P.get(r),[i,q]=De(e),re=m.useRef(!1),G=m.useRef(!1),T=m.useRef(i),b=m.useRef(t),$=m.useRef(n),v=()=>$.current,K=()=>v().isVisible()&&v().isOnline(),[M,J,W,V]=He(r,i),Y=m.useRef({}).current,le=f(a)?f(n.fallback)?R:n.fallback[i]:a,st=(_,p)=>{for(const A in Y){const w=A;if(w==="data"){if(!o(_[w],p[w])&&(!f(_[w])||!o(de,p[w])))return!1}else if(p[w]!==_[w])return!1}return!0},it=m.useMemo(()=>{const _=!i||!t?!1:f(h)?v().isPaused()||s?!1:S!==!1:h,p=I=>{const j=k(I);return delete j._k,_?{isValidating:!0,isLoading:!0,...j}:j},A=M(),w=V(),F=p(A),Q=A===w?F:p(w);let y=F;return[()=>{const I=p(M());return st(I,y)?(y.data=I.data,y.isLoading=I.isLoading,y.isValidating=I.isValidating,y.error=I.error,y):(y=I,I)},()=>Q]},[r,i]),z=_t.useSyncExternalStore(m.useCallback(_=>W(i,(p,A)=>{st(A,p)||_()}),[r,i]),it[0],it[1]),at=!re.current,sn=u[i]&&u[i].length>0,X=z.data,B=f(X)?le&&Be(le)?Ce(le):le:X,fe=z.error,Ve=m.useRef(B),de=d?f(X)?f(Ve.current)?B:Ve.current:X:B,ut=sn&&!f(fe)?!1:at&&!f(h)?h:v().isPaused()?!1:s?f(B)?!1:S:f(B)||S,ct=!!(i&&t&&at&&ut),an=f(z.isValidating)?ct:z.isValidating,un=f(z.isLoading)?ct:z.isLoading,oe=m.useCallback(async _=>{const p=b.current;if(!i||!p||G.current||v().isPaused())return!1;let A,w,F=!0;const Q=_||{},y=!l[i]||!Q.dedupe,I=()=>$e?!G.current&&i===T.current&&re.current:i===T.current,j={isValidating:!1,isLoading:!1},ft=()=>{J(j)},dt=()=>{const L=l[i];L&&L[1]===w&&delete l[i]},Et={isValidating:!0};f(M().data)&&(Et.isLoading=!0);try{if(y&&(J(Et),n.loadingTimeout&&f(M().data)&&setTimeout(()=>{F&&I()&&v().onLoadingSlow(i,n)},n.loadingTimeout),l[i]=[p(q),Ie()]),[A,w]=l[i],A=await A,y&&setTimeout(dt,n.dedupingInterval),!l[i]||l[i][1]!==w)return y&&I()&&v().onDiscarded(i),!1;j.error=R;const L=E[i];if(!f(L)&&(w<=L[0]||w<=L[1]||L[1]===0))return ft(),y&&I()&&v().onDiscarded(i),!1;const x=M().data;j.data=o(x,A)?x:A,y&&I()&&v().onSuccess(A,i,n)}catch(L){dt();const x=v(),{shouldRetryOnError:Fe}=x;x.isPaused()||(j.error=L,y&&I()&&(x.onError(L,i,x),(Fe===!0||N(Fe)&&Fe(L))&&(!v().revalidateOnFocus||!v().revalidateOnReconnect||K())&&x.onErrorRetry(L,i,x,cn=>{const Ne=u[i];Ne&&Ne[0]&&Ne[0](Ge,cn)},{retryCount:(Q.retryCount||0)+1,dedupe:!0})))}return F=!1,ft(),!0},[i,r]),lt=m.useCallback((..._)=>Je(r,T.current,..._),[]);if(ye(()=>{b.current=t,$.current=n,f(X)||(Ve.current=X)}),ye(()=>{if(!i)return;const _=oe.bind(R,be);let p=0;v().revalidateOnFocus&&(p=Date.now()+v().focusThrottleInterval);const w=Ht(i,u,(F,Q={})=>{if(F==Ue){const y=Date.now();v().revalidateOnFocus&&y>p&&K()&&(p=y+v().focusThrottleInterval,_())}else if(F==ke)v().revalidateOnReconnect&&K()&&_();else{if(F==qe)return oe();if(F==Ge)return oe(Q)}});return G.current=!1,T.current=i,re.current=!0,J({_k:q}),ut&&(f(B)||te?_():Dt(_)),()=>{G.current=!0,w()}},[i]),ye(()=>{let _;function p(){const w=N(D)?D(M().data):D;w&&_!==-1&&(_=setTimeout(A,w))}function A(){!M().error&&(O||v().isVisible())&&(c||v().isOnline())?oe(be).then(p):p()}return p(),()=>{_&&(clearTimeout(_),_=-1)}},[D,O,c,i]),m.useDebugValue(de),s&&f(B)&&i){if(!$e&&te)throw new Error("Fallback data is required when using Suspense in SSR.");b.current=t,$.current=n,G.current=!1;const _=C[i];if(!f(_)){const p=lt(_);Ce(p)}if(f(fe)){const p=oe(be);f(de)||(p.status="fulfilled",p.value=!0),Ce(p)}else throw fe}return{mutate:lt,get data(){return Y.data=!0,de},get error(){return Y.error=!0,fe},get isValidating(){return Y.isValidating=!0,an},get isLoading(){return Y.isLoading=!0,un}}}),Qe="https://api.figma.com",Kt=`${Qe}/v1/files`,Ze=`${Qe}/v1/variables`,et=Ze,tt=e=>`${Ze}/${e}`,Jt=e=>`${Kt}/${e}/variables/local`,nt="application/json",rt="X-FIGMA-TOKEN",ne="A Figma API token is required.",ot="An error occurred while fetching data from the Figma API.",Yt=async(e,t)=>{if(!t)throw new Error(ne);const n=await fetch(e,{headers:{[rt]:t,"Content-Type":nt}});if(!n.ok){const r=await n.json();throw new Error(r.message||ot)}return n.json()},Le=()=>{const{token:e,fileKey:t}=H(),n=t?Jt(t):null,{data:r,error:o,isLoading:s,isValidating:a}=$t(e&&n?[n,e]:null,Yt);return{data:r,isLoading:s,isValidating:a,error:o}},zt=()=>{const{data:e}=Le(),t=m.useMemo(()=>e!=null&&e.meta?Object.values(e.meta.variableCollections):[],[e]),n=m.useMemo(()=>e!=null&&e.meta?e.meta.variableCollections:{},[e]);return{collections:t,collectionsById:n}},Xt=()=>{const{data:e}=Le();return m.useMemo(()=>{const t=[],n={},r={};if(e!=null&&e.meta)for(const o of Object.values(e.meta.variableCollections)){t.push(...o.modes),n[o.id]=o.modes;for(const s of o.modes)r[s.modeId]=s}return{modes:t,modesByCollectionId:n,modesById:r}},[e])},Qt=()=>{const{token:e}=H();return e};function Zt(e,t){switch(t.type){case"loading":return{...e,status:"loading",error:null};case"success":return{...e,status:"success",data:t.payload};case"error":return{...e,status:"error",error:t.payload};default:return e}}const ue=e=>{const t={status:"idle",data:null,error:null},[n,r]=m.useReducer(Zt,t);return{mutate:m.useCallback(async s=>{r({type:"loading"});try{const a=await e(s);return r({type:"success",payload:a}),a}catch(a){r({type:"error",payload:a});return}},[e]),...n,isLoading:n.status==="loading",isSuccess:n.status==="success",isError:n.status==="error"}},ce=async(e,t,n,r)=>{if(!t)throw new Error(ne);const o=await fetch(e,{method:n,headers:{[rt]:t,"Content-Type":nt},...r&&{body:JSON.stringify(r)}});if(!o.ok){const s=await o.json();throw new Error(s.message||ot)}return o.status===204?Promise.resolve(void 0):o.json()},en=()=>{const{token:e}=H();if(!e)throw new Error(ne);return ue(async n=>await ce(et,e,"POST",n))},tn=()=>{const{token:e}=H();if(!e)throw new Error(ne);return ue(async n=>await ce(tt(n),e,"DELETE"))},nn=()=>{const{token:e}=H();return ue(async({variableId:n,payload:r})=>{if(!e)throw new Error("A Figma API token is required.");const o=tt(n);return await ce(o,e,"PUT",r)})},rn=()=>{const{token:e}=H();return ue(async n=>{if(!e)throw new Error(ne);return await ce(et,e,"PUT",n)})};function on(e,t){return e.filter(n=>{let r=!0;return t.resolvedType&&(r=r&&n.resolvedType===t.resolvedType),t.name&&(r=r&&n.name.includes(t.name)),r})}g.FigmaVarsProvider=mt,g.filterVariables=on,g.useBulkUpdateVariables=rn,g.useCreateVariable=en,g.useDeleteVariable=tn,g.useFigmaToken=Qt,g.useUpdateVariable=nn,g.useVariableCollections=zt,g.useVariableModes=Xt,g.useVariables=Le,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|