Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 176 additions & 7 deletions Sources/HTMLKit/Abstraction/Attributes/ContentAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -982,16 +982,62 @@ extension DisabledAttribute where Self: EmptyNode {
public protocol DownloadAttribute: Attribute {

/// Mark the target as downloadable.
///
///
/// ```swift
/// Anchor {
/// "Lorem ipsum..."
/// }
/// .download()
/// .download(true)
/// ```
///
///
/// - Parameter condition: Whether the target is downloadable.
///
/// - Returns: The element
func download(_ condition: Bool) -> Self

/// Mark the target as downloadable.
///
/// ```swift
/// Anchor {
/// "Lorem ipsum..."
/// }
/// .download("filename")
/// ```
///
/// - Parameter value: The name to label the download.
///
/// - Returns: The element
func download(_ name: String) -> Self

/// Mark the target as downloadable.
///
/// ```swift
/// Anchor {
/// "Lorem ipsum..."
/// }
/// .download("filename")
/// ```
///
/// - Parameters:
/// - localizedKey: The string key to be translated.
/// - tableName: The translation table to look in.
///
/// - Returns: The element
func download() -> Self
func download(_ localizedKey: LocalizedStringKey, tableName: String?) -> Self

/// Mark the target as downloadable.
///
/// ```swift
/// Anchor {
/// "Lorem ipsum..."
/// }
/// .download("filename")
/// ```
///
/// - Parameter value: The name to label the download.
///
/// - Returns: The element
func download(verbatim name: String) -> Self
}

extension DownloadAttribute where Self: ContentNode {
Expand Down Expand Up @@ -1334,6 +1380,20 @@ public protocol HiddenAttribute: Attribute {
///
/// - Returns: The element
func hidden(_ condition: Bool) -> Self

/// Hide an element.
///
/// ```swift
/// Paragraph {
/// "Lorem ipsum..."
/// }
/// .hidden(.untilFound)
/// ```
///
/// - Parameter value: The condition under which to hide the element.
///
/// - Returns: The element
func hidden(_ value: Values.Condition) -> Self
}

extension HiddenAttribute where Self: ContentNode {
Expand Down Expand Up @@ -2726,13 +2786,28 @@ public protocol RelationshipAttribute: Attribute {
/// "Lorem ipsum..."
/// }
/// .reference("https://...")
/// .relationship(.author)
/// .relationship(.author, .external)
/// ```
///
/// - Parameter values: The relationship types to associate with.
///
/// - Returns: The element
func relationship(_ values: Values.Relation...) -> Self

/// Indicate the relationship between documents.
///
/// ```swift
/// Anchor {
/// "Lorem ipsum..."
/// }
/// .reference("https://...")
/// .relationship([.author, .external])
/// ```
///
/// - Parameter value: The relationship type to associate with.
/// - Parameter values: The relationship types to associate with.
///
/// - Returns: The element
func relationship(_ value: Values.Relation) -> Self
func relationship(_ values: [Values.Relation]) -> Self
}

extension RelationshipAttribute where Self: ContentNode {
Expand Down Expand Up @@ -4245,3 +4320,97 @@ extension AbbreviatedAttribute where Self: EmptyNode {
return self.mutate(key: "abbr", value: value)
}
}

/// A type that provides the `imageSources` modifier.
@_documentation(visibility: internal)
public protocol ImageSourcesAttribute: Attribute {

/// Preload a set of sources.
///
/// ```swift
/// Link()
/// .relationship(.preload)
/// .as(.image)
/// .imageSources([SourceCandidate("...webp", width: 1024), SourceCandidate("...webp", width: 1680)])
/// ```
///
/// - Parameter candidates: The candidates to load in advance.
///
/// - Returns: The element.
func imageSources(_ candidates: [SourceCandidate]) -> Self

/// Preload a set of sources.
///
/// ```swift
/// Link()
/// .relationship(.preload)
/// .as(.image)
/// .imageSources(SourceCandidate("...webp", width: 1024), SourceCandidate("...webp", width: 1680))
/// ```
///
/// - Parameter candidates: The candidates to load in advance.
///
/// - Returns: The element.
func imageSources(_ candidates: SourceCandidate...) -> Self
}

extension ImageSourcesAttribute where Self: ContentNode {

internal func mutate(imagesrcset value: AttributeData) -> Self {
return self.mutate(key: "imagesrcset", value: value)
}
}

extension ImageSourcesAttribute where Self: EmptyNode {

internal func mutate(imagesrcset value: AttributeData) -> Self {
return self.mutate(key: "imagesrcset", value: value)
}
}

/// A type that provides the `imageSizes` modifier.
@_documentation(visibility: internal)
public protocol ImageSizesAttribute: Attribute {

/// Preload the right source size.
///
/// ```swift
/// Link()
/// .relationship(.preload)
/// .as(.image)
/// .imageSizes(SizeCandidate("100vw", conditions: .maxWidth("1680px")), SizeCandidate("80vw"))
/// ```
///
/// - Parameter candidates: The candidates to choose from.
///
/// - Returns: The element.
func imageSizes(_ candidates: [SizeCandidate]) -> Self

/// Preload the right source size.
///
/// ```swift
/// Link()
/// .relationship(.preload)
/// .as(.image)
/// .imageSizes(SizeCandidate("100vw", conditions: .maxWidth("1680px")), SizeCandidate("80vw"))
/// ```
///
/// - Parameter candidates: The candidates to choose from.
///
/// - Returns: The element.
func imageSizes(_ candidates: SizeCandidate...) -> Self
}

extension ImageSizesAttribute where Self: ContentNode {

internal func mutate(imagesizes value: AttributeData) -> Self {
return self.mutate(key: "imagesizes", value: value)
}
}

extension ImageSizesAttribute where Self: EmptyNode {

internal func mutate(imagesizes value: AttributeData) -> Self {
return self.mutate(key: "imagesizes", value: value)
}
}
4 changes: 4 additions & 0 deletions Sources/HTMLKit/Abstraction/Elements/BasicElements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ extension Html: GlobalContentAttributes, GlobalEventAttributes {
return self
}

public func hidden(_ value: Values.Condition) -> Html {
return mutate(hidden: .init(value.rawValue, context: .trusted))
}

public func inputMode(_ value: Values.Mode) -> Html {
return mutate(inputmode: .init(value.rawValue, context: .trusted))
}
Expand Down
Loading
Loading