Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make area element an empty node #158

Merged
merged 2 commits into from
Nov 29, 2024
Merged
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
30 changes: 19 additions & 11 deletions Sources/HTMLKit/Abstraction/Elements/MapElements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,34 @@

import OrderedCollections

/// The element defines an image map.
/// A element that defines an image map area.
///
/// ```html
/// <area></area>
/// Use `Area` to define specific clickable regions within an image map.
///
/// ```swift
/// Image()
/// .source(...png)
/// .useMap("#...")
/// Map {
/// Area()
/// .coordinates("...")
/// }
/// .name("...")
/// ```
public struct Area: ContentNode, MapElement {
public struct Area: EmptyNode, MapElement {

internal var name: String { "area" }

internal var attributes: OrderedDictionary<String, Any>?

internal var content: [Content]

public init(@ContentBuilder<Content> content: () -> [Content]) {
self.content = content()
}
/// Creates a area
public init() {}

@available(*, deprecated, message: "The area element is actually an empty element. Use Area() instead.")
public init(@ContentBuilder<Content> content: () -> [Content]) {}

internal init(attributes: OrderedDictionary<String, Any>?, content: [Content]) {
internal init(attributes: OrderedDictionary<String, Any>?) {
self.attributes = attributes
self.content = content
}

public func modify(if condition: Bool, element: (Area) -> Area) -> Area {
Expand Down
4 changes: 2 additions & 2 deletions Tests/HTMLKitTests/ElementTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1142,12 +1142,12 @@ final class ElementTests: XCTestCase {
func testAreaElement() throws {

let view = TestView {
Area {}
Area()
}

XCTAssertEqual(try renderer.render(view: view),
"""
<area></area>
<area>
"""
)
}
Expand Down