@animaapp/anima-sdk-react 0.22.0 → 0.23.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/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +238 -225
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";var nn=Object.defineProperty,sn=Object.defineProperties;var rn=Object.getOwnPropertyDescriptors;var vt=Object.getOwnPropertySymbols;var on=Object.prototype.hasOwnProperty,an=Object.prototype.propertyIsEnumerable;var wt=(e,n,t)=>n in e?nn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,I=(e,n)=>{for(var t in n||(n={}))on.call(n,t)&&wt(e,t,n[t]);if(vt)for(var t of vt(n))an.call(n,t)&&wt(e,t,n[t]);return e},
|
|
2
|
-
`;break;case"id":l=
|
|
3
|
-
`)?r.slice(0,-1):r}),l=void 0,r="",o=""}function
|
|
1
|
+
"use strict";var nn=Object.defineProperty,sn=Object.defineProperties;var rn=Object.getOwnPropertyDescriptors;var vt=Object.getOwnPropertySymbols;var on=Object.prototype.hasOwnProperty,an=Object.prototype.propertyIsEnumerable;var wt=(e,n,t)=>n in e?nn(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,I=(e,n)=>{for(var t in n||(n={}))on.call(n,t)&&wt(e,t,n[t]);if(vt)for(var t of vt(n))an.call(n,t)&&wt(e,t,n[t]);return e},Me=(e,n)=>sn(e,rn(n));var P=(e,n,t)=>new Promise((s,i)=>{var c=r=>{try{l(t.next(r))}catch(o){i(o)}},a=r=>{try{l(t.throw(r))}catch(o){i(o)}},l=r=>r.done?s(r.value):Promise.resolve(r.value).then(c,a);l((t=t.apply(e,n)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const cn=require("react/jsx-runtime"),y=require("react"),be=require("@animaapp/anima-sdk");class yt extends Error{constructor(n,t){super(n),this.name="ParseError",this.type=t.type,this.field=t.field,this.value=t.value,this.line=t.line}}function xe(e){}function un(e){if(typeof e=="function")throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");const{onEvent:n=xe,onError:t=xe,onRetry:s=xe,onComment:i}=e;let c="",a=!0,l,r="",o="";function f(d){const E=a?d.replace(/^\xEF\xBB\xBF/,""):d,[u,w]=ln(`${c}${E}`);for(const b of u)p(b);c=w,a=!1}function p(d){if(d===""){h();return}if(d.startsWith(":")){i&&i(d.slice(d.startsWith(": ")?2:1));return}const E=d.indexOf(":");if(E!==-1){const u=d.slice(0,E),w=d[E+1]===" "?2:1,b=d.slice(E+w);m(u,b,d);return}m(d,"",d)}function m(d,E,u){switch(d){case"event":o=E;break;case"data":r=`${r}${E}
|
|
2
|
+
`;break;case"id":l=E.includes("\0")?void 0:E;break;case"retry":/^\d+$/.test(E)?s(parseInt(E,10)):t(new yt(`Invalid \`retry\` value: "${E}"`,{type:"invalid-retry",value:E,line:u}));break;default:t(new yt(`Unknown field "${d.length>20?`${d.slice(0,20)}…`:d}"`,{type:"unknown-field",field:d,value:E,line:u}));break}}function h(){r.length>0&&n({id:l,event:o||void 0,data:r.endsWith(`
|
|
3
|
+
`)?r.slice(0,-1):r}),l=void 0,r="",o=""}function g(d={}){c&&d.consume&&p(c),a=!0,l=void 0,r="",o="",c=""}return{feed:f,reset:g}}function ln(e){const n=[];let t="",s=0;for(;s<e.length;){const i=e.indexOf("\r",s),c=e.indexOf(`
|
|
4
4
|
`,s);let a=-1;if(i!==-1&&c!==-1?a=Math.min(i,c):i!==-1?i===e.length-1?a=-1:a=i:c!==-1&&(a=c),a===-1){t=e.slice(s);break}else{const l=e.slice(s,a);n.push(l),s=a+1,e[s-1]==="\r"&&e[s]===`
|
|
5
|
-
`&&s++}}return[n,t]}class _t extends Event{constructor(n,t){var s,i;super(n),this.code=(s=t==null?void 0:t.code)!=null?s:void 0,this.message=(i=t==null?void 0:t.message)!=null?i:void 0}[Symbol.for("nodejs.util.inspect.custom")](n,t,s){return s(Ot(this),t)}[Symbol.for("Deno.customInspect")](n,t){return n(Ot(this),t)}}function dn(e){const n=globalThis.DOMException;return typeof n=="function"?new n(e,"SyntaxError"):new SyntaxError(e)}function Ue(e){return e instanceof Error?"errors"in e&&Array.isArray(e.errors)?e.errors.map(Ue).join(", "):"cause"in e&&e.cause instanceof Error?`${e}: ${Ue(e.cause)}`:e.message:`${e}`}function Ot(e){return{type:e.type,message:e.message,code:e.code,defaultPrevented:e.defaultPrevented,cancelable:e.cancelable,timeStamp:e.timeStamp}}var kt=e=>{throw TypeError(e)},ot=(e,n,t)=>n.has(e)||kt("Cannot "+t),S=(e,n,t)=>(ot(e,n,"read from private field"),t?t.call(e):n.get(e)),D=(e,n,t)=>n.has(e)?kt("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(e):n.set(e,t),C=(e,n,t,s)=>(ot(e,n,"write to private field"),n.set(e,t),t),K=(e,n,t)=>(ot(e,n,"access private method"),t),F,te,ie,Te,Le,Ee,le,me,Y,ce,de,ue,pe,J,qe,Ge,Be,bt,He,Ke,ge,ze,Ye;class Se extends EventTarget{constructor(n,t){var s,i;super(),D(this,J),this.CONNECTING=0,this.OPEN=1,this.CLOSED=2,D(this,F),D(this,te),D(this,ie),D(this,Te),D(this,Le),D(this,Ee),D(this,le),D(this,me,null),D(this,Y),D(this,ce),D(this,de,null),D(this,ue,null),D(this,pe,null),D(this,Ge,c=>P(this,null,function*(){var a;S(this,ce).reset();const{body:l,redirected:r,status:o,headers:f}=c;if(o===204){K(this,J,ge).call(this,"Server sent HTTP 204, not reconnecting",204),this.close();return}if(r?C(this,ie,new URL(c.url)):C(this,ie,void 0),o!==200){K(this,J,ge).call(this,`Non-200 status code (${o})`,o);return}if(!(f.get("content-type")||"").startsWith("text/event-stream")){K(this,J,ge).call(this,'Invalid content type, expected "text/event-stream"',o);return}if(S(this,F)===this.CLOSED)return;C(this,F,this.OPEN);const E=new Event("open");if((a=S(this,pe))==null||a.call(this,E),this.dispatchEvent(E),typeof l!="object"||!l||!("getReader"in l)){K(this,J,ge).call(this,"Invalid response body, expected a web ReadableStream",o),this.close();return}const m=new TextDecoder,h=l.getReader();let p=!0;do{const{done:d,value:g}=yield h.read();g&&S(this,ce).feed(m.decode(g,{stream:!d})),d&&(p=!1,S(this,ce).reset(),K(this,J,ze).call(this))}while(p)})),D(this,Be,c=>{C(this,Y,void 0),!(c.name==="AbortError"||c.type==="aborted")&&K(this,J,ze).call(this,Ue(c))}),D(this,He,c=>{typeof c.id=="string"&&C(this,me,c.id);const a=new MessageEvent(c.event||"message",{data:c.data,origin:S(this,ie)?S(this,ie).origin:S(this,te).origin,lastEventId:c.id||""});S(this,ue)&&(!c.event||c.event==="message")&&S(this,ue).call(this,a),this.dispatchEvent(a)}),D(this,Ke,c=>{C(this,Ee,c)}),D(this,Ye,()=>{C(this,le,void 0),S(this,F)===this.CONNECTING&&K(this,J,qe).call(this)});try{if(n instanceof URL)C(this,te,n);else if(typeof n=="string")C(this,te,new URL(n,fn()));else throw new Error("Invalid URL")}catch(c){throw dn("An invalid or illegal string was specified")}C(this,ce,un({onEvent:S(this,He),onRetry:S(this,Ke)})),C(this,F,this.CONNECTING),C(this,Ee,3e3),C(this,Le,(s=t==null?void 0:t.fetch)!=null?s:globalThis.fetch),C(this,Te,(i=t==null?void 0:t.withCredentials)!=null?i:!1),K(this,J,qe).call(this)}get readyState(){return S(this,F)}get url(){return S(this,te).href}get withCredentials(){return S(this,Te)}get onerror(){return S(this,de)}set onerror(n){C(this,de,n)}get onmessage(){return S(this,ue)}set onmessage(n){C(this,ue,n)}get onopen(){return S(this,pe)}set onopen(n){C(this,pe,n)}addEventListener(n,t,s){const i=t;super.addEventListener(n,i,s)}removeEventListener(n,t,s){const i=t;super.removeEventListener(n,i,s)}close(){S(this,le)&&clearTimeout(S(this,le)),S(this,F)!==this.CLOSED&&(S(this,Y)&&S(this,Y).abort(),C(this,F,this.CLOSED),C(this,Y,void 0))}}F=new WeakMap,te=new WeakMap,ie=new WeakMap,Te=new WeakMap,Le=new WeakMap,Ee=new WeakMap,le=new WeakMap,me=new WeakMap,Y=new WeakMap,ce=new WeakMap,de=new WeakMap,ue=new WeakMap,pe=new WeakMap,J=new WeakSet,qe=function(){C(this,F,this.CONNECTING),C(this,Y,new AbortController),S(this,Le)(S(this,te),K(this,J,bt).call(this)).then(S(this,Ge)).catch(S(this,Be))},Ge=new WeakMap,Be=new WeakMap,bt=function(){var e;const n={mode:"cors",redirect:"follow",headers:I({Accept:"text/event-stream"},S(this,me)?{"Last-Event-ID":S(this,me)}:void 0),cache:"no-store",signal:(e=S(this,Y))==null?void 0:e.signal};return"window"in globalThis&&(n.credentials=this.withCredentials?"include":"same-origin"),n},He=new WeakMap,Ke=new WeakMap,ge=function(e,n){var t;S(this,F)!==this.CLOSED&&C(this,F,this.CLOSED);const s=new _t("error",{code:n,message:e});(t=S(this,de))==null||t.call(this,s),this.dispatchEvent(s)},ze=function(e,n){var t;if(S(this,F)===this.CLOSED)return;C(this,F,this.CONNECTING);const s=new _t("error",{code:n,message:e});(t=S(this,de))==null||t.call(this,s),this.dispatchEvent(s),C(this,le,setTimeout(S(this,Ye),S(this,Ee)))},Ye=new WeakMap,Se.CONNECTING=0,Se.OPEN=1,Se.CLOSED=2;function fn(){const e="document"in globalThis?globalThis.document:void 0;return e&&typeof e=="object"&&"baseURI"in e&&typeof e.baseURI=="string"?e.baseURI:void 0}const hn=e=>{let n="";const t=new Uint8Array(e),s=t.byteLength;for(let i=0;i<s;i++)n+=String.fromCharCode(t[i]);return btoa(n)},at={status:"idle",error:null,result:null,progressMessages:[],tasks:{fetchDesign:{status:"pending"},codeGeneration:{status:"pending",progress:0},uploadAssets:{status:"pending"}},jobSessionId:null,jobStatus:{},jobType:null},Rt=10,jt=e=>"path"in e?{filePath:e.path.replace(/^\//,""),referencePath:e.path==="/"?"":e.path}:{filePath:e.filePath.replace(/^\//,""),referencePath:e.referencePath==="/"?"":e.referencePath},Wt=({es:e,lastFetchResponse:n,stateUpdated:t})=>{const s=structuredClone(at);return s.status="pending",t(I({},s)),new Promise((i,c)=>{const a={};e.addEventListener("set_job_type",r=>{const o=JSON.parse(r.data);s.jobType=o.payload.jobType,t(I({},s))}),e.addEventListener("start",r=>{const o=JSON.parse(r.data);a.sessionId=o.sessionId,s.tasks.fetchDesign.status="running",s.jobSessionId=o.sessionId,t(I({},s))}),e.addEventListener("queueing",r=>{const o=JSON.parse(r.data);s.jobSessionId=o.payload.sessionId,t(I({},s))}),e.addEventListener("pre_codegen",r=>{JSON.parse(r.data).message==="Anima model built"&&(s.tasks.fetchDesign.status="finished",s.tasks.codeGeneration.status="running",s.tasks.uploadAssets.status="running",t(I({},s)))}),e.addEventListener("figma_metadata",r=>{const o=JSON.parse(r.data);a.figmaFileName=o.figmaFileName,a.figmaSelectedFrameName=o.figmaSelectedFrameName}),e.addEventListener("aborted",()=>{const r=new Me.CodegenError({name:"Aborted",reason:"Unknown"});s.status="aborted",s.result=null,s.error=r,t(I({},s)),i({result:null,error:r})}),e.addEventListener("generating_code",r=>{const o=JSON.parse(r.data);o.payload.status==="success"&&(a.files=o.payload.files),s.tasks.codeGeneration.progress=o.payload.progress,s.tasks.codeGeneration.status="running",t(I({},s))}),e.addEventListener("progress_messages_updated",r=>{const o=JSON.parse(r.data);s.progressMessages=o.payload.progressMessages,t(I({},s))}),e.addEventListener("job_status_updated",r=>{const o=JSON.parse(r.data);s.jobStatus=o.payload.jobStatus,t(I({},s))}),e.addEventListener("codegen_completed",()=>{s.tasks.codeGeneration.status="finished",t(I({},s))}),e.addEventListener("generation_completed",()=>{s.tasks.codeGeneration.status="finished",t(I({},s))}),e.addEventListener("assets_uploaded",()=>{s.tasks.uploadAssets.status="finished",t(I({},s))}),e.addEventListener("assets_list",r=>{const o=JSON.parse(r.data);a.assets=o.payload.assets});let l=0;e.addEventListener("error",r=>P(null,null,function*(){var p,d,g,u,w,b,x;if(!n)return;const o=yield n;if(!o.ok){let R="";try{R=yield o.text();const A=JSON.parse(R);(p=A==null?void 0:A.payload)!=null&&p.message&&(R=A.payload.message)}catch(A){}c(new Me.CodegenError({name:"Request failed",reason:R,status:o.status})),e.close();return}console.warn(`Experienced error during code generation (attempt ${l+1} / ${Rt})`,r);let f,E=!1;if(r instanceof MessageEvent)try{f=JSON.parse(r.data)}catch(R){}(((d=f==null?void 0:f.payload)==null?void 0:d.name)==="Task Crashed"||((g=f==null?void 0:f.payload)==null?void 0:g.name)==="TimeoutError"||((u=f==null?void 0:f.payload)==null?void 0:u.name)==="Error"||((w=f==null?void 0:f.payload)==null?void 0:w.name)==="Unknown error")&&(E=!0);const m=new Me.CodegenError({name:(b=f==null?void 0:f.payload.name)!=null?b:"Unknown error",reason:(x=f==null?void 0:f.payload.message)!=null?x:"Unknown",status:f==null?void 0:f.payload.status,detail:f==null?void 0:f.payload.detail});l++;let h=!1;l>Rt?(console.error("Experienced too many errors, terminating request"),h=!0):E&&(console.error("Experienced unrecoverable error, terminating request"),h=!0),h&&(s.status="error",s.error=m,t(I({},s)),i({result:null,error:m}))})),e.addEventListener("done",r=>{const o=JSON.parse(r.data);a.tokenUsage=o.payload.tokenUsage,a.sessionId=o.payload.sessionId,s.status="success",s.result=a,t(I({},s)),i({result:a,error:null})})})},Ft=(e,n,t,s)=>P(null,null,function*(){var l;const i=structuredClone(t);if(((l=t.assetsStorage)==null?void 0:l.strategy)==="local"){const{referencePath:r}=jt(t.assetsStorage);t.assetsStorage={strategy:"external",url:r}}let c;const a=new Se(e,{fetch:(r,o)=>(c=fetch(r,Ne(I({},o),{method:n,body:JSON.stringify(t)})),c)});try{const{result:r,error:o}=yield Wt({es:a,lastFetchResponse:c,stateUpdated:s});if(o||!r)return{result:null,error:o};const f=structuredClone(r);return Vt(f,i),{result:f,error:null}}finally{a.close()}}),pn=(e,n,t)=>P(null,null,function*(){const s=structuredClone(n);let i;const c=new Se(e,{fetch:(a,l)=>(i=fetch(a,Ne(I({},l),{method:"POST",body:JSON.stringify(n)})),i)});try{const{result:a,error:l}=yield Wt({es:c,lastFetchResponse:i,stateUpdated:t});if(l||!a)return{result:null,error:l};const r=structuredClone(a);return Vt(r,s),{result:r,error:null}}finally{c.close()}}),Vt=(e,n)=>P(null,null,function*(){var t,s;if(((t=n.assetsStorage)==null?void 0:t.strategy)==="local"&&((s=e.assets)!=null&&s.length)){const{filePath:i}=jt(n.assetsStorage),c=e.assets.map(l=>P(null,null,function*(){const o=yield(yield fetch(l.url)).arrayBuffer();return{assetName:l.name,base64:hn(o)}})),a=yield Promise.allSettled(c);for(const l of a)if(l.status==="fulfilled"){const{assetName:r,base64:o}=l.value,f=i?`${i}/${r}`:r;e.files[f]={content:o,isBinary:!0}}}});class Pt extends Error{constructor(n,t){super(n),this.name="CreateJobError",this.cause=t}}class $t extends Error{constructor(n,t){super(n),this.name="AttachJobError",this.cause=t}}class Jt extends Error{constructor(){super(""),this.name="UnknownCodegenError"}}const it=y.createContext(null);function gn({figmaRestApi:e,f2cUrl:n,l2cUrl:t,p2cUrl:s,jobsUrl:i,children:c}){const[a,l]=y.useState({status:"idle"}),r=y.useRef(null),[o,f]=y.useState(at),E={f2c:n,l2c:t,p2c:s},m=(p,d)=>P(null,null,function*(){var g;if(a.status==="pending")throw new Error("A job is already in progress");r.current=p;try{const u=E[p],{result:w}=yield Ft(u,"POST",d,b=>f(b));if(w){const b=w.sessionId,x=w.files,R=w.assets;l(A=>({status:"success",type:p,params:"params"in A?A.params:{},sessionId:b,payload:o.jobStatus,assets:R,files:x,progressMessages:o.progressMessages}));return}}catch(u){r.current=null;const w=u instanceof Error?u.message:"Unknown error",b=new Pt(w,u);throw l({status:"error",type:p,params:d,error:b,sessionId:(g=o.jobSessionId)!=null?g:null,payload:o.jobStatus,progressMessages:o.progressMessages}),b}}),h=(p,d)=>P(null,null,function*(){if(!i)throw new Error("jobsUrl is required in order to attach to a job");try{const g=`${i}/${p}`,{result:u}=yield pn(g,d,w=>f(w));if(u){const w=u.files,b=u.assets;l(x=>({status:"success",type:o.jobType,params:"params"in x?x.params:{},sessionId:p,payload:o.jobStatus,assets:b,files:w,progressMessages:o.progressMessages}))}}catch(g){const u=g instanceof Error?g.message:"Unknown error",w=new $t(u,g);throw l({status:"error",type:r.current,params:{},error:w,sessionId:p,payload:o.jobStatus,progressMessages:o.progressMessages}),w}});return y.useEffect(()=>{var d,g;const p=(d=r.current)!=null?d:o.jobType;if(p){if(o.status==="error"){const u=(g=o.error)!=null?g:new Jt;l(w=>{var b;return{status:"error",type:p,params:"params"in w?w.params:{},error:u,sessionId:(b=o.jobSessionId)!=null?b:null,payload:o.jobStatus,progressMessages:o.progressMessages}});return}if(o.status==="pending"){l(u=>({status:"pending",type:p,params:"params"in u?u.params:{},sessionId:o.jobSessionId,payload:o.jobStatus,progressMessages:o.progressMessages}));return}}},[o]),cn.jsx(it.Provider,{value:{createJob:m,attachJob:h,job:a,figmaRestApi:e},children:c})}function Ut(){const e=y.useContext(it);if(!e)throw new Error("useAnimaSDK must be used within AnimaSDKProvider");return e}const En=({url:e,method:n="POST"})=>{const[t,s]=y.useState(at);return{getCode:y.useCallback(c=>Ft(e,n,c,s),[e,n]),status:t.status,progressMessages:t.progressMessages,jobSessionId:t.jobSessionId,jobStatus:t.jobStatus,tasks:t.tasks,error:t.error,result:t.result}};var be={exports:{}},ke={};/**
|
|
5
|
+
`&&s++}}return[n,t]}class _t extends Event{constructor(n,t){var s,i;super(n),this.code=(s=t==null?void 0:t.code)!=null?s:void 0,this.message=(i=t==null?void 0:t.message)!=null?i:void 0}[Symbol.for("nodejs.util.inspect.custom")](n,t,s){return s(Ot(this),t)}[Symbol.for("Deno.customInspect")](n,t){return n(Ot(this),t)}}function dn(e){const n=globalThis.DOMException;return typeof n=="function"?new n(e,"SyntaxError"):new SyntaxError(e)}function Ue(e){return e instanceof Error?"errors"in e&&Array.isArray(e.errors)?e.errors.map(Ue).join(", "):"cause"in e&&e.cause instanceof Error?`${e}: ${Ue(e.cause)}`:e.message:`${e}`}function Ot(e){return{type:e.type,message:e.message,code:e.code,defaultPrevented:e.defaultPrevented,cancelable:e.cancelable,timeStamp:e.timeStamp}}var kt=e=>{throw TypeError(e)},ot=(e,n,t)=>n.has(e)||kt("Cannot "+t),S=(e,n,t)=>(ot(e,n,"read from private field"),t?t.call(e):n.get(e)),D=(e,n,t)=>n.has(e)?kt("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(e):n.set(e,t),C=(e,n,t,s)=>(ot(e,n,"write to private field"),n.set(e,t),t),K=(e,n,t)=>(ot(e,n,"access private method"),t),F,te,ie,Le,Ie,Ee,le,me,Y,ce,de,ue,pe,J,qe,Ge,Be,bt,He,Ke,ge,ze,Ye;class Se extends EventTarget{constructor(n,t){var s,i;super(),D(this,J),this.CONNECTING=0,this.OPEN=1,this.CLOSED=2,D(this,F),D(this,te),D(this,ie),D(this,Le),D(this,Ie),D(this,Ee),D(this,le),D(this,me,null),D(this,Y),D(this,ce),D(this,de,null),D(this,ue,null),D(this,pe,null),D(this,Ge,c=>P(this,null,function*(){var a;S(this,ce).reset();const{body:l,redirected:r,status:o,headers:f}=c;if(o===204){K(this,J,ge).call(this,"Server sent HTTP 204, not reconnecting",204),this.close();return}if(r?C(this,ie,new URL(c.url)):C(this,ie,void 0),o!==200){K(this,J,ge).call(this,`Non-200 status code (${o})`,o);return}if(!(f.get("content-type")||"").startsWith("text/event-stream")){K(this,J,ge).call(this,'Invalid content type, expected "text/event-stream"',o);return}if(S(this,F)===this.CLOSED)return;C(this,F,this.OPEN);const p=new Event("open");if((a=S(this,pe))==null||a.call(this,p),this.dispatchEvent(p),typeof l!="object"||!l||!("getReader"in l)){K(this,J,ge).call(this,"Invalid response body, expected a web ReadableStream",o),this.close();return}const m=new TextDecoder,h=l.getReader();let g=!0;do{const{done:d,value:E}=yield h.read();E&&S(this,ce).feed(m.decode(E,{stream:!d})),d&&(g=!1,S(this,ce).reset(),K(this,J,ze).call(this))}while(g)})),D(this,Be,c=>{C(this,Y,void 0),!(c.name==="AbortError"||c.type==="aborted")&&K(this,J,ze).call(this,Ue(c))}),D(this,He,c=>{typeof c.id=="string"&&C(this,me,c.id);const a=new MessageEvent(c.event||"message",{data:c.data,origin:S(this,ie)?S(this,ie).origin:S(this,te).origin,lastEventId:c.id||""});S(this,ue)&&(!c.event||c.event==="message")&&S(this,ue).call(this,a),this.dispatchEvent(a)}),D(this,Ke,c=>{C(this,Ee,c)}),D(this,Ye,()=>{C(this,le,void 0),S(this,F)===this.CONNECTING&&K(this,J,qe).call(this)});try{if(n instanceof URL)C(this,te,n);else if(typeof n=="string")C(this,te,new URL(n,fn()));else throw new Error("Invalid URL")}catch(c){throw dn("An invalid or illegal string was specified")}C(this,ce,un({onEvent:S(this,He),onRetry:S(this,Ke)})),C(this,F,this.CONNECTING),C(this,Ee,3e3),C(this,Ie,(s=t==null?void 0:t.fetch)!=null?s:globalThis.fetch),C(this,Le,(i=t==null?void 0:t.withCredentials)!=null?i:!1),K(this,J,qe).call(this)}get readyState(){return S(this,F)}get url(){return S(this,te).href}get withCredentials(){return S(this,Le)}get onerror(){return S(this,de)}set onerror(n){C(this,de,n)}get onmessage(){return S(this,ue)}set onmessage(n){C(this,ue,n)}get onopen(){return S(this,pe)}set onopen(n){C(this,pe,n)}addEventListener(n,t,s){const i=t;super.addEventListener(n,i,s)}removeEventListener(n,t,s){const i=t;super.removeEventListener(n,i,s)}close(){S(this,le)&&clearTimeout(S(this,le)),S(this,F)!==this.CLOSED&&(S(this,Y)&&S(this,Y).abort(),C(this,F,this.CLOSED),C(this,Y,void 0))}}F=new WeakMap,te=new WeakMap,ie=new WeakMap,Le=new WeakMap,Ie=new WeakMap,Ee=new WeakMap,le=new WeakMap,me=new WeakMap,Y=new WeakMap,ce=new WeakMap,de=new WeakMap,ue=new WeakMap,pe=new WeakMap,J=new WeakSet,qe=function(){C(this,F,this.CONNECTING),C(this,Y,new AbortController),S(this,Ie)(S(this,te),K(this,J,bt).call(this)).then(S(this,Ge)).catch(S(this,Be))},Ge=new WeakMap,Be=new WeakMap,bt=function(){var e;const n={mode:"cors",redirect:"follow",headers:I({Accept:"text/event-stream"},S(this,me)?{"Last-Event-ID":S(this,me)}:void 0),cache:"no-store",signal:(e=S(this,Y))==null?void 0:e.signal};return"window"in globalThis&&(n.credentials=this.withCredentials?"include":"same-origin"),n},He=new WeakMap,Ke=new WeakMap,ge=function(e,n){var t;S(this,F)!==this.CLOSED&&C(this,F,this.CLOSED);const s=new _t("error",{code:n,message:e});(t=S(this,de))==null||t.call(this,s),this.dispatchEvent(s)},ze=function(e,n){var t;if(S(this,F)===this.CLOSED)return;C(this,F,this.CONNECTING);const s=new _t("error",{code:n,message:e});(t=S(this,de))==null||t.call(this,s),this.dispatchEvent(s),C(this,le,setTimeout(S(this,Ye),S(this,Ee)))},Ye=new WeakMap,Se.CONNECTING=0,Se.OPEN=1,Se.CLOSED=2;function fn(){const e="document"in globalThis?globalThis.document:void 0;return e&&typeof e=="object"&&"baseURI"in e&&typeof e.baseURI=="string"?e.baseURI:void 0}const hn=e=>{let n="";const t=new Uint8Array(e),s=t.byteLength;for(let i=0;i<s;i++)n+=String.fromCharCode(t[i]);return btoa(n)},at={status:"idle",error:null,result:null,progressMessages:[],tasks:{fetchDesign:{status:"pending"},codeGeneration:{status:"pending",progress:0},uploadAssets:{status:"pending"}},jobSessionId:null,jobStatus:{},jobType:null},Rt=10,jt=e=>"path"in e?{filePath:e.path.replace(/^\//,""),referencePath:e.path==="/"?"":e.path}:{filePath:e.filePath.replace(/^\//,""),referencePath:e.referencePath==="/"?"":e.referencePath},Wt=({es:e,lastFetchResponse:n,stateUpdated:t})=>{const s=structuredClone(at);return s.status="pending",t(I({},s)),new Promise((i,c)=>{const a={};e.addEventListener("set_job_type",r=>{const o=JSON.parse(r.data);s.jobType=o.payload.jobType,t(I({},s))}),e.addEventListener("start",r=>{const o=JSON.parse(r.data);a.sessionId=o.sessionId,s.tasks.fetchDesign.status="running",s.jobSessionId=o.sessionId,t(I({},s))}),e.addEventListener("queueing",r=>{const o=JSON.parse(r.data);s.jobSessionId=o.payload.sessionId,t(I({},s))}),e.addEventListener("pre_codegen",r=>{JSON.parse(r.data).message==="Anima model built"&&(s.tasks.fetchDesign.status="finished",s.tasks.codeGeneration.status="running",s.tasks.uploadAssets.status="running",t(I({},s)))}),e.addEventListener("figma_metadata",r=>{const o=JSON.parse(r.data);a.figmaFileName=o.figmaFileName,a.figmaSelectedFrameName=o.figmaSelectedFrameName}),e.addEventListener("aborted",()=>{const r=new be.CodegenError({name:"Aborted",reason:"Unknown"});s.status="aborted",s.result=null,s.error=r,t(I({},s)),i({result:null,error:r})}),e.addEventListener("generating_code",r=>{var f,p;const o=JSON.parse(r.data);if(o.payload.status==="success"&&(a.files=o.payload.files),o.payload.status==="failure"){const m=(p=(f=o.payload.files)==null?void 0:f.error)==null?void 0:p.content,h=new be.CodegenError({name:"Generation failed",reason:"Code generation failed",detail:m});s.status="error",s.error=h,t(I({},s)),i({result:null,error:h});return}s.tasks.codeGeneration.progress=o.payload.progress,s.tasks.codeGeneration.status="running",t(I({},s))}),e.addEventListener("progress_messages_updated",r=>{const o=JSON.parse(r.data);s.progressMessages=o.payload.progressMessages,t(I({},s))}),e.addEventListener("job_status_updated",r=>{const o=JSON.parse(r.data);s.jobStatus=o.payload.jobStatus,t(I({},s))}),e.addEventListener("codegen_completed",()=>{s.tasks.codeGeneration.status="finished",t(I({},s))}),e.addEventListener("generation_completed",()=>{s.tasks.codeGeneration.status="finished",t(I({},s))}),e.addEventListener("assets_uploaded",()=>{s.tasks.uploadAssets.status="finished",t(I({},s))}),e.addEventListener("assets_list",r=>{const o=JSON.parse(r.data);a.assets=o.payload.assets});let l=0;e.addEventListener("error",r=>P(null,null,function*(){var g,d,E,u,w,b,x;if(!n)return;const o=yield n;if(!o.ok){let R="";try{R=yield o.text();const A=JSON.parse(R);(g=A==null?void 0:A.payload)!=null&&g.message&&(R=A.payload.message)}catch(A){}c(new be.CodegenError({name:"Request failed",reason:R,status:o.status})),e.close();return}console.warn(`Experienced error during code generation (attempt ${l+1} / ${Rt})`,r);let f,p=!1;if(r instanceof MessageEvent)try{f=JSON.parse(r.data)}catch(R){}(((d=f==null?void 0:f.payload)==null?void 0:d.name)==="Task Crashed"||((E=f==null?void 0:f.payload)==null?void 0:E.name)==="TimeoutError"||((u=f==null?void 0:f.payload)==null?void 0:u.name)==="Error"||((w=f==null?void 0:f.payload)==null?void 0:w.name)==="Unknown error")&&(p=!0);const m=new be.CodegenError({name:(b=f==null?void 0:f.payload.name)!=null?b:"Unknown error",reason:(x=f==null?void 0:f.payload.message)!=null?x:"Unknown",status:f==null?void 0:f.payload.status,detail:f==null?void 0:f.payload.detail});l++;let h=!1;l>Rt?(console.error("Experienced too many errors, terminating request"),h=!0):p&&(console.error("Experienced unrecoverable error, terminating request"),h=!0),h&&(s.status="error",s.error=m,t(I({},s)),i({result:null,error:m}))})),e.addEventListener("done",r=>{const o=JSON.parse(r.data);a.tokenUsage=o.payload.tokenUsage,a.sessionId=o.payload.sessionId,s.status="success",s.result=a,t(I({},s)),i({result:a,error:null})})})},Ft=(e,n,t,s)=>P(null,null,function*(){var l;const i=structuredClone(t);if(((l=t.assetsStorage)==null?void 0:l.strategy)==="local"){const{referencePath:r}=jt(t.assetsStorage);t.assetsStorage={strategy:"external",url:r}}let c;const a=new Se(e,{fetch:(r,o)=>(c=fetch(r,Me(I({},o),{method:n,body:JSON.stringify(t)})),c)});try{const{result:r,error:o}=yield Wt({es:a,lastFetchResponse:c,stateUpdated:s});if(o||!r)return{result:null,error:o};const f=structuredClone(r);return Vt(f,i),{result:f,error:null}}finally{a.close()}}),pn=(e,n,t)=>P(null,null,function*(){const s=structuredClone(n);let i;const c=new Se(e,{fetch:(a,l)=>(i=fetch(a,Me(I({},l),{method:"POST",body:JSON.stringify(n)})),i)});try{const{result:a,error:l}=yield Wt({es:c,lastFetchResponse:i,stateUpdated:t});if(l||!a)return{result:null,error:l};const r=structuredClone(a);return Vt(r,s),{result:r,error:null}}finally{c.close()}}),Vt=(e,n)=>P(null,null,function*(){var t,s;if(((t=n.assetsStorage)==null?void 0:t.strategy)==="local"&&((s=e.assets)!=null&&s.length)){const{filePath:i}=jt(n.assetsStorage),c=e.assets.map(l=>P(null,null,function*(){const o=yield(yield fetch(l.url)).arrayBuffer();return{assetName:l.name,base64:hn(o)}})),a=yield Promise.allSettled(c);for(const l of a)if(l.status==="fulfilled"){const{assetName:r,base64:o}=l.value,f=i?`${i}/${r}`:r;e.files[f]={content:o,isBinary:!0}}}});class Pt extends Error{constructor(n,t){super(n),this.name="CreateJobError",this.cause=t}}class $t extends Error{constructor(n,t){super(n),this.name="AttachJobError",this.cause=t}}class Jt extends Error{constructor(){super(""),this.name="UnknownCodegenError"}}const it=y.createContext(null);function gn({figmaRestApi:e,f2cUrl:n,l2cUrl:t,p2cUrl:s,jobsUrl:i,children:c}){const[a,l]=y.useState({status:"idle"}),r=y.useRef(null),[o,f]=y.useState(at),p={f2c:n,l2c:t,p2c:s},m=(g,d)=>P(null,null,function*(){var E;if(a.status==="pending")throw new Error("A job is already in progress");r.current=g;try{const u=p[g],{result:w}=yield Ft(u,"POST",d,b=>f(b));if(w){const b=w.sessionId,x=w.files,R=w.assets;l(A=>({status:"success",type:g,params:"params"in A?A.params:{},sessionId:b,payload:o.jobStatus,assets:R,files:x,progressMessages:o.progressMessages}));return}}catch(u){r.current=null;const w=u instanceof Error?u.message:"Unknown error",b=new Pt(w,u);throw l({status:"error",type:g,params:d,error:b,sessionId:(E=o.jobSessionId)!=null?E:null,payload:o.jobStatus,progressMessages:o.progressMessages}),b}}),h=(g,d)=>P(null,null,function*(){if(!i)throw new Error("jobsUrl is required in order to attach to a job");try{const E=`${i}/${g}`,{result:u}=yield pn(E,d,w=>f(w));if(u){const w=u.files,b=u.assets;l(x=>({status:"success",type:o.jobType,params:"params"in x?x.params:{},sessionId:g,payload:o.jobStatus,assets:b,files:w,progressMessages:o.progressMessages}))}}catch(E){const u=E instanceof Error?E.message:"Unknown error",w=new $t(u,E);throw l({status:"error",type:r.current,params:{},error:w,sessionId:g,payload:o.jobStatus,progressMessages:o.progressMessages}),w}});return y.useEffect(()=>{var d,E;const g=(d=r.current)!=null?d:o.jobType;if(g){if(o.status==="error"){const u=(E=o.error)!=null?E:new Jt;l(w=>{var b;return{status:"error",type:g,params:"params"in w?w.params:{},error:u,sessionId:(b=o.jobSessionId)!=null?b:null,payload:o.jobStatus,progressMessages:o.progressMessages}});return}if(o.status==="pending"){l(u=>({status:"pending",type:g,params:"params"in u?u.params:{},sessionId:o.jobSessionId,payload:o.jobStatus,progressMessages:o.progressMessages}));return}}},[o]),cn.jsx(it.Provider,{value:{createJob:m,attachJob:h,job:a,figmaRestApi:e},children:c})}function Ut(){const e=y.useContext(it);if(!e)throw new Error("useAnimaSDK must be used within AnimaSDKProvider");return e}const En=({url:e,method:n="POST"})=>{const[t,s]=y.useState(at);return{getCode:y.useCallback(c=>Ft(e,n,c,s),[e,n]),status:t.status,progressMessages:t.progressMessages,jobSessionId:t.jobSessionId,jobStatus:t.jobStatus,tasks:t.tasks,error:t.error,result:t.result}};var Re={exports:{}},ke={};/**
|
|
6
6
|
* @license React
|
|
7
7
|
* use-sync-external-store-shim.production.js
|
|
8
8
|
*
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* This source code is licensed under the MIT license found in the
|
|
12
12
|
* LICENSE file in the root directory of this source tree.
|
|
13
|
-
*/var Ct;function mn(){if(Ct)return ke;Ct=1;var e=y;function n(
|
|
13
|
+
*/var Ct;function mn(){if(Ct)return ke;Ct=1;var e=y;function n(p,m){return p===m&&(p!==0||1/p===1/m)||p!==p&&m!==m}var t=typeof Object.is=="function"?Object.is:n,s=e.useState,i=e.useEffect,c=e.useLayoutEffect,a=e.useDebugValue;function l(p,m){var h=m(),g=s({inst:{value:h,getSnapshot:m}}),d=g[0].inst,E=g[1];return c(function(){d.value=h,d.getSnapshot=m,r(d)&&E({inst:d})},[p,h,m]),i(function(){return r(d)&&E({inst:d}),p(function(){r(d)&&E({inst:d})})},[p]),a(h),h}function r(p){var m=p.getSnapshot;p=p.value;try{var h=m();return!t(p,h)}catch(g){return!0}}function o(p,m){return m()}var f=typeof window=="undefined"||typeof window.document=="undefined"||typeof window.document.createElement=="undefined"?o:l;return ke.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:f,ke}var je={};/**
|
|
14
14
|
* @license React
|
|
15
15
|
* use-sync-external-store-shim.development.js
|
|
16
16
|
*
|
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
*
|
|
19
19
|
* This source code is licensed under the MIT license found in the
|
|
20
20
|
* LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/var Tt;function Sn(){return Tt||(Tt=1,process.env.NODE_ENV!=="production"&&(function(){function e(h,p){return h===p&&(h!==0||1/h===1/p)||h!==h&&p!==p}function n(h,p){f||i.startTransition===void 0||(f=!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=p();if(!E){var g=p();c(d,g)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),E=!0)}g=a({inst:{value:d,getSnapshot:p}});var u=g[0].inst,w=g[1];return r(function(){u.value=d,u.getSnapshot=p,t(u)&&w({inst:u})},[h,d,p]),l(function(){return t(u)&&w({inst:u}),h(function(){t(u)&&w({inst:u})})},[h]),o(d),d}function t(h){var p=h.getSnapshot;h=h.value;try{var d=p();return!c(h,d)}catch(g){return!0}}function s(h,p){return p()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__!="undefined"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var i=y,c=typeof Object.is=="function"?Object.is:e,a=i.useState,l=i.useEffect,r=i.useLayoutEffect,o=i.useDebugValue,f=!1,E=!1,m=typeof window=="undefined"||typeof window.document=="undefined"||typeof window.document.createElement=="undefined"?s:n;je.useSyncExternalStore=i.useSyncExternalStore!==void 0?i.useSyncExternalStore:m,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__!="undefined"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()),je}var Lt;function vn(){return Lt||(Lt=1,process.env.NODE_ENV==="production"?be.exports=mn():be.exports=Sn()),be.exports}var wn=vn();const qt=0,Gt=1,Bt=2,It=3;var Dt=Object.prototype.hasOwnProperty;function Xe(e,n){var t,s;if(e===n)return!0;if(e&&n&&(t=e.constructor)===n.constructor){if(t===Date)return e.getTime()===n.getTime();if(t===RegExp)return e.toString()===n.toString();if(t===Array){if((s=e.length)===n.length)for(;s--&&Xe(e[s],n[s]););return s===-1}if(!t||typeof e=="object"){s=0;for(t in e)if(Dt.call(e,t)&&++s&&!Dt.call(n,t)||!(t in n)||!Xe(e[t],n[t]))return!1;return Object.keys(n).length===s}}return e!==e&&n!==n}const z=new WeakMap,X=()=>{},k=X(),Qe=Object,v=e=>e===k,G=e=>typeof e=="function",Q=(e,n)=>I(I({},e),n),Ht=e=>G(e.then),We={},Re={},ct="undefined",we=typeof window!=ct,Ze=typeof document!=ct,yn=we&&"Deno"in window,_n=()=>we&&typeof window.requestAnimationFrame!=ct,Kt=(e,n)=>{const t=z.get(e);return[()=>!v(n)&&e.get(n)||We,s=>{if(!v(n)){const i=e.get(n);n in Re||(Re[n]=i),t[5](n,Q(i,s),i||We)}},t[6],()=>!v(n)&&n in Re?Re[n]:!v(n)&&e.get(n)||We]};let et=!0;const On=()=>et,[tt,nt]=we&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[X,X],bn=()=>{const e=Ze&&document.visibilityState;return v(e)||e!=="hidden"},Rn=e=>(Ze&&document.addEventListener("visibilitychange",e),tt("focus",e),()=>{Ze&&document.removeEventListener("visibilitychange",e),nt("focus",e)}),Cn=e=>{const n=()=>{et=!0,e()},t=()=>{et=!1};return tt("online",n),tt("offline",t),()=>{nt("online",n),nt("offline",t)}},Tn={isOnline:On,isVisible:bn},Ln={initFocus:Rn,initReconnect:Cn},At=!y.useId,ve=!we||yn,In=e=>_n()?window.requestAnimationFrame(e):setTimeout(e,1),Fe=ve?y.useEffect:y.useLayoutEffect,Ve=typeof navigator!="undefined"&&navigator.connection,Nt=!ve&&Ve&&(["slow-2g","2g"].includes(Ve.effectiveType)||Ve.saveData),Ce=new WeakMap,Dn=e=>Qe.prototype.toString.call(e),Pe=(e,n)=>e===`[object ${n}]`;let An=0;const st=e=>{const n=typeof e,t=Dn(e),s=Pe(t,"Date"),i=Pe(t,"RegExp"),c=Pe(t,"Object");let a,l;if(Qe(e)===e&&!s&&!i){if(a=Ce.get(e),a)return a;if(a=++An+"~",Ce.set(e,a),Array.isArray(e)){for(a="@",l=0;l<e.length;l++)a+=st(e[l])+",";Ce.set(e,a)}if(c){a="#";const r=Qe.keys(e).sort();for(;!v(l=r.pop());)v(e[l])||(a+=l+":"+st(e[l])+",");Ce.set(e,a)}}else a=s?e.toJSON():n=="symbol"?e.toString():n=="string"?JSON.stringify(e):""+e;return a},ut=e=>{if(G(e))try{e=e()}catch(t){e=""}const n=e;return e=typeof e=="string"?e:(Array.isArray(e)?e.length:e)?st(e):"",[e,n]};let Nn=0;const rt=()=>++Nn;function zt(...e){return P(this,null,function*(){const[n,t,s,i]=e,c=Q({populateCache:!0,throwOnError:!0},typeof i=="boolean"?{revalidate:i}:i||{});let a=c.populateCache;const l=c.rollbackOnError;let r=c.optimisticData;const o=m=>typeof l=="function"?l(m):l!==!1,f=c.throwOnError;if(G(t)){const m=t,h=[],p=n.keys();for(const d of p)!/^\$(inf|sub)\$/.test(d)&&m(n.get(d)._k)&&h.push(d);return Promise.all(h.map(E))}return E(t);function E(m){return P(this,null,function*(){const[h]=ut(m);if(!h)return;const[p,d]=Kt(n,h),[g,u,w,b]=z.get(n),x=()=>{const j=g[h];return(G(c.revalidate)?c.revalidate(p().data,m):c.revalidate!==!1)&&(delete w[h],delete b[h],j&&j[0])?j[0](Bt).then(()=>p().data):p().data};if(e.length<3)return x();let R=s,A,U=!1;const L=rt();u[h]=[L,0];const ne=!v(r),q=p(),se=q.data,ye=q._c,Z=v(ye)?se:ye;if(ne&&(r=G(r)?r(Z,se):r,d({data:r,_c:Z})),G(R))try{R=R(Z)}catch(j){A=j,U=!0}if(R&&Ht(R))if(R=yield R.catch(j=>{A=j,U=!0}),L!==u[h][0]){if(U)throw A;return R}else U&&ne&&o(A)&&(a=!0,d({data:Z,_c:k}));if(a&&!U)if(G(a)){const j=a(R,Z);d({data:j,error:k,_c:k})}else d({data:R,error:k,_c:k});if(u[h][1]=rt(),Promise.resolve(x()).then(()=>{d({_c:k})}),U){if(f)throw A;return}return R})}})}const Mt=(e,n)=>{for(const t in e)e[t][0]&&e[t][0](n)},Mn=(e,n)=>{if(!z.has(e)){const t=Q(Ln,n),s=Object.create(null),i=zt.bind(k,e);let c=X;const a=Object.create(null),l=(f,E)=>{const m=a[f]||[];return a[f]=m,m.push(E),()=>m.splice(m.indexOf(E),1)},r=(f,E,m)=>{e.set(f,E);const h=a[f];if(h)for(const p of h)p(E,m)},o=()=>{if(!z.has(e)&&(z.set(e,[s,Object.create(null),Object.create(null),Object.create(null),i,r,l]),!ve)){const f=t.initFocus(setTimeout.bind(k,Mt.bind(k,s,qt))),E=t.initReconnect(setTimeout.bind(k,Mt.bind(k,s,Gt)));c=()=>{f&&f(),E&&E(),z.delete(e)}}};return o(),[e,i,o,c]}return[e,z.get(e)[4]]},xn=(e,n,t,s,i)=>{const c=t.errorRetryCount,a=i.retryCount,l=~~((Math.random()+.5)*(1<<(a<8?a:8)))*t.errorRetryInterval;!v(c)&&a>c||setTimeout(s,l,i)},kn=Xe,[Yt,jn]=Mn(new Map),Wn=Q({onLoadingSlow:X,onSuccess:X,onError:X,onErrorRetry:xn,onDiscarded:X,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:Nt?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:Nt?5e3:3e3,compare:kn,isPaused:()=>!1,cache:Yt,mutate:jn,fallback:{}},Tn),Fn=(e,n)=>{const t=Q(e,n);if(n){const{use:s,fallback:i}=e,{use:c,fallback:a}=n;s&&c&&(t.use=s.concat(c)),i&&a&&(t.fallback=Q(i,a))}return t},Vn=y.createContext({}),Pn="$inf$",Xt=we&&window.__SWR_DEVTOOLS_USE__,$n=Xt?window.__SWR_DEVTOOLS_USE__:[],Jn=()=>{Xt&&(window.__SWR_DEVTOOLS_REACT__=y)},Un=e=>G(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],qn=()=>{const e=y.useContext(Vn);return y.useMemo(()=>Q(Wn,e),[e])},Gn=e=>(n,t,s)=>e(n,t&&((...c)=>{const[a]=ut(n),[,,,l]=z.get(Yt);if(a.startsWith(Pn))return t(...c);const r=l[a];return v(r)?t(...c):(delete l[a],r)}),s),Bn=$n.concat(Gn),Hn=e=>function(...t){const s=qn(),[i,c,a]=Un(t),l=Fn(s,a);let r=e;const{use:o}=l,f=(o||[]).concat(Bn);for(let E=f.length;E--;)r=f[E](r);return r(i,c||l.fetcher||null,l)},Kn=(e,n,t)=>{const s=n[e]||(n[e]=[]);return s.push(t),()=>{const i=s.indexOf(t);i>=0&&(s[i]=s[s.length-1],s.pop())}};Jn();const $e=y.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(n=>{e.status="fulfilled",e.value=n},n=>{e.status="rejected",e.reason=n}),e}}),Je={dedupe:!0},xt=Promise.resolve(k),zn=(e,n,t)=>{const{cache:s,compare:i,suspense:c,fallbackData:a,revalidateOnMount:l,revalidateIfStale:r,refreshInterval:o,refreshWhenHidden:f,refreshWhenOffline:E,keepPreviousData:m}=t,[h,p,d,g]=z.get(s),[u,w]=ut(e),b=y.useRef(!1),x=y.useRef(!1),R=y.useRef(u),A=y.useRef(n),U=y.useRef(t),L=()=>U.current,ne=()=>L().isVisible()&&L().isOnline(),[q,se,ye,Z]=Kt(s,u),j=y.useRef({}).current,fe=v(a)?v(t.fallback)?k:t.fallback[u]:a,lt=(_,T)=>{for(const N in j){const O=N;if(O==="data"){if(!i(_[O],T[O])&&(!v(_[O])||!i(Oe,T[O])))return!1}else if(T[O]!==_[O])return!1}return!0},dt=y.useMemo(()=>{const _=!u||!n?!1:v(l)?L().isPaused()||c?!1:r!==!1:l,T=W=>{const B=Q(W);return delete B._k,_?I({isValidating:!0,isLoading:!0},B):B},N=q(),O=Z(),$=T(N),ae=N===O?$:T(O);let M=$;return[()=>{const W=T(q());return lt(W,M)?(M.data=W.data,M.isLoading=W.isLoading,M.isValidating=W.isValidating,M.error=W.error,M):(M=W,W)},()=>ae]},[s,u]),re=wn.useSyncExternalStore(y.useCallback(_=>ye(u,(T,N)=>{lt(N,T)||_()}),[s,u]),dt[0],dt[1]),ft=!b.current,Qt=h[u]&&h[u].length>0,oe=re.data,ee=v(oe)?fe&&Ht(fe)?$e(fe):fe:oe,_e=re.error,Ie=y.useRef(ee),Oe=m?v(oe)?v(Ie.current)?ee:Ie.current:oe:ee,ht=Qt&&!v(_e)?!1:ft&&!v(l)?l:L().isPaused()?!1:c?v(ee)?!1:r:v(ee)||r,pt=!!(u&&n&&ft&&ht),Zt=v(re.isValidating)?pt:re.isValidating,en=v(re.isLoading)?pt:re.isLoading,he=y.useCallback(_=>P(null,null,function*(){const T=A.current;if(!u||!T||x.current||L().isPaused())return!1;let N,O,$=!0;const ae=_||{},M=!d[u]||!ae.dedupe,W=()=>At?!x.current&&u===R.current&&b.current:u===R.current,B={isValidating:!1,isLoading:!1},Et=()=>{se(B)},mt=()=>{const V=d[u];V&&V[1]===O&&delete d[u]},St={isValidating:!0};v(q().data)&&(St.isLoading=!0);try{if(M&&(se(St),t.loadingTimeout&&v(q().data)&&setTimeout(()=>{$&&W()&&L().onLoadingSlow(u,t)},t.loadingTimeout),d[u]=[T(w),rt()]),[N,O]=d[u],N=yield N,M&&setTimeout(mt,t.dedupingInterval),!d[u]||d[u][1]!==O)return M&&W()&&L().onDiscarded(u),!1;B.error=k;const V=p[u];if(!v(V)&&(O<=V[0]||O<=V[1]||V[1]===0))return Et(),M&&W()&&L().onDiscarded(u),!1;const H=q().data;B.data=i(H,N)?H:N,M&&W()&&L().onSuccess(N,u,t)}catch(V){mt();const H=L(),{shouldRetryOnError:De}=H;H.isPaused()||(B.error=V,M&&W()&&(H.onError(V,u,H),(De===!0||G(De)&&De(V))&&(!L().revalidateOnFocus||!L().revalidateOnReconnect||ne())&&H.onErrorRetry(V,u,H,tn=>{const Ae=h[u];Ae&&Ae[0]&&Ae[0](It,tn)},{retryCount:(ae.retryCount||0)+1,dedupe:!0})))}return $=!1,Et(),!0}),[u,s]),gt=y.useCallback((..._)=>zt(s,R.current,..._),[]);if(Fe(()=>{A.current=n,U.current=t,v(oe)||(Ie.current=oe)}),Fe(()=>{if(!u)return;const _=he.bind(k,Je);let T=0;L().revalidateOnFocus&&(T=Date.now()+L().focusThrottleInterval);const O=Kn(u,h,($,ae={})=>{if($==qt){const M=Date.now();L().revalidateOnFocus&&M>T&&ne()&&(T=M+L().focusThrottleInterval,_())}else if($==Gt)L().revalidateOnReconnect&&ne()&&_();else{if($==Bt)return he();if($==It)return he(ae)}});return x.current=!1,R.current=u,b.current=!0,se({_k:w}),ht&&(d[u]||(v(ee)||ve?_():In(_))),()=>{x.current=!0,O()}},[u]),Fe(()=>{let _;function T(){const O=G(o)?o(q().data):o;O&&_!==-1&&(_=setTimeout(N,O))}function N(){!q().error&&(f||L().isVisible())&&(E||L().isOnline())?he(Je).then(T):T()}return T(),()=>{_&&(clearTimeout(_),_=-1)}},[o,f,E,u]),y.useDebugValue(Oe),c){const _=u&&v(ee);if(!At&&ve&&_)throw new Error("Fallback data is required when using Suspense in SSR.");_&&(A.current=n,U.current=t,x.current=!1);const T=g[u],N=!v(T)&&_?gt(T):xt;if($e(N),!v(_e)&&_)throw _e;const O=_?he(Je):xt;!v(Oe)&&_&&(O.status="fulfilled",O.value=!0),$e(O)}return{mutate:gt,get data(){return j.data=!0,Oe},get error(){return j.error=!0,_e},get isValidating(){return j.isValidating=!0,Zt},get isLoading(){return j.isLoading=!0,en}}},Yn=Hn(zn),Xn=({fileKey:e,authToken:n,enabled:t=!0,params:s={}})=>{const{figmaRestApi:i}=Ut(),c=!!(t&&e&&n),{data:a,isLoading:l,error:r}=Yn(["useFigmaFile",e,n,s],()=>c?i.withOptions(n?{token:n}:{}).getFile({fileKey:e,depth:s.depth}):null,{revalidateIfStale:!1,revalidateOnFocus:!1,revalidateOnReconnect:!1});return{data:a!=null?a:null,isLoading:l,error:r}};exports.AnimaSdkContext=it;exports.AnimaSdkProvider=gn;exports.AttachJobError=$t;exports.CreateJobError=Pt;exports.UnknownCodegenError=Jt;exports.useAnimaCodegen=En;exports.useAnimaSDK=Ut;exports.useFigmaFile=Xn;
|
|
21
|
+
*/var Tt;function Sn(){return Tt||(Tt=1,process.env.NODE_ENV!=="production"&&(function(){function e(h,g){return h===g&&(h!==0||1/h===1/g)||h!==h&&g!==g}function n(h,g){f||i.startTransition===void 0||(f=!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=g();if(!p){var E=g();c(d,E)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),p=!0)}E=a({inst:{value:d,getSnapshot:g}});var u=E[0].inst,w=E[1];return r(function(){u.value=d,u.getSnapshot=g,t(u)&&w({inst:u})},[h,d,g]),l(function(){return t(u)&&w({inst:u}),h(function(){t(u)&&w({inst:u})})},[h]),o(d),d}function t(h){var g=h.getSnapshot;h=h.value;try{var d=g();return!c(h,d)}catch(E){return!0}}function s(h,g){return g()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__!="undefined"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var i=y,c=typeof Object.is=="function"?Object.is:e,a=i.useState,l=i.useEffect,r=i.useLayoutEffect,o=i.useDebugValue,f=!1,p=!1,m=typeof window=="undefined"||typeof window.document=="undefined"||typeof window.document.createElement=="undefined"?s:n;je.useSyncExternalStore=i.useSyncExternalStore!==void 0?i.useSyncExternalStore:m,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__!="undefined"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()),je}var Lt;function vn(){return Lt||(Lt=1,process.env.NODE_ENV==="production"?Re.exports=mn():Re.exports=Sn()),Re.exports}var wn=vn();const qt=0,Gt=1,Bt=2,It=3;var Dt=Object.prototype.hasOwnProperty;function Xe(e,n){var t,s;if(e===n)return!0;if(e&&n&&(t=e.constructor)===n.constructor){if(t===Date)return e.getTime()===n.getTime();if(t===RegExp)return e.toString()===n.toString();if(t===Array){if((s=e.length)===n.length)for(;s--&&Xe(e[s],n[s]););return s===-1}if(!t||typeof e=="object"){s=0;for(t in e)if(Dt.call(e,t)&&++s&&!Dt.call(n,t)||!(t in n)||!Xe(e[t],n[t]))return!1;return Object.keys(n).length===s}}return e!==e&&n!==n}const z=new WeakMap,X=()=>{},k=X(),Qe=Object,v=e=>e===k,G=e=>typeof e=="function",Q=(e,n)=>I(I({},e),n),Ht=e=>G(e.then),We={},Ce={},ct="undefined",we=typeof window!=ct,Ze=typeof document!=ct,yn=we&&"Deno"in window,_n=()=>we&&typeof window.requestAnimationFrame!=ct,Kt=(e,n)=>{const t=z.get(e);return[()=>!v(n)&&e.get(n)||We,s=>{if(!v(n)){const i=e.get(n);n in Ce||(Ce[n]=i),t[5](n,Q(i,s),i||We)}},t[6],()=>!v(n)&&n in Ce?Ce[n]:!v(n)&&e.get(n)||We]};let et=!0;const On=()=>et,[tt,nt]=we&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[X,X],bn=()=>{const e=Ze&&document.visibilityState;return v(e)||e!=="hidden"},Rn=e=>(Ze&&document.addEventListener("visibilitychange",e),tt("focus",e),()=>{Ze&&document.removeEventListener("visibilitychange",e),nt("focus",e)}),Cn=e=>{const n=()=>{et=!0,e()},t=()=>{et=!1};return tt("online",n),tt("offline",t),()=>{nt("online",n),nt("offline",t)}},Tn={isOnline:On,isVisible:bn},Ln={initFocus:Rn,initReconnect:Cn},At=!y.useId,ve=!we||yn,In=e=>_n()?window.requestAnimationFrame(e):setTimeout(e,1),Fe=ve?y.useEffect:y.useLayoutEffect,Ve=typeof navigator!="undefined"&&navigator.connection,Nt=!ve&&Ve&&(["slow-2g","2g"].includes(Ve.effectiveType)||Ve.saveData),Te=new WeakMap,Dn=e=>Qe.prototype.toString.call(e),Pe=(e,n)=>e===`[object ${n}]`;let An=0;const st=e=>{const n=typeof e,t=Dn(e),s=Pe(t,"Date"),i=Pe(t,"RegExp"),c=Pe(t,"Object");let a,l;if(Qe(e)===e&&!s&&!i){if(a=Te.get(e),a)return a;if(a=++An+"~",Te.set(e,a),Array.isArray(e)){for(a="@",l=0;l<e.length;l++)a+=st(e[l])+",";Te.set(e,a)}if(c){a="#";const r=Qe.keys(e).sort();for(;!v(l=r.pop());)v(e[l])||(a+=l+":"+st(e[l])+",");Te.set(e,a)}}else a=s?e.toJSON():n=="symbol"?e.toString():n=="string"?JSON.stringify(e):""+e;return a},ut=e=>{if(G(e))try{e=e()}catch(t){e=""}const n=e;return e=typeof e=="string"?e:(Array.isArray(e)?e.length:e)?st(e):"",[e,n]};let Nn=0;const rt=()=>++Nn;function zt(...e){return P(this,null,function*(){const[n,t,s,i]=e,c=Q({populateCache:!0,throwOnError:!0},typeof i=="boolean"?{revalidate:i}:i||{});let a=c.populateCache;const l=c.rollbackOnError;let r=c.optimisticData;const o=m=>typeof l=="function"?l(m):l!==!1,f=c.throwOnError;if(G(t)){const m=t,h=[],g=n.keys();for(const d of g)!/^\$(inf|sub)\$/.test(d)&&m(n.get(d)._k)&&h.push(d);return Promise.all(h.map(p))}return p(t);function p(m){return P(this,null,function*(){const[h]=ut(m);if(!h)return;const[g,d]=Kt(n,h),[E,u,w,b]=z.get(n),x=()=>{const j=E[h];return(G(c.revalidate)?c.revalidate(g().data,m):c.revalidate!==!1)&&(delete w[h],delete b[h],j&&j[0])?j[0](Bt).then(()=>g().data):g().data};if(e.length<3)return x();let R=s,A,U=!1;const L=rt();u[h]=[L,0];const ne=!v(r),q=g(),se=q.data,ye=q._c,Z=v(ye)?se:ye;if(ne&&(r=G(r)?r(Z,se):r,d({data:r,_c:Z})),G(R))try{R=R(Z)}catch(j){A=j,U=!0}if(R&&Ht(R))if(R=yield R.catch(j=>{A=j,U=!0}),L!==u[h][0]){if(U)throw A;return R}else U&&ne&&o(A)&&(a=!0,d({data:Z,_c:k}));if(a&&!U)if(G(a)){const j=a(R,Z);d({data:j,error:k,_c:k})}else d({data:R,error:k,_c:k});if(u[h][1]=rt(),Promise.resolve(x()).then(()=>{d({_c:k})}),U){if(f)throw A;return}return R})}})}const Mt=(e,n)=>{for(const t in e)e[t][0]&&e[t][0](n)},Mn=(e,n)=>{if(!z.has(e)){const t=Q(Ln,n),s=Object.create(null),i=zt.bind(k,e);let c=X;const a=Object.create(null),l=(f,p)=>{const m=a[f]||[];return a[f]=m,m.push(p),()=>m.splice(m.indexOf(p),1)},r=(f,p,m)=>{e.set(f,p);const h=a[f];if(h)for(const g of h)g(p,m)},o=()=>{if(!z.has(e)&&(z.set(e,[s,Object.create(null),Object.create(null),Object.create(null),i,r,l]),!ve)){const f=t.initFocus(setTimeout.bind(k,Mt.bind(k,s,qt))),p=t.initReconnect(setTimeout.bind(k,Mt.bind(k,s,Gt)));c=()=>{f&&f(),p&&p(),z.delete(e)}}};return o(),[e,i,o,c]}return[e,z.get(e)[4]]},xn=(e,n,t,s,i)=>{const c=t.errorRetryCount,a=i.retryCount,l=~~((Math.random()+.5)*(1<<(a<8?a:8)))*t.errorRetryInterval;!v(c)&&a>c||setTimeout(s,l,i)},kn=Xe,[Yt,jn]=Mn(new Map),Wn=Q({onLoadingSlow:X,onSuccess:X,onError:X,onErrorRetry:xn,onDiscarded:X,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:Nt?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:Nt?5e3:3e3,compare:kn,isPaused:()=>!1,cache:Yt,mutate:jn,fallback:{}},Tn),Fn=(e,n)=>{const t=Q(e,n);if(n){const{use:s,fallback:i}=e,{use:c,fallback:a}=n;s&&c&&(t.use=s.concat(c)),i&&a&&(t.fallback=Q(i,a))}return t},Vn=y.createContext({}),Pn="$inf$",Xt=we&&window.__SWR_DEVTOOLS_USE__,$n=Xt?window.__SWR_DEVTOOLS_USE__:[],Jn=()=>{Xt&&(window.__SWR_DEVTOOLS_REACT__=y)},Un=e=>G(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],qn=()=>{const e=y.useContext(Vn);return y.useMemo(()=>Q(Wn,e),[e])},Gn=e=>(n,t,s)=>e(n,t&&((...c)=>{const[a]=ut(n),[,,,l]=z.get(Yt);if(a.startsWith(Pn))return t(...c);const r=l[a];return v(r)?t(...c):(delete l[a],r)}),s),Bn=$n.concat(Gn),Hn=e=>function(...t){const s=qn(),[i,c,a]=Un(t),l=Fn(s,a);let r=e;const{use:o}=l,f=(o||[]).concat(Bn);for(let p=f.length;p--;)r=f[p](r);return r(i,c||l.fetcher||null,l)},Kn=(e,n,t)=>{const s=n[e]||(n[e]=[]);return s.push(t),()=>{const i=s.indexOf(t);i>=0&&(s[i]=s[s.length-1],s.pop())}};Jn();const $e=y.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(n=>{e.status="fulfilled",e.value=n},n=>{e.status="rejected",e.reason=n}),e}}),Je={dedupe:!0},xt=Promise.resolve(k),zn=(e,n,t)=>{const{cache:s,compare:i,suspense:c,fallbackData:a,revalidateOnMount:l,revalidateIfStale:r,refreshInterval:o,refreshWhenHidden:f,refreshWhenOffline:p,keepPreviousData:m}=t,[h,g,d,E]=z.get(s),[u,w]=ut(e),b=y.useRef(!1),x=y.useRef(!1),R=y.useRef(u),A=y.useRef(n),U=y.useRef(t),L=()=>U.current,ne=()=>L().isVisible()&&L().isOnline(),[q,se,ye,Z]=Kt(s,u),j=y.useRef({}).current,fe=v(a)?v(t.fallback)?k:t.fallback[u]:a,lt=(_,T)=>{for(const N in j){const O=N;if(O==="data"){if(!i(_[O],T[O])&&(!v(_[O])||!i(Oe,T[O])))return!1}else if(T[O]!==_[O])return!1}return!0},dt=y.useMemo(()=>{const _=!u||!n?!1:v(l)?L().isPaused()||c?!1:r!==!1:l,T=W=>{const B=Q(W);return delete B._k,_?I({isValidating:!0,isLoading:!0},B):B},N=q(),O=Z(),$=T(N),ae=N===O?$:T(O);let M=$;return[()=>{const W=T(q());return lt(W,M)?(M.data=W.data,M.isLoading=W.isLoading,M.isValidating=W.isValidating,M.error=W.error,M):(M=W,W)},()=>ae]},[s,u]),re=wn.useSyncExternalStore(y.useCallback(_=>ye(u,(T,N)=>{lt(N,T)||_()}),[s,u]),dt[0],dt[1]),ft=!b.current,Qt=h[u]&&h[u].length>0,oe=re.data,ee=v(oe)?fe&&Ht(fe)?$e(fe):fe:oe,_e=re.error,De=y.useRef(ee),Oe=m?v(oe)?v(De.current)?ee:De.current:oe:ee,ht=Qt&&!v(_e)?!1:ft&&!v(l)?l:L().isPaused()?!1:c?v(ee)?!1:r:v(ee)||r,pt=!!(u&&n&&ft&&ht),Zt=v(re.isValidating)?pt:re.isValidating,en=v(re.isLoading)?pt:re.isLoading,he=y.useCallback(_=>P(null,null,function*(){const T=A.current;if(!u||!T||x.current||L().isPaused())return!1;let N,O,$=!0;const ae=_||{},M=!d[u]||!ae.dedupe,W=()=>At?!x.current&&u===R.current&&b.current:u===R.current,B={isValidating:!1,isLoading:!1},Et=()=>{se(B)},mt=()=>{const V=d[u];V&&V[1]===O&&delete d[u]},St={isValidating:!0};v(q().data)&&(St.isLoading=!0);try{if(M&&(se(St),t.loadingTimeout&&v(q().data)&&setTimeout(()=>{$&&W()&&L().onLoadingSlow(u,t)},t.loadingTimeout),d[u]=[T(w),rt()]),[N,O]=d[u],N=yield N,M&&setTimeout(mt,t.dedupingInterval),!d[u]||d[u][1]!==O)return M&&W()&&L().onDiscarded(u),!1;B.error=k;const V=g[u];if(!v(V)&&(O<=V[0]||O<=V[1]||V[1]===0))return Et(),M&&W()&&L().onDiscarded(u),!1;const H=q().data;B.data=i(H,N)?H:N,M&&W()&&L().onSuccess(N,u,t)}catch(V){mt();const H=L(),{shouldRetryOnError:Ae}=H;H.isPaused()||(B.error=V,M&&W()&&(H.onError(V,u,H),(Ae===!0||G(Ae)&&Ae(V))&&(!L().revalidateOnFocus||!L().revalidateOnReconnect||ne())&&H.onErrorRetry(V,u,H,tn=>{const Ne=h[u];Ne&&Ne[0]&&Ne[0](It,tn)},{retryCount:(ae.retryCount||0)+1,dedupe:!0})))}return $=!1,Et(),!0}),[u,s]),gt=y.useCallback((..._)=>zt(s,R.current,..._),[]);if(Fe(()=>{A.current=n,U.current=t,v(oe)||(De.current=oe)}),Fe(()=>{if(!u)return;const _=he.bind(k,Je);let T=0;L().revalidateOnFocus&&(T=Date.now()+L().focusThrottleInterval);const O=Kn(u,h,($,ae={})=>{if($==qt){const M=Date.now();L().revalidateOnFocus&&M>T&&ne()&&(T=M+L().focusThrottleInterval,_())}else if($==Gt)L().revalidateOnReconnect&&ne()&&_();else{if($==Bt)return he();if($==It)return he(ae)}});return x.current=!1,R.current=u,b.current=!0,se({_k:w}),ht&&(d[u]||(v(ee)||ve?_():In(_))),()=>{x.current=!0,O()}},[u]),Fe(()=>{let _;function T(){const O=G(o)?o(q().data):o;O&&_!==-1&&(_=setTimeout(N,O))}function N(){!q().error&&(f||L().isVisible())&&(p||L().isOnline())?he(Je).then(T):T()}return T(),()=>{_&&(clearTimeout(_),_=-1)}},[o,f,p,u]),y.useDebugValue(Oe),c){const _=u&&v(ee);if(!At&&ve&&_)throw new Error("Fallback data is required when using Suspense in SSR.");_&&(A.current=n,U.current=t,x.current=!1);const T=E[u],N=!v(T)&&_?gt(T):xt;if($e(N),!v(_e)&&_)throw _e;const O=_?he(Je):xt;!v(Oe)&&_&&(O.status="fulfilled",O.value=!0),$e(O)}return{mutate:gt,get data(){return j.data=!0,Oe},get error(){return j.error=!0,_e},get isValidating(){return j.isValidating=!0,Zt},get isLoading(){return j.isLoading=!0,en}}},Yn=Hn(zn),Xn=({fileKey:e,authToken:n,enabled:t=!0,params:s={}})=>{const{figmaRestApi:i}=Ut(),c=!!(t&&e&&n),{data:a,isLoading:l,error:r}=Yn(["useFigmaFile",e,n,s],()=>c?i.withOptions(n?{token:n}:{}).getFile({fileKey:e,depth:s.depth}):null,{revalidateIfStale:!1,revalidateOnFocus:!1,revalidateOnReconnect:!1});return{data:a!=null?a:null,isLoading:l,error:r}};exports.AnimaSdkContext=it;exports.AnimaSdkProvider=gn;exports.AttachJobError=$t;exports.CreateJobError=Pt;exports.UnknownCodegenError=Jt;exports.useAnimaCodegen=En;exports.useAnimaSDK=Ut;exports.useFigmaFile=Xn;
|
|
22
22
|
//# sourceMappingURL=index.cjs.map
|