Merge commit '7621e2f8dec938cf48181c8b10afc9b01f444e68' into beta

This commit is contained in:
Ilya Laktyushin
2025-12-06 02:17:48 +04:00
commit 8344b97e03
28070 changed files with 7995182 additions and 0 deletions
@@ -0,0 +1,61 @@
//
// Font.swift
// lottie-swift
//
// Created by Brandon Withrow on 1/9/19.
//
import Foundation
// MARK: - Font
final class Font: Codable, DictionaryInitializable {
// MARK: Lifecycle
init(dictionary: [String: Any]) throws {
name = try dictionary.value(for: CodingKeys.name)
familyName = try dictionary.value(for: CodingKeys.familyName)
style = try dictionary.value(for: CodingKeys.style)
ascent = try dictionary.value(for: CodingKeys.ascent)
}
// MARK: Internal
let name: String
let familyName: String
let style: String
let ascent: Double
// MARK: Private
private enum CodingKeys: String, CodingKey {
case name = "fName"
case familyName = "fFamily"
case style = "fStyle"
case ascent
}
}
// MARK: - FontList
/// A list of fonts
final class FontList: Codable, DictionaryInitializable {
// MARK: Lifecycle
init(dictionary: [String: Any]) throws {
let fontDictionaries: [[String: Any]] = try dictionary.value(for: CodingKeys.fonts)
fonts = try fontDictionaries.map({ try Font(dictionary: $0) })
}
// MARK: Internal
enum CodingKeys: String, CodingKey {
case fonts = "list"
}
let fonts: [Font]
}
@@ -0,0 +1,96 @@
//
// Glyph.swift
// lottie-swift
//
// Created by Brandon Withrow on 1/9/19.
//
import Foundation
/// A model that holds a vector character
final class Glyph: Codable, DictionaryInitializable {
// MARK: Lifecycle
required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: Glyph.CodingKeys.self)
character = try container.decode(String.self, forKey: .character)
fontSize = try container.decode(Double.self, forKey: .fontSize)
fontFamily = try container.decode(String.self, forKey: .fontFamily)
fontStyle = try container.decode(String.self, forKey: .fontStyle)
width = try container.decode(Double.self, forKey: .width)
if
container.contains(.shapeWrapper),
let shapeContainer = try? container.nestedContainer(keyedBy: ShapeKey.self, forKey: .shapeWrapper),
shapeContainer.contains(.shapes)
{
shapes = try shapeContainer.decode([ShapeItem].self, ofFamily: ShapeType.self, forKey: .shapes)
} else {
shapes = []
}
}
init(dictionary: [String: Any]) throws {
character = try dictionary.value(for: CodingKeys.character)
fontSize = try dictionary.value(for: CodingKeys.fontSize)
fontFamily = try dictionary.value(for: CodingKeys.fontFamily)
fontStyle = try dictionary.value(for: CodingKeys.fontStyle)
width = try dictionary.value(for: CodingKeys.width)
if
let shapes = dictionary[CodingKeys.shapeWrapper.rawValue] as? [String: Any],
let shapeDictionaries = shapes[ShapeKey.shapes.rawValue] as? [[String: Any]]
{
self.shapes = try [ShapeItem].fromDictionaries(shapeDictionaries)
} else {
shapes = [ShapeItem]()
}
}
// MARK: Internal
/// The character
let character: String
/// The font size of the character
let fontSize: Double
/// The font family of the character
let fontFamily: String
/// The Style of the character
let fontStyle: String
/// The Width of the character
let width: Double
/// The Shape Data of the Character
let shapes: [ShapeItem]
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(character, forKey: .character)
try container.encode(fontSize, forKey: .fontSize)
try container.encode(fontFamily, forKey: .fontFamily)
try container.encode(fontStyle, forKey: .fontStyle)
try container.encode(width, forKey: .width)
var shapeContainer = container.nestedContainer(keyedBy: ShapeKey.self, forKey: .shapeWrapper)
try shapeContainer.encode(shapes, forKey: .shapes)
}
// MARK: Private
private enum CodingKeys: String, CodingKey {
case character = "ch"
case fontSize = "size"
case fontFamily = "fFamily"
case fontStyle = "style"
case width = "w"
case shapeWrapper = "data"
}
private enum ShapeKey: String, CodingKey {
case shapes
}
}
@@ -0,0 +1,165 @@
//
// TextAnimator.swift
// lottie-swift
//
// Created by Brandon Withrow on 1/9/19.
//
import Foundation
final class TextAnimator: Codable, DictionaryInitializable {
// MARK: Lifecycle
required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: TextAnimator.CodingKeys.self)
name = try container.decodeIfPresent(String.self, forKey: .name) ?? ""
let animatorContainer = try container.nestedContainer(keyedBy: TextAnimatorKeys.self, forKey: .textAnimator)
fillColor = try animatorContainer.decodeIfPresent(KeyframeGroup<Color>.self, forKey: .fillColor)
strokeColor = try animatorContainer.decodeIfPresent(KeyframeGroup<Color>.self, forKey: .strokeColor)
strokeWidth = try animatorContainer.decodeIfPresent(KeyframeGroup<Vector1D>.self, forKey: .strokeWidth)
tracking = try animatorContainer.decodeIfPresent(KeyframeGroup<Vector1D>.self, forKey: .tracking)
anchor = try animatorContainer.decodeIfPresent(KeyframeGroup<Vector3D>.self, forKey: .anchor)
position = try animatorContainer.decodeIfPresent(KeyframeGroup<Vector3D>.self, forKey: .position)
scale = try animatorContainer.decodeIfPresent(KeyframeGroup<Vector3D>.self, forKey: .scale)
skew = try animatorContainer.decodeIfPresent(KeyframeGroup<Vector1D>.self, forKey: .skew)
skewAxis = try animatorContainer.decodeIfPresent(KeyframeGroup<Vector1D>.self, forKey: .skewAxis)
rotation = try animatorContainer.decodeIfPresent(KeyframeGroup<Vector1D>.self, forKey: .rotation)
opacity = try animatorContainer.decodeIfPresent(KeyframeGroup<Vector1D>.self, forKey: .opacity)
}
init(dictionary: [String: Any]) throws {
name = (try? dictionary.value(for: CodingKeys.name)) ?? ""
let animatorDictionary: [String: Any] = try dictionary.value(for: CodingKeys.textAnimator)
if let fillColorDictionary = animatorDictionary[TextAnimatorKeys.fillColor.rawValue] as? [String: Any] {
fillColor = try? KeyframeGroup<Color>(dictionary: fillColorDictionary)
} else {
fillColor = nil
}
if let strokeColorDictionary = animatorDictionary[TextAnimatorKeys.strokeColor.rawValue] as? [String: Any] {
strokeColor = try? KeyframeGroup<Color>(dictionary: strokeColorDictionary)
} else {
strokeColor = nil
}
if let strokeWidthDictionary = animatorDictionary[TextAnimatorKeys.strokeWidth.rawValue] as? [String: Any] {
strokeWidth = try? KeyframeGroup<Vector1D>(dictionary: strokeWidthDictionary)
} else {
strokeWidth = nil
}
if let trackingDictionary = animatorDictionary[TextAnimatorKeys.tracking.rawValue] as? [String: Any] {
tracking = try? KeyframeGroup<Vector1D>(dictionary: trackingDictionary)
} else {
tracking = nil
}
if let anchorDictionary = animatorDictionary[TextAnimatorKeys.anchor.rawValue] as? [String: Any] {
anchor = try? KeyframeGroup<Vector3D>(dictionary: anchorDictionary)
} else {
anchor = nil
}
if let positionDictionary = animatorDictionary[TextAnimatorKeys.position.rawValue] as? [String: Any] {
position = try? KeyframeGroup<Vector3D>(dictionary: positionDictionary)
} else {
position = nil
}
if let scaleDictionary = animatorDictionary[TextAnimatorKeys.scale.rawValue] as? [String: Any] {
scale = try? KeyframeGroup<Vector3D>(dictionary: scaleDictionary)
} else {
scale = nil
}
if let skewDictionary = animatorDictionary[TextAnimatorKeys.skew.rawValue] as? [String: Any] {
skew = try? KeyframeGroup<Vector1D>(dictionary: skewDictionary)
} else {
skew = nil
}
if let skewAxisDictionary = animatorDictionary[TextAnimatorKeys.skewAxis.rawValue] as? [String: Any] {
skewAxis = try? KeyframeGroup<Vector1D>(dictionary: skewAxisDictionary)
} else {
skewAxis = nil
}
if let rotationDictionary = animatorDictionary[TextAnimatorKeys.rotation.rawValue] as? [String: Any] {
rotation = try? KeyframeGroup<Vector1D>(dictionary: rotationDictionary)
} else {
rotation = nil
}
if let opacityDictionary = animatorDictionary[TextAnimatorKeys.opacity.rawValue] as? [String: Any] {
opacity = try KeyframeGroup<Vector1D>(dictionary: opacityDictionary)
} else {
opacity = nil
}
}
// MARK: Internal
let name: String
/// Anchor
let anchor: KeyframeGroup<Vector3D>?
/// Position
let position: KeyframeGroup<Vector3D>?
/// Scale
let scale: KeyframeGroup<Vector3D>?
/// Skew
let skew: KeyframeGroup<Vector1D>?
/// Skew Axis
let skewAxis: KeyframeGroup<Vector1D>?
/// Rotation
let rotation: KeyframeGroup<Vector1D>?
/// Opacity
let opacity: KeyframeGroup<Vector1D>?
/// Stroke Color
let strokeColor: KeyframeGroup<Color>?
/// Fill Color
let fillColor: KeyframeGroup<Color>?
/// Stroke Width
let strokeWidth: KeyframeGroup<Vector1D>?
/// Tracking
let tracking: KeyframeGroup<Vector1D>?
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
var animatorContainer = container.nestedContainer(keyedBy: TextAnimatorKeys.self, forKey: .textAnimator)
try animatorContainer.encodeIfPresent(fillColor, forKey: .fillColor)
try animatorContainer.encodeIfPresent(strokeColor, forKey: .strokeColor)
try animatorContainer.encodeIfPresent(strokeWidth, forKey: .strokeWidth)
try animatorContainer.encodeIfPresent(tracking, forKey: .tracking)
}
// MARK: Private
private enum CodingKeys: String, CodingKey {
// case textSelector = "s" TODO
case textAnimator = "a"
case name = "nm"
}
private enum TextSelectorKeys: String, CodingKey {
case start = "s"
case end = "e"
case offset = "o"
}
private enum TextAnimatorKeys: String, CodingKey {
case fillColor = "fc"
case strokeColor = "sc"
case strokeWidth = "sw"
case tracking = "t"
case anchor = "a"
case position = "p"
case scale = "s"
case skew = "sk"
case skewAxis = "sa"
case rotation = "r"
case opacity = "o"
}
}
@@ -0,0 +1,123 @@
//
// TextDocument.swift
// lottie-swift
//
// Created by Brandon Withrow on 1/9/19.
//
import Foundation
// MARK: - TextJustification
enum TextJustification: Int, Codable {
case left
case right
case center
}
// MARK: - TextDocument
final class TextDocument: Codable, DictionaryInitializable, AnyInitializable {
// MARK: Lifecycle
init(dictionary: [String: Any]) throws {
text = try dictionary.value(for: CodingKeys.text)
fontSize = try dictionary.value(for: CodingKeys.fontSize)
fontFamily = try dictionary.value(for: CodingKeys.fontFamily)
let justificationValue: Int = try dictionary.value(for: CodingKeys.justification)
guard let justification = TextJustification(rawValue: justificationValue) else {
throw InitializableError.invalidInput
}
self.justification = justification
tracking = try dictionary.value(for: CodingKeys.tracking)
lineHeight = try dictionary.value(for: CodingKeys.lineHeight)
baseline = try dictionary.value(for: CodingKeys.baseline)
if let fillColorRawValue = dictionary[CodingKeys.fillColorData.rawValue] {
fillColorData = try? Color(value: fillColorRawValue)
} else {
fillColorData = nil
}
if let strokeColorRawValue = dictionary[CodingKeys.strokeColorData.rawValue] {
strokeColorData = try? Color(value: strokeColorRawValue)
} else {
strokeColorData = nil
}
strokeWidth = try? dictionary.value(for: CodingKeys.strokeWidth)
strokeOverFill = try? dictionary.value(for: CodingKeys.strokeOverFill)
if let textFramePositionRawValue = dictionary[CodingKeys.textFramePosition.rawValue] {
textFramePosition = try? Vector3D(value: textFramePositionRawValue)
} else {
textFramePosition = nil
}
if let textFrameSizeRawValue = dictionary[CodingKeys.textFrameSize.rawValue] {
textFrameSize = try? Vector3D(value: textFrameSizeRawValue)
} else {
textFrameSize = nil
}
}
convenience init(value: Any) throws {
guard let dictionary = value as? [String: Any] else {
throw InitializableError.invalidInput
}
try self.init(dictionary: dictionary)
}
// MARK: Internal
/// The Text
let text: String
/// The Font size
let fontSize: Double
/// The Font Family
let fontFamily: String
/// Justification
let justification: TextJustification
/// Tracking
let tracking: Int
/// Line Height
let lineHeight: Double
/// Baseline
let baseline: Double?
/// Fill Color data
let fillColorData: Color?
/// Scroke Color data
let strokeColorData: Color?
/// Stroke Width
let strokeWidth: Double?
/// Stroke Over Fill
let strokeOverFill: Bool?
let textFramePosition: Vector3D?
let textFrameSize: Vector3D?
// MARK: Private
private enum CodingKeys: String, CodingKey {
case text = "t"
case fontSize = "s"
case fontFamily = "f"
case justification = "j"
case tracking = "tr"
case lineHeight = "lh"
case baseline = "ls"
case fillColorData = "fc"
case strokeColorData = "sc"
case strokeWidth = "sw"
case strokeOverFill = "of"
case textFramePosition = "ps"
case textFrameSize = "sz"
}
}