Make things public

This commit is contained in:
Shadowfacts 2023-11-25 22:58:00 -05:00
parent 97ce18d056
commit e22f778f8f
3 changed files with 47 additions and 31 deletions

View File

@ -11,7 +11,7 @@ import UIKit
import AppKit
#endif
struct AttributedStringConverter<Callbacks: AttributedStringCallbacks> {
public struct AttributedStringConverter<Callbacks: AttributedStringCallbacks> {
private let configuration: AttributedStringConverterConfiguration
private var tokenizer: Tokenizer<String.Iterator>
private let str = NSMutableAttributedString()
@ -21,16 +21,16 @@ struct AttributedStringConverter<Callbacks: AttributedStringCallbacks> {
// The current run of text w/o styles changing
private var currentRun: String = ""
init(html: String, configuration: AttributedStringConverterConfiguration) where Callbacks == DefaultCallbacks {
public init(html: String, configuration: AttributedStringConverterConfiguration) where Callbacks == DefaultCallbacks {
self.init(html: html, configuration: configuration, callbacks: DefaultCallbacks.self)
}
init(html: String, configuration: AttributedStringConverterConfiguration, callbacks _: Callbacks.Type = Callbacks.self) {
public init(html: String, configuration: AttributedStringConverterConfiguration, callbacks _: Callbacks.Type = Callbacks.self) {
self.configuration = configuration
self.tokenizer = Tokenizer(chars: html.makeIterator())
}
mutating func convert() -> NSAttributedString {
public mutating func convert() -> NSAttributedString {
while let token = tokenizer.next() {
switch token {
case .character(let c):
@ -265,12 +265,12 @@ struct AttributedStringConverter<Callbacks: AttributedStringCallbacks> {
}
}
protocol AttributedStringCallbacks {
public protocol AttributedStringCallbacks {
static func makeURL(string: String) -> URL?
static func elementAction(name: String, attributes: InlineArray3<Attribute>) -> ElementAction
}
enum ElementAction: Equatable {
public enum ElementAction: Equatable {
case `default`
case skip
case replace(String)
@ -284,7 +284,7 @@ enum ElementAction: Equatable {
}
}
extension AttributedStringCallbacks {
public extension AttributedStringCallbacks {
static func makeURL(string: String) -> URL? {
URL(string: string)
}
@ -293,20 +293,36 @@ extension AttributedStringCallbacks {
}
}
struct DefaultCallbacks: AttributedStringCallbacks {
public struct DefaultCallbacks: AttributedStringCallbacks {
}
struct AttributedStringConverterConfiguration {
public struct AttributedStringConverterConfiguration {
#if os(iOS)
var font: UIFont
var monospaceFont: UIFont
var color: UIColor
public var font: UIFont
public var monospaceFont: UIFont
public var color: UIColor
#elseif os(macOS)
var font: NSFont
var monospaceFont: NSFont
var color: NSColor
public var font: NSFont
public var monospaceFont: NSFont
public var color: NSColor
#endif
public var paragraphStyle: NSParagraphStyle
#if os(iOS)
public init(font: UIFont, monospaceFont: UIFont, color: UIColor, paragraphStyle: NSParagraphStyle) {
self.font = font
self.monospaceFont = monospaceFont
self.color = color
self.paragraphStyle = paragraphStyle
}
#elseif os(macOS)
public init(font: NSFont, monospaceFont: NSFont, color: NSColor, paragraphStyle: NSParagraphStyle) {
self.font = font
self.monospaceFont = monospaceFont
self.color = color
self.paragraphStyle = paragraphStyle
}
#endif
var paragraphStyle: NSParagraphStyle
}
#if os(macOS)
@ -372,7 +388,7 @@ private enum Style {
}
extension Collection where Element == Attribute {
func attributeValue(for name: String) -> String? {
public func attributeValue(for name: String) -> String? {
first(where: { $0.name == name })?.value
}
}

View File

@ -12,10 +12,10 @@ import Foundation
/// If the array grows beyond 3 elements, it will be stored out-of-line.
/// Once that happens, the array will never return to being stored inline,
/// since the allocation cost has already been paid.
struct InlineArray3<E> {
public struct InlineArray3<E> {
private var storage: Storage
init() {
public init() {
self.storage = .inline(nil, nil, nil)
}
}
@ -28,7 +28,7 @@ extension InlineArray3 {
}
extension InlineArray3: ExpressibleByArrayLiteral {
init(arrayLiteral elements: Element...) {
public init(arrayLiteral elements: Element...) {
switch elements.count {
case 0:
self.storage = .inline(nil, nil, nil)
@ -45,11 +45,11 @@ extension InlineArray3: ExpressibleByArrayLiteral {
}
extension InlineArray3: MutableCollection {
typealias Element = E
typealias Index = Int
typealias Indices = Range<Int>
public typealias Element = E
public typealias Index = Int
public typealias Indices = Range<Int>
subscript(position: Int) -> Element {
public subscript(position: Int) -> Element {
_read {
precondition(position < endIndex)
switch storage {
@ -94,11 +94,11 @@ extension InlineArray3: MutableCollection {
}
}
var startIndex: Int {
public var startIndex: Int {
0
}
var endIndex: Int {
public var endIndex: Int {
switch storage {
case .inline(let a, let b, let c):
a == nil ? 0 : b == nil ? 1 : c == nil ? 2 : 3
@ -115,7 +115,7 @@ extension InlineArray3: RandomAccessCollection {
}
extension InlineArray3: RangeReplaceableCollection {
mutating func replaceSubrange<C>(_ subrange: Range<Int>, with newElements: C) where C: Collection, Element == C.Element {
public mutating func replaceSubrange<C>(_ subrange: Range<Int>, with newElements: C) where C: Collection, Element == C.Element {
switch storage {
case .array(var arr):
arr.replaceSubrange(subrange, with: newElements)
@ -201,7 +201,7 @@ extension InlineArray3: Equatable where E: Equatable {
}
extension InlineArray3: CustomStringConvertible {
var description: String {
public var description: String {
switch storage {
case .inline(nil, nil, nil):
return "[]"

View File

@ -200,9 +200,9 @@ enum Token: Equatable {
case doctype(String, forceQuirks: Bool, publicIdentifier: String?, systemIdentifier: String?)
}
struct Attribute: Equatable {
var name: String
var value: String
public struct Attribute: Equatable {
public var name: String
public var value: String
}
private enum State {