Skip to content

Conversation

@mattesmohr
Copy link
Member

@mattesmohr mattesmohr commented Oct 17, 2025

This pull request tries to make some attributes more typesafe.

Vector attributes

// Absolute length
Rectangle {}.position(x: 50, y: 50)
Circle {}.center(x: 10, y: 10)
Rectangle {}.radius(x: 10, y: 10)
Vector {}.viewBox(x: 0, y: 0, width: 400, height: 200)

// Relative length
Circle {}.center(UnitPoint(x: 10, y: 10, format: .relative))

The challenge here is that these attributes accept absolute lengths such as 50 or 50.3 (for precision), as well as percentage values 50%. I couldn't come up with a better way to support both.

Also for future consideration, mixing those types (for whatever reason someone wants to do this) is not possible yet.

Circle {}.center(x: 10, y: 10.0) // This won't work

Sourceset attribute

Image()
   .sourceSet(SourceCandidate("...png", width: 1024), SourceCandidate("...png", width: 1680))

Image()
   .sourceSet(SourceCandidate("...png", density: .ultra))

Sizes attribute

Image()
   .sizes(SizeCandidate("15vw", conditions: .orientation(.landscape), SizeCandidate("100vw"))

Link()
   .sizes("16x16", "32x32")

Media attribute

Link()
   .media(MediaQuery(.screen, features: .orientation(.landscape)), MediaQuery(.print, features: .resolution("300dpi"))

Accept attribute

Input()
   .type(.file)
   .accept(.ogg, .mpeg)

@mattesmohr mattesmohr marked this pull request as ready for review November 6, 2025 18:45
@mattesmohr mattesmohr merged commit 5bf3348 into main Nov 24, 2025
1 check passed
@mattesmohr mattesmohr deleted the make-attributes-typesafe branch November 24, 2025 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant