icons8 / free

.free format is an open efficient format for UI Design vector graphics
MIT License
26 stars 2 forks source link

Free Format

FREE is an open source format for vector graphic files designed to be compact, human-readable, back-compatible, and optimized for multithreaded parsing.

A FREE file is a ZIP archive with the following structure:

Lunacy has the support for the Sketch format from the very beginning. Including both opening and saving such files. It's actually a great format with lots of advantages (JSON, everything bundled in a ZIP archive, extensions via UserInfo, a time-proved data structure, and many others) but over time, we've accumulated a long list of drawbacks that have been limiting Lunacy’s growth.

What’s wrong with the Sketch format

Stringent limitations

Large file size

And there are reasons for this:

Some objects have inefficient serialization, which slows down parsing performance.

Downsides of the .fig format.

While working on import from Figma, we thoroughly explored the .fig format. It has one huge advantage — it’s binary and therefore extremely efficient in terms of disk space usage. But there are also serious downsides of the format:

Due to this, supporting the .fig format is costly. It requires at least one experienced full-time developer with reverse engineering expertise dedicated solely to this task. And during Figma updates, sleepless nights may be required to quickly roll out an update to support the new format. Lots of products that previously supported the format have given up.

Goals of the FREE format

We've made the decision to take the Sketch format and address all of its drawbacks while introducing new advantages. Therefore, the FREE format can be considered the successor to the Sketch format. We aimed for the format to be:

We didn't rush the development and release of this format. We worked on it for an extended period, carefully refining all ideas and solutions, so that after new releases its back-compatibility would be as seamless as possible.

Key differences from the Sketch format

Results

On small files or files with few layers but many images, improvements might not be very noticeable. But you will definitely see them on massive files with dozens or even hundreds of thousands of layers.

Side-by-side comparison

Assume that we have a red rectangle on the canvas. In Sketch, it would result in a JSON representation of 1639 characters (measured with the JSON formatted into a single line).

{
  "_class": "rectangle",
  "do_objectID": "5FF2A422-C956-4F7A-9E49-C295DB00A4D9",
  "booleanOperation": -1,
  "isFixedToViewport": false,
  "isLocked": false,
  "isVisible": true,
  "isTemplate": false,
  "layerListExpandedType": 0,
  "name": "Rectangle",
  "nameIsFixed": false,
  "resizingConstraint": 63,
  "resizingType": 0,
  "rotation": 0,
  "shouldBreakMaskChain": false,
  "exportOptions": {
    "_class": "exportOptions",
    "includedLayerIds": [],
    "layerOptions": 0,
    "shouldTrim": false,
    "exportFormats": []
  },
  "frame": {
    "_class": "rect",
    "constrainProportions": false,
    "height": 428,
    "width": 431,
    "x": 1887,
    "y": -751
  },
  "clippingMaskMode": 0,
  "hasClippingMask": false,
  "style": {
    "_class": "style",
    "endMarkerType": 0,
    "miterLimit": 10,
    "startMarkerType": 0,
    "windingRule": 1,
    "fills": [
      {
        "_class": "fill",
        "isEnabled": true,
        "fillType": 0,
        "color": {
          "_class": "color",
          "alpha": 1,
          "blue": 0,
          "green": 0,
          "red": 1
        }
      }
    ]
  },
  "edited": false,
  "isClosed": true,
  "pointRadiusBehaviour": 1,
  "points": [
    {
      "_class": "curvePoint",
      "cornerRadius": 0,
      "cornerStyle": 0,
      "curveFrom": "{0, 0}",
      "curveMode": 1,
      "curveTo": "{0, 0}",
      "hasCurveFrom": false,
      "hasCurveTo": false,
      "point": "{0, 0}"
    },
    {
      "_class": "curvePoint",
      "cornerRadius": 0,
      "cornerStyle": 0,
      "curveFrom": "{1, 0}",
      "curveMode": 1,
      "curveTo": "{1, 0}",
      "hasCurveFrom": false,
      "hasCurveTo": false,
      "point": "{1, 0}"
    },
    {
      "_class": "curvePoint",
      "cornerRadius": 0,
      "cornerStyle": 0,
      "curveFrom": "{1, 1}",
      "curveMode": 1,
      "curveTo": "{1, 1}",
      "hasCurveFrom": false,
      "hasCurveTo": false,
      "point": "{1, 1}"
    },
    {
      "_class": "curvePoint",
      "cornerRadius": 0,
      "cornerStyle": 0,
      "curveFrom": "{0, 1}",
      "curveMode": 1,
      "curveTo": "{0, 1}",
      "hasCurveFrom": false,
      "hasCurveTo": false,
      "point": "{0, 1}"
    }
  ],
  "fixedRadius": 0,
  "needsConvertionToNewRoundCorners": false,
  "hasConvertedToNewRoundCorners": true
}

