|
6 | 6 | // |
7 | 7 |
|
8 | 8 | import Foundation |
9 | | -import OrderedCollections |
10 | | - |
11 | | -// A typealias that allows us to use `OrderedSet` without importing OrderedCollections |
12 | | -public typealias OrderedSet<Element: Hashable> = OrderedCollections.OrderedSet<Element> |
13 | | - |
14 | | -// A typealias that allows us to use `OrderedDictionary` without importing OrderedCollections |
15 | | -public typealias OrderedDictionary<Key: Hashable, Value> = OrderedCollections.OrderedDictionary<Key, Value> |
16 | | - |
17 | | -// A typealias that allows us to use `UUID` without importing Foundation |
18 | | -public typealias UUID = Foundation.UUID |
19 | | - |
20 | | -// A typealias that allows us to use `URL` without importing Foundation |
21 | | -public typealias URL = Foundation.URL |
22 | | - |
23 | | -// A typealias that allows us to use `Data` without importing Foundation |
24 | | -public typealias Data = Foundation.Data |
25 | | - |
26 | | -// A typealias that allows us to use `Date` without importing Foundation |
27 | | -public typealias Date = Foundation.Date |
28 | | - |
29 | | -/// A publishing-time registration required by rendered attributes. |
30 | | -enum PublishingRegistration: Hashable, Equatable, Sendable { |
31 | | - case fontFamily(Font) |
32 | | - case responsiveFont(ResponsiveValues<LengthUnit>) |
33 | | - case responsiveVisibility(ResponsiveValues<Bool>) |
34 | | - |
35 | | - func apply(to context: PublishingContext) { |
36 | | - switch self { |
37 | | - case .fontFamily(let font): |
38 | | - context.cssManager.registerFontFamily(font) |
39 | | - case .responsiveFont(let values): |
40 | | - _ = context.cssManager.registerFont(values) |
41 | | - case .responsiveVisibility(let values): |
42 | | - _ = context.cssManager.registerStyles(values) |
43 | | - } |
44 | | - } |
45 | | -} |
46 | 9 |
|
47 | 10 | /// A handful of attributes that all HTML types must support, either for |
48 | 11 | /// rendering or for publishing purposes. |
49 | | -public struct CoreAttributes: Equatable, Sendable, CustomStringConvertible { |
| 12 | +public struct CoreAttributes: Equatable, Sendable { |
50 | 13 | /// A unique identifier. Can be empty. |
51 | 14 | var id = "" |
52 | 15 |
|
@@ -75,10 +38,10 @@ public struct CoreAttributes: Equatable, Sendable, CustomStringConvertible { |
75 | 38 | /// Whether this set of attributes is empty. |
76 | 39 | var isEmpty: Bool { self == CoreAttributes() } |
77 | 40 |
|
78 | | - /// All core attributes collapsed down to a single string for easy application. |
79 | | - public var description: String { |
80 | | - registerPublishingRequirements() |
81 | | - return "\(idString)\(customAttributeString)\(classString)\(styleString)\(dataString)\(ariaString)\(eventString)" |
| 41 | + /// All core attributes collapsed down to a single string for inclusion |
| 42 | + /// in HTML markup output. |
| 43 | + var markupAttributeString: String { |
| 44 | + "\(idString)\(customAttributeString)\(classString)\(styleString)\(dataString)\(ariaString)\(eventString)" |
82 | 45 | } |
83 | 46 |
|
84 | 47 | /// The ID of this element, if set. |
@@ -337,12 +300,11 @@ public struct CoreAttributes: Equatable, Sendable, CustomStringConvertible { |
337 | 300 | publishingRegistrations.formUnion(other.publishingRegistrations) |
338 | 301 | } |
339 | 302 |
|
340 | | - /// Applies publishing-time registrations when a publishing context is active. |
341 | | - private func registerPublishingRequirements() { |
342 | | - guard let context = PublishingContext.current else { return } |
| 303 | +} |
343 | 304 |
|
344 | | - for registration in publishingRegistrations { |
345 | | - registration.apply(to: context) |
346 | | - } |
| 305 | +extension String.StringInterpolation { |
| 306 | + @available(*, deprecated, message: "Interpolate CoreAttributes into Markup, not String — String interpolation drops publishing-time registrations.") |
| 307 | + public mutating func appendInterpolation(_ attributes: CoreAttributes) { |
| 308 | + appendLiteral(attributes.markupAttributeString) |
347 | 309 | } |
348 | 310 | } |
0 commit comments