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