-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdefinitions.swift
552 lines (504 loc) · 20 KB
/
definitions.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
/*
Generated by typeshare 1.5.0
*/
import Foundation
/// [Figma documentation](https://www.figma.com/developers/api#color-type)
public struct Color: Codable {
public let r: Double
public let g: Double
public let b: Double
public let a: Double
public init(r: Double, g: Double, b: Double, a: Double) {
self.r = r
self.g = g
self.b = b
self.a = a
}
}
/// [Figma documentation](https://www.figma.com/developers/api#component-type)
public struct Component: Codable {
public let key: String
public let name: String
public let description: String
public init(key: String, name: String, description: String) {
self.key = key
self.name = name
self.description = description
}
}
public enum EffectType: String, Codable {
case innerShadow = "INNER_SHADOW"
case dropShadow = "DROP_SHADOW"
case layerBlur = "LAYER_BLUR"
case backgroundBlur = "BACKGROUND_BLUR"
}
/// [Figma documentation](https://www.figma.com/developers/api#vector-type)
public struct Vector: Codable {
public let x: Double
public let y: Double
public init(x: Double, y: Double) {
self.x = x
self.y = y
}
}
/// A visual effect such as a shadow or blur
///
/// [Figma documentation](https://www.figma.com/developers/api#effect-type)
public struct Effect: Codable {
/// Type of effect
public let type: EffectType
/// Is the effect active?
public let visible: Bool
/// The color of the shadow
public let color: Color?
/// How far the shadow is projected in the x and y directions
public let offset: Vector?
/// How far the shadow spreads
public let spread: Double?
public init(type: EffectType, visible: Bool, color: Color?, offset: Vector?, spread: Double?) {
self.type = type
self.visible = visible
self.color = color
self.offset = offset
self.spread = spread
}
}
/// Node type indicates what kind of node you are working with: for example, a FRAME node versus a RECTANGLE node. A node can have additional properties associated with it depending on its node type.
public enum NodeType: String, Codable {
case document = "DOCUMENT"
case canvas = "CANVAS"
case frame = "FRAME"
case group = "GROUP"
case vector = "VECTOR"
case booleanOperation = "BOOLEAN_OPERATION"
case star = "STAR"
case line = "LINE"
case ellipse = "ELLIPSE"
case regularPolygon = "REGULAR_POLYGON"
case rectangle = "RECTANGLE"
case text = "TEXT"
case slice = "SLICE"
case component = "COMPONENT"
case componentSet = "COMPONENT_SET"
case instance = "INSTANCE"
case sticky = "STICKY"
case shapeWithText = "SHAPE_WITH_TEXT"
case connector = "CONNECTOR"
case section = "SECTION"
}
public enum PaintType: String, Codable {
case solid = "SOLID"
case gradientLinear = "GRADIENT_LINEAR"
case gradientRadial = "GRADIENT_RADIAL"
case gradientAngular = "GRADIENT_ANGULAR"
case gradientDiamond = "GRADIENT_DIAMOND"
case image = "IMAGE"
}
/// how layer blends with layers below
///
/// [Figma documentation](https://www.figma.com/developers/api#blendmode-type)
public enum BlendMode: String, Codable {
case passThrough = "PASS_THROUGH"
case normal = "NORMAL"
case darken = "DARKEN"
case multiply = "MULTIPLY"
case linearBurn = "LINEAR_BURN"
case colorBurn = "COLOR_BURN"
case lighten = "LIGHTEN"
case screen = "SCREEN"
case linearDodge = "LINEAR_DODGE"
case colorDodge = "COLOR_DODGE"
case overlay = "OVERLAY"
case softLight = "SOFT_LIGHT"
case hardLight = "HARD_LIGHT"
case difference = "DIFFERENCE"
case exclusion = "EXCLUSION"
case hue = "HUE"
case saturation = "SATURATION"
case color = "COLOR"
case luminosity = "LUMINOSITY"
}
/// A solid color, gradient, or image texture that can be applied as fills or strokes
///
/// [Figma documentation](https://www.figma.com/developers/api#paint-type)
public struct Paint: Codable {
public let type: PaintType
/// Is the paint enabled?
public let visible: Bool?
/// Overall opacity of paint (colors within the paint can also have opacity values which would blend with this)
public let opacity: Double?
/// Solid color of the paint
public let color: Color?
/// How this node blends with nodes behind it in the scene
public let blend_mode: BlendMode?
/// This field contains three vectors, each of which are a position in normalized object space (normalized object space is if the top left corner of the bounding box of the object is (0, 0) and the bottom right is (1,1)). The first position corresponds to the start of the gradient (value 0 for the purposes of calculating gradient stops), the second position is the end of the gradient (value 1), and the third handle position determines the width of the gradient. See image examples below:
public let gradient_handle_positions: [Vector]?
public init(type: PaintType, visible: Bool?, opacity: Double?, color: Color?, blend_mode: BlendMode?, gradient_handle_positions: [Vector]?) {
self.type = type
self.visible = visible
self.opacity = opacity
self.color = color
self.blend_mode = blend_mode
self.gradient_handle_positions = gradient_handle_positions
}
}
/// Individual stroke weights
public struct StrokeWeights: Codable {
/// The top stroke weight
public let top: Double
/// The right stroke weight
public let right: Double
/// The bottom stroke weight
public let bottom: Double
/// The left stroke weight
public let left: Double
public init(top: Double, right: Double, bottom: Double, left: Double) {
self.top = top
self.right = right
self.bottom = bottom
self.left = left
}
}
public enum StrokeAlign: String, Codable {
/// stroke drawn inside the shape boundary
case inside = "INSIDE"
/// stroke drawn outside the shape boundary
case outside = "OUTSIDE"
/// stroke drawn centered along the shape boundary
case center = "CENTER"
}
/// Animation easing curves
///
/// [Figma documentation](https://www.figma.com/developers/api#easingtype-type)
public enum EasingType: String, Codable {
/// Ease in with an animation curve similar to CSS ease-in
case easeIn = "EASE_IN"
/// Ease out with an animation curve similar to CSS ease-out
case easeOut = "EASE_OUT"
/// Ease in and then out with an animation curve similar to CSS ease-in-out
case easeInAndOut = "EASE_IN_AND_OUT"
/// No easing, similar to CSS linear
case linear = "LINEAR"
case easeInBack = "EASE_IN_BACK"
case easeOutBack = "EASE_OUT_BACK"
case easeInAndOutBack = "EASE_IN_AND_OUT_BACK"
case customBezier = "CUSTOM_BEZIER"
case gentle = "GENTLE"
case quick = "QUICK"
case bouncy = "BOUNCY"
case slow = "SLOW"
case customSpring = "CUSTOM_SPRING"
}
/// [Figma documentation](https://www.figma.com/developers/api#rectangle-type)
public struct Rectangle: Codable {
public let x: Double?
public let y: Double?
public let width: Double?
public let height: Double?
public init(x: Double?, y: Double?, width: Double?, height: Double?) {
self.x = x
self.y = y
self.width = width
self.height = height
}
}
public enum AxisSizingMode: String, Codable {
case fixed = "FIXED"
case auto = "AUTO"
}
public enum PrimaryAxisAlignItems: String, Codable {
case min = "MIN"
case center = "CENTER"
case max = "MAX"
case spaceBetween = "SPACE_BETWEEN"
}
public enum CounterAxisAlignItems: String, Codable {
case min = "MIN"
case center = "CENTER"
case max = "MAX"
case baseline = "BASELINE"
}
public enum LayoutPositioning: String, Codable {
case absolute = "ABSOLUTE"
}
public enum LayoutMode: String, Codable {
case none = "NONE"
case horizontal = "HORIZONTAL"
case vertical = "VERTICAL"
}
public struct Styles: Codable {
public let fill: String?
public let text: String?
public let stroke: String?
public let effect: String?
public init(fill: String?, text: String?, stroke: String?, effect: String?) {
self.fill = fill
self.text = text
self.stroke = stroke
self.effect = effect
}
}
public enum TextCase: String, Codable {
case upper = "UPPER"
case lower = "LOWER"
case title = "TITLE"
case smallCaps = "SMALL_CAPS"
case smallCapsForced = "SMALL_CAPS_FORCED"
}
public enum TextDecoration: String, Codable {
case strikethrough = "STRIKETHROUGH"
case underline = "UNDERLINE"
}
public enum TextAutoResize: String, Codable {
case height = "HEIGHT"
case widthAndHeight = "WIDTH_AND_HEIGHT"
/// The text will be shortened and trailing text will be replaced with "…" if the text contents is larger than the bounds
case truncate = "TRUNCATE"
}
/// Type of hyperlink
public enum HyperlinkType: String, Codable {
case url = "URL"
case node = "NODE"
}
public struct Hyperlink: Codable {
public let type: HyperlinkType?
/// URL being linked to, if URL type
public let url: String?
/// ID of frame hyperlink points to, if NODE type
public let nodeId: String?
public init(type: HyperlinkType?, url: String?, nodeId: String?) {
self.type = type
self.url = url
self.nodeId = nodeId
}
}
/// Metadata for character formatting
///
/// [Figma documentation](https://www.figma.com/developers/api#typestyle-type)
public struct TypeStyle: Codable {
/// Font family of text (standard name)
public let fontFamily: String
/// Space between paragraphs in px, 0 if not present
public let paragraphSpacing: Double?
/// Whether or not text is italicized
public let italic: Bool?
/// Numeric font weight
public let fontWeight: Double
/// Font size in px
public let fontSize: Double
/// Text casing applied to the node, default is the original casing
public let textCase: TextCase?
/// Text decoration applied to the node, default is none
public let textDecoration: TextDecoration?
/// Dimensions along which text will auto resize, default is that the text does not auto-resize
public let textAutoResize: TextAutoResize?
/// Link to a URL or frame
public let hyperlink: Hyperlink?
/// Line height in px
public let lineHeightPx: Double
public init(fontFamily: String, paragraphSpacing: Double?, italic: Bool?, fontWeight: Double, fontSize: Double, textCase: TextCase?, textDecoration: TextDecoration?, textAutoResize: TextAutoResize?, hyperlink: Hyperlink?, lineHeightPx: Double) {
self.fontFamily = fontFamily
self.paragraphSpacing = paragraphSpacing
self.italic = italic
self.fontWeight = fontWeight
self.fontSize = fontSize
self.textCase = textCase
self.textDecoration = textDecoration
self.textAutoResize = textAutoResize
self.hyperlink = hyperlink
self.lineHeightPx = lineHeightPx
}
}
public enum LayoutConstraintVertical: String, Codable {
/// Node is laid out relative to top of the containing frame
case top = "TOP"
/// Node is laid out relative to bottom of the containing frame
case bottom = "BOTTOM"
/// Node is vertically centered relative to containing frame
case center = "CENTER"
/// Both top and bottom of node are constrained relative to containing frame (node stretches with frame)
case topBottom = "TOP_BOTTOM"
/// Node scales vertically with containing frame
case scale = "SCALE"
}
public enum LayoutConstraintHorizontal: String, Codable {
/// Node is laid out relative to left of the containing frame
case left = "LEFT"
/// Node is laid out relative to right of the containing frame
case right = "RIGHT"
/// Node is horizontally centered relative to containing frame
case center = "CENTER"
/// Both left and right of node are constrained relative to containing frame (node stretches with frame)
case leftRight = "LEFT_RIGHT"
/// Node scales horizontally with containing frame
case scale = "SCALE"
}
/// Layout constraint relative to containing Frame
public struct LayoutConstraint: Codable {
public let vertical: LayoutConstraintVertical
public let horizontal: LayoutConstraintHorizontal
public init(vertical: LayoutConstraintVertical, horizontal: LayoutConstraintHorizontal) {
self.vertical = vertical
self.horizontal = horizontal
}
}
public enum LayoutAlign: String, Codable {
case inherit = "INHERIT"
case stretch = "STRETCH"
case min = "MIN"
case center = "CENTER"
case max = "MAX"
}
/// [Figma documentation](https://www.figma.com/developers/api#node-types)
public struct Node: Codable {
/// A string uniquely identifying this node within the document.
public let id: String
/// The name given to the node by the user in the tool.
public let name: String
/// Whether or not the node is visible on the canvas.
public let visible: Bool?
/// The type of the node
public let type: NodeType
/// An array of nodes that are direct children of this node
public let children: [Node]?
/// Background color of the canvas
public let backgroundColor: Color?
/// An array of fill paints applied to the node
public let fills: [Paint]?
/// An array of stroke paints applied to the node
public let strokes: [Paint]?
/// The weight of strokes on the node
public let strokeWeight: Double?
/// An object including the top, bottom, left, and right stroke weights. Only returned if individual stroke weights are used.
public let individualStrokeWeights: StrokeWeights?
/// Position of stroke relative to vector outline
public let strokeAlign: StrokeAlign?
/// An array of floating point numbers describing the pattern of dash length and gap lengths that the vector path follows. For example a value of [1, 2] indicates that the path has a dash of length 1 followed by a gap of length 2, repeated.
public let strokeDashes: [Double]?
/// Radius of each corner of the node if a single radius is set for all corners
public let cornerRadius: Double?
/// Array of length 4 of the radius of each corner of the node, starting in the top left and proceeding clockwise
public let rectangleCornerRadii: [Double]?
/// The duration of the prototyping transition on this node (in milliseconds)
public let transitionDuration: Double?
/// The easing curve used in the prototyping transition on this node
public let transitionEasing: EasingType?
/// Opacity of the node
public let opacity: Double?
/// Bounding box of the node in absolute space coordinates
public let absoluteBoundingBox: Rectangle?
/// The bounds of the rendered node in the file in absolute space coordinates
public let absoluteRenderBounds: Rectangle?
/// Whether the primary axis has a fixed length (determined by the user) or an automatic length (determined by the layout engine). This property is only applicable for auto-layout frames.
public let primaryAxisSizingMode: AxisSizingMode?
/// Whether the counter axis has a fixed length (determined by the user) or an automatic length (determined by the layout engine). This property is only applicable for auto-layout frames.
public let counterAxisSizingMode: AxisSizingMode?
/// Determines how the auto-layout frame’s children should be aligned in the primary axis direction. This property is only applicable for auto-layout frames.
public let primaryAxisAlignItems: PrimaryAxisAlignItems?
/// Determines how the auto-layout frame’s children should be aligned in the counter axis direction. This property is only applicable for auto-layout frames.
public let counterAxisAlignItems: CounterAxisAlignItems?
/// The distance between children of the frame. Can be negative. This property is only applicable for auto-layout frames.
public let itemSpacing: Double?
/// Determines whether a layer's size and position should be determined by auto-layout settings or manually adjustable.
public let layoutPositioning: LayoutPositioning?
/// Whether this layer uses auto-layout to position its children.
public let layoutMode: LayoutMode?
/// The padding between the left border of the frame and its children. This property is only applicable for auto-layout frames.
public let paddingLeft: Double?
/// The padding between the right border of the frame and its children. This property is only applicable for auto-layout frames.
public let paddingRight: Double?
/// The padding between the top border of the frame and its children. This property is only applicable for auto-layout frames.
public let paddingTop: Double?
/// The padding between the bottom border of the frame and its children. This property is only applicable for auto-layout frames.
public let paddingBottom: Double?
/// An array of effects attached to this node
public let effects: [Effect]?
/// A mapping of a StyleType to style ID of styles present on this node. The style ID can be used to look up more information about the style in the top-level styles field.
public let styles: Styles?
/// Text contained within a text box
public let characters: String?
/// Style of text including font family and weight
public let style: TypeStyle?
/// Horizontal and vertical layout contraints for node
public let constraints: LayoutConstraint?
/// Determines if the layer should stretch along the parent’s counter axis. This property is only provided for direct children of auto-layout frames.
public let layoutAlign: LayoutAlign?
/// This property is applicable only for direct children of auto-layout frames, ignored otherwise. Determines whether a layer should stretch along the parent’s primary axis. A 0 corresponds to a fixed size and 1 corresponds to stretch
public let layoutGrow: Double?
public init(id: String, name: String, visible: Bool?, type: NodeType, children: [Node]?, backgroundColor: Color?, fills: [Paint]?, strokes: [Paint]?, strokeWeight: Double?, individualStrokeWeights: StrokeWeights?, strokeAlign: StrokeAlign?, strokeDashes: [Double]?, cornerRadius: Double?, rectangleCornerRadii: [Double]?, transitionDuration: Double?, transitionEasing: EasingType?, opacity: Double?, absoluteBoundingBox: Rectangle?, absoluteRenderBounds: Rectangle?, primaryAxisSizingMode: AxisSizingMode?, counterAxisSizingMode: AxisSizingMode?, primaryAxisAlignItems: PrimaryAxisAlignItems?, counterAxisAlignItems: CounterAxisAlignItems?, itemSpacing: Double?, layoutPositioning: LayoutPositioning?, layoutMode: LayoutMode?, paddingLeft: Double?, paddingRight: Double?, paddingTop: Double?, paddingBottom: Double?, effects: [Effect]?, styles: Styles?, characters: String?, style: TypeStyle?, constraints: LayoutConstraint?, layoutAlign: LayoutAlign?, layoutGrow: Double?) {
self.id = id
self.name = name
self.visible = visible
self.type = type
self.children = children
self.backgroundColor = backgroundColor
self.fills = fills
self.strokes = strokes
self.strokeWeight = strokeWeight
self.individualStrokeWeights = individualStrokeWeights
self.strokeAlign = strokeAlign
self.strokeDashes = strokeDashes
self.cornerRadius = cornerRadius
self.rectangleCornerRadii = rectangleCornerRadii
self.transitionDuration = transitionDuration
self.transitionEasing = transitionEasing
self.opacity = opacity
self.absoluteBoundingBox = absoluteBoundingBox
self.absoluteRenderBounds = absoluteRenderBounds
self.primaryAxisSizingMode = primaryAxisSizingMode
self.counterAxisSizingMode = counterAxisSizingMode
self.primaryAxisAlignItems = primaryAxisAlignItems
self.counterAxisAlignItems = counterAxisAlignItems
self.itemSpacing = itemSpacing
self.layoutPositioning = layoutPositioning
self.layoutMode = layoutMode
self.paddingLeft = paddingLeft
self.paddingRight = paddingRight
self.paddingTop = paddingTop
self.paddingBottom = paddingBottom
self.effects = effects
self.styles = styles
self.characters = characters
self.style = style
self.constraints = constraints
self.layoutAlign = layoutAlign
self.layoutGrow = layoutGrow
}
}
public enum StyleType: String, Codable {
case fill = "FILL"
case text = "TEXT"
case effect = "EFFECT"
case grid = "GRID"
}
/// [Figma documentation](https://www.figma.com/developers/api#style-type)
public struct Style: Codable {
public let key: String
public let name: String
public let description: String
public let remote: Bool
public let styleType: StyleType
public init(key: String, name: String, description: String, remote: Bool, styleType: StyleType) {
self.key = key
self.name = name
self.description = description
self.remote = remote
self.styleType = styleType
}
}
public struct File: Codable {
public let document: Node
public let components: [String: Component]
public let styles: [String: Style]
public let name: String
public let schemaVersion: UInt8
public let version: String
public init(document: Node, components: [String: Component], styles: [String: Style], name: String, schemaVersion: UInt8, version: String) {
self.document = document
self.components = components
self.styles = styles
self.name = name
self.schemaVersion = schemaVersion
self.version = version
}
}