@mcastiello/figmatic
Version:
1 lines • 50.2 kB
JavaScript
var e,t,n,o,r,i,a,s,l,u,c,p,f,d,h,g,y,v,x,m,S,T,A,E,k,N,D,b,F,I,L,w,C,P,O,R,M,B,G,_,V,H=require("@mcastiello/event-bus");function W(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,K(o.key),o)}}function j(e,t,n){return t&&W(e.prototype,t),n&&W(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function U(){return U=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)({}).hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},U.apply(null,arguments)}function z(e){return z=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},z(e)}function J(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,Y(e,t)}function X(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(X=function(){return!!e})()}function Z(e,t){if(null==e)return{};var n={};for(var o in e)if({}.hasOwnProperty.call(e,o)){if(-1!==t.indexOf(o))continue;n[o]=e[o]}return n}function Y(e,t){return Y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Y(e,t)}function K(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}function q(e){var t="function"==typeof Map?new Map:void 0;return q=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return function(e,t,n){if(X())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,t);var r=new(e.bind.apply(e,o));return n&&Y(r,n.prototype),r}(e,arguments,z(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),Y(n,e)},q(e)}exports.NodeType=void 0,(e=exports.NodeType||(exports.NodeType={})).BooleanOperation="BOOLEAN_OPERATION",e.Canvas="CANVAS",e.Component="COMPONENT",e.ComponentSet="COMPONENT_SET",e.Document="DOCUMENT",e.Ellipse="ELLIPSE",e.Frame="FRAME",e.Generic="NODE",e.Group="GROUP",e.Instance="INSTANCE",e.Line="LINE",e.Rectangle="RECTANGLE",e.RegularPolygon="REGULAR_POLYGON",e.Section="SECTION",e.Slice="SLICE",e.Star="STAR",e.Text="TEXT",e.Vector="VECTOR",e.WashiTape="WASHI_TAPE",exports.PropertyTypes=void 0,(exports.PropertyTypes||(exports.PropertyTypes={})).VariableAlias="VARIABLE_ALIAS",exports.ConstraintType=void 0,(t=exports.ConstraintType||(exports.ConstraintType={})).Scale="SCALE",t.Width="WIDTH",t.Height="HEIGHT",exports.PaintType=void 0,(n=exports.PaintType||(exports.PaintType={})).Solid="SOLID",n.GradientLinear="GRADIENT_LINEAR",n.GradientRadial="GRADIENT_RADIAL",n.GradientAngular="GRADIENT_ANGULAR",n.GradientDiamond="GRADIENT_DIAMOND",n.Image="IMAGE",n.Emoji="EMOJI",n.Video="VIDEO",exports.BlendMode=void 0,(o=exports.BlendMode||(exports.BlendMode={})).PassThrough="PASS_THROUGH",o.Normal="NORMAL",o.Darken="DARKEN",o.Multiply="MULTIPLY",o.LinearBurn="LINEAR_BURN",o.ColorBurn="COLOR_BURN",o.Lighten="LIGHTEN",o.Screen="SCREEN",o.LinearDodge="LINEAR_DODGE",o.ColorDodge="COLOR_DODGE",o.Overlay="OVERLAY",o.SoftLight="SOFT_LIGHT",o.HardLight="HARD_LIGHT",o.Difference="DIFFERENCE",o.Exclusion="EXCLUSION",o.Hue="HUE",o.Saturation="SATURATION",o.Color="COLOR",o.Luminosity="LUMINOSITY",exports.ScaleMode=void 0,(r=exports.ScaleMode||(exports.ScaleMode={})).Fill="FILL",r.Fit="FIT",r.Tile="TILE",r.Stretch="STRETCH",exports.StrokeAlign=void 0,(i=exports.StrokeAlign||(exports.StrokeAlign={})).Inside="INSIDE",i.Outside="OUTSIDE",i.Center="CENTER",exports.VerticalLayoutConstraint=void 0,(a=exports.VerticalLayoutConstraint||(exports.VerticalLayoutConstraint={})).Top="TOP",a.Bottom="BOTTOM",a.Center="CENTER",a.TopBottom="TOP_BOTTOM",a.Scale="SCALE",exports.HorizontalLayoutConstrain=void 0,(s=exports.HorizontalLayoutConstrain||(exports.HorizontalLayoutConstrain={})).Left="LEFT",s.Right="RIGHT",s.Center="CENTER",s.LeftRight="LEFT_RIGHT",s.Scale="SCALE",exports.LayoutAlign=void 0,(l=exports.LayoutAlign||(exports.LayoutAlign={})).Inherit="INHERIT",l.Stretch="STRETCH",l.Min="MIN",l.Center="CENTER",l.Max="MAX",exports.LayoutMode=void 0,(u=exports.LayoutMode||(exports.LayoutMode={})).None="NONE",u.Horizontal="HORIZONTAL",u.Vertical="VERTICAL",exports.LayoutSizing=void 0,(c=exports.LayoutSizing||(exports.LayoutSizing={})).Fixed="FIXED",c.Hug="HUG",c.Fill="FILL",exports.LayoutWrap=void 0,(p=exports.LayoutWrap||(exports.LayoutWrap={})).NoWrap="NO_WRAP",p.Wrap="WRAP",exports.LayoutPositioning=void 0,(f=exports.LayoutPositioning||(exports.LayoutPositioning={})).Auto="AUTO",f.Absolute="ABSOLUTE",exports.LayoutGridPattern=void 0,(d=exports.LayoutGridPattern||(exports.LayoutGridPattern={})).Columns="COLUMNS",d.Rows="ROWS",d.Grid="GRID",exports.AxisSizing=void 0,(h=exports.AxisSizing||(exports.AxisSizing={})).Fixed="FIXED",h.Auto="AUTO",exports.AxisAlign=void 0,(g=exports.AxisAlign||(exports.AxisAlign={})).Auto="AUTO",g.Min="MIN",g.Center="CENTER",g.Max="MAX",g.SpaceBetween="SPACE_BETWEEN",g.Baseline="BASELINE",exports.OverflowDirection=void 0,(y=exports.OverflowDirection||(exports.OverflowDirection={})).None="NONE",y.Horizontal="HORIZONTAL_SCROLLING",y.Vertical="VERTICAL_SCROLLING",y.Both="HORIZONTAL_AND_VERTICAL_SCROLLING",exports.EffectType=void 0,(v=exports.EffectType||(exports.EffectType={})).InnerShadow="INNER_SHADOW",v.DropShadow="DROP_SHADOW",v.LayerBlur="LAYER_BLUR",v.BackgroundBlur="BACKGROUND_BLUR",exports.MaskType=void 0,(x=exports.MaskType||(exports.MaskType={})).Alpha="ALPHA",x.Vector="VECTOR",x.Luminance="LUMINANCE",exports.StyleType=void 0,(m=exports.StyleType||(exports.StyleType={})).Fill="FILL",m.Text="TEXT",m.Effect="EFFECT",m.Grid="GRID",exports.DevStatusType=void 0,(S=exports.DevStatusType||(exports.DevStatusType={})).ReadyForDev="READY_FOR_DEV",S.Completed="COMPLETED",exports.AnnotationProperty=void 0,(T=exports.AnnotationProperty||(exports.AnnotationProperty={})).Width="width",T.Height="height",T.MaxWidth="maxWidth",T.MinWidth="minWidth",T.MaxHeight="maxHeight",T.MinHeight="minHeight",T.Fills="fills",T.Strokes="strokes",T.Effects="effects",T.StrokeWeight="strokeWeight",T.CornerRadius="cornerRadius",T.TextStyleId="textStyleId",T.TextAlignHorizontal="textAlignHorizontal",T.FontFamily="fontFamily",T.FontStyle="fontStyle",T.FontSize="fontSize",T.FontWeight="fontWeight",T.LineHeight="lineHeight",T.LetterSpacing="letterSpacing",T.ItemSpacing="itemSpacing",T.Padding="padding",T.LayoutMode="layoutMode",T.AlignItems="alignItems",T.Opacity="opacity",T.MainComponent="mainComponent",exports.StrokeCap=void 0,(A=exports.StrokeCap||(exports.StrokeCap={})).None="NONE",A.Round="ROUND",A.Square="SQUARE",A.LineArrow="LINE_ARROW",A.TriangleArrow="TRIANGLE_ARROW",A.DiamondFilled="DIAMOND_FILLED",A.CircleFilled="CIRCLE_FILLED",A.TriangleFilled="TRIANGLE_FILLED",A.WashiTape1="WASHI_TAPE_1",A.WashiTape2="WASHI_TAPE_2",A.WashiTape3="WASHI_TAPE_3",A.WashiTape4="WASHI_TAPE_4",A.WashiTape5="WASHI_TAPE_5",A.WashiTape6="WASHI_TAPE_6",exports.StrokeJoin=void 0,(E=exports.StrokeJoin||(exports.StrokeJoin={})).Bevel="BEVEL",E.Miter="MITER",E.Round="ROUND",exports.BooleanOperation=void 0,(k=exports.BooleanOperation||(exports.BooleanOperation={})).Exclude="EXCLUDE",k.Intersect="INTERSECT",k.Subtract="SUBTRACT",k.Union="UNION",exports.TextCase=void 0,(N=exports.TextCase||(exports.TextCase={})).Lower="LOWER",N.Original="ORIGINAL",N.SmallCaps="SMALL_CAPS",N.SmallCapsForced="SMALL_CAPS_FORCED",N.Title="TITLE",N.Upper="UPPER",exports.TextDecoration=void 0,(D=exports.TextDecoration||(exports.TextDecoration={})).None="NONE",D.Strikethrough="STRIKETHROUGH",D.Underline="UNDERLINE",exports.TextAutoResize=void 0,(b=exports.TextAutoResize||(exports.TextAutoResize={})).Height="HEIGHT",b.None="NONE",b.WidthHeight="WIDTH_AND_HEIGHT",exports.TextTruncation=void 0,(F=exports.TextTruncation||(exports.TextTruncation={})).Disabled="DISABLED",F.Enabled="ENABLED",exports.TextAlignHorizontal=void 0,(I=exports.TextAlignHorizontal||(exports.TextAlignHorizontal={})).Left="LEFT",I.Right="RIGHT",I.Center="CENTER",I.Justified="JUSTIFIED",exports.TextAlignVertical=void 0,(L=exports.TextAlignVertical||(exports.TextAlignVertical={})).Top="TOP",L.Center="CENTER",L.Bottom="BOTTOM",exports.HyperlinkType=void 0,(w=exports.HyperlinkType||(exports.HyperlinkType={})).Url="URL",w.Node="NODE",exports.LineHeightUnit=void 0,(C=exports.LineHeightUnit||(exports.LineHeightUnit={})).Pixels="PIXELS",C.FontSize="FONT_SIZE_%",C.Intrinsic="INTRINSIC_%",exports.FontWeight=void 0,(P=exports.FontWeight||(exports.FontWeight={})).Bold="BOLD",P.Normal="NORMAL",exports.FontStyle=void 0,(O=exports.FontStyle||(exports.FontStyle={})).Italic="ITALIC",O.Normal="NORMAL",exports.LineType=void 0,(R=exports.LineType||(exports.LineType={})).Ordered="ORDERED",R.Unordered="UNORDERED",R.None="NONE",exports.ComponentPropertyType=void 0,(M=exports.ComponentPropertyType||(exports.ComponentPropertyType={})).Boolean="BOOLEAN",M.InstanceSwap="INSTANCE_SWAP",M.Text="TEXT",M.Variant="VARIANT",exports.VariableType=void 0,(B=exports.VariableType||(exports.VariableType={})).Boolean="BOOLEAN",B.Float="FLOAT",B.String="STRING",B.Color="COLOR",exports.VariableScope=void 0,(G=exports.VariableScope||(exports.VariableScope={})).AllFills="ALL_FILLS",G.AllScopes="ALL_SCOPES",G.CornerRadius="CORNER_RADIUS",G.EffectColor="EFFECT_COLOR",G.EffectFloat="EFFECT_FLOAT",G.FontFamily="FONT_FAMILY",G.FontSize="FONT_SIZE",G.FontStyle="FONT_STYLE",G.FontWeight="FONT_WEIGHT",G.FrameFill="FRAME_FILL",G.Gap="GAP",G.LetterSpacing="LETTER_SPACING",G.LineHeight="LINE_HEIGHT",G.Opacity="OPACITY",G.ParagraphIndent="PARAGRAPH_INDENT",G.ParagraphSpacing="PARAGRAPH_SPACING",G.ShapeFill="SHAPE_FILL",G.StrokeColor="STROKE_COLOR",G.StrokeFloat="STROKE_FLOAT",G.TextContent="TEXT_CONTENT",G.TextFill="TEXT_FILL",G.WidthHeight="WIDTH_HEIGHT",exports.ExportFormat=void 0,(_=exports.ExportFormat||(exports.ExportFormat={})).JPG="jpg",_.PDF="pdf",_.PNG="png",_.SVG="svg",exports.TokenStyleTypes=void 0,(V=exports.TokenStyleTypes||(exports.TokenStyleTypes={})).Fill="fill",V.Fills="fills",V.Stroke="stroke",V.Strokes="strokes",V.Effect="effect",V.Text="text";var Q,$,ee,te=function(e){return Object.values(exports.NodeType).includes(e)},ne=function(e){return"object"==typeof e&&Object.hasOwn(e,"type")},oe=function(e){return"string"==typeof(null==e?void 0:e.type)&&te(e.type)},re=function(e,t){return"string"==typeof(null==e?void 0:e.type)&&e.type===t&&te(e.type)},ie=function(e,t){return!!e&&e.type===t},ae=function(e){return!!e&&Object.hasOwn(e,"styles")},se=function(e){return!!e&&Object.hasOwn(e,"exportSettings")};!function(e){e.Figmatic="figmatic"}(Q||(Q={})),exports.FigmaticEvents=void 0,($=exports.FigmaticEvents||(exports.FigmaticEvents={})).Message="message",$.LoadStarted="loadStarted",$.LoadCompleted="loadCompleted",$.SwitchBranchStarted="switchBranchStarted",$.SwitchBranchCompleted="switchBranchCompleted",$.BranchDownloadStarted="branchDownloadStarted",$.BranchDownloadCompleted="branchDownloadCompleted",$.BranchDownloadFailed="branchDownloadFailed",$.TokensDownloadStarted="tokensDownloadStarted",$.TokensDownloadCompleted="tokensDownloadCompleted",$.TokensDownloadFailed="tokensDownloadFailed",$.GraphicDownloadStarted="graphicDownloadStarted",$.GraphicDownloadCompleted="graphicDownloadCompleted",$.GraphicDownloadFailed="graphicDownloadFailed",$.ParseNodesStarted="parseNodesStarted",$.ParseNodesCompleted="parseNodesCompleted",$.ParseNodesFailed="parseNodesFailed",$.ParseComponentsStarted="parseComponentsStarted",$.ParseComponentsCompleted="parseComponentsCompleted",$.ParseComponentsFailed="parseComponentsFailed",$.ParseTokensStarted="parseTokensStarted",$.ParseTokensCompleted="parseTokensCompleted",$.ParseTokensFailed="parseTokensFailed",exports.FigmaticSeverity=void 0,(ee=exports.FigmaticSeverity||(exports.FigmaticSeverity={})).Debug="debug",ee.Info="info",ee.Warning="warning",ee.Error="error";var le={cacheEvents:!0,publishAsynchronously:!0},ue=new Map,ce=new Map,pe=new Map,fe=new Map,de=new Map,he=new(/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}J(t,e);var n=t.prototype;return n.getByType=function(e){return Array.from(this.values()).filter(function(t){return ie(t,e)})},n.getByName=function(e){var t=this,n=[];if(e instanceof RegExp){var o=Array.from(new Set(Array.from(ue.keys()).filter(function(t){return e.test(t)}).map(function(e){return ue.get(e)||[]}).reduce(function(e,t){return[].concat(e,t)},[])));n.push.apply(n,o)}else{var r=ue.get(e)||[];n.push.apply(n,r)}return(null==n?void 0:n.map(function(e){return t.get(e)}).filter(function(e){return!!e}))||[]},n.clear=function(){e.prototype.clear.call(this),ue.clear()},n.get=function(t){return e.prototype.get.call(this,t)},t}(/*#__PURE__*/q(Map))),ge=/*#__PURE__*/function(){return j(function(e){this.data=void 0,this.data=e},[{key:"definition",get:function(){return this.data}},{key:"variantNodes",get:function(){if(0===this.data.variants.length){var e=he.get(this.data.nodeId);return e?[e]:[]}return this.data.variants.map(function(e){return he.get(e.nodeId)}).filter(function(e){return void 0!==e})}}])}(),ye=new(/*#__PURE__*/function(){function e(){this.bus=new H.EventBus(le)}return e.prototype.log=function(e,t,n,o){void 0===t&&(t=exports.FigmaticSeverity.Info),void 0===n&&(n=Date.now()),this.channel.publish(exports.FigmaticEvents.Message,{message:e,severity:t,timestamp:n,data:o})},j(e,[{key:"channel",get:function(){return this.bus.getChannel(Q.Figmatic)}}])}());function ve(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var xe=/*#__PURE__*/function(e){function t(){for(var t,n=arguments.length,o=new Array(n),r=0;r<n;r++)o[r]=arguments[r];return(t=e.call.apply(e,[this].concat(o))||this).plugins=new Map,t}J(t,e);var n=t.prototype;return n.registerExportPlugin=function(e,t){void 0===t&&(t="default"),this.plugins.set(t,e)},n.getPlugin=function(e){return this.plugins.get(e)},n.generateExport=function(e){void 0===e&&(e="default");try{var t=this,n={},o=t.plugins.get(e),r=function(){if(o){var e=function(){return function(e,t){if("function"==typeof e[me]){var n,o,r,i=function(e){try{for(;!(n=a.next()).done;)if((e=t(n.value))&&e.then){if(!Ae(e))return void e.then(i,r||(r=Se.bind(null,o=new Te,2)));e=e.v}o?Se(o,1,e):o=e}catch(e){Se(o||(o=new Te),2,e)}},a=e[me]();if(i(),a.return){var s=function(e){try{n.done||a.return()}catch(e){}return e};if(o&&o.then)return o.then(s,function(e){throw s(e)});s()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var l=[],u=0;u<e.length;u++)l.push(e[u]);return function(e,t){var n,o,r=-1;return function i(a){try{for(;++r<e.length;)if((a=t(r))&&a.then){if(!Ae(a))return void a.then(i,o||(o=Se.bind(null,n=new Te,2)));a=a.v}n?Se(n,1,a):n=a}catch(e){Se(n||(n=new Te),2,e)}}(),n}(l,function(e){return t(l[e])})}(t.values(),function(e){var t=ve(function(){return ye.log('Export component "'+e.definition.name+'"',exports.FigmaticSeverity.Debug),Promise.resolve(o.processor.generateComponent(e)).then(function(e){n[e.name]=e.content})},function(t){ye.log('Error while exporting component "'+e.definition.name+'"',exports.FigmaticSeverity.Error,Date.now(),{error:t})});if(t&&t.then)return t.then(function(){})})},r=ve(function(){return ye.log("Export tokens",exports.FigmaticSeverity.Debug),Promise.resolve(o.processor.generateTokens()).then(function(e){n[e.name]=e.content})},function(e){ye.log("Error while generating tokens",exports.FigmaticSeverity.Error,Date.now(),{error:e})});return r&&r.then?r.then(e):e()}}();return Promise.resolve(r&&r.then?r.then(function(){return n}):n)}catch(e){return Promise.reject(e)}},t}(/*#__PURE__*/q(Map));const me="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function Se(e,t,n){if(!e.s){if(n instanceof Te){if(!n.s)return void(n.o=Se.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Se.bind(null,e,t),Se.bind(null,e,2));e.s=t,e.v=n;var o=e.o;o&&o(e)}}var Te=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var o=new e,r=this.s;if(r){var i=1&r?t:n;if(i){try{Se(o,1,i(this.v))}catch(e){Se(o,2,e)}return o}return this}return this.o=function(e){try{var r=e.v;1&e.s?Se(o,1,t?t(r):r):n?Se(o,1,n(r)):Se(o,2,r)}catch(e){Se(o,2,e)}},o},e}();function Ae(e){return e instanceof Te&&1&e.s}var Ee,ke,Ne=new xe,De=/*#__PURE__*/function(){function e(e){this.color=void 0,this.h=void 0,this.s=void 0,this.l=void 0,this.color=U({a:1},e);var t=Math.max(this.color.r,this.color.g,this.color.b),n=Math.min(this.color.r,this.color.g,this.color.b),o=0,r=0,i=(t+n)/2;if(t==n)o=r=0;else{var a=t-n;switch(r=i>.5?a/(2-t-n):a/(t+n),t){case this.color.r:o=(this.color.g-this.color.b)/a+(this.color.g<this.color.b?6:0);break;case this.color.g:o=(this.color.b-this.color.r)/a+2;break;case this.color.b:o=(this.color.r-this.color.g)/a+4}o/=6}this.h=o,this.s=r,this.l=i}return e.prototype.toString=function(e){return void 0===e&&(e=!1),e?1!==this.alpha?this.hsla:this.hsl:1!==this.alpha?this.rgba:this.hex},j(e,[{key:"red",get:function(){return Math.round(255*this.color.r)}},{key:"green",get:function(){return Math.round(255*this.color.g)}},{key:"blue",get:function(){return Math.round(255*this.color.b)}},{key:"alpha",get:function(){return this.color.a}},{key:"hue",get:function(){return this.h}},{key:"saturation",get:function(){return this.s}},{key:"lightness",get:function(){return this.s}},{key:"hsl",get:function(){return"hsl("+this.hue+", "+this.saturation+", "+this.lightness+")"}},{key:"hsla",get:function(){return"hsla("+this.hue+", "+this.saturation+", "+this.lightness+", "+this.alpha+")"}},{key:"rgb",get:function(){return"rgb("+this.red+", "+this.green+", "+this.blue+")"}},{key:"rgba",get:function(){return"rgba("+this.red+", "+this.green+", "+this.blue+", "+this.alpha+")"}},{key:"hex",get:function(){return"#"+this.red.toString(16).padStart(2,"0")+this.green.toString(16).padStart(2,"0")+this.blue.toString(16).padStart(2,"0")}}])}(),be=[exports.NodeType.BooleanOperation,exports.NodeType.Ellipse,exports.NodeType.Line,exports.NodeType.Rectangle,exports.NodeType.RegularPolygon,exports.NodeType.Slice,exports.NodeType.Star,exports.NodeType.Vector,exports.NodeType.WashiTape],Fe=((Ee={})[exports.ExportFormat.JPG]="image/jpeg",Ee[exports.ExportFormat.PNG]="image/png",Ee[exports.ExportFormat.SVG]="image/svg+xml",Ee[exports.ExportFormat.PDF]="application/pdf",Ee),Ie=((ke={})[exports.TokenStyleTypes.Fill]="fills",ke[exports.TokenStyleTypes.Fills]="fills",ke[exports.TokenStyleTypes.Stroke]="strokes",ke[exports.TokenStyleTypes.Strokes]="strokes",ke[exports.TokenStyleTypes.Text]="style",ke[exports.TokenStyleTypes.Effect]="effects",ke),Le="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function we(e,t,n){if(!e.s){if(n instanceof Ce){if(!n.s)return void(n.o=we.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(we.bind(null,e,t),we.bind(null,e,2));e.s=t,e.v=n;var o=e.o;o&&o(e)}}var Ce=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var o=new e,r=this.s;if(r){var i=1&r?t:n;if(i){try{we(o,1,i(this.v))}catch(e){we(o,2,e)}return o}return this}return this.o=function(e){try{var r=e.v;1&e.s?we(o,1,t?t(r):r):n?we(o,1,n(r)):we(o,2,r)}catch(e){we(o,2,e)}},o},e}();function Pe(e){return e instanceof Ce&&1&e.s}var Oe="https://api.figma.com/v1",Re=new(/*#__PURE__*/function(){function e(){this.token=void 0,this.fileName=void 0}var t=e.prototype;return t.setToken=function(e){this.token=e},t.getFigmaFile=function(e){try{var t=this;return Promise.resolve(function(){if(t.token)return t.fileName=e,Promise.resolve(fetch(Oe+"/files/"+t.fileName,{method:"GET",headers:{"Content-Type":"application/json","Accept-Charset":"UTF-8","X-Figma-Token":t.token}})).then(function(e){return Promise.resolve(e.json())})}())}catch(e){return Promise.reject(e)}},t.getLocalVariables=function(){try{var e=this;return Promise.resolve(function(){if(e.token)return Promise.resolve(fetch(Oe+"/files/"+e.fileName+"/variables/local",{method:"GET",headers:{"Content-Type":"application/json","Accept-Charset":"UTF-8","X-Figma-Token":e.token}})).then(function(e){return Promise.resolve(e.json())})}())}catch(e){return Promise.reject(e)}},t.getPublishedVariables=function(){try{var e=this;return Promise.resolve(function(){if(e.token)return Promise.resolve(fetch(Oe+"/files/"+e.fileName+"/variables/published",{method:"GET",headers:{"Content-Type":"application/json","Accept-Charset":"UTF-8","X-Figma-Token":e.token}})).then(function(e){return Promise.resolve(e.json())})}())}catch(e){return Promise.reject(e)}},t.calculateSize=function(e){return(e instanceof ArrayBuffer?e.byteLength:e.length)/1024},t.calculateTotalSize=function(e){var t=this;return e.reduce(function(e,n){return e+t.calculateSize(n)},0).toFixed(2)+"Kb"},t.downloadGraphicNodes=function(e,t,n){void 0===n&&(n=1);try{var o=this;void 0===t&&(t=exports.ExportFormat.SVG);var r={},i=function(){if(o.token)return Promise.resolve(fetch(Oe+"/images/"+o.fileName+"?ids="+e+"&scale="+n+"&format="+t,{method:"GET",headers:{"Content-Type":"application/json","Accept-Charset":"UTF-8","X-Figma-Token":o.token}})).then(function(e){return Promise.resolve(e.json()).then(function(e){return function(e,t){if("function"==typeof e[Le]){var n,o,r,i=function(e){try{for(;!(n=a.next()).done;)if((e=t(n.value))&&e.then){if(!Pe(e))return void e.then(i,r||(r=we.bind(null,o=new Ce,2)));e=e.v}o?we(o,1,e):o=e}catch(e){we(o||(o=new Ce),2,e)}},a=e[Le]();if(i(),a.return){var s=function(e){try{n.done||a.return()}catch(e){}return e};if(o&&o.then)return o.then(s,function(e){throw s(e)});s()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var l=[],u=0;u<e.length;u++)l.push(e[u]);return function(e,t){var n,o,r=-1;return function i(a){try{for(;++r<e.length;)if((a=t(r))&&a.then){if(!Pe(a))return void a.then(i,o||(o=we.bind(null,n=new Ce,2)));a=a.v}n?we(n,1,a):n=a}catch(e){we(n||(n=new Ce),2,e)}}(),n}(l,function(e){return t(l[e])})}(Object.entries(e.images),function(e){var n=e[0],i=e[1];ye.log("Download of file "+i,exports.FigmaticSeverity.Debug);var a=function(){if(i)return Promise.resolve(fetch(i,{method:"GET",headers:{"Content-Type":Fe[t],"Accept-Charset":"UTF-8"}})).then(function(e){return Promise.resolve(t===exports.ExportFormat.SVG?e.text():e.arrayBuffer()).then(function(e){r[n]=e,ye.log("Download completed: "+o.calculateTotalSize([r[n]]),exports.FigmaticSeverity.Debug)})})}();if(a&&a.then)return a.then(function(){})})})})}();return Promise.resolve(i&&i.then?i.then(function(){return r}):r)}catch(e){return Promise.reject(e)}},e}());function Me(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var Be=/*#__PURE__*/function(){function e(){}return e.prototype.log=function(e,t,n){void 0===t&&(t=exports.FigmaticSeverity.Info),ye.log(e,t,Date.now(),n)},e}(),Ge=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}J(t,e);var n=t.prototype;return n.getSvgData=function(e,t){void 0===t&&(t=1);try{var n=this;return Promise.resolve(Me(function(){return Promise.resolve(Re.downloadGraphicNodes([e],exports.ExportFormat.SVG,t)).then(function(e){var t=Object.values(e).shift();if("string"==typeof t)return t})},function(t){n.log('Download of graphic node "'+e+'" failed',exports.FigmaticSeverity.Error,{error:t})}))}catch(e){return Promise.reject(e)}},n.getImageData=function(e,t,n){void 0===n&&(n=1);try{var o=this;return Promise.resolve(Me(function(){return Promise.resolve(Re.downloadGraphicNodes([e],t,n)).then(function(e){var t=Object.values(e).shift();if(t instanceof ArrayBuffer)return t})},function(t){o.log('Download of graphic node "'+e+'" failed',exports.FigmaticSeverity.Error,{error:t})}))}catch(e){return Promise.reject(e)}},t}(Be),_e=/*#__PURE__*/function(){return j(function(e,t){this.data=void 0,this.childrenIds=void 0,this.data=e,this.childrenIds=t},[{key:"children",get:function(){return this.childrenIds.map(function(e){return de.get(e)}).filter(function(e){return!!e})}},{key:"name",get:function(){return this.data.styles.name}},{key:"definition",get:function(){return this.data}}])}(),Ve=/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.log=function(e,t,n){void 0===t&&(t=exports.FigmaticSeverity.Info),ye.log(e,t,Date.now(),n)},t.getParsedNode=function(e){return de.get(e)},e}(),He=new(/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}J(t,e);var n=t.prototype;return n.getByCollection=function(e){var t,n=this,o=ce.get(e);return(null==o||null==(t=o.variableIds)?void 0:t.map(function(e){return n.get(e)}).filter(function(e){return!!e}))||[]},n.getCollection=function(e){return ce.get(e)},n.getCollections=function(){return Array.from(ce.values())},n.setStyle=function(e,t){pe.set(e,t)},n.getStyle=function(e){var t=fe.get(e),n=pe.get(e);if(t&&n)return U({id:e},t,{data:n})},n.getStyles=function(){var e=this;return Array.from(fe.keys()).map(function(t){return e.getStyle(t)}).filter(function(e){return!!e})},n.getByKey=function(e){var t;if(e=(null==(t=e.split("/").shift())?void 0:t.replace("VariableID:",""))||"")return Array.from(this.values()).find(function(t){return t.key===e})},n.getModeName=function(e){var t;return null==(t=this.getCollections().reduce(function(e,t){return[].concat(e,t.modes)},[]).find(function(t){return t.modeId===e}))?void 0:t.name},n.resolveTokenVariable=function(e){var t=this,n=this.get(e)||this.getByKey(e);return n?Object.keys(n.valuesByMode).reduce(function(e,o){var r,i=n.valuesByMode[o];if(ne(i)){var a=t.resolveTokenVariable(i.id);return U({},e,Object.keys(a).reduce(function(e,t){var n;return U({},e,((n={})[t!==o?o+"+"+t:t]=null==a?void 0:a[t],n))},{}))}return U({},e,((r={})[o]="object"==typeof i?new De(i):i,r))},{}):{}},n.clear=function(){e.prototype.clear.call(this),ce.clear(),fe.clear(),pe.clear()},t}(/*#__PURE__*/q(Map))),We=["id","type","children"],je=/*#__PURE__*/function(){function e(e,t){if(this.nodeId=void 0,this.nodeType=void 0,this.data=void 0,this.childrenIds=void 0,this.parentId=void 0,oe(e)){var n=e.id,o=e.type,r=e.children,i=Z(e,We);this.nodeId=n,this.nodeType=o,this.parentId=t,this.data=U({},this.DefaultValues,i),this.childrenIds=null==r?void 0:r.map(function(e){return e.id})}}var t=e.prototype;return t.getTokens=function(e){var t;if(null!=(t=this.data)&&t.boundVariables){var n=this.data.boundVariables[e];return(Array.isArray(n)?n:n?[n]:[]).map(function(e){return He.get(e.id)}).filter(function(e){return!!e})}return[]},t.isDescendant=function(e){return!!e&&!!this.parent&&(this.parent.id===e||this.parent.isDescendant(e))},t.getNodesByType=function(e){var t=this;return he.getByType(e).filter(function(e){return e.isDescendant(t.id)})},j(e,[{key:"DefaultValues",get:function(){return{componentPropertyReferences:{},explicitVariableModes:{},rotation:0,visible:!0}}},{key:"id",get:function(){return this.nodeId}},{key:"type",get:function(){return this.nodeType}},{key:"name",get:function(){var e;return null==(e=this.data)?void 0:e.name}},{key:"definition",get:function(){return this.data}},{key:"valid",get:function(){return!!this.nodeId}},{key:"children",get:function(){var e;return(null==(e=this.childrenIds)?void 0:e.map(function(e){return he.get(e)}).filter(function(e){return!!e&&e.valid}))||[]}},{key:"parent",get:function(){return this.parentId?he.get(this.parentId):void 0}},{key:"isGraphicNode",get:function(){var e;return be.includes(this.nodeType)||se(this.data)&&(null==(e=this.data.exportSettings)?void 0:e.length)>0}},{key:"styles",get:function(){var e=U({},this.data);return ae(e)?Object.keys(e.styles).reduce(function(t,n){var o,r,i=null==(o=e.styles)?void 0:o[n],a=e[Ie[n]],s=Array.isArray(a)?a[0]:a;return i&&s?U({},t,((r={})[i]=s,r)):t},{}):{}}}])}(),Ue=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{effects:[],exportSettings:[],fills:[],isMask:!1,layoutGrow:0,locked:!1,opacity:1,preserveRatio:!1,strokeCap:exports.StrokeCap.None,strokeJoin:exports.StrokeJoin.Miter,strokeMiterAngle:28.96,strokes:[]})}}])}(je),ze=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{exportSettings:[]})}}])}(je),Je=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{annotations:[],componentPropertyDefinitions:{},counterAxisAlignContent:exports.AxisAlign.Auto,counterAxisAlignItems:exports.AxisAlign.Min,counterAxisSpacing:0,effects:[],exportSettings:[],fills:[],isMask:!1,isMaskOutline:!1,itemReverseZIndex:!1,itemSpacing:0,layoutMode:exports.LayoutMode.None,layoutPositioning:exports.LayoutPositioning.Auto,layoutWrap:exports.LayoutWrap.NoWrap,locked:!1,opacity:1,overflowDirection:exports.OverflowDirection.None,paddingBottom:0,paddingLeft:0,paddingRight:0,paddingTop:0,preserveRatio:!1,primaryAxisAlignItems:exports.AxisAlign.Min,primaryAxisSizingMode:exports.AxisSizing.Auto,strokes:[],strokesIncludedInLayout:!1,styles:{}})}}])}(je),Xe=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{annotations:[],componentPropertyDefinitions:{},counterAxisAlignContent:exports.AxisAlign.Auto,counterAxisAlignItems:exports.AxisAlign.Min,counterAxisSpacing:0,effects:[],exportSettings:[],fills:[],isMask:!1,isMaskOutline:!1,itemReverseZIndex:!1,itemSpacing:0,layoutMode:exports.LayoutMode.None,layoutPositioning:exports.LayoutPositioning.Auto,layoutWrap:exports.LayoutWrap.NoWrap,locked:!1,opacity:1,overflowDirection:exports.OverflowDirection.None,paddingBottom:0,paddingLeft:0,paddingRight:0,paddingTop:0,preserveRatio:!1,primaryAxisAlignItems:exports.AxisAlign.Min,primaryAxisSizingMode:exports.AxisSizing.Auto,strokes:[],strokesIncludedInLayout:!1,styles:{}})}}])}(je),Ze=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),t}(je),Ye=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{effects:[],exportSettings:[],fills:[],isMask:!1,layoutGrow:0,locked:!1,opacity:1,preserveRatio:!1,strokeCap:exports.StrokeCap.None,strokeJoin:exports.StrokeJoin.Miter,strokeMiterAngle:28.96,strokes:[]})}}])}(je),Ke=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{annotations:[],counterAxisAlignContent:exports.AxisAlign.Auto,counterAxisAlignItems:exports.AxisAlign.Min,counterAxisSpacing:0,effects:[],exportSettings:[],fills:[],isMask:!1,isMaskOutline:!1,itemReverseZIndex:!1,itemSpacing:0,layoutMode:exports.LayoutMode.None,layoutPositioning:exports.LayoutPositioning.Auto,layoutWrap:exports.LayoutWrap.NoWrap,locked:!1,opacity:1,overflowDirection:exports.OverflowDirection.None,paddingBottom:0,paddingLeft:0,paddingRight:0,paddingTop:0,preserveRatio:!1,primaryAxisAlignItems:exports.AxisAlign.Min,primaryAxisSizingMode:exports.AxisSizing.Auto,strokes:[],strokesIncludedInLayout:!1,styles:{}})}}])}(je),qe=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{annotations:[],counterAxisAlignContent:exports.AxisAlign.Auto,counterAxisAlignItems:exports.AxisAlign.Min,counterAxisSpacing:0,effects:[],exportSettings:[],fills:[],isMask:!1,isMaskOutline:!1,itemReverseZIndex:!1,itemSpacing:0,layoutMode:exports.LayoutMode.None,layoutPositioning:exports.LayoutPositioning.Auto,layoutWrap:exports.LayoutWrap.NoWrap,locked:!1,opacity:1,overflowDirection:exports.OverflowDirection.None,paddingBottom:0,paddingLeft:0,paddingRight:0,paddingTop:0,preserveRatio:!1,primaryAxisAlignItems:exports.AxisAlign.Min,primaryAxisSizingMode:exports.AxisSizing.Auto,strokes:[],strokesIncludedInLayout:!1,styles:{}})}}])}(je),Qe=["children"],$e=/*#__PURE__*/function(e){function t(t,n){var o,r=[];if(oe(t)){var i=t.children;t=Z(t,Qe),r=(null==i?void 0:i.map(function(e){return e.id}))||[]}return(o=e.call(this,t,n)||this).overrideIds=void 0,o.overrideIds=r,o}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{annotations:[],componentProperties:{},counterAxisAlignContent:exports.AxisAlign.Auto,counterAxisAlignItems:exports.AxisAlign.Min,counterAxisSpacing:0,effects:[],exportSettings:[],exposedInstances:[],fills:[],isExposedInstance:!1,isMask:!1,isMaskOutline:!1,itemReverseZIndex:!1,itemSpacing:0,layoutMode:exports.LayoutMode.None,layoutPositioning:exports.LayoutPositioning.Auto,layoutWrap:exports.LayoutWrap.NoWrap,locked:!1,opacity:1,overflowDirection:exports.OverflowDirection.None,overrides:[],paddingBottom:0,paddingLeft:0,paddingRight:0,paddingTop:0,preserveRatio:!1,primaryAxisAlignItems:exports.AxisAlign.Min,primaryAxisSizingMode:exports.AxisSizing.Auto,strokes:[],strokesIncludedInLayout:!1,styles:{}})}},{key:"overrides",get:function(){var e;return null==(e=this.overrideIds)?void 0:e.map(function(e){return he.get(e)}).filter(function(e){return!!e&&e.valid})}},{key:"component",get:function(){var e;return null!=(e=this.data)&&e.componentId?he.get(this.data.componentId):void 0}}])}(je),et=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{effects:[],exportSettings:[],fills:[],isMask:!1,layoutGrow:0,locked:!1,opacity:1,preserveRatio:!1,strokeCap:exports.StrokeCap.None,strokeJoin:exports.StrokeJoin.Miter,strokeMiterAngle:28.96,strokes:[]})}}])}(je),tt=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{effects:[],exportSettings:[],fills:[],isMask:!1,layoutGrow:0,locked:!1,opacity:1,preserveRatio:!1,strokeCap:exports.StrokeCap.None,strokeJoin:exports.StrokeJoin.Miter,strokeMiterAngle:28.96,strokes:[]})}}])}(je),nt=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{effects:[],exportSettings:[],fills:[],isMask:!1,layoutGrow:0,locked:!1,opacity:1,preserveRatio:!1,strokeCap:exports.StrokeCap.None,strokeJoin:exports.StrokeJoin.Miter,strokeMiterAngle:28.96,strokes:[]})}}])}(je),ot=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{fills:[],strokes:[]})}}])}(je),rt=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{effects:[],exportSettings:[],fills:[],isMask:!1,layoutGrow:0,locked:!1,opacity:1,preserveRatio:!1,strokeCap:exports.StrokeCap.None,strokeJoin:exports.StrokeJoin.Miter,strokeMiterAngle:28.96,strokes:[]})}}])}(je),it=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{locked:!1,exportSettings:[],preserveRatio:!1,layoutGrow:0,opacity:1,fills:[],strokes:[],effects:[],isMask:!1,strokeCap:exports.StrokeCap.None,strokeJoin:exports.StrokeJoin.Miter,strokeMiterAngle:28.96})}},{key:"content",get:function(){var e;return(null==(e=this.data)?void 0:e.characters)||""}}])}(je),at=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{locked:!1,exportSettings:[],preserveRatio:!1,layoutGrow:0,opacity:1,fills:[],strokes:[],effects:[],isMask:!1,strokeCap:exports.StrokeCap.None,strokeJoin:exports.StrokeJoin.Miter,strokeMiterAngle:28.96})}}])}(je),st=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}return J(t,e),j(t,[{key:"DefaultValues",get:function(){return U({},e.prototype.DefaultValues,{effects:[],exportSettings:[],fills:[],isMask:!1,layoutGrow:0,locked:!1,opacity:1,preserveRatio:!1,strokeCap:exports.StrokeCap.None,strokeJoin:exports.StrokeJoin.Miter,strokeMiterAngle:28.96,strokes:[]})}}])}(je),lt="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function ut(e,t,n){if(!e.s){if(n instanceof ct){if(!n.s)return void(n.o=ut.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(ut.bind(null,e,t),ut.bind(null,e,2));e.s=t,e.v=n;var o=e.o;o&&o(e)}}var ct=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var o=new e,r=this.s;if(r){var i=1&r?t:n;if(i){try{ut(o,1,i(this.v))}catch(e){ut(o,2,e)}return o}return this}return this.o=function(e){try{var r=e.v;1&e.s?ut(o,1,t?t(r):r):n?ut(o,1,n(r)):ut(o,2,r)}catch(e){ut(o,2,e)}},o},e}();function pt(e){return e instanceof ct&&1&e.s}var ft=new(/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.parseComponents=function(e,t,n){void 0===t&&(t={}),void 0===n&&(n={});var o=Object.keys(n).filter(function(e){return!n[e].componentSetId}).map(function(t){return{nodeId:t,name:n[t].name,description:n[t].description,variants:[],fileName:e}}),r=Object.keys(t).map(function(o){var r=Object.keys(n).filter(function(e){return n[e].componentSetId===o}).map(function(e){return{nodeId:e,name:n[e].name,description:n[e].description}});return{nodeId:o,name:t[o].name,description:t[o].description,variants:r,fileName:e}});[].concat(o,r).forEach(function(e){var t=new ge(e);Ne.set(e.nodeId,t),e.variants.forEach(function(e){return Ne.set(e.nodeId,t)})})},t.parseNodes=function(e,t,n){var o,r=this;if(re(e,exports.NodeType.BooleanOperation)&&(o=new Ue(e,n)),re(e,exports.NodeType.Canvas)&&(!oe(e)||t&&0!==t.length&&!t.some(function(t){return t instanceof RegExp?t.test(e.name):t.toLowerCase()===e.name.toLowerCase()})||(o=new ze(e,n))),re(e,exports.NodeType.ComponentSet)&&(o=new Xe(e,n)),re(e,exports.NodeType.Component)&&(o=new Je(e,n)),re(e,exports.NodeType.Document)&&(o=new Ze(e,n)),re(e,exports.NodeType.Ellipse)&&(o=new Ye(e,n)),re(e,exports.NodeType.Frame)&&(o=new Ke(e,n)),re(e,exports.NodeType.Group)&&(o=new qe(e,n)),re(e,exports.NodeType.Instance)&&(o=new $e(e,n)),re(e,exports.NodeType.Line)&&(o=new et(e,n)),re(e,exports.NodeType.Rectangle)&&(o=new tt(e,n)),re(e,exports.NodeType.RegularPolygon)&&(o=new nt(e,n)),re(e,exports.NodeType.Section)&&(o=new ot(e,n)),re(e,exports.NodeType.Star)&&(o=new rt(e,n)),re(e,exports.NodeType.Text)&&(o=new it(e,n)),re(e,exports.NodeType.Vector)&&(o=new at(e,n)),re(e,exports.NodeType.WashiTape)&&(o=new st(e,n)),o&&o.id){var i,a=o.id;if(he.set(a,o),o.name){var s=ue.get(o.name)||[];ue.set(o.name,[].concat(s,[a]))}Object.entries(o.styles).map(function(e){He.setStyle(e[0],e[1])}),oe(e)&&(null==(i=e.children)||i.forEach(function(e){return r.parseNodes(e,t,a)}))}},t.parseTokens=function(e,t){void 0===t&&(t={}),null!=e&&e.meta&&(Object.values(e.meta.variables).forEach(function(e){He.set(e.id,e)}),Object.values(e.meta.variableCollections).forEach(function(e){ce.set(e.id,e)}),Object.entries(t).forEach(function(e){fe.set(e[0],e[1])}))},t.generateParsedNodes=function(e){try{return Promise.resolve(function(e,t){if("function"==typeof e[lt]){var n,o,r,i=e[lt]();if(function e(a){try{for(;!(n=i.next()).done;)if((a=t(n.value))&&a.then){if(!pt(a))return void a.then(e,r||(r=ut.bind(null,o=new ct,2)));a=a.v}o?ut(o,1,a):o=a}catch(e){ut(o||(o=new ct),2,e)}}(),i.return){var a=function(e){try{n.done||i.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],l=0;l<e.length;l++)s.push(e[l]);return function(e,t){var n,o,r=-1;return function i(a){try{for(;++r<e.length;)if((a=t(r))&&a.then){if(!pt(a))return void a.then(i,o||(o=ut.bind(null,n=new ct,2)));a=a.v}n?ut(n,1,a):n=a}catch(e){ut(n||(n=new ct),2,e)}}(),n}(s,function(e){return t(s[e])})}(he.values(),function(t){var n=t.type,o=t.id,r=function(){if(n&&o&&ie(t,n)){var r=function(){if(t.isGraphicNode&&e.graphicParser){var r=function(n){if(null==(n=t.parent)||!n.isGraphicNode)return Promise.resolve(e.graphicParser.parse(t)).then(function(e){de.set(o,new _e(e,[]))})}();if(r&&r.then)return r.then(function(){})}else{var i=e.parsers[n],a=function(){if(i)return Promise.resolve(i.parse(t)).then(function(e){var n=t.children.map(function(e){return e.id}).filter(function(e){return!!e})||[],r=new _e(e,n);de.set(o,r)})}();if(a&&a.then)return a.then(function(){})}}();if(r&&r.then)return r.then(function(){})}}();if(r&&r.then)return r.then(function(){})}))}catch(e){return Promise.reject(e)}},e}());function dt(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var ht=new(/*#__PURE__*/function(){function e(){this.file=void 0,this.branch=void 0,this.pageFilters=void 0,this.data=new Map,this.variables=new Map}var t=e.prototype;return t.getDuration=function(e,t){var n=t-e;return Math.floor(n/1e3/60).toString().padStart(2,"0")+":"+Math.floor(n/1e3%60).toString().padStart(2,"0")+"."+Math.floor(n%1e3).toString().padStart(3,"0")},t.subscribe=function(e,t,n){return ye.channel.subscribe(e,t,n)},t.load=function(e,t,n){try{var o=function(){r.parseFigmaFile();var e=Date.now();ye.channel.publish(exports.FigmaticEvents.LoadCompleted),ye.log("Loading completed:\n\t- Duration: "+r.getDuration(i,e),exports.FigmaticSeverity.Info,e)},r=this;r.file=e,r.branch=void 0,r.pageFilters=n,Re.setToken(t);var i=Date.now();ye.channel.publish(exports.FigmaticEvents.LoadStarted),ye.log('Load Figma file "'+e+'" started',exports.FigmaticSeverity.Info,i);var a=function(){if(!r.data.get(e))return Promise.resolve(r.downloadSelectedBranch()).then(function(){})}();return Promise.resolve(a&&a.then?a.then(o):o())}catch(e){return Promise.reject(e)}},t.downloadBranch=function(e){try{var t=function(t){var o=dt(function(){return ye.channel.publish(exports.FigmaticEvents.TokensDownloadStarted,{branch:e}),ye.log('Download of tokens for "'+e+'" started',exports.FigmaticSeverity.Debug),Promise.resolve(Re.getLocalVariables()).then(function(t){return Promise.resolve(Re.getPublishedVariables()).then(function(o){var r,i,a,s;n.variables.set(e,{meta:{variables:U({},null==o||null==(r=o.meta)?void 0:r.variables,null==t||null==(i=t.meta)?void 0:i.variables),variableCollections:U({},null==o||null==(a=o.meta)?void 0:a.variableCollections,null==t||null==(s=t.meta)?void 0:s.variableCollections)}}),ye.channel.publish(exports.FigmaticEvents.TokensDownloadCompleted,{branch:e}),ye.log('Download of tokens for branch "'+e+'" completed',exports.FigmaticSeverity.Debug)})})},function(t){ye.channel.publish(exports.FigmaticEvents.TokensDownloadFailed,t),ye.log('Download of tokens for branch "'+e+'" failed',exports.FigmaticSeverity.Error,Date.now(),{error:t})});if(o&&o.then)return o.then(function(){})},n=this,o=dt(function(){return ye.channel.publish(exports.FigmaticEvents.BranchDownloadStarted,{branch:e}),ye.log('Download of branch "'+e+'" started',exports.FigmaticSeverity.Debug),Promise.resolve(Re.getFigmaFile(e)).then(function(t){if(!t)throw new Error("File not downloaded");n.data.set(e,t),ye.channel.publish(exports.FigmaticEvents.BranchDownloadCompleted,{branch:e}),ye.log('Download of branch "'+e+'" completed',exports.FigmaticSeverity.Debug)})},function(t){ye.channel.publish(exports.FigmaticEvents.BranchDownloadFailed,t),ye.log('Download of branch "'+e+'" failed',exports.FigmaticSeverity.Error,Date.now(),{error:t})});return Promise.resolve(o&&o.then?o.then(t):t())}catch(e){return Promise.reject(e)}},t.downloadSelectedBranch=function(){try{var e=this;return e.selectedBranch?Promise.resolve(e.downloadBranch(e.selectedBranch)):Promise.resolve()}catch(e){return Promise.reject(e)}},t.parseFigmaFile=function(){if(this.selectedBranch){var e=this.data.get(this.selectedBranch),t=this.variables.get(this.selectedBranch);if(e){try{var n=Date.now();ye.channel.publish(exports.FigmaticEvents.ParseNodesStarted),ye.log('Parsing of nodes for "'+this.selectedBranch+'" started',exports.FigmaticSeverity.Debug,n,{filters:this.pageFilters}),ft.parseNodes(e.document,this.pageFilters);var o=Date.now();ye.channel.publish(exports.FigmaticEvents.ParseNodesCompleted),ye.log('Parsing of nodes for "'+this.selectedBranch+'" completed:\n\t- Total nodes: '+he.size+"\n\t- Pages: "+he.getByType(exports.NodeType.Canvas).length+"\n\t- Duration: "+this.getDuration(n,o),exports.FigmaticSeverity.Info,o,{filters:this.pageFilters})}catch(e){ye.channel.publish(exports.FigmaticEvents.ParseNodesFailed,e),ye.log('Parsing of nodes for branch "'+this.selectedBranch+'" failed',exports.FigmaticSeverity.Error,Date.now(),{error:e})}try{ye.channel.publish(exports.FigmaticEvents.ParseComponentsStarted),ye.log('Parsing of components for "'+this.selectedBranch+'" started',exports.FigmaticSeverity.Debug),ft.parseComponents(this.selectedBranch,e.componentSets,e.components),ye.channel.publish(exports.FigmaticEvents.ParseComponentsCompleted),ye.log('Parsing of components for "'+this.selectedBranch+'" completed:\n\t- Total components: '+Ne.size)}catch(e){ye.channel.publish(exports.FigmaticEvents.ParseComponentsFailed,e),ye.log('Parsing of components for branch "'+this.selectedBranch+'" failed',exports.FigmaticSeverity.Error,Date.now(),{error:e})}try{ye.channel.publish(exports.FigmaticEvents.ParseTokensStarted),ye.log('Parsing of tokens for "'+this.selectedBranch+'" started',exports.FigmaticSeverity.Debug),t&&ft.parseTokens(t,e.styles),ye.channel.publish(exports.FigmaticEvents.ParseTokensCompleted),ye.log('Parsing of tokens for "'+this.selectedBranch+'" completed:\n\t- Total tokens: '+He.size+"\n\t- Collections: "+He.getCollections().length+"\n\t- Styles: "+He.getStyles().length,exports.FigmaticSeverity.Info)}catch(e){ye.channel.publish(exports.FigmaticEvents.ParseTokensFailed,e),ye.log('Parsing of tokens for branch "'+this.selectedBranch+'" failed',exports.FigmaticSeverity.Error,Date.now(),{error:e})}}}},t.clear=function(){he.clear(),Ne.clear(),He.clear()},t.downloadGraphics=function(e,t,n){void 0===n&&(n=1);try{var o,r=function(e){return o?e:{}},i=this;void 0===t&&(t=exports.ExportFormat.SVG);var a=function(){if(i.selectedBranch)return dt(function(){var r=Date.now(),a=e.map(function(e){return e.name||e.id}).filter(function(e){return!!e});ye.channel.publish(exports.FigmaticEvents.GraphicDownloadStarted,{nodes:a,format:t,scale:n}),ye.log("Download of graphic elements started",exports.FigmaticSeverity.Info,r);var s=e.map(function(e){return e.id}).filter(function(e){return!!e});return Promise.resolve(Re.downloadGraphicNodes(s,t,n)).then(function(e){var s=Date.now();return ye.channel.publish(exports.FigmaticEvents.GraphicDownloadCompleted,{nodes:a,format:t,scale:n}),ye.log("Download of graphic elements completed:\n\t- Total downloads: "+Object.keys(e).length+"\n\t- Duration: "+i.getDuration(r,s)+"\n\t- Total Size: "+Re.calculateTotalSize(Object.values(e)),exports.FigmaticSeverity.Info,r),o=1,e})},function(e){ye.channel.publish(exports.FigmaticEvents.GraphicDownloadFailed,e),ye.log("Download of graphic elements failed",exports.FigmaticSeverity.Error,Date.now(),{error:e})})}();return Promise.resolve(a&&a.then?a.then(r):r(a))}catch(e){return Promise.reject(e)}},t.selectBranch=function(e){try{var t=this,n=function(){if(e!==t.branch&&t.file){if(e){var n=t.data.get(t.file);null!=n&&n.branches.map(function(e){return e.name}).includes(e)&&(t.branch=e)}else t.branch=void 0;var o=function(){if(t.selectedBranch&&!t.data.get(t.selectedBranch)){var e=Date.now();return ye.channel.publish(exports.FigmaticEvents.SwitchBranchStarted,{branch:t.selectedBranch}),ye.log('Switch to branch "'+t.selectedBranch+'" started',exports.FigmaticSeverity.Info,e),Promise.resolve(t.downloadSelectedBranch()).then(function(){t.parseFigmaFile();var n=Date.now();ye.channel.publish(exports.FigmaticEvents.SwitchBranchCompleted,{branch:t.selectedBranch}),ye.log('Switch to branch "'+t.selectedBranch+'" completed: '+t.getDuration(e,n),exports.FigmaticSeverity.Info,n)})}}();if(o&&o.then)return o.then(function(){})}}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},t.registerExportPlugin=function(e,t){void 0===t&&(t="default"),Ne.registerExportPlugin(e,t)},t.generateExport=function(e){void 0===e&&(e="default");try{var t,n=function(e){return t?e:{}},o=this,r=Ne.getPlugin(e),i=function(){if(r&&o.selectedBranch){var n=Date.now();return ye.log("Start parsing nodes",exports.FigmaticSeverity.Info,n),Promise.resolve(ft.generateParsedNodes(r)).then(function(){var r=Date.now();return ye.log("Parsing of nodes completed\n\t- Total nodes parsed: "+de.size+"\n\t- Duration: "+o.getDuration(n,r),exports.FigmaticSeverity.Info,r),ye.log("Start generating exported files",exports.FigmaticSeverity.Info,r),Promise.resolve(Ne.generateExport(e)).then(function(e){var n=Date.now();return ye.log("Export completed\n\t- Total files generated: "+Object.values(e).length+"\n\t- Duration: "+o.getDuration(r,n),exports.FigmaticSeverity.Info,n),t=1,e})})}}();return Promise.resolve(i&&i.then?i.then(n):n(i))}catch(e){return Promise.reject(e)}},j(e,[{key:"selectedBranch",get:function(){return this.branch||this.file}}])}());exports.Figmatic=ht,exports.GraphicParser=Ge,exports.NodesCollection=he,exports.Parser=Be,exports.Processor=Ve,exports.TokensCollection=He,exports.