In Lunacy's FREE format the same will take only 110 characters. A 15-fold difference.

{
  "_t": "RECT",
  "id": "IqTyX1bJek-eScKV2wCk2Q",
  "transform": [1887,-751],
  "size": [431,428],
  "fills": [{"color":"F00"}]
}

Plans

After fully adapting the new format and polishing it, we plan to develop, test, and, once acceptable results are achieved, introduce support for a binary variation of the format. This means that within the ZIP archive, you'll have .BIN files instead of .JSON. The idea is to maintain the same structure and practices but represent the data in the most efficient manner. Additionally, in the case of providing such serialization options, we will offer a converter that will be able to convert the data to JSON and back, preserving user-readability and maximum file size efficiency. If successful, we can attain the efficiency of the .fig format without its drawbacks.

Base Types

Free format is NULL-free, NaN-free and Infinity-free - if any of this values are in JSON - it's broken.

Layers

Component

A component is a reusable groups of layers.

Has all properties of Frame, plus:

Sketch compatibility * BackgroundInInstance: [bool](#bool) = `False` - defines whether to include background in component instances.

Oval

An oval is a shape drawn on the canvas with the Oval tool.

Has all properties of Path, plus:

Polygon

A polygon is a shape drawn on the canvas with the Polygon tool.

Has all properties of Path, plus:

Rectangle

A rectangle is a shape drawn on the canvas with the Rectangle tool.

Has all properties of Path, plus:

Star

A star is a shape drawn on the canvas with the Star tool.

Has all properties of Path, plus:

Triangle

A triangle is a shape drawn on the canvas with the Triangle tool.

Has all properties of Path, plus:

Sketch compatibility * Equilateral: [bool](#bool) = `False` - if the triangle is equilateral.

Frame

A frame is a special type of layers that serves as a container for other layers or layer groups. Frames are a must for prototypes.

Has all properties of Styled, plus:

Sketch compatibility * OverlayStyle: [Style](#Style) - style settings for the frame if it acts as an overlay in Sketch prototyping. * GroupLayout: [SketchGroupLayout](#SketchGroupLayout) - sketch Layout settings. Not supported in Lunacy, but keeping data for compatibility. * BackgroundInExport: [bool](#bool) = `False` - when enabled, the frame background is included into export files. * OverlayInteraction: [OverlayBackgroundInteraction](#OverlayBackgroundInteraction) = `None` - overlay interaction for Sketch prototyping. * Overlay: [bool](#bool) = `False` - defines whether the frame acts as an overlay in prototyping. * HasBackground: [bool](#bool) = `False` - defines whether the frame has background. * Background: [Color](#Color) = `ffffffff` - defines the frame background color. * BackgroundId: [GUID](#GUID) - defines the background color variable ID. * OverlaySettings: [OverlaySettings](#OverlaySettings) - sketch prototyping overlay feature settings.

Group

A layer group is two or more layers unified into a single entity that can be manipulated, organized, and treated as a single layer.

Has all properties of Styled, plus:

Sketch compatibility * SkipConstraints: [bool](#bool) = `False` - serves for constraints compatibility with Sketch. If the file is imported from the Sketch format, the parameter should be set to false to handle constraints properly. * GroupLayout: [SketchGroupLayout](#SketchGroupLayout) - sketch group layout. We don't support it but keep it for compatibility

Instance

An instance is a copy of the main component. With instances, you can reuse the same design element in multiple places in your project while retaining a connection to the main component.

Has all properties of Styled, plus:

Sketch compatibility * VerticalSpacing: [float](#float) = `0` - defines vertical spacing. * HorizontalSpacing: [float](#float) = `0` - defines horizontal spacing.

Path

A vector path determines the outline and form of a vector object. A path is made up of points and segments.

Has all properties of Styled, plus:

Shape

A shape is a rectangle, oval, polygon, triangle, or star drawn with the respective shape tool. You can draw a triangle, rectangle, etc. with the Pen tool, but they won't be treated as shapes.

Has all properties of Styled, plus:

Sketch compatibility * SkipConstraints: [bool](#bool) = `False` - serves for constraints compatibility with Sketch. If the file is imported from the Sketch format, the parameter should be set to false to handle constraints properly. * GroupLayout: [SketchGroupLayout](#SketchGroupLayout) - sketch group layout. We don't support it, but keep it for compatibility.

Text

Text is a block or line of text on the canvas.

Has all properties of Styled, plus:

Hotspot

A hotspot is a special type of layers used to define clickable areas on prototypes.

Has all properties of Layer, plus:

Slice

A slice is a special type of layers used for exporting certaing parts of designs.

Has all properties of Layer, plus:

Styled

A styled layer is a layer that has layer styling options.

Has all properties of Layer, plus:

Layer

A layer is any ungrouped element available on the canvas.

Lunacy specific * PhotoId: [string](#string) - identifier of a photo from the Lunacy gallery. * IllustrationId: [string](#string) - identifier of an illustraion from the Lunacy gallery. * IconId: [string](#string) - identifier of an icon from the Lunacy gallery. * AvatarId: [string](#string) - identifier of a Lunacy-generated avatar. * Data: [DataInfo](#DataInfo) - information about auto generated texts. * Upscaled: [bool](#bool) = `False` - if the image has been upscaled in Lunacy. * BackgroundRemove: [BackgroundRemovalState](#BackgroundRemovalState) = `None` - background removal procedure info.

Border

Defines the appearance of borders.

Has all properties of Fill, plus:

AutoLayoutContainer

Defines auto layout settings.

BlurEffect

Defines the settings of the blur effect.

Sketch compatibility * Center: [Point](#Point) = `[0,5,0,5]` - center point of motion blur. * MotionAngle: [float](#float) = `0` - angle of motion for motion blur.

BorderOptions

Defines the advanced options of borders, arrows, lines, and paths drawn with the Pen or Pencil tools.

ColorAsset

Colors stored in the document (color picker > dropdown list (global) > document).

ColorVariable

Color variables stored in the document.

Columns

Defines column settings in a layout grid.

Document

The document's .json structure.

Sketch compatibility * ColorSpace: [ColorSpace](#ColorSpace) = `Unmanaged` - сolor scheme the document uses.

ExportOption

Export settings.

Fill

Defines the fill applied to a layer.

Font

Embedded fonts stored in the document.

Gradient

An object that represents a gradient.

GradientAsset

Gradients stored in the document (color picker > dropdown list (global) > document).

GradientStop

A position-color pair representing a gradient stop.

Grid

Defines square grid settings for a frame.

Sketch compatibility * ThickTimes: [int](#int) = `10` - every N line should be thick.

ImageFilters

Defines filters that can be applied to images.

InlineStyle

Style (bold, italic, etc.) applied to a part of text or single word within a text block.

Meta

Contains metadata about the document.

Override

Defines overrides for components.

Sketch compatibility * LegacyColor: [ColorOverride](#ColorOverride) - color override. * LegacyTextColor: [TextColorOverride](#TextColorOverride) - text color override. * LegacyTextWeight: [TextWeightOverride](#TextWeightOverride) - text weight override.

Page

Document page properties.

Pattern

Defines the image fill options.

PrototypeViewport

This is a frame preset. Also used to determine viewport size for a large frame to scroll it properly.

Rows

Defines row settings in a layout grid.

Rulers

An object containing ruler origins and guideline positions.

Sketch compatibility * Origin: [Point](#Point) = `[0,0]` - ruler origin. Not supported in Lunacy. Sketch Compatibility

ShadowEffect

Defines the shadow options.

SharedLibrary

Contains components, styles and variables from external library that is used in current document. Every file in the shared folder is Shared Library.

SharedStyle

Style saved in the document.

Style

Defines a set of properties that make up a style.

TextStyle

Defines a set of properties that make up a text style.

IGridLayout

Defines layout grid settings for a frame.

ILayoutContainer

Defines an auto layout.

Color Struct

32-bit ARGB unpremultiplied color value.

Matrix Struct

A transformation matrix is standard way in computer graphics to represent translation and rotation. These are the top two rows of a 3x3 matrix. The bottom row of the matrix is assumed to be [0, 0, 1]. This is known as an affine transform and is enough to represent translation, rotation, and skew. The identity transform is [1, 0, 0, 0, 1, 0]. A translation matrix will typically look like: [1, 0, tx, 0, 1, ty] and a rotation matrix will typically look like: [cos(angle), -sin(angle), 0, sin(angle), cos(angle), 0] If a matrix contains only translation it will be printed like point [0,5]

Point Struct

A utility class to represent a point.

Rect Struct

A utility class to represent a rectangle.

Size Struct

A utility class to represent layer size.

Thickness Struct

Thickness struct. Used for Border thickness and Padding values

Vertex Struct

A utility class to represent a vertex.

AnimationType Enum

Defines animation types in prototypes.

Arrowhead Enum

Defines the appearance of arrowheads.

BaselinePosition Enum

Defines text position against the baseline.

BlendMode Enum

Defines the type of blend mode applied to a layer.

BlurType Enum

Defines the blur type.

BoolOp Enum

Types of boolean operations used to combine shapes.

BorderPosition Enum

Defines the border postion.

CharacterCasing Enum

Defines letter case.

ComponentType Enum

Types of components. Currently used for filtering only. Some of the types are not supported yet.

CurveMode Enum

Defines the types of points on Bézier curves.

FillType Enum

Defines the fill type.

GradientType Enum

List of Gradient types.

HorizontalAlignment Enum

Defines how a set of layers is aligned horizontally.

LayoutHorizontalAlignment Enum

Defines horizontal alignment settings in layout grids.

LayoutOrientation Enum

Orientation of an auto layout.

LayoutVerticalAlignment Enum

Defines vertical alignment settings in layout grids.

LineCap Enum

Defines the shape of the end caps of open paths drawn with the Line, Arrow, or Pen/Pencil tools.

LineJoin Enum

Defines the appearance of the corners for arrows and paths with corners drawn with the Pen/Pencil tool.

ListMarkerType Enum

Defines the type of a text list.

MaskType Enum

Type of a mask.

PathFillType Enum

Defines the filling options for overlapping paths.

PatternFillType Enum

Defines the image fill type.

ScaleType Enum

Defines the scale type for exported objects.

SizingMode Enum

Defines the behavior of auto layout containers as their content is changed.

TextBehavior Enum

Defines textbox behavior options.

TextHorizontalAlignment Enum

Defines how a text is aligned horizontally.

TextVerticalAlignment Enum

Defines how a text is aligned vertically.

VertexFlags Enum

Defines vertex flags.

Sketch compatibility * `16` RoundedInverted * `32` Angled * `48` Squared

VerticalAlignment Enum

Defines how a set of layers is aligned vertically.

DataInfo

Information about auto generated texts. //Lunacy Specific

BackgroundRemovalState Enum

Background removal procedure info. //Lunacy Specific

DataFieldType Enum

Defines the type of generated text. //Lunacy Specific

DataType Enum

Defines the category of generated text. //Lunacy Specific

ColorOverride

Defines color overrides for components. //Sketch Compatibility

OverlaySettings

Defines overlay settings. //Sketch Compatibility

SketchGroupLayout

Sketch Group Layout Properties //Sketch Compatibility

TextColorOverride

Defines text color overrides for components. //Sketch Compatibility

TextWeightOverride

Defines text weight overrides for components. //Sketch Compatibility

ColorOverrideType Enum

Defines types of color overrides for components. //Sketch Compatibility

ColorSpace Enum

Сolor scheme the document uses. //Sketch Compatibility

CornerStyle Enum

Sketch legacy, not supported in Lunacy //Sketch Compatibility

GroupLayoutAnchor Enum

Layout alignment on axis. For vertical it's: left, center or right. For horizontal: top, middle or bottom. //Sketch Compatibility

GroupLayoutAxis Enum

Group Layout Orientation //Sketch Compatibility

NamingScheme Enum

Controls the use of suffixes/prefixes in the names of export files. //Sketch Compatibility

OverlayBackgroundInteraction Enum

Overlay-background interaction options. //Sketch Compatibility

OverlayType Enum

Defines overlay types. //Sketch Compatibility

Changelog

Version 4 - TBD

Version 3 - 25.09.2024

Version 2 - 11.08.2024

Version 1 - 19.03.2024

by Icons8 LLC 2